@yaredfall/class-variants 0.6.0-rc.3 → 0.6.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 (64) hide show
  1. package/LICENSE +1 -1
  2. package/build/chunk-36Z7UYAL.js +2 -0
  3. package/build/chunk-36Z7UYAL.js.map +1 -0
  4. package/build/chunk-BO7CCVZY.js +2 -0
  5. package/build/chunk-BO7CCVZY.js.map +1 -0
  6. package/build/chunk-LLMR7HCR.js +2 -0
  7. package/build/chunk-LLMR7HCR.js.map +1 -0
  8. package/build/{chunk-IMTFPGTY.js → chunk-N3ZCNVFV.js} +1 -1
  9. package/build/chunk-N3ZCNVFV.js.map +1 -0
  10. package/build/{chunk-FIET564E.js → chunk-O5WYIZI3.js} +1 -1
  11. package/build/chunk-O5WYIZI3.js.map +1 -0
  12. package/build/{chunk-32VQFSFZ.js → chunk-SJ6AQKOA.js} +1 -1
  13. package/build/chunk-SJ6AQKOA.js.map +1 -0
  14. package/build/cn.cjs.map +1 -1
  15. package/build/cn.js +1 -1
  16. package/build/cv-BA68QNCx.d.ts +79 -0
  17. package/build/cv-C4LDfd1S.d.cts +79 -0
  18. package/build/cv.cjs +1 -1
  19. package/build/cv.cjs.map +1 -1
  20. package/build/cv.d.cts +1 -1
  21. package/build/cv.d.ts +1 -1
  22. package/build/cv.js +1 -1
  23. package/build/define.cjs +1 -1
  24. package/build/define.cjs.map +1 -1
  25. package/build/define.d.cts +1 -1
  26. package/build/define.d.ts +1 -1
  27. package/build/define.js +1 -1
  28. package/build/extend.cjs +1 -1
  29. package/build/extend.cjs.map +1 -1
  30. package/build/extend.d.cts +5 -5
  31. package/build/extend.d.ts +5 -5
  32. package/build/extend.js +1 -1
  33. package/build/index.cjs +1 -1
  34. package/build/index.cjs.map +1 -1
  35. package/build/index.d.cts +2 -2
  36. package/build/index.d.ts +2 -2
  37. package/build/index.js +1 -1
  38. package/build/index.js.map +1 -1
  39. package/build/tokens.cjs.map +1 -1
  40. package/build/tokens.d.cts +1 -1
  41. package/build/tokens.d.ts +1 -1
  42. package/build/tokens.js +1 -1
  43. package/build/utils.cjs +1 -1
  44. package/build/utils.cjs.map +1 -1
  45. package/build/utils.d.cts +1 -1
  46. package/build/utils.d.ts +1 -1
  47. package/build/utils.js +1 -1
  48. package/build/vue.cjs +1 -1
  49. package/build/vue.cjs.map +1 -1
  50. package/build/vue.d.cts +2 -2
  51. package/build/vue.d.ts +2 -2
  52. package/build/vue.js.map +1 -1
  53. package/package.json +13 -13
  54. package/build/chunk-32VQFSFZ.js.map +0 -1
  55. package/build/chunk-FIET564E.js.map +0 -1
  56. package/build/chunk-FNDRMHIF.js +0 -2
  57. package/build/chunk-FNDRMHIF.js.map +0 -1
  58. package/build/chunk-G3WOK6WL.js +0 -2
  59. package/build/chunk-G3WOK6WL.js.map +0 -1
  60. package/build/chunk-IMTFPGTY.js.map +0 -1
  61. package/build/chunk-NDMNWVIC.js +0 -2
  62. package/build/chunk-NDMNWVIC.js.map +0 -1
  63. package/build/cv-B7zWq-Wg.d.cts +0 -78
  64. package/build/cv-BdqZkdFD.d.ts +0 -78
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
+ import{c as r}from"./chunk-LLMR7HCR.js";function m({cn:s,cv:i}){let o=(V,a)=>{let e=structuredClone(V);for(let t in a){e[t]??={};for(let n in a[t])e[t][n]=s(V[t]?.[n],a[t][n])}return e};return(V,a)=>{let{config:e}=V;return i({base:s(e.base,a.base),variants:o(e.variants,a.variants),compoundVariants:t=>r(e.compoundVariants,V).concat(r(a.compoundVariants??[],t)),defaultVariants:{...e.defaultVariants,...a.defaultVariants}})}}export{m as a};
2
+ //# sourceMappingURL=chunk-36Z7UYAL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/extend.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n"],"mappings":"wCAyCO,SAASA,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,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{a as e}from"./chunk-O5WYIZI3.js";import{a as i}from"./chunk-36Z7UYAL.js";import{a as o}from"./chunk-LLMR7HCR.js";function m({merge:r}={}){let n=e({merge:r}),t=o({cn:n}),c=i({cn:n,cv:t});return{cn:n,cv:t,extend:c}}export{m as a};
2
+ //# sourceMappingURL=chunk-BO7CCVZY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/define.ts"],"sourcesContent":["import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n"],"mappings":"wHAMO,SAASA,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,CAAC,EAElBG,EAAKC,EAAI,CAAE,GAAAH,CAAG,CAAC,EAEfI,EAASC,EAAQ,CAAE,GAAAL,EAAI,GAAAE,CAAG,CAAC,EAEjC,MAAO,CAAE,GAAAF,EAAI,GAAAE,EAAI,OAAAE,CAAO,CAC5B","names":["defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
@@ -0,0 +1,2 @@
1
+ import{c as l,d}from"./chunk-N3ZCNVFV.js";import{e as f}from"./chunk-SJ6AQKOA.js";function E(t){return e=>{let[a,n]=x(e),{base:r,variants:i,compoundVariants:p,defaultVariants:c}=a,C=s=>{let V=n.getVariantProps(s),o=new Array;for(let m in i){let u=V[m]?.toString();u&&o.push(i?.[m]?.[u])}return o},S=s=>p?.reduce((V,o)=>(h(s,o,c)&&V.push(o.class),V),new Array);return Object.assign(Object.assign((s,...V)=>{let o=C(s),m=S(s);return t.cn(r,o,m,...V)},n),{config:a})}}function h(t,e,a){return Object.keys(e).every(n=>{if(n==="class")return!0;let r=e[n],i=a?.[n],p=t?.[n];if(l(r))return d(r,p);let c=p??i;return Array.isArray(r)?r.some(C=>y(c,C)):y(c,r)})}function y(t,e){return t?.toString()===e?.toString()}function x(t){let e={variants:{},compoundVariants:[],defaultVariants:{},...t},a=f(e);return[Object.assign(e,{compoundVariants:g(e.compoundVariants,a)}),a]}function g(t,e){return typeof t=="function"?t(e):t}export{E as a,x as b,g as c};
2
+ //# sourceMappingURL=chunk-LLMR7HCR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cv.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n"],"mappings":"kFA0DO,SAASA,EAAIC,EAAwB,CACxC,OAAgDC,GAAiC,CAC7E,GAAM,CAACC,EAAgBC,CAAK,EAAIC,EAAcH,CAAM,EAE9C,CAAE,KAAAI,EAAM,SAAAC,EAAU,iBAAAC,EAAkB,gBAAAC,CAAgB,EAAIN,EAExDO,EA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EACX,iBAAkB,CAAC,EACnB,gBAAiB,CAAC,EAClB,GAAGhC,CACP,EAEME,EAAQ+B,EAAQD,CAAe,EAErC,MAAO,CACH,OAAO,OAAOA,EAAiB,CAC3B,iBAAkBE,EAAwBF,EAAgB,iBAAkB9B,CAAK,CACrF,CAAC,EACDA,CACJ,CACJ,CAEO,SAASgC,EACZ5B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E","names":["_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}
@@ -1,2 +1,2 @@
1
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
2
+ //# sourceMappingURL=chunk-N3ZCNVFV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tokens.ts"],"sourcesContent":["import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n"],"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"]}
@@ -1,2 +1,2 @@
1
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
2
+ //# sourceMappingURL=chunk-O5WYIZI3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cn.ts"],"sourcesContent":["import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n"],"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"]}
@@ -1,2 +1,2 @@
1
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
2
+ //# sourceMappingURL=chunk-SJ6AQKOA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n"],"mappings":"AAGO,SAASA,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAAwCC,EAAa,CACjE,OAAO,OAAO,YAAYF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASC,EAAmBC,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO,MAAO,CAACE,EAAeC,CAAU,EAC7C,QAAWC,KAAWJ,EAAO,CACzB,IAAMK,EAAMD,EACRH,EAAYI,CAAG,EAAGH,EAAcG,CAAG,EAAIL,EAAMK,CAAG,EAC/CF,EAAWE,CAAG,EAAIL,EAAMK,CAAG,CACpC,CACA,MAAO,CAACH,EAAeC,CAAU,CACrC,CAWO,SAASG,EAAkCC,EAAiC,CAC/E,IAAMC,EAAchB,EAAQe,EAAO,QAAQ,EACrCE,EAAad,EAAcY,EAAO,QAAQ,EAUhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBATPT,GAA6BD,EAAWC,EAAQK,GAAQA,KAAOI,CAAU,EAS/C,gBAR5BT,GAA6B,CAClD,IAAMU,EAAiB,gBAAgBH,EAAO,eAAe,EAC7D,QAAWF,KAAOL,EACVA,EAAMK,CAAG,IAAM,SAAWK,EAAeL,CAAG,EAAIL,EAAMK,CAAG,GAEjE,OAAOK,CACX,CAEqE,CACzE","names":["getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps"]}
package/build/cn.cjs.map CHANGED
@@ -1 +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"]}
1
+ {"version":3,"sources":["../src/cn.ts"],"sourcesContent":["import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n"],"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.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-FIET564E.js";export{a as _cn};
1
+ import{a}from"./chunk-O5WYIZI3.js";export{a as _cn};
2
2
  //# sourceMappingURL=cn.js.map
@@ -0,0 +1,79 @@
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 & VariantKey)[];
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 VariantsSchema> = {
25
+ [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];
26
+ };
27
+ declare function getVariantMap<V extends VariantsSchema>(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 VariantsSchema> {
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 VariantsSchema>(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 VariantKey = string | number;
40
+ type Variant = Record<VariantKey, ClassValue>;
41
+ type VariantsSchema = Record<string, Variant>;
42
+ type EmptySchema = Record<never, never>;
43
+ type CVVariant<V extends VariantsSchema = EmptySchema> = {
44
+ [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;
45
+ };
46
+ type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;
47
+ type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {
48
+ [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;
49
+ } & {
50
+ class: ClassValue;
51
+ };
52
+ type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];
53
+ type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (utils: CVUtils<V>) => CompoundVariantsSchema<V>;
54
+ interface CVConfig<V extends VariantsSchema = EmptySchema> {
55
+ base: ClassValue;
56
+ variants: V;
57
+ compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;
58
+ defaultVariants: CVVariant<V>;
59
+ }
60
+ interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {
61
+ compoundVariants: CompoundVariantsSchema<V>;
62
+ }
63
+ type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;
64
+ interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {
65
+ (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;
66
+ config: ResolvedCVConfig<V>;
67
+ }
68
+ interface CV {
69
+ <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;
70
+ }
71
+ interface CVOptions {
72
+ cn: CN;
73
+ }
74
+ declare function _cv(options: CVOptions): CV;
75
+ type CVPropsValue = VariantKey | boolean | undefined;
76
+ declare function resolveConfig<V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
77
+ declare function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CompoundVariantsSchema<V>;
78
+
79
+ export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantsSchema as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type VariantProps as h, type Variant as i, type CompoundVariantsSchemaFunction as j, isCVToken as k, getKeys as l, getEntries as m, type VariantMap as n, onlyWhenDefined as o, getVariantMap as p, splitProps as q, cvUtils as r, shouldApplySelectorByToken as s, type VariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
@@ -0,0 +1,79 @@
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 & VariantKey)[];
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 VariantsSchema> = {
25
+ [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];
26
+ };
27
+ declare function getVariantMap<V extends VariantsSchema>(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 VariantsSchema> {
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 VariantsSchema>(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 VariantKey = string | number;
40
+ type Variant = Record<VariantKey, ClassValue>;
41
+ type VariantsSchema = Record<string, Variant>;
42
+ type EmptySchema = Record<never, never>;
43
+ type CVVariant<V extends VariantsSchema = EmptySchema> = {
44
+ [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;
45
+ };
46
+ type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;
47
+ type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {
48
+ [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;
49
+ } & {
50
+ class: ClassValue;
51
+ };
52
+ type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];
53
+ type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (utils: CVUtils<V>) => CompoundVariantsSchema<V>;
54
+ interface CVConfig<V extends VariantsSchema = EmptySchema> {
55
+ base: ClassValue;
56
+ variants: V;
57
+ compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;
58
+ defaultVariants: CVVariant<V>;
59
+ }
60
+ interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {
61
+ compoundVariants: CompoundVariantsSchema<V>;
62
+ }
63
+ type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;
64
+ interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {
65
+ (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;
66
+ config: ResolvedCVConfig<V>;
67
+ }
68
+ interface CV {
69
+ <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;
70
+ }
71
+ interface CVOptions {
72
+ cn: CN;
73
+ }
74
+ declare function _cv(options: CVOptions): CV;
75
+ type CVPropsValue = VariantKey | boolean | undefined;
76
+ declare function resolveConfig<V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
77
+ declare function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CompoundVariantsSchema<V>;
78
+
79
+ export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantsSchema as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type VariantProps as h, type Variant as i, type CompoundVariantsSchemaFunction as j, isCVToken as k, getKeys as l, getEntries as m, type VariantMap as n, onlyWhenDefined as o, getVariantMap as p, splitProps as q, cvUtils as r, shouldApplySelectorByToken as s, type VariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
package/build/cv.cjs CHANGED
@@ -1,2 +1,2 @@
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});
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})},E=(e,n,t,o)=>{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:!(o=O(n,r))||o.enumerable});return e};var K=e=>E(l({},"__esModule",{value:!0}),e);var w={};v(w,{_cv:()=>A,resolveCompoundVariants:()=>g,resolveConfig:()=>P});module.exports=K(w);var U={__token:"OnlyWhenDefined"},_={__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,U)?n!==void 0:d(e,_)?n===void 0:!1}function x(e){return Object.keys(e)}function b(e){return Object.entries(e)}function B(e){return Object.fromEntries(b(e).map(([n,t])=>[n,x(t)]))}function W(e,n){let t={},o={};if(!e)return[t,o];for(let r in e){let a=r;n(a)?t[a]=e[a]:o[a]=e[a]}return[t,o]}function h(e){let n=x(e.variants),t=B(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:a=>W(a,s=>s in t),getVariantProps:a=>{let s=structuredClone(e.defaultVariants);for(let i in a)a[i]!==void 0&&(s[i]=a[i]);return s}}}function A(e){return n=>{let[t,o]=P(n),{base:r,variants:a,compoundVariants:s,defaultVariants:i}=t,f=p=>{let c=o.getVariantProps(p),V=new Array;for(let u in a){let C=c[u]?.toString();C&&V.push(a?.[u]?.[C])}return V},k=p=>s?.reduce((c,V)=>(j(p,V,i)&&c.push(V.class),c),new Array);return Object.assign(Object.assign((p,...c)=>{let V=f(p),u=k(p);return e.cn(r,V,u,...c)},o),{config:t})}}function j(e,n,t){return Object.keys(n).every(o=>{if(o==="class")return!0;let r=n[o],a=t?.[o],s=e?.[o];if(y(r))return m(r,s);let i=s??a;return Array.isArray(r)?r.some(f=>S(i,f)):S(i,r)})}function S(e,n){return e?.toString()===n?.toString()}function P(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=h(n);return[Object.assign(n,{compoundVariants:g(n.compoundVariants,t)}),t]}function g(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>) => {\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,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,C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F,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"]}
1
+ {"version":3,"sources":["../src/cv.ts","../src/tokens.ts","../src/utils.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,4BAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAL,GCSO,IAAMM,EAAkB,CAAE,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,E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AAU,CAAC,EACX,iBAAkB,CAAC,EACnB,gBAAiB,CAAC,EAClB,GAAGhC,CACP,EAEME,EAAQ+B,EAAQD,CAAe,EAErC,MAAO,CACH,OAAO,OAAOA,EAAiB,CAC3B,iBAAkBE,EAAwBF,EAAgB,iBAAkB9B,CAAK,CACrF,CAAC,EACDA,CACJ,CACJ,CAEO,SAASgC,EACZ5B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E","names":["cv_exports","__export","_cv","resolveCompoundVariants","resolveConfig","__toCommonJS","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}
package/build/cv.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'clsx';
2
2
  import 'ts-essentials';
3
3
  import './cn.cjs';
4
- export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, 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';
4
+ export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-C4LDfd1S.cjs';
package/build/cv.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import 'clsx';
2
2
  import 'ts-essentials';
3
3
  import './cn.js';
4
- export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, 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';
4
+ export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-BA68QNCx.js';
package/build/cv.js CHANGED
@@ -1,2 +1,2 @@
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};
1
+ import{a,b,c}from"./chunk-LLMR7HCR.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _cv,c as resolveCompoundVariants,b as resolveConfig};
2
2
  //# sourceMappingURL=cv.js.map
package/build/define.cjs CHANGED
@@ -1,2 +1,2 @@
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});
1
+ "use strict";var T=Object.create;var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var n in t)m(e,n,{get:t[n],enumerable:!0})},l=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of K(t))!_.call(e,a)&&a!==n&&m(e,a,{get:()=>t[a],enumerable:!(s=E(t,a))||s.enumerable});return e};var w=(e,t,n)=>(n=e!=null?T(M(e)):{},l(t||!e||!e.__esModule?m(n,"default",{value:e,enumerable:!0}):n,e)),U=e=>l(m({},"__esModule",{value:!0}),e);var G={};b(G,{defineCV:()=>z});module.exports=U(G);var y=w(require("clsx"),1);function x({merge:e=t=>t}){return(...t)=>e((0,y.default)(...t))}var B={__token:"OnlyWhenDefined"},W={__token:"OnlyWhenUndefined"};function S(e){return e?typeof e=="object"&&"__token"in e:!1}function h(e,t){return e.__token===t.__token}function g(e,t){return h(e,B)?t!==void 0:h(e,W)?t===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(([t,n])=>[t,P(n)]))}function D(e,t){let n={},s={};if(!e)return[n,s];for(let a in e){let r=a;t(r)?n[r]=e[r]:s[r]=e[r]}return[n,s]}function k(e){let t=P(e.variants),n=j(e.variants);return{variantKeys:t,variantMap:n,splitVariantProps:r=>D(r,o=>o in n),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 t=>{let[n,s]=q(t),{base:a,variants:r,compoundVariants:o,defaultVariants:V}=n,C=p=>{let c=s.getVariantProps(p),i=new Array;for(let u in r){let d=c[u]?.toString();d&&i.push(r?.[u]?.[d])}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=C(p),u=N(p);return e.cn(a,i,u,...c)},s),{config:n})}}function F(e,t,n){return Object.keys(t).every(s=>{if(s==="class")return!0;let a=t[s],r=n?.[s],o=e?.[s];if(S(a))return g(a,o);let V=o??r;return Array.isArray(a)?a.some(C=>O(V,C)):O(V,a)})}function O(e,t){return e?.toString()===t?.toString()}function q(e){let t={variants:{},compoundVariants:[],defaultVariants:{},...e},n=k(t);return[Object.assign(t,{compoundVariants:f(t.compoundVariants,n)}),n]}function f(e,t){return typeof e=="function"?e(t):e}function v({cn:e,cv:t}){let n=(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 t({base:e(r.base,a.base),variants:n(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 t=x({merge:e}),n=R({cn:t}),s=v({cn:t,cv:n});return{cn:t,cv:n,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>) => {\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,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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","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
+ {"version":3,"sources":["../src/define.ts","../src/cn.ts","../src/tokens.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts"],"sourcesContent":["import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n","import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, additionalClassName?: ClassValue): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n"],"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,CCtBO,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAAwCC,EAAa,CACjE,OAAO,OAAO,YAAYF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASC,EAAmBC,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO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F,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAiBC,CAAG,IAAM,CAAC,EAC3B,QAAWC,KAAWH,EAAYE,CAAG,EACjCD,EAAiBC,CAAG,EAAEC,CAAO,EAAIP,EAAGG,EAASG,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ,CLtEO,SAASI,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,CAAC,EAElBG,EAAKC,EAAI,CAAE,GAAAH,CAAG,CAAC,EAEfI,EAASC,EAAQ,CAAE,GAAAL,EAAI,GAAAE,CAAG,CAAC,EAEjC,MAAO,CAAE,GAAAF,EAAI,GAAAE,EAAI,OAAAE,CAAO,CAC5B","names":["define_exports","__export","defineCV","__toCommonJS","import_clsx","_cn","merge","className","inputs","clsx","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
@@ -1,5 +1,5 @@
1
1
  import { CVExtend } from './extend.cjs';
2
- import { C as CV } from './cv-B7zWq-Wg.cjs';
2
+ import { C as CV } from './cv-C4LDfd1S.cjs';
3
3
  import { CNOptions, CN } from './cn.cjs';
4
4
  import 'clsx';
5
5
  import 'ts-essentials';
package/build/define.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CVExtend } from './extend.js';
2
- import { C as CV } from './cv-BdqZkdFD.js';
2
+ import { C as CV } from './cv-BA68QNCx.js';
3
3
  import { CNOptions, CN } from './cn.js';
4
4
  import 'clsx';
5
5
  import 'ts-essentials';
package/build/define.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-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};
1
+ import{a}from"./chunk-BO7CCVZY.js";import"./chunk-O5WYIZI3.js";import"./chunk-36Z7UYAL.js";import"./chunk-LLMR7HCR.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as defineCV};
2
2
  //# sourceMappingURL=define.js.map
package/build/extend.cjs CHANGED
@@ -1,2 +1,2 @@
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});
1
+ "use strict";var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var d=(e,n)=>{for(var o in n)i(e,o,{get:n[o],enumerable:!0})},f=(e,n,o,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of u(n))!m.call(e,t)&&t!==o&&i(e,t,{get:()=>n[t],enumerable:!(a=c(n,t))||a.enumerable});return e};var C=e=>f(i({},"__esModule",{value:!0}),e);var y={};d(y,{_extend:()=>l});module.exports=C(y);function p(e,n){return typeof e=="function"?e(n):e}function l({cn:e,cv:n}){let o=(a,t)=>{let r=structuredClone(a);for(let s in t){r[s]??={};for(let V in t[s])r[s][V]=e(a[s]?.[V],t[s][V])}return r};return(a,t)=>{let{config:r}=a;return n({base:e(r.base,t.base),variants:o(r.variants,t.variants),compoundVariants:s=>p(r.compoundVariants,a).concat(p(t.compoundVariants??[],s)),defaultVariants:{...r.defaultVariants,...t.defaultVariants}})}}0&&(module.exports={_extend});
2
2
  //# sourceMappingURL=extend.cjs.map