clava 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +29 -45
- package/src/test.ts +72 -0
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -508,7 +508,10 @@ function createResolveDefaults(config) {
|
|
|
508
508
|
variants: resolvedVariants,
|
|
509
509
|
setVariants: () => {},
|
|
510
510
|
setDefaultVariants: (newDefaults) => {
|
|
511
|
-
for (const [key, value] of Object.entries(newDefaults))
|
|
511
|
+
for (const [key, value] of Object.entries(newDefaults)) {
|
|
512
|
+
if (userProps[key] !== void 0) continue;
|
|
513
|
+
computedDefaults[key] = value;
|
|
514
|
+
}
|
|
512
515
|
},
|
|
513
516
|
addClass: () => {},
|
|
514
517
|
addStyle: () => {}
|
|
@@ -578,14 +581,16 @@ function create({ defaultMode = "jsx", transformClass = (className) => className
|
|
|
578
581
|
component.class = (props = {}) => {
|
|
579
582
|
return computeResult(props).className;
|
|
580
583
|
};
|
|
581
|
-
component.style = (
|
|
584
|
+
component.style = (props = {}) => {
|
|
582
585
|
const { style } = computeResult(props);
|
|
583
586
|
if (mode === "jsx") return styleValueToJSXStyle(style);
|
|
584
587
|
if (mode === "html") return styleValueToHTMLStyle(style);
|
|
585
588
|
return styleValueToHTMLObjStyle(style);
|
|
586
|
-
}
|
|
589
|
+
};
|
|
587
590
|
component.getVariants = (variants) => {
|
|
588
|
-
|
|
591
|
+
const variantProps = variants ?? {};
|
|
592
|
+
const { updatedVariants } = runComputedFunction(config, resolveVariants(config, variantProps), variantProps);
|
|
593
|
+
return updatedVariants;
|
|
589
594
|
};
|
|
590
595
|
component.keys = propsKeys;
|
|
591
596
|
component.variantKeys = variantKeys;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EA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"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) continue;\n computedDefaults[key] = value;\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(config);\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[key];\n }\n }\n // Resolve variants with defaults\n let resolvedVariants = resolveVariants(config, variantProps);\n // Process computed first to potentially update variants\n const computedResult = runComputedFunction(\n config,\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,\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,\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) };\n }\n if (mode === \"html\") {\n return { class: className, style: styleValueToHTMLStyle(style) };\n }\n // htmlObj\n return { class: className, style: styleValueToHTMLObjStyle(style) };\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 };\n\n component.getVariants = (variants?: VariantValues<MergedVariants>) => {\n const variantProps = variants ?? {};\n const resolvedVariants = resolveVariants(config, variantProps);\n // Run computed function to get variants set via setVariants and\n // setDefaultVariants\n const { updatedVariants } = runComputedFunction(\n config,\n resolvedVariants,\n variantProps,\n );\n return updatedVariants as VariantValues<MergedVariants>;\n };\n\n component.keys = propsKeys;\n component.variantKeys = variantKeys;\n component.propKeys = propsKeys;\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(config);\n\n // Store internal metadata hidden from public types\n setComponentMeta(component, {\n baseClass,\n staticDefaults,\n resolveDefaults: createResolveDefaults(config),\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,I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AS,QAAwC,EAAE,KAAK;IAChE,MAAM,EAAE,UAAU,cAAc,MAAM;AACtC,QAAI,SAAS,MAAO,QAAO,qBAAqB,MAAM;AACtD,QAAI,SAAS,OAAQ,QAAO,sBAAsB,MAAM;AACxD,WAAO,yBAAyB,MAAM;;AAGxC,aAAU,eAAe,aAA6C;IACpE,MAAM,eAAe,YAAY,EAAE;IAInC,MAAM,EAAE,oBAAoB,oBAC1B,QAJuB,gBAAgB,QAAQ,aAAa,EAM5D,aACD;AACD,WAAO;;AAGT,aAAU,OAAO;AACjB,aAAU,cAAc;AACxB,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;;AAanD,oBAAiB,WAAW;IAC1B,WAXgB,GAChB,GAAI,qBACJ,OAAO,MACR;IASC,gBALqB,sBAAsB,OAAO;IAMlD,iBAAiB,sBAAsB,OAAO;IAC/C,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
|
@@ -675,9 +675,8 @@ function createResolveDefaults(
|
|
|
675
675
|
// Only apply defaults for variants not explicitly set by user
|
|
676
676
|
// (child's static defaults should not block setDefaultVariants)
|
|
677
677
|
for (const [key, value] of Object.entries(newDefaults)) {
|
|
678
|
-
if (userProps[key]
|
|
679
|
-
|
|
680
|
-
}
|
|
678
|
+
if (userProps[key] !== undefined) continue;
|
|
679
|
+
computedDefaults[key] = value;
|
|
681
680
|
}
|
|
682
681
|
},
|
|
683
682
|
addClass: () => {
|
|
@@ -711,9 +710,7 @@ export function create<M extends Mode = "jsx">({
|
|
|
711
710
|
): CVComponent<V, CV, E, StyleProps[M]> => {
|
|
712
711
|
type MergedVariants = MergeVariants<V, CV, E>;
|
|
713
712
|
|
|
714
|
-
const variantKeys = collectVariantKeys(
|
|
715
|
-
config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,
|
|
716
|
-
);
|
|
713
|
+
const variantKeys = collectVariantKeys(config);
|
|
717
714
|
|
|
718
715
|
const getPropsKeys = (mode: Mode) => [
|
|
719
716
|
getClassPropertyName(mode),
|
|
@@ -737,19 +734,14 @@ export function create<M extends Mode = "jsx">({
|
|
|
737
734
|
const variantProps: Record<string, unknown> = {};
|
|
738
735
|
for (const key of variantKeys) {
|
|
739
736
|
if (key in props) {
|
|
740
|
-
variantProps[key] =
|
|
737
|
+
variantProps[key] = props[key];
|
|
741
738
|
}
|
|
742
739
|
}
|
|
743
|
-
|
|
744
740
|
// Resolve variants with defaults
|
|
745
|
-
let resolvedVariants = resolveVariants(
|
|
746
|
-
config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,
|
|
747
|
-
variantProps,
|
|
748
|
-
);
|
|
749
|
-
|
|
741
|
+
let resolvedVariants = resolveVariants(config, variantProps);
|
|
750
742
|
// Process computed first to potentially update variants
|
|
751
743
|
const computedResult = runComputedFunction(
|
|
752
|
-
config
|
|
744
|
+
config,
|
|
753
745
|
resolvedVariants,
|
|
754
746
|
variantProps,
|
|
755
747
|
);
|
|
@@ -766,7 +758,7 @@ export function create<M extends Mode = "jsx">({
|
|
|
766
758
|
|
|
767
759
|
// Process extended components (separates base and variant classes)
|
|
768
760
|
const extendedResult = computeExtendedStyles(
|
|
769
|
-
config
|
|
761
|
+
config,
|
|
770
762
|
resolvedVariants,
|
|
771
763
|
computedVariantKeys,
|
|
772
764
|
);
|
|
@@ -788,7 +780,7 @@ export function create<M extends Mode = "jsx">({
|
|
|
788
780
|
|
|
789
781
|
// 5. Current component's variants (skip keys that are overridden)
|
|
790
782
|
const variantsResult = computeVariantStyles(
|
|
791
|
-
config
|
|
783
|
+
config,
|
|
792
784
|
resolvedVariants,
|
|
793
785
|
skipStyleKeys,
|
|
794
786
|
);
|
|
@@ -827,46 +819,42 @@ export function create<M extends Mode = "jsx">({
|
|
|
827
819
|
const { className, style } = computeResult(props);
|
|
828
820
|
|
|
829
821
|
if (mode === "jsx") {
|
|
830
|
-
return { className, style: styleValueToJSXStyle(style) }
|
|
822
|
+
return { className, style: styleValueToJSXStyle(style) };
|
|
831
823
|
}
|
|
832
824
|
if (mode === "html") {
|
|
833
|
-
return {
|
|
834
|
-
class: className,
|
|
835
|
-
style: styleValueToHTMLStyle(style),
|
|
836
|
-
} as R;
|
|
825
|
+
return { class: className, style: styleValueToHTMLStyle(style) };
|
|
837
826
|
}
|
|
838
827
|
// htmlObj
|
|
839
|
-
return {
|
|
840
|
-
class: className,
|
|
841
|
-
style: styleValueToHTMLObjStyle(style),
|
|
842
|
-
} as R;
|
|
828
|
+
return { class: className, style: styleValueToHTMLObjStyle(style) };
|
|
843
829
|
}) as ModalComponent<MergedVariants, R>;
|
|
844
830
|
|
|
845
831
|
component.class = (props: ComponentProps<MergedVariants> = {}) => {
|
|
846
832
|
return computeResult(props).className;
|
|
847
833
|
};
|
|
848
834
|
|
|
849
|
-
component.style = (
|
|
835
|
+
component.style = (props: ComponentProps<MergedVariants> = {}) => {
|
|
850
836
|
const { style } = computeResult(props);
|
|
851
837
|
if (mode === "jsx") return styleValueToJSXStyle(style);
|
|
852
838
|
if (mode === "html") return styleValueToHTMLStyle(style);
|
|
853
839
|
return styleValueToHTMLObjStyle(style);
|
|
854
|
-
}) as ModalComponent<MergedVariants, R>["style"];
|
|
855
|
-
|
|
856
|
-
component.getVariants = (
|
|
857
|
-
variants?: VariantValues<MergedVariants>,
|
|
858
|
-
): VariantValues<MergedVariants> => {
|
|
859
|
-
return resolveVariants(
|
|
860
|
-
config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,
|
|
861
|
-
variants as VariantValues<Record<string, unknown>>,
|
|
862
|
-
) as VariantValues<MergedVariants>;
|
|
863
840
|
};
|
|
864
841
|
|
|
865
|
-
component.
|
|
866
|
-
|
|
867
|
-
|
|
842
|
+
component.getVariants = (variants?: VariantValues<MergedVariants>) => {
|
|
843
|
+
const variantProps = variants ?? {};
|
|
844
|
+
const resolvedVariants = resolveVariants(config, variantProps);
|
|
845
|
+
// Run computed function to get variants set via setVariants and
|
|
846
|
+
// setDefaultVariants
|
|
847
|
+
const { updatedVariants } = runComputedFunction(
|
|
848
|
+
config,
|
|
849
|
+
resolvedVariants,
|
|
850
|
+
variantProps,
|
|
851
|
+
);
|
|
852
|
+
return updatedVariants as VariantValues<MergedVariants>;
|
|
853
|
+
};
|
|
868
854
|
|
|
869
|
-
component.
|
|
855
|
+
component.keys = propsKeys;
|
|
856
|
+
component.variantKeys = variantKeys;
|
|
857
|
+
component.propKeys = propsKeys;
|
|
870
858
|
|
|
871
859
|
// Compute base class (without variants) - includes extended base classes
|
|
872
860
|
const extendedBaseClasses: ClassValue[] = [];
|
|
@@ -883,17 +871,13 @@ export function create<M extends Mode = "jsx">({
|
|
|
883
871
|
|
|
884
872
|
// Compute static defaults once at creation time (without triggering
|
|
885
873
|
// computed functions)
|
|
886
|
-
const staticDefaults = collectStaticDefaults(
|
|
887
|
-
config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,
|
|
888
|
-
);
|
|
874
|
+
const staticDefaults = collectStaticDefaults(config);
|
|
889
875
|
|
|
890
876
|
// Store internal metadata hidden from public types
|
|
891
877
|
setComponentMeta(component, {
|
|
892
878
|
baseClass,
|
|
893
879
|
staticDefaults,
|
|
894
|
-
resolveDefaults: createResolveDefaults(
|
|
895
|
-
config as CVConfig<Variants, ComputedVariants, AnyComponent[]>,
|
|
896
|
-
),
|
|
880
|
+
resolveDefaults: createResolveDefaults(config),
|
|
897
881
|
});
|
|
898
882
|
|
|
899
883
|
return component;
|
package/src/test.ts
CHANGED
|
@@ -1941,6 +1941,78 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1941
1941
|
expect(variants).toEqual({ size: "sm" });
|
|
1942
1942
|
});
|
|
1943
1943
|
|
|
1944
|
+
test("getVariants returns variants set by computed setVariants", () => {
|
|
1945
|
+
const component = getModalComponent(
|
|
1946
|
+
mode,
|
|
1947
|
+
cv({
|
|
1948
|
+
variants: {
|
|
1949
|
+
size: { sm: "sm", lg: "lg" },
|
|
1950
|
+
color: { red: "red", blue: "blue" },
|
|
1951
|
+
},
|
|
1952
|
+
computed: ({ variants, setVariants }) => {
|
|
1953
|
+
if (variants.size === "lg") {
|
|
1954
|
+
setVariants({ color: "red" });
|
|
1955
|
+
}
|
|
1956
|
+
},
|
|
1957
|
+
}),
|
|
1958
|
+
);
|
|
1959
|
+
const variants = component.getVariants({ size: "lg" });
|
|
1960
|
+
expect(variants).toEqual({ size: "lg", color: "red" });
|
|
1961
|
+
});
|
|
1962
|
+
|
|
1963
|
+
test("getVariants returns variants set by computed setDefaultVariants", () => {
|
|
1964
|
+
const component = getModalComponent(
|
|
1965
|
+
mode,
|
|
1966
|
+
cv({
|
|
1967
|
+
variants: {
|
|
1968
|
+
size: { sm: "sm", lg: "lg" },
|
|
1969
|
+
color: { red: "red", blue: "blue" },
|
|
1970
|
+
},
|
|
1971
|
+
computed: ({ variants, setDefaultVariants }) => {
|
|
1972
|
+
if (variants.size === "lg") {
|
|
1973
|
+
setDefaultVariants({ color: "blue" });
|
|
1974
|
+
}
|
|
1975
|
+
},
|
|
1976
|
+
}),
|
|
1977
|
+
);
|
|
1978
|
+
const variants = component.getVariants({ size: "lg" });
|
|
1979
|
+
expect(variants).toEqual({ size: "lg", color: "blue" });
|
|
1980
|
+
});
|
|
1981
|
+
|
|
1982
|
+
test("getVariants setDefaultVariants does not override props", () => {
|
|
1983
|
+
const component = getModalComponent(
|
|
1984
|
+
mode,
|
|
1985
|
+
cv({
|
|
1986
|
+
variants: {
|
|
1987
|
+
size: { sm: "sm", lg: "lg" },
|
|
1988
|
+
color: { red: "red", blue: "blue" },
|
|
1989
|
+
},
|
|
1990
|
+
computed: ({ setDefaultVariants }) => {
|
|
1991
|
+
setDefaultVariants({ color: "blue" });
|
|
1992
|
+
},
|
|
1993
|
+
}),
|
|
1994
|
+
);
|
|
1995
|
+
const variants = component.getVariants({ color: "red" });
|
|
1996
|
+
expect(variants).toEqual({ color: "red" });
|
|
1997
|
+
});
|
|
1998
|
+
|
|
1999
|
+
test("getVariants setVariants overrides props", () => {
|
|
2000
|
+
const component = getModalComponent(
|
|
2001
|
+
mode,
|
|
2002
|
+
cv({
|
|
2003
|
+
variants: {
|
|
2004
|
+
size: { sm: "sm", lg: "lg" },
|
|
2005
|
+
color: { red: "red", blue: "blue" },
|
|
2006
|
+
},
|
|
2007
|
+
computed: ({ setVariants }) => {
|
|
2008
|
+
setVariants({ color: "blue" });
|
|
2009
|
+
},
|
|
2010
|
+
}),
|
|
2011
|
+
);
|
|
2012
|
+
const variants = component.getVariants({ color: "red" });
|
|
2013
|
+
expect(variants).toEqual({ color: "blue" });
|
|
2014
|
+
});
|
|
2015
|
+
|
|
1944
2016
|
test("keys returns props keys", () => {
|
|
1945
2017
|
const component = getModalComponent(
|
|
1946
2018
|
mode,
|