@yaredfall/class-variants 0.6.1 → 0.6.2

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.
@@ -1,2 +1,2 @@
1
- import{c as l,d}from"./chunk-N3ZCNVFV.js";import{e as f}from"./chunk-SJ6AQKOA.js";function E(t){return e=>{let[a,n]=x(e),{base:r,variants:i,compoundVariants:p,defaultVariants:c}=a,C=s=>{let V=n.getVariantProps(s),o=new Array;for(let m in i){let u=V[m]?.toString();u&&o.push(i?.[m]?.[u])}return o},S=s=>p?.reduce((V,o)=>(h(s,o,c)&&V.push(o.class),V),new Array);return Object.assign(Object.assign((s,...V)=>{let o=C(s),m=S(s);return t.cn(r,o,m,...V)},n),{config:a})}}function h(t,e,a){return Object.keys(e).every(n=>{if(n==="class")return!0;let r=e[n],i=a?.[n],p=t?.[n];if(l(r))return d(r,p);let c=p??i;return Array.isArray(r)?r.some(C=>y(c,C)):y(c,r)})}function y(t,e){return t?.toString()===e?.toString()}function x(t){let e={variants:{},compoundVariants:[],defaultVariants:{},...t},a=f(e);return[Object.assign(e,{compoundVariants:g(e.compoundVariants,a)}),a]}function g(t,e){return typeof t=="function"?t(e):t}export{E as a,x as b,g as c};
2
- //# sourceMappingURL=chunk-LLMR7HCR.js.map
1
+ import{c as l,d}from"./chunk-N3ZCNVFV.js";import{e as f}from"./chunk-SJ6AQKOA.js";function E(t){return e=>{let[a,n]=x(e),{base:r,variants:i,compoundVariants:p,defaultVariants:c}=a,C=o=>{let V=n.getVariantProps(o),s=new Array;for(let m in i){let u=V[m]?.toString();u&&s.push(i?.[m]?.[u])}return s},S=o=>p?.reduce((V,s)=>(h(o,s,c)&&V.push(s.class),V),new Array);return Object.assign(Object.assign((o,...V)=>{let s=C(o),m=S(o);return t.cn(r,s,m,...V)},n),{config:a})}}function h(t,e,a){return Object.keys(e).every(n=>{if(n==="class")return!0;let r=e[n],i=a?.[n],p=t?.[n];if(l(r))return d(r,p);let c=p??i;return Array.isArray(r)?r.some(C=>y(c,C)):y(c,r)})}function y(t,e){return t?.toString()===e?.toString()}function x(t){let e={variants:{},compoundVariants:[],defaultVariants:{},...t},a=f(e);return[Object.assign(e,{compoundVariants:g(e.compoundVariants,a)}),a]}function g(t,e){return typeof t=="function"?t(e):t}export{E as a,x as b,g as c};
2
+ //# sourceMappingURL=chunk-KFWDEJ5D.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cv.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n"],"mappings":"kFA0DO,SAASA,EAAIC,EAAwB,CACxC,OAAgDC,GAAiC,CAC7E,GAAM,CAACC,EAAgBC,CAAK,EAAIC,EAAcH,CAAM,EAE9C,CAAE,KAAAI,EAAM,SAAAC,EAAU,iBAAAC,EAAkB,gBAAAC,CAAgB,EAAIN,EAExDO,EAAyBC,GAA6B,CACxD,IAAMC,EAAiBR,EAAM,gBAAgBO,CAAK,EAE5CE,EAAa,IAAI,MACvB,QAAWC,KAAOP,EAAU,CACxB,IAAMQ,EAAUH,EAAeE,CAAG,GAAG,SAAS,EAC1CC,GAASF,EAAW,KAAKN,IAAWO,C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EACDA,CACJ,CACJ,CAEO,SAASgC,EACZ5B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E","names":["_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}
@@ -1,2 +1,2 @@
1
- import{a as e}from"./chunk-O5WYIZI3.js";import{a as i}from"./chunk-36Z7UYAL.js";import{a as o}from"./chunk-LLMR7HCR.js";function m({merge:r}={}){let n=e({merge:r}),t=o({cn:n}),c=i({cn:n,cv:t});return{cn:n,cv:t,extend:c}}export{m as a};
2
- //# sourceMappingURL=chunk-BO7CCVZY.js.map
1
+ import{a as e}from"./chunk-O5WYIZI3.js";import{a as i}from"./chunk-WMIMBE4W.js";import{a as o}from"./chunk-KFWDEJ5D.js";function m({merge:r}={}){let n=e({merge:r}),t=o({cn:n}),c=i({cn:n,cv:t});return{cn:n,cv:t,extend:c}}export{m as a};
2
+ //# sourceMappingURL=chunk-MV6NY2DZ.js.map
@@ -1,2 +1,2 @@
1
- import{c as r}from"./chunk-LLMR7HCR.js";function m({cn:s,cv:i}){let o=(V,a)=>{let e=structuredClone(V);for(let t in a){e[t]??={};for(let n in a[t])e[t][n]=s(V[t]?.[n],a[t][n])}return e};return(V,a)=>{let{config:e}=V;return i({base:s(e.base,a.base),variants:o(e.variants,a.variants),compoundVariants:t=>r(e.compoundVariants,V).concat(r(a.compoundVariants??[],t)),defaultVariants:{...e.defaultVariants,...a.defaultVariants}})}}export{m as a};
2
- //# sourceMappingURL=chunk-36Z7UYAL.js.map
1
+ import{c as r}from"./chunk-KFWDEJ5D.js";function m({cn:s,cv:i}){let o=(V,a)=>{let e=structuredClone(V);for(let t in a){e[t]??={};for(let n in a[t])e[t][n]=s(V[t]?.[n],a[t][n])}return e};return(V,a)=>{let{config:e}=V;return i({base:s(e.base,a.base),variants:o(e.variants,a.variants),compoundVariants:t=>r(e.compoundVariants,V).concat(r(a.compoundVariants??[],t)),defaultVariants:{...e.defaultVariants,...a.defaultVariants}})}}export{m as a};
2
+ //# sourceMappingURL=chunk-WMIMBE4W.js.map
@@ -62,7 +62,7 @@ interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVCon
62
62
  }
63
63
  type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;
64
64
  interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {
65
- (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;
65
+ (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;
66
66
  config: ResolvedCVConfig<V>;
67
67
  }
68
68
  interface CV {
@@ -62,7 +62,7 @@ interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVCon
62
62
  }
63
63
  type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;
64
64
  interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {
65
- (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;
65
+ (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;
66
66
  config: ResolvedCVConfig<V>;
67
67
  }
68
68
  interface CV {
package/build/cv.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cv.ts","../src/tokens.ts","../src/utils.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type 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\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\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 VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,4BAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAL,GCSO,IAAMM,EAAkB,CAAE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Aa,EAEtF,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeM,EAAiBD,EAAUL,CAAU,CAAC,EACtEM,EAAiBD,EAAUL,CAAU,CAC/C,CAAC,CACL,CAGA,SAASM,EAAiBC,EAAyBC,EAAyB,CACxE,OAAOD,GAAW,SAAS,IAAMC,GAAW,SAAS,CACzD,CAEO,SAAS5B,EACZH,EACiC,CACjC,IAAMgC,EAAkB,CACpB,SAAU,CAAC,EACX,iBAAkB,CAAC,EACnB,gBAAiB,CAAC,EAClB,GAAGhC,CACP,EAEME,EAAQ+B,EAAQD,CAAe,EAErC,MAAO,CACH,OAAO,OAAOA,EAAiB,CAC3B,iBAAkBE,EAAwBF,EAAgB,iBAAkB9B,CAAK,CACrF,CAAC,EACDA,CACJ,CACJ,CAEO,SAASgC,EACZ5B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E","names":["cv_exports","__export","_cv","resolveCompoundVariants","resolveConfig","__toCommonJS","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}
1
+ {"version":3,"sources":["../src/cv.ts","../src/tokens.ts","../src/utils.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type 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\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\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 VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { vari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AIA,IAAU,QAAS,MAAO,GAE9B,IAAMC,EAAaH,EAAQE,CAAK,EAE1BE,EAAmBH,IAAWC,CAA8B,EAC5DG,EAAgBhB,IAAQa,CAA2B,EAEzD,GAAII,EAAUH,CAAU,EAAG,OAAOI,EAA2BJ,EAAYE,CAAa,EAEtF,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeM,EAAiBD,EAAUL,CAAU,CAAC,EACtEM,EAAiBD,EAAUL,CAAU,CAC/C,CAAC,CACL,CAGA,SAASM,EAAiBC,EAAyBC,EAAyB,CACxE,OAAOD,GAAW,SAAS,IAAMC,GAAW,SAAS,CACzD,CAEO,SAAS5B,EACZH,EACiC,CACjC,IAAMgC,EAAkB,CACpB,SAAU,CAAC,EACX,iBAAkB,CAAC,EACnB,gBAAiB,CAAC,EAClB,GAAGhC,CACP,EAEME,EAAQ+B,EAAQD,CAAe,EAErC,MAAO,CACH,OAAO,OAAOA,EAAiB,CAC3B,iBAAkBE,EAAwBF,EAAgB,iBAAkB9B,CAAK,CACrF,CAAC,EACDA,CACJ,CACJ,CAEO,SAASgC,EACZ5B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E","names":["cv_exports","__export","_cv","resolveCompoundVariants","resolveConfig","__toCommonJS","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}
package/build/cv.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'clsx';
2
2
  import 'ts-essentials';
3
3
  import './cn.cjs';
4
- export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-C4LDfd1S.cjs';
4
+ export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-CU8ASolx.cjs';
package/build/cv.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'clsx';
2
2
  import 'ts-essentials';
3
3
  import './cn.js';
4
- export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-BA68QNCx.js';
4
+ export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-CxGrT76R.js';
package/build/cv.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a,b,c}from"./chunk-LLMR7HCR.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _cv,c as resolveCompoundVariants,b as resolveConfig};
1
+ import{a,b,c}from"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _cv,c as resolveCompoundVariants,b as resolveConfig};
2
2
  //# sourceMappingURL=cv.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/define.ts","../src/cn.ts","../src/tokens.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts"],"sourcesContent":["import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n","import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type 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\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\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 VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n"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AE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ,CLtEO,SAASI,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,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","names":["define_exports","__export","defineCV","__toCommonJS","import_clsx","_cn","merge","className","inputs","clsx","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","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"]}
1
+ {"version":3,"sources":["../src/define.ts","../src/cn.ts","../src/tokens.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts"],"sourcesContent":["import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n","import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type 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\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\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 VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAsC,qBAU/B,SAASC,EAAI,CAAE,MAAAC,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,KAAM,EAAAG,SAAK,GAAGD,CAAM,CAAC,CAC/C,CCHO,IAAME,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EA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U,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ,CLtEO,SAASI,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,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","names":["define_exports","__export","defineCV","__toCommonJS","import_clsx","_cn","merge","className","inputs","clsx","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","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"]}
@@ -1,5 +1,5 @@
1
1
  import { CVExtend } from './extend.cjs';
2
- import { C as CV } from './cv-C4LDfd1S.cjs';
2
+ import { C as CV } from './cv-CU8ASolx.cjs';
3
3
  import { CNOptions, CN } from './cn.cjs';
4
4
  import 'clsx';
5
5
  import 'ts-essentials';
package/build/define.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CVExtend } from './extend.js';
2
- import { C as CV } from './cv-BA68QNCx.js';
2
+ import { C as CV } from './cv-CxGrT76R.js';
3
3
  import { CNOptions, CN } from './cn.js';
4
4
  import 'clsx';
5
5
  import 'ts-essentials';
package/build/define.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-BO7CCVZY.js";import"./chunk-O5WYIZI3.js";import"./chunk-36Z7UYAL.js";import"./chunk-LLMR7HCR.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as defineCV};
1
+ import{a}from"./chunk-MV6NY2DZ.js";import"./chunk-O5WYIZI3.js";import"./chunk-WMIMBE4W.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as defineCV};
2
2
  //# sourceMappingURL=define.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/extend.ts","../src/cv.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GC+IO,SAASI,EACZC,EACAC,EACF,CACE,OAAO,OAAOD,GAAqB,WAAaA,EAAiBC,CAAK,EAAID,CAC9E,CD3GO,SAASE,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAiBC,CAAG,IAAM,CAAC,EAC3B,QAAWC,KAAWH,EAAYE,CAAG,EACjCD,EAAiBC,CAAG,EAAEC,CAAO,EAAIP,EAAGG,EAASG,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ","names":["extend_exports","__export","_extend","__toCommonJS","resolveCompoundVariants","compoundVariants","utils","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}
1
+ {"version":3,"sources":["../src/extend.ts","../src/cv.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GC+IO,SAASI,EACZC,EACAC,EACF,CACE,OAAO,OAAOD,GAAqB,WAAaA,EAAiBC,CAAK,EAAID,CAC9E,CD3GO,SAASE,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAiBC,CAAG,IAAM,CAAC,EAC3B,QAAWC,KAAWH,EAAYE,CAAG,EACjCD,EAAiBC,CAAG,EAAEC,CAAO,EAAIP,EAAGG,EAASG,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ","names":["extend_exports","__export","_extend","__toCommonJS","resolveCompoundVariants","compoundVariants","utils","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}
@@ -1,7 +1,7 @@
1
1
  import { ClassValue } from 'clsx';
2
2
  import { Merge, Prettify } from 'ts-essentials';
3
3
  import { CN } from './cn.cjs';
4
- import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-C4LDfd1S.cjs';
4
+ import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-CU8ASolx.cjs';
5
5
 
6
6
  type MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
7
7
  type MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<V1 & V2, {
package/build/extend.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ClassValue } from 'clsx';
2
2
  import { Merge, Prettify } from 'ts-essentials';
3
3
  import { CN } from './cn.js';
4
- import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-BA68QNCx.js';
4
+ import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-CxGrT76R.js';
5
5
 
6
6
  type MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
7
7
  type MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<V1 & V2, {
package/build/extend.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-36Z7UYAL.js";import"./chunk-LLMR7HCR.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _extend};
1
+ import{a}from"./chunk-WMIMBE4W.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _extend};
2
2
  //# sourceMappingURL=extend.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/cn.ts","../src/tokens.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts","../src/define.ts"],"sourcesContent":["import type { CN } from \"./cn\";\nimport type {\n CV,\n CVCompoundVariant,\n CompoundVariantsSchema,\n CVReturn,\n CVVariant,\n VariantsSchema,\n VariantProps,\n} from \"./cv\";\nimport { defineCV } from \"./define\";\nimport { type CVExtend } from \"./extend\";\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\nimport type { CVUtils } from \"./utils\";\n\nexport const { cn, cv, extend } = defineCV();\n\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\nexport type {\n CN,\n CV,\n CVCompoundVariant,\n CompoundVariantsSchema,\n CVExtend,\n CVReturn,\n CVToken,\n CVUtils,\n CVVariant,\n VariantsSchema,\n VariantProps,\n};\n","import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type 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\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\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 VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n","import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,OAAAC,EAAA,aAAAC,EAAA,WAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAR,GCAA,IAAAS,EAAsC,qBAU/B,SAASC,EAAI,CAAE,MAAAC,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,KAAM,EAAAG,SAAK,GAAGD,CAAM,CAAC,CAC/C,CCHO,IAAME,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,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AAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ,CCtEO,SAASI,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,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,CNCO,GAAM,CAAE,GAAAE,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["index_exports","__export","cn","cv","defineCV","extend","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","import_clsx","_cn","merge","className","inputs","clsx","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","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"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/cn.ts","../src/tokens.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts","../src/define.ts"],"sourcesContent":["import type { CN } from \"./cn\";\nimport type {\n CV,\n CVCompoundVariant,\n CompoundVariantsSchema,\n CVReturn,\n CVVariant,\n VariantsSchema,\n VariantProps,\n} from \"./cv\";\nimport { defineCV } from \"./define\";\nimport { type CVExtend } from \"./extend\";\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\nimport type { CVUtils } from \"./utils\";\n\nexport const { cn, cv, extend } = defineCV();\n\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\nexport type {\n CN,\n CV,\n CVCompoundVariant,\n CompoundVariantsSchema,\n CVExtend,\n CVReturn,\n CVToken,\n CVUtils,\n CVVariant,\n VariantsSchema,\n VariantProps,\n};\n","import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type 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\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\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 VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n","import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n"],"mappings":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,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ,CCtEO,SAASI,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,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,CNCO,GAAM,CAAE,GAAAE,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["index_exports","__export","cn","cv","defineCV","extend","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","import_clsx","_cn","merge","className","inputs","clsx","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","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,6 +1,6 @@
1
1
  import { CN } from './cn.cjs';
2
- import { C as CV } from './cv-C4LDfd1S.cjs';
3
- export { b as CVCompoundVariant, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, c as CompoundVariantsSchema, h as VariantProps, V as VariantsSchema, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-C4LDfd1S.cjs';
2
+ import { C as CV } from './cv-CU8ASolx.cjs';
3
+ export { b as CVCompoundVariant, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, c as CompoundVariantsSchema, h as VariantProps, V as VariantsSchema, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-CU8ASolx.cjs';
4
4
  export { defineCV } from './define.cjs';
5
5
  import { CVExtend } from './extend.cjs';
6
6
  import 'clsx';
package/build/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CN } from './cn.js';
2
- import { C as CV } from './cv-BA68QNCx.js';
3
- export { b as CVCompoundVariant, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, c as CompoundVariantsSchema, h as VariantProps, V as VariantsSchema, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-BA68QNCx.js';
2
+ import { C as CV } from './cv-CxGrT76R.js';
3
+ export { b as CVCompoundVariant, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, c as CompoundVariantsSchema, h as VariantProps, V as VariantsSchema, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-CxGrT76R.js';
4
4
  export { defineCV } from './define.js';
5
5
  import { CVExtend } from './extend.js';
6
6
  import 'clsx';
package/build/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as t}from"./chunk-BO7CCVZY.js";import"./chunk-O5WYIZI3.js";import"./chunk-36Z7UYAL.js";import"./chunk-LLMR7HCR.js";import{a as n,b as o}from"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";var{cn:V,cv:a,extend:i}=t();export{V as cn,a as cv,t as defineCV,i as extend,n as onlyWhenDefined,o as onlyWhenUndefined};
1
+ import{a as t}from"./chunk-MV6NY2DZ.js";import"./chunk-O5WYIZI3.js";import"./chunk-WMIMBE4W.js";import"./chunk-KFWDEJ5D.js";import{a as n,b as o}from"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";var{cn:V,cv:a,extend:i}=t();export{V as cn,a as cv,t as defineCV,i as extend,n as onlyWhenDefined,o as onlyWhenUndefined};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
1
  import 'ts-essentials';
2
- export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-C4LDfd1S.cjs';
2
+ export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-CU8ASolx.cjs';
3
3
  import 'clsx';
4
4
  import './cn.cjs';
package/build/tokens.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'ts-essentials';
2
- export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-BA68QNCx.js';
2
+ export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-CxGrT76R.js';
3
3
  import 'clsx';
4
4
  import './cn.js';
package/build/utils.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'ts-essentials';
2
- export { f 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-C4LDfd1S.cjs';
2
+ export { f 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-CU8ASolx.cjs';
3
3
  import 'clsx';
4
4
  import './cn.cjs';
package/build/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'ts-essentials';
2
- export { f 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-BA68QNCx.js';
2
+ export { f 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-CxGrT76R.js';
3
3
  import 'clsx';
4
4
  import './cn.js';
package/build/vue.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PropType } from 'vue';
2
- import { V as VariantsSchema, d as CVReturn } from './cv-C4LDfd1S.cjs';
2
+ import { V as VariantsSchema, d as CVReturn } from './cv-CU8ASolx.cjs';
3
3
  import 'clsx';
4
4
  import 'ts-essentials';
5
5
  import './cn.cjs';
package/build/vue.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PropType } from 'vue';
2
- import { V as VariantsSchema, d as CVReturn } from './cv-BA68QNCx.js';
2
+ import { V as VariantsSchema, d as CVReturn } from './cv-CxGrT76R.js';
3
3
  import 'clsx';
4
4
  import 'ts-essentials';
5
5
  import './cn.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaredfall/class-variants",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "author": "yaredfall",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cv.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n"],"mappings":"kFA0DO,SAASA,EAAIC,EAAwB,CACxC,OAAgDC,GAAiC,CAC7E,GAAM,CAACC,EAAgBC,CAAK,EAAIC,EAAcH,CAAM,EAE9C,CAAE,KAAAI,EAAM,SAAAC,EAAU,iBAAAC,EAAkB,gBAAAC,CAAgB,EAAIN,EAExDO,EAAyBC,GAA6B,CACxD,IAAMC,EAAiBR,EAAM,gBAAgBO,CAAK,EAE5CE,EAAa,IAAI,MACvB,QAAWC,KAAOP,EAAU,CACxB,IAAMQ,EAAUH,EAAeE,CAAG,GAAG,SAAS,EAC1CC,GAASF,EAAW,KAAKN,IAAWO,CAAG,IAAIC,CAAO,CAAC,CAC3D,CACA,OAAOF,CACX,EAEMG,EAAiCL,GAC5BH,GAAkB,OAAO,CAACS,EAAKC,KAC9BC,EAA2BR,EAAOO,EAAiBT,CAAe,GAClEQ,EAAI,KAAKC,EAAgB,KAAK,EAC3BD,GACR,IAAI,KAAmB,EAW9B,OAAO,OAAO,OAAO,OAAO,OART,CAACN,KAA6BE,IAA6B,CAC1E,IAAMO,EAAoBV,EAAsBC,CAAK,EAE/CU,EAA4BL,EAA8BL,CAAK,EAErE,OAAOV,EAAQ,GAAGK,EAAMc,EAAmBC,EAA2B,GAAGR,CAAU,CACvF,EAE+CT,CAAK,EAAG,CAAE,OAAQD,CAAe,CAAC,CACrF,CACJ,CAEA,SAASgB,EACLR,EACAW,EACAC,EACF,CACE,OAAO,OAAO,KAAKD,CAAO,EAAE,MAAOE,GAAU,CACzC,GAAIA,IAAU,QAAS,MAAO,GAE9B,IAAMC,EAAaH,EAAQE,CAAK,EAE1BE,EAAmBH,IAAWC,CAA8B,EAC5DG,EAAgBhB,IAAQa,CAA2B,EAEzD,GAAII,EAAUH,CAAU,EAAG,OAAOI,EAA2BJ,EAAYE,CAAa,EAEtF,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeM,EAAiBD,EAAUL,CAAU,CAAC,EACtEM,EAAiBD,EAAUL,CAAU,CAC/C,CAAC,CACL,CAGA,SAASM,EAAiBC,EAAyBC,EAAyB,CACxE,OAAOD,GAAW,SAAS,IAAMC,GAAW,SAAS,CACzD,CAEO,SAAS5B,EACZH,EACiC,CACjC,IAAMgC,EAAkB,CACpB,SAAU,CAAC,EACX,iBAAkB,CAAC,EACnB,gBAAiB,CAAC,EAClB,GAAGhC,CACP,EAEME,EAAQ+B,EAAQD,CAAe,EAErC,MAAO,CACH,OAAO,OAAOA,EAAiB,CAC3B,iBAAkBE,EAAwBF,EAAgB,iBAAkB9B,CAAK,CACrF,CAAC,EACDA,CACJ,CACJ,CAEO,SAASgC,EACZ5B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E","names":["_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}