UNPKG

3.04 kBTypeScriptView Raw
1/**
2 * Valid CSS property values.
3 */
4export type PropertyValue = number | boolean | string | null | undefined;
5/**
6 * Input styles object.
7 */
8export interface Styles {
9 $unique?: boolean;
10 $global?: boolean;
11 $displayName?: string;
12 [selector: string]: PropertyValue | PropertyValue[] | Styles;
13}
14export interface CompiledStyle {
15 selector: string;
16 style: string;
17 isUnique: boolean;
18}
19export interface CompiledRule {
20 selector: string;
21 style: string;
22 rules: CompiledRule[];
23 styles: CompiledStyle[];
24}
25/**
26 * Pre-registered container for cached styles and rules.
27 */
28export interface Compiled {
29 id: string;
30 rules: CompiledRule[];
31 styles: CompiledStyle[];
32 displayName: string | undefined;
33}
34/**
35 * Propagate change events.
36 */
37export interface Changes {
38 add(style: Container<any>, index: number): void;
39 remove(style: Container<any>, index: number): void;
40 change(style: Container<any>, index: number): void;
41}
42/**
43 * Cache-able interface.
44 */
45export interface Container<T> {
46 /** Unique identifier for the cache, used for merging styles. */
47 cid(): string;
48 clone(): T;
49 getStyles(): string;
50}
51/**
52 * Implement a cache/event emitter.
53 */
54export declare class Cache<T extends Container<any>> {
55 changes?: Changes | undefined;
56 changeId: number;
57 protected sheet: string[];
58 protected children: T[];
59 protected counters: Map<string, number>;
60 constructor(changes?: Changes | undefined);
61 add(style: T): void;
62 remove(style: T): void;
63 merge(cache: Cache<any>): this;
64 unmerge(cache: Cache<any>): this;
65}
66/**
67 * Selector is a dumb class made to represent nested CSS selectors.
68 */
69export declare class Selector implements Container<Selector> {
70 selector: string;
71 constructor(selector: string);
72 cid(): string;
73 getStyles(): string;
74 clone(): Selector;
75}
76/**
77 * The style container registers a style string with selectors.
78 */
79export declare class Style extends Cache<Selector> implements Container<Style> {
80 style: string;
81 id: string;
82 constructor(style: string, id: string);
83 cid(): string;
84 getStyles(): string;
85 clone(): Style;
86}
87/**
88 * Implement rule logic for style output.
89 */
90export declare class Rule extends Cache<Rule | Style> implements Container<Rule> {
91 rule: string;
92 style: string;
93 id: string;
94 constructor(rule: string, style: string, id: string);
95 cid(): string;
96 getStyles(): string;
97 clone(): Rule;
98}
99/**
100 * The FreeStyle class implements the API for everything else.
101 */
102export declare class Sheet extends Cache<Rule | Style> {
103 prefix: string;
104 constructor(prefix: string, changes?: Changes);
105 register(compiled: Compiled): string;
106 registerStyle(styles: Styles): string;
107 getStyles(): string;
108}
109/**
110 * Exports a simple function to create a new instance.
111 */
112export declare function create(changes?: Changes, prefix?: string): Sheet;
113/**
114 * Compile styles into a registerable object.
115 */
116export declare function compile(styles: Styles): Compiled;