typestyles 0.3.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
@@ -13,10 +13,33 @@ interface CSSProperties extends CSS.Properties<CSSValue> {
13
13
  /** Nested selector (e.g., '&:hover', '& .child', '&::before', '&[data-variant]') */
14
14
  [selector: `&${string}`]: CSSProperties;
15
15
  /** Attribute selector (e.g., '[data-variant]', '[data-variant="primary"]', '[disabled]') */
16
- [attribute: `[${string}`]: CSSProperties;
16
+ [attribute: `[${string}]`]: CSSProperties;
17
17
  /** At-rule (e.g., '@media (max-width: 768px)', '@container', '@supports') */
18
18
  [atRule: `@${string}`]: CSSProperties;
19
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>>;
20
43
  /**
21
44
  * A map of variant names to their CSS property definitions.
22
45
  */
@@ -50,7 +73,16 @@ type KeyframeStops$1 = Record<string, CSSProperties>;
50
73
  /**
51
74
  * A map of variant dimensions to their options (each option maps to CSSProperties).
52
75
  */
76
+ type VariantDimensions = Record<string, Record<string, unknown>>;
53
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
+ };
54
86
  /**
55
87
  * The full config object passed to styles.component().
56
88
  */
@@ -59,20 +91,29 @@ type ComponentConfig<V extends VariantDefinitions> = {
59
91
  variants?: V;
60
92
  compoundVariants?: Array<{
61
93
  variants: {
62
- [K in keyof V]?: keyof V[K];
94
+ [K in keyof V]?: CompoundSelectionValue<VariantOptionKey<V, K>>;
63
95
  };
64
96
  style: CSSProperties;
65
97
  }>;
66
- defaultVariants?: {
67
- [K in keyof V]?: keyof V[K];
68
- };
98
+ defaultVariants?: ComponentSelections<V>;
69
99
  };
70
100
  /**
71
101
  * The function returned by styles.component().
72
102
  */
73
- type ComponentFunction<V extends VariantDefinitions> = (selections?: {
74
- [K in keyof V]?: keyof V[K] | false | null | undefined;
75
- }) => 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>;
76
117
  /**
77
118
  * A reference to a CSS custom property created by createVar().
78
119
  * The string value is `var(--ts-N)` and can be used directly as a CSS value.
@@ -91,11 +132,11 @@ type CSSVarRef = `var(--${string})`;
91
132
  * },
92
133
  * });
93
134
  *
94
- * type ButtonProps = RecipeVariants<typeof button>;
135
+ * type ButtonProps = ComponentVariants<typeof button>;
95
136
  * // { intent?: 'primary' | 'ghost'; size?: 'sm' | 'lg' }
96
137
  * ```
97
138
  */
98
- type RecipeVariants<T> = T extends ComponentFunction<infer V> ? {
139
+ type ComponentVariants<T> = T extends (selections?: ComponentSelections<infer V>) => unknown ? {
99
140
  [K in keyof V]?: keyof V[K];
100
141
  } : never;
101
142
  /**
@@ -111,25 +152,70 @@ type FontFaceProps = {
111
152
  };
112
153
 
113
154
  /**
114
- * 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.
115
157
  *
116
- * The selector function accepts variant names and returns a composed
117
- * class name string. Class names are deterministic and human-readable:
118
- * `{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.
119
176
  *
120
177
  * @example
121
178
  * ```ts
122
- * const button = createStyles('button', {
123
- * base: { padding: '8px 16px', fontSize: '14px' },
124
- * primary: { backgroundColor: '#0066ff', color: '#fff' },
125
- * 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' },
126
199
  * });
200
+ * button('base', 'primary') // "button-base button-primary"
201
+ * ```
127
202
  *
128
- * button('base', 'primary') // "button-base button-primary"
129
- * 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"
130
215
  * ```
131
216
  */
132
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>;
133
219
  /**
134
220
  * Compose multiple selector functions or class strings into one.
135
221
  * Returns a new SelectorFunction that calls all inputs and joins results.
@@ -147,6 +233,32 @@ type AnySelectorFunction = {
147
233
  (...args: unknown[]): string;
148
234
  };
149
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>;
150
262
 
151
263
  /**
152
264
  * Create design tokens as CSS custom properties.
@@ -364,7 +476,7 @@ declare namespace colorFns {
364
476
  /**
365
477
  * Create a multi-variant component style and return a selector function.
366
478
  *
367
- * Class naming convention:
479
+ * Class naming convention (default `semantic` mode; see `configureClassNaming`):
368
480
  * base → `{namespace}-base`
369
481
  * variants.intent.primary → `{namespace}-intent-primary`
370
482
  * compoundVariants[0] → `{namespace}-compound-0`
@@ -395,6 +507,7 @@ declare namespace colorFns {
395
507
  * ```
396
508
  */
397
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>;
398
511
 
399
512
  /**
400
513
  * Apply styles to an arbitrary CSS selector.
@@ -469,6 +582,34 @@ declare function createVar(): CSSVarRef;
469
582
  */
470
583
  declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<string, string>;
471
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
+
472
613
  /**
473
614
  * Style creation API.
474
615
  *
@@ -479,12 +620,17 @@ declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<st
479
620
  * primary: { backgroundColor: '#0066ff' },
480
621
  * });
481
622
  *
482
- * <button className={button('base', 'primary')}>
623
+ * const hashed = styles.hashClass({ display: 'inline-flex' }, 'button');
624
+ *
625
+ * <button className={`${button('base', 'primary')} ${hashed}`}>
483
626
  * ```
484
627
  */
485
628
  declare const styles: {
486
629
  readonly create: typeof createStyles;
630
+ readonly class: typeof createClass;
631
+ readonly hashClass: typeof createHashClass;
487
632
  readonly component: typeof createComponent;
633
+ readonly withUtils: typeof createStylesWithUtils;
488
634
  readonly compose: typeof compose;
489
635
  };
490
636
  /**
@@ -552,4 +698,4 @@ declare const keyframes: {
552
698
  */
553
699
  declare const color: typeof colorFns;
554
700
 
555
- 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
@@ -13,10 +13,33 @@ interface CSSProperties extends CSS.Properties<CSSValue> {
13
13
  /** Nested selector (e.g., '&:hover', '& .child', '&::before', '&[data-variant]') */
14
14
  [selector: `&${string}`]: CSSProperties;
15
15
  /** Attribute selector (e.g., '[data-variant]', '[data-variant="primary"]', '[disabled]') */
16
- [attribute: `[${string}`]: CSSProperties;
16
+ [attribute: `[${string}]`]: CSSProperties;
17
17
  /** At-rule (e.g., '@media (max-width: 768px)', '@container', '@supports') */
18
18
  [atRule: `@${string}`]: CSSProperties;
19
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>>;
20
43
  /**
21
44
  * A map of variant names to their CSS property definitions.
22
45
  */
@@ -50,7 +73,16 @@ type KeyframeStops$1 = Record<string, CSSProperties>;
50
73
  /**
51
74
  * A map of variant dimensions to their options (each option maps to CSSProperties).
52
75
  */
76
+ type VariantDimensions = Record<string, Record<string, unknown>>;
53
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
+ };
54
86
  /**
55
87
  * The full config object passed to styles.component().
56
88
  */
@@ -59,20 +91,29 @@ type ComponentConfig<V extends VariantDefinitions> = {
59
91
  variants?: V;
60
92
  compoundVariants?: Array<{
61
93
  variants: {
62
- [K in keyof V]?: keyof V[K];
94
+ [K in keyof V]?: CompoundSelectionValue<VariantOptionKey<V, K>>;
63
95
  };
64
96
  style: CSSProperties;
65
97
  }>;
66
- defaultVariants?: {
67
- [K in keyof V]?: keyof V[K];
68
- };
98
+ defaultVariants?: ComponentSelections<V>;
69
99
  };
70
100
  /**
71
101
  * The function returned by styles.component().
72
102
  */
73
- type ComponentFunction<V extends VariantDefinitions> = (selections?: {
74
- [K in keyof V]?: keyof V[K] | false | null | undefined;
75
- }) => 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>;
76
117
  /**
77
118
  * A reference to a CSS custom property created by createVar().
78
119
  * The string value is `var(--ts-N)` and can be used directly as a CSS value.
@@ -91,11 +132,11 @@ type CSSVarRef = `var(--${string})`;
91
132
  * },
92
133
  * });
93
134
  *
94
- * type ButtonProps = RecipeVariants<typeof button>;
135
+ * type ButtonProps = ComponentVariants<typeof button>;
95
136
  * // { intent?: 'primary' | 'ghost'; size?: 'sm' | 'lg' }
96
137
  * ```
97
138
  */
98
- type RecipeVariants<T> = T extends ComponentFunction<infer V> ? {
139
+ type ComponentVariants<T> = T extends (selections?: ComponentSelections<infer V>) => unknown ? {
99
140
  [K in keyof V]?: keyof V[K];
100
141
  } : never;
101
142
  /**
@@ -111,25 +152,70 @@ type FontFaceProps = {
111
152
  };
112
153
 
113
154
  /**
114
- * 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.
115
157
  *
116
- * The selector function accepts variant names and returns a composed
117
- * class name string. Class names are deterministic and human-readable:
118
- * `{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.
119
176
  *
120
177
  * @example
121
178
  * ```ts
122
- * const button = createStyles('button', {
123
- * base: { padding: '8px 16px', fontSize: '14px' },
124
- * primary: { backgroundColor: '#0066ff', color: '#fff' },
125
- * 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' },
126
199
  * });
200
+ * button('base', 'primary') // "button-base button-primary"
201
+ * ```
127
202
  *
128
- * button('base', 'primary') // "button-base button-primary"
129
- * 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"
130
215
  * ```
131
216
  */
132
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>;
133
219
  /**
134
220
  * Compose multiple selector functions or class strings into one.
135
221
  * Returns a new SelectorFunction that calls all inputs and joins results.
@@ -147,6 +233,32 @@ type AnySelectorFunction = {
147
233
  (...args: unknown[]): string;
148
234
  };
149
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>;
150
262
 
151
263
  /**
152
264
  * Create design tokens as CSS custom properties.
@@ -364,7 +476,7 @@ declare namespace colorFns {
364
476
  /**
365
477
  * Create a multi-variant component style and return a selector function.
366
478
  *
367
- * Class naming convention:
479
+ * Class naming convention (default `semantic` mode; see `configureClassNaming`):
368
480
  * base → `{namespace}-base`
369
481
  * variants.intent.primary → `{namespace}-intent-primary`
370
482
  * compoundVariants[0] → `{namespace}-compound-0`
@@ -395,6 +507,7 @@ declare namespace colorFns {
395
507
  * ```
396
508
  */
397
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>;
398
511
 
399
512
  /**
400
513
  * Apply styles to an arbitrary CSS selector.
@@ -469,6 +582,34 @@ declare function createVar(): CSSVarRef;
469
582
  */
470
583
  declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<string, string>;
471
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
+
472
613
  /**
473
614
  * Style creation API.
474
615
  *
@@ -479,12 +620,17 @@ declare function assignVars(vars: Partial<Record<CSSVarRef, string>>): Record<st
479
620
  * primary: { backgroundColor: '#0066ff' },
480
621
  * });
481
622
  *
482
- * <button className={button('base', 'primary')}>
623
+ * const hashed = styles.hashClass({ display: 'inline-flex' }, 'button');
624
+ *
625
+ * <button className={`${button('base', 'primary')} ${hashed}`}>
483
626
  * ```
484
627
  */
485
628
  declare const styles: {
486
629
  readonly create: typeof createStyles;
630
+ readonly class: typeof createClass;
631
+ readonly hashClass: typeof createHashClass;
487
632
  readonly component: typeof createComponent;
633
+ readonly withUtils: typeof createStylesWithUtils;
488
634
  readonly compose: typeof compose;
489
635
  };
490
636
  /**
@@ -552,4 +698,4 @@ declare const keyframes: {
552
698
  */
553
699
  declare const color: typeof colorFns;
554
700
 
555
- 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 };