@bamboocss/types 1.11.1 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifact.d.ts +65 -0
- package/dist/composition.d.ts +226 -0
- package/dist/conditions.d.ts +74 -0
- package/dist/config.d.ts +535 -0
- package/dist/csstype.d.ts +22569 -0
- package/dist/hooks-api.d.ts +61 -0
- package/dist/hooks.d.ts +237 -0
- package/dist/index.d.ts +21 -0
- package/dist/logger.d.ts +28 -0
- package/dist/parser.d.ts +43 -0
- package/dist/parts.d.ts +7 -0
- package/dist/pattern.d.ts +77 -0
- package/dist/prop-type.d.ts +14 -0
- package/dist/recipe.d.ts +181 -0
- package/dist/reporter.d.ts +167 -0
- package/dist/runtime.d.ts +48 -0
- package/dist/selectors.d.ts +58 -0
- package/dist/shared.d.ts +39 -0
- package/dist/spec.d.ts +197 -0
- package/dist/static-css.d.ts +55 -0
- package/dist/style-props.d.ts +20 -0
- package/dist/style-rules.d.ts +41 -0
- package/dist/system-types.d.ts +150 -0
- package/dist/theme.d.ts +94 -0
- package/dist/tokens.d.ts +104 -0
- package/dist/utility.d.ts +114 -0
- package/package.json +6 -6
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { UserConfig } from './config'
|
|
2
|
+
import type { RecipeDefinition, RecipeVariantRecord, SlotRecipeDefinition, SlotRecipeVariantRecord } from './recipe'
|
|
3
|
+
import type { AtomicStyleResult, GroupedResult, RecipeBaseResult } from './style-rules'
|
|
4
|
+
import type { SystemStyleObject } from './system-types'
|
|
5
|
+
|
|
6
|
+
export interface BaseRule {
|
|
7
|
+
getClassNames: () => string[]
|
|
8
|
+
toCss: () => string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AtomicRule extends BaseRule {
|
|
12
|
+
styles: SystemStyleObject
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface GroupedRule extends BaseRule {
|
|
16
|
+
styles: SystemStyleObject
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AtomicRecipeRule extends BaseRule {
|
|
20
|
+
config: RecipeDefinition<any> | SlotRecipeDefinition<string, any>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RecipeVariantsRule extends BaseRule {
|
|
24
|
+
variants: RecipeVariantRecord
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ProcessorInterface {
|
|
28
|
+
css(styles: SystemStyleObject): AtomicRule
|
|
29
|
+
grouped(styles: SystemStyleObject): GroupedRule
|
|
30
|
+
cva(recipeConfig: RecipeDefinition<RecipeVariantRecord>): AtomicRecipeRule
|
|
31
|
+
sva(recipeConfig: SlotRecipeDefinition<string, SlotRecipeVariantRecord<string>>): AtomicRecipeRule
|
|
32
|
+
recipe(name: string, variants?: RecipeVariantRecord): RecipeVariantsRule | undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface HooksApiInterface {
|
|
36
|
+
/**
|
|
37
|
+
* The resolved config (after all the presets are loaded and merged)
|
|
38
|
+
*/
|
|
39
|
+
config: UserConfig
|
|
40
|
+
/**
|
|
41
|
+
* The path to the config file
|
|
42
|
+
*/
|
|
43
|
+
configPath: string
|
|
44
|
+
/**
|
|
45
|
+
* The list of all the config dependencies (direct/transitive imports) filepaths
|
|
46
|
+
*/
|
|
47
|
+
configDependencies: string[]
|
|
48
|
+
//
|
|
49
|
+
/**
|
|
50
|
+
* The processor can be used to generate atomic or recipe classes
|
|
51
|
+
*/
|
|
52
|
+
processor: ProcessorInterface
|
|
53
|
+
/**
|
|
54
|
+
* Map that contains all the utility classNames
|
|
55
|
+
*/
|
|
56
|
+
classNames: Map<string, string>
|
|
57
|
+
/**
|
|
58
|
+
* Map that contains all the classNames found (and therefore generated) in the app code
|
|
59
|
+
*/
|
|
60
|
+
generatedClassNames: Map<string, AtomicStyleResult | RecipeBaseResult | GroupedResult>
|
|
61
|
+
}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { Artifact, ArtifactId, DiffConfigResult } from './artifact'
|
|
2
|
+
import type { LoadConfigResult, UserConfig } from './config'
|
|
3
|
+
import type { HooksApiInterface } from './hooks-api'
|
|
4
|
+
import type { LoggerInterface } from './logger'
|
|
5
|
+
import type { ParserResultInterface, ResultItem } from './parser'
|
|
6
|
+
|
|
7
|
+
export interface BambooHooks {
|
|
8
|
+
/**
|
|
9
|
+
* Called when the config is resolved, after all the presets are loaded and merged.
|
|
10
|
+
* This is the first hook called, you can use it to tweak the config before the context is created.
|
|
11
|
+
*/
|
|
12
|
+
'config:resolved': (args: ConfigResolvedHookArgs) => MaybeAsyncReturn<void | ConfigResolvedHookArgs['config']>
|
|
13
|
+
/**
|
|
14
|
+
* Called when each preset is resolved, allowing modification of individual presets.
|
|
15
|
+
* This hook is called for each preset during the resolution process, before they are merged together.
|
|
16
|
+
*/
|
|
17
|
+
'preset:resolved': (args: PresetResolvedHookArgs) => MaybeAsyncReturn<void | PresetResolvedHookArgs['preset']>
|
|
18
|
+
/**
|
|
19
|
+
* Called when the token engine has been created
|
|
20
|
+
*/
|
|
21
|
+
'tokens:created': (args: TokenCreatedHookArgs) => MaybeAsyncReturn
|
|
22
|
+
/**
|
|
23
|
+
* Called when the classname engine has been created
|
|
24
|
+
*/
|
|
25
|
+
'utility:created': (args: UtilityCreatedHookArgs) => MaybeAsyncReturn
|
|
26
|
+
/**
|
|
27
|
+
* Called when the Bamboo context has been created and the API is ready to be used.
|
|
28
|
+
*/
|
|
29
|
+
'context:created': (args: ContextCreatedHookArgs) => void
|
|
30
|
+
/**
|
|
31
|
+
* Called when the config file or one of its dependencies (imports) has changed.
|
|
32
|
+
*/
|
|
33
|
+
'config:change': (args: ConfigChangeHookArgs) => MaybeAsyncReturn
|
|
34
|
+
/**
|
|
35
|
+
* Called after reading the file content but before parsing it.
|
|
36
|
+
* You can use this hook to transform the file content to a tsx-friendly syntax so that Bamboo's parser can parse it.
|
|
37
|
+
* You can also use this hook to parse the file's content on your side using a custom parser, in this case you don't have to return anything.
|
|
38
|
+
*/
|
|
39
|
+
'parser:before': (args: ParserResultBeforeHookArgs) => string | void
|
|
40
|
+
/**
|
|
41
|
+
* @private USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING
|
|
42
|
+
*/
|
|
43
|
+
'parser:preprocess': JsxFactoryResultTransform['transform']
|
|
44
|
+
/**
|
|
45
|
+
* Called after the file styles are extracted and processed into the resulting ParserResult object.
|
|
46
|
+
* You can also use this hook to add your own extraction results from your custom parser to the ParserResult object.
|
|
47
|
+
*/
|
|
48
|
+
'parser:after': (args: ParserResultAfterHookArgs) => void
|
|
49
|
+
/**
|
|
50
|
+
* Called right before writing the codegen files to disk.
|
|
51
|
+
* You can use this hook to tweak the codegen files before they are written to disk.
|
|
52
|
+
*/
|
|
53
|
+
'codegen:prepare': (args: CodegenPrepareHookArgs) => MaybeAsyncReturn<void | Artifact[]>
|
|
54
|
+
/**
|
|
55
|
+
* Called after the codegen is completed
|
|
56
|
+
*/
|
|
57
|
+
'codegen:done': (args: CodegenDoneHookArgs) => MaybeAsyncReturn
|
|
58
|
+
/**
|
|
59
|
+
* Called right before adding the design-system CSS (global, static, preflight, tokens, keyframes) to the final CSS
|
|
60
|
+
* Called right before writing/injecting the final CSS (styles.css) that contains the design-system CSS and the parser CSS
|
|
61
|
+
* You can use it to tweak the CSS content before it's written to disk or injected through the postcss plugin.
|
|
62
|
+
*/
|
|
63
|
+
'cssgen:done': (args: CssgenDoneHookArgs) => string | void
|
|
64
|
+
/**
|
|
65
|
+
* Called when CSS needs to be optimized. Use this hook to replace the default PostCSS-based optimizer
|
|
66
|
+
* with a custom one (e.g. LightningCSS).
|
|
67
|
+
* Return the optimized CSS string, or void to fall through to the default PostCSS optimizer.
|
|
68
|
+
*/
|
|
69
|
+
'css:optimize': (args: CssOptimizeHookArgs) => string | void
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type MaybeAsyncReturn<T = void> = Promise<T> | T
|
|
73
|
+
|
|
74
|
+
/* -----------------------------------------------------------------------------
|
|
75
|
+
* Token hooks
|
|
76
|
+
* -----------------------------------------------------------------------------*/
|
|
77
|
+
|
|
78
|
+
interface TokenCssVarOptions {
|
|
79
|
+
fallback?: string
|
|
80
|
+
prefix?: string
|
|
81
|
+
hash?: boolean
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface TokenCssVar {
|
|
85
|
+
var: `--${string}`
|
|
86
|
+
ref: string
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface TokenConfigureOptions {
|
|
90
|
+
formatTokenName?: (path: string[]) => string
|
|
91
|
+
formatCssVar?: (path: string[], options: TokenCssVarOptions) => TokenCssVar
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface TokenCreatedHookArgs {
|
|
95
|
+
configure(opts: TokenConfigureOptions): void
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* -----------------------------------------------------------------------------
|
|
99
|
+
* Utility hooks
|
|
100
|
+
* -----------------------------------------------------------------------------*/
|
|
101
|
+
|
|
102
|
+
export interface UtilityConfigureOptions {
|
|
103
|
+
toHash?(path: string[], toHash: (str: string) => string): string
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface UtilityCreatedHookArgs {
|
|
107
|
+
configure(opts: UtilityConfigureOptions): void
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* -----------------------------------------------------------------------------
|
|
111
|
+
* Config hooks
|
|
112
|
+
* -----------------------------------------------------------------------------*/
|
|
113
|
+
|
|
114
|
+
interface CallbackItem {
|
|
115
|
+
value: any
|
|
116
|
+
path: string
|
|
117
|
+
depth: number
|
|
118
|
+
parent: any[] | Record<string, unknown>
|
|
119
|
+
key: string
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type CallbackFn = (args: CallbackItem) => void
|
|
123
|
+
|
|
124
|
+
interface TraverseOptions {
|
|
125
|
+
separator: string
|
|
126
|
+
maxDepth?: number | undefined
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface TraverseFn {
|
|
130
|
+
(obj: any, callback: CallbackFn, options?: TraverseOptions): void
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface ConfigResolvedHookUtils {
|
|
134
|
+
omit: <T, K extends keyof T | (string & {})>(obj: T, paths: K[]) => Omit<T, K>
|
|
135
|
+
pick: <T, K extends keyof T | (string & {})>(obj: T, paths: K[]) => Partial<T>
|
|
136
|
+
traverse: TraverseFn
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface ConfigResolvedHookArgs {
|
|
140
|
+
config: LoadConfigResult['config']
|
|
141
|
+
path: string
|
|
142
|
+
dependencies: string[]
|
|
143
|
+
utils: ConfigResolvedHookUtils
|
|
144
|
+
original?: LoadConfigResult['config']
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface ConfigChangeHookArgs {
|
|
148
|
+
config: UserConfig
|
|
149
|
+
changes: DiffConfigResult
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface PresetResolvedHookArgs {
|
|
153
|
+
preset: LoadConfigResult['config']
|
|
154
|
+
name: string
|
|
155
|
+
utils: ConfigResolvedHookUtils
|
|
156
|
+
original?: LoadConfigResult['config']
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* -----------------------------------------------------------------------------
|
|
160
|
+
* Parser hooks
|
|
161
|
+
* -----------------------------------------------------------------------------*/
|
|
162
|
+
|
|
163
|
+
export interface ParserResultConfigureOptions {
|
|
164
|
+
matchTag?: (tag: string, isBambooComponent: boolean) => boolean
|
|
165
|
+
matchTagMode?: 'extend' | 'override'
|
|
166
|
+
matchTagProp?: (tag: string, prop: string) => boolean
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface ParserResultBeforeHookArgs {
|
|
170
|
+
filePath: string
|
|
171
|
+
content: string
|
|
172
|
+
configure: (opts: ParserResultConfigureOptions) => void
|
|
173
|
+
original?: string
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface JsxFactoryResultTransform {
|
|
177
|
+
transform: (result: { type: 'jsx-factory'; data: ResultItem['data'] }) => ResultItem['data']
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface ParserResultAfterHookArgs {
|
|
181
|
+
filePath: string
|
|
182
|
+
result: ParserResultInterface | undefined
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* -----------------------------------------------------------------------------
|
|
186
|
+
* Codegen hooks
|
|
187
|
+
* -----------------------------------------------------------------------------*/
|
|
188
|
+
|
|
189
|
+
export interface CodegenPrepareHookArgs {
|
|
190
|
+
artifacts: Artifact[]
|
|
191
|
+
/**
|
|
192
|
+
* The original state of the artifacts, as it was generated by Bamboo, without any modification from other preset hooks
|
|
193
|
+
*/
|
|
194
|
+
original?: Artifact[]
|
|
195
|
+
changed: ArtifactId[] | undefined
|
|
196
|
+
}
|
|
197
|
+
export interface CodegenDoneHookArgs {
|
|
198
|
+
changed: ArtifactId[] | undefined
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/* -----------------------------------------------------------------------------
|
|
202
|
+
* Cssgen hooks
|
|
203
|
+
* -----------------------------------------------------------------------------*/
|
|
204
|
+
|
|
205
|
+
type CssgenArtifact = 'global' | 'static' | 'reset' | 'tokens' | 'keyframes' | 'styles.css'
|
|
206
|
+
|
|
207
|
+
export interface CssgenDoneHookArgs {
|
|
208
|
+
artifact: CssgenArtifact
|
|
209
|
+
/**
|
|
210
|
+
* The current state of the CSS, if any other preset hook has modified the CSS, this will be the modified state
|
|
211
|
+
*/
|
|
212
|
+
content: string
|
|
213
|
+
/**
|
|
214
|
+
* The original state of the CSS, as it was generated by Bamboo, without any modification from other preset hooks
|
|
215
|
+
*/
|
|
216
|
+
original?: string
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* -----------------------------------------------------------------------------
|
|
220
|
+
* CSS optimize hooks
|
|
221
|
+
* -----------------------------------------------------------------------------*/
|
|
222
|
+
|
|
223
|
+
export interface CssOptimizeHookArgs {
|
|
224
|
+
css: string
|
|
225
|
+
minify?: boolean
|
|
226
|
+
browserslist?: string[]
|
|
227
|
+
original?: string
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* -----------------------------------------------------------------------------
|
|
231
|
+
* Context hooks
|
|
232
|
+
* -----------------------------------------------------------------------------*/
|
|
233
|
+
|
|
234
|
+
export interface ContextCreatedHookArgs {
|
|
235
|
+
ctx: HooksApiInterface
|
|
236
|
+
logger: LoggerInterface
|
|
237
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type * from './artifact'
|
|
2
|
+
export type * from './composition'
|
|
3
|
+
export type * from './conditions'
|
|
4
|
+
export type * from './config'
|
|
5
|
+
export type * from './hooks'
|
|
6
|
+
export type * from './hooks-api'
|
|
7
|
+
export type * from './logger'
|
|
8
|
+
export type * from './parser'
|
|
9
|
+
export type * from './parts'
|
|
10
|
+
export type * from './pattern'
|
|
11
|
+
export type * from './recipe'
|
|
12
|
+
export type * from './reporter'
|
|
13
|
+
export type * from './runtime'
|
|
14
|
+
export type * from './shared'
|
|
15
|
+
export type * from './spec'
|
|
16
|
+
export type * from './static-css'
|
|
17
|
+
export type * from './style-rules'
|
|
18
|
+
export type * from './system-types'
|
|
19
|
+
export type * from './theme'
|
|
20
|
+
export type * from './tokens'
|
|
21
|
+
export type * from './utility'
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
2
|
+
|
|
3
|
+
export interface LogEntry {
|
|
4
|
+
level: LogLevel | null
|
|
5
|
+
msg: string
|
|
6
|
+
[key: string]: any
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface LoggerInterface {
|
|
10
|
+
level: 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
11
|
+
print(data: any): void
|
|
12
|
+
onLog?: (entry: LogEntry) => void
|
|
13
|
+
warn: (type: string, data: any) => void
|
|
14
|
+
info: (type: string, data: any) => void
|
|
15
|
+
debug: (type: string, data: any) => void
|
|
16
|
+
error: (type: string, data: any) => void
|
|
17
|
+
/**
|
|
18
|
+
* Log a caught error with context. Extracts the message for the error level,
|
|
19
|
+
* and logs the full stack at debug level.
|
|
20
|
+
*/
|
|
21
|
+
caughtError: (type: string, context: string, error: unknown) => void
|
|
22
|
+
log: (data: string) => void
|
|
23
|
+
time: {
|
|
24
|
+
info: (msg: string) => (_msg?: string) => void
|
|
25
|
+
debug: (msg: string) => (_msg?: string) => void
|
|
26
|
+
}
|
|
27
|
+
isDebug: boolean
|
|
28
|
+
}
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BoxNodeArray, BoxNodeLiteral, BoxNodeMap, Unboxed } from '@bamboocss/extractor'
|
|
2
|
+
|
|
3
|
+
export interface ResultItem {
|
|
4
|
+
name?: string
|
|
5
|
+
data: Array<Unboxed['raw']>
|
|
6
|
+
type?: 'css' | 'cva' | 'sva' | 'token' | 'pattern' | 'recipe' | 'jsx-factory' | 'jsx-pattern' | 'jsx-recipe' | 'jsx'
|
|
7
|
+
box?: BoxNodeMap | BoxNodeLiteral | BoxNodeArray
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ParserResultInterface {
|
|
11
|
+
all: Array<ResultItem>
|
|
12
|
+
jsx: Set<ResultItem>
|
|
13
|
+
css: Set<ResultItem>
|
|
14
|
+
cva: Set<ResultItem>
|
|
15
|
+
sva: Set<ResultItem>
|
|
16
|
+
token: Set<ResultItem>
|
|
17
|
+
recipe: Map<string, Set<ResultItem>>
|
|
18
|
+
pattern: Map<string, Set<ResultItem>>
|
|
19
|
+
filePath: string | undefined
|
|
20
|
+
isEmpty: () => boolean
|
|
21
|
+
toArray: () => Array<ResultItem>
|
|
22
|
+
set: (name: 'cva' | 'css' | 'sva' | 'token', result: ResultItem) => void
|
|
23
|
+
setCss: (result: ResultItem) => void
|
|
24
|
+
setCva: (result: ResultItem) => void
|
|
25
|
+
setSva: (result: ResultItem) => void
|
|
26
|
+
setToken: (result: ResultItem) => void
|
|
27
|
+
setJsx: (result: ResultItem) => void
|
|
28
|
+
setPattern: (name: string, result: ResultItem) => void
|
|
29
|
+
setRecipe: (name: string, result: ResultItem) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface EncoderJson {
|
|
33
|
+
schemaVersion: string
|
|
34
|
+
styles: {
|
|
35
|
+
atomic?: string[]
|
|
36
|
+
recipes?: {
|
|
37
|
+
[name: string]: string[]
|
|
38
|
+
}
|
|
39
|
+
grouped?: {
|
|
40
|
+
[groupId: string]: string[]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/parts.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { CssProperty, SystemStyleObject } from './system-types'
|
|
2
|
+
import type { TokenCategory } from './tokens'
|
|
3
|
+
|
|
4
|
+
type Primitive = string | number | boolean | null | undefined
|
|
5
|
+
type LiteralUnion<T, K extends Primitive = string> = T | (K & Record<never, never>)
|
|
6
|
+
|
|
7
|
+
export type PatternProperty =
|
|
8
|
+
| { type: 'property'; value: CssProperty; description?: string }
|
|
9
|
+
| { type: 'enum'; value: string[]; description?: string }
|
|
10
|
+
| { type: 'token'; value: TokenCategory; property?: CssProperty; description?: string }
|
|
11
|
+
| { type: 'string' | 'boolean' | 'number'; description?: string }
|
|
12
|
+
|
|
13
|
+
export interface PatternHelpers {
|
|
14
|
+
map: (value: any, fn: (value: string) => string | undefined) => any
|
|
15
|
+
isCssUnit: (value: any) => boolean
|
|
16
|
+
isCssVar: (value: any) => boolean
|
|
17
|
+
isCssFunction: (value: any) => boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PatternProperties {
|
|
21
|
+
[key: string]: PatternProperty
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type InferProps<T> = Record<LiteralUnion<keyof T>, any>
|
|
25
|
+
|
|
26
|
+
export type PatternDefaultValue<T> = Partial<InferProps<T>>
|
|
27
|
+
|
|
28
|
+
export type PatternDefaultValueFn<T> = (props: InferProps<T>) => PatternDefaultValue<T>
|
|
29
|
+
|
|
30
|
+
export interface PatternConfig<T extends PatternProperties = PatternProperties> {
|
|
31
|
+
/**
|
|
32
|
+
* The description of the pattern. This will be used in the JSDoc comment.
|
|
33
|
+
*/
|
|
34
|
+
description?: string
|
|
35
|
+
/**
|
|
36
|
+
* The JSX element rendered by the pattern
|
|
37
|
+
* @default 'div'
|
|
38
|
+
*/
|
|
39
|
+
jsxElement?: string
|
|
40
|
+
/**
|
|
41
|
+
* The properties of the pattern.
|
|
42
|
+
*/
|
|
43
|
+
properties?: T
|
|
44
|
+
/**
|
|
45
|
+
* The default values of the pattern.
|
|
46
|
+
*/
|
|
47
|
+
defaultValues?: PatternDefaultValue<T> | PatternDefaultValueFn<T>
|
|
48
|
+
/**
|
|
49
|
+
* The css object this pattern will generate.
|
|
50
|
+
*/
|
|
51
|
+
transform?: (props: InferProps<T>, helpers: PatternHelpers) => SystemStyleObject
|
|
52
|
+
/**
|
|
53
|
+
* Whether the pattern is deprecated.
|
|
54
|
+
*/
|
|
55
|
+
deprecated?: boolean | string
|
|
56
|
+
/**
|
|
57
|
+
* The jsx element name this pattern will generate.
|
|
58
|
+
*/
|
|
59
|
+
jsxName?: string
|
|
60
|
+
/**
|
|
61
|
+
* The jsx elements to track for this pattern. Can be string or Regexp.
|
|
62
|
+
*
|
|
63
|
+
* @default capitalize(pattern.name)
|
|
64
|
+
* @example ['Button', 'Link', /Button$/]
|
|
65
|
+
*/
|
|
66
|
+
jsx?: Array<string | RegExp>
|
|
67
|
+
/**
|
|
68
|
+
* Whether to only generate types for the specified properties.
|
|
69
|
+
* This will disallow css properties
|
|
70
|
+
*/
|
|
71
|
+
strict?: boolean
|
|
72
|
+
/**
|
|
73
|
+
* @experimental
|
|
74
|
+
* Disallow certain css properties for this pattern
|
|
75
|
+
*/
|
|
76
|
+
blocklist?: LiteralUnion<CssProperty>[]
|
|
77
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ConditionalValue } from './conditions'
|
|
2
|
+
import type { CssProperties } from './system-types'
|
|
3
|
+
|
|
4
|
+
/* -----------------------------------------------------------------------------
|
|
5
|
+
* Shadowed export (in CLI): DO NOT REMOVE
|
|
6
|
+
* -----------------------------------------------------------------------------*/
|
|
7
|
+
|
|
8
|
+
export interface PropertyTypes {}
|
|
9
|
+
|
|
10
|
+
export type PropertyValue<K extends string> = K extends keyof PropertyTypes
|
|
11
|
+
? ConditionalValue<PropertyTypes[K]>
|
|
12
|
+
: K extends keyof CssProperties
|
|
13
|
+
? ConditionalValue<CssProperties[K]>
|
|
14
|
+
: never
|
package/dist/recipe.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { RecipeRule } from './static-css'
|
|
2
|
+
import type { SystemStyleObject, DistributiveOmit, Pretty } from './system-types'
|
|
3
|
+
|
|
4
|
+
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T
|
|
5
|
+
|
|
6
|
+
export type RecipeVariantRecord = Record<any, Record<any, SystemStyleObject>>
|
|
7
|
+
|
|
8
|
+
export type RecipeSelection<T extends RecipeVariantRecord> = keyof any extends keyof T
|
|
9
|
+
? {}
|
|
10
|
+
: {
|
|
11
|
+
[K in keyof T]?: StringToBoolean<keyof T[K]> | undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type RecipeVariantFn<T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => string
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Extract the variant as optional props from a `cva` function.
|
|
18
|
+
* Intended to be used with a JSX component, prefer `RecipeVariant` for a more strict type.
|
|
19
|
+
*/
|
|
20
|
+
export type RecipeVariantProps<
|
|
21
|
+
T extends RecipeVariantFn<RecipeVariantRecord> | SlotRecipeVariantFn<string, SlotRecipeVariantRecord<string>>,
|
|
22
|
+
> = Pretty<Parameters<T>[0]>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Extract the variants from a `cva` function.
|
|
26
|
+
*/
|
|
27
|
+
export type RecipeVariant<
|
|
28
|
+
T extends RecipeVariantFn<RecipeVariantRecord> | SlotRecipeVariantFn<string, SlotRecipeVariantRecord<string>>,
|
|
29
|
+
> = Exclude<Pretty<Required<RecipeVariantProps<T>>>, undefined>
|
|
30
|
+
|
|
31
|
+
type RecipeVariantMap<T extends RecipeVariantRecord> = {
|
|
32
|
+
[K in keyof T]: Array<keyof T[K]>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* -----------------------------------------------------------------------------
|
|
36
|
+
* Recipe / Standard
|
|
37
|
+
* -----------------------------------------------------------------------------*/
|
|
38
|
+
|
|
39
|
+
export interface RecipeRuntimeFn<T extends RecipeVariantRecord> extends RecipeVariantFn<T> {
|
|
40
|
+
__type: RecipeSelection<T>
|
|
41
|
+
variantKeys: (keyof T)[]
|
|
42
|
+
variantMap: RecipeVariantMap<T>
|
|
43
|
+
raw: (props?: RecipeSelection<T>) => SystemStyleObject
|
|
44
|
+
config: RecipeConfig<T>
|
|
45
|
+
splitVariantProps<Props extends RecipeSelection<T>>(
|
|
46
|
+
props: Props,
|
|
47
|
+
): [RecipeSelection<T>, Pretty<DistributiveOmit<Props, keyof T>>]
|
|
48
|
+
getVariantProps: (props?: RecipeSelection<T>) => RecipeSelection<T>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type OneOrMore<T> = T | Array<T>
|
|
52
|
+
|
|
53
|
+
export type RecipeCompoundSelection<T> = {
|
|
54
|
+
[K in keyof T]?: OneOrMore<StringToBoolean<keyof T[K]>> | undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type RecipeCompoundVariant<T> = T & {
|
|
58
|
+
css: SystemStyleObject
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface RecipeDefinition<T extends RecipeVariantRecord = RecipeVariantRecord> {
|
|
62
|
+
/**
|
|
63
|
+
* The base styles of the recipe.
|
|
64
|
+
*/
|
|
65
|
+
base?: SystemStyleObject
|
|
66
|
+
/**
|
|
67
|
+
* Whether the recipe is deprecated.
|
|
68
|
+
*/
|
|
69
|
+
deprecated?: boolean | string
|
|
70
|
+
/**
|
|
71
|
+
* The multi-variant styles of the recipe.
|
|
72
|
+
*/
|
|
73
|
+
variants?: T
|
|
74
|
+
/**
|
|
75
|
+
* The default variants of the recipe.
|
|
76
|
+
*/
|
|
77
|
+
defaultVariants?: RecipeSelection<T>
|
|
78
|
+
/**
|
|
79
|
+
* The styles to apply when a combination of variants is selected.
|
|
80
|
+
*/
|
|
81
|
+
compoundVariants?: Pretty<RecipeCompoundVariant<RecipeCompoundSelection<T>>>[]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type RecipeCreatorFn = <T extends RecipeVariantRecord>(config: RecipeDefinition<T>) => RecipeRuntimeFn<T>
|
|
85
|
+
|
|
86
|
+
interface RecipeConfigMeta {
|
|
87
|
+
/**
|
|
88
|
+
* The class name of the recipe.
|
|
89
|
+
*/
|
|
90
|
+
className: string
|
|
91
|
+
/**
|
|
92
|
+
* The description of the recipe. This will be used in the JSDoc comment.
|
|
93
|
+
*/
|
|
94
|
+
description?: string
|
|
95
|
+
/**
|
|
96
|
+
* The jsx elements to track for this recipe. Can be string or Regexp.
|
|
97
|
+
*
|
|
98
|
+
* @default capitalize(recipe.name)
|
|
99
|
+
* @example ['Button', 'Link', /Button$/]
|
|
100
|
+
*/
|
|
101
|
+
jsx?: Array<string | RegExp>
|
|
102
|
+
/**
|
|
103
|
+
* Variants to pre-generate, will be include in the final `config.staticCss`
|
|
104
|
+
*/
|
|
105
|
+
staticCss?: RecipeRule[]
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface RecipeConfig<T extends RecipeVariantRecord = RecipeVariantRecord>
|
|
109
|
+
extends RecipeDefinition<T>, RecipeConfigMeta {}
|
|
110
|
+
|
|
111
|
+
/* -----------------------------------------------------------------------------
|
|
112
|
+
* Recipe / Slot
|
|
113
|
+
* -----------------------------------------------------------------------------*/
|
|
114
|
+
|
|
115
|
+
type SlotRecord<S extends string, T> = Partial<Record<S, T>>
|
|
116
|
+
|
|
117
|
+
export type SlotRecipeVariantRecord<S extends string> = Record<any, Record<any, SlotRecord<S, SystemStyleObject>>>
|
|
118
|
+
|
|
119
|
+
export type SlotRecipeVariantFn<S extends string, T extends RecipeVariantRecord> = (
|
|
120
|
+
props?: RecipeSelection<T>,
|
|
121
|
+
) => SlotRecord<S, string>
|
|
122
|
+
|
|
123
|
+
export interface SlotRecipeRuntimeFn<
|
|
124
|
+
S extends string,
|
|
125
|
+
T extends SlotRecipeVariantRecord<S>,
|
|
126
|
+
> extends SlotRecipeVariantFn<S, T> {
|
|
127
|
+
raw: (props?: RecipeSelection<T>) => Record<S, SystemStyleObject>
|
|
128
|
+
variantKeys: (keyof T)[]
|
|
129
|
+
variantMap: RecipeVariantMap<T>
|
|
130
|
+
splitVariantProps<Props extends RecipeSelection<T>>(
|
|
131
|
+
props: Props,
|
|
132
|
+
): [RecipeSelection<T>, Pretty<DistributiveOmit<Props, keyof T>>]
|
|
133
|
+
getVariantProps: (props?: RecipeSelection<T>) => RecipeSelection<T>
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type SlotRecipeCompoundVariant<S extends string, T> = T & {
|
|
137
|
+
css: SlotRecord<S, SystemStyleObject>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface SlotRecipeDefinition<
|
|
141
|
+
S extends string = string,
|
|
142
|
+
T extends SlotRecipeVariantRecord<S> = SlotRecipeVariantRecord<S>,
|
|
143
|
+
> {
|
|
144
|
+
/**
|
|
145
|
+
* An optional class name that can be used to target slots in the DOM.
|
|
146
|
+
*/
|
|
147
|
+
className?: string
|
|
148
|
+
/**
|
|
149
|
+
* Whether the recipe is deprecated.
|
|
150
|
+
*/
|
|
151
|
+
deprecated?: boolean | string
|
|
152
|
+
/**
|
|
153
|
+
* The parts/slots of the recipe.
|
|
154
|
+
*/
|
|
155
|
+
slots: S[] | Readonly<S[]>
|
|
156
|
+
/**
|
|
157
|
+
* The base styles of the recipe.
|
|
158
|
+
*/
|
|
159
|
+
base?: SlotRecord<S, SystemStyleObject>
|
|
160
|
+
/**
|
|
161
|
+
* The multi-variant styles of the recipe.
|
|
162
|
+
*/
|
|
163
|
+
variants?: T
|
|
164
|
+
/**
|
|
165
|
+
* The default variants of the recipe.
|
|
166
|
+
*/
|
|
167
|
+
defaultVariants?: RecipeSelection<T>
|
|
168
|
+
/**
|
|
169
|
+
* The styles to apply when a combination of variants is selected.
|
|
170
|
+
*/
|
|
171
|
+
compoundVariants?: Pretty<SlotRecipeCompoundVariant<S, RecipeCompoundSelection<T>>>[]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export type SlotRecipeCreatorFn = <S extends string, T extends SlotRecipeVariantRecord<S>>(
|
|
175
|
+
config: SlotRecipeDefinition<S, T>,
|
|
176
|
+
) => SlotRecipeRuntimeFn<S, T>
|
|
177
|
+
|
|
178
|
+
export type SlotRecipeConfig<
|
|
179
|
+
S extends string = string,
|
|
180
|
+
T extends SlotRecipeVariantRecord<S> = SlotRecipeVariantRecord<S>,
|
|
181
|
+
> = SlotRecipeDefinition<S, T> & RecipeConfigMeta
|