@yaredfall/class-variants 0.6.3 → 0.6.5

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.
@@ -0,0 +1,2 @@
1
+ import{c as r}from"./chunk-KFWDEJ5D.js";function m({cn:s,cv:i}){let o=(V,t)=>{let a=structuredClone(V);for(let e in t){a[e]??(a[e]={});for(let n in t[e])a[e][n]=s(V[e]?.[n],t[e][n])}return a};return(V,t)=>{let{config:a}=V;return i({base:s(a.base,t.base),variants:o(a.variants,t.variants),compoundVariants:e=>r(a.compoundVariants,V).concat(r(t.compoundVariants??[],e)),defaultVariants:{...a.defaultVariants,...t.defaultVariants}})}}export{m as a};
2
+ //# sourceMappingURL=chunk-IUIPT6RZ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/extend.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n"],"mappings":"wCAyCO,SAASA,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAiBC,CAAG,IAAM,CAAC,EAC3B,QAAWC,KAAWH,EAAYE,CAAG,EACjCD,EAAiBC,CAAG,EAAEC,CAAO,EAAIP,EAAGG,EAASG,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ","names":["_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}
1
+ {"version":3,"sources":["../src/extend.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n"],"mappings":"wCAyCO,SAASA,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAAC,KAAAD,EAAAC,GAA0B,CAAC,GAC3B,QAAWC,KAAWH,EAAYE,CAAG,EACjCD,EAAiBC,CAAG,EAAEC,CAAO,EAAIP,EAAGG,EAASG,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ","names":["_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}
@@ -1,2 +1,2 @@
1
- import{a as e}from"./chunk-O5WYIZI3.js";import{a as i}from"./chunk-WMIMBE4W.js";import{a as o}from"./chunk-KFWDEJ5D.js";function m({merge:r}={}){let n=e({merge:r}),t=o({cn:n}),c=i({cn:n,cv:t});return{cn:n,cv:t,extend:c}}export{m as a};
2
- //# sourceMappingURL=chunk-MV6NY2DZ.js.map
1
+ import{a as e}from"./chunk-O5WYIZI3.js";import{a as i}from"./chunk-IUIPT6RZ.js";import{a as o}from"./chunk-KFWDEJ5D.js";function m({merge:r}={}){let n=e({merge:r}),t=o({cn:n}),c=i({cn:n,cv:t});return{cn:n,cv:t,extend:c}}export{m as a};
2
+ //# sourceMappingURL=chunk-N6TNUPPW.js.map
@@ -1,7 +1,19 @@
1
1
  import { ClassValue } from 'clsx';
2
- import { Opaque, Prettify, ArrayOrSingle } from 'ts-essentials';
3
2
  import { CN } from './cn.js';
4
3
 
4
+ type StringLiteral<Type> = Type extends string ? (string extends Type ? never : Type) : never;
5
+ declare const __OPAQUE_TYPE__: unique symbol;
6
+ type WithOpaque<Token extends string> = {
7
+ readonly [__OPAQUE_TYPE__]: Token;
8
+ };
9
+ type Opaque<Type, Token extends string> = Token extends StringLiteral<Token> ? Type & WithOpaque<Token> : never;
10
+
11
+ type Prettify<Type> = Type extends Function ? Type : Extract<{
12
+ [Key in keyof Type]: Type[Key];
13
+ }, Type>;
14
+
15
+ type ArrayOrSingle<Type> = Type | Type[];
16
+
5
17
  type OnlyWhenDefined = Opaque<{
6
18
  __token: string;
7
19
  }, "OnlyWhenDefined">;
@@ -76,4 +88,4 @@ type CVPropsValue = VariantKey | boolean | undefined;
76
88
  declare function resolveConfig<V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
77
89
  declare function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CompoundVariantsSchema<V>;
78
90
 
79
- export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantsSchema as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type VariantProps as h, type Variant as i, type CompoundVariantsSchemaFunction as j, isCVToken as k, getKeys as l, getEntries as m, type VariantMap as n, onlyWhenDefined as o, getVariantMap as p, splitProps as q, cvUtils as r, shouldApplySelectorByToken as s, type VariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
91
+ export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type Prettify as P, type ResolvedCVConfig as R, type VariantsSchema as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type VariantProps as h, type Variant as i, type CompoundVariantsSchemaFunction as j, isCVToken as k, getKeys as l, getEntries as m, type VariantMap as n, onlyWhenDefined as o, getVariantMap as p, splitProps as q, cvUtils as r, shouldApplySelectorByToken as s, type VariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
package/build/cv.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import 'clsx';
2
- import 'ts-essentials';
2
+ export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-96SI2TYA.js';
3
3
  import './cn.js';
4
- export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-CxGrT76R.js';
package/build/define.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { CVExtend } from './extend.js';
2
- import { C as CV } from './cv-CxGrT76R.js';
2
+ import { C as CV } from './cv-96SI2TYA.js';
3
3
  import { CNOptions, CN } from './cn.js';
4
4
  import 'clsx';
5
- import 'ts-essentials';
5
+ import '../prettify';
6
6
 
7
7
  interface DefineCVOptions extends CNOptions {
8
8
  }
package/build/define.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-MV6NY2DZ.js";import"./chunk-O5WYIZI3.js";import"./chunk-WMIMBE4W.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as defineCV};
1
+ import{a}from"./chunk-N6TNUPPW.js";import"./chunk-O5WYIZI3.js";import"./chunk-IUIPT6RZ.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as defineCV};
2
2
  //# sourceMappingURL=define.js.map
package/build/extend.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { ClassValue } from 'clsx';
2
- import { Merge, Prettify } from 'ts-essentials';
2
+ import { Prettify } from '../prettify';
3
+ import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, P as Prettify$1, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-96SI2TYA.js';
3
4
  import { CN } from './cn.js';
4
- import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-CxGrT76R.js';
5
5
 
6
- type MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
6
+ type Merge<Object1, Object2> = Prettify<Omit<Object1, keyof Object2> & Object2>;
7
+
8
+ type MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify$1<Record<keyof V1 | keyof V2, ClassValue>>;
7
9
  type MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<V1 & V2, {
8
10
  [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;
9
11
  }>;
package/build/extend.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a}from"./chunk-WMIMBE4W.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _extend};
1
+ import{a}from"./chunk-IUIPT6RZ.js";import"./chunk-KFWDEJ5D.js";import"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";export{a as _extend};
2
2
  //# sourceMappingURL=extend.js.map
package/build/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { CN } from './cn.js';
2
- import { C as CV } from './cv-CxGrT76R.js';
3
- export { b as CVCompoundVariant, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, c as CompoundVariantsSchema, h as VariantProps, V as VariantsSchema, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-CxGrT76R.js';
2
+ import { C as CV } from './cv-96SI2TYA.js';
3
+ export { b as CVCompoundVariant, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, c as CompoundVariantsSchema, h as VariantProps, V as VariantsSchema, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-96SI2TYA.js';
4
4
  export { defineCV } from './define.js';
5
5
  import { CVExtend } from './extend.js';
6
6
  import 'clsx';
7
- import 'ts-essentials';
7
+ import '../prettify';
8
8
 
9
9
  declare const cn: CN;
10
10
  declare const cv: CV;
package/build/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as t}from"./chunk-MV6NY2DZ.js";import"./chunk-O5WYIZI3.js";import"./chunk-WMIMBE4W.js";import"./chunk-KFWDEJ5D.js";import{a as n,b as o}from"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";var{cn:V,cv:a,extend:i}=t();export{V as cn,a as cv,t as defineCV,i as extend,n as onlyWhenDefined,o as onlyWhenUndefined};
1
+ import{a as t}from"./chunk-N6TNUPPW.js";import"./chunk-O5WYIZI3.js";import"./chunk-IUIPT6RZ.js";import"./chunk-KFWDEJ5D.js";import{a as n,b as o}from"./chunk-N3ZCNVFV.js";import"./chunk-SJ6AQKOA.js";var{cn:V,cv:a,extend:i}=t();export{V as cn,a as cv,t as defineCV,i as extend,n as onlyWhenDefined,o as onlyWhenUndefined};
2
2
  //# sourceMappingURL=index.js.map
package/build/tokens.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import 'ts-essentials';
2
- export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-CxGrT76R.js';
1
+ export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-96SI2TYA.js';
3
2
  import 'clsx';
4
3
  import './cn.js';
package/build/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import 'ts-essentials';
2
- export { f as CVUtils, E as EntriesOf, n as VariantMap, r as cvUtils, m as getEntries, l as getKeys, p as getVariantMap, q as splitProps } from './cv-CxGrT76R.js';
1
+ export { f as CVUtils, E as EntriesOf, n as VariantMap, r as cvUtils, m as getEntries, l as getKeys, p as getVariantMap, q as splitProps } from './cv-96SI2TYA.js';
3
2
  import 'clsx';
4
3
  import './cn.js';
package/build/vue.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { PropType } from 'vue';
2
- import { V as VariantsSchema, d as CVReturn } from './cv-CxGrT76R.js';
2
+ import { V as VariantsSchema, d as CVReturn } from './cv-96SI2TYA.js';
3
3
  import 'clsx';
4
- import 'ts-essentials';
5
4
  import './cn.js';
6
5
 
7
6
  declare function getPropsDeclaration<V extends VariantsSchema>(cv: CVReturn<V>): { [K in keyof V]: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaredfall/class-variants",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "private": false,
5
5
  "author": "yaredfall",
6
6
  "type": "module",
@@ -47,10 +47,10 @@
47
47
  "clsx": "^2.1.1"
48
48
  },
49
49
  "devDependencies": {
50
- "ts-essentials": "^10.1.1",
51
50
  "tsup": "^8.5.0",
52
51
  "typescript": "^5.8.3",
53
- "vue": "^3.5.16"
52
+ "vue": "^3.5.16",
53
+ "ts-essentials": "^10.0.0"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -1,2 +0,0 @@
1
- import{c as r}from"./chunk-KFWDEJ5D.js";function m({cn:s,cv:i}){let o=(V,a)=>{let e=structuredClone(V);for(let t in a){e[t]??={};for(let n in a[t])e[t][n]=s(V[t]?.[n],a[t][n])}return e};return(V,a)=>{let{config:e}=V;return i({base:s(e.base,a.base),variants:o(e.variants,a.variants),compoundVariants:t=>r(e.compoundVariants,V).concat(r(a.compoundVariants??[],t)),defaultVariants:{...e.defaultVariants,...a.defaultVariants}})}}export{m as a};
2
- //# sourceMappingURL=chunk-WMIMBE4W.js.map
package/build/cn.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var p=Object.create;var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})},a=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of l(e))!u.call(t,s)&&s!==r&&n(t,s,{get:()=>e[s],enumerable:!(i=c(e,s))||i.enumerable});return t};var f=(t,e,r)=>(r=t!=null?p(C(t)):{},a(e||!t||!t.__esModule?n(r,"default",{value:t,enumerable:!0}):r,t)),g=t=>a(n({},"__esModule",{value:!0}),t);var x={};N(x,{_cn:()=>m});module.exports=g(x);var o=f(require("clsx"),1);function m({merge:t=e=>e}){return(...e)=>t((0,o.default)(...e))}0&&(module.exports={_cn});
2
- //# sourceMappingURL=cn.cjs.map
package/build/cn.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cn.ts"],"sourcesContent":["import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsC,qBAU/B,SAASF,EAAI,CAAE,MAAAG,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,KAAM,EAAAG,SAAK,GAAGD,CAAM,CAAC,CAC/C","names":["cn_exports","__export","_cn","__toCommonJS","import_clsx","merge","className","inputs","clsx"]}
package/build/cn.d.cts DELETED
@@ -1,11 +0,0 @@
1
- import { ClassValue } from 'clsx';
2
-
3
- interface CNOptions {
4
- merge?: (className: string) => string;
5
- }
6
- interface CN {
7
- (...inputs: ClassValue[]): string;
8
- }
9
- declare function _cn({ merge }: CNOptions): CN;
10
-
11
- export { type CN, type CNOptions, _cn };
@@ -1,79 +0,0 @@
1
- import { ClassValue } from 'clsx';
2
- import { Opaque, Prettify, ArrayOrSingle } from 'ts-essentials';
3
- import { CN } from './cn.cjs';
4
-
5
- type OnlyWhenDefined = Opaque<{
6
- __token: string;
7
- }, "OnlyWhenDefined">;
8
- type OnlyWhenUndefined = Opaque<{
9
- __token: string;
10
- }, "OnlyWhenUndefined">;
11
- type CVToken = OnlyWhenDefined | OnlyWhenUndefined;
12
- /** Apply compound variant only if prop **is** specified */
13
- declare const onlyWhenDefined: OnlyWhenDefined;
14
- /** Apply compound variant only if prop **is not** specified */
15
- declare const onlyWhenUndefined: OnlyWhenUndefined;
16
- declare function isCVToken(token: unknown): token is CVToken;
17
- declare function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue): boolean;
18
-
19
- declare function getKeys<O extends Record<string, unknown>>(obj: O): (keyof O & VariantKey)[];
20
- type EntriesOf<O extends Record<string, unknown>> = {
21
- [K in keyof O]: [K, O[K]];
22
- };
23
- declare function getEntries<O extends Record<string, unknown>>(obj: O): EntriesOf<O>[keyof EntriesOf<O>][];
24
- type VariantMap<V extends VariantsSchema> = {
25
- [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];
26
- };
27
- declare function getVariantMap<V extends VariantsSchema>(variants: V): VariantMap<V>;
28
- declare function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean): readonly [Partial<Record<keyof TProps, unknown>>, Partial<Record<keyof TProps, unknown>>];
29
- interface CVUtils<V extends VariantsSchema> {
30
- variantKeys: (keyof V & string)[];
31
- variantMap: Prettify<VariantMap<V>>;
32
- splitVariantProps: <TProps extends CVReturnProps<V>>(props?: TProps) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];
33
- getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;
34
- }
35
- declare function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V>;
36
-
37
- type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;
38
- type BooleanStringToBoolean<T> = T extends "true" | "false" ? boolean : T;
39
- type VariantKey = string | number;
40
- type Variant = Record<VariantKey, ClassValue>;
41
- type VariantsSchema = Record<string, Variant>;
42
- type EmptySchema = Record<never, never>;
43
- type CVVariant<V extends VariantsSchema = EmptySchema> = {
44
- [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;
45
- };
46
- type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;
47
- type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {
48
- [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;
49
- } & {
50
- class: ClassValue;
51
- };
52
- type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];
53
- type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (utils: CVUtils<V>) => CompoundVariantsSchema<V>;
54
- interface CVConfig<V extends VariantsSchema = EmptySchema> {
55
- base: ClassValue;
56
- variants: V;
57
- compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;
58
- defaultVariants: CVVariant<V>;
59
- }
60
- interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {
61
- compoundVariants: CompoundVariantsSchema<V>;
62
- }
63
- type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;
64
- interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {
65
- (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;
66
- config: ResolvedCVConfig<V>;
67
- }
68
- interface CV {
69
- <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;
70
- }
71
- interface CVOptions {
72
- cn: CN;
73
- }
74
- declare function _cv(options: CVOptions): CV;
75
- type CVPropsValue = VariantKey | boolean | undefined;
76
- declare function resolveConfig<V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): [ResolvedCVConfig<V>, CVUtils<V>];
77
- declare function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(compoundVariants: CVConfig<V>["compoundVariants"], utils: CVUtils<V>): CompoundVariantsSchema<V>;
78
-
79
- export { type BooleanStringToBoolean as B, type CV as C, type EntriesOf as E, type ResolvedCVConfig as R, type VariantsSchema as V, _cv as _, onlyWhenUndefined as a, type CVCompoundVariant as b, type CompoundVariantsSchema as c, type CVReturn as d, type CVToken as e, type CVUtils as f, type CVVariant as g, type VariantProps as h, type Variant as i, type CompoundVariantsSchemaFunction as j, isCVToken as k, getKeys as l, getEntries as m, type VariantMap as n, onlyWhenDefined as o, getVariantMap as p, splitProps as q, cvUtils as r, shouldApplySelectorByToken as s, type VariantKey as t, type CVProps as u, type CVConfig as v, type CVReturnProps as w, type CVPropsValue as x, resolveConfig as y, resolveCompoundVariants as z };
package/build/cv.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var l=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var v=(e,n)=>{for(var t in n)l(e,t,{get:n[t],enumerable:!0})},E=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of R(n))!T.call(e,r)&&r!==t&&l(e,r,{get:()=>n[r],enumerable:!(o=O(n,r))||o.enumerable});return e};var K=e=>E(l({},"__esModule",{value:!0}),e);var w={};v(w,{_cv:()=>A,resolveCompoundVariants:()=>g,resolveConfig:()=>P});module.exports=K(w);var U={__token:"OnlyWhenDefined"},_={__token:"OnlyWhenUndefined"};function y(e){return e?typeof e=="object"&&"__token"in e:!1}function d(e,n){return e.__token===n.__token}function m(e,n){return d(e,U)?n!==void 0:d(e,_)?n===void 0:!1}function x(e){return Object.keys(e)}function b(e){return Object.entries(e)}function B(e){return Object.fromEntries(b(e).map(([n,t])=>[n,x(t)]))}function W(e,n){let t={},o={};if(!e)return[t,o];for(let r in e){let a=r;n(a)?t[a]=e[a]:o[a]=e[a]}return[t,o]}function h(e){let n=x(e.variants),t=B(e.variants);return{variantKeys:n,variantMap:t,splitVariantProps:a=>W(a,s=>s in t),getVariantProps:a=>{let s=structuredClone(e.defaultVariants);for(let i in a)a[i]!==void 0&&(s[i]=a[i]);return s}}}function A(e){return n=>{let[t,o]=P(n),{base:r,variants:a,compoundVariants:s,defaultVariants:i}=t,f=p=>{let c=o.getVariantProps(p),V=new Array;for(let u in a){let C=c[u]?.toString();C&&V.push(a?.[u]?.[C])}return V},k=p=>s?.reduce((c,V)=>(j(p,V,i)&&c.push(V.class),c),new Array);return Object.assign(Object.assign((p,...c)=>{let V=f(p),u=k(p);return e.cn(r,V,u,...c)},o),{config:t})}}function j(e,n,t){return Object.keys(n).every(o=>{if(o==="class")return!0;let r=n[o],a=t?.[o],s=e?.[o];if(y(r))return m(r,s);let i=s??a;return Array.isArray(r)?r.some(f=>S(i,f)):S(i,r)})}function S(e,n){return e?.toString()===n?.toString()}function P(e){let n={variants:{},compoundVariants:[],defaultVariants:{},...e},t=h(n);return[Object.assign(n,{compoundVariants:g(n.compoundVariants,t)}),t]}function g(e,n){return typeof e=="function"?e(n):e}0&&(module.exports={_cv,resolveCompoundVariants,resolveConfig});
2
- //# sourceMappingURL=cv.cjs.map
package/build/cv.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cv.ts","../src/tokens.ts","../src/utils.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,4BAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAL,GCSO,IAAMM,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,O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AAeM,EAAiBD,EAAUL,CAAU,CAAC,EACtEM,EAAiBD,EAAUL,CAAU,CAC/C,CAAC,CACL,CAGA,SAASM,EAAiBC,EAAyBC,EAAyB,CACxE,OAAOD,GAAW,SAAS,IAAMC,GAAW,SAAS,CACzD,CAEO,SAAS5B,EACZH,EACiC,CACjC,IAAMgC,EAAkB,CACpB,SAAU,CAAC,EACX,iBAAkB,CAAC,EACnB,gBAAiB,CAAC,EAClB,GAAGhC,CACP,EAEME,EAAQ+B,EAAQD,CAAe,EAErC,MAAO,CACH,OAAO,OAAOA,EAAiB,CAC3B,iBAAkBE,EAAwBF,EAAgB,iBAAkB9B,CAAK,CACrF,CAAC,EACDA,CACJ,CACJ,CAEO,SAASgC,EACZ5B,EACAJ,EACF,CACE,OAAO,OAAOI,GAAqB,WAAaA,EAAiBJ,CAAK,EAAII,CAC9E","names":["cv_exports","__export","_cv","resolveCompoundVariants","resolveConfig","__toCommonJS","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants"]}
package/build/cv.d.cts DELETED
@@ -1,4 +0,0 @@
1
- import 'clsx';
2
- import 'ts-essentials';
3
- import './cn.cjs';
4
- export { B as BooleanStringToBoolean, C as CV, b as CVCompoundVariant, v as CVConfig, u as CVProps, x as CVPropsValue, d as CVReturn, w as CVReturnProps, g as CVVariant, c as CompoundVariantsSchema, j as CompoundVariantsSchemaFunction, R as ResolvedCVConfig, i as Variant, t as VariantKey, h as VariantProps, V as VariantsSchema, _ as _cv, z as resolveCompoundVariants, y as resolveConfig } from './cv-CU8ASolx.cjs';
package/build/define.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var T=Object.create;var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var n in t)m(e,n,{get:t[n],enumerable:!0})},l=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of K(t))!_.call(e,a)&&a!==n&&m(e,a,{get:()=>t[a],enumerable:!(s=E(t,a))||s.enumerable});return e};var w=(e,t,n)=>(n=e!=null?T(M(e)):{},l(t||!e||!e.__esModule?m(n,"default",{value:e,enumerable:!0}):n,e)),U=e=>l(m({},"__esModule",{value:!0}),e);var G={};b(G,{defineCV:()=>z});module.exports=U(G);var y=w(require("clsx"),1);function x({merge:e=t=>t}){return(...t)=>e((0,y.default)(...t))}var B={__token:"OnlyWhenDefined"},W={__token:"OnlyWhenUndefined"};function S(e){return e?typeof e=="object"&&"__token"in e:!1}function h(e,t){return e.__token===t.__token}function g(e,t){return h(e,B)?t!==void 0:h(e,W)?t===void 0:!1}function P(e){return Object.keys(e)}function A(e){return Object.entries(e)}function j(e){return Object.fromEntries(A(e).map(([t,n])=>[t,P(n)]))}function D(e,t){let n={},s={};if(!e)return[n,s];for(let a in e){let r=a;t(r)?n[r]=e[r]:s[r]=e[r]}return[n,s]}function k(e){let t=P(e.variants),n=j(e.variants);return{variantKeys:t,variantMap:n,splitVariantProps:r=>D(r,o=>o in n),getVariantProps:r=>{let o=structuredClone(e.defaultVariants);for(let V in r)r[V]!==void 0&&(o[V]=r[V]);return o}}}function R(e){return t=>{let[n,s]=q(t),{base:a,variants:r,compoundVariants:o,defaultVariants:V}=n,C=p=>{let c=s.getVariantProps(p),i=new Array;for(let u in r){let d=c[u]?.toString();d&&i.push(r?.[u]?.[d])}return i},N=p=>o?.reduce((c,i)=>(F(p,i,V)&&c.push(i.class),c),new Array);return Object.assign(Object.assign((p,...c)=>{let i=C(p),u=N(p);return e.cn(a,i,u,...c)},s),{config:n})}}function F(e,t,n){return Object.keys(t).every(s=>{if(s==="class")return!0;let a=t[s],r=n?.[s],o=e?.[s];if(S(a))return g(a,o);let V=o??r;return Array.isArray(a)?a.some(C=>O(V,C)):O(V,a)})}function O(e,t){return e?.toString()===t?.toString()}function q(e){let t={variants:{},compoundVariants:[],defaultVariants:{},...e},n=k(t);return[Object.assign(t,{compoundVariants:f(t.compoundVariants,n)}),n]}function f(e,t){return typeof e=="function"?e(t):e}function v({cn:e,cv:t}){let n=(s,a)=>{let r=structuredClone(s);for(let o in a){r[o]??={};for(let V in a[o])r[o][V]=e(s[o]?.[V],a[o][V])}return r};return(s,a)=>{let{config:r}=s;return t({base:e(r.base,a.base),variants:n(r.variants,a.variants),compoundVariants:o=>f(r.compoundVariants,s).concat(f(a.compoundVariants??[],o)),defaultVariants:{...r.defaultVariants,...a.defaultVariants}})}}function z({merge:e}={}){let t=x({merge:e}),n=R({cn:t}),s=v({cn:t,cv:n});return{cn:t,cv:n,extend:s}}0&&(module.exports={defineCV});
2
- //# sourceMappingURL=define.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/define.ts","../src/cn.ts","../src/tokens.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts"],"sourcesContent":["import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n","import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAsC,qBAU/B,SAASC,EAAI,CAAE,MAAAC,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,KAAM,EAAAG,SAAK,GAAGD,CAAM,CAAC,CAC/C,CCHO,IAAME,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASC,EAA2BH,EAAgBI,EAAwB,CAC/E,OAAIH,EAAkBD,EAAOH,CAAe,EAAUO,IAAa,OAC1DH,EAAkBD,EAAOF,CAAiB,EAAUM,IAAa,OAEnE,EACX,CCtBO,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B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lyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend"]}
@@ -1,15 +0,0 @@
1
- import { CVExtend } from './extend.cjs';
2
- import { C as CV } from './cv-CU8ASolx.cjs';
3
- import { CNOptions, CN } from './cn.cjs';
4
- import 'clsx';
5
- import 'ts-essentials';
6
-
7
- interface DefineCVOptions extends CNOptions {
8
- }
9
- declare function defineCV({ merge }?: DefineCVOptions): {
10
- readonly cn: CN;
11
- readonly cv: CV;
12
- readonly extend: CVExtend;
13
- };
14
-
15
- export { type DefineCVOptions, defineCV };
package/build/extend.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var d=(e,n)=>{for(var o in n)i(e,o,{get:n[o],enumerable:!0})},f=(e,n,o,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of u(n))!m.call(e,t)&&t!==o&&i(e,t,{get:()=>n[t],enumerable:!(a=c(n,t))||a.enumerable});return e};var C=e=>f(i({},"__esModule",{value:!0}),e);var y={};d(y,{_extend:()=>l});module.exports=C(y);function p(e,n){return typeof e=="function"?e(n):e}function l({cn:e,cv:n}){let o=(a,t)=>{let r=structuredClone(a);for(let s in t){r[s]??={};for(let V in t[s])r[s][V]=e(a[s]?.[V],t[s][V])}return r};return(a,t)=>{let{config:r}=a;return n({base:e(r.base,t.base),variants:o(r.variants,t.variants),compoundVariants:s=>p(r.compoundVariants,a).concat(p(t.compoundVariants??[],s)),defaultVariants:{...r.defaultVariants,...t.defaultVariants}})}}0&&(module.exports={_extend});
2
- //# sourceMappingURL=extend.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/extend.ts","../src/cv.ts"],"sourcesContent":["import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GC+IO,SAASI,EACZC,EACAC,EACF,CACE,OAAO,OAAOD,GAAqB,WAAaA,EAAiBC,CAAK,EAAID,CAC9E,CD3GO,SAASE,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAiBC,CAAG,IAAM,CAAC,EAC3B,QAAWC,KAAWH,EAAYE,CAAG,EACjCD,EAAiBC,CAAG,EAAEC,CAAO,EAAIP,EAAGG,EAASG,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ","names":["extend_exports","__export","_extend","__toCommonJS","resolveCompoundVariants","compoundVariants","utils","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants"]}
@@ -1,24 +0,0 @@
1
- import { ClassValue } from 'clsx';
2
- import { Merge, Prettify } from 'ts-essentials';
3
- import { CN } from './cn.cjs';
4
- import { V as VariantsSchema, d as CVReturn, c as CompoundVariantsSchema, i as Variant, j as CompoundVariantsSchemaFunction, g as CVVariant, C as CV } from './cv-CU8ASolx.cjs';
5
-
6
- type MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;
7
- type MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<V1 & V2, {
8
- [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;
9
- }>;
10
- interface CVExtend {
11
- <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(component: CVReturn<V>, newConfig: {
12
- base?: ClassValue;
13
- variants?: NewV;
14
- compoundVariants?: CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>> | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;
15
- defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;
16
- }): CVReturn<MergeVariantsSchemas<V, NewV>>;
17
- }
18
- interface CVExtendOptions {
19
- cn: CN;
20
- cv: CV;
21
- }
22
- declare function _extend({ cn, cv }: CVExtendOptions): CVExtend;
23
-
24
- export { type CVExtend, _extend };
package/build/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var M=Object.create;var u=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var W=(e,t)=>{for(var n in t)u(e,n,{get:t[n],enumerable:!0})},h=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of b(t))!U.call(e,a)&&a!==n&&u(e,a,{get:()=>t[a],enumerable:!(o=_(t,a))||o.enumerable});return e};var B=(e,t,n)=>(n=e!=null?M(w(e)):{},h(t||!e||!e.__esModule?u(n,"default",{value:e,enumerable:!0}):n,e)),A=e=>h(u({},"__esModule",{value:!0}),e);var J={};W(J,{cn:()=>G,cv:()=>H,defineCV:()=>y,extend:()=>I,onlyWhenDefined:()=>d,onlyWhenUndefined:()=>l});module.exports=A(J);var S=B(require("clsx"),1);function g({merge:e=t=>t}){return(...t)=>e((0,S.default)(...t))}var d={__token:"OnlyWhenDefined"},l={__token:"OnlyWhenUndefined"};function k(e){return e?typeof e=="object"&&"__token"in e:!1}function P(e,t){return e.__token===t.__token}function O(e,t){return P(e,d)?t!==void 0:P(e,l)?t===void 0:!1}function R(e){return Object.keys(e)}function D(e){return Object.entries(e)}function j(e){return Object.fromEntries(D(e).map(([t,n])=>[t,R(n)]))}function F(e,t){let n={},o={};if(!e)return[n,o];for(let a in e){let r=a;t(r)?n[r]=e[r]:o[r]=e[r]}return[n,o]}function v(e){let t=R(e.variants),n=j(e.variants);return{variantKeys:t,variantMap:n,splitVariantProps:r=>F(r,s=>s in n),getVariantProps:r=>{let s=structuredClone(e.defaultVariants);for(let V in r)r[V]!==void 0&&(s[V]=r[V]);return s}}}function T(e){return t=>{let[n,o]=z(t),{base:a,variants:r,compoundVariants:s,defaultVariants:V}=n,f=p=>{let c=o.getVariantProps(p),i=new Array;for(let m in r){let x=c[m]?.toString();x&&i.push(r?.[m]?.[x])}return i},K=p=>s?.reduce((c,i)=>(q(p,i,V)&&c.push(i.class),c),new Array);return Object.assign(Object.assign((p,...c)=>{let i=f(p),m=K(p);return e.cn(a,i,m,...c)},o),{config:n})}}function q(e,t,n){return Object.keys(t).every(o=>{if(o==="class")return!0;let a=t[o],r=n?.[o],s=e?.[o];if(k(a))return O(a,s);let V=s??r;return Array.isArray(a)?a.some(f=>N(V,f)):N(V,a)})}function N(e,t){return e?.toString()===t?.toString()}function z(e){let t={variants:{},compoundVariants:[],defaultVariants:{},...e},n=v(t);return[Object.assign(t,{compoundVariants:C(t.compoundVariants,n)}),n]}function C(e,t){return typeof e=="function"?e(t):e}function E({cn:e,cv:t}){let n=(o,a)=>{let r=structuredClone(o);for(let s in a){r[s]??={};for(let V in a[s])r[s][V]=e(o[s]?.[V],a[s][V])}return r};return(o,a)=>{let{config:r}=o;return t({base:e(r.base,a.base),variants:n(r.variants,a.variants),compoundVariants:s=>C(r.compoundVariants,o).concat(C(a.compoundVariants??[],s)),defaultVariants:{...r.defaultVariants,...a.defaultVariants}})}}function y({merge:e}={}){let t=g({merge:e}),n=T({cn:t}),o=E({cn:t,cv:n});return{cn:t,cv:n,extend:o}}var{cn:G,cv:H,extend:I}=y();0&&(module.exports={cn,cv,defineCV,extend,onlyWhenDefined,onlyWhenUndefined});
2
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/cn.ts","../src/tokens.ts","../src/utils.ts","../src/cv.ts","../src/extend.ts","../src/define.ts"],"sourcesContent":["import type { CN } from \"./cn\";\nimport type {\n CV,\n CVCompoundVariant,\n CompoundVariantsSchema,\n CVReturn,\n CVVariant,\n VariantsSchema,\n VariantProps,\n} from \"./cv\";\nimport { defineCV } from \"./define\";\nimport { type CVExtend } from \"./extend\";\nimport { type CVToken, onlyWhenDefined, onlyWhenUndefined } from \"./tokens\";\nimport type { CVUtils } from \"./utils\";\n\nexport const { cn, cv, extend } = defineCV();\n\nexport { defineCV, onlyWhenDefined, onlyWhenUndefined };\nexport type {\n CN,\n CV,\n CVCompoundVariant,\n CompoundVariantsSchema,\n CVExtend,\n CVReturn,\n CVToken,\n CVUtils,\n CVVariant,\n VariantsSchema,\n VariantProps,\n};\n","import clsx, { type ClassValue } from \"clsx\";\n\nexport interface CNOptions {\n merge?: (className: string) => string;\n}\n\nexport interface CN {\n (...inputs: ClassValue[]): string;\n}\n\nexport function _cn({ merge = (className) => className }: CNOptions): CN {\n return (...inputs) => merge(clsx(...inputs));\n}\n","import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n","import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { ArrayOrSingle } from \"ts-essentials\";\nimport { type CN } from \"./cn\";\nimport { isCVToken, shouldApplySelectorByToken, type CVToken } from \"./tokens\";\nimport { cvUtils, type CVUtils } from \"./utils\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type VariantProps<CVR extends (props?: any) => string> = CVR extends CVReturn<infer V> ? CVProps<V> : never;\n\nexport type BooleanStringToBoolean<T> = T extends \"true\" | \"false\" ? boolean : T;\n\nexport type VariantKey = string | number;\n\nexport type Variant = Record<VariantKey, ClassValue>;\nexport type VariantsSchema = Record<string, Variant>;\n\ntype EmptySchema = Record<never, never>;\n\nexport type CVVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: BooleanStringToBoolean<keyof V[K] & VariantKey>;\n};\n\nexport type CVProps<V extends VariantsSchema = EmptySchema> = CVVariant<V>;\n\nexport type CVCompoundVariant<V extends VariantsSchema = EmptySchema> = {\n [K in keyof V]?: ArrayOrSingle<BooleanStringToBoolean<keyof V[K] & VariantKey>> | CVToken;\n} & { class: ClassValue };\n\nexport type CompoundVariantsSchema<V extends VariantsSchema = EmptySchema> = CVCompoundVariant<V>[];\nexport type CompoundVariantsSchemaFunction<V extends VariantsSchema = EmptySchema> = (\n utils: CVUtils<V>,\n) => CompoundVariantsSchema<V>;\n\nexport interface CVConfig<V extends VariantsSchema = EmptySchema> {\n base: ClassValue;\n variants: V;\n compoundVariants: CompoundVariantsSchema<V> | CompoundVariantsSchemaFunction<V>;\n defaultVariants: CVVariant<V>;\n}\n\nexport interface ResolvedCVConfig<V extends VariantsSchema = EmptySchema> extends CVConfig<V> {\n compoundVariants: CompoundVariantsSchema<V>;\n}\n\nexport type CVReturnProps<V extends VariantsSchema = EmptySchema> = CVProps<V>;\n\nexport interface CVReturn<V extends VariantsSchema = EmptySchema> extends CVUtils<V> {\n (props?: CVReturnProps<V>, ...classNames: ClassValue[]): string;\n config: ResolvedCVConfig<V>;\n}\n\nexport interface CV {\n <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>): CVReturn<V>;\n}\n\ninterface CVOptions {\n cn: CN;\n}\nexport function _cv(options: CVOptions): CV {\n return <V extends VariantsSchema = EmptySchema>(config: Partial<CVConfig<V>>) => {\n const [resolvedConfig, utils] = resolveConfig(config);\n\n const { base, variants, compoundVariants, defaultVariants } = resolvedConfig;\n\n const getVariantsClassNames = (props?: CVReturnProps<V>) => {\n const defaultedProps = utils.getVariantProps(props);\n\n const classNames = new Array<ClassValue>();\n for (const key in variants) {\n const variant = defaultedProps[key]?.toString();\n if (variant) classNames.push(variants?.[key]?.[variant]);\n }\n return classNames;\n };\n\n const getCompoundVariantsClassNames = (props?: CVReturnProps<V>) => {\n return compoundVariants?.reduce((acc, compoundVariant) => {\n if (shouldApplyCompoundVariant(props, compoundVariant, defaultVariants))\n acc.push(compoundVariant.class);\n return acc;\n }, new Array<ClassValue>());\n };\n\n const getVariant = (props?: CVReturnProps<V>, ...classNames: ClassValue[]) => {\n const variantClassNames = getVariantsClassNames(props);\n\n const compoundVariantClassNames = getCompoundVariantsClassNames(props);\n\n return options.cn(base, variantClassNames, compoundVariantClassNames, ...classNames);\n };\n\n return Object.assign(Object.assign(getVariant, utils), { config: resolvedConfig });\n };\n}\n\nfunction shouldApplyCompoundVariant<V extends VariantsSchema = EmptySchema>(\n props: CVReturnProps<V> | undefined,\n matcher: CVCompoundVariant<V>,\n defaults: CVVariant<V> | undefined,\n) {\n return Object.keys(matcher).every((cvKey) => {\n if (cvKey === \"class\") return true;\n\n const cvSelector = matcher[cvKey];\n\n const defaultsSelector = defaults?.[cvKey as keyof typeof defaults];\n const propsSelector = props?.[cvKey as keyof typeof props];\n\n if (isCVToken(cvSelector)) return shouldApplySelectorByToken(cvSelector, propsSelector);\n\n const selector = propsSelector ?? defaultsSelector;\n\n return Array.isArray(cvSelector)\n ? cvSelector.some((cvSelector) => compareSelectors(selector, cvSelector))\n : compareSelectors(selector, cvSelector);\n });\n}\n\nexport type CVPropsValue = VariantKey | boolean | undefined;\nfunction compareSelectors(selector1: CVPropsValue, selector2: CVPropsValue) {\n return selector1?.toString() === selector2?.toString();\n}\n\nexport function resolveConfig<V extends VariantsSchema = EmptySchema>(\n config: Partial<CVConfig<V>>,\n): [ResolvedCVConfig<V>, CVUtils<V>] {\n const defaultedConfig = {\n variants: {},\n compoundVariants: [],\n defaultVariants: {},\n ...config,\n } as CVConfig<V>;\n\n const utils = cvUtils(defaultedConfig);\n\n return [\n Object.assign(defaultedConfig, {\n compoundVariants: resolveCompoundVariants(defaultedConfig.compoundVariants, utils),\n }),\n utils,\n ] as const;\n}\n\nexport function resolveCompoundVariants<V extends VariantsSchema = EmptySchema>(\n compoundVariants: CVConfig<V>[\"compoundVariants\"],\n utils: CVUtils<V>,\n) {\n return typeof compoundVariants === \"function\" ? compoundVariants(utils) : compoundVariants;\n}\n","import type { ClassValue } from \"clsx\";\nimport type { Merge, Prettify } from \"ts-essentials\";\nimport type { CN } from \"./cn\";\nimport {\n resolveCompoundVariants,\n type CompoundVariantsSchema,\n type CompoundVariantsSchemaFunction,\n type CV,\n type CVConfig,\n type CVReturn,\n type CVVariant,\n type Variant,\n type VariantsSchema,\n} from \"./cv\";\n\ntype MergeVariant<V1 extends Variant, V2 extends Variant> = Prettify<Record<keyof V1 | keyof V2, ClassValue>>;\ntype MergeVariantsSchemas<V1 extends VariantsSchema, V2 extends VariantsSchema> = Merge<\n V1 & V2,\n {\n [K in keyof V1 & keyof V2]: MergeVariant<V1[K], V2[K]>;\n }\n>;\n\nexport interface CVExtend {\n <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ): CVReturn<MergeVariantsSchemas<V, NewV>>;\n}\n\ninterface CVExtendOptions {\n cn: CN;\n cv: CV;\n}\nexport function _extend({ cn, cv }: CVExtendOptions): CVExtend {\n const extendVariants = <V extends VariantsSchema, NewV extends VariantsSchema>(variants: V, newVariants?: NewV) => {\n const extendedVariants: VariantsSchema = structuredClone(variants);\n for (const key in newVariants) {\n extendedVariants[key] ??= {};\n for (const variant in newVariants[key]) {\n extendedVariants[key][variant] = cn(variants[key]?.[variant], newVariants[key][variant]);\n }\n }\n return extendedVariants as MergeVariantsSchemas<V, NewV>;\n };\n\n return <V extends VariantsSchema, NewV extends VariantsSchema | (V & {})>(\n component: CVReturn<V>,\n newConfig: {\n base?: ClassValue;\n variants?: NewV;\n compoundVariants?:\n | CompoundVariantsSchema<MergeVariantsSchemas<V, NewV>>\n | CompoundVariantsSchemaFunction<MergeVariantsSchemas<V, NewV>>;\n defaultVariants?: CVVariant<MergeVariantsSchemas<V, NewV>>;\n },\n ) => {\n const { config } = component;\n\n return cv({\n base: cn(config.base, newConfig.base),\n variants: extendVariants(config.variants, newConfig.variants),\n compoundVariants: (utils) =>\n resolveCompoundVariants(config.compoundVariants, component).concat(\n resolveCompoundVariants(newConfig.compoundVariants ?? [], utils),\n ),\n defaultVariants: { ...config.defaultVariants, ...newConfig.defaultVariants },\n } as CVConfig<MergeVariantsSchemas<V, NewV>>);\n };\n}\n","import { _cn, type CNOptions } from \"./cn\";\nimport { _cv } from \"./cv\";\nimport { _extend } from \"./extend\";\n\nexport interface DefineCVOptions extends CNOptions {}\n\nexport function defineCV({ merge }: DefineCVOptions = {}) {\n const cn = _cn({ merge });\n\n const cv = _cv({ cn });\n\n const extend = _extend({ cn, cv });\n\n return { cn, cv, extend } as const;\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,OAAAC,EAAA,aAAAC,EAAA,WAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAR,GCAA,IAAAS,EAAsC,qBAU/B,SAASC,EAAI,CAAE,MAAAC,EAASC,GAAcA,CAAU,EAAkB,CACrE,MAAO,IAAIC,IAAWF,KAAM,EAAAG,SAAK,GAAGD,CAAM,CAAC,CAC/C,CCHO,IAAME,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASC,EAAUC,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASC,EAA2BH,EAAgBI,EAAwB,CAC/E,OAAIH,EAAkBD,EAAOH,CAAe,EAAUO,IAAa,OAC1DH,EAAkBD,EAAOF,CAAiB,EAAUM,IAAa,OAEnE,EACX,CCtBO,SAASC,EAA2CC,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASC,EAA8CD,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASE,EAAwCC,EAAa,CACjE,OAAO,OAAO,YAAYF,EAAWE,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,C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AAK,EAAII,CAC9E,CC3GO,SAAS6B,EAAQ,CAAE,GAAAC,EAAI,GAAAC,CAAG,EAA8B,CAC3D,IAAMC,EAAiB,CAAwDC,EAAaC,IAAuB,CAC/G,IAAMC,EAAmC,gBAAgBF,CAAQ,EACjE,QAAWG,KAAOF,EAAa,CAC3BC,EAAiBC,CAAG,IAAM,CAAC,EAC3B,QAAWC,KAAWH,EAAYE,CAAG,EACjCD,EAAiBC,CAAG,EAAEC,CAAO,EAAIP,EAAGG,EAASG,CAAG,IAAIC,CAAO,EAAGH,EAAYE,CAAG,EAAEC,CAAO,CAAC,CAE/F,CACA,OAAOF,CACX,EAEA,MAAO,CACHG,EACAC,IAQC,CACD,GAAM,CAAE,OAAAC,CAAO,EAAIF,EAEnB,OAAOP,EAAG,CACN,KAAMD,EAAGU,EAAO,KAAMD,EAAU,IAAI,EACpC,SAAUP,EAAeQ,EAAO,SAAUD,EAAU,QAAQ,EAC5D,iBAAmBE,GACfC,EAAwBF,EAAO,iBAAkBF,CAAS,EAAE,OACxDI,EAAwBH,EAAU,kBAAoB,CAAC,EAAGE,CAAK,CACnE,EACJ,gBAAiB,CAAE,GAAGD,EAAO,gBAAiB,GAAGD,EAAU,eAAgB,CAC/E,CAA4C,CAChD,CACJ,CCtEO,SAASI,EAAS,CAAE,MAAAC,CAAM,EAAqB,CAAC,EAAG,CACtD,IAAMC,EAAKC,EAAI,CAAE,MAAAF,CAAM,CAAC,EAElBG,EAAKC,EAAI,CAAE,GAAAH,CAAG,CAAC,EAEfI,EAASC,EAAQ,CAAE,GAAAL,EAAI,GAAAE,CAAG,CAAC,EAEjC,MAAO,CAAE,GAAAF,EAAI,GAAAE,EAAI,OAAAE,CAAO,CAC5B,CNCO,GAAM,CAAE,GAAAE,EAAI,GAAAC,EAAI,OAAAC,CAAO,EAAIC,EAAS","names":["index_exports","__export","cn","cv","defineCV","extend","onlyWhenDefined","onlyWhenUndefined","__toCommonJS","import_clsx","_cn","merge","className","inputs","clsx","onlyWhenDefined","onlyWhenUndefined","isCVToken","token","isSpecificCVToken","reference","shouldApplySelectorByToken","selector","getKeys","obj","getEntries","getVariantMap","variants","cvKey","cvVal","splitProps","props","shouldSplit","splittedProps","otherProps","propKey","key","cvUtils","config","variantKeys","variantMap","defaultedProps","_cv","options","config","resolvedConfig","utils","resolveConfig","base","variants","compoundVariants","defaultVariants","getVariantsClassNames","props","defaultedProps","classNames","key","variant","getCompoundVariantsClassNames","acc","compoundVariant","shouldApplyCompoundVariant","variantClassNames","compoundVariantClassNames","matcher","defaults","cvKey","cvSelector","defaultsSelector","propsSelector","isCVToken","shouldApplySelectorByToken","selector","compareSelectors","selector1","selector2","defaultedConfig","cvUtils","resolveCompoundVariants","_extend","cn","cv","extendVariants","variants","newVariants","extendedVariants","key","variant","component","newConfig","config","utils","resolveCompoundVariants","defineCV","merge","cn","_cn","cv","_cv","extend","_extend","cn","cv","extend","defineCV"]}
package/build/index.d.cts DELETED
@@ -1,13 +0,0 @@
1
- import { CN } from './cn.cjs';
2
- import { C as CV } from './cv-CU8ASolx.cjs';
3
- export { b as CVCompoundVariant, d as CVReturn, e as CVToken, f as CVUtils, g as CVVariant, c as CompoundVariantsSchema, h as VariantProps, V as VariantsSchema, o as onlyWhenDefined, a as onlyWhenUndefined } from './cv-CU8ASolx.cjs';
4
- export { defineCV } from './define.cjs';
5
- import { CVExtend } from './extend.cjs';
6
- import 'clsx';
7
- import 'ts-essentials';
8
-
9
- declare const cn: CN;
10
- declare const cv: CV;
11
- declare const extend: CVExtend;
12
-
13
- export { CN, CV, CVExtend, cn, cv, extend };
package/build/tokens.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var u=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},k=(e,n,t,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of s(n))!y.call(e,o)&&o!==t&&i(e,o,{get:()=>n[o],enumerable:!(f=l(n,o))||f.enumerable});return e};var _=e=>k(i({},"__esModule",{value:!0}),e);var c={};u(c,{isCVToken:()=>h,onlyWhenDefined:()=>d,onlyWhenUndefined:()=>p,shouldApplySelectorByToken:()=>O});module.exports=_(c);var d={__token:"OnlyWhenDefined"},p={__token:"OnlyWhenUndefined"};function h(e){return e?typeof e=="object"&&"__token"in e:!1}function r(e,n){return e.__token===n.__token}function O(e,n){return r(e,d)?n!==void 0:r(e,p)?n===void 0:!1}0&&(module.exports={isCVToken,onlyWhenDefined,onlyWhenUndefined,shouldApplySelectorByToken});
2
- //# sourceMappingURL=tokens.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tokens.ts"],"sourcesContent":["import type { Opaque } from \"ts-essentials\";\nimport type { CVPropsValue } from \"./cv\";\n\ntype OnlyWhenDefined = Opaque<{ __token: string }, \"OnlyWhenDefined\">;\ntype OnlyWhenUndefined = Opaque<{ __token: string }, \"OnlyWhenUndefined\">;\n\nexport type CVToken = OnlyWhenDefined | OnlyWhenUndefined;\n\n/** Apply compound variant only if prop **is** specified */\nexport const onlyWhenDefined = { __token: \"OnlyWhenDefined\" } as OnlyWhenDefined;\n/** Apply compound variant only if prop **is not** specified */\nexport const onlyWhenUndefined = { __token: \"OnlyWhenUndefined\" } as OnlyWhenUndefined;\n\nexport function isCVToken(token: unknown): token is CVToken {\n return token ? typeof token === \"object\" && \"__token\" in token : false;\n}\nfunction isSpecificCVToken<TReference extends CVToken>(token: CVToken, reference: TReference): token is TReference {\n return token.__token === reference.__token;\n}\n\nexport function shouldApplySelectorByToken(token: CVToken, selector: CVPropsValue) {\n if (isSpecificCVToken(token, onlyWhenDefined)) return selector !== undefined;\n else if (isSpecificCVToken(token, onlyWhenUndefined)) return selector === undefined;\n\n return false;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,EAAA,oBAAAC,EAAA,sBAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAN,GASO,IAAMG,EAAkB,CAAE,QAAS,iBAAkB,EAE/CC,EAAoB,CAAE,QAAS,mBAAoB,EAEzD,SAASF,EAAUK,EAAkC,CACxD,OAAOA,EAAQ,OAAOA,GAAU,UAAY,YAAaA,EAAQ,EACrE,CACA,SAASC,EAA8CD,EAAgBE,EAA4C,CAC/G,OAAOF,EAAM,UAAYE,EAAU,OACvC,CAEO,SAASJ,EAA2BE,EAAgBG,EAAwB,CAC/E,OAAIF,EAAkBD,EAAOJ,CAAe,EAAUO,IAAa,OAC1DF,EAAkBD,EAAOH,CAAiB,EAAUM,IAAa,OAEnE,EACX","names":["tokens_exports","__export","isCVToken","onlyWhenDefined","onlyWhenUndefined","shouldApplySelectorByToken","__toCommonJS","token","isSpecificCVToken","reference","selector"]}
@@ -1,4 +0,0 @@
1
- import 'ts-essentials';
2
- export { e as CVToken, k as isCVToken, o as onlyWhenDefined, a as onlyWhenUndefined, s as shouldApplySelectorByToken } from './cv-CU8ASolx.cjs';
3
- import 'clsx';
4
- import './cn.cjs';
package/build/utils.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var V=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(t,e)=>{for(var r in e)V(t,r,{get:e[r],enumerable:!0})},k=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of y(e))!d.call(t,o)&&o!==r&&V(t,o,{get:()=>e[o],enumerable:!(s=u(e,o))||s.enumerable});return t};var x=t=>k(V({},"__esModule",{value:!0}),t);var C={};l(C,{cvUtils:()=>O,getEntries:()=>f,getKeys:()=>p,getVariantMap:()=>c,splitProps:()=>P});module.exports=x(C);function p(t){return Object.keys(t)}function f(t){return Object.entries(t)}function c(t){return Object.fromEntries(f(t).map(([e,r])=>[e,p(r)]))}function P(t,e){let r={},s={};if(!t)return[r,s];for(let o in t){let n=o;e(n)?r[n]=t[n]:s[n]=t[n]}return[r,s]}function O(t){let e=p(t.variants),r=c(t.variants);return{variantKeys:e,variantMap:r,splitVariantProps:n=>P(n,a=>a in r),getVariantProps:n=>{let a=structuredClone(t.defaultVariants);for(let i in n)n[i]!==void 0&&(a[i]=n[i]);return a}}}0&&(module.exports={cvUtils,getEntries,getKeys,getVariantMap,splitProps});
2
- //# sourceMappingURL=utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import type { Prettify } from \"ts-essentials\";\nimport type { BooleanStringToBoolean, CVConfig, CVReturnProps, VariantKey, VariantsSchema } from \"./cv\";\n\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\n return Object.keys(obj) as (keyof O & VariantKey)[];\n}\n\nexport type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\n return Object.entries(obj) as EntriesOf<O>[keyof EntriesOf<O>][];\n}\n\nexport type VariantMap<V extends VariantsSchema> = {\n [K in keyof V]: BooleanStringToBoolean<keyof V[K] & VariantKey>[];\n};\nexport function getVariantMap<V extends VariantsSchema>(variants: V) {\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as VariantMap<V>;\n}\n\nexport function splitProps<TProps>(props: TProps, shouldSplit: (key: keyof TProps) => boolean) {\n const splittedProps = {} as Partial<Record<keyof TProps, unknown>>;\n const otherProps = {} as Partial<Record<keyof TProps, unknown>>;\n if (!props) return [splittedProps, otherProps] as const;\n for (const propKey in props) {\n const key = propKey as keyof TProps;\n if (shouldSplit(key)) splittedProps[key] = props[key];\n else otherProps[key] = props[key];\n }\n return [splittedProps, otherProps] as const;\n}\n\nexport interface CVUtils<V extends VariantsSchema> {\n variantKeys: (keyof V & string)[];\n variantMap: Prettify<VariantMap<V>>;\n splitVariantProps: <TProps extends CVReturnProps<V>>(\n props?: TProps,\n ) => [CVReturnProps<V>, Prettify<Omit<TProps, keyof CVReturnProps<V>>>];\n getVariantProps: (props?: CVReturnProps<V>) => Exclude<CVReturnProps<V>, void>;\n}\n\nexport function cvUtils<V extends VariantsSchema>(config: CVConfig<V>): CVUtils<V> {\n const variantKeys = getKeys(config.variants);\n const variantMap = getVariantMap(config.variants);\n const splitVariantProps = (props?: CVReturnProps<V>) => splitProps(props, (key) => key in variantMap);\n const getVariantProps = (props?: CVReturnProps<V>) => {\n const defaultedProps = structuredClone(config.defaultVariants);\n for (const key in props) {\n if (props[key] !== undefined) defaultedProps[key] = props[key];\n }\n return defaultedProps;\n };\n\n return { variantKeys, variantMap, splitVariantProps, getVariantProps } as CVUtils<V>;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,eAAAC,EAAA,YAAAC,EAAA,kBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GAGO,SAASI,EAA2CI,EAAQ,CAC/D,OAAO,OAAO,KAAKA,CAAG,CAC1B,CAGO,SAASL,EAA8CK,EAAQ,CAClE,OAAO,OAAO,QAAQA,CAAG,CAC7B,CAKO,SAASH,EAAwCI,EAAa,CACjE,OAAO,OAAO,YAAYN,EAAWM,CAAQ,EAAE,IAAI,CAAC,CAACC,EAAOC,CAAK,IAAM,CAACD,EAAON,EAAQO,CAAK,CAAC,CAAC,CAAC,CACnG,CAEO,SAASL,EAAmBM,EAAeC,EAA6C,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAa,CAAC,EACpB,GAAI,CAACH,EAAO,MAAO,CAACE,EAAeC,CAAU,EAC7C,QAAWC,KAAWJ,EAAO,CACzB,IAAMK,EAAMD,EACRH,EAAYI,CAAG,EAAGH,EAAcG,CAAG,EAAIL,EAAMK,CAAG,EAC/CF,EAAWE,CAAG,EAAIL,EAAMK,CAAG,CACpC,CACA,MAAO,CAACH,EAAeC,CAAU,CACrC,CAWO,SAASb,EAAkCgB,EAAiC,CAC/E,IAAMC,EAAcf,EAAQc,EAAO,QAAQ,EACrCE,EAAaf,EAAca,EAAO,QAAQ,EAUhD,MAAO,CAAE,YAAAC,EAAa,WAAAC,EAAY,kBATPR,GAA6BN,EAAWM,EAAQK,GAAQA,KAAOG,CAAU,EAS/C,gBAR5BR,GAA6B,CAClD,IAAMS,EAAiB,gBAAgBH,EAAO,eAAe,EAC7D,QAAWD,KAAOL,EACVA,EAAMK,CAAG,IAAM,SAAWI,EAAeJ,CAAG,EAAIL,EAAMK,CAAG,GAEjE,OAAOI,CACX,CAEqE,CACzE","names":["utils_exports","__export","cvUtils","getEntries","getKeys","getVariantMap","splitProps","__toCommonJS","obj","variants","cvKey","cvVal","props","shouldSplit","splittedProps","otherProps","propKey","key","config","variantKeys","variantMap","defaultedProps"]}
package/build/utils.d.cts DELETED
@@ -1,4 +0,0 @@
1
- import 'ts-essentials';
2
- export { f as CVUtils, E as EntriesOf, n as VariantMap, r as cvUtils, m as getEntries, l as getKeys, p as getVariantMap, q as splitProps } from './cv-CU8ASolx.cjs';
3
- import 'clsx';
4
- import './cn.cjs';
package/build/vue.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},s=(t,e,n,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of y(e))!i.call(t,r)&&r!==n&&o(t,r,{get:()=>e[r],enumerable:!(p=a(e,r))||p.enumerable});return t};var V=t=>s(o({},"__esModule",{value:!0}),t);var u={};m(u,{getPropsDeclaration:()=>f});module.exports=V(u);function f(t){return Object.fromEntries(t.variantKeys.map(e=>[e,{type:null}]))}0&&(module.exports={getPropsDeclaration});
2
- //# sourceMappingURL=vue.cjs.map
package/build/vue.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { type PropType } from \"vue\";\nimport { type CVReturn, type VariantsSchema } from \"./cv\";\n\nexport function getPropsDeclaration<V extends VariantsSchema /* , R extends keyof V = never */>(cv: CVReturn<V>) {\n return Object.fromEntries(\n cv.variantKeys.map((key) => [key, { type: null /* , required: cv.requiredVariants[key as R] */ }]),\n ) as unknown as { [K in keyof V]: { type: PropType<keyof V[K]> /* ; required: K extends R ? true : false */ } };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAGO,SAASE,EAAgFE,EAAiB,CAC7G,OAAO,OAAO,YACVA,EAAG,YAAY,IAAKC,GAAQ,CAACA,EAAK,CAAE,KAAM,IAAqD,CAAC,CAAC,CACrG,CACJ","names":["vue_exports","__export","getPropsDeclaration","__toCommonJS","cv","key"]}
package/build/vue.d.cts DELETED
@@ -1,11 +0,0 @@
1
- import { PropType } from 'vue';
2
- import { V as VariantsSchema, d as CVReturn } from './cv-CU8ASolx.cjs';
3
- import 'clsx';
4
- import 'ts-essentials';
5
- import './cn.cjs';
6
-
7
- declare function getPropsDeclaration<V extends VariantsSchema>(cv: CVReturn<V>): { [K in keyof V]: {
8
- type: PropType<keyof V[K]>;
9
- }; };
10
-
11
- export { getPropsDeclaration };