@windi-ui/core 0.8.0-beta.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,6 +40,8 @@ declare abstract class BuilderBase<T, TContext extends BuilderContext> {
40
40
  protected get theme(): ThemeProvider;
41
41
  names(): string[];
42
42
  add(name: string, builder: (ctx: TContext) => T): void;
43
+ /** Adds an item, or replaces the one of that name, `default` included. */
44
+ set(name: string, builder: (ctx: TContext) => T): void;
43
45
  update(name: string, builder: (element: T, ctx: TContext) => T | void): void;
44
46
  remove(name: string): void;
45
47
  }
@@ -73,8 +75,16 @@ interface VariantProperties {
73
75
  type VariantPseudos = Partial<Record<SimplePseudos, Partial<VariantProperties>>>;
74
76
  interface Variant extends VariantProperties {
75
77
  pseudos?: VariantPseudos;
76
- dark?: Omit<Partial<Variant>, 'dark'>;
78
+ dark?: Omit<Partial<Variant>, 'dark' | 'colors'>;
79
+ /** Values of the variant for some colors, by color name; `'amber,lime'` names several. */
80
+ colors?: Record<string, VariantOverride>;
77
81
  }
82
+ type WithShades<T> = { [K in keyof T]?: NonNullable<T[K]> extends string ? T[K] | ExColorShade : WithShades<NonNullable<T[K]>>; };
83
+ /**
84
+ * Any values of a variant, `pseudos` and `dark` included, for some colors. A value is a reference or a shade of the
85
+ * color: `'700'`, `'accent-600'`, `'white'`.
86
+ */
87
+ type VariantOverride = WithShades<Omit<Variant, 'colors'>>;
78
88
  type VariantProperty = keyof VariantProperties | `${keyof VariantProperties}-${SimplePseudos}`;
79
89
  type ApplyVariantMainProp = 'bg' | 'border' | 'text';
80
90
  type ApplyVariantSubProp = 'soft' | 'muted' | 'accent' | 'default';
@@ -83,6 +93,16 @@ type ApplyVariant = boolean | ApplyVariantProp[];
83
93
  type ApplyVariantPseudos = Partial<Record<SimplePseudos, ApplyVariant>> | SimplePseudos[] | false;
84
94
  interface VariantCssVars extends VariantVars {
85
95
  '@dark'?: VariantVars;
96
+ /** The rules of the `compound` override mode, such as `&.c-yellow` */
97
+ [compound: `&.${string}`]: VariantVars & {
98
+ '@dark'?: VariantVars;
99
+ };
100
+ }
101
+ /** Values by key: `bg` for a property, `bg-:hover` for its value in a state. */
102
+ type Values = Record<string, string>;
103
+ interface Flat {
104
+ light: Values;
105
+ dark: Values;
86
106
  }
87
107
  interface VariantContext {
88
108
  apply(v?: ApplyVariant, pseudos?: ApplyVariantPseudos, target?: Properties): Properties;
@@ -94,12 +114,51 @@ interface VariantContext {
94
114
  }
95
115
  declare class VariantsGenerator extends VarsGeneratorBase<Variant, VariantCssVars> implements VariantContext {
96
116
  private readonly scope;
117
+ private readonly mode;
97
118
  protected readonly items: Map<string, Variant>;
98
- constructor(ctx: BuilderContext, scope?: VariantScope);
119
+ /** Palettes given by CSS variables that also take their overrides from variables. */
120
+ private readonly aliases;
121
+ /** Whether a color is applied anywhere; the overrides of the others are left out. Set by `colors.only`. */
122
+ hasColor: (_color: string) => boolean;
123
+ constructor(ctx: BuilderContext, scope?: VariantScope, mode?: OverrideMode);
99
124
  cssVars(name: string): VariantCssVars;
125
+ /**
126
+ * Sets values of a variant for some colors, over those they have.
127
+ * @param under keeps the values set before, so that a preset or a calibration never replaces an explicit override
128
+ */
129
+ override(name: string, colors: string | string[], override: VariantOverride | ((ctx: BuilderContext) => VariantOverride), under?: boolean): void;
130
+ /** The colors that overrides name. */
131
+ overrideColors(): string[];
132
+ /** Makes the palette `color` take its overrides from `{vars}-{variant}-{prop}` variables, or with no `value` stops that. */
133
+ alias(color: string, value?: OverrideVars & {
134
+ vars: string;
135
+ }): void;
136
+ /**
137
+ * The override variables a `c-*` class sets: the values of `color`, and `initial` for the others, so that a color
138
+ * inside another one is not overridden by it. In dark mode it resets a light override where the variant has a dark
139
+ * value of its own. With `accent`, those of the `-accent` properties, for `c-accent-*`.
140
+ */
141
+ colorVars(color: string, accent?: boolean): ColorCssVars;
142
+ private values;
143
+ /**
144
+ * The values of a variant, and its overrides by color: `statics` as configured, `entries` with what a palette given
145
+ * by variables forwards. `keys` get an override variable, which the colors of `varEntries` set.
146
+ */
147
+ private resolved;
100
148
  /** Every variable a variant can set, as `initial`: on a child it stops the parent's variant from inheriting. */
101
149
  resetVars(): VariantVars;
102
150
  utilCss(v: ApplyVariantMainProp, prop?: ApplyVariantSubProp, alpha?: string): Properties;
151
+ /**
152
+ * The CSS of `apply-v`: what `btn` gets, `bg`, `border` and `text` with `:hover`. `list` names props and states
153
+ * instead, such as `bg,text,focus-visible`: the props are applied at rest and in each state. Without props it is
154
+ * all three, without states `:hover`. A name it does not know gives `undefined`.
155
+ */
156
+ applyCss(list?: string): Properties | undefined;
157
+ /**
158
+ * The values of a variant on an element of `color`, its overrides applied as the `c-*` and `v-*` classes would
159
+ * resolve them. `dark` holds the values that change in dark mode.
160
+ */
161
+ colorValues(name: string, color: string): Flat | undefined;
103
162
  /**
104
163
  * The two switches a fallback picks its light or dark value with: `var(on-light, <light>) var(on-dark, <dark>)`.
105
164
  * The one of the current mode is not set, so its fallback is used, and the other one is empty.
@@ -114,7 +173,7 @@ declare class VariantsGenerator extends VarsGeneratorBase<Variant, VariantCssVar
114
173
  private vApplyProp;
115
174
  }
116
175
  type SizeVars = Record<CSSVarName<'s'>, string>;
117
- type SizeProperty = 'text' | `spacing-${keyof Size['spacing']}` | 'line-height';
176
+ type SizeProperty = 'text' | `spacing-${keyof Size['spacing']}` | 'line-height' | 'letter-spacing' | 'font-weight' | (string & {});
118
177
  type Size = {
119
178
  spacing: {
120
179
  '1': string;
@@ -124,10 +183,18 @@ type Size = {
124
183
  '4': string;
125
184
  };
126
185
  text: FontSize;
186
+ /** A key of your own: a string or a number is written to `--wui-s-<key>`, after the built-in variables. */
187
+ [key: string]: unknown;
127
188
  };
128
189
  declare class SizesGenerator extends VarsGeneratorBase<Size, SizeVars> {
129
190
  protected readonly items: Map<string, Size>;
191
+ /** Whether `md` names the `default` size while no size of that name exists. Removing `md` ends it. */
192
+ private md;
130
193
  constructor(ctx: BuilderContext);
194
+ private alias;
195
+ names(): string[];
196
+ update(name: string, builder: (element: Size, ctx: BuilderContext) => Size | void): void;
197
+ remove(name: string): void;
131
198
  cssVars(name: string): SizeVars;
132
199
  }
133
200
  interface ComponentBuilderContext extends BuilderContext {
@@ -149,7 +216,8 @@ declare class ComponentsGenerator extends BuilderBase<IComponent, ComponentBuild
149
216
  }
150
217
  type BuilderFunc<TFunc extends (...args: any) => void> = (...args: Parameters<TFunc>) => Builder;
151
218
  interface Builder {
152
- colorsNames: () => string[];
219
+ /** @param all also the palettes that `colors.only` leaves without a class */
220
+ colorsNames: (all?: boolean) => string[];
153
221
  variantsNames: () => string[];
154
222
  sizesNames: () => string[];
155
223
  componentsNames: () => string[];
@@ -160,6 +228,10 @@ interface Builder {
160
228
  addComponent: BuilderFunc<ComponentsGenerator['add']>;
161
229
  /** Adds a color, or replaces the one of that name. */
162
230
  setColor: Builder['addColor'];
231
+ /** Adds a variant, or replaces the one of that name, `default` included. */
232
+ setVariant: BuilderFunc<VariantsGenerator['set']>;
233
+ setSize: BuilderFunc<SizesGenerator['set']>;
234
+ setComponent: BuilderFunc<ComponentsGenerator['set']>;
163
235
  updateColor: BuilderFunc<ColorsGenerator['update']>;
164
236
  updateVariant: BuilderFunc<VariantsGenerator['update']>;
165
237
  updateSize: BuilderFunc<SizesGenerator['update']>;
@@ -168,7 +240,29 @@ interface Builder {
168
240
  removeVariant: BuilderFunc<VariantsGenerator['remove']>;
169
241
  removeSize: BuilderFunc<SizesGenerator['remove']>;
170
242
  removeComponent: BuilderFunc<ComponentsGenerator['remove']>;
243
+ /** Sets values of a variant for one or more colors, over the overrides they have. */
244
+ overrideVariant: (variant: string, colors: string | string[], override: VariantOverride | ((ctx: BuilderContext) => VariantOverride)) => Builder;
245
+ }
246
+ interface PresetOptions {
247
+ /** Replaces an item of the same name that exists. Left out, the preset keeps that item and says so once. */
248
+ override?: boolean;
249
+ /** Namespaces the names of the items the preset adds: `nui` gives `nui-soft`. */
250
+ prefix?: string;
251
+ /** The names, without the prefix, of the items the preset adds or changes; the others are left out. */
252
+ only?: string[];
171
253
  }
254
+ /** A named `build` function, which runs before the `build` of the config. */
255
+ interface Preset {
256
+ readonly name: string;
257
+ build(builder: Builder): void;
258
+ }
259
+ /** Makes a preset from a `build` function. The preset takes the options every preset takes: `override`, `prefix` and `only`. */
260
+ declare function definePreset(name: string, build: (builder: Builder) => void): ({ override, prefix, only }?: PresetOptions) => Preset;
261
+ declare const PRESETS: {
262
+ 'nuxt-ui': ({ override, prefix, only }?: PresetOptions) => Preset;
263
+ };
264
+ /** A preset of WindiUI by name, with its default options, as a config file or an `@plugin` block gives it. */
265
+ type PresetName = keyof typeof PRESETS;
172
266
  /**
173
267
  * Where the default variant comes from for an element without a `v-*` class of its own:
174
268
  * - `universal`: a `*` rule sets it on every element (the 0.7 behaviour);
@@ -187,7 +281,25 @@ type DarkSelectorOption = 'media' | 'class' | 'selector' | ['class' | 'selector'
187
281
  */
188
282
  type ColorValue = string | {
189
283
  vars: string;
284
+ overrideVars?: OverrideVars;
190
285
  } | Record<ColorShade, string>;
286
+ /**
287
+ * Which variant values a palette given by CSS variables also takes from variables, named
288
+ * `{vars}-{variant}-{prop}`, such as `--ui-color-primary-solid-bg-hover` for `bg-:hover`.
289
+ */
290
+ interface OverrideVars {
291
+ /** Left out, every registered variant. */
292
+ variants?: string[];
293
+ /** `'calibrated'`, the default, is `bg`, `fg`, `border` and their `:hover` values; `'all'` is every value of the variant. */
294
+ props?: 'calibrated' | 'all' | VariantProperty[];
295
+ }
296
+ /**
297
+ * How a per-color override reaches the variant:
298
+ * - `vars`: the `c-*` class sets override variables that the `v-*` class reads, wherever the two classes are;
299
+ * - `compound`: a `.c-{color}.v-{variant}` rule, for both classes on one element;
300
+ * - `both`.
301
+ */
302
+ type OverrideMode = 'vars' | 'compound' | 'both';
191
303
  interface ColorOptions {
192
304
  /**
193
305
  * Also registers the palette as a color of the theme, for utilities such as `bg-{name}-{shade}`. This is up to the
@@ -195,6 +307,13 @@ interface ColorOptions {
195
307
  */
196
308
  utilities?: boolean;
197
309
  }
310
+ interface ColorsConfig {
311
+ /**
312
+ * The palettes of the theme that get a `c-*` and a `c-accent-*` class; left out, all of them. Colors of the builder
313
+ * always get theirs, and the root variables of `default` and `accent` stay.
314
+ */
315
+ only?: string[];
316
+ }
198
317
  interface ResolvedConfig {
199
318
  prefix: string;
200
319
  /** Where the root color and size variables are declared. More selectors let a scoped theme resolve them again. */
@@ -203,39 +322,75 @@ interface ResolvedConfig {
203
322
  default?: ColorValue;
204
323
  /** The palette behind `accent`. Left out, it is a complete `accent` palette of the theme, or else blue. */
205
324
  accent?: ColorValue;
325
+ colors?: ColorsConfig;
206
326
  variantScope: VariantScope;
327
+ /** Per-color overrides of variants: `{ solid: { yellow: { bg: '700' }, 'amber,lime': { ... } } }`. */
328
+ overrides?: Record<string, Record<string, VariantOverride>>;
329
+ overrideMode: OverrideMode;
330
+ /**
331
+ * Color utilities from a variant: `{ bg: 'solid' }` gives `bg-{color}` the `solid` background of that color, its
332
+ * overrides and dark value included. Left out, there are none.
333
+ */
334
+ variantUtilities?: Partial<Record<ApplyVariantMainProp, string>>;
207
335
  /** Left out, dark mode follows Tailwind's own. */
208
336
  darkSelector?: DarkSelectorOption;
337
+ /** Run in order, before `build`. */
338
+ presets: Preset[];
209
339
  build?: (builder: Builder) => void;
210
340
  /** Asks the host to emit every `c-*`, `v-*` and `s-*` class, also those it does not find in use. */
211
341
  safelist: boolean;
212
342
  /** Logs what is otherwise skipped silently, such as a theme palette without all 11 shades. */
213
343
  debug: boolean;
214
344
  }
215
- type Config = Partial<ResolvedConfig>;
345
+ type Config = Partial<Omit<ResolvedConfig, 'presets'>> & {
346
+ presets?: (Preset | PresetName)[];
347
+ };
216
348
  /** Types a config object, so that one object can be shared by the plugin, a config file and other tools. */
217
349
  declare function defineConfig(config: Config): Config;
218
350
  type ColorShade = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | '950';
219
351
  type ExColorShade = ColorShade | `default-${ColorShade}` | `accent-${ColorShade}` | 'black' | 'white';
220
- type ColorVars = Record<CSSVarName<'c'>, string>;
352
+ type ColorVars = Record<CSSVarName<'c' | 'cv'>, string>;
353
+ interface ColorCssVars extends ColorVars {
354
+ '@dark'?: ColorVars;
355
+ }
221
356
  interface ColorContext {
222
357
  toValue(name: ExColorShade | (string & {}), alpha?: number | string): string;
223
358
  }
224
- declare class ColorsGenerator extends VarsGeneratorBase<Map<ColorShade, string>, ColorVars> implements ColorContext {
359
+ declare class ColorsGenerator extends VarsGeneratorBase<Map<ColorShade, string>, ColorCssVars> implements ColorContext {
360
+ private readonly options;
361
+ private readonly variants;
225
362
  private readonly colors;
226
363
  protected readonly items: Map<string, Map<ColorShade, string>>;
227
- constructor(ctx: BuilderContext, options?: Pick<Config, 'default' | 'accent' | 'debug'>);
364
+ /** The colors with a `c-*` class: `colors.only` and those of the builder. Left out, all of them. */
365
+ private readonly only?;
366
+ /** @param variants gives the override variables of each `c-*` class */
367
+ constructor(ctx: BuilderContext, options: Pick<Config, 'default' | 'accent' | 'colors' | 'debug'>, variants: VariantsGenerator);
228
368
  /** The 11 shades of a palette given by name, by CSS variables or as the shades themselves. */
229
369
  resolve(value: ColorValue): Map<ColorShade, string> | undefined;
230
370
  addColor(name: string, value: ColorValue): void;
231
371
  /** Adds a palette, or replaces the one of that name. */
232
372
  setColor(name: string, value: ColorValue): void;
233
- names(): string[];
234
- cssVars(name: string): Record<`--${string}-c-${string}`, string>;
235
- rootVars(): ColorVars;
373
+ remove(name: string): void;
374
+ private alias;
375
+ /** @param all also the palettes that `colors.only` leaves without a class */
376
+ names(all?: boolean): string[];
377
+ /** The names of `colors.only` that are not palettes. */
378
+ unknownOnly(): string[];
379
+ cssVars(name: string): {
380
+ [x: `--${string}-c-${string}`]: string;
381
+ '@dark'?: ColorVars;
382
+ };
383
+ rootVars(): ColorCssVars;
384
+ /**
385
+ * `bg-{color}` and the like of `variantUtilities`: the value of `variant` for this color, overrides included, with
386
+ * its opacity unless `alpha` is given, light and dark. A shade is this palette's, not the element's `c-*` class.
387
+ */
388
+ variantUtilCss(color: string, prop: ApplyVariantMainProp, variant: string, alpha?: string): Properties & {
389
+ '@dark'?: Properties;
390
+ };
236
391
  toValue(name: ExColorShade | (string & {}), alpha?: number | string): string;
237
392
  }
238
- type VarType = 'c' | 'v' | 's';
393
+ type VarType = 'c' | 'v' | 's' | 'cv';
239
394
  type VarName<T extends VarType = VarType> = `${T}-${string}`;
240
395
  type CSSVarName<T extends VarType = VarType> = `--${string}-${VarName<T>}`;
241
396
  type CSSVarValue<T extends VarType = VarType> = `var(${CSSVarName<T>})`;
@@ -243,6 +398,8 @@ interface VarsProvider {
243
398
  c(n: string): CSSVarName<'c'>;
244
399
  v(n: string): CSSVarName<'v'>;
245
400
  s(n: string): CSSVarName<'s'>;
401
+ /** An override variable, such as `cv('solid-bg')`: a `c-*` class sets it and the `v-*` class reads it. */
402
+ cv(n: string): CSSVarName<'cv'>;
246
403
  color: {
247
404
  (name: ExColorShade, fallback?: string): CSSVarValue<'c'>;
248
405
  default(name: ColorShade, fallback?: string): CSSVarValue<'c'>;
@@ -255,4 +412,4 @@ interface VarsProvider {
255
412
  }): CSSVarValue<'v'>;
256
413
  }
257
414
  declare function varsProvider(prefix: string): VarsProvider;
258
- export { Variant as C, ThemeProvider as D, FontSize as E, css_d_exports as O, ApplyVariantSubProp as S, VariantsGenerator as T, IComponent as _, ExColorShade as a, ApplyVariantMainProp as b, Config as c, VariantScope as d, defineConfig as f, ComponentBuilderContext as g, ComponentBuilder as h, ColorsGenerator as i, DarkSelectorOption as l, ComponentsGenerator as m, varsProvider as n, ColorOptions as o, Builder as p, ColorShade as r, ColorValue as s, VarsProvider as t, ResolvedConfig as u, SizesGenerator as v, VariantProperties as w, ApplyVariantProp as x, ApplyVariant as y };
415
+ export { ApplyVariantProp as A, ComponentBuilderContext 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, ComponentBuilder as S, Size as T, Preset as _, ExColorShade as a, Builder as b, ColorsConfig as c, OverrideMode as d, OverrideVars as f, defineConfig as g, VariantScope as h, ColorsGenerator as i, ApplyVariantSubProp as j, ApplyVariantMainProp as k, Config as l, ResolvedConfig as m, varsProvider as n, ColorOptions as o, PresetName as p, ColorShade as r, ColorValue as s, VarsProvider as t, DarkSelectorOption as u, PresetOptions as v, IComponent as w, ComponentsGenerator as x, definePreset as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windi-ui/core",
3
- "version": "0.8.0-beta.1",
3
+ "version": "0.8.0",
4
4
  "license": "MIT",
5
5
  "author": "Waleed Khaled <https://github.com/Waleed-KH>",
6
6
  "description": "Modern, modular, and customizable UI component library",
@@ -28,6 +28,10 @@
28
28
  "import": "./dist/components.mjs",
29
29
  "require": "./dist/components.cjs"
30
30
  },
31
+ "./presets": {
32
+ "import": "./dist/presets.mjs",
33
+ "require": "./dist/presets.cjs"
34
+ },
31
35
  "./package.json": "./package.json"
32
36
  },
33
37
  "files": [