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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/build/chunk-77XW3WZ4.js +2 -0
  2. package/build/chunk-77XW3WZ4.js.map +1 -0
  3. package/build/chunk-AQKDS5WX.js +2 -0
  4. package/build/chunk-AQKDS5WX.js.map +1 -0
  5. package/build/chunk-FIET564E.js +2 -0
  6. package/build/chunk-FIET564E.js.map +1 -0
  7. package/build/chunk-IMTFPGTY.js +2 -0
  8. package/build/chunk-IMTFPGTY.js.map +1 -0
  9. package/build/chunk-UUT6STP6.js +2 -0
  10. package/build/chunk-UUT6STP6.js.map +1 -0
  11. package/build/chunk-XWAQU5O6.js +2 -0
  12. package/build/chunk-XWAQU5O6.js.map +1 -0
  13. package/build/cn.cjs +2 -0
  14. package/build/cn.cjs.map +1 -0
  15. package/build/cn.d.cts +11 -0
  16. package/build/cn.d.ts +11 -0
  17. package/build/cn.js +2 -0
  18. package/build/cn.js.map +1 -0
  19. package/build/cv--G8-bDtP.d.ts +78 -0
  20. package/build/cv-gIK0IznJ.d.cts +78 -0
  21. package/build/cv.cjs +2 -0
  22. package/build/cv.cjs.map +1 -0
  23. package/build/cv.d.cts +4 -0
  24. package/build/cv.d.ts +4 -0
  25. package/build/cv.js +2 -0
  26. package/build/cv.js.map +1 -0
  27. package/build/define.cjs +2 -0
  28. package/build/define.cjs.map +1 -0
  29. package/build/define.d.cts +19 -0
  30. package/build/define.d.ts +19 -0
  31. package/build/define.js +2 -0
  32. package/build/define.js.map +1 -0
  33. package/build/extend.cjs +2 -0
  34. package/build/extend.cjs.map +1 -0
  35. package/build/extend.d.cts +21 -0
  36. package/build/extend.d.ts +21 -0
  37. package/build/extend.js +2 -0
  38. package/build/extend.js.map +1 -0
  39. package/build/index.cjs +1 -1
  40. package/build/index.cjs.map +1 -1
  41. package/build/index.d.cts +17 -3
  42. package/build/index.d.ts +17 -3
  43. package/build/index.js +1 -1
  44. package/build/index.js.map +1 -1
  45. package/build/tokens.cjs +2 -0
  46. package/build/tokens.cjs.map +1 -0
  47. package/build/tokens.d.cts +4 -0
  48. package/build/tokens.d.ts +4 -0
  49. package/build/tokens.js +2 -0
  50. package/build/tokens.js.map +1 -0
  51. package/build/utils.cjs +1 -1
  52. package/build/utils.cjs.map +1 -1
  53. package/build/utils.d.cts +2 -1
  54. package/build/utils.d.ts +2 -1
  55. package/build/utils.js +1 -1
  56. package/build/vue.cjs +1 -1
  57. package/build/vue.cjs.map +1 -1
  58. package/build/vue.d.cts +7 -18
  59. package/build/vue.d.ts +7 -18
  60. package/build/vue.js +1 -1
  61. package/build/vue.js.map +1 -1
  62. package/package.json +1 -1
  63. package/build/chunk-4HS2U3AJ.js +0 -2
  64. package/build/chunk-4HS2U3AJ.js.map +0 -1
  65. package/build/chunk-IW3RSJHX.js +0 -2
  66. package/build/chunk-IW3RSJHX.js.map +0 -1
  67. package/build/index-w3SZ98rX.d.cts +0 -87
  68. package/build/index-w3SZ98rX.d.ts +0 -87
@@ -0,0 +1,2 @@
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
@@ -0,0 +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"]}
@@ -0,0 +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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/define.ts"],"sourcesContent":["import { _cn, type CNOptions } from \"./cn\";\r\nimport { _cv } from \"./cv\";\r\nimport { _extend } from \"./extend\";\r\n\r\nexport interface DefineCVOptions extends CNOptions {}\r\n\r\nexport function defineCV({ merge }: DefineCVOptions = {}) {\r\n const cn = _cn({ merge });\r\n\r\n const cv = _cv({ cn });\r\n\r\n const extend = _extend({ cn, cv });\r\n\r\n return { cn, cv, extend } as const;\r\n}\r\n"],"mappings":"wHAMO,SAASA,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,CAAC,EAElBG,EAAKC,EAAI,CAAE,GAAAH,CAAG,CAAC,EAEfI,EAASC,EAAQ,CAAE,GAAAL,EAAI,GAAAE,CAAG,CAAC,EAEjC,MAAO,CAAE,GAAAF,EAAI,GAAAE,EAAI,OAAAE,CAAO,CAC5B","names":["defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
@@ -0,0 +1,2 @@
1
+ import r from"clsx";function n({merge:e=t=>t}){return(...t)=>e(r(...t))}export{n as a};
2
+ //# sourceMappingURL=chunk-FIET564E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cn.ts"],"sourcesContent":["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"],"mappings":"AAAA,OAAOA,MAA+B,OAU/B,SAASC,EAAI,CAAE,MAAAC,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,EAAMF,EAAK,GAAGI,CAAM,CAAC,CAC/C","names":["clsx","_cn","merge","className","inputs"]}
@@ -0,0 +1,2 @@
1
+ var t={__token:"OnlyWhenDefined"},i={__token:"OnlyWhenUndefined"};function f(e){return e?typeof e=="object"&&"__token"in e:!1}function o(e,n){return e.__token===n.__token}function r(e,n){return o(e,t)?n!==void 0:o(e,i)?n===void 0:!1}export{t as a,i as b,f as c,r as d};
2
+ //# sourceMappingURL=chunk-IMTFPGTY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tokens.ts"],"sourcesContent":["import type { Opaque } from \"ts-essentials\";\r\nimport type { CVPropsValue } from \"./cv\";\r\n\r\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\r\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\r\n\r\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\r\n\r\n/** Apply compound variant only if prop **is** specified */\r\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\r\n/** Apply compound variant only if prop **is not** specified */\r\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\r\n\r\nexport function isCVToken(token: unknown): token is CVToken {\r\n return token ? typeof token === \"object\" && \"__token\" in token : false;\r\n}\r\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\r\n return token.__token === reference.__token;\r\n}\r\n\r\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\r\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\r\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\r\n\r\n return false;\r\n}\r\n"],"mappings":"AASO,IAAMA,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","names":["onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector"]}
@@ -0,0 +1,2 @@
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
@@ -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\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"]}
@@ -0,0 +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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cv.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"],"mappings":"uFAwDO,SAASA,EAAIC,EAAwB,CACxC,OAAoCC,GAAiC,CACjE,GAAM,CAACC,EAAgBC,CAAK,EAAIC,EAAcH,CAAM,EAE9C,CAAE,KAAAI,EAAM,SAAAC,EAAU,iBAAAC,EAAkB,gBAAAC,CAAgB,EAAIN,EAExDO,EAAyBC,GAA6B,CACxD,IAAMC,EAAiBR,EAAM,gBAAgBO,CAAK,EAE5CE,EAAa,IAAI,MACvB,QAAWC,KAAOP,EAAU,CACxB,IAAMQ,EAAUH,E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B,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","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/cn.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var p=Object.create;var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})},a=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of l(e))!u.call(t,s)&&s!==r&&n(t,s,{get:()=>e[s],enumerable:!(i=c(e,s))||i.enumerable});return t};var f=(t,e,r)=>(r=t!=null?p(C(t)):{},a(e||!t||!t.__esModule?n(r,"default",{value:t,enumerable:!0}):r,t)),g=t=>a(n({},"__esModule",{value:!0}),t);var x={};N(x,{_cn:()=>m});module.exports=g(x);var o=f(require("clsx"),1);function m({merge:t=e=>e}){return(...e)=>t((0,o.default)(...e))}0&&(module.exports={_cn});
2
+ //# sourceMappingURL=cn.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cn.ts"],"sourcesContent":["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"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsC,qBAU/B,SAASF,EAAI,CAAE,MAAAG,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,KAAM,EAAAG,SAAK,GAAGD,CAAM,CAAC,CAC/C","names":["cn_exports","__export","_cn","__toCommonJS","import_clsx","merge","className","inputs","clsx"]}
package/build/cn.d.cts ADDED
@@ -0,0 +1,11 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ interface CNOptions {
4
+ merge?: (className: string) => string;
5
+ }
6
+ interface CN {
7
+ (...inputs: ClassValue[]): string;
8
+ }
9
+ declare function _cn({ merge }: CNOptions): CN;
10
+
11
+ export { type CN, type CNOptions, _cn };
package/build/cn.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ interface CNOptions {
4
+ merge?: (className: string) => string;
5
+ }
6
+ interface CN {
7
+ (...inputs: ClassValue[]): string;
8
+ }
9
+ declare function _cn({ merge }: CNOptions): CN;
10
+
11
+ export { type CN, type CNOptions, _cn };
package/build/cn.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a}from"./chunk-FIET564E.js";export{a as _cn};
2
+ //# sourceMappingURL=cn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,78 @@
1
+ import { ClassValue } from 'clsx';
2
+ import { Opaque, Prettify, ArrayOrSingle } from 'ts-essentials';
3
+ import { CN } from './cn.js';
4
+
5
+ type OnlyWhenDefined = Opaque<{
6
+ __token: string;
7
+ }, "OnlyWhenDefined">;
8
+ type OnlyWhenUndefined = Opaque<{
9
+ __token: string;
10
+ }, "OnlyWhenUndefined">;
11
+ type CVToken = OnlyWhenDefined | OnlyWhenUndefined;
12
+ /** Apply compound variant only if prop **is** specified */
13
+ declare const onlyWhenDefined: OnlyWhenDefined;
14
+ /** Apply compound variant only if prop **is not** specified */
15
+ declare const onlyWhenUndefined: OnlyWhenUndefined;
16
+ declare function isCVToken(token: unknown): token is CVToken;
17
+ declare function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue): boolean;
18
+
19
+ declare function getKeys<O extends Record<string, unknown>>(obj: O): (keyof O & CVVariantKey)[];
20
+ type EntriesOf<O extends Record<string, unknown>> = {
21
+ [K in keyof O]: [K, O[K]];
22
+ };
23
+ declare function getEntries<O extends Record<string, unknown>>(obj: O): EntriesOf<O>[keyof EntriesOf<O>][];
24
+ type VariantMap<V extends CVVariantsSchema> = {
25
+ [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];
26
+ };
27
+ declare function getVariantMap<V extends CVVariantsSchema>(variants: V): VariantMap<V>;
28
+ declare function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean): readonly [Partial<Record<keyof TProps, unknown>>, Partial<Record<keyof TProps, unknown>>];
29
+ interface CVUtils<V extends CVVariantsSchema> {
30
+ variantKeys: (keyof V & string)[];
31
+ variantMap: Prettify<VariantMap<V>>;
32
+ splitVariantProps: <TProps extends CVReturnProps<V>>(props?: TProps) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];
33
+ getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;
34
+ }
35
+ declare function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V>;
36
+
37
+ type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;
38
+ type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
39
+ type CVVariantKey = string | number;
40
+ type CVVariantSchema = Record<CVVariantKey, ClassValue>;
41
+ type CVVariantsSchema = Record<string, CVVariantSchema>;
42
+ type CVVariant<V extends CVVariantsSchema> = {
43
+ [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;
44
+ };
45
+ type CVProps<V extends CVVariantsSchema> = CVVariant<V>;
46
+ type CVCompoundVariant<V extends CVVariantsSchema> = {
47
+ [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;
48
+ } & {
49
+ class: ClassValue;
50
+ };
51
+ type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];
52
+ type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (utils: CVUtils<V>) => CVCompoundVariantsSchema<V>;
53
+ interface CVConfig<V extends CVVariantsSchema> {
54
+ base: ClassValue;
55
+ variants: V;
56
+ compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;
57
+ defaultVariants: CVVariant<V>;
58
+ }
59
+ interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {
60
+ compoundVariants: CVCompoundVariantsSchema<V>;
61
+ }
62
+ type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;
63
+ interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {
64
+ (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;
65
+ config: ResolvedCVConfig<V>;
66
+ }
67
+ interface CV {
68
+ <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;
69
+ }
70
+ interface CVOptions {
71
+ cn: CN;
72
+ }
73
+ declare function _cv(options: CVOptions): CV;
74
+ type CVPropsValue = CVVariantKey | boolean | undefined;
75
+ declare function resolveConfig<V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
76
+ declare function resolveCompoundVariants<V extends CVVariantsSchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CVCompoundVariantsSchema<V>;
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 };
@@ -0,0 +1,78 @@
1
+ import { ClassValue } from 'clsx';
2
+ import { Opaque, Prettify, ArrayOrSingle } from 'ts-essentials';
3
+ import { CN } from './cn.cjs';
4
+
5
+ type OnlyWhenDefined = Opaque<{
6
+ __token: string;
7
+ }, "OnlyWhenDefined">;
8
+ type OnlyWhenUndefined = Opaque<{
9
+ __token: string;
10
+ }, "OnlyWhenUndefined">;
11
+ type CVToken = OnlyWhenDefined | OnlyWhenUndefined;
12
+ /** Apply compound variant only if prop **is** specified */
13
+ declare const onlyWhenDefined: OnlyWhenDefined;
14
+ /** Apply compound variant only if prop **is not** specified */
15
+ declare const onlyWhenUndefined: OnlyWhenUndefined;
16
+ declare function isCVToken(token: unknown): token is CVToken;
17
+ declare function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue): boolean;
18
+
19
+ declare function getKeys<O extends Record<string, unknown>>(obj: O): (keyof O & CVVariantKey)[];
20
+ type EntriesOf<O extends Record<string, unknown>> = {
21
+ [K in keyof O]: [K, O[K]];
22
+ };
23
+ declare function getEntries<O extends Record<string, unknown>>(obj: O): EntriesOf<O>[keyof EntriesOf<O>][];
24
+ type VariantMap<V extends CVVariantsSchema> = {
25
+ [K in keyof V]: BooleanStringToBoolean<keyof V[K] & CVVariantKey>[];
26
+ };
27
+ declare function getVariantMap<V extends CVVariantsSchema>(variants: V): VariantMap<V>;
28
+ declare function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean): readonly [Partial<Record<keyof TProps, unknown>>, Partial<Record<keyof TProps, unknown>>];
29
+ interface CVUtils<V extends CVVariantsSchema> {
30
+ variantKeys: (keyof V & string)[];
31
+ variantMap: Prettify<VariantMap<V>>;
32
+ splitVariantProps: <TProps extends CVReturnProps<V>>(props?: TProps) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];
33
+ getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;
34
+ }
35
+ declare function cvUtils<V extends CVVariantsSchema>(config: CVConfig<V>): CVUtils<V>;
36
+
37
+ type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;
38
+ type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
39
+ type CVVariantKey = string | number;
40
+ type CVVariantSchema = Record<CVVariantKey, ClassValue>;
41
+ type CVVariantsSchema = Record<string, CVVariantSchema>;
42
+ type CVVariant<V extends CVVariantsSchema> = {
43
+ [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & CVVariantKey>;
44
+ };
45
+ type CVProps<V extends CVVariantsSchema> = CVVariant<V>;
46
+ type CVCompoundVariant<V extends CVVariantsSchema> = {
47
+ [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & CVVariantKey>> | CVToken;
48
+ } & {
49
+ class: ClassValue;
50
+ };
51
+ type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];
52
+ type CVCompoundVariantsSchemaFunction<V extends CVVariantsSchema> = (utils: CVUtils<V>) => CVCompoundVariantsSchema<V>;
53
+ interface CVConfig<V extends CVVariantsSchema> {
54
+ base: ClassValue;
55
+ variants: V;
56
+ compoundVariants: CVCompoundVariantsSchema<V> | CVCompoundVariantsSchemaFunction<V>;
57
+ defaultVariants: CVVariant<V>;
58
+ }
59
+ interface ResolvedCVConfig<V extends CVVariantsSchema> extends CVConfig<V> {
60
+ compoundVariants: CVCompoundVariantsSchema<V>;
61
+ }
62
+ type CVReturnProps<V extends CVVariantsSchema> = CVProps<V>;
63
+ interface CVReturn<V extends CVVariantsSchema> extends CVUtils<V> {
64
+ (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;
65
+ config: ResolvedCVConfig<V>;
66
+ }
67
+ interface CV {
68
+ <V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): CVReturn<V>;
69
+ }
70
+ interface CVOptions {
71
+ cn: CN;
72
+ }
73
+ declare function _cv(options: CVOptions): CV;
74
+ type CVPropsValue = CVVariantKey | boolean | undefined;
75
+ declare function resolveConfig<V extends CVVariantsSchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
76
+ declare function resolveCompoundVariants<V extends CVVariantsSchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CVCompoundVariantsSchema<V>;
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 };
package/build/cv.cjs ADDED
@@ -0,0 +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});
2
+ //# sourceMappingURL=cv.cjs.map
@@ -0,0 +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,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA0CC,EAAa,CACnE,OAAO,OAAO,YAAYF,EAAWE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CommonJS","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"]}
package/build/cv.d.cts ADDED
@@ -0,0 +1,4 @@
1
+ import 'clsx';
2
+ import 'ts-essentials';
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';
package/build/cv.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import 'clsx';
2
+ import 'ts-essentials';
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';
package/build/cv.js ADDED
@@ -0,0 +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};
2
+ //# sourceMappingURL=cv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +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});
2
+ //# sourceMappingURL=define.cjs.map
@@ -0,0 +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,mBAAo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AAE,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"]}
@@ -0,0 +1,19 @@
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';
4
+ import { CNOptions, CN } from './cn.cjs';
5
+
6
+ interface DefineCVOptions extends CNOptions {
7
+ }
8
+ declare function defineCV({ merge }?: DefineCVOptions): {
9
+ readonly cn: CN;
10
+ 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>>; }>>;
17
+ };
18
+
19
+ export { type DefineCVOptions, defineCV };
@@ -0,0 +1,19 @@
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';
4
+ import { CNOptions, CN } from './cn.js';
5
+
6
+ interface DefineCVOptions extends CNOptions {
7
+ }
8
+ declare function defineCV({ merge }?: DefineCVOptions): {
9
+ readonly cn: CN;
10
+ 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>>; }>>;
17
+ };
18
+
19
+ export { type DefineCVOptions, defineCV };
@@ -0,0 +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};
2
+ //# sourceMappingURL=define.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +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});
2
+ //# sourceMappingURL=extend.cjs.map
@@ -0,0 +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"]}
@@ -0,0 +1,21 @@
1
+ import { ClassValue } from 'clsx';
2
+ import { Merge, Prettify } from 'ts-essentials';
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';
5
+
6
+ type MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
7
+ type MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<V1 & V2, {
8
+ [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;
9
+ }>;
10
+ interface CVExtendOptions {
11
+ cn: CN;
12
+ cv: CV;
13
+ }
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>>; }>>;
20
+
21
+ export { _extend };
@@ -0,0 +1,21 @@
1
+ import { ClassValue } from 'clsx';
2
+ import { Merge, Prettify } from 'ts-essentials';
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';
5
+
6
+ type MergeVariant<V1 extends CVVariantSchema, V2 extends CVVariantSchema> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
7
+ type MergeVariantsSchemas<V1 extends CVVariantsSchema, V2 extends CVVariantsSchema> = Merge<V1 & V2, {
8
+ [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;
9
+ }>;
10
+ interface CVExtendOptions {
11
+ cn: CN;
12
+ cv: CV;
13
+ }
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>>; }>>;
20
+
21
+ export { _extend };
@@ -0,0 +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};
2
+ //# sourceMappingURL=extend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/build/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var C=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var s in n)C(e,s,{get:n[s],enumerable:!0})},j=(e,n,s,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of U(n))!q.call(e,t)&&t!==s&&C(e,t,{get:()=>n[t],enumerable:!(l=E(n,t))||l.enumerable});return e};var D=e=>j(C({},"__esModule",{value:!0}),e);var A={};N(A,{cn:()=>M,compose:()=>w,cv:()=>B,defineCV:()=>h,onlyWhenDefined:()=>v,onlyWhenUndefined:()=>K});module.exports=D(A);var g=require("clsx");function m(e){return Object.keys(e)}function x(e){return Object.entries(e)}function k(e){return Object.fromEntries(x(e).map(([n,s])=>[n,m(s)]))}function h(e={}){let n=e.merge??g.clsx;return{cn:n,cv:t=>{let{base:i,variants:r,defaultVariants:V,requiredVariants:P}=t,y={variants:r??{},variantKeys:r?m(r):[],variantMap:r?k(r):{},defaultVariants:V??{},requiredVariants:P??{}},T=r?typeof t.compoundVariants=="function"?t.compoundVariants(y):t.compoundVariants:void 0;return Object.assign(p=>{let b=r?y.variantKeys.map(o=>{let c=p?.[o],f=V?.[o],d=c?.toString()||f?.toString();return d?r[o][d]:void 0}):void 0,W=T?.reduce((o,{class:c,className:f,...d})=>(x(d).every(([O,a])=>{let _=V?.[O],u=p?.[O];if(typeof a=="object"&&"__token"in a){if(a.__token===v.__token)return u!==void 0;if(a.__token===K.__token)return u===void 0}let R=u??_;return Array.isArray(a)?a.some(S=>R===S):R===a})&&o.push(c,f),o),new Array);return n(i,b,W,p?.class,p?.className)},y)},compose:(...t)=>i=>{let r={...i,class:void 0,className:void 0};return n(t.map(V=>V(r)),i?.class,i?.className)}}}var{cn:M,cv:B,compose:w}=h(),v={__token:"OnlyWhenDefined"},K={__token:"OnlyWhenUndefined"};0&&(module.exports={cn,compose,cv,defineCV,onlyWhenDefined,onlyWhenUndefined});
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});
2
2
  //# sourceMappingURL=index.cjs.map