@bamboocss/types 1.11.1 → 1.11.3

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.
@@ -0,0 +1,167 @@
1
+ import type { ParserResultInterface } from './parser'
2
+
3
+ export type ReportItemType =
4
+ | 'css'
5
+ | 'cva'
6
+ | 'sva'
7
+ | 'token'
8
+ | 'pattern'
9
+ | 'recipe'
10
+ | 'jsx-factory'
11
+ | 'jsx-pattern'
12
+ | 'jsx-recipe'
13
+ | 'jsx'
14
+
15
+ type ComponentKind = 'component' | 'function'
16
+
17
+ interface PropertyLocationRange {
18
+ startPosition: number
19
+ startLineNumber: number
20
+ startColumn: number
21
+ endPosition: number
22
+ endLineNumber: number
23
+ endColumn: number
24
+ }
25
+
26
+ export interface PropertyReportItem {
27
+ index: string
28
+ componentIndex: ComponentReportItem['componentIndex']
29
+ componentName: ComponentReportItem['componentName']
30
+ reportItemKind: 'token' | 'utility'
31
+ reportItemType: ReportItemType
32
+
33
+ path: string[]
34
+ conditionName?: string | undefined
35
+ propName: string
36
+ value: string | number | boolean
37
+
38
+ tokenType?: string
39
+ isKnownValue: boolean
40
+
41
+ range: PropertyLocationRange | null
42
+ filepath: string
43
+ }
44
+
45
+ /**
46
+ * An component is either a component usage or a function usage
47
+ * @example an component name could be 'Button', 'css', 'bamboo.div', 'vstack', ...
48
+ */
49
+ export interface ComponentReportItem extends Pick<PropertyReportItem, 'filepath'> {
50
+ componentIndex: string
51
+ componentName: string
52
+ reportItemType: ReportItemType
53
+ kind: ComponentKind
54
+ contains: Array<PropertyReportItem['index']>
55
+ value: Record<string, any>
56
+ range: PropertyLocationRange | null
57
+ debug?: boolean
58
+ }
59
+
60
+ export interface ReportDerivedMaps {
61
+ byComponentOfKind: Map<ComponentKind, Set<ComponentReportItem['componentIndex']>>
62
+ byPropertyName: Map<string, Set<PropertyReportItem['index']>>
63
+ byTokenType: Map<string, Set<PropertyReportItem['index']>>
64
+ byConditionName: Map<string, Set<PropertyReportItem['index']>>
65
+ byShorthand: Map<string, Set<PropertyReportItem['index']>>
66
+ byTokenName: Map<string, Set<PropertyReportItem['index']>>
67
+ byPropertyPath: Map<string, Set<PropertyReportItem['index']>>
68
+ fromKind: Map<ComponentKind, Set<PropertyReportItem['index']>>
69
+ byType: Map<string, Set<PropertyReportItem['index']>>
70
+ byComponentName: Map<string, Set<PropertyReportItem['index']>>
71
+ colorsUsed: Map<string, Set<PropertyReportItem['index']>>
72
+ }
73
+
74
+ interface ReportDerivedMapsJSON {
75
+ byComponentOfKind: Record<ComponentKind, Array<ComponentReportItem['componentIndex']>>
76
+ byPropertyName: Record<string, Array<PropertyReportItem['index']>>
77
+ byTokenType: Record<string, Array<PropertyReportItem['index']>>
78
+ byConditionName: Record<string, Array<PropertyReportItem['index']>>
79
+ byShorthand: Record<string, Array<PropertyReportItem['index']>>
80
+ byTokenName: Record<string, Array<PropertyReportItem['index']>>
81
+ byPropertyPath: Record<string, Array<PropertyReportItem['index']>>
82
+ fromKind: Record<ComponentKind, Array<PropertyReportItem['index']>>
83
+ byType: Record<string, Array<PropertyReportItem['index']>>
84
+ byComponentName: Record<string, Array<PropertyReportItem['index']>>
85
+ colorsUsed: Record<string, Array<PropertyReportItem['index']>>
86
+ }
87
+
88
+ export interface ReportCounts {
89
+ filesWithTokens: number
90
+ propNameUsed: number
91
+ tokenUsed: number
92
+ shorthandUsed: number
93
+ propertyPathUsed: number
94
+ typeUsed: number
95
+ componentNameUsed: number
96
+ kindUsed: number
97
+ componentOfKindUsed: number
98
+ colorsUsed: number
99
+ }
100
+
101
+ export interface MostUsedItem {
102
+ key: string
103
+ count: number
104
+ }
105
+
106
+ export interface ReportStats {
107
+ filesWithMostComponent: Record<string, number>
108
+ mostUseds: {
109
+ propNames: Array<MostUsedItem>
110
+ tokens: Array<MostUsedItem>
111
+ shorthands: Array<MostUsedItem>
112
+ categories: Array<MostUsedItem>
113
+ conditions: Array<MostUsedItem>
114
+ propertyPaths: Array<MostUsedItem>
115
+ types: Array<MostUsedItem>
116
+ componentNames: Array<MostUsedItem>
117
+ fromKinds: Array<MostUsedItem>
118
+ componentOfKinds: Array<MostUsedItem>
119
+ colors: Array<MostUsedItem>
120
+ }
121
+ }
122
+
123
+ export interface ReportDetails {
124
+ counts: ReportCounts
125
+ stats: ReportStats
126
+ }
127
+
128
+ export interface AnalysisOptions {
129
+ onResult?: (file: string, result: ParserResultInterface) => void
130
+ }
131
+
132
+ interface ReportDerivedMap {
133
+ byFilepath: Map<string, Set<PropertyReportItem['index']>>
134
+ byComponentInFilepath: Map<string, Set<ComponentReportItem['componentIndex']>>
135
+ globalMaps: ReportDerivedMaps
136
+ byFilePathMaps: Map<string, ReportDerivedMaps>
137
+ }
138
+
139
+ interface ReportDerivedMapJSON {
140
+ byFilepath: Record<string, Array<PropertyReportItem['index']>>
141
+ byComponentInFilepath: Record<string, Array<ComponentReportItem['componentIndex']>>
142
+ globalMaps: ReportDerivedMapsJSON
143
+ byFilePathMaps: Record<string, ReportDerivedMapsJSON>
144
+ }
145
+
146
+ export interface AnalysisReport {
147
+ schemaVersion: string
148
+ details: ReportDetails
149
+
150
+ propByIndex: Map<PropertyReportItem['index'], PropertyReportItem>
151
+ componentByIndex: Map<ComponentReportItem['componentIndex'], ComponentReportItem>
152
+
153
+ derived: ReportDerivedMap
154
+ }
155
+
156
+ export interface ReportSnapshotJSON extends Omit<AnalysisReport, 'propByIndex' | 'componentByIndex' | 'derived'> {
157
+ propByIndex: Record<PropertyReportItem['index'], PropertyReportItem>
158
+ componentByIndex: Record<ComponentReportItem['componentIndex'], ComponentReportItem>
159
+ derived: ReportDerivedMapJSON
160
+ }
161
+
162
+ export interface ClassifyReport {
163
+ propById: Map<string, PropertyReportItem>
164
+ componentById: Map<ComponentReportItem['componentIndex'], ComponentReportItem>
165
+ details: Pick<ReportDetails, 'counts' | 'stats'>
166
+ derived: ReportDerivedMap
167
+ }
@@ -0,0 +1,48 @@
1
+ interface Watcher {
2
+ on(event: 'add' | 'addDir' | 'change', listener: (path: string) => void): this
3
+ on(event: 'all', listener: (evt: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string) => void): this
4
+ close(): Promise<void>
5
+ }
6
+
7
+ interface InputOptions {
8
+ include: string[]
9
+ exclude?: string[]
10
+ cwd?: string
11
+ }
12
+
13
+ export type WatcherEventType = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'
14
+
15
+ export interface WatchOptions extends InputOptions {
16
+ poll?: boolean
17
+ }
18
+
19
+ interface FileSystem {
20
+ readDirSync(dir: string): string[]
21
+ existsSync(fileLike: string): boolean
22
+ glob(opts: InputOptions): string[]
23
+ readFileSync(filePath: string): string
24
+ rmDirSync(dirPath: string): void
25
+ writeFile(file: string, content: string): Promise<void>
26
+ rmFileSync(file: string): void
27
+ ensureDirSync(dirPath: string): void
28
+ writeFileSync(filePath: string, content: string): void
29
+ watch(options: WatchOptions): Watcher
30
+ }
31
+
32
+ interface Path {
33
+ join(...paths: string[]): string
34
+ dirname(path: string): string
35
+ resolve(...paths: string[]): string
36
+ extname(path: string): string
37
+ relative(from: string, to: string): string
38
+ isAbsolute(path: string): boolean
39
+ sep: string
40
+ abs(cwd: string, path: string): string
41
+ }
42
+
43
+ export interface Runtime {
44
+ fs: FileSystem
45
+ path: Path
46
+ cwd(): string
47
+ env(name: string): string | undefined
48
+ }
@@ -0,0 +1,58 @@
1
+ import type { Pseudos } from './csstype'
2
+
3
+ type AriaAttributes =
4
+ | '[aria-disabled]'
5
+ | '[aria-hidden]'
6
+ | '[aria-invalid]'
7
+ | '[aria-readonly]'
8
+ | '[aria-required]'
9
+ | '[aria-selected]'
10
+ | '[aria-checked]'
11
+ | '[aria-expanded]'
12
+ | '[aria-pressed]'
13
+ | `[aria-current=${'page' | 'step' | 'location' | 'date' | 'time'}]`
14
+ | '[aria-invalid]'
15
+ | `[aria-sort=${'ascending' | 'descending'}]`
16
+
17
+ type DataAttributes =
18
+ | '[data-selected]'
19
+ | '[data-highlighted]'
20
+ | '[data-hover]'
21
+ | '[data-active]'
22
+ | '[data-checked]'
23
+ | '[data-disabled]'
24
+ | '[data-readonly]'
25
+ | '[data-focus]'
26
+ | '[data-focus-visible]'
27
+ | '[data-focus-visible-added]'
28
+ | '[data-invalid]'
29
+ | '[data-pressed]'
30
+ | '[data-expanded]'
31
+ | '[data-grabbed]'
32
+ | '[data-dragged]'
33
+ | '[data-orientation=horizontal]'
34
+ | '[data-orientation=vertical]'
35
+ | '[data-in-range]'
36
+ | '[data-out-of-range]'
37
+ | '[data-placeholder-shown]'
38
+ | `[data-part=${string}]`
39
+ | `[data-attr=${string}]`
40
+ | `[data-placement=${string}]`
41
+ | `[data-theme=${string}]`
42
+ | `[data-size=${string}]`
43
+ | `[data-state=${string}]`
44
+ | '[data-empty]'
45
+ | '[data-loading]'
46
+ | '[data-loaded]'
47
+ | '[data-enter]'
48
+ | '[data-entering]'
49
+ | '[data-exited]'
50
+ | '[data-exiting]'
51
+
52
+ type AttributeSelector = `&${Pseudos | DataAttributes | AriaAttributes}`
53
+ type ParentSelector = `${DataAttributes | AriaAttributes} &`
54
+
55
+ type AtRuleType = 'media' | 'layer' | 'container' | 'supports' | 'page' | 'scope' | 'starting-style'
56
+
57
+ export type AnySelector = `${string}&` | `&${string}` | `@${AtRuleType}${string}`
58
+ export type Selectors = AttributeSelector | ParentSelector
@@ -0,0 +1,39 @@
1
+ type Primitive = string | number | boolean | null | undefined
2
+
3
+ export type LiteralUnion<T, K extends Primitive = string> = T | (K & Record<never, never>)
4
+
5
+ export interface Recursive<T> {
6
+ [key: string]: T | Recursive<T>
7
+ }
8
+
9
+ export type Dict<T = any> = Record<string, T>
10
+
11
+ export type RequiredBy<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>
12
+
13
+ export type AnyFunction<T = any> = (...args: T[]) => any
14
+
15
+ export type Nullable<T> = T | null | undefined
16
+
17
+ export type Keys<T> = keyof NonNullable<T>
18
+
19
+ type Subtract<T extends number, D extends number> = T extends D ? 0 : T extends D | any ? Exclude<T, D> : never
20
+
21
+ /**
22
+ * Get all the (nested) paths of an object until a certain depth
23
+ * e.g. Paths<{a: {b: {c: 1}}}, '', 2> => 'a' | 'a.b' | 'a.b.c'
24
+ */
25
+ type Paths<T, Prefix extends string = '', Depth extends number = 0> = {
26
+ [K in keyof T]: Depth extends 0
27
+ ? never
28
+ : T[K] extends object
29
+ ? K extends string
30
+ ? `${Prefix}${K}` | Paths<T[K], `${Prefix}${K}.`, Depth extends 1 ? 0 : Subtract<Depth, 1>>
31
+ : never
32
+ : K extends string | number
33
+ ? `${Prefix}${K}`
34
+ : never
35
+ }[keyof T]
36
+
37
+ export type PathIn<T, Key extends keyof T> = Key extends string ? Paths<T[Key], `${Key}.`, 1> : never
38
+
39
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
package/dist/spec.d.ts ADDED
@@ -0,0 +1,197 @@
1
+ export type SpecType =
2
+ | 'tokens'
3
+ | 'recipes'
4
+ | 'patterns'
5
+ | 'conditions'
6
+ | 'keyframes'
7
+ | 'semantic-tokens'
8
+ | 'text-styles'
9
+ | 'layer-styles'
10
+ | 'animation-styles'
11
+ | 'color-palette'
12
+ | 'themes'
13
+
14
+ interface Examples {
15
+ functionExamples: string[]
16
+ jsxExamples: string[]
17
+ }
18
+
19
+ export interface TokenValue {
20
+ name: string
21
+ value: any
22
+ description?: string
23
+ deprecated?: boolean | string
24
+ cssVar?: string
25
+ }
26
+
27
+ export interface TokenGroupDefinition extends Examples {
28
+ type: string
29
+ values: TokenValue[]
30
+ tokenFunctionExamples: string[]
31
+ }
32
+
33
+ export interface TokenSpec {
34
+ type: 'tokens'
35
+ data: TokenGroupDefinition[]
36
+ }
37
+
38
+ export interface SemanticTokenValue {
39
+ name: string
40
+ values: Array<{ value: string; condition?: string }>
41
+ description?: string
42
+ deprecated?: boolean | string
43
+ cssVar?: string
44
+ }
45
+
46
+ export interface SemanticTokenGroupDefinition extends Examples {
47
+ type: string
48
+ values: SemanticTokenValue[]
49
+ tokenFunctionExamples: string[]
50
+ }
51
+
52
+ export interface SemanticTokenSpec {
53
+ type: 'semantic-tokens'
54
+ data: SemanticTokenGroupDefinition[]
55
+ }
56
+
57
+ export interface RecipeSpecDefinition extends Examples {
58
+ name: string
59
+ description?: string
60
+ variants: Record<string, string[]>
61
+ defaultVariants: Record<string, any>
62
+ }
63
+
64
+ export interface RecipeSpec {
65
+ type: 'recipes'
66
+ data: RecipeSpecDefinition[]
67
+ }
68
+
69
+ export interface PatternSpecProperty {
70
+ name: string
71
+ type: string
72
+ description?: string
73
+ required?: boolean
74
+ defaultValue?: any
75
+ }
76
+
77
+ export interface PatternSpecDefinition extends Examples {
78
+ name: string
79
+ description?: string
80
+ properties: PatternSpecProperty[]
81
+ jsx?: string
82
+ }
83
+
84
+ export interface PatternSpec {
85
+ type: 'patterns'
86
+ data: PatternSpecDefinition[]
87
+ }
88
+
89
+ export interface ConditionSpecDefinition extends Examples {
90
+ name: string
91
+ value: string
92
+ }
93
+
94
+ export interface ConditionSpec {
95
+ type: 'conditions'
96
+ data: ConditionSpecDefinition[]
97
+ }
98
+
99
+ export interface KeyframeSpecDefinition extends Examples {
100
+ name: string
101
+ }
102
+
103
+ export interface KeyframeSpec {
104
+ type: 'keyframes'
105
+ data: KeyframeSpecDefinition[]
106
+ }
107
+
108
+ export interface TextStyleSpecDefinition extends Examples {
109
+ name: string
110
+ description?: string
111
+ }
112
+
113
+ export interface TextStyleSpec {
114
+ type: 'text-styles'
115
+ data: TextStyleSpecDefinition[]
116
+ }
117
+
118
+ export interface LayerStyleSpecDefinition extends Examples {
119
+ name: string
120
+ description?: string
121
+ }
122
+
123
+ export interface LayerStyleSpec {
124
+ type: 'layer-styles'
125
+ data: LayerStyleSpecDefinition[]
126
+ }
127
+
128
+ export interface AnimationStyleSpecDefinition extends Examples {
129
+ name: string
130
+ description?: string
131
+ }
132
+
133
+ export interface AnimationStyleSpec {
134
+ type: 'animation-styles'
135
+ data: AnimationStyleSpecDefinition[]
136
+ }
137
+
138
+ export interface ColorPaletteSpec {
139
+ type: 'color-palette'
140
+ data: {
141
+ values: string[]
142
+ functionExamples: string[]
143
+ jsxExamples: string[]
144
+ }
145
+ }
146
+
147
+ export interface ThemeTokenValue {
148
+ name: string
149
+ values: Array<{ value: string; condition?: string }>
150
+ description?: string
151
+ deprecated?: boolean | string
152
+ cssVar?: string
153
+ }
154
+
155
+ export interface ThemeTokenGroupDefinition extends Examples {
156
+ type: string
157
+ values: ThemeTokenValue[]
158
+ tokenFunctionExamples: string[]
159
+ }
160
+
161
+ export interface ThemeSpecDefinition {
162
+ name: string
163
+ tokens: ThemeTokenGroupDefinition[]
164
+ semanticTokens: ThemeTokenGroupDefinition[]
165
+ }
166
+
167
+ export interface ThemesSpec {
168
+ type: 'themes'
169
+ data: ThemeSpecDefinition[]
170
+ }
171
+
172
+ export type SpecFile =
173
+ | TokenSpec
174
+ | SemanticTokenSpec
175
+ | RecipeSpec
176
+ | PatternSpec
177
+ | ConditionSpec
178
+ | KeyframeSpec
179
+ | TextStyleSpec
180
+ | LayerStyleSpec
181
+ | AnimationStyleSpec
182
+ | ColorPaletteSpec
183
+ | ThemesSpec
184
+
185
+ export interface SpecTypeMap {
186
+ tokens: TokenSpec
187
+ 'semantic-tokens': SemanticTokenSpec
188
+ recipes: RecipeSpec
189
+ patterns: PatternSpec
190
+ conditions: ConditionSpec
191
+ keyframes: KeyframeSpec
192
+ 'text-styles': TextStyleSpec
193
+ 'layer-styles': LayerStyleSpec
194
+ 'animation-styles': AnimationStyleSpec
195
+ 'color-palette': ColorPaletteSpec
196
+ themes: ThemesSpec
197
+ }
@@ -0,0 +1,55 @@
1
+ interface ConditionOptions {
2
+ /**
3
+ * The conditions to generate for the rule.
4
+ * @example ['hover', 'focus']
5
+ */
6
+ conditions?: string[]
7
+ /**
8
+ * Whether to generate responsive styles for the rule.
9
+ */
10
+ responsive?: boolean
11
+ }
12
+
13
+ export interface CssRule extends ConditionOptions {
14
+ /**
15
+ * The css properties to generate utilities for.
16
+ * @example ['margin', 'padding']
17
+ */
18
+ properties: {
19
+ [property: string]: Array<string | number>
20
+ }
21
+ }
22
+
23
+ interface RecipeRuleVariants {
24
+ [variant: string]: boolean | string[]
25
+ }
26
+
27
+ export type RecipeRuleObject = RecipeRuleVariants & ConditionOptions
28
+ export type RecipeRule = '*' | RecipeRuleObject
29
+
30
+ export type PatternRule = '*' | CssRule
31
+
32
+ export interface StaticCssOptions {
33
+ /**
34
+ * The css utility classes to generate.
35
+ */
36
+ css?: CssRule[]
37
+ /**
38
+ * The css recipes to generate.
39
+ */
40
+ recipes?:
41
+ | '*'
42
+ | {
43
+ [recipe: string]: RecipeRule[]
44
+ }
45
+ /**
46
+ * The css patterns to generate.
47
+ */
48
+ patterns?: {
49
+ [pattern: string]: PatternRule[]
50
+ }
51
+ /**
52
+ * The CSS themes to generate
53
+ */
54
+ themes?: string[]
55
+ }
@@ -0,0 +1,20 @@
1
+ import type { ConditionalValue } from './conditions'
2
+ import type { PropertiesFallback } from './csstype'
3
+ import type { PropertyValue } from './prop-type'
4
+
5
+ type String = string & {}
6
+ type Number = number & {}
7
+
8
+ /* -----------------------------------------------------------------------------
9
+ * Shadowed export (in CLI): DO NOT REMOVE
10
+ * -----------------------------------------------------------------------------*/
11
+
12
+ type CssProperties = PropertiesFallback<String | Number>
13
+
14
+ export type CssVarProperties = {
15
+ [key in `--${string}`]?: ConditionalValue<string | number>
16
+ }
17
+
18
+ export type SystemProperties = {
19
+ [K in keyof CssProperties]?: PropertyValue<K>
20
+ }
@@ -0,0 +1,41 @@
1
+ import type { ConditionDetails } from './conditions'
2
+
3
+ export interface StyleResultObject {
4
+ [key: string]: any
5
+ }
6
+ export interface StyleProps extends StyleResultObject {
7
+ css?: StyleResultObject
8
+ }
9
+
10
+ export interface StyleEntry {
11
+ prop: string
12
+ value: string | number | boolean
13
+ cond: string
14
+ recipe?: string
15
+ slot?: string
16
+ layer?: string
17
+ variants?: boolean
18
+ }
19
+
20
+ export interface AtomicStyleResult {
21
+ result: StyleResultObject
22
+ entry: StyleEntry
23
+ hash: string
24
+ className: string
25
+ conditions?: ConditionDetails[]
26
+ layer?: string
27
+ }
28
+
29
+ export interface GroupedResult extends Pick<AtomicStyleResult, 'result' | 'className'> {
30
+ hashSet: Set<string>
31
+ details: GroupedStyleResultDetails[]
32
+ }
33
+
34
+ export interface RecipeBaseResult extends GroupedResult {
35
+ recipe: string
36
+ slot?: string
37
+ }
38
+
39
+ export interface GroupedStyleResultDetails extends Pick<AtomicStyleResult, 'hash' | 'entry' | 'conditions'> {
40
+ result: StyleResultObject
41
+ }