@yaredfall/class-variants 0.1.2 → 0.4.0-rc
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.
- package/LICENSE +21 -0
- package/build/{chunk-BV75ULQK.js → chunk-4HS2U3AJ.js} +1 -1
- package/build/{chunk-BV75ULQK.js.map → chunk-4HS2U3AJ.js.map} +1 -1
- package/build/chunk-IW3RSJHX.js +2 -0
- package/build/chunk-IW3RSJHX.js.map +1 -0
- package/build/{index-CFb2xboY.d.cts → index-w3SZ98rX.d.cts} +29 -22
- package/build/{index-CFb2xboY.d.ts → index-w3SZ98rX.d.ts} +29 -22
- package/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/utils.cjs +1 -1
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +1 -1
- package/build/utils.d.ts +1 -1
- package/build/utils.js +1 -1
- package/build/vue.cjs +1 -1
- package/build/vue.cjs.map +1 -1
- package/build/vue.d.cts +1 -1
- package/build/vue.d.ts +1 -1
- package/build/vue.js +1 -1
- package/build/vue.js.map +1 -1
- package/package.json +56 -57
- package/build/chunk-4SXOWWRN.js +0 -2
- package/build/chunk-4SXOWWRN.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 YaredFall
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
function r(e){return Object.keys(e)}function o(e){return Object.entries(e)}function i(e){return Object.fromEntries(o(e).map(([n,t])=>[n,r(t)]))}function s(e){return Object.fromEntries(e)}export{r as a,o as b,i as c,s as d};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-4HS2U3AJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ?
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? Record<key & PropertyKey, val>\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"AAIO,SAASA,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA+CC,EAAa,CACxE,OAAO,OAAO,YACVF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CACxE,CACJ,CAYO,SAASC,EAAqCC,EAAY,CAC7D,OAAO,OAAO,YAAYA,CAAO,CAGrC","names":["getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","objectFromEntries","entries"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as f,b as y,c as m}from"./chunk-4HS2U3AJ.js";import{clsx as T}from"clsx";function P(x={}){let V=x.merge??T;return{cn:V,cv:a=>{let{base:s,variants:e,defaultVariants:o,requiredVariants:R}=a,d={variants:e??{},variantKeys:e?f(e):[],variantMap:e?m(e):{},defaultVariants:o??{},requiredVariants:R??{}},h=e?typeof a.compoundVariants=="function"?a.compoundVariants(d):a.compoundVariants:void 0;return Object.assign(r=>{let v=e?d.variantKeys.map(t=>{let p=r?.[t],l=o?.[t],i=p?.toString()||l?.toString();return i?e[t][i]:void 0}):void 0,k=h?.reduce((t,{class:p,className:l,...i})=>(y(i).every(([C,n])=>{let g=o?.[C],u=r?.[C];if(typeof n=="object"&&"__token"in n){if(n.__token===_.__token)return u!==void 0;if(n.__token===W.__token)return u===void 0}let c=u??g;return Array.isArray(n)?n.some(O=>c===O):c===n})&&t.push(p,l),t),new Array);return V(s,v,k,r?.class,r?.className)},d)},compose:(...a)=>s=>{let e={...s,class:void 0,className:void 0};return V(a.map(o=>o(e)),s?.class,s?.className)}}}var{cn:A,cv:j,compose:E}=P(),_={__token:"OnlyWhenDefined"},W={__token:"OnlyWhenUndefined"};export{P as a,A as b,j as c,E as d,_ as e,W as f};
|
|
2
|
+
//# sourceMappingURL=chunk-IW3RSJHX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\nimport {\n MarkRequired,\n Opaque,\n Prettify,\n type RequiredKeys,\n type UnionToIntersection,\n} from \"ts-essentials\";\nimport {\n getEntries,\n getKeys,\n getVariantsOptions,\n KeysOf,\n VariantOptions as VariantMap,\n} from \"./utils\";\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\nexport type WithClassProp<T extends object> = T & ClassProp;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = Prettify<\n Omit<\n UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>,\n \"class\" | \"className\"\n >\n>;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);\n defaultVariants?: CVVariant<V>;\n requiredVariants?: Record<R, boolean>;\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | WithClassProp<MarkRequired<CVVariant<V>, R>>\n | ([R] extends [never] ? void : never);\n\nexport interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {\n variants: V;\n variantKeys: KeysOf<V>;\n variantMap: VariantMap<V>;\n defaultVariants: CVVariant<V>;\n requiredVariants: Record<R, boolean>;\n}\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never>\n extends CVUtils<V, R> {\n (props: CVReturnProps<V, R>): string;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype CVComposeReturnProps<T extends (props?: any) => string> =\n | WithClassProp<VariantProps<T>>\n | (RequiredKeys<VariantProps<T>> extends never ? void : never);\nexport interface CVCompose {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type, @typescript-eslint/no-explicit-any\n <T extends ((props?: any) => string)[]>(\n ...components: T\n ): (props: CVComposeReturnProps<T[number]>) => string;\n}\n\nexport function defineCV(options: CVOptions = {}) {\n const cn = options.merge ?? clsx;\n\n const cv: CV = (config) => {\n const { base, variants, defaultVariants, requiredVariants } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const utils = {\n variants: variants ?? ({} as ResolvedV),\n variantKeys: variants ? getKeys(variants) : [],\n variantMap: variants ? getVariantsOptions(variants) : ({} as VariantMap<ResolvedV>),\n defaultVariants: defaultVariants ?? ({} as CVVariant<ResolvedV>),\n requiredVariants: requiredVariants ?? ({} as Record<keyof ResolvedV, boolean>),\n };\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants(utils)\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? utils.variantKeys.map((variant) => {\n const variantProp = props?.[variant];\n const defaults = defaultVariants?.[variant];\n\n const variantKey = variantProp?.toString() || defaults?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariants?.[cvKey as keyof typeof defaultVariants];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return cn(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, utils);\n };\n\n const compose: CVCompose =\n (...components) =>\n (props) => {\n const propsWithoutClass = { ...props, class: undefined, className: undefined };\n\n return cn(\n components.map((component) => component(propsWithoutClass)),\n props?.class,\n props?.className,\n );\n };\n\n return { cn, cv, compose };\n}\n\nexport const { cn, cv, compose } = defineCV();\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype 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"],"mappings":"sDAAA,OAAqB,QAAAA,MAAY,OA8F1B,SAASC,EAASC,EAAqB,CAAC,EAAG,CAC9C,IAAMC,EAAKD,EAAQ,OAASE,EAyF5B,MAAO,CAAE,GAAAD,EAAI,GAvFGE,GAAW,CACvB,GAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,gBAAAC,EAAiB,iBAAAC,CAAiB,EAAIJ,EAIxDK,EAAQ,CACV,SAAUH,GAAa,CAAC,EACxB,YAAaA,EAAWI,EAAQJ,CAAQ,EAAI,CAAC,EAC7C,WAAYA,EAAWK,EAAmBL,CAAQ,EAAK,CAAC,EACxD,gBAAiBC,GAAoB,CAAC,EACtC,iBAAkBC,GAAqB,CAAC,CAC5C,EAEMI,EAAmBN,EACnB,OAAOF,EAAO,kBAAqB,WAC/BA,EAAO,iBAAiBK,CAAK,EAC7BL,EAAO,iBACX,OAuDN,OAAO,OAAO,OApDVS,GACC,CACD,IAAMC,EAAoBR,EACpBG,EAAM,YAAY,IAAKM,GAAY,CAC/B,IAAMC,EAAcH,IAAQE,CAAO,EAC7BE,EAAWV,IAAkBQ,CAAO,EAEpCG,EAAaF,GAAa,SAAS,GAAKC,GAAU,SAAS,EAEjE,OAAOC,EAAaZ,EAASS,CAAO,EAAEG,CAAU,EAAI,MACxD,CAAC,EACD,OAEAC,EAA4BP,GAAkB,OAChD,CAACQ,EAAK,CAAE,MAAOC,EAAS,UAAWC,EAAa,GAAGC,CAAS,KACrBC,EAAWD,CAAQ,EAAE,MACpD,CAAC,CAACE,EAAOC,CAAU,IAAM,CACrB,IAAMC,EACFpB,IAAkBkB,CAAqC,EACrDG,EAAgBf,IAAQY,CAA2B,EAEzD,GAAI,OAAOC,GAAe,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOlB,EACHG,EACAS,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiCJ,CAAK,CAC1C,EAciB,QAXb,IAAIuB,IACHnB,GAAU,CACP,IAAMoB,EAAoB,CAAE,GAAGpB,EAAO,MAAO,OAAW,UAAW,MAAU,EAE7E,OAAOX,EACH8B,EAAW,IAAKE,GAAcA,EAAUD,CAAiB,CAAC,EAC1DpB,GAAO,MACPA,GAAO,SACX,CACJ,CAEqB,CAC7B,CAEO,GAAM,CAAE,GAAAX,EAAI,GAAAiC,EAAI,QAAAC,CAAQ,EAAIpC,EAAS,EAQ/B6B,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB","names":["clsx","defineCV","options","cn","clsx","config","base","variants","defaultVariants","requiredVariants","utils","getKeys","getVariantsOptions","compoundVariants","props","variantClassNames","variant","variantProp","defaults","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","components","propsWithoutClass","component","cv","compose"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClassValue } from 'clsx';
|
|
2
|
-
import { Prettify, UnionToIntersection,
|
|
2
|
+
import { DeepReadonly, Prettify, UnionToIntersection, DeepWritable, Opaque, MarkRequired, RequiredKeys } from 'ts-essentials';
|
|
3
3
|
|
|
4
4
|
type KeysOf<O extends Record<string, unknown>> = (keyof O)[];
|
|
5
5
|
declare function getKeys<O extends Record<string, unknown>>(obj: O): KeysOf<O>;
|
|
@@ -12,15 +12,12 @@ type VariantOptions<V extends CVVariantsSchema> = {
|
|
|
12
12
|
};
|
|
13
13
|
declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): VariantOptions<V>;
|
|
14
14
|
type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
|
|
15
|
-
type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ?
|
|
16
|
-
[prop in key & PropertyKey]: val;
|
|
17
|
-
} : never : never;
|
|
15
|
+
type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? Record<key & PropertyKey, val> : never : never;
|
|
18
16
|
type MergeIntersectingObjects<O> = {
|
|
19
17
|
[K in keyof O]: O[K];
|
|
20
18
|
};
|
|
21
19
|
declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
|
|
22
20
|
|
|
23
|
-
type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<StrictExclude<Parameters<CVR>[0], void>>, "class" | "className">>;
|
|
24
21
|
type ClassProp = {
|
|
25
22
|
class?: ClassValue;
|
|
26
23
|
className?: never;
|
|
@@ -28,9 +25,10 @@ type ClassProp = {
|
|
|
28
25
|
class?: never;
|
|
29
26
|
className?: ClassValue;
|
|
30
27
|
};
|
|
31
|
-
type WithClassProp<T extends
|
|
28
|
+
type WithClassProp<T extends object> = T & ClassProp;
|
|
29
|
+
type VariantProps<CVR extends (props?: any) => string> = Prettify<Omit<UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>, "class" | "className">>;
|
|
32
30
|
type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
33
|
-
type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
|
|
31
|
+
type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;
|
|
34
32
|
type CVVariant<V extends CVVariantsSchema> = {
|
|
35
33
|
[K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;
|
|
36
34
|
};
|
|
@@ -41,30 +39,39 @@ type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>
|
|
|
41
39
|
interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {
|
|
42
40
|
base?: ClassValue;
|
|
43
41
|
variants?: V;
|
|
44
|
-
compoundVariants?: CVCompoundVariantsSchema<V> | ((arg:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
options: VariantOptions<V>;
|
|
48
|
-
defaults: CVVariant<V>;
|
|
49
|
-
}) => CVCompoundVariantsSchema<V>);
|
|
50
|
-
defaultVariant?: CVVariant<V>;
|
|
51
|
-
requiredProps?: R[];
|
|
42
|
+
compoundVariants?: CVCompoundVariantsSchema<V> | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);
|
|
43
|
+
defaultVariants?: CVVariant<V>;
|
|
44
|
+
requiredVariants?: Record<R, boolean>;
|
|
52
45
|
}
|
|
53
46
|
interface CVOptions {
|
|
54
47
|
merge?: (...args: ClassValue[]) => string;
|
|
55
48
|
}
|
|
56
|
-
type CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =
|
|
57
|
-
interface
|
|
49
|
+
type CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> = WithClassProp<MarkRequired<CVVariant<V>, R>> | ([R] extends [never] ? void : never);
|
|
50
|
+
interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {
|
|
51
|
+
variants: V;
|
|
52
|
+
variantKeys: KeysOf<V>;
|
|
53
|
+
variantMap: VariantOptions<V>;
|
|
54
|
+
defaultVariants: CVVariant<V>;
|
|
55
|
+
requiredVariants: Record<R, boolean>;
|
|
56
|
+
}
|
|
57
|
+
interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never> extends CVUtils<V, R> {
|
|
58
58
|
(props: CVReturnProps<V, R>): string;
|
|
59
|
-
keys: KeysOf<V>;
|
|
60
|
-
options: VariantOptions<V>;
|
|
61
|
-
defaults: CVVariant<V>;
|
|
62
59
|
}
|
|
63
60
|
interface CV {
|
|
64
61
|
<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, cvOptions?: CVOptions): CVReturn<V, R>;
|
|
65
62
|
}
|
|
63
|
+
type CVComposeReturnProps<T extends (props?: any) => string> = WithClassProp<VariantProps<T>> | (RequiredKeys<VariantProps<T>> extends never ? void : never);
|
|
64
|
+
interface CVCompose {
|
|
65
|
+
<T extends ((props?: any) => string)[]>(...components: T): (props: CVComposeReturnProps<T[number]>) => string;
|
|
66
|
+
}
|
|
67
|
+
declare function defineCV(options?: CVOptions): {
|
|
68
|
+
cn: (...args: ClassValue[]) => string;
|
|
69
|
+
cv: CV;
|
|
70
|
+
compose: CVCompose;
|
|
71
|
+
};
|
|
72
|
+
declare const cn: (...args: ClassValue[]) => string;
|
|
66
73
|
declare const cv: CV;
|
|
67
|
-
declare
|
|
74
|
+
declare const compose: CVCompose;
|
|
68
75
|
type OnlyWhenDefined = Opaque<{
|
|
69
76
|
__token: string;
|
|
70
77
|
}, "OnlyWhenDefined">;
|
|
@@ -77,4 +84,4 @@ declare const onlyWhenDefined: OnlyWhenDefined;
|
|
|
77
84
|
/** Apply compound variant only if prop **is not** specified */
|
|
78
85
|
declare const onlyWhenUndefined: OnlyWhenUndefined;
|
|
79
86
|
|
|
80
|
-
export { type CVVariantsSchema as C, type EntriesOf as E, type KeysOf as K, type VariantOptions as V, type WithClassProp as W, type CVReturn as a, type CVConfig as b, type CVOptions as c, getEntries as d, getVariantsOptions as e, type VariantProps as f, getKeys as g, type CVVariant as h, type CVCompoundVariant as i, type CVCompoundVariantsSchema as j, type
|
|
87
|
+
export { type CVVariantsSchema as C, type EntriesOf as E, type KeysOf as K, type VariantOptions as V, type WithClassProp as W, type CVReturn as a, type CVConfig as b, type CVOptions as c, getEntries as d, getVariantsOptions as e, type VariantProps as f, getKeys as g, type CVVariant as h, type CVCompoundVariant as i, type CVCompoundVariantsSchema as j, type CVUtils as k, type CV as l, type CVCompose as m, defineCV as n, objectFromEntries as o, cn as p, cv as q, compose as r, onlyWhenDefined as s, onlyWhenUndefined as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClassValue } from 'clsx';
|
|
2
|
-
import { Prettify, UnionToIntersection,
|
|
2
|
+
import { DeepReadonly, Prettify, UnionToIntersection, DeepWritable, Opaque, MarkRequired, RequiredKeys } from 'ts-essentials';
|
|
3
3
|
|
|
4
4
|
type KeysOf<O extends Record<string, unknown>> = (keyof O)[];
|
|
5
5
|
declare function getKeys<O extends Record<string, unknown>>(obj: O): KeysOf<O>;
|
|
@@ -12,15 +12,12 @@ type VariantOptions<V extends CVVariantsSchema> = {
|
|
|
12
12
|
};
|
|
13
13
|
declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): VariantOptions<V>;
|
|
14
14
|
type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
|
|
15
|
-
type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ?
|
|
16
|
-
[prop in key & PropertyKey]: val;
|
|
17
|
-
} : never : never;
|
|
15
|
+
type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? Record<key & PropertyKey, val> : never : never;
|
|
18
16
|
type MergeIntersectingObjects<O> = {
|
|
19
17
|
[K in keyof O]: O[K];
|
|
20
18
|
};
|
|
21
19
|
declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
|
|
22
20
|
|
|
23
|
-
type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<StrictExclude<Parameters<CVR>[0], void>>, "class" | "className">>;
|
|
24
21
|
type ClassProp = {
|
|
25
22
|
class?: ClassValue;
|
|
26
23
|
className?: never;
|
|
@@ -28,9 +25,10 @@ type ClassProp = {
|
|
|
28
25
|
class?: never;
|
|
29
26
|
className?: ClassValue;
|
|
30
27
|
};
|
|
31
|
-
type WithClassProp<T extends
|
|
28
|
+
type WithClassProp<T extends object> = T & ClassProp;
|
|
29
|
+
type VariantProps<CVR extends (props?: any) => string> = Prettify<Omit<UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>, "class" | "className">>;
|
|
32
30
|
type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
33
|
-
type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
|
|
31
|
+
type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;
|
|
34
32
|
type CVVariant<V extends CVVariantsSchema> = {
|
|
35
33
|
[K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;
|
|
36
34
|
};
|
|
@@ -41,30 +39,39 @@ type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>
|
|
|
41
39
|
interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {
|
|
42
40
|
base?: ClassValue;
|
|
43
41
|
variants?: V;
|
|
44
|
-
compoundVariants?: CVCompoundVariantsSchema<V> | ((arg:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
options: VariantOptions<V>;
|
|
48
|
-
defaults: CVVariant<V>;
|
|
49
|
-
}) => CVCompoundVariantsSchema<V>);
|
|
50
|
-
defaultVariant?: CVVariant<V>;
|
|
51
|
-
requiredProps?: R[];
|
|
42
|
+
compoundVariants?: CVCompoundVariantsSchema<V> | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);
|
|
43
|
+
defaultVariants?: CVVariant<V>;
|
|
44
|
+
requiredVariants?: Record<R, boolean>;
|
|
52
45
|
}
|
|
53
46
|
interface CVOptions {
|
|
54
47
|
merge?: (...args: ClassValue[]) => string;
|
|
55
48
|
}
|
|
56
|
-
type CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =
|
|
57
|
-
interface
|
|
49
|
+
type CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> = WithClassProp<MarkRequired<CVVariant<V>, R>> | ([R] extends [never] ? void : never);
|
|
50
|
+
interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {
|
|
51
|
+
variants: V;
|
|
52
|
+
variantKeys: KeysOf<V>;
|
|
53
|
+
variantMap: VariantOptions<V>;
|
|
54
|
+
defaultVariants: CVVariant<V>;
|
|
55
|
+
requiredVariants: Record<R, boolean>;
|
|
56
|
+
}
|
|
57
|
+
interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never> extends CVUtils<V, R> {
|
|
58
58
|
(props: CVReturnProps<V, R>): string;
|
|
59
|
-
keys: KeysOf<V>;
|
|
60
|
-
options: VariantOptions<V>;
|
|
61
|
-
defaults: CVVariant<V>;
|
|
62
59
|
}
|
|
63
60
|
interface CV {
|
|
64
61
|
<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, cvOptions?: CVOptions): CVReturn<V, R>;
|
|
65
62
|
}
|
|
63
|
+
type CVComposeReturnProps<T extends (props?: any) => string> = WithClassProp<VariantProps<T>> | (RequiredKeys<VariantProps<T>> extends never ? void : never);
|
|
64
|
+
interface CVCompose {
|
|
65
|
+
<T extends ((props?: any) => string)[]>(...components: T): (props: CVComposeReturnProps<T[number]>) => string;
|
|
66
|
+
}
|
|
67
|
+
declare function defineCV(options?: CVOptions): {
|
|
68
|
+
cn: (...args: ClassValue[]) => string;
|
|
69
|
+
cv: CV;
|
|
70
|
+
compose: CVCompose;
|
|
71
|
+
};
|
|
72
|
+
declare const cn: (...args: ClassValue[]) => string;
|
|
66
73
|
declare const cv: CV;
|
|
67
|
-
declare
|
|
74
|
+
declare const compose: CVCompose;
|
|
68
75
|
type OnlyWhenDefined = Opaque<{
|
|
69
76
|
__token: string;
|
|
70
77
|
}, "OnlyWhenDefined">;
|
|
@@ -77,4 +84,4 @@ declare const onlyWhenDefined: OnlyWhenDefined;
|
|
|
77
84
|
/** Apply compound variant only if prop **is not** specified */
|
|
78
85
|
declare const onlyWhenUndefined: OnlyWhenUndefined;
|
|
79
86
|
|
|
80
|
-
export { type CVVariantsSchema as C, type EntriesOf as E, type KeysOf as K, type VariantOptions as V, type WithClassProp as W, type CVReturn as a, type CVConfig as b, type CVOptions as c, getEntries as d, getVariantsOptions as e, type VariantProps as f, getKeys as g, type CVVariant as h, type CVCompoundVariant as i, type CVCompoundVariantsSchema as j, type
|
|
87
|
+
export { type CVVariantsSchema as C, type EntriesOf as E, type KeysOf as K, type VariantOptions as V, type WithClassProp as W, type CVReturn as a, type CVConfig as b, type CVOptions as c, getEntries as d, getVariantsOptions as e, type VariantProps as f, getKeys as g, type CVVariant as h, type CVCompoundVariant as i, type CVCompoundVariantsSchema as j, type CVUtils as k, type CV as l, type CVCompose as m, defineCV as n, objectFromEntries as o, cn as p, cv as q, compose as r, onlyWhenDefined as s, onlyWhenUndefined as t };
|
package/build/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var s in n)C(e,s,{get:n[s],enumerable:!0})},j=(e,n,s,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of U(n))!q.call(e,t)&&t!==s&&C(e,t,{get:()=>n[t],enumerable:!(l=E(n,t))||l.enumerable});return e};var D=e=>j(C({},"__esModule",{value:!0}),e);var A={};N(A,{cn:()=>M,compose:()=>w,cv:()=>B,defineCV:()=>h,onlyWhenDefined:()=>v,onlyWhenUndefined:()=>K});module.exports=D(A);var g=require("clsx");function m(e){return Object.keys(e)}function x(e){return Object.entries(e)}function k(e){return Object.fromEntries(x(e).map(([n,s])=>[n,m(s)]))}function h(e={}){let n=e.merge??g.clsx;return{cn:n,cv:t=>{let{base:i,variants:r,defaultVariants:V,requiredVariants:P}=t,y={variants:r??{},variantKeys:r?m(r):[],variantMap:r?k(r):{},defaultVariants:V??{},requiredVariants:P??{}},T=r?typeof t.compoundVariants=="function"?t.compoundVariants(y):t.compoundVariants:void 0;return Object.assign(p=>{let b=r?y.variantKeys.map(o=>{let c=p?.[o],f=V?.[o],d=c?.toString()||f?.toString();return d?r[o][d]:void 0}):void 0,W=T?.reduce((o,{class:c,className:f,...d})=>(x(d).every(([O,a])=>{let _=V?.[O],u=p?.[O];if(typeof a=="object"&&"__token"in a){if(a.__token===v.__token)return u!==void 0;if(a.__token===K.__token)return u===void 0}let R=u??_;return Array.isArray(a)?a.some(S=>R===S):R===a})&&o.push(c,f),o),new Array);return n(i,b,W,p?.class,p?.className)},y)},compose:(...t)=>i=>{let r={...i,class:void 0,className:void 0};return n(t.map(V=>V(r)),i?.class,i?.className)}}}var{cn:M,cv:B,compose:w}=h(),v={__token:"OnlyWhenDefined"},K={__token:"OnlyWhenUndefined"};0&&(module.exports={cn,compose,cv,defineCV,onlyWhenDefined,onlyWhenUndefined});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\nimport { MarkRequired, Prettify, StrictExclude, Opaque } from \"ts-essentials\";\nimport { getEntries, getKeys, getVariantsOptions, KeysOf, VariantOptions } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<\n Omit<NonNullable<StrictExclude<Parameters<CVR>[0], void>>, \"class\" | \"className\">\n>;\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type WithClassProp<T extends Record<string, any>> = T & ClassProp;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: {\n variants: V;\n keys: KeysOf<V>;\n options: VariantOptions<V>;\n defaults: CVVariant<V>;\n }) => CVCompoundVariantsSchema<V>);\n defaultVariant?: CVVariant<V>;\n requiredProps?: R[];\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | Prettify<WithClassProp<MarkRequired<CVVariant<V>, R>>>\n | ([R] extends [never] ? void : never);\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n (props: CVReturnProps<V, R>): string;\n keys: KeysOf<V>;\n options: VariantOptions<V>;\n defaults: CVVariant<V>;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\nexport const cv: CV = (config, cvOptions = {}) => {\n const merge = cvOptions.merge ?? clsx;\n\n const { variants, defaultVariant, base } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const keys = variants ? getKeys(variants) : [];\n const options = variants ? getVariantsOptions(variants) : ({} as VariantOptions<ResolvedV>);\n const defaults = defaultVariant ?? ({} as CVVariant<ResolvedV>);\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants({ variants, keys, options, defaults })\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? keys.map((variant) => {\n const variantProp = props?.[variant];\n const defaultVariantProp = defaultVariant?.[variant];\n\n const variantKey = variantProp?.toString() || defaultVariantProp?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariant?.[cvKey as keyof typeof defaultVariant];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return merge(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, { keys, options, defaults });\n};\n\nexport function defineCV(options: CVOptions): CV {\n return (config) => cv(config, options);\n}\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype 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","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? { [prop in key & PropertyKey]: val }\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,aAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAiC,gBCI1B,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA+CC,EAAa,CACxE,OAAO,OAAO,YACVF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CACxE,CACJ,CDgDO,IAAMC,EAAS,CAACC,EAAQC,EAAY,CAAC,IAAM,CAC9C,IAAMC,EAAQD,EAAU,OAAS,OAE3B,CAAE,SAAAE,EAAU,eAAAC,EAAgB,KAAAC,CAAK,EAAIL,EAIrCM,EAAOH,EAAWI,EAAQJ,CAAQ,EAAI,CAAC,EACvCK,EAAUL,EAAWM,EAAmBN,CAAQ,EAAK,CAAC,EACtDO,EAAWN,GAAmB,CAAC,EAE/BO,EAAmBR,EACnB,OAAOH,EAAO,kBAAqB,WAC/BA,EAAO,iBAAiB,CAAE,SAAAG,EAAU,KAAAG,EAAM,QAAAE,EAAS,SAAAE,CAAS,CAAC,EAC7DV,EAAO,iBACX,OAuDN,OAAO,OAAO,OApDVY,GACC,CACD,IAAMC,EAAoBV,EACpBG,EAAK,IAAKQ,GAAY,CAClB,IAAMC,EAAcH,IAAQE,CAAO,EAC7BE,EAAqBZ,IAAiBU,CAAO,EAE7CG,EAAaF,GAAa,SAAS,GAAKC,GAAoB,SAAS,EAE3E,OAAOC,EAAad,EAASW,CAAO,EAAEG,CAAU,EAAI,MACxD,CAAC,EACD,OAEAC,EAA4BP,GAAkB,OAChD,CAACQ,EAAK,CAAE,MAAOC,EAAS,UAAWC,EAAa,GAAGC,CAAS,KACrBC,EAAWD,CAAQ,EAAE,MACpD,CAAC,CAACE,EAAOC,CAAU,IAAM,CACrB,IAAMC,EACFtB,IAAiBoB,CAAoC,EACnDG,EAAgBf,IAAQY,CAA2B,EAEzD,GAAI,OAAOC,GAAe,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOjB,EACHG,EACAQ,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiC,CAAE,KAAAN,EAAM,QAAAE,EAAS,SAAAE,CAAS,CAAC,CAChE,EAEO,SAASqB,EAASvB,EAAwB,CAC7C,OAAQR,GAAWD,EAAGC,EAAQQ,CAAO,CACzC,CAQO,IAAMoB,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB","names":["src_exports","__export","cv","defineCV","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","import_clsx","getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","cv","config","cvOptions","merge","variants","defaultVariant","base","keys","getKeys","options","getVariantsOptions","defaults","compoundVariants","props","variantClassNames","variant","variantProp","defaultVariantProp","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","defineCV"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\nimport {\n MarkRequired,\n Opaque,\n Prettify,\n type RequiredKeys,\n type UnionToIntersection,\n} from \"ts-essentials\";\nimport {\n getEntries,\n getKeys,\n getVariantsOptions,\n KeysOf,\n VariantOptions as VariantMap,\n} from \"./utils\";\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\nexport type WithClassProp<T extends object> = T & ClassProp;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = Prettify<\n Omit<\n UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>,\n \"class\" | \"className\"\n >\n>;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);\n defaultVariants?: CVVariant<V>;\n requiredVariants?: Record<R, boolean>;\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | WithClassProp<MarkRequired<CVVariant<V>, R>>\n | ([R] extends [never] ? void : never);\n\nexport interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {\n variants: V;\n variantKeys: KeysOf<V>;\n variantMap: VariantMap<V>;\n defaultVariants: CVVariant<V>;\n requiredVariants: Record<R, boolean>;\n}\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never>\n extends CVUtils<V, R> {\n (props: CVReturnProps<V, R>): string;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype CVComposeReturnProps<T extends (props?: any) => string> =\n | WithClassProp<VariantProps<T>>\n | (RequiredKeys<VariantProps<T>> extends never ? void : never);\nexport interface CVCompose {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type, @typescript-eslint/no-explicit-any\n <T extends ((props?: any) => string)[]>(\n ...components: T\n ): (props: CVComposeReturnProps<T[number]>) => string;\n}\n\nexport function defineCV(options: CVOptions = {}) {\n const cn = options.merge ?? clsx;\n\n const cv: CV = (config) => {\n const { base, variants, defaultVariants, requiredVariants } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const utils = {\n variants: variants ?? ({} as ResolvedV),\n variantKeys: variants ? getKeys(variants) : [],\n variantMap: variants ? getVariantsOptions(variants) : ({} as VariantMap<ResolvedV>),\n defaultVariants: defaultVariants ?? ({} as CVVariant<ResolvedV>),\n requiredVariants: requiredVariants ?? ({} as Record<keyof ResolvedV, boolean>),\n };\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants(utils)\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? utils.variantKeys.map((variant) => {\n const variantProp = props?.[variant];\n const defaults = defaultVariants?.[variant];\n\n const variantKey = variantProp?.toString() || defaults?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariants?.[cvKey as keyof typeof defaultVariants];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return cn(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, utils);\n };\n\n const compose: CVCompose =\n (...components) =>\n (props) => {\n const propsWithoutClass = { ...props, class: undefined, className: undefined };\n\n return cn(\n components.map((component) => component(propsWithoutClass)),\n props?.class,\n props?.className,\n );\n };\n\n return { cn, cv, compose };\n}\n\nexport const { cn, cv, compose } = defineCV();\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype 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","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? Record<key & PropertyKey, val>\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,YAAAC,EAAA,OAAAC,EAAA,aAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAR,GAAA,IAAAS,EAAiC,gBCI1B,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA+CC,EAAa,CACxE,OAAO,OAAO,YACVF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CACxE,CACJ,CD0EO,SAASC,EAASC,EAAqB,CAAC,EAAG,CAC9C,IAAMC,EAAKD,EAAQ,OAAS,OAyF5B,MAAO,CAAE,GAAAC,EAAI,GAvFGC,GAAW,CACvB,GAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,gBAAAC,EAAiB,iBAAAC,CAAiB,EAAIJ,EAIxDK,EAAQ,CACV,SAAUH,GAAa,CAAC,EACxB,YAAaA,EAAWI,EAAQJ,CAAQ,EAAI,CAAC,EAC7C,WAAYA,EAAWK,EAAmBL,CAAQ,EAAK,CAAC,EACxD,gBAAiBC,GAAoB,CAAC,EACtC,iBAAkBC,GAAqB,CAAC,CAC5C,EAEMI,EAAmBN,EACnB,OAAOF,EAAO,kBAAqB,WAC/BA,EAAO,iBAAiBK,CAAK,EAC7BL,EAAO,iBACX,OAuDN,OAAO,OAAO,OApDVS,GACC,CACD,IAAMC,EAAoBR,EACpBG,EAAM,YAAY,IAAKM,GAAY,CAC/B,IAAMC,EAAcH,IAAQE,CAAO,EAC7BE,EAAWV,IAAkBQ,CAAO,EAEpCG,EAAaF,GAAa,SAAS,GAAKC,GAAU,SAAS,EAEjE,OAAOC,EAAaZ,EAASS,CAAO,EAAEG,CAAU,EAAI,MACxD,CAAC,EACD,OAEAC,EAA4BP,GAAkB,OAChD,CAACQ,EAAK,CAAE,MAAOC,EAAS,UAAWC,EAAa,GAAGC,CAAS,KACrBC,EAAWD,CAAQ,EAAE,MACpD,CAAC,CAACE,EAAOC,CAAU,IAAM,CACrB,IAAMC,EACFpB,IAAkBkB,CAAqC,EACrDG,EAAgBf,IAAQY,CAA2B,EAEzD,GAAI,OAAOC,GAAe,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOjB,EACHE,EACAS,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiCJ,CAAK,CAC1C,EAciB,QAXb,IAAIuB,IACHnB,GAAU,CACP,IAAMoB,EAAoB,CAAE,GAAGpB,EAAO,MAAO,OAAW,UAAW,MAAU,EAE7E,OAAOV,EACH6B,EAAW,IAAKE,GAAcA,EAAUD,CAAiB,CAAC,EAC1DpB,GAAO,MACPA,GAAO,SACX,CACJ,CAEqB,CAC7B,CAEO,GAAM,CAAE,GAAAV,EAAI,GAAAgC,EAAI,QAAAC,CAAQ,EAAInC,EAAS,EAQ/B4B,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB","names":["index_exports","__export","cn","compose","cv","defineCV","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","import_clsx","getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","defineCV","options","cn","config","base","variants","defaultVariants","requiredVariants","utils","getKeys","getVariantsOptions","compoundVariants","props","variantClassNames","variant","variantProp","defaults","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","components","propsWithoutClass","component","cv","compose"]}
|
package/build/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'clsx';
|
|
2
2
|
import 'ts-essentials';
|
|
3
|
-
export {
|
|
3
|
+
export { l as CV, m as CVCompose, i as CVCompoundVariant, j as CVCompoundVariantsSchema, b as CVConfig, c as CVOptions, a as CVReturn, k as CVUtils, h as CVVariant, C as CVVariantsSchema, f as VariantProps, W as WithClassProp, p as cn, r as compose, q as cv, n as defineCV, s as onlyWhenDefined, t as onlyWhenUndefined } from './index-w3SZ98rX.cjs';
|
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'clsx';
|
|
2
2
|
import 'ts-essentials';
|
|
3
|
-
export {
|
|
3
|
+
export { l as CV, m as CVCompose, i as CVCompoundVariant, j as CVCompoundVariantsSchema, b as CVConfig, c as CVOptions, a as CVReturn, k as CVUtils, h as CVVariant, C as CVVariantsSchema, f as VariantProps, W as WithClassProp, p as cn, r as compose, q as cv, n as defineCV, s as onlyWhenDefined, t as onlyWhenUndefined } from './index-w3SZ98rX.js';
|
package/build/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f}from"./chunk-IW3RSJHX.js";import"./chunk-4HS2U3AJ.js";export{b as cn,d as compose,c as cv,a as defineCV,e as onlyWhenDefined,f as onlyWhenUndefined};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/build/utils.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=(e,n)=>{for(var t in n)o(e,t,{get:n[t],enumerable:!0})},c=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of y(n))!p.call(e,r)&&r!==t&&o(e,r,{get:()=>n[r],enumerable:!(i=a(n,r))||i.enumerable});return e};var d=e=>c(o({},"__esModule",{value:!0}),e);var k={};f(k,{getEntries:()=>O,getKeys:()=>s,getVariantsOptions:()=>x,objectFromEntries:()=>V});module.exports=d(k);function s(e){return Object.keys(e)}function O(e){return Object.entries(e)}function x(e){return Object.fromEntries(O(e).map(([n,t])=>[n,s(t)]))}function V(e){return Object.fromEntries(e)}0&&(module.exports={getEntries,getKeys,getVariantsOptions,objectFromEntries});
|
|
2
2
|
//# sourceMappingURL=utils.cjs.map
|
package/build/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ?
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? Record<key & PropertyKey, val>\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,EAAA,uBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAN,GAIO,SAASG,EAA2CI,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASL,EAA8CK,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASH,EAA+CI,EAAa,CACxE,OAAO,OAAO,YACVN,EAAWM,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAON,EAAQO,CAAK,CAAC,CAAC,CACxE,CACJ,CAYO,SAASL,EAAqCM,EAAY,CAC7D,OAAO,OAAO,YAAYA,CAAO,CAGrC","names":["utils_exports","__export","getEntries","getKeys","getVariantsOptions","objectFromEntries","__toCommonJS","obj","variants","cvKey","cvVal","entries"]}
|
package/build/utils.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'ts-essentials';
|
|
2
|
-
export { E as EntriesOf, K as KeysOf, V as VariantOptions, d as getEntries, g as getKeys, e as getVariantsOptions, o as objectFromEntries } from './index-
|
|
2
|
+
export { E as EntriesOf, K as KeysOf, V as VariantOptions, d as getEntries, g as getKeys, e as getVariantsOptions, o as objectFromEntries } from './index-w3SZ98rX.cjs';
|
|
3
3
|
import 'clsx';
|
package/build/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'ts-essentials';
|
|
2
|
-
export { E as EntriesOf, K as KeysOf, V as VariantOptions, d as getEntries, g as getKeys, e as getVariantsOptions, o as objectFromEntries } from './index-
|
|
2
|
+
export { E as EntriesOf, K as KeysOf, V as VariantOptions, d as getEntries, g as getKeys, e as getVariantsOptions, o as objectFromEntries } from './index-w3SZ98rX.js';
|
|
3
3
|
import 'clsx';
|
package/build/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d}from"./chunk-
|
|
1
|
+
import{a,b,c,d}from"./chunk-4HS2U3AJ.js";export{b as getEntries,a as getKeys,c as getVariantsOptions,d as objectFromEntries};
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
package/build/vue.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var D=(e,n)=>{for(var s in n)m(e,s,{get:n[s],enumerable:!0})},N=(e,n,s,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of U(n))!q.call(e,t)&&t!==s&&m(e,t,{get:()=>n[t],enumerable:!(i=E(n,t))||i.enumerable});return e};var j=e=>N(m({},"__esModule",{value:!0}),e);var A={};D(A,{cvWithProps:()=>w,getPropsDeclaration:()=>P});module.exports=j(A);var g=require("clsx");function d(e){return Object.keys(e)}function x(e){return Object.entries(e)}function h(e){return Object.fromEntries(x(e).map(([n,s])=>[n,d(s)]))}function k(e){return Object.fromEntries(e)}function M(e={}){let n=e.merge??g.clsx;return{cn:n,cv:t=>{let{base:V,variants:r,defaultVariants:p,requiredVariants:K}=t,y={variants:r??{},variantKeys:r?d(r):[],variantMap:r?h(r):{},defaultVariants:p??{},requiredVariants:K??{}},T=r?typeof t.compoundVariants=="function"?t.compoundVariants(y):t.compoundVariants:void 0;return Object.assign(f=>{let W=r?y.variantKeys.map(a=>{let u=f?.[a],l=p?.[a],c=u?.toString()||l?.toString();return c?r[a][c]:void 0}):void 0,S=T?.reduce((a,{class:u,className:l,...c})=>(x(c).every(([R,o])=>{let b=p?.[R],C=f?.[R];if(typeof o=="object"&&"__token"in o){if(o.__token===B.__token)return C!==void 0;if(o.__token===I.__token)return C===void 0}let O=C??b;return Array.isArray(o)?o.some(_=>O===_):O===o})&&a.push(u,l),a),new Array);return n(V,W,S,f?.class,f?.className)},y)},compose:(...t)=>V=>{let r={...V,class:void 0,className:void 0};return n(t.map(p=>p(r)),V?.class,V?.className)}}}var{cn:Y,cv:v,compose:Z}=M(),B={__token:"OnlyWhenDefined"},I={__token:"OnlyWhenUndefined"};function P(e){return typeof e?.variants>"u"?{}:k(d(e.variants).map(n=>[n,{type:String,required:e.requiredVariants?.[n]}]))}var w=(e,n)=>{let s=v(e,n),i=P(e);return{getClass:s,props:i}};0&&(module.exports={cvWithProps,getPropsDeclaration});
|
|
2
2
|
//# 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 { Prettify } from \"ts-essentials\";\nimport { PropType } from \"vue\";\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\nimport { getKeys, objectFromEntries } from \"./utils\";\n\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{\n [K in keyof V]: {\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\n required: K extends R ? true : false;\n };\n}>;\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n getClass: CVReturn<V, R>;\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\n}\n\nexport interface CVWithProps {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n options?: CVOptions,\n ): CVWithPropsReturn<V, R>;\n}\n\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n) {\n if (typeof config?.variants === \"undefined\") {\n return {};\n }\n\n return objectFromEntries(\n getKeys(config.variants).map(\n (key) =>\n [\n key,\n {\n type: String,\n required: config.requiredProps?.includes(key as R),\n },\n ] as const,\n ),\n );\n}\n\nexport const cvWithProps: CVWithProps = ((config, options) => {\n const getClass = cv(config, options);\n const props = getPropsDeclaration(config);\n\n return { getClass, props };\n}) as CVWithProps;\n","import { ClassValue, clsx } from \"clsx\";\nimport { MarkRequired, Prettify, StrictExclude, Opaque } from \"ts-essentials\";\nimport { getEntries, getKeys, getVariantsOptions, KeysOf, VariantOptions } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<\n Omit<NonNullable<StrictExclude<Parameters<CVR>[0], void>>, \"class\" | \"className\">\n>;\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type WithClassProp<T extends Record<string, any>> = T & ClassProp;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: {\n variants: V;\n keys: KeysOf<V>;\n options: VariantOptions<V>;\n defaults: CVVariant<V>;\n }) => CVCompoundVariantsSchema<V>);\n defaultVariant?: CVVariant<V>;\n requiredProps?: R[];\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | Prettify<WithClassProp<MarkRequired<CVVariant<V>, R>>>\n | ([R] extends [never] ? void : never);\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n (props: CVReturnProps<V, R>): string;\n keys: KeysOf<V>;\n options: VariantOptions<V>;\n defaults: CVVariant<V>;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\nexport const cv: CV = (config, cvOptions = {}) => {\n const merge = cvOptions.merge ?? clsx;\n\n const { variants, defaultVariant, base } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const keys = variants ? getKeys(variants) : [];\n const options = variants ? getVariantsOptions(variants) : ({} as VariantOptions<ResolvedV>);\n const defaults = defaultVariant ?? ({} as CVVariant<ResolvedV>);\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants({ variants, keys, options, defaults })\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? keys.map((variant) => {\n const variantProp = props?.[variant];\n const defaultVariantProp = defaultVariant?.[variant];\n\n const variantKey = variantProp?.toString() || defaultVariantProp?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariant?.[cvKey as keyof typeof defaultVariant];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return merge(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, { keys, options, defaults });\n};\n\nexport function defineCV(options: CVOptions): CV {\n return (config) => cv(config, options);\n}\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype 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","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? { [prop in key & PropertyKey]: val }\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,EAAA,wBAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAAiC,gBCI1B,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA+CC,EAAa,CACxE,OAAO,OAAO,YACVF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CACxE,CACJ,CAYO,SAASC,EAAqCC,EAAY,CAC7D,OAAO,OAAO,YAAYA,CAAO,CAGrC,CDgCO,IAAMC,EAAS,CAACC,EAAQC,EAAY,CAAC,IAAM,CAC9C,IAAMC,EAAQD,EAAU,OAAS,OAE3B,CAAE,SAAAE,EAAU,eAAAC,EAAgB,KAAAC,CAAK,EAAIL,EAIrCM,EAAOH,EAAWI,EAAQJ,CAAQ,EAAI,CAAC,EACvCK,EAAUL,EAAWM,EAAmBN,CAAQ,EAAK,CAAC,EACtDO,EAAWN,GAAmB,CAAC,EAE/BO,EAAmBR,EACnB,OAAOH,EAAO,kBAAqB,WAC/BA,EAAO,iBAAiB,CAAE,SAAAG,EAAU,KAAAG,EAAM,QAAAE,EAAS,SAAAE,CAAS,CAAC,EAC7DV,EAAO,iBACX,OAuDN,OAAO,OAAO,OApDVY,GACC,CACD,IAAMC,EAAoBV,EACpBG,EAAK,IAAKQ,GAAY,CAClB,IAAMC,EAAcH,IAAQE,CAAO,EAC7BE,EAAqBZ,IAAiBU,CAAO,EAE7CG,EAAaF,GAAa,SAAS,GAAKC,GAAoB,SAAS,EAE3E,OAAOC,EAAad,EAASW,CAAO,EAAEG,CAAU,EAAI,MACxD,CAAC,EACD,OAEAC,EAA4BP,GAAkB,OAChD,CAACQ,EAAK,CAAE,MAAOC,EAAS,UAAWC,EAAa,GAAGC,CAAS,KACrBC,EAAWD,CAAQ,EAAE,MACpD,CAAC,CAACE,EAAOC,CAAU,IAAM,CACrB,IAAMC,EACFtB,IAAiBoB,CAAoC,EACnDG,EAAgBf,IAAQY,CAA2B,EAEzD,GAAI,OAAOC,GAAe,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOjB,EACHG,EACAQ,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiC,CAAE,KAAAN,EAAM,QAAAE,EAAS,SAAAE,CAAS,CAAC,CAChE,EAYO,IAAMqB,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EDjIzD,SAASC,EACZC,EACF,CACE,OAAI,OAAOA,GAAQ,SAAa,IACrB,CAAC,EAGLC,EACHC,EAAQF,EAAO,QAAQ,EAAE,IACpBG,GACG,CACIA,EACA,CACI,KAAM,OACN,SAAUH,EAAO,eAAe,SAASG,CAAQ,CACrD,CACJ,CACR,CACJ,CACJ,CAEO,IAAMC,EAA4B,CAACJ,EAAQK,IAAY,CAC1D,IAAMC,EAAWC,EAAGP,EAAQK,CAAO,EAC7BG,EAAQT,EAAoBC,CAAM,EAExC,MAAO,CAAE,SAAAM,EAAU,MAAAE,CAAM,CAC7B","names":["vue_exports","__export","cvWithProps","getPropsDeclaration","__toCommonJS","import_clsx","getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","objectFromEntries","entries","cv","config","cvOptions","merge","variants","defaultVariant","base","keys","getKeys","options","getVariantsOptions","defaults","compoundVariants","props","variantClassNames","variant","variantProp","defaultVariantProp","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","onlyWhenDefined","onlyWhenUndefined","getPropsDeclaration","config","objectFromEntries","getKeys","key","cvWithProps","options","getClass","cv","props"]}
|
|
1
|
+
{"version":3,"sources":["../src/vue.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\nimport { PropType } from \"vue\";\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\nimport { getKeys, objectFromEntries } from \"./utils\";\n\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{\n [K in keyof V]: {\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\n required: K extends R ? true : false;\n };\n}>;\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n getClass: CVReturn<V, R>;\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\n}\n\nexport interface CVWithProps {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n options?: CVOptions,\n ): CVWithPropsReturn<V, R>;\n}\n\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n) {\n if (typeof config?.variants === \"undefined\") {\n return {};\n }\n\n return objectFromEntries(\n getKeys(config.variants).map(\n (key) =>\n [\n key,\n {\n type: String,\n required: config.requiredVariants?.[key as R],\n },\n ] as const,\n ),\n );\n}\n\nexport const cvWithProps: CVWithProps = ((config, options) => {\n const getClass = cv(config, options);\n const props = getPropsDeclaration(config);\n\n return { getClass, props };\n}) as CVWithProps;\n","import { ClassValue, clsx } from \"clsx\";\nimport {\n MarkRequired,\n Opaque,\n Prettify,\n type RequiredKeys,\n type UnionToIntersection,\n} from \"ts-essentials\";\nimport {\n getEntries,\n getKeys,\n getVariantsOptions,\n KeysOf,\n VariantOptions as VariantMap,\n} from \"./utils\";\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\nexport type WithClassProp<T extends object> = T & ClassProp;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = Prettify<\n Omit<\n UnionToIntersection<Exclude<Parameters<CVR>[0], void | null | undefined>>,\n \"class\" | \"className\"\n >\n>;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string | number, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: CVUtils<V, R>) => CVCompoundVariantsSchema<V>);\n defaultVariants?: CVVariant<V>;\n requiredVariants?: Record<R, boolean>;\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | WithClassProp<MarkRequired<CVVariant<V>, R>>\n | ([R] extends [never] ? void : never);\n\nexport interface CVUtils<V extends CVVariantsSchema, R extends keyof V = never> {\n variants: V;\n variantKeys: KeysOf<V>;\n variantMap: VariantMap<V>;\n defaultVariants: CVVariant<V>;\n requiredVariants: Record<R, boolean>;\n}\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never>\n extends CVUtils<V, R> {\n (props: CVReturnProps<V, R>): string;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype CVComposeReturnProps<T extends (props?: any) => string> =\n | WithClassProp<VariantProps<T>>\n | (RequiredKeys<VariantProps<T>> extends never ? void : never);\nexport interface CVCompose {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type, @typescript-eslint/no-explicit-any\n <T extends ((props?: any) => string)[]>(\n ...components: T\n ): (props: CVComposeReturnProps<T[number]>) => string;\n}\n\nexport function defineCV(options: CVOptions = {}) {\n const cn = options.merge ?? clsx;\n\n const cv: CV = (config) => {\n const { base, variants, defaultVariants, requiredVariants } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const utils = {\n variants: variants ?? ({} as ResolvedV),\n variantKeys: variants ? getKeys(variants) : [],\n variantMap: variants ? getVariantsOptions(variants) : ({} as VariantMap<ResolvedV>),\n defaultVariants: defaultVariants ?? ({} as CVVariant<ResolvedV>),\n requiredVariants: requiredVariants ?? ({} as Record<keyof ResolvedV, boolean>),\n };\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants(utils)\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? utils.variantKeys.map((variant) => {\n const variantProp = props?.[variant];\n const defaults = defaultVariants?.[variant];\n\n const variantKey = variantProp?.toString() || defaults?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariants?.[cvKey as keyof typeof defaultVariants];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return cn(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, utils);\n };\n\n const compose: CVCompose =\n (...components) =>\n (props) => {\n const propsWithoutClass = { ...props, class: undefined, className: undefined };\n\n return cn(\n components.map((component) => component(propsWithoutClass)),\n props?.class,\n props?.className,\n );\n };\n\n return { cn, cv, compose };\n}\n\nexport const { cn, cv, compose } = defineCV();\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype 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","import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\nimport { CVVariantsSchema } from \".\";\n\nexport type KeysOf<O extends Record<string, unknown>> = (keyof O)[];\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as KeysOf<O>;\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 VariantOptions<V extends CVVariantsSchema> = {\n [K in keyof V]: KeysOf<V[K]>;\n};\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\n return Object.fromEntries(\n getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]),\n ) as VariantOptions<V>;\n}\n\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\ntype UnionFromPairs<TArr extends Entries> =\n DeepWritable<TArr> extends (infer R)[]\n ? R extends [infer key, infer val]\n ? Record<key & PropertyKey, val>\n : never\n : never;\n\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\n\nexport function objectFromEntries<E extends Entries>(entries: E) {\n return Object.fromEntries(entries) as Prettify<\n MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>\n >;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,EAAA,wBAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAAiC,gBCI1B,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAA+CC,EAAa,CACxE,OAAO,OAAO,YACVF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAOL,EAAQM,CAAK,CAAC,CAAC,CACxE,CACJ,CAYO,SAASC,EAAqCC,EAAY,CAC7D,OAAO,OAAO,YAAYA,CAAO,CAGrC,CD0DO,SAASC,EAASC,EAAqB,CAAC,EAAG,CAC9C,IAAMC,EAAKD,EAAQ,OAAS,OAyF5B,MAAO,CAAE,GAAAC,EAAI,GAvFGC,GAAW,CACvB,GAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,gBAAAC,EAAiB,iBAAAC,CAAiB,EAAIJ,EAIxDK,EAAQ,CACV,SAAUH,GAAa,CAAC,EACxB,YAAaA,EAAWI,EAAQJ,CAAQ,EAAI,CAAC,EAC7C,WAAYA,EAAWK,EAAmBL,CAAQ,EAAK,CAAC,EACxD,gBAAiBC,GAAoB,CAAC,EACtC,iBAAkBC,GAAqB,CAAC,CAC5C,EAEMI,EAAmBN,EACnB,OAAOF,EAAO,kBAAqB,WAC/BA,EAAO,iBAAiBK,CAAK,EAC7BL,EAAO,iBACX,OAuDN,OAAO,OAAO,OApDVS,GACC,CACD,IAAMC,EAAoBR,EACpBG,EAAM,YAAY,IAAKM,GAAY,CAC/B,IAAMC,EAAcH,IAAQE,CAAO,EAC7BE,EAAWV,IAAkBQ,CAAO,EAEpCG,EAAaF,GAAa,SAAS,GAAKC,GAAU,SAAS,EAEjE,OAAOC,EAAaZ,EAASS,CAAO,EAAEG,CAAU,EAAI,MACxD,CAAC,EACD,OAEAC,EAA4BP,GAAkB,OAChD,CAACQ,EAAK,CAAE,MAAOC,EAAS,UAAWC,EAAa,GAAGC,CAAS,KACrBC,EAAWD,CAAQ,EAAE,MACpD,CAAC,CAACE,EAAOC,CAAU,IAAM,CACrB,IAAMC,EACFpB,IAAkBkB,CAAqC,EACrDG,EAAgBf,IAAQY,CAA2B,EAEzD,GAAI,OAAOC,GAAe,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOjB,EACHE,EACAS,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiCJ,CAAK,CAC1C,EAciB,QAXb,IAAIuB,IACHnB,GAAU,CACP,IAAMoB,EAAoB,CAAE,GAAGpB,EAAO,MAAO,OAAW,UAAW,MAAU,EAE7E,OAAOV,EACH6B,EAAW,IAAKE,GAAcA,EAAUD,CAAiB,CAAC,EAC1DpB,GAAO,MACPA,GAAO,SACX,CACJ,CAEqB,CAC7B,CAEO,GAAM,CAAE,GAAAV,EAAI,GAAAgC,EAAI,QAAAC,CAAQ,EAAInC,EAAS,EAQ/B4B,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,ED7KzD,SAASO,EACZC,EACF,CACE,OAAI,OAAOA,GAAQ,SAAa,IACrB,CAAC,EAGLC,EACHC,EAAQF,EAAO,QAAQ,EAAE,IACpBG,GACG,CACIA,EACA,CACI,KAAM,OACN,SAAUH,EAAO,mBAAmBG,CAAQ,CAChD,CACJ,CACR,CACJ,CACJ,CAEO,IAAMC,EAA4B,CAACJ,EAAQK,IAAY,CAC1D,IAAMC,EAAWC,EAAGP,EAAQK,CAAO,EAC7BG,EAAQT,EAAoBC,CAAM,EAExC,MAAO,CAAE,SAAAM,EAAU,MAAAE,CAAM,CAC7B","names":["vue_exports","__export","cvWithProps","getPropsDeclaration","__toCommonJS","import_clsx","getKeys","obj","getEntries","getVariantsOptions","variants","cvKey","cvVal","objectFromEntries","entries","defineCV","options","cn","config","base","variants","defaultVariants","requiredVariants","utils","getKeys","getVariantsOptions","compoundVariants","props","variantClassNames","variant","variantProp","defaults","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","components","propsWithoutClass","component","cv","compose","getPropsDeclaration","config","objectFromEntries","getKeys","key","cvWithProps","options","getClass","cv","props"]}
|
package/build/vue.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Prettify } from 'ts-essentials';
|
|
2
2
|
import { PropType } from 'vue';
|
|
3
|
-
import { C as CVVariantsSchema, a as CVReturn, b as CVConfig, c as CVOptions } from './index-
|
|
3
|
+
import { C as CVVariantsSchema, a as CVReturn, b as CVConfig, c as CVOptions } from './index-w3SZ98rX.cjs';
|
|
4
4
|
import 'clsx';
|
|
5
5
|
|
|
6
6
|
type PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{
|
package/build/vue.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Prettify } from 'ts-essentials';
|
|
2
2
|
import { PropType } from 'vue';
|
|
3
|
-
import { C as CVVariantsSchema, a as CVReturn, b as CVConfig, c as CVOptions } from './index-
|
|
3
|
+
import { C as CVVariantsSchema, a as CVReturn, b as CVConfig, c as CVOptions } from './index-w3SZ98rX.js';
|
|
4
4
|
import 'clsx';
|
|
5
5
|
|
|
6
6
|
type PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{
|
package/build/vue.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{c as o}from"./chunk-IW3RSJHX.js";import{a as r,d as n}from"./chunk-4HS2U3AJ.js";function V(e){return typeof e?.variants>"u"?{}:n(r(e.variants).map(t=>[t,{type:String,required:e.requiredVariants?.[t]}]))}var R=(e,t)=>{let s=o(e,t),i=V(e);return{getClass:s,props:i}};export{R as cvWithProps,V as getPropsDeclaration};
|
|
2
2
|
//# sourceMappingURL=vue.js.map
|
package/build/vue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\nimport { PropType } from \"vue\";\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\nimport { getKeys, objectFromEntries } from \"./utils\";\n\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{\n [K in keyof V]: {\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\n required: K extends R ? true : false;\n };\n}>;\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n getClass: CVReturn<V, R>;\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\n}\n\nexport interface CVWithProps {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n options?: CVOptions,\n ): CVWithPropsReturn<V, R>;\n}\n\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n) {\n if (typeof config?.variants === \"undefined\") {\n return {};\n }\n\n return objectFromEntries(\n getKeys(config.variants).map(\n (key) =>\n [\n key,\n {\n type: String,\n required: config.
|
|
1
|
+
{"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\nimport { PropType } from \"vue\";\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\nimport { getKeys, objectFromEntries } from \"./utils\";\n\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{\n [K in keyof V]: {\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\n required: K extends R ? true : false;\n };\n}>;\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n getClass: CVReturn<V, R>;\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\n}\n\nexport interface CVWithProps {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n options?: CVOptions,\n ): CVWithPropsReturn<V, R>;\n}\n\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n) {\n if (typeof config?.variants === \"undefined\") {\n return {};\n }\n\n return objectFromEntries(\n getKeys(config.variants).map(\n (key) =>\n [\n key,\n {\n type: String,\n required: config.requiredVariants?.[key as R],\n },\n ] as const,\n ),\n );\n}\n\nexport const cvWithProps: CVWithProps = ((config, options) => {\n const getClass = cv(config, options);\n const props = getPropsDeclaration(config);\n\n return { getClass, props };\n}) as CVWithProps;\n"],"mappings":"uFAwBO,SAASA,EACZC,EACF,CACE,OAAI,OAAOA,GAAQ,SAAa,IACrB,CAAC,EAGLC,EACHC,EAAQF,EAAO,QAAQ,EAAE,IACpBG,GACG,CACIA,EACA,CACI,KAAM,OACN,SAAUH,EAAO,mBAAmBG,CAAQ,CAChD,CACJ,CACR,CACJ,CACJ,CAEO,IAAMC,EAA4B,CAACJ,EAAQK,IAAY,CAC1D,IAAMC,EAAWC,EAAGP,EAAQK,CAAO,EAC7BG,EAAQT,EAAoBC,CAAM,EAExC,MAAO,CAAE,SAAAM,EAAU,MAAAE,CAAM,CAC7B","names":["getPropsDeclaration","config","objectFromEntries","getKeys","key","cvWithProps","options","getClass","cv","props"]}
|
package/package.json
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@yaredfall/class-variants",
|
|
3
|
+
"author": "yaredfall",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"version": "0.4.0-rc",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"files": [
|
|
11
|
+
"build"
|
|
12
|
+
],
|
|
13
|
+
"main": "build/index.cjs",
|
|
14
|
+
"module": "build/index.js",
|
|
15
|
+
"types": "build/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./build/index.d.ts",
|
|
20
|
+
"default": "./build/index.js"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./build/index.d.cts",
|
|
24
|
+
"default": "./build/index.cjs"
|
|
25
|
+
}
|
|
7
26
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"build"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
".": {
|
|
18
|
-
"import": {
|
|
19
|
-
"types": "./build/index.d.ts",
|
|
20
|
-
"default": "./build/index.js"
|
|
21
|
-
},
|
|
22
|
-
"require": {
|
|
23
|
-
"types": "./build/index.d.cts",
|
|
24
|
-
"default": "./build/index.cjs"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"./utils": {
|
|
28
|
-
"import": {
|
|
29
|
-
"types": "./build/utils.d.ts",
|
|
30
|
-
"default": "./build/utils.js"
|
|
31
|
-
},
|
|
32
|
-
"require": {
|
|
33
|
-
"types": "./build/utils.d.cts",
|
|
34
|
-
"default": "./build/utils.cjs"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"./vue": {
|
|
38
|
-
"import": {
|
|
39
|
-
"types": "./build/vue.d.ts",
|
|
40
|
-
"default": "./build/vue.js"
|
|
41
|
-
},
|
|
42
|
-
"require": {
|
|
43
|
-
"types": "./build/vue.d.cts",
|
|
44
|
-
"default": "./build/vue.cjs"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"./package.json": "./package.json"
|
|
27
|
+
"./utils": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./build/utils.d.ts",
|
|
30
|
+
"default": "./build/utils.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./build/utils.d.cts",
|
|
34
|
+
"default": "./build/utils.cjs"
|
|
35
|
+
}
|
|
48
36
|
},
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
"
|
|
37
|
+
"./vue": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./build/vue.d.ts",
|
|
40
|
+
"default": "./build/vue.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./build/vue.d.cts",
|
|
44
|
+
"default": "./build/vue.cjs"
|
|
45
|
+
}
|
|
52
46
|
},
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"tsup": "^8.5.0",
|
|
51
|
+
"typescript": "^5.8.3",
|
|
52
|
+
"vue": "^3.5.16"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"clsx": "^2.1.1"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc && tsup"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/build/chunk-4SXOWWRN.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as c,b as m,c as x}from"./chunk-BV75ULQK.js";import{clsx as v}from"clsx";var S=(t,r={})=>{let h=r.merge??v,{variants:e,defaultVariant:V,base:k}=t,i=e?c(e):[],f=e?x(e):{},u=V??{},R=e?typeof t.compoundVariants=="function"?t.compoundVariants({variants:e,keys:i,options:f,defaults:u}):t.compoundVariants:void 0;return Object.assign(s=>{let O=e?i.map(a=>{let d=s?.[a],p=V?.[a],o=d?.toString()||p?.toString();return o?e[a][o]:void 0}):void 0,g=R?.reduce((a,{class:d,className:p,...o})=>(m(o).every(([y,n])=>{let _=V?.[y],l=s?.[y];if(typeof n=="object"&&"__token"in n){if(n.__token===W.__token)return l!==void 0;if(n.__token===N.__token)return l===void 0}let C=l??_;return Array.isArray(n)?n.some(P=>C===P):C===n})&&a.push(d,p),a),new Array);return h(k,O,g,s?.class,s?.className)},{keys:i,options:f,defaults:u})};function A(t){return r=>S(r,t)}var W={__token:"OnlyWhenDefined"},N={__token:"OnlyWhenUndefined"};export{S as a,A as b,W as c,N as d};
|
|
2
|
-
//# sourceMappingURL=chunk-4SXOWWRN.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\nimport { MarkRequired, Prettify, StrictExclude, Opaque } from \"ts-essentials\";\nimport { getEntries, getKeys, getVariantsOptions, KeysOf, VariantOptions } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<\n Omit<NonNullable<StrictExclude<Parameters<CVR>[0], void>>, \"class\" | \"className\">\n>;\n\ntype ClassProp =\n | { class?: ClassValue; className?: never }\n | { class?: never; className?: ClassValue };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type WithClassProp<T extends Record<string, any>> = T & ClassProp;\n\ntype BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\n\nexport type CVVariant<V extends CVVariantsSchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K]>;\n};\nexport type CVCompoundVariant<V extends CVVariantsSchema> = WithClassProp<{\n [K in keyof V]?:\n | BooleanStringToBoolean<keyof V[K]>\n | BooleanStringToBoolean<keyof V[K]>[]\n | CVToken;\n}>;\n\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = CVCompoundVariant<V>[];\n\nexport interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {\n base?: ClassValue;\n variants?: V;\n compoundVariants?:\n | CVCompoundVariantsSchema<V>\n | ((arg: {\n variants: V;\n keys: KeysOf<V>;\n options: VariantOptions<V>;\n defaults: CVVariant<V>;\n }) => CVCompoundVariantsSchema<V>);\n defaultVariant?: CVVariant<V>;\n requiredProps?: R[];\n}\nexport interface CVOptions {\n merge?: (...args: ClassValue[]) => string;\n}\n\ntype CVReturnProps<V extends CVVariantsSchema, R extends keyof V = never> =\n | Prettify<WithClassProp<MarkRequired<CVVariant<V>, R>>>\n | ([R] extends [never] ? void : never);\nexport interface CVReturn<V extends CVVariantsSchema, R extends keyof V = never> {\n (props: CVReturnProps<V, R>): string;\n keys: KeysOf<V>;\n options: VariantOptions<V>;\n defaults: CVVariant<V>;\n}\n\nexport interface CV {\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\n <V extends CVVariantsSchema, R extends keyof V = never>(\n config: CVConfig<V, R>,\n cvOptions?: CVOptions,\n ): CVReturn<V, R>;\n}\n\nexport const cv: CV = (config, cvOptions = {}) => {\n const merge = cvOptions.merge ?? clsx;\n\n const { variants, defaultVariant, base } = config;\n\n type ResolvedV = NonNullable<typeof variants>;\n\n const keys = variants ? getKeys(variants) : [];\n const options = variants ? getVariantsOptions(variants) : ({} as VariantOptions<ResolvedV>);\n const defaults = defaultVariant ?? ({} as CVVariant<ResolvedV>);\n\n const compoundVariants = variants\n ? typeof config.compoundVariants === \"function\"\n ? config.compoundVariants({ variants, keys, options, defaults })\n : config.compoundVariants\n : undefined;\n\n const getVariant = <V extends ResolvedV, R extends keyof V = never>(\n props: CVReturnProps<V, R>,\n ) => {\n const variantClassNames = variants\n ? keys.map((variant) => {\n const variantProp = props?.[variant];\n const defaultVariantProp = defaultVariant?.[variant];\n\n const variantKey = variantProp?.toString() || defaultVariantProp?.toString();\n\n return variantKey ? variants[variant][variantKey] : undefined;\n })\n : undefined;\n\n const compoundVariantClassNames = compoundVariants?.reduce(\n (acc, { class: cvClass, className: cvClassName, ...cvConfig }) => {\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(\n ([cvKey, cvSelector]) => {\n const defaultsSelector =\n defaultVariant?.[cvKey as keyof typeof defaultVariant];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (typeof cvSelector === \"object\" && \"__token\" in cvSelector) {\n if (cvSelector.__token === onlyWhenDefined.__token) {\n return propsSelector !== undefined;\n } else if (cvSelector.__token === onlyWhenUndefined.__token) {\n return propsSelector === undefined;\n }\n }\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => selector === cvSelector)\n : selector === cvSelector;\n },\n );\n\n if (shouldApplyCompoundVariant) acc.push(cvClass, cvClassName);\n return acc;\n },\n new Array<ClassValue>(),\n );\n\n return merge(\n base,\n variantClassNames,\n compoundVariantClassNames,\n props?.class,\n props?.className,\n );\n };\n\n return Object.assign(getVariant, { keys, options, defaults });\n};\n\nexport function defineCV(options: CVOptions): CV {\n return (config) => cv(config, options);\n}\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\ntype 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"],"mappings":"sDAAA,OAAqB,QAAAA,MAAY,OAoE1B,IAAMC,EAAS,CAACC,EAAQC,EAAY,CAAC,IAAM,CAC9C,IAAMC,EAAQD,EAAU,OAASE,EAE3B,CAAE,SAAAC,EAAU,eAAAC,EAAgB,KAAAC,CAAK,EAAIN,EAIrCO,EAAOH,EAAWI,EAAQJ,CAAQ,EAAI,CAAC,EACvCK,EAAUL,EAAWM,EAAmBN,CAAQ,EAAK,CAAC,EACtDO,EAAWN,GAAmB,CAAC,EAE/BO,EAAmBR,EACnB,OAAOJ,EAAO,kBAAqB,WAC/BA,EAAO,iBAAiB,CAAE,SAAAI,EAAU,KAAAG,EAAM,QAAAE,EAAS,SAAAE,CAAS,CAAC,EAC7DX,EAAO,iBACX,OAuDN,OAAO,OAAO,OApDVa,GACC,CACD,IAAMC,EAAoBV,EACpBG,EAAK,IAAKQ,GAAY,CAClB,IAAMC,EAAcH,IAAQE,CAAO,EAC7BE,EAAqBZ,IAAiBU,CAAO,EAE7CG,EAAaF,GAAa,SAAS,GAAKC,GAAoB,SAAS,EAE3E,OAAOC,EAAad,EAASW,CAAO,EAAEG,CAAU,EAAI,MACxD,CAAC,EACD,OAEAC,EAA4BP,GAAkB,OAChD,CAACQ,EAAK,CAAE,MAAOC,EAAS,UAAWC,EAAa,GAAGC,CAAS,KACrBC,EAAWD,CAAQ,EAAE,MACpD,CAAC,CAACE,EAAOC,CAAU,IAAM,CACrB,IAAMC,EACFtB,IAAiBoB,CAAoC,EACnDG,EAAgBf,IAAQY,CAA2B,EAEzD,GAAI,OAAOC,GAAe,UAAY,YAAaA,EAAY,CAC3D,GAAIA,EAAW,UAAYG,EAAgB,QACvC,OAAOD,IAAkB,OACtB,GAAIF,EAAW,UAAYI,EAAkB,QAChD,OAAOF,IAAkB,MAEjC,CAEA,IAAMG,EAAWH,GAAiBD,EAElC,OAAO,MAAM,QAAQD,CAAU,EACzBA,EAAW,KAAMA,GAAeK,IAAaL,CAAU,EACvDK,IAAaL,CACvB,CACJ,GAEgCN,EAAI,KAAKC,EAASC,CAAW,EACtDF,GAEX,IAAI,KACR,EAEA,OAAOlB,EACHI,EACAQ,EACAK,EACAN,GAAO,MACPA,GAAO,SACX,CACJ,EAEiC,CAAE,KAAAN,EAAM,QAAAE,EAAS,SAAAE,CAAS,CAAC,CAChE,EAEO,SAASqB,EAASvB,EAAwB,CAC7C,OAAQT,GAAWD,EAAGC,EAAQS,CAAO,CACzC,CAQO,IAAMoB,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB","names":["clsx","cv","config","cvOptions","merge","clsx","variants","defaultVariant","base","keys","getKeys","options","getVariantsOptions","defaults","compoundVariants","props","variantClassNames","variant","variantProp","defaultVariantProp","variantKey","compoundVariantClassNames","acc","cvClass","cvClassName","cvConfig","getEntries","cvKey","cvSelector","defaultsSelector","propsSelector","onlyWhenDefined","onlyWhenUndefined","selector","defineCV"]}
|