import * as CSS from 'csstype'; import { ApplyStyles, Breakpoints, CSSObject, Mixins, SxConfig, ThemeOptions, Transitions } from '@mui/system'; import type { SizeTokens } from './tokens/size'; import type { ViewportTokens } from './tokens/viewport'; import type { NovaPalette } from './tokens/theme'; import type { NovaTypography } from './tokens/typography'; /** * Remove properties `K` from `T`. * Distributive for union types. * * @internal */ export type DistributiveOmit = T extends any ? Omit : never; /** * Generate a set of string literal types with the given default record `T` and * override record `U`. * * If the property value was `true`, the property key will be added to the * string union. * * @internal */ export type OverridableStringUnion = GenerateStringUnion, U>>; /** * Like `T & U`, but using the value types from `U` where their properties overlap. * * @internal */ export type Overwrite = DistributiveOmit & U; type GenerateStringUnion = Extract<{ [Key in keyof T]: true extends T[Key] ? Key : never; }[keyof T], string>; /** * default MD color-schemes */ export type DefaultColorScheme = 'light' | 'dark'; export interface ColorSchemeOverrides { } export type ExtendedColorScheme = OverridableStringUnion; /** * default MD color-schemes */ export type SupportedColorScheme = DefaultColorScheme | ExtendedColorScheme; export interface CssVarsThemeOptions extends Omit { /** * @default 'light' */ defaultColorScheme?: SupportedColorScheme; /** * Prefix of the generated CSS variables * @default 'nova' */ cssVarPrefix?: string; /** * Color schemes configuration */ colorSchemes?: Partial>; /** * The strategy to generate CSS variables * * @example 'media' * Generate CSS variables using [prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme) * * @example '.mode-%s' * Generate CSS variables within a class .mode-light, .mode-dark * * @example '[data-mode-%s]' * Generate CSS variables within a data attribute [data-mode-light], [data-mode-dark] */ colorSchemeSelector?: 'media' | 'class' | 'data' | string; /** * The selector to generate the global CSS variables (non-color-scheme related) * @default ':root' * @example ':host' // (for shadow DOM) * @see https://mui.com/material-ui/customization/shadow-dom/#3-css-theme-variables-optional */ rootSelector?: string; /** * If `true`, the CSS color-scheme will not be set. * https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme * @default false */ disableCssColorScheme?: boolean; /** * A function to determine if the key, value should be attached as CSS Variable * `keys` is an array that represents the object path keys. * Ex, if the theme is { foo: { bar: 'var(--test)' } } * then, keys = ['foo', 'bar'] * value = 'var(--test)' */ shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean; } export interface ThemeVars extends NovaPigmentTheme { } export interface ColorSystem { palette: Theme['palette']; } type Split = K extends string | number ? { [k in K]: Exclude; } : never; type ConcatDeep = T extends Record ? keyof T extends string | number ? V extends string | number ? keyof T : keyof V extends string | number ? `${keyof T}-${ConcatDeep>}` : never : never : never; type NormalizeVars = ConcatDeep>; export type ThemeCssVar = OverridableStringUnion>>; export interface CssVarsTheme extends ColorSystem { colorSchemes: Partial>; rootSelector: string; colorSchemeSelector: 'media' | 'class' | 'data' | string; cssVarPrefix: string; defaultColorScheme: SupportedColorScheme; vars: ThemeVars; getCssVar: (field: ThemeCssVar, ...vars: ThemeCssVar[]) => string; getColorSchemeSelector: (colorScheme: SupportedColorScheme) => string; generateThemeVars: () => ThemeVars; generateStyleSheets: () => Array>; generateSpacing: () => Theme['spacing']; spacing: Theme['spacing']; breakpoints: Theme['breakpoints']; typography: Theme['typography']; shadows: Theme['shadows']; sys: Theme['sys']; /** * A function to determine if the key, value should be attached as CSS Variable * `keys` is an array that represents the object path keys. * Ex, if the theme is { foo: { bar: 'var(--test)' } } * then, keys = ['foo', 'bar'] * value = 'var(--test)' */ shouldSkipGeneratingVar: (keys: string[], value: string | number) => boolean; applyStyles: ApplyStyles; } export type NovaPigmentTheme = { palette: NovaPalette; shadows: ['none', string, string, string, string, string]; spacing: number; typography: NovaTypography & { fontFamily: string; }; sys: { size: SizeTokens; viewport: ViewportTokens; }; breakpoints: Breakpoints; }; type CssVarsProperties = Pick; export interface BaseTheme extends NovaPigmentTheme { mixins: Mixins; transitions: Transitions; } export interface CSSSelectorObjectOrCssVariables { [cssSelectorOrVariable: string]: ((theme: Theme) => SystemStyleObject | string | number) | SystemStyleObject | string | number; } export type CSSPseudoSelectorProps = { [K in CSS.Pseudos]?: ((theme: Theme) => SystemStyleObject) | SystemStyleObject; }; export type SystemStyleObject = React.CSSProperties | CSSPseudoSelectorProps | CSSSelectorObjectOrCssVariables | null; type SystemSxProps = SystemStyleObject | ((theme: Theme) => SystemStyleObject) | ReadonlyArray | ((theme: Theme) => SystemStyleObject)>; export type SxProps = SystemSxProps; export interface Theme extends NovaPigmentTheme, CssVarsProperties { cssVariables?: true; unstable_sx: (props: SxProps) => CSSObject; unstable_sxConfig: SxConfig; } export {};