@yaredfall/class-variants 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getEntries,
3
3
  getKeys
4
- } from "./chunk-3RDDXOQ3.js";
4
+ } from "./chunk-AQSN2Y5C.js";
5
5
 
6
6
  // src/index.ts
7
7
  import { clsx } from "clsx";
@@ -36,4 +36,4 @@ var cv = (config, options = {}) => {
36
36
  export {
37
37
  cv
38
38
  };
39
- //# sourceMappingURL=chunk-BNE2ZOTW.js.map
39
+ //# sourceMappingURL=chunk-5UWIPH6K.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { MarkRequired, Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, \"class\">>;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type WithClassProp<T extends Record<string, any>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n requiredProps?: R[];\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> =\r\nWithClassProp<MarkRequired<{ [K in keyof V]?: keyof V[K] }, R>>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n"],"mappings":";;;;;;AAAA,SAAqB,YAAY;AAwC1B,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;","names":[]}
@@ -8,10 +8,14 @@ function getEntries(obj) {
8
8
  function getVariantsOptions(variants) {
9
9
  return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]));
10
10
  }
11
+ function objectFromEntries(entries) {
12
+ return Object.fromEntries(entries);
13
+ }
11
14
 
12
15
  export {
13
16
  getKeys,
14
17
  getEntries,
15
- getVariantsOptions
18
+ getVariantsOptions,
19
+ objectFromEntries
16
20
  };
17
- //# sourceMappingURL=chunk-3RDDXOQ3.js.map
21
+ //# sourceMappingURL=chunk-AQSN2Y5C.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype 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 function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";AAGO,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;AAEO,SAAS,mBAA+C,UAAa;AACxE,SAAO,OAAO,YAAY,WAAW,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC;AACnG;AAQO,SAAS,kBAAqC,SAAY;AAC7D,SAAO,OAAO,YAAY,OAAO;AACrC;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\nexport type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, \"class\">> | undefined;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\nexport type WithClassProp<T extends Record<string, unknown>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{ [K in keyof V]?: keyof V[K] }>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n","import { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype Entries<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 (Entries<O>[keyof Entries<O>])[];\r\n}\r\n\r\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;;;ACE1B,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;;;AD2BO,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { MarkRequired, Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, \"class\">>;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type WithClassProp<T extends Record<string, any>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n requiredProps?: R[];\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> =\r\nWithClassProp<MarkRequired<{ [K in keyof V]?: keyof V[K] }, R>>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype 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 function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;;;ACG1B,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;;;AD8BO,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;","names":[]}
package/build/index.d.cts CHANGED
@@ -1,31 +1,32 @@
1
1
  import { ClassValue } from 'clsx';
2
- import { Prettify } from 'ts-essentials';
2
+ import { Prettify, MarkRequired } from 'ts-essentials';
3
3
 
4
- type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, "class">> | undefined;
4
+ type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, "class">>;
5
5
  type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
6
- type WithClassProp<T extends Record<string, unknown>> = T & {
6
+ type WithClassProp<T extends Record<string, any>> = T & {
7
7
  class?: ClassValue;
8
8
  };
9
9
  type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{
10
10
  [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean;
11
11
  }>[];
12
- interface CVConfig<V extends CVVariantsSchema> {
12
+ interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {
13
13
  baseClass?: ClassValue;
14
14
  variants?: V;
15
15
  compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);
16
16
  defaultVariant?: Partial<{
17
17
  [K in keyof V]?: keyof V[K];
18
18
  }>;
19
+ requiredProps?: R[];
19
20
  }
20
- type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{
21
+ type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> = WithClassProp<MarkRequired<{
21
22
  [K in keyof V]?: keyof V[K];
22
- }>;
23
- type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;
23
+ }, R>>;
24
+ type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;
24
25
  interface CVOptions {
25
26
  merge?: (...args: ClassValue[]) => string;
26
27
  }
27
28
  interface CV {
28
- <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;
29
+ <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;
29
30
  }
30
31
  declare const cv: CV;
31
32
 
package/build/index.d.ts CHANGED
@@ -1,31 +1,32 @@
1
1
  import { ClassValue } from 'clsx';
2
- import { Prettify } from 'ts-essentials';
2
+ import { Prettify, MarkRequired } from 'ts-essentials';
3
3
 
4
- type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, "class">> | undefined;
4
+ type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, "class">>;
5
5
  type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
6
- type WithClassProp<T extends Record<string, unknown>> = T & {
6
+ type WithClassProp<T extends Record<string, any>> = T & {
7
7
  class?: ClassValue;
8
8
  };
9
9
  type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{
10
10
  [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean;
11
11
  }>[];
12
- interface CVConfig<V extends CVVariantsSchema> {
12
+ interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {
13
13
  baseClass?: ClassValue;
14
14
  variants?: V;
15
15
  compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);
16
16
  defaultVariant?: Partial<{
17
17
  [K in keyof V]?: keyof V[K];
18
18
  }>;
19
+ requiredProps?: R[];
19
20
  }
20
- type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{
21
+ type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> = WithClassProp<MarkRequired<{
21
22
  [K in keyof V]?: keyof V[K];
22
- }>;
23
- type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;
23
+ }, R>>;
24
+ type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;
24
25
  interface CVOptions {
25
26
  merge?: (...args: ClassValue[]) => string;
26
27
  }
27
28
  interface CV {
28
- <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;
29
+ <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;
29
30
  }
30
31
  declare const cv: CV;
31
32
 
package/build/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  cv
3
- } from "./chunk-BNE2ZOTW.js";
4
- import "./chunk-3RDDXOQ3.js";
5
- import "./chunk-PLDDJCW6.js";
3
+ } from "./chunk-5UWIPH6K.js";
4
+ import "./chunk-AQSN2Y5C.js";
6
5
  export {
7
6
  cv
8
7
  };
package/build/utils.cjs CHANGED
@@ -22,7 +22,8 @@ var utils_exports = {};
22
22
  __export(utils_exports, {
23
23
  getEntries: () => getEntries,
24
24
  getKeys: () => getKeys,
25
- getVariantsOptions: () => getVariantsOptions
25
+ getVariantsOptions: () => getVariantsOptions,
26
+ objectFromEntries: () => objectFromEntries
26
27
  });
27
28
  module.exports = __toCommonJS(utils_exports);
28
29
  function getKeys(obj) {
@@ -34,10 +35,14 @@ function getEntries(obj) {
34
35
  function getVariantsOptions(variants) {
35
36
  return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]));
36
37
  }
38
+ function objectFromEntries(entries) {
39
+ return Object.fromEntries(entries);
40
+ }
37
41
  // Annotate the CommonJS export names for ESM import in node:
38
42
  0 && (module.exports = {
39
43
  getEntries,
40
44
  getKeys,
41
- getVariantsOptions
45
+ getVariantsOptions,
46
+ objectFromEntries
42
47
  });
43
48
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype Entries<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 (Entries<O>[keyof Entries<O>])[];\r\n}\r\n\r\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;AAEO,SAAS,mBAA+C,UAAa;AACxE,SAAO,OAAO,YAAY,WAAW,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC;AACnG;","names":[]}
1
+ {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype 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 function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;AAEO,SAAS,mBAA+C,UAAa;AACxE,SAAO,OAAO,YAAY,WAAW,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC;AACnG;AAQO,SAAS,kBAAqC,SAAY;AAC7D,SAAO,OAAO,YAAY,OAAO;AACrC;","names":[]}
package/build/utils.d.cts CHANGED
@@ -1,12 +1,20 @@
1
+ import { Prettify, UnionToIntersection, DeepReadonly, DeepWritable } from 'ts-essentials';
1
2
  import { CVVariantsSchema } from './index.cjs';
2
3
  import 'clsx';
3
- import 'ts-essentials';
4
4
 
5
5
  declare function getKeys<O extends Record<string, unknown>>(obj: O): (keyof O)[];
6
- type Entries<O extends Record<string, unknown>> = {
6
+ type EntriesOf<O extends Record<string, unknown>> = {
7
7
  [K in keyof O]: [K, O[K]];
8
8
  };
9
- declare function getEntries<O extends Record<string, unknown>>(obj: O): (Entries<O>[keyof Entries<O>])[];
9
+ declare function getEntries<O extends Record<string, unknown>>(obj: O): (EntriesOf<O>[keyof EntriesOf<O>])[];
10
10
  declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): { [K in keyof V]: (keyof V[K])[]; };
11
+ type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
12
+ type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? {
13
+ [prop in key & PropertyKey]: val;
14
+ } : never : never;
15
+ type MergeIntersectingObjects<O> = {
16
+ [K in keyof O]: O[K];
17
+ };
18
+ declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
11
19
 
12
- export { getEntries, getKeys, getVariantsOptions };
20
+ export { getEntries, getKeys, getVariantsOptions, objectFromEntries };
package/build/utils.d.ts CHANGED
@@ -1,12 +1,20 @@
1
+ import { Prettify, UnionToIntersection, DeepReadonly, DeepWritable } from 'ts-essentials';
1
2
  import { CVVariantsSchema } from './index.js';
2
3
  import 'clsx';
3
- import 'ts-essentials';
4
4
 
5
5
  declare function getKeys<O extends Record<string, unknown>>(obj: O): (keyof O)[];
6
- type Entries<O extends Record<string, unknown>> = {
6
+ type EntriesOf<O extends Record<string, unknown>> = {
7
7
  [K in keyof O]: [K, O[K]];
8
8
  };
9
- declare function getEntries<O extends Record<string, unknown>>(obj: O): (Entries<O>[keyof Entries<O>])[];
9
+ declare function getEntries<O extends Record<string, unknown>>(obj: O): (EntriesOf<O>[keyof EntriesOf<O>])[];
10
10
  declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): { [K in keyof V]: (keyof V[K])[]; };
11
+ type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
12
+ type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? {
13
+ [prop in key & PropertyKey]: val;
14
+ } : never : never;
15
+ type MergeIntersectingObjects<O> = {
16
+ [K in keyof O]: O[K];
17
+ };
18
+ declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
11
19
 
12
- export { getEntries, getKeys, getVariantsOptions };
20
+ export { getEntries, getKeys, getVariantsOptions, objectFromEntries };
package/build/utils.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  getEntries,
3
3
  getKeys,
4
- getVariantsOptions
5
- } from "./chunk-3RDDXOQ3.js";
6
- import "./chunk-PLDDJCW6.js";
4
+ getVariantsOptions,
5
+ objectFromEntries
6
+ } from "./chunk-AQSN2Y5C.js";
7
7
  export {
8
8
  getEntries,
9
9
  getKeys,
10
- getVariantsOptions
10
+ getVariantsOptions,
11
+ objectFromEntries
11
12
  };
12
13
  //# sourceMappingURL=utils.js.map
package/build/vue.cjs CHANGED
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/vue.ts
21
21
  var vue_exports = {};
22
22
  __export(vue_exports, {
23
- cvWithProps: () => cvWithProps
23
+ cvWithProps: () => cvWithProps,
24
+ getPropsDeclaration: () => getPropsDeclaration
24
25
  });
25
26
  module.exports = __toCommonJS(vue_exports);
26
27
 
@@ -34,6 +35,9 @@ function getKeys(obj) {
34
35
  function getEntries(obj) {
35
36
  return Object.entries(obj);
36
37
  }
38
+ function objectFromEntries(entries) {
39
+ return Object.fromEntries(entries);
40
+ }
37
41
 
38
42
  // src/index.ts
39
43
  var cv = (config, options = {}) => {
@@ -65,24 +69,28 @@ var cv = (config, options = {}) => {
65
69
  };
66
70
 
67
71
  // src/vue.ts
68
- var cvWithProps = (config, options) => {
69
- const getClass = cv(config, options);
72
+ function getPropsDeclaration(config) {
70
73
  if (typeof config?.variants === "undefined") {
71
- return { getClass, props: {} };
74
+ return {};
72
75
  }
73
- const props = Object.fromEntries(
74
- Object.keys(config.variants).map((key) => [
76
+ return objectFromEntries(
77
+ getKeys(config.variants).map((key) => [
75
78
  key,
76
79
  {
77
80
  type: String,
78
- default: config.defaultVariant?.[key]
81
+ required: config.requiredProps?.includes(key)
79
82
  }
80
83
  ])
81
84
  );
85
+ }
86
+ var cvWithProps = (config, options) => {
87
+ const getClass = cv(config, options);
88
+ const props = getPropsDeclaration(config);
82
89
  return { getClass, props };
83
90
  };
84
91
  // Annotate the CommonJS export names for ESM import in node:
85
92
  0 && (module.exports = {
86
- cvWithProps
93
+ cvWithProps,
94
+ getPropsDeclaration
87
95
  });
88
96
  //# sourceMappingURL=vue.cjs.map
package/build/vue.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vue.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import { cv, CVConfig, CVOptions, CVReturn, CVVariantsSchema } from \".\";\r\nimport { Prettify } from \"ts-essentials\";\r\nimport { type Prop } from \"vue\";\r\n\r\ntype PropsDeclaration<V extends CVVariantsSchema> = Prettify<{ [K in keyof V]: Prop<keyof V[K]> }>;\r\n\r\nexport interface CVWithPropsReturn<V extends CVVariantsSchema> {\r\n getClass: CVReturn<V>;\r\n props: PropsDeclaration<V>;\r\n}\r\n\r\nexport interface CVWithProps {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVWithPropsReturn<V>;\r\n}\r\n\r\nexport const cvWithProps = ((config, options) => {\r\n const getClass = cv(config, options);\r\n\r\n if (typeof config?.variants === \"undefined\") {\r\n return { getClass, props: {} };\r\n }\r\n\r\n const props = Object.fromEntries(\r\n Object.keys(config.variants).map(key => [\r\n key,\r\n {\r\n type: String,\r\n default: config.defaultVariant?.[key],\r\n },\r\n ]),\r\n );\r\n\r\n return { getClass, props };\r\n}) as CVWithProps;\r\n","import { ClassValue, clsx } from \"clsx\";\r\nimport { Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\nexport type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, \"class\">> | undefined;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\nexport type WithClassProp<T extends Record<string, unknown>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{ [K in keyof V]?: keyof V[K] }>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n","import { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype Entries<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 (Entries<O>[keyof Entries<O>])[];\r\n}\r\n\r\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAiC;;;ACE1B,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;;;AD2BO,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;;;AD1DO,IAAM,cAAe,CAAC,QAAQ,YAAY;AAC7C,QAAM,WAAW,GAAG,QAAQ,OAAO;AAEnC,MAAI,OAAO,QAAQ,aAAa,aAAa;AACzC,WAAO,EAAE,UAAU,OAAO,CAAC,EAAE;AAAA,EACjC;AAEA,QAAM,QAAQ,OAAO;AAAA,IACjB,OAAO,KAAK,OAAO,QAAQ,EAAE,IAAI,SAAO;AAAA,MACpC;AAAA,MACA;AAAA,QACI,MAAM;AAAA,QACN,SAAS,OAAO,iBAAiB,GAAG;AAAA,MACxC;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO,EAAE,UAAU,MAAM;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../src/vue.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\r\nimport { PropType } from \"vue\";\r\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\r\nimport { getKeys, objectFromEntries } from \"./utils\";\r\n\r\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{ [K in keyof V]: {\r\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\r\n required: K extends R ? true : false;\r\n} }>;\r\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\r\n getClass: CVReturn<V, R>;\r\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\r\n}\r\n\r\nexport interface CVWithProps {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;\r\n}\r\n\r\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>) {\r\n if (typeof config?.variants === \"undefined\") {\r\n return {};\r\n }\r\n\r\n return objectFromEntries(\r\n getKeys(config.variants).map(key => [\r\n key,\r\n {\r\n type: String,\r\n required: config.requiredProps?.includes(key as R),\r\n },\r\n ] as const),\r\n );\r\n}\r\n\r\nexport const cvWithProps: CVWithProps = ((config, options) => {\r\n const getClass = cv(config, options);\r\n const props = getPropsDeclaration(config);\r\n\r\n return { getClass, props };\r\n}) as CVWithProps;\r\n","import { ClassValue, clsx } from \"clsx\";\r\nimport { MarkRequired, Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, \"class\">>;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type WithClassProp<T extends Record<string, any>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n requiredProps?: R[];\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> =\r\nWithClassProp<MarkRequired<{ [K in keyof V]?: keyof V[K] }, R>>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype 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 function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAiC;;;ACG1B,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;AAYO,SAAS,kBAAqC,SAAY;AAC7D,SAAO,OAAO,YAAY,OAAO;AACrC;;;ADgBO,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;;;AD3DO,SAAS,oBAA2E,QAAwB;AAC/G,MAAI,OAAO,QAAQ,aAAa,aAAa;AACzC,WAAO,CAAC;AAAA,EACZ;AAEA,SAAO;AAAA,IACH,QAAQ,OAAO,QAAQ,EAAE,IAAI,SAAO;AAAA,MAChC;AAAA,MACA;AAAA,QACI,MAAM;AAAA,QACN,UAAU,OAAO,eAAe,SAAS,GAAQ;AAAA,MACrD;AAAA,IACJ,CAAU;AAAA,EACd;AACJ;AAEO,IAAM,cAA4B,CAAC,QAAQ,YAAY;AAC1D,QAAM,WAAW,GAAG,QAAQ,OAAO;AACnC,QAAM,QAAQ,oBAAoB,MAAM;AAExC,SAAO,EAAE,UAAU,MAAM;AAC7B;","names":[]}
package/build/vue.d.cts CHANGED
@@ -1,18 +1,22 @@
1
- import { CVVariantsSchema, CVReturn, CVConfig, CVOptions } from './index.cjs';
2
1
  import { Prettify } from 'ts-essentials';
3
- import { Prop } from 'vue';
2
+ import { PropType } from 'vue';
3
+ import { CVVariantsSchema, CVReturn, CVConfig, CVOptions } from './index.cjs';
4
4
  import 'clsx';
5
5
 
6
- type PropsDeclaration<V extends CVVariantsSchema> = Prettify<{
7
- [K in keyof V]: Prop<keyof V[K]>;
6
+ type PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{
7
+ [K in keyof V]: {
8
+ type: PropType<keyof V[K] | (K extends R ? never : undefined)>;
9
+ required: K extends R ? true : false;
10
+ };
8
11
  }>;
9
- interface CVWithPropsReturn<V extends CVVariantsSchema> {
10
- getClass: CVReturn<V>;
11
- props: PropsDeclaration<V>;
12
+ interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {
13
+ getClass: CVReturn<V, R>;
14
+ props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;
12
15
  }
13
16
  interface CVWithProps {
14
- <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVWithPropsReturn<V>;
17
+ <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;
15
18
  }
19
+ declare function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>): {};
16
20
  declare const cvWithProps: CVWithProps;
17
21
 
18
- export { type CVWithProps, type CVWithPropsReturn, cvWithProps };
22
+ export { type CVWithProps, type CVWithPropsReturn, cvWithProps, getPropsDeclaration };
package/build/vue.d.ts CHANGED
@@ -1,18 +1,22 @@
1
- import { CVVariantsSchema, CVReturn, CVConfig, CVOptions } from './index.js';
2
1
  import { Prettify } from 'ts-essentials';
3
- import { Prop } from 'vue';
2
+ import { PropType } from 'vue';
3
+ import { CVVariantsSchema, CVReturn, CVConfig, CVOptions } from './index.js';
4
4
  import 'clsx';
5
5
 
6
- type PropsDeclaration<V extends CVVariantsSchema> = Prettify<{
7
- [K in keyof V]: Prop<keyof V[K]>;
6
+ type PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{
7
+ [K in keyof V]: {
8
+ type: PropType<keyof V[K] | (K extends R ? never : undefined)>;
9
+ required: K extends R ? true : false;
10
+ };
8
11
  }>;
9
- interface CVWithPropsReturn<V extends CVVariantsSchema> {
10
- getClass: CVReturn<V>;
11
- props: PropsDeclaration<V>;
12
+ interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {
13
+ getClass: CVReturn<V, R>;
14
+ props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;
12
15
  }
13
16
  interface CVWithProps {
14
- <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVWithPropsReturn<V>;
17
+ <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;
15
18
  }
19
+ declare function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>): {};
16
20
  declare const cvWithProps: CVWithProps;
17
21
 
18
- export { type CVWithProps, type CVWithPropsReturn, cvWithProps };
22
+ export { type CVWithProps, type CVWithPropsReturn, cvWithProps, getPropsDeclaration };
package/build/vue.js CHANGED
@@ -1,27 +1,33 @@
1
1
  import {
2
2
  cv
3
- } from "./chunk-BNE2ZOTW.js";
4
- import "./chunk-3RDDXOQ3.js";
5
- import "./chunk-PLDDJCW6.js";
3
+ } from "./chunk-5UWIPH6K.js";
4
+ import {
5
+ getKeys,
6
+ objectFromEntries
7
+ } from "./chunk-AQSN2Y5C.js";
6
8
 
7
9
  // src/vue.ts
8
- var cvWithProps = (config, options) => {
9
- const getClass = cv(config, options);
10
+ function getPropsDeclaration(config) {
10
11
  if (typeof config?.variants === "undefined") {
11
- return { getClass, props: {} };
12
+ return {};
12
13
  }
13
- const props = Object.fromEntries(
14
- Object.keys(config.variants).map((key) => [
14
+ return objectFromEntries(
15
+ getKeys(config.variants).map((key) => [
15
16
  key,
16
17
  {
17
18
  type: String,
18
- default: config.defaultVariant?.[key]
19
+ required: config.requiredProps?.includes(key)
19
20
  }
20
21
  ])
21
22
  );
23
+ }
24
+ var cvWithProps = (config, options) => {
25
+ const getClass = cv(config, options);
26
+ const props = getPropsDeclaration(config);
22
27
  return { getClass, props };
23
28
  };
24
29
  export {
25
- cvWithProps
30
+ cvWithProps,
31
+ getPropsDeclaration
26
32
  };
27
33
  //# sourceMappingURL=vue.js.map
package/build/vue.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { cv, CVConfig, CVOptions, CVReturn, CVVariantsSchema } from \".\";\r\nimport { Prettify } from \"ts-essentials\";\r\nimport { type Prop } from \"vue\";\r\n\r\ntype PropsDeclaration<V extends CVVariantsSchema> = Prettify<{ [K in keyof V]: Prop<keyof V[K]> }>;\r\n\r\nexport interface CVWithPropsReturn<V extends CVVariantsSchema> {\r\n getClass: CVReturn<V>;\r\n props: PropsDeclaration<V>;\r\n}\r\n\r\nexport interface CVWithProps {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVWithPropsReturn<V>;\r\n}\r\n\r\nexport const cvWithProps = ((config, options) => {\r\n const getClass = cv(config, options);\r\n\r\n if (typeof config?.variants === \"undefined\") {\r\n return { getClass, props: {} };\r\n }\r\n\r\n const props = Object.fromEntries(\r\n Object.keys(config.variants).map(key => [\r\n key,\r\n {\r\n type: String,\r\n default: config.defaultVariant?.[key],\r\n },\r\n ]),\r\n );\r\n\r\n return { getClass, props };\r\n}) as CVWithProps;\r\n"],"mappings":";;;;;;;AAgBO,IAAM,cAAe,CAAC,QAAQ,YAAY;AAC7C,QAAM,WAAW,GAAG,QAAQ,OAAO;AAEnC,MAAI,OAAO,QAAQ,aAAa,aAAa;AACzC,WAAO,EAAE,UAAU,OAAO,CAAC,EAAE;AAAA,EACjC;AAEA,QAAM,QAAQ,OAAO;AAAA,IACjB,OAAO,KAAK,OAAO,QAAQ,EAAE,IAAI,SAAO;AAAA,MACpC;AAAA,MACA;AAAA,QACI,MAAM;AAAA,QACN,SAAS,OAAO,iBAAiB,GAAG;AAAA,MACxC;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO,EAAE,UAAU,MAAM;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\r\nimport { PropType } from \"vue\";\r\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\r\nimport { getKeys, objectFromEntries } from \"./utils\";\r\n\r\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{ [K in keyof V]: {\r\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\r\n required: K extends R ? true : false;\r\n} }>;\r\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\r\n getClass: CVReturn<V, R>;\r\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\r\n}\r\n\r\nexport interface CVWithProps {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;\r\n}\r\n\r\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>) {\r\n if (typeof config?.variants === \"undefined\") {\r\n return {};\r\n }\r\n\r\n return objectFromEntries(\r\n getKeys(config.variants).map(key => [\r\n key,\r\n {\r\n type: String,\r\n required: config.requiredProps?.includes(key as R),\r\n },\r\n ] as const),\r\n );\r\n}\r\n\r\nexport const cvWithProps: CVWithProps = ((config, options) => {\r\n const getClass = cv(config, options);\r\n const props = getPropsDeclaration(config);\r\n\r\n return { getClass, props };\r\n}) as CVWithProps;\r\n"],"mappings":";;;;;;;;;AAmBO,SAAS,oBAA2E,QAAwB;AAC/G,MAAI,OAAO,QAAQ,aAAa,aAAa;AACzC,WAAO,CAAC;AAAA,EACZ;AAEA,SAAO;AAAA,IACH,QAAQ,OAAO,QAAQ,EAAE,IAAI,SAAO;AAAA,MAChC;AAAA,MACA;AAAA,QACI,MAAM;AAAA,QACN,UAAU,OAAO,eAAe,SAAS,GAAQ;AAAA,MACrD;AAAA,IACJ,CAAU;AAAA,EACd;AACJ;AAEO,IAAM,cAA4B,CAAC,QAAQ,YAAY;AAC1D,QAAM,WAAW,GAAG,QAAQ,OAAO;AACnC,QAAM,QAAQ,oBAAoB,MAAM;AAExC,SAAO,EAAE,UAAU,MAAM;AAC7B;","names":[]}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.0.7",
8
+ "version": "0.0.8",
9
9
  "type": "module",
10
10
  "main": "build/index.cjs",
11
11
  "module": "build/index.js",
package/src/vue.ts CHANGED
@@ -27,7 +27,6 @@ export function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof
27
27
  key,
28
28
  {
29
29
  type: String,
30
- default: config.defaultVariant?.[key],
31
30
  required: config.requiredProps?.includes(key as R),
32
31
  },
33
32
  ] as const),
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype Entries<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 (Entries<O>[keyof Entries<O>])[];\r\n}\r\n\r\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n"],"mappings":";AAEO,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;AAEO,SAAS,mBAA+C,UAAa;AACxE,SAAO,OAAO,YAAY,WAAW,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC;AACnG;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\nexport type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, \"class\">> | undefined;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\nexport type WithClassProp<T extends Record<string, unknown>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{ [K in keyof V]?: keyof V[K] }>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n"],"mappings":";;;;;;AAAA,SAAqB,YAAY;AAoC1B,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;","names":[]}
@@ -1,49 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
- var __esm = (fn, res) => function __init() {
14
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
- };
16
- var __commonJS = (cb, mod) => function __require2() {
17
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
- };
19
- var __export = (target, all) => {
20
- for (var name in all)
21
- __defProp(target, name, { get: all[name], enumerable: true });
22
- };
23
- var __copyProps = (to, from, except, desc) => {
24
- if (from && typeof from === "object" || typeof from === "function") {
25
- for (let key of __getOwnPropNames(from))
26
- if (!__hasOwnProp.call(to, key) && key !== except)
27
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
- }
29
- return to;
30
- };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
- // If the importer is in node compatibility mode or this is not an ESM
33
- // file that has been converted to a CommonJS file using a Babel-
34
- // compatible transform (i.e. "__esModule" has not been set), then set
35
- // "default" to the CommonJS "module.exports" for node compatibility.
36
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
- mod
38
- ));
39
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
-
41
- export {
42
- __require,
43
- __esm,
44
- __commonJS,
45
- __export,
46
- __toESM,
47
- __toCommonJS
48
- };
49
- //# sourceMappingURL=chunk-PLDDJCW6.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}