clava 0.6.0 → 0.6.1
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 +11 -0
- package/README.md +23 -15
- package/dist/index.d.ts +28 -19
- package/dist/index.js +384 -594
- package/dist/index.js.map +1 -1
- package/package.json +17 -2
- package/src/index.ts +281 -634
- package/src/refine-warning.ts +4 -11
- package/src/types.ts +19 -15
- package/src/utils.ts +123 -99
- package/rolldown.config.ts +0 -15
- package/tests/_utils.ts +0 -178
- package/tests/build.test.ts +0 -93
- package/tests/class-style.test.ts +0 -341
- package/tests/component-api.test.ts +0 -548
- package/tests/extend.test.ts +0 -421
- package/tests/function-variants.test.ts +0 -378
- package/tests/language-service.test.ts +0 -192
- package/tests/prototype-pollution.test.ts +0 -46
- package/tests/react.test.ts +0 -40
- package/tests/refine-warning.test.ts +0 -28
- package/tests/refine.test.ts +0 -1498
- package/tests/solid.test.ts +0 -64
- package/tests/split-props.test.ts +0 -662
- package/tests/variants-inference.test.ts +0 -401
- package/tests/variants.test.ts +0 -408
- package/tsconfig.json +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# clava
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
- Reduced the production bundle size and improved tree-shaking for standalone imports.
|
|
6
|
+
- Fixed [`getVariants`](https://clava.style/docs/reference/getVariants) to ignore input keys that are not declared variants.
|
|
7
|
+
- Limited the published package to runtime builds, source-condition files, and package documentation.
|
|
8
|
+
- Fixed Microsoft-prefixed CSS properties to round-trip between camelCase and hyphenated style formats.
|
|
9
|
+
- Fixed [`cv`](https://clava.style/docs/reference/cv) to preserve inherited variant types when extending `.jsx`, `.html`, or `.htmlObj` mode components.
|
|
10
|
+
- Fixed deep component extension chains to preserve stable refinement output without exhausting the convergence limit.
|
|
11
|
+
- Fixed [`splitProps`](https://clava.style/docs/reference/split-props) to ignore inherited property values.
|
|
12
|
+
- Fixed numeric style normalization to preserve unitless CSS and custom property values.
|
|
13
|
+
|
|
3
14
|
## 0.6.0
|
|
4
15
|
|
|
5
16
|
### 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
|
|
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:
|
|
243
|
-
style: { "--grid-columns":
|
|
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
|
-
|
|
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-
|
|
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`
|
|
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`,
|
|
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.4`, `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
|
| ---------------------------------------------------- | -------------- | ------------------ | ------------------ | ------------------ | ------------------ |
|
|
@@ -560,13 +567,14 @@ This table compares Clava with the packages used by the repository's alternative
|
|
|
560
567
|
|
|
561
568
|
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:
|
|
562
569
|
|
|
563
|
-
| Package
|
|
564
|
-
|
|
|
565
|
-
| `clava@0.
|
|
566
|
-
| `
|
|
567
|
-
| `
|
|
568
|
-
| `tailwind-variants@3.2.2`
|
|
569
|
-
| `
|
|
570
|
+
| Package | Ops/sec | Relative to Clava |
|
|
571
|
+
| ------------------------------------ | --------: | ----------------: |
|
|
572
|
+
| `clava@0.6.0` | 1,093,632 | 1.00x |
|
|
573
|
+
| `clava@0.6.0 + tailwind-merge@3.6.0` | 535,392 | 2.04x slower |
|
|
574
|
+
| `class-variance-authority@0.7.1` | 445,527 | 2.45x slower |
|
|
575
|
+
| `tailwind-variants/lite@3.2.2` | 377,985 | 2.89x slower |
|
|
576
|
+
| `tailwind-variants@3.2.2` | 286,653 | 3.82x slower |
|
|
577
|
+
| `cva@1.0.0-beta.4` | 218,829 | 5.00x 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,8 +17,12 @@ import * as CSS from "csstype";
|
|
|
18
17
|
* ```
|
|
19
18
|
*/
|
|
20
19
|
type ClassValue = string | number | boolean | null | undefined | void | ClassValue[];
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
interface JSXCSSProperties extends CSS.Properties<string | number> {
|
|
21
|
+
[key: `--${string}`]: string | number;
|
|
22
|
+
}
|
|
23
|
+
interface HTMLCSSProperties extends CSS.PropertiesHyphen<string | number> {
|
|
24
|
+
[key: `--${string}`]: string | number;
|
|
25
|
+
}
|
|
23
26
|
type StyleProperty = JSXCSSProperties | HTMLCSSProperties | string;
|
|
24
27
|
/**
|
|
25
28
|
* The prop object returned by a component's `.jsx()` mode.
|
|
@@ -87,7 +90,7 @@ interface StyleClassProps {
|
|
|
87
90
|
type ComponentResult = JSXProps | HTMLProps | HTMLObjProps | StyleClassProps;
|
|
88
91
|
type AllComponentResultKeys = keyof JSXProps | keyof HTMLProps | keyof HTMLObjProps;
|
|
89
92
|
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 };
|
|
93
|
+
type NullableComponentResult = { [K in AllComponentResultKeys]?: ComponentResultValue<K> | null; };
|
|
91
94
|
type ComponentProps<V = {}> = VariantValues<V> & NullableComponentResult;
|
|
92
95
|
type GetVariants<V> = (variants?: VariantValues<V>) => VariantValues<V>;
|
|
93
96
|
type ComponentPropKey<R extends ComponentResult> = keyof R | (R extends StyleClassProps ? "className" : never);
|
|
@@ -149,22 +152,23 @@ interface CVComponent<V extends Variants = {}, E extends AnyComponent[] = [], R
|
|
|
149
152
|
}
|
|
150
153
|
type AnyComponent = CVComponent<any, any, any> | ModalComponent<any, any>;
|
|
151
154
|
type MergeExtendedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractVariants<First> & MergeExtendedVariants<Rest> : {};
|
|
152
|
-
type ExtractVariants<T> = T extends
|
|
155
|
+
type ExtractVariants<T> = T extends ModalComponent<infer V, any> ? V : {};
|
|
153
156
|
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]
|
|
157
|
+
type MergeVariantMaps<Child, Parent> = Omit<Parent, keyof Child> & Child & { [K in keyof Child & keyof Parent]: MergeVariantDefinition<Child[K], Parent[K]>; };
|
|
155
158
|
type MergeVariants<V, E extends AnyComponent[]> = MergeVariantMaps<NoInfer<V>, MergeExtendedVariants<E>>;
|
|
156
159
|
type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
157
160
|
type VariantValue = ClassValue | StyleClassValue;
|
|
158
|
-
type NonNullKeys<T> = { [K in keyof T]: T[K] extends null ? never : K }[keyof T];
|
|
161
|
+
type NonNullKeys<T> = { [K in keyof T]: T[K] extends null ? never : K; }[keyof T];
|
|
159
162
|
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 };
|
|
163
|
+
type VariantValues<V> = { [K in keyof V]?: ExtractVariantValue<V[K]> | undefined; };
|
|
161
164
|
type ComputedDefaultVariant<V, K extends keyof V> = (defaultValue: ExtractVariantValue<V[K]> | undefined, variants: Readonly<VariantValues<V>>) => ExtractVariantValue<V[K]> | undefined;
|
|
162
165
|
type NonFunctionVariantValue<T> = Exclude<T, (...args: any[]) => any>;
|
|
163
166
|
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 };
|
|
167
|
+
type DefaultVariants<V> = { [K in keyof V]?: DefaultVariantValue<V, K> | undefined; };
|
|
165
168
|
/**
|
|
166
169
|
* A normalized style object accepted by Clava config, variant, and refine
|
|
167
|
-
* style entries. CSS custom properties are supported with string
|
|
170
|
+
* style entries. CSS custom properties are supported with string and number
|
|
171
|
+
* values.
|
|
168
172
|
*
|
|
169
173
|
* @example
|
|
170
174
|
* ```ts
|
|
@@ -173,12 +177,13 @@ type DefaultVariants<V> = { [K in keyof V]?: DefaultVariantValue<V, K> | undefin
|
|
|
173
177
|
* const style: StyleValue = {
|
|
174
178
|
* color: "red",
|
|
175
179
|
* "--button-accent": "oklch(62% 0.2 250)",
|
|
180
|
+
* "--button-scale": 1.1,
|
|
176
181
|
* };
|
|
177
182
|
* ```
|
|
178
183
|
*/
|
|
179
|
-
|
|
180
|
-
[key: `--${string}`]: string;
|
|
181
|
-
}
|
|
184
|
+
interface StyleValue extends CSS.Properties {
|
|
185
|
+
[key: `--${string}`]: string | number;
|
|
186
|
+
}
|
|
182
187
|
/**
|
|
183
188
|
* A value that contributes both class and style output from a base config,
|
|
184
189
|
* variant value, function variant, or refine callback.
|
|
@@ -206,8 +211,8 @@ interface RefineContext<V> {
|
|
|
206
211
|
type Refine<V> = (context: RefineContext<V>) => VariantValue;
|
|
207
212
|
type Variant$1 = ClassValue | Record<string, VariantValue> | ((value: any) => VariantValue);
|
|
208
213
|
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 };
|
|
214
|
+
type NullablePartial<T> = T extends Record<string, any> ? { [K in keyof T]?: T[K] | null; } : T | null;
|
|
215
|
+
type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K in keyof MergeExtendedVariants<E>]?: NullablePartial<MergeExtendedVariants<E>[K]> | Variant$1; };
|
|
211
216
|
//#endregion
|
|
212
217
|
//#region src/index.d.ts
|
|
213
218
|
/**
|
|
@@ -314,13 +319,17 @@ declare const splitProps: SplitPropsFunction;
|
|
|
314
319
|
/**
|
|
315
320
|
* Creates the cv and cx functions.
|
|
316
321
|
*/
|
|
317
|
-
declare function create({
|
|
318
|
-
transformClass
|
|
319
|
-
}?: CreateParams): {
|
|
322
|
+
declare function create({ transformClass }?: CreateParams): {
|
|
320
323
|
cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E>;
|
|
321
324
|
cx: (...classes: ClassValue$1[]) => string;
|
|
322
325
|
};
|
|
323
|
-
declare const cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E
|
|
326
|
+
declare const cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E>;
|
|
327
|
+
/**
|
|
328
|
+
* Joins class values without applying a class transform.
|
|
329
|
+
*
|
|
330
|
+
* This behaves like the `cx` function returned by `create()` with no options.
|
|
331
|
+
*/
|
|
332
|
+
declare function cx(...classes: ClassValue$1[]): string;
|
|
324
333
|
//#endregion
|
|
325
334
|
export { type CVComponent, CVConfig, type ClassValue, type HTMLObjProps, type HTMLProps, type JSXProps, type StyleClassProps, type StyleClassValue, type StyleValue, Variant, VariantProps, create, cv, cx, splitProps };
|
|
326
335
|
//# sourceMappingURL=index.d.ts.map
|