UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

35 lines (34 loc) 1.34 kB
import type { As, ComponentWithAs } from './PropsWithAs.js'; type VariantImpl<T extends string> = T | { [K in T]?: boolean; }; export type Variant<T extends string> = VariantImpl<T> | Array<VariantImpl<T>>; export type Styler = { (...state: Array<Variant<any>>): string; className: string; with(...extra: Array<string | Styler | undefined>): Styler; mergeProps(attrs: { [key: string]: any; } | undefined): Styler; toSelector(): string; toString(): string; toElement<Props, Type extends As>(element: Type): ComponentWithAs<Props, Type>; }; type GenericStyler = Styler & { [key: string]: GenericStyler; }; export type GenericStyles = { [key: string]: GenericStyler; }; type Style<State> = string extends State ? GenericStyles : State extends string ? State extends `${infer Parent}-${infer Sub}` ? { [P in Parent]: Style<Sub>; } : { [P in State]: Styler; } : never; type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; export type ModuleStyles<M> = {} extends M ? GenericStyles : UnionToIntersection<Style<keyof M>>; export declare const styler: (selector: string, variants?: Map<string, string>) => Styler; export declare const fromModule: <M extends { [key: string]: string; }>(styles: M) => ModuleStyles<M>; export {};