cva 1.0.0-beta.8 → 1.0.0-beta.9
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/LICENSE +1 -1
- package/dist/config.cjs +3 -0
- package/dist/config.d.cts +2 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +2 -0
- package/dist/core-BMF1ydiV.d.cts +188 -0
- package/dist/core-BMF1ydiV.d.mts +188 -0
- package/dist/core-DPc9m0ph.mjs +99 -0
- package/dist/core-DPc9m0ph.mjs.map +1 -0
- package/dist/core-iwLcNxRW.cjs +104 -0
- package/dist/core-iwLcNxRW.cjs.map +1 -0
- package/dist/index.cjs +20 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -117
- package/dist/index.d.mts +25 -117
- package/dist/index.mjs +20 -118
- package/dist/index.mjs.map +1 -1
- package/dist/utils.cjs +31 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +6 -0
- package/dist/utils.d.mts +6 -0
- package/dist/utils.mjs +30 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +31 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,107 +1,23 @@
|
|
|
1
|
+
import { _ as VariantProps, a as CVAVariantShape, c as CXOptions, d as ClassDictionary, f as ClassValue, g as GetSchema$1, h as DefineConfigOptions$1, i as CVAComponentShape, l as CXReturn, n as CVA, o as CX, p as Compose, r as CVAComponent, s as CXInput, t as AnyCX, u as ClassArray } from "./core-BMF1ydiV.mjs";
|
|
1
2
|
//#region src/index.d.ts
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
7
|
-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
8
|
-
type ComposedTuple<S extends CVAComponentShape | undefined, L extends readonly CVAComponentShape[]> = [S] extends [CVAComponentShape] ? [S] : L;
|
|
9
|
-
type MergedVariants<T extends readonly unknown[]> = UnionToIntersection<{ [K in keyof T]: T[K] extends {
|
|
10
|
-
config: {
|
|
11
|
-
variants?: infer V extends CVAVariantShape;
|
|
12
|
-
};
|
|
13
|
-
} ? V : never; }[number]>;
|
|
14
|
-
type RightMerge<A, B> = { [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never; };
|
|
15
|
-
type DefaultsOf<Component> = Component extends {
|
|
16
|
-
config: {
|
|
17
|
-
defaultVariants?: infer D;
|
|
18
|
-
};
|
|
19
|
-
} ? D extends undefined ? {} : D : {};
|
|
20
|
-
type MergedDefaultVariants<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Rest] ? RightMerge<DefaultsOf<Head>, MergedDefaultVariants<Rest>> : {};
|
|
21
|
-
type ComponentProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, "class" | "className">;
|
|
22
|
-
type VariantProps<Component extends (...args: any) => any> = Omit<ComponentProps<Component>, InternalVariantKey>;
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated Use the `composes` property inside `cva` instead.
|
|
25
|
-
* @example
|
|
26
|
-
* // Before
|
|
27
|
-
* const card = compose(box, stack)
|
|
28
|
-
* // After
|
|
29
|
-
* const card = cva({ composes: [box, stack] })
|
|
30
|
-
*/
|
|
31
|
-
interface Compose {
|
|
32
|
-
<T extends ReturnType<CVA>[]>(...components: [...T]): (props?: (UnionToIntersection<{ [K in keyof T]: ComponentProps<T[K]>; }[number]> | undefined) & CVAClassProp) => string;
|
|
33
|
-
}
|
|
34
|
-
interface CX {
|
|
35
|
-
(...inputs: ClassValue[]): string;
|
|
36
|
-
}
|
|
37
|
-
type CXOptions = Parameters<CX>;
|
|
38
|
-
type CXReturn = ReturnType<CX>;
|
|
39
|
-
type CVAComponentConfigBase = {
|
|
40
|
-
base?: ClassValue;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Exported so TypeScript can name this type in your generated declarations
|
|
44
|
-
* (`declaration: true`) — you shouldn't really use it directly.
|
|
45
|
-
*/
|
|
46
|
-
type CVAVariantShape = Record<string, Record<string, ClassValue>>;
|
|
47
|
-
type CVAVariantSchema<V extends CVAVariantShape> = { [Variant in keyof V]?: StringToBoolean<keyof V[Variant]> | undefined; };
|
|
48
|
-
type InternalVariantKey = `_${string}`;
|
|
49
|
-
type CVAClassProp = {
|
|
50
|
-
class?: ClassValue;
|
|
51
|
-
className?: never;
|
|
52
|
-
} | {
|
|
53
|
-
class?: never;
|
|
54
|
-
className?: ClassValue;
|
|
55
|
-
};
|
|
56
|
-
type InternalOnlyWarning = "cva's generic parameters are restricted to internal use only.";
|
|
57
|
-
type CVAComponentConfig<Config, Variants, ComposedSingle extends CVAComponentShape | undefined = CVAComponentShape | undefined, ComposedList extends readonly CVAComponentShape[] = readonly CVAComponentShape[]> = Config & {
|
|
58
|
-
composes?: ComposedSingle | readonly [...ComposedList];
|
|
59
|
-
} & (Variants extends CVAVariantShape ? CVAComponentConfigBase & {
|
|
60
|
-
variants?: Variants;
|
|
61
|
-
compoundVariants?: (Variants extends CVAVariantShape ? (CVAVariantSchema<Variants> | { [Variant in keyof Variants]?: StringToBoolean<keyof Variants[Variant]> | StringToBoolean<keyof Variants[Variant]>[] | undefined; }) & CVAClassProp : CVAClassProp)[];
|
|
62
|
-
defaultVariants?: CVAVariantSchema<Variants>;
|
|
63
|
-
} : CVAComponentConfigBase & {
|
|
64
|
-
variants?: never;
|
|
65
|
-
compoundVariants?: never;
|
|
66
|
-
defaultVariants?: never;
|
|
67
|
-
});
|
|
3
|
+
/** @deprecated Import `GetSchema` from `cva/utils` instead. */
|
|
4
|
+
type GetSchema = GetSchema$1;
|
|
5
|
+
/** @deprecated Import `getSchema` from `cva/utils` instead. */
|
|
6
|
+
declare const getSchema: GetSchema;
|
|
68
7
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
8
|
+
* @deprecated Import `DefineConfigOptions` from `cva/config` instead and provide
|
|
9
|
+
* the required `cx` concatenator (for example, `clsx`).
|
|
71
10
|
*/
|
|
72
|
-
interface
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
config: Config;
|
|
11
|
+
interface DefineConfigOptions<TCX extends AnyCX = CX> extends Omit<DefineConfigOptions$1<TCX>, "cx"> {
|
|
12
|
+
/** Defaults to `clsx`. */
|
|
13
|
+
cx?: DefineConfigOptions$1<TCX>["cx"];
|
|
76
14
|
}
|
|
77
15
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
16
|
+
* @deprecated Import `DefineConfig` from `cva/config` instead. Its options require
|
|
17
|
+
* a `cx` concatenator (for example, `clsx`).
|
|
80
18
|
*/
|
|
81
|
-
type CVAComponentShape = CVAComponent<any, any>;
|
|
82
|
-
type CVADefaultVariants<Config> = Config extends {
|
|
83
|
-
defaultVariants?: infer D;
|
|
84
|
-
} ? D : {};
|
|
85
|
-
interface CVA {
|
|
86
|
-
<_ extends InternalOnlyWarning, Config, Variants, ComposedSingle extends CVAComponentShape | undefined = undefined, ComposedList extends readonly CVAComponentShape[] = []>(config: CVAComponentConfig<Config, Variants, ComposedSingle, ComposedList>): CVAComponent<Omit<Config, "defaultVariants"> & {
|
|
87
|
-
variants: Variants & MergedVariants<ComposedTuple<ComposedSingle, ComposedList>>;
|
|
88
|
-
defaultVariants: Omit<MergedDefaultVariants<ComposedTuple<ComposedSingle, ComposedList>>, keyof CVADefaultVariants<Config>> & CVADefaultVariants<Config>;
|
|
89
|
-
}, Variants & MergedVariants<ComposedTuple<ComposedSingle, ComposedList>>>;
|
|
90
|
-
}
|
|
91
|
-
interface DefineConfigOptions {
|
|
92
|
-
hooks?: {
|
|
93
|
-
/**
|
|
94
|
-
* @deprecated please use `onComplete`
|
|
95
|
-
*/
|
|
96
|
-
"cx:done"?: (className: string) => string;
|
|
97
|
-
/**
|
|
98
|
-
* Returns the completed string of concatenated classes/classNames.
|
|
99
|
-
*/
|
|
100
|
-
onComplete?: (className: string) => string;
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
19
|
interface DefineConfig {
|
|
104
|
-
(options?: DefineConfigOptions): {
|
|
20
|
+
<TCX extends AnyCX = CX>(options?: DefineConfigOptions<TCX>): {
|
|
105
21
|
/**
|
|
106
22
|
* @deprecated Use the `composes` property inside `cva` instead.
|
|
107
23
|
* @example
|
|
@@ -110,28 +26,20 @@ interface DefineConfig {
|
|
|
110
26
|
* // After
|
|
111
27
|
* const card = cva({ composes: [box, stack] })
|
|
112
28
|
*/
|
|
113
|
-
compose: Compose
|
|
114
|
-
cx: CX
|
|
115
|
-
cva: CVA
|
|
29
|
+
compose: Compose<CXInput<TCX>>;
|
|
30
|
+
cx: CX<CXInput<TCX>>;
|
|
31
|
+
cva: CVA<CXInput<TCX>>;
|
|
116
32
|
};
|
|
117
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Import `defineConfig` from `cva/config` instead — the `cva`
|
|
36
|
+
* package is the clsx preset, while `cva/config` is where custom
|
|
37
|
+
* configuration (your own `cx` concatenator, hooks) lives.
|
|
38
|
+
*/
|
|
118
39
|
declare const defineConfig: DefineConfig;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
config: CVAComponentConfig<Config, Variants>;
|
|
123
|
-
} : never)): { [Variant in keyof Variants as Variant extends InternalVariantKey ? never : Variant]: Config extends CVAComponentConfig<Config, Variants> ? Variant extends keyof Config["defaultVariants"] ? Config["defaultVariants"][Variant] extends undefined ? never : {
|
|
124
|
-
values: ReadonlyArray<StringToBoolean<keyof Variants[Variant]>>;
|
|
125
|
-
defaultValue: Readonly<StringToBoolean<Config["defaultVariants"][Variant]>>;
|
|
126
|
-
} : {
|
|
127
|
-
values: ReadonlyArray<StringToBoolean<keyof Variants[Variant]>>;
|
|
128
|
-
} : never; } extends (infer Schema) ? { [K in keyof Schema as Schema[K] extends {
|
|
129
|
-
values: readonly never[];
|
|
130
|
-
} ? never : K]: Schema[K] extends {
|
|
131
|
-
defaultValue: never;
|
|
132
|
-
} ? never : Schema[K]; } : never;
|
|
133
|
-
}
|
|
134
|
-
declare const getSchema: GetSchema;
|
|
40
|
+
/** @deprecated Use the `composes` property inside `cva` instead. */
|
|
41
|
+
declare const compose: Compose<import("clsx").ClassValue>;
|
|
42
|
+
declare const cva: CVA<import("clsx").ClassValue>, cx: CX<import("clsx").ClassValue>;
|
|
135
43
|
//#endregion
|
|
136
|
-
export { CVA, CVAComponent, CVAComponentShape, CVAVariantShape, CX, CXOptions, CXReturn, ClassArray, ClassDictionary, ClassValue, Compose, DefineConfig, DefineConfigOptions, GetSchema, VariantProps, compose, cva, cx, defineConfig, getSchema };
|
|
44
|
+
export { type AnyCX, type CVA, type CVAComponent, type CVAComponentShape, type CVAVariantShape, type CX, type CXInput, type CXOptions, type CXReturn, type ClassArray, type ClassDictionary, type ClassValue, type Compose, DefineConfig, DefineConfigOptions, GetSchema, type VariantProps, compose, cva, cx, defineConfig, getSchema };
|
|
137
45
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { t as defineConfig$1 } from "./core-DPc9m0ph.mjs";
|
|
2
|
+
import { getSchema as getSchema$1 } from "./utils.mjs";
|
|
1
3
|
import { clsx } from "clsx";
|
|
2
4
|
//#region src/index.ts
|
|
3
5
|
/**
|
|
4
|
-
* Copyright 2022 Joe Bell. All rights reserved.
|
|
6
|
+
* Copyright 2022-present Joe Bell. All rights reserved.
|
|
5
7
|
*
|
|
6
8
|
* This file is licensed to you under the Apache License, Version 2.0
|
|
7
9
|
* (the "License"); you may not use this file except in compliance with the
|
|
@@ -15,124 +17,24 @@ import { clsx } from "clsx";
|
|
|
15
17
|
* License for the specific language governing permissions and limitations under
|
|
16
18
|
* the License.
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!variants) return acc;
|
|
31
|
-
const merged = { ...acc };
|
|
32
|
-
for (const key of Object.keys(variants)) merged[key] = {
|
|
33
|
-
...merged[key],
|
|
34
|
-
...variants[key]
|
|
35
|
-
};
|
|
36
|
-
return merged;
|
|
37
|
-
};
|
|
38
|
-
const mergedVariants = mergeVariants(components.reduce((acc, component) => {
|
|
39
|
-
var _component$config;
|
|
40
|
-
return mergeVariants(acc, (_component$config = component.config) === null || _component$config === void 0 ? void 0 : _component$config.variants);
|
|
41
|
-
}, {}), config === null || config === void 0 ? void 0 : config.variants);
|
|
42
|
-
const mergedDefaultVariants = {
|
|
43
|
-
...components.reduce((acc, component) => {
|
|
44
|
-
var _component$config2;
|
|
45
|
-
return {
|
|
46
|
-
...acc,
|
|
47
|
-
...(_component$config2 = component.config) === null || _component$config2 === void 0 ? void 0 : _component$config2.defaultVariants
|
|
48
|
-
};
|
|
49
|
-
}, {}),
|
|
50
|
-
...config === null || config === void 0 ? void 0 : config.defaultVariants
|
|
51
|
-
};
|
|
52
|
-
const component = (props) => {
|
|
53
|
-
var _config$compoundVaria;
|
|
54
|
-
const definedPropsWithoutClass = components.length || (config === null || config === void 0 ? void 0 : config.variants) != null ? Object.fromEntries(Object.entries(props || {}).filter(([key, value]) => key !== "class" && key !== "className" && typeof value !== "undefined")) : {};
|
|
55
|
-
const getComposedClassNames = components.length ? components.map((component) => component({
|
|
56
|
-
...mergedDefaultVariants,
|
|
57
|
-
...definedPropsWithoutClass
|
|
58
|
-
})) : emptyClassNames;
|
|
59
|
-
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(getComposedClassNames, config === null || config === void 0 ? void 0 : config.base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
60
|
-
const { variants } = config;
|
|
61
|
-
const getVariantClassNames = Object.keys(variants).map((variant) => {
|
|
62
|
-
const variantProp = props === null || props === void 0 ? void 0 : props[variant];
|
|
63
|
-
const defaultVariantProp = mergedDefaultVariants[variant];
|
|
64
|
-
const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
|
|
65
|
-
return variants[variant][variantKey];
|
|
66
|
-
});
|
|
67
|
-
const defaultsAndProps = {
|
|
68
|
-
...mergedDefaultVariants,
|
|
69
|
-
...definedPropsWithoutClass
|
|
70
|
-
};
|
|
71
|
-
const getCompoundVariantClassNames = config === null || config === void 0 || (_config$compoundVaria = config.compoundVariants) === null || _config$compoundVaria === void 0 ? void 0 : _config$compoundVaria.reduce((acc, { class: cvClass, className: cvClassName, ...cvConfig }) => Object.entries(cvConfig).every(([cvKey, cvSelector]) => {
|
|
72
|
-
const selector = defaultsAndProps[cvKey];
|
|
73
|
-
return Array.isArray(cvSelector) ? cvSelector.includes(selector) : selector === cvSelector;
|
|
74
|
-
}) ? [
|
|
75
|
-
...acc,
|
|
76
|
-
cvClass,
|
|
77
|
-
cvClassName
|
|
78
|
-
] : acc, []);
|
|
79
|
-
return cx(getComposedClassNames, config === null || config === void 0 ? void 0 : config.base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
80
|
-
};
|
|
81
|
-
component.config = {
|
|
82
|
-
...config,
|
|
83
|
-
variants: mergedVariants,
|
|
84
|
-
defaultVariants: mergedDefaultVariants
|
|
85
|
-
};
|
|
86
|
-
return component;
|
|
20
|
+
/** @deprecated Import `getSchema` from `cva/utils` instead. */
|
|
21
|
+
const getSchema = getSchema$1;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Import `defineConfig` from `cva/config` instead — the `cva`
|
|
24
|
+
* package is the clsx preset, while `cva/config` is where custom
|
|
25
|
+
* configuration (your own `cx` concatenator, hooks) lives.
|
|
26
|
+
*/
|
|
27
|
+
const defineConfig = ((options) => {
|
|
28
|
+
var _options$cx;
|
|
29
|
+
return defineConfig$1({
|
|
30
|
+
...options,
|
|
31
|
+
cx: (_options$cx = options === null || options === void 0 ? void 0 : options.cx) !== null && _options$cx !== void 0 ? _options$cx : clsx
|
|
87
32
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
...value
|
|
94
|
-
} : value;
|
|
95
|
-
});
|
|
96
|
-
return acc;
|
|
97
|
-
}, {});
|
|
98
|
-
const component = (props) => {
|
|
99
|
-
const propsWithoutClass = Object.fromEntries(Object.entries(props || {}).filter(([key]) => !["class", "className"].includes(key)));
|
|
100
|
-
return cx(components.map((component) => component(propsWithoutClass)), props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
101
|
-
};
|
|
102
|
-
component.config = config;
|
|
103
|
-
return component;
|
|
104
|
-
};
|
|
105
|
-
return {
|
|
106
|
-
compose,
|
|
107
|
-
cva,
|
|
108
|
-
cx
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
const { compose, cva, cx } = defineConfig();
|
|
112
|
-
const getSchema = (component) => {
|
|
113
|
-
var _component$config3;
|
|
114
|
-
if (!((_component$config3 = component.config) === null || _component$config3 === void 0 ? void 0 : _component$config3.variants)) return {};
|
|
115
|
-
return Object.entries(component.config.variants).reduce((acc, [key, value]) => {
|
|
116
|
-
var _component$config$def;
|
|
117
|
-
if (key.startsWith("_")) return acc;
|
|
118
|
-
const defaultValue = (_component$config$def = component.config.defaultVariants) === null || _component$config$def === void 0 ? void 0 : _component$config$def[key];
|
|
119
|
-
const hasDefaultValue = defaultValue !== void 0;
|
|
120
|
-
const values = Object.keys(value).map((v) => {
|
|
121
|
-
if (v === "true") return true;
|
|
122
|
-
if (v === "false") return false;
|
|
123
|
-
const n = Number(v);
|
|
124
|
-
return Number.isFinite(n) && String(n) === v ? n : v;
|
|
125
|
-
});
|
|
126
|
-
const hasValues = values.length > 0;
|
|
127
|
-
return hasValues || hasDefaultValue ? {
|
|
128
|
-
...acc,
|
|
129
|
-
[key]: {
|
|
130
|
-
...hasValues ? { values } : {},
|
|
131
|
-
...hasDefaultValue ? { defaultValue } : {}
|
|
132
|
-
}
|
|
133
|
-
} : acc;
|
|
134
|
-
}, {});
|
|
135
|
-
};
|
|
33
|
+
});
|
|
34
|
+
const preset = defineConfig$1({ cx: clsx });
|
|
35
|
+
/** @deprecated Use the `composes` property inside `cva` instead. */
|
|
36
|
+
const compose = preset.compose;
|
|
37
|
+
const { cva, cx } = preset;
|
|
136
38
|
//#endregion
|
|
137
39
|
export { compose, cva, cx, defineConfig, getSchema };
|
|
138
40
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2022 Joe Bell. All rights reserved.\n *\n * This file is licensed to you under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with the\n * License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\nimport { clsx } from \"clsx\";\n\n/* Types\n ============================================ */\n\n/* clsx\n ---------------------------------- */\n\n// When compiling with `declaration: true`, many projects experience the dreaded\n// TS2742 error. To combat this, we copy clsx's types manually.\n// Should this project move to JSDoc, this workaround would no longer be needed.\n\nexport type ClassValue =\n | ClassArray\n | ClassDictionary\n | string\n | number\n | bigint\n | null\n | boolean\n | undefined;\nexport type ClassDictionary = Record<string, any>;\nexport type ClassArray = ClassValue[];\n\n/* Utils\n ---------------------------------- */\n\ntype OmitUndefined<T> = T extends undefined ? never : T;\ntype StringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never;\n\n// `composes` accepts either a single component or a list of components. A\n// plain union (`CVAComponentShape | CVAComponentShape[]`) collapses an array\n// literal's element type to a union, silently dropping components whose\n// variants are a structural subtype of another composed component's (e.g.\n// `composes: [a, b]` where `b`'s variants are a superset of `a`'s). Splitting\n// inference across two type parameters preserves the array as a real tuple.\ntype ComposedTuple<\n S extends CVAComponentShape | undefined,\n L extends readonly CVAComponentShape[],\n> = [S] extends [CVAComponentShape] ? [S] : L;\n\ntype MergedVariants<T extends readonly unknown[]> = UnionToIntersection<\n {\n [K in keyof T]: T[K] extends {\n config: { variants?: infer V extends CVAVariantShape };\n }\n ? V\n : never;\n }[number]\n>;\n\n// Right-biased merge (`B`'s keys win on conflicts) implemented as a mapped\n// type rather than `Omit<A, keyof B> & B`: the latter stays an unresolved\n// deferred type when `A`/`B` are themselves generic (as they are here, via\n// `ReturnType<CVA>` with no concrete `Config`), which then breaks downstream\n// `any`-narrowing in unrelated code that consumes `ReturnType<CVA>` (e.g.\n// the deprecated `compose`). A mapped type resolves eagerly instead.\ntype RightMerge<A, B> = {\n [K in keyof A | keyof B]: K extends keyof B\n ? B[K]\n : K extends keyof A\n ? A[K]\n : never;\n};\n\n// `D` infers as `undefined` (not absent) when a component declares no\n// `defaultVariants` at all. `NonNullable<undefined>` would give `never`,\n// and `keyof never` is `string | number | symbol` (not `never`) — poisoning\n// `RightMerge`'s key union with every possible key. Normalize to `{}` instead,\n// matching a component that contributes nothing to the merge.\ntype DefaultsOf<Component> = Component extends {\n config: { defaultVariants?: infer D };\n}\n ? D extends undefined\n ? {}\n : D\n : {};\n\ntype MergedDefaultVariants<T extends readonly unknown[]> = T extends readonly [\n infer Head,\n ...infer Rest,\n]\n ? RightMerge<DefaultsOf<Head>, MergedDefaultVariants<Rest>>\n : {};\n\ntype ComponentProps<Component extends (...args: any) => any> = Omit<\n OmitUndefined<Parameters<Component>[0]>,\n \"class\" | \"className\"\n>;\n\nexport type VariantProps<Component extends (...args: any) => any> = Omit<\n ComponentProps<Component>,\n InternalVariantKey\n>;\n\n/* compose\n ---------------------------------- */\n\n/**\n * @deprecated Use the `composes` property inside `cva` instead.\n * @example\n * // Before\n * const card = compose(box, stack)\n * // After\n * const card = cva({ composes: [box, stack] })\n */\nexport interface Compose {\n <T extends ReturnType<CVA>[]>(\n ...components: [...T]\n ): (\n props?: (\n | UnionToIntersection<\n {\n [K in keyof T]: ComponentProps<T[K]>;\n }[number]\n >\n | undefined\n ) &\n CVAClassProp,\n ) => string;\n}\n\n/* cx\n ---------------------------------- */\n\nexport interface CX {\n (...inputs: ClassValue[]): string;\n}\n\nexport type CXOptions = Parameters<CX>;\nexport type CXReturn = ReturnType<CX>;\n\n/* cva\n ============================================ */\n\ntype CVAComponentConfigBase = { base?: ClassValue };\n/**\n * Exported so TypeScript can name this type in your generated declarations\n * (`declaration: true`) — you shouldn't really use it directly.\n */\nexport type CVAVariantShape = Record<string, Record<string, ClassValue>>;\ntype CVAVariantSchema<V extends CVAVariantShape> = {\n [Variant in keyof V]?: StringToBoolean<keyof V[Variant]> | undefined;\n};\ntype InternalVariantKey = `_${string}`;\ntype CVAClassProp =\n | {\n class?: ClassValue;\n className?: never;\n }\n | {\n class?: never;\n className?: ClassValue;\n };\n\ntype InternalOnlyWarning =\n \"cva's generic parameters are restricted to internal use only.\";\n\ntype CVAComponentConfig<\n Config,\n Variants,\n ComposedSingle extends CVAComponentShape | undefined =\n | CVAComponentShape\n | undefined,\n ComposedList extends readonly CVAComponentShape[] =\n readonly CVAComponentShape[],\n> = Config & {\n composes?: ComposedSingle | readonly [...ComposedList];\n} & (Variants extends CVAVariantShape\n ? CVAComponentConfigBase & {\n variants?: Variants;\n compoundVariants?: (Variants extends CVAVariantShape\n ? (\n | CVAVariantSchema<Variants>\n | {\n [Variant in keyof Variants]?:\n | StringToBoolean<keyof Variants[Variant]>\n | StringToBoolean<keyof Variants[Variant]>[]\n | undefined;\n }\n ) &\n CVAClassProp\n : CVAClassProp)[];\n defaultVariants?: CVAVariantSchema<Variants>;\n }\n : CVAComponentConfigBase & {\n variants?: never;\n compoundVariants?: never;\n defaultVariants?: never;\n });\n\n/**\n * Exported so TypeScript can name this type in your generated declarations\n * (`declaration: true`) — you shouldn't really use it directly.\n */\nexport interface CVAComponent<Config, Variants> {\n (\n props?: Variants extends CVAVariantShape\n ? CVAVariantSchema<Variants> & CVAClassProp\n : CVAClassProp,\n ): string;\n /** @internal */\n config: Config;\n}\n\n// The loosest form a composable component can take, constraining `composes`\n// and the composition merge helpers above. Deriving it from `CVAComponent`\n// keeps the two from drifting: instantiated with `any`, the props conditional\n// and `config` both collapse to `any` (mapped types over `any` are `any`),\n// i.e. `{ (props?: any): string; config: any }`. The required `config`\n// property is what rejects plain functions and (deprecated) `compose`\n// results.\n//\n// The `any` arguments are deliberate, not lazy typing — a shaped `config`\n// (e.g. `{ variants?: CVAVariantShape }`) was tried and verifiably breaks:\n// a variant-less `cva({ base })` carries `variants: unknown`, and\n// `ReturnType<CVA>` instantiates this constraint inside the\n// `Compose`/`GetSchema` guards, where the shaped form rejects every real\n// component via props contravariance.\n/**\n * Exported so TypeScript can name this type in your generated declarations\n * (`declaration: true`) — you shouldn't really use it directly.\n */\nexport type CVAComponentShape = CVAComponent<any, any>;\n\ntype CVADefaultVariants<Config> = Config extends { defaultVariants?: infer D }\n ? D\n : {};\n\nexport interface CVA {\n <\n _ extends InternalOnlyWarning,\n Config,\n Variants,\n ComposedSingle extends CVAComponentShape | undefined = undefined,\n ComposedList extends readonly CVAComponentShape[] = [],\n >(\n config: CVAComponentConfig<Config, Variants, ComposedSingle, ComposedList>,\n ): CVAComponent<\n Omit<Config, \"defaultVariants\"> & {\n variants: Variants &\n MergedVariants<ComposedTuple<ComposedSingle, ComposedList>>;\n // Local `defaultVariants` win over composed ones on key conflicts,\n // matching the runtime spread order. A plain intersection would collapse\n // a conflicting key's value to `never` (e.g. `\"sm\" & \"lg\"`), which then\n // silently drops the variant from `getSchema`'s inferred type.\n defaultVariants: Omit<\n MergedDefaultVariants<ComposedTuple<ComposedSingle, ComposedList>>,\n keyof CVADefaultVariants<Config>\n > &\n CVADefaultVariants<Config>;\n },\n Variants & MergedVariants<ComposedTuple<ComposedSingle, ComposedList>>\n >;\n}\n\n/* defineConfig\n ---------------------------------- */\n\nexport interface DefineConfigOptions {\n hooks?: {\n /**\n * @deprecated please use `onComplete`\n */\n \"cx:done\"?: (className: string) => string;\n /**\n * Returns the completed string of concatenated classes/classNames.\n */\n onComplete?: (className: string) => string;\n };\n}\n\nexport interface DefineConfig {\n (options?: DefineConfigOptions): {\n /**\n * @deprecated Use the `composes` property inside `cva` instead.\n * @example\n * // Before\n * const card = compose(box, stack)\n * // After\n * const card = cva({ composes: [box, stack] })\n */\n compose: Compose;\n cx: CX;\n cva: CVA;\n };\n}\n\n/* Exports\n ============================================ */\n\nconst falsyToString = <T extends unknown>(value: T) =>\n typeof value === \"boolean\" ? `${value}` : value === 0 ? \"0\" : value;\n\n// Shared across every non-composed call, rather than allocating a fresh `[]`\n// per call — `cx` (clsx) treats an empty array identically to an absent one.\nconst emptyClassNames: string[] = [];\n\nexport const defineConfig: DefineConfig = (options) => {\n const cx: CX = (...inputs) => {\n if (typeof options?.hooks?.[\"cx:done\"] !== \"undefined\")\n return options?.hooks[\"cx:done\"](clsx(inputs));\n\n if (typeof options?.hooks?.onComplete !== \"undefined\")\n return options?.hooks.onComplete(clsx(inputs));\n\n return clsx(inputs);\n };\n\n const cva = (<\n _ extends InternalOnlyWarning,\n Config,\n Variants,\n ComposedSingle extends CVAComponentShape | undefined = undefined,\n ComposedList extends readonly CVAComponentShape[] = [],\n >(\n config: CVAComponentConfig<Config, Variants, ComposedSingle, ComposedList>,\n ) => {\n const components = (\n config?.composes == null\n ? []\n : Array.isArray(config.composes)\n ? config.composes\n : [config.composes]\n ) as CVAComponentShape[];\n // A one-level-deep merge per variant key, so overlapping variants (e.g.\n // multiple composed components declaring `style`) union their values\n // instead of the last component's values silently replacing the rest.\n const mergeVariants = (\n acc: CVAVariantShape,\n variants: CVAVariantShape | undefined,\n ): CVAVariantShape => {\n if (!variants) return acc;\n const merged: CVAVariantShape = { ...acc };\n for (const key of Object.keys(variants)) {\n merged[key] = { ...merged[key], ...variants[key] };\n }\n return merged;\n };\n const mergedVariantsFromComposed = components.reduce(\n (acc: CVAVariantShape, component: CVAComponentShape) =>\n mergeVariants(acc, component.config?.variants),\n {} as CVAVariantShape,\n );\n const mergedVariants = mergeVariants(\n mergedVariantsFromComposed,\n config?.variants as CVAVariantShape | undefined,\n );\n const mergedDefaultVariantsFromComposed = components.reduce(\n (acc: Record<string, unknown>, component: CVAComponentShape) => ({\n ...acc,\n ...component.config?.defaultVariants,\n }),\n {} as Record<string, unknown>,\n );\n // Local `defaultVariants` win over composed ones here too (last spread).\n const mergedDefaultVariants: Record<string, unknown> = {\n ...mergedDefaultVariantsFromComposed,\n ...config?.defaultVariants,\n };\n\n const component: CVAComponent<typeof config, typeof config.variants> = (\n props,\n ) => {\n // Strip `class`/`className` and explicit `undefined` from props once,\n // reused for both the composed-component calls and compound-variant\n // matching. An explicit `{ variant: undefined }` is dropped so it falls\n // back to the (possibly composed) default, matching variant resolution\n // below. Only built when something consumes it — a plain component with\n // no `composes` and no `variants` skips the work entirely.\n const definedPropsWithoutClass =\n components.length || config?.variants != null\n ? Object.fromEntries(\n Object.entries(props || {}).filter(\n ([key, value]) =>\n key !== \"class\" &&\n key !== \"className\" &&\n typeof value !== \"undefined\",\n ),\n )\n : {};\n\n const getComposedClassNames = components.length\n ? components.map((component: CVAComponentShape) =>\n component({\n ...mergedDefaultVariants,\n ...definedPropsWithoutClass,\n }),\n )\n : emptyClassNames;\n\n if (config?.variants == null) {\n return cx(\n getComposedClassNames,\n config?.base,\n props?.class,\n props?.className,\n );\n }\n\n const { variants } = config;\n\n // Resolve against the *merged* defaults (composed + local) so a variant\n // redeclared locally over a composed key uses the same effective default\n // the composed components and `getSchema` see.\n const getVariantClassNames = Object.keys(variants).map(\n (variant: keyof typeof variants) => {\n const variantProp = props?.[variant as keyof typeof props];\n const defaultVariantProp = mergedDefaultVariants[variant as string];\n\n const variantKey = (falsyToString(variantProp) ||\n falsyToString(\n defaultVariantProp,\n )) as keyof (typeof variants)[typeof variant];\n\n return variants[variant][variantKey];\n },\n );\n\n const defaultsAndProps = {\n ...mergedDefaultVariants,\n ...definedPropsWithoutClass,\n };\n\n const getCompoundVariantClassNames = config?.compoundVariants?.reduce(\n (\n acc: ClassValue[],\n {\n class: cvClass,\n className: cvClassName,\n ...cvConfig\n }: CVAClassProp & Record<string, unknown>,\n ) =>\n Object.entries(cvConfig).every(([cvKey, cvSelector]) => {\n const selector =\n defaultsAndProps[cvKey as keyof typeof defaultsAndProps];\n\n return Array.isArray(cvSelector)\n ? cvSelector.includes(selector)\n : selector === cvSelector;\n })\n ? [...acc, cvClass, cvClassName]\n : acc,\n [] as ClassValue[],\n );\n\n return cx(\n getComposedClassNames,\n config?.base,\n getVariantClassNames,\n getCompoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n component.config = {\n ...config,\n variants: mergedVariants,\n defaultVariants: mergedDefaultVariants,\n };\n\n return component as ReturnType<CVA>;\n }) as CVA;\n\n const compose: Compose = (...components) => {\n const config = components.reduce(\n (acc, { config }) => {\n Object.entries(config || {}).forEach(([key, value]) => {\n acc[key] =\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? {\n ...acc[key],\n ...value,\n }\n : value;\n });\n return acc;\n },\n // A loose accumulator: composed configs carry heterogeneous values\n // (base strings, variant maps, compoundVariant arrays), not just the\n // `CVAVariantShape` the merged `variants` key holds.\n {} as Record<string, any>,\n );\n\n const component: CVAComponent<typeof config, typeof config.variants> = (\n props,\n ) => {\n const propsWithoutClass = Object.fromEntries(\n Object.entries(props || {}).filter(\n ([key]) => ![\"class\", \"className\"].includes(key),\n ),\n );\n\n return cx(\n components.map((component) => component(propsWithoutClass)),\n props?.class,\n props?.className,\n );\n };\n\n component.config = config;\n\n return component;\n };\n\n return {\n compose,\n cva,\n cx,\n };\n};\n\nexport const { compose, cva, cx } = defineConfig();\n\nexport interface GetSchema {\n <_ extends InternalOnlyWarning, Component, Config, Variants>(\n component: Component &\n (Component extends ReturnType<CVA>\n ? { config: CVAComponentConfig<Config, Variants> }\n : never),\n ): {\n [Variant in keyof Variants as Variant extends InternalVariantKey\n ? never\n : Variant]: Config extends CVAComponentConfig<Config, Variants>\n ? Variant extends keyof Config[\"defaultVariants\"]\n ? Config[\"defaultVariants\"][Variant] extends undefined\n ? never\n : {\n values: ReadonlyArray<StringToBoolean<keyof Variants[Variant]>>;\n defaultValue: Readonly<\n StringToBoolean<Config[\"defaultVariants\"][Variant]>\n >;\n }\n : {\n values: ReadonlyArray<StringToBoolean<keyof Variants[Variant]>>;\n }\n : never;\n // Iterate over the returned schema and remove any keys that have no values\n } extends infer Schema\n ? {\n [K in keyof Schema as Schema[K] extends {\n values: readonly never[];\n }\n ? never\n : K]: Schema[K] extends { defaultValue: never } ? never : Schema[K];\n }\n : never;\n}\n\nexport const getSchema: GetSchema = (component) => {\n if (!component.config?.variants) return {} as any;\n\n return Object.entries(component.config.variants).reduce(\n (acc, [key, value]) => {\n if (key.startsWith(\"_\")) return acc;\n\n const defaultValue = component.config.defaultVariants?.[key];\n const hasDefaultValue = defaultValue !== undefined;\n const values = Object.keys(value).map((v) => {\n if (v === \"true\") return true;\n if (v === \"false\") return false;\n // Normalize numeric-literal keys back to numbers, since that's how\n // they appear in variant prop types (`keyof { 1: ... }` is `1`, not\n // `\"1\"`) — object keys are always strings/symbols at runtime. The\n // `String(n) === v` round-trip only accepts canonical numeric forms\n // (so `\"01\"`, `\"\"`, `\" 1\"` stay strings), covering negatives too.\n const n = Number(v);\n return Number.isFinite(n) && String(n) === v ? n : v;\n }) as StringToBoolean<keyof typeof value>[];\n const hasValues = values.length > 0;\n\n return hasValues || hasDefaultValue\n ? {\n ...acc,\n [key]: {\n ...(hasValues ? { values } : {}),\n ...(hasDefaultValue ? { defaultValue } : {}),\n },\n }\n : acc;\n },\n {} as ReturnType<GetSchema>,\n );\n};\n"],"mappings":";;;;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1D,MAAO,OAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IACP,MAAO,SACT;EACF;EAEA,UAAU,SAAS;EAEnB,OAAO;CACT;CAEA,OAAO;EACL;EACA;EACA;CACF;AACF;AAEA,MAAa,EAAE,SAAS,KAAK,OAAO,aAAa;AAqCjD,MAAa,aAAwB,cAAc;;CACjD,IAAI,GAAA,qBAAC,UAAU,YAAA,QAAA,uBAAA,KAAA,IAAA,KAAA,IAAA,mBAAQ,WAAU,OAAO,CAAC;CAEzC,OAAO,OAAO,QAAQ,UAAU,OAAO,QAAQ,CAAC,CAAC,QAC9C,KAAK,CAAC,KAAK,WAAW;;EACrB,IAAI,IAAI,WAAW,GAAG,GAAG,OAAO;EAEhC,MAAM,gBAAA,wBAAe,UAAU,OAAO,qBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAkB;EACxD,MAAM,kBAAkB,iBAAiB,KAAA;EACzC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM;GAC3C,IAAI,MAAM,QAAQ,OAAO;GACzB,IAAI,MAAM,SAAS,OAAO;GAM1B,MAAM,IAAI,OAAO,CAAC;GAClB,OAAO,OAAO,SAAS,CAAC,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI;EACrD,CAAC;EACD,MAAM,YAAY,OAAO,SAAS;EAElC,OAAO,aAAa,kBAChB;GACE,GAAG;IACF,MAAM;IACL,GAAI,YAAY,EAAE,OAAO,IAAI,CAAC;IAC9B,GAAI,kBAAkB,EAAE,aAAa,IAAI,CAAC;GAC5C;EACF,IACA;CACN,GACA,CAAC,CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["getSchemaUtils","defineCoreConfig"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2022-present Joe Bell. All rights reserved.\n *\n * This file is licensed to you under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with the\n * License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\nimport { clsx } from \"clsx\";\nimport {\n defineConfig as defineCoreConfig,\n type AnyCX,\n type CVA,\n type CXInput,\n type Compose,\n type CX,\n type DefineConfigOptions as CoreDefineConfigOptions,\n} from \"./core.js\";\nimport {\n getSchema as getSchemaUtils,\n type GetSchema as UtilsGetSchema,\n} from \"./utils.js\";\n\nexport type {\n AnyCX,\n ClassValue,\n ClassDictionary,\n ClassArray,\n VariantProps,\n Compose,\n CX,\n CXInput,\n CXOptions,\n CXReturn,\n CVAVariantShape,\n CVAComponent,\n CVAComponentShape,\n CVA,\n} from \"./config.js\";\n\n/** @deprecated Import `GetSchema` from `cva/utils` instead. */\nexport type GetSchema = UtilsGetSchema;\n\n/** @deprecated Import `getSchema` from `cva/utils` instead. */\nexport const getSchema: GetSchema = getSchemaUtils;\n\n/**\n * @deprecated Import `DefineConfigOptions` from `cva/config` instead and provide\n * the required `cx` concatenator (for example, `clsx`).\n */\nexport interface DefineConfigOptions<TCX extends AnyCX = CX> extends Omit<\n CoreDefineConfigOptions<TCX>,\n \"cx\"\n> {\n /** Defaults to `clsx`. */\n cx?: CoreDefineConfigOptions<TCX>[\"cx\"];\n}\n\n/**\n * @deprecated Import `DefineConfig` from `cva/config` instead. Its options require\n * a `cx` concatenator (for example, `clsx`).\n */\nexport interface DefineConfig {\n <TCX extends AnyCX = CX>(\n options?: DefineConfigOptions<TCX>,\n ): {\n /**\n * @deprecated Use the `composes` property inside `cva` instead.\n * @example\n * // Before\n * const card = compose(box, stack)\n * // After\n * const card = cva({ composes: [box, stack] })\n */\n compose: Compose<CXInput<TCX>>;\n cx: CX<CXInput<TCX>>;\n cva: CVA<CXInput<TCX>>;\n };\n}\n\n/**\n * @deprecated Import `defineConfig` from `cva/config` instead — the `cva`\n * package is the clsx preset, while `cva/config` is where custom\n * configuration (your own `cx` concatenator, hooks) lives.\n */\nexport const defineConfig = ((options?: DefineConfigOptions) =>\n defineCoreConfig({\n ...options,\n cx: options?.cx ?? clsx,\n })) as DefineConfig;\n\nconst preset = defineCoreConfig({ cx: clsx });\n\n/** @deprecated Use the `composes` property inside `cva` instead. */\nexport const compose = preset.compose;\nexport const { cva, cx } = preset;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,YAAuBA;;;;;;AAyCpC,MAAa,iBAAiB,YAC5B;;uBAAiB;EACf,GAAG;EACH,KAAA,cAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAI,QAAS,QAAA,QAAA,gBAAA,KAAA,IAAA,cAAM;CACrB,CAAC;;AAEH,MAAM,SAASC,eAAiB,EAAE,IAAI,KAAK,CAAC;;AAG5C,MAAa,UAAU,OAAO;AAC9B,MAAa,EAAE,KAAK,OAAO"}
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const getSchema = ((component) => {
|
|
4
|
+
var _component$config;
|
|
5
|
+
const variants = (_component$config = component.config) === null || _component$config === void 0 ? void 0 : _component$config.variants;
|
|
6
|
+
if (!variants) return {};
|
|
7
|
+
return Object.entries(variants).reduce((acc, [key, value]) => {
|
|
8
|
+
var _component$config$def;
|
|
9
|
+
if (key.startsWith("_")) return acc;
|
|
10
|
+
const defaultValue = (_component$config$def = component.config.defaultVariants) === null || _component$config$def === void 0 ? void 0 : _component$config$def[key];
|
|
11
|
+
const hasDefaultValue = defaultValue !== void 0;
|
|
12
|
+
const values = Object.keys(value).map((v) => {
|
|
13
|
+
if (v === "true") return true;
|
|
14
|
+
if (v === "false") return false;
|
|
15
|
+
const n = Number(v);
|
|
16
|
+
return Number.isFinite(n) && String(n) === v ? n : v;
|
|
17
|
+
});
|
|
18
|
+
const hasValues = values.length > 0;
|
|
19
|
+
return hasValues || hasDefaultValue ? {
|
|
20
|
+
...acc,
|
|
21
|
+
[key]: {
|
|
22
|
+
...hasValues ? { values } : {},
|
|
23
|
+
...hasDefaultValue ? { defaultValue } : {}
|
|
24
|
+
}
|
|
25
|
+
} : acc;
|
|
26
|
+
}, {});
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.getSchema = getSchema;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Copyright 2022-present Joe Bell. All rights reserved.\n *\n * This file is licensed to you under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with the\n * License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\nimport type { CVAComponentShape, CVAVariantShape, GetSchema } from \"./core.js\";\n\nexport type { GetSchema } from \"./core.js\";\n\n// Cast to `GetSchema`: its conditional parameter type cannot narrow here.\nexport const getSchema = ((component: CVAComponentShape) => {\n const variants: CVAVariantShape | undefined = component.config?.variants;\n if (!variants) return {};\n\n return Object.entries(variants).reduce((acc, [key, value]) => {\n if (key.startsWith(\"_\")) return acc;\n\n const defaultValue = component.config.defaultVariants?.[key];\n const hasDefaultValue = defaultValue !== undefined;\n const values = Object.keys(value).map((v) => {\n if (v === \"true\") return true;\n if (v === \"false\") return false;\n // Normalize numeric-literal keys back to numbers, since that's how\n // they appear in variant prop types (`keyof { 1: ... }` is `1`, not\n // `\"1\"`) — object keys are always strings/symbols at runtime. The\n // `String(n) === v` round-trip only accepts canonical numeric forms\n // (so `\"01\"`, `\"\"`, `\" 1\"` stay strings), covering negatives too.\n const n = Number(v);\n return Number.isFinite(n) && String(n) === v ? n : v;\n });\n const hasValues = values.length > 0;\n\n return hasValues || hasDefaultValue\n ? {\n ...acc,\n [key]: {\n ...(hasValues ? { values } : {}),\n ...(hasDefaultValue ? { defaultValue } : {}),\n },\n }\n : acc;\n }, {} as ReturnType<GetSchema>);\n}) as GetSchema;\n"],"mappings":";;AAqBA,MAAa,cAAc,cAAiC;;CAC1D,MAAM,YAAA,oBAAwC,UAAU,YAAA,QAAA,sBAAA,KAAA,IAAA,KAAA,IAAA,kBAAQ;CAChE,IAAI,CAAC,UAAU,OAAO,CAAC;CAEvB,OAAO,OAAO,QAAQ,QAAQ,CAAC,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;;EAC5D,IAAI,IAAI,WAAW,GAAG,GAAG,OAAO;EAEhC,MAAM,gBAAA,wBAAe,UAAU,OAAO,qBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAkB;EACxD,MAAM,kBAAkB,iBAAiB,KAAA;EACzC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM;GAC3C,IAAI,MAAM,QAAQ,OAAO;GACzB,IAAI,MAAM,SAAS,OAAO;GAM1B,MAAM,IAAI,OAAO,CAAC;GAClB,OAAO,OAAO,SAAS,CAAC,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI;EACrD,CAAC;EACD,MAAM,YAAY,OAAO,SAAS;EAElC,OAAO,aAAa,kBAChB;GACE,GAAG;IACF,MAAM;IACL,GAAI,YAAY,EAAE,OAAO,IAAI,CAAC;IAC9B,GAAI,kBAAkB,EAAE,aAAa,IAAI,CAAC;GAC5C;EACF,IACA;CACN,GAAG,CAAC,CAA0B;AAChC"}
|
package/dist/utils.d.cts
ADDED
package/dist/utils.d.mts
ADDED
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
2
|
+
const getSchema = ((component) => {
|
|
3
|
+
var _component$config;
|
|
4
|
+
const variants = (_component$config = component.config) === null || _component$config === void 0 ? void 0 : _component$config.variants;
|
|
5
|
+
if (!variants) return {};
|
|
6
|
+
return Object.entries(variants).reduce((acc, [key, value]) => {
|
|
7
|
+
var _component$config$def;
|
|
8
|
+
if (key.startsWith("_")) return acc;
|
|
9
|
+
const defaultValue = (_component$config$def = component.config.defaultVariants) === null || _component$config$def === void 0 ? void 0 : _component$config$def[key];
|
|
10
|
+
const hasDefaultValue = defaultValue !== void 0;
|
|
11
|
+
const values = Object.keys(value).map((v) => {
|
|
12
|
+
if (v === "true") return true;
|
|
13
|
+
if (v === "false") return false;
|
|
14
|
+
const n = Number(v);
|
|
15
|
+
return Number.isFinite(n) && String(n) === v ? n : v;
|
|
16
|
+
});
|
|
17
|
+
const hasValues = values.length > 0;
|
|
18
|
+
return hasValues || hasDefaultValue ? {
|
|
19
|
+
...acc,
|
|
20
|
+
[key]: {
|
|
21
|
+
...hasValues ? { values } : {},
|
|
22
|
+
...hasDefaultValue ? { defaultValue } : {}
|
|
23
|
+
}
|
|
24
|
+
} : acc;
|
|
25
|
+
}, {});
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { getSchema };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Copyright 2022-present Joe Bell. All rights reserved.\n *\n * This file is licensed to you under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with the\n * License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\nimport type { CVAComponentShape, CVAVariantShape, GetSchema } from \"./core.js\";\n\nexport type { GetSchema } from \"./core.js\";\n\n// Cast to `GetSchema`: its conditional parameter type cannot narrow here.\nexport const getSchema = ((component: CVAComponentShape) => {\n const variants: CVAVariantShape | undefined = component.config?.variants;\n if (!variants) return {};\n\n return Object.entries(variants).reduce((acc, [key, value]) => {\n if (key.startsWith(\"_\")) return acc;\n\n const defaultValue = component.config.defaultVariants?.[key];\n const hasDefaultValue = defaultValue !== undefined;\n const values = Object.keys(value).map((v) => {\n if (v === \"true\") return true;\n if (v === \"false\") return false;\n // Normalize numeric-literal keys back to numbers, since that's how\n // they appear in variant prop types (`keyof { 1: ... }` is `1`, not\n // `\"1\"`) — object keys are always strings/symbols at runtime. The\n // `String(n) === v` round-trip only accepts canonical numeric forms\n // (so `\"01\"`, `\"\"`, `\" 1\"` stay strings), covering negatives too.\n const n = Number(v);\n return Number.isFinite(n) && String(n) === v ? n : v;\n });\n const hasValues = values.length > 0;\n\n return hasValues || hasDefaultValue\n ? {\n ...acc,\n [key]: {\n ...(hasValues ? { values } : {}),\n ...(hasDefaultValue ? { defaultValue } : {}),\n },\n }\n : acc;\n }, {} as ReturnType<GetSchema>);\n}) as GetSchema;\n"],"mappings":";AAqBA,MAAa,cAAc,cAAiC;;CAC1D,MAAM,YAAA,oBAAwC,UAAU,YAAA,QAAA,sBAAA,KAAA,IAAA,KAAA,IAAA,kBAAQ;CAChE,IAAI,CAAC,UAAU,OAAO,CAAC;CAEvB,OAAO,OAAO,QAAQ,QAAQ,CAAC,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;;EAC5D,IAAI,IAAI,WAAW,GAAG,GAAG,OAAO;EAEhC,MAAM,gBAAA,wBAAe,UAAU,OAAO,qBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAkB;EACxD,MAAM,kBAAkB,iBAAiB,KAAA;EACzC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM;GAC3C,IAAI,MAAM,QAAQ,OAAO;GACzB,IAAI,MAAM,SAAS,OAAO;GAM1B,MAAM,IAAI,OAAO,CAAC;GAClB,OAAO,OAAO,SAAS,CAAC,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI;EACrD,CAAC;EACD,MAAM,YAAY,OAAO,SAAS;EAElC,OAAO,aAAa,kBAChB;GACE,GAAG;IACF,MAAM;IACL,GAAI,YAAY,EAAE,OAAO,IAAI,CAAC;IAC9B,GAAI,kBAAkB,EAAE,aAAa,IAAI,CAAC;GAC5C;EACF,IACA;CACN,GAAG,CAAC,CAA0B;AAChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cva",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "Class Variance Authority",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Class Variance Authority",
|
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
"import": "./dist/index.mjs",
|
|
26
26
|
"require": "./dist/index.cjs"
|
|
27
27
|
},
|
|
28
|
+
"./config": {
|
|
29
|
+
"import": "./dist/config.mjs",
|
|
30
|
+
"require": "./dist/config.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./utils": {
|
|
33
|
+
"import": "./dist/utils.mjs",
|
|
34
|
+
"require": "./dist/utils.cjs"
|
|
35
|
+
},
|
|
28
36
|
"./package.json": "./package.json"
|
|
29
37
|
},
|
|
30
38
|
"main": "dist/index.cjs",
|
|
@@ -42,16 +50,18 @@
|
|
|
42
50
|
"@types/node": "24.13.2",
|
|
43
51
|
"@types/react": "19.2.14",
|
|
44
52
|
"@types/react-dom": "19.2.3",
|
|
53
|
+
"cn": "0.2.2",
|
|
45
54
|
"publint": "0.3.21",
|
|
46
55
|
"react": "19.2.6",
|
|
47
56
|
"react-dom": "19.2.6",
|
|
48
57
|
"size-limit": "^12.1.0",
|
|
58
|
+
"tailwind-merge": "3.6.0",
|
|
49
59
|
"tsdown": "0.22.4",
|
|
50
60
|
"typescript": "6.0.3",
|
|
51
61
|
"unplugin-unused": "0.5.7"
|
|
52
62
|
},
|
|
53
63
|
"peerDependencies": {
|
|
54
|
-
"typescript": ">=
|
|
64
|
+
"typescript": ">= 6.0.0"
|
|
55
65
|
},
|
|
56
66
|
"peerDependenciesMeta": {
|
|
57
67
|
"typescript": {
|
|
@@ -61,7 +71,15 @@
|
|
|
61
71
|
"size-limit": [
|
|
62
72
|
{
|
|
63
73
|
"path": "dist/index.cjs",
|
|
64
|
-
"limit": "1.
|
|
74
|
+
"limit": "1.35KB"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"path": "dist/config.cjs",
|
|
78
|
+
"limit": "1.05KB"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"path": "dist/utils.cjs",
|
|
82
|
+
"limit": "0.35KB"
|
|
65
83
|
}
|
|
66
84
|
],
|
|
67
85
|
"scripts": {
|
|
@@ -70,5 +88,15 @@
|
|
|
70
88
|
"check": "pnpm run '/^check:.*/'",
|
|
71
89
|
"check:tsc": "tsc --project tsconfig.json --noEmit",
|
|
72
90
|
"dev": "tsdown --watch"
|
|
91
|
+
},
|
|
92
|
+
"typesVersions": {
|
|
93
|
+
"*": {
|
|
94
|
+
"config": [
|
|
95
|
+
"./dist/config.d.cts"
|
|
96
|
+
],
|
|
97
|
+
"utils": [
|
|
98
|
+
"./dist/utils.d.cts"
|
|
99
|
+
]
|
|
100
|
+
}
|
|
73
101
|
}
|
|
74
102
|
}
|