@windi-ui/core 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/badge-B-3Z5qKd.mjs +54 -0
- package/dist/badge-DP_7SF0i.cjs +71 -0
- package/dist/components.cjs +5 -58
- package/dist/components.d.cts +3 -9
- package/dist/components.d.mts +3 -9
- package/dist/components.mjs +1 -54
- package/dist/index.cjs +1136 -656
- package/dist/index.d.cts +12 -45
- package/dist/index.d.mts +12 -45
- package/dist/index.mjs +1133 -655
- 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-7pMUZGLb.d.mts +415 -0
- package/dist/vars-D-T56h9H.d.cts +415 -0
- package/package.json +14 -12
- package/dist/components.d.ts +0 -11
- package/dist/index.d.ts +0 -46
- package/dist/shared/core.BBBw5V2R.d.cts +0 -182
- package/dist/shared/core.BBBw5V2R.d.mts +0 -182
- package/dist/shared/core.BBBw5V2R.d.ts +0 -182
package/dist/index.mjs
CHANGED
|
@@ -1,680 +1,1158 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as definePreset, t as nuxtUi } from "./nuxt-ui-S3tspIeQ.mjs";
|
|
2
|
+
import { n as button_default, t as badge_default } from "./badge-B-3Z5qKd.mjs";
|
|
3
|
+
// src/config.ts
|
|
4
|
+
const PRESETS = { "nuxt-ui": nuxtUi };
|
|
3
5
|
function resolveConfig(config) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const { prefix = "wui", rootSelector = ":root", variantScope = "element", overrideMode = "vars", darkSelector, presets = [], build, safelist = false, debug = false } = config;
|
|
7
|
+
return {
|
|
8
|
+
prefix,
|
|
9
|
+
rootSelector,
|
|
10
|
+
default: config.default,
|
|
11
|
+
accent: config.accent,
|
|
12
|
+
colors: config.colors,
|
|
13
|
+
variantScope,
|
|
14
|
+
overrides: config.overrides,
|
|
15
|
+
overrideMode,
|
|
16
|
+
variantUtilities: config.variantUtilities,
|
|
17
|
+
darkSelector,
|
|
18
|
+
presets: presets.map((p) => typeof p !== "string" ? p : Object.hasOwn(PRESETS, p) ? PRESETS[p]() : unknownPreset(p)),
|
|
19
|
+
build,
|
|
20
|
+
safelist,
|
|
21
|
+
debug
|
|
22
|
+
};
|
|
12
23
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return name.replace(/([.:@])/g, "\\$1");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function varsProvider(prefix) {
|
|
19
|
-
function vName(name) {
|
|
20
|
-
return `--${prefix}-${name}`;
|
|
21
|
-
}
|
|
22
|
-
function varFunc(v2, fallback) {
|
|
23
|
-
return `var(${cssEsc(v2)}${fallback ? `, ${fallback}` : ""})`;
|
|
24
|
-
}
|
|
25
|
-
const c = (v2) => vName(`c-${v2}`);
|
|
26
|
-
const v = (v2) => vName(`v-${v2}`);
|
|
27
|
-
const s = (v2) => vName(`s-${v2}`);
|
|
28
|
-
function color(name, fallback) {
|
|
29
|
-
return varFunc(c(name), fallback);
|
|
30
|
-
}
|
|
31
|
-
color.default = (name) => color(`default-${name}`);
|
|
32
|
-
color.accent = (name) => color(`accent-${name}`);
|
|
33
|
-
return {
|
|
34
|
-
c,
|
|
35
|
-
v,
|
|
36
|
-
s,
|
|
37
|
-
color,
|
|
38
|
-
variant(name, fallback) {
|
|
39
|
-
return varFunc(v(name), fallback);
|
|
40
|
-
},
|
|
41
|
-
size(name, fallback) {
|
|
42
|
-
return varFunc(s(name), fallback);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
24
|
+
function unknownPreset(name) {
|
|
25
|
+
throw new Error(`WindiUI: unknown preset "${name}". The presets are: ${Object.keys(PRESETS).join(", ")}.`);
|
|
45
26
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (typeof val === "string") {
|
|
50
|
-
vars[cssEsc(keyMap(p))] = val;
|
|
51
|
-
} else {
|
|
52
|
-
cssVars(val, (cp) => `${keyMap(p)}-${cp}`, vars);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return vars;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
class BuilderBase {
|
|
59
|
-
constructor(ctx) {
|
|
60
|
-
this.ctx = ctx;
|
|
61
|
-
}
|
|
62
|
-
get vars() {
|
|
63
|
-
return this.ctx.vars;
|
|
64
|
-
}
|
|
65
|
-
get theme() {
|
|
66
|
-
return this.ctx.theme;
|
|
67
|
-
}
|
|
68
|
-
names() {
|
|
69
|
-
return [...this.items.keys()];
|
|
70
|
-
}
|
|
71
|
-
add(name, builder) {
|
|
72
|
-
if (this.items.has(name)) {
|
|
73
|
-
console.error(`"${name}" already exists.`);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const elem = builder(this.ctx);
|
|
77
|
-
this.items.set(name, elem);
|
|
78
|
-
}
|
|
79
|
-
update(name, builder) {
|
|
80
|
-
const elem = this.items.get(name);
|
|
81
|
-
if (!elem) {
|
|
82
|
-
console.error(`"${name}" not found.`);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const res = builder(elem, this.ctx);
|
|
86
|
-
if (res && res !== elem) {
|
|
87
|
-
this.items.set(name, res);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
remove(name) {
|
|
91
|
-
if (!this.items.has(name)) {
|
|
92
|
-
console.error(`"${name}" not found.`);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
this.items.delete(name);
|
|
96
|
-
}
|
|
27
|
+
/** Types a config object, so that one object can be shared by the plugin, a config file and other tools. */
|
|
28
|
+
function defineConfig(config) {
|
|
29
|
+
return config;
|
|
97
30
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
add(name, builder) {
|
|
103
|
-
if (name === "default") {
|
|
104
|
-
console.error('"default" can only be updated.');
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
super.add(name, builder);
|
|
108
|
-
}
|
|
109
|
-
remove(name) {
|
|
110
|
-
if (name === "default") {
|
|
111
|
-
console.error('"default" can only be updated.');
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
super.remove(name);
|
|
115
|
-
}
|
|
116
|
-
rootVars() {
|
|
117
|
-
return this.cssVars("default");
|
|
118
|
-
}
|
|
31
|
+
// src/utils.ts
|
|
32
|
+
function cssEsc(name) {
|
|
33
|
+
return name.replace(/([.:@])/g, "\\$1");
|
|
119
34
|
}
|
|
120
|
-
|
|
35
|
+
// src/base.ts
|
|
36
|
+
var BuilderBase = class {
|
|
37
|
+
ctx;
|
|
38
|
+
constructor(ctx) {
|
|
39
|
+
this.ctx = ctx;
|
|
40
|
+
}
|
|
41
|
+
get vars() {
|
|
42
|
+
return this.ctx.vars;
|
|
43
|
+
}
|
|
44
|
+
get theme() {
|
|
45
|
+
return this.ctx.theme;
|
|
46
|
+
}
|
|
47
|
+
names() {
|
|
48
|
+
return [...this.items.keys()];
|
|
49
|
+
}
|
|
50
|
+
add(name, builder) {
|
|
51
|
+
if (this.items.has(name)) {
|
|
52
|
+
console.error(`"${name}" already exists.`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
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));
|
|
60
|
+
}
|
|
61
|
+
update(name, builder) {
|
|
62
|
+
const elem = this.items.get(name);
|
|
63
|
+
if (!elem) {
|
|
64
|
+
console.error(`"${name}" not found.`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const res = builder(elem, this.ctx);
|
|
68
|
+
if (res && res !== elem) this.items.set(name, res);
|
|
69
|
+
}
|
|
70
|
+
remove(name) {
|
|
71
|
+
if (!this.items.has(name)) {
|
|
72
|
+
console.error(`"${name}" not found.`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.items.delete(name);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var VarsGeneratorBase = class extends BuilderBase {
|
|
79
|
+
constructor(ctx) {
|
|
80
|
+
super(ctx);
|
|
81
|
+
}
|
|
82
|
+
add(name, builder) {
|
|
83
|
+
if (name === "default") {
|
|
84
|
+
console.error("\"default\" can only be updated.");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
super.add(name, builder);
|
|
88
|
+
}
|
|
89
|
+
remove(name) {
|
|
90
|
+
if (name === "default") {
|
|
91
|
+
console.error("\"default\" can only be updated.");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
super.remove(name);
|
|
95
|
+
}
|
|
96
|
+
rootVars() {
|
|
97
|
+
return this.cssVars("default");
|
|
98
|
+
}
|
|
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
|
+
];
|
|
121
114
|
const COLOR_SHADE_REGEX = /50|950|[1-9]00/;
|
|
122
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
|
+
};
|
|
123
128
|
const COLOR_PALETTE_REGEX = new RegExp(`^(.+)-(${COLOR_SHADE_REGEX.source})$`);
|
|
124
129
|
const FLAT_COLORS = {
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
black: "#000",
|
|
131
|
+
white: "#fff"
|
|
127
132
|
};
|
|
128
|
-
function getColorMap(colors) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
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) {
|
|
152
|
-
cMap.custom.set(`${cName}-${sKey}`, sVal);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return cMap;
|
|
157
|
-
}
|
|
158
|
-
class ColorsGenerator extends VarsGeneratorBase {
|
|
159
|
-
colors;
|
|
160
|
-
items;
|
|
161
|
-
constructor(ctx) {
|
|
162
|
-
super(ctx);
|
|
163
|
-
this.colors = getColorMap(this.theme.colors());
|
|
164
|
-
this.items = this.colors.palette;
|
|
165
|
-
}
|
|
166
|
-
names() {
|
|
167
|
-
const cNames = super.names();
|
|
168
|
-
cNames.push(...cNames.map((c) => `accent-${c}`));
|
|
169
|
-
return cNames;
|
|
170
|
-
}
|
|
171
|
-
cssVars(name) {
|
|
172
|
-
let palette = this.items.get(name);
|
|
173
|
-
let accentVars = false;
|
|
174
|
-
if (!palette) {
|
|
175
|
-
if (name.startsWith("accent-")) {
|
|
176
|
-
name = name.replace(/^accent-/, "");
|
|
177
|
-
palette = this.items.get(name);
|
|
178
|
-
if (palette) {
|
|
179
|
-
accentVars = true;
|
|
180
|
-
} else {
|
|
181
|
-
console.error(`Color "${name}" not found.`);
|
|
182
|
-
return {};
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
console.error(`Color "${name}" not found.`);
|
|
186
|
-
return {};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const cObj = Object.fromEntries(palette.entries());
|
|
190
|
-
return cssVars(cObj, (n) => this.vars.c(accentVars ? `accent-${n}` : n));
|
|
191
|
-
}
|
|
192
|
-
rootVars() {
|
|
193
|
-
const cRoot = {};
|
|
194
|
-
for (const mn in FLAT_COLORS) {
|
|
195
|
-
cRoot[this.vars.c(mn)] = this.colors.custom.get(mn) ?? FLAT_COLORS[mn];
|
|
196
|
-
}
|
|
197
|
-
const dc = super.rootVars();
|
|
198
|
-
Object.assign(cRoot, dc);
|
|
199
|
-
const addPalette = (suffix, palette) => {
|
|
200
|
-
for (const [shade, color] of palette) {
|
|
201
|
-
cRoot[this.vars.c(`${suffix}-${shade}`)] = color;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
addPalette("default", this.items.get("default") ?? /* @__PURE__ */ new Map());
|
|
205
|
-
addPalette("accent", this.items.get("accent") ?? /* @__PURE__ */ new Map());
|
|
206
|
-
return cRoot;
|
|
207
|
-
}
|
|
208
|
-
toValue(name, alpha) {
|
|
209
|
-
return this.theme.colorValue(COLOR_SHADE_EX_REGEX.exec(name) ? this.vars.color(name) : name, alpha);
|
|
210
|
-
}
|
|
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;
|
|
211
154
|
}
|
|
212
|
-
|
|
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
|
+
};
|
|
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
|
+
];
|
|
213
346
|
function defaultVariant(vars) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
};
|
|
347
|
+
return {
|
|
348
|
+
"bg": vars.color("white"),
|
|
349
|
+
"bg-soft": vars.color("100"),
|
|
350
|
+
"bg-muted": vars.color("200"),
|
|
351
|
+
"bg-accent": vars.color.accent("100"),
|
|
352
|
+
"bg-opacity": "1",
|
|
353
|
+
"border": vars.color("500"),
|
|
354
|
+
"border-soft": vars.color("400"),
|
|
355
|
+
"border-muted": vars.color("300"),
|
|
356
|
+
"border-accent": vars.color.accent("500"),
|
|
357
|
+
"border-opacity": "1",
|
|
358
|
+
"fg": vars.color("800"),
|
|
359
|
+
"fg-soft": vars.color("500"),
|
|
360
|
+
"fg-muted": vars.color("400"),
|
|
361
|
+
"fg-accent": vars.color.accent("700"),
|
|
362
|
+
"fg-opacity": "1",
|
|
363
|
+
pseudos: { ":hover": {
|
|
364
|
+
"bg": vars.color("100"),
|
|
365
|
+
"bg-soft": vars.color("200"),
|
|
366
|
+
"bg-muted": vars.color("300"),
|
|
367
|
+
"bg-accent": vars.color.accent("200")
|
|
368
|
+
} },
|
|
369
|
+
dark: {
|
|
370
|
+
"bg": vars.color("950"),
|
|
371
|
+
"bg-soft": vars.color("900"),
|
|
372
|
+
"bg-muted": vars.color("800"),
|
|
373
|
+
"bg-accent": vars.color.accent("900"),
|
|
374
|
+
"border": vars.color("700"),
|
|
375
|
+
"border-soft": vars.color("600"),
|
|
376
|
+
"border-muted": vars.color("500"),
|
|
377
|
+
"border-accent": vars.color.accent("700"),
|
|
378
|
+
"fg": vars.color("200"),
|
|
379
|
+
"fg-soft": vars.color("300"),
|
|
380
|
+
"fg-muted": vars.color("400"),
|
|
381
|
+
"fg-accent": vars.color.accent("200"),
|
|
382
|
+
"pseudos": { ":hover": {
|
|
383
|
+
"bg": vars.color("900"),
|
|
384
|
+
"bg-soft": vars.color("800"),
|
|
385
|
+
"bg-muted": vars.color("700"),
|
|
386
|
+
"bg-accent": vars.color.accent("900")
|
|
387
|
+
} }
|
|
388
|
+
}
|
|
389
|
+
};
|
|
261
390
|
}
|
|
262
391
|
function mainVariants(vars) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
392
|
+
return {
|
|
393
|
+
solid: {
|
|
394
|
+
"bg": vars.color("600"),
|
|
395
|
+
"bg-soft": vars.color("500"),
|
|
396
|
+
"bg-muted": vars.color("400"),
|
|
397
|
+
"bg-accent": vars.color.accent("600"),
|
|
398
|
+
"bg-opacity": "1",
|
|
399
|
+
"border": vars.color("600"),
|
|
400
|
+
"border-soft": vars.color("500"),
|
|
401
|
+
"border-muted": vars.color("400"),
|
|
402
|
+
"border-accent": vars.color.accent("600"),
|
|
403
|
+
"border-opacity": "0",
|
|
404
|
+
"fg": vars.color("white"),
|
|
405
|
+
"fg-soft": vars.color("200"),
|
|
406
|
+
"fg-muted": vars.color("300"),
|
|
407
|
+
"fg-accent": vars.color.accent("200"),
|
|
408
|
+
"fg-opacity": "1",
|
|
409
|
+
pseudos: { ":hover": {
|
|
410
|
+
"bg": vars.color("700"),
|
|
411
|
+
"bg-soft": vars.color("600"),
|
|
412
|
+
"bg-muted": vars.color("500"),
|
|
413
|
+
"bg-accent": vars.color.accent("700"),
|
|
414
|
+
"border": vars.color("700"),
|
|
415
|
+
"border-soft": vars.color("600"),
|
|
416
|
+
"border-muted": vars.color("500"),
|
|
417
|
+
"border-accent": vars.color.accent("700"),
|
|
418
|
+
"fg": vars.color("50")
|
|
419
|
+
} }
|
|
420
|
+
},
|
|
421
|
+
outline: {
|
|
422
|
+
"bg": vars.color("white"),
|
|
423
|
+
"bg-soft": vars.color("white"),
|
|
424
|
+
"bg-muted": vars.color("white"),
|
|
425
|
+
"bg-accent": vars.color("white"),
|
|
426
|
+
"bg-opacity": "0",
|
|
427
|
+
"border": vars.color("600"),
|
|
428
|
+
"border-soft": vars.color("500"),
|
|
429
|
+
"border-muted": vars.color("400"),
|
|
430
|
+
"border-accent": vars.color.accent("600"),
|
|
431
|
+
"border-opacity": "1",
|
|
432
|
+
"fg": vars.color("600"),
|
|
433
|
+
"fg-soft": vars.color("500"),
|
|
434
|
+
"fg-muted": vars.color("400"),
|
|
435
|
+
"fg-accent": vars.color.accent("600"),
|
|
436
|
+
"fg-opacity": "1",
|
|
437
|
+
pseudos: { ":hover": {
|
|
438
|
+
"bg": vars.color("100"),
|
|
439
|
+
"bg-soft": vars.color("100"),
|
|
440
|
+
"bg-muted": vars.color("100"),
|
|
441
|
+
"bg-accent": vars.color.accent("100"),
|
|
442
|
+
"bg-opacity": "0.75"
|
|
443
|
+
} },
|
|
444
|
+
dark: {
|
|
445
|
+
"border": vars.color("400"),
|
|
446
|
+
"border-soft": vars.color("500"),
|
|
447
|
+
"border-muted": vars.color("600"),
|
|
448
|
+
"border-accent": vars.color.accent("400"),
|
|
449
|
+
"fg": vars.color("400"),
|
|
450
|
+
"fg-soft": vars.color("500"),
|
|
451
|
+
"fg-muted": vars.color("600"),
|
|
452
|
+
"fg-accent": vars.color.accent("400"),
|
|
453
|
+
pseudos: { ":hover": {
|
|
454
|
+
"bg": vars.color("900"),
|
|
455
|
+
"bg-soft": vars.color("900"),
|
|
456
|
+
"bg-muted": vars.color("900"),
|
|
457
|
+
"bg-accent": vars.color.accent("900"),
|
|
458
|
+
"bg-opacity": "0.50"
|
|
459
|
+
} }
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
light: {
|
|
463
|
+
"bg": vars.color("100"),
|
|
464
|
+
"bg-soft": vars.color("200"),
|
|
465
|
+
"bg-muted": vars.color("300"),
|
|
466
|
+
"bg-accent": vars.color.accent("100"),
|
|
467
|
+
"bg-opacity": "1",
|
|
468
|
+
"border": vars.color("100"),
|
|
469
|
+
"border-soft": vars.color("200"),
|
|
470
|
+
"border-muted": vars.color("300"),
|
|
471
|
+
"border-accent": vars.color.accent("100"),
|
|
472
|
+
"border-opacity": "0",
|
|
473
|
+
"fg": vars.color("600"),
|
|
474
|
+
"fg-soft": vars.color("500"),
|
|
475
|
+
"fg-muted": vars.color("400"),
|
|
476
|
+
"fg-accent": vars.color.accent("600"),
|
|
477
|
+
"fg-opacity": "1",
|
|
478
|
+
pseudos: { ":hover": {
|
|
479
|
+
"bg": vars.color("600"),
|
|
480
|
+
"bg-soft": vars.color("500"),
|
|
481
|
+
"bg-muted": vars.color("400"),
|
|
482
|
+
"bg-accent": vars.color.accent("600"),
|
|
483
|
+
"border": vars.color("600"),
|
|
484
|
+
"border-soft": vars.color("500"),
|
|
485
|
+
"border-muted": vars.color("400"),
|
|
486
|
+
"border-accent": vars.color.accent("600"),
|
|
487
|
+
"fg": vars.color("50"),
|
|
488
|
+
"fg-soft": vars.color("100"),
|
|
489
|
+
"fg-muted": vars.color("200"),
|
|
490
|
+
"fg-accent": vars.color.accent("50")
|
|
491
|
+
} },
|
|
492
|
+
dark: {
|
|
493
|
+
"bg": vars.color("900"),
|
|
494
|
+
"bg-soft": vars.color("700"),
|
|
495
|
+
"bg-muted": vars.color("600"),
|
|
496
|
+
"bg-accent": vars.color.accent("900"),
|
|
497
|
+
"bg-opacity": "0.5",
|
|
498
|
+
"border": vars.color("900"),
|
|
499
|
+
"border-soft": vars.color("700"),
|
|
500
|
+
"border-muted": vars.color("600"),
|
|
501
|
+
"border-accent": vars.color.accent("900"),
|
|
502
|
+
"fg": vars.color("300"),
|
|
503
|
+
"fg-soft": vars.color("400"),
|
|
504
|
+
"fg-muted": vars.color("500"),
|
|
505
|
+
"fg-accent": vars.color.accent("300"),
|
|
506
|
+
pseudos: { ":hover": {
|
|
507
|
+
"bg": vars.color("600"),
|
|
508
|
+
"bg-soft": vars.color("500"),
|
|
509
|
+
"bg-muted": vars.color("400"),
|
|
510
|
+
"bg-accent": vars.color.accent("600"),
|
|
511
|
+
"bg-opacity": "1",
|
|
512
|
+
"border": vars.color("600"),
|
|
513
|
+
"border-soft": vars.color("500"),
|
|
514
|
+
"border-muted": vars.color("400"),
|
|
515
|
+
"border-accent": vars.color.accent("600"),
|
|
516
|
+
"fg": vars.color("50")
|
|
517
|
+
} }
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
/** @param fill whether a state refers to the base value of each property it leaves out */
|
|
523
|
+
function flatten(vars, props, fill = true) {
|
|
524
|
+
const { pseudos: vPseudos, ...vProps } = props;
|
|
525
|
+
const cssObj = vProps;
|
|
526
|
+
if (vPseudos) {
|
|
527
|
+
const propKeys = fill ? Object.keys(vProps) : [];
|
|
528
|
+
for (const vpk in vPseudos) {
|
|
529
|
+
const vp = vPseudos[vpk];
|
|
530
|
+
if (vp) {
|
|
531
|
+
const vpPropKeys = /* @__PURE__ */ new Set([...Object.keys(vp), ...propKeys]);
|
|
532
|
+
for (const vppk of vpPropKeys) cssObj[`${vppk}-${vpk}`] = vp[vppk] ?? vars.variant(vppk);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return cssObj;
|
|
402
537
|
}
|
|
403
538
|
function getCssVars(vars, props) {
|
|
404
|
-
|
|
405
|
-
const cssObj = vProps;
|
|
406
|
-
if (vPseudos) {
|
|
407
|
-
const propKeys = new Set(Object.keys(vProps));
|
|
408
|
-
for (const vpk in vPseudos) {
|
|
409
|
-
const vp = vPseudos[vpk];
|
|
410
|
-
if (vp) {
|
|
411
|
-
const vpPropKeys = new Set(Object.keys(vp)).union(propKeys);
|
|
412
|
-
for (const vppk of vpPropKeys) {
|
|
413
|
-
cssObj[`${vppk}-${vpk}`] = vppk in vp ? vp[vppk] : vProps[vppk];
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return cssVars(cssObj, (n) => vars.v(n));
|
|
539
|
+
return cssVars(flatten(vars, props), (n) => vars.v(n));
|
|
419
540
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
this.items = new Map([
|
|
425
|
-
["default", defaultVariant(this.vars)],
|
|
426
|
-
...Object.entries(mainVariants(this.vars))
|
|
427
|
-
]);
|
|
428
|
-
}
|
|
429
|
-
cssVars(name) {
|
|
430
|
-
const variant = this.items.get(name);
|
|
431
|
-
if (!variant) {
|
|
432
|
-
console.error(`Variant "${name}" not found.`);
|
|
433
|
-
return {};
|
|
434
|
-
}
|
|
435
|
-
const { dark: vDark, ...vProps } = variant;
|
|
436
|
-
const cssVars2 = getCssVars(this.vars, vProps);
|
|
437
|
-
if (vDark) {
|
|
438
|
-
cssVars2["@dark"] = getCssVars(this.vars, vDark);
|
|
439
|
-
}
|
|
440
|
-
return cssVars2;
|
|
441
|
-
}
|
|
442
|
-
utilCss(v, prop, alpha) {
|
|
443
|
-
return this.vApplyProp(v, prop, {}, void 0, alpha);
|
|
444
|
-
}
|
|
445
|
-
apply(v = true, pseudos, target = {}) {
|
|
446
|
-
const appl = (pV, pTarget, pseudo) => {
|
|
447
|
-
if (pV === false)
|
|
448
|
-
return pTarget;
|
|
449
|
-
if (pV === true)
|
|
450
|
-
pV = ["bg", "border", "text"];
|
|
451
|
-
const aV = pV;
|
|
452
|
-
const applProp = (mProp) => {
|
|
453
|
-
const vP = aV.find((p) => p.startsWith(mProp));
|
|
454
|
-
if (!vP) return;
|
|
455
|
-
const sProp = vP.replace(new RegExp(`^${mProp}-?`), "");
|
|
456
|
-
this.vApplyProp(mProp, sProp, pTarget, pseudo);
|
|
457
|
-
};
|
|
458
|
-
applProp("bg");
|
|
459
|
-
applProp("border");
|
|
460
|
-
applProp("text");
|
|
461
|
-
return pTarget;
|
|
462
|
-
};
|
|
463
|
-
if (v) {
|
|
464
|
-
appl(v, target);
|
|
465
|
-
}
|
|
466
|
-
if (pseudos) {
|
|
467
|
-
if (Array.isArray(pseudos)) {
|
|
468
|
-
pseudos = pseudos.reduce((acc, p) => {
|
|
469
|
-
acc[p] = true;
|
|
470
|
-
return acc;
|
|
471
|
-
}, {});
|
|
472
|
-
}
|
|
473
|
-
for (const pseudo in pseudos) {
|
|
474
|
-
const pV = pseudos[pseudo];
|
|
475
|
-
if (pV) {
|
|
476
|
-
const pTarget = target[`&${pseudo}`] ??= {};
|
|
477
|
-
appl(pV, pTarget, pseudo);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
return target;
|
|
482
|
-
}
|
|
483
|
-
vApplyProp(mProp, sProp, target = {}, pseudo, alpha) {
|
|
484
|
-
const mvp = mProp === "text" ? "fg" : mProp;
|
|
485
|
-
const vp = sProp && sProp !== "default" ? `${mvp}-${sProp}` : mvp;
|
|
486
|
-
const aVar = pseudo ? `${mvp}-opacity-${pseudo}` : `${mvp}-opacity`;
|
|
487
|
-
const vVal = this.vars.variant(pseudo ? `${vp}-${pseudo}` : vp);
|
|
488
|
-
const vAlpha = this.vars.variant(aVar, pseudo ? this.vars.variant(`${mvp}-opacity`, "1") : "1");
|
|
489
|
-
switch (mProp) {
|
|
490
|
-
case "bg":
|
|
491
|
-
this.theme.applyBackgroundColor(vVal, target, vAlpha);
|
|
492
|
-
break;
|
|
493
|
-
case "border":
|
|
494
|
-
this.theme.applyBorderColor(vVal, target, vAlpha);
|
|
495
|
-
break;
|
|
496
|
-
case "text":
|
|
497
|
-
this.theme.applyTextColor(vVal, target, vAlpha);
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
if (alpha) {
|
|
501
|
-
target[this.vars.v(aVar)] = `${alpha} !important`;
|
|
502
|
-
}
|
|
503
|
-
return target;
|
|
504
|
-
}
|
|
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);
|
|
505
545
|
}
|
|
506
|
-
|
|
507
|
-
function
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
spacing: {
|
|
511
|
-
"1": themeProvider.spacing("1"),
|
|
512
|
-
"1.5": themeProvider.spacing("1.5"),
|
|
513
|
-
"2": themeProvider.spacing("2"),
|
|
514
|
-
"3": themeProvider.spacing("3"),
|
|
515
|
-
"4": themeProvider.spacing("4")
|
|
516
|
-
},
|
|
517
|
-
text: themeProvider.fontSize("base")
|
|
518
|
-
},
|
|
519
|
-
xs: {
|
|
520
|
-
spacing: {
|
|
521
|
-
"1": themeProvider.spacing("px"),
|
|
522
|
-
"1.5": themeProvider.spacing("0.5"),
|
|
523
|
-
"2": themeProvider.spacing("1"),
|
|
524
|
-
"3": themeProvider.spacing("1.5"),
|
|
525
|
-
"4": themeProvider.spacing("2")
|
|
526
|
-
},
|
|
527
|
-
text: themeProvider.fontSize("xs")
|
|
528
|
-
},
|
|
529
|
-
sm: {
|
|
530
|
-
spacing: {
|
|
531
|
-
"1": themeProvider.spacing("0.5"),
|
|
532
|
-
"1.5": themeProvider.spacing("1"),
|
|
533
|
-
"2": themeProvider.spacing("1.5"),
|
|
534
|
-
"3": themeProvider.spacing("2"),
|
|
535
|
-
"4": themeProvider.spacing("3")
|
|
536
|
-
},
|
|
537
|
-
text: themeProvider.fontSize("sm")
|
|
538
|
-
},
|
|
539
|
-
lg: {
|
|
540
|
-
spacing: {
|
|
541
|
-
"1": themeProvider.spacing("1.5"),
|
|
542
|
-
"1.5": themeProvider.spacing("2"),
|
|
543
|
-
"2": themeProvider.spacing("3"),
|
|
544
|
-
"3": themeProvider.spacing("4"),
|
|
545
|
-
"4": themeProvider.spacing("5")
|
|
546
|
-
},
|
|
547
|
-
text: themeProvider.fontSize("lg")
|
|
548
|
-
},
|
|
549
|
-
xl: {
|
|
550
|
-
spacing: {
|
|
551
|
-
"1": themeProvider.spacing("2"),
|
|
552
|
-
"1.5": themeProvider.spacing("3"),
|
|
553
|
-
"2": themeProvider.spacing("4"),
|
|
554
|
-
"3": themeProvider.spacing("5"),
|
|
555
|
-
"4": themeProvider.spacing("6")
|
|
556
|
-
},
|
|
557
|
-
text: themeProvider.fontSize("xl")
|
|
558
|
-
}
|
|
559
|
-
};
|
|
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;
|
|
560
550
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
console.error(`Size "${name}" not found.`);
|
|
571
|
-
return {};
|
|
572
|
-
}
|
|
573
|
-
const rSize = { ...size };
|
|
574
|
-
const sText = size.text;
|
|
575
|
-
if (Array.isArray(sText)) {
|
|
576
|
-
rSize.text = sText[0];
|
|
577
|
-
const rVal = sText[1];
|
|
578
|
-
if (typeof rVal === "string") {
|
|
579
|
-
rSize["line-height"] = rVal;
|
|
580
|
-
} else if (typeof rVal === "object" && rVal !== null) {
|
|
581
|
-
if (rVal.lineHeight) rSize["line-height"] = rVal.lineHeight;
|
|
582
|
-
if (rVal.letterSpacing) rSize["letter-spacing"] = rVal.letterSpacing;
|
|
583
|
-
if (rVal.fontWeight) rSize["font-weight"] = rVal.fontWeight;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
return cssVars(rSize, (n) => this.vars.s(n));
|
|
587
|
-
}
|
|
551
|
+
/** The light values of the built-in default variant, by CSS variable name. */
|
|
552
|
+
function defaultVariantVars(vars) {
|
|
553
|
+
const { dark: _, ...props } = defaultVariant(vars);
|
|
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;
|
|
588
560
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
561
|
+
var VariantsGenerator = class extends VarsGeneratorBase {
|
|
562
|
+
scope;
|
|
563
|
+
mode;
|
|
564
|
+
items;
|
|
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") {
|
|
570
|
+
super(ctx);
|
|
571
|
+
this.scope = scope;
|
|
572
|
+
this.mode = mode;
|
|
573
|
+
this.items = new Map([["default", defaultVariant(this.vars)], ...Object.entries(mainVariants(this.vars))]);
|
|
574
|
+
}
|
|
575
|
+
cssVars(name) {
|
|
576
|
+
const variant = this.items.get(name);
|
|
577
|
+
if (!variant) {
|
|
578
|
+
console.error(`Variant "${name}" not found.`);
|
|
579
|
+
return {};
|
|
580
|
+
}
|
|
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
|
+
};
|
|
744
|
+
}
|
|
745
|
+
/** Every variable a variant can set, as `initial`: on a child it stops the parent's variant from inheriting. */
|
|
746
|
+
resetVars() {
|
|
747
|
+
const reset = {};
|
|
748
|
+
for (const name of this.items.keys()) {
|
|
749
|
+
const { "@dark": dark, ...light } = this.cssVars(name);
|
|
750
|
+
for (const v of Object.keys({
|
|
751
|
+
...light,
|
|
752
|
+
...dark
|
|
753
|
+
})) if (v.startsWith("--")) reset[v] = "initial";
|
|
754
|
+
}
|
|
755
|
+
return reset;
|
|
756
|
+
}
|
|
757
|
+
utilCss(v, prop, alpha) {
|
|
758
|
+
return this.withFallback(this.vApplyProp(v, prop, {}, void 0, alpha));
|
|
759
|
+
}
|
|
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
|
+
/**
|
|
798
|
+
* The two switches a fallback picks its light or dark value with: `var(on-light, <light>) var(on-dark, <dark>)`.
|
|
799
|
+
* The one of the current mode is not set, so its fallback is used, and the other one is empty.
|
|
800
|
+
* They inherit, so a pseudo-element is in the mode of its element, which a dark selector nested in its rule cannot tell.
|
|
801
|
+
*/
|
|
802
|
+
modeVars() {
|
|
803
|
+
const empty = `var(${this.vars.v("nil")},)`;
|
|
804
|
+
return {
|
|
805
|
+
light: { [this.vars.v("on-dark")]: empty },
|
|
806
|
+
dark: {
|
|
807
|
+
[this.vars.v("on-light")]: empty,
|
|
808
|
+
[this.vars.v("on-dark")]: "initial"
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
withFallback(css) {
|
|
813
|
+
if (this.scope === "universal") return css;
|
|
814
|
+
const { "@dark": dark = {}, ...light } = this.cssVars("default");
|
|
815
|
+
const bareRead = new RegExp(`var\\((${this.vars.v("").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[^,()\\s]+)\\)`, "g");
|
|
816
|
+
const resolve = (value, seen = []) => value.replace(bareRead, (read, name) => {
|
|
817
|
+
if (!(name in light) || seen.includes(name)) return read;
|
|
818
|
+
const onLight = resolve(light[name], [...seen, name]);
|
|
819
|
+
const onDark = resolve(dark[name] ?? light[name], [...seen, name]);
|
|
820
|
+
return onLight === onDark ? `var(${name}, ${onLight})` : `var(${name}, ${this.vars.variant("on-light", onLight)} ${this.vars.variant("on-dark", onDark)})`;
|
|
821
|
+
});
|
|
822
|
+
const addFallback = (rule) => Object.fromEntries(Object.entries(rule).map(([prop, value]) => [prop, typeof value === "string" ? resolve(value) : typeof value === "object" ? addFallback(value) : value]));
|
|
823
|
+
return addFallback(css);
|
|
824
|
+
}
|
|
825
|
+
apply(v = true, pseudos, target = {}) {
|
|
826
|
+
const appl = (pV, pTarget, pseudo) => {
|
|
827
|
+
if (pV === false) return pTarget;
|
|
828
|
+
if (pV === true) pV = [
|
|
829
|
+
"bg",
|
|
830
|
+
"border",
|
|
831
|
+
"text"
|
|
832
|
+
];
|
|
833
|
+
const aV = pV;
|
|
834
|
+
const applProp = (mProp) => {
|
|
835
|
+
const vP = aV.find((p) => p.startsWith(mProp));
|
|
836
|
+
if (!vP) return;
|
|
837
|
+
const sProp = vP.replace(new RegExp(`^${mProp}-?`), "");
|
|
838
|
+
this.vApplyProp(mProp, sProp, pTarget, pseudo);
|
|
839
|
+
};
|
|
840
|
+
applProp("bg");
|
|
841
|
+
applProp("border");
|
|
842
|
+
applProp("text");
|
|
843
|
+
return pTarget;
|
|
844
|
+
};
|
|
845
|
+
if (v) appl(v, target);
|
|
846
|
+
if (pseudos) {
|
|
847
|
+
if (Array.isArray(pseudos)) pseudos = pseudos.reduce((acc, p) => {
|
|
848
|
+
acc[p] = true;
|
|
849
|
+
return acc;
|
|
850
|
+
}, {});
|
|
851
|
+
for (const pseudo in pseudos) {
|
|
852
|
+
const pV = pseudos[pseudo];
|
|
853
|
+
if (pV) appl(pV, target[`&${pseudo}`] ??= {}, pseudo);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return target;
|
|
857
|
+
}
|
|
858
|
+
vApplyProp(mProp, sProp, target = {}, pseudo, alpha) {
|
|
859
|
+
const mvp = VAR_PROP[mProp];
|
|
860
|
+
const vp = sProp && sProp !== "default" ? `${mvp}-${sProp}` : mvp;
|
|
861
|
+
const aVar = pseudo ? `${mvp}-opacity-${pseudo}` : `${mvp}-opacity`;
|
|
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));
|
|
864
|
+
const one = this.scope === "universal" ? "1" : void 0;
|
|
865
|
+
const vAlpha = this.vars.variant(aVar, pseudo ? this.vars.variant(`${mvp}-opacity`, one) : one);
|
|
866
|
+
this.theme[APPLY[mProp]](vVal, target, vAlpha);
|
|
867
|
+
if (alpha) {
|
|
868
|
+
target[this.vars.v(aVar)] = `${alpha} !important`;
|
|
869
|
+
if (this.scope === "element") target[":where(&) > *"] = { [this.vars.v(aVar)]: "initial" };
|
|
870
|
+
}
|
|
871
|
+
return target;
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
// src/vars.ts
|
|
875
|
+
function varsProvider(prefix) {
|
|
876
|
+
function vName(name) {
|
|
877
|
+
return `--${prefix}-${name}`;
|
|
878
|
+
}
|
|
879
|
+
function varFunc(v, fallback) {
|
|
880
|
+
return `var(${cssEsc(v)}${fallback ? `, ${fallback}` : ""})`;
|
|
881
|
+
}
|
|
882
|
+
const c = (v) => vName(`c-${v}`);
|
|
883
|
+
const v = (v) => vName(`v-${v}`);
|
|
884
|
+
const s = (v) => vName(`s-${v}`);
|
|
885
|
+
const cv = (v) => vName(`cv-${v}`);
|
|
886
|
+
function color(name, fallback) {
|
|
887
|
+
return varFunc(c(name), fallback);
|
|
888
|
+
}
|
|
889
|
+
color.default = (name) => color(`default-${name}`);
|
|
890
|
+
color.accent = (name) => color(`accent-${name}`);
|
|
891
|
+
const vars = {
|
|
892
|
+
c,
|
|
893
|
+
v,
|
|
894
|
+
s,
|
|
895
|
+
cv,
|
|
896
|
+
color,
|
|
897
|
+
variant(name, fallback) {
|
|
898
|
+
if (typeof fallback === "object") fallback = defaultVariantVars(vars)[cssEsc(v(name))];
|
|
899
|
+
return varFunc(v(name), fallback);
|
|
900
|
+
},
|
|
901
|
+
size(name, fallback) {
|
|
902
|
+
return varFunc(s(name), fallback);
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
return vars;
|
|
613
906
|
}
|
|
614
|
-
|
|
907
|
+
function cssVars(obj, keyMap, vars = {}) {
|
|
908
|
+
for (const p in obj) {
|
|
909
|
+
const val = obj[p];
|
|
910
|
+
if (typeof val === "string" || typeof val === "number") vars[cssEsc(keyMap(p))] = String(val);
|
|
911
|
+
else cssVars(val, (cp) => `${keyMap(p)}-${cp}`, vars);
|
|
912
|
+
}
|
|
913
|
+
return vars;
|
|
914
|
+
}
|
|
915
|
+
// src/size.ts
|
|
916
|
+
function sizes(themeProvider) {
|
|
917
|
+
return {
|
|
918
|
+
default: {
|
|
919
|
+
spacing: {
|
|
920
|
+
"1": themeProvider.spacing("1"),
|
|
921
|
+
"1.5": themeProvider.spacing("1.5"),
|
|
922
|
+
"2": themeProvider.spacing("2"),
|
|
923
|
+
"3": themeProvider.spacing("3"),
|
|
924
|
+
"4": themeProvider.spacing("4")
|
|
925
|
+
},
|
|
926
|
+
text: themeProvider.fontSize("base")
|
|
927
|
+
},
|
|
928
|
+
xs: {
|
|
929
|
+
spacing: {
|
|
930
|
+
"1": themeProvider.spacing("px"),
|
|
931
|
+
"1.5": themeProvider.spacing("0.5"),
|
|
932
|
+
"2": themeProvider.spacing("1"),
|
|
933
|
+
"3": themeProvider.spacing("1.5"),
|
|
934
|
+
"4": themeProvider.spacing("2")
|
|
935
|
+
},
|
|
936
|
+
text: themeProvider.fontSize("xs")
|
|
937
|
+
},
|
|
938
|
+
sm: {
|
|
939
|
+
spacing: {
|
|
940
|
+
"1": themeProvider.spacing("0.5"),
|
|
941
|
+
"1.5": themeProvider.spacing("1"),
|
|
942
|
+
"2": themeProvider.spacing("1.5"),
|
|
943
|
+
"3": themeProvider.spacing("2"),
|
|
944
|
+
"4": themeProvider.spacing("3")
|
|
945
|
+
},
|
|
946
|
+
text: themeProvider.fontSize("sm")
|
|
947
|
+
},
|
|
948
|
+
lg: {
|
|
949
|
+
spacing: {
|
|
950
|
+
"1": themeProvider.spacing("1.5"),
|
|
951
|
+
"1.5": themeProvider.spacing("2"),
|
|
952
|
+
"2": themeProvider.spacing("3"),
|
|
953
|
+
"3": themeProvider.spacing("4"),
|
|
954
|
+
"4": themeProvider.spacing("5")
|
|
955
|
+
},
|
|
956
|
+
text: themeProvider.fontSize("lg")
|
|
957
|
+
},
|
|
958
|
+
xl: {
|
|
959
|
+
spacing: {
|
|
960
|
+
"1": themeProvider.spacing("2"),
|
|
961
|
+
"1.5": themeProvider.spacing("3"),
|
|
962
|
+
"2": themeProvider.spacing("4"),
|
|
963
|
+
"3": themeProvider.spacing("5"),
|
|
964
|
+
"4": themeProvider.spacing("6")
|
|
965
|
+
},
|
|
966
|
+
text: themeProvider.fontSize("xl")
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
var SizesGenerator = class extends VarsGeneratorBase {
|
|
971
|
+
items;
|
|
972
|
+
/** Whether `md` names the `default` size while no size of that name exists. Removing `md` ends it. */
|
|
973
|
+
md = true;
|
|
974
|
+
constructor(ctx) {
|
|
975
|
+
super(ctx);
|
|
976
|
+
this.items = new Map(Object.entries(sizes(this.theme)));
|
|
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
|
+
}
|
|
994
|
+
cssVars(name) {
|
|
995
|
+
const size = this.items.get(this.alias(name) ? "default" : name);
|
|
996
|
+
if (!size) {
|
|
997
|
+
console.error(`Size "${name}" not found.`);
|
|
998
|
+
return {};
|
|
999
|
+
}
|
|
1000
|
+
const { spacing, text: sText, ...own } = size;
|
|
1001
|
+
const rSize = {
|
|
1002
|
+
spacing,
|
|
1003
|
+
text: Array.isArray(sText) ? sText[0] : sText
|
|
1004
|
+
};
|
|
1005
|
+
if (Array.isArray(sText)) {
|
|
1006
|
+
const rVal = sText[1];
|
|
1007
|
+
if (typeof rVal === "string") rSize["line-height"] = rVal;
|
|
1008
|
+
else if (typeof rVal === "object" && rVal !== null) {
|
|
1009
|
+
if (rVal.lineHeight) rSize["line-height"] = rVal.lineHeight;
|
|
1010
|
+
if (rVal.letterSpacing) rSize["letter-spacing"] = rVal.letterSpacing;
|
|
1011
|
+
if (rVal.fontWeight) rSize["font-weight"] = rVal.fontWeight;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
Object.assign(rSize, own);
|
|
1015
|
+
return cssVars(rSize, (n) => this.vars.s(n));
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
// src/components/generator.ts
|
|
1019
|
+
var ComponentsGenerator = class extends BuilderBase {
|
|
1020
|
+
items = /* @__PURE__ */ new Map();
|
|
1021
|
+
constructor(context) {
|
|
1022
|
+
super(context);
|
|
1023
|
+
[button_default(context), badge_default(context)].forEach((component) => {
|
|
1024
|
+
this.items.set(component.name, component);
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
*css() {
|
|
1028
|
+
for (const [cName, component] of this.items) {
|
|
1029
|
+
const cClass = `.${cName}`;
|
|
1030
|
+
const css = { [cClass]: { ...component.style } };
|
|
1031
|
+
if (component.pseudos) for (const pseudo in component.pseudos) css[cClass][`&${pseudo}`] = component.pseudos[pseudo];
|
|
1032
|
+
if (component.applyVariant || component.applyVariantPseudos) this.ctx.variants.apply(component.applyVariant, component.applyVariantPseudos, css[cClass]);
|
|
1033
|
+
css[cClass] = this.ctx.variants.withFallback(css[cClass]);
|
|
1034
|
+
yield css;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
// src/builder.ts
|
|
615
1039
|
function createBuilder(colors, variants, sizes, components) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
1040
|
+
return {
|
|
1041
|
+
colorsNames: (all) => colors.names(all),
|
|
1042
|
+
variantsNames: () => variants.names(),
|
|
1043
|
+
sizesNames: () => sizes.names(),
|
|
1044
|
+
componentsNames: () => components.names(),
|
|
1045
|
+
addColor(name, value) {
|
|
1046
|
+
colors.addColor(name, value);
|
|
1047
|
+
return this;
|
|
1048
|
+
},
|
|
1049
|
+
addVariant(name, builder) {
|
|
1050
|
+
variants.add(name, builder);
|
|
1051
|
+
return this;
|
|
1052
|
+
},
|
|
1053
|
+
addSize(name, builder) {
|
|
1054
|
+
sizes.add(name, builder);
|
|
1055
|
+
return this;
|
|
1056
|
+
},
|
|
1057
|
+
addComponent(name, builder) {
|
|
1058
|
+
components.add(name, builder);
|
|
1059
|
+
return this;
|
|
1060
|
+
},
|
|
1061
|
+
setColor(name, value) {
|
|
1062
|
+
colors.setColor(name, value);
|
|
1063
|
+
return this;
|
|
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
|
+
},
|
|
1077
|
+
updateColor(name, builder) {
|
|
1078
|
+
colors.update(name, builder);
|
|
1079
|
+
return this;
|
|
1080
|
+
},
|
|
1081
|
+
updateVariant(name, builder) {
|
|
1082
|
+
variants.update(name, builder);
|
|
1083
|
+
return this;
|
|
1084
|
+
},
|
|
1085
|
+
updateSize(name, builder) {
|
|
1086
|
+
sizes.update(name, builder);
|
|
1087
|
+
return this;
|
|
1088
|
+
},
|
|
1089
|
+
updateComponent(name, builder) {
|
|
1090
|
+
components.update(name, builder);
|
|
1091
|
+
return this;
|
|
1092
|
+
},
|
|
1093
|
+
removeColor(name) {
|
|
1094
|
+
colors.remove(name);
|
|
1095
|
+
return this;
|
|
1096
|
+
},
|
|
1097
|
+
removeVariant(name) {
|
|
1098
|
+
variants.remove(name);
|
|
1099
|
+
return this;
|
|
1100
|
+
},
|
|
1101
|
+
removeSize(name) {
|
|
1102
|
+
sizes.remove(name);
|
|
1103
|
+
return this;
|
|
1104
|
+
},
|
|
1105
|
+
removeComponent(name) {
|
|
1106
|
+
components.remove(name);
|
|
1107
|
+
return this;
|
|
1108
|
+
},
|
|
1109
|
+
overrideVariant(variant, colors, override) {
|
|
1110
|
+
variants.override(variant, colors, override);
|
|
1111
|
+
return this;
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
658
1114
|
}
|
|
659
|
-
|
|
1115
|
+
// src/index.ts
|
|
660
1116
|
function create(config) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
1117
|
+
const rConfig = resolveConfig(config);
|
|
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
|
+
};
|
|
1126
|
+
return {
|
|
1127
|
+
vars,
|
|
1128
|
+
config: rConfig,
|
|
1129
|
+
generator(theme) {
|
|
1130
|
+
const ctx = {
|
|
1131
|
+
vars,
|
|
1132
|
+
theme
|
|
1133
|
+
};
|
|
1134
|
+
const variants = new VariantsGenerator(ctx, rConfig.variantScope, rConfig.overrideMode);
|
|
1135
|
+
const colors = new ColorsGenerator(ctx, rConfig, variants);
|
|
1136
|
+
const sizes = new SizesGenerator(ctx);
|
|
1137
|
+
const components = new ComponentsGenerator({
|
|
1138
|
+
...ctx,
|
|
1139
|
+
colors,
|
|
1140
|
+
variants
|
|
1141
|
+
});
|
|
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"));
|
|
1149
|
+
return {
|
|
1150
|
+
colors,
|
|
1151
|
+
variants,
|
|
1152
|
+
sizes,
|
|
1153
|
+
components
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
678
1157
|
}
|
|
679
|
-
|
|
680
|
-
export { create };
|
|
1158
|
+
export { create, defineConfig, definePreset, varsProvider };
|