@pandacss/types 0.0.0-dev-20221222102219 → 0.0.0-dev-20221229135204

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.
@@ -1,7 +1,9 @@
1
- import type { Conditional, NativeCssProperties, Nested } from './system-types'
2
- import type { LiteralUnion, Primitive, Recursive } from './shared'
1
+ import type { CompositionStyleObject } from './system-types'
2
+ import type { LiteralUnion, Recursive } from './shared'
3
3
 
4
- export type Composition<Value = any> = {
4
+ type Cond = Record<string, string>
5
+
6
+ export type Token<Value = any> = {
5
7
  value: Value
6
8
  description?: string
7
9
  }
@@ -41,13 +43,9 @@ type TextStyleProperty = LiteralUnion<
41
43
  | 'textRendering'
42
44
  >
43
45
 
44
- type TCondition = Record<string, string>
45
-
46
- export type TextStyle<T extends TCondition = TCondition> = Nested<{
47
- [K in TextStyleProperty]?: Conditional<T, K extends keyof NativeCssProperties ? NativeCssProperties[K] : Primitive>
48
- }>
46
+ export type TextStyle<Conditions extends Cond = {}> = CompositionStyleObject<Conditions, TextStyleProperty>
49
47
 
50
- export type TextStyles<T extends TCondition = TCondition> = Recursive<Composition<TextStyle<T>>>
48
+ export type TextStyles<T extends Cond = {}> = Recursive<Token<TextStyle<T>>>
51
49
 
52
50
  /* -----------------------------------------------------------------------------
53
51
  * Layer styles
@@ -102,11 +100,5 @@ type LayerStyleProperty = LiteralUnion<
102
100
  | `padding${Placement}`
103
101
  >
104
102
 
105
- export type LayerStyle<Conditions extends TCondition = TCondition> = Nested<{
106
- [K in LayerStyleProperty]?: Conditional<
107
- Conditions,
108
- K extends keyof NativeCssProperties ? NativeCssProperties[K] : Primitive
109
- >
110
- }>
111
-
112
- export type LayerStyles<Conditions extends TCondition = TCondition> = Recursive<Composition<LayerStyle<Conditions>>>
103
+ export type LayerStyle<Conditions extends Cond = {}> = CompositionStyleObject<Conditions, LayerStyleProperty>
104
+ export type LayerStyles<Conditions extends Cond = {}> = Recursive<Token<LayerStyle<Conditions>>>
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export type { PropertyConfig, PropertyTransform, PropertyValues, UtilityConfig }
4
4
  export type { StyleObject, CssKeyframes } from './system-types'
5
5
  export type { PatternConfig, PatternProperty, PatternHelpers } from './pattern'
6
6
  export type { RecipeConfig, RecipeVariant } from './recipe'
7
- export type { Composition, TextStyles, LayerStyles } from './composition'
7
+ export type { TextStyles, LayerStyles } from './composition'
8
8
  export type { Token, TokenCategory, TokenDataTypes, Tokens, SemanticToken, SemanticTokens } from './tokens'
9
9
  export type { Dict, RequiredBy, AnyFunction } from './shared'
10
10
  export type { Parts, Part } from './parts'
@@ -1,8 +1,10 @@
1
1
  import type * as CSS from './csstype'
2
2
 
3
- type Loose<T = string> = T & { __type?: never }
3
+ type Dict<T = unknown> = Record<string, T>
4
4
 
5
- type NeverType = { __type?: 'never' }
5
+ type String = string & {}
6
+
7
+ type Number = number & {}
6
8
 
7
9
  // list of aria states selectors
8
10
  type AriaAttributes =
@@ -40,12 +42,12 @@ type DataAttributes =
40
42
  | '[data-in-range]'
41
43
  | '[data-out-of-range]'
42
44
  | '[data-placeholder-shown]'
43
- | `[data-part=${string}']`
44
- | `[data-attr=${string}']`
45
- | `[data-placement=${string}']`
46
- | `[data-theme=${string}']`
47
- | `[data-size=${string}']`
48
- | `[data-state=${string}']`
45
+ | `[data-part=${string}]`
46
+ | `[data-attr=${string}]`
47
+ | `[data-placement=${string}]`
48
+ | `[data-theme=${string}]`
49
+ | `[data-size=${string}]`
50
+ | `[data-state=${string}]`
49
51
  | '[data-empty]'
50
52
  | '[data-loading]'
51
53
  | '[data-loaded]'
@@ -54,126 +56,158 @@ type DataAttributes =
54
56
  | '[data-exited]'
55
57
  | '[data-exiting]'
56
58
 
57
- type Selectors = `&${CSS.Pseudos | DataAttributes | AriaAttributes}` | `${DataAttributes} &` | `${AriaAttributes} &`
59
+ type AttributeSelector = `&${CSS.Pseudos | DataAttributes | AriaAttributes}`
60
+ type ParentSelector = `${DataAttributes | AriaAttributes} &`
61
+ type AnySelector = `${string}&` | `&${string}`
58
62
 
59
- /**
60
- * We currently allow group css properties for better maintainability.
61
- */
62
- type Grouped<T> = {
63
- selectors?: {
64
- [key in Selectors | Loose]?: T
65
- }
66
- '@media'?: {
67
- [query: string]: T
68
- }
69
- '@container'?: {
70
- [query: string]: T
71
- }
72
- '@supports'?: {
73
- [query: string]: T
74
- }
75
- }
63
+ type Selectors = AttributeSelector | ParentSelector
76
64
 
77
- export type Nested<T> = T & {
78
- [key in Selectors | Loose]?: Nested<T> | Loose<string | number | boolean>
65
+ type ContainerProperties = {
66
+ container?: string
67
+ containerType?: 'size' | 'inline-size' | String
68
+ containerName?: string
79
69
  }
80
70
 
81
71
  /* -----------------------------------------------------------------------------
82
72
  * Native css properties
83
73
  * -----------------------------------------------------------------------------*/
84
74
 
85
- type ContainerProperties = {
86
- container?: string
87
- containerType?: 'size' | 'inline-size' | Loose
88
- containerName?: string
75
+ type CssVarProperties = {
76
+ [key in `--${string}`]?: string | number
89
77
  }
90
78
 
91
- export type NativeCssProperties = CSS.PropertiesFallback<Loose<string | number>> & ContainerProperties
79
+ export type NativeCssProperties = CSS.PropertiesFallback<String | Number> & ContainerProperties & CssVarProperties
92
80
 
93
81
  export type NativeCssProperty = keyof NativeCssProperties
94
82
 
95
- export type CssProperties = NativeCssProperties & {
96
- [property: string]: string | number | boolean | Record<string, any> | undefined
97
- }
83
+ export type CssProperties = NativeCssProperties & CssVarProperties
98
84
 
99
85
  export type CssKeyframes = {
100
- [time: string]: CssProperties
86
+ [name: string]: {
87
+ [time: string]: CssProperties
88
+ }
101
89
  }
102
90
 
103
91
  /* -----------------------------------------------------------------------------
104
92
  * Conditional css properties
105
93
  * -----------------------------------------------------------------------------*/
106
94
 
107
- type TCondition = Record<string, string>
95
+ type Cond = Record<string, string>
108
96
 
109
- export type Conditional<C extends TCondition, V> =
97
+ export type Conditional<C extends Cond, V> =
110
98
  | V
111
- | V[] // responsive array
99
+ | Array<V | null>
112
100
  | {
113
101
  [K in keyof C]?: Conditional<C, V>
114
102
  }
115
103
 
116
- type NestedConditional<C extends TCondition, V> = {
117
- [K in keyof V]?: Conditional<C, V[K]>
104
+ /* -----------------------------------------------------------------------------
105
+ * Groupings and Conditions
106
+ * -----------------------------------------------------------------------------*/
107
+
108
+ /**
109
+ * Group properties for better maintainability
110
+ */
111
+ type Grouped<T> = T & {
112
+ selectors?: {
113
+ [key in Selectors]?: T
114
+ }
115
+ '@media'?: {
116
+ [query: string]: T
117
+ }
118
+ '@container'?: {
119
+ [query: string]: T
120
+ }
121
+ '@supports'?: {
122
+ [query: string]: T
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Support arbitrary nesting of selectors
128
+ */
129
+ type Nested<C extends Cond, P> = P & {
130
+ [K in Selectors | keyof C]?: Nested<C, P>
131
+ } & {
132
+ [K in AnySelector]?: Nested<C, P>
118
133
  }
119
134
 
120
135
  /* -----------------------------------------------------------------------------
121
136
  * Mixed css properties (native + conditional + custom properties)
137
+
138
+ C - condition record
139
+ P - custom properties or utilities
140
+ S - strict mode? true or false
122
141
  * -----------------------------------------------------------------------------*/
123
142
 
124
- type UnionOf<Key extends string, Native extends Record<Key, any>, Custom> = Custom extends NeverType
125
- ? Native[Key]
126
- : Key extends keyof Custom
127
- ? Native[Key] | Custom[Key]
128
- : Native[Key]
143
+ type NativeCssValue<T> = T extends NativeCssProperty ? NativeCssProperties[T] : never
129
144
 
130
- type EitherOf<Key extends string, Native extends Record<Key, any>, Custom> = Key extends keyof Custom
131
- ? Custom[Key]
132
- : Native[Key]
145
+ type NativeProperties<Conditions extends Cond, PropTypes extends Dict, Overrides extends Dict> = {
146
+ [K in Exclude<NativeCssProperty, keyof PropTypes | keyof Overrides>]?: Conditional<Conditions, NativeCssProperties[K]>
147
+ }
133
148
 
134
- type StrictCssProperties<P extends Record<string, any> = NeverType, Strict extends boolean = false> = {
135
- [Key in NativeCssProperty]?: true extends Strict
136
- ? EitherOf<Key, NativeCssProperties, P>
137
- : UnionOf<Key, NativeCssProperties, P>
149
+ type CustomProperties<
150
+ Conditions extends Cond,
151
+ PropTypes extends Dict,
152
+ StrictMode extends boolean,
153
+ Overrides extends Dict,
154
+ > = {
155
+ [K in Exclude<keyof PropTypes, keyof Overrides>]?: Conditional<
156
+ Conditions,
157
+ true extends StrictMode ? PropTypes[K] : PropTypes[K] | NativeCssValue<K>
158
+ >
138
159
  }
139
160
 
140
- type CustomCssProperties<P extends Record<string, any> = NeverType> = {
141
- [Key in keyof Omit<P, NativeCssProperty>]?: P[Key]
161
+ type GenericProperties<Conditions extends Cond> = {
162
+ [key: string]: Conditional<Conditions, boolean | String | Number | undefined>
142
163
  }
143
164
 
144
- type MixedCssProperties<
145
- C extends TCondition = TCondition,
146
- P extends Record<string, any> = NeverType,
147
- S extends boolean = false,
148
- > = NestedConditional<C, StrictCssProperties<P, S>> &
149
- NestedConditional<C, CustomCssProperties<P>> & {
150
- [Key in keyof C]?: MixedCssProperties<Omit<C, Key>, P, S>
151
- }
165
+ type Css<Conditions extends Cond, PropTypes extends Dict, StrictMode extends boolean, Overrides extends Dict> =
166
+ | (Partial<Overrides> &
167
+ NativeProperties<Conditions, PropTypes, Overrides> &
168
+ CustomProperties<Conditions, PropTypes, StrictMode, Overrides>)
169
+ | GenericProperties<Conditions>
152
170
 
153
171
  /* -----------------------------------------------------------------------------
154
172
  * Exported types
155
173
  * -----------------------------------------------------------------------------*/
156
174
 
157
- export type NestedCssProperties = Nested<CssProperties>
175
+ export type NestedCssProperties = Nested<{}, CssProperties>
158
176
 
159
177
  export type StyleObject<
160
- C extends TCondition = TCondition,
161
- P extends Record<string, any> = NeverType,
162
- S extends boolean = false,
163
- > = Nested<MixedCssProperties<C, P, S>> | Grouped<MixedCssProperties<C, P, S>>
164
-
165
- export type JSXStyleProperties<
166
- C extends TCondition = TCondition,
167
- P extends Record<string, any> = NeverType,
168
- S extends boolean = false,
169
- > = Nested<MixedCssProperties<C, P, S>> & {
170
- css?: JSXStyleProperties<C, P, S>
178
+ Conditions extends Cond = {},
179
+ PropTypes extends Dict = {},
180
+ StrictMode extends boolean = false,
181
+ Overrides extends Dict = {},
182
+ > = Grouped<Nested<Conditions, Css<Conditions, PropTypes, StrictMode, Overrides>>>
183
+
184
+ type WithJsxStyleProps<P> = P & {
185
+ css?: P
186
+ sx?: P
171
187
  }
172
188
 
189
+ export type JsxStyleProps<
190
+ Conditions extends Cond = {},
191
+ PropTypes extends Dict = {},
192
+ StrictMode extends boolean = false,
193
+ Overrides extends Dict = {},
194
+ > = WithJsxStyleProps<StyleObject<Conditions, PropTypes, StrictMode, Overrides>>
195
+
173
196
  export type GlobalStyleObject<
174
- C extends TCondition = TCondition,
175
- P extends Record<string, any> = NeverType,
176
- S extends boolean = false,
197
+ Conditions extends Cond = {},
198
+ PropTypes extends Dict = {},
199
+ StrictMode extends boolean = false,
200
+ Overrides extends Dict = {},
177
201
  > = {
178
- [selector: string]: Nested<MixedCssProperties<C, P, S>>
202
+ [selector: string]: StyleObject<Conditions, PropTypes, StrictMode, Overrides>
179
203
  }
204
+
205
+ export type CompositionStyleObject<Conditions extends Cond, PropTypes> = Nested<
206
+ Conditions,
207
+ {
208
+ [K in Extract<PropTypes, string>]?: Conditional<
209
+ Conditions,
210
+ K extends NativeCssProperty ? NativeCssProperties[K] : unknown
211
+ >
212
+ }
213
+ >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/types",
3
- "version": "0.0.0-dev-20221222102219",
3
+ "version": "0.0.0-dev-20221229135204",
4
4
  "description": "The types for css panda",
5
5
  "main": "dist/index.d.ts",
6
6
  "author": "Segun Adebayo <joseshegs@gmail.com>",