theme-vir
Version:
Create an entire web theme.
84 lines (83 loc) • 2.93 kB
TypeScript
import { type RequiredAndNotNull, type Values } from '@augment-vir/common';
import { CSSResult } from 'element-vir';
import { type CssVarName, type SingleCssVarDefinition } from 'lit-css-vars';
import { type RequireAtLeastOne } from 'type-fest';
import { type ColorInit, type ColorInitReference, type ColorInitValue, type ColorThemeInit } from './color-theme-init.js';
/**
* Same as {@link ColorInit} but without references.
*
* @category Internal
*/
export type NoRefColorInit = RequireAtLeastOne<{
foreground: Exclude<ColorInitValue, ColorInitReference>;
background: Exclude<ColorInitValue, ColorInitReference>;
}>;
/**
* A defined individual color from a color theme.
*
* @category Internal
*/
export type ColorThemeColor<Init extends ColorInit = ColorInit, Name extends CssVarName = CssVarName> = {
foreground: SingleCssVarDefinition;
background: SingleCssVarDefinition;
/**
* The name of this theme color within the theme itself. (This is not any of the CSS variable
* names.)
*/
name: Name;
init: Init;
};
/**
* A finalized color theme, output from {@link defineColorTheme}.
*
* @category Internal
*/
export type ColorTheme<Init extends ColorThemeInit = ColorThemeInit> = {
colors: AllColorThemeColors<Init>;
inverse: AllColorThemeColors<Init>;
/** The original init object for this theme. */
init: {
colors: Init;
default: Readonly<DefaultColorThemeInit>;
};
prefix: string;
};
/**
* All colors within a {@link ColorTheme}.
*
* @category Internal
*/
export type AllColorThemeColors<Init extends ColorThemeInit = ColorThemeInit> = {
[ColorName in keyof Init as ColorName extends CssVarName ? ColorName : never]: ColorName extends CssVarName ? Init[ColorName] extends ColorInit ? ColorThemeColor<Init[ColorName], ColorName> : never : never;
} & {
[themeDefaultKey]: ColorThemeColor<DefaultColorThemeInit, typeof themeDefaultKey>;
};
/** @category Internal */
export declare function noRefColorInitToString(init: Values<NoRefColorInit>): string;
/**
* Handles a color init value.
*
* @category Internal
*/
export declare function createColorCssVarDefault(fromName: string, init: ColorInitValue, defaultInit: Readonly<DefaultColorThemeInit>, colorsInit: ColorThemeInit): string | number | CSSResult;
/**
* Default theme init for {@link defineColorTheme}.
*
* @category Internal
*/
export type DefaultColorThemeInit = RequiredAndNotNull<NoRefColorInit> & {
prefix: string;
};
/**
* Default foreground/background color theme used in {@link ColorTheme}. Do not define a theme color
* with this name!
*
* @category Internal
*/
export declare const themeDefaultKey = "theme-default";
/**
* Define a color theme.
*
* @category Color Theme
*/
export declare function defineColorTheme<const Init extends ColorThemeInit>(defaultInit: Readonly<DefaultColorThemeInit>, allColorsInit: Init): ColorTheme<Init>;