UNPKG

@lithiumjs/ngx-material-theming

Version:

Dynamic and customizable Angular Material theming made easy.

117 lines (114 loc) 4.41 kB
type PaletteOffset = keyof ThemeCreator.PaletteBase; /** * @param name The name that will be used to reference the new theme. * @param templateData The CSS theme template that will be used to create the final theme data. * @param primaryPalette The primary color palette. * @param accentPalette The accent color palette. * @param warnPalette The warn color palette. */ interface TemplateThemeCreationOptions { name: string; templateData: string; primaryPalette: ThemeCreator.Palette; accentPalette: ThemeCreator.Palette; warnPalette: ThemeCreator.Palette; templateOptions?: Partial<ThemeTemplateOptions>; } interface ThemeTemplateOptions { nameMatcher: string | RegExp; primaryHexMatcher: string | RegExp; primaryRgbaMatcher: string | RegExp; accentHexMatcher: string | RegExp; accentRgbaMatcher: string | RegExp; warnHexMatcher: string | RegExp; warnRgbaMatcher: string | RegExp; primaryContrastHexMatcher: string | RegExp; primaryContrastRgbaMatcher: string | RegExp; accentContrastHexMatcher: string | RegExp; accentContrastRgbaMatcher: string | RegExp; warnContrastHexMatcher: string | RegExp; warnContrastRgbaMatcher: string | RegExp; } declare namespace ThemeTemplateOptions { const defaultValues: Readonly<ThemeTemplateOptions>; } declare class ThemeCreator { /** * @description Creates a new theme from the given template theme CSS and theme palettes and loads it for use with the given name. * @param options The options to use to create the new theme. * @return The compiled theme CSS. */ static createFromTemplate(options: TemplateThemeCreationOptions): string; private static substituteThemeHex; private static substituteThemeRgba; /** @description Compute the palette offset from an associated hex color regex match. */ private static hexOffset; /** @description Compute the palette offset from an associated rgba color regex match. */ private static rgbaOffset; /** @description Compute the alpha channel from an associated rgba alpha regex match. */ private static rgbaAlpha; } declare namespace ThemeCreator { interface PaletteBase { "50": string; "100": string; "200": string; "300": string; "400": string; "500": string; "600": string; "700": string; "800": string; "900": string; "A100": string; "A200": string; "A400": string; "A700": string; } interface Palette extends PaletteBase { contrast: PaletteBase; } } /** * @param isDark Whether or not the theme should be a dark theme. Defaults to `false`. * @see TemplateThemeCreationOptions */ interface ThemeCreationOptions extends Omit<TemplateThemeCreationOptions, "templateData" | "templateOptions"> { isDark?: boolean; } declare class ThemeGenerator { /** * @see ThemeCreator.createFromTemplate */ static createFromTemplate(options: TemplateThemeCreationOptions): string; /** * @description Creates a new theme from the given theme palettes and loads it for use with the given name. * @param options The options to use to create the new theme. * @return The compiled theme. */ static create(options: ThemeCreationOptions): string; /** * @description Computes a Material color palette for the given `baseColor`. * @param baseColor The color that the palette will be based off of. * @requires chroma-js */ static createPalette(baseColor: string): ThemeCreator.Palette; /** * @description Computes a color for a Material theme palette using `baseColor` and the given `paletteOffset`. * @param baseColor The base color. * @param paletteOffset The offset in the palette. * @return The new color to be used for the given palette offset. * @requires chroma-js */ static paletteColor(baseColor: string, paletteOffset: PaletteOffset): string; /** * @description Computes an appropriate contrast color (either black or white) that contrasts the given `color`. * @param color The color to be contrasted. * @return The contrast color. * @requires chroma-js */ static contrastColor(color: string): string; private static loadStandardThemeTemplate; } export { ThemeGenerator }; export type { ThemeCreationOptions };