UNPKG

free-style

Version:

Make CSS easier and more maintainable by using JavaScript

117 lines (116 loc) 3.04 kB
/** * Valid CSS property values. */ export type PropertyValue = number | boolean | string | null | undefined; /** * Input styles object. */ export interface Styles { $unique?: boolean; $global?: boolean; $displayName?: string; [selector: string]: PropertyValue | PropertyValue[] | Styles; } export interface CompiledStyle { selector: string; style: string; isUnique: boolean; } export interface CompiledRule { selector: string; style: string; rules: CompiledRule[]; styles: CompiledStyle[]; } /** * Pre-registered container for cached styles and rules. */ export interface Compiled { id: string; rules: CompiledRule[]; styles: CompiledStyle[]; displayName: string | undefined; } /** * Propagate change events. */ export interface Changes { add(style: Container<any>, index: number): void; remove(style: Container<any>, index: number): void; change(style: Container<any>, index: number): void; } /** * Cache-able interface. */ export interface Container<T> { /** Unique identifier for the cache, used for merging styles. */ cid(): string; clone(): T; getStyles(): string; } /** * Implement a cache/event emitter. */ export declare class Cache<T extends Container<any>> { changes?: Changes | undefined; changeId: number; protected sheet: string[]; protected children: T[]; protected counters: Map<string, number>; constructor(changes?: Changes | undefined); add(style: T): void; remove(style: T): void; merge(cache: Cache<any>): this; unmerge(cache: Cache<any>): this; } /** * Selector is a dumb class made to represent nested CSS selectors. */ export declare class Selector implements Container<Selector> { selector: string; constructor(selector: string); cid(): string; getStyles(): string; clone(): Selector; } /** * The style container registers a style string with selectors. */ export declare class Style extends Cache<Selector> implements Container<Style> { style: string; id: string; constructor(style: string, id: string); cid(): string; getStyles(): string; clone(): Style; } /** * Implement rule logic for style output. */ export declare class Rule extends Cache<Rule | Style> implements Container<Rule> { rule: string; style: string; id: string; constructor(rule: string, style: string, id: string); cid(): string; getStyles(): string; clone(): Rule; } /** * The FreeStyle class implements the API for everything else. */ export declare class Sheet extends Cache<Rule | Style> { prefix: string; constructor(prefix: string, changes?: Changes); register(compiled: Compiled): string; registerStyle(styles: Styles): string; getStyles(): string; } /** * Exports a simple function to create a new instance. */ export declare function create(changes?: Changes, prefix?: string): Sheet; /** * Compile styles into a registerable object. */ export declare function compile(styles: Styles): Compiled;