typestyles 0.2.0 → 0.4.0

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/index.d.cts CHANGED
@@ -10,11 +10,36 @@ type CSSValue = string | number;
10
10
  * Extends csstype's Properties with nesting capabilities.
11
11
  */
12
12
  interface CSSProperties extends CSS.Properties<CSSValue> {
13
- /** Nested selector (e.g., '&:hover', '& .child', '&::before') */
13
+ /** Nested selector (e.g., '&:hover', '& .child', '&::before', '&[data-variant]') */
14
14
  [selector: `&${string}`]: CSSProperties;
15
+ /** Attribute selector (e.g., '[data-variant]', '[data-variant="primary"]', '[disabled]') */
16
+ [attribute: `[${string}]`]: CSSProperties;
15
17
  /** At-rule (e.g., '@media (max-width: 768px)', '@container', '@supports') */
16
18
  [atRule: `@${string}`]: CSSProperties;
17
19
  }
20
+ /**
21
+ * Utility function map used by styles.withUtils().
22
+ * Each key becomes an extra style property that expands into CSSProperties.
23
+ */
24
+ type BivariantCallback<Arg, Ret> = {
25
+ bivarianceHack(value: Arg): Ret;
26
+ }['bivarianceHack'];
27
+ type StyleUtils = Record<string, BivariantCallback<unknown, CSSProperties>>;
28
+ type UtilityValue<U extends StyleUtils, K extends keyof U> = U[K] extends (value: infer V) => CSSProperties ? V : never;
29
+ /**
30
+ * CSS properties augmented with user-defined utility keys.
31
+ */
32
+ type CSSPropertiesWithUtils<U extends StyleUtils> = CSS.Properties<CSSValue> & {
33
+ [K in keyof U]?: UtilityValue<U, K>;
34
+ } & {
35
+ [selector: `&${string}`]: CSSPropertiesWithUtils<U>;
36
+ [attribute: `[${string}]`]: CSSPropertiesWithUtils<U>;
37
+ [atRule: `@${string}`]: CSSPropertiesWithUtils<U>;
38
+ };
39
+ /**
40
+ * A map of style names to utility-aware CSS property definitions.
41
+ */
42
+ type StyleDefinitionsWithUtils<U extends StyleUtils> = Record<string, CSSPropertiesWithUtils<U>>;
18
43
  /**
19
44
  * A map of variant names to their CSS property definitions.
20
45
  */
@@ -48,7 +73,16 @@ type KeyframeStops$1 = Record<string, CSSProperties>;
48
73
  /**
49
74
  * A map of variant dimensions to their options (each option maps to CSSProperties).
50
75
  */
76
+ type VariantDimensions = Record<string, Record<string, unknown>>;
51
77
  type VariantDefinitions = Record<string, Record<string, CSSProperties>>;
78
+ type SlotStyles<S extends string> = Partial<Record<S, CSSProperties>>;
79
+ type SlotVariantDefinitions<S extends string> = Record<string, Record<string, SlotStyles<S>>>;
80
+ type VariantOptionKey<V extends VariantDimensions, K extends keyof V> = Extract<keyof V[K], string>;
81
+ type VariantSelectionValue<OptionKey extends string> = OptionKey | (Extract<OptionKey, 'true'> extends never ? never : true) | (Extract<OptionKey, 'false'> extends never ? never : false);
82
+ type CompoundSelectionValue<OptionKey extends string> = VariantSelectionValue<OptionKey> | readonly VariantSelectionValue<OptionKey>[];
83
+ type ComponentSelections<V extends VariantDimensions> = {
84
+ [K in keyof V]?: VariantSelectionValue<VariantOptionKey<V, K>> | null | undefined;
85
+ };
52
86
  /**
53
87
  * The full config object passed to styles.component().
54
88
  */
@@ -57,20 +91,29 @@ type ComponentConfig<V extends VariantDefinitions> = {
57
91
  variants?: V;
58
92
  compoundVariants?: Array<{
59
93
  variants: {
60
- [K in keyof V]?: keyof V[K];
94
+ [K in keyof V]?: CompoundSelectionValue<VariantOptionKey<V, K>>;
61
95
  };
62
96
  style: CSSProperties;
63
97
  }>;
64
- defaultVariants?: {
65
- [K in keyof V]?: keyof V[K];
66
- };
98
+ defaultVariants?: ComponentSelections<V>;
67
99
  };
68
100
  /**
69
101
  * The function returned by styles.component().
70
102
  */
71
- type ComponentFunction<V extends VariantDefinitions> = (selections?: {
72
- [K in keyof V]?: keyof V[K] | false | null | undefined;
73
- }) => string;
103
+ type ComponentFunction<V extends VariantDefinitions> = (selections?: ComponentSelections<V>) => string;
104
+ type SlotComponentConfig<S extends string, V extends SlotVariantDefinitions<S>> = {
105
+ slots: readonly S[];
106
+ base?: SlotStyles<S>;
107
+ variants?: V;
108
+ compoundVariants?: Array<{
109
+ variants: {
110
+ [K in keyof V]?: CompoundSelectionValue<VariantOptionKey<V, K>>;
111
+ };
112
+ style: SlotStyles<S>;
113
+ }>;
114
+ defaultVariants?: ComponentSelections<V>;
115
+ };
116
+ type SlotComponentFunction<S extends string, V extends SlotVariantDefinitions<S>> = (selections?: ComponentSelections<V>) => Record<S, string>;
74
117
  /**
75
118
  * A reference to a CSS custom property created by createVar().
76
119
  * The string value is `var(--ts-N)` and can be used directly as a CSS value.
@@ -89,11 +132,11 @@ type CSSVarRef = `var(--${string})`;
89
132
  * },
90
133
  * });
91
134
  *
92
- * type ButtonProps = RecipeVariants<typeof button>;
135
+ * type ButtonProps = ComponentVariants<typeof button>;
93
136
  * // { intent?: 'primary' | 'ghost'; size?: 'sm' | 'lg' }
94
137
  * ```
95
138
  */
96
- type RecipeVariants<T> = T extends ComponentFunction<infer V> ? {
139
+ type ComponentVariants<T> = T extends (selections?: ComponentSelections<infer V>) => unknown ? {
97
140
  [K in keyof V]?: keyof V[K];
98
141
  } : never;
99
142
  /**
@@ -109,25 +152,70 @@ type FontFaceProps = {
109
152
  };
110
153
 
111
154
  /**
112
- * Create a style group and return a selector function.
155
+ * Create a single class with the given styles. Returns the class name string.
156
+ * Use this when you don't need variants — just a class with typed CSS properties.
113
157
  *
114
- * The selector function accepts variant names and returns a composed
115
- * class name string. Class names are deterministic and human-readable:
116
- * `{namespace}-{variant}`.
158
+ * @example
159
+ * ```ts
160
+ * const card = styles.class('card', {
161
+ * padding: '1rem',
162
+ * borderRadius: '0.5rem',
163
+ * backgroundColor: 'white',
164
+ * '&:hover': { boxShadow: '0 4px 6px rgb(0 0 0 / 0.1)' },
165
+ * });
166
+ *
167
+ * <div className={card} /> // class="card"
168
+ * ```
169
+ */
170
+ declare function createClass(name: string, properties: CSSProperties): string;
171
+ /**
172
+ * Create a deterministic hashed class from a style object.
173
+ * The same style object shape+values always returns the same class name.
174
+ *
175
+ * Optional `label` is appended as a readable prefix for debugging.
117
176
  *
118
177
  * @example
119
178
  * ```ts
120
- * const button = createStyles('button', {
121
- * base: { padding: '8px 16px', fontSize: '14px' },
122
- * primary: { backgroundColor: '#0066ff', color: '#fff' },
123
- * large: { padding: '12px 24px', fontSize: '16px' },
179
+ * const button = styles.hashClass({
180
+ * padding: '8px 12px',
181
+ * borderRadius: '8px',
182
+ * });
183
+ *
184
+ * const danger = styles.hashClass(
185
+ * { backgroundColor: 'red', color: 'white' },
186
+ * 'danger'
187
+ * );
188
+ * ```
189
+ */
190
+ declare function createHashClass(properties: CSSProperties, label?: string): string;
191
+ /**
192
+ * Create a style group and return a selector function.
193
+ *
194
+ * **Two-argument form** (definitions object with 'base' and variants):
195
+ * ```ts
196
+ * const button = styles.create('button', {
197
+ * base: { padding: '8px 16px' },
198
+ * primary: { backgroundColor: '#0066ff' },
124
199
  * });
200
+ * button('base', 'primary') // "button-base button-primary"
201
+ * ```
125
202
  *
126
- * button('base', 'primary') // "button-base button-primary"
127
- * button('base', isLarge && 'large') // conditional application
203
+ * **Three-argument form** (base styles + variants, no 'base' key needed):
204
+ * ```ts
205
+ * const button = styles.create('button',
206
+ * { padding: '8px 16px', borderRadius: '6px' }, // base styles
207
+ * {
208
+ * default: { backgroundColor: '#0066ff', color: '#fff' },
209
+ * outline: { border: '1px solid', backgroundColor: 'transparent' },
210
+ * large: { padding: '12px 24px' },
211
+ * }
212
+ * );
213
+ * button('default') // "button-base button-default" — base always included
214
+ * button('outline', 'large') // "button-base button-outline button-large"
128
215
  * ```
129
216
  */
130
217
  declare function createStyles<K extends string>(namespace: string, definitions: StyleDefinitions & Record<K, CSSProperties>): SelectorFunction<K>;
218
+ declare function createStyles(namespace: string, base: CSSProperties, variants: Record<string, CSSProperties>): SelectorFunction<string>;
131
219
  /**
132
220
  * Compose multiple selector functions or class strings into one.
133
221
  * Returns a new SelectorFunction that calls all inputs and joins results.
@@ -142,9 +230,35 @@ declare function createStyles<K extends string>(namespace: string, definitions:
142
230
  * ```
143
231
  */
144
232
  type AnySelectorFunction = {
145
- (...args: any[]): string;
233
+ (...args: unknown[]): string;
146
234
  };
147
235
  declare function compose(...selectors: Array<AnySelectorFunction | string | false | null | undefined>): AnySelectorFunction;
236
+ type StylesWithUtilsApi<U extends StyleUtils> = {
237
+ class: (name: string, properties: CSSPropertiesWithUtils<U>) => string;
238
+ hashClass: (properties: CSSPropertiesWithUtils<U>, label?: string) => string;
239
+ create: {
240
+ <K extends string>(namespace: string, definitions: StyleDefinitionsWithUtils<U> & Record<K, CSSPropertiesWithUtils<U>>): SelectorFunction<K>;
241
+ (namespace: string, base: CSSPropertiesWithUtils<U>, variants: Record<string, CSSPropertiesWithUtils<U>>): SelectorFunction<string>;
242
+ };
243
+ compose: typeof compose;
244
+ };
245
+ /**
246
+ * Create a utility-aware styles API, similar to Stitches' `utils`.
247
+ *
248
+ * @example
249
+ * ```ts
250
+ * const u = createStylesWithUtils({
251
+ * marginX: (value: string | number) => ({ marginLeft: value, marginRight: value }),
252
+ * size: (value: string | number) => ({ width: value, height: value }),
253
+ * });
254
+ *
255
+ * const card = u.class('card', {
256
+ * size: 40,
257
+ * marginX: 16,
258
+ * });
259
+ * ```
260
+ */
261
+ declare function createStylesWithUtils<U extends StyleUtils>(utils: U): StylesWithUtilsApi<U>;
148
262
 
149
263
  /**
150
264
  * Create design tokens as CSS custom properties.
@@ -362,7 +476,7 @@ declare namespace colorFns {
362
476
  /**
363
477
  * Create a multi-variant component style and return a selector function.
364
478
  *
365
- * Class naming convention:
479
+ * Class naming convention (default `semantic` mode; see `configureClassNaming`):
366
480
  * base → `{namespace}-base`
367
481
  * variants.intent.primary → `{namespace}-intent-primary`
368
482
  * compoundVariants[0] → `{namespace}-compound-0`
@@ -393,6 +507,7 @@ declare namespace colorFns {
393
507
  * ```
394
508
  */
395
509
  declare function createComponent<V extends VariantDefinitions>(namespace: string, config: ComponentConfig<V>): ComponentFunction<V>;
510
+ declare function createComponent<S extends string, V extends SlotVariantDefinitions<S>>(namespace: string, config: SlotComponentConfig<S, V>): SlotComponentFunction<S, V>;
396
511
 
397
512
  /**
398
513
  * Apply styles to an arbitrary CSS selector.
@@ -467,6 +582,34 @@ declare function createVar(): CSSVarRef;
467
582
  */
468
583
  declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<string, string>;
469
584
 
585
+ /**
586
+ * How generated class names are formed for `styles.create`, `styles.class`,
587
+ * `styles.component`, and related APIs.
588
+ *
589
+ * - `semantic` — readable names like `button-base`, `button-intent-primary` (default).
590
+ * - `hashed` — stable hash from namespace, variant segment, and declarations, with a short namespace slug for debugging.
591
+ * - `atomic` — hash-only names (shortest); same collision properties as `hashed` when `scopeId` differs.
592
+ */
593
+ type ClassNamingMode = 'semantic' | 'hashed' | 'atomic';
594
+ type ClassNamingConfig = {
595
+ mode: ClassNamingMode;
596
+ /** Prefix for hashed / atomic output and for `hashClass`. Default `ts`. */
597
+ prefix: string;
598
+ /**
599
+ * Optional package or app id mixed into hash input so identical logical
600
+ * names from different packages do not produce the same class string.
601
+ */
602
+ scopeId: string;
603
+ };
604
+ declare function getClassNamingConfig(): Readonly<ClassNamingConfig>;
605
+ /**
606
+ * Set global class naming options. Call once at app or package entry
607
+ * (e.g. design-system `index.ts`) for per-package adoption in a monorepo.
608
+ */
609
+ declare function configureClassNaming(partial: Partial<ClassNamingConfig>): void;
610
+ /** Restore defaults (primarily for tests). */
611
+ declare function resetClassNaming(): void;
612
+
470
613
  /**
471
614
  * Style creation API.
472
615
  *
@@ -477,12 +620,17 @@ declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<st
477
620
  * primary: { backgroundColor: '#0066ff' },
478
621
  * });
479
622
  *
480
- * <button className={button('base', 'primary')}>
623
+ * const hashed = styles.hashClass({ display: 'inline-flex' }, 'button');
624
+ *
625
+ * <button className={`${button('base', 'primary')} ${hashed}`}>
481
626
  * ```
482
627
  */
483
628
  declare const styles: {
484
629
  readonly create: typeof createStyles;
630
+ readonly class: typeof createClass;
631
+ readonly hashClass: typeof createHashClass;
485
632
  readonly component: typeof createComponent;
633
+ readonly withUtils: typeof createStylesWithUtils;
486
634
  readonly compose: typeof compose;
487
635
  };
488
636
  /**
@@ -550,4 +698,4 @@ declare const keyframes: {
550
698
  */
551
699
  declare const color: typeof colorFns;
552
700
 
553
- export { type CSSProperties, type CSSValue, type CSSVarRef, type ColorMixSpace, type ComponentConfig, type ComponentFunction, type FontFaceProps, type KeyframeStops$1 as KeyframeStops, type RecipeVariants, type SelectorFunction, type StyleDefinitions, type ThemeOverrides, type TokenRef, type TokenValues, type VariantDefinitions, assignVars, color, createVar, global, keyframes, styles, tokens };
701
+ export { type CSSProperties, type CSSPropertiesWithUtils, type CSSValue, type CSSVarRef, type ClassNamingConfig, type ClassNamingMode, type ColorMixSpace, type ComponentConfig, type ComponentFunction, type ComponentVariants, type FontFaceProps, type KeyframeStops$1 as KeyframeStops, type SelectorFunction, type SlotComponentConfig, type SlotComponentFunction, type SlotStyles, type SlotVariantDefinitions, type StyleDefinitions, type StyleDefinitionsWithUtils, type StyleUtils, type ThemeOverrides, type TokenRef, type TokenValues, type VariantDefinitions, assignVars, color, configureClassNaming, createVar, getClassNamingConfig, global, keyframes, resetClassNaming, styles, tokens };
package/dist/index.d.ts CHANGED
@@ -10,11 +10,36 @@ type CSSValue = string | number;
10
10
  * Extends csstype's Properties with nesting capabilities.
11
11
  */
12
12
  interface CSSProperties extends CSS.Properties<CSSValue> {
13
- /** Nested selector (e.g., '&:hover', '& .child', '&::before') */
13
+ /** Nested selector (e.g., '&:hover', '& .child', '&::before', '&[data-variant]') */
14
14
  [selector: `&${string}`]: CSSProperties;
15
+ /** Attribute selector (e.g., '[data-variant]', '[data-variant="primary"]', '[disabled]') */
16
+ [attribute: `[${string}]`]: CSSProperties;
15
17
  /** At-rule (e.g., '@media (max-width: 768px)', '@container', '@supports') */
16
18
  [atRule: `@${string}`]: CSSProperties;
17
19
  }
20
+ /**
21
+ * Utility function map used by styles.withUtils().
22
+ * Each key becomes an extra style property that expands into CSSProperties.
23
+ */
24
+ type BivariantCallback<Arg, Ret> = {
25
+ bivarianceHack(value: Arg): Ret;
26
+ }['bivarianceHack'];
27
+ type StyleUtils = Record<string, BivariantCallback<unknown, CSSProperties>>;
28
+ type UtilityValue<U extends StyleUtils, K extends keyof U> = U[K] extends (value: infer V) => CSSProperties ? V : never;
29
+ /**
30
+ * CSS properties augmented with user-defined utility keys.
31
+ */
32
+ type CSSPropertiesWithUtils<U extends StyleUtils> = CSS.Properties<CSSValue> & {
33
+ [K in keyof U]?: UtilityValue<U, K>;
34
+ } & {
35
+ [selector: `&${string}`]: CSSPropertiesWithUtils<U>;
36
+ [attribute: `[${string}]`]: CSSPropertiesWithUtils<U>;
37
+ [atRule: `@${string}`]: CSSPropertiesWithUtils<U>;
38
+ };
39
+ /**
40
+ * A map of style names to utility-aware CSS property definitions.
41
+ */
42
+ type StyleDefinitionsWithUtils<U extends StyleUtils> = Record<string, CSSPropertiesWithUtils<U>>;
18
43
  /**
19
44
  * A map of variant names to their CSS property definitions.
20
45
  */
@@ -48,7 +73,16 @@ type KeyframeStops$1 = Record<string, CSSProperties>;
48
73
  /**
49
74
  * A map of variant dimensions to their options (each option maps to CSSProperties).
50
75
  */
76
+ type VariantDimensions = Record<string, Record<string, unknown>>;
51
77
  type VariantDefinitions = Record<string, Record<string, CSSProperties>>;
78
+ type SlotStyles<S extends string> = Partial<Record<S, CSSProperties>>;
79
+ type SlotVariantDefinitions<S extends string> = Record<string, Record<string, SlotStyles<S>>>;
80
+ type VariantOptionKey<V extends VariantDimensions, K extends keyof V> = Extract<keyof V[K], string>;
81
+ type VariantSelectionValue<OptionKey extends string> = OptionKey | (Extract<OptionKey, 'true'> extends never ? never : true) | (Extract<OptionKey, 'false'> extends never ? never : false);
82
+ type CompoundSelectionValue<OptionKey extends string> = VariantSelectionValue<OptionKey> | readonly VariantSelectionValue<OptionKey>[];
83
+ type ComponentSelections<V extends VariantDimensions> = {
84
+ [K in keyof V]?: VariantSelectionValue<VariantOptionKey<V, K>> | null | undefined;
85
+ };
52
86
  /**
53
87
  * The full config object passed to styles.component().
54
88
  */
@@ -57,20 +91,29 @@ type ComponentConfig<V extends VariantDefinitions> = {
57
91
  variants?: V;
58
92
  compoundVariants?: Array<{
59
93
  variants: {
60
- [K in keyof V]?: keyof V[K];
94
+ [K in keyof V]?: CompoundSelectionValue<VariantOptionKey<V, K>>;
61
95
  };
62
96
  style: CSSProperties;
63
97
  }>;
64
- defaultVariants?: {
65
- [K in keyof V]?: keyof V[K];
66
- };
98
+ defaultVariants?: ComponentSelections<V>;
67
99
  };
68
100
  /**
69
101
  * The function returned by styles.component().
70
102
  */
71
- type ComponentFunction<V extends VariantDefinitions> = (selections?: {
72
- [K in keyof V]?: keyof V[K] | false | null | undefined;
73
- }) => string;
103
+ type ComponentFunction<V extends VariantDefinitions> = (selections?: ComponentSelections<V>) => string;
104
+ type SlotComponentConfig<S extends string, V extends SlotVariantDefinitions<S>> = {
105
+ slots: readonly S[];
106
+ base?: SlotStyles<S>;
107
+ variants?: V;
108
+ compoundVariants?: Array<{
109
+ variants: {
110
+ [K in keyof V]?: CompoundSelectionValue<VariantOptionKey<V, K>>;
111
+ };
112
+ style: SlotStyles<S>;
113
+ }>;
114
+ defaultVariants?: ComponentSelections<V>;
115
+ };
116
+ type SlotComponentFunction<S extends string, V extends SlotVariantDefinitions<S>> = (selections?: ComponentSelections<V>) => Record<S, string>;
74
117
  /**
75
118
  * A reference to a CSS custom property created by createVar().
76
119
  * The string value is `var(--ts-N)` and can be used directly as a CSS value.
@@ -89,11 +132,11 @@ type CSSVarRef = `var(--${string})`;
89
132
  * },
90
133
  * });
91
134
  *
92
- * type ButtonProps = RecipeVariants<typeof button>;
135
+ * type ButtonProps = ComponentVariants<typeof button>;
93
136
  * // { intent?: 'primary' | 'ghost'; size?: 'sm' | 'lg' }
94
137
  * ```
95
138
  */
96
- type RecipeVariants<T> = T extends ComponentFunction<infer V> ? {
139
+ type ComponentVariants<T> = T extends (selections?: ComponentSelections<infer V>) => unknown ? {
97
140
  [K in keyof V]?: keyof V[K];
98
141
  } : never;
99
142
  /**
@@ -109,25 +152,70 @@ type FontFaceProps = {
109
152
  };
110
153
 
111
154
  /**
112
- * Create a style group and return a selector function.
155
+ * Create a single class with the given styles. Returns the class name string.
156
+ * Use this when you don't need variants — just a class with typed CSS properties.
113
157
  *
114
- * The selector function accepts variant names and returns a composed
115
- * class name string. Class names are deterministic and human-readable:
116
- * `{namespace}-{variant}`.
158
+ * @example
159
+ * ```ts
160
+ * const card = styles.class('card', {
161
+ * padding: '1rem',
162
+ * borderRadius: '0.5rem',
163
+ * backgroundColor: 'white',
164
+ * '&:hover': { boxShadow: '0 4px 6px rgb(0 0 0 / 0.1)' },
165
+ * });
166
+ *
167
+ * <div className={card} /> // class="card"
168
+ * ```
169
+ */
170
+ declare function createClass(name: string, properties: CSSProperties): string;
171
+ /**
172
+ * Create a deterministic hashed class from a style object.
173
+ * The same style object shape+values always returns the same class name.
174
+ *
175
+ * Optional `label` is appended as a readable prefix for debugging.
117
176
  *
118
177
  * @example
119
178
  * ```ts
120
- * const button = createStyles('button', {
121
- * base: { padding: '8px 16px', fontSize: '14px' },
122
- * primary: { backgroundColor: '#0066ff', color: '#fff' },
123
- * large: { padding: '12px 24px', fontSize: '16px' },
179
+ * const button = styles.hashClass({
180
+ * padding: '8px 12px',
181
+ * borderRadius: '8px',
182
+ * });
183
+ *
184
+ * const danger = styles.hashClass(
185
+ * { backgroundColor: 'red', color: 'white' },
186
+ * 'danger'
187
+ * );
188
+ * ```
189
+ */
190
+ declare function createHashClass(properties: CSSProperties, label?: string): string;
191
+ /**
192
+ * Create a style group and return a selector function.
193
+ *
194
+ * **Two-argument form** (definitions object with 'base' and variants):
195
+ * ```ts
196
+ * const button = styles.create('button', {
197
+ * base: { padding: '8px 16px' },
198
+ * primary: { backgroundColor: '#0066ff' },
124
199
  * });
200
+ * button('base', 'primary') // "button-base button-primary"
201
+ * ```
125
202
  *
126
- * button('base', 'primary') // "button-base button-primary"
127
- * button('base', isLarge && 'large') // conditional application
203
+ * **Three-argument form** (base styles + variants, no 'base' key needed):
204
+ * ```ts
205
+ * const button = styles.create('button',
206
+ * { padding: '8px 16px', borderRadius: '6px' }, // base styles
207
+ * {
208
+ * default: { backgroundColor: '#0066ff', color: '#fff' },
209
+ * outline: { border: '1px solid', backgroundColor: 'transparent' },
210
+ * large: { padding: '12px 24px' },
211
+ * }
212
+ * );
213
+ * button('default') // "button-base button-default" — base always included
214
+ * button('outline', 'large') // "button-base button-outline button-large"
128
215
  * ```
129
216
  */
130
217
  declare function createStyles<K extends string>(namespace: string, definitions: StyleDefinitions & Record<K, CSSProperties>): SelectorFunction<K>;
218
+ declare function createStyles(namespace: string, base: CSSProperties, variants: Record<string, CSSProperties>): SelectorFunction<string>;
131
219
  /**
132
220
  * Compose multiple selector functions or class strings into one.
133
221
  * Returns a new SelectorFunction that calls all inputs and joins results.
@@ -142,9 +230,35 @@ declare function createStyles<K extends string>(namespace: string, definitions:
142
230
  * ```
143
231
  */
144
232
  type AnySelectorFunction = {
145
- (...args: any[]): string;
233
+ (...args: unknown[]): string;
146
234
  };
147
235
  declare function compose(...selectors: Array<AnySelectorFunction | string | false | null | undefined>): AnySelectorFunction;
236
+ type StylesWithUtilsApi<U extends StyleUtils> = {
237
+ class: (name: string, properties: CSSPropertiesWithUtils<U>) => string;
238
+ hashClass: (properties: CSSPropertiesWithUtils<U>, label?: string) => string;
239
+ create: {
240
+ <K extends string>(namespace: string, definitions: StyleDefinitionsWithUtils<U> & Record<K, CSSPropertiesWithUtils<U>>): SelectorFunction<K>;
241
+ (namespace: string, base: CSSPropertiesWithUtils<U>, variants: Record<string, CSSPropertiesWithUtils<U>>): SelectorFunction<string>;
242
+ };
243
+ compose: typeof compose;
244
+ };
245
+ /**
246
+ * Create a utility-aware styles API, similar to Stitches' `utils`.
247
+ *
248
+ * @example
249
+ * ```ts
250
+ * const u = createStylesWithUtils({
251
+ * marginX: (value: string | number) => ({ marginLeft: value, marginRight: value }),
252
+ * size: (value: string | number) => ({ width: value, height: value }),
253
+ * });
254
+ *
255
+ * const card = u.class('card', {
256
+ * size: 40,
257
+ * marginX: 16,
258
+ * });
259
+ * ```
260
+ */
261
+ declare function createStylesWithUtils<U extends StyleUtils>(utils: U): StylesWithUtilsApi<U>;
148
262
 
149
263
  /**
150
264
  * Create design tokens as CSS custom properties.
@@ -362,7 +476,7 @@ declare namespace colorFns {
362
476
  /**
363
477
  * Create a multi-variant component style and return a selector function.
364
478
  *
365
- * Class naming convention:
479
+ * Class naming convention (default `semantic` mode; see `configureClassNaming`):
366
480
  * base → `{namespace}-base`
367
481
  * variants.intent.primary → `{namespace}-intent-primary`
368
482
  * compoundVariants[0] → `{namespace}-compound-0`
@@ -393,6 +507,7 @@ declare namespace colorFns {
393
507
  * ```
394
508
  */
395
509
  declare function createComponent<V extends VariantDefinitions>(namespace: string, config: ComponentConfig<V>): ComponentFunction<V>;
510
+ declare function createComponent<S extends string, V extends SlotVariantDefinitions<S>>(namespace: string, config: SlotComponentConfig<S, V>): SlotComponentFunction<S, V>;
396
511
 
397
512
  /**
398
513
  * Apply styles to an arbitrary CSS selector.
@@ -467,6 +582,34 @@ declare function createVar(): CSSVarRef;
467
582
  */
468
583
  declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<string, string>;
469
584
 
585
+ /**
586
+ * How generated class names are formed for `styles.create`, `styles.class`,
587
+ * `styles.component`, and related APIs.
588
+ *
589
+ * - `semantic` — readable names like `button-base`, `button-intent-primary` (default).
590
+ * - `hashed` — stable hash from namespace, variant segment, and declarations, with a short namespace slug for debugging.
591
+ * - `atomic` — hash-only names (shortest); same collision properties as `hashed` when `scopeId` differs.
592
+ */
593
+ type ClassNamingMode = 'semantic' | 'hashed' | 'atomic';
594
+ type ClassNamingConfig = {
595
+ mode: ClassNamingMode;
596
+ /** Prefix for hashed / atomic output and for `hashClass`. Default `ts`. */
597
+ prefix: string;
598
+ /**
599
+ * Optional package or app id mixed into hash input so identical logical
600
+ * names from different packages do not produce the same class string.
601
+ */
602
+ scopeId: string;
603
+ };
604
+ declare function getClassNamingConfig(): Readonly<ClassNamingConfig>;
605
+ /**
606
+ * Set global class naming options. Call once at app or package entry
607
+ * (e.g. design-system `index.ts`) for per-package adoption in a monorepo.
608
+ */
609
+ declare function configureClassNaming(partial: Partial<ClassNamingConfig>): void;
610
+ /** Restore defaults (primarily for tests). */
611
+ declare function resetClassNaming(): void;
612
+
470
613
  /**
471
614
  * Style creation API.
472
615
  *
@@ -477,12 +620,17 @@ declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<st
477
620
  * primary: { backgroundColor: '#0066ff' },
478
621
  * });
479
622
  *
480
- * <button className={button('base', 'primary')}>
623
+ * const hashed = styles.hashClass({ display: 'inline-flex' }, 'button');
624
+ *
625
+ * <button className={`${button('base', 'primary')} ${hashed}`}>
481
626
  * ```
482
627
  */
483
628
  declare const styles: {
484
629
  readonly create: typeof createStyles;
630
+ readonly class: typeof createClass;
631
+ readonly hashClass: typeof createHashClass;
485
632
  readonly component: typeof createComponent;
633
+ readonly withUtils: typeof createStylesWithUtils;
486
634
  readonly compose: typeof compose;
487
635
  };
488
636
  /**
@@ -550,4 +698,4 @@ declare const keyframes: {
550
698
  */
551
699
  declare const color: typeof colorFns;
552
700
 
553
- export { type CSSProperties, type CSSValue, type CSSVarRef, type ColorMixSpace, type ComponentConfig, type ComponentFunction, type FontFaceProps, type KeyframeStops$1 as KeyframeStops, type RecipeVariants, type SelectorFunction, type StyleDefinitions, type ThemeOverrides, type TokenRef, type TokenValues, type VariantDefinitions, assignVars, color, createVar, global, keyframes, styles, tokens };
701
+ export { type CSSProperties, type CSSPropertiesWithUtils, type CSSValue, type CSSVarRef, type ClassNamingConfig, type ClassNamingMode, type ColorMixSpace, type ComponentConfig, type ComponentFunction, type ComponentVariants, type FontFaceProps, type KeyframeStops$1 as KeyframeStops, type SelectorFunction, type SlotComponentConfig, type SlotComponentFunction, type SlotStyles, type SlotVariantDefinitions, type StyleDefinitions, type StyleDefinitionsWithUtils, type StyleUtils, type ThemeOverrides, type TokenRef, type TokenValues, type VariantDefinitions, assignVars, color, configureClassNaming, createVar, getClassNamingConfig, global, keyframes, resetClassNaming, styles, tokens };