@yaredfall/class-variants 0.6.5 → 0.7.0

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{a as e}from"./chunk-O5WYIZI3.js";import{a as i}from"./chunk-IUIPT6RZ.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-N6TNUPPW.js.map
1
+ import{a as e}from"./chunk-O5WYIZI3.js";import{a as i}from"./chunk-CRH3RFJH.js";import{a as o}from"./chunk-QZQFLP4L.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-5EH72RDS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/define.ts"],"sourcesContent":["import { _cn, type CNOptions } from \"./cn\";\r\nimport { _cv } from \"./cv\";\r\nimport { _extend } from \"./extend\";\r\n\r\nexport interface DefineCVOptions extends CNOptions {}\r\n\r\nexport function defineCV({ merge }: DefineCVOptions = {}) {\r\n const cn = _cn({ merge });\r\n\r\n const cv = _cv({ cn });\r\n\r\n const extend = _extend({ cn, cv });\r\n\r\n return { cn, cv, extend } as const;\r\n}\r\n"],"mappings":"wHAMO,SAASA,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":["defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
@@ -0,0 +1,2 @@
1
+ function V(t){return Object.keys(t)}function p(t){return Object.entries(t)}function f(t){return Object.fromEntries(p(t).map(([r,e])=>[r,V(e)]))}function c(t,r){let e={},a={};if(!t)return[e,a];for(let i in t){let n=i;r(n)?e[n]=t[n]:a[n]=t[n]}return[e,a]}function y(t){let r=V(t.variants),e=f(t.variants);return{variantKeys:r,variantMap:e,splitVariantProps:n=>c(n,o=>o in e),getVariantProps:n=>{let o=structuredClone(t.defaultVariants);for(let s in n)n[s]!==void 0&&(o[s]=n[s]);return o}}}export{V as a,p as b,f as c,c as d,y as e};
2
+ //# sourceMappingURL=chunk-C577IOC7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVVariant, 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 CVVariant<V>>(\n props?: TProps,\n ) => [CVVariant<V>, Prettify<Omit<TProps, keyof CVVariant<V>>>];\n getVariantProps: (props?: CVVariant<V>) => Exclude<CVVariant<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?: CVVariant<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVVariant<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":"AAGO,SAASA,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAAwCC,EAAa,CACjE,OAAO,OAAO,YAAYF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASC,EAAmBC,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO,MAAO,CAACE,EAAeC,CAAU,EAC7C,QAAWC,KAAWJ,EAAO,CACzB,IAAMK,EAAMD,EACRH,EAAYI,CAAG,EAAGH,EAAcG,CAAG,EAAIL,EAAMK,CAAG,EAC/CF,EAAWE,CAAG,EAAIL,EAAMK,CAAG,CACpC,CACA,MAAO,CAACH,EAAeC,CAAU,CACrC,CAWO,SAASG,EAAkCC,EAAiC,CAC/E,IAAMC,EAAchB,EAAQe,EAAO,QAAQ,EACrCE,EAAad,EAAcY,EAAO,QAAQ,EAUhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBATPT,GAAyBD,EAAWC,EAAQK,GAAQA,KAAOI,CAAU,EAS3C,gBAR5BT,GAAyB,CAC9C,IAAMU,EAAiB,gBAAgBH,EAAO,eAAe,EAC7D,QAAWF,KAAOL,EACVA,EAAMK,CAAG,IAAM,SAAWK,EAAeL,CAAG,EAAIL,EAAMK,CAAG,GAEjE,OAAOK,CACX,CAEqE,CACzE","names":["getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps"]}
@@ -0,0 +1,2 @@
1
+ import{c as r}from"./chunk-QZQFLP4L.js";function m({cn:s,cv:i}){let o=(t,n)=>{let a=structuredClone(t);for(let e in n){a[e]??(a[e]={});for(let V in n[e])a[e][V]=s(t[e]?.[V],n[e][V])}return a};return(t,n)=>{let{config:a}=t,e="config"in n?n.config:n;return i({base:s(a.base,e.base),variants:o(a.variants,e.variants),compoundVariants:V=>r(a.compoundVariants,t).concat(r(e.compoundVariants??[],V)),defaultVariants:{...a.defaultVariants,...e.defaultVariants}})}}export{m as a};
2
+ //# sourceMappingURL=chunk-CRH3RFJH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/extend.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\r\nimport type { Merge, Prettify } from \"ts-essentials\";\r\nimport type { CN } from \"./cn\";\r\nimport {\r\n resolveCompoundVariants,\r\n type CompoundVariantsSchema,\r\n type CompoundVariantsSchemaFunction,\r\n type CV,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type Variant,\r\n type VariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\r\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\ninterface ExtensionConfig<V extends VariantsSchema, NewV extends VariantsSchema> {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n}\r\n\r\nexport interface CVExtend {\r\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n extension: ExtensionConfig<V, NewV>,\r\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\r\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n extension: CVReturn<NewV>,\r\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\r\n}\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\r\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\r\n const extendedVariants: VariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n extension: ExtensionConfig<V, NewV> | CVReturn<NewV>,\r\n ) => {\r\n const { config } = component;\r\n\r\n const extensionConfig = (\"config\" in extension ? extension.config : extension) as ExtensionConfig<V, NewV>;\r\n\r\n return cv({\r\n base: cn(config.base, extensionConfig.base),\r\n variants: extendVariants(config.variants, extensionConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(extensionConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...extensionConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n"],"mappings":"wCA+CO,SAASA,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAAC,KAAAD,EAAAC,GAA0B,CAAC,GAC3B,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,IACC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEbG,EAAmB,WAAYF,EAAYA,EAAU,OAASA,EAEpE,OAAOR,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMC,EAAgB,IAAI,EAC1C,SAAUT,EAAeQ,EAAO,SAAUC,EAAgB,QAAQ,EAClE,iBAAmBC,GACfC,EAAwBH,EAAO,iBAAkBF,CAAS,EAAE,OACxDK,EAAwBF,EAAgB,kBAAoB,CAAC,EAAGC,CAAK,CACzE,EACJ,gBAAiB,CAAE,GAAGF,EAAO,gBAAiB,GAAGC,EAAgB,eAAgB,CACrF,CAA4C,CAChD,CACJ","names":["_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","extension","config","extensionConfig","utils","resolveCompoundVariants"]}
@@ -0,0 +1,2 @@
1
+ import{c as u,d as f}from"./chunk-N3ZCNVFV.js";import{e as d}from"./chunk-C577IOC7.js";function P(t){return e=>{let[a,n]=h(e),{base:r,variants:i,compoundVariants:p,defaultVariants:c}=a,m=s=>{let V=n.getVariantProps(s),o=new Array;for(let C in i){let l=V[C]?.toString();l&&o.push(i?.[C]?.[l])}return o},S=s=>p?.reduce((V,o)=>(g(s,o,c)&&V.push(o.class),V),new Array);return Object.assign(Object.assign((s,...V)=>{let o=m(s),C=S(s);return t.cn(r,o,C,...V)},n),{config:a,$inferProps:void 0})}}function g(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(u(r))return f(r,p);let c=p??i;return Array.isArray(r)?r.some(m=>y(c,m)):y(c,r)})}function y(t,e){return t?.toString()===e?.toString()}function h(t){let e={variants:{},compoundVariants:[],defaultVariants:{},...t},a=d(e);return[Object.assign(e,{compoundVariants:x(e.compoundVariants,a)}),a]}function x(t,e){return typeof t=="function"?t(e):t}export{P as a,h as b,x as c};
2
+ //# sourceMappingURL=chunk-QZQFLP4L.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> =\n CVR extends CVReturn<infer _V> ? CVR[\"$inferProps\"] : 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 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 interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVVariant<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n\n $inferProps: CVVariant<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?: CVVariant<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?: CVVariant<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?: CVVariant<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, $inferProps: undefined! });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVVariant<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":"uFAyDO,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,GAAyB,CACpD,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,KAAyBE,IAA6B,CACtE,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,EAAgB,YAAa,MAAW,CAAC,CAC9G,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"]}
@@ -1,6 +1,10 @@
1
1
  import { ClassValue } from 'clsx';
2
2
  import { CN } from './cn.js';
3
3
 
4
+ type Prettify<Type> = Type extends Function ? Type : Extract<{
5
+ [Key in keyof Type]: Type[Key];
6
+ }, Type>;
7
+
4
8
  type StringLiteral<Type> = Type extends string ? (string extends Type ? never : Type) : never;
5
9
  declare const __OPAQUE_TYPE__: unique symbol;
6
10
  type WithOpaque<Token extends string> = {
@@ -8,10 +12,6 @@ type WithOpaque<Token extends string> = {
8
12
  };
9
13
  type Opaque<Type, Token extends string> = Token extends StringLiteral<Token> ? Type & WithOpaque<Token> : never;
10
14
 
11
- type Prettify<Type> = Type extends Function ? Type : Extract<{
12
- [Key in keyof Type]: Type[Key];
13
- }, Type>;
14
-
15
15
  type ArrayOrSingle<Type> = Type | Type[];
16
16
 
17
17
  type OnlyWhenDefined = Opaque<{
@@ -41,12 +41,12 @@ declare function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TPro
41
41
  interface CVUtils<V extends VariantsSchema> {
42
42
  variantKeys: (keyof V & string)[];
43
43
  variantMap: Prettify<VariantMap<V>>;
44
- splitVariantProps: <TProps extends CVReturnProps<V>>(props?: TProps) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];
45
- getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;
44
+ splitVariantProps: <TProps extends CVVariant<V>>(props?: TProps) => [CVVariant<V>, Prettify<Omit<TProps, keyof CVVariant<V>>>];
45
+ getVariantProps: (props?: CVVariant<V>) => Exclude<CVVariant<V>, void>;
46
46
  }
47
47
  declare function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V>;
48
48
 
49
- type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;
49
+ type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer _V> ? CVR["$inferProps"] : never;
50
50
  type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
51
51
  type VariantKey = string | number;
52
52
  type Variant = Record<VariantKey, ClassValue>;
@@ -55,7 +55,6 @@ type EmptySchema = Record<never, never>;
55
55
  type CVVariant<V extends VariantsSchema = EmptySchema> = {
56
56
  [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;
57
57
  };
58
- type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;
59
58
  type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {
60
59
  [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;
61
60
  } & {
@@ -72,10 +71,10 @@ interface CVConfig<V extends VariantsSchema = EmptySchema> {
72
71
  interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {
73
72
  compoundVariants: CompoundVariantsSchema<V>;
74
73
  }
75
- type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;
76
74
  interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {
77
- (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;
75
+ (props?: CVVariant<V>, ...classNames: ClassValue[]): string;
78
76
  config: ResolvedCVConfig<V>;
77
+ $inferProps: CVVariant<V>;
79
78
  }
80
79
  interface CV {
81
80
  <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;
@@ -88,4 +87,4 @@ type CVPropsValue = VariantKey | boolean | undefined;
88
87
  declare function resolveConfig<V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
89
88
  declare function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CompoundVariantsSchema<V>;
90
89
 
91
- export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type Prettify as P, type ResolvedCVConfig as R, type VariantsSchema as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type VariantProps as h, type Variant as i, type CompoundVariantsSchemaFunction as j, isCVToken as k, getKeys as l, getEntries as m, type VariantMap as n, onlyWhenDefined as o, getVariantMap as p, splitProps as q, cvUtils as r, shouldApplySelectorByToken as s, type VariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
90
+ export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type Prettify as P, type ResolvedCVConfig as R, type VariantsSchema as V, _cv as _, type CVReturn as a, type CompoundVariantsSchema as b, type Variant as c, type CompoundVariantsSchemaFunction as d, type CVVariant as e, onlyWhenUndefined as f, type CVCompoundVariant as g, type CVToken as h, type CVUtils as i, type VariantProps as j, isCVToken as k, getKeys as l, getEntries as m, type VariantMap as n, onlyWhenDefined as o, getVariantMap as p, splitProps as q, cvUtils as r, shouldApplySelectorByToken as s, type VariantKey as t, type CVConfig as u, type CVPropsValue as v, resolveConfig as w, resolveCompoundVariants as x };
package/build/cv.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import 'clsx';
2
- 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-96SI2TYA.js';
2
+ export { B as BooleanStringToBoolean, C as CV, g as CVCompoundVariant, u as CVConfig, v as CVPropsValue, a as CVReturn, e as CVVariant, b as CompoundVariantsSchema, d as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, c as Variant, t as VariantKey, j as VariantProps, V as VariantsSchema, _ as _cv, x as resolveCompoundVariants, w as resolveConfig } from './cv-zY1EPoUz.js';
3
3
  import './cn.js';
package/build/cv.js CHANGED
@@ -1,2 +1,2 @@
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};
1
+ import{a,b,c}from"./chunk-QZQFLP4L.js";import"./chunk-N3ZCNVFV.js";import"./chunk-C577IOC7.js";export{a as _cv,c as resolveCompoundVariants,b as resolveConfig};
2
2
  //# sourceMappingURL=cv.js.map
package/build/define.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { CVExtend } from './extend.js';
2
- import { C as CV } from './cv-96SI2TYA.js';
3
1
  import { CNOptions, CN } from './cn.js';
2
+ import { C as CV } from './cv-zY1EPoUz.js';
3
+ import { CVExtend } from './extend.js';
4
4
  import 'clsx';
5
- import '../prettify';
6
5
 
7
6
  interface DefineCVOptions extends CNOptions {
8
7
  }
package/build/define.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-N6TNUPPW.js";import"./chunk-O5WYIZI3.js";import"./chunk-IUIPT6RZ.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as defineCV};
1
+ import{a}from"./chunk-5EH72RDS.js";import"./chunk-O5WYIZI3.js";import"./chunk-CRH3RFJH.js";import"./chunk-QZQFLP4L.js";import"./chunk-N3ZCNVFV.js";import"./chunk-C577IOC7.js";export{a as defineCV};
2
2
  //# sourceMappingURL=define.js.map
package/build/extend.d.ts CHANGED
@@ -1,21 +1,22 @@
1
1
  import { ClassValue } from 'clsx';
2
- import { Prettify } from '../prettify';
3
- import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, P as Prettify$1, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-96SI2TYA.js';
2
+ import { P as Prettify, V as VariantsSchema, a as CVReturn, b as CompoundVariantsSchema, c as Variant, d as CompoundVariantsSchemaFunction, e as CVVariant, C as CV } from './cv-zY1EPoUz.js';
4
3
  import { CN } from './cn.js';
5
4
 
6
5
  type Merge<Object1, Object2> = Prettify<Omit<Object1, keyof Object2> & Object2>;
7
6
 
8
- type MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify$1<Record<keyof V1 | keyof V2, ClassValue>>;
7
+ type MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
9
8
  type MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<V1 & V2, {
10
9
  [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;
11
10
  }>;
11
+ interface ExtensionConfig<V extends VariantsSchema, NewV extends VariantsSchema> {
12
+ base?: ClassValue;
13
+ variants?: NewV;
14
+ compoundVariants?: CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>> | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;
15
+ defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;
16
+ }
12
17
  interface CVExtend {
13
- <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
14
- base?: ClassValue;
15
- variants?: NewV;
16
- compoundVariants?: CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>> | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;
17
- defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;
18
- }): CVReturn<MergeVariantsSchemas<V, NewV>>;
18
+ <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(component: CVReturn<V>, extension: ExtensionConfig<V, NewV>): CVReturn<MergeVariantsSchemas<V, NewV>>;
19
+ <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(component: CVReturn<V>, extension: CVReturn<NewV>): CVReturn<MergeVariantsSchemas<V, NewV>>;
19
20
  }
20
21
  interface CVExtendOptions {
21
22
  cn: CN;
package/build/extend.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-IUIPT6RZ.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _extend};
1
+ import{a}from"./chunk-CRH3RFJH.js";import"./chunk-QZQFLP4L.js";import"./chunk-N3ZCNVFV.js";import"./chunk-C577IOC7.js";export{a as _extend};
2
2
  //# sourceMappingURL=extend.js.map
package/build/index.d.ts CHANGED
@@ -1,13 +1,5 @@
1
- import { CN } from './cn.js';
2
- import { C as CV } from './cv-96SI2TYA.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-96SI2TYA.js';
1
+ export { CN } from './cn.js';
2
+ export { C as CV, g as CVCompoundVariant, a as CVReturn, h as CVToken, i as CVUtils, e as CVVariant, b as CompoundVariantsSchema, j as VariantProps, V as VariantsSchema, o as onlyWhenDefined, f as onlyWhenUndefined } from './cv-zY1EPoUz.js';
4
3
  export { defineCV } from './define.js';
5
- import { CVExtend } from './extend.js';
4
+ export { CVExtend } from './extend.js';
6
5
  import 'clsx';
7
- import '../prettify';
8
-
9
- declare const cn: CN;
10
- declare const cv: CV;
11
- declare const extend: CVExtend;
12
-
13
- export { CN, CV, CVExtend, cn, cv, extend };
package/build/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as t}from"./chunk-N6TNUPPW.js";import"./chunk-O5WYIZI3.js";import"./chunk-IUIPT6RZ.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};
1
+ import{a as o}from"./chunk-5EH72RDS.js";import"./chunk-O5WYIZI3.js";import"./chunk-CRH3RFJH.js";import"./chunk-QZQFLP4L.js";import{a as t,b as n}from"./chunk-N3ZCNVFV.js";import"./chunk-C577IOC7.js";export{o as defineCV,t as onlyWhenDefined,n as onlyWhenUndefined};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.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"],"mappings":"uMAeO,GAAM,CAAE,GAAAA,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["cn","cv","extend","defineCV"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/build/std.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { CVExtend } from './extend.js';
2
+ import { C as CV } from './cv-zY1EPoUz.js';
3
+ import { CN } from './cn.js';
4
+ import 'clsx';
5
+
6
+ declare const cn: CN;
7
+ declare const cv: CV;
8
+ declare const extend: CVExtend;
9
+
10
+ export { cn, cv, extend };
package/build/std.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a as e}from"./chunk-5EH72RDS.js";import"./chunk-O5WYIZI3.js";import"./chunk-CRH3RFJH.js";import"./chunk-QZQFLP4L.js";import"./chunk-N3ZCNVFV.js";import"./chunk-C577IOC7.js";var{cn:o,cv:t,extend:c}=e();export{o as cn,t as cv,c as extend};
2
+ //# sourceMappingURL=std.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/std.ts"],"sourcesContent":["import { defineCV } from \"./define\";\r\n\r\nexport const { cn, cv, extend } = defineCV();\r\n"],"mappings":"oLAEO,GAAM,CAAE,GAAAA,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["cn","cv","extend","defineCV"]}
package/build/tokens.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-96SI2TYA.js';
1
+ export { h as CVToken, k as isCVToken, o as onlyWhenDefined, f as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-zY1EPoUz.js';
2
2
  import 'clsx';
3
3
  import './cn.js';
package/build/utils.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- 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-96SI2TYA.js';
1
+ export { i 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-zY1EPoUz.js';
2
2
  import 'clsx';
3
3
  import './cn.js';
package/build/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a,b,c,d,e}from"./chunk-SJ6AQKOA.js";export{e as cvUtils,b as getEntries,a as getKeys,c as getVariantMap,d as splitProps};
1
+ import{a,b,c,d,e}from"./chunk-C577IOC7.js";export{e as cvUtils,b as getEntries,a as getKeys,c as getVariantMap,d as splitProps};
2
2
  //# sourceMappingURL=utils.js.map
package/build/vue.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PropType } from 'vue';
2
- import { V as VariantsSchema, d as CVReturn } from './cv-96SI2TYA.js';
2
+ import { V as VariantsSchema, a as CVReturn } from './cv-zY1EPoUz.js';
3
3
  import 'clsx';
4
4
  import './cn.js';
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaredfall/class-variants",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "private": false,
5
5
  "author": "yaredfall",
6
6
  "type": "module",
@@ -15,6 +15,16 @@
15
15
  "default": "./build/index.cjs"
16
16
  }
17
17
  },
18
+ "./std": {
19
+ "import": {
20
+ "types": "./build/std.d.ts",
21
+ "default": "./build/std.js"
22
+ },
23
+ "require": {
24
+ "types": "./build/std.d.cts",
25
+ "default": "./build/std.cjs"
26
+ }
27
+ },
18
28
  "./utils": {
19
29
  "import": {
20
30
  "types": "./build/utils.d.ts",
@@ -1,2 +0,0 @@
1
- import{c as r}from"./chunk-KFWDEJ5D.js";function m({cn:s,cv:i}){let o=(V,t)=>{let a=structuredClone(V);for(let e in t){a[e]??(a[e]={});for(let n in t[e])a[e][n]=s(V[e]?.[n],t[e][n])}return a};return(V,t)=>{let{config:a}=V;return i({base:s(a.base,t.base),variants:o(a.variants,t.variants),compoundVariants:e=>r(a.compoundVariants,V).concat(r(t.compoundVariants??[],e)),defaultVariants:{...a.defaultVariants,...t.defaultVariants}})}}export{m as a};
2
- //# sourceMappingURL=chunk-IUIPT6RZ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/extend.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"],"mappings":"wCAyCO,SAASA,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAAC,KAAAD,EAAAC,GAA0B,CAAC,GAC3B,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","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}
@@ -1,2 +0,0 @@
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
@@ -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>, ...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,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"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/define.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"],"mappings":"wHAMO,SAASA,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":["defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
@@ -1,2 +0,0 @@
1
- function V(t){return Object.keys(t)}function p(t){return Object.entries(t)}function f(t){return Object.fromEntries(p(t).map(([n,r])=>[n,V(r)]))}function c(t,n){let r={},o={};if(!t)return[r,o];for(let i in t){let e=i;n(e)?r[e]=t[e]:o[e]=t[e]}return[r,o]}function P(t){let n=V(t.variants),r=f(t.variants);return{variantKeys:n,variantMap:r,splitVariantProps:e=>c(e,s=>s in r),getVariantProps:e=>{let s=structuredClone(t.defaultVariants);for(let a in e)e[a]!==void 0&&(s[a]=e[a]);return s}}}export{V as a,p as b,f as c,c as d,P as e};
2
- //# sourceMappingURL=chunk-SJ6AQKOA.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["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":"AAGO,SAASA,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAAwCC,EAAa,CACjE,OAAO,OAAO,YAAYF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASC,EAAmBC,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO,MAAO,CAACE,EAAeC,CAAU,EAC7C,QAAWC,KAAWJ,EAAO,CACzB,IAAMK,EAAMD,EACRH,EAAYI,CAAG,EAAGH,EAAcG,CAAG,EAAIL,EAAMK,CAAG,EAC/CF,EAAWE,CAAG,EAAIL,EAAMK,CAAG,CACpC,CACA,MAAO,CAACH,EAAeC,CAAU,CACrC,CAWO,SAASG,EAAkCC,EAAiC,CAC/E,IAAMC,EAAchB,EAAQe,EAAO,QAAQ,EACrCE,EAAad,EAAcY,EAAO,QAAQ,EAUhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBATPT,GAA6BD,EAAWC,EAAQK,GAAQA,KAAOI,CAAU,EAS/C,gBAR5BT,GAA6B,CAClD,IAAMU,EAAiB,gBAAgBH,EAAO,eAAe,EAC7D,QAAWF,KAAOL,EACVA,EAAMK,CAAG,IAAM,SAAWK,EAAeL,CAAG,EAAIL,EAAMK,CAAG,GAEjE,OAAOK,CACX,CAEqE,CACzE","names":["getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps"]}