clava 0.6.0 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # clava
2
2
 
3
+ ## 0.6.2
4
+
5
+ - Fixed `TS2590` and `TS2345` type errors when a framework style value, such as React's `CSSProperties` or Solid's `JSX.CSSProperties`, is passed to a [`cv`](https://clava.style/docs/reference/cv) component.
6
+
7
+ ## 0.6.1
8
+
9
+ - Reduced the production bundle size and improved tree-shaking for standalone imports.
10
+ - Fixed [`getVariants`](https://clava.style/docs/reference/getVariants) to ignore input keys that are not declared variants.
11
+ - Limited the published package to runtime builds, source-condition files, and package documentation.
12
+ - Fixed Microsoft-prefixed CSS properties to round-trip between camelCase and hyphenated style formats.
13
+ - Fixed [`cv`](https://clava.style/docs/reference/cv) to preserve inherited variant types when extending `.jsx`, `.html`, or `.htmlObj` mode components.
14
+ - Fixed deep component extension chains to preserve stable refinement output without exhausting the convergence limit.
15
+ - Fixed [`splitProps`](https://clava.style/docs/reference/split-props) to ignore inherited property values.
16
+ - Fixed numeric style normalization to preserve unitless CSS and custom property values.
17
+
3
18
  ## 0.6.0
4
19
 
5
20
  ### Computed default variant parameters
package/README.md CHANGED
@@ -142,13 +142,14 @@ box().class;
142
142
  // "box rounded"
143
143
  ```
144
144
 
145
- Config styles use camelCase CSS property names and string values. CSS custom properties are supported.
145
+ Config styles use camelCase CSS property names. CSS custom properties accept string or number values.
146
146
 
147
147
  ```ts
148
148
  const card = cv({
149
149
  style: {
150
150
  paddingBlock: "8px",
151
151
  "--card-accent": "oklch(62% 0.2 250)",
152
+ "--card-scale": 1.05,
152
153
  },
153
154
  });
154
155
  ```
@@ -233,26 +234,32 @@ Variant values can be class values, arrays, `{ class, style }` objects, or [func
233
234
 
234
235
  Add a function as a variant value when the prop should generate class/style output dynamically. The function's parameter type defines the prop type. Method syntax works well for multi-line callbacks; compact one-line callbacks can stay as arrow-function property values.
235
236
 
237
+ When function variants emit Tailwind utilities, keep utility names static so Tailwind can detect them at build time. Pass dynamic CSS values through variables instead of building utilities like `` `grid-cols-${value}` ``.
238
+
236
239
  ```ts
237
240
  const grid = cv({
238
241
  class: "grid",
239
242
  variants: {
240
243
  columns(value: number) {
241
244
  return {
242
- class: `grid-cols-${value}`,
243
- style: { "--grid-columns": `${value}` },
245
+ class: "grid-cols-(--grid-columns)",
246
+ style: { "--grid-columns": `repeat(${value}, minmax(0, 1fr))` },
244
247
  };
245
248
  },
246
249
  color(value: string | null) {
247
- return value ? `text-${value}` : "text-current";
250
+ if (!value) return "text-current";
251
+ return {
252
+ class: "text-(--text-color)",
253
+ style: { "--text-color": value },
254
+ };
248
255
  },
249
256
  },
250
257
  });
251
258
 
252
259
  grid({ columns: 3, color: null });
253
260
  // {
254
- // class: "grid grid-cols-3 text-current",
255
- // style: { "--grid-columns": "3" },
261
+ // class: "grid grid-cols-(--grid-columns) text-current",
262
+ // style: { "--grid-columns": "repeat(3, minmax(0, 1fr))" },
256
263
  // }
257
264
  ```
258
265
 
@@ -476,7 +483,7 @@ function Button(props: ButtonProps) {
476
483
 
477
484
  ## `create()` And `cx()`
478
485
 
479
- The package-level `cv` and `cx` come from `create()` with no class transform. Use `create({ transformClass })` when every generated class string should pass through a transform, such as a prefixer or CSS-module lookup.
486
+ The package-level `cv` and `cx` behave like the helpers returned by `create()` with no class transform. Use `create({ transformClass })` when every generated class string should pass through a transform, such as a prefixer or CSS-module lookup.
480
487
 
481
488
  ```ts
482
489
  import { create } from "clava";
@@ -542,7 +549,7 @@ The package also exports `ClassValue`, `StyleValue`, `StyleClassProps`, `StyleCl
542
549
 
543
550
  ## Comparison
544
551
 
545
- This table compares Clava with the packages used by the repository's alternative benchmark: `class-variance-authority@0.7.1`, `cva@1.0.0-beta.4`, `tailwind-variants/lite@3.2.2`, and `tailwind-variants@3.2.2`.
552
+ This table compares Clava with the packages used by the repository's alternative benchmark: `class-variance-authority@0.7.1`, `cva@1.0.0-beta.6`, `tailwind-variants/lite@3.2.2`, `tailwind-variants@3.2.2`, and `tailwind-merge@3.6.0` through Clava's `transformClass`.
546
553
 
547
554
  | Feature | Clava | CVA v0 | CVA v1 beta | TV Lite | TV |
548
555
  | ---------------------------------------------------- | -------------- | ------------------ | ------------------ | ------------------ | ------------------ |
@@ -558,15 +565,16 @@ This table compares Clava with the packages used by the repository's alternative
558
565
  | Dedicated slots API | No | No | No | Yes | Yes |
559
566
  | Built-in Tailwind conflict merging | No | No | No | No | Yes |
560
567
 
561
- The `pnpm perf-alternatives` benchmark resolves a composed Tailwind-style button with inherited variants, defaults, and cross-variant conditions. On Node v24.14.1, Vitest reported these results, where higher ops/sec is better:
568
+ The `pnpm perf-alternatives` benchmark resolves a composed Tailwind-style button with inherited variants, defaults, and cross-variant conditions. On Node v24.18.0, Vitest reported these results, where higher ops/sec is better:
562
569
 
563
- | Package | Ops/sec | Relative to Clava |
564
- | -------------------------------- | --------: | ----------------: |
565
- | `clava@0.5.0` | 1,040,314 | 1.00x |
566
- | `class-variance-authority@0.7.1` | 426,132 | 2.44x slower |
567
- | `tailwind-variants/lite@3.2.2` | 369,732 | 2.81x slower |
568
- | `tailwind-variants@3.2.2` | 273,503 | 3.80x slower |
569
- | `cva@1.0.0-beta.4` | 211,474 | 4.92x slower |
570
+ | Package | Ops/sec | Relative to Clava |
571
+ | ------------------------------------ | --------: | ----------------: |
572
+ | `clava@0.6.1` | 1,064,359 | 1.00x |
573
+ | `clava@0.6.1 + tailwind-merge@3.6.0` | 505,454 | 2.11x slower |
574
+ | `class-variance-authority@0.7.1` | 435,382 | 2.44x slower |
575
+ | `tailwind-variants/lite@3.2.2` | 371,763 | 2.86x slower |
576
+ | `cva@1.0.0-beta.6` | 328,566 | 3.24x slower |
577
+ | `tailwind-variants@3.2.2` | 274,351 | 3.88x slower |
570
578
 
571
579
  Benchmark results vary by runtime and hardware, so treat them as a reproducible snapshot of this repository's composed-variant case rather than a universal ranking.
572
580
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ClassValue as ClassValue$1 } from "clsx";
2
2
  import * as CSS from "csstype";
3
-
4
3
  //#region src/types.d.ts
5
4
  /**
6
5
  * A class value accepted by Clava. It supports strings, numbers, booleans,
@@ -18,9 +17,12 @@ import * as CSS from "csstype";
18
17
  * ```
19
18
  */
20
19
  type ClassValue = string | number | boolean | null | undefined | void | ClassValue[];
21
- type JSXCSSProperties = CSS.Properties<string | number>;
22
- type HTMLCSSProperties = CSS.PropertiesHyphen<string | number>;
23
- type StyleProperty = JSXCSSProperties | HTMLCSSProperties | string;
20
+ interface CustomProperties {
21
+ [key: `--${string}`]: string | number;
22
+ }
23
+ interface JSXCSSProperties extends CSS.Properties<string | number>, CustomProperties {}
24
+ interface HTMLCSSProperties extends CSS.PropertiesHyphen<string | number>, CustomProperties {}
25
+ type StyleProperty = JSXCSSProperties | HTMLCSSProperties | CSS.Properties<string | number> | CSS.PropertiesHyphen<string | number> | string;
24
26
  /**
25
27
  * The prop object returned by a component's `.jsx()` mode.
26
28
  *
@@ -87,7 +89,7 @@ interface StyleClassProps {
87
89
  type ComponentResult = JSXProps | HTMLProps | HTMLObjProps | StyleClassProps;
88
90
  type AllComponentResultKeys = keyof JSXProps | keyof HTMLProps | keyof HTMLObjProps;
89
91
  type ComponentResultValue<K extends AllComponentResultKeys> = K extends "style" ? StyleProperty : K extends "className" ? string : K extends "class" ? string : never;
90
- type NullableComponentResult = { [K in AllComponentResultKeys]?: ComponentResultValue<K> | null };
92
+ type NullableComponentResult = { [K in AllComponentResultKeys]?: ComponentResultValue<K> | null; };
91
93
  type ComponentProps<V = {}> = VariantValues<V> & NullableComponentResult;
92
94
  type GetVariants<V> = (variants?: VariantValues<V>) => VariantValues<V>;
93
95
  type ComponentPropKey<R extends ComponentResult> = keyof R | (R extends StyleClassProps ? "className" : never);
@@ -149,22 +151,23 @@ interface CVComponent<V extends Variants = {}, E extends AnyComponent[] = [], R
149
151
  }
150
152
  type AnyComponent = CVComponent<any, any, any> | ModalComponent<any, any>;
151
153
  type MergeExtendedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractVariants<First> & MergeExtendedVariants<Rest> : {};
152
- type ExtractVariants<T> = T extends CVComponent<infer V, infer E, any> ? MergeVariantMaps<V, MergeExtendedVariants<E>> : {};
154
+ type ExtractVariants<T> = T extends ModalComponent<infer V, any> ? V : {};
153
155
  type MergeVariantDefinition<Child, Parent> = Child extends ((...args: any[]) => any) ? Child : Parent extends ((...args: any[]) => any) ? Child : Child extends Record<string, any> ? Parent extends Record<string, any> ? Omit<Parent, keyof Child> & Child : Child : Child;
154
- type MergeVariantMaps<Child, Parent> = Omit<Parent, keyof Child> & Child & { [K in keyof Child & keyof Parent]: MergeVariantDefinition<Child[K], Parent[K]> };
156
+ type MergeVariantMaps<Child, Parent> = Omit<Parent, keyof Child> & Child & { [K in keyof Child & keyof Parent]: MergeVariantDefinition<Child[K], Parent[K]>; };
155
157
  type MergeVariants<V, E extends AnyComponent[]> = MergeVariantMaps<NoInfer<V>, MergeExtendedVariants<E>>;
156
158
  type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
157
159
  type VariantValue = ClassValue | StyleClassValue;
158
- type NonNullKeys<T> = { [K in keyof T]: T[K] extends null ? never : K }[keyof T];
160
+ type NonNullKeys<T> = { [K in keyof T]: T[K] extends null ? never : K; }[keyof T];
159
161
  type ExtractVariantValue<T> = T extends null ? never : T extends ((value: infer V) => any) ? V : T extends readonly unknown[] ? boolean : T extends Record<string, any> ? StringToBoolean<NonNullKeys<T>> : T extends ClassValue ? boolean : never;
160
- type VariantValues<V> = { [K in keyof V]?: ExtractVariantValue<V[K]> | undefined };
162
+ type VariantValues<V> = { [K in keyof V]?: ExtractVariantValue<V[K]> | undefined; };
161
163
  type ComputedDefaultVariant<V, K extends keyof V> = (defaultValue: ExtractVariantValue<V[K]> | undefined, variants: Readonly<VariantValues<V>>) => ExtractVariantValue<V[K]> | undefined;
162
164
  type NonFunctionVariantValue<T> = Exclude<T, (...args: any[]) => any>;
163
165
  type DefaultVariantValue<V, K extends keyof V> = [NonFunctionVariantValue<ExtractVariantValue<V[K]>>] extends [never] ? ComputedDefaultVariant<V, K> : NonFunctionVariantValue<ExtractVariantValue<V[K]>> | ComputedDefaultVariant<V, K>;
164
- type DefaultVariants<V> = { [K in keyof V]?: DefaultVariantValue<V, K> | undefined };
166
+ type DefaultVariants<V> = { [K in keyof V]?: DefaultVariantValue<V, K> | undefined; };
165
167
  /**
166
168
  * A normalized style object accepted by Clava config, variant, and refine
167
- * style entries. CSS custom properties are supported with string values.
169
+ * style entries. CSS custom properties are supported with string and number
170
+ * values.
168
171
  *
169
172
  * @example
170
173
  * ```ts
@@ -173,12 +176,11 @@ type DefaultVariants<V> = { [K in keyof V]?: DefaultVariantValue<V, K> | undefin
173
176
  * const style: StyleValue = {
174
177
  * color: "red",
175
178
  * "--button-accent": "oklch(62% 0.2 250)",
179
+ * "--button-scale": 1.1,
176
180
  * };
177
181
  * ```
178
182
  */
179
- type StyleValue = CSS.Properties & {
180
- [key: `--${string}`]: string;
181
- };
183
+ interface StyleValue extends CSS.Properties, CustomProperties {}
182
184
  /**
183
185
  * A value that contributes both class and style output from a base config,
184
186
  * variant value, function variant, or refine callback.
@@ -206,8 +208,8 @@ interface RefineContext<V> {
206
208
  type Refine<V> = (context: RefineContext<V>) => VariantValue;
207
209
  type Variant$1 = ClassValue | Record<string, VariantValue> | ((value: any) => VariantValue);
208
210
  type Variants = Record<string, Variant$1>;
209
- type NullablePartial<T> = T extends Record<string, any> ? { [K in keyof T]?: T[K] | null } : T | null;
210
- type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K in keyof MergeExtendedVariants<E>]?: NullablePartial<MergeExtendedVariants<E>[K]> | Variant$1 };
211
+ type NullablePartial<T> = T extends Record<string, any> ? { [K in keyof T]?: T[K] | null; } : T | null;
212
+ type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K in keyof MergeExtendedVariants<E>]?: NullablePartial<MergeExtendedVariants<E>[K]> | Variant$1; };
211
213
  //#endregion
212
214
  //#region src/index.d.ts
213
215
  /**
@@ -236,7 +238,7 @@ type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K
236
238
  * };
237
239
  * ```
238
240
  */
239
- type VariantProps<T extends Pick<AnyComponent, "getVariants">> = ReturnType<T["getVariants"]>;
241
+ export type VariantProps<T extends Pick<AnyComponent, "getVariants">> = ReturnType<T["getVariants"]>;
240
242
  type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
241
243
  /**
242
244
  * Constrains a variant map to the same value keys as a variant on another
@@ -264,7 +266,7 @@ type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
264
266
  * });
265
267
  * ```
266
268
  */
267
- type Variant<T extends Pick<AnyComponent, "getVariants">, K extends keyof VariantProps<T>> = Record<VariantKey<NonNullable<VariantProps<T>[K]>>, ClassValue | StyleClassValue>;
269
+ export type Variant<T extends Pick<AnyComponent, "getVariants">, K extends keyof VariantProps<T>> = Record<VariantKey<NonNullable<VariantProps<T>[K]>>, ClassValue | StyleClassValue>;
268
270
  /**
269
271
  * The configuration object accepted by `cv()`. It defines base class/style
270
272
  * output, variants, default variants, component extensions, and refinement
@@ -291,7 +293,7 @@ type Variant<T extends Pick<AnyComponent, "getVariants">, K extends keyof Varian
291
293
  * const alert = cv(config);
292
294
  * ```
293
295
  */
294
- interface CVConfig<V extends Variants = {}, E extends AnyComponent[] = []> {
296
+ export interface CVConfig<V extends Variants = {}, E extends AnyComponent[] = []> {
295
297
  extend?: E;
296
298
  class?: ClassValue;
297
299
  style?: StyleValue;
@@ -310,17 +312,21 @@ interface CreateParams {
310
312
  * styling props. The last element is always the "rest" containing keys not
311
313
  * claimed by any source.
312
314
  */
313
- declare const splitProps: SplitPropsFunction;
315
+ export declare const splitProps: SplitPropsFunction;
314
316
  /**
315
317
  * Creates the cv and cx functions.
316
318
  */
317
- declare function create({
318
- transformClass
319
- }?: CreateParams): {
319
+ export declare function create({ transformClass }?: CreateParams): {
320
320
  cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E>;
321
321
  cx: (...classes: ClassValue$1[]) => string;
322
322
  };
323
- declare const cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E>, cx: (...classes: ClassValue$1[]) => string;
323
+ export declare const cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E>;
324
+ /**
325
+ * Joins class values without applying a class transform.
326
+ *
327
+ * This behaves like the `cx` function returned by `create()` with no options.
328
+ */
329
+ export declare function cx(...classes: ClassValue$1[]): string;
324
330
  //#endregion
325
- export { type CVComponent, CVConfig, type ClassValue, type HTMLObjProps, type HTMLProps, type JSXProps, type StyleClassProps, type StyleClassValue, type StyleValue, Variant, VariantProps, create, cv, cx, splitProps };
331
+ export type { CVComponent, ClassValue, HTMLObjProps, HTMLProps, JSXProps, StyleClassProps, StyleClassValue, StyleValue };
326
332
  //# sourceMappingURL=index.d.ts.map