@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.
@@ -0,0 +1,535 @@
1
+ import type { TSConfig } from 'pkg-types'
2
+ import type { Conditions, ExtendableConditions } from './conditions'
3
+ import type { BambooHooks } from './hooks'
4
+ import type { PatternConfig } from './pattern'
5
+ import type { Keys, LiteralUnion, PathIn, RequiredBy } from './shared'
6
+ import type { StaticCssOptions } from './static-css'
7
+ import type {
8
+ ExtendableGlobalFontface,
9
+ ExtendableGlobalStyleObject,
10
+ GlobalFontface,
11
+ GlobalStyleObject,
12
+ SystemStyleObject,
13
+ } from './system-types'
14
+ import type { ExtendableTheme, Theme } from './theme'
15
+ import type { ExtendableUtilityConfig, UtilityConfig } from './utility'
16
+
17
+ export type { TSConfig }
18
+
19
+ export type CascadeLayer = 'reset' | 'base' | 'tokens' | 'recipes' | 'utilities'
20
+
21
+ export type CascadeLayers = Record<CascadeLayer, string>
22
+
23
+ export interface StudioOptions {
24
+ /**
25
+ * Used to customize the design system studio
26
+ * @default { title: 'Bamboo', logo: '🎋' }
27
+ */
28
+ studio?: {
29
+ /**
30
+ * The output directory for the design system studio when the build command is run.
31
+ */
32
+ outdir?: string
33
+ /**
34
+ * The logo url for the design system studio.
35
+ */
36
+ logo?: string
37
+ /**
38
+ * Used to inject custom html into the head or body of the studio
39
+ */
40
+ inject?: {
41
+ head?: string
42
+ body?: string
43
+ }
44
+ }
45
+ }
46
+
47
+ export interface Patterns {
48
+ [pattern: string]: PatternConfig
49
+ }
50
+
51
+ export interface PresetCore {
52
+ /**
53
+ * The css selectors or media queries shortcuts.
54
+ * @example `{ hover: "&:hover" }`
55
+ */
56
+ conditions: Conditions
57
+ /**
58
+ * The global styles for your project.
59
+ */
60
+ globalCss: GlobalStyleObject
61
+ /**
62
+ * The global fontface for your project.
63
+ */
64
+ globalFontface?: GlobalFontface
65
+ /**
66
+ * The global custom position try fallback option
67
+ */
68
+ globalPositionTry?: GlobalPositionTry
69
+ /**
70
+ * Used to generate css utility classes for your project.
71
+ */
72
+ staticCss: StaticCssOptions
73
+ /**
74
+ * The theme configuration for your project.
75
+ */
76
+ theme: Theme
77
+ /**
78
+ * The css utility definitions.
79
+ */
80
+ utilities: UtilityConfig
81
+ /**
82
+ * Common styling or layout patterns for your project.
83
+ */
84
+ patterns: Record<string, PatternConfig>
85
+ /**
86
+ * Multiple themes for your project.
87
+ */
88
+ themes?: ThemeVariantsMap
89
+ }
90
+
91
+ interface ExtendablePatterns {
92
+ [pattern: string]: PatternConfig | Patterns | undefined
93
+ extend?: Patterns | undefined
94
+ }
95
+
96
+ interface ExtendableStaticCssOptions extends StaticCssOptions {
97
+ extend?: StaticCssOptions | undefined
98
+ }
99
+
100
+ export type CssPropertySyntax =
101
+ | '*'
102
+ | '<length>'
103
+ | '<number>'
104
+ | '<percentage>'
105
+ | '<length-percentage>'
106
+ | '<color>'
107
+ | '<image>'
108
+ | '<url>'
109
+ | '<integer>'
110
+ | '<angle>'
111
+ | '<time>'
112
+ | '<resolution>'
113
+ | '<transform-function>'
114
+ | '<length> | <percentage>'
115
+
116
+ export interface CssPropertyDefinition {
117
+ /**
118
+ * Controls whether the custom property registration specified by @property inherits by default.
119
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/inherits
120
+ */
121
+ inherits: boolean
122
+ /**
123
+ * Sets the initial value for the property.
124
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/initial-value
125
+ */
126
+ initialValue?: string
127
+ /**
128
+ * Describes the allowable syntax for the property.
129
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax
130
+ */
131
+ syntax: LiteralUnion<CssPropertySyntax>
132
+ }
133
+
134
+ export interface GlobalVarsDefinition {
135
+ [key: string]: string | CssPropertyDefinition
136
+ }
137
+
138
+ interface ExtendableGlobalVars {
139
+ [key: string]: string | CssPropertyDefinition | GlobalVarsDefinition | undefined
140
+ extend?: GlobalVarsDefinition
141
+ }
142
+
143
+ export interface GlobalPositionTry {
144
+ [key: string]: SystemStyleObject
145
+ }
146
+
147
+ interface ExtendableGlobalPositionTry {
148
+ [key: string]: SystemStyleObject | GlobalPositionTry | undefined
149
+ extend?: GlobalPositionTry | undefined
150
+ }
151
+
152
+ export interface ThemeVariant extends Pick<Theme, 'tokens' | 'semanticTokens'> {}
153
+
154
+ export interface ThemeVariantsMap {
155
+ [name: string]: ThemeVariant
156
+ }
157
+
158
+ interface ExtendableThemeVariantsMap {
159
+ [name: string]: ThemeVariantsMap | ThemeVariant | undefined
160
+ extend?: ThemeVariantsMap | undefined
161
+ }
162
+
163
+ export interface ExtendableOptions {
164
+ /**
165
+ * The css selectors or media queries shortcuts.
166
+ * @example `{ hover: "&:hover" }`
167
+ */
168
+ conditions?: ExtendableConditions
169
+ /**
170
+ * The global styles for your project.
171
+ */
172
+ globalCss?: ExtendableGlobalStyleObject
173
+ /**
174
+ * The global fontface for your project.
175
+ */
176
+ globalFontface?: ExtendableGlobalFontface
177
+ /**
178
+ * The global custom position try fallback option
179
+ */
180
+ globalPositionTry?: ExtendableGlobalPositionTry
181
+ /**
182
+ * Used to generate css utility classes for your project.
183
+ */
184
+ staticCss?: ExtendableStaticCssOptions
185
+ /**
186
+ * The theme configuration for your project.
187
+ */
188
+ theme?: ExtendableTheme
189
+ /**
190
+ * The css utility definitions.
191
+ */
192
+ utilities?: ExtendableUtilityConfig
193
+ /**
194
+ * Common styling or layout patterns for your project.
195
+ */
196
+ patterns?: ExtendablePatterns
197
+ /**
198
+ * The css variables for your project.
199
+ */
200
+ globalVars?: ExtendableGlobalVars
201
+ /**
202
+ * The theme variants for your project.
203
+ */
204
+ themes?: ExtendableThemeVariantsMap
205
+ }
206
+
207
+ export interface ImportMapInput {
208
+ css?: string | string[]
209
+ recipes?: string | string[]
210
+ patterns?: string | string[]
211
+ jsx?: string | string[]
212
+ tokens?: string | string[]
213
+ }
214
+
215
+ export interface ImportMapOutput<T = string> {
216
+ css: T[]
217
+ recipe: T[]
218
+ pattern: T[]
219
+ jsx: T[]
220
+ tokens: T[]
221
+ }
222
+
223
+ type ImportMapOption = string | ImportMapInput
224
+
225
+ interface FileSystemOptions {
226
+ /**
227
+ * Whether to clean the output directory before generating the css.
228
+ * @default false
229
+ */
230
+ clean?: boolean
231
+ /**
232
+ * The output directory.
233
+ * @default 'styled-system'
234
+ */
235
+ outdir?: string
236
+ /**
237
+ * Allows you to customize the import paths for the generated outdir.
238
+ * @default
239
+ * ```js
240
+ * {
241
+ * css: 'styled-system/css',
242
+ * recipes: 'styled-system/recipes',
243
+ * patterns: 'styled-system/patterns',
244
+ * jsx: 'styled-system/jsx',
245
+ * }
246
+ * ```
247
+ */
248
+ importMap?: ImportMapOption | Array<ImportMapOption>
249
+ /**
250
+ * List of files glob to watch for changes.
251
+ * @default []
252
+ */
253
+ include?: string[]
254
+ /**
255
+ * List of files glob to ignore.
256
+ * @default []
257
+ */
258
+ exclude?: string[]
259
+ /**
260
+ * List of globs or files that will trigger a config reload when changed.
261
+ *
262
+ * We automatically track the config file and (transitive) files imported by the config file as much as possible, but sometimes we might miss some.
263
+ * Use this option as a workaround.
264
+ */
265
+ dependencies?: string[]
266
+ /**
267
+ * Whether to watch for changes and regenerate the css.
268
+ * @default false
269
+ */
270
+ watch?: boolean
271
+ /**
272
+ * Whether to use polling instead of filesystem events when watching.
273
+ * @default false
274
+ */
275
+ poll?: boolean
276
+ /**
277
+ * The current working directory.
278
+ * @default 'process.cwd()'
279
+ */
280
+ cwd?: string
281
+ /**
282
+ * The log level for the built-in logger.
283
+ * @default 'info'
284
+ */
285
+ logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent'
286
+ }
287
+
288
+ export type JsxFramework = 'react' | 'solid' | 'preact' | 'vue' | 'qwik'
289
+
290
+ interface JsxOptions {
291
+ /**
292
+ * The framework to use for generating supercharged elements.
293
+ */
294
+ jsxFramework?: JsxFramework | (string & {})
295
+ /**
296
+ * The factory name of the element
297
+ * @default 'styled'
298
+ *
299
+ * @example
300
+ * ```jsx
301
+ * <styled.button marginTop="40px">Click me</styled.button>
302
+ * ```
303
+ */
304
+ jsxFactory?: string
305
+ /**
306
+ * The style props allowed on generated JSX components
307
+ * - When set to 'all', all style props are allowed.
308
+ * - When set to 'minimal', only the `css` prop is allowed.
309
+ * - When set to 'none', no style props are allowed and therefore the jsxFactory will not be importable.
310
+ *
311
+ * @default 'all'
312
+ *
313
+ * @example with 'all':
314
+ * ```jsx
315
+ * <styled.button marginTop="40px">Click me</styled.button>
316
+ * ```
317
+ *
318
+ * @example with 'minimal':
319
+ * ```jsx
320
+ * <styled.button css={{ marginTop: "40px" }}>Click me</styled.button>
321
+ * ```
322
+ *
323
+ * @example with 'none':
324
+ * ```jsx
325
+ * <button className={css({ marginTop: "40px" })}>Click me</button>
326
+ * ```
327
+ */
328
+ jsxStyleProps?: 'all' | 'minimal' | 'none'
329
+ }
330
+
331
+ interface CssgenOptions {
332
+ /**
333
+ * Whether to include css reset styles in the generated css.
334
+ * @default false
335
+ */
336
+ preflight?: boolean | { scope: string; level?: 'element' | 'parent' }
337
+ /**
338
+ * The namespace prefix for the generated css classes and css variables.
339
+ * @default ''
340
+ */
341
+ prefix?: string | { cssVar?: string; className?: string }
342
+ /**
343
+ * The value separator used in the generated class names.
344
+ * @default '_'
345
+ */
346
+ separator?: '_' | '=' | '-'
347
+ /**
348
+ * Whether to minify the generated css.
349
+ * @default false
350
+ */
351
+ minify?: boolean
352
+ /**
353
+ * The root selector for the css variables.
354
+ * @default ':where(:host, :root)'
355
+ */
356
+ cssVarRoot?: string
357
+ /**
358
+ * The css syntax kind to use
359
+ * @default 'object-literal'
360
+ */
361
+ syntax?: 'template-literal' | 'object-literal'
362
+ /**
363
+ * Whether to use `lightningcss` instead of `postcss` for css optimization.
364
+ * @default false
365
+ */
366
+ lightningcss?: boolean
367
+ /**
368
+ * Browserslist query to target specific browsers.
369
+ * @see https://www.npmjs.com/package/browserslist
370
+ */
371
+ browserslist?: string[]
372
+ /**
373
+ * Layer mappings used in the generated css.
374
+ * @default 'true'
375
+ */
376
+ layers?: Partial<CascadeLayers>
377
+ /**
378
+ * Polyfill CSS @layers at-rules for older browsers.
379
+ * @default 'false'
380
+ * @see https://www.npmjs.com/package/@csstools/postcss-cascade-layers
381
+ */
382
+ polyfill?: boolean
383
+ }
384
+
385
+ interface CodegenOptions {
386
+ /**
387
+ * Whether to only emit the `tokens` directory
388
+ * @default false
389
+ */
390
+ emitTokensOnly?: boolean
391
+ /**
392
+ * Whether to hash the generated class names / css variables.
393
+ * This is useful if want to shorten the class names or css variables.
394
+ * @default false
395
+ */
396
+ hash?: boolean | { cssVar: boolean; className: boolean }
397
+ /**
398
+ * Change generated typescript definitions to be more strict for property having a token or utility.
399
+ */
400
+ strictTokens?: boolean
401
+ /**
402
+ * Change generated typescript definitions to be more strict for built-in CSS properties to only allow valid CSS values.
403
+ */
404
+ strictPropertyValues?: boolean
405
+ /**
406
+ * Whether to update the .gitignore file.
407
+ * @default 'true'
408
+ */
409
+ gitignore?: boolean
410
+ /**
411
+ * Whether to allow shorthand properties
412
+ * @default 'true'
413
+ */
414
+ shorthands?: boolean
415
+ /**
416
+ * File extension for generated javascript files.
417
+ * @default 'mjs'
418
+ */
419
+ outExtension?: 'mjs' | 'js'
420
+ /**
421
+ * Whether to force consistent type extensions for generated typescript .d.ts files.
422
+ * If set to `true` and `outExtension` is set to `mjs`, the generated typescript .d.ts files will have the extension `.d.mts`.
423
+ * @default false
424
+ */
425
+ forceConsistentTypeExtension?: boolean
426
+ /**
427
+ * Controls how CSS utility classes are generated.
428
+ * - `'atomic'` (default): one class per property (e.g. `c_red p_8px`)
429
+ * - `'grouped'`: one class per `css()` call, grouping all properties together
430
+ *
431
+ * Grouped mode reduces the number of classes in the HTML at the cost of potential CSS duplication.
432
+ * @default 'atomic'
433
+ */
434
+ cssMode?: 'atomic' | 'grouped'
435
+ }
436
+
437
+ interface PresetOptions {
438
+ /**
439
+ * Used to create reusable config presets for your project or team.
440
+ */
441
+ presets?: (string | Preset | Promise<Preset>)[]
442
+ }
443
+
444
+ export interface HooksOptions {
445
+ hooks?: Partial<BambooHooks>
446
+ }
447
+
448
+ export interface BambooPlugin extends HooksOptions {
449
+ name: string
450
+ }
451
+
452
+ export interface PluginsOptions {
453
+ plugins?: BambooPlugin[]
454
+ }
455
+
456
+ export interface Config
457
+ extends
458
+ StudioOptions,
459
+ ExtendableOptions,
460
+ CssgenOptions,
461
+ CodegenOptions,
462
+ FileSystemOptions,
463
+ JsxOptions,
464
+ PresetOptions,
465
+ HooksOptions,
466
+ PluginsOptions {
467
+ /**
468
+ * Whether to opt-out of the defaults config presets: [`@bamboocss/preset-base`, `@bamboocss/preset-bamboo`]
469
+ * @default 'false'
470
+ */
471
+ eject?: boolean
472
+ /**
473
+ * The validation strictness to use when validating the config.
474
+ * - When set to 'none', no validation will be performed.
475
+ * - When set to 'warn', warnings will be logged when validation fails.
476
+ * - When set to 'error', errors will be thrown when validation fails.
477
+ *
478
+ * @default 'warn'
479
+ */
480
+ validation?: 'none' | 'warn' | 'error'
481
+ }
482
+
483
+ export interface Preset extends ExtendableOptions, PresetOptions {
484
+ name: string
485
+ }
486
+
487
+ export interface UserConfig
488
+ extends Partial<PresetCore>, RequiredBy<Omit<Config, keyof PresetCore>, 'outdir' | 'cwd' | 'include'> {}
489
+
490
+ export interface PathMapping {
491
+ pattern: RegExp
492
+ paths: string[]
493
+ }
494
+
495
+ export interface ConfigTsOptions {
496
+ baseUrl?: string | undefined
497
+ pathMappings: PathMapping[]
498
+ }
499
+
500
+ export interface LoadTsConfigResult {
501
+ tsconfig?: TSConfig
502
+ tsOptions?: ConfigTsOptions
503
+ tsconfigFile?: string
504
+ }
505
+
506
+ export interface LoadConfigResult extends LoadTsConfigResult {
507
+ /** Config path */
508
+ path: string
509
+ config: UserConfig
510
+ serialized: string
511
+ deserialize: () => Config
512
+ dependencies: string[]
513
+ hooks: Partial<BambooHooks>
514
+ }
515
+
516
+ export interface HashOptions {
517
+ tokens: boolean | undefined
518
+ className: boolean | undefined
519
+ }
520
+
521
+ export interface PrefixOptions {
522
+ tokens: string | undefined
523
+ className: string | undefined
524
+ }
525
+
526
+ type ReqConf = Required<UserConfig>
527
+
528
+ export type ConfigPath = Exclude<
529
+ | Exclude<NonNullable<Keys<ReqConf>>, 'theme'>
530
+ | PathIn<ReqConf, 'theme'>
531
+ | PathIn<ReqConf, 'patterns'>
532
+ | PathIn<ReqConf, 'staticCss'>
533
+ | (string & {}),
534
+ undefined
535
+ >