/
core.ts
46 lines (35 loc) · 1.35 KB
/
core.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { Falsy } from './util'
import type { Declarations } from './common'
import type { ThemeValueResolver } from './theme'
export interface TokenGrouping extends Record<string, Token> {}
type TypescriptCompat = boolean | number
export type Token = string | InlinePlugin | TokenGrouping | Token[] | Falsy | TypescriptCompat
export type InjectKeyframes = (name: string, waypoints?: Record<string, Declarations>) => string
export interface PluginApply {
(strings: TemplateStringsArray, ...interpolations: Token[]): PluginTokenResult
(...tokens: Token[]): PluginTokenResult
}
export type TokenParser = (token: Token) => void
export type PluginTokenResult = (parse: TokenParser) => void
export interface PluginContext {
readonly keyframes: InjectKeyframes
readonly tag: (token: string) => string
}
export type SelectorDecorator = (selector: string) => string
export type PluginResult =
| string
| Declarations
| [suffix: string, declarations: Declarations | Falsy]
| [selectorDecorator: SelectorDecorator, declarations: Declarations | Falsy]
| Falsy
export type Plugin =
| PluginResult
| ((
parts: string[],
theme: ThemeValueResolver,
context: PluginContext,
) => PluginResult | PluginTokenResult)
export type InlinePlugin = (
theme: ThemeValueResolver,
context: PluginContext,
) => PluginResult | PluginTokenResult