responsive-class-variants 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -49,9 +49,10 @@ type VariantConfig = Record<string, VariantValue>;
|
|
|
49
49
|
type StringBoolean = "true" | "false";
|
|
50
50
|
type BooleanVariant = Partial<Record<StringBoolean, ClassValue | Record<string, ClassValue>>>;
|
|
51
51
|
type VariantPropValue<T, B extends string> = T extends BooleanVariant ? ResponsiveValue<boolean, B> | undefined : T extends Record<string, unknown> ? ResponsiveValue<keyof T, B> : never;
|
|
52
|
-
type
|
|
52
|
+
type VariantPropsBase<T extends VariantConfig, B extends string> = {
|
|
53
53
|
[K in keyof T]?: VariantPropValue<T[K], B>;
|
|
54
|
-
}
|
|
54
|
+
};
|
|
55
|
+
type VariantProps<T extends VariantConfig, B extends string> = VariantPropsBase<T, B> & {
|
|
55
56
|
className?: string;
|
|
56
57
|
};
|
|
57
58
|
type SlotConfig = ClassValue;
|
|
@@ -104,7 +105,7 @@ export declare const createRcv: <B extends string>(_breakpoints?: readonly B[],
|
|
|
104
105
|
compoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];
|
|
105
106
|
onComplete?: (classes: string) => string;
|
|
106
107
|
}): () => { [K in keyof S]: (props?: VariantProps<T, B>) => string; };
|
|
107
|
-
<T extends VariantConfig
|
|
108
|
+
<T extends VariantConfig = Record<never, VariantValue>>(config: {
|
|
108
109
|
base: string;
|
|
109
110
|
variants?: T;
|
|
110
111
|
compoundVariants?: Partial<VariantProps<T, B>>[];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAe5B,MAAM,eAAe,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CAAC;YAC3B,OAAO,GAAG,CAAU;gBACnB,GAAG,MAAM;gBACT,UAAU,EAAE,UAAU,IAAI,MAAM,CAAC,UAAU;aAM3C,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,OAAO,GAAG,CAAO;gBAChB,GAAG,MAAM;gBACT,UAAU,EAAE,UAAU,IAAI,MAAM,CAAC,UAAU;aAC3C,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { clsx } from \"clsx\";\n\nexport type DefaultBreakpoints = \"sm\" | \"md\" | \"lg\" | \"xl\";\nexport type Breakpoints = DefaultBreakpoints;\n\nexport type BreakpointsMap<V, B extends string = DefaultBreakpoints> = {\n\tinitial: V;\n} & Partial<{\n\t[breakpoint in B]: V;\n}>;\n\nexport type ResponsiveValue<T, B extends string = DefaultBreakpoints> =\n\t| T\n\t| BreakpointsMap<T, B>;\n\nconst isSingularValue = <A, B extends string>(\n\tvalue: ResponsiveValue<A, B>,\n): value is A => !isBreakpointsMap(value);\n\nconst isBreakpointsMap = <A, B extends string>(\n\tvalue: ResponsiveValue<A, B>,\n): value is BreakpointsMap<A, B> =>\n\ttypeof value === \"object\" && value != null && !Array.isArray(value);\n\n/**\n * Maps a ResponsiveValue to a new ResponsiveValue using the provided mapper function. Singular values are passed through as is.\n *\n * @template V The type of the original value\n * @template T The type of the mapped value\n * @template B The type of breakpoints\n * @param {ResponsiveValue<V, B>} value - The original ResponsiveValue to be mapped\n * @param {function(V): T} mapper - A function that maps a ResponsiveValue to a new ResponsiveValue\n * @returns {ResponsiveValue<T, B>} A new ResponsiveValue with the mapped values\n *\n *\n * @example\n * const sizes = {\n * initial: 'md',\n * sm: 'lg',\n * }\n *\n * const output = mapResponsiveValue(sizes, size => {\n *\tswitch (size) {\n *\t\tcase 'initial':\n *\t\treturn 'sm';\n *\t\tcase 'sm':\n *\t\t\treturn 'md';\n *\t\t}\n *\t});\n *\n * // console.log(output)\n * {\n *\tinitial: 'sm',\n *\tsm: 'md',\n * }\n */\nexport const mapResponsiveValue = <V, T, B extends string = DefaultBreakpoints>(\n\tvalue: ResponsiveValue<V, B>,\n\tmapper: (value: V) => T,\n): ResponsiveValue<T, B> =>\n\tisSingularValue(value)\n\t\t? mapper(value)\n\t\t: (Object.fromEntries(\n\t\t\t\tObject.entries(value).map(([breakpoint, value]) => [\n\t\t\t\t\tbreakpoint,\n\t\t\t\t\tmapper(value),\n\t\t\t\t]),\n\t\t\t) as BreakpointsMap<T, B>);\n\n/**\n * Start of rcv and types\n */\n\ntype ClassValue = string | ReadonlyArray<string>;\n\ntype ValueType = ClassValue | Record<string, ClassValue>;\n\ntype VariantValue = Record<string, ValueType>;\ntype VariantConfig = Record<string, VariantValue>;\n\ntype StringBoolean = \"true\" | \"false\";\ntype BooleanVariant = Partial<\n\tRecord<StringBoolean, ClassValue | Record<string, ClassValue>>\n>;\n\ntype VariantPropValue<T, B extends string> = T extends BooleanVariant\n\t? ResponsiveValue<boolean, B> | undefined\n\t: T extends Record<string, unknown>\n\t\t? ResponsiveValue<keyof T, B>\n\t\t: never;\n\ntype VariantProps<T extends VariantConfig, B extends string> = {\n\t[K in keyof T]?: VariantPropValue<T[K], B>;\n} & {\n\tclassName?: string;\n};\n\n// Slot configuration types\ntype SlotConfig = ClassValue;\n\ntype SlotsConfig<S extends Record<string, SlotConfig>> = S;\n\ntype CompoundVariantWithSlots<\n\tT extends VariantConfig,\n\tS extends string,\n\tB extends string,\n> = Partial<VariantProps<T, B>> & {\n\tclass?: Partial<Record<S, ClassValue>>;\n\tclassName?: string;\n};\n\ntype ResponsiveClassesConfigBase<T extends VariantConfig, B extends string> = {\n\tbase: string;\n\tvariants?: T;\n\tcompoundVariants?: Partial<VariantProps<T, B>>[];\n\tonComplete?: (classes: string) => string;\n};\n\ntype ResponsiveClassesConfigSlots<\n\tT extends VariantConfig,\n\tS extends Record<string, SlotConfig>,\n\tB extends string,\n> = {\n\tslots: SlotsConfig<S>;\n\tvariants?: T;\n\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\tonComplete?: (classes: string) => string;\n};\n\ntype ResponsiveClassesConfig<T extends VariantConfig, B extends string> =\n\t| ResponsiveClassesConfigBase<T, B>\n\t| ResponsiveClassesConfigSlots<T, Record<string, SlotConfig>, B>;\n\n// Helper functions for slots\nconst isSlotsConfig = <T extends VariantConfig, B extends string>(\n\tconfig: ResponsiveClassesConfig<T, B>,\n): config is ResponsiveClassesConfigSlots<T, Record<string, SlotConfig>, B> => {\n\treturn \"slots\" in config;\n};\n\nconst normalizeClassValue = (value: ClassValue | undefined) => {\n\tif (Array.isArray(value)) {\n\t\treturn value.join(\" \");\n\t}\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t}\n\treturn undefined;\n};\n\nconst prefixClasses = (classes: string, prefix: string) =>\n\tclasses\n\t\t.split(\" \")\n\t\t.map((className) => `${prefix}:${className}`)\n\t\t.join(\" \");\n\n// Helper function to get variant value for a specific slot or base\nconst getVariantValue = <T extends VariantConfig>(\n\tvariants: T | undefined,\n\tkey: keyof T,\n\tvalue: string,\n\tslotName?: string,\n): string | undefined => {\n\tconst variant = variants?.[key];\n\tconst variantValue = variant?.[value];\n\n\tif (typeof variantValue === \"string\" || Array.isArray(variantValue)) {\n\t\treturn normalizeClassValue(variantValue);\n\t}\n\n\tif (\n\t\ttypeof variantValue === \"object\" &&\n\t\tvariantValue !== null &&\n\t\tslotName &&\n\t\tslotName in variantValue\n\t) {\n\t\tconst slotSpecificValue = (variantValue as Record<string, ClassValue>)[\n\t\t\tslotName\n\t\t];\n\t\treturn normalizeClassValue(slotSpecificValue);\n\t}\n\n\treturn undefined;\n};\n\n// Helper function to process responsive values\nconst processResponsiveValue = <T extends VariantConfig, B extends string>(\n\tvariants: T | undefined,\n\tkey: keyof T,\n\tvalue: Partial<BreakpointsMap<T, B>>,\n\tslotName?: string,\n) => {\n\treturn Object.entries(value)\n\t\t.map(([breakpoint, breakpointValue]) => {\n\t\t\tconst variantValue = getVariantValue(\n\t\t\t\tvariants,\n\t\t\t\tkey,\n\t\t\t\tbreakpointValue as string,\n\t\t\t\tslotName,\n\t\t\t);\n\n\t\t\tif (!variantValue) return undefined;\n\n\t\t\t// If the breakpoint is initial, return without prefix\n\t\t\tif (breakpoint === \"initial\") {\n\t\t\t\treturn variantValue;\n\t\t\t}\n\n\t\t\t// Otherwise, return with breakpoint prefix\n\t\t\treturn prefixClasses(variantValue, breakpoint);\n\t\t})\n\t\t.filter(Boolean)\n\t\t.join(\" \");\n};\n\n// Helper function to process variant props into classes\nconst processVariantProps = <T extends VariantConfig, B extends string>(\n\tprops: Omit<VariantProps<T, B>, \"className\">,\n\tvariants: T | undefined,\n\tslotName?: string,\n) => {\n\treturn Object.entries(props)\n\t\t.map(([key, propValue]: [keyof T, VariantPropValue<T[keyof T], B>]) => {\n\t\t\tconst value =\n\t\t\t\ttypeof propValue === \"boolean\" ? String(propValue) : propValue;\n\n\t\t\t// Handle undefined values\n\t\t\tif (!value) return undefined;\n\n\t\t\t// Handle singular values\n\t\t\tif (typeof value === \"string\") {\n\t\t\t\treturn getVariantValue(variants, key, value, slotName);\n\t\t\t}\n\n\t\t\t// Handle responsive values\n\t\t\treturn processResponsiveValue(\n\t\t\t\tvariants,\n\t\t\t\tkey,\n\t\t\t\tvalue as Partial<BreakpointsMap<T, B>>,\n\t\t\t\tslotName,\n\t\t\t);\n\t\t})\n\t\t.filter(Boolean)\n\t\t.join(\" \");\n};\n\n// Helper function to match compound variants\nconst matchesCompoundVariant = <T extends VariantConfig, B extends string>(\n\tcompound: Omit<CompoundVariantWithSlots<T, string, B>, \"className\" | \"class\">,\n\tprops: Omit<VariantProps<T, B>, \"className\">,\n) => {\n\treturn Object.entries(compound).every(\n\t\t([key, value]) =>\n\t\t\tprops[key as keyof typeof props] === String(value) ||\n\t\t\tprops[key as keyof typeof props] === value,\n\t);\n};\n\nconst createSlotFunction =\n\t<T extends VariantConfig, B extends string>(\n\t\tslotConfig: SlotConfig,\n\t\tvariants: T | undefined,\n\t\tcompoundVariants: CompoundVariantWithSlots<T, string, B>[] | undefined,\n\t\tonComplete: ((classes: string) => string) | undefined,\n\t\tslotName: string,\n\t) =>\n\t({ className, ...props }: VariantProps<T, B> = {} as VariantProps<T, B>) => {\n\t\tconst responsiveClasses = processVariantProps(props, variants, slotName);\n\n\t\tconst compoundClasses = compoundVariants\n\t\t\t?.map(\n\t\t\t\t({ class: slotClasses, className: compoundClassName, ...compound }) => {\n\t\t\t\t\tif (matchesCompoundVariant(compound, props)) {\n\t\t\t\t\t\t// If compound variant has slot-specific classes, use those for this slot\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tslotClasses &&\n\t\t\t\t\t\t\ttypeof slotClasses === \"object\" &&\n\t\t\t\t\t\t\tslotClasses[slotName]\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn normalizeClassValue(slotClasses[slotName]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise use the general className\n\t\t\t\t\t\treturn compoundClassName;\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t)\n\t\t\t.filter(Boolean);\n\n\t\tconst classes = clsx(\n\t\t\tslotConfig,\n\t\t\tresponsiveClasses,\n\t\t\tcompoundClasses,\n\t\t\tclassName,\n\t\t);\n\t\treturn onComplete ? onComplete(classes) : classes;\n\t};\n\n// Function overloads for rcv\nexport function rcv<\n\tT extends VariantConfig = Record<never, VariantValue>,\n\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\tB extends string = DefaultBreakpoints,\n>(config: {\n\tslots: S;\n\tvariants?: T;\n\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\tonComplete?: (classes: string) => string;\n}): () => {\n\t[K in keyof S]: (props?: VariantProps<T, B>) => string;\n};\n\nexport function rcv<\n\tT extends VariantConfig = Record<never, VariantValue>,\n\tB extends string = DefaultBreakpoints,\n>(config: {\n\tbase: string;\n\tvariants?: T;\n\tcompoundVariants?: Partial<VariantProps<T, B>>[];\n\tonComplete?: (classes: string) => string;\n}): (props?: VariantProps<T, B>) => string;\n\nexport function rcv<\n\tT extends VariantConfig = Record<never, VariantValue>,\n\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\tB extends string = DefaultBreakpoints,\n>(\n\tconfig:\n\t\t| ResponsiveClassesConfig<T, B>\n\t\t| {\n\t\t\t\tslots: S;\n\t\t\t\tvariants?: T;\n\t\t\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\t\t\tonComplete?: (classes: string) => string;\n\t\t },\n) {\n\t// Check if config is a slots config\n\tif (isSlotsConfig(config)) {\n\t\tconst { slots, variants, compoundVariants, onComplete } = config;\n\t\treturn () => {\n\t\t\tconst slotFunctions = {} as {\n\t\t\t\t[K in keyof S]: (props?: VariantProps<T, B>) => string;\n\t\t\t};\n\n\t\t\t// Create slot functions for each slot - ensure all slots are always present\n\t\t\tfor (const [slotName, slotConfig] of Object.entries(slots)) {\n\t\t\t\tconst slotFunction = createSlotFunction<T, B>(\n\t\t\t\t\tslotConfig,\n\t\t\t\t\tvariants,\n\t\t\t\t\tcompoundVariants,\n\t\t\t\t\tonComplete,\n\t\t\t\t\tslotName,\n\t\t\t\t);\n\n\t\t\t\tslotFunctions[slotName as keyof S] = slotFunction;\n\t\t\t}\n\n\t\t\treturn slotFunctions;\n\t\t};\n\t}\n\n\t// If config is not a slots config, create a base function\n\tconst { base, variants, compoundVariants, onComplete } = config;\n\treturn (\n\t\t{ className, ...props }: VariantProps<T, B> = {} as VariantProps<T, B>,\n\t) => {\n\t\tconst responsiveClasses = processVariantProps(props, variants);\n\n\t\tconst compoundClasses = compoundVariants\n\t\t\t?.map(({ className: compoundClassName, ...compound }) => {\n\t\t\t\tif (\n\t\t\t\t\tmatchesCompoundVariant(\n\t\t\t\t\t\tcompound as Omit<\n\t\t\t\t\t\t\tCompoundVariantWithSlots<T, string, B>,\n\t\t\t\t\t\t\t\"className\" | \"class\"\n\t\t\t\t\t\t>,\n\t\t\t\t\t\tprops,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn compoundClassName;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t})\n\t\t\t.filter(Boolean);\n\n\t\tconst classes = clsx(base, responsiveClasses, compoundClasses, className);\n\t\treturn onComplete ? onComplete(classes) : classes;\n\t};\n}\n\n/**\n * Creates a custom rcv function with custom breakpoints and an optional onComplete callback\n *\n * @template B - The custom breakpoints type\n * @param breakpoints - Optional array of custom breakpoint names\n * @param onComplete - Optional callback function that receives the generated classes and returns the final classes\n * @returns A function that creates rcv with custom breakpoints\n *\n * @example\n * const customRcv = createRcv(['mobile', 'tablet', 'desktop']);\n *\n * const getButtonVariants = customRcv({\n * base: \"px-4 py-2 rounded\",\n * variants: {\n * intent: {\n * primary: \"bg-blue-500 text-white\",\n * secondary: \"bg-gray-200 text-gray-800\"\n * }\n * }\n * });\n *\n * // Usage with custom breakpoints:\n * getButtonVariants({ intent: { initial: \"primary\", mobile: \"secondary\", desktop: \"primary\" } })\n */\n\nexport const createRcv = <B extends string>(\n\t_breakpoints?: readonly B[],\n\tonComplete?: (classes: string) => string,\n) => {\n\tfunction customRcv<\n\t\tT extends VariantConfig = Record<never, VariantValue>,\n\t\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\t>(config: {\n\t\tslots: S;\n\t\tvariants?: T;\n\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\tonComplete?: (classes: string) => string;\n\t}): () => {\n\t\t[K in keyof S]: (props?: VariantProps<T, B>) => string;\n\t};\n\n\tfunction customRcv<T extends VariantConfig>(config: {\n\t\tbase: string;\n\t\tvariants?: T;\n\t\tcompoundVariants?: Partial<VariantProps<T, B>>[];\n\t\tonComplete?: (classes: string) => string;\n\t}): (props?: VariantProps<T, B>) => string;\n\n\tfunction customRcv<\n\t\tT extends VariantConfig,\n\t\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\t>(\n\t\tconfig:\n\t\t\t| ResponsiveClassesConfig<T, B>\n\t\t\t| {\n\t\t\t\t\tslots: S;\n\t\t\t\t\tvariants?: T;\n\t\t\t\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\t\t\t\tonComplete?: (classes: string) => string;\n\t\t\t },\n\t) {\n\t\tif (isSlotsConfig(config)) {\n\t\t\treturn rcv<T, S, B>({\n\t\t\t\t...config,\n\t\t\t\tonComplete: onComplete || config.onComplete,\n\t\t\t} as {\n\t\t\t\tslots: S;\n\t\t\t\tvariants?: T;\n\t\t\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\t\t\tonComplete?: (classes: string) => string;\n\t\t\t});\n\t\t} else {\n\t\t\treturn rcv<T, B>({\n\t\t\t\t...config,\n\t\t\t\tonComplete: onComplete || config.onComplete,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn customRcv;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAe5B,MAAM,eAAe,GAAG,CACvB,KAA4B,EACf,EAAE,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAE1C,MAAM,gBAAgB,GAAG,CACxB,KAA4B,EACI,EAAE,CAClC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,KAA4B,EAC5B,MAAuB,EACC,EAAE,CAC1B,eAAe,CAAC,KAAK,CAAC;IACrB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IACf,CAAC,CAAE,MAAM,CAAC,WAAW,CACnB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B,GAAG,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE/D,MAAM,eAAe,GAAG,gBAAgB;YACvC,EAAE,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,QAAQ,EAAE,EAAE,EAAE;YACvD,IACC,sBAAsB,CACrB,QAGC,EACD,KAAK,CACL,EACA,CAAC;gBACF,OAAO,iBAAiB,CAAC;YAC1B,CAAC;YACD,OAAO,SAAS,CAAC;QAClB,CAAC,CAAC;aACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAElB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,iBAAiB,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;QAC1E,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACnD,CAAC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CACxB,YAA2B,EAC3B,UAAwC,EACvC,EAAE;IAsBH,SAAS,SAAS,CAIjB,MAOI;QAEJ,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,OAAO,GAAG,CAAU;gBACnB,GAAG,MAAM;gBACT,UAAU,EAAE,UAAU,IAAI,MAAM,CAAC,UAAU;aAM3C,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,OAAO,GAAG,CAAO;gBAChB,GAAG,MAAM;gBACT,UAAU,EAAE,UAAU,IAAI,MAAM,CAAC,UAAU;aAC3C,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { clsx } from \"clsx\";\n\nexport type DefaultBreakpoints = \"sm\" | \"md\" | \"lg\" | \"xl\";\nexport type Breakpoints = DefaultBreakpoints;\n\nexport type BreakpointsMap<V, B extends string = DefaultBreakpoints> = {\n\tinitial: V;\n} & Partial<{\n\t[breakpoint in B]: V;\n}>;\n\nexport type ResponsiveValue<T, B extends string = DefaultBreakpoints> =\n\t| T\n\t| BreakpointsMap<T, B>;\n\nconst isSingularValue = <A, B extends string>(\n\tvalue: ResponsiveValue<A, B>,\n): value is A => !isBreakpointsMap(value);\n\nconst isBreakpointsMap = <A, B extends string>(\n\tvalue: ResponsiveValue<A, B>,\n): value is BreakpointsMap<A, B> =>\n\ttypeof value === \"object\" && value != null && !Array.isArray(value);\n\n/**\n * Maps a ResponsiveValue to a new ResponsiveValue using the provided mapper function. Singular values are passed through as is.\n *\n * @template V The type of the original value\n * @template T The type of the mapped value\n * @template B The type of breakpoints\n * @param {ResponsiveValue<V, B>} value - The original ResponsiveValue to be mapped\n * @param {function(V): T} mapper - A function that maps a ResponsiveValue to a new ResponsiveValue\n * @returns {ResponsiveValue<T, B>} A new ResponsiveValue with the mapped values\n *\n *\n * @example\n * const sizes = {\n * initial: 'md',\n * sm: 'lg',\n * }\n *\n * const output = mapResponsiveValue(sizes, size => {\n *\tswitch (size) {\n *\t\tcase 'initial':\n *\t\treturn 'sm';\n *\t\tcase 'sm':\n *\t\t\treturn 'md';\n *\t\t}\n *\t});\n *\n * // console.log(output)\n * {\n *\tinitial: 'sm',\n *\tsm: 'md',\n * }\n */\nexport const mapResponsiveValue = <V, T, B extends string = DefaultBreakpoints>(\n\tvalue: ResponsiveValue<V, B>,\n\tmapper: (value: V) => T,\n): ResponsiveValue<T, B> =>\n\tisSingularValue(value)\n\t\t? mapper(value)\n\t\t: (Object.fromEntries(\n\t\t\t\tObject.entries(value).map(([breakpoint, value]) => [\n\t\t\t\t\tbreakpoint,\n\t\t\t\t\tmapper(value),\n\t\t\t\t]),\n\t\t\t) as BreakpointsMap<T, B>);\n\n/**\n * Start of rcv and types\n */\n\ntype ClassValue = string | ReadonlyArray<string>;\n\ntype ValueType = ClassValue | Record<string, ClassValue>;\n\ntype VariantValue = Record<string, ValueType>;\ntype VariantConfig = Record<string, VariantValue>;\n\ntype StringBoolean = \"true\" | \"false\";\ntype BooleanVariant = Partial<\n\tRecord<StringBoolean, ClassValue | Record<string, ClassValue>>\n>;\n\ntype VariantPropValue<T, B extends string> = T extends BooleanVariant\n\t? ResponsiveValue<boolean, B> | undefined\n\t: T extends Record<string, unknown>\n\t\t? ResponsiveValue<keyof T, B>\n\t\t: never;\n\ntype VariantPropsBase<T extends VariantConfig, B extends string> = {\n\t[K in keyof T]?: VariantPropValue<T[K], B>;\n};\n\ntype VariantProps<T extends VariantConfig, B extends string> = VariantPropsBase<\n\tT,\n\tB\n> & {\n\tclassName?: string;\n};\n\n// Slot configuration types\ntype SlotConfig = ClassValue;\n\ntype SlotsConfig<S extends Record<string, SlotConfig>> = S;\n\ntype CompoundVariantWithSlots<\n\tT extends VariantConfig,\n\tS extends string,\n\tB extends string,\n> = Partial<VariantProps<T, B>> & {\n\tclass?: Partial<Record<S, ClassValue>>;\n\tclassName?: string;\n};\n\ntype ResponsiveClassesConfigBase<T extends VariantConfig, B extends string> = {\n\tbase: string;\n\tvariants?: T;\n\tcompoundVariants?: Partial<VariantProps<T, B>>[];\n\tonComplete?: (classes: string) => string;\n};\n\ntype ResponsiveClassesConfigSlots<\n\tT extends VariantConfig,\n\tS extends Record<string, SlotConfig>,\n\tB extends string,\n> = {\n\tslots: SlotsConfig<S>;\n\tvariants?: T;\n\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\tonComplete?: (classes: string) => string;\n};\n\ntype ResponsiveClassesConfig<T extends VariantConfig, B extends string> =\n\t| ResponsiveClassesConfigBase<T, B>\n\t| ResponsiveClassesConfigSlots<T, Record<string, SlotConfig>, B>;\n\n// Helper functions for slots\nconst isSlotsConfig = <T extends VariantConfig, B extends string>(\n\tconfig: ResponsiveClassesConfig<T, B>,\n): config is ResponsiveClassesConfigSlots<T, Record<string, SlotConfig>, B> => {\n\treturn \"slots\" in config;\n};\n\nconst normalizeClassValue = (value: ClassValue | undefined) => {\n\tif (Array.isArray(value)) {\n\t\treturn value.join(\" \");\n\t}\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t}\n\treturn undefined;\n};\n\nconst prefixClasses = (classes: string, prefix: string) =>\n\tclasses\n\t\t.split(\" \")\n\t\t.map((className) => `${prefix}:${className}`)\n\t\t.join(\" \");\n\n// Helper function to get variant value for a specific slot or base\nconst getVariantValue = <T extends VariantConfig>(\n\tvariants: T | undefined,\n\tkey: keyof T,\n\tvalue: string,\n\tslotName?: string,\n): string | undefined => {\n\tconst variant = variants?.[key];\n\tconst variantValue = variant?.[value];\n\n\tif (typeof variantValue === \"string\" || Array.isArray(variantValue)) {\n\t\treturn normalizeClassValue(variantValue);\n\t}\n\n\tif (\n\t\ttypeof variantValue === \"object\" &&\n\t\tvariantValue !== null &&\n\t\tslotName &&\n\t\tslotName in variantValue\n\t) {\n\t\tconst slotSpecificValue = (variantValue as Record<string, ClassValue>)[\n\t\t\tslotName\n\t\t];\n\t\treturn normalizeClassValue(slotSpecificValue);\n\t}\n\n\treturn undefined;\n};\n\n// Helper function to process responsive values\nconst processResponsiveValue = <T extends VariantConfig, B extends string>(\n\tvariants: T | undefined,\n\tkey: keyof T,\n\tvalue: Partial<BreakpointsMap<T, B>>,\n\tslotName?: string,\n) => {\n\treturn Object.entries(value)\n\t\t.map(([breakpoint, breakpointValue]) => {\n\t\t\tconst variantValue = getVariantValue(\n\t\t\t\tvariants,\n\t\t\t\tkey,\n\t\t\t\tbreakpointValue as string,\n\t\t\t\tslotName,\n\t\t\t);\n\n\t\t\tif (!variantValue) return undefined;\n\n\t\t\t// If the breakpoint is initial, return without prefix\n\t\t\tif (breakpoint === \"initial\") {\n\t\t\t\treturn variantValue;\n\t\t\t}\n\n\t\t\t// Otherwise, return with breakpoint prefix\n\t\t\treturn prefixClasses(variantValue, breakpoint);\n\t\t})\n\t\t.filter(Boolean)\n\t\t.join(\" \");\n};\n\n// Helper function to process variant props into classes\nconst processVariantProps = <T extends VariantConfig, B extends string>(\n\tprops: Omit<VariantProps<T, B>, \"className\">,\n\tvariants: T | undefined,\n\tslotName?: string,\n) => {\n\treturn Object.entries(props)\n\t\t.map(([key, propValue]: [keyof T, VariantPropValue<T[keyof T], B>]) => {\n\t\t\tconst value =\n\t\t\t\ttypeof propValue === \"boolean\" ? String(propValue) : propValue;\n\n\t\t\t// Handle undefined values\n\t\t\tif (!value) return undefined;\n\n\t\t\t// Handle singular values\n\t\t\tif (typeof value === \"string\") {\n\t\t\t\treturn getVariantValue(variants, key, value, slotName);\n\t\t\t}\n\n\t\t\t// Handle responsive values\n\t\t\treturn processResponsiveValue(\n\t\t\t\tvariants,\n\t\t\t\tkey,\n\t\t\t\tvalue as Partial<BreakpointsMap<T, B>>,\n\t\t\t\tslotName,\n\t\t\t);\n\t\t})\n\t\t.filter(Boolean)\n\t\t.join(\" \");\n};\n\n// Helper function to match compound variants\nconst matchesCompoundVariant = <T extends VariantConfig, B extends string>(\n\tcompound: Omit<CompoundVariantWithSlots<T, string, B>, \"className\" | \"class\">,\n\tprops: Omit<VariantProps<T, B>, \"className\">,\n) => {\n\treturn Object.entries(compound).every(\n\t\t([key, value]) =>\n\t\t\tprops[key as keyof typeof props] === String(value) ||\n\t\t\tprops[key as keyof typeof props] === value,\n\t);\n};\n\nconst createSlotFunction =\n\t<T extends VariantConfig, B extends string>(\n\t\tslotConfig: SlotConfig,\n\t\tvariants: T | undefined,\n\t\tcompoundVariants: CompoundVariantWithSlots<T, string, B>[] | undefined,\n\t\tonComplete: ((classes: string) => string) | undefined,\n\t\tslotName: string,\n\t) =>\n\t({ className, ...props }: VariantProps<T, B> = {} as VariantProps<T, B>) => {\n\t\tconst responsiveClasses = processVariantProps(props, variants, slotName);\n\n\t\tconst compoundClasses = compoundVariants\n\t\t\t?.map(\n\t\t\t\t({ class: slotClasses, className: compoundClassName, ...compound }) => {\n\t\t\t\t\tif (matchesCompoundVariant(compound, props)) {\n\t\t\t\t\t\t// If compound variant has slot-specific classes, use those for this slot\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tslotClasses &&\n\t\t\t\t\t\t\ttypeof slotClasses === \"object\" &&\n\t\t\t\t\t\t\tslotClasses[slotName]\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn normalizeClassValue(slotClasses[slotName]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise use the general className\n\t\t\t\t\t\treturn compoundClassName;\n\t\t\t\t\t}\n\t\t\t\t\treturn undefined;\n\t\t\t\t},\n\t\t\t)\n\t\t\t.filter(Boolean);\n\n\t\tconst classes = clsx(\n\t\t\tslotConfig,\n\t\t\tresponsiveClasses,\n\t\t\tcompoundClasses,\n\t\t\tclassName,\n\t\t);\n\t\treturn onComplete ? onComplete(classes) : classes;\n\t};\n\n// Function overloads for rcv\nexport function rcv<\n\tT extends VariantConfig = Record<never, VariantValue>,\n\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\tB extends string = DefaultBreakpoints,\n>(config: {\n\tslots: S;\n\tvariants?: T;\n\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\tonComplete?: (classes: string) => string;\n}): () => {\n\t[K in keyof S]: (props?: VariantProps<T, B>) => string;\n};\n\nexport function rcv<\n\tT extends VariantConfig = Record<never, VariantValue>,\n\tB extends string = DefaultBreakpoints,\n>(config: {\n\tbase: string;\n\tvariants?: T;\n\tcompoundVariants?: Partial<VariantProps<T, B>>[];\n\tonComplete?: (classes: string) => string;\n}): (props?: VariantProps<T, B>) => string;\n\nexport function rcv<\n\tT extends VariantConfig = Record<never, VariantValue>,\n\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\tB extends string = DefaultBreakpoints,\n>(\n\tconfig:\n\t\t| ResponsiveClassesConfig<T, B>\n\t\t| {\n\t\t\t\tslots: S;\n\t\t\t\tvariants?: T;\n\t\t\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\t\t\tonComplete?: (classes: string) => string;\n\t\t },\n) {\n\t// Check if config is a slots config\n\tif (isSlotsConfig(config)) {\n\t\tconst { slots, variants, compoundVariants, onComplete } = config;\n\t\treturn () => {\n\t\t\tconst slotFunctions = {} as {\n\t\t\t\t[K in keyof S]: (props?: VariantProps<T, B>) => string;\n\t\t\t};\n\n\t\t\t// Create slot functions for each slot - ensure all slots are always present\n\t\t\tfor (const [slotName, slotConfig] of Object.entries(slots)) {\n\t\t\t\tconst slotFunction = createSlotFunction<T, B>(\n\t\t\t\t\tslotConfig,\n\t\t\t\t\tvariants,\n\t\t\t\t\tcompoundVariants,\n\t\t\t\t\tonComplete,\n\t\t\t\t\tslotName,\n\t\t\t\t);\n\n\t\t\t\tslotFunctions[slotName as keyof S] = slotFunction;\n\t\t\t}\n\n\t\t\treturn slotFunctions;\n\t\t};\n\t}\n\n\t// If config is not a slots config, create a base function\n\tconst { base, variants, compoundVariants, onComplete } = config;\n\treturn (\n\t\t{ className, ...props }: VariantProps<T, B> = {} as VariantProps<T, B>,\n\t) => {\n\t\tconst responsiveClasses = processVariantProps(props, variants);\n\n\t\tconst compoundClasses = compoundVariants\n\t\t\t?.map(({ className: compoundClassName, ...compound }) => {\n\t\t\t\tif (\n\t\t\t\t\tmatchesCompoundVariant(\n\t\t\t\t\t\tcompound as Omit<\n\t\t\t\t\t\t\tCompoundVariantWithSlots<T, string, B>,\n\t\t\t\t\t\t\t\"className\" | \"class\"\n\t\t\t\t\t\t>,\n\t\t\t\t\t\tprops,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn compoundClassName;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t})\n\t\t\t.filter(Boolean);\n\n\t\tconst classes = clsx(base, responsiveClasses, compoundClasses, className);\n\t\treturn onComplete ? onComplete(classes) : classes;\n\t};\n}\n\n/**\n * Creates a custom rcv function with custom breakpoints and an optional onComplete callback\n *\n * @template B - The custom breakpoints type\n * @param breakpoints - Optional array of custom breakpoint names\n * @param onComplete - Optional callback function that receives the generated classes and returns the final classes\n * @returns A function that creates rcv with custom breakpoints\n *\n * @example\n * const customRcv = createRcv(['mobile', 'tablet', 'desktop']);\n *\n * const getButtonVariants = customRcv({\n * base: \"px-4 py-2 rounded\",\n * variants: {\n * intent: {\n * primary: \"bg-blue-500 text-white\",\n * secondary: \"bg-gray-200 text-gray-800\"\n * }\n * }\n * });\n *\n * // Usage with custom breakpoints:\n * getButtonVariants({ intent: { initial: \"primary\", mobile: \"secondary\", desktop: \"primary\" } })\n */\n\nexport const createRcv = <B extends string>(\n\t_breakpoints?: readonly B[],\n\tonComplete?: (classes: string) => string,\n) => {\n\tfunction customRcv<\n\t\tT extends VariantConfig = Record<never, VariantValue>,\n\t\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\t>(config: {\n\t\tslots: S;\n\t\tvariants?: T;\n\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\tonComplete?: (classes: string) => string;\n\t}): () => {\n\t\t[K in keyof S]: (props?: VariantProps<T, B>) => string;\n\t};\n\n\tfunction customRcv<\n\t\tT extends VariantConfig = Record<never, VariantValue>,\n\t>(config: {\n\t\tbase: string;\n\t\tvariants?: T;\n\t\tcompoundVariants?: Partial<VariantProps<T, B>>[];\n\t\tonComplete?: (classes: string) => string;\n\t}): (props?: VariantProps<T, B>) => string;\n\n\tfunction customRcv<\n\t\tT extends VariantConfig = Record<never, VariantValue>,\n\t\tS extends Record<string, SlotConfig> = Record<string, SlotConfig>,\n\t>(\n\t\tconfig:\n\t\t\t| ResponsiveClassesConfig<T, B>\n\t\t\t| {\n\t\t\t\t\tslots: S;\n\t\t\t\t\tvariants?: T;\n\t\t\t\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\t\t\t\tonComplete?: (classes: string) => string;\n\t\t\t },\n\t) {\n\t\tif (isSlotsConfig(config)) {\n\t\t\treturn rcv<T, S, B>({\n\t\t\t\t...config,\n\t\t\t\tonComplete: onComplete || config.onComplete,\n\t\t\t} as {\n\t\t\t\tslots: S;\n\t\t\t\tvariants?: T;\n\t\t\t\tcompoundVariants?: CompoundVariantWithSlots<T, keyof S & string, B>[];\n\t\t\t\tonComplete?: (classes: string) => string;\n\t\t\t});\n\t\t} else {\n\t\t\treturn rcv<T, B>({\n\t\t\t\t...config,\n\t\t\t\tonComplete: onComplete || config.onComplete,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn customRcv;\n};\n"]}
|