@yaredfall/class-variants 0.6.0-rc.1 → 0.6.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +1 -1
  2. package/build/chunk-32VQFSFZ.js +2 -0
  3. package/build/{chunk-77XW3WZ4.js.map → chunk-32VQFSFZ.js.map} +1 -1
  4. package/build/chunk-FNDRMHIF.js +2 -0
  5. package/build/chunk-FNDRMHIF.js.map +1 -0
  6. package/build/{chunk-AQKDS5WX.js → chunk-G3WOK6WL.js} +2 -2
  7. package/build/{chunk-XWAQU5O6.js → chunk-NDMNWVIC.js} +2 -2
  8. package/build/{cv-gIK0IznJ.d.cts → cv-B7zWq-Wg.d.cts} +1 -1
  9. package/build/{cv--G8-bDtP.d.ts → cv-BdqZkdFD.d.ts} +1 -1
  10. package/build/cv.cjs +1 -1
  11. package/build/cv.cjs.map +1 -1
  12. package/build/cv.d.cts +1 -1
  13. package/build/cv.d.ts +1 -1
  14. package/build/cv.js +1 -1
  15. package/build/define.cjs +1 -1
  16. package/build/define.cjs.map +1 -1
  17. package/build/define.d.cts +5 -9
  18. package/build/define.d.ts +5 -9
  19. package/build/define.js +1 -1
  20. package/build/extend.cjs +1 -1
  21. package/build/extend.cjs.map +1 -1
  22. package/build/extend.d.cts +11 -8
  23. package/build/extend.d.ts +11 -8
  24. package/build/extend.js +1 -1
  25. package/build/index.cjs +1 -1
  26. package/build/index.cjs.map +1 -1
  27. package/build/index.d.cts +7 -11
  28. package/build/index.d.ts +7 -11
  29. package/build/index.js +1 -1
  30. package/build/index.js.map +1 -1
  31. package/build/tokens.d.cts +1 -1
  32. package/build/tokens.d.ts +1 -1
  33. package/build/utils.cjs +1 -1
  34. package/build/utils.cjs.map +1 -1
  35. package/build/utils.d.cts +1 -1
  36. package/build/utils.d.ts +1 -1
  37. package/build/utils.js +1 -1
  38. package/build/vue.d.cts +1 -1
  39. package/build/vue.d.ts +1 -1
  40. package/package.json +1 -1
  41. package/build/chunk-77XW3WZ4.js +0 -2
  42. package/build/chunk-UUT6STP6.js +0 -2
  43. package/build/chunk-UUT6STP6.js.map +0 -1
  44. /package/build/{chunk-AQKDS5WX.js.map → chunk-G3WOK6WL.js.map} +0 -0
  45. /package/build/{chunk-XWAQU5O6.js.map → chunk-NDMNWVIC.js.map} +0 -0
package/LICENSE CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
@@ -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(([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-32VQFSFZ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => ({ ...config.defaultVariants, ...props });\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n"],"mappings":"AAIO,SAASA,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA0CC,EAAa,CACnE,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,EAAoCC,EAAiC,CACjF,IAAMC,EAAchB,EAAQe,EAAO,QAAQ,EACrCE,EAAad,EAAcY,EAAO,QAAQ,EAIhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBAHPT,GAA6BD,EAAWC,EAAQK,GAAQA,KAAOI,CAAU,EAG/C,gBAF5BT,IAA8B,CAAE,GAAGO,EAAO,gBAAiB,GAAGP,CAAM,EAExB,CACzE","names":["getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap"]}
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = structuredClone(config.defaultVariants);\r\n for (const key in props) {\r\n if (props[key] !== undefined) defaultedProps[key] = props[key];\r\n }\r\n return defaultedProps;\r\n };\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n"],"mappings":"AAIO,SAASA,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA0CC,EAAa,CACnE,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,EAAoCC,EAAiC,CACjF,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"]}
@@ -0,0 +1,2 @@
1
+ import{c as r}from"./chunk-NDMNWVIC.js";function m({cn:s,cv:i}){let o=(t,a)=>{let e=structuredClone(t);for(let V in a){e[V]??={};for(let n in a[V])e[V][n]=s(t[V]?.[n],a[V][n])}return e};return(t,a)=>{let{config:e}=t;return i({base:s(e.base,a.base),variants:o(e.variants,a.variants),compoundVariants:V=>r(e.compoundVariants,t).concat(r(a.compoundVariants??[],V)),defaultVariants:{...e.defaultVariants,...a.defaultVariants}})}}export{m as a};
2
+ //# sourceMappingURL=chunk-FNDRMHIF.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 CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\nexport interface CVExtend {\r\n <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ): CVReturn<MergeVariantsSchemas<V, NewV>>\r\n}\r\n\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n"],"mappings":"wCA4CO,SAASA,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CACnBC,EACAC,IACC,CACD,IAAMC,EAAqC,gBAAgBF,CAAQ,EACnE,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","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}
@@ -1,2 +1,2 @@
1
- import{a as e}from"./chunk-FIET564E.js";import{a as i}from"./chunk-UUT6STP6.js";import{a as o}from"./chunk-XWAQU5O6.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-AQKDS5WX.js.map
1
+ import{a as e}from"./chunk-FIET564E.js";import{a as i}from"./chunk-FNDRMHIF.js";import{a as o}from"./chunk-NDMNWVIC.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-G3WOK6WL.js.map
@@ -1,2 +1,2 @@
1
- import{c as d,d as f}from"./chunk-IMTFPGTY.js";import{e as m}from"./chunk-77XW3WZ4.js";function k(t){return e=>{let[n,a]=S(e),{base:r,variants:i,compoundVariants:C,defaultVariants:p}=n,u=o=>{let s=a.getVariantProps(o),V=new Array;for(let c in i){let l=s[c]?.toString();l&&V.push(i?.[c]?.[l])}return V},x=o=>C?.reduce((s,V)=>(g(o,V,p)&&s.push(V.class),s),new Array);return Object.assign(Object.assign((o,s)=>{let V=u(o),c=x(o);return t.cn(r,V,c,s)},a),{config:n})}}function g(t,e,n){return Object.keys(e).every(a=>{if(a==="class")return!0;let r=e[a],i=n?.[a],C=t?.[a];if(d(r))return f(r,C);let p=C??i;return Array.isArray(r)?r.some(u=>y(p,u)):y(p,r)})}function y(t,e){return t?.toString()===e?.toString()}function S(t){let e={variants:{},compoundVariants:[],defaultVariants:{},...t},n=m(e);return[Object.assign(e,{compoundVariants:h(e.compoundVariants,n)}),n]}function h(t,e){return typeof t=="function"?t(e):t}export{k as a,S as b,h as c};
2
- //# sourceMappingURL=chunk-XWAQU5O6.js.map
1
+ import{c as d,d as f}from"./chunk-IMTFPGTY.js";import{e as m}from"./chunk-32VQFSFZ.js";function k(t){return e=>{let[n,a]=S(e),{base:r,variants:i,compoundVariants:C,defaultVariants:p}=n,u=o=>{let s=a.getVariantProps(o),V=new Array;for(let c in i){let l=s[c]?.toString();l&&V.push(i?.[c]?.[l])}return V},x=o=>C?.reduce((s,V)=>(g(o,V,p)&&s.push(V.class),s),new Array);return Object.assign(Object.assign((o,s)=>{let V=u(o),c=x(o);return t.cn(r,V,c,s)},a),{config:n})}}function g(t,e,n){return Object.keys(e).every(a=>{if(a==="class")return!0;let r=e[a],i=n?.[a],C=t?.[a];if(d(r))return f(r,C);let p=C??i;return Array.isArray(r)?r.some(u=>y(p,u)):y(p,r)})}function y(t,e){return t?.toString()===e?.toString()}function S(t){let e={variants:{},compoundVariants:[],defaultVariants:{},...t},n=m(e);return[Object.assign(e,{compoundVariants:h(e.compoundVariants,n)}),n]}function h(t,e){return typeof t=="function"?t(e):t}export{k as a,S as b,h as c};
2
+ //# sourceMappingURL=chunk-NDMNWVIC.js.map
@@ -75,4 +75,4 @@ type CVPropsValue = CVVariantKey | boolean | undefined;
75
75
  declare function resolveConfig<V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
76
76
  declare function resolveCompoundVariants<V extends CVVariantsSchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CVCompoundVariantsSchema<V>;
77
77
 
78
- export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantProps as V, _cv as _, type CVVariantsSchema as a, type CVReturn as b, type CVCompoundVariantsSchema as c, type CVVariantSchema as d, type CVCompoundVariantsSchemaFunction as e, type CVVariant as f, onlyWhenUndefined as g, type CVUtils as h, type CVCompoundVariant as i, type CVToken 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 CVVariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
78
+ export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantProps as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CVCompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type CVVariantsSchema as h, type CVVariantSchema as i, type CVCompoundVariantsSchemaFunction 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 CVVariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
@@ -75,4 +75,4 @@ type CVPropsValue = CVVariantKey | boolean | undefined;
75
75
  declare function resolveConfig<V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
76
76
  declare function resolveCompoundVariants<V extends CVVariantsSchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CVCompoundVariantsSchema<V>;
77
77
 
78
- export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantProps as V, _cv as _, type CVVariantsSchema as a, type CVReturn as b, type CVCompoundVariantsSchema as c, type CVVariantSchema as d, type CVCompoundVariantsSchemaFunction as e, type CVVariant as f, onlyWhenUndefined as g, type CVUtils as h, type CVCompoundVariant as i, type CVToken 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 CVVariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
78
+ export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantProps as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CVCompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type CVVariantsSchema as h, type CVVariantSchema as i, type CVCompoundVariantsSchemaFunction 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 CVVariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
package/build/cv.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var v=(e,n)=>{for(var t in n)l(e,t,{get:n[t],enumerable:!0})},K=(e,n,t,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of R(n))!T.call(e,r)&&r!==t&&l(e,r,{get:()=>n[r],enumerable:!(a=O(n,r))||a.enumerable});return e};var U=e=>K(l({},"__esModule",{value:!0}),e);var N={};v(N,{_cv:()=>j,resolveCompoundVariants:()=>h,resolveConfig:()=>k});module.exports=U(N);var _={__token:"OnlyWhenDefined"},b={__token:"OnlyWhenUndefined"};function y(e){return e?typeof e=="object"&&"__token"in e:!1}function d(e,n){return e.__token===n.__token}function m(e,n){return d(e,_)?n!==void 0:d(e,b)?n===void 0:!1}function x(e){return Object.keys(e)}function B(e){return Object.entries(e)}function W(e){return Object.fromEntries(B(e).map(([n,t])=>[n,x(t)]))}function A(e,n){let t={},a={};if(!e)return[t,a];for(let r in e){let o=r;n(o)?t[o]=e[o]:a[o]=e[o]}return[t,a]}function P(e){let n=x(e.variants),t=W(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:o=>A(o,V=>V in t),getVariantProps:o=>({...e.defaultVariants,...o})}}function j(e){return n=>{let[t,a]=k(n),{base:r,variants:o,compoundVariants:V,defaultVariants:C}=t,u=i=>{let p=a.getVariantProps(i),s=new Array;for(let c in o){let f=p[c]?.toString();f&&s.push(o?.[c]?.[f])}return s},S=i=>V?.reduce((p,s)=>(w(i,s,C)&&p.push(s.class),p),new Array);return Object.assign(Object.assign((i,p)=>{let s=u(i),c=S(i);return e.cn(r,s,c,p)},a),{config:t})}}function w(e,n,t){return Object.keys(n).every(a=>{if(a==="class")return!0;let r=n[a],o=t?.[a],V=e?.[a];if(y(r))return m(r,V);let C=V??o;return Array.isArray(r)?r.some(u=>g(C,u)):g(C,r)})}function g(e,n){return e?.toString()===n?.toString()}function k(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=P(n);return[Object.assign(n,{compoundVariants:h(n.compoundVariants,t)}),t]}function h(e,n){return typeof e=="function"?e(n):e}0&&(module.exports={_cv,resolveCompoundVariants,resolveConfig});
1
+ "use strict";var f=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var v=(e,n)=>{for(var t in n)f(e,t,{get:n[t],enumerable:!0})},K=(e,n,t,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of R(n))!T.call(e,r)&&r!==t&&f(e,r,{get:()=>n[r],enumerable:!(a=O(n,r))||a.enumerable});return e};var U=e=>K(f({},"__esModule",{value:!0}),e);var N={};v(N,{_cv:()=>j,resolveCompoundVariants:()=>h,resolveConfig:()=>k});module.exports=U(N);var _={__token:"OnlyWhenDefined"},b={__token:"OnlyWhenUndefined"};function y(e){return e?typeof e=="object"&&"__token"in e:!1}function d(e,n){return e.__token===n.__token}function m(e,n){return d(e,_)?n!==void 0:d(e,b)?n===void 0:!1}function x(e){return Object.keys(e)}function B(e){return Object.entries(e)}function W(e){return Object.fromEntries(B(e).map(([n,t])=>[n,x(t)]))}function A(e,n){let t={},a={};if(!e)return[t,a];for(let r in e){let o=r;n(o)?t[o]=e[o]:a[o]=e[o]}return[t,a]}function P(e){let n=x(e.variants),t=W(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:o=>A(o,s=>s in t),getVariantProps:o=>{let s=structuredClone(e.defaultVariants);for(let V in o)o[V]!==void 0&&(s[V]=o[V]);return s}}}function j(e){return n=>{let[t,a]=k(n),{base:r,variants:o,compoundVariants:s,defaultVariants:V}=t,c=p=>{let C=a.getVariantProps(p),i=new Array;for(let u in o){let l=C[u]?.toString();l&&i.push(o?.[u]?.[l])}return i},S=p=>s?.reduce((C,i)=>(w(p,i,V)&&C.push(i.class),C),new Array);return Object.assign(Object.assign((p,C)=>{let i=c(p),u=S(p);return e.cn(r,i,u,C)},a),{config:t})}}function w(e,n,t){return Object.keys(n).every(a=>{if(a==="class")return!0;let r=n[a],o=t?.[a],s=e?.[a];if(y(r))return m(r,s);let V=s??o;return Array.isArray(r)?r.some(c=>g(V,c)):g(V,r)})}function g(e,n){return e?.toString()===n?.toString()}function k(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=P(n);return[Object.assign(n,{compoundVariants:h(n.compoundVariants,t)}),t]}function h(e,n){return typeof e=="function"?e(n):e}0&&(module.exports={_cv,resolveCompoundVariants,resolveConfig});
2
2
  //# sourceMappingURL=cv.cjs.map
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\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n","import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n","// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => ({ ...config.defaultVariants, ...props });\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,4BAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAL,GCSO,IAAMM,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASC,EAA2BH,EAAgBI,EAAwB,CAC/E,OAAIH,EAAkBD,EAAOH,CAAe,EAAUO,IAAa,OAC1DH,EAAkBD,EAAOF,CAAiB,EAAUM,IAAa,OAEnE,EACX,CCrBO,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,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CACJ,CACJ,CAEO,SAASiC,EACZ7B,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","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","additionalClassName","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}
1
+ {"version":3,"sources":["../src/cv.ts","../src/tokens.ts","../src/utils.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n","import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n","// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = structuredClone(config.defaultVariants);\r\n for (const key in props) {\r\n if (props[key] !== undefined) defaultedProps[key] = props[key];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AAKD,CAAO,EAAE,MAAOE,GAAU,CACzC,GAAIA,IAAU,QAAS,MAAO,GAE9B,IAAMC,EAAaH,EAAQE,CAAK,EAE1BE,EAAmBH,IAAWC,CAA8B,EAC5DG,EAAgBjB,IAAQc,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,SAAS7B,EACZH,EACiC,CACjC,IAAMiC,EAAkB,CACpB,SAAU,CAAC,EACX,iBAAkB,CAAC,EACnB,gBAAiB,CAAC,EAClB,GAAGjC,CACP,EAEME,EAAQgC,EAAQD,CAAe,EAErC,MAAO,CACH,OAAO,OAAOA,EAAiB,CAC3B,iBAAkBE,EAAwBF,EAAgB,iBAAkB/B,CAAK,CACrF,CAAC,EACDA,CACJ,CACJ,CAEO,SAASiC,EACZ7B,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","additionalClassName","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, i as CVCompoundVariant, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, v as CVConfig, u as CVProps, x as CVPropsValue, b as CVReturn, w as CVReturnProps, f as CVVariant, t as CVVariantKey, d as CVVariantSchema, a as CVVariantsSchema, R as ResolvedCVConfig, V as VariantProps, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-gIK0IznJ.cjs';
4
+ export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, c as CVCompoundVariantsSchema, j as CVCompoundVariantsSchemaFunction, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, t as CVVariantKey, i as CVVariantSchema, h as CVVariantsSchema, R as ResolvedCVConfig, V as VariantProps, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-B7zWq-Wg.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, i as CVCompoundVariant, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, v as CVConfig, u as CVProps, x as CVPropsValue, b as CVReturn, w as CVReturnProps, f as CVVariant, t as CVVariantKey, d as CVVariantSchema, a as CVVariantsSchema, R as ResolvedCVConfig, V as VariantProps, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv--G8-bDtP.js';
4
+ export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, c as CVCompoundVariantsSchema, j as CVCompoundVariantsSchemaFunction, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, t as CVVariantKey, i as CVVariantSchema, h as CVVariantsSchema, R as ResolvedCVConfig, V as VariantProps, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-BdqZkdFD.js';
package/build/cv.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a,b,c}from"./chunk-XWAQU5O6.js";import"./chunk-IMTFPGTY.js";import"./chunk-77XW3WZ4.js";export{a as _cv,c as resolveCompoundVariants,b as resolveConfig};
1
+ import{a,b,c}from"./chunk-NDMNWVIC.js";import"./chunk-IMTFPGTY.js";import"./chunk-32VQFSFZ.js";export{a as _cv,c as resolveCompoundVariants,b as resolveConfig};
2
2
  //# sourceMappingURL=cv.js.map
package/build/define.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var N=Object.create;var u=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var U=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},m=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of _(n))!M.call(e,a)&&a!==t&&u(e,a,{get:()=>n[a],enumerable:!(r=K(n,a))||r.enumerable});return e};var w=(e,n,t)=>(t=e!=null?N(b(e)):{},m(n||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),B=e=>m(u({},"__esModule",{value:!0}),e);var G={};U(G,{defineCV:()=>z});module.exports=B(G);var y=w(require("clsx"),1);function x({merge:e=n=>n}){return(...n)=>e((0,y.default)(...n))}var W={__token:"OnlyWhenDefined"},A={__token:"OnlyWhenUndefined"};function S(e){return e?typeof e=="object"&&"__token"in e:!1}function h(e,n){return e.__token===n.__token}function g(e,n){return h(e,W)?n!==void 0:h(e,A)?n===void 0:!1}function P(e){return Object.keys(e)}function j(e){return Object.entries(e)}function D(e){return Object.fromEntries(j(e).map(([n,t])=>[n,P(t)]))}function E(e,n){let t={},r={};if(!e)return[t,r];for(let a in e){let s=a;n(s)?t[s]=e[s]:r[s]=e[s]}return[t,r]}function k(e){let n=P(e.variants),t=D(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:s=>E(s,o=>o in t),getVariantProps:s=>({...e.defaultVariants,...s})}}function R(e){return n=>{let[t,r]=q(n),{base:a,variants:s,compoundVariants:o,defaultVariants:V}=t,l=p=>{let C=r.getVariantProps(p),i=new Array;for(let c in s){let d=C[c]?.toString();d&&i.push(s?.[c]?.[d])}return i},v=p=>o?.reduce((C,i)=>(F(p,i,V)&&C.push(i.class),C),new Array);return Object.assign(Object.assign((p,C)=>{let i=l(p),c=v(p);return e.cn(a,i,c,C)},r),{config:t})}}function F(e,n,t){return Object.keys(n).every(r=>{if(r==="class")return!0;let a=n[r],s=t?.[r],o=e?.[r];if(S(a))return g(a,o);let V=o??s;return Array.isArray(a)?a.some(l=>O(V,l)):O(V,a)})}function O(e,n){return e?.toString()===n?.toString()}function q(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=k(n);return[Object.assign(n,{compoundVariants:f(n.compoundVariants,t)}),t]}function f(e,n){return typeof e=="function"?e(n):e}function T({cn:e,cv:n}){let t=(r,a)=>{let s=structuredClone(r);for(let o in a){s[o]??={};for(let V in a[o])s[o][V]=e(r[o]?.[V],a[o][V])}return s};return(r,a)=>{let{config:s}=r;return n({base:e(s.base,a.base),variants:t(s.variants,a.variants),compoundVariants:o=>f(s.compoundVariants,r).concat(f(a.compoundVariants??[],o)),defaultVariants:{...s.defaultVariants,...a.defaultVariants}})}}function z({merge:e}={}){let n=x({merge:e}),t=R({cn:n}),r=T({cn:n,cv:t});return{cn:n,cv:t,extend:r}}0&&(module.exports={defineCV});
1
+ "use strict";var T=Object.create;var u=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var w=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},m=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of M(n))!b.call(e,a)&&a!==t&&u(e,a,{get:()=>n[a],enumerable:!(s=K(n,a))||s.enumerable});return e};var U=(e,n,t)=>(t=e!=null?T(_(e)):{},m(n||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),B=e=>m(u({},"__esModule",{value:!0}),e);var G={};w(G,{defineCV:()=>z});module.exports=B(G);var y=U(require("clsx"),1);function x({merge:e=n=>n}){return(...n)=>e((0,y.default)(...n))}var W={__token:"OnlyWhenDefined"},E={__token:"OnlyWhenUndefined"};function S(e){return e?typeof e=="object"&&"__token"in e:!1}function h(e,n){return e.__token===n.__token}function g(e,n){return h(e,W)?n!==void 0:h(e,E)?n===void 0:!1}function P(e){return Object.keys(e)}function A(e){return Object.entries(e)}function j(e){return Object.fromEntries(A(e).map(([n,t])=>[n,P(t)]))}function D(e,n){let t={},s={};if(!e)return[t,s];for(let a in e){let r=a;n(r)?t[r]=e[r]:s[r]=e[r]}return[t,s]}function k(e){let n=P(e.variants),t=j(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:r=>D(r,o=>o in t),getVariantProps:r=>{let o=structuredClone(e.defaultVariants);for(let V in r)r[V]!==void 0&&(o[V]=r[V]);return o}}}function R(e){return n=>{let[t,s]=q(n),{base:a,variants:r,compoundVariants:o,defaultVariants:V}=t,d=p=>{let C=s.getVariantProps(p),i=new Array;for(let c in r){let l=C[c]?.toString();l&&i.push(r?.[c]?.[l])}return i},N=p=>o?.reduce((C,i)=>(F(p,i,V)&&C.push(i.class),C),new Array);return Object.assign(Object.assign((p,C)=>{let i=d(p),c=N(p);return e.cn(a,i,c,C)},s),{config:t})}}function F(e,n,t){return Object.keys(n).every(s=>{if(s==="class")return!0;let a=n[s],r=t?.[s],o=e?.[s];if(S(a))return g(a,o);let V=o??r;return Array.isArray(a)?a.some(d=>O(V,d)):O(V,a)})}function O(e,n){return e?.toString()===n?.toString()}function q(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=k(n);return[Object.assign(n,{compoundVariants:f(n.compoundVariants,t)}),t]}function f(e,n){return typeof e=="function"?e(n):e}function v({cn:e,cv:n}){let t=(s,a)=>{let r=structuredClone(s);for(let o in a){r[o]??={};for(let V in a[o])r[o][V]=e(s[o]?.[V],a[o][V])}return r};return(s,a)=>{let{config:r}=s;return n({base:e(r.base,a.base),variants:t(r.variants,a.variants),compoundVariants:o=>f(r.compoundVariants,s).concat(f(a.compoundVariants??[],o)),defaultVariants:{...r.defaultVariants,...a.defaultVariants}})}}function z({merge:e}={}){let n=x({merge:e}),t=R({cn:n}),s=v({cn:n,cv:t});return{cn:n,cv:t,extend:s}}0&&(module.exports={defineCV});
2
2
  //# sourceMappingURL=define.cjs.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\";\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","import clsx, { type ClassValue } from \"clsx\";\r\n\r\nexport interface CNOptions {\r\n merge?: (className: string) => string;\r\n}\r\n\r\nexport interface CN {\r\n (...inputs: ClassValue[]): string;\r\n}\r\n\r\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\r\n return (...inputs) => merge(clsx(...inputs));\r\n}\r\n","import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n","// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => ({ ...config.defaultVariants, ...props });\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { Merge, Prettify } from \"ts-essentials\";\r\nimport type { CN } from \"./cn\";\r\nimport {\r\n resolveCompoundVariants,\r\n type CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions) {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n"],"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,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASC,EAA2BH,EAAgBI,EAAwB,CAC/E,OAAIH,EAAkBD,EAAOH,CAAe,EAAUO,IAAa,OAC1DH,EAAkBD,EAAOF,CAAiB,EAAUM,IAAa,OAEnE,EACX,CCrBO,SAASC,EAA2CC,EAAQ,CA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AAC,EACDA,CACJ,CACJ,CAEO,SAASiC,EACZ7B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E,CCrHO,SAAS8B,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,IAAMC,EAAiB,CACnBC,EACAC,IACC,CACD,IAAMC,EAAqC,gBAAgBF,CAAQ,EACnE,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,CL7DO,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","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","additionalClassName","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
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\";\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","import clsx, { type ClassValue } from \"clsx\";\r\n\r\nexport interface CNOptions {\r\n merge?: (className: string) => string;\r\n}\r\n\r\nexport interface CN {\r\n (...inputs: ClassValue[]): string;\r\n}\r\n\r\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\r\n return (...inputs) => merge(clsx(...inputs));\r\n}\r\n","import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n","// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = structuredClone(config.defaultVariants);\r\n for (const key in props) {\r\n if (props[key] !== undefined) defaultedProps[key] = props[key];\r\n }\r\n return defaultedProps;\r\n };\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { Merge, Prettify } from \"ts-essentials\";\r\nimport type { CN } from \"./cn\";\r\nimport {\r\n resolveCompoundVariants,\r\n type CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\nexport interface CVExtend {\r\n <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ): CVReturn<MergeVariantsSchemas<V, NewV>>\r\n}\r\n\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAsC,qBAU/B,SAASC,EAAI,CAAE,MAAAC,EAASC,GAAcA,CAAU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AUP,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,CL5EO,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","additionalClassName","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
@@ -1,19 +1,15 @@
1
- import * as ts_essentials from 'ts-essentials';
2
- import * as clsx from 'clsx';
3
- import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv-gIK0IznJ.cjs';
1
+ import { CVExtend } from './extend.cjs';
2
+ import { C as CV } from './cv-B7zWq-Wg.cjs';
4
3
  import { CNOptions, CN } from './cn.cjs';
4
+ import 'clsx';
5
+ import 'ts-essentials';
5
6
 
6
7
  interface DefineCVOptions extends CNOptions {
7
8
  }
8
9
  declare function defineCV({ merge }?: DefineCVOptions): {
9
10
  readonly cn: CN;
10
11
  readonly cv: CV;
11
- readonly extend: <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
12
- base?: clsx.ClassValue;
13
- variants?: NewV;
14
- compoundVariants?: CVCompoundVariantsSchema<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>> | CVCompoundVariantsSchemaFunction<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
15
- defaultVariants?: CVVariant<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
16
- }) => CVReturn<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
12
+ readonly extend: CVExtend;
17
13
  };
18
14
 
19
15
  export { type DefineCVOptions, defineCV };
package/build/define.d.ts CHANGED
@@ -1,19 +1,15 @@
1
- import * as ts_essentials from 'ts-essentials';
2
- import * as clsx from 'clsx';
3
- import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv--G8-bDtP.js';
1
+ import { CVExtend } from './extend.js';
2
+ import { C as CV } from './cv-BdqZkdFD.js';
4
3
  import { CNOptions, CN } from './cn.js';
4
+ import 'clsx';
5
+ import 'ts-essentials';
5
6
 
6
7
  interface DefineCVOptions extends CNOptions {
7
8
  }
8
9
  declare function defineCV({ merge }?: DefineCVOptions): {
9
10
  readonly cn: CN;
10
11
  readonly cv: CV;
11
- readonly extend: <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
12
- base?: clsx.ClassValue;
13
- variants?: NewV;
14
- compoundVariants?: CVCompoundVariantsSchema<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>> | CVCompoundVariantsSchemaFunction<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
15
- defaultVariants?: CVVariant<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
16
- }) => CVReturn<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
12
+ readonly extend: CVExtend;
17
13
  };
18
14
 
19
15
  export { type DefineCVOptions, defineCV };
package/build/define.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-AQKDS5WX.js";import"./chunk-FIET564E.js";import"./chunk-UUT6STP6.js";import"./chunk-XWAQU5O6.js";import"./chunk-IMTFPGTY.js";import"./chunk-77XW3WZ4.js";export{a as defineCV};
1
+ import{a}from"./chunk-G3WOK6WL.js";import"./chunk-FIET564E.js";import"./chunk-FNDRMHIF.js";import"./chunk-NDMNWVIC.js";import"./chunk-IMTFPGTY.js";import"./chunk-32VQFSFZ.js";export{a as defineCV};
2
2
  //# sourceMappingURL=define.js.map
package/build/extend.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var o in t)i(e,o,{get:t[o],enumerable:!0})},d=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of c(t))!u.call(e,n)&&n!==o&&i(e,n,{get:()=>t[n],enumerable:!(a=C(t,n))||a.enumerable});return e};var l=e=>d(i({},"__esModule",{value:!0}),e);var y={};f(y,{_extend:()=>m});module.exports=l(y);function p(e,t){return typeof e=="function"?e(t):e}function m({cn:e,cv:t}){let o=(a,n)=>{let r=structuredClone(a);for(let s in n){r[s]??={};for(let V in n[s])r[s][V]=e(a[s]?.[V],n[s][V])}return r};return(a,n)=>{let{config:r}=a;return t({base:e(r.base,n.base),variants:o(r.variants,n.variants),compoundVariants:s=>p(r.compoundVariants,a).concat(p(n.compoundVariants??[],s)),defaultVariants:{...r.defaultVariants,...n.defaultVariants}})}}0&&(module.exports={_extend});
1
+ "use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var d=(e,t)=>{for(var s in t)i(e,s,{get:t[s],enumerable:!0})},f=(e,t,s,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of c(t))!u.call(e,n)&&n!==s&&i(e,n,{get:()=>t[n],enumerable:!(a=p(t,n))||a.enumerable});return e};var l=e=>f(i({},"__esModule",{value:!0}),e);var y={};d(y,{_extend:()=>m});module.exports=l(y);function C(e,t){return typeof e=="function"?e(t):e}function m({cn:e,cv:t}){let s=(a,n)=>{let r=structuredClone(a);for(let V in n){r[V]??={};for(let o in n[V])r[V][o]=e(a[V]?.[o],n[V][o])}return r};return(a,n)=>{let{config:r}=a;return t({base:e(r.base,n.base),variants:s(r.variants,n.variants),compoundVariants:V=>C(r.compoundVariants,a).concat(C(n.compoundVariants??[],V)),defaultVariants:{...r.defaultVariants,...n.defaultVariants}})}}0&&(module.exports={_extend});
2
2
  //# sourceMappingURL=extend.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/extend.ts","../src/cv.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 CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions) {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GC6IO,SAASI,EACZC,EACAC,EACF,CACE,OAAO,OAAOD,GAAqB,WAAaA,EAAiBC,CAAK,EAAID,CAC9E,CDrHO,SAASE,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,IAAMC,EAAiB,CACnBC,EACAC,IACC,CACD,IAAMC,EAAqC,gBAAgBF,CAAQ,EACnE,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\";\r\nimport type { Merge, Prettify } from \"ts-essentials\";\r\nimport type { CN } from \"./cn\";\r\nimport {\r\n resolveCompoundVariants,\r\n type CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\nexport interface CVExtend {\r\n <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ): CVReturn<MergeVariantsSchemas<V, NewV>>\r\n}\r\n\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GC6IO,SAASI,EACZC,EACAC,EACF,CACE,OAAO,OAAOD,GAAqB,WAAaA,EAAiBC,CAAK,EAAID,CAC9E,CDtGO,SAASE,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CACnBC,EACAC,IACC,CACD,IAAMC,EAAqC,gBAAgBF,CAAQ,EACnE,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,21 +1,24 @@
1
1
  import { ClassValue } from 'clsx';
2
2
  import { Merge, Prettify } from 'ts-essentials';
3
3
  import { CN } from './cn.cjs';
4
- import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, d as CVVariantSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv-gIK0IznJ.cjs';
4
+ import { h as CVVariantsSchema, d as CVReturn, c as CVCompoundVariantsSchema, i as CVVariantSchema, j as CVCompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-B7zWq-Wg.cjs';
5
5
 
6
6
  type MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
7
7
  type MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<V1 & V2, {
8
8
  [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;
9
9
  }>;
10
+ interface CVExtend {
11
+ <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
12
+ base?: ClassValue;
13
+ variants?: NewV;
14
+ compoundVariants?: CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>> | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;
15
+ defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;
16
+ }): CVReturn<MergeVariantsSchemas<V, NewV>>;
17
+ }
10
18
  interface CVExtendOptions {
11
19
  cn: CN;
12
20
  cv: CV;
13
21
  }
14
- declare function _extend({ cn, cv }: CVExtendOptions): <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
15
- base?: ClassValue;
16
- variants?: NewV;
17
- compoundVariants?: CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>> | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;
18
- defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;
19
- }) => CVReturn<Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: Prettify<Record<keyof V[K] | keyof NewV[K], ClassValue>>; }>>;
22
+ declare function _extend({ cn, cv }: CVExtendOptions): CVExtend;
20
23
 
21
- export { _extend };
24
+ export { type CVExtend, _extend };
package/build/extend.d.ts CHANGED
@@ -1,21 +1,24 @@
1
1
  import { ClassValue } from 'clsx';
2
2
  import { Merge, Prettify } from 'ts-essentials';
3
3
  import { CN } from './cn.js';
4
- import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, d as CVVariantSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv--G8-bDtP.js';
4
+ import { h as CVVariantsSchema, d as CVReturn, c as CVCompoundVariantsSchema, i as CVVariantSchema, j as CVCompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-BdqZkdFD.js';
5
5
 
6
6
  type MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
7
7
  type MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<V1 & V2, {
8
8
  [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;
9
9
  }>;
10
+ interface CVExtend {
11
+ <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
12
+ base?: ClassValue;
13
+ variants?: NewV;
14
+ compoundVariants?: CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>> | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;
15
+ defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;
16
+ }): CVReturn<MergeVariantsSchemas<V, NewV>>;
17
+ }
10
18
  interface CVExtendOptions {
11
19
  cn: CN;
12
20
  cv: CV;
13
21
  }
14
- declare function _extend({ cn, cv }: CVExtendOptions): <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
15
- base?: ClassValue;
16
- variants?: NewV;
17
- compoundVariants?: CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>> | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;
18
- defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;
19
- }) => CVReturn<Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: Prettify<Record<keyof V[K] | keyof NewV[K], ClassValue>>; }>>;
22
+ declare function _extend({ cn, cv }: CVExtendOptions): CVExtend;
20
23
 
21
- export { _extend };
24
+ export { type CVExtend, _extend };
package/build/extend.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-UUT6STP6.js";import"./chunk-XWAQU5O6.js";import"./chunk-IMTFPGTY.js";import"./chunk-77XW3WZ4.js";export{a as _extend};
1
+ import{a}from"./chunk-FNDRMHIF.js";import"./chunk-NDMNWVIC.js";import"./chunk-IMTFPGTY.js";import"./chunk-32VQFSFZ.js";export{a as _extend};
2
2
  //# sourceMappingURL=extend.js.map
package/build/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var U=Object.create;var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var B=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},h=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of M(n))!w.call(e,a)&&a!==t&&u(e,a,{get:()=>n[a],enumerable:!(r=b(n,a))||r.enumerable});return e};var A=(e,n,t)=>(t=e!=null?U(W(e)):{},h(n||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),D=e=>h(u({},"__esModule",{value:!0}),e);var J={};B(J,{cn:()=>G,cv:()=>H,defineCV:()=>y,extend:()=>I,onlyWhenDefined:()=>l,onlyWhenUndefined:()=>m});module.exports=D(J);var l={__token:"OnlyWhenDefined"},m={__token:"OnlyWhenUndefined"};function g(e){return e?typeof e=="object"&&"__token"in e:!1}function S(e,n){return e.__token===n.__token}function P(e,n){return S(e,l)?n!==void 0:S(e,m)?n===void 0:!1}var k=A(require("clsx"),1);function O({merge:e=n=>n}){return(...n)=>e((0,k.default)(...n))}function R(e){return Object.keys(e)}function j(e){return Object.entries(e)}function E(e){return Object.fromEntries(j(e).map(([n,t])=>[n,R(t)]))}function F(e,n){let t={},r={};if(!e)return[t,r];for(let a in e){let o=a;n(o)?t[o]=e[o]:r[o]=e[o]}return[t,r]}function T(e){let n=R(e.variants),t=E(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:o=>F(o,s=>s in t),getVariantProps:o=>({...e.defaultVariants,...o})}}function N(e){return n=>{let[t,r]=z(n),{base:a,variants:o,compoundVariants:s,defaultVariants:V}=t,d=p=>{let C=r.getVariantProps(p),i=new Array;for(let c in o){let x=C[c]?.toString();x&&i.push(o?.[c]?.[x])}return i},_=p=>s?.reduce((C,i)=>(q(p,i,V)&&C.push(i.class),C),new Array);return Object.assign(Object.assign((p,C)=>{let i=d(p),c=_(p);return e.cn(a,i,c,C)},r),{config:t})}}function q(e,n,t){return Object.keys(n).every(r=>{if(r==="class")return!0;let a=n[r],o=t?.[r],s=e?.[r];if(g(a))return P(a,s);let V=s??o;return Array.isArray(a)?a.some(d=>v(V,d)):v(V,a)})}function v(e,n){return e?.toString()===n?.toString()}function z(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=T(n);return[Object.assign(n,{compoundVariants:f(n.compoundVariants,t)}),t]}function f(e,n){return typeof e=="function"?e(n):e}function K({cn:e,cv:n}){let t=(r,a)=>{let o=structuredClone(r);for(let s in a){o[s]??={};for(let V in a[s])o[s][V]=e(r[s]?.[V],a[s][V])}return o};return(r,a)=>{let{config:o}=r;return n({base:e(o.base,a.base),variants:t(o.variants,a.variants),compoundVariants:s=>f(o.compoundVariants,r).concat(f(a.compoundVariants??[],s)),defaultVariants:{...o.defaultVariants,...a.defaultVariants}})}}function y({merge:e}={}){let n=O({merge:e}),t=N({cn:n}),r=K({cn:n,cv:t});return{cn:n,cv:t,extend:r}}var{cn:G,cv:H,extend:I}=y();0&&(module.exports={cn,cv,defineCV,extend,onlyWhenDefined,onlyWhenUndefined});
1
+ "use strict";var _=Object.create;var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var B=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},h=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of w(n))!W.call(e,a)&&a!==t&&u(e,a,{get:()=>n[a],enumerable:!(o=b(n,a))||o.enumerable});return e};var E=(e,n,t)=>(t=e!=null?_(U(e)):{},h(n||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),A=e=>h(u({},"__esModule",{value:!0}),e);var J={};B(J,{cn:()=>G,cv:()=>H,defineCV:()=>y,extend:()=>I,onlyWhenDefined:()=>m,onlyWhenUndefined:()=>l});module.exports=A(J);var S=E(require("clsx"),1);function g({merge:e=n=>n}){return(...n)=>e((0,S.default)(...n))}var m={__token:"OnlyWhenDefined"},l={__token:"OnlyWhenUndefined"};function k(e){return e?typeof e=="object"&&"__token"in e:!1}function P(e,n){return e.__token===n.__token}function O(e,n){return P(e,m)?n!==void 0:P(e,l)?n===void 0:!1}function R(e){return Object.keys(e)}function D(e){return Object.entries(e)}function j(e){return Object.fromEntries(D(e).map(([n,t])=>[n,R(t)]))}function F(e,n){let t={},o={};if(!e)return[t,o];for(let a in e){let r=a;n(r)?t[r]=e[r]:o[r]=e[r]}return[t,o]}function v(e){let n=R(e.variants),t=j(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:r=>F(r,V=>V in t),getVariantProps:r=>{let V=structuredClone(e.defaultVariants);for(let s in r)r[s]!==void 0&&(V[s]=r[s]);return V}}}function T(e){return n=>{let[t,o]=z(n),{base:a,variants:r,compoundVariants:V,defaultVariants:s}=t,d=p=>{let C=o.getVariantProps(p),i=new Array;for(let c in r){let x=C[c]?.toString();x&&i.push(r?.[c]?.[x])}return i},M=p=>V?.reduce((C,i)=>(q(p,i,s)&&C.push(i.class),C),new Array);return Object.assign(Object.assign((p,C)=>{let i=d(p),c=M(p);return e.cn(a,i,c,C)},o),{config:t})}}function q(e,n,t){return Object.keys(n).every(o=>{if(o==="class")return!0;let a=n[o],r=t?.[o],V=e?.[o];if(k(a))return O(a,V);let s=V??r;return Array.isArray(a)?a.some(d=>N(s,d)):N(s,a)})}function N(e,n){return e?.toString()===n?.toString()}function z(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=v(n);return[Object.assign(n,{compoundVariants:f(n.compoundVariants,t)}),t]}function f(e,n){return typeof e=="function"?e(n):e}function K({cn:e,cv:n}){let t=(o,a)=>{let r=structuredClone(o);for(let V in a){r[V]??={};for(let s in a[V])r[V][s]=e(o[V]?.[s],a[V][s])}return r};return(o,a)=>{let{config:r}=o;return n({base:e(r.base,a.base),variants:t(r.variants,a.variants),compoundVariants:V=>f(r.compoundVariants,o).concat(f(a.compoundVariants??[],V)),defaultVariants:{...r.defaultVariants,...a.defaultVariants}})}}function y({merge:e}={}){let n=g({merge:e}),t=T({cn:n}),o=K({cn:n,cv:t});return{cn:n,cv:t,extend:o}}var{cn:G,cv:H,extend:I}=y();0&&(module.exports={cn,cv,defineCV,extend,onlyWhenDefined,onlyWhenUndefined});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/tokens.ts","../src/cn.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts","../src/define.ts"],"sourcesContent":["import type { CN } from \"./cn\";\r\nimport type {\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVReturn,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n} from \"./cv\";\r\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\r\nimport { defineCV } from \"./define\";\r\nimport type { CVUtils } from \"./utils\";\r\n\r\nexport const { cn, cv, extend } = defineCV();\r\n\r\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\r\nexport type {\r\n CN,\r\n CV,\r\n CVUtils,\r\n CVReturn,\r\n VariantProps,\r\n CVVariantsSchema,\r\n CVCompoundVariantsSchema,\r\n CVVariant,\r\n CVCompoundVariant,\r\n CVToken,\r\n};\r\n","import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n","import clsx, { type ClassValue } from \"clsx\";\r\n\r\nexport interface CNOptions {\r\n merge?: (className: string) => string;\r\n}\r\n\r\nexport interface CN {\r\n (...inputs: ClassValue[]): string;\r\n}\r\n\r\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\r\n return (...inputs) => merge(clsx(...inputs));\r\n}\r\n","// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => ({ ...config.defaultVariants, ...props });\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { Merge, Prettify } from \"ts-essentials\";\r\nimport type { CN } from \"./cn\";\r\nimport {\r\n resolveCompoundVariants,\r\n type CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions) {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n","import { _cn, type CNOptions } from \"./cn\";\r\nimport { _cv } from \"./cv\";\r\nimport { _extend } from \"./extend\";\r\n\r\nexport interface DefineCVOptions extends CNOptions {}\r\n\r\nexport function defineCV({ merge }: DefineCVOptions = {}) {\r\n const cn = _cn({ merge });\r\n\r\n const cv = _cv({ cn });\r\n\r\n const extend = _extend({ cn, cv });\r\n\r\n return { cn, cv, extend } as const;\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,OAAAC,EAAA,aAAAC,EAAA,WAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAR,GCSO,IAAMS,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASC,EAA2BH,EAAgBI,EAAwB,CAC/E,OAAIH,EAAkBD,EAAOH,CAAe,EAAUO,IAAa,OAC1DH,EAAkBD,EAAOF,CAAiB,EAAUM,IAAa,OAEnE,EACX,CCzBA,IAAAC,EAAsC,qBAU/B,SAASC,EAAI,CAAE,MAAAC,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,KAAM,EAAAG,SAAK,GAAGD,CAAM,CAAC,CAC/C,CCRO,SAASE,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA0CC,EAAa,CACnE,OAAO,OAAO,YAAYF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IA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ACAC,IACC,CACD,IAAMC,EAAqC,gBAAgBF,CAAQ,EACnE,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,CC7DO,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,CNAO,GAAM,CAAE,GAAAE,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["index_exports","__export","cn","cv","defineCV","extend","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","import_clsx","_cn","merge","className","inputs","clsx","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","additionalClassName","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend","cn","cv","extend","defineCV"]}
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\";\r\nimport type {\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVReturn,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n} from \"./cv\";\r\nimport { defineCV } from \"./define\";\r\nimport { type CVExtend } from \"./extend\";\r\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\r\nimport type { CVUtils } from \"./utils\";\r\n\r\nexport const { cn, cv, extend } = defineCV();\r\n\r\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\r\nexport type {\r\n CN,\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVExtend,\r\n CVReturn,\r\n CVToken,\r\n CVUtils,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n};\r\n","import clsx, { type ClassValue } from \"clsx\";\r\n\r\nexport interface CNOptions {\r\n merge?: (className: string) => string;\r\n}\r\n\r\nexport interface CN {\r\n (...inputs: ClassValue[]): string;\r\n}\r\n\r\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\r\n return (...inputs) => merge(clsx(...inputs));\r\n}\r\n","import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n","// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = structuredClone(config.defaultVariants);\r\n for (const key in props) {\r\n if (props[key] !== undefined) defaultedProps[key] = props[key];\r\n }\r\n return defaultedProps;\r\n };\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { ArrayOrSingle } from \"ts-essentials\";\r\nimport { type CN } from \"./cn\";\r\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\r\nimport { cvUtils, type CVUtils } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\r\n\r\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\r\n\r\nexport type CVVariantKey = string | number;\r\n\r\nexport type CVVariantSchema = Record<CVVariantKey, ClassValue>;\r\nexport type CVVariantsSchema = Record<string, CVVariantSchema>;\r\n\r\nexport type CVVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;\r\n};\r\n\r\nexport type CVProps<V extends CVVariantsSchema> = CVVariant<V>;\r\n\r\nexport type CVCompoundVariant<V extends CVVariantsSchema> = {\r\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;\r\n} & { class: ClassValue };\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\r\nexport type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (\r\n utils: CVUtils<V>,\r\n) => CVCompoundVariantsSchema<V>;\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n base: ClassValue;\r\n variants: V;\r\n compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;\r\n defaultVariants: CVVariant<V>;\r\n}\r\n\r\nexport interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {\r\n compoundVariants: CVCompoundVariantsSchema<V>;\r\n}\r\n\r\nexport type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;\r\n\r\nexport interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {\r\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\r\n config: ResolvedCVConfig<V>;\r\n}\r\n\r\nexport interface CV {\r\n <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\r\n}\r\n\r\ninterface CVOptions {\r\n cn: CN;\r\n}\r\nexport function _cv(options: CVOptions): CV {\r\n return <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>) => {\r\n const [resolvedConfig, utils] = resolveConfig(config);\r\n\r\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\r\n\r\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = utils.getVariantProps(props);\r\n\r\n const classNames = new Array<ClassValue>();\r\n for (const key in variants) {\r\n const variant = defaultedProps[key]?.toString();\r\n if (variant) classNames.push(variants?.[key]?.[variant]);\r\n }\r\n return classNames;\r\n };\r\n\r\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\r\n return compoundVariants?.reduce((acc, compoundVariant) => {\r\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\r\n acc.push(compoundVariant.class);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n };\r\n\r\n const getVariant = (props?: CVReturnProps<V>, additionalClassName?: ClassValue) => {\r\n const variantClassNames = getVariantsClassNames(props);\r\n\r\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\r\n\r\n return options.cn(base, variantClassNames, compoundVariantClassNames, additionalClassName);\r\n };\r\n\r\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\r\n };\r\n}\r\n\r\nfunction shouldApplyCompoundVariant<V extends CVVariantsSchema>(\r\n props: CVReturnProps<V> | undefined,\r\n matcher: CVCompoundVariant<V>,\r\n defaults: CVVariant<V> | undefined,\r\n) {\r\n return Object.keys(matcher).every((cvKey) => {\r\n if (cvKey === \"class\") return true;\r\n\r\n const cvSelector = matcher[cvKey];\r\n\r\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector)\r\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\r\n : compareSelectors(selector, cvSelector);\r\n });\r\n}\r\n\r\nexport type CVPropsValue = CVVariantKey | boolean | undefined;\r\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\r\n return selector1?.toString() === selector2?.toString();\r\n}\r\n\r\nexport function resolveConfig<V extends CVVariantsSchema>(\r\n config: Partial<CVConfig<V>>,\r\n): [ResolvedCVConfig<V>, CVUtils<V>] {\r\n const defaultedConfig = {\r\n variants: {},\r\n compoundVariants: [],\r\n defaultVariants: {},\r\n ...config,\r\n } as CVConfig<V>;\r\n\r\n const utils = cvUtils(defaultedConfig);\r\n\r\n return [\r\n Object.assign(defaultedConfig, {\r\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\r\n }),\r\n utils,\r\n ] as const;\r\n}\r\n\r\nexport function resolveCompoundVariants<V extends CVVariantsSchema>(\r\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\r\n utils: CVUtils<V>,\r\n) {\r\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\r\n}\r\n","import type { ClassValue } from \"clsx\";\r\nimport type { Merge, Prettify } from \"ts-essentials\";\r\nimport type { CN } from \"./cn\";\r\nimport {\r\n resolveCompoundVariants,\r\n type CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\nexport interface CVExtend {\r\n <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ): CVReturn<MergeVariantsSchemas<V, NewV>>\r\n}\r\n\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n","import { _cn, type CNOptions } from \"./cn\";\r\nimport { _cv } from \"./cv\";\r\nimport { _extend } from \"./extend\";\r\n\r\nexport interface DefineCVOptions extends CNOptions {}\r\n\r\nexport function defineCV({ merge }: DefineCVOptions = {}) {\r\n const cn = _cn({ merge });\r\n\r\n const cv = _cv({ cn });\r\n\r\n const extend = _extend({ cn, cv });\r\n\r\n return { cn, cv, extend } as const;\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,OAAAC,EAAA,aAAAC,EAAA,WAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAR,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,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASC,EAA2BH,EAAgBI,EAAwB,CAC/E,OAAIH,EAAkBD,EAAOH,CAAe,EAAUO,IAAa,OAC1DH,EAAkBD,EAAOF,CAAiB,EAAUM,IAAa,OAEnE,EACX,CCrBO,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA0CC,EAAa,CACnE,OAAO,OAAO,YAAYF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CA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AS8B,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CACnBC,EACAC,IACC,CACD,IAAMC,EAAqC,gBAAgBF,CAAQ,EACnE,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,CC5EO,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","additionalClassName","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend","cn","cv","extend","defineCV"]}
package/build/index.d.cts CHANGED
@@ -1,17 +1,13 @@
1
- import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv-gIK0IznJ.cjs';
2
- export { i as CVCompoundVariant, j as CVToken, h as CVUtils, V as VariantProps, o as onlyWhenDefined, g as onlyWhenUndefined } from './cv-gIK0IznJ.cjs';
3
- import * as ts_essentials from 'ts-essentials';
4
- import * as clsx from 'clsx';
5
1
  import { CN } from './cn.cjs';
2
+ import { C as CV } from './cv-B7zWq-Wg.cjs';
3
+ export { b as CVCompoundVariant, c as CVCompoundVariantsSchema, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, h as CVVariantsSchema, V as VariantProps, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-B7zWq-Wg.cjs';
6
4
  export { defineCV } from './define.cjs';
5
+ import { CVExtend } from './extend.cjs';
6
+ import 'clsx';
7
+ import 'ts-essentials';
7
8
 
8
9
  declare const cn: CN;
9
10
  declare const cv: CV;
10
- declare const extend: <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
11
- base?: clsx.ClassValue;
12
- variants?: NewV;
13
- compoundVariants?: CVCompoundVariantsSchema<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>> | CVCompoundVariantsSchemaFunction<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
14
- defaultVariants?: CVVariant<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
15
- }) => CVReturn<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
11
+ declare const extend: CVExtend;
16
12
 
17
- export { CN, CV, CVCompoundVariantsSchema, CVReturn, CVVariant, CVVariantsSchema, cn, cv, extend };
13
+ export { CN, CV, CVExtend, cn, cv, extend };
package/build/index.d.ts CHANGED
@@ -1,17 +1,13 @@
1
- import { C as CV, a as CVVariantsSchema, b as CVReturn, c as CVCompoundVariantsSchema, e as CVCompoundVariantsSchemaFunction, f as CVVariant } from './cv--G8-bDtP.js';
2
- export { i as CVCompoundVariant, j as CVToken, h as CVUtils, V as VariantProps, o as onlyWhenDefined, g as onlyWhenUndefined } from './cv--G8-bDtP.js';
3
- import * as ts_essentials from 'ts-essentials';
4
- import * as clsx from 'clsx';
5
1
  import { CN } from './cn.js';
2
+ import { C as CV } from './cv-BdqZkdFD.js';
3
+ export { b as CVCompoundVariant, c as CVCompoundVariantsSchema, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, h as CVVariantsSchema, V as VariantProps, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-BdqZkdFD.js';
6
4
  export { defineCV } from './define.js';
5
+ import { CVExtend } from './extend.js';
6
+ import 'clsx';
7
+ import 'ts-essentials';
7
8
 
8
9
  declare const cn: CN;
9
10
  declare const cv: CV;
10
- declare const extend: <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
11
- base?: clsx.ClassValue;
12
- variants?: NewV;
13
- compoundVariants?: CVCompoundVariantsSchema<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>> | CVCompoundVariantsSchemaFunction<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
14
- defaultVariants?: CVVariant<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
15
- }) => CVReturn<ts_essentials.Prettify<Omit<V & NewV, keyof V & keyof NewV> & { [K in keyof V & keyof NewV]: ts_essentials.Prettify<Record<keyof V[K] | keyof NewV[K], clsx.ClassValue>>; }>>;
11
+ declare const extend: CVExtend;
16
12
 
17
- export { CN, CV, CVCompoundVariantsSchema, CVReturn, CVVariant, CVVariantsSchema, cn, cv, extend };
13
+ export { CN, CV, CVExtend, cn, cv, extend };
package/build/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as n}from"./chunk-AQKDS5WX.js";import"./chunk-FIET564E.js";import"./chunk-UUT6STP6.js";import"./chunk-XWAQU5O6.js";import{a as t,b as o}from"./chunk-IMTFPGTY.js";import"./chunk-77XW3WZ4.js";var{cn:e,cv:a,extend:C}=n();export{e as cn,a as cv,n as defineCV,C as extend,t as onlyWhenDefined,o as onlyWhenUndefined};
1
+ import{a as t}from"./chunk-G3WOK6WL.js";import"./chunk-FIET564E.js";import"./chunk-FNDRMHIF.js";import"./chunk-NDMNWVIC.js";import{a as n,b as o}from"./chunk-IMTFPGTY.js";import"./chunk-32VQFSFZ.js";var{cn:V,cv:C,extend:a}=t();export{V as cn,C as cv,t as defineCV,a as extend,n as onlyWhenDefined,o as onlyWhenUndefined};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CN } from \"./cn\";\r\nimport type {\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVReturn,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n} from \"./cv\";\r\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\r\nimport { defineCV } from \"./define\";\r\nimport type { CVUtils } from \"./utils\";\r\n\r\nexport const { cn, cv, extend } = defineCV();\r\n\r\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\r\nexport type {\r\n CN,\r\n CV,\r\n CVUtils,\r\n CVReturn,\r\n VariantProps,\r\n CVVariantsSchema,\r\n CVCompoundVariantsSchema,\r\n CVVariant,\r\n CVCompoundVariant,\r\n CVToken,\r\n};\r\n"],"mappings":"uMAcO,GAAM,CAAE,GAAAA,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["cn","cv","extend","defineCV"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CN } from \"./cn\";\r\nimport type {\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVReturn,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n} from \"./cv\";\r\nimport { defineCV } from \"./define\";\r\nimport { type CVExtend } from \"./extend\";\r\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\r\nimport type { CVUtils } from \"./utils\";\r\n\r\nexport const { cn, cv, extend } = defineCV();\r\n\r\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\r\nexport type {\r\n CN,\r\n CV,\r\n CVCompoundVariant,\r\n CVCompoundVariantsSchema,\r\n CVExtend,\r\n CVReturn,\r\n CVToken,\r\n CVUtils,\r\n CVVariant,\r\n CVVariantsSchema,\r\n VariantProps,\r\n};\r\n"],"mappings":"uMAeO,GAAM,CAAE,GAAAA,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["cn","cv","extend","defineCV"]}
@@ -1,4 +1,4 @@
1
1
  import 'ts-essentials';
2
- export { j as CVToken, k as isCVToken, o as onlyWhenDefined, g as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-gIK0IznJ.cjs';
2
+ export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-B7zWq-Wg.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 { j as CVToken, k as isCVToken, o as onlyWhenDefined, g as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv--G8-bDtP.js';
2
+ export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-BdqZkdFD.js';
3
3
  import 'clsx';
4
4
  import './cn.js';
package/build/utils.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var C=(t,r)=>{for(var e in r)a(t,e,{get:r[e],enumerable:!0})},l=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of y(r))!u.call(t,o)&&o!==e&&a(t,o,{get:()=>r[o],enumerable:!(s=f(r,o))||s.enumerable});return t};var k=t=>l(a({},"__esModule",{value:!0}),t);var x={};C(x,{cvUtils:()=>d,getEntries:()=>V,getKeys:()=>i,getVariantMap:()=>p,splitProps:()=>P});module.exports=k(x);function i(t){return Object.keys(t)}function V(t){return Object.entries(t)}function p(t){return Object.fromEntries(V(t).map(([r,e])=>[r,i(e)]))}function P(t,r){let e={},s={};if(!t)return[e,s];for(let o in t){let n=o;r(n)?e[n]=t[n]:s[n]=t[n]}return[e,s]}function d(t){let r=i(t.variants),e=p(t.variants);return{variantKeys:r,variantMap:e,splitVariantProps:n=>P(n,c=>c in e),getVariantProps:n=>({...t.defaultVariants,...n})}}0&&(module.exports={cvUtils,getEntries,getKeys,getVariantMap,splitProps});
1
+ "use strict";var V=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var r in e)V(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of y(e))!C.call(t,o)&&o!==r&&V(t,o,{get:()=>e[o],enumerable:!(s=u(e,o))||s.enumerable});return t};var k=t=>l(V({},"__esModule",{value:!0}),t);var O={};d(O,{cvUtils:()=>x,getEntries:()=>f,getKeys:()=>p,getVariantMap:()=>c,splitProps:()=>P});module.exports=k(O);function p(t){return Object.keys(t)}function f(t){return Object.entries(t)}function c(t){return Object.fromEntries(f(t).map(([e,r])=>[e,p(r)]))}function P(t,e){let r={},s={};if(!t)return[r,s];for(let o in t){let n=o;e(n)?r[n]=t[n]:s[n]=t[n]}return[r,s]}function x(t){let e=p(t.variants),r=c(t.variants);return{variantKeys:e,variantMap:r,splitVariantProps:n=>P(n,a=>a in r),getVariantProps:n=>{let a=structuredClone(t.defaultVariants);for(let i in n)n[i]!==void 0&&(a[i]=n[i]);return a}}}0&&(module.exports={cvUtils,getEntries,getKeys,getVariantMap,splitProps});
2
2
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => ({ ...config.defaultVariants, ...props });\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,eAAAC,EAAA,YAAAC,EAAA,kBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GAIO,SAASI,EAA2CI,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASL,EAA8CK,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASH,EAA0CI,EAAa,CACnE,OAAO,OAAO,YAAYN,EAAWM,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAON,EAAQO,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASL,EAAmBM,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO,MAAO,CAACE,EAAeC,CAAU,EAC7C,QAAWC,KAAWJ,EAAO,CACzB,IAAMK,EAAMD,EACRH,EAAYI,CAAG,EAAGH,EAAcG,CAAG,EAAIL,EAAMK,CAAG,EAC/CF,EAAWE,CAAG,EAAIL,EAAMK,CAAG,CACpC,CACA,MAAO,CAACH,EAAeC,CAAU,CACrC,CAWO,SAASb,EAAoCgB,EAAiC,CACjF,IAAMC,EAAcf,EAAQc,EAAO,QAAQ,EACrCE,EAAaf,EAAca,EAAO,QAAQ,EAIhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBAHPR,GAA6BN,EAAWM,EAAQK,GAAQA,KAAOG,CAAU,EAG/C,gBAF5BR,IAA8B,CAAE,GAAGM,EAAO,gBAAiB,GAAGN,CAAM,EAExB,CACzE","names":["utils_exports","__export","cvUtils","getEntries","getKeys","getVariantMap","splitProps","__toCommonJS","obj","variants","cvKey","cvVal","props","shouldSplit","splittedProps","otherProps","propKey","key","config","variantKeys","variantMap"]}
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["// import type { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport type { Prettify } from \"ts-essentials\";\r\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, CVVariantKey, CVVariantsSchema } from \"./cv\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O & CVVariantKey)[];\r\n}\r\n\r\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\r\n}\r\n\r\nexport type VariantMap<V extends CVVariantsSchema> = {\r\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];\r\n};\r\nexport function getVariantMap<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\r\n}\r\n\r\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\r\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\r\n if (!props) return [splittedProps, otherProps] as const;\r\n for (const propKey in props) {\r\n const key = propKey as keyof TProps;\r\n if (shouldSplit(key)) splittedProps[key] = props[key];\r\n else otherProps[key] = props[key];\r\n }\r\n return [splittedProps, otherProps] as const;\r\n}\r\n\r\nexport interface CVUtils<V extends CVVariantsSchema> {\r\n variantKeys: (keyof V & string)[];\r\n variantMap: Prettify<VariantMap<V>>;\r\n splitVariantProps: <TProps extends CVReturnProps<V>>(\r\n props?: TProps,\r\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\r\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\r\n}\r\n\r\nexport function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V> {\r\n const variantKeys = getKeys(config.variants);\r\n const variantMap = getVariantMap(config.variants);\r\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\r\n const getVariantProps = (props?: CVReturnProps<V>) => {\r\n const defaultedProps = structuredClone(config.defaultVariants);\r\n for (const key in props) {\r\n if (props[key] !== undefined) defaultedProps[key] = props[key];\r\n }\r\n return defaultedProps;\r\n };\r\n\r\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,eAAAC,EAAA,YAAAC,EAAA,kBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GAIO,SAASI,EAA2CI,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASL,EAA8CK,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASH,EAA0CI,EAAa,CACnE,OAAO,OAAO,YAAYN,EAAWM,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAON,EAAQO,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASL,EAAmBM,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO,MAAO,CAACE,EAAeC,CAAU,EAC7C,QAAWC,KAAWJ,EAAO,CACzB,IAAMK,EAAMD,EACRH,EAAYI,CAAG,EAAGH,EAAcG,CAAG,EAAIL,EAAMK,CAAG,EAC/CF,EAAWE,CAAG,EAAIL,EAAMK,CAAG,CACpC,CACA,MAAO,CAACH,EAAeC,CAAU,CACrC,CAWO,SAASb,EAAoCgB,EAAiC,CACjF,IAAMC,EAAcf,EAAQc,EAAO,QAAQ,EACrCE,EAAaf,EAAca,EAAO,QAAQ,EAUhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBATPR,GAA6BN,EAAWM,EAAQK,GAAQA,KAAOG,CAAU,EAS/C,gBAR5BR,GAA6B,CAClD,IAAMS,EAAiB,gBAAgBH,EAAO,eAAe,EAC7D,QAAWD,KAAOL,EACVA,EAAMK,CAAG,IAAM,SAAWI,EAAeJ,CAAG,EAAIL,EAAMK,CAAG,GAEjE,OAAOI,CACX,CAEqE,CACzE","names":["utils_exports","__export","cvUtils","getEntries","getKeys","getVariantMap","splitProps","__toCommonJS","obj","variants","cvKey","cvVal","props","shouldSplit","splittedProps","otherProps","propKey","key","config","variantKeys","variantMap","defaultedProps"]}
package/build/utils.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'ts-essentials';
2
- export { h as CVUtils, E as EntriesOf, n as VariantMap, r as cvUtils, m as getEntries, l as getKeys, p as getVariantMap, q as splitProps } from './cv-gIK0IznJ.cjs';
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-B7zWq-Wg.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 { h as CVUtils, E as EntriesOf, n as VariantMap, r as cvUtils, m as getEntries, l as getKeys, p as getVariantMap, q as splitProps } from './cv--G8-bDtP.js';
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-BdqZkdFD.js';
3
3
  import 'clsx';
4
4
  import './cn.js';
package/build/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a,b,c,d,e}from"./chunk-77XW3WZ4.js";export{e as cvUtils,b as getEntries,a as getKeys,c as getVariantMap,d as splitProps};
1
+ import{a,b,c,d,e}from"./chunk-32VQFSFZ.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.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PropType } from 'vue';
2
- import { a as CVVariantsSchema, b as CVReturn } from './cv-gIK0IznJ.cjs';
2
+ import { h as CVVariantsSchema, d as CVReturn } from './cv-B7zWq-Wg.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 { a as CVVariantsSchema, b as CVReturn } from './cv--G8-bDtP.js';
2
+ import { h as CVVariantsSchema, d as CVReturn } from './cv-BdqZkdFD.js';
3
3
  import 'clsx';
4
4
  import 'ts-essentials';
5
5
  import './cn.js';
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.6.0-rc.1",
8
+ "version": "0.6.0-rc.3",
9
9
  "type": "module",
10
10
  "files": [
11
11
  "build"
@@ -1,2 +0,0 @@
1
- function a(t){return Object.keys(t)}function V(t){return Object.entries(t)}function p(t){return Object.fromEntries(V(t).map(([n,e])=>[n,a(e)]))}function P(t,n){let e={},o={};if(!t)return[e,o];for(let s in t){let r=s;n(r)?e[r]=t[r]:o[r]=t[r]}return[e,o]}function c(t){let n=a(t.variants),e=p(t.variants);return{variantKeys:n,variantMap:e,splitVariantProps:r=>P(r,i=>i in e),getVariantProps:r=>({...t.defaultVariants,...r})}}export{a,V as b,p as c,P as d,c as e};
2
- //# sourceMappingURL=chunk-77XW3WZ4.js.map
@@ -1,2 +0,0 @@
1
- import{c as r}from"./chunk-XWAQU5O6.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-UUT6STP6.js.map
@@ -1 +0,0 @@
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 CV,\r\n type CVCompoundVariantsSchema,\r\n type CVCompoundVariantsSchemaFunction,\r\n type CVConfig,\r\n type CVReturn,\r\n type CVVariant,\r\n type CVVariantSchema,\r\n type CVVariantsSchema,\r\n} from \"./cv\";\r\n\r\ntype MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<\r\n Record<keyof V1 | keyof V2, ClassValue>\r\n>;\r\ntype MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<\r\n V1 & V2,\r\n {\r\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\r\n }\r\n>;\r\n\r\ninterface CVExtendOptions {\r\n cn: CN;\r\n cv: CV;\r\n}\r\nexport function _extend({ cn, cv }: CVExtendOptions) {\r\n const extendVariants = <V extends CVVariantsSchema, NewV extends CVVariantsSchema>(\r\n variants: V,\r\n newVariants?: NewV,\r\n ) => {\r\n const extendedVariants: CVVariantsSchema = structuredClone(variants);\r\n for (const key in newVariants) {\r\n extendedVariants[key] ??= {};\r\n for (const variant in newVariants[key]) {\r\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\r\n }\r\n }\r\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\r\n };\r\n\r\n return <V extends CVVariantsSchema, NewV extends CVVariantsSchema | (V & {})>(\r\n component: CVReturn<V>,\r\n newConfig: {\r\n base?: ClassValue;\r\n variants?: NewV;\r\n compoundVariants?:\r\n | CVCompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\r\n | CVCompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\r\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\r\n },\r\n ) => {\r\n const { config } = component;\r\n\r\n return cv({\r\n base: cn(config.base, newConfig.base),\r\n variants: extendVariants(config.variants, newConfig.variants),\r\n compoundVariants: (utils) =>\r\n resolveCompoundVariants(config.compoundVariants, component).concat(\r\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\r\n ),\r\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\r\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\r\n };\r\n}\r\n"],"mappings":"wCA6BO,SAASA,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,IAAMC,EAAiB,CACnBC,EACAC,IACC,CACD,IAAMC,EAAqC,gBAAgBF,CAAQ,EACnE,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","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}