@yaredfall/class-variants 0.4.0-rc → 0.6.0-rc.1
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/build/chunk-77XW3WZ4.js +2 -0
- package/build/chunk-77XW3WZ4.js.map +1 -0
- package/build/chunk-AQKDS5WX.js +2 -0
- package/build/chunk-AQKDS5WX.js.map +1 -0
- package/build/chunk-FIET564E.js +2 -0
- package/build/chunk-FIET564E.js.map +1 -0
- package/build/chunk-IMTFPGTY.js +2 -0
- package/build/chunk-IMTFPGTY.js.map +1 -0
- package/build/chunk-UUT6STP6.js +2 -0
- package/build/chunk-UUT6STP6.js.map +1 -0
- package/build/chunk-XWAQU5O6.js +2 -0
- package/build/chunk-XWAQU5O6.js.map +1 -0
- package/build/cn.cjs +2 -0
- package/build/cn.cjs.map +1 -0
- package/build/cn.d.cts +11 -0
- package/build/cn.d.ts +11 -0
- package/build/cn.js +2 -0
- package/build/cn.js.map +1 -0
- package/build/cv--G8-bDtP.d.ts +78 -0
- package/build/cv-gIK0IznJ.d.cts +78 -0
- package/build/cv.cjs +2 -0
- package/build/cv.cjs.map +1 -0
- package/build/cv.d.cts +4 -0
- package/build/cv.d.ts +4 -0
- package/build/cv.js +2 -0
- package/build/cv.js.map +1 -0
- package/build/define.cjs +2 -0
- package/build/define.cjs.map +1 -0
- package/build/define.d.cts +19 -0
- package/build/define.d.ts +19 -0
- package/build/define.js +2 -0
- package/build/define.js.map +1 -0
- package/build/extend.cjs +2 -0
- package/build/extend.cjs.map +1 -0
- package/build/extend.d.cts +21 -0
- package/build/extend.d.ts +21 -0
- package/build/extend.js +2 -0
- package/build/extend.js.map +1 -0
- package/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +17 -3
- package/build/index.d.ts +17 -3
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/tokens.cjs +2 -0
- package/build/tokens.cjs.map +1 -0
- package/build/tokens.d.cts +4 -0
- package/build/tokens.d.ts +4 -0
- package/build/tokens.js +2 -0
- package/build/tokens.js.map +1 -0
- package/build/utils.cjs +1 -1
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +2 -1
- package/build/utils.d.ts +2 -1
- package/build/utils.js +1 -1
- package/build/vue.cjs +1 -1
- package/build/vue.cjs.map +1 -1
- package/build/vue.d.cts +7 -18
- package/build/vue.d.ts +7 -18
- package/build/vue.js +1 -1
- package/build/vue.js.map +1 -1
- package/package.json +1 -1
- package/build/chunk-4HS2U3AJ.js +0 -2
- package/build/chunk-4HS2U3AJ.js.map +0 -1
- package/build/chunk-IW3RSJHX.js +0 -2
- package/build/chunk-IW3RSJHX.js.map +0 -1
- package/build/index-w3SZ98rX.d.cts +0 -87
- package/build/index-w3SZ98rX.d.ts +0 -87
package/build/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\nimport {\n MarkRequired,\n Opaque,\n Prettify,\n type RequiredKeys,\n type UnionToIntersection,\n} from \"ts-essentials\";\nimport {\n getEntries,\n getKeys,\n getVariantsOptions,\n KeysOf,\n VariantOptions as VariantMap,\n} from \"./utils\";\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\nexport type WithClassProp<T extends object> = T & ClassProp;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = Prettify<\n Omit<\n UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>,\n \"class\" | \"className\"\n >\n>;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);\n defaultVariants?: CVVariant<V>;\n requiredVariants?: Record<R, boolean>;\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | WithClassProp<MarkRequired<CVVariant<V>, R>>\n | ([R] extends [never] ? void : never);\n\nexport interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {\n variants: V;\n variantKeys: KeysOf<V>;\n variantMap: VariantMap<V>;\n defaultVariants: CVVariant<V>;\n requiredVariants: Record<R, boolean>;\n}\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never>\n extends CVUtils<V, R> {\n (props: CVReturnProps<V, R>): string;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype CVComposeReturnProps<T extends (props?: any) => string> =\n | WithClassProp<VariantProps<T>>\n | (RequiredKeys<VariantProps<T>> extends never ? void : never);\nexport interface CVCompose {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type, @typescript-eslint/no-explicit-any\n <T extends ((props?: any) => string)[]>(\n ...components: T\n ): (props: CVComposeReturnProps<T[number]>) => string;\n}\n\nexport function defineCV(options: CVOptions = {}) {\n const cn = options.merge ?? clsx;\n\n const cv: CV = (config) => {\n const { base, variants, defaultVariants, requiredVariants } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const utils = {\n variants: variants ?? ({} as ResolvedV),\n variantKeys: variants ? getKeys(variants) : [],\n variantMap: variants ? getVariantsOptions(variants) : ({} as VariantMap<ResolvedV>),\n defaultVariants: defaultVariants ?? ({} as CVVariant<ResolvedV>),\n requiredVariants: requiredVariants ?? ({} as Record<keyof ResolvedV, boolean>),\n };\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants(utils)\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? utils.variantKeys.map((variant) => {\n const variantProp = props?.[variant];\n const defaults = defaultVariants?.[variant];\n\n const variantKey = variantProp?.toString() || defaults?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariants?.[cvKey as keyof typeof defaultVariants];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return cn(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, utils);\n };\n\n const compose: CVCompose =\n (...components) =>\n (props) => {\n const propsWithoutClass = { ...props, class: undefined, className: undefined };\n\n return cn(\n components.map((component) => component(propsWithoutClass)),\n props?.class,\n props?.className,\n );\n };\n\n return { cn, cv, compose };\n}\n\nexport const { cn, cv, compose } = defineCV();\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? Record<key & PropertyKey, val>\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n M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,EAASS,CAAO,EAAEG,CAAU,EAAI,MACxD,CAAC,EACD,OAEAC,EAA4BP,GAAkB,OAChD,CAACQ,EAAK,CAAE,MAAOC,EAAS,UAAWC,EAAa,GAAGC,CAAS,KACrBC,EAAWD,CAAQ,EAAE,MACpD,CAAC,CAACE,EAAOC,CAAU,IAAM,CACrB,IAAMC,EACFpB,IAAkBkB,CAAqC,EACrDG,EAAgBf,IAAQY,CAA2B,EAEzD,GAAI,OAAOC,GAAe,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOjB,EACHE,EACAS,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiCJ,CAAK,CAC1C,EAciB,QAXb,IAAIuB,IACHnB,GAAU,CACP,IAAMoB,EAAoB,CAAE,GAAGpB,EAAO,MAAO,OAAW,UAAW,MAAU,EAE7E,OAAOV,EACH6B,EAAW,IAAKE,GAAcA,EAAUD,CAAiB,CAAC,EAC1DpB,GAAO,MACPA,GAAO,SACX,CACJ,CAEqB,CAC7B,CAEO,GAAM,CAAE,GAAAV,EAAI,GAAAgC,EAAI,QAAAC,CAAQ,EAAInC,EAAS,EAQ/B4B,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB","names":["index_exports","__export","cn","compose","cv","defineCV","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","import_clsx","getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","defineCV","options","cn","config","base","variants","defaultVariants","requiredVariants","utils","getKeys","getVariantsOptions","compoundVariants","props","variantClassNames","variant","variantProp","defaults","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","components","propsWithoutClass","component","cv","compose"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/tokens.ts","../src/cn.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts","../src/define.ts"],"sourcesContent":["import type { CN } from \"./cn\";\r\nimport type {\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVReturn,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n} from \"./cv\";\r\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\r\nimport { defineCV } from \"./define\";\r\nimport type { CVUtils } from \"./utils\";\r\n\r\nexport const { cn, cv, extend } = defineCV();\r\n\r\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\r\nexport type {\r\n CN,\r\n CV,\r\n CVUtils,\r\n CVReturn,\r\n VariantProps,\r\n CVVariantsSchema,\r\n CVCompoundVariantsSchema,\r\n CVVariant,\r\n CVCompoundVariant,\r\n CVToken,\r\n};\r\n","import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n","import clsx, { type ClassValue } from \"clsx\";\r\n\r\nexport interface CNOptions {\r\n merge?: (className: string) => string;\r\n}\r\n\r\nexport interface CN {\r\n (...inputs: ClassValue[]): string;\r\n}\r\n\r\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\r\n return (...inputs) => merge(clsx(...inputs));\r\n}\r\n","// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => ({ ...config.defaultVariants, ...props });\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { Merge, Prettify } from \"ts-essentials\";\r\nimport type { CN } from \"./cn\";\r\nimport {\r\n resolveCompoundVariants,\r\n type CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions) {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n","import { _cn, type CNOptions } from \"./cn\";\r\nimport { _cv } from \"./cv\";\r\nimport { _extend } from \"./extend\";\r\n\r\nexport interface DefineCVOptions extends CNOptions {}\r\n\r\nexport function defineCV({ merge }: DefineCVOptions = {}) {\r\n const cn = _cn({ merge });\r\n\r\n const cv = _cv({ cn });\r\n\r\n const extend = _extend({ cn, cv });\r\n\r\n return { cn, cv, extend } as const;\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,OAAAC,EAAA,aAAAC,EAAA,WAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAR,GCSO,IAAMS,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASC,EAA2BH,EAAgBI,EAAwB,CAC/E,OAAIH,EAAkBD,EAAOH,C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AM,CAAC,EAElBG,EAAKC,EAAI,CAAE,GAAAH,CAAG,CAAC,EAEfI,EAASC,EAAQ,CAAE,GAAAL,EAAI,GAAAE,CAAG,CAAC,EAEjC,MAAO,CAAE,GAAAF,EAAI,GAAAE,EAAI,OAAAE,CAAO,CAC5B,CNAO,GAAM,CAAE,GAAAE,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["index_exports","__export","cn","cv","defineCV","extend","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","import_clsx","_cn","merge","className","inputs","clsx","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","additionalClassName","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend","cn","cv","extend","defineCV"]}
|
package/build/index.d.cts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv-gIK0IznJ.cjs';
|
|
2
|
+
export { i as CVCompoundVariant, j as CVToken, h as CVUtils, V as VariantProps, o as onlyWhenDefined, g as onlyWhenUndefined } from './cv-gIK0IznJ.cjs';
|
|
3
|
+
import * as ts_essentials from 'ts-essentials';
|
|
4
|
+
import * as clsx from 'clsx';
|
|
5
|
+
import { CN } from './cn.cjs';
|
|
6
|
+
export { defineCV } from './define.cjs';
|
|
7
|
+
|
|
8
|
+
declare const cn: CN;
|
|
9
|
+
declare const cv: CV;
|
|
10
|
+
declare const extend: <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
|
|
11
|
+
base?: clsx.ClassValue;
|
|
12
|
+
variants?: NewV;
|
|
13
|
+
compoundVariants?: CVCompoundVariantsSchema<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>> | CVCompoundVariantsSchemaFunction<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
|
|
14
|
+
defaultVariants?: CVVariant<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
|
|
15
|
+
}) => CVReturn<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
|
|
16
|
+
|
|
17
|
+
export { CN, CV, CVCompoundVariantsSchema, CVReturn, CVVariant, CVVariantsSchema, cn, cv, extend };
|
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv--G8-bDtP.js';
|
|
2
|
+
export { i as CVCompoundVariant, j as CVToken, h as CVUtils, V as VariantProps, o as onlyWhenDefined, g as onlyWhenUndefined } from './cv--G8-bDtP.js';
|
|
3
|
+
import * as ts_essentials from 'ts-essentials';
|
|
4
|
+
import * as clsx from 'clsx';
|
|
5
|
+
import { CN } from './cn.js';
|
|
6
|
+
export { defineCV } from './define.js';
|
|
7
|
+
|
|
8
|
+
declare const cn: CN;
|
|
9
|
+
declare const cv: CV;
|
|
10
|
+
declare const extend: <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
|
|
11
|
+
base?: clsx.ClassValue;
|
|
12
|
+
variants?: NewV;
|
|
13
|
+
compoundVariants?: CVCompoundVariantsSchema<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>> | CVCompoundVariantsSchemaFunction<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
|
|
14
|
+
defaultVariants?: CVVariant<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
|
|
15
|
+
}) => CVReturn<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
|
|
16
|
+
|
|
17
|
+
export { CN, CV, CVCompoundVariantsSchema, CVReturn, CVVariant, CVVariantsSchema, cn, cv, extend };
|
package/build/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a
|
|
1
|
+
import{a as n}from"./chunk-AQKDS5WX.js";import"./chunk-FIET564E.js";import"./chunk-UUT6STP6.js";import"./chunk-XWAQU5O6.js";import{a as t,b as o}from"./chunk-IMTFPGTY.js";import"./chunk-77XW3WZ4.js";var{cn:e,cv:a,extend:C}=n();export{e as cn,a as cv,n as defineCV,C as extend,t as onlyWhenDefined,o as onlyWhenUndefined};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CN } from \"./cn\";\r\nimport type {\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVReturn,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n} from \"./cv\";\r\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\r\nimport { defineCV } from \"./define\";\r\nimport type { CVUtils } from \"./utils\";\r\n\r\nexport const { cn, cv, extend } = defineCV();\r\n\r\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\r\nexport type {\r\n CN,\r\n CV,\r\n CVUtils,\r\n CVReturn,\r\n VariantProps,\r\n CVVariantsSchema,\r\n CVCompoundVariantsSchema,\r\n CVVariant,\r\n CVCompoundVariant,\r\n CVToken,\r\n};\r\n"],"mappings":"uMAcO,GAAM,CAAE,GAAAA,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["cn","cv","extend","defineCV"]}
|
package/build/tokens.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var u=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},k=(e,n,t,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of s(n))!y.call(e,o)&&o!==t&&i(e,o,{get:()=>n[o],enumerable:!(f=l(n,o))||f.enumerable});return e};var _=e=>k(i({},"__esModule",{value:!0}),e);var c={};u(c,{isCVToken:()=>h,onlyWhenDefined:()=>d,onlyWhenUndefined:()=>p,shouldApplySelectorByToken:()=>O});module.exports=_(c);var d={__token:"OnlyWhenDefined"},p={__token:"OnlyWhenUndefined"};function h(e){return e?typeof e=="object"&&"__token"in e:!1}function r(e,n){return e.__token===n.__token}function O(e,n){return r(e,d)?n!==void 0:r(e,p)?n===void 0:!1}0&&(module.exports={isCVToken,onlyWhenDefined,onlyWhenUndefined,shouldApplySelectorByToken});
|
|
2
|
+
//# sourceMappingURL=tokens.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tokens.ts"],"sourcesContent":["import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,oBAAAC,EAAA,sBAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAN,GASO,IAAMG,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASF,EAAUK,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASJ,EAA2BE,EAAgBG,EAAwB,CAC/E,OAAIF,EAAkBD,EAAOJ,CAAe,EAAUO,IAAa,OAC1DF,EAAkBD,EAAOH,CAAiB,EAAUM,IAAa,OAEnE,EACX","names":["tokens_exports","__export","isCVToken","onlyWhenDefined","onlyWhenUndefined","shouldApplySelectorByToken","__toCommonJS","token","isSpecificCVToken","reference","selector"]}
|
package/build/tokens.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/build/utils.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var C=(t,r)=>{for(var e in r)a(t,e,{get:r[e],enumerable:!0})},l=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of y(r))!u.call(t,o)&&o!==e&&a(t,o,{get:()=>r[o],enumerable:!(s=f(r,o))||s.enumerable});return t};var k=t=>l(a({},"__esModule",{value:!0}),t);var x={};C(x,{cvUtils:()=>d,getEntries:()=>V,getKeys:()=>i,getVariantMap:()=>p,splitProps:()=>P});module.exports=k(x);function i(t){return Object.keys(t)}function V(t){return Object.entries(t)}function p(t){return Object.fromEntries(V(t).map(([r,e])=>[r,i(e)]))}function P(t,r){let e={},s={};if(!t)return[e,s];for(let o in t){let n=o;r(n)?e[n]=t[n]:s[n]=t[n]}return[e,s]}function d(t){let r=i(t.variants),e=p(t.variants);return{variantKeys:r,variantMap:e,splitVariantProps:n=>P(n,c=>c in e),getVariantProps:n=>({...t.defaultVariants,...n})}}0&&(module.exports={cvUtils,getEntries,getKeys,getVariantMap,splitProps});
|
|
2
2
|
//# sourceMappingURL=utils.cjs.map
|
package/build/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => ({ ...config.defaultVariants, ...props });\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,eAAAC,EAAA,YAAAC,EAAA,kBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GAIO,SAASI,EAA2CI,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASL,EAA8CK,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASH,EAA0CI,EAAa,CACnE,OAAO,OAAO,YAAYN,EAAWM,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAON,EAAQO,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASL,EAAmBM,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO,MAAO,CAACE,EAAeC,CAAU,EAC7C,QAAWC,KAAWJ,EAAO,CACzB,IAAMK,EAAMD,EACRH,EAAYI,CAAG,EAAGH,EAAcG,CAAG,EAAIL,EAAMK,CAAG,EAC/CF,EAAWE,CAAG,EAAIL,EAAMK,CAAG,CACpC,CACA,MAAO,CAACH,EAAeC,CAAU,CACrC,CAWO,SAASb,EAAoCgB,EAAiC,CACjF,IAAMC,EAAcf,EAAQc,EAAO,QAAQ,EACrCE,EAAaf,EAAca,EAAO,QAAQ,EAIhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBAHPR,GAA6BN,EAAWM,EAAQK,GAAQA,KAAOG,CAAU,EAG/C,gBAF5BR,IAA8B,CAAE,GAAGM,EAAO,gBAAiB,GAAGN,CAAM,EAExB,CACzE","names":["utils_exports","__export","cvUtils","getEntries","getKeys","getVariantMap","splitProps","__toCommonJS","obj","variants","cvKey","cvVal","props","shouldSplit","splittedProps","otherProps","propKey","key","config","variantKeys","variantMap"]}
|
package/build/utils.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import 'ts-essentials';
|
|
2
|
-
export { E as EntriesOf,
|
|
2
|
+
export { h as CVUtils, E as EntriesOf, n as VariantMap, r as cvUtils, m as getEntries, l as getKeys, p as getVariantMap, q as splitProps } from './cv-gIK0IznJ.cjs';
|
|
3
3
|
import 'clsx';
|
|
4
|
+
import './cn.cjs';
|
package/build/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import 'ts-essentials';
|
|
2
|
-
export { E as EntriesOf,
|
|
2
|
+
export { h as CVUtils, E as EntriesOf, n as VariantMap, r as cvUtils, m as getEntries, l as getKeys, p as getVariantMap, q as splitProps } from './cv--G8-bDtP.js';
|
|
3
3
|
import 'clsx';
|
|
4
|
+
import './cn.js';
|
package/build/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e}from"./chunk-77XW3WZ4.js";export{e as cvUtils,b as getEntries,a as getKeys,c as getVariantMap,d as splitProps};
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
package/build/vue.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var i=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},m=(t,e,n,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of y(e))!V.call(t,r)&&r!==n&&o(t,r,{get:()=>e[r],enumerable:!(p=a(e,r))||p.enumerable});return t};var s=t=>m(o({},"__esModule",{value:!0}),t);var u={};i(u,{getPropsDeclaration:()=>f});module.exports=s(u);function f(t){return Object.fromEntries(t.variantKeys.map(e=>[e,{type:null}]))}0&&(module.exports={getPropsDeclaration});
|
|
2
2
|
//# sourceMappingURL=vue.cjs.map
|
package/build/vue.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vue.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\nimport { PropType } from \"vue\";\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\nimport { getKeys, objectFromEntries } from \"./utils\";\n\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{\n [K in keyof V]: {\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\n required: K extends R ? true : false;\n };\n}>;\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n getClass: CVReturn<V, R>;\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\n}\n\nexport interface CVWithProps {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n options?: CVOptions,\n ): CVWithPropsReturn<V, R>;\n}\n\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n) {\n if (typeof config?.variants === \"undefined\") {\n return {};\n }\n\n return objectFromEntries(\n getKeys(config.variants).map(\n (key) =>\n [\n key,\n {\n type: String,\n required: config.requiredVariants?.[key as R],\n },\n ] as const,\n ),\n );\n}\n\nexport const cvWithProps: CVWithProps = ((config, options) => {\n const getClass = cv(config, options);\n const props = getPropsDeclaration(config);\n\n return { getClass, props };\n}) as CVWithProps;\n","import { ClassValue, clsx } from \"clsx\";\nimport {\n MarkRequired,\n Opaque,\n Prettify,\n type RequiredKeys,\n type UnionToIntersection,\n} from \"ts-essentials\";\nimport {\n getEntries,\n getKeys,\n getVariantsOptions,\n KeysOf,\n VariantOptions as VariantMap,\n} from \"./utils\";\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\nexport type WithClassProp<T extends object> = T & ClassProp;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = Prettify<\n Omit<\n UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>,\n \"class\" | \"className\"\n >\n>;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);\n defaultVariants?: CVVariant<V>;\n requiredVariants?: Record<R, boolean>;\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | WithClassProp<MarkRequired<CVVariant<V>, R>>\n | ([R] extends [never] ? void : never);\n\nexport interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {\n variants: V;\n variantKeys: KeysOf<V>;\n variantMap: VariantMap<V>;\n defaultVariants: CVVariant<V>;\n requiredVariants: Record<R, boolean>;\n}\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never>\n extends CVUtils<V, R> {\n (props: CVReturnProps<V, R>): string;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype CVComposeReturnProps<T extends (props?: any) => string> =\n | WithClassProp<VariantProps<T>>\n | (RequiredKeys<VariantProps<T>> extends never ? void : never);\nexport interface CVCompose {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type, @typescript-eslint/no-explicit-any\n <T extends ((props?: any) => string)[]>(\n ...components: T\n ): (props: CVComposeReturnProps<T[number]>) => string;\n}\n\nexport function defineCV(options: CVOptions = {}) {\n const cn = options.merge ?? clsx;\n\n const cv: CV = (config) => {\n const { base, variants, defaultVariants, requiredVariants } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const utils = {\n variants: variants ?? ({} as ResolvedV),\n variantKeys: variants ? getKeys(variants) : [],\n variantMap: variants ? getVariantsOptions(variants) : ({} as VariantMap<ResolvedV>),\n defaultVariants: defaultVariants ?? ({} as CVVariant<ResolvedV>),\n requiredVariants: requiredVariants ?? ({} as Record<keyof ResolvedV, boolean>),\n };\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants(utils)\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? utils.variantKeys.map((variant) => {\n const variantProp = props?.[variant];\n const defaults = defaultVariants?.[variant];\n\n const variantKey = variantProp?.toString() || defaults?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariants?.[cvKey as keyof typeof defaultVariants];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return cn(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, utils);\n };\n\n const compose: CVCompose =\n (...components) =>\n (props) => {\n const propsWithoutClass = { ...props, class: undefined, className: undefined };\n\n return cn(\n components.map((component) => component(propsWithoutClass)),\n props?.class,\n props?.className,\n );\n };\n\n return { cn, cv, compose };\n}\n\nexport const { cn, cv, compose } = defineCV();\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? Record<key & PropertyKey, val>\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,EAAA,wBAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAAiC,gBCI1B,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SA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,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOjB,EACHE,EACAS,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiCJ,CAAK,CAC1C,EAciB,QAXb,IAAIuB,IACHnB,GAAU,CACP,IAAMoB,EAAoB,CAAE,GAAGpB,EAAO,MAAO,OAAW,UAAW,MAAU,EAE7E,OAAOV,EACH6B,EAAW,IAAKE,GAAcA,EAAUD,CAAiB,CAAC,EAC1DpB,GAAO,MACPA,GAAO,SACX,CACJ,CAEqB,CAC7B,CAEO,GAAM,CAAE,GAAAV,EAAI,GAAAgC,EAAI,QAAAC,CAAQ,EAAInC,EAAS,EAQ/B4B,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,ED7KzD,SAASO,EACZC,EACF,CACE,OAAI,OAAOA,GAAQ,SAAa,IACrB,CAAC,EAGLC,EACHC,EAAQF,EAAO,QAAQ,EAAE,IACpBG,GACG,CACIA,EACA,CACI,KAAM,OACN,SAAUH,EAAO,mBAAmBG,CAAQ,CAChD,CACJ,CACR,CACJ,CACJ,CAEO,IAAMC,EAA4B,CAACJ,EAAQK,IAAY,CAC1D,IAAMC,EAAWC,EAAGP,EAAQK,CAAO,EAC7BG,EAAQT,EAAoBC,CAAM,EAExC,MAAO,CAAE,SAAAM,EAAU,MAAAE,CAAM,CAC7B","names":["vue_exports","__export","cvWithProps","getPropsDeclaration","__toCommonJS","import_clsx","getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","objectFromEntries","entries","defineCV","options","cn","config","base","variants","defaultVariants","requiredVariants","utils","getKeys","getVariantsOptions","compoundVariants","props","variantClassNames","variant","variantProp","defaults","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","components","propsWithoutClass","component","cv","compose","getPropsDeclaration","config","objectFromEntries","getKeys","key","cvWithProps","options","getClass","cv","props"]}
|
|
1
|
+
{"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { type PropType } from \"vue\";\r\nimport { type CVReturn, type CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getPropsDeclaration<V extends CVVariantsSchema /* , R extends keyof V = never */>(cv: CVReturn<V>) {\r\n return Object.fromEntries(\r\n cv.variantKeys.map((key) => [key, { type: null /* , required: cv.requiredVariants[key as R] */ }]),\r\n ) as unknown as { [K in keyof V]: { type: PropType<keyof V[K]> /* ; required: K extends R ? true : false */ } };\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAGO,SAASE,EAAkFE,EAAiB,CAC/G,OAAO,OAAO,YACVA,EAAG,YAAY,IAAKC,GAAQ,CAACA,EAAK,CAAE,KAAM,IAAqD,CAAC,CAAC,CACrG,CACJ","names":["vue_exports","__export","getPropsDeclaration","__toCommonJS","cv","key"]}
|
package/build/vue.d.cts
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import { Prettify } from 'ts-essentials';
|
|
2
1
|
import { PropType } from 'vue';
|
|
3
|
-
import {
|
|
2
|
+
import { a as CVVariantsSchema, b as CVReturn } from './cv-gIK0IznJ.cjs';
|
|
4
3
|
import 'clsx';
|
|
4
|
+
import 'ts-essentials';
|
|
5
|
+
import './cn.cjs';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
required: K extends R ? true : false;
|
|
10
|
-
};
|
|
11
|
-
}>;
|
|
12
|
-
interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {
|
|
13
|
-
getClass: CVReturn<V, R>;
|
|
14
|
-
props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;
|
|
15
|
-
}
|
|
16
|
-
interface CVWithProps {
|
|
17
|
-
<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;
|
|
18
|
-
}
|
|
19
|
-
declare function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>): {};
|
|
20
|
-
declare const cvWithProps: CVWithProps;
|
|
7
|
+
declare function getPropsDeclaration<V extends CVVariantsSchema>(cv: CVReturn<V>): { [K in keyof V]: {
|
|
8
|
+
type: PropType<keyof V[K]>;
|
|
9
|
+
}; };
|
|
21
10
|
|
|
22
|
-
export {
|
|
11
|
+
export { getPropsDeclaration };
|
package/build/vue.d.ts
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import { Prettify } from 'ts-essentials';
|
|
2
1
|
import { PropType } from 'vue';
|
|
3
|
-
import {
|
|
2
|
+
import { a as CVVariantsSchema, b as CVReturn } from './cv--G8-bDtP.js';
|
|
4
3
|
import 'clsx';
|
|
4
|
+
import 'ts-essentials';
|
|
5
|
+
import './cn.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
required: K extends R ? true : false;
|
|
10
|
-
};
|
|
11
|
-
}>;
|
|
12
|
-
interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {
|
|
13
|
-
getClass: CVReturn<V, R>;
|
|
14
|
-
props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;
|
|
15
|
-
}
|
|
16
|
-
interface CVWithProps {
|
|
17
|
-
<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;
|
|
18
|
-
}
|
|
19
|
-
declare function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>): {};
|
|
20
|
-
declare const cvWithProps: CVWithProps;
|
|
7
|
+
declare function getPropsDeclaration<V extends CVVariantsSchema>(cv: CVReturn<V>): { [K in keyof V]: {
|
|
8
|
+
type: PropType<keyof V[K]>;
|
|
9
|
+
}; };
|
|
21
10
|
|
|
22
|
-
export {
|
|
11
|
+
export { getPropsDeclaration };
|
package/build/vue.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function r(e){return Object.fromEntries(e.variantKeys.map(t=>[t,{type:null}]))}export{r as getPropsDeclaration};
|
|
2
2
|
//# sourceMappingURL=vue.js.map
|
package/build/vue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { type PropType } from \"vue\";\r\nimport { type CVReturn, type CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getPropsDeclaration<V extends CVVariantsSchema /* , R extends keyof V = never */>(cv: CVReturn<V>) {\r\n return Object.fromEntries(\r\n cv.variantKeys.map((key) => [key, { type: null /* , required: cv.requiredVariants[key as R] */ }]),\r\n ) as unknown as { [K in keyof V]: { type: PropType<keyof V[K]> /* ; required: K extends R ? true : false */ } };\r\n}\r\n"],"mappings":"AAGO,SAASA,EAAkFC,EAAiB,CAC/G,OAAO,OAAO,YACVA,EAAG,YAAY,IAAKC,GAAQ,CAACA,EAAK,CAAE,KAAM,IAAqD,CAAC,CAAC,CACrG,CACJ","names":["getPropsDeclaration","cv","key"]}
|
package/package.json
CHANGED
package/build/chunk-4HS2U3AJ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? Record<key & PropertyKey, val>\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"AAIO,SAASA,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA+CC,EAAa,CACxE,OAAO,OAAO,YACVF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CACxE,CACJ,CAYO,SAASC,EAAqCC,EAAY,CAC7D,OAAO,OAAO,YAAYA,CAAO,CAGrC","names":["getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","objectFromEntries","entries"]}
|
package/build/chunk-IW3RSJHX.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as f,b as y,c as m}from"./chunk-4HS2U3AJ.js";import{clsx as T}from"clsx";function P(x={}){let V=x.merge??T;return{cn:V,cv:a=>{let{base:s,variants:e,defaultVariants:o,requiredVariants:R}=a,d={variants:e??{},variantKeys:e?f(e):[],variantMap:e?m(e):{},defaultVariants:o??{},requiredVariants:R??{}},h=e?typeof a.compoundVariants=="function"?a.compoundVariants(d):a.compoundVariants:void 0;return Object.assign(r=>{let v=e?d.variantKeys.map(t=>{let p=r?.[t],l=o?.[t],i=p?.toString()||l?.toString();return i?e[t][i]:void 0}):void 0,k=h?.reduce((t,{class:p,className:l,...i})=>(y(i).every(([C,n])=>{let g=o?.[C],u=r?.[C];if(typeof n=="object"&&"__token"in n){if(n.__token===_.__token)return u!==void 0;if(n.__token===W.__token)return u===void 0}let c=u??g;return Array.isArray(n)?n.some(O=>c===O):c===n})&&t.push(p,l),t),new Array);return V(s,v,k,r?.class,r?.className)},d)},compose:(...a)=>s=>{let e={...s,class:void 0,className:void 0};return V(a.map(o=>o(e)),s?.class,s?.className)}}}var{cn:A,cv:j,compose:E}=P(),_={__token:"OnlyWhenDefined"},W={__token:"OnlyWhenUndefined"};export{P as a,A as b,j as c,E as d,_ as e,W as f};
|
|
2
|
-
//# sourceMappingURL=chunk-IW3RSJHX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\nimport {\n MarkRequired,\n Opaque,\n Prettify,\n type RequiredKeys,\n type UnionToIntersection,\n} from \"ts-essentials\";\nimport {\n getEntries,\n getKeys,\n getVariantsOptions,\n KeysOf,\n VariantOptions as VariantMap,\n} from \"./utils\";\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\nexport type WithClassProp<T extends object> = T & ClassProp;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = Prettify<\n Omit<\n UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>,\n \"class\" | \"className\"\n >\n>;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);\n defaultVariants?: CVVariant<V>;\n requiredVariants?: Record<R, boolean>;\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | WithClassProp<MarkRequired<CVVariant<V>, R>>\n | ([R] extends [never] ? void : never);\n\nexport interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {\n variants: V;\n variantKeys: KeysOf<V>;\n variantMap: VariantMap<V>;\n defaultVariants: CVVariant<V>;\n requiredVariants: Record<R, boolean>;\n}\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never>\n extends CVUtils<V, R> {\n (props: CVReturnProps<V, R>): string;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype CVComposeReturnProps<T extends (props?: any) => string> =\n | WithClassProp<VariantProps<T>>\n | (RequiredKeys<VariantProps<T>> extends never ? void : never);\nexport interface CVCompose {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type, @typescript-eslint/no-explicit-any\n <T extends ((props?: any) => string)[]>(\n ...components: T\n ): (props: CVComposeReturnProps<T[number]>) => string;\n}\n\nexport function defineCV(options: CVOptions = {}) {\n const cn = options.merge ?? clsx;\n\n const cv: CV = (config) => {\n const { base, variants, defaultVariants, requiredVariants } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const utils = {\n variants: variants ?? ({} as ResolvedV),\n variantKeys: variants ? getKeys(variants) : [],\n variantMap: variants ? getVariantsOptions(variants) : ({} as VariantMap<ResolvedV>),\n defaultVariants: defaultVariants ?? ({} as CVVariant<ResolvedV>),\n requiredVariants: requiredVariants ?? ({} as Record<keyof ResolvedV, boolean>),\n };\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants(utils)\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? utils.variantKeys.map((variant) => {\n const variantProp = props?.[variant];\n const defaults = defaultVariants?.[variant];\n\n const variantKey = variantProp?.toString() || defaults?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariants?.[cvKey as keyof typeof defaultVariants];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return cn(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, utils);\n };\n\n const compose: CVCompose =\n (...components) =>\n (props) => {\n const propsWithoutClass = { ...props, class: undefined, className: undefined };\n\n return cn(\n components.map((component) => component(propsWithoutClass)),\n props?.class,\n props?.className,\n );\n };\n\n return { cn, cv, compose };\n}\n\nexport const { cn, cv, compose } = defineCV();\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n"],"mappings":"sDAAA,OAAqB,QAAAA,MAAY,OA8F1B,SAASC,EAASC,EAAqB,CAAC,EAAG,CAC9C,IAAMC,EAAKD,EAAQ,OAASE,EAyF5B,MAAO,CAAE,GAAAD,EAAI,GAvFGE,GAAW,CACvB,GAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,gBAAAC,EAAiB,iBAAAC,CAAiB,EAAIJ,EAIxDK,EAAQ,CACV,SAAUH,GAAa,CAAC,EACxB,YAAaA,EAAWI,EAAQJ,CAAQ,EAAI,CAAC,EAC7C,WAAYA,EAAWK,EAAmBL,CAAQ,EAAK,CAAC,EACxD,gBAAiBC,GAAoB,CAAC,EACtC,iBAAkBC,GAAqB,CAAC,CAC5C,EAEMI,EAAmBN,EACnB,OAAOF,EAAO,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AAAiC,EAAI,QAAAC,CAAQ,EAAIpC,EAAS,EAQ/B6B,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB","names":["clsx","defineCV","options","cn","clsx","config","base","variants","defaultVariants","requiredVariants","utils","getKeys","getVariantsOptions","compoundVariants","props","variantClassNames","variant","variantProp","defaults","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","components","propsWithoutClass","component","cv","compose"]}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { ClassValue } from 'clsx';
|
|
2
|
-
import { DeepReadonly, Prettify, UnionToIntersection, DeepWritable, Opaque, MarkRequired, RequiredKeys } from 'ts-essentials';
|
|
3
|
-
|
|
4
|
-
type KeysOf<O extends Record<string, unknown>> = (keyof O)[];
|
|
5
|
-
declare function getKeys<O extends Record<string, unknown>>(obj: O): KeysOf<O>;
|
|
6
|
-
type EntriesOf<O extends Record<string, unknown>> = {
|
|
7
|
-
[K in keyof O]: [K, O[K]];
|
|
8
|
-
};
|
|
9
|
-
declare function getEntries<O extends Record<string, unknown>>(obj: O): EntriesOf<O>[keyof EntriesOf<O>][];
|
|
10
|
-
type VariantOptions<V extends CVVariantsSchema> = {
|
|
11
|
-
[K in keyof V]: KeysOf<V[K]>;
|
|
12
|
-
};
|
|
13
|
-
declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): VariantOptions<V>;
|
|
14
|
-
type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
|
|
15
|
-
type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? Record<key & PropertyKey, val> : never : never;
|
|
16
|
-
type MergeIntersectingObjects<O> = {
|
|
17
|
-
[K in keyof O]: O[K];
|
|
18
|
-
};
|
|
19
|
-
declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
|
|
20
|
-
|
|
21
|
-
type ClassProp = {
|
|
22
|
-
class?: ClassValue;
|
|
23
|
-
className?: never;
|
|
24
|
-
} | {
|
|
25
|
-
class?: never;
|
|
26
|
-
className?: ClassValue;
|
|
27
|
-
};
|
|
28
|
-
type WithClassProp<T extends object> = T & ClassProp;
|
|
29
|
-
type VariantProps<CVR extends (props?: any) => string> = Prettify<Omit<UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>, "class" | "className">>;
|
|
30
|
-
type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
31
|
-
type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;
|
|
32
|
-
type CVVariant<V extends CVVariantsSchema> = {
|
|
33
|
-
[K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;
|
|
34
|
-
};
|
|
35
|
-
type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{
|
|
36
|
-
[K in keyof V]?: BooleanStringToBoolean<keyof V[K]> | BooleanStringToBoolean<keyof V[K]>[] | CVToken;
|
|
37
|
-
}>;
|
|
38
|
-
type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];
|
|
39
|
-
interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {
|
|
40
|
-
base?: ClassValue;
|
|
41
|
-
variants?: V;
|
|
42
|
-
compoundVariants?: CVCompoundVariantsSchema<V> | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);
|
|
43
|
-
defaultVariants?: CVVariant<V>;
|
|
44
|
-
requiredVariants?: Record<R, boolean>;
|
|
45
|
-
}
|
|
46
|
-
interface CVOptions {
|
|
47
|
-
merge?: (...args: ClassValue[]) => string;
|
|
48
|
-
}
|
|
49
|
-
type CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> = WithClassProp<MarkRequired<CVVariant<V>, R>> | ([R] extends [never] ? void : never);
|
|
50
|
-
interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {
|
|
51
|
-
variants: V;
|
|
52
|
-
variantKeys: KeysOf<V>;
|
|
53
|
-
variantMap: VariantOptions<V>;
|
|
54
|
-
defaultVariants: CVVariant<V>;
|
|
55
|
-
requiredVariants: Record<R, boolean>;
|
|
56
|
-
}
|
|
57
|
-
interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never> extends CVUtils<V, R> {
|
|
58
|
-
(props: CVReturnProps<V, R>): string;
|
|
59
|
-
}
|
|
60
|
-
interface CV {
|
|
61
|
-
<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, cvOptions?: CVOptions): CVReturn<V, R>;
|
|
62
|
-
}
|
|
63
|
-
type CVComposeReturnProps<T extends (props?: any) => string> = WithClassProp<VariantProps<T>> | (RequiredKeys<VariantProps<T>> extends never ? void : never);
|
|
64
|
-
interface CVCompose {
|
|
65
|
-
<T extends ((props?: any) => string)[]>(...components: T): (props: CVComposeReturnProps<T[number]>) => string;
|
|
66
|
-
}
|
|
67
|
-
declare function defineCV(options?: CVOptions): {
|
|
68
|
-
cn: (...args: ClassValue[]) => string;
|
|
69
|
-
cv: CV;
|
|
70
|
-
compose: CVCompose;
|
|
71
|
-
};
|
|
72
|
-
declare const cn: (...args: ClassValue[]) => string;
|
|
73
|
-
declare const cv: CV;
|
|
74
|
-
declare const compose: CVCompose;
|
|
75
|
-
type OnlyWhenDefined = Opaque<{
|
|
76
|
-
__token: string;
|
|
77
|
-
}, "OnlyWhenDefined">;
|
|
78
|
-
type OnlyWhenUndefined = Opaque<{
|
|
79
|
-
__token: string;
|
|
80
|
-
}, "OnlyWhenUndefined">;
|
|
81
|
-
type CVToken = OnlyWhenDefined | OnlyWhenUndefined;
|
|
82
|
-
/** Apply compound variant only if prop **is** specified */
|
|
83
|
-
declare const onlyWhenDefined: OnlyWhenDefined;
|
|
84
|
-
/** Apply compound variant only if prop **is not** specified */
|
|
85
|
-
declare const onlyWhenUndefined: OnlyWhenUndefined;
|
|
86
|
-
|
|
87
|
-
export { type CVVariantsSchema as C, type EntriesOf as E, type KeysOf as K, type VariantOptions as V, type WithClassProp as W, type CVReturn as a, type CVConfig as b, type CVOptions as c, getEntries as d, getVariantsOptions as e, type VariantProps as f, getKeys as g, type CVVariant as h, type CVCompoundVariant as i, type CVCompoundVariantsSchema as j, type CVUtils as k, type CV as l, type CVCompose as m, defineCV as n, objectFromEntries as o, cn as p, cv as q, compose as r, onlyWhenDefined as s, onlyWhenUndefined as t };
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { ClassValue } from 'clsx';
|
|
2
|
-
import { DeepReadonly, Prettify, UnionToIntersection, DeepWritable, Opaque, MarkRequired, RequiredKeys } from 'ts-essentials';
|
|
3
|
-
|
|
4
|
-
type KeysOf<O extends Record<string, unknown>> = (keyof O)[];
|
|
5
|
-
declare function getKeys<O extends Record<string, unknown>>(obj: O): KeysOf<O>;
|
|
6
|
-
type EntriesOf<O extends Record<string, unknown>> = {
|
|
7
|
-
[K in keyof O]: [K, O[K]];
|
|
8
|
-
};
|
|
9
|
-
declare function getEntries<O extends Record<string, unknown>>(obj: O): EntriesOf<O>[keyof EntriesOf<O>][];
|
|
10
|
-
type VariantOptions<V extends CVVariantsSchema> = {
|
|
11
|
-
[K in keyof V]: KeysOf<V[K]>;
|
|
12
|
-
};
|
|
13
|
-
declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): VariantOptions<V>;
|
|
14
|
-
type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
|
|
15
|
-
type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? Record<key & PropertyKey, val> : never : never;
|
|
16
|
-
type MergeIntersectingObjects<O> = {
|
|
17
|
-
[K in keyof O]: O[K];
|
|
18
|
-
};
|
|
19
|
-
declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
|
|
20
|
-
|
|
21
|
-
type ClassProp = {
|
|
22
|
-
class?: ClassValue;
|
|
23
|
-
className?: never;
|
|
24
|
-
} | {
|
|
25
|
-
class?: never;
|
|
26
|
-
className?: ClassValue;
|
|
27
|
-
};
|
|
28
|
-
type WithClassProp<T extends object> = T & ClassProp;
|
|
29
|
-
type VariantProps<CVR extends (props?: any) => string> = Prettify<Omit<UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>, "class" | "className">>;
|
|
30
|
-
type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
31
|
-
type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;
|
|
32
|
-
type CVVariant<V extends CVVariantsSchema> = {
|
|
33
|
-
[K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;
|
|
34
|
-
};
|
|
35
|
-
type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{
|
|
36
|
-
[K in keyof V]?: BooleanStringToBoolean<keyof V[K]> | BooleanStringToBoolean<keyof V[K]>[] | CVToken;
|
|
37
|
-
}>;
|
|
38
|
-
type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];
|
|
39
|
-
interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {
|
|
40
|
-
base?: ClassValue;
|
|
41
|
-
variants?: V;
|
|
42
|
-
compoundVariants?: CVCompoundVariantsSchema<V> | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);
|
|
43
|
-
defaultVariants?: CVVariant<V>;
|
|
44
|
-
requiredVariants?: Record<R, boolean>;
|
|
45
|
-
}
|
|
46
|
-
interface CVOptions {
|
|
47
|
-
merge?: (...args: ClassValue[]) => string;
|
|
48
|
-
}
|
|
49
|
-
type CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> = WithClassProp<MarkRequired<CVVariant<V>, R>> | ([R] extends [never] ? void : never);
|
|
50
|
-
interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {
|
|
51
|
-
variants: V;
|
|
52
|
-
variantKeys: KeysOf<V>;
|
|
53
|
-
variantMap: VariantOptions<V>;
|
|
54
|
-
defaultVariants: CVVariant<V>;
|
|
55
|
-
requiredVariants: Record<R, boolean>;
|
|
56
|
-
}
|
|
57
|
-
interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never> extends CVUtils<V, R> {
|
|
58
|
-
(props: CVReturnProps<V, R>): string;
|
|
59
|
-
}
|
|
60
|
-
interface CV {
|
|
61
|
-
<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, cvOptions?: CVOptions): CVReturn<V, R>;
|
|
62
|
-
}
|
|
63
|
-
type CVComposeReturnProps<T extends (props?: any) => string> = WithClassProp<VariantProps<T>> | (RequiredKeys<VariantProps<T>> extends never ? void : never);
|
|
64
|
-
interface CVCompose {
|
|
65
|
-
<T extends ((props?: any) => string)[]>(...components: T): (props: CVComposeReturnProps<T[number]>) => string;
|
|
66
|
-
}
|
|
67
|
-
declare function defineCV(options?: CVOptions): {
|
|
68
|
-
cn: (...args: ClassValue[]) => string;
|
|
69
|
-
cv: CV;
|
|
70
|
-
compose: CVCompose;
|
|
71
|
-
};
|
|
72
|
-
declare const cn: (...args: ClassValue[]) => string;
|
|
73
|
-
declare const cv: CV;
|
|
74
|
-
declare const compose: CVCompose;
|
|
75
|
-
type OnlyWhenDefined = Opaque<{
|
|
76
|
-
__token: string;
|
|
77
|
-
}, "OnlyWhenDefined">;
|
|
78
|
-
type OnlyWhenUndefined = Opaque<{
|
|
79
|
-
__token: string;
|
|
80
|
-
}, "OnlyWhenUndefined">;
|
|
81
|
-
type CVToken = OnlyWhenDefined | OnlyWhenUndefined;
|
|
82
|
-
/** Apply compound variant only if prop **is** specified */
|
|
83
|
-
declare const onlyWhenDefined: OnlyWhenDefined;
|
|
84
|
-
/** Apply compound variant only if prop **is not** specified */
|
|
85
|
-
declare const onlyWhenUndefined: OnlyWhenUndefined;
|
|
86
|
-
|
|
87
|
-
export { type CVVariantsSchema as C, type EntriesOf as E, type KeysOf as K, type VariantOptions as V, type WithClassProp as W, type CVReturn as a, type CVConfig as b, type CVOptions as c, getEntries as d, getVariantsOptions as e, type VariantProps as f, getKeys as g, type CVVariant as h, type CVCompoundVariant as i, type CVCompoundVariantsSchema as j, type CVUtils as k, type CV as l, type CVCompose as m, defineCV as n, objectFromEntries as o, cn as p, cv as q, compose as r, onlyWhenDefined as s, onlyWhenUndefined as t };
|