/** Keys to exclude from variant configurations. Currently includes `'defaultVariants'` and `''`. */ type ExcludeKeys = 'defaultVariants' | ''; /** Utility type to exclude `undefined` from a given type `T`. */ type Undefined = T extends undefined ? never : T; /** * Extracts the properties of the first argument of a given function type `T`, excluding `ExcludeKeys`. * @example * @docs {@link https://ilkhoeri.github.io/xuxi/cvx#cvxvariants Docs} */ type cvxVariants any> = Omit[0]>, ExcludeKeys>; /** * Extracts the value of a variant from the first argument based on the key value. * @example * @docs {@link https://ilkhoeri.github.io/xuxi/cvx#cvxvariant Docs} */ type cvxVariant any, K extends keyof cvxVariants> = NonNullable[K]>; /** A value that can be returned by a variant. Arrays contain only strings or only numbers. */ type cvxValue = string | string[] | number | number[] | Record; /** A value that can be used as a base assignment. */ type cvxAssign = string | string[] | number[] | Record; /** Describes a structure for variant configurations and their possible return values. */ type cvxKeys = {[key: string]: { [key: string]: cvxValue;}; }; /** Casts string keys to primitive values if they match known literals. */ type cvxPrimitiveCast = T extends 'true' ? boolean : T extends 'false' ? boolean : T extends 'null' ? null : T extends 'undefined' ? undefined : T extends 'Infinity' ? typeof Infinity : T extends 'NaN' ? typeof NaN : T extends `${infer N extends number}` ? N : T; /** Utility type to remove index signatures */ type RemoveIndexSignature = {[K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K];}; /** Variant result type that infers primitive equivalents from string keys. * @example * @see {@link https://ilkhoeri.github.io/xuxi/cvx#cvx-types https://ilkhoeri.github.io/xuxi/cvx#cvx-types} */ type cvxResult = {[K in keyof RemoveIndexSignature]?: cvxPrimitiveCast;}; /** Widens primitive literals and string tuples while retaining object shapes. */ type cvxWiden = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends string[] ? string[] : T extends Record ? {[K in keyof T]: cvxWiden;} : T; /** The value returned by a configured variant. */ type cvxReturn = cvxWiden<{[K in keyof T]: T[K][keyof T[K]];}[keyof T]>; /** The value returned when a base assignment is configured. */ type cvxAssignedReturn = A extends Record ? ([ Extract, Record> ] extends [ never ] ? cvxWiden : cvxWiden & Extract, Record>) : cvxWiden; /** * Configuration object for defining variants and their options. * @property `string` `[assign]` - An optional base class name to prepend to the generated string. * @property `T` variants - Defines the variant keys and their possible values. * @property `cvxResult` `[defaultVariants]` - Optional default variant mappings. */ interface cvxRecord {variants: T; defaultVariants?: cvxResult;} interface cvxAssignedRecord {/** * assign sekarang mendukung `string`, `string[]`, `number[]`, dan `object`. * - `Object`: assign digabung dengan object variant; nilai variant menimpa key yang sama. * - `Array`: assign hanya digabung dengan array variant yang tipe elemennya sama (`string[]` dengan `string[]`, `number[]` dengan `number[]`). * - `String`: assign hanya digabung dengan variant string. * - Jika assign tidak didefinisikan, perilaku cvx dinamis sebelumnya tetap berlaku. */ assign: A; variants: T; defaultVariants?: cvxResult;} /** * A utility function for managing values based on variant configurations. * * @template T - The type of variant keys and their possible values. * @param {cvxRecord} keys - The configuration object containing: * - `assign` (optional): A base value to always include. * - `variants`: An object defining variant keys and their possible values as classes. * - `defaultVariants` (optional): Default variant values for each variant key. * @returns A function that takes a `variants` object to override default variants. String values are combined as class * names; object and string-array values are returned as their native values. * @example * @docs {@link https://ilkhoeri.github.io/xuxi/cvx https://ilkhoeri.github.io/xuxi/cvx} */ declare function cvx(keys: cvxAssignedRecord): (vars?: cvxResult) => cvxAssignedReturn; declare function cvx(keys: cvxRecord): (vars?: cvxResult) => cvxReturn; export {cvx}; export type {cvxAssign, cvxKeys, cvxPrimitiveCast, cvxRecord, cvxResult, cvxValue, cvxVariant, cvxVariants};