clava 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +27 -18
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +34 -40
- package/src/test.ts +77 -34
- package/src/types.ts +43 -285
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -38,34 +38,28 @@ type SourceDefaults<S> = S extends {
|
|
|
38
38
|
getVariants: () => infer Defaults;
|
|
39
39
|
} ? Defaults : {};
|
|
40
40
|
type SourceResult<T, S> = Pick<T, Extract<keyof T, SourceKeys<S>>> & Omit<SourceDefaults<S>, keyof T>;
|
|
41
|
-
type
|
|
42
|
-
type
|
|
43
|
-
|
|
44
|
-
type SplitProps<V$1, D, _R extends ComponentResult> = <const T extends Record<string, unknown>, const Sources extends readonly KeySource[]>(props: T, ...sources: Sources) => SplitPropsResult<T, V$1, D, Sources>;
|
|
45
|
-
type OnlyVariantsSplitPropsResult<T, V$1, D, Sources extends readonly KeySource[]> = Sources extends readonly [] ? [SelfResult<T, keyof V$1, D>, Omit<T, keyof V$1>] : Sources extends readonly [infer S1 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, Omit<T, keyof V$1 | SourceKeys<S1>>] : Sources extends readonly [infer S1 extends KeySource, infer S2 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, SourceResult<T, S2>, Omit<T, keyof V$1 | SourceKeys<S1> | SourceKeys<S2>>] : Sources extends readonly [infer S1 extends KeySource, infer S2 extends KeySource, infer S3 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, Omit<T, keyof V$1 | SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3>>] : Sources extends readonly [infer S1 extends KeySource, infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, Omit<T, keyof V$1 | SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4>>] : Sources extends readonly [infer S1 extends KeySource, infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, Omit<T, keyof V$1 | SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5>>] : Sources extends readonly [infer S1 extends KeySource, infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource, infer S6 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, SourceResult<T, S6>, Omit<T, keyof V$1 | SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5> | SourceKeys<S6>>] : Sources extends readonly [infer S1 extends KeySource, infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource, infer S6 extends KeySource, infer S7 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, SourceResult<T, S6>, SourceResult<T, S7>, Omit<T, keyof V$1 | SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5> | SourceKeys<S6> | SourceKeys<S7>>] : Sources extends readonly [infer S1 extends KeySource, infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource, infer S6 extends KeySource, infer S7 extends KeySource, infer S8 extends KeySource] ? [SelfResult<T, keyof V$1, D>, SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, SourceResult<T, S6>, SourceResult<T, S7>, SourceResult<T, S8>, Omit<T, keyof V$1 | SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5> | SourceKeys<S6> | SourceKeys<S7> | SourceKeys<S8>>] : unknown[];
|
|
46
|
-
type OnlyVariantsSplitProps<V$1, D> = <const T extends Record<string, unknown>, const Sources extends readonly KeySource[]>(props: T, ...sources: Sources) => OnlyVariantsSplitPropsResult<T, V$1, D, Sources>;
|
|
47
|
-
interface OnlyVariantsComponent<V$1, D> {
|
|
48
|
-
splitProps: OnlyVariantsSplitProps<V$1, D>;
|
|
41
|
+
type SplitPropsFunction = <const T extends Record<string, unknown>, const S1 extends KeySource, const Sources extends readonly KeySource[]>(props: T, source1: S1, ...sources: Sources) => SplitPropsFunctionResult<T, S1, Sources>;
|
|
42
|
+
type SplitPropsFunctionResult<T, S1 extends KeySource, Sources extends readonly KeySource[]> = Sources extends readonly [] ? [SourceResult<T, S1>, Omit<T, SourceKeys<S1>>] : Sources extends readonly [infer S2 extends KeySource] ? [SourceResult<T, S1>, SourceResult<T, S2>, Omit<T, SourceKeys<S1> | SourceKeys<S2>>] : Sources extends readonly [infer S2 extends KeySource, infer S3 extends KeySource] ? [SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, Omit<T, SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3>>] : Sources extends readonly [infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource] ? [SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, Omit<T, SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4>>] : Sources extends readonly [infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource] ? [SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, Omit<T, SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5>>] : Sources extends readonly [infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource, infer S6 extends KeySource] ? [SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, SourceResult<T, S6>, Omit<T, SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5> | SourceKeys<S6>>] : Sources extends readonly [infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource, infer S6 extends KeySource, infer S7 extends KeySource] ? [SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, SourceResult<T, S6>, SourceResult<T, S7>, Omit<T, SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5> | SourceKeys<S6> | SourceKeys<S7>>] : Sources extends readonly [infer S2 extends KeySource, infer S3 extends KeySource, infer S4 extends KeySource, infer S5 extends KeySource, infer S6 extends KeySource, infer S7 extends KeySource, infer S8 extends KeySource] ? [SourceResult<T, S1>, SourceResult<T, S2>, SourceResult<T, S3>, SourceResult<T, S4>, SourceResult<T, S5>, SourceResult<T, S6>, SourceResult<T, S7>, SourceResult<T, S8>, Omit<T, SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4> | SourceKeys<S5> | SourceKeys<S6> | SourceKeys<S7> | SourceKeys<S8>>] : unknown[];
|
|
43
|
+
interface OnlyVariantsComponent<V$1> {
|
|
49
44
|
getVariants: GetVariants<V$1>;
|
|
50
45
|
keys: (keyof V$1)[];
|
|
51
46
|
}
|
|
52
|
-
interface ModalComponent<V$1,
|
|
47
|
+
interface ModalComponent<V$1, R extends ComponentResult> {
|
|
53
48
|
(props?: ComponentProps<V$1>): R;
|
|
54
49
|
class: (props?: ComponentProps<V$1>) => string;
|
|
55
50
|
style: (props?: ComponentProps<V$1>) => R["style"];
|
|
56
|
-
splitProps: SplitProps<V$1, D, R>;
|
|
57
51
|
getVariants: GetVariants<V$1>;
|
|
58
52
|
keys: (keyof V$1 | keyof R)[];
|
|
59
|
-
onlyVariants: OnlyVariantsComponent<V$1
|
|
53
|
+
onlyVariants: OnlyVariantsComponent<V$1>;
|
|
60
54
|
/** @internal Base class without variants */
|
|
61
55
|
_baseClass: string;
|
|
62
56
|
}
|
|
63
|
-
interface Component<V$1 extends Variants = {}, CV$1 extends ComputedVariants = {}, E$1 extends AnyComponent[] = [], R extends ComponentResult = ComponentResult
|
|
64
|
-
jsx: ModalComponent<MergeVariants<V$1, CV$1, E$1>,
|
|
65
|
-
html: ModalComponent<MergeVariants<V$1, CV$1, E$1>,
|
|
66
|
-
htmlObj: ModalComponent<MergeVariants<V$1, CV$1, E$1>,
|
|
57
|
+
interface Component<V$1 extends Variants = {}, CV$1 extends ComputedVariants = {}, E$1 extends AnyComponent[] = [], R extends ComponentResult = ComponentResult> extends ModalComponent<MergeVariants<V$1, CV$1, E$1>, R> {
|
|
58
|
+
jsx: ModalComponent<MergeVariants<V$1, CV$1, E$1>, JSXProps>;
|
|
59
|
+
html: ModalComponent<MergeVariants<V$1, CV$1, E$1>, HTMLProps>;
|
|
60
|
+
htmlObj: ModalComponent<MergeVariants<V$1, CV$1, E$1>, HTMLObjProps>;
|
|
67
61
|
}
|
|
68
|
-
type AnyComponent = Component<any, any, any, any
|
|
62
|
+
type AnyComponent = Component<any, any, any, any> | ModalComponent<any, any>;
|
|
69
63
|
type MergeExtendedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractVariants<First> & MergeExtendedVariants<Rest> : {};
|
|
70
64
|
type MergeExtendedComputedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractComputedVariants<First> & MergeExtendedComputedVariants<Rest> : {};
|
|
71
65
|
type ExtractVariants<T> = T extends Component<infer V, any, infer E, any> ? V & MergeExtendedVariants<E> : {};
|
|
@@ -111,6 +105,21 @@ interface CreateParams<M extends Mode> {
|
|
|
111
105
|
defaultMode?: M;
|
|
112
106
|
transformClass?: (className: string) => string;
|
|
113
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Splits props into multiple groups based on key sources.
|
|
110
|
+
* Each source gets its own result object containing all its matching keys.
|
|
111
|
+
* The last element is always the "rest" containing keys not claimed by any source.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const [buttonProps, inputProps, rest] = splitProps(
|
|
116
|
+
* props,
|
|
117
|
+
* buttonComponent,
|
|
118
|
+
* inputComponent.onlyVariants,
|
|
119
|
+
* );
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
declare const splitProps: SplitPropsFunction;
|
|
114
123
|
declare function create<M extends Mode>({
|
|
115
124
|
defaultMode,
|
|
116
125
|
transformClass
|
|
@@ -118,7 +127,7 @@ declare function create<M extends Mode>({
|
|
|
118
127
|
cv: <V$1 extends Variants = {}, CV$1 extends ComputedVariants = {}, const E$1 extends AnyComponent[] = []>(config?: CVConfig<V$1, CV$1, E$1>) => Component<V$1, CV$1, E$1, StyleProps[M]>;
|
|
119
128
|
cx: (...classes: ClassValue$1[]) => string;
|
|
120
129
|
};
|
|
121
|
-
declare const cv: <V$1 extends Variants = {}, CV$1 extends ComputedVariants = {}, const E$1 extends AnyComponent[] = []>(config?: CVConfig<V$1, CV$1, E$1>) => Component<V$1, CV$1, E$1, JSXProps | HTMLProps | HTMLObjProps
|
|
130
|
+
declare const cv: <V$1 extends Variants = {}, CV$1 extends ComputedVariants = {}, const E$1 extends AnyComponent[] = []>(config?: CVConfig<V$1, CV$1, E$1>) => Component<V$1, CV$1, E$1, JSXProps | HTMLProps | HTMLObjProps>, cx: (...classes: ClassValue$1[]) => string;
|
|
122
131
|
//#endregion
|
|
123
|
-
export { CVConfig, type ClassValue, type StyleClassValue, type StyleValue, VariantProps, create, cv, cx };
|
|
132
|
+
export { CVConfig, type ClassValue, type StyleClassValue, type StyleValue, VariantProps, create, cv, cx, splitProps };
|
|
124
133
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -399,6 +399,25 @@ function splitPropsImpl(selfKeys, selfDefaults, props, sources) {
|
|
|
399
399
|
results.push(rest);
|
|
400
400
|
return results;
|
|
401
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* Splits props into multiple groups based on key sources.
|
|
404
|
+
* Each source gets its own result object containing all its matching keys.
|
|
405
|
+
* The last element is always the "rest" containing keys not claimed by any source.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```ts
|
|
409
|
+
* const [buttonProps, inputProps, rest] = splitProps(
|
|
410
|
+
* props,
|
|
411
|
+
* buttonComponent,
|
|
412
|
+
* inputComponent.onlyVariants,
|
|
413
|
+
* );
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
const splitProps = ((props, source1, ...sources) => {
|
|
417
|
+
const normalizedSource1 = normalizeKeySource(source1);
|
|
418
|
+
const normalizedSources = sources.map(normalizeKeySource);
|
|
419
|
+
return splitPropsImpl(normalizedSource1.keys, normalizedSource1.defaults, props, normalizedSources);
|
|
420
|
+
});
|
|
402
421
|
function create({ defaultMode = "jsx", transformClass = (className) => className } = {}) {
|
|
403
422
|
const cx$1 = (...classes) => transformClass(clsx_default(...classes));
|
|
404
423
|
const cv$1 = (config = {}) => {
|
|
@@ -482,18 +501,11 @@ function create({ defaultMode = "jsx", transformClass = (className) => className
|
|
|
482
501
|
return resolveVariants(config, variants);
|
|
483
502
|
};
|
|
484
503
|
component$1.keys = propsKeys;
|
|
485
|
-
const selfDefaults = collectDefaultVariants(config);
|
|
486
|
-
component$1.splitProps = ((props, ...sources) => {
|
|
487
|
-
return splitPropsImpl(propsKeys, selfDefaults, props, sources.map(normalizeKeySource));
|
|
488
|
-
});
|
|
489
504
|
component$1.onlyVariants = {
|
|
490
505
|
getVariants: (variants) => {
|
|
491
506
|
return resolveVariants(config, variants);
|
|
492
507
|
},
|
|
493
|
-
keys: variantKeys
|
|
494
|
-
splitProps: ((props, ...sources) => {
|
|
495
|
-
return splitPropsImpl(variantKeys, selfDefaults, props, sources.map(normalizeKeySource));
|
|
496
|
-
})
|
|
508
|
+
keys: variantKeys
|
|
497
509
|
};
|
|
498
510
|
const extendedBaseClasses = [];
|
|
499
511
|
if (config.extend) for (const ext of config.extend) extendedBaseClasses.push(ext._baseClass);
|
|
@@ -518,5 +530,5 @@ function create({ defaultMode = "jsx", transformClass = (className) => className
|
|
|
518
530
|
const { cv, cx } = create();
|
|
519
531
|
|
|
520
532
|
//#endregion
|
|
521
|
-
export { create, cv, cx };
|
|
533
|
+
export { create, cv, cx, splitProps };
|
|
522
534
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["cx","clsx","cv","component"],"sources":["../../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs","../src/utils.ts","../src/index.ts"],"sourcesContent":["function r(e){var t,f,n=\"\";if(\"string\"==typeof e||\"number\"==typeof e)n+=e;else if(\"object\"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=\" \"),n+=f)}else for(f in e)e[f]&&(n&&(n+=\" \"),n+=f);return n}export function clsx(){for(var e,t,f=0,n=\"\",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=\" \"),n+=t);return n}export default clsx;","import type * as CSS from \"csstype\";\n\nimport type {\n StyleValue,\n JSXCSSProperties,\n HTMLCSSProperties,\n} from \"./types.ts\";\n\n/**\n * Converts a hyphenated CSS property name to camelCase.\n * @example\n * hyphenToCamel(\"background-color\") // \"backgroundColor\"\n * hyphenToCamel(\"--custom-var\") // \"--custom-var\" (CSS variables are preserved)\n */\nexport function hyphenToCamel(str: string) {\n // CSS custom properties (variables) should not be converted\n if (str.startsWith(\"--\")) {\n return str;\n }\n return str.replace(/-([a-z])/gi, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Converts a camelCase CSS property name to hyphenated form.\n * @example\n * camelToHyphen(\"backgroundColor\") // \"background-color\"\n * camelToHyphen(\"--customVar\") // \"--customVar\" (CSS variables are preserved)\n */\nexport function camelToHyphen(str: string) {\n // CSS custom properties (variables) should not be converted\n if (str.startsWith(\"--\")) {\n return str;\n }\n return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n/**\n * Parses a length value, adding \"px\" if it's a number.\n * @example\n * parseLengthValue(16); // \"16px\"\n * parseLengthValue(\"2em\"); // \"2em\"\n */\nexport function parseLengthValue(value: string | number) {\n if (typeof value === \"string\") return value;\n return `${value}px`;\n}\n\n/**\n * Parses a CSS style string into a StyleValue object.\n * @example\n * htmlStyleToStyleValue(\"background-color: red; font-size: 16px;\");\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function htmlStyleToStyleValue(styleString: string) {\n if (!styleString) return {};\n\n const result: StyleValue = {};\n const declarations = styleString.split(\";\");\n\n for (const declaration of declarations) {\n const trimmed = declaration.trim();\n if (!trimmed) continue;\n\n const colonIndex = trimmed.indexOf(\":\");\n if (colonIndex === -1) continue;\n\n const property = trimmed.slice(0, colonIndex).trim();\n const value = trimmed.slice(colonIndex + 1).trim();\n if (!property) continue;\n if (!value) continue;\n\n const camelProperty = hyphenToCamel(property) as any;\n result[camelProperty] = value;\n }\n\n return result;\n}\n\n/**\n * Converts a hyphenated style object to a camelCase StyleValue object.\n * @example\n * htmlObjStyleToStyleValue({ \"background-color\": \"red\", \"font-size\": \"16px\" });\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function htmlObjStyleToStyleValue(style: HTMLCSSProperties) {\n const result: StyleValue = {};\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n const property = hyphenToCamel(key) as any;\n result[property] = parseLengthValue(value);\n }\n return result;\n}\n\n/**\n * Converts a camelCase style object to a StyleValue object.\n * @example\n * jsxStyleToStyleValue({ backgroundColor: \"red\", fontSize: 16 });\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function jsxStyleToStyleValue(style: JSXCSSProperties) {\n const result: StyleValue = {};\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n result[key as any] = parseLengthValue(value);\n }\n return result;\n}\n\n/**\n * Converts a StyleValue object to a CSS style string.\n * @example\n * styleValueToHTMLStyle({ backgroundColor: \"red\", fontSize: \"16px\" });\n * // \"background-color: red; font-size: 16px;\"\n */\nexport function styleValueToHTMLStyle(style: StyleValue): string {\n const parts: string[] = [];\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n parts.push(`${camelToHyphen(key)}: ${value}`);\n }\n if (!parts.length) return \"\";\n return `${parts.join(\"; \")};`;\n}\n\n/**\n * Converts a StyleValue object to a hyphenated style object.\n * @example\n * styleValueToHTMLObjStyle({ backgroundColor: \"red\", fontSize: \"16px\" });\n * // { \"background-color\": \"red\", \"font-size\": \"16px\" }\n */\nexport function styleValueToHTMLObjStyle(style: StyleValue) {\n const result: CSS.PropertiesHyphen = {};\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n const property = camelToHyphen(key) as keyof HTMLCSSProperties;\n result[property] = value;\n }\n return result;\n}\n\n/**\n * Converts a StyleValue object to a camelCase style object.\n * @example\n * styleValueToJSXStyle({ backgroundColor: \"red\", fontSize: \"16px\" });\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function styleValueToJSXStyle(style: StyleValue) {\n return style as JSXCSSProperties;\n}\n\n/**\n * Type guard to check if a style object has hyphenated keys.\n * @example\n * isHTMLObjStyle({ \"background-color\": \"red\" }); // true\n * isHTMLObjStyle({ backgroundColor: \"red\" }); // false\n */\nexport function isHTMLObjStyle(\n style: CSS.Properties<any> | CSS.PropertiesHyphen<any>,\n): style is CSS.PropertiesHyphen {\n return Object.keys(style).some(\n (key) => key.includes(\"-\") && !key.startsWith(\"--\"),\n );\n}\n","import clsx, { type ClassValue as ClsxClassValue } from \"clsx\";\n\nimport type {\n Variants,\n ComputedVariants,\n AnyComponent,\n Component,\n StyleProps,\n ClassValue,\n StyleValue,\n StyleClassValue,\n VariantValues,\n Computed,\n ExtendableVariants,\n MergeVariants,\n ModalComponent,\n ComponentResult,\n JSXProps,\n HTMLProps,\n HTMLObjProps,\n OnlyVariantsComponent,\n ComponentProps,\n SplitProps,\n OnlyVariantsSplitProps,\n} from \"./types.ts\";\n\nimport {\n htmlObjStyleToStyleValue,\n htmlStyleToStyleValue,\n isHTMLObjStyle,\n jsxStyleToStyleValue,\n styleValueToHTMLObjStyle,\n styleValueToHTMLStyle,\n styleValueToJSXStyle,\n} from \"./utils.ts\";\n\nconst MODES = [\"jsx\", \"html\", \"htmlObj\"] as const;\ntype Mode = (typeof MODES)[number];\n\nexport type { ClassValue, StyleValue, StyleClassValue };\n\nexport type VariantProps<T extends Pick<AnyComponent, \"getVariants\">> =\n ReturnType<T[\"getVariants\"]>;\n\nexport interface CVConfig<\n V extends Variants = {},\n CV extends ComputedVariants = {},\n E extends AnyComponent[] = [],\n> {\n extend?: E;\n class?: ClassValue;\n style?: StyleValue;\n variants?: ExtendableVariants<V, E>;\n computedVariants?: CV;\n defaultVariants?: VariantValues<MergeVariants<V, CV, E>>;\n computed?: Computed<MergeVariants<V, CV, E>>;\n}\n\ninterface CreateParams<M extends Mode> {\n defaultMode?: M;\n transformClass?: (className: string) => string;\n}\n\n/**\n * Checks if a value is a style-class object (has style properties, not just a\n * class value).\n */\nfunction isStyleClassValue(value: unknown): value is StyleClassValue {\n if (typeof value !== \"object\") return false;\n if (value == null) return false;\n if (Array.isArray(value)) return false;\n return true;\n}\n\n/**\n * Converts any style input (string, JSX object, or HTML object) to a\n * normalized StyleValue.\n */\nfunction normalizeStyle(style: unknown): StyleValue {\n if (typeof style === \"string\") {\n return htmlStyleToStyleValue(style);\n }\n if (typeof style === \"object\" && style != null) {\n if (isHTMLObjStyle(style as Record<string, unknown>)) {\n return htmlObjStyleToStyleValue(style as Record<string, string | number>);\n }\n return jsxStyleToStyleValue(style as Record<string, string | number>);\n }\n return {};\n}\n\n/**\n * Extracts class and style from a style-class value object.\n */\nfunction extractStyleClass(value: StyleClassValue): {\n class: ClassValue;\n style: StyleValue;\n} {\n const { class: cls, ...style } = value;\n return { class: cls, style };\n}\n\n/**\n * Processes a variant value to extract class and style.\n */\nfunction processVariantValue(value: unknown): {\n class: ClassValue;\n style: StyleValue;\n} {\n if (isStyleClassValue(value)) {\n return extractStyleClass(value);\n }\n return { class: value as ClassValue, style: {} };\n}\n\n/**\n * Gets all variant keys from a component's config, including extended\n * components.\n */\nfunction collectVariantKeys(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): string[] {\n const keys = new Set<string>();\n\n // Collect from extended components\n if (config.extend) {\n for (const ext of config.extend) {\n for (const key of ext.onlyVariants.keys) {\n keys.add(key as string);\n }\n }\n }\n\n // Collect from variants\n if (config.variants) {\n for (const key of Object.keys(config.variants)) {\n keys.add(key);\n }\n }\n\n // Collect from computedVariants\n if (config.computedVariants) {\n for (const key of Object.keys(config.computedVariants)) {\n keys.add(key);\n }\n }\n\n return Array.from(keys);\n}\n\n/**\n * Collects default variants from extended components and the current config.\n * Also handles implicit boolean defaults (when only `false` key exists).\n */\nfunction collectDefaultVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): Record<string, unknown> {\n let defaults: Record<string, unknown> = {};\n\n // Collect from extended components\n if (config.extend) {\n for (const ext of config.extend) {\n const extDefaults = ext.getVariants();\n defaults = { ...defaults, ...extDefaults };\n }\n }\n\n // Handle implicit boolean defaults from variants\n // If a variant only has a `false` key and no `true` key, default to false\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n if (isStyleClassValue(variantDef)) {\n const keys = Object.keys(variantDef);\n const hasFalseOnly = keys.includes(\"false\") && !keys.includes(\"true\");\n if (hasFalseOnly && defaults[variantName] === undefined) {\n defaults[variantName] = false;\n }\n }\n }\n }\n\n // Override with current config's defaults\n if (config.defaultVariants) {\n defaults = { ...defaults, ...config.defaultVariants };\n }\n\n return defaults;\n}\n\n/**\n * Resolves variant values by merging defaults with provided props.\n */\nfunction resolveVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n props: Record<string, unknown> = {},\n): Record<string, unknown> {\n const defaults = collectDefaultVariants(config);\n return { ...defaults, ...props };\n}\n\n/**\n * Gets the value for a single variant based on the variant definition and the\n * selected value.\n */\nfunction getVariantResult(\n variantDef: unknown,\n selectedValue: unknown,\n): { class: ClassValue; style: StyleValue } {\n // Shorthand variant: `disabled: \"disabled-class\"` means { true: \"...\" }\n if (!isStyleClassValue(variantDef)) {\n if (selectedValue === true) {\n return processVariantValue(variantDef);\n }\n return { class: null, style: {} };\n }\n\n // Object variant: { sm: \"...\", lg: \"...\" }\n const key = String(selectedValue);\n const value = (variantDef as Record<string, unknown>)[key];\n if (value === undefined) return { class: null, style: {} };\n\n return processVariantValue(value);\n}\n\n/**\n * Processes extended components and returns base classes and variant classes separately.\n * Base classes should come before current component's base, variant classes come after.\n * When overrideVariantKeys is provided, those variant keys are excluded from the extended\n * component's result (used when current component's computedVariants overrides them).\n */\nfunction processExtended(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n overrideVariantKeys: Set<string> = new Set(),\n): {\n baseClasses: ClassValue[];\n variantClasses: ClassValue[];\n style: StyleValue;\n} {\n const baseClasses: ClassValue[] = [];\n const variantClasses: ClassValue[] = [];\n let style: StyleValue = {};\n\n if (config.extend) {\n for (const ext of config.extend) {\n // Filter out variant keys that are being overridden by current component's computedVariants\n const filteredVariants = { ...resolvedVariants };\n for (const key of overrideVariantKeys) {\n delete filteredVariants[key];\n }\n\n // Get the result with filtered variants (excluding overridden keys)\n const extResult = ext({ ...filteredVariants });\n\n // Only merge style for non-overridden keys\n const extStyle = normalizeStyle(extResult.style);\n style = { ...style, ...extStyle };\n\n // Get base class from internal property (no variants)\n const baseClass = ext._baseClass;\n baseClasses.push(baseClass);\n\n // Get full class with variants\n const fullClass =\n \"className\" in extResult ? extResult.className : extResult.class;\n\n // Extract variant portion (full class minus base class)\n if (fullClass && baseClass) {\n const baseClassSet = new Set(baseClass.split(\" \").filter(Boolean));\n const variantPortion = fullClass\n .split(\" \")\n .filter((c: string) => c && !baseClassSet.has(c))\n .join(\" \");\n if (variantPortion) {\n variantClasses.push(variantPortion);\n }\n } else if (fullClass && !baseClass) {\n variantClasses.push(fullClass);\n }\n }\n }\n\n return { baseClasses, variantClasses, style };\n}\n\n/**\n * Processes all variants (not extended) and returns accumulated class and\n * style.\n */\nfunction processVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n): { classes: ClassValue[]; style: StyleValue } {\n const classes: ClassValue[] = [];\n let style: StyleValue = {};\n\n // Process current component's variants\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const result = getVariantResult(variantDef, selectedValue);\n classes.push(result.class);\n style = { ...style, ...result.style };\n }\n }\n\n // Process computedVariants\n if (config.computedVariants) {\n for (const [variantName, computeFn] of Object.entries(\n config.computedVariants,\n )) {\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const computedResult = computeFn(selectedValue);\n const result = processVariantValue(computedResult);\n classes.push(result.class);\n style = { ...style, ...result.style };\n }\n }\n\n return { classes, style };\n}\n\n/**\n * Processes the computed function if present.\n */\nfunction processComputed(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n): {\n classes: ClassValue[];\n style: StyleValue;\n updatedVariants: Record<string, unknown>;\n} {\n const classes: ClassValue[] = [];\n let style: StyleValue = {};\n let updatedVariants = { ...resolvedVariants };\n\n if (config.computed) {\n const context = {\n variants: resolvedVariants,\n setVariants: (newVariants: VariantValues<Record<string, unknown>>) => {\n updatedVariants = { ...updatedVariants, ...newVariants };\n },\n setDefaultVariants: (\n newDefaults: VariantValues<Record<string, unknown>>,\n ) => {\n // Only apply defaults for variants not already set\n for (const [key, value] of Object.entries(newDefaults)) {\n if (resolvedVariants[key] === undefined) {\n updatedVariants[key] = value;\n }\n }\n },\n };\n\n const computedResult = config.computed(context);\n if (computedResult != null) {\n const result = processVariantValue(computedResult);\n classes.push(result.class);\n style = { ...style, ...result.style };\n }\n }\n\n return { classes, style, updatedVariants };\n}\n\n/**\n * Normalizes a key source (array or component) to an object with keys and defaults.\n */\nfunction normalizeKeySource(source: unknown): {\n keys: string[];\n defaults: Record<string, unknown>;\n} {\n if (Array.isArray(source)) {\n return { keys: source as string[], defaults: {} };\n }\n // Components are functions with keys property, onlyVariants are objects with keys\n if (\n source &&\n (typeof source === \"object\" || typeof source === \"function\") &&\n \"keys\" in source\n ) {\n const keys = [...(source as { keys: string[] }).keys] as string[];\n const defaults =\n \"getVariants\" in source\n ? (\n source as { getVariants: () => Record<string, unknown> }\n ).getVariants()\n : {};\n return { keys, defaults };\n }\n return { keys: [], defaults: {} };\n}\n\n/**\n * Splits props into multiple groups based on key sources.\n */\nfunction splitPropsImpl(\n selfKeys: string[],\n selfDefaults: Record<string, unknown>,\n props: Record<string, unknown>,\n sources: Array<{ keys: string[]; defaults: Record<string, unknown> }>,\n): Record<string, unknown>[] {\n const allUsedKeys = new Set<string>(selfKeys);\n const results: Record<string, unknown>[] = [];\n\n // Self result with defaults\n const selfResult: Record<string, unknown> = {};\n // First apply defaults\n for (const [key, value] of Object.entries(selfDefaults)) {\n if (selfKeys.includes(key)) {\n selfResult[key] = value;\n }\n }\n // Then override with props\n for (const key of selfKeys) {\n if (key in props) {\n selfResult[key] = props[key];\n }\n }\n results.push(selfResult);\n\n // Process each source\n for (const source of sources) {\n const sourceResult: Record<string, unknown> = {};\n // First apply defaults\n for (const [key, value] of Object.entries(source.defaults)) {\n if (source.keys.includes(key)) {\n sourceResult[key] = value;\n }\n }\n // Then override with props\n for (const key of source.keys) {\n allUsedKeys.add(key);\n if (key in props) {\n sourceResult[key] = props[key];\n }\n }\n results.push(sourceResult);\n }\n\n // Rest - keys not used by anyone\n const rest: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n if (!allUsedKeys.has(key)) {\n rest[key] = value;\n }\n }\n results.push(rest);\n\n return results;\n}\n\nexport function create<M extends Mode>({\n defaultMode = \"jsx\" as M,\n transformClass = (className) => className,\n}: CreateParams<M> = {}) {\n const cx = (...classes: ClsxClassValue[]) => transformClass(clsx(...classes));\n\n const cv = <\n V extends Variants = {},\n CV extends ComputedVariants = {},\n const E extends AnyComponent[] = [],\n >(\n config: CVConfig<V, CV, E> = {},\n ): Component<V, CV, E, StyleProps[M]> => {\n type MergedVariants = MergeVariants<V, CV, E>;\n\n const variantKeys = collectVariantKeys(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n );\n\n const getClassPropertyName = (mode: Mode) =>\n mode === \"jsx\" ? \"className\" : \"class\";\n\n const getPropsKeys = (mode: Mode) => [\n getClassPropertyName(mode),\n \"style\",\n ...variantKeys,\n ];\n\n const computeResult = (\n props: ComponentProps<MergedVariants> = {},\n ): { className: string; style: StyleValue } => {\n const allClasses: ClassValue[] = [];\n let allStyle: StyleValue = {};\n\n // Extract variant props from input\n const variantProps: Record<string, unknown> = {};\n for (const key of variantKeys) {\n if (key in props) {\n variantProps[key] = (props as Record<string, unknown>)[key];\n }\n }\n\n // Resolve variants with defaults\n let resolvedVariants = resolveVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n variantProps,\n );\n\n // Process computed first to potentially update variants\n const computedResult = processComputed(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n );\n resolvedVariants = computedResult.updatedVariants;\n\n // Collect computedVariants keys that will override extended variants\n const computedVariantKeys = new Set<string>(\n config.computedVariants ? Object.keys(config.computedVariants) : [],\n );\n\n // Process extended components (separates base and variant classes)\n const extendedResult = processExtended(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n computedVariantKeys,\n );\n\n // 1. Extended base classes first\n allClasses.push(...extendedResult.baseClasses);\n allStyle = { ...allStyle, ...extendedResult.style };\n\n // 2. Current component's base class\n allClasses.push(config.class);\n\n // 3. Add base style\n if (config.style) {\n allStyle = { ...allStyle, ...config.style };\n }\n\n // 4. Extended variant classes\n allClasses.push(...extendedResult.variantClasses);\n\n // 5. Current component's variants\n const variantsResult = processVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n );\n allClasses.push(...variantsResult.classes);\n allStyle = { ...allStyle, ...variantsResult.style };\n\n // Add computed results\n allClasses.push(...computedResult.classes);\n allStyle = { ...allStyle, ...computedResult.style };\n\n // Merge class from props\n if (\"class\" in props) {\n allClasses.push(props.class);\n }\n if (\"className\" in props) {\n allClasses.push(props.className);\n }\n\n // Merge style from props\n if (props.style != null) {\n allStyle = { ...allStyle, ...normalizeStyle(props.style) };\n }\n\n return {\n className: cx(...(allClasses as ClsxClassValue[])),\n style: allStyle,\n };\n };\n\n type Defaults = VariantValues<MergedVariants>;\n\n const createModalComponent = <R extends ComponentResult>(\n mode: Mode,\n ): ModalComponent<MergedVariants, Defaults, R> => {\n const propsKeys = getPropsKeys(mode);\n\n const component = ((props: ComponentProps<MergedVariants> = {}) => {\n const { className, style } = computeResult(props);\n\n if (mode === \"jsx\") {\n return { className, style: styleValueToJSXStyle(style) } as R;\n }\n if (mode === \"html\") {\n return {\n class: className,\n style: styleValueToHTMLStyle(style),\n } as R;\n }\n // htmlObj\n return {\n class: className,\n style: styleValueToHTMLObjStyle(style),\n } as R;\n }) as ModalComponent<MergedVariants, Defaults, R>;\n\n component.class = (props: ComponentProps<MergedVariants> = {}) => {\n return computeResult(props).className;\n };\n\n component.style = ((props: ComponentProps<MergedVariants> = {}) => {\n const { style } = computeResult(props);\n if (mode === \"jsx\") return styleValueToJSXStyle(style);\n if (mode === \"html\") return styleValueToHTMLStyle(style);\n return styleValueToHTMLObjStyle(style);\n }) as ModalComponent<MergedVariants, Defaults, R>[\"style\"];\n\n component.getVariants = (\n variants?: VariantValues<MergedVariants>,\n ): VariantValues<MergedVariants> => {\n return resolveVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n variants as VariantValues<Record<string, unknown>>,\n ) as VariantValues<MergedVariants>;\n };\n\n component.keys = propsKeys as (keyof MergedVariants | keyof R)[];\n\n const selfDefaults = collectDefaultVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n );\n\n component.splitProps = ((\n props: Record<string, unknown>,\n ...sources: unknown[]\n ) => {\n const normalizedSources = sources.map(normalizeKeySource);\n return splitPropsImpl(\n propsKeys,\n selfDefaults,\n props,\n normalizedSources,\n );\n }) as SplitProps<MergedVariants, VariantValues<MergedVariants>, R>;\n\n component.onlyVariants = {\n getVariants: (\n variants?: VariantValues<MergedVariants>,\n ): VariantValues<MergedVariants> => {\n return resolveVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n variants as VariantValues<Record<string, unknown>>,\n ) as VariantValues<MergedVariants>;\n },\n keys: variantKeys as (keyof MergedVariants)[],\n splitProps: ((\n props: Record<string, unknown>,\n ...sources: unknown[]\n ) => {\n const normalizedSources = sources.map(normalizeKeySource);\n return splitPropsImpl(\n variantKeys,\n selfDefaults,\n props,\n normalizedSources,\n );\n }) as OnlyVariantsSplitProps<\n MergedVariants,\n VariantValues<MergedVariants>\n >,\n } as OnlyVariantsComponent<MergedVariants, VariantValues<MergedVariants>>;\n\n // Compute base class (without variants) - includes extended base classes\n const extendedBaseClasses: ClassValue[] = [];\n if (config.extend) {\n for (const ext of config.extend) {\n extendedBaseClasses.push(ext._baseClass);\n }\n }\n component._baseClass = cx(\n ...(extendedBaseClasses as ClsxClassValue[]),\n config.class as ClsxClassValue,\n );\n\n return component;\n };\n\n // Create the default modal component\n const defaultComponent = createModalComponent<StyleProps[M]>(defaultMode);\n\n // Create all modal variants\n const jsxComponent = createModalComponent<JSXProps>(\"jsx\");\n const htmlComponent = createModalComponent<HTMLProps>(\"html\");\n const htmlObjComponent = createModalComponent<HTMLObjProps>(\"htmlObj\");\n\n // Build the final component\n const component = defaultComponent as Component<V, CV, E, StyleProps[M]>;\n component.jsx = jsxComponent;\n component.html = htmlComponent;\n component.htmlObj = htmlObjComponent;\n\n return component;\n };\n\n return { cv, cx };\n}\n\nexport const { cv, cx } = create();\n"],"x_google_ignoreList":[0],"mappings":";AAAA,SAAS,EAAE,GAAE;CAAC,IAAI,GAAE,GAAE,IAAE;AAAG,KAAG,YAAU,OAAO,KAAG,YAAU,OAAO,EAAE,MAAG;UAAU,YAAU,OAAO,EAAE,KAAG,MAAM,QAAQ,EAAE,EAAC;EAAC,IAAI,IAAE,EAAE;AAAO,OAAI,IAAE,GAAE,IAAE,GAAE,IAAI,GAAE,OAAK,IAAE,EAAE,EAAE,GAAG,MAAI,MAAI,KAAG,MAAK,KAAG;OAAQ,MAAI,KAAK,EAAE,GAAE,OAAK,MAAI,KAAG,MAAK,KAAG;AAAG,QAAO;;AAAE,SAAgB,OAAM;AAAC,MAAI,IAAI,GAAE,GAAE,IAAE,GAAE,IAAE,IAAG,IAAE,UAAU,QAAO,IAAE,GAAE,IAAI,EAAC,IAAE,UAAU,QAAM,IAAE,EAAE,EAAE,MAAI,MAAI,KAAG,MAAK,KAAG;AAAG,QAAO;;AAAE,mBAAe;;;;;;;;;;ACc/X,SAAgB,cAAc,KAAa;AAEzC,KAAI,IAAI,WAAW,KAAK,CACtB,QAAO;AAET,QAAO,IAAI,QAAQ,eAAe,GAAG,WAAW,OAAO,aAAa,CAAC;;;;;;;;AASvE,SAAgB,cAAc,KAAa;AAEzC,KAAI,IAAI,WAAW,KAAK,CACtB,QAAO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js","names":["cx","clsx","cv","component"],"sources":["../../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs","../src/utils.ts","../src/index.ts"],"sourcesContent":["function r(e){var t,f,n=\"\";if(\"string\"==typeof e||\"number\"==typeof e)n+=e;else if(\"object\"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=\" \"),n+=f)}else for(f in e)e[f]&&(n&&(n+=\" \"),n+=f);return n}export function clsx(){for(var e,t,f=0,n=\"\",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=\" \"),n+=t);return n}export default clsx;","import type * as CSS from \"csstype\";\n\nimport type {\n StyleValue,\n JSXCSSProperties,\n HTMLCSSProperties,\n} from \"./types.ts\";\n\n/**\n * Converts a hyphenated CSS property name to camelCase.\n * @example\n * hyphenToCamel(\"background-color\") // \"backgroundColor\"\n * hyphenToCamel(\"--custom-var\") // \"--custom-var\" (CSS variables are preserved)\n */\nexport function hyphenToCamel(str: string) {\n // CSS custom properties (variables) should not be converted\n if (str.startsWith(\"--\")) {\n return str;\n }\n return str.replace(/-([a-z])/gi, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Converts a camelCase CSS property name to hyphenated form.\n * @example\n * camelToHyphen(\"backgroundColor\") // \"background-color\"\n * camelToHyphen(\"--customVar\") // \"--customVar\" (CSS variables are preserved)\n */\nexport function camelToHyphen(str: string) {\n // CSS custom properties (variables) should not be converted\n if (str.startsWith(\"--\")) {\n return str;\n }\n return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n/**\n * Parses a length value, adding \"px\" if it's a number.\n * @example\n * parseLengthValue(16); // \"16px\"\n * parseLengthValue(\"2em\"); // \"2em\"\n */\nexport function parseLengthValue(value: string | number) {\n if (typeof value === \"string\") return value;\n return `${value}px`;\n}\n\n/**\n * Parses a CSS style string into a StyleValue object.\n * @example\n * htmlStyleToStyleValue(\"background-color: red; font-size: 16px;\");\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function htmlStyleToStyleValue(styleString: string) {\n if (!styleString) return {};\n\n const result: StyleValue = {};\n const declarations = styleString.split(\";\");\n\n for (const declaration of declarations) {\n const trimmed = declaration.trim();\n if (!trimmed) continue;\n\n const colonIndex = trimmed.indexOf(\":\");\n if (colonIndex === -1) continue;\n\n const property = trimmed.slice(0, colonIndex).trim();\n const value = trimmed.slice(colonIndex + 1).trim();\n if (!property) continue;\n if (!value) continue;\n\n const camelProperty = hyphenToCamel(property) as any;\n result[camelProperty] = value;\n }\n\n return result;\n}\n\n/**\n * Converts a hyphenated style object to a camelCase StyleValue object.\n * @example\n * htmlObjStyleToStyleValue({ \"background-color\": \"red\", \"font-size\": \"16px\" });\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function htmlObjStyleToStyleValue(style: HTMLCSSProperties) {\n const result: StyleValue = {};\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n const property = hyphenToCamel(key) as any;\n result[property] = parseLengthValue(value);\n }\n return result;\n}\n\n/**\n * Converts a camelCase style object to a StyleValue object.\n * @example\n * jsxStyleToStyleValue({ backgroundColor: \"red\", fontSize: 16 });\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function jsxStyleToStyleValue(style: JSXCSSProperties) {\n const result: StyleValue = {};\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n result[key as any] = parseLengthValue(value);\n }\n return result;\n}\n\n/**\n * Converts a StyleValue object to a CSS style string.\n * @example\n * styleValueToHTMLStyle({ backgroundColor: \"red\", fontSize: \"16px\" });\n * // \"background-color: red; font-size: 16px;\"\n */\nexport function styleValueToHTMLStyle(style: StyleValue): string {\n const parts: string[] = [];\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n parts.push(`${camelToHyphen(key)}: ${value}`);\n }\n if (!parts.length) return \"\";\n return `${parts.join(\"; \")};`;\n}\n\n/**\n * Converts a StyleValue object to a hyphenated style object.\n * @example\n * styleValueToHTMLObjStyle({ backgroundColor: \"red\", fontSize: \"16px\" });\n * // { \"background-color\": \"red\", \"font-size\": \"16px\" }\n */\nexport function styleValueToHTMLObjStyle(style: StyleValue) {\n const result: CSS.PropertiesHyphen = {};\n for (const [key, value] of Object.entries(style)) {\n if (value == null) continue;\n const property = camelToHyphen(key) as keyof HTMLCSSProperties;\n result[property] = value;\n }\n return result;\n}\n\n/**\n * Converts a StyleValue object to a camelCase style object.\n * @example\n * styleValueToJSXStyle({ backgroundColor: \"red\", fontSize: \"16px\" });\n * // { backgroundColor: \"red\", fontSize: \"16px\" }\n */\nexport function styleValueToJSXStyle(style: StyleValue) {\n return style as JSXCSSProperties;\n}\n\n/**\n * Type guard to check if a style object has hyphenated keys.\n * @example\n * isHTMLObjStyle({ \"background-color\": \"red\" }); // true\n * isHTMLObjStyle({ backgroundColor: \"red\" }); // false\n */\nexport function isHTMLObjStyle(\n style: CSS.Properties<any> | CSS.PropertiesHyphen<any>,\n): style is CSS.PropertiesHyphen {\n return Object.keys(style).some(\n (key) => key.includes(\"-\") && !key.startsWith(\"--\"),\n );\n}\n","import clsx, { type ClassValue as ClsxClassValue } from \"clsx\";\n\nimport type {\n Variants,\n ComputedVariants,\n AnyComponent,\n Component,\n StyleProps,\n ClassValue,\n StyleValue,\n StyleClassValue,\n VariantValues,\n Computed,\n ExtendableVariants,\n MergeVariants,\n ModalComponent,\n ComponentResult,\n JSXProps,\n HTMLProps,\n HTMLObjProps,\n OnlyVariantsComponent,\n ComponentProps,\n SplitPropsFunction,\n} from \"./types.ts\";\n\nimport {\n htmlObjStyleToStyleValue,\n htmlStyleToStyleValue,\n isHTMLObjStyle,\n jsxStyleToStyleValue,\n styleValueToHTMLObjStyle,\n styleValueToHTMLStyle,\n styleValueToJSXStyle,\n} from \"./utils.ts\";\n\nconst MODES = [\"jsx\", \"html\", \"htmlObj\"] as const;\ntype Mode = (typeof MODES)[number];\n\nexport type { ClassValue, StyleValue, StyleClassValue };\n\nexport type VariantProps<T extends Pick<AnyComponent, \"getVariants\">> =\n ReturnType<T[\"getVariants\"]>;\n\nexport interface CVConfig<\n V extends Variants = {},\n CV extends ComputedVariants = {},\n E extends AnyComponent[] = [],\n> {\n extend?: E;\n class?: ClassValue;\n style?: StyleValue;\n variants?: ExtendableVariants<V, E>;\n computedVariants?: CV;\n defaultVariants?: VariantValues<MergeVariants<V, CV, E>>;\n computed?: Computed<MergeVariants<V, CV, E>>;\n}\n\ninterface CreateParams<M extends Mode> {\n defaultMode?: M;\n transformClass?: (className: string) => string;\n}\n\n/**\n * Checks if a value is a style-class object (has style properties, not just a\n * class value).\n */\nfunction isStyleClassValue(value: unknown): value is StyleClassValue {\n if (typeof value !== \"object\") return false;\n if (value == null) return false;\n if (Array.isArray(value)) return false;\n return true;\n}\n\n/**\n * Converts any style input (string, JSX object, or HTML object) to a\n * normalized StyleValue.\n */\nfunction normalizeStyle(style: unknown): StyleValue {\n if (typeof style === \"string\") {\n return htmlStyleToStyleValue(style);\n }\n if (typeof style === \"object\" && style != null) {\n if (isHTMLObjStyle(style as Record<string, unknown>)) {\n return htmlObjStyleToStyleValue(style as Record<string, string | number>);\n }\n return jsxStyleToStyleValue(style as Record<string, string | number>);\n }\n return {};\n}\n\n/**\n * Extracts class and style from a style-class value object.\n */\nfunction extractStyleClass(value: StyleClassValue): {\n class: ClassValue;\n style: StyleValue;\n} {\n const { class: cls, ...style } = value;\n return { class: cls, style };\n}\n\n/**\n * Processes a variant value to extract class and style.\n */\nfunction processVariantValue(value: unknown): {\n class: ClassValue;\n style: StyleValue;\n} {\n if (isStyleClassValue(value)) {\n return extractStyleClass(value);\n }\n return { class: value as ClassValue, style: {} };\n}\n\n/**\n * Gets all variant keys from a component's config, including extended\n * components.\n */\nfunction collectVariantKeys(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): string[] {\n const keys = new Set<string>();\n\n // Collect from extended components\n if (config.extend) {\n for (const ext of config.extend) {\n for (const key of ext.onlyVariants.keys) {\n keys.add(key as string);\n }\n }\n }\n\n // Collect from variants\n if (config.variants) {\n for (const key of Object.keys(config.variants)) {\n keys.add(key);\n }\n }\n\n // Collect from computedVariants\n if (config.computedVariants) {\n for (const key of Object.keys(config.computedVariants)) {\n keys.add(key);\n }\n }\n\n return Array.from(keys);\n}\n\n/**\n * Collects default variants from extended components and the current config.\n * Also handles implicit boolean defaults (when only `false` key exists).\n */\nfunction collectDefaultVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): Record<string, unknown> {\n let defaults: Record<string, unknown> = {};\n\n // Collect from extended components\n if (config.extend) {\n for (const ext of config.extend) {\n const extDefaults = ext.getVariants();\n defaults = { ...defaults, ...extDefaults };\n }\n }\n\n // Handle implicit boolean defaults from variants\n // If a variant only has a `false` key and no `true` key, default to false\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n if (isStyleClassValue(variantDef)) {\n const keys = Object.keys(variantDef);\n const hasFalseOnly = keys.includes(\"false\") && !keys.includes(\"true\");\n if (hasFalseOnly && defaults[variantName] === undefined) {\n defaults[variantName] = false;\n }\n }\n }\n }\n\n // Override with current config's defaults\n if (config.defaultVariants) {\n defaults = { ...defaults, ...config.defaultVariants };\n }\n\n return defaults;\n}\n\n/**\n * Resolves variant values by merging defaults with provided props.\n */\nfunction resolveVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n props: Record<string, unknown> = {},\n): Record<string, unknown> {\n const defaults = collectDefaultVariants(config);\n return { ...defaults, ...props };\n}\n\n/**\n * Gets the value for a single variant based on the variant definition and the\n * selected value.\n */\nfunction getVariantResult(\n variantDef: unknown,\n selectedValue: unknown,\n): { class: ClassValue; style: StyleValue } {\n // Shorthand variant: `disabled: \"disabled-class\"` means { true: \"...\" }\n if (!isStyleClassValue(variantDef)) {\n if (selectedValue === true) {\n return processVariantValue(variantDef);\n }\n return { class: null, style: {} };\n }\n\n // Object variant: { sm: \"...\", lg: \"...\" }\n const key = String(selectedValue);\n const value = (variantDef as Record<string, unknown>)[key];\n if (value === undefined) return { class: null, style: {} };\n\n return processVariantValue(value);\n}\n\n/**\n * Processes extended components and returns base classes and variant classes separately.\n * Base classes should come before current component's base, variant classes come after.\n * When overrideVariantKeys is provided, those variant keys are excluded from the extended\n * component's result (used when current component's computedVariants overrides them).\n */\nfunction processExtended(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n overrideVariantKeys: Set<string> = new Set(),\n): {\n baseClasses: ClassValue[];\n variantClasses: ClassValue[];\n style: StyleValue;\n} {\n const baseClasses: ClassValue[] = [];\n const variantClasses: ClassValue[] = [];\n let style: StyleValue = {};\n\n if (config.extend) {\n for (const ext of config.extend) {\n // Filter out variant keys that are being overridden by current component's computedVariants\n const filteredVariants = { ...resolvedVariants };\n for (const key of overrideVariantKeys) {\n delete filteredVariants[key];\n }\n\n // Get the result with filtered variants (excluding overridden keys)\n const extResult = ext({ ...filteredVariants });\n\n // Only merge style for non-overridden keys\n const extStyle = normalizeStyle(extResult.style);\n style = { ...style, ...extStyle };\n\n // Get base class from internal property (no variants)\n const baseClass = ext._baseClass;\n baseClasses.push(baseClass);\n\n // Get full class with variants\n const fullClass =\n \"className\" in extResult ? extResult.className : extResult.class;\n\n // Extract variant portion (full class minus base class)\n if (fullClass && baseClass) {\n const baseClassSet = new Set(baseClass.split(\" \").filter(Boolean));\n const variantPortion = fullClass\n .split(\" \")\n .filter((c: string) => c && !baseClassSet.has(c))\n .join(\" \");\n if (variantPortion) {\n variantClasses.push(variantPortion);\n }\n } else if (fullClass && !baseClass) {\n variantClasses.push(fullClass);\n }\n }\n }\n\n return { baseClasses, variantClasses, style };\n}\n\n/**\n * Processes all variants (not extended) and returns accumulated class and\n * style.\n */\nfunction processVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n): { classes: ClassValue[]; style: StyleValue } {\n const classes: ClassValue[] = [];\n let style: StyleValue = {};\n\n // Process current component's variants\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const result = getVariantResult(variantDef, selectedValue);\n classes.push(result.class);\n style = { ...style, ...result.style };\n }\n }\n\n // Process computedVariants\n if (config.computedVariants) {\n for (const [variantName, computeFn] of Object.entries(\n config.computedVariants,\n )) {\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const computedResult = computeFn(selectedValue);\n const result = processVariantValue(computedResult);\n classes.push(result.class);\n style = { ...style, ...result.style };\n }\n }\n\n return { classes, style };\n}\n\n/**\n * Processes the computed function if present.\n */\nfunction processComputed(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n): {\n classes: ClassValue[];\n style: StyleValue;\n updatedVariants: Record<string, unknown>;\n} {\n const classes: ClassValue[] = [];\n let style: StyleValue = {};\n let updatedVariants = { ...resolvedVariants };\n\n if (config.computed) {\n const context = {\n variants: resolvedVariants,\n setVariants: (newVariants: VariantValues<Record<string, unknown>>) => {\n updatedVariants = { ...updatedVariants, ...newVariants };\n },\n setDefaultVariants: (\n newDefaults: VariantValues<Record<string, unknown>>,\n ) => {\n // Only apply defaults for variants not already set\n for (const [key, value] of Object.entries(newDefaults)) {\n if (resolvedVariants[key] === undefined) {\n updatedVariants[key] = value;\n }\n }\n },\n };\n\n const computedResult = config.computed(context);\n if (computedResult != null) {\n const result = processVariantValue(computedResult);\n classes.push(result.class);\n style = { ...style, ...result.style };\n }\n }\n\n return { classes, style, updatedVariants };\n}\n\n/**\n * Normalizes a key source (array or component) to an object with keys and defaults.\n */\nfunction normalizeKeySource(source: unknown): {\n keys: string[];\n defaults: Record<string, unknown>;\n} {\n if (Array.isArray(source)) {\n return { keys: source as string[], defaults: {} };\n }\n // Components are functions with keys property, onlyVariants are objects with keys\n if (\n source &&\n (typeof source === \"object\" || typeof source === \"function\") &&\n \"keys\" in source\n ) {\n const keys = [...(source as { keys: string[] }).keys] as string[];\n const defaults =\n \"getVariants\" in source\n ? (\n source as { getVariants: () => Record<string, unknown> }\n ).getVariants()\n : {};\n return { keys, defaults };\n }\n return { keys: [], defaults: {} };\n}\n\n/**\n * Splits props into multiple groups based on key sources.\n */\nfunction splitPropsImpl(\n selfKeys: string[],\n selfDefaults: Record<string, unknown>,\n props: Record<string, unknown>,\n sources: Array<{ keys: string[]; defaults: Record<string, unknown> }>,\n): Record<string, unknown>[] {\n const allUsedKeys = new Set<string>(selfKeys);\n const results: Record<string, unknown>[] = [];\n\n // Self result with defaults\n const selfResult: Record<string, unknown> = {};\n // First apply defaults\n for (const [key, value] of Object.entries(selfDefaults)) {\n if (selfKeys.includes(key)) {\n selfResult[key] = value;\n }\n }\n // Then override with props\n for (const key of selfKeys) {\n if (key in props) {\n selfResult[key] = props[key];\n }\n }\n results.push(selfResult);\n\n // Process each source\n for (const source of sources) {\n const sourceResult: Record<string, unknown> = {};\n // First apply defaults\n for (const [key, value] of Object.entries(source.defaults)) {\n if (source.keys.includes(key)) {\n sourceResult[key] = value;\n }\n }\n // Then override with props\n for (const key of source.keys) {\n allUsedKeys.add(key);\n if (key in props) {\n sourceResult[key] = props[key];\n }\n }\n results.push(sourceResult);\n }\n\n // Rest - keys not used by anyone\n const rest: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n if (!allUsedKeys.has(key)) {\n rest[key] = value;\n }\n }\n results.push(rest);\n\n return results;\n}\n\n/**\n * Splits props into multiple groups based on key sources.\n * Each source gets its own result object containing all its matching keys.\n * The last element is always the \"rest\" containing keys not claimed by any source.\n *\n * @example\n * ```ts\n * const [buttonProps, inputProps, rest] = splitProps(\n * props,\n * buttonComponent,\n * inputComponent.onlyVariants,\n * );\n * ```\n */\nexport const splitProps: SplitPropsFunction = ((\n props: Record<string, unknown>,\n source1: unknown,\n ...sources: unknown[]\n) => {\n const normalizedSource1 = normalizeKeySource(source1);\n const normalizedSources = sources.map(normalizeKeySource);\n return splitPropsImpl(\n normalizedSource1.keys,\n normalizedSource1.defaults,\n props,\n normalizedSources,\n );\n}) as SplitPropsFunction;\n\nexport function create<M extends Mode>({\n defaultMode = \"jsx\" as M,\n transformClass = (className) => className,\n}: CreateParams<M> = {}) {\n const cx = (...classes: ClsxClassValue[]) => transformClass(clsx(...classes));\n\n const cv = <\n V extends Variants = {},\n CV extends ComputedVariants = {},\n const E extends AnyComponent[] = [],\n >(\n config: CVConfig<V, CV, E> = {},\n ): Component<V, CV, E, StyleProps[M]> => {\n type MergedVariants = MergeVariants<V, CV, E>;\n\n const variantKeys = collectVariantKeys(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n );\n\n const getClassPropertyName = (mode: Mode) =>\n mode === \"jsx\" ? \"className\" : \"class\";\n\n const getPropsKeys = (mode: Mode) => [\n getClassPropertyName(mode),\n \"style\",\n ...variantKeys,\n ];\n\n const computeResult = (\n props: ComponentProps<MergedVariants> = {},\n ): { className: string; style: StyleValue } => {\n const allClasses: ClassValue[] = [];\n let allStyle: StyleValue = {};\n\n // Extract variant props from input\n const variantProps: Record<string, unknown> = {};\n for (const key of variantKeys) {\n if (key in props) {\n variantProps[key] = (props as Record<string, unknown>)[key];\n }\n }\n\n // Resolve variants with defaults\n let resolvedVariants = resolveVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n variantProps,\n );\n\n // Process computed first to potentially update variants\n const computedResult = processComputed(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n );\n resolvedVariants = computedResult.updatedVariants;\n\n // Collect computedVariants keys that will override extended variants\n const computedVariantKeys = new Set<string>(\n config.computedVariants ? Object.keys(config.computedVariants) : [],\n );\n\n // Process extended components (separates base and variant classes)\n const extendedResult = processExtended(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n computedVariantKeys,\n );\n\n // 1. Extended base classes first\n allClasses.push(...extendedResult.baseClasses);\n allStyle = { ...allStyle, ...extendedResult.style };\n\n // 2. Current component's base class\n allClasses.push(config.class);\n\n // 3. Add base style\n if (config.style) {\n allStyle = { ...allStyle, ...config.style };\n }\n\n // 4. Extended variant classes\n allClasses.push(...extendedResult.variantClasses);\n\n // 5. Current component's variants\n const variantsResult = processVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n );\n allClasses.push(...variantsResult.classes);\n allStyle = { ...allStyle, ...variantsResult.style };\n\n // Add computed results\n allClasses.push(...computedResult.classes);\n allStyle = { ...allStyle, ...computedResult.style };\n\n // Merge class from props\n if (\"class\" in props) {\n allClasses.push(props.class);\n }\n if (\"className\" in props) {\n allClasses.push(props.className);\n }\n\n // Merge style from props\n if (props.style != null) {\n allStyle = { ...allStyle, ...normalizeStyle(props.style) };\n }\n\n return {\n className: cx(...(allClasses as ClsxClassValue[])),\n style: allStyle,\n };\n };\n\n const createModalComponent = <R extends ComponentResult>(\n mode: Mode,\n ): ModalComponent<MergedVariants, R> => {\n const propsKeys = getPropsKeys(mode);\n\n const component = ((props: ComponentProps<MergedVariants> = {}) => {\n const { className, style } = computeResult(props);\n\n if (mode === \"jsx\") {\n return { className, style: styleValueToJSXStyle(style) } as R;\n }\n if (mode === \"html\") {\n return {\n class: className,\n style: styleValueToHTMLStyle(style),\n } as R;\n }\n // htmlObj\n return {\n class: className,\n style: styleValueToHTMLObjStyle(style),\n } as R;\n }) as ModalComponent<MergedVariants, R>;\n\n component.class = (props: ComponentProps<MergedVariants> = {}) => {\n return computeResult(props).className;\n };\n\n component.style = ((props: ComponentProps<MergedVariants> = {}) => {\n const { style } = computeResult(props);\n if (mode === \"jsx\") return styleValueToJSXStyle(style);\n if (mode === \"html\") return styleValueToHTMLStyle(style);\n return styleValueToHTMLObjStyle(style);\n }) as ModalComponent<MergedVariants, R>[\"style\"];\n\n component.getVariants = (\n variants?: VariantValues<MergedVariants>,\n ): VariantValues<MergedVariants> => {\n return resolveVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n variants as VariantValues<Record<string, unknown>>,\n ) as VariantValues<MergedVariants>;\n };\n\n component.keys = propsKeys as (keyof MergedVariants | keyof R)[];\n\n component.onlyVariants = {\n getVariants: (\n variants?: VariantValues<MergedVariants>,\n ): VariantValues<MergedVariants> => {\n return resolveVariants(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n variants as VariantValues<Record<string, unknown>>,\n ) as VariantValues<MergedVariants>;\n },\n keys: variantKeys as (keyof MergedVariants)[],\n } as OnlyVariantsComponent<MergedVariants>;\n\n // Compute base class (without variants) - includes extended base classes\n const extendedBaseClasses: ClassValue[] = [];\n if (config.extend) {\n for (const ext of config.extend) {\n extendedBaseClasses.push(ext._baseClass);\n }\n }\n component._baseClass = cx(\n ...(extendedBaseClasses as ClsxClassValue[]),\n config.class as ClsxClassValue,\n );\n\n return component;\n };\n\n // Create the default modal component\n const defaultComponent = createModalComponent<StyleProps[M]>(defaultMode);\n\n // Create all modal variants\n const jsxComponent = createModalComponent<JSXProps>(\"jsx\");\n const htmlComponent = createModalComponent<HTMLProps>(\"html\");\n const htmlObjComponent = createModalComponent<HTMLObjProps>(\"htmlObj\");\n\n // Build the final component\n const component = defaultComponent as Component<V, CV, E, StyleProps[M]>;\n component.jsx = jsxComponent;\n component.html = htmlComponent;\n component.htmlObj = htmlObjComponent;\n\n return component;\n };\n\n return { cv, cx };\n}\n\nexport const { cv, cx } = create();\n"],"x_google_ignoreList":[0],"mappings":";AAAA,SAAS,EAAE,GAAE;CAAC,IAAI,GAAE,GAAE,IAAE;AAAG,KAAG,YAAU,OAAO,KAAG,YAAU,OAAO,EAAE,MAAG;UAAU,YAAU,OAAO,EAAE,KAAG,MAAM,QAAQ,EAAE,EAAC;EAAC,IAAI,IAAE,EAAE;AAAO,OAAI,IAAE,GAAE,IAAE,GAAE,IAAI,GAAE,OAAK,IAAE,EAAE,EAAE,GAAG,MAAI,MAAI,KAAG,MAAK,KAAG;OAAQ,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OAAI,OAAO,OACT,MAAK,MAAM,OAAO,OAAO,OACvB,qBAAoB,KAAK,IAAI,WAAW;AAG5C,eAAU,aAAaH,KACrB,GAAI,qBACJ,OAAO,MACR;AAED,UAAOG;;EAIT,MAAM,mBAAmB,qBAAoC,YAAY;EAGzE,MAAM,eAAe,qBAA+B,MAAM;EAC1D,MAAM,gBAAgB,qBAAgC,OAAO;EAC7D,MAAM,mBAAmB,qBAAmC,UAAU;EAGtE,MAAM,YAAY;AAClB,YAAU,MAAM;AAChB,YAAU,OAAO;AACjB,YAAU,UAAU;AAEpB,SAAO;;AAGT,QAAO;EAAE;EAAI;EAAI;;AAGnB,MAAa,EAAE,IAAI,OAAO,QAAQ"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -20,8 +20,7 @@ import type {
|
|
|
20
20
|
HTMLObjProps,
|
|
21
21
|
OnlyVariantsComponent,
|
|
22
22
|
ComponentProps,
|
|
23
|
-
|
|
24
|
-
OnlyVariantsSplitProps,
|
|
23
|
+
SplitPropsFunction,
|
|
25
24
|
} from "./types.ts";
|
|
26
25
|
|
|
27
26
|
import {
|
|
@@ -455,6 +454,35 @@ function splitPropsImpl(
|
|
|
455
454
|
return results;
|
|
456
455
|
}
|
|
457
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Splits props into multiple groups based on key sources.
|
|
459
|
+
* Each source gets its own result object containing all its matching keys.
|
|
460
|
+
* The last element is always the "rest" containing keys not claimed by any source.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* const [buttonProps, inputProps, rest] = splitProps(
|
|
465
|
+
* props,
|
|
466
|
+
* buttonComponent,
|
|
467
|
+
* inputComponent.onlyVariants,
|
|
468
|
+
* );
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
export const splitProps: SplitPropsFunction = ((
|
|
472
|
+
props: Record<string, unknown>,
|
|
473
|
+
source1: unknown,
|
|
474
|
+
...sources: unknown[]
|
|
475
|
+
) => {
|
|
476
|
+
const normalizedSource1 = normalizeKeySource(source1);
|
|
477
|
+
const normalizedSources = sources.map(normalizeKeySource);
|
|
478
|
+
return splitPropsImpl(
|
|
479
|
+
normalizedSource1.keys,
|
|
480
|
+
normalizedSource1.defaults,
|
|
481
|
+
props,
|
|
482
|
+
normalizedSources,
|
|
483
|
+
);
|
|
484
|
+
}) as SplitPropsFunction;
|
|
485
|
+
|
|
458
486
|
export function create<M extends Mode>({
|
|
459
487
|
defaultMode = "jsx" as M,
|
|
460
488
|
transformClass = (className) => className,
|
|
@@ -568,11 +596,9 @@ export function create<M extends Mode>({
|
|
|
568
596
|
};
|
|
569
597
|
};
|
|
570
598
|
|
|
571
|
-
type Defaults = VariantValues<MergedVariants>;
|
|
572
|
-
|
|
573
599
|
const createModalComponent = <R extends ComponentResult>(
|
|
574
600
|
mode: Mode,
|
|
575
|
-
): ModalComponent<MergedVariants,
|
|
601
|
+
): ModalComponent<MergedVariants, R> => {
|
|
576
602
|
const propsKeys = getPropsKeys(mode);
|
|
577
603
|
|
|
578
604
|
const component = ((props: ComponentProps<MergedVariants> = {}) => {
|
|
@@ -592,7 +618,7 @@ export function create<M extends Mode>({
|
|
|
592
618
|
class: className,
|
|
593
619
|
style: styleValueToHTMLObjStyle(style),
|
|
594
620
|
} as R;
|
|
595
|
-
}) as ModalComponent<MergedVariants,
|
|
621
|
+
}) as ModalComponent<MergedVariants, R>;
|
|
596
622
|
|
|
597
623
|
component.class = (props: ComponentProps<MergedVariants> = {}) => {
|
|
598
624
|
return computeResult(props).className;
|
|
@@ -603,7 +629,7 @@ export function create<M extends Mode>({
|
|
|
603
629
|
if (mode === "jsx") return styleValueToJSXStyle(style);
|
|
604
630
|
if (mode === "html") return styleValueToHTMLStyle(style);
|
|
605
631
|
return styleValueToHTMLObjStyle(style);
|
|
606
|
-
}) as ModalComponent<MergedVariants,
|
|
632
|
+
}) as ModalComponent<MergedVariants, R>["style"];
|
|
607
633
|
|
|
608
634
|
component.getVariants = (
|
|
609
635
|
variants?: VariantValues<MergedVariants>,
|
|
@@ -616,23 +642,6 @@ export function create<M extends Mode>({
|
|
|
616
642
|
|
|
617
643
|
component.keys = propsKeys as (keyof MergedVariants | keyof R)[];
|
|
618
644
|
|
|
619
|
-
const selfDefaults = collectDefaultVariants(
|
|
620
|
-
config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,
|
|
621
|
-
);
|
|
622
|
-
|
|
623
|
-
component.splitProps = ((
|
|
624
|
-
props: Record<string, unknown>,
|
|
625
|
-
...sources: unknown[]
|
|
626
|
-
) => {
|
|
627
|
-
const normalizedSources = sources.map(normalizeKeySource);
|
|
628
|
-
return splitPropsImpl(
|
|
629
|
-
propsKeys,
|
|
630
|
-
selfDefaults,
|
|
631
|
-
props,
|
|
632
|
-
normalizedSources,
|
|
633
|
-
);
|
|
634
|
-
}) as SplitProps<MergedVariants, VariantValues<MergedVariants>, R>;
|
|
635
|
-
|
|
636
645
|
component.onlyVariants = {
|
|
637
646
|
getVariants: (
|
|
638
647
|
variants?: VariantValues<MergedVariants>,
|
|
@@ -643,22 +652,7 @@ export function create<M extends Mode>({
|
|
|
643
652
|
) as VariantValues<MergedVariants>;
|
|
644
653
|
},
|
|
645
654
|
keys: variantKeys as (keyof MergedVariants)[],
|
|
646
|
-
|
|
647
|
-
props: Record<string, unknown>,
|
|
648
|
-
...sources: unknown[]
|
|
649
|
-
) => {
|
|
650
|
-
const normalizedSources = sources.map(normalizeKeySource);
|
|
651
|
-
return splitPropsImpl(
|
|
652
|
-
variantKeys,
|
|
653
|
-
selfDefaults,
|
|
654
|
-
props,
|
|
655
|
-
normalizedSources,
|
|
656
|
-
);
|
|
657
|
-
}) as OnlyVariantsSplitProps<
|
|
658
|
-
MergedVariants,
|
|
659
|
-
VariantValues<MergedVariants>
|
|
660
|
-
>,
|
|
661
|
-
} as OnlyVariantsComponent<MergedVariants, VariantValues<MergedVariants>>;
|
|
655
|
+
} as OnlyVariantsComponent<MergedVariants>;
|
|
662
656
|
|
|
663
657
|
// Compute base class (without variants) - includes extended base classes
|
|
664
658
|
const extendedBaseClasses: ClassValue[] = [];
|
package/src/test.ts
CHANGED
|
@@ -12,7 +12,12 @@ import type {
|
|
|
12
12
|
StyleProperty,
|
|
13
13
|
} from "./types.ts";
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
cv as cvBase,
|
|
17
|
+
create,
|
|
18
|
+
splitProps,
|
|
19
|
+
type VariantProps,
|
|
20
|
+
} from "./index.ts";
|
|
16
21
|
import {
|
|
17
22
|
htmlObjStyleToStyleValue,
|
|
18
23
|
htmlStyleToStyleValue,
|
|
@@ -1299,7 +1304,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1299
1304
|
style: { color: "red" },
|
|
1300
1305
|
[classNameProp]: "extra",
|
|
1301
1306
|
};
|
|
1302
|
-
const [variantProps, otherProps] =
|
|
1307
|
+
const [variantProps, otherProps] = splitProps(props, component);
|
|
1303
1308
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1304
1309
|
Pick<
|
|
1305
1310
|
HTMLProperties<typeof component>,
|
|
@@ -1327,8 +1332,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1327
1332
|
style: "color: red;",
|
|
1328
1333
|
[classNameProp]: "extra",
|
|
1329
1334
|
};
|
|
1330
|
-
const [variantProps, otherProps] =
|
|
1331
|
-
|
|
1335
|
+
const [variantProps, otherProps] = splitProps(
|
|
1336
|
+
props,
|
|
1337
|
+
component.onlyVariants,
|
|
1338
|
+
);
|
|
1332
1339
|
expectTypeOf(variantProps).branded.toEqualTypeOf<{
|
|
1333
1340
|
size?: "sm" | "lg";
|
|
1334
1341
|
}>();
|
|
@@ -1382,7 +1389,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1382
1389
|
id: "test",
|
|
1383
1390
|
size: "lg",
|
|
1384
1391
|
};
|
|
1385
|
-
const [variantProps, otherProps] =
|
|
1392
|
+
const [variantProps, otherProps] = splitProps(props, component);
|
|
1386
1393
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1387
1394
|
Pick<
|
|
1388
1395
|
HTMLProperties<typeof component>,
|
|
@@ -1410,8 +1417,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1410
1417
|
[classNameProp]: "extra",
|
|
1411
1418
|
disabled: true,
|
|
1412
1419
|
};
|
|
1413
|
-
const [variantProps, extraProps, otherProps] =
|
|
1420
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1414
1421
|
props,
|
|
1422
|
+
component,
|
|
1415
1423
|
["disabled"],
|
|
1416
1424
|
);
|
|
1417
1425
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
@@ -1451,8 +1459,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1451
1459
|
color: "blue",
|
|
1452
1460
|
[classNameProp]: "extra",
|
|
1453
1461
|
};
|
|
1454
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1462
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1455
1463
|
props,
|
|
1464
|
+
component1,
|
|
1456
1465
|
component2,
|
|
1457
1466
|
);
|
|
1458
1467
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
@@ -1496,8 +1505,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1496
1505
|
id: "test",
|
|
1497
1506
|
size: "lg",
|
|
1498
1507
|
};
|
|
1499
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1508
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1500
1509
|
props,
|
|
1510
|
+
component1,
|
|
1501
1511
|
component2,
|
|
1502
1512
|
);
|
|
1503
1513
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
@@ -1523,8 +1533,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1523
1533
|
style: { backgroundColor: "yellow" },
|
|
1524
1534
|
[classNameProp]: "extra",
|
|
1525
1535
|
};
|
|
1526
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1536
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1527
1537
|
props,
|
|
1538
|
+
component1,
|
|
1528
1539
|
component2.onlyVariants,
|
|
1529
1540
|
);
|
|
1530
1541
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
@@ -1562,8 +1573,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1562
1573
|
color: "blue",
|
|
1563
1574
|
disabled: true,
|
|
1564
1575
|
};
|
|
1565
|
-
const [comp1Props, extraProps, comp2Props, otherProps] =
|
|
1566
|
-
|
|
1576
|
+
const [comp1Props, extraProps, comp2Props, otherProps] = splitProps(
|
|
1577
|
+
props,
|
|
1578
|
+
component1,
|
|
1579
|
+
["disabled"],
|
|
1580
|
+
component2.onlyVariants,
|
|
1581
|
+
);
|
|
1567
1582
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1568
1583
|
expect(extraProps).toEqual({ disabled: true });
|
|
1569
1584
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
@@ -1584,8 +1599,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1584
1599
|
id: "test",
|
|
1585
1600
|
size: "lg",
|
|
1586
1601
|
};
|
|
1587
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1602
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1588
1603
|
props,
|
|
1604
|
+
component1,
|
|
1589
1605
|
component2.onlyVariants,
|
|
1590
1606
|
);
|
|
1591
1607
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
@@ -1617,8 +1633,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1617
1633
|
defaultVariants: { color: "red" },
|
|
1618
1634
|
}),
|
|
1619
1635
|
);
|
|
1620
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1636
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1621
1637
|
{ id: "test" },
|
|
1638
|
+
component1,
|
|
1622
1639
|
component2.onlyVariants,
|
|
1623
1640
|
);
|
|
1624
1641
|
// Each gets its own defaults
|
|
@@ -1641,8 +1658,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1641
1658
|
size: "lg",
|
|
1642
1659
|
[classNameProp]: "extra",
|
|
1643
1660
|
};
|
|
1644
|
-
const [variantProps, otherProps] =
|
|
1645
|
-
|
|
1661
|
+
const [variantProps, otherProps] = splitProps(
|
|
1662
|
+
props,
|
|
1663
|
+
component.onlyVariants,
|
|
1664
|
+
);
|
|
1646
1665
|
expect(variantProps).toEqual({
|
|
1647
1666
|
size: "lg",
|
|
1648
1667
|
color: "red",
|
|
@@ -1662,8 +1681,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1662
1681
|
[classNameProp]: "extra",
|
|
1663
1682
|
disabled: true,
|
|
1664
1683
|
};
|
|
1665
|
-
const [variantProps, extraProps, otherProps] =
|
|
1666
|
-
|
|
1684
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1685
|
+
props,
|
|
1686
|
+
component.onlyVariants,
|
|
1687
|
+
["disabled"],
|
|
1688
|
+
);
|
|
1667
1689
|
expect(variantProps).toEqual({ size: "lg" });
|
|
1668
1690
|
expect(extraProps).toEqual({ disabled: true });
|
|
1669
1691
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
@@ -1692,8 +1714,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1692
1714
|
color: "blue",
|
|
1693
1715
|
[classNameProp]: "extra",
|
|
1694
1716
|
};
|
|
1695
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1696
|
-
|
|
1717
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1718
|
+
props,
|
|
1719
|
+
component1.onlyVariants,
|
|
1720
|
+
component2.onlyVariants,
|
|
1721
|
+
);
|
|
1697
1722
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1698
1723
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
1699
1724
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
@@ -1711,7 +1736,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1711
1736
|
id: "test",
|
|
1712
1737
|
size: "lg",
|
|
1713
1738
|
};
|
|
1714
|
-
const [variantProps, otherProps] =
|
|
1739
|
+
const [variantProps, otherProps] = splitProps(props, component);
|
|
1715
1740
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1716
1741
|
Pick<
|
|
1717
1742
|
HTMLProperties<typeof component>,
|
|
@@ -1736,8 +1761,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1736
1761
|
[classNameProp]: "extra",
|
|
1737
1762
|
disabled: true,
|
|
1738
1763
|
};
|
|
1739
|
-
const [variantProps, extraProps, otherProps] =
|
|
1764
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1740
1765
|
props,
|
|
1766
|
+
component,
|
|
1741
1767
|
["disabled"],
|
|
1742
1768
|
);
|
|
1743
1769
|
expect(variantProps).toEqual({
|
|
@@ -1769,8 +1795,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1769
1795
|
color: "blue",
|
|
1770
1796
|
[classNameProp]: "extra",
|
|
1771
1797
|
};
|
|
1772
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1798
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1773
1799
|
props,
|
|
1800
|
+
component1,
|
|
1774
1801
|
component2,
|
|
1775
1802
|
);
|
|
1776
1803
|
expect(comp1Props).toEqual({
|
|
@@ -1802,8 +1829,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1802
1829
|
id: "test",
|
|
1803
1830
|
size: "lg",
|
|
1804
1831
|
};
|
|
1805
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1832
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1806
1833
|
props,
|
|
1834
|
+
component1,
|
|
1807
1835
|
component2,
|
|
1808
1836
|
);
|
|
1809
1837
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
@@ -1830,8 +1858,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1830
1858
|
style: { backgroundColor: "yellow" },
|
|
1831
1859
|
[classNameProp]: "extra",
|
|
1832
1860
|
};
|
|
1833
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1861
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1834
1862
|
props,
|
|
1863
|
+
component1,
|
|
1835
1864
|
component2.onlyVariants,
|
|
1836
1865
|
);
|
|
1837
1866
|
expect(comp1Props).toEqual({
|
|
@@ -1860,8 +1889,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1860
1889
|
color: "blue",
|
|
1861
1890
|
disabled: true,
|
|
1862
1891
|
};
|
|
1863
|
-
const [comp1Props, extraProps, comp2Props, otherProps] =
|
|
1864
|
-
|
|
1892
|
+
const [comp1Props, extraProps, comp2Props, otherProps] = splitProps(
|
|
1893
|
+
props,
|
|
1894
|
+
component1,
|
|
1895
|
+
["disabled"],
|
|
1896
|
+
component2.onlyVariants,
|
|
1897
|
+
);
|
|
1865
1898
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1866
1899
|
expect(extraProps).toEqual({ disabled: true });
|
|
1867
1900
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
@@ -1882,8 +1915,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1882
1915
|
id: "test",
|
|
1883
1916
|
size: "lg",
|
|
1884
1917
|
};
|
|
1885
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1918
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1886
1919
|
props,
|
|
1920
|
+
component1,
|
|
1887
1921
|
component2.onlyVariants,
|
|
1888
1922
|
);
|
|
1889
1923
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
@@ -1911,8 +1945,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1911
1945
|
HTMLProperties<typeof component2> = {
|
|
1912
1946
|
id: "test",
|
|
1913
1947
|
};
|
|
1914
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1948
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1915
1949
|
props,
|
|
1950
|
+
component1,
|
|
1916
1951
|
component2.onlyVariants,
|
|
1917
1952
|
);
|
|
1918
1953
|
// Each gets its own defaults
|
|
@@ -1935,8 +1970,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1935
1970
|
size: "lg",
|
|
1936
1971
|
[classNameProp]: "extra",
|
|
1937
1972
|
};
|
|
1938
|
-
const [variantProps, otherProps] =
|
|
1939
|
-
|
|
1973
|
+
const [variantProps, otherProps] = splitProps(
|
|
1974
|
+
props,
|
|
1975
|
+
component.onlyVariants,
|
|
1976
|
+
);
|
|
1940
1977
|
expect(variantProps).toEqual({
|
|
1941
1978
|
size: "lg",
|
|
1942
1979
|
color: "red",
|
|
@@ -1956,8 +1993,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1956
1993
|
[classNameProp]: "extra",
|
|
1957
1994
|
disabled: true,
|
|
1958
1995
|
};
|
|
1959
|
-
const [variantProps, extraProps, otherProps] =
|
|
1960
|
-
|
|
1996
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1997
|
+
props,
|
|
1998
|
+
component.onlyVariants,
|
|
1999
|
+
["disabled"],
|
|
2000
|
+
);
|
|
1961
2001
|
expect(variantProps).toEqual({ size: "lg" });
|
|
1962
2002
|
expect(extraProps).toEqual({ disabled: true });
|
|
1963
2003
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
@@ -1986,8 +2026,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1986
2026
|
color: "blue",
|
|
1987
2027
|
[classNameProp]: "extra",
|
|
1988
2028
|
};
|
|
1989
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1990
|
-
|
|
2029
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
2030
|
+
props,
|
|
2031
|
+
component1.onlyVariants,
|
|
2032
|
+
component2.onlyVariants,
|
|
2033
|
+
);
|
|
1991
2034
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1992
2035
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
1993
2036
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
package/src/types.ts
CHANGED
|
@@ -69,335 +69,137 @@ type SourceDefaults<S> = S extends { getVariants: () => infer Defaults }
|
|
|
69
69
|
type SourceResult<T, S> = Pick<T, Extract<keyof T, SourceKeys<S>>> &
|
|
70
70
|
Omit<SourceDefaults<S>, keyof T>;
|
|
71
71
|
|
|
72
|
-
//
|
|
73
|
-
type
|
|
74
|
-
Omit<Defaults, keyof T>;
|
|
75
|
-
|
|
76
|
-
// All possible keys from ComponentResult (class, className, style)
|
|
77
|
-
type ComponentResultKeys =
|
|
78
|
-
| keyof JSXProps
|
|
79
|
-
| keyof HTMLProps
|
|
80
|
-
| keyof HTMLObjProps;
|
|
81
|
-
|
|
82
|
-
// Build result tuple based on number of sources
|
|
83
|
-
type SplitPropsResult<
|
|
84
|
-
T,
|
|
85
|
-
V,
|
|
86
|
-
D,
|
|
87
|
-
Sources extends readonly KeySource[],
|
|
88
|
-
> = Sources extends readonly []
|
|
89
|
-
? [
|
|
90
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
91
|
-
Omit<T, keyof V | ComponentResultKeys>,
|
|
92
|
-
]
|
|
93
|
-
: Sources extends readonly [infer S1 extends KeySource]
|
|
94
|
-
? [
|
|
95
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
96
|
-
SourceResult<T, S1>,
|
|
97
|
-
Omit<T, keyof V | ComponentResultKeys | SourceKeys<S1>>,
|
|
98
|
-
]
|
|
99
|
-
: Sources extends readonly [
|
|
100
|
-
infer S1 extends KeySource,
|
|
101
|
-
infer S2 extends KeySource,
|
|
102
|
-
]
|
|
103
|
-
? [
|
|
104
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
105
|
-
SourceResult<T, S1>,
|
|
106
|
-
SourceResult<T, S2>,
|
|
107
|
-
Omit<
|
|
108
|
-
T,
|
|
109
|
-
keyof V | ComponentResultKeys | SourceKeys<S1> | SourceKeys<S2>
|
|
110
|
-
>,
|
|
111
|
-
]
|
|
112
|
-
: Sources extends readonly [
|
|
113
|
-
infer S1 extends KeySource,
|
|
114
|
-
infer S2 extends KeySource,
|
|
115
|
-
infer S3 extends KeySource,
|
|
116
|
-
]
|
|
117
|
-
? [
|
|
118
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
119
|
-
SourceResult<T, S1>,
|
|
120
|
-
SourceResult<T, S2>,
|
|
121
|
-
SourceResult<T, S3>,
|
|
122
|
-
Omit<
|
|
123
|
-
T,
|
|
124
|
-
| keyof V
|
|
125
|
-
| ComponentResultKeys
|
|
126
|
-
| SourceKeys<S1>
|
|
127
|
-
| SourceKeys<S2>
|
|
128
|
-
| SourceKeys<S3>
|
|
129
|
-
>,
|
|
130
|
-
]
|
|
131
|
-
: Sources extends readonly [
|
|
132
|
-
infer S1 extends KeySource,
|
|
133
|
-
infer S2 extends KeySource,
|
|
134
|
-
infer S3 extends KeySource,
|
|
135
|
-
infer S4 extends KeySource,
|
|
136
|
-
]
|
|
137
|
-
? [
|
|
138
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
139
|
-
SourceResult<T, S1>,
|
|
140
|
-
SourceResult<T, S2>,
|
|
141
|
-
SourceResult<T, S3>,
|
|
142
|
-
SourceResult<T, S4>,
|
|
143
|
-
Omit<
|
|
144
|
-
T,
|
|
145
|
-
| keyof V
|
|
146
|
-
| ComponentResultKeys
|
|
147
|
-
| SourceKeys<S1>
|
|
148
|
-
| SourceKeys<S2>
|
|
149
|
-
| SourceKeys<S3>
|
|
150
|
-
| SourceKeys<S4>
|
|
151
|
-
>,
|
|
152
|
-
]
|
|
153
|
-
: Sources extends readonly [
|
|
154
|
-
infer S1 extends KeySource,
|
|
155
|
-
infer S2 extends KeySource,
|
|
156
|
-
infer S3 extends KeySource,
|
|
157
|
-
infer S4 extends KeySource,
|
|
158
|
-
infer S5 extends KeySource,
|
|
159
|
-
]
|
|
160
|
-
? [
|
|
161
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
162
|
-
SourceResult<T, S1>,
|
|
163
|
-
SourceResult<T, S2>,
|
|
164
|
-
SourceResult<T, S3>,
|
|
165
|
-
SourceResult<T, S4>,
|
|
166
|
-
SourceResult<T, S5>,
|
|
167
|
-
Omit<
|
|
168
|
-
T,
|
|
169
|
-
| keyof V
|
|
170
|
-
| ComponentResultKeys
|
|
171
|
-
| SourceKeys<S1>
|
|
172
|
-
| SourceKeys<S2>
|
|
173
|
-
| SourceKeys<S3>
|
|
174
|
-
| SourceKeys<S4>
|
|
175
|
-
| SourceKeys<S5>
|
|
176
|
-
>,
|
|
177
|
-
]
|
|
178
|
-
: Sources extends readonly [
|
|
179
|
-
infer S1 extends KeySource,
|
|
180
|
-
infer S2 extends KeySource,
|
|
181
|
-
infer S3 extends KeySource,
|
|
182
|
-
infer S4 extends KeySource,
|
|
183
|
-
infer S5 extends KeySource,
|
|
184
|
-
infer S6 extends KeySource,
|
|
185
|
-
]
|
|
186
|
-
? [
|
|
187
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
188
|
-
SourceResult<T, S1>,
|
|
189
|
-
SourceResult<T, S2>,
|
|
190
|
-
SourceResult<T, S3>,
|
|
191
|
-
SourceResult<T, S4>,
|
|
192
|
-
SourceResult<T, S5>,
|
|
193
|
-
SourceResult<T, S6>,
|
|
194
|
-
Omit<
|
|
195
|
-
T,
|
|
196
|
-
| keyof V
|
|
197
|
-
| ComponentResultKeys
|
|
198
|
-
| SourceKeys<S1>
|
|
199
|
-
| SourceKeys<S2>
|
|
200
|
-
| SourceKeys<S3>
|
|
201
|
-
| SourceKeys<S4>
|
|
202
|
-
| SourceKeys<S5>
|
|
203
|
-
| SourceKeys<S6>
|
|
204
|
-
>,
|
|
205
|
-
]
|
|
206
|
-
: Sources extends readonly [
|
|
207
|
-
infer S1 extends KeySource,
|
|
208
|
-
infer S2 extends KeySource,
|
|
209
|
-
infer S3 extends KeySource,
|
|
210
|
-
infer S4 extends KeySource,
|
|
211
|
-
infer S5 extends KeySource,
|
|
212
|
-
infer S6 extends KeySource,
|
|
213
|
-
infer S7 extends KeySource,
|
|
214
|
-
]
|
|
215
|
-
? [
|
|
216
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
217
|
-
SourceResult<T, S1>,
|
|
218
|
-
SourceResult<T, S2>,
|
|
219
|
-
SourceResult<T, S3>,
|
|
220
|
-
SourceResult<T, S4>,
|
|
221
|
-
SourceResult<T, S5>,
|
|
222
|
-
SourceResult<T, S6>,
|
|
223
|
-
SourceResult<T, S7>,
|
|
224
|
-
Omit<
|
|
225
|
-
T,
|
|
226
|
-
| keyof V
|
|
227
|
-
| ComponentResultKeys
|
|
228
|
-
| SourceKeys<S1>
|
|
229
|
-
| SourceKeys<S2>
|
|
230
|
-
| SourceKeys<S3>
|
|
231
|
-
| SourceKeys<S4>
|
|
232
|
-
| SourceKeys<S5>
|
|
233
|
-
| SourceKeys<S6>
|
|
234
|
-
| SourceKeys<S7>
|
|
235
|
-
>,
|
|
236
|
-
]
|
|
237
|
-
: Sources extends readonly [
|
|
238
|
-
infer S1 extends KeySource,
|
|
239
|
-
infer S2 extends KeySource,
|
|
240
|
-
infer S3 extends KeySource,
|
|
241
|
-
infer S4 extends KeySource,
|
|
242
|
-
infer S5 extends KeySource,
|
|
243
|
-
infer S6 extends KeySource,
|
|
244
|
-
infer S7 extends KeySource,
|
|
245
|
-
infer S8 extends KeySource,
|
|
246
|
-
]
|
|
247
|
-
? [
|
|
248
|
-
SelfResult<T, keyof V | ComponentResultKeys, D>,
|
|
249
|
-
SourceResult<T, S1>,
|
|
250
|
-
SourceResult<T, S2>,
|
|
251
|
-
SourceResult<T, S3>,
|
|
252
|
-
SourceResult<T, S4>,
|
|
253
|
-
SourceResult<T, S5>,
|
|
254
|
-
SourceResult<T, S6>,
|
|
255
|
-
SourceResult<T, S7>,
|
|
256
|
-
SourceResult<T, S8>,
|
|
257
|
-
Omit<
|
|
258
|
-
T,
|
|
259
|
-
| keyof V
|
|
260
|
-
| ComponentResultKeys
|
|
261
|
-
| SourceKeys<S1>
|
|
262
|
-
| SourceKeys<S2>
|
|
263
|
-
| SourceKeys<S3>
|
|
264
|
-
| SourceKeys<S4>
|
|
265
|
-
| SourceKeys<S5>
|
|
266
|
-
| SourceKeys<S6>
|
|
267
|
-
| SourceKeys<S7>
|
|
268
|
-
| SourceKeys<S8>
|
|
269
|
-
>,
|
|
270
|
-
]
|
|
271
|
-
: unknown[];
|
|
272
|
-
|
|
273
|
-
// SplitProps as a single generic function type
|
|
274
|
-
export type SplitProps<V, D, _R extends ComponentResult> = <
|
|
72
|
+
// Standalone splitProps function type - first source is required
|
|
73
|
+
export type SplitPropsFunction = <
|
|
275
74
|
const T extends Record<string, unknown>,
|
|
75
|
+
const S1 extends KeySource,
|
|
276
76
|
const Sources extends readonly KeySource[],
|
|
277
77
|
>(
|
|
278
78
|
props: T,
|
|
79
|
+
source1: S1,
|
|
279
80
|
...sources: Sources
|
|
280
|
-
) =>
|
|
81
|
+
) => SplitPropsFunctionResult<T, S1, Sources>;
|
|
281
82
|
|
|
282
|
-
//
|
|
283
|
-
type
|
|
83
|
+
// Result type for standalone splitProps function
|
|
84
|
+
type SplitPropsFunctionResult<
|
|
284
85
|
T,
|
|
285
|
-
|
|
286
|
-
D,
|
|
86
|
+
S1 extends KeySource,
|
|
287
87
|
Sources extends readonly KeySource[],
|
|
288
88
|
> = Sources extends readonly []
|
|
289
|
-
? [
|
|
290
|
-
: Sources extends readonly [infer
|
|
89
|
+
? [SourceResult<T, S1>, Omit<T, SourceKeys<S1>>]
|
|
90
|
+
: Sources extends readonly [infer S2 extends KeySource]
|
|
291
91
|
? [
|
|
292
|
-
SelfResult<T, keyof V, D>,
|
|
293
92
|
SourceResult<T, S1>,
|
|
294
|
-
|
|
93
|
+
SourceResult<T, S2>,
|
|
94
|
+
Omit<T, SourceKeys<S1> | SourceKeys<S2>>,
|
|
295
95
|
]
|
|
296
96
|
: Sources extends readonly [
|
|
297
|
-
infer S1 extends KeySource,
|
|
298
97
|
infer S2 extends KeySource,
|
|
98
|
+
infer S3 extends KeySource,
|
|
299
99
|
]
|
|
300
100
|
? [
|
|
301
|
-
SelfResult<T, keyof V, D>,
|
|
302
101
|
SourceResult<T, S1>,
|
|
303
102
|
SourceResult<T, S2>,
|
|
304
|
-
|
|
103
|
+
SourceResult<T, S3>,
|
|
104
|
+
Omit<T, SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3>>,
|
|
305
105
|
]
|
|
306
106
|
: Sources extends readonly [
|
|
307
|
-
infer S1 extends KeySource,
|
|
308
107
|
infer S2 extends KeySource,
|
|
309
108
|
infer S3 extends KeySource,
|
|
109
|
+
infer S4 extends KeySource,
|
|
310
110
|
]
|
|
311
111
|
? [
|
|
312
|
-
SelfResult<T, keyof V, D>,
|
|
313
112
|
SourceResult<T, S1>,
|
|
314
113
|
SourceResult<T, S2>,
|
|
315
114
|
SourceResult<T, S3>,
|
|
316
|
-
|
|
115
|
+
SourceResult<T, S4>,
|
|
116
|
+
Omit<
|
|
117
|
+
T,
|
|
118
|
+
SourceKeys<S1> | SourceKeys<S2> | SourceKeys<S3> | SourceKeys<S4>
|
|
119
|
+
>,
|
|
317
120
|
]
|
|
318
121
|
: Sources extends readonly [
|
|
319
|
-
infer S1 extends KeySource,
|
|
320
122
|
infer S2 extends KeySource,
|
|
321
123
|
infer S3 extends KeySource,
|
|
322
124
|
infer S4 extends KeySource,
|
|
125
|
+
infer S5 extends KeySource,
|
|
323
126
|
]
|
|
324
127
|
? [
|
|
325
|
-
SelfResult<T, keyof V, D>,
|
|
326
128
|
SourceResult<T, S1>,
|
|
327
129
|
SourceResult<T, S2>,
|
|
328
130
|
SourceResult<T, S3>,
|
|
329
131
|
SourceResult<T, S4>,
|
|
132
|
+
SourceResult<T, S5>,
|
|
330
133
|
Omit<
|
|
331
134
|
T,
|
|
332
|
-
| keyof V
|
|
333
135
|
| SourceKeys<S1>
|
|
334
136
|
| SourceKeys<S2>
|
|
335
137
|
| SourceKeys<S3>
|
|
336
138
|
| SourceKeys<S4>
|
|
139
|
+
| SourceKeys<S5>
|
|
337
140
|
>,
|
|
338
141
|
]
|
|
339
142
|
: Sources extends readonly [
|
|
340
|
-
infer S1 extends KeySource,
|
|
341
143
|
infer S2 extends KeySource,
|
|
342
144
|
infer S3 extends KeySource,
|
|
343
145
|
infer S4 extends KeySource,
|
|
344
146
|
infer S5 extends KeySource,
|
|
147
|
+
infer S6 extends KeySource,
|
|
345
148
|
]
|
|
346
149
|
? [
|
|
347
|
-
SelfResult<T, keyof V, D>,
|
|
348
150
|
SourceResult<T, S1>,
|
|
349
151
|
SourceResult<T, S2>,
|
|
350
152
|
SourceResult<T, S3>,
|
|
351
153
|
SourceResult<T, S4>,
|
|
352
154
|
SourceResult<T, S5>,
|
|
155
|
+
SourceResult<T, S6>,
|
|
353
156
|
Omit<
|
|
354
157
|
T,
|
|
355
|
-
| keyof V
|
|
356
158
|
| SourceKeys<S1>
|
|
357
159
|
| SourceKeys<S2>
|
|
358
160
|
| SourceKeys<S3>
|
|
359
161
|
| SourceKeys<S4>
|
|
360
162
|
| SourceKeys<S5>
|
|
163
|
+
| SourceKeys<S6>
|
|
361
164
|
>,
|
|
362
165
|
]
|
|
363
166
|
: Sources extends readonly [
|
|
364
|
-
infer S1 extends KeySource,
|
|
365
167
|
infer S2 extends KeySource,
|
|
366
168
|
infer S3 extends KeySource,
|
|
367
169
|
infer S4 extends KeySource,
|
|
368
170
|
infer S5 extends KeySource,
|
|
369
171
|
infer S6 extends KeySource,
|
|
172
|
+
infer S7 extends KeySource,
|
|
370
173
|
]
|
|
371
174
|
? [
|
|
372
|
-
SelfResult<T, keyof V, D>,
|
|
373
175
|
SourceResult<T, S1>,
|
|
374
176
|
SourceResult<T, S2>,
|
|
375
177
|
SourceResult<T, S3>,
|
|
376
178
|
SourceResult<T, S4>,
|
|
377
179
|
SourceResult<T, S5>,
|
|
378
180
|
SourceResult<T, S6>,
|
|
181
|
+
SourceResult<T, S7>,
|
|
379
182
|
Omit<
|
|
380
183
|
T,
|
|
381
|
-
| keyof V
|
|
382
184
|
| SourceKeys<S1>
|
|
383
185
|
| SourceKeys<S2>
|
|
384
186
|
| SourceKeys<S3>
|
|
385
187
|
| SourceKeys<S4>
|
|
386
188
|
| SourceKeys<S5>
|
|
387
189
|
| SourceKeys<S6>
|
|
190
|
+
| SourceKeys<S7>
|
|
388
191
|
>,
|
|
389
192
|
]
|
|
390
193
|
: Sources extends readonly [
|
|
391
|
-
infer S1 extends KeySource,
|
|
392
194
|
infer S2 extends KeySource,
|
|
393
195
|
infer S3 extends KeySource,
|
|
394
196
|
infer S4 extends KeySource,
|
|
395
197
|
infer S5 extends KeySource,
|
|
396
198
|
infer S6 extends KeySource,
|
|
397
199
|
infer S7 extends KeySource,
|
|
200
|
+
infer S8 extends KeySource,
|
|
398
201
|
]
|
|
399
202
|
? [
|
|
400
|
-
SelfResult<T, keyof V, D>,
|
|
401
203
|
SourceResult<T, S1>,
|
|
402
204
|
SourceResult<T, S2>,
|
|
403
205
|
SourceResult<T, S3>,
|
|
@@ -405,9 +207,9 @@ type OnlyVariantsSplitPropsResult<
|
|
|
405
207
|
SourceResult<T, S5>,
|
|
406
208
|
SourceResult<T, S6>,
|
|
407
209
|
SourceResult<T, S7>,
|
|
210
|
+
SourceResult<T, S8>,
|
|
408
211
|
Omit<
|
|
409
212
|
T,
|
|
410
|
-
| keyof V
|
|
411
213
|
| SourceKeys<S1>
|
|
412
214
|
| SourceKeys<S2>
|
|
413
215
|
| SourceKeys<S3>
|
|
@@ -415,66 +217,23 @@ type OnlyVariantsSplitPropsResult<
|
|
|
415
217
|
| SourceKeys<S5>
|
|
416
218
|
| SourceKeys<S6>
|
|
417
219
|
| SourceKeys<S7>
|
|
220
|
+
| SourceKeys<S8>
|
|
418
221
|
>,
|
|
419
222
|
]
|
|
420
|
-
:
|
|
421
|
-
infer S1 extends KeySource,
|
|
422
|
-
infer S2 extends KeySource,
|
|
423
|
-
infer S3 extends KeySource,
|
|
424
|
-
infer S4 extends KeySource,
|
|
425
|
-
infer S5 extends KeySource,
|
|
426
|
-
infer S6 extends KeySource,
|
|
427
|
-
infer S7 extends KeySource,
|
|
428
|
-
infer S8 extends KeySource,
|
|
429
|
-
]
|
|
430
|
-
? [
|
|
431
|
-
SelfResult<T, keyof V, D>,
|
|
432
|
-
SourceResult<T, S1>,
|
|
433
|
-
SourceResult<T, S2>,
|
|
434
|
-
SourceResult<T, S3>,
|
|
435
|
-
SourceResult<T, S4>,
|
|
436
|
-
SourceResult<T, S5>,
|
|
437
|
-
SourceResult<T, S6>,
|
|
438
|
-
SourceResult<T, S7>,
|
|
439
|
-
SourceResult<T, S8>,
|
|
440
|
-
Omit<
|
|
441
|
-
T,
|
|
442
|
-
| keyof V
|
|
443
|
-
| SourceKeys<S1>
|
|
444
|
-
| SourceKeys<S2>
|
|
445
|
-
| SourceKeys<S3>
|
|
446
|
-
| SourceKeys<S4>
|
|
447
|
-
| SourceKeys<S5>
|
|
448
|
-
| SourceKeys<S6>
|
|
449
|
-
| SourceKeys<S7>
|
|
450
|
-
| SourceKeys<S8>
|
|
451
|
-
>,
|
|
452
|
-
]
|
|
453
|
-
: unknown[];
|
|
454
|
-
|
|
455
|
-
// OnlyVariantsSplitProps as a single generic function type
|
|
456
|
-
export type OnlyVariantsSplitProps<V, D> = <
|
|
457
|
-
const T extends Record<string, unknown>,
|
|
458
|
-
const Sources extends readonly KeySource[],
|
|
459
|
-
>(
|
|
460
|
-
props: T,
|
|
461
|
-
...sources: Sources
|
|
462
|
-
) => OnlyVariantsSplitPropsResult<T, V, D, Sources>;
|
|
223
|
+
: unknown[];
|
|
463
224
|
|
|
464
|
-
export interface OnlyVariantsComponent<V
|
|
465
|
-
splitProps: OnlyVariantsSplitProps<V, D>;
|
|
225
|
+
export interface OnlyVariantsComponent<V> {
|
|
466
226
|
getVariants: GetVariants<V>;
|
|
467
227
|
keys: (keyof V)[];
|
|
468
228
|
}
|
|
469
229
|
|
|
470
|
-
export interface ModalComponent<V,
|
|
230
|
+
export interface ModalComponent<V, R extends ComponentResult> {
|
|
471
231
|
(props?: ComponentProps<V>): R;
|
|
472
232
|
class: (props?: ComponentProps<V>) => string;
|
|
473
233
|
style: (props?: ComponentProps<V>) => R["style"];
|
|
474
|
-
splitProps: SplitProps<V, D, R>;
|
|
475
234
|
getVariants: GetVariants<V>;
|
|
476
235
|
keys: (keyof V | keyof R)[];
|
|
477
|
-
onlyVariants: OnlyVariantsComponent<V
|
|
236
|
+
onlyVariants: OnlyVariantsComponent<V>;
|
|
478
237
|
/** @internal Base class without variants */
|
|
479
238
|
_baseClass: string;
|
|
480
239
|
}
|
|
@@ -484,16 +243,15 @@ export interface Component<
|
|
|
484
243
|
CV extends ComputedVariants = {},
|
|
485
244
|
E extends AnyComponent[] = [],
|
|
486
245
|
R extends ComponentResult = ComponentResult,
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
htmlObj: ModalComponent<MergeVariants<V, CV, E>, D, HTMLObjProps>;
|
|
246
|
+
> extends ModalComponent<MergeVariants<V, CV, E>, R> {
|
|
247
|
+
jsx: ModalComponent<MergeVariants<V, CV, E>, JSXProps>;
|
|
248
|
+
html: ModalComponent<MergeVariants<V, CV, E>, HTMLProps>;
|
|
249
|
+
htmlObj: ModalComponent<MergeVariants<V, CV, E>, HTMLObjProps>;
|
|
492
250
|
}
|
|
493
251
|
|
|
494
252
|
export type AnyComponent =
|
|
495
|
-
| Component<any, any, any, any
|
|
496
|
-
| ModalComponent<any, any
|
|
253
|
+
| Component<any, any, any, any>
|
|
254
|
+
| ModalComponent<any, any>;
|
|
497
255
|
|
|
498
256
|
type MergeExtendedVariants<T> = T extends readonly [infer First, ...infer Rest]
|
|
499
257
|
? ExtractVariants<First> & MergeExtendedVariants<Rest>
|