UNPKG

@compositive/foundation

Version:

Compositive framework foundation package.

76 lines 3.42 kB
import type { NullablePartial } from "@compositive/commons-types"; import type { ColorPicker, ColorScale } from "../color"; import type { SurfaceSpec } from "../surfaces"; import type { Font, FontSpec } from "../typography"; export declare abstract class Theme<A extends Theme.Attributes, V extends Theme.Variants> { get allFonts(): Font[]; loadAllFonts(): Promise<void>; areFontsLoaded(): boolean; abstract using(activeVariants: NullablePartial<V>): Theme<A, V>; abstract get surfaces(): A["surfaces"]; abstract get typography(): A["typography"]; abstract get metrics(): A["metrics"]; abstract get palette(): A["palette"]; abstract get colorPicks(): A["colorPicks"]; abstract get variants(): Theme.VariantOptions<V>; } export declare type AnyTheme = Theme<Theme.Open<Theme.Attributes>, Theme.Variants>; export declare type UnknownTheme = Theme<Theme.Attributes, Theme.NoVariants>; declare type PartialRecord<T> = { readonly [x: string | symbol]: T | undefined; }; export declare namespace Theme { type Attributes = { readonly metrics: { readonly grid: number; }; readonly palette: { readonly primary: ColorScale; readonly neutral: ColorScale; readonly info: ColorScale; readonly danger: ColorScale; readonly success: ColorScale; readonly warning: ColorScale; }; readonly colorPicks: { readonly background: ColorPicker; readonly foreground: ColorPicker; }; readonly surfaces: { readonly default: SurfaceSpec; }; readonly typography: { readonly default: FontSpec; }; }; type Open<A extends Attributes> = { readonly metrics: A["metrics"]; readonly palette: A["palette"] & PartialRecord<ColorScale>; readonly colorPicks: A["colorPicks"] & PartialRecord<ColorPicker>; readonly surfaces: A["surfaces"] & PartialRecord<SurfaceSpec>; readonly typography: A["typography"] & PartialRecord<FontSpec>; }; type AttributeExtraKeys = Partial<Record<Exclude<keyof Attributes, "metrics">, string | symbol>>; type AttributesWithExtraKeys<A extends Attributes, K extends AttributeExtraKeys> = { readonly [I in keyof A]: A[I] & (I extends keyof K ? undefined extends K[I] ? unknown : { readonly [J in K[I] & (string | symbol)]: NonNullable<A[I][keyof A[I]]>; } : unknown); }; type OnlyKnownAttributes<T extends Attributes> = { readonly [K in keyof T]: { readonly [J in keyof T[K] as undefined extends T[K][J] ? never : J]: T[K][J]; }; }; type Variants = { readonly [variantName: string]: string; }; type InferVariants<T extends Theme<any, any>> = [T] extends [never] ? Theme.NoVariants : T extends Theme<any, infer V> ? V : Theme.NoVariants; type VariantOptions<V extends Theme.Variants> = { readonly [K in keyof V]: ReadonlyArray<V[K]>; }; type NoVariants = Record<never, never>; type Reference<T extends AnyTheme, K extends keyof T> = T extends any ? keyof T[K] & (string | symbol) : never; type ReferenceCascade<T extends AnyTheme, K extends keyof T> = (keyof T[K] & (string | symbol)) | readonly [...(string | symbol)[], keyof T[K] & (string | symbol)]; } export {}; //# sourceMappingURL=Theme.d.ts.map