clava 0.1.13 → 0.1.15
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 +12 -0
- package/dist/index.d.ts +34 -32
- package/dist/index.js +25 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +15 -5
- package/src/test.ts +235 -0
- package/src/types.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# clava
|
|
2
2
|
|
|
3
|
+
## 0.1.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c15884d: Added `addClass` and `addStyle` methods to the `computed` parameters.
|
|
8
|
+
|
|
9
|
+
## 0.1.14
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fee9f84: Fixed `computed` method not receiving default variants set by an intermediate component.
|
|
14
|
+
|
|
3
15
|
## 0.1.13
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -20198,10 +20198,10 @@ interface StyleProps {
|
|
|
20198
20198
|
}
|
|
20199
20199
|
type ComponentResult = JSXProps | HTMLProps | HTMLObjProps;
|
|
20200
20200
|
type AllComponentResultKeys = keyof JSXProps | keyof HTMLProps | keyof HTMLObjProps;
|
|
20201
|
-
type ComponentResultValue<K
|
|
20201
|
+
type ComponentResultValue<K extends AllComponentResultKeys> = K extends "style" ? StyleProperty : K extends "className" ? string : K extends "class" ? string : never;
|
|
20202
20202
|
type NullableComponentResult = { [K in AllComponentResultKeys]?: ComponentResultValue<K> | null };
|
|
20203
|
-
type ComponentProps<V
|
|
20204
|
-
type GetVariants<V
|
|
20203
|
+
type ComponentProps<V = {}> = VariantValues<V> & NullableComponentResult;
|
|
20204
|
+
type GetVariants<V> = (variants?: VariantValues<V>) => VariantValues<V>;
|
|
20205
20205
|
type KeySourceArray = readonly string[];
|
|
20206
20206
|
type KeySourceComponent = {
|
|
20207
20207
|
keys: readonly (string | number | symbol)[];
|
|
@@ -20226,48 +20226,50 @@ type SourceResultWithoutStyling<T, S> = IsComponent<S> extends true ? Pick<T, Ex
|
|
|
20226
20226
|
type BuildSourceResults<T, Sources extends readonly KeySource[], StylingClaimed extends boolean, UsedKeys> = Sources extends readonly [infer Current extends KeySource, ...infer Rest extends readonly KeySource[]] ? [StylingClaimed extends true ? SourceResultWithoutStyling<T, Current> : SourceResultWithStyling<T, Current>, ...BuildSourceResults<T, Rest, StylingClaimed extends true ? true : IsComponent<Current>, UsedKeys | SourceKeys<Current>>] : [Omit<T, UsedKeys & (string | number | symbol)>];
|
|
20227
20227
|
type SplitPropsFunction = <T, const S1 extends KeySource, const Sources extends readonly KeySource[]>(props: T, source1: S1, ...sources: Sources) => SplitPropsFunctionResult<T, S1, Sources>;
|
|
20228
20228
|
type SplitPropsFunctionResult<T, S1 extends KeySource, Sources extends readonly KeySource[]> = [SourceResultWithStyling<T, S1>, ...BuildSourceResults<T, Sources, IsComponent<S1>, SourceKeys<S1>>];
|
|
20229
|
-
interface ModalComponent<V
|
|
20230
|
-
(props?: ComponentProps<V
|
|
20231
|
-
class: (props?: ComponentProps<V
|
|
20232
|
-
style: (props?: ComponentProps<V
|
|
20233
|
-
getVariants: GetVariants<V
|
|
20234
|
-
keys: (keyof V
|
|
20235
|
-
variantKeys: (keyof V
|
|
20236
|
-
propKeys: (keyof V
|
|
20229
|
+
interface ModalComponent<V, R extends ComponentResult> {
|
|
20230
|
+
(props?: ComponentProps<V>): R;
|
|
20231
|
+
class: (props?: ComponentProps<V>) => string;
|
|
20232
|
+
style: (props?: ComponentProps<V>) => R["style"];
|
|
20233
|
+
getVariants: GetVariants<V>;
|
|
20234
|
+
keys: (keyof V | keyof R)[];
|
|
20235
|
+
variantKeys: (keyof V)[];
|
|
20236
|
+
propKeys: (keyof V | keyof R)[];
|
|
20237
20237
|
}
|
|
20238
|
-
interface CVComponent<V
|
|
20239
|
-
jsx: ModalComponent<MergeVariants<V
|
|
20240
|
-
html: ModalComponent<MergeVariants<V
|
|
20241
|
-
htmlObj: ModalComponent<MergeVariants<V
|
|
20238
|
+
interface CVComponent<V extends Variants = {}, CV extends ComputedVariants = {}, E extends AnyComponent[] = [], R extends ComponentResult = ComponentResult> extends ModalComponent<MergeVariants<V, CV, E>, R> {
|
|
20239
|
+
jsx: ModalComponent<MergeVariants<V, CV, E>, JSXProps>;
|
|
20240
|
+
html: ModalComponent<MergeVariants<V, CV, E>, HTMLProps>;
|
|
20241
|
+
htmlObj: ModalComponent<MergeVariants<V, CV, E>, HTMLObjProps>;
|
|
20242
20242
|
}
|
|
20243
20243
|
type AnyComponent = CVComponent<any, any, any, any> | ModalComponent<any, any>;
|
|
20244
20244
|
type MergeExtendedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractVariants<First> & MergeExtendedVariants<Rest> : {};
|
|
20245
20245
|
type MergeExtendedComputedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractComputedVariants<First> & MergeExtendedComputedVariants<Rest> : {};
|
|
20246
20246
|
type ExtractVariants<T> = T extends CVComponent<infer V, any, infer E, any> ? V & MergeExtendedVariants<E> : {};
|
|
20247
20247
|
type ExtractComputedVariants<T> = T extends CVComponent<any, infer CV, infer E, any> ? CV & Omit<MergeExtendedComputedVariants<E>, keyof CV> : {};
|
|
20248
|
-
type MergeVariants<V
|
|
20248
|
+
type MergeVariants<V, CV, E extends AnyComponent[]> = NoInfer<CV> & Omit<NoInfer<V>, keyof CV> & Omit<MergeExtendedVariants<E>, keyof CV> & Omit<MergeExtendedComputedVariants<E>, keyof CV>;
|
|
20249
20249
|
type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
20250
20250
|
type VariantValue = ClassValue | StyleClassValue;
|
|
20251
20251
|
type ExtractVariantValue<T> = T extends ((value: infer V) => any) ? V : T extends ClassValue ? boolean : T extends Record<infer K, any> ? StringToBoolean<K> : never;
|
|
20252
|
-
type VariantValues<V
|
|
20252
|
+
type VariantValues<V> = { [K in keyof V]?: ExtractVariantValue<V[K]> };
|
|
20253
20253
|
type StyleValue = Properties & {
|
|
20254
20254
|
[key: `--${string}`]: string;
|
|
20255
20255
|
};
|
|
20256
20256
|
type StyleClassValue = StyleValue & {
|
|
20257
20257
|
class?: ClassValue;
|
|
20258
20258
|
};
|
|
20259
|
-
interface ComputedContext<V
|
|
20260
|
-
variants: VariantValues<V
|
|
20261
|
-
setVariants: (variants: VariantValues<V
|
|
20262
|
-
setDefaultVariants: (variants: VariantValues<V
|
|
20259
|
+
interface ComputedContext<V> {
|
|
20260
|
+
variants: VariantValues<V>;
|
|
20261
|
+
setVariants: (variants: VariantValues<V>) => void;
|
|
20262
|
+
setDefaultVariants: (variants: VariantValues<V>) => void;
|
|
20263
|
+
addClass: (className: ClassValue) => void;
|
|
20264
|
+
addStyle: (style: StyleValue) => void;
|
|
20263
20265
|
}
|
|
20264
|
-
type Computed<V
|
|
20266
|
+
type Computed<V> = (context: ComputedContext<V>) => VariantValue;
|
|
20265
20267
|
type ComputedVariant = (value: any) => VariantValue;
|
|
20266
20268
|
type ComputedVariants = Record<string, ComputedVariant>;
|
|
20267
20269
|
type Variant = ClassValue | Record<string, VariantValue>;
|
|
20268
20270
|
type Variants = Record<string, Variant>;
|
|
20269
|
-
type ExtendedVariants<E
|
|
20270
|
-
type ExtendableVariants<V
|
|
20271
|
+
type ExtendedVariants<E extends AnyComponent[]> = MergeExtendedVariants<E> & MergeExtendedComputedVariants<E>;
|
|
20272
|
+
type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K in keyof ExtendedVariants<E>]?: Partial<ExtendedVariants<E>[K]> | Variant };
|
|
20271
20273
|
//#endregion
|
|
20272
20274
|
//#region src/utils.d.ts
|
|
20273
20275
|
declare const MODES: readonly ["jsx", "html", "htmlObj"];
|
|
@@ -20275,14 +20277,14 @@ type Mode = (typeof MODES)[number];
|
|
|
20275
20277
|
//#endregion
|
|
20276
20278
|
//#region src/index.d.ts
|
|
20277
20279
|
type VariantProps<T extends Pick<AnyComponent, "getVariants">> = ReturnType<T["getVariants"]>;
|
|
20278
|
-
interface CVConfig<V
|
|
20279
|
-
extend?: E
|
|
20280
|
+
interface CVConfig<V extends Variants = {}, CV extends ComputedVariants = {}, E extends AnyComponent[] = []> {
|
|
20281
|
+
extend?: E;
|
|
20280
20282
|
class?: ClassValue;
|
|
20281
20283
|
style?: StyleValue;
|
|
20282
|
-
variants?: ExtendableVariants<V
|
|
20283
|
-
computedVariants?: CV
|
|
20284
|
-
defaultVariants?: VariantValues<MergeVariants<V
|
|
20285
|
-
computed?: Computed<MergeVariants<V
|
|
20284
|
+
variants?: ExtendableVariants<V, E>;
|
|
20285
|
+
computedVariants?: CV;
|
|
20286
|
+
defaultVariants?: VariantValues<MergeVariants<V, CV, E>>;
|
|
20287
|
+
computed?: Computed<MergeVariants<V, CV, E>>;
|
|
20286
20288
|
}
|
|
20287
20289
|
interface CreateParams<M extends Mode> {
|
|
20288
20290
|
defaultMode?: M;
|
|
@@ -20314,10 +20316,10 @@ declare function create<M extends Mode = "jsx">({
|
|
|
20314
20316
|
defaultMode,
|
|
20315
20317
|
transformClass
|
|
20316
20318
|
}?: CreateParams<M>): {
|
|
20317
|
-
cv: <V
|
|
20319
|
+
cv: <V extends Variants = {}, CV extends ComputedVariants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, CV, E>) => CVComponent<V, CV, E, StyleProps[M]>;
|
|
20318
20320
|
cx: (...classes: ClassValue$1[]) => string;
|
|
20319
20321
|
};
|
|
20320
|
-
declare const cv: <V
|
|
20322
|
+
declare const cv: <V extends Variants = {}, CV extends ComputedVariants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, CV, E>) => CVComponent<V, CV, E, JSXProps>, cx: (...classes: ClassValue$1[]) => string;
|
|
20321
20323
|
//#endregion
|
|
20322
20324
|
export { type CVComponent, CVConfig, type ClassValue, type HTMLObjProps, type HTMLProps, type JSXProps, type StyleClassValue, type StyleValue, VariantProps, create, cv, cx, splitProps };
|
|
20323
20325
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -254,11 +254,10 @@ function collectStaticDefaults(config) {
|
|
|
254
254
|
function collectDefaultVariants(config, propsVariants = {}) {
|
|
255
255
|
const defaults = collectStaticDefaults(config);
|
|
256
256
|
if (!config.extend) return defaults;
|
|
257
|
-
const childStaticDefaults = config.defaultVariants || {};
|
|
258
257
|
for (const ext of config.extend) {
|
|
259
258
|
const meta = getComponentMeta(ext);
|
|
260
259
|
if (!meta) continue;
|
|
261
|
-
Object.assign(defaults, meta.resolveDefaults(
|
|
260
|
+
Object.assign(defaults, meta.resolveDefaults(defaults, propsVariants));
|
|
262
261
|
}
|
|
263
262
|
return defaults;
|
|
264
263
|
}
|
|
@@ -387,6 +386,12 @@ function runComputedFunction(config, resolvedVariants, propsVariants) {
|
|
|
387
386
|
},
|
|
388
387
|
setDefaultVariants: (newDefaults) => {
|
|
389
388
|
for (const [key, value] of Object.entries(newDefaults)) if (propsVariants[key] === void 0) updatedVariants[key] = value;
|
|
389
|
+
},
|
|
390
|
+
addClass: (className) => {
|
|
391
|
+
classes.push(className);
|
|
392
|
+
},
|
|
393
|
+
addStyle: (newStyle) => {
|
|
394
|
+
assign(style, newStyle);
|
|
390
395
|
}
|
|
391
396
|
};
|
|
392
397
|
const computedResult = config.computed(context);
|
|
@@ -504,7 +509,9 @@ function createResolveDefaults(config) {
|
|
|
504
509
|
setVariants: () => {},
|
|
505
510
|
setDefaultVariants: (newDefaults) => {
|
|
506
511
|
for (const [key, value] of Object.entries(newDefaults)) if (userProps[key] === void 0) computedDefaults[key] = value;
|
|
507
|
-
}
|
|
512
|
+
},
|
|
513
|
+
addClass: () => {},
|
|
514
|
+
addStyle: () => {}
|
|
508
515
|
});
|
|
509
516
|
return computedDefaults;
|
|
510
517
|
};
|
|
@@ -513,8 +520,8 @@ function createResolveDefaults(config) {
|
|
|
513
520
|
* Creates the cv and cx functions.
|
|
514
521
|
*/
|
|
515
522
|
function create({ defaultMode = "jsx", transformClass = (className) => className } = {}) {
|
|
516
|
-
const cx
|
|
517
|
-
const cv
|
|
523
|
+
const cx = (...classes) => transformClass(clsx_default(...classes));
|
|
524
|
+
const cv = (config = {}) => {
|
|
518
525
|
const variantKeys = collectVariantKeys(config);
|
|
519
526
|
const getPropsKeys = (mode) => [
|
|
520
527
|
getClassPropertyName(mode),
|
|
@@ -547,13 +554,13 @@ function create({ defaultMode = "jsx", transformClass = (className) => className
|
|
|
547
554
|
if ("className" in props) allClasses.push(props.className);
|
|
548
555
|
if (props.style != null) assign(allStyle, normalizeStyle(props.style));
|
|
549
556
|
return {
|
|
550
|
-
className: cx
|
|
557
|
+
className: cx(...allClasses),
|
|
551
558
|
style: allStyle
|
|
552
559
|
};
|
|
553
560
|
};
|
|
554
561
|
const createModalComponent = (mode) => {
|
|
555
562
|
const propsKeys = getPropsKeys(mode);
|
|
556
|
-
const component
|
|
563
|
+
const component = ((props = {}) => {
|
|
557
564
|
const { className, style } = computeResult(props);
|
|
558
565
|
if (mode === "jsx") return {
|
|
559
566
|
className,
|
|
@@ -568,32 +575,32 @@ function create({ defaultMode = "jsx", transformClass = (className) => className
|
|
|
568
575
|
style: styleValueToHTMLObjStyle(style)
|
|
569
576
|
};
|
|
570
577
|
});
|
|
571
|
-
component
|
|
578
|
+
component.class = (props = {}) => {
|
|
572
579
|
return computeResult(props).className;
|
|
573
580
|
};
|
|
574
|
-
component
|
|
581
|
+
component.style = ((props = {}) => {
|
|
575
582
|
const { style } = computeResult(props);
|
|
576
583
|
if (mode === "jsx") return styleValueToJSXStyle(style);
|
|
577
584
|
if (mode === "html") return styleValueToHTMLStyle(style);
|
|
578
585
|
return styleValueToHTMLObjStyle(style);
|
|
579
586
|
});
|
|
580
|
-
component
|
|
587
|
+
component.getVariants = (variants) => {
|
|
581
588
|
return resolveVariants(config, variants);
|
|
582
589
|
};
|
|
583
|
-
component
|
|
584
|
-
component
|
|
585
|
-
component
|
|
590
|
+
component.keys = propsKeys;
|
|
591
|
+
component.variantKeys = variantKeys;
|
|
592
|
+
component.propKeys = propsKeys;
|
|
586
593
|
const extendedBaseClasses = [];
|
|
587
594
|
if (config.extend) for (const ext of config.extend) {
|
|
588
595
|
const meta = getComponentMeta(ext);
|
|
589
596
|
extendedBaseClasses.push(meta?.baseClass ?? "");
|
|
590
597
|
}
|
|
591
|
-
setComponentMeta(component
|
|
592
|
-
baseClass: cx
|
|
598
|
+
setComponentMeta(component, {
|
|
599
|
+
baseClass: cx(...extendedBaseClasses, config.class),
|
|
593
600
|
staticDefaults: collectStaticDefaults(config),
|
|
594
601
|
resolveDefaults: createResolveDefaults(config)
|
|
595
602
|
});
|
|
596
|
-
return component
|
|
603
|
+
return component;
|
|
597
604
|
};
|
|
598
605
|
const defaultComponent = createModalComponent(defaultMode);
|
|
599
606
|
const jsxComponent = createModalComponent("jsx");
|
|
@@ -606,8 +613,8 @@ function create({ defaultMode = "jsx", transformClass = (className) => className
|
|
|
606
613
|
return component;
|
|
607
614
|
};
|
|
608
615
|
return {
|
|
609
|
-
cv
|
|
610
|
-
cx
|
|
616
|
+
cv,
|
|
617
|
+
cx
|
|
611
618
|
};
|
|
612
619
|
}
|
|
613
620
|
const { cv, cx } = create();
|
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\";\nimport type {\n HTMLCSSProperties,\n JSXCSSProperties,\n StyleValue,\n} from \"./types.ts\";\n\nexport const MODES = [\"jsx\", \"html\", \"htmlObj\"] as const;\nexport type Mode = (typeof MODES)[number];\n\n/**\n * Returns the appropriate class property name based on the mode.\n * @example\n * getClassPropertyName(\"jsx\") // \"className\"\n * getClassPropertyName(\"html\") // \"class\"\n */\nexport function getClassPropertyName(mode: Mode) {\n return mode === \"jsx\" ? \"className\" : \"class\";\n}\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 // CSS property names and values are dynamic - cast required for index access\n (result as Record<string, string>)[hyphenToCamel(property)] = 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 // CSS property names and values are dynamic - cast required for index access\n (result as Record<string, string>)[hyphenToCamel(key)] =\n 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 // CSS property names and values are dynamic - cast required for index access\n (result as Record<string, string>)[key] = 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\";\nimport type {\n AnyComponent,\n CVComponent,\n ClassValue,\n ComponentProps,\n ComponentResult,\n Computed,\n ComputedVariants,\n ExtendableVariants,\n HTMLObjProps,\n HTMLProps,\n JSXProps,\n MergeVariants,\n ModalComponent,\n SplitPropsFunction,\n StyleClassValue,\n StyleProps,\n StyleValue,\n VariantValues,\n Variants,\n} from \"./types.ts\";\nimport {\n type Mode,\n getClassPropertyName,\n htmlObjStyleToStyleValue,\n htmlStyleToStyleValue,\n isHTMLObjStyle,\n jsxStyleToStyleValue,\n styleValueToHTMLObjStyle,\n styleValueToHTMLStyle,\n styleValueToJSXStyle,\n} from \"./utils.ts\";\n\n// Internal metadata stored on components but hidden from public types\ninterface ComponentMeta {\n baseClass: string;\n staticDefaults: Record<string, unknown>;\n resolveDefaults: (\n childDefaults: Record<string, unknown>,\n userProps?: Record<string, unknown>,\n ) => Record<string, unknown>;\n}\n\nconst META_KEY = \"__meta\";\n\n// Symbol property used to pass skip keys through the props object without\n// polluting the actual variant values. This allows the computed function to\n// see actual variant values while still skipping styling for overridden keys.\nconst SKIP_STYLE_KEYS = Symbol(\"skipStyleKeys\");\n\n// Dynamic property access on function requires cast through unknown\nfunction getComponentMeta(component: AnyComponent): ComponentMeta | undefined {\n return (component as unknown as Record<string, unknown>)[META_KEY] as\n | ComponentMeta\n | undefined;\n}\n\nfunction setComponentMeta(component: AnyComponent, meta: ComponentMeta): void {\n (component as unknown as Record<string, unknown>)[META_KEY] = meta;\n}\n\n/**\n * Mutates target by assigning all properties from source. Avoids object spread\n * overhead in hot paths where we're building up a result object.\n */\nfunction assign<T extends object>(target: T, source: T): void {\n for (const key of Object.keys(source)) {\n (target as Record<string, unknown>)[key] = (\n source as Record<string, unknown>\n )[key];\n }\n}\n\nexport type {\n ClassValue,\n StyleValue,\n StyleClassValue,\n JSXProps,\n HTMLProps,\n HTMLObjProps,\n CVComponent,\n};\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 normalized\n * 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 * Extracts class and style from a variant value (either a class value or a\n * style-class object).\n */\nfunction extractClassAndStyle(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.variantKeys) {\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 static default variants from extended components and the current\n * config. Also handles implicit boolean defaults (when only `false` key\n * exists). This does NOT trigger computed functions - use collectDefaultVariants\n * for that.\n */\nfunction collectStaticDefaults(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): Record<string, unknown> {\n const defaults: Record<string, unknown> = {};\n\n // Collect static defaults from extended components (via metadata to avoid\n // triggering computed functions)\n if (config.extend) {\n for (const ext of config.extend) {\n const meta = getComponentMeta(ext);\n if (meta) {\n Object.assign(defaults, meta.staticDefaults);\n }\n }\n }\n\n // Handle implicit boolean defaults from variants\n // If a variant has a `false` key, default to false when no value is provided\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n if (!isStyleClassValue(variantDef)) continue;\n const keys = Object.keys(variantDef);\n const hasFalse = keys.includes(\"false\");\n if (hasFalse && !defaults[variantName]) {\n defaults[variantName] = false;\n }\n }\n }\n\n // Override with current config's static defaults\n if (config.defaultVariants) {\n Object.assign(defaults, config.defaultVariants);\n }\n\n return defaults;\n}\n\n/**\n * Collects default variants from extended components and the current config.\n * This includes both static defaults and computed defaults (from\n * setDefaultVariants in extended components' computed functions). Priority:\n * parent static < child static < parent computed < child computed.\n */\nfunction collectDefaultVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n propsVariants: Record<string, unknown> = {},\n): Record<string, unknown> {\n // Start with static defaults (parent static < child static)\n const defaults = collectStaticDefaults(config);\n\n // Apply computed defaults from extended components\n // Parent's setDefaultVariants should override child's static defaults\n if (!config.extend) return defaults;\n\n const childStaticDefaults = config.defaultVariants || {};\n for (const ext of config.extend) {\n const meta = getComponentMeta(ext);\n if (!meta) continue;\n Object.assign(\n defaults,\n meta.resolveDefaults(childStaticDefaults, propsVariants),\n );\n }\n\n return defaults;\n}\n\n/**\n * Filters out keys with undefined values from an object.\n */\nfunction filterUndefined(\n obj: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n if (value === undefined) continue;\n result[key] = value;\n }\n return result;\n}\n\n/**\n * Resolves variant values by merging defaults with provided props. Props with\n * undefined values are filtered out so they don't override defaults.\n */\nfunction resolveVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n props: Record<string, unknown> = {},\n): Record<string, unknown> {\n const defaults = collectDefaultVariants(config, props);\n return { ...defaults, ...filterUndefined(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 extractClassAndStyle(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 extractClassAndStyle(value);\n}\n\n/**\n * Extracts classes from fullClass that are not in baseClass. Uses string\n * comparison optimization: if fullClass starts with baseClass, just take the\n * suffix.\n */\nfunction extractVariantClasses(fullClass: string, baseClass: string): string {\n if (!fullClass) return \"\";\n if (!baseClass) return fullClass;\n\n // Fast path: fullClass starts with baseClass (common case)\n if (fullClass.startsWith(baseClass)) {\n return fullClass.slice(baseClass.length).trim();\n }\n\n // Slow path: need to diff the class sets\n const baseClassSet = new Set(baseClass.split(\" \").filter(Boolean));\n return fullClass\n .split(\" \")\n .filter((c) => c && !baseClassSet.has(c))\n .join(\" \");\n}\n\nfunction computeExtendedStyles(\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 const style: StyleValue = {};\n\n if (!config.extend) return { baseClasses, variantClasses, style };\n\n for (const ext of config.extend) {\n // Pass actual variant values but mark which keys should skip styling.\n // Using a Symbol property keeps variant values clean for computed functions\n // while still allowing us to skip styling for overridden keys.\n const propsForExt: Record<string | symbol, unknown> = {\n ...resolvedVariants,\n };\n if (overrideVariantKeys.size > 0) {\n propsForExt[SKIP_STYLE_KEYS] = overrideVariantKeys;\n }\n\n const extResult = ext(propsForExt);\n assign(style, normalizeStyle(extResult.style));\n\n // Get base class from internal metadata (no variants)\n const meta = getComponentMeta(ext);\n const baseClass = meta?.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 const variantPortion = extractVariantClasses(fullClass, baseClass);\n if (variantPortion) {\n variantClasses.push(variantPortion);\n }\n }\n\n return { baseClasses, variantClasses, style };\n}\n\n/**\n * Computes class and style from the component's own variants and\n * computedVariants (not extended components).\n */\nfunction computeVariantStyles(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string | symbol, unknown>,\n skipStyleKeys: Set<string> = new Set(),\n): { classes: ClassValue[]; style: StyleValue } {\n const classes: ClassValue[] = [];\n const style: StyleValue = {};\n\n // Process current component's variants\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n // Skip styling for variants that are overridden by child's computedVariants\n if (skipStyleKeys.has(variantName)) continue;\n\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const result = getVariantResult(variantDef, selectedValue);\n classes.push(result.class);\n assign(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 // Skip styling for variants that are overridden by child's computedVariants\n if (skipStyleKeys.has(variantName)) continue;\n\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const computedResult = computeFn(selectedValue);\n const result = extractClassAndStyle(computedResult);\n classes.push(result.class);\n assign(style, result.style);\n }\n }\n\n return { classes, style };\n}\n\n/**\n * Runs the computed function if present, returning classes, styles, and updated\n * variants.\n */\nfunction runComputedFunction(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n propsVariants: Record<string, unknown>,\n): {\n classes: ClassValue[];\n style: StyleValue;\n updatedVariants: Record<string, unknown>;\n} {\n const classes: ClassValue[] = [];\n const style: StyleValue = {};\n const updatedVariants = { ...resolvedVariants };\n\n if (!config.computed) {\n return { classes, style, updatedVariants };\n }\n\n const context = {\n variants: resolvedVariants,\n setVariants: (newVariants: VariantValues<Record<string, unknown>>) => {\n Object.assign(updatedVariants, newVariants);\n },\n setDefaultVariants: (\n newDefaults: VariantValues<Record<string, unknown>>,\n ) => {\n // Only apply defaults for variants not explicitly set in props\n for (const [key, value] of Object.entries(newDefaults)) {\n if (propsVariants[key] === undefined) {\n updatedVariants[key] = value;\n }\n }\n },\n };\n\n const computedResult = config.computed(context);\n if (computedResult != null) {\n const result = extractClassAndStyle(computedResult);\n classes.push(result.class);\n assign(style, result.style);\n }\n\n return { classes, style, updatedVariants };\n}\n\ninterface NormalizedSource {\n keys: string[];\n variantKeys: string[];\n defaults: Record<string, unknown>;\n isComponent: boolean;\n}\n\nconst EMPTY_SOURCE: NormalizedSource = {\n keys: [],\n variantKeys: [],\n defaults: {},\n isComponent: false,\n};\n\n/**\n * Normalizes a key source (array or component) to an object with keys,\n * variantKeys, defaults, and isComponent flag.\n */\nfunction normalizeKeySource(source: unknown): NormalizedSource {\n if (Array.isArray(source)) {\n return {\n keys: source as string[],\n variantKeys: source as string[],\n defaults: {},\n isComponent: false,\n };\n }\n\n if (!source) return EMPTY_SOURCE;\n if (typeof source !== \"object\" && typeof source !== \"function\") {\n return EMPTY_SOURCE;\n }\n if (!(\"keys\" in source)) return EMPTY_SOURCE;\n if (!(\"variantKeys\" in source)) return EMPTY_SOURCE;\n\n // Source is a component with keys and variantKeys properties\n const typed = source as {\n keys: string[];\n variantKeys: string[];\n getVariants?: () => Record<string, unknown>;\n };\n return {\n keys: [...typed.keys],\n variantKeys: [...typed.variantKeys],\n defaults: typed.getVariants?.() ?? {},\n isComponent: true,\n };\n}\n\n/**\n * Splits props into multiple groups based on key sources. Only the first\n * component claims styling props (class/className/style). Subsequent components\n * only receive variant props. Arrays always receive their listed keys but don't\n * claim styling props.\n */\nfunction splitPropsImpl(\n selfKeys: string[],\n selfIsComponent: boolean,\n props: Record<string, unknown>,\n sources: NormalizedSource[],\n): Record<string, unknown>[] {\n const allUsedKeys = new Set<string>(selfKeys);\n const results: Record<string, unknown>[] = [];\n\n // Track if styling has been claimed by a component\n let stylingClaimed = selfIsComponent;\n\n // Self result\n const selfResult: Record<string, unknown> = {};\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\n // Determine which keys this source should use\n // Components use variantKeys if styling has already been claimed\n // Arrays always use their listed keys\n const effectiveKeys =\n source.isComponent && stylingClaimed ? source.variantKeys : source.keys;\n\n for (const key of effectiveKeys) {\n allUsedKeys.add(key);\n if (key in props) {\n sourceResult[key] = props[key];\n }\n }\n results.push(sourceResult);\n\n // If this is a component that hasn't claimed styling yet, mark styling as claimed\n if (source.isComponent && !stylingClaimed) {\n stylingClaimed = true;\n }\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. Each source gets its\n * own result object containing all its matching keys. The first component\n * source claims styling props (class/className/style). Subsequent components\n * only receive variant props. Arrays receive their listed keys but don't claim\n * styling props. The last element is always the \"rest\" containing keys not\n * claimed by any source.\n * @example\n * ```ts\n * const [buttonProps, inputProps, rest] = splitProps(\n * props,\n * buttonComponent,\n * inputComponent,\n * );\n * // buttonProps has class/style + button variants\n * // inputProps has only input variants (no class/style)\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.isComponent,\n props,\n normalizedSources,\n );\n}) as SplitPropsFunction;\n\n/**\n * Creates the resolveDefaults function for a component. This function returns\n * only the variants set via setDefaultVariants in the computed function. Used\n * by child components to get parent's computed defaults.\n */\nfunction createResolveDefaults(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): ComponentMeta[\"resolveDefaults\"] {\n return (childDefaults, userProps = {}) => {\n // Get static defaults (including from extended components)\n const staticDefaults = collectStaticDefaults(config);\n\n // Merge: parent static < child static < user props\n // This is what parent's computed will see in `variants`\n const resolvedVariants = {\n ...staticDefaults,\n ...filterUndefined(childDefaults),\n ...filterUndefined(userProps),\n };\n\n // Track which keys are set via setDefaultVariants\n const computedDefaults: Record<string, unknown> = {};\n\n // Propagate to extended components so their computed functions can run\n // This allows grandparent computed functions to see grandchild defaults\n if (config.extend) {\n for (const ext of config.extend) {\n const meta = getComponentMeta(ext);\n if (!meta) continue;\n Object.assign(\n computedDefaults,\n meta.resolveDefaults(childDefaults, userProps),\n );\n }\n }\n\n if (config.computed) {\n config.computed({\n variants: resolvedVariants as VariantValues<Record<string, unknown>>,\n setVariants: () => {\n // Not relevant for collecting defaults\n },\n setDefaultVariants: (newDefaults) => {\n // Only apply defaults for variants not explicitly set by user\n // (child's static defaults should not block setDefaultVariants)\n for (const [key, value] of Object.entries(newDefaults)) {\n if (userProps[key] === undefined) {\n computedDefaults[key] = value;\n }\n }\n },\n });\n }\n\n return computedDefaults;\n };\n}\n\n/**\n * Creates the cv and cx functions.\n */\nexport function create<M extends Mode = \"jsx\">({\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 ): CVComponent<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 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 const allStyle: StyleValue = {};\n\n // Extract skip style keys from props (set by child's computedVariants)\n const skipStyleKeys =\n ((props as Record<symbol, unknown>)[SKIP_STYLE_KEYS] as\n | Set<string>\n | undefined) ?? new Set<string>();\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 = runComputedFunction(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n variantProps,\n );\n resolvedVariants = computedResult.updatedVariants;\n\n // Collect computedVariants keys that will override extended variants.\n // Combine with incoming skip keys to propagate through the extend chain.\n const computedVariantKeys = new Set<string>(skipStyleKeys);\n if (config.computedVariants) {\n for (const key of Object.keys(config.computedVariants)) {\n computedVariantKeys.add(key);\n }\n }\n\n // Process extended components (separates base and variant classes)\n const extendedResult = computeExtendedStyles(\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 assign(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 assign(allStyle, config.style);\n }\n\n // 4. Extended variant classes\n allClasses.push(...extendedResult.variantClasses);\n\n // 5. Current component's variants (skip keys that are overridden)\n const variantsResult = computeVariantStyles(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n skipStyleKeys,\n );\n allClasses.push(...variantsResult.classes);\n assign(allStyle, variantsResult.style);\n\n // Add computed results\n allClasses.push(...computedResult.classes);\n assign(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 assign(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.variantKeys = variantKeys as (keyof MergedVariants)[];\n\n component.propKeys = propsKeys as (keyof MergedVariants | keyof R)[];\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 const meta = getComponentMeta(ext);\n extendedBaseClasses.push(meta?.baseClass ?? \"\");\n }\n }\n const baseClass = cx(\n ...(extendedBaseClasses as ClsxClassValue[]),\n config.class as ClsxClassValue,\n );\n\n // Compute static defaults once at creation time (without triggering\n // computed functions)\n const staticDefaults = collectStaticDefaults(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n );\n\n // Store internal metadata hidden from public types\n setComponentMeta(component, {\n baseClass,\n staticDefaults,\n resolveDefaults: createResolveDefaults(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n ),\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 CVComponent<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;;;;;;;;;;ACgB/X,SAAgB,qBAAqB,MAAY;AAC/C,QAAO,SAAS,QAAQ,cAAc;;;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AAU,WAAW;GAGrB,MAAM,sBAAoC,EAAE;AAC5C,OAAI,OAAO,OACT,MAAK,MAAM,OAAO,OAAO,QAAQ;IAC/B,MAAM,OAAO,iBAAiB,IAAI;AAClC,wBAAoB,KAAK,MAAM,aAAa,GAAG;;AAenD,oBAAiBA,aAAW;IAC1B,WAbgBH,KAChB,GAAI,qBACJ,OAAO,MACR;IAWC,gBAPqB,sBACrB,OACD;IAMC,iBAAiB,sBACf,OACD;IACF,CAAC;AAEF,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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["clsx"],"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\";\nimport type {\n HTMLCSSProperties,\n JSXCSSProperties,\n StyleValue,\n} from \"./types.ts\";\n\nexport const MODES = [\"jsx\", \"html\", \"htmlObj\"] as const;\nexport type Mode = (typeof MODES)[number];\n\n/**\n * Returns the appropriate class property name based on the mode.\n * @example\n * getClassPropertyName(\"jsx\") // \"className\"\n * getClassPropertyName(\"html\") // \"class\"\n */\nexport function getClassPropertyName(mode: Mode) {\n return mode === \"jsx\" ? \"className\" : \"class\";\n}\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 // CSS property names and values are dynamic - cast required for index access\n (result as Record<string, string>)[hyphenToCamel(property)] = 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 // CSS property names and values are dynamic - cast required for index access\n (result as Record<string, string>)[hyphenToCamel(key)] =\n 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 // CSS property names and values are dynamic - cast required for index access\n (result as Record<string, string>)[key] = 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\";\nimport type {\n AnyComponent,\n CVComponent,\n ClassValue,\n ComponentProps,\n ComponentResult,\n Computed,\n ComputedVariants,\n ExtendableVariants,\n HTMLObjProps,\n HTMLProps,\n JSXProps,\n MergeVariants,\n ModalComponent,\n SplitPropsFunction,\n StyleClassValue,\n StyleProps,\n StyleValue,\n VariantValues,\n Variants,\n} from \"./types.ts\";\nimport {\n type Mode,\n getClassPropertyName,\n htmlObjStyleToStyleValue,\n htmlStyleToStyleValue,\n isHTMLObjStyle,\n jsxStyleToStyleValue,\n styleValueToHTMLObjStyle,\n styleValueToHTMLStyle,\n styleValueToJSXStyle,\n} from \"./utils.ts\";\n\n// Internal metadata stored on components but hidden from public types\ninterface ComponentMeta {\n baseClass: string;\n staticDefaults: Record<string, unknown>;\n resolveDefaults: (\n childDefaults: Record<string, unknown>,\n userProps?: Record<string, unknown>,\n ) => Record<string, unknown>;\n}\n\nconst META_KEY = \"__meta\";\n\n// Symbol property used to pass skip keys through the props object without\n// polluting the actual variant values. This allows the computed function to\n// see actual variant values while still skipping styling for overridden keys.\nconst SKIP_STYLE_KEYS = Symbol(\"skipStyleKeys\");\n\n// Dynamic property access on function requires cast through unknown\nfunction getComponentMeta(component: AnyComponent): ComponentMeta | undefined {\n return (component as unknown as Record<string, unknown>)[META_KEY] as\n | ComponentMeta\n | undefined;\n}\n\nfunction setComponentMeta(component: AnyComponent, meta: ComponentMeta): void {\n (component as unknown as Record<string, unknown>)[META_KEY] = meta;\n}\n\n/**\n * Mutates target by assigning all properties from source. Avoids object spread\n * overhead in hot paths where we're building up a result object.\n */\nfunction assign<T extends object>(target: T, source: T): void {\n for (const key of Object.keys(source)) {\n (target as Record<string, unknown>)[key] = (\n source as Record<string, unknown>\n )[key];\n }\n}\n\nexport type {\n ClassValue,\n StyleValue,\n StyleClassValue,\n JSXProps,\n HTMLProps,\n HTMLObjProps,\n CVComponent,\n};\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 normalized\n * 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 * Extracts class and style from a variant value (either a class value or a\n * style-class object).\n */\nfunction extractClassAndStyle(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.variantKeys) {\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 static default variants from extended components and the current\n * config. Also handles implicit boolean defaults (when only `false` key\n * exists). This does NOT trigger computed functions - use collectDefaultVariants\n * for that.\n */\nfunction collectStaticDefaults(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): Record<string, unknown> {\n const defaults: Record<string, unknown> = {};\n\n // Collect static defaults from extended components (via metadata to avoid\n // triggering computed functions)\n if (config.extend) {\n for (const ext of config.extend) {\n const meta = getComponentMeta(ext);\n if (meta) {\n Object.assign(defaults, meta.staticDefaults);\n }\n }\n }\n\n // Handle implicit boolean defaults from variants\n // If a variant has a `false` key, default to false when no value is provided\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n if (!isStyleClassValue(variantDef)) continue;\n const keys = Object.keys(variantDef);\n const hasFalse = keys.includes(\"false\");\n if (hasFalse && !defaults[variantName]) {\n defaults[variantName] = false;\n }\n }\n }\n\n // Override with current config's static defaults\n if (config.defaultVariants) {\n Object.assign(defaults, config.defaultVariants);\n }\n\n return defaults;\n}\n\n/**\n * Collects default variants from extended components and the current config.\n * This includes both static defaults and computed defaults (from\n * setDefaultVariants in extended components' computed functions). Priority:\n * parent static < child static < parent computed < child computed.\n */\nfunction collectDefaultVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n propsVariants: Record<string, unknown> = {},\n): Record<string, unknown> {\n // Start with static defaults (parent static < child static)\n const defaults = collectStaticDefaults(config);\n\n // Apply computed defaults from extended components\n // Parent's setDefaultVariants should override child's static defaults\n if (!config.extend) return defaults;\n\n // Pass full static defaults (not just this config's defaultVariants)\n // so that intermediate components' defaults are visible to ancestors\n for (const ext of config.extend) {\n const meta = getComponentMeta(ext);\n if (!meta) continue;\n Object.assign(defaults, meta.resolveDefaults(defaults, propsVariants));\n }\n\n return defaults;\n}\n\n/**\n * Filters out keys with undefined values from an object.\n */\nfunction filterUndefined(\n obj: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n if (value === undefined) continue;\n result[key] = value;\n }\n return result;\n}\n\n/**\n * Resolves variant values by merging defaults with provided props. Props with\n * undefined values are filtered out so they don't override defaults.\n */\nfunction resolveVariants(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n props: Record<string, unknown> = {},\n): Record<string, unknown> {\n const defaults = collectDefaultVariants(config, props);\n return { ...defaults, ...filterUndefined(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 extractClassAndStyle(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 extractClassAndStyle(value);\n}\n\n/**\n * Extracts classes from fullClass that are not in baseClass. Uses string\n * comparison optimization: if fullClass starts with baseClass, just take the\n * suffix.\n */\nfunction extractVariantClasses(fullClass: string, baseClass: string): string {\n if (!fullClass) return \"\";\n if (!baseClass) return fullClass;\n\n // Fast path: fullClass starts with baseClass (common case)\n if (fullClass.startsWith(baseClass)) {\n return fullClass.slice(baseClass.length).trim();\n }\n\n // Slow path: need to diff the class sets\n const baseClassSet = new Set(baseClass.split(\" \").filter(Boolean));\n return fullClass\n .split(\" \")\n .filter((c) => c && !baseClassSet.has(c))\n .join(\" \");\n}\n\nfunction computeExtendedStyles(\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 const style: StyleValue = {};\n\n if (!config.extend) return { baseClasses, variantClasses, style };\n\n for (const ext of config.extend) {\n // Pass actual variant values but mark which keys should skip styling.\n // Using a Symbol property keeps variant values clean for computed functions\n // while still allowing us to skip styling for overridden keys.\n const propsForExt: Record<string | symbol, unknown> = {\n ...resolvedVariants,\n };\n if (overrideVariantKeys.size > 0) {\n propsForExt[SKIP_STYLE_KEYS] = overrideVariantKeys;\n }\n\n const extResult = ext(propsForExt);\n assign(style, normalizeStyle(extResult.style));\n\n // Get base class from internal metadata (no variants)\n const meta = getComponentMeta(ext);\n const baseClass = meta?.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 const variantPortion = extractVariantClasses(fullClass, baseClass);\n if (variantPortion) {\n variantClasses.push(variantPortion);\n }\n }\n\n return { baseClasses, variantClasses, style };\n}\n\n/**\n * Computes class and style from the component's own variants and\n * computedVariants (not extended components).\n */\nfunction computeVariantStyles(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string | symbol, unknown>,\n skipStyleKeys: Set<string> = new Set(),\n): { classes: ClassValue[]; style: StyleValue } {\n const classes: ClassValue[] = [];\n const style: StyleValue = {};\n\n // Process current component's variants\n if (config.variants) {\n for (const [variantName, variantDef] of Object.entries(config.variants)) {\n // Skip styling for variants that are overridden by child's computedVariants\n if (skipStyleKeys.has(variantName)) continue;\n\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const result = getVariantResult(variantDef, selectedValue);\n classes.push(result.class);\n assign(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 // Skip styling for variants that are overridden by child's computedVariants\n if (skipStyleKeys.has(variantName)) continue;\n\n const selectedValue = resolvedVariants[variantName];\n if (selectedValue === undefined) continue;\n\n const computedResult = computeFn(selectedValue);\n const result = extractClassAndStyle(computedResult);\n classes.push(result.class);\n assign(style, result.style);\n }\n }\n\n return { classes, style };\n}\n\n/**\n * Runs the computed function if present, returning classes, styles, and updated\n * variants.\n */\nfunction runComputedFunction(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants: Record<string, unknown>,\n propsVariants: Record<string, unknown>,\n): {\n classes: ClassValue[];\n style: StyleValue;\n updatedVariants: Record<string, unknown>;\n} {\n const classes: ClassValue[] = [];\n const style: StyleValue = {};\n const updatedVariants = { ...resolvedVariants };\n\n if (!config.computed) {\n return { classes, style, updatedVariants };\n }\n\n const context = {\n variants: resolvedVariants,\n setVariants: (newVariants: VariantValues<Record<string, unknown>>) => {\n Object.assign(updatedVariants, newVariants);\n },\n setDefaultVariants: (\n newDefaults: VariantValues<Record<string, unknown>>,\n ) => {\n // Only apply defaults for variants not explicitly set in props\n for (const [key, value] of Object.entries(newDefaults)) {\n if (propsVariants[key] === undefined) {\n updatedVariants[key] = value;\n }\n }\n },\n addClass: (className: ClassValue) => {\n classes.push(className);\n },\n addStyle: (newStyle: StyleValue) => {\n assign(style, newStyle);\n },\n };\n\n const computedResult = config.computed(context);\n if (computedResult != null) {\n const result = extractClassAndStyle(computedResult);\n classes.push(result.class);\n assign(style, result.style);\n }\n\n return { classes, style, updatedVariants };\n}\n\ninterface NormalizedSource {\n keys: string[];\n variantKeys: string[];\n defaults: Record<string, unknown>;\n isComponent: boolean;\n}\n\nconst EMPTY_SOURCE: NormalizedSource = {\n keys: [],\n variantKeys: [],\n defaults: {},\n isComponent: false,\n};\n\n/**\n * Normalizes a key source (array or component) to an object with keys,\n * variantKeys, defaults, and isComponent flag.\n */\nfunction normalizeKeySource(source: unknown): NormalizedSource {\n if (Array.isArray(source)) {\n return {\n keys: source as string[],\n variantKeys: source as string[],\n defaults: {},\n isComponent: false,\n };\n }\n\n if (!source) return EMPTY_SOURCE;\n if (typeof source !== \"object\" && typeof source !== \"function\") {\n return EMPTY_SOURCE;\n }\n if (!(\"keys\" in source)) return EMPTY_SOURCE;\n if (!(\"variantKeys\" in source)) return EMPTY_SOURCE;\n\n // Source is a component with keys and variantKeys properties\n const typed = source as {\n keys: string[];\n variantKeys: string[];\n getVariants?: () => Record<string, unknown>;\n };\n return {\n keys: [...typed.keys],\n variantKeys: [...typed.variantKeys],\n defaults: typed.getVariants?.() ?? {},\n isComponent: true,\n };\n}\n\n/**\n * Splits props into multiple groups based on key sources. Only the first\n * component claims styling props (class/className/style). Subsequent components\n * only receive variant props. Arrays always receive their listed keys but don't\n * claim styling props.\n */\nfunction splitPropsImpl(\n selfKeys: string[],\n selfIsComponent: boolean,\n props: Record<string, unknown>,\n sources: NormalizedSource[],\n): Record<string, unknown>[] {\n const allUsedKeys = new Set<string>(selfKeys);\n const results: Record<string, unknown>[] = [];\n\n // Track if styling has been claimed by a component\n let stylingClaimed = selfIsComponent;\n\n // Self result\n const selfResult: Record<string, unknown> = {};\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\n // Determine which keys this source should use\n // Components use variantKeys if styling has already been claimed\n // Arrays always use their listed keys\n const effectiveKeys =\n source.isComponent && stylingClaimed ? source.variantKeys : source.keys;\n\n for (const key of effectiveKeys) {\n allUsedKeys.add(key);\n if (key in props) {\n sourceResult[key] = props[key];\n }\n }\n results.push(sourceResult);\n\n // If this is a component that hasn't claimed styling yet, mark styling as claimed\n if (source.isComponent && !stylingClaimed) {\n stylingClaimed = true;\n }\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. Each source gets its\n * own result object containing all its matching keys. The first component\n * source claims styling props (class/className/style). Subsequent components\n * only receive variant props. Arrays receive their listed keys but don't claim\n * styling props. The last element is always the \"rest\" containing keys not\n * claimed by any source.\n * @example\n * ```ts\n * const [buttonProps, inputProps, rest] = splitProps(\n * props,\n * buttonComponent,\n * inputComponent,\n * );\n * // buttonProps has class/style + button variants\n * // inputProps has only input variants (no class/style)\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.isComponent,\n props,\n normalizedSources,\n );\n}) as SplitPropsFunction;\n\n/**\n * Creates the resolveDefaults function for a component. This function returns\n * only the variants set via setDefaultVariants in the computed function. Used\n * by child components to get parent's computed defaults.\n */\nfunction createResolveDefaults(\n config: CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n): ComponentMeta[\"resolveDefaults\"] {\n return (childDefaults, userProps = {}) => {\n // Get static defaults (including from extended components)\n const staticDefaults = collectStaticDefaults(config);\n\n // Merge: parent static < child static < user props\n // This is what parent's computed will see in `variants`\n const resolvedVariants = {\n ...staticDefaults,\n ...filterUndefined(childDefaults),\n ...filterUndefined(userProps),\n };\n\n // Track which keys are set via setDefaultVariants\n const computedDefaults: Record<string, unknown> = {};\n\n // Propagate to extended components so their computed functions can run\n // This allows grandparent computed functions to see grandchild defaults\n if (config.extend) {\n for (const ext of config.extend) {\n const meta = getComponentMeta(ext);\n if (!meta) continue;\n Object.assign(\n computedDefaults,\n meta.resolveDefaults(childDefaults, userProps),\n );\n }\n }\n\n if (config.computed) {\n config.computed({\n variants: resolvedVariants as VariantValues<Record<string, unknown>>,\n setVariants: () => {\n // Not relevant for collecting defaults\n },\n setDefaultVariants: (newDefaults) => {\n // Only apply defaults for variants not explicitly set by user\n // (child's static defaults should not block setDefaultVariants)\n for (const [key, value] of Object.entries(newDefaults)) {\n if (userProps[key] === undefined) {\n computedDefaults[key] = value;\n }\n }\n },\n addClass: () => {\n // Not relevant for collecting defaults\n },\n addStyle: () => {\n // Not relevant for collecting defaults\n },\n });\n }\n\n return computedDefaults;\n };\n}\n\n/**\n * Creates the cv and cx functions.\n */\nexport function create<M extends Mode = \"jsx\">({\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 ): CVComponent<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 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 const allStyle: StyleValue = {};\n\n // Extract skip style keys from props (set by child's computedVariants)\n const skipStyleKeys =\n ((props as Record<symbol, unknown>)[SKIP_STYLE_KEYS] as\n | Set<string>\n | undefined) ?? new Set<string>();\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 = runComputedFunction(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n variantProps,\n );\n resolvedVariants = computedResult.updatedVariants;\n\n // Collect computedVariants keys that will override extended variants.\n // Combine with incoming skip keys to propagate through the extend chain.\n const computedVariantKeys = new Set<string>(skipStyleKeys);\n if (config.computedVariants) {\n for (const key of Object.keys(config.computedVariants)) {\n computedVariantKeys.add(key);\n }\n }\n\n // Process extended components (separates base and variant classes)\n const extendedResult = computeExtendedStyles(\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 assign(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 assign(allStyle, config.style);\n }\n\n // 4. Extended variant classes\n allClasses.push(...extendedResult.variantClasses);\n\n // 5. Current component's variants (skip keys that are overridden)\n const variantsResult = computeVariantStyles(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n resolvedVariants,\n skipStyleKeys,\n );\n allClasses.push(...variantsResult.classes);\n assign(allStyle, variantsResult.style);\n\n // Add computed results\n allClasses.push(...computedResult.classes);\n assign(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 assign(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.variantKeys = variantKeys as (keyof MergedVariants)[];\n\n component.propKeys = propsKeys as (keyof MergedVariants | keyof R)[];\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 const meta = getComponentMeta(ext);\n extendedBaseClasses.push(meta?.baseClass ?? \"\");\n }\n }\n const baseClass = cx(\n ...(extendedBaseClasses as ClsxClassValue[]),\n config.class as ClsxClassValue,\n );\n\n // Compute static defaults once at creation time (without triggering\n // computed functions)\n const staticDefaults = collectStaticDefaults(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n );\n\n // Store internal metadata hidden from public types\n setComponentMeta(component, {\n baseClass,\n staticDefaults,\n resolveDefaults: createResolveDefaults(\n config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,\n ),\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 CVComponent<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;;;;;;;;;;ACgB/X,SAAgB,qBAAqB,MAAY;AAC/C,QAAO,SAAS,QAAQ,cAAc;;;;;;;;AASxC,SAAgB,cAAc,KAAa;AAEzC,KAAI,IAAI,WAAW,KAAK,CACtB,QAAO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ExB,aAAU,WAAW;GAGrB,MAAM,sBAAoC,EAAE;AAC5C,OAAI,OAAO,OACT,MAAK,MAAM,OAAO,OAAO,QAAQ;IAC/B,MAAM,OAAO,iBAAiB,IAAI;AAClC,wBAAoB,KAAK,MAAM,aAAa,GAAG;;AAenD,oBAAiB,WAAW;IAC1B,WAbgB,GAChB,GAAI,qBACJ,OAAO,MACR;IAWC,gBAPqB,sBACrB,OACD;IAMC,iBAAiB,sBACf,OACD;IACF,CAAC;AAEF,UAAO;;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
|
@@ -252,14 +252,12 @@ function collectDefaultVariants(
|
|
|
252
252
|
// Parent's setDefaultVariants should override child's static defaults
|
|
253
253
|
if (!config.extend) return defaults;
|
|
254
254
|
|
|
255
|
-
|
|
255
|
+
// Pass full static defaults (not just this config's defaultVariants)
|
|
256
|
+
// so that intermediate components' defaults are visible to ancestors
|
|
256
257
|
for (const ext of config.extend) {
|
|
257
258
|
const meta = getComponentMeta(ext);
|
|
258
259
|
if (!meta) continue;
|
|
259
|
-
Object.assign(
|
|
260
|
-
defaults,
|
|
261
|
-
meta.resolveDefaults(childStaticDefaults, propsVariants),
|
|
262
|
-
);
|
|
260
|
+
Object.assign(defaults, meta.resolveDefaults(defaults, propsVariants));
|
|
263
261
|
}
|
|
264
262
|
|
|
265
263
|
return defaults;
|
|
@@ -468,6 +466,12 @@ function runComputedFunction(
|
|
|
468
466
|
}
|
|
469
467
|
}
|
|
470
468
|
},
|
|
469
|
+
addClass: (className: ClassValue) => {
|
|
470
|
+
classes.push(className);
|
|
471
|
+
},
|
|
472
|
+
addStyle: (newStyle: StyleValue) => {
|
|
473
|
+
assign(style, newStyle);
|
|
474
|
+
},
|
|
471
475
|
};
|
|
472
476
|
|
|
473
477
|
const computedResult = config.computed(context);
|
|
@@ -676,6 +680,12 @@ function createResolveDefaults(
|
|
|
676
680
|
}
|
|
677
681
|
}
|
|
678
682
|
},
|
|
683
|
+
addClass: () => {
|
|
684
|
+
// Not relevant for collecting defaults
|
|
685
|
+
},
|
|
686
|
+
addStyle: () => {
|
|
687
|
+
// Not relevant for collecting defaults
|
|
688
|
+
},
|
|
679
689
|
});
|
|
680
690
|
}
|
|
681
691
|
|
package/src/test.ts
CHANGED
|
@@ -1262,6 +1262,21 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1262
1262
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
1263
1263
|
});
|
|
1264
1264
|
|
|
1265
|
+
test("computed receives default variants from intermediate component", () => {
|
|
1266
|
+
const parent = cv({
|
|
1267
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1268
|
+
computed: ({ variants, setDefaultVariants }) => {
|
|
1269
|
+
if (!variants.size) {
|
|
1270
|
+
setDefaultVariants({ size: "lg" });
|
|
1271
|
+
}
|
|
1272
|
+
},
|
|
1273
|
+
});
|
|
1274
|
+
const child = cv({ extend: [parent], defaultVariants: { size: "sm" } });
|
|
1275
|
+
const component = getModalComponent(mode, cv({ extend: [child] }));
|
|
1276
|
+
const props = component();
|
|
1277
|
+
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
1278
|
+
});
|
|
1279
|
+
|
|
1265
1280
|
test("child computed setDefaultVariants overrides parent computed setDefaultVariants", () => {
|
|
1266
1281
|
const base = cv({
|
|
1267
1282
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
@@ -1593,6 +1608,226 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1593
1608
|
expect(getStyleClass(props)).toEqual({ class: "" });
|
|
1594
1609
|
});
|
|
1595
1610
|
|
|
1611
|
+
test("computed addClass with string", () => {
|
|
1612
|
+
const component = getModalComponent(
|
|
1613
|
+
mode,
|
|
1614
|
+
cv({
|
|
1615
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1616
|
+
computed: ({ variants, addClass }) => {
|
|
1617
|
+
if (variants.size === "lg") {
|
|
1618
|
+
addClass("added-lg");
|
|
1619
|
+
}
|
|
1620
|
+
},
|
|
1621
|
+
}),
|
|
1622
|
+
);
|
|
1623
|
+
const props = component({ size: "lg" });
|
|
1624
|
+
expect(getStyleClass(props)).toEqual({ class: cls("lg added-lg") });
|
|
1625
|
+
});
|
|
1626
|
+
|
|
1627
|
+
test("computed addClass with array", () => {
|
|
1628
|
+
const component = getModalComponent(
|
|
1629
|
+
mode,
|
|
1630
|
+
cv({
|
|
1631
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1632
|
+
computed: ({ variants, addClass }) => {
|
|
1633
|
+
if (variants.size === "lg") {
|
|
1634
|
+
addClass(["added-lg", "extra-class"]);
|
|
1635
|
+
}
|
|
1636
|
+
},
|
|
1637
|
+
}),
|
|
1638
|
+
);
|
|
1639
|
+
const props = component({ size: "lg" });
|
|
1640
|
+
expect(getStyleClass(props)).toEqual({
|
|
1641
|
+
class: cls("lg added-lg extra-class"),
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
|
|
1645
|
+
test("computed addStyle", () => {
|
|
1646
|
+
const component = getModalComponent(
|
|
1647
|
+
mode,
|
|
1648
|
+
cv({
|
|
1649
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1650
|
+
computed: ({ variants, addStyle }) => {
|
|
1651
|
+
if (variants.size === "lg") {
|
|
1652
|
+
addStyle({ fontSize: "20px" });
|
|
1653
|
+
}
|
|
1654
|
+
},
|
|
1655
|
+
}),
|
|
1656
|
+
);
|
|
1657
|
+
const props = component({ size: "lg" });
|
|
1658
|
+
expect(getStyleClass(props)).toEqual({
|
|
1659
|
+
class: cls("lg"),
|
|
1660
|
+
fontSize: "20px",
|
|
1661
|
+
});
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
test("computed addClass combined with return value", () => {
|
|
1665
|
+
const component = getModalComponent(
|
|
1666
|
+
mode,
|
|
1667
|
+
cv({
|
|
1668
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1669
|
+
computed: ({ variants, addClass }) => {
|
|
1670
|
+
if (variants.size === "lg") {
|
|
1671
|
+
addClass("added-class");
|
|
1672
|
+
}
|
|
1673
|
+
return "returned-class";
|
|
1674
|
+
},
|
|
1675
|
+
}),
|
|
1676
|
+
);
|
|
1677
|
+
const props = component({ size: "lg" });
|
|
1678
|
+
expect(getStyleClass(props)).toEqual({
|
|
1679
|
+
class: cls("lg added-class returned-class"),
|
|
1680
|
+
});
|
|
1681
|
+
});
|
|
1682
|
+
|
|
1683
|
+
test("computed addStyle combined with return value", () => {
|
|
1684
|
+
const component = getModalComponent(
|
|
1685
|
+
mode,
|
|
1686
|
+
cv({
|
|
1687
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1688
|
+
computed: ({ variants, addStyle }) => {
|
|
1689
|
+
if (variants.size === "lg") {
|
|
1690
|
+
addStyle({ fontSize: "20px" });
|
|
1691
|
+
}
|
|
1692
|
+
return { backgroundColor: "red" };
|
|
1693
|
+
},
|
|
1694
|
+
}),
|
|
1695
|
+
);
|
|
1696
|
+
const props = component({ size: "lg" });
|
|
1697
|
+
expect(getStyleClass(props)).toEqual({
|
|
1698
|
+
class: cls("lg"),
|
|
1699
|
+
fontSize: "20px",
|
|
1700
|
+
backgroundColor: "red",
|
|
1701
|
+
});
|
|
1702
|
+
});
|
|
1703
|
+
|
|
1704
|
+
test("computed addClass and addStyle together", () => {
|
|
1705
|
+
const component = getModalComponent(
|
|
1706
|
+
mode,
|
|
1707
|
+
cv({
|
|
1708
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1709
|
+
computed: ({ variants, addClass, addStyle }) => {
|
|
1710
|
+
if (variants.size === "lg") {
|
|
1711
|
+
addClass("added-lg");
|
|
1712
|
+
addStyle({ fontSize: "20px" });
|
|
1713
|
+
}
|
|
1714
|
+
},
|
|
1715
|
+
}),
|
|
1716
|
+
);
|
|
1717
|
+
const props = component({ size: "lg" });
|
|
1718
|
+
expect(getStyleClass(props)).toEqual({
|
|
1719
|
+
class: cls("lg added-lg"),
|
|
1720
|
+
fontSize: "20px",
|
|
1721
|
+
});
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
test("computed addClass and addStyle with return value", () => {
|
|
1725
|
+
const component = getModalComponent(
|
|
1726
|
+
mode,
|
|
1727
|
+
cv({
|
|
1728
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1729
|
+
computed: ({ variants, addClass, addStyle }) => {
|
|
1730
|
+
if (variants.size === "lg") {
|
|
1731
|
+
addClass("added-lg");
|
|
1732
|
+
addStyle({ fontSize: "20px" });
|
|
1733
|
+
}
|
|
1734
|
+
return { class: "returned-class", backgroundColor: "red" };
|
|
1735
|
+
},
|
|
1736
|
+
}),
|
|
1737
|
+
);
|
|
1738
|
+
const props = component({ size: "lg" });
|
|
1739
|
+
expect(getStyleClass(props)).toEqual({
|
|
1740
|
+
class: cls("lg added-lg returned-class"),
|
|
1741
|
+
fontSize: "20px",
|
|
1742
|
+
backgroundColor: "red",
|
|
1743
|
+
});
|
|
1744
|
+
});
|
|
1745
|
+
|
|
1746
|
+
test("computed addClass multiple calls", () => {
|
|
1747
|
+
const component = getModalComponent(
|
|
1748
|
+
mode,
|
|
1749
|
+
cv({
|
|
1750
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1751
|
+
computed: ({ variants, addClass }) => {
|
|
1752
|
+
if (variants.size === "lg") {
|
|
1753
|
+
addClass("first");
|
|
1754
|
+
addClass("second");
|
|
1755
|
+
addClass("third");
|
|
1756
|
+
}
|
|
1757
|
+
},
|
|
1758
|
+
}),
|
|
1759
|
+
);
|
|
1760
|
+
const props = component({ size: "lg" });
|
|
1761
|
+
expect(getStyleClass(props)).toEqual({
|
|
1762
|
+
class: cls("lg first second third"),
|
|
1763
|
+
});
|
|
1764
|
+
});
|
|
1765
|
+
|
|
1766
|
+
test("computed addStyle multiple calls merges styles", () => {
|
|
1767
|
+
const component = getModalComponent(
|
|
1768
|
+
mode,
|
|
1769
|
+
cv({
|
|
1770
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1771
|
+
computed: ({ variants, addStyle }) => {
|
|
1772
|
+
if (variants.size === "lg") {
|
|
1773
|
+
addStyle({ fontSize: "20px" });
|
|
1774
|
+
addStyle({ backgroundColor: "red" });
|
|
1775
|
+
addStyle({ color: "blue" });
|
|
1776
|
+
}
|
|
1777
|
+
},
|
|
1778
|
+
}),
|
|
1779
|
+
);
|
|
1780
|
+
const props = component({ size: "lg" });
|
|
1781
|
+
expect(getStyleClass(props)).toEqual({
|
|
1782
|
+
class: cls("lg"),
|
|
1783
|
+
fontSize: "20px",
|
|
1784
|
+
backgroundColor: "red",
|
|
1785
|
+
color: "blue",
|
|
1786
|
+
});
|
|
1787
|
+
});
|
|
1788
|
+
|
|
1789
|
+
test("computed addStyle later call overrides earlier", () => {
|
|
1790
|
+
const component = getModalComponent(
|
|
1791
|
+
mode,
|
|
1792
|
+
cv({
|
|
1793
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1794
|
+
computed: ({ variants, addStyle }) => {
|
|
1795
|
+
if (variants.size === "lg") {
|
|
1796
|
+
addStyle({ fontSize: "16px" });
|
|
1797
|
+
addStyle({ fontSize: "20px" });
|
|
1798
|
+
}
|
|
1799
|
+
},
|
|
1800
|
+
}),
|
|
1801
|
+
);
|
|
1802
|
+
const props = component({ size: "lg" });
|
|
1803
|
+
expect(getStyleClass(props)).toEqual({
|
|
1804
|
+
class: cls("lg"),
|
|
1805
|
+
fontSize: "20px",
|
|
1806
|
+
});
|
|
1807
|
+
});
|
|
1808
|
+
|
|
1809
|
+
test("computed addStyle does not accept numbers", () => {
|
|
1810
|
+
const component = getModalComponent(
|
|
1811
|
+
mode,
|
|
1812
|
+
cv({
|
|
1813
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1814
|
+
computed: ({ variants, addStyle }) => {
|
|
1815
|
+
if (variants.size === "lg") {
|
|
1816
|
+
addStyle({
|
|
1817
|
+
// @ts-expect-error
|
|
1818
|
+
fontSize: 20,
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
},
|
|
1822
|
+
}),
|
|
1823
|
+
);
|
|
1824
|
+
const props = component({ size: "lg" });
|
|
1825
|
+
expect(getStyleClass(props)).toEqual({
|
|
1826
|
+
class: cls("lg"),
|
|
1827
|
+
fontSize: expect.toBeOneOf(["20", "20px"]),
|
|
1828
|
+
});
|
|
1829
|
+
});
|
|
1830
|
+
|
|
1596
1831
|
test("extend single component", () => {
|
|
1597
1832
|
const base = cv({ class: "base", variants: { size: { sm: "sm" } } });
|
|
1598
1833
|
const component = getModalComponent(
|
package/src/types.ts
CHANGED
|
@@ -232,6 +232,8 @@ export interface ComputedContext<V> {
|
|
|
232
232
|
variants: VariantValues<V>;
|
|
233
233
|
setVariants: (variants: VariantValues<V>) => void;
|
|
234
234
|
setDefaultVariants: (variants: VariantValues<V>) => void;
|
|
235
|
+
addClass: (className: ClassValue) => void;
|
|
236
|
+
addStyle: (style: StyleValue) => void;
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
export type Computed<V> = (context: ComputedContext<V>) => VariantValue;
|