cva 1.0.0-beta.6 → 1.0.0-beta.7

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.mjs CHANGED
@@ -1,166 +1,138 @@
1
+ import { clsx } from "clsx";
2
+ //#region src/index.ts
1
3
  /**
2
- * Copyright 2022 Joe Bell. All rights reserved.
3
- *
4
- * This file is licensed to you under the Apache License, Version 2.0
5
- * (the "License"); you may not use this file except in compliance with the
6
- * License. You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the
13
- * License for the specific language governing permissions and limitations under
14
- * the License.
15
- */ import { clsx } from "clsx";
16
- /* Exports
17
- ============================================ */ const falsyToString = (value)=>typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
18
- // Shared across every non-composed call, rather than allocating a fresh `[]`
19
- // per call — `cx` (clsx) treats an empty array identically to an absent one.
4
+ * Copyright 2022 Joe Bell. All rights reserved.
5
+ *
6
+ * This file is licensed to you under the Apache License, Version 2.0
7
+ * (the "License"); you may not use this file except in compliance with the
8
+ * License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the
15
+ * License for the specific language governing permissions and limitations under
16
+ * the License.
17
+ */
18
+ const falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
20
19
  const emptyClassNames = [];
21
- export const defineConfig = (options)=>{
22
- const cx = (...inputs)=>{
23
- if (typeof options?.hooks?.["cx:done"] !== "undefined") return options?.hooks["cx:done"](clsx(inputs));
24
- if (typeof options?.hooks?.onComplete !== "undefined") return options?.hooks.onComplete(clsx(inputs));
25
- return clsx(inputs);
26
- };
27
- const cva = (config)=>{
28
- const components = config?.composes == null ? [] : Array.isArray(config.composes) ? config.composes : [
29
- config.composes
30
- ];
31
- // A one-level-deep merge per variant key, so overlapping variants (e.g.
32
- // multiple composed components declaring `style`) union their values
33
- // instead of the last component's values silently replacing the rest.
34
- const mergeVariants = (acc, variants)=>{
35
- if (!variants) return acc;
36
- const merged = {
37
- ...acc
38
- };
39
- for (const key of Object.keys(variants)){
40
- merged[key] = {
41
- ...merged[key],
42
- ...variants[key]
43
- };
44
- }
45
- return merged;
46
- };
47
- const mergedVariantsFromComposed = components.reduce((acc, component)=>mergeVariants(acc, component.config?.variants), {});
48
- const mergedVariants = mergeVariants(mergedVariantsFromComposed, config?.variants);
49
- const mergedDefaultVariantsFromComposed = components.reduce((acc, component)=>({
50
- ...acc,
51
- ...component.config?.defaultVariants
52
- }), {});
53
- // Local `defaultVariants` win over composed ones here too (last spread).
54
- const mergedDefaultVariants = {
55
- ...mergedDefaultVariantsFromComposed,
56
- ...config?.defaultVariants
57
- };
58
- const component = (props)=>{
59
- // Strip `class`/`className` and explicit `undefined` from props once,
60
- // reused for both the composed-component calls and compound-variant
61
- // matching. An explicit `{ variant: undefined }` is dropped so it falls
62
- // back to the (possibly composed) default, matching variant resolution
63
- // below. Only built when something consumes it — a plain component with
64
- // no `composes` and no `variants` skips the work entirely.
65
- const definedPropsWithoutClass = components.length || config?.variants != null ? Object.fromEntries(Object.entries(props || {}).filter(([key, value])=>key !== "class" && key !== "className" && typeof value !== "undefined")) : {};
66
- const getComposedClassNames = components.length ? components.map((component)=>component({
67
- ...mergedDefaultVariants,
68
- ...definedPropsWithoutClass
69
- })) : emptyClassNames;
70
- if (config?.variants == null) {
71
- return cx(getComposedClassNames, config?.base, props?.class, props?.className);
72
- }
73
- const { variants } = config;
74
- // Resolve against the *merged* defaults (composed + local) so a variant
75
- // redeclared locally over a composed key uses the same effective default
76
- // the composed components and `getSchema` see.
77
- const getVariantClassNames = Object.keys(variants).map((variant)=>{
78
- const variantProp = props?.[variant];
79
- const defaultVariantProp = mergedDefaultVariants[variant];
80
- const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
81
- return variants[variant][variantKey];
82
- });
83
- const defaultsAndProps = {
84
- ...mergedDefaultVariants,
85
- ...definedPropsWithoutClass
86
- };
87
- const getCompoundVariantClassNames = config?.compoundVariants?.reduce((acc, { class: cvClass, className: cvClassName, ...cvConfig })=>Object.entries(cvConfig).every(([cvKey, cvSelector])=>{
88
- const selector = defaultsAndProps[cvKey];
89
- return Array.isArray(cvSelector) ? cvSelector.includes(selector) : selector === cvSelector;
90
- }) ? [
91
- ...acc,
92
- cvClass,
93
- cvClassName
94
- ] : acc, []);
95
- return cx(getComposedClassNames, config?.base, getVariantClassNames, getCompoundVariantClassNames, props?.class, props?.className);
96
- };
97
- component.config = {
98
- ...config,
99
- variants: mergedVariants,
100
- defaultVariants: mergedDefaultVariants
101
- };
102
- return component;
103
- };
104
- const compose = (...components)=>{
105
- const config = components.reduce((acc, { config })=>{
106
- Object.entries(config || {}).forEach(([key, value])=>{
107
- acc[key] = typeof value === "object" && value !== null && !Array.isArray(value) ? {
108
- ...acc[key],
109
- ...value
110
- } : value;
111
- });
112
- return acc;
113
- }, // A loose accumulator: composed configs carry heterogeneous values
114
- // (base strings, variant maps, compoundVariant arrays), not just the
115
- // `CVAVariantShape` the merged `variants` key holds.
116
- {});
117
- const component = (props)=>{
118
- const propsWithoutClass = Object.fromEntries(Object.entries(props || {}).filter(([key])=>![
119
- "class",
120
- "className"
121
- ].includes(key)));
122
- return cx(components.map((component)=>component(propsWithoutClass)), props?.class, props?.className);
123
- };
124
- component.config = config;
125
- return component;
126
- };
127
- return {
128
- compose,
129
- cva,
130
- cx
131
- };
20
+ const defineConfig = (options) => {
21
+ const cx = (...inputs) => {
22
+ var _options$hooks, _options$hooks2;
23
+ if (typeof (options === null || options === void 0 || (_options$hooks = options.hooks) === null || _options$hooks === void 0 ? void 0 : _options$hooks["cx:done"]) !== "undefined") return options === null || options === void 0 ? void 0 : options.hooks["cx:done"](clsx(inputs));
24
+ if (typeof (options === null || options === void 0 || (_options$hooks2 = options.hooks) === null || _options$hooks2 === void 0 ? void 0 : _options$hooks2.onComplete) !== "undefined") return options === null || options === void 0 ? void 0 : options.hooks.onComplete(clsx(inputs));
25
+ return clsx(inputs);
26
+ };
27
+ const cva = ((config) => {
28
+ const components = (config === null || config === void 0 ? void 0 : config.composes) == null ? [] : Array.isArray(config.composes) ? config.composes : [config.composes];
29
+ const mergeVariants = (acc, variants) => {
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;
87
+ });
88
+ const compose = (...components) => {
89
+ const config = components.reduce((acc, { config }) => {
90
+ Object.entries(config || {}).forEach(([key, value]) => {
91
+ acc[key] = typeof value === "object" && value !== null && !Array.isArray(value) ? {
92
+ ...acc[key],
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
+ };
132
110
  };
133
- export const { compose, cva, cx } = defineConfig();
134
- export const getSchema = (component)=>{
135
- if (!component.config?.variants) return {};
136
- return Object.entries(component.config.variants).reduce((acc, [key, value])=>{
137
- const defaultValue = component.config.defaultVariants?.[key];
138
- const hasDefaultValue = defaultValue !== undefined;
139
- const values = Object.keys(value).map((v)=>{
140
- if (v === "true") return true;
141
- if (v === "false") return false;
142
- // Normalize numeric-literal keys back to numbers, since that's how
143
- // they appear in variant prop types (`keyof { 1: ... }` is `1`, not
144
- // `"1"`) — object keys are always strings/symbols at runtime. The
145
- // `String(n) === v` round-trip only accepts canonical numeric forms
146
- // (so `"01"`, `""`, `" 1"` stay strings), covering negatives too.
147
- const n = Number(v);
148
- return Number.isFinite(n) && String(n) === v ? n : v;
149
- });
150
- const hasValues = values.length > 0;
151
- return hasValues || hasDefaultValue ? {
152
- ...acc,
153
- [key]: {
154
- ...hasValues ? {
155
- values
156
- } : {},
157
- ...hasDefaultValue ? {
158
- defaultValue
159
- } : {}
160
- }
161
- } : acc;
162
- }, {});
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
+ const defaultValue = (_component$config$def = component.config.defaultVariants) === null || _component$config$def === void 0 ? void 0 : _component$config$def[key];
118
+ const hasDefaultValue = defaultValue !== void 0;
119
+ const values = Object.keys(value).map((v) => {
120
+ if (v === "true") return true;
121
+ if (v === "false") return false;
122
+ const n = Number(v);
123
+ return Number.isFinite(n) && String(n) === v ? n : v;
124
+ });
125
+ const hasValues = values.length > 0;
126
+ return hasValues || hasDefaultValue ? {
127
+ ...acc,
128
+ [key]: {
129
+ ...hasValues ? { values } : {},
130
+ ...hasDefaultValue ? { defaultValue } : {}
131
+ }
132
+ } : acc;
133
+ }, {});
163
134
  };
164
-
135
+ //#endregion
136
+ export { compose, cva, cx, defineConfig, getSchema };
165
137
 
166
138
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["clsx","falsyToString","value","emptyClassNames","defineConfig","options","cx","inputs","hooks","onComplete","cva","config","components","composes","Array","isArray","mergeVariants","acc","variants","merged","key","Object","keys","mergedVariantsFromComposed","reduce","component","mergedVariants","mergedDefaultVariantsFromComposed","defaultVariants","mergedDefaultVariants","props","definedPropsWithoutClass","length","fromEntries","entries","filter","getComposedClassNames","map","base","class","className","getVariantClassNames","variant","variantProp","defaultVariantProp","variantKey","defaultsAndProps","getCompoundVariantClassNames","compoundVariants","cvClass","cvClassName","cvConfig","every","cvKey","cvSelector","selector","includes","compose","forEach","propsWithoutClass","getSchema","defaultValue","hasDefaultValue","undefined","values","v","n","Number","isFinite","String","hasValues"],"mappings":"AAAA;;;;;;;;;;;;;;CAcC,GACD,SAASA,IAAI,QAAQ,OAAO;AA+R5B;+CAC+C,GAE/C,MAAMC,gBAAgB,CAAoBC,QACxC,OAAOA,UAAU,YAAY,GAAGA,OAAO,GAAGA,UAAU,IAAI,MAAMA;AAEhE,6EAA6E;AAC7E,6EAA6E;AAC7E,MAAMC,kBAA4B,EAAE;AAEpC,OAAO,MAAMC,eAA6B,CAACC;IACzC,MAAMC,KAAS,CAAC,GAAGC;QACjB,IAAI,OAAOF,SAASG,OAAO,CAAC,UAAU,KAAK,aACzC,OAAOH,SAASG,KAAK,CAAC,UAAU,CAACR,KAAKO;QAExC,IAAI,OAAOF,SAASG,OAAOC,eAAe,aACxC,OAAOJ,SAASG,MAAMC,WAAWT,KAAKO;QAExC,OAAOP,KAAKO;IACd;IAEA,MAAMG,MAAO,CAOXC;QAEA,MAAMC,aACJD,QAAQE,YAAY,OAChB,EAAE,GACFC,MAAMC,OAAO,CAACJ,OAAOE,QAAQ,IAC3BF,OAAOE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QAAQ,OAAO;YACzB,IAAIA,MAAM,SAAS,OAAO;YAC1B,mEAAmE;YACnE,oEAAoE;YACpE,kEAAkE;YAClE,oEAAoE;YACpE,kEAAkE;YAClE,MAAMC,IAAIC,OAAOF;YACjB,OAAOE,OAAOC,QAAQ,CAACF,MAAMG,OAAOH,OAAOD,IAAIC,IAAID;QACrD;QACA,MAAMK,YAAYN,OAAOhC,MAAM,GAAG;QAElC,OAAOsC,aAAaR,kBAChB;YACE,GAAG7C,GAAG;YACN,CAACG,IAAI,EAAE;gBACL,GAAIkD,YAAY;oBAAEN;gBAAO,IAAI,CAAC,CAAC;gBAC/B,GAAIF,kBAAkB;oBAAED;gBAAa,IAAI,CAAC,CAAC;YAC7C;QACF,IACA5C;IACN,GACA,CAAC;AAEL,EAAE","file":"index.mjs","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\nexport type VariantProps<Component extends (...args: any) => any> = Omit<\n OmitUndefined<Parameters<Component>[0]>,\n \"class\" | \"className\"\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]: VariantProps<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 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]: Config extends CVAComponentConfig<\n Config,\n Variants\n >\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 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"]}
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\nexport type VariantProps<Component extends (...args: any) => any> = Omit<\n OmitUndefined<Parameters<Component>[0]>,\n \"class\" | \"className\"\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]: VariantProps<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 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]: Config extends CVAComponentConfig<\n Config,\n Variants\n >\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 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":";;;;;;;;;;;;;;;;;AAiTA,MAAM,iBAAoC,UACxC,OAAO,UAAU,YAAY,GAAG,UAAU,UAAU,IAAI,MAAM;AAIhE,MAAM,kBAA4B,CAAC;AAEnC,MAAa,gBAA8B,YAAY;CACrD,MAAM,MAAU,GAAG,WAAW;;EAC5B,IAAI,QAAA,YAAA,QAAA,YAAA,KAAA,MAAA,iBAAO,QAAS,WAAA,QAAA,mBAAA,KAAA,IAAA,KAAA,IAAA,eAAQ,gBAAe,aACzC,OAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAO,QAAS,MAAM,UAAU,CAAC,KAAK,MAAM,CAAC;EAE/C,IAAI,QAAA,YAAA,QAAA,YAAA,KAAA,MAAA,kBAAO,QAAS,WAAA,QAAA,oBAAA,KAAA,IAAA,KAAA,IAAA,gBAAO,gBAAe,aACxC,OAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAO,QAAS,MAAM,WAAW,KAAK,MAAM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C,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cva",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "Class Variance Authority",
5
5
  "keywords": [
6
6
  "Class Variance Authority",
@@ -21,13 +21,15 @@
21
21
  "author": "Joe Bell (https://joebell.studio)",
22
22
  "sideEffects": false,
23
23
  "exports": {
24
- "types": "./dist/index.d.ts",
25
- "import": "./dist/index.mjs",
26
- "require": "./dist/index.js"
24
+ ".": {
25
+ "import": "./dist/index.mjs",
26
+ "require": "./dist/index.cjs"
27
+ },
28
+ "./package.json": "./package.json"
27
29
  },
28
- "main": "dist/index.js",
30
+ "main": "dist/index.cjs",
29
31
  "module": "dist/index.mjs",
30
- "types": "dist/index.d.ts",
32
+ "types": "dist/index.d.cts",
31
33
  "files": [
32
34
  "dist/"
33
35
  ],
@@ -35,18 +37,18 @@
35
37
  "clsx": "^2.1.1"
36
38
  },
37
39
  "devDependencies": {
38
- "@arethetypeswrong/cli": "0.18.2",
40
+ "@arethetypeswrong/core": "0.18.2",
39
41
  "@size-limit/preset-small-lib": "^12.1.0",
40
- "@swc/cli": "0.8.1",
41
- "@swc/core": "1.15.33",
42
42
  "@types/node": "24.13.2",
43
43
  "@types/react": "19.2.14",
44
44
  "@types/react-dom": "19.2.3",
45
+ "publint": "0.3.21",
45
46
  "react": "19.2.6",
46
47
  "react-dom": "19.2.6",
47
48
  "size-limit": "^12.1.0",
48
- "ts-node": "10.9.2",
49
- "typescript": "6.0.3"
49
+ "tsdown": "0.22.4",
50
+ "typescript": "6.0.3",
51
+ "unplugin-unused": "0.5.7"
50
52
  },
51
53
  "peerDependencies": {
52
54
  "typescript": ">= 4.5.5"
@@ -58,18 +60,15 @@
58
60
  },
59
61
  "size-limit": [
60
62
  {
61
- "path": "dist/index.js",
63
+ "path": "dist/index.cjs",
62
64
  "limit": "1.6KB"
63
65
  }
64
66
  ],
65
67
  "scripts": {
66
- "build": "pnpm run '/^build:.*/'",
67
- "build:cjs": "swc ./src/index.ts --config-file ./.config/.swcrc -o dist/index.js -C module.type=commonjs",
68
- "build:esm": "swc ./src/index.ts --config-file ./.config/.swcrc -o dist/index.mjs -C module.type=es6 ",
69
- "build:tsc": "tsc --project .config/tsconfig.build.json",
68
+ "build": "tsdown",
70
69
  "bundlesize": "pnpm build && size-limit",
71
70
  "check": "pnpm run '/^check:.*/'",
72
- "check:exports": "attw --pack .",
73
- "check:tsc": "tsc --project tsconfig.json --noEmit"
71
+ "check:tsc": "tsc --project tsconfig.json --noEmit",
72
+ "dev": "tsdown --watch"
74
73
  }
75
74
  }