cva 1.0.0-beta.6 → 1.0.0-beta.8

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.cjs ADDED
@@ -0,0 +1,144 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let clsx = require("clsx");
3
+ //#region src/index.ts
4
+ /**
5
+ * Copyright 2022 Joe Bell. All rights reserved.
6
+ *
7
+ * This file is licensed to you under the Apache License, Version 2.0
8
+ * (the "License"); you may not use this file except in compliance with the
9
+ * License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the
16
+ * License for the specific language governing permissions and limitations under
17
+ * the License.
18
+ */
19
+ const falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
20
+ const emptyClassNames = [];
21
+ const defineConfig = (options) => {
22
+ const cx = (...inputs) => {
23
+ var _options$hooks, _options$hooks2;
24
+ 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"]((0, clsx.clsx)(inputs));
25
+ 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((0, clsx.clsx)(inputs));
26
+ return (0, clsx.clsx)(inputs);
27
+ };
28
+ const cva = ((config) => {
29
+ const components = (config === null || config === void 0 ? void 0 : config.composes) == null ? [] : Array.isArray(config.composes) ? config.composes : [config.composes];
30
+ const mergeVariants = (acc, variants) => {
31
+ if (!variants) return acc;
32
+ const merged = { ...acc };
33
+ for (const key of Object.keys(variants)) merged[key] = {
34
+ ...merged[key],
35
+ ...variants[key]
36
+ };
37
+ return merged;
38
+ };
39
+ const mergedVariants = mergeVariants(components.reduce((acc, component) => {
40
+ var _component$config;
41
+ return mergeVariants(acc, (_component$config = component.config) === null || _component$config === void 0 ? void 0 : _component$config.variants);
42
+ }, {}), config === null || config === void 0 ? void 0 : config.variants);
43
+ const mergedDefaultVariants = {
44
+ ...components.reduce((acc, component) => {
45
+ var _component$config2;
46
+ return {
47
+ ...acc,
48
+ ...(_component$config2 = component.config) === null || _component$config2 === void 0 ? void 0 : _component$config2.defaultVariants
49
+ };
50
+ }, {}),
51
+ ...config === null || config === void 0 ? void 0 : config.defaultVariants
52
+ };
53
+ const component = (props) => {
54
+ var _config$compoundVaria;
55
+ 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")) : {};
56
+ const getComposedClassNames = components.length ? components.map((component) => component({
57
+ ...mergedDefaultVariants,
58
+ ...definedPropsWithoutClass
59
+ })) : emptyClassNames;
60
+ 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);
61
+ const { variants } = config;
62
+ const getVariantClassNames = Object.keys(variants).map((variant) => {
63
+ const variantProp = props === null || props === void 0 ? void 0 : props[variant];
64
+ const defaultVariantProp = mergedDefaultVariants[variant];
65
+ const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
66
+ return variants[variant][variantKey];
67
+ });
68
+ const defaultsAndProps = {
69
+ ...mergedDefaultVariants,
70
+ ...definedPropsWithoutClass
71
+ };
72
+ 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]) => {
73
+ const selector = defaultsAndProps[cvKey];
74
+ return Array.isArray(cvSelector) ? cvSelector.includes(selector) : selector === cvSelector;
75
+ }) ? [
76
+ ...acc,
77
+ cvClass,
78
+ cvClassName
79
+ ] : acc, []);
80
+ 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);
81
+ };
82
+ component.config = {
83
+ ...config,
84
+ variants: mergedVariants,
85
+ defaultVariants: mergedDefaultVariants
86
+ };
87
+ return component;
88
+ });
89
+ const compose = (...components) => {
90
+ const config = components.reduce((acc, { config }) => {
91
+ Object.entries(config || {}).forEach(([key, value]) => {
92
+ acc[key] = typeof value === "object" && value !== null && !Array.isArray(value) ? {
93
+ ...acc[key],
94
+ ...value
95
+ } : value;
96
+ });
97
+ return acc;
98
+ }, {});
99
+ const component = (props) => {
100
+ const propsWithoutClass = Object.fromEntries(Object.entries(props || {}).filter(([key]) => !["class", "className"].includes(key)));
101
+ 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);
102
+ };
103
+ component.config = config;
104
+ return component;
105
+ };
106
+ return {
107
+ compose,
108
+ cva,
109
+ cx
110
+ };
111
+ };
112
+ const { compose, cva, cx } = defineConfig();
113
+ const getSchema = (component) => {
114
+ var _component$config3;
115
+ if (!((_component$config3 = component.config) === null || _component$config3 === void 0 ? void 0 : _component$config3.variants)) return {};
116
+ return Object.entries(component.config.variants).reduce((acc, [key, value]) => {
117
+ var _component$config$def;
118
+ if (key.startsWith("_")) return acc;
119
+ const defaultValue = (_component$config$def = component.config.defaultVariants) === null || _component$config$def === void 0 ? void 0 : _component$config$def[key];
120
+ const hasDefaultValue = defaultValue !== void 0;
121
+ const values = Object.keys(value).map((v) => {
122
+ if (v === "true") return true;
123
+ if (v === "false") return false;
124
+ const n = Number(v);
125
+ return Number.isFinite(n) && String(n) === v ? n : v;
126
+ });
127
+ const hasValues = values.length > 0;
128
+ return hasValues || hasDefaultValue ? {
129
+ ...acc,
130
+ [key]: {
131
+ ...hasValues ? { values } : {},
132
+ ...hasDefaultValue ? { defaultValue } : {}
133
+ }
134
+ } : acc;
135
+ }, {});
136
+ };
137
+ //#endregion
138
+ exports.compose = compose;
139
+ exports.cva = cva;
140
+ exports.cx = cx;
141
+ exports.defineConfig = defineConfig;
142
+ exports.getSchema = getSchema;
143
+
144
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","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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AiB,CAAC,GAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAC1D,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"}
@@ -0,0 +1,137 @@
1
+ //#region src/index.d.ts
2
+ type ClassValue = ClassArray | ClassDictionary | string | number | bigint | null | boolean | undefined;
3
+ type ClassDictionary = Record<string, any>;
4
+ type ClassArray = ClassValue[];
5
+ type OmitUndefined<T> = T extends undefined ? never : T;
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
+ });
68
+ /**
69
+ * Exported so TypeScript can name this type in your generated declarations
70
+ * (`declaration: true`) — you shouldn't really use it directly.
71
+ */
72
+ interface CVAComponent<Config, Variants> {
73
+ (props?: Variants extends CVAVariantShape ? CVAVariantSchema<Variants> & CVAClassProp : CVAClassProp): string;
74
+ /** @internal */
75
+ config: Config;
76
+ }
77
+ /**
78
+ * Exported so TypeScript can name this type in your generated declarations
79
+ * (`declaration: true`) — you shouldn't really use it directly.
80
+ */
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
+ interface DefineConfig {
104
+ (options?: DefineConfigOptions): {
105
+ /**
106
+ * @deprecated Use the `composes` property inside `cva` instead.
107
+ * @example
108
+ * // Before
109
+ * const card = compose(box, stack)
110
+ * // After
111
+ * const card = cva({ composes: [box, stack] })
112
+ */
113
+ compose: Compose;
114
+ cx: CX;
115
+ cva: CVA;
116
+ };
117
+ }
118
+ declare const defineConfig: DefineConfig;
119
+ declare const compose: Compose, cva: CVA, cx: CX;
120
+ interface GetSchema {
121
+ <_ extends InternalOnlyWarning, Component, Config, Variants>(component: Component & (Component extends ReturnType<CVA> ? {
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;
135
+ //#endregion
136
+ export { CVA, CVAComponent, CVAComponentShape, CVAVariantShape, CX, CXOptions, CXReturn, ClassArray, ClassDictionary, ClassValue, Compose, DefineConfig, DefineConfigOptions, GetSchema, VariantProps, compose, cva, cx, defineConfig, getSchema };
137
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,137 @@
1
+ //#region src/index.d.ts
2
+ type ClassValue = ClassArray | ClassDictionary | string | number | bigint | null | boolean | undefined;
3
+ type ClassDictionary = Record<string, any>;
4
+ type ClassArray = ClassValue[];
5
+ type OmitUndefined<T> = T extends undefined ? never : T;
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
+ });
68
+ /**
69
+ * Exported so TypeScript can name this type in your generated declarations
70
+ * (`declaration: true`) — you shouldn't really use it directly.
71
+ */
72
+ interface CVAComponent<Config, Variants> {
73
+ (props?: Variants extends CVAVariantShape ? CVAVariantSchema<Variants> & CVAClassProp : CVAClassProp): string;
74
+ /** @internal */
75
+ config: Config;
76
+ }
77
+ /**
78
+ * Exported so TypeScript can name this type in your generated declarations
79
+ * (`declaration: true`) — you shouldn't really use it directly.
80
+ */
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
+ interface DefineConfig {
104
+ (options?: DefineConfigOptions): {
105
+ /**
106
+ * @deprecated Use the `composes` property inside `cva` instead.
107
+ * @example
108
+ * // Before
109
+ * const card = compose(box, stack)
110
+ * // After
111
+ * const card = cva({ composes: [box, stack] })
112
+ */
113
+ compose: Compose;
114
+ cx: CX;
115
+ cva: CVA;
116
+ };
117
+ }
118
+ declare const defineConfig: DefineConfig;
119
+ declare const compose: Compose, cva: CVA, cx: CX;
120
+ interface GetSchema {
121
+ <_ extends InternalOnlyWarning, Component, Config, Variants>(component: Component & (Component extends ReturnType<CVA> ? {
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;
135
+ //#endregion
136
+ export { CVA, CVAComponent, CVAComponentShape, CVAVariantShape, CX, CXOptions, CXReturn, ClassArray, ClassDictionary, ClassValue, Compose, DefineConfig, DefineConfigOptions, GetSchema, VariantProps, compose, cva, cx, defineConfig, getSchema };
137
+ //# sourceMappingURL=index.d.mts.map