@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
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/preset.ts
|
|
2
|
+
const CALL = /^(add|set|update|remove)(Color|Variant|Size|Component)$/;
|
|
3
|
+
/** Makes a preset from a `build` function. The preset takes the options every preset takes: `override`, `prefix` and `only`. */
|
|
4
|
+
function definePreset(name, build) {
|
|
5
|
+
return ({ override = false, prefix, only } = {}) => ({
|
|
6
|
+
name,
|
|
7
|
+
build(builder) {
|
|
8
|
+
const b = builder;
|
|
9
|
+
const own = /* @__PURE__ */ new Set();
|
|
10
|
+
const skipped = /* @__PURE__ */ new Set();
|
|
11
|
+
const kept = [];
|
|
12
|
+
const named = (n) => prefix ? `${prefix}-${n}` : n;
|
|
13
|
+
const target = (kind, n) => own.has(`${kind}:${named(n)}`) ? named(n) : n;
|
|
14
|
+
const left = (kind, n) => only?.includes(n) === false || skipped.has(`${kind}:${n}`);
|
|
15
|
+
const scoped = new Proxy(builder, { get(_, key) {
|
|
16
|
+
if (key === "overrideVariant") return (variant, colors, value) => {
|
|
17
|
+
if (!left("Variant", variant)) b.overrideVariant(target("Variant", variant), [colors].flat().flatMap((c) => c.split(",")).map((c) => target("Color", c.trim())), value);
|
|
18
|
+
return scoped;
|
|
19
|
+
};
|
|
20
|
+
const [, action, kind] = CALL.exec(key) ?? [];
|
|
21
|
+
if (!kind) return b[key];
|
|
22
|
+
return (n, ...rest) => {
|
|
23
|
+
if (left(kind, n)) return scoped;
|
|
24
|
+
if (action === "add" || action === "set") {
|
|
25
|
+
const id = `${kind}:${named(n)}`;
|
|
26
|
+
const ours = own.has(id);
|
|
27
|
+
if (!override && !ours && b[`${kind.toLowerCase()}sNames`](true).includes(named(n))) {
|
|
28
|
+
kept.push(named(n));
|
|
29
|
+
skipped.add(`${kind}:${n}`);
|
|
30
|
+
return scoped;
|
|
31
|
+
}
|
|
32
|
+
b[`${override || ours ? "set" : "add"}${kind}`](named(n), ...rest);
|
|
33
|
+
own.add(id);
|
|
34
|
+
} else b[key](target(kind, n), ...rest);
|
|
35
|
+
return scoped;
|
|
36
|
+
};
|
|
37
|
+
} });
|
|
38
|
+
build(scoped);
|
|
39
|
+
if (kept.length) console.warn(`WindiUI: the "${name}" preset keeps ${kept.map((k) => `"${k}"`).join(", ")}, which already ${kept.length > 1 ? "exist" : "exists"}. Pass \`override: true\` to replace ${kept.length > 1 ? "them" : "it"}.`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// src/presets/nuxt-ui.ts
|
|
44
|
+
/** The variants of Nuxt UI that WindiUI lacks: `soft`, `subtle`, `ghost` and `link`. `solid` and `outline` exist. */
|
|
45
|
+
const nuxtUi = definePreset("nuxt-ui", (b) => b.setVariant("soft", ({ vars: { color: c } }) => ({
|
|
46
|
+
bg: c("100"),
|
|
47
|
+
border: c("100"),
|
|
48
|
+
"border-opacity": "0",
|
|
49
|
+
fg: c("800"),
|
|
50
|
+
pseudos: { ":hover": { bg: c("200") } },
|
|
51
|
+
dark: {
|
|
52
|
+
bg: c("900"),
|
|
53
|
+
"bg-opacity": "0.5",
|
|
54
|
+
fg: c("300"),
|
|
55
|
+
pseudos: { ":hover": { bg: c("800") } }
|
|
56
|
+
}
|
|
57
|
+
})).setVariant("subtle", ({ vars: { color: c } }) => ({
|
|
58
|
+
bg: c("50"),
|
|
59
|
+
border: c("200"),
|
|
60
|
+
fg: c("800"),
|
|
61
|
+
pseudos: { ":hover": { bg: c("100") } },
|
|
62
|
+
dark: {
|
|
63
|
+
bg: c("950"),
|
|
64
|
+
"bg-opacity": "0.5",
|
|
65
|
+
border: c("800"),
|
|
66
|
+
fg: c("300"),
|
|
67
|
+
pseudos: { ":hover": { bg: c("900") } }
|
|
68
|
+
}
|
|
69
|
+
})).setVariant("ghost", ({ vars: { color: c } }) => ({
|
|
70
|
+
bg: c("50"),
|
|
71
|
+
"bg-opacity": "0",
|
|
72
|
+
border: c("50"),
|
|
73
|
+
"border-opacity": "0",
|
|
74
|
+
fg: c("700"),
|
|
75
|
+
pseudos: { ":hover": { "bg-opacity": "1" } },
|
|
76
|
+
dark: {
|
|
77
|
+
bg: c("900"),
|
|
78
|
+
fg: c("400"),
|
|
79
|
+
pseudos: { ":hover": { "bg-opacity": "0.5" } }
|
|
80
|
+
}
|
|
81
|
+
})).setVariant("link", ({ vars: { color: c } }) => ({
|
|
82
|
+
bg: c("50"),
|
|
83
|
+
"bg-opacity": "0",
|
|
84
|
+
border: c("50"),
|
|
85
|
+
"border-opacity": "0",
|
|
86
|
+
fg: c("700"),
|
|
87
|
+
pseudos: { ":hover": { fg: c("800") } },
|
|
88
|
+
dark: {
|
|
89
|
+
fg: c("400"),
|
|
90
|
+
pseudos: { ":hover": { fg: c("300") } }
|
|
91
|
+
}
|
|
92
|
+
})));
|
|
93
|
+
Object.defineProperty(exports, "definePreset", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function() {
|
|
96
|
+
return definePreset;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "nuxtUi", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function() {
|
|
102
|
+
return nuxtUi;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/preset.ts
|
|
2
|
+
const CALL = /^(add|set|update|remove)(Color|Variant|Size|Component)$/;
|
|
3
|
+
/** Makes a preset from a `build` function. The preset takes the options every preset takes: `override`, `prefix` and `only`. */
|
|
4
|
+
function definePreset(name, build) {
|
|
5
|
+
return ({ override = false, prefix, only } = {}) => ({
|
|
6
|
+
name,
|
|
7
|
+
build(builder) {
|
|
8
|
+
const b = builder;
|
|
9
|
+
const own = /* @__PURE__ */ new Set();
|
|
10
|
+
const skipped = /* @__PURE__ */ new Set();
|
|
11
|
+
const kept = [];
|
|
12
|
+
const named = (n) => prefix ? `${prefix}-${n}` : n;
|
|
13
|
+
const target = (kind, n) => own.has(`${kind}:${named(n)}`) ? named(n) : n;
|
|
14
|
+
const left = (kind, n) => only?.includes(n) === false || skipped.has(`${kind}:${n}`);
|
|
15
|
+
const scoped = new Proxy(builder, { get(_, key) {
|
|
16
|
+
if (key === "overrideVariant") return (variant, colors, value) => {
|
|
17
|
+
if (!left("Variant", variant)) b.overrideVariant(target("Variant", variant), [colors].flat().flatMap((c) => c.split(",")).map((c) => target("Color", c.trim())), value);
|
|
18
|
+
return scoped;
|
|
19
|
+
};
|
|
20
|
+
const [, action, kind] = CALL.exec(key) ?? [];
|
|
21
|
+
if (!kind) return b[key];
|
|
22
|
+
return (n, ...rest) => {
|
|
23
|
+
if (left(kind, n)) return scoped;
|
|
24
|
+
if (action === "add" || action === "set") {
|
|
25
|
+
const id = `${kind}:${named(n)}`;
|
|
26
|
+
const ours = own.has(id);
|
|
27
|
+
if (!override && !ours && b[`${kind.toLowerCase()}sNames`](true).includes(named(n))) {
|
|
28
|
+
kept.push(named(n));
|
|
29
|
+
skipped.add(`${kind}:${n}`);
|
|
30
|
+
return scoped;
|
|
31
|
+
}
|
|
32
|
+
b[`${override || ours ? "set" : "add"}${kind}`](named(n), ...rest);
|
|
33
|
+
own.add(id);
|
|
34
|
+
} else b[key](target(kind, n), ...rest);
|
|
35
|
+
return scoped;
|
|
36
|
+
};
|
|
37
|
+
} });
|
|
38
|
+
build(scoped);
|
|
39
|
+
if (kept.length) console.warn(`WindiUI: the "${name}" preset keeps ${kept.map((k) => `"${k}"`).join(", ")}, which already ${kept.length > 1 ? "exist" : "exists"}. Pass \`override: true\` to replace ${kept.length > 1 ? "them" : "it"}.`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// src/presets/nuxt-ui.ts
|
|
44
|
+
/** The variants of Nuxt UI that WindiUI lacks: `soft`, `subtle`, `ghost` and `link`. `solid` and `outline` exist. */
|
|
45
|
+
const nuxtUi = definePreset("nuxt-ui", (b) => b.setVariant("soft", ({ vars: { color: c } }) => ({
|
|
46
|
+
bg: c("100"),
|
|
47
|
+
border: c("100"),
|
|
48
|
+
"border-opacity": "0",
|
|
49
|
+
fg: c("800"),
|
|
50
|
+
pseudos: { ":hover": { bg: c("200") } },
|
|
51
|
+
dark: {
|
|
52
|
+
bg: c("900"),
|
|
53
|
+
"bg-opacity": "0.5",
|
|
54
|
+
fg: c("300"),
|
|
55
|
+
pseudos: { ":hover": { bg: c("800") } }
|
|
56
|
+
}
|
|
57
|
+
})).setVariant("subtle", ({ vars: { color: c } }) => ({
|
|
58
|
+
bg: c("50"),
|
|
59
|
+
border: c("200"),
|
|
60
|
+
fg: c("800"),
|
|
61
|
+
pseudos: { ":hover": { bg: c("100") } },
|
|
62
|
+
dark: {
|
|
63
|
+
bg: c("950"),
|
|
64
|
+
"bg-opacity": "0.5",
|
|
65
|
+
border: c("800"),
|
|
66
|
+
fg: c("300"),
|
|
67
|
+
pseudos: { ":hover": { bg: c("900") } }
|
|
68
|
+
}
|
|
69
|
+
})).setVariant("ghost", ({ vars: { color: c } }) => ({
|
|
70
|
+
bg: c("50"),
|
|
71
|
+
"bg-opacity": "0",
|
|
72
|
+
border: c("50"),
|
|
73
|
+
"border-opacity": "0",
|
|
74
|
+
fg: c("700"),
|
|
75
|
+
pseudos: { ":hover": { "bg-opacity": "1" } },
|
|
76
|
+
dark: {
|
|
77
|
+
bg: c("900"),
|
|
78
|
+
fg: c("400"),
|
|
79
|
+
pseudos: { ":hover": { "bg-opacity": "0.5" } }
|
|
80
|
+
}
|
|
81
|
+
})).setVariant("link", ({ vars: { color: c } }) => ({
|
|
82
|
+
bg: c("50"),
|
|
83
|
+
"bg-opacity": "0",
|
|
84
|
+
border: c("50"),
|
|
85
|
+
"border-opacity": "0",
|
|
86
|
+
fg: c("700"),
|
|
87
|
+
pseudos: { ":hover": { fg: c("800") } },
|
|
88
|
+
dark: {
|
|
89
|
+
fg: c("400"),
|
|
90
|
+
pseudos: { ":hover": { fg: c("300") } }
|
|
91
|
+
}
|
|
92
|
+
})));
|
|
93
|
+
export { definePreset as n, nuxtUi as t };
|
package/dist/presets.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { _ as Preset, v as PresetOptions, y as definePreset } from "./vars-D-T56h9H.cjs";
|
|
2
|
+
/** The variants of Nuxt UI that WindiUI lacks: `soft`, `subtle`, `ghost` and `link`. `solid` and `outline` exist. */
|
|
3
|
+
export declare const nuxtUi: ({ override, prefix, only }?: PresetOptions) => Preset;
|
|
4
|
+
export { type Preset, type PresetOptions, definePreset };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { S as definePreset, b as Preset, x as PresetOptions } from "./types-7pMUZGLb.mjs";
|
|
2
|
+
/** The variants of Nuxt UI that WindiUI lacks: `soft`, `subtle`, `ghost` and `link`. `solid` and `outline` exist. */
|
|
3
|
+
export declare const nuxtUi: ({ override, prefix, only }?: PresetOptions) => Preset;
|
|
4
|
+
export { type Preset, type PresetOptions, definePreset };
|
package/dist/presets.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as definePreset, t as nuxtUi } from "./nuxt-ui-S3tspIeQ.mjs";
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { AdvancedPseudos, AtRule, AtRules, DataType, Properties as Properties$1, Property, PropertyValue, Pseudos, SimplePseudos } from "csstype";
|
|
2
|
+
declare namespace css_d_exports {
|
|
3
|
+
export { AdvancedPseudos, AtRule, AtRules, DataType, ExpandedPseudos, Properties, Property, PropertyValue, Pseudos, Rules, SimplePseudos };
|
|
4
|
+
}
|
|
5
|
+
type Expand<T, TKey extends string | number | symbol = string, TValue = any> = T & Record<TKey, TValue>;
|
|
6
|
+
declare module 'csstype' {
|
|
7
|
+
interface Properties<TLength, TTime> {
|
|
8
|
+
[key: string]: string | number | Properties<TLength, TTime>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
type Properties = Properties$1<string>;
|
|
12
|
+
type Rules = Record<string, Properties>;
|
|
13
|
+
type ExpandedPseudos = Expand<Partial<Record<Pseudos, Properties>>, string, Properties>;
|
|
14
|
+
type FontSize = string | [string, string | {
|
|
15
|
+
lineHeight?: string;
|
|
16
|
+
letterSpacing?: string;
|
|
17
|
+
fontWeight?: string;
|
|
18
|
+
}];
|
|
19
|
+
interface ThemeProvider {
|
|
20
|
+
colors(): Record<string, string>;
|
|
21
|
+
colors(name: string): string | Record<string, string>;
|
|
22
|
+
spacing(name: string): string;
|
|
23
|
+
fontSize(name: string): FontSize;
|
|
24
|
+
applyTextColor(value: string, target: Properties, alpha?: string): void;
|
|
25
|
+
applyBackgroundColor(value: string, target: Properties, alpha?: string): void;
|
|
26
|
+
applyBorderColor(value: string, target: Properties, alpha?: string): void;
|
|
27
|
+
colorValue(value: string, alpha?: number | string): string;
|
|
28
|
+
/** Converts a color to the form `colors()` returns them in. Left out, a color is used as it is written. */
|
|
29
|
+
toColor?(value: string): string;
|
|
30
|
+
}
|
|
31
|
+
type VariantVars = Record<CSSVarName<'v'>, string>;
|
|
32
|
+
type VariantPropValue = CSSVarValue<'c'> | CSSVarValue<'v'>;
|
|
33
|
+
type OpacityValue = '1' | '0' | `0.${number}`;
|
|
34
|
+
interface VariantProperties {
|
|
35
|
+
'bg': VariantPropValue;
|
|
36
|
+
'bg-soft'?: VariantPropValue;
|
|
37
|
+
'bg-muted'?: VariantPropValue;
|
|
38
|
+
'bg-accent'?: VariantPropValue;
|
|
39
|
+
'bg-opacity'?: OpacityValue;
|
|
40
|
+
'border': VariantPropValue;
|
|
41
|
+
'border-soft'?: VariantPropValue;
|
|
42
|
+
'border-muted'?: VariantPropValue;
|
|
43
|
+
'border-accent'?: VariantPropValue;
|
|
44
|
+
'border-opacity'?: OpacityValue;
|
|
45
|
+
'fg': VariantPropValue;
|
|
46
|
+
'fg-soft'?: VariantPropValue;
|
|
47
|
+
'fg-muted'?: VariantPropValue;
|
|
48
|
+
'fg-accent'?: VariantPropValue;
|
|
49
|
+
'fg-opacity'?: OpacityValue;
|
|
50
|
+
}
|
|
51
|
+
type VariantPseudos = Partial<Record<SimplePseudos, Partial<VariantProperties>>>;
|
|
52
|
+
interface Variant extends VariantProperties {
|
|
53
|
+
pseudos?: VariantPseudos;
|
|
54
|
+
dark?: Omit<Partial<Variant>, 'dark' | 'colors'>;
|
|
55
|
+
/** Values of the variant for some colors, by color name; `'amber,lime'` names several. */
|
|
56
|
+
colors?: Record<string, VariantOverride>;
|
|
57
|
+
}
|
|
58
|
+
type WithShades<T> = { [K in keyof T]?: NonNullable<T[K]> extends string ? T[K] | ExColorShade : WithShades<NonNullable<T[K]>>; };
|
|
59
|
+
/**
|
|
60
|
+
* Any values of a variant, `pseudos` and `dark` included, for some colors. A value is a reference or a shade of the
|
|
61
|
+
* color: `'700'`, `'accent-600'`, `'white'`.
|
|
62
|
+
*/
|
|
63
|
+
type VariantOverride = WithShades<Omit<Variant, 'colors'>>;
|
|
64
|
+
type VariantProperty = keyof VariantProperties | `${keyof VariantProperties}-${SimplePseudos}`;
|
|
65
|
+
type ApplyVariantMainProp = 'bg' | 'border' | 'text';
|
|
66
|
+
type ApplyVariantSubProp = 'soft' | 'muted' | 'accent' | 'default';
|
|
67
|
+
type ApplyVariantProp = ApplyVariantMainProp | `${ApplyVariantMainProp}-${Exclude<ApplyVariantSubProp, 'default'>}`;
|
|
68
|
+
type ApplyVariant = boolean | ApplyVariantProp[];
|
|
69
|
+
type ApplyVariantPseudos = Partial<Record<SimplePseudos, ApplyVariant>> | SimplePseudos[] | false;
|
|
70
|
+
interface VariantCssVars extends VariantVars {
|
|
71
|
+
'@dark'?: VariantVars;
|
|
72
|
+
/** The rules of the `compound` override mode, such as `&.c-yellow` */
|
|
73
|
+
[compound: `&.${string}`]: VariantVars & {
|
|
74
|
+
'@dark'?: VariantVars;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Values by key: `bg` for a property, `bg-:hover` for its value in a state. */
|
|
78
|
+
type Values = Record<string, string>;
|
|
79
|
+
interface Flat {
|
|
80
|
+
light: Values;
|
|
81
|
+
dark: Values;
|
|
82
|
+
}
|
|
83
|
+
interface VariantContext {
|
|
84
|
+
apply(v?: ApplyVariant, pseudos?: ApplyVariantPseudos, target?: Properties): Properties;
|
|
85
|
+
/**
|
|
86
|
+
* Outside the `universal` scope, gives every bare `var()` read of a variant variable in `css` the default
|
|
87
|
+
* variant's value, light or dark, as its fallback.
|
|
88
|
+
*/
|
|
89
|
+
withFallback<T extends Properties>(css: T): T;
|
|
90
|
+
}
|
|
91
|
+
declare class VariantsGenerator extends VarsGeneratorBase<Variant, VariantCssVars> implements VariantContext {
|
|
92
|
+
private readonly scope;
|
|
93
|
+
private readonly mode;
|
|
94
|
+
protected readonly items: Map<string, Variant>;
|
|
95
|
+
/** Palettes given by CSS variables that also take their overrides from variables. */
|
|
96
|
+
private readonly aliases;
|
|
97
|
+
/** Whether a color is applied anywhere; the overrides of the others are left out. Set by `colors.only`. */
|
|
98
|
+
hasColor: (_color: string) => boolean;
|
|
99
|
+
constructor(ctx: BuilderContext, scope?: VariantScope, mode?: OverrideMode);
|
|
100
|
+
cssVars(name: string): VariantCssVars;
|
|
101
|
+
/**
|
|
102
|
+
* Sets values of a variant for some colors, over those they have.
|
|
103
|
+
* @param under keeps the values set before, so that a preset or a calibration never replaces an explicit override
|
|
104
|
+
*/
|
|
105
|
+
override(name: string, colors: string | string[], override: VariantOverride | ((ctx: BuilderContext) => VariantOverride), under?: boolean): void;
|
|
106
|
+
/** The colors that overrides name. */
|
|
107
|
+
overrideColors(): string[];
|
|
108
|
+
/** Makes the palette `color` take its overrides from `{vars}-{variant}-{prop}` variables, or with no `value` stops that. */
|
|
109
|
+
alias(color: string, value?: OverrideVars & {
|
|
110
|
+
vars: string;
|
|
111
|
+
}): void;
|
|
112
|
+
/**
|
|
113
|
+
* The override variables a `c-*` class sets: the values of `color`, and `initial` for the others, so that a color
|
|
114
|
+
* inside another one is not overridden by it. In dark mode it resets a light override where the variant has a dark
|
|
115
|
+
* value of its own. With `accent`, those of the `-accent` properties, for `c-accent-*`.
|
|
116
|
+
*/
|
|
117
|
+
colorVars(color: string, accent?: boolean): ColorCssVars;
|
|
118
|
+
private values;
|
|
119
|
+
/**
|
|
120
|
+
* The values of a variant, and its overrides by color: `statics` as configured, `entries` with what a palette given
|
|
121
|
+
* by variables forwards. `keys` get an override variable, which the colors of `varEntries` set.
|
|
122
|
+
*/
|
|
123
|
+
private resolved;
|
|
124
|
+
/** Every variable a variant can set, as `initial`: on a child it stops the parent's variant from inheriting. */
|
|
125
|
+
resetVars(): VariantVars;
|
|
126
|
+
utilCss(v: ApplyVariantMainProp, prop?: ApplyVariantSubProp, alpha?: string): Properties;
|
|
127
|
+
/**
|
|
128
|
+
* The CSS of `apply-v`: what `btn` gets, `bg`, `border` and `text` with `:hover`. `list` names props and states
|
|
129
|
+
* instead, such as `bg,text,focus-visible`: the props are applied at rest and in each state. Without props it is
|
|
130
|
+
* all three, without states `:hover`. A name it does not know gives `undefined`.
|
|
131
|
+
*/
|
|
132
|
+
applyCss(list?: string): Properties | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* The values of a variant on an element of `color`, its overrides applied as the `c-*` and `v-*` classes would
|
|
135
|
+
* resolve them. `dark` holds the values that change in dark mode.
|
|
136
|
+
*/
|
|
137
|
+
colorValues(name: string, color: string): Flat | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* The two switches a fallback picks its light or dark value with: `var(on-light, <light>) var(on-dark, <dark>)`.
|
|
140
|
+
* The one of the current mode is not set, so its fallback is used, and the other one is empty.
|
|
141
|
+
* They inherit, so a pseudo-element is in the mode of its element, which a dark selector nested in its rule cannot tell.
|
|
142
|
+
*/
|
|
143
|
+
modeVars(): {
|
|
144
|
+
light: VariantVars;
|
|
145
|
+
dark: VariantVars;
|
|
146
|
+
};
|
|
147
|
+
withFallback<T extends Properties>(css: T): T;
|
|
148
|
+
apply(v?: ApplyVariant, pseudos?: ApplyVariantPseudos, target?: Properties): Properties;
|
|
149
|
+
private vApplyProp;
|
|
150
|
+
}
|
|
151
|
+
type SizeVars = Record<CSSVarName<'s'>, string>;
|
|
152
|
+
type SizeProperty = 'text' | `spacing-${keyof Size['spacing']}` | 'line-height' | 'letter-spacing' | 'font-weight' | (string & {});
|
|
153
|
+
type Size = {
|
|
154
|
+
spacing: {
|
|
155
|
+
'1': string;
|
|
156
|
+
'1.5': string;
|
|
157
|
+
'2': string;
|
|
158
|
+
'3': string;
|
|
159
|
+
'4': string;
|
|
160
|
+
};
|
|
161
|
+
text: FontSize;
|
|
162
|
+
/** A key of your own: a string or a number is written to `--wui-s-<key>`, after the built-in variables. */
|
|
163
|
+
[key: string]: unknown;
|
|
164
|
+
};
|
|
165
|
+
declare class SizesGenerator extends VarsGeneratorBase<Size, SizeVars> {
|
|
166
|
+
protected readonly items: Map<string, Size>;
|
|
167
|
+
/** Whether `md` names the `default` size while no size of that name exists. Removing `md` ends it. */
|
|
168
|
+
private md;
|
|
169
|
+
constructor(ctx: BuilderContext);
|
|
170
|
+
private alias;
|
|
171
|
+
names(): string[];
|
|
172
|
+
update(name: string, builder: (element: Size, ctx: BuilderContext) => Size | void): void;
|
|
173
|
+
remove(name: string): void;
|
|
174
|
+
cssVars(name: string): SizeVars;
|
|
175
|
+
}
|
|
176
|
+
declare class ComponentsGenerator extends BuilderBase<IComponent, ComponentBuilderContext> {
|
|
177
|
+
protected readonly items: Map<string, IComponent>;
|
|
178
|
+
constructor(context: ComponentBuilderContext);
|
|
179
|
+
css(): Generator<Rules, void, unknown>;
|
|
180
|
+
}
|
|
181
|
+
type BuilderFunc<TFunc extends (...args: any) => void> = (...args: Parameters<TFunc>) => Builder;
|
|
182
|
+
interface Builder {
|
|
183
|
+
/** @param all also the palettes that `colors.only` leaves without a class */
|
|
184
|
+
colorsNames: (all?: boolean) => string[];
|
|
185
|
+
variantsNames: () => string[];
|
|
186
|
+
sizesNames: () => string[];
|
|
187
|
+
componentsNames: () => string[];
|
|
188
|
+
/** `options` are for the host: the generator itself has no use for them. */
|
|
189
|
+
addColor: (name: string, value: ColorValue, options?: ColorOptions) => Builder;
|
|
190
|
+
addVariant: BuilderFunc<VariantsGenerator['add']>;
|
|
191
|
+
addSize: BuilderFunc<SizesGenerator['add']>;
|
|
192
|
+
addComponent: BuilderFunc<ComponentsGenerator['add']>;
|
|
193
|
+
/** Adds a color, or replaces the one of that name. */
|
|
194
|
+
setColor: Builder['addColor'];
|
|
195
|
+
/** Adds a variant, or replaces the one of that name, `default` included. */
|
|
196
|
+
setVariant: BuilderFunc<VariantsGenerator['set']>;
|
|
197
|
+
setSize: BuilderFunc<SizesGenerator['set']>;
|
|
198
|
+
setComponent: BuilderFunc<ComponentsGenerator['set']>;
|
|
199
|
+
updateColor: BuilderFunc<ColorsGenerator['update']>;
|
|
200
|
+
updateVariant: BuilderFunc<VariantsGenerator['update']>;
|
|
201
|
+
updateSize: BuilderFunc<SizesGenerator['update']>;
|
|
202
|
+
updateComponent: BuilderFunc<ComponentsGenerator['update']>;
|
|
203
|
+
removeColor: BuilderFunc<ColorsGenerator['remove']>;
|
|
204
|
+
removeVariant: BuilderFunc<VariantsGenerator['remove']>;
|
|
205
|
+
removeSize: BuilderFunc<SizesGenerator['remove']>;
|
|
206
|
+
removeComponent: BuilderFunc<ComponentsGenerator['remove']>;
|
|
207
|
+
/** Sets values of a variant for one or more colors, over the overrides they have. */
|
|
208
|
+
overrideVariant: (variant: string, colors: string | string[], override: VariantOverride | ((ctx: BuilderContext) => VariantOverride)) => Builder;
|
|
209
|
+
}
|
|
210
|
+
interface PresetOptions {
|
|
211
|
+
/** Replaces an item of the same name that exists. Left out, the preset keeps that item and says so once. */
|
|
212
|
+
override?: boolean;
|
|
213
|
+
/** Namespaces the names of the items the preset adds: `nui` gives `nui-soft`. */
|
|
214
|
+
prefix?: string;
|
|
215
|
+
/** The names, without the prefix, of the items the preset adds or changes; the others are left out. */
|
|
216
|
+
only?: string[];
|
|
217
|
+
}
|
|
218
|
+
/** A named `build` function, which runs before the `build` of the config. */
|
|
219
|
+
interface Preset {
|
|
220
|
+
readonly name: string;
|
|
221
|
+
build(builder: Builder): void;
|
|
222
|
+
}
|
|
223
|
+
/** Makes a preset from a `build` function. The preset takes the options every preset takes: `override`, `prefix` and `only`. */
|
|
224
|
+
declare function definePreset(name: string, build: (builder: Builder) => void): ({ override, prefix, only }?: PresetOptions) => Preset;
|
|
225
|
+
declare const PRESETS: {
|
|
226
|
+
'nuxt-ui': ({ override, prefix, only }?: PresetOptions) => Preset;
|
|
227
|
+
};
|
|
228
|
+
/** A preset of WindiUI by name, with its default options, as a config file or an `@plugin` block gives it. */
|
|
229
|
+
type PresetName = keyof typeof PRESETS;
|
|
230
|
+
/**
|
|
231
|
+
* Where the default variant comes from for an element without a `v-*` class of its own:
|
|
232
|
+
* - `universal`: a `*` rule sets it on every element (the 0.7 behaviour);
|
|
233
|
+
* - `element`: a `var()` fallback where a variant value is read, and children of a `v-*` element are reset to it;
|
|
234
|
+
* - `inherit`: the fallback only, so a `v-*` element sets the variant for its content.
|
|
235
|
+
*/
|
|
236
|
+
type VariantScope = 'universal' | 'element' | 'inherit';
|
|
237
|
+
/**
|
|
238
|
+
* What dark mode follows. It takes what Tailwind's `darkMode` takes, or a bare selector such as `'.dark'`, which is
|
|
239
|
+
* the `selector` strategy with that selector.
|
|
240
|
+
*/
|
|
241
|
+
type DarkSelectorOption = 'media' | 'class' | 'selector' | ['class' | 'selector', string] | ['variant', string | string[]] | (string & {});
|
|
242
|
+
/**
|
|
243
|
+
* A palette of 11 shades: the name of a palette of the theme, CSS variables named `{vars}-{shade}`, or the shades
|
|
244
|
+
* themselves.
|
|
245
|
+
*/
|
|
246
|
+
type ColorValue = string | {
|
|
247
|
+
vars: string;
|
|
248
|
+
overrideVars?: OverrideVars;
|
|
249
|
+
} | Record<ColorShade, string>;
|
|
250
|
+
/**
|
|
251
|
+
* Which variant values a palette given by CSS variables also takes from variables, named
|
|
252
|
+
* `{vars}-{variant}-{prop}`, such as `--ui-color-primary-solid-bg-hover` for `bg-:hover`.
|
|
253
|
+
*/
|
|
254
|
+
interface OverrideVars {
|
|
255
|
+
/** Left out, every registered variant. */
|
|
256
|
+
variants?: string[];
|
|
257
|
+
/** `'calibrated'`, the default, is `bg`, `fg`, `border` and their `:hover` values; `'all'` is every value of the variant. */
|
|
258
|
+
props?: 'calibrated' | 'all' | VariantProperty[];
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* How a per-color override reaches the variant:
|
|
262
|
+
* - `vars`: the `c-*` class sets override variables that the `v-*` class reads, wherever the two classes are;
|
|
263
|
+
* - `compound`: a `.c-{color}.v-{variant}` rule, for both classes on one element;
|
|
264
|
+
* - `both`.
|
|
265
|
+
*/
|
|
266
|
+
type OverrideMode = 'vars' | 'compound' | 'both';
|
|
267
|
+
interface ColorOptions {
|
|
268
|
+
/**
|
|
269
|
+
* Also registers the palette as a color of the theme, for utilities such as `bg-{name}-{shade}`. This is up to the
|
|
270
|
+
* host; a palette name must then be one of the host's own palettes.
|
|
271
|
+
*/
|
|
272
|
+
utilities?: boolean;
|
|
273
|
+
}
|
|
274
|
+
interface ColorsConfig {
|
|
275
|
+
/**
|
|
276
|
+
* The palettes of the theme that get a `c-*` and a `c-accent-*` class; left out, all of them. Colors of the builder
|
|
277
|
+
* always get theirs, and the root variables of `default` and `accent` stay.
|
|
278
|
+
*/
|
|
279
|
+
only?: string[];
|
|
280
|
+
}
|
|
281
|
+
interface ResolvedConfig {
|
|
282
|
+
prefix: string;
|
|
283
|
+
/** Where the root color and size variables are declared. More selectors let a scoped theme resolve them again. */
|
|
284
|
+
rootSelector: string;
|
|
285
|
+
/** The palette behind `default`. Left out, it is a complete `default` palette of the theme, or else gray. */
|
|
286
|
+
default?: ColorValue;
|
|
287
|
+
/** The palette behind `accent`. Left out, it is a complete `accent` palette of the theme, or else blue. */
|
|
288
|
+
accent?: ColorValue;
|
|
289
|
+
colors?: ColorsConfig;
|
|
290
|
+
variantScope: VariantScope;
|
|
291
|
+
/** Per-color overrides of variants: `{ solid: { yellow: { bg: '700' }, 'amber,lime': { ... } } }`. */
|
|
292
|
+
overrides?: Record<string, Record<string, VariantOverride>>;
|
|
293
|
+
overrideMode: OverrideMode;
|
|
294
|
+
/**
|
|
295
|
+
* Color utilities from a variant: `{ bg: 'solid' }` gives `bg-{color}` the `solid` background of that color, its
|
|
296
|
+
* overrides and dark value included. Left out, there are none.
|
|
297
|
+
*/
|
|
298
|
+
variantUtilities?: Partial<Record<ApplyVariantMainProp, string>>;
|
|
299
|
+
/** Left out, dark mode follows Tailwind's own. */
|
|
300
|
+
darkSelector?: DarkSelectorOption;
|
|
301
|
+
/** Run in order, before `build`. */
|
|
302
|
+
presets: Preset[];
|
|
303
|
+
build?: (builder: Builder) => void;
|
|
304
|
+
/** Asks the host to emit every `c-*`, `v-*` and `s-*` class, also those it does not find in use. */
|
|
305
|
+
safelist: boolean;
|
|
306
|
+
/** Logs what is otherwise skipped silently, such as a theme palette without all 11 shades. */
|
|
307
|
+
debug: boolean;
|
|
308
|
+
}
|
|
309
|
+
type Config = Partial<Omit<ResolvedConfig, 'presets'>> & {
|
|
310
|
+
presets?: (Preset | PresetName)[];
|
|
311
|
+
};
|
|
312
|
+
/** Types a config object, so that one object can be shared by the plugin, a config file and other tools. */
|
|
313
|
+
declare function defineConfig(config: Config): Config;
|
|
314
|
+
type ColorShade = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | '950';
|
|
315
|
+
type ExColorShade = ColorShade | `default-${ColorShade}` | `accent-${ColorShade}` | 'black' | 'white';
|
|
316
|
+
type ColorVars = Record<CSSVarName<'c' | 'cv'>, string>;
|
|
317
|
+
interface ColorCssVars extends ColorVars {
|
|
318
|
+
'@dark'?: ColorVars;
|
|
319
|
+
}
|
|
320
|
+
interface ColorContext {
|
|
321
|
+
toValue(name: ExColorShade | (string & {}), alpha?: number | string): string;
|
|
322
|
+
}
|
|
323
|
+
declare class ColorsGenerator extends VarsGeneratorBase<Map<ColorShade, string>, ColorCssVars> implements ColorContext {
|
|
324
|
+
private readonly options;
|
|
325
|
+
private readonly variants;
|
|
326
|
+
private readonly colors;
|
|
327
|
+
protected readonly items: Map<string, Map<ColorShade, string>>;
|
|
328
|
+
/** The colors with a `c-*` class: `colors.only` and those of the builder. Left out, all of them. */
|
|
329
|
+
private readonly only?;
|
|
330
|
+
/** @param variants gives the override variables of each `c-*` class */
|
|
331
|
+
constructor(ctx: BuilderContext, options: Pick<Config, 'default' | 'accent' | 'colors' | 'debug'>, variants: VariantsGenerator);
|
|
332
|
+
/** The 11 shades of a palette given by name, by CSS variables or as the shades themselves. */
|
|
333
|
+
resolve(value: ColorValue): Map<ColorShade, string> | undefined;
|
|
334
|
+
addColor(name: string, value: ColorValue): void;
|
|
335
|
+
/** Adds a palette, or replaces the one of that name. */
|
|
336
|
+
setColor(name: string, value: ColorValue): void;
|
|
337
|
+
remove(name: string): void;
|
|
338
|
+
private alias;
|
|
339
|
+
/** @param all also the palettes that `colors.only` leaves without a class */
|
|
340
|
+
names(all?: boolean): string[];
|
|
341
|
+
/** The names of `colors.only` that are not palettes. */
|
|
342
|
+
unknownOnly(): string[];
|
|
343
|
+
cssVars(name: string): {
|
|
344
|
+
[x: `--${string}-c-${string}`]: string;
|
|
345
|
+
'@dark'?: ColorVars;
|
|
346
|
+
};
|
|
347
|
+
rootVars(): ColorCssVars;
|
|
348
|
+
/**
|
|
349
|
+
* `bg-{color}` and the like of `variantUtilities`: the value of `variant` for this color, overrides included, with
|
|
350
|
+
* its opacity unless `alpha` is given, light and dark. A shade is this palette's, not the element's `c-*` class.
|
|
351
|
+
*/
|
|
352
|
+
variantUtilCss(color: string, prop: ApplyVariantMainProp, variant: string, alpha?: string): Properties & {
|
|
353
|
+
'@dark'?: Properties;
|
|
354
|
+
};
|
|
355
|
+
toValue(name: ExColorShade | (string & {}), alpha?: number | string): string;
|
|
356
|
+
}
|
|
357
|
+
type VarType = 'c' | 'v' | 's' | 'cv';
|
|
358
|
+
type VarName<T extends VarType = VarType> = `${T}-${string}`;
|
|
359
|
+
type CSSVarName<T extends VarType = VarType> = `--${string}-${VarName<T>}`;
|
|
360
|
+
type CSSVarValue<T extends VarType = VarType> = `var(${CSSVarName<T>})`;
|
|
361
|
+
interface VarsProvider {
|
|
362
|
+
c(n: string): CSSVarName<'c'>;
|
|
363
|
+
v(n: string): CSSVarName<'v'>;
|
|
364
|
+
s(n: string): CSSVarName<'s'>;
|
|
365
|
+
/** An override variable, such as `cv('solid-bg')`: a `c-*` class sets it and the `v-*` class reads it. */
|
|
366
|
+
cv(n: string): CSSVarName<'cv'>;
|
|
367
|
+
color: {
|
|
368
|
+
(name: ExColorShade, fallback?: string): CSSVarValue<'c'>;
|
|
369
|
+
default(name: ColorShade, fallback?: string): CSSVarValue<'c'>;
|
|
370
|
+
accent(name: ColorShade, fallback?: string): CSSVarValue<'c'>;
|
|
371
|
+
};
|
|
372
|
+
size(name: SizeProperty, fallback?: string): CSSVarValue<'s'>;
|
|
373
|
+
/** `{ fallback: true }` falls back to the light value of the built-in default variant. */
|
|
374
|
+
variant(name: VariantProperty, fallback?: string | {
|
|
375
|
+
fallback: true;
|
|
376
|
+
}): CSSVarValue<'v'>;
|
|
377
|
+
}
|
|
378
|
+
declare function varsProvider(prefix: string): VarsProvider;
|
|
379
|
+
interface BuilderContext {
|
|
380
|
+
readonly vars: VarsProvider;
|
|
381
|
+
readonly theme: ThemeProvider;
|
|
382
|
+
}
|
|
383
|
+
declare abstract class BuilderBase<T, TContext extends BuilderContext> {
|
|
384
|
+
protected readonly ctx: TContext;
|
|
385
|
+
protected abstract readonly items: Map<string, T>;
|
|
386
|
+
constructor(ctx: TContext);
|
|
387
|
+
protected get vars(): VarsProvider;
|
|
388
|
+
protected get theme(): ThemeProvider;
|
|
389
|
+
names(): string[];
|
|
390
|
+
add(name: string, builder: (ctx: TContext) => T): void;
|
|
391
|
+
/** Adds an item, or replaces the one of that name, `default` included. */
|
|
392
|
+
set(name: string, builder: (ctx: TContext) => T): void;
|
|
393
|
+
update(name: string, builder: (element: T, ctx: TContext) => T | void): void;
|
|
394
|
+
remove(name: string): void;
|
|
395
|
+
}
|
|
396
|
+
declare abstract class VarsGeneratorBase<T, TVars, TContext extends BuilderContext = BuilderContext> extends BuilderBase<T, TContext> {
|
|
397
|
+
constructor(ctx: TContext);
|
|
398
|
+
add(name: string, builder: (ctx: TContext) => T): void;
|
|
399
|
+
remove(name: string): void;
|
|
400
|
+
abstract cssVars(name: string): TVars;
|
|
401
|
+
rootVars(): TVars;
|
|
402
|
+
}
|
|
403
|
+
interface ComponentBuilderContext extends BuilderContext {
|
|
404
|
+
readonly colors: ColorContext;
|
|
405
|
+
readonly variants: VariantContext;
|
|
406
|
+
}
|
|
407
|
+
type ComponentBuilder = (context: ComponentBuilderContext) => IComponent;
|
|
408
|
+
interface IComponent {
|
|
409
|
+
name: string;
|
|
410
|
+
style: Properties;
|
|
411
|
+
pseudos?: ExpandedPseudos;
|
|
412
|
+
applyVariant?: ApplyVariant;
|
|
413
|
+
applyVariantPseudos?: ApplyVariantPseudos;
|
|
414
|
+
}
|
|
415
|
+
export { ApplyVariantProp as A, Builder as C, SizesGenerator as D, SizeProperty as E, VariantsGenerator as F, FontSize as I, ThemeProvider as L, Variant as M, VariantOverride as N, ApplyVariant as O, VariantProperties as P, css_d_exports as R, definePreset as S, Size as T, ResolvedConfig as _, varsProvider as a, Preset as b, ExColorShade as c, ColorsConfig as d, Config as f, PresetName as g, OverrideVars as h, VarsProvider as i, ApplyVariantSubProp as j, ApplyVariantMainProp as k, ColorOptions as l, OverrideMode as m, ComponentBuilderContext as n, ColorShade as o, DarkSelectorOption as p, IComponent as r, ColorsGenerator as s, ComponentBuilder as t, ColorValue as u, VariantScope as v, ComponentsGenerator as w, PresetOptions as x, defineConfig as y };
|