css-variants 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -39
- package/dist/cv.cjs +2 -0
- package/dist/cv.cjs.map +1 -0
- package/dist/{esm/cv.d.ts → cv.d.cts} +13 -10
- package/dist/{cjs/cv.d.ts → cv.d.ts} +13 -10
- package/dist/cv.js +2 -0
- package/dist/cv.js.map +1 -0
- package/dist/cx.cjs +2 -0
- package/dist/cx.cjs.map +1 -0
- package/dist/cx.d.cts +6 -0
- package/dist/cx.d.ts +6 -0
- package/dist/cx.js +2 -0
- package/dist/cx.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/scv.cjs +2 -0
- package/dist/scv.cjs.map +1 -0
- package/dist/scv.d.cts +59 -0
- package/dist/scv.d.ts +59 -0
- package/dist/scv.js +2 -0
- package/dist/scv.js.map +1 -0
- package/dist/ssv.cjs +2 -0
- package/dist/ssv.cjs.map +1 -0
- package/dist/ssv.d.cts +54 -0
- package/dist/ssv.d.ts +54 -0
- package/dist/ssv.js +2 -0
- package/dist/ssv.js.map +1 -0
- package/dist/sv.cjs +2 -0
- package/dist/sv.cjs.map +1 -0
- package/dist/{cjs/sv.d.ts → sv.d.cts} +12 -9
- package/dist/{esm/sv.d.ts → sv.d.ts} +12 -9
- package/dist/sv.js +2 -0
- package/dist/sv.js.map +1 -0
- package/dist/types-BXKyjXhG.d.cts +16 -0
- package/dist/types-BXKyjXhG.d.ts +16 -0
- package/package.json +35 -13
- package/dist/cjs/cv.js +0 -75
- package/dist/cjs/cv.js.map +0 -1
- package/dist/cjs/cx.d.ts +0 -5
- package/dist/cjs/cx.js +0 -57
- package/dist/cjs/cx.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/scv.d.ts +0 -56
- package/dist/cjs/scv.js +0 -107
- package/dist/cjs/scv.js.map +0 -1
- package/dist/cjs/ssv.d.ts +0 -51
- package/dist/cjs/ssv.js +0 -94
- package/dist/cjs/ssv.js.map +0 -1
- package/dist/cjs/sv.js +0 -74
- package/dist/cjs/sv.js.map +0 -1
- package/dist/cjs/utils/merge-props.d.ts +0 -1
- package/dist/cjs/utils/merge-props.js +0 -15
- package/dist/cjs/utils/merge-props.js.map +0 -1
- package/dist/cjs/utils/types.d.ts +0 -16
- package/dist/cjs/utils/types.js +0 -3
- package/dist/cjs/utils/types.js.map +0 -1
- package/dist/esm/cv.js +0 -71
- package/dist/esm/cv.js.map +0 -1
- package/dist/esm/cx.d.ts +0 -5
- package/dist/esm/cx.js +0 -54
- package/dist/esm/cx.js.map +0 -1
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/scv.d.ts +0 -56
- package/dist/esm/scv.js +0 -103
- package/dist/esm/scv.js.map +0 -1
- package/dist/esm/ssv.d.ts +0 -51
- package/dist/esm/ssv.js +0 -90
- package/dist/esm/ssv.js.map +0 -1
- package/dist/esm/sv.js +0 -70
- package/dist/esm/sv.js.map +0 -1
- package/dist/esm/utils/merge-props.d.ts +0 -1
- package/dist/esm/utils/merge-props.js +0 -12
- package/dist/esm/utils/merge-props.js.map +0 -1
- package/dist/esm/utils/types.d.ts +0 -16
- package/dist/esm/utils/types.js +0 -2
- package/dist/esm/utils/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,35 +1,42 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# css-variants
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
**Zero-dependency, type-safe CSS variant composition for modern JavaScript**
|
|
4
6
|
|
|
5
|
-
Build powerful, flexible component style systems with variants
|
|
7
|
+
Build powerful, flexible component style systems with variants.<br/>
|
|
8
|
+
Perfect for Tailwind CSS, vanilla CSS, or any CSS-in-JS solution.
|
|
6
9
|
|
|
7
10
|
[](https://github.com/timphandev/css-variants/actions/workflows/ci.yml)
|
|
8
11
|
[](https://www.npmjs.com/package/css-variants)
|
|
9
12
|
[](https://bundlephobia.com/package/css-variants)
|
|
10
13
|
[](https://www.typescriptlang.org/)
|
|
11
14
|
[](https://opensource.org/licenses/MIT)
|
|
12
|
-
[](https://github.com/timphandev/css-variants)
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
[Documentation](https://css-variants.vercel.app/) · [Getting Started](https://css-variants.vercel.app/getting-started/introduction/) · [API Reference](https://css-variants.vercel.app/api/cv/)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
---
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
## Why css-variants?
|
|
23
|
+
|
|
24
|
+
| | Feature |
|
|
25
|
+
|---|---------|
|
|
26
|
+
| ⚡ | **~1KB** — Zero dependencies, tree-shakeable |
|
|
27
|
+
| 🔒 | **Type-Safe** — Full TypeScript inference for variants & props |
|
|
28
|
+
| 🧩 | **Flexible** — Works with Tailwind, CSS Modules, vanilla CSS, inline styles |
|
|
29
|
+
| 🚀 | **Fast** — Up to 10x faster than alternatives in complex scenarios |
|
|
21
30
|
|
|
22
31
|
## Installation
|
|
23
32
|
|
|
24
33
|
```bash
|
|
25
34
|
npm install css-variants
|
|
26
|
-
# or
|
|
27
|
-
yarn add css-variants
|
|
28
|
-
# or
|
|
29
|
-
pnpm add css-variants
|
|
30
35
|
```
|
|
31
36
|
|
|
32
|
-
## Quick
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Single-Element Variants (`cv`)
|
|
33
40
|
|
|
34
41
|
```typescript
|
|
35
42
|
import { cv } from 'css-variants'
|
|
@@ -43,49 +50,98 @@ const button = cv({
|
|
|
43
50
|
},
|
|
44
51
|
size: {
|
|
45
52
|
sm: 'px-3 py-1.5 text-sm',
|
|
46
|
-
md: 'px-4 py-2 text-base',
|
|
47
53
|
lg: 'px-6 py-3 text-lg',
|
|
48
54
|
},
|
|
49
55
|
},
|
|
50
|
-
defaultVariants: {
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
defaultVariants: { color: 'primary', size: 'sm' },
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
button() // Primary + Small (defaults)
|
|
60
|
+
button({ color: 'secondary' }) // Secondary + Small
|
|
61
|
+
button({ size: 'lg', className: 'w-full' }) // Primary + Large + custom class
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Multi-Element Components (`scv`)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { scv } from 'css-variants'
|
|
68
|
+
|
|
69
|
+
const card = scv({
|
|
70
|
+
slots: ['root', 'header', 'body', 'footer'],
|
|
71
|
+
base: {
|
|
72
|
+
root: 'rounded-xl border shadow-sm',
|
|
73
|
+
header: 'px-6 py-4 border-b',
|
|
74
|
+
body: 'px-6 py-4',
|
|
75
|
+
footer: 'px-6 py-3 bg-gray-50',
|
|
76
|
+
},
|
|
77
|
+
variants: {
|
|
78
|
+
variant: {
|
|
79
|
+
default: { root: 'bg-white border-gray-200' },
|
|
80
|
+
danger: { root: 'bg-red-50 border-red-200', header: 'text-red-900' },
|
|
81
|
+
},
|
|
53
82
|
},
|
|
54
83
|
})
|
|
55
84
|
|
|
56
|
-
|
|
57
|
-
|
|
85
|
+
const styles = card({ variant: 'danger' })
|
|
86
|
+
// styles.root → 'rounded-xl border shadow-sm bg-red-50 border-red-200'
|
|
87
|
+
// styles.header → 'px-6 py-4 border-b text-red-900'
|
|
58
88
|
```
|
|
59
89
|
|
|
60
|
-
|
|
90
|
+
### Compound Variants
|
|
61
91
|
|
|
62
|
-
|
|
92
|
+
Apply styles when multiple variants match:
|
|
63
93
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
94
|
+
```typescript
|
|
95
|
+
const button = cv({
|
|
96
|
+
variants: {
|
|
97
|
+
color: { primary: '...', danger: '...' },
|
|
98
|
+
size: { sm: '...', lg: '...' },
|
|
99
|
+
},
|
|
100
|
+
compoundVariants: [
|
|
101
|
+
{ color: 'danger', size: 'lg', className: 'font-bold uppercase' },
|
|
102
|
+
],
|
|
103
|
+
})
|
|
104
|
+
```
|
|
68
105
|
|
|
69
|
-
|
|
106
|
+
### Style Variants (`sv`)
|
|
70
107
|
|
|
71
|
-
|
|
108
|
+
For inline styles instead of class names:
|
|
72
109
|
|
|
73
|
-
|
|
110
|
+
```typescript
|
|
111
|
+
import { sv } from 'css-variants'
|
|
74
112
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
113
|
+
const box = sv({
|
|
114
|
+
base: { display: 'flex', borderRadius: '8px' },
|
|
115
|
+
variants: {
|
|
116
|
+
size: {
|
|
117
|
+
sm: { padding: '8px' },
|
|
118
|
+
lg: { padding: '24px' },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
box({ size: 'lg' }) // => { display: 'flex', borderRadius: '8px', padding: '24px' }
|
|
81
124
|
```
|
|
82
125
|
|
|
83
|
-
##
|
|
126
|
+
## Performance
|
|
84
127
|
|
|
85
|
-
|
|
128
|
+
| vs cva | vs tailwind-variants |
|
|
129
|
+
|:------:|:--------------------:|
|
|
130
|
+
| 3-4x faster (compound variants) | 5-6x faster (compound variants) |
|
|
131
|
+
| 4-9x faster (complex components) | 10-11x faster (complex components) |
|
|
132
|
+
|
|
133
|
+
## Documentation
|
|
134
|
+
|
|
135
|
+
**[Full documentation →](https://css-variants.vercel.app/)**
|
|
136
|
+
|
|
137
|
+
## Contributing
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git clone https://github.com/timphandev/css-variants.git
|
|
141
|
+
cd css-variants && yarn install
|
|
142
|
+
yarn test && yarn build
|
|
143
|
+
```
|
|
86
144
|
|
|
87
145
|
## License
|
|
88
146
|
|
|
89
147
|
MIT © [Tim Phan](https://github.com/timphandev)
|
|
90
|
-
|
|
91
|
-
**Made with ❤️ by developers, for developers**
|
package/dist/cv.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});function p(s){if(typeof s=="string")return s;if(typeof s=="number"||typeof s=="bigint")return String(s);if(s==null||typeof s=="boolean")return "";let e="";if(Array.isArray(s)){let a=0,r,n;for(;a<s.length;a++)(r=s[a])&&(n=p(r))&&(e&&(e+=" "),e+=n);return e}for(let a in s)s[a]&&(e&&(e+=" "),e+=a);return e}function y(...s){let e="",a=0,r,n;for(;a<s.length;a++)(r=s[a])&&(n=p(r))&&(e&&(e+=" "),e+=n);return e}function m(s,e,a){let r={...s};if(e)for(let n in e)e[n]!==void 0&&(!a||!a.includes(n))&&(r[n]=e[n]);return r}var x=s=>{let{base:e,variants:a,compoundVariants:r,defaultVariants:n,classNameResolver:u=y}=s;return a?i=>{let o=m(n,i,["className"]),c=[];for(let l in o){let t=a[l]?.[o[l]];t&&c.push(t);}if(r)for(let l=0;l<r.length;l++){let t=r[l],V=true;for(let f in t){if(f==="className")continue;let d=t[f],C=o[f];if(Array.isArray(d)?!d.includes(C):d!==C){V=false;break}}V&&t.className&&c.push(t.className);}return u(e,c,i?.className)}:i=>u(e,i?.className)},T=x;exports.cv=x;exports.default=T;//# sourceMappingURL=cv.cjs.map
|
|
2
|
+
//# sourceMappingURL=cv.cjs.map
|
package/dist/cv.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cx.ts","../src/utils/merge-props.ts","../src/cv.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","mergeProps","defaultProps","props","omitKeys","merged","k","cv","config","base","variants","compoundVariants","defaultVariants","classNameResolver","mergedProps","classValues","classValue","comp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AAOmB,CAAAA,CAAU,CAC1B,GAAInB,IAAQ,WAAA,CAAa,SACzB,IAAMqB,CAAAA,CAAQF,CAAAA,CAASnB,CAA4B,CAAA,CAC7CsB,CAAAA,CAAYN,EAAYhB,CAAG,CAAA,CACjC,GAAI,KAAA,CAAM,OAAA,CAAQqB,CAAK,CAAA,CAAI,CAACA,EAAM,QAAA,CAASC,CAAS,CAAA,CAAID,CAAAA,GAAUC,CAAAA,CAAW,CAC3EF,CAAAA,CAAU,KAAA,CACV,KACF,CACF,CACIA,CAAAA,EAAWD,CAAAA,CAAS,SAAA,EACtBF,CAAAA,CAAY,IAAA,CAAKE,EAAS,SAAS,EAEvC,CAGF,OAAOJ,CAAAA,CAAkBJ,CAAAA,CAAMM,CAAAA,CAAaZ,CAAAA,EAAO,SAAS,CAC9D,CAAA,CAnCUA,CAAAA,EAAUU,CAAAA,CAAkBJ,CAAAA,CAAMN,CAAAA,EAAO,SAAS,CAoC9D,EAEOkB,CAAAA,CAAQd","file":"cv.cjs","sourcesContent":["// credit: https://github.com/lukeed/clsx\n\nexport type ClassDictionary = Record<string, unknown>\nexport type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined\nexport type ClassArray = ClassValue[]\n\nfunction toVal(input: ClassValue): string {\n if (typeof input === 'string') {\n return input\n }\n\n if (typeof input === 'number' || typeof input === 'bigint') {\n return String(input)\n }\n\n if (input === null || input === undefined || typeof input === 'boolean') {\n return ''\n }\n\n let result = ''\n\n if (Array.isArray(input)) {\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n for (; i < input.length; i++) {\n if ((tmpClassValue = input[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n }\n\n for (const key in input) {\n if (input[key]) {\n if (result) result += ' '\n result += key\n }\n }\n\n return result\n}\n\nexport function cx(...args: ClassValue[]): string {\n let result = ''\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n\n for (; i < args.length; i++) {\n if ((tmpClassValue = args[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n}\n\nexport default cx\n","export function mergeProps<T extends Record<string, unknown>, P extends Record<string, unknown>>(\n defaultProps: T | undefined,\n props: P | undefined,\n omitKeys?: (keyof P)[]\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...defaultProps }\n\n if (props) {\n for (const k in props) {\n if (props[k] !== undefined && (!omitKeys || !omitKeys.includes(k))) {\n merged[k] = props[k]\n }\n }\n }\n\n return merged\n}\n","import { ObjectKeyPicker, ObjectKeyArrayPicker } from './utils/types'\nimport { cx, ClassValue } from './cx'\nimport { mergeProps } from './utils/merge-props'\n\nexport type ClassVariantRecord = Record<string, Record<string, ClassValue>>\n\nexport type ClassVariantExtendProps = { className: ClassValue }\n\nexport interface ClassVariantDefinition<T extends ClassVariantRecord | undefined> {\n base?: ClassValue\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & ClassVariantExtendProps)[]\n defaultVariants?: ObjectKeyPicker<T>\n classNameResolver?: typeof cx\n}\n\nexport type ClassVariantFnProps<T extends ClassVariantRecord | undefined> = T extends undefined\n ? Partial<ClassVariantExtendProps>\n : ObjectKeyPicker<T> & Partial<ClassVariantExtendProps>\n\nexport type ClassVariantFn<T extends ClassVariantRecord | undefined> = (props?: ClassVariantFnProps<T>) => string\n\nexport type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(\n config: ClassVariantDefinition<T>\n) => ClassVariantFn<T>\n\n/**\n * Creates a class variant function that combines base classes, variants, compound variants, and default variants.\n *\n * @template T - Type of the variant record\n * @param config - Configuration object for creating class variants\n * @returns A function that accepts variant props and returns a combined class string\n *\n * @example\n * ```typescript\n * const button = cv({\n * base: 'px-4 py-2 rounded',\n * variants: {\n * color: {\n * primary: 'bg-blue-500 text-white',\n * secondary: 'bg-gray-500 text-white'\n * },\n * size: {\n * sm: 'text-sm',\n * lg: 'text-lg'\n * }\n * },\n * defaultVariants: {\n * color: 'primary',\n * size: 'sm'\n * }\n * });\n *\n * button(); // => 'px-4 py-2 rounded bg-blue-500 text-white text-sm'\n * button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'\n * ```\n */\nexport const cv: ClassVariantCreatorFn = (config) => {\n const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config\n\n if (!variants) {\n return (props) => classNameResolver(base, props?.className)\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['className'])\n\n const classValues: ClassValue[] = []\n\n for (const key in mergedProps) {\n const classValue = variants[key]?.[mergedProps[key] as string]\n if (classValue) {\n classValues.push(classValue)\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'className') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.className) {\n classValues.push(compound.className)\n }\n }\n }\n\n return classNameResolver(base, classValues, props?.className)\n }\n}\n\nexport default cv\n"]}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.cjs';
|
|
2
|
+
import cx, { ClassValue } from './cx.cjs';
|
|
3
|
+
import 'csstype';
|
|
4
|
+
|
|
5
|
+
type ClassVariantRecord = Record<string, Record<string, ClassValue>>;
|
|
6
|
+
type ClassVariantExtendProps = {
|
|
5
7
|
className: ClassValue;
|
|
6
8
|
};
|
|
7
|
-
|
|
9
|
+
interface ClassVariantDefinition<T extends ClassVariantRecord | undefined> {
|
|
8
10
|
base?: ClassValue;
|
|
9
11
|
variants?: T;
|
|
10
12
|
compoundVariants?: (ObjectKeyArrayPicker<T> & ClassVariantExtendProps)[];
|
|
11
13
|
defaultVariants?: ObjectKeyPicker<T>;
|
|
12
14
|
classNameResolver?: typeof cx;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
type ClassVariantFnProps<T extends ClassVariantRecord | undefined> = T extends undefined ? Partial<ClassVariantExtendProps> : ObjectKeyPicker<T> & Partial<ClassVariantExtendProps>;
|
|
17
|
+
type ClassVariantFn<T extends ClassVariantRecord | undefined> = (props?: ClassVariantFnProps<T>) => string;
|
|
18
|
+
type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(config: ClassVariantDefinition<T>) => ClassVariantFn<T>;
|
|
17
19
|
/**
|
|
18
20
|
* Creates a class variant function that combines base classes, variants, compound variants, and default variants.
|
|
19
21
|
*
|
|
@@ -45,5 +47,6 @@ export type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(c
|
|
|
45
47
|
* button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
declare const cv: ClassVariantCreatorFn;
|
|
51
|
+
|
|
52
|
+
export { type ClassVariantCreatorFn, type ClassVariantDefinition, type ClassVariantExtendProps, type ClassVariantFn, type ClassVariantFnProps, type ClassVariantRecord, cv, cv as default };
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.js';
|
|
2
|
+
import cx, { ClassValue } from './cx.js';
|
|
3
|
+
import 'csstype';
|
|
4
|
+
|
|
5
|
+
type ClassVariantRecord = Record<string, Record<string, ClassValue>>;
|
|
6
|
+
type ClassVariantExtendProps = {
|
|
5
7
|
className: ClassValue;
|
|
6
8
|
};
|
|
7
|
-
|
|
9
|
+
interface ClassVariantDefinition<T extends ClassVariantRecord | undefined> {
|
|
8
10
|
base?: ClassValue;
|
|
9
11
|
variants?: T;
|
|
10
12
|
compoundVariants?: (ObjectKeyArrayPicker<T> & ClassVariantExtendProps)[];
|
|
11
13
|
defaultVariants?: ObjectKeyPicker<T>;
|
|
12
14
|
classNameResolver?: typeof cx;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
type ClassVariantFnProps<T extends ClassVariantRecord | undefined> = T extends undefined ? Partial<ClassVariantExtendProps> : ObjectKeyPicker<T> & Partial<ClassVariantExtendProps>;
|
|
17
|
+
type ClassVariantFn<T extends ClassVariantRecord | undefined> = (props?: ClassVariantFnProps<T>) => string;
|
|
18
|
+
type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(config: ClassVariantDefinition<T>) => ClassVariantFn<T>;
|
|
17
19
|
/**
|
|
18
20
|
* Creates a class variant function that combines base classes, variants, compound variants, and default variants.
|
|
19
21
|
*
|
|
@@ -45,5 +47,6 @@ export type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(c
|
|
|
45
47
|
* button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
declare const cv: ClassVariantCreatorFn;
|
|
51
|
+
|
|
52
|
+
export { type ClassVariantCreatorFn, type ClassVariantDefinition, type ClassVariantExtendProps, type ClassVariantFn, type ClassVariantFnProps, type ClassVariantRecord, cv, cv as default };
|
package/dist/cv.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function p(s){if(typeof s=="string")return s;if(typeof s=="number"||typeof s=="bigint")return String(s);if(s==null||typeof s=="boolean")return "";let e="";if(Array.isArray(s)){let a=0,r,n;for(;a<s.length;a++)(r=s[a])&&(n=p(r))&&(e&&(e+=" "),e+=n);return e}for(let a in s)s[a]&&(e&&(e+=" "),e+=a);return e}function y(...s){let e="",a=0,r,n;for(;a<s.length;a++)(r=s[a])&&(n=p(r))&&(e&&(e+=" "),e+=n);return e}function m(s,e,a){let r={...s};if(e)for(let n in e)e[n]!==void 0&&(!a||!a.includes(n))&&(r[n]=e[n]);return r}var x=s=>{let{base:e,variants:a,compoundVariants:r,defaultVariants:n,classNameResolver:u=y}=s;return a?i=>{let o=m(n,i,["className"]),c=[];for(let l in o){let t=a[l]?.[o[l]];t&&c.push(t);}if(r)for(let l=0;l<r.length;l++){let t=r[l],V=true;for(let f in t){if(f==="className")continue;let d=t[f],C=o[f];if(Array.isArray(d)?!d.includes(C):d!==C){V=false;break}}V&&t.className&&c.push(t.className);}return u(e,c,i?.className)}:i=>u(e,i?.className)},T=x;export{x as cv,T as default};//# sourceMappingURL=cv.js.map
|
|
2
|
+
//# sourceMappingURL=cv.js.map
|
package/dist/cv.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cx.ts","../src/utils/merge-props.ts","../src/cv.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","mergeProps","defaultProps","props","omitKeys","merged","k","cv","config","base","variants","compoundVariants","defaultVariants","classNameResolver","mergedProps","classValues","classValue","compound","matches","value","propValue","cv_default"],"mappings":"AAMA,SAASA,CAAAA,CAAMC,CAAAA,CAA2B,CACxC,GAAI,OAAOA,CAAAA,EAAU,QAAA,CACnB,OAAOA,CAAAA,CAGT,GAAI,OAAOA,CAAAA,EAAU,UAAY,OAAOA,CAAAA,EAAU,QAAA,CAChD,OAAO,MAAA,CAAOA,CAAK,CAAA,CAGrB,GAAIA,GAAU,IAAA,EAA+B,OAAOA,CAAAA,EAAU,SAAA,CAC5D,OAAO,EAAA,CAGT,IAAIC,CAAAA,CAAS,GAEb,GAAI,KAAA,CAAM,OAAA,CAAQD,CAAK,CAAA,CAAG,CACxB,IAAIE,CAAAA,CAAI,CAAA,CACJC,CAAAA,CACAC,CAAAA,CACJ,KAAOF,CAAAA,CAAIF,CAAAA,C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AO,SAAS,CAC9D,CAAA,CAnCUA,CAAAA,EAAUU,CAAAA,CAAkBJ,CAAAA,CAAMN,CAAAA,EAAO,SAAS,CAoC9D,EAEOkB,CAAAA,CAAQd","file":"cv.js","sourcesContent":["// credit: https://github.com/lukeed/clsx\n\nexport type ClassDictionary = Record<string, unknown>\nexport type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined\nexport type ClassArray = ClassValue[]\n\nfunction toVal(input: ClassValue): string {\n if (typeof input === 'string') {\n return input\n }\n\n if (typeof input === 'number' || typeof input === 'bigint') {\n return String(input)\n }\n\n if (input === null || input === undefined || typeof input === 'boolean') {\n return ''\n }\n\n let result = ''\n\n if (Array.isArray(input)) {\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n for (; i < input.length; i++) {\n if ((tmpClassValue = input[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n }\n\n for (const key in input) {\n if (input[key]) {\n if (result) result += ' '\n result += key\n }\n }\n\n return result\n}\n\nexport function cx(...args: ClassValue[]): string {\n let result = ''\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n\n for (; i < args.length; i++) {\n if ((tmpClassValue = args[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n}\n\nexport default cx\n","export function mergeProps<T extends Record<string, unknown>, P extends Record<string, unknown>>(\n defaultProps: T | undefined,\n props: P | undefined,\n omitKeys?: (keyof P)[]\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...defaultProps }\n\n if (props) {\n for (const k in props) {\n if (props[k] !== undefined && (!omitKeys || !omitKeys.includes(k))) {\n merged[k] = props[k]\n }\n }\n }\n\n return merged\n}\n","import { ObjectKeyPicker, ObjectKeyArrayPicker } from './utils/types'\nimport { cx, ClassValue } from './cx'\nimport { mergeProps } from './utils/merge-props'\n\nexport type ClassVariantRecord = Record<string, Record<string, ClassValue>>\n\nexport type ClassVariantExtendProps = { className: ClassValue }\n\nexport interface ClassVariantDefinition<T extends ClassVariantRecord | undefined> {\n base?: ClassValue\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & ClassVariantExtendProps)[]\n defaultVariants?: ObjectKeyPicker<T>\n classNameResolver?: typeof cx\n}\n\nexport type ClassVariantFnProps<T extends ClassVariantRecord | undefined> = T extends undefined\n ? Partial<ClassVariantExtendProps>\n : ObjectKeyPicker<T> & Partial<ClassVariantExtendProps>\n\nexport type ClassVariantFn<T extends ClassVariantRecord | undefined> = (props?: ClassVariantFnProps<T>) => string\n\nexport type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(\n config: ClassVariantDefinition<T>\n) => ClassVariantFn<T>\n\n/**\n * Creates a class variant function that combines base classes, variants, compound variants, and default variants.\n *\n * @template T - Type of the variant record\n * @param config - Configuration object for creating class variants\n * @returns A function that accepts variant props and returns a combined class string\n *\n * @example\n * ```typescript\n * const button = cv({\n * base: 'px-4 py-2 rounded',\n * variants: {\n * color: {\n * primary: 'bg-blue-500 text-white',\n * secondary: 'bg-gray-500 text-white'\n * },\n * size: {\n * sm: 'text-sm',\n * lg: 'text-lg'\n * }\n * },\n * defaultVariants: {\n * color: 'primary',\n * size: 'sm'\n * }\n * });\n *\n * button(); // => 'px-4 py-2 rounded bg-blue-500 text-white text-sm'\n * button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'\n * ```\n */\nexport const cv: ClassVariantCreatorFn = (config) => {\n const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config\n\n if (!variants) {\n return (props) => classNameResolver(base, props?.className)\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['className'])\n\n const classValues: ClassValue[] = []\n\n for (const key in mergedProps) {\n const classValue = variants[key]?.[mergedProps[key] as string]\n if (classValue) {\n classValues.push(classValue)\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'className') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.className) {\n classValues.push(compound.className)\n }\n }\n }\n\n return classNameResolver(base, classValues, props?.className)\n }\n}\n\nexport default cv\n"]}
|
package/dist/cx.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});function a(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="bigint")return String(e);if(e==null||typeof e=="boolean")return "";let l="";if(Array.isArray(e)){let r=0,t,s;for(;r<e.length;r++)(t=e[r])&&(s=a(t))&&(l&&(l+=" "),l+=s);return l}for(let r in e)e[r]&&(l&&(l+=" "),l+=r);return l}function n(...e){let l="",r=0,t,s;for(;r<e.length;r++)(t=e[r])&&(s=a(t))&&(l&&(l+=" "),l+=s);return l}var f=n;exports.cx=n;exports.default=f;//# sourceMappingURL=cx.cjs.map
|
|
2
|
+
//# sourceMappingURL=cx.cjs.map
|
package/dist/cx.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cx.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","cx_default"],"mappings":"sEAMA,SAASA,CAAAA,CAAMC,CAAAA,CAA2B,CACxC,GAAI,OAAOA,GAAU,QAAA,CACnB,OAAOA,CAAAA,CAGT,GAAI,OAAOA,CAAAA,EAAU,UAAY,OAAOA,CAAAA,EAAU,QAAA,CAChD,OAAO,MAAA,CAAOA,CAAK,EAGrB,GAAIA,CAAAA,EAAU,IAAA,EAA+B,OAAOA,CAAAA,EAAU,SAAA,CAC5D,OAAO,EAAA,CAGT,IAAIC,CAAAA,CAAS,EAAA,CAEb,GAAI,KAAA,CAAM,QAAQD,CAAK,CAAA,CAAG,CACxB,IAAIE,CAAAA,CAAI,CAAA,CACJC,EACAC,CAAAA,CACJ,KAAOF,CAAAA,CAAIF,CAAAA,CAAM,MAAA,CAAQE,CAAAA,EAAAA,CAAAA,CAClBC,CAAAA,CAAgBH,CAAAA,CAAME,CAAC,CAAA,IACrBE,CAAAA,CAAeL,CAAAA,CAAMI,CAAa,CAAA,CAAA,GACjCF,IAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAA,IAAWI,CAAAA,IAAOL,CAAAA,CACZA,CAAAA,CAAMK,CAAG,CAAA,GACPJ,IAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUI,CAAAA,CAAAA,CAId,OAAOJ,CACT,CAEO,SAASK,CAAAA,CAAAA,GAAMC,CAAAA,CAA4B,CAChD,IAAIN,CAAAA,CAAS,GACTC,CAAAA,CAAI,CAAA,CACJC,CAAAA,CACAC,CAAAA,CAEJ,KAAOF,CAAAA,CAAIK,EAAK,MAAA,CAAQL,CAAAA,EAAAA,CAAAA,CACjBC,CAAAA,CAAgBI,CAAAA,CAAKL,CAAC,CAAA,IACpBE,EAAeL,CAAAA,CAAMI,CAAa,CAAA,CAAA,GACjCF,CAAAA,GAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAOO,CAAAA,CAAQF","file":"cx.cjs","sourcesContent":["// credit: https://github.com/lukeed/clsx\n\nexport type ClassDictionary = Record<string, unknown>\nexport type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined\nexport type ClassArray = ClassValue[]\n\nfunction toVal(input: ClassValue): string {\n if (typeof input === 'string') {\n return input\n }\n\n if (typeof input === 'number' || typeof input === 'bigint') {\n return String(input)\n }\n\n if (input === null || input === undefined || typeof input === 'boolean') {\n return ''\n }\n\n let result = ''\n\n if (Array.isArray(input)) {\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n for (; i < input.length; i++) {\n if ((tmpClassValue = input[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n }\n\n for (const key in input) {\n if (input[key]) {\n if (result) result += ' '\n result += key\n }\n }\n\n return result\n}\n\nexport function cx(...args: ClassValue[]): string {\n let result = ''\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n\n for (; i < args.length; i++) {\n if ((tmpClassValue = args[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n}\n\nexport default cx\n"]}
|
package/dist/cx.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type ClassDictionary = Record<string, unknown>;
|
|
2
|
+
type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined;
|
|
3
|
+
type ClassArray = ClassValue[];
|
|
4
|
+
declare function cx(...args: ClassValue[]): string;
|
|
5
|
+
|
|
6
|
+
export { type ClassArray, type ClassDictionary, type ClassValue, cx, cx as default };
|
package/dist/cx.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type ClassDictionary = Record<string, unknown>;
|
|
2
|
+
type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined;
|
|
3
|
+
type ClassArray = ClassValue[];
|
|
4
|
+
declare function cx(...args: ClassValue[]): string;
|
|
5
|
+
|
|
6
|
+
export { type ClassArray, type ClassDictionary, type ClassValue, cx, cx as default };
|
package/dist/cx.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function a(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="bigint")return String(e);if(e==null||typeof e=="boolean")return "";let l="";if(Array.isArray(e)){let r=0,t,s;for(;r<e.length;r++)(t=e[r])&&(s=a(t))&&(l&&(l+=" "),l+=s);return l}for(let r in e)e[r]&&(l&&(l+=" "),l+=r);return l}function n(...e){let l="",r=0,t,s;for(;r<e.length;r++)(t=e[r])&&(s=a(t))&&(l&&(l+=" "),l+=s);return l}var f=n;export{n as cx,f as default};//# sourceMappingURL=cx.js.map
|
|
2
|
+
//# sourceMappingURL=cx.js.map
|
package/dist/cx.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cx.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","cx_default"],"mappings":"AAMA,SAASA,CAAAA,CAAMC,CAAAA,CAA2B,CACxC,GAAI,OAAOA,GAAU,QAAA,CACnB,OAAOA,CAAAA,CAGT,GAAI,OAAOA,CAAAA,EAAU,UAAY,OAAOA,CAAAA,EAAU,QAAA,CAChD,OAAO,MAAA,CAAOA,CAAK,EAGrB,GAAIA,CAAAA,EAAU,IAAA,EAA+B,OAAOA,CAAAA,EAAU,SAAA,CAC5D,OAAO,EAAA,CAGT,IAAIC,CAAAA,CAAS,EAAA,CAEb,GAAI,KAAA,CAAM,QAAQD,CAAK,CAAA,CAAG,CACxB,IAAIE,CAAAA,CAAI,CAAA,CACJC,EACAC,CAAAA,CACJ,KAAOF,CAAAA,CAAIF,CAAAA,CAAM,MAAA,CAAQE,CAAAA,EAAAA,CAAAA,CAClBC,CAAAA,CAAgBH,CAAAA,CAAME,CAAC,CAAA,IACrBE,CAAAA,CAAeL,CAAAA,CAAMI,CAAa,CAAA,CAAA,GACjCF,IAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAA,IAAWI,CAAAA,IAAOL,CAAAA,CACZA,CAAAA,CAAMK,CAAG,CAAA,GACPJ,IAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUI,CAAAA,CAAAA,CAId,OAAOJ,CACT,CAEO,SAASK,CAAAA,CAAAA,GAAMC,CAAAA,CAA4B,CAChD,IAAIN,CAAAA,CAAS,GACTC,CAAAA,CAAI,CAAA,CACJC,CAAAA,CACAC,CAAAA,CAEJ,KAAOF,CAAAA,CAAIK,EAAK,MAAA,CAAQL,CAAAA,EAAAA,CAAAA,CACjBC,CAAAA,CAAgBI,CAAAA,CAAKL,CAAC,CAAA,IACpBE,EAAeL,CAAAA,CAAMI,CAAa,CAAA,CAAA,GACjCF,CAAAA,GAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAOO,CAAAA,CAAQF","file":"cx.js","sourcesContent":["// credit: https://github.com/lukeed/clsx\n\nexport type ClassDictionary = Record<string, unknown>\nexport type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined\nexport type ClassArray = ClassValue[]\n\nfunction toVal(input: ClassValue): string {\n if (typeof input === 'string') {\n return input\n }\n\n if (typeof input === 'number' || typeof input === 'bigint') {\n return String(input)\n }\n\n if (input === null || input === undefined || typeof input === 'boolean') {\n return ''\n }\n\n let result = ''\n\n if (Array.isArray(input)) {\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n for (; i < input.length; i++) {\n if ((tmpClassValue = input[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n }\n\n for (const key in input) {\n if (input[key]) {\n if (result) result += ' '\n result += key\n }\n }\n\n return result\n}\n\nexport function cx(...args: ClassValue[]): string {\n let result = ''\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n\n for (; i < args.length; i++) {\n if ((tmpClassValue = args[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n}\n\nexport default cx\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';function C(a){if(typeof a=="string")return a;if(typeof a=="number"||typeof a=="bigint")return String(a);if(a==null||typeof a=="boolean")return "";let s="";if(Array.isArray(a)){let r=0,l,c;for(;r<a.length;r++)(l=a[r])&&(c=C(l))&&(s&&(s+=" "),s+=c);return s}for(let r in a)a[r]&&(s&&(s+=" "),s+=r);return s}function V(...a){let s="",r=0,l,c;for(;r<a.length;r++)(l=a[r])&&(c=C(l))&&(s&&(s+=" "),s+=c);return s}function S(a,s,r){let l={...a};if(s)for(let c in s)s[c]!==void 0&&(!r||!r.includes(c))&&(l[c]=s[c]);return l}var k=a=>{let{base:s,variants:r,compoundVariants:l,defaultVariants:c,classNameResolver:p=V}=a;return r?f=>{let d=S(c,f,["className"]),n=[];for(let e in d){let i=r[e]?.[d[e]];i&&n.push(i);}if(l)for(let e=0;e<l.length;e++){let i=l[e],t=true;for(let o in i){if(o==="className")continue;let y=i[o],u=d[o];if(Array.isArray(y)?!y.includes(u):y!==u){t=false;break}}t&&i.className&&n.push(i.className);}return p(s,n,f?.className)}:f=>p(s,f?.className)};var A=a=>{let{slots:s,base:r,variants:l,compoundVariants:c,defaultVariants:p,classNameResolver:f=V}=a;return l?d=>{let n=S(p,d,["classNames"]),e={};for(let t of s)r?.[t]?e[t]=Array.isArray(r[t])?[...r[t]]:[r[t]]:e[t]=[];for(let t in n){let o=l[t]?.[n[t]];if(o)for(let y in o)e[y]?.push(o[y]);}if(c)for(let t=0;t<c.length;t++){let o=c[t],y=true;for(let u in o){if(u==="classNames")continue;let x=o[u],m=n[u];if(Array.isArray(x)?!x.includes(m):x!==m){y=false;break}}if(y&&o.classNames)for(let u in o.classNames)e[u]?.push(o.classNames[u]);}if(d?.classNames)for(let t in d.classNames)e[t]?.push(d.classNames[t]);let i={};for(let t in e)i[t]=f(e[t]);return i}:d=>{let n={};for(let e of s)n[e]=f(r?.[e],d?.classNames?.[e]);return n}};var E=a=>{let{base:s,variants:r,compoundVariants:l,defaultVariants:c}=a;return r?p=>{let f={...s},d=S(c,p,["style"]);for(let n in d){let e=r[n]?.[d[n]];e&&Object.assign(f,e);}if(l)for(let n=0;n<l.length;n++){let e=l[n],i=true;for(let t in e){if(t==="style")continue;let o=e[t],y=d[t];if(Array.isArray(o)?!o.includes(y):o!==y){i=false;break}}i&&e.style&&Object.assign(f,e.style);}return p?.style&&Object.assign(f,p.style),f}:p=>({...s,...p?.style})};var w=a=>{let{slots:s,base:r,variants:l,compoundVariants:c,defaultVariants:p}=a;return l?f=>{let d=S(p,f,["styles"]),n={};for(let e of s)n[e]={...r?.[e]};for(let e in d){let i=l[e]?.[d[e]];if(i)for(let t in i)Object.assign(n[t],i[t]);}if(c)for(let e=0;e<c.length;e++){let i=c[e],t=true;for(let o in i){if(o==="styles")continue;let y=i[o],u=d[o];if(Array.isArray(y)?!y.includes(u):y!==u){t=false;break}}if(t&&i.styles)for(let o in i.styles)Object.assign(n[o],i.styles[o]);}if(f?.styles)for(let e in f.styles)Object.assign(n[e],f.styles[e]);return n}:f=>{let d={};for(let n of s)d[n]={...r?.[n],...f?.styles?.[n]};return d}};exports.cv=k;exports.cx=V;exports.scv=A;exports.ssv=w;exports.sv=E;//# sourceMappingURL=index.cjs.map
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cx.ts","../src/utils/merge-props.ts","../src/cv.ts","../src/scv.ts","../src/sv.ts","../src/ssv.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","mergeProps","defaultProps","props","omitKeys","merged","k","cv","config","base","variants","compoundVariants","defaultVariants","classNameResolver","mergedProps","classValues","classValue","compound","matches","value","propValue","scv","slots","slotClassValues","slot","cls","sv","styleValue","ssv","slotStyle"],"mappings":"aAMA,SAASA,CAAAA,CAAMC,EAA2B,CACxC,GAAI,OAAOA,CAAAA,EAAU,QAAA,CACnB,OAAOA,CAAAA,CAGT,GAAI,OAAOA,CAAAA,EAAU,QAAA,EAAY,OAAOA,CAAAA,EAAU,QAAA,CAChD,OAAO,MAAA,CAAOA,CAAK,CAAA,CAGrB,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7CsB,EAAYN,CAAAA,CAAYhB,CAAG,EAEjC,GAAI,KAAA,CAAM,OAAA,CAAQqB,CAAK,CAAA,CAAI,CAACA,EAAM,QAAA,CAASC,CAAS,EAAID,CAAAA,GAAUC,CAAAA,CAAW,CAC3EF,CAAAA,CAAU,KAAA,CACV,KACF,CACF,CAEA,GAAIA,GAAWD,CAAAA,CAAS,MAAA,CACtB,QAAWO,CAAAA,IAAQP,CAAAA,CAAS,OAC1B,MAAA,CAAO,MAAA,CAAOvB,CAAAA,CAAO8B,CAAI,CAAA,CAAGP,CAAAA,CAAS,OAAOO,CAAI,CAAC,EAGvD,CAGF,GAAIrB,GAAO,MAAA,CACT,IAAA,IAAWqB,CAAAA,IAAQrB,CAAAA,CAAM,MAAA,CACvB,MAAA,CAAO,OAAOT,CAAAA,CAAO8B,CAAI,EAAGrB,CAAAA,CAAM,MAAA,CAAOqB,CAAI,CAAC,CAAA,CAIlD,OAAO9B,CACT,CAAA,CA7DUS,CAAAA,EAAU,CAChB,IAAMT,CAAAA,CAAS,EAAC,CAEhB,IAAA,IAAW8B,KAAQF,CAAAA,CACjB5B,CAAAA,CAAO8B,CAAI,CAAA,CAAI,CAAE,GAAGf,IAAOe,CAAI,CAAA,CAAG,GAAGrB,CAAAA,EAAO,MAAA,GAASqB,CAAI,CAAE,CAAA,CAG7D,OAAO9B,CACT,CAsDJ","file":"index.cjs","sourcesContent":["// credit: https://github.com/lukeed/clsx\n\nexport type ClassDictionary = Record<string, unknown>\nexport type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined\nexport type ClassArray = ClassValue[]\n\nfunction toVal(input: ClassValue): string {\n if (typeof input === 'string') {\n return input\n }\n\n if (typeof input === 'number' || typeof input === 'bigint') {\n return String(input)\n }\n\n if (input === null || input === undefined || typeof input === 'boolean') {\n return ''\n }\n\n let result = ''\n\n if (Array.isArray(input)) {\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n for (; i < input.length; i++) {\n if ((tmpClassValue = input[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n }\n\n for (const key in input) {\n if (input[key]) {\n if (result) result += ' '\n result += key\n }\n }\n\n return result\n}\n\nexport function cx(...args: ClassValue[]): string {\n let result = ''\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n\n for (; i < args.length; i++) {\n if ((tmpClassValue = args[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n}\n\nexport default cx\n","export function mergeProps<T extends Record<string, unknown>, P extends Record<string, unknown>>(\n defaultProps: T | undefined,\n props: P | undefined,\n omitKeys?: (keyof P)[]\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...defaultProps }\n\n if (props) {\n for (const k in props) {\n if (props[k] !== undefined && (!omitKeys || !omitKeys.includes(k))) {\n merged[k] = props[k]\n }\n }\n }\n\n return merged\n}\n","import { ObjectKeyPicker, ObjectKeyArrayPicker } from './utils/types'\nimport { cx, ClassValue } from './cx'\nimport { mergeProps } from './utils/merge-props'\n\nexport type ClassVariantRecord = Record<string, Record<string, ClassValue>>\n\nexport type ClassVariantExtendProps = { className: ClassValue }\n\nexport interface ClassVariantDefinition<T extends ClassVariantRecord | undefined> {\n base?: ClassValue\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & ClassVariantExtendProps)[]\n defaultVariants?: ObjectKeyPicker<T>\n classNameResolver?: typeof cx\n}\n\nexport type ClassVariantFnProps<T extends ClassVariantRecord | undefined> = T extends undefined\n ? Partial<ClassVariantExtendProps>\n : ObjectKeyPicker<T> & Partial<ClassVariantExtendProps>\n\nexport type ClassVariantFn<T extends ClassVariantRecord | undefined> = (props?: ClassVariantFnProps<T>) => string\n\nexport type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(\n config: ClassVariantDefinition<T>\n) => ClassVariantFn<T>\n\n/**\n * Creates a class variant function that combines base classes, variants, compound variants, and default variants.\n *\n * @template T - Type of the variant record\n * @param config - Configuration object for creating class variants\n * @returns A function that accepts variant props and returns a combined class string\n *\n * @example\n * ```typescript\n * const button = cv({\n * base: 'px-4 py-2 rounded',\n * variants: {\n * color: {\n * primary: 'bg-blue-500 text-white',\n * secondary: 'bg-gray-500 text-white'\n * },\n * size: {\n * sm: 'text-sm',\n * lg: 'text-lg'\n * }\n * },\n * defaultVariants: {\n * color: 'primary',\n * size: 'sm'\n * }\n * });\n *\n * button(); // => 'px-4 py-2 rounded bg-blue-500 text-white text-sm'\n * button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'\n * ```\n */\nexport const cv: ClassVariantCreatorFn = (config) => {\n const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config\n\n if (!variants) {\n return (props) => classNameResolver(base, props?.className)\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['className'])\n\n const classValues: ClassValue[] = []\n\n for (const key in mergedProps) {\n const classValue = variants[key]?.[mergedProps[key] as string]\n if (classValue) {\n classValues.push(classValue)\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'className') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.className) {\n classValues.push(compound.className)\n }\n }\n }\n\n return classNameResolver(base, classValues, props?.className)\n }\n}\n\nexport default cv\n","import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord } from './utils/types'\nimport { cx, ClassValue } from './cx'\nimport { mergeProps } from './utils/merge-props'\n\nexport type SlotClassRecord<S extends string> = PartialRecord<S, ClassValue>\n\nexport type SlotClassVariantRecord<S extends string> = Record<string, Record<string, SlotClassRecord<S>>>\n\nexport type SlotClassVariantExtendProps<S extends string> = { classNames: SlotClassRecord<S> }\n\nexport interface SlotClassVariantDefinition<S extends string, T extends SlotClassVariantRecord<S> | undefined> {\n slots: S[]\n base?: SlotClassRecord<S>\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & SlotClassVariantExtendProps<S>)[]\n defaultVariants?: ObjectKeyPicker<T>\n classNameResolver?: typeof cx\n}\n\nexport type SlotClassVariantFnProps<\n S extends string,\n T extends SlotClassVariantRecord<S> | undefined,\n> = T extends undefined\n ? Partial<SlotClassVariantExtendProps<S>>\n : ObjectKeyPicker<T> & Partial<SlotClassVariantExtendProps<S>>\n\nexport type SlotClassVariantFn<S extends string, T extends SlotClassVariantRecord<S> | undefined> = (\n props?: SlotClassVariantFnProps<S, T>\n) => Record<S, string>\n\nexport type SlotClassVariantCreatorFn = <S extends string, T extends SlotClassVariantRecord<S> | undefined>(\n config: SlotClassVariantDefinition<S, T>\n) => SlotClassVariantFn<S, T>\n\n/**\n * Creates a slot-based class variant function that manages class names for multiple slots with variants.\n *\n * @param config - Configuration object for creating the variant function\n * @returns A function that accepts variant props and returns class names for each slot\n *\n * @example\n * ```typescript\n * const button = scv({\n * slots: ['root', 'icon'],\n * base: {\n * root: 'btn',\n * icon: 'btn-icon'\n * },\n * variants: {\n * size: {\n * sm: {\n * root: 'btn-sm',\n * icon: 'icon-sm'\n * },\n * lg: {\n * root: 'btn-lg',\n * icon: 'icon-lg'\n * }\n * }\n * },\n * defaultVariants: {\n * size: 'sm'\n * }\n * })\n *\n * // Usage\n * const classes = button({ size: 'lg' })\n * // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }\n * ```\n */\nexport const scv: SlotClassVariantCreatorFn = (config) => {\n const { slots, base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config\n\n if (!variants) {\n return (props) => {\n const result = {} as Record<(typeof slots)[number], string>\n\n for (const slot of slots) {\n result[slot] = classNameResolver(base?.[slot], props?.classNames?.[slot])\n }\n\n return result\n }\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['classNames'])\n\n const slotClassValues = {} as Record<(typeof slots)[number], ClassValue[]>\n\n for (const slot of slots) {\n if (base?.[slot]) {\n slotClassValues[slot] = Array.isArray(base[slot]) ? [...base[slot]] : [base[slot]]\n } else {\n slotClassValues[slot] = []\n }\n }\n\n for (const key in mergedProps) {\n const cls = variants[key]?.[mergedProps[key] as string]\n\n if (cls) {\n for (const slot in cls) {\n slotClassValues[slot]?.push(cls[slot])\n }\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'classNames') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.classNames) {\n for (const slot in compound.classNames) {\n slotClassValues[slot]?.push(compound.classNames[slot])\n }\n }\n }\n }\n\n if (props?.classNames) {\n for (const slot in props.classNames) {\n slotClassValues[slot]?.push(props.classNames[slot])\n }\n }\n\n const result = {} as Record<(typeof slots)[number], string>\n\n for (const slot in slotClassValues) {\n result[slot] = classNameResolver(slotClassValues[slot])\n }\n\n return result\n }\n}\n\nexport default scv\n","import { CssProperties, ObjectKeyArrayPicker, ObjectKeyPicker } from './utils/types'\nimport { mergeProps } from './utils/merge-props'\n\nexport type StyleVariantRecord = Record<string, Record<string, CssProperties>>\n\nexport type StyleVariantExtendProps = { style: CssProperties }\n\nexport interface StyleVariantDefinition<T extends StyleVariantRecord | undefined> {\n base?: CssProperties\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & StyleVariantExtendProps)[]\n defaultVariants?: ObjectKeyPicker<T>\n}\n\nexport type StyleVariantFnProps<T extends StyleVariantRecord | undefined> = T extends undefined\n ? Partial<StyleVariantExtendProps>\n : ObjectKeyPicker<T> & Partial<StyleVariantExtendProps>\n\nexport type StyleVariantFn<T extends StyleVariantRecord | undefined> = (props?: StyleVariantFnProps<T>) => CssProperties\n\nexport type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(\n config: StyleVariantDefinition<T>\n) => StyleVariantFn<T>\n\n/**\n * Creates a style variant function based on the provided configuration.\n *\n * @template T - The type of the style variant record.\n * @param {StyleVariantDefinition<T>} config - The configuration object for style variants.\n * @returns {StyleVariantFn<T>} A function that takes props and returns the computed CSS properties.\n *\n * @example\n * ```typescript\n *\n * const makeStyle = sv({\n * base: { color: 'black' },\n * variants: {\n * size: {\n * small: { fontSize: '12px' },\n * large: { fontSize: '24px' }\n * }\n * },\n * compoundVariants: [\n * { size: 'large', style: { fontWeight: 'bold' } }\n * ],\n * defaultVariants: { size: 'small' }\n * });\n *\n * const style = makeStyle({ size: 'large' });\n * // style = { color: 'black', fontSize: '24px', fontWeight: 'bold' }\n * ```\n */\nexport const sv: StyleVariantCreatorFn = (config) => {\n const { base, variants, compoundVariants, defaultVariants } = config\n\n if (!variants) {\n return (props) => ({ ...base, ...props?.style })\n }\n\n return (props) => {\n const result: CssProperties = { ...base }\n\n const mergedProps = mergeProps(defaultVariants, props, ['style'])\n\n for (const key in mergedProps) {\n const styleValue = variants[key]?.[mergedProps[key] as string]\n if (styleValue) {\n Object.assign(result, styleValue)\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'style') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.style) {\n Object.assign(result, compound.style)\n }\n }\n }\n\n if (props?.style) {\n Object.assign(result, props.style)\n }\n\n return result\n }\n}\n\nexport default sv\n","import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord, CssProperties } from './utils/types'\nimport { mergeProps } from './utils/merge-props'\n\nexport type SlotStyleRecord<S extends string> = PartialRecord<S, CssProperties>\n\nexport type SlotStyleVariantRecord<S extends string> = Record<string, Record<string, SlotStyleRecord<S>>>\n\nexport type SlotStyleVariantExtendProps<S extends string> = { styles: SlotStyleRecord<S> }\n\nexport interface SlotStyleVariantDefinition<S extends string, T extends SlotStyleVariantRecord<S> | undefined> {\n slots: S[]\n base?: SlotStyleRecord<S>\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & SlotStyleVariantExtendProps<S>)[]\n defaultVariants?: ObjectKeyPicker<T>\n}\n\nexport type SlotStyleVariantFnProps<\n S extends string,\n T extends SlotStyleVariantRecord<S> | undefined,\n> = T extends undefined\n ? Partial<SlotStyleVariantExtendProps<S>>\n : ObjectKeyPicker<T> & Partial<SlotStyleVariantExtendProps<S>>\n\nexport type SlotStyleVariantFn<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = (\n props?: SlotStyleVariantFnProps<S, T>\n) => Record<S, CssProperties>\n\nexport type SlotStyleVariantCreatorFn = <S extends string, T extends SlotStyleVariantRecord<S> | undefined>(\n config: SlotStyleVariantDefinition<S, T>\n) => SlotStyleVariantFn<S, T>\n\n/**\n * Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.\n *\n * @param config - Configuration object for creating style variants\n * @returns A function that accepts variant props and returns composed styles for each slot\n *\n * @example\n * ```ts\n * const buttonStyles = csv({\n * slots: ['root', 'icon'],\n * base: {\n * root: { padding: '8px' },\n * icon: { size: '16px' }\n * },\n * variants: {\n * size: {\n * small: {\n * root: { padding: '4px' },\n * icon: { size: '12px' }\n * },\n * large: {\n * root: { padding: '12px' },\n * icon: { size: '20px' }\n * }\n * }\n * }\n * });\n *\n * // Usage\n * const styles = buttonStyles({ size: 'small' });\n * // => { root: { padding: '4px' }, icon: { size: '12px' } }\n * ```\n */\nexport const ssv: SlotStyleVariantCreatorFn = (config) => {\n const { slots, base, variants, compoundVariants, defaultVariants } = config\n\n if (!variants) {\n return (props) => {\n const result = {} as Record<(typeof slots)[number], CssProperties>\n\n for (const slot of slots) {\n result[slot] = { ...base?.[slot], ...props?.styles?.[slot] }\n }\n\n return result\n }\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['styles'])\n\n const result = {} as Record<(typeof slots)[number], CssProperties>\n\n for (const slot of slots) {\n result[slot] = { ...base?.[slot] }\n }\n\n for (const key in mergedProps) {\n const slotStyle = variants[key]?.[mergedProps[key] as string]\n\n if (slotStyle) {\n for (const slot in slotStyle) {\n Object.assign(result[slot], slotStyle[slot])\n }\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n\n for (const key in compound) {\n if (key === 'styles') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n\n if (matches && compound.styles) {\n for (const slot in compound.styles) {\n Object.assign(result[slot], compound.styles[slot])\n }\n }\n }\n }\n\n if (props?.styles) {\n for (const slot in props.styles) {\n Object.assign(result[slot], props.styles[slot])\n }\n }\n\n return result\n }\n}\n\nexport default ssv\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ClassArray, ClassDictionary, ClassValue, default as cx } from './cx.cjs';
|
|
2
|
+
export { ClassVariantCreatorFn, ClassVariantDefinition, ClassVariantExtendProps, ClassVariantFn, ClassVariantFnProps, ClassVariantRecord, default as cv } from './cv.cjs';
|
|
3
|
+
export { SlotClassRecord, SlotClassVariantCreatorFn, SlotClassVariantDefinition, SlotClassVariantExtendProps, SlotClassVariantFn, SlotClassVariantFnProps, SlotClassVariantRecord, default as scv } from './scv.cjs';
|
|
4
|
+
export { StyleVariantCreatorFn, StyleVariantDefinition, StyleVariantExtendProps, StyleVariantFn, StyleVariantFnProps, StyleVariantRecord, default as sv } from './sv.cjs';
|
|
5
|
+
export { SlotStyleRecord, SlotStyleVariantCreatorFn, SlotStyleVariantDefinition, SlotStyleVariantExtendProps, SlotStyleVariantFn, SlotStyleVariantFnProps, SlotStyleVariantRecord, default as ssv } from './ssv.cjs';
|
|
6
|
+
import './types-BXKyjXhG.cjs';
|
|
7
|
+
import 'csstype';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ClassArray, ClassDictionary, ClassValue, default as cx } from './cx.js';
|
|
2
|
+
export { ClassVariantCreatorFn, ClassVariantDefinition, ClassVariantExtendProps, ClassVariantFn, ClassVariantFnProps, ClassVariantRecord, default as cv } from './cv.js';
|
|
3
|
+
export { SlotClassRecord, SlotClassVariantCreatorFn, SlotClassVariantDefinition, SlotClassVariantExtendProps, SlotClassVariantFn, SlotClassVariantFnProps, SlotClassVariantRecord, default as scv } from './scv.js';
|
|
4
|
+
export { StyleVariantCreatorFn, StyleVariantDefinition, StyleVariantExtendProps, StyleVariantFn, StyleVariantFnProps, StyleVariantRecord, default as sv } from './sv.js';
|
|
5
|
+
export { SlotStyleRecord, SlotStyleVariantCreatorFn, SlotStyleVariantDefinition, SlotStyleVariantExtendProps, SlotStyleVariantFn, SlotStyleVariantFnProps, SlotStyleVariantRecord, default as ssv } from './ssv.js';
|
|
6
|
+
import './types-BXKyjXhG.js';
|
|
7
|
+
import 'csstype';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function C(a){if(typeof a=="string")return a;if(typeof a=="number"||typeof a=="bigint")return String(a);if(a==null||typeof a=="boolean")return "";let s="";if(Array.isArray(a)){let r=0,l,c;for(;r<a.length;r++)(l=a[r])&&(c=C(l))&&(s&&(s+=" "),s+=c);return s}for(let r in a)a[r]&&(s&&(s+=" "),s+=r);return s}function V(...a){let s="",r=0,l,c;for(;r<a.length;r++)(l=a[r])&&(c=C(l))&&(s&&(s+=" "),s+=c);return s}function S(a,s,r){let l={...a};if(s)for(let c in s)s[c]!==void 0&&(!r||!r.includes(c))&&(l[c]=s[c]);return l}var k=a=>{let{base:s,variants:r,compoundVariants:l,defaultVariants:c,classNameResolver:p=V}=a;return r?f=>{let d=S(c,f,["className"]),n=[];for(let e in d){let i=r[e]?.[d[e]];i&&n.push(i);}if(l)for(let e=0;e<l.length;e++){let i=l[e],t=true;for(let o in i){if(o==="className")continue;let y=i[o],u=d[o];if(Array.isArray(y)?!y.includes(u):y!==u){t=false;break}}t&&i.className&&n.push(i.className);}return p(s,n,f?.className)}:f=>p(s,f?.className)};var A=a=>{let{slots:s,base:r,variants:l,compoundVariants:c,defaultVariants:p,classNameResolver:f=V}=a;return l?d=>{let n=S(p,d,["classNames"]),e={};for(let t of s)r?.[t]?e[t]=Array.isArray(r[t])?[...r[t]]:[r[t]]:e[t]=[];for(let t in n){let o=l[t]?.[n[t]];if(o)for(let y in o)e[y]?.push(o[y]);}if(c)for(let t=0;t<c.length;t++){let o=c[t],y=true;for(let u in o){if(u==="classNames")continue;let x=o[u],m=n[u];if(Array.isArray(x)?!x.includes(m):x!==m){y=false;break}}if(y&&o.classNames)for(let u in o.classNames)e[u]?.push(o.classNames[u]);}if(d?.classNames)for(let t in d.classNames)e[t]?.push(d.classNames[t]);let i={};for(let t in e)i[t]=f(e[t]);return i}:d=>{let n={};for(let e of s)n[e]=f(r?.[e],d?.classNames?.[e]);return n}};var E=a=>{let{base:s,variants:r,compoundVariants:l,defaultVariants:c}=a;return r?p=>{let f={...s},d=S(c,p,["style"]);for(let n in d){let e=r[n]?.[d[n]];e&&Object.assign(f,e);}if(l)for(let n=0;n<l.length;n++){let e=l[n],i=true;for(let t in e){if(t==="style")continue;let o=e[t],y=d[t];if(Array.isArray(o)?!o.includes(y):o!==y){i=false;break}}i&&e.style&&Object.assign(f,e.style);}return p?.style&&Object.assign(f,p.style),f}:p=>({...s,...p?.style})};var w=a=>{let{slots:s,base:r,variants:l,compoundVariants:c,defaultVariants:p}=a;return l?f=>{let d=S(p,f,["styles"]),n={};for(let e of s)n[e]={...r?.[e]};for(let e in d){let i=l[e]?.[d[e]];if(i)for(let t in i)Object.assign(n[t],i[t]);}if(c)for(let e=0;e<c.length;e++){let i=c[e],t=true;for(let o in i){if(o==="styles")continue;let y=i[o],u=d[o];if(Array.isArray(y)?!y.includes(u):y!==u){t=false;break}}if(t&&i.styles)for(let o in i.styles)Object.assign(n[o],i.styles[o]);}if(f?.styles)for(let e in f.styles)Object.assign(n[e],f.styles[e]);return n}:f=>{let d={};for(let n of s)d[n]={...r?.[n],...f?.styles?.[n]};return d}};export{k as cv,V as cx,A as scv,w as ssv,E as sv};//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cx.ts","../src/utils/merge-props.ts","../src/cv.ts","../src/scv.ts","../src/sv.ts","../src/ssv.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","mergeProps","defaultProps","props","omitKeys","merged","k","cv","config","base","variants","compoundVariants","defaultVariants","classNameResolver","mergedProps","classValues","classValue","compound","matches","value","propValue","scv","slots","slotClassValues","slot","cls","sv","styleValue","ssv","slotStyle"],"mappings":"AAMA,SAASA,CAAAA,CAAMC,EAA2B,CACxC,GAAI,OAAOA,CAAAA,EAAU,QAAA,CACnB,OAAOA,CAAAA,CAGT,GAAI,OAAOA,CAAAA,EAAU,QAAA,EAAY,OAAOA,CAAAA,EAAU,QAAA,CAChD,OAAO,MAAA,CAAOA,CAAK,CAAA,CAGrB,GAAIA,CAAAA,EAAU,IAAA,EAA+B,OAAOA,CAAAA,EAAU,SAAA,CAC5D,OAAO,EAAA,CAGT,IAAIC,EAAS,EAAA,CAEb,GAAI,KAAA,CAAM,OAAA,CAAQD,CAAK,CAAA,CAAG,CACxB,IAAIE,CAAAA,CAAI,EACJC,CAAAA,CACAC,CAAAA,CACJ,KAAOF,CAAAA,CAAIF,CAAAA,CAAM,MAAA,CAAQE,CAAAA,EAAAA,CAAAA,CAClBC,CAAAA,CAAgBH,CAAAA,CAAME,CAAC,CAAA,IACrBE,CAAAA,CAAeL,EAAMI,CAAa,CAAA,CAAA,GACjCF,IAAQA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IrB,GAAO,MAAA,CACT,IAAA,IAAWqB,CAAAA,IAAQrB,CAAAA,CAAM,MAAA,CACvB,MAAA,CAAO,OAAOT,CAAAA,CAAO8B,CAAI,EAAGrB,CAAAA,CAAM,MAAA,CAAOqB,CAAI,CAAC,CAAA,CAIlD,OAAO9B,CACT,CAAA,CA7DUS,CAAAA,EAAU,CAChB,IAAMT,CAAAA,CAAS,EAAC,CAEhB,IAAA,IAAW8B,KAAQF,CAAAA,CACjB5B,CAAAA,CAAO8B,CAAI,CAAA,CAAI,CAAE,GAAGf,IAAOe,CAAI,CAAA,CAAG,GAAGrB,CAAAA,EAAO,MAAA,GAASqB,CAAI,CAAE,CAAA,CAG7D,OAAO9B,CACT,CAsDJ","file":"index.js","sourcesContent":["// credit: https://github.com/lukeed/clsx\n\nexport type ClassDictionary = Record<string, unknown>\nexport type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined\nexport type ClassArray = ClassValue[]\n\nfunction toVal(input: ClassValue): string {\n if (typeof input === 'string') {\n return input\n }\n\n if (typeof input === 'number' || typeof input === 'bigint') {\n return String(input)\n }\n\n if (input === null || input === undefined || typeof input === 'boolean') {\n return ''\n }\n\n let result = ''\n\n if (Array.isArray(input)) {\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n for (; i < input.length; i++) {\n if ((tmpClassValue = input[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n }\n\n for (const key in input) {\n if (input[key]) {\n if (result) result += ' '\n result += key\n }\n }\n\n return result\n}\n\nexport function cx(...args: ClassValue[]): string {\n let result = ''\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n\n for (; i < args.length; i++) {\n if ((tmpClassValue = args[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n}\n\nexport default cx\n","export function mergeProps<T extends Record<string, unknown>, P extends Record<string, unknown>>(\n defaultProps: T | undefined,\n props: P | undefined,\n omitKeys?: (keyof P)[]\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...defaultProps }\n\n if (props) {\n for (const k in props) {\n if (props[k] !== undefined && (!omitKeys || !omitKeys.includes(k))) {\n merged[k] = props[k]\n }\n }\n }\n\n return merged\n}\n","import { ObjectKeyPicker, ObjectKeyArrayPicker } from './utils/types'\nimport { cx, ClassValue } from './cx'\nimport { mergeProps } from './utils/merge-props'\n\nexport type ClassVariantRecord = Record<string, Record<string, ClassValue>>\n\nexport type ClassVariantExtendProps = { className: ClassValue }\n\nexport interface ClassVariantDefinition<T extends ClassVariantRecord | undefined> {\n base?: ClassValue\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & ClassVariantExtendProps)[]\n defaultVariants?: ObjectKeyPicker<T>\n classNameResolver?: typeof cx\n}\n\nexport type ClassVariantFnProps<T extends ClassVariantRecord | undefined> = T extends undefined\n ? Partial<ClassVariantExtendProps>\n : ObjectKeyPicker<T> & Partial<ClassVariantExtendProps>\n\nexport type ClassVariantFn<T extends ClassVariantRecord | undefined> = (props?: ClassVariantFnProps<T>) => string\n\nexport type ClassVariantCreatorFn = <T extends ClassVariantRecord | undefined>(\n config: ClassVariantDefinition<T>\n) => ClassVariantFn<T>\n\n/**\n * Creates a class variant function that combines base classes, variants, compound variants, and default variants.\n *\n * @template T - Type of the variant record\n * @param config - Configuration object for creating class variants\n * @returns A function that accepts variant props and returns a combined class string\n *\n * @example\n * ```typescript\n * const button = cv({\n * base: 'px-4 py-2 rounded',\n * variants: {\n * color: {\n * primary: 'bg-blue-500 text-white',\n * secondary: 'bg-gray-500 text-white'\n * },\n * size: {\n * sm: 'text-sm',\n * lg: 'text-lg'\n * }\n * },\n * defaultVariants: {\n * color: 'primary',\n * size: 'sm'\n * }\n * });\n *\n * button(); // => 'px-4 py-2 rounded bg-blue-500 text-white text-sm'\n * button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'\n * ```\n */\nexport const cv: ClassVariantCreatorFn = (config) => {\n const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config\n\n if (!variants) {\n return (props) => classNameResolver(base, props?.className)\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['className'])\n\n const classValues: ClassValue[] = []\n\n for (const key in mergedProps) {\n const classValue = variants[key]?.[mergedProps[key] as string]\n if (classValue) {\n classValues.push(classValue)\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'className') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.className) {\n classValues.push(compound.className)\n }\n }\n }\n\n return classNameResolver(base, classValues, props?.className)\n }\n}\n\nexport default cv\n","import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord } from './utils/types'\nimport { cx, ClassValue } from './cx'\nimport { mergeProps } from './utils/merge-props'\n\nexport type SlotClassRecord<S extends string> = PartialRecord<S, ClassValue>\n\nexport type SlotClassVariantRecord<S extends string> = Record<string, Record<string, SlotClassRecord<S>>>\n\nexport type SlotClassVariantExtendProps<S extends string> = { classNames: SlotClassRecord<S> }\n\nexport interface SlotClassVariantDefinition<S extends string, T extends SlotClassVariantRecord<S> | undefined> {\n slots: S[]\n base?: SlotClassRecord<S>\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & SlotClassVariantExtendProps<S>)[]\n defaultVariants?: ObjectKeyPicker<T>\n classNameResolver?: typeof cx\n}\n\nexport type SlotClassVariantFnProps<\n S extends string,\n T extends SlotClassVariantRecord<S> | undefined,\n> = T extends undefined\n ? Partial<SlotClassVariantExtendProps<S>>\n : ObjectKeyPicker<T> & Partial<SlotClassVariantExtendProps<S>>\n\nexport type SlotClassVariantFn<S extends string, T extends SlotClassVariantRecord<S> | undefined> = (\n props?: SlotClassVariantFnProps<S, T>\n) => Record<S, string>\n\nexport type SlotClassVariantCreatorFn = <S extends string, T extends SlotClassVariantRecord<S> | undefined>(\n config: SlotClassVariantDefinition<S, T>\n) => SlotClassVariantFn<S, T>\n\n/**\n * Creates a slot-based class variant function that manages class names for multiple slots with variants.\n *\n * @param config - Configuration object for creating the variant function\n * @returns A function that accepts variant props and returns class names for each slot\n *\n * @example\n * ```typescript\n * const button = scv({\n * slots: ['root', 'icon'],\n * base: {\n * root: 'btn',\n * icon: 'btn-icon'\n * },\n * variants: {\n * size: {\n * sm: {\n * root: 'btn-sm',\n * icon: 'icon-sm'\n * },\n * lg: {\n * root: 'btn-lg',\n * icon: 'icon-lg'\n * }\n * }\n * },\n * defaultVariants: {\n * size: 'sm'\n * }\n * })\n *\n * // Usage\n * const classes = button({ size: 'lg' })\n * // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }\n * ```\n */\nexport const scv: SlotClassVariantCreatorFn = (config) => {\n const { slots, base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config\n\n if (!variants) {\n return (props) => {\n const result = {} as Record<(typeof slots)[number], string>\n\n for (const slot of slots) {\n result[slot] = classNameResolver(base?.[slot], props?.classNames?.[slot])\n }\n\n return result\n }\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['classNames'])\n\n const slotClassValues = {} as Record<(typeof slots)[number], ClassValue[]>\n\n for (const slot of slots) {\n if (base?.[slot]) {\n slotClassValues[slot] = Array.isArray(base[slot]) ? [...base[slot]] : [base[slot]]\n } else {\n slotClassValues[slot] = []\n }\n }\n\n for (const key in mergedProps) {\n const cls = variants[key]?.[mergedProps[key] as string]\n\n if (cls) {\n for (const slot in cls) {\n slotClassValues[slot]?.push(cls[slot])\n }\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'classNames') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.classNames) {\n for (const slot in compound.classNames) {\n slotClassValues[slot]?.push(compound.classNames[slot])\n }\n }\n }\n }\n\n if (props?.classNames) {\n for (const slot in props.classNames) {\n slotClassValues[slot]?.push(props.classNames[slot])\n }\n }\n\n const result = {} as Record<(typeof slots)[number], string>\n\n for (const slot in slotClassValues) {\n result[slot] = classNameResolver(slotClassValues[slot])\n }\n\n return result\n }\n}\n\nexport default scv\n","import { CssProperties, ObjectKeyArrayPicker, ObjectKeyPicker } from './utils/types'\nimport { mergeProps } from './utils/merge-props'\n\nexport type StyleVariantRecord = Record<string, Record<string, CssProperties>>\n\nexport type StyleVariantExtendProps = { style: CssProperties }\n\nexport interface StyleVariantDefinition<T extends StyleVariantRecord | undefined> {\n base?: CssProperties\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & StyleVariantExtendProps)[]\n defaultVariants?: ObjectKeyPicker<T>\n}\n\nexport type StyleVariantFnProps<T extends StyleVariantRecord | undefined> = T extends undefined\n ? Partial<StyleVariantExtendProps>\n : ObjectKeyPicker<T> & Partial<StyleVariantExtendProps>\n\nexport type StyleVariantFn<T extends StyleVariantRecord | undefined> = (props?: StyleVariantFnProps<T>) => CssProperties\n\nexport type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(\n config: StyleVariantDefinition<T>\n) => StyleVariantFn<T>\n\n/**\n * Creates a style variant function based on the provided configuration.\n *\n * @template T - The type of the style variant record.\n * @param {StyleVariantDefinition<T>} config - The configuration object for style variants.\n * @returns {StyleVariantFn<T>} A function that takes props and returns the computed CSS properties.\n *\n * @example\n * ```typescript\n *\n * const makeStyle = sv({\n * base: { color: 'black' },\n * variants: {\n * size: {\n * small: { fontSize: '12px' },\n * large: { fontSize: '24px' }\n * }\n * },\n * compoundVariants: [\n * { size: 'large', style: { fontWeight: 'bold' } }\n * ],\n * defaultVariants: { size: 'small' }\n * });\n *\n * const style = makeStyle({ size: 'large' });\n * // style = { color: 'black', fontSize: '24px', fontWeight: 'bold' }\n * ```\n */\nexport const sv: StyleVariantCreatorFn = (config) => {\n const { base, variants, compoundVariants, defaultVariants } = config\n\n if (!variants) {\n return (props) => ({ ...base, ...props?.style })\n }\n\n return (props) => {\n const result: CssProperties = { ...base }\n\n const mergedProps = mergeProps(defaultVariants, props, ['style'])\n\n for (const key in mergedProps) {\n const styleValue = variants[key]?.[mergedProps[key] as string]\n if (styleValue) {\n Object.assign(result, styleValue)\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'style') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.style) {\n Object.assign(result, compound.style)\n }\n }\n }\n\n if (props?.style) {\n Object.assign(result, props.style)\n }\n\n return result\n }\n}\n\nexport default sv\n","import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord, CssProperties } from './utils/types'\nimport { mergeProps } from './utils/merge-props'\n\nexport type SlotStyleRecord<S extends string> = PartialRecord<S, CssProperties>\n\nexport type SlotStyleVariantRecord<S extends string> = Record<string, Record<string, SlotStyleRecord<S>>>\n\nexport type SlotStyleVariantExtendProps<S extends string> = { styles: SlotStyleRecord<S> }\n\nexport interface SlotStyleVariantDefinition<S extends string, T extends SlotStyleVariantRecord<S> | undefined> {\n slots: S[]\n base?: SlotStyleRecord<S>\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & SlotStyleVariantExtendProps<S>)[]\n defaultVariants?: ObjectKeyPicker<T>\n}\n\nexport type SlotStyleVariantFnProps<\n S extends string,\n T extends SlotStyleVariantRecord<S> | undefined,\n> = T extends undefined\n ? Partial<SlotStyleVariantExtendProps<S>>\n : ObjectKeyPicker<T> & Partial<SlotStyleVariantExtendProps<S>>\n\nexport type SlotStyleVariantFn<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = (\n props?: SlotStyleVariantFnProps<S, T>\n) => Record<S, CssProperties>\n\nexport type SlotStyleVariantCreatorFn = <S extends string, T extends SlotStyleVariantRecord<S> | undefined>(\n config: SlotStyleVariantDefinition<S, T>\n) => SlotStyleVariantFn<S, T>\n\n/**\n * Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.\n *\n * @param config - Configuration object for creating style variants\n * @returns A function that accepts variant props and returns composed styles for each slot\n *\n * @example\n * ```ts\n * const buttonStyles = csv({\n * slots: ['root', 'icon'],\n * base: {\n * root: { padding: '8px' },\n * icon: { size: '16px' }\n * },\n * variants: {\n * size: {\n * small: {\n * root: { padding: '4px' },\n * icon: { size: '12px' }\n * },\n * large: {\n * root: { padding: '12px' },\n * icon: { size: '20px' }\n * }\n * }\n * }\n * });\n *\n * // Usage\n * const styles = buttonStyles({ size: 'small' });\n * // => { root: { padding: '4px' }, icon: { size: '12px' } }\n * ```\n */\nexport const ssv: SlotStyleVariantCreatorFn = (config) => {\n const { slots, base, variants, compoundVariants, defaultVariants } = config\n\n if (!variants) {\n return (props) => {\n const result = {} as Record<(typeof slots)[number], CssProperties>\n\n for (const slot of slots) {\n result[slot] = { ...base?.[slot], ...props?.styles?.[slot] }\n }\n\n return result\n }\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['styles'])\n\n const result = {} as Record<(typeof slots)[number], CssProperties>\n\n for (const slot of slots) {\n result[slot] = { ...base?.[slot] }\n }\n\n for (const key in mergedProps) {\n const slotStyle = variants[key]?.[mergedProps[key] as string]\n\n if (slotStyle) {\n for (const slot in slotStyle) {\n Object.assign(result[slot], slotStyle[slot])\n }\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n\n for (const key in compound) {\n if (key === 'styles') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n\n if (matches && compound.styles) {\n for (const slot in compound.styles) {\n Object.assign(result[slot], compound.styles[slot])\n }\n }\n }\n }\n\n if (props?.styles) {\n for (const slot in props.styles) {\n Object.assign(result[slot], props.styles[slot])\n }\n }\n\n return result\n }\n}\n\nexport default ssv\n"]}
|
package/dist/scv.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});function m(s){if(typeof s=="string")return s;if(typeof s=="number"||typeof s=="bigint")return String(s);if(s==null||typeof s=="boolean")return "";let e="";if(Array.isArray(s)){let t=0,a,n;for(;t<s.length;t++)(a=s[t])&&(n=m(a))&&(e&&(e+=" "),e+=n);return e}for(let t in s)s[t]&&(e&&(e+=" "),e+=t);return e}function p(...s){let e="",t=0,a,n;for(;t<s.length;t++)(a=s[t])&&(n=m(a))&&(e&&(e+=" "),e+=n);return e}function x(s,e,t){let a={...s};if(e)for(let n in e)e[n]!==void 0&&(!t||!t.includes(n))&&(a[n]=e[n]);return a}var g=s=>{let{slots:e,base:t,variants:a,compoundVariants:n,defaultVariants:V,classNameResolver:S=p}=s;return a?i=>{let c=x(V,i,["classNames"]),o={};for(let r of e)t?.[r]?o[r]=Array.isArray(t[r])?[...t[r]]:[t[r]]:o[r]=[];for(let r in c){let l=a[r]?.[c[r]];if(l)for(let d in l)o[d]?.push(l[d]);}if(n)for(let r=0;r<n.length;r++){let l=n[r],d=true;for(let f in l){if(f==="classNames")continue;let u=l[f],y=c[f];if(Array.isArray(u)?!u.includes(y):u!==y){d=false;break}}if(d&&l.classNames)for(let f in l.classNames)o[f]?.push(l.classNames[f]);}if(i?.classNames)for(let r in i.classNames)o[r]?.push(i.classNames[r]);let C={};for(let r in o)C[r]=S(o[r]);return C}:i=>{let c={};for(let o of e)c[o]=S(t?.[o],i?.classNames?.[o]);return c}},T=g;exports.default=T;exports.scv=g;//# sourceMappingURL=scv.cjs.map
|
|
2
|
+
//# sourceMappingURL=scv.cjs.map
|
package/dist/scv.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cx.ts","../src/utils/merge-props.ts","../src/scv.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","mergeProps","defaultProps","props","omitKeys","merged","k","scv","config","slots","base","variants","compoundVariants","defaultVariants","classNameResolver","mergedProps","slotClassValues","slot","cls","compound","matches","value","propValue","scv_default"],"mappings":"sEAMA,SAASA,EAAMC,CAAAA,CAA2B,CACxC,GAAI,OAAOA,CAAAA,EAAU,SACnB,OAAOA,CAAAA,CAGT,GAAI,OAAOA,CAAAA,EAAU,UAAY,OAAOA,CAAAA,EAAU,SAChD,OAAO,MAAA,CAAOA,CAAK,CAAA,CAGrB,GAAIA,CAAAA,EAAU,IAAA,EAA+B,OAAOA,CAAAA,EAAU,SAAA,CAC5D,OAAO,EAAA,CAGT,IAAIC,EAAS,EAAA,CAEb,GAAI,MAAM,OAAA,CAAQD,CAAK,EAAG,CACxB,IAAIE,EAAI,CAAA,CACJC,CAAAA,CACAC,EACJ,KAAOF,CAAAA,CAAIF,CAAAA,CAAM,MAAA,CAAQE,KAClBC,CAAAA,CAAgBH,CAAAA,CAAME,CAAC,CAAA,IACrBE,CAAAA,CAAeL,EAAMI,CAAa,CAAA,CAAA,GACjCF,IAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,GAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAA,IAAWI,KAAOL,CAAAA,CACZA,CAAAA,CAAMK,CAAG,CAAA,GACPJ,CAAAA,GAAQA,GAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUI,GAId,OAAOJ,CACT,CAEO,SAASK,CAAAA,CAAAA,GAAMC,EAA4B,CAChD,IAAIN,EAAS,EAAA,CACTC,CAAAA,CAAI,EACJC,CAAAA,CACAC,CAAAA,CAEJ,KAA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uB,CAAI,EAAIH,CAAAA,CAAkBE,CAAAA,CAAgBC,CAAI,CAAC,CAAA,CAGxD,OAAOvB,CACT,CAAA,CApEUS,GAAU,CAChB,IAAMT,EAAS,EAAC,CAEhB,QAAWuB,CAAAA,IAAQR,CAAAA,CACjBf,EAAOuB,CAAI,CAAA,CAAIH,EAAkBJ,CAAAA,GAAOO,CAAI,EAAGd,CAAAA,EAAO,UAAA,GAAac,CAAI,CAAC,CAAA,CAG1E,OAAOvB,CACT,CA6DJ,EAEO6B,CAAAA,CAAQhB","file":"scv.cjs","sourcesContent":["// credit: https://github.com/lukeed/clsx\n\nexport type ClassDictionary = Record<string, unknown>\nexport type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined\nexport type ClassArray = ClassValue[]\n\nfunction toVal(input: ClassValue): string {\n if (typeof input === 'string') {\n return input\n }\n\n if (typeof input === 'number' || typeof input === 'bigint') {\n return String(input)\n }\n\n if (input === null || input === undefined || typeof input === 'boolean') {\n return ''\n }\n\n let result = ''\n\n if (Array.isArray(input)) {\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n for (; i < input.length; i++) {\n if ((tmpClassValue = input[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n }\n\n for (const key in input) {\n if (input[key]) {\n if (result) result += ' '\n result += key\n }\n }\n\n return result\n}\n\nexport function cx(...args: ClassValue[]): string {\n let result = ''\n let i = 0\n let tmpClassValue: ClassValue\n let tmpClassName: string\n\n for (; i < args.length; i++) {\n if ((tmpClassValue = args[i])) {\n if ((tmpClassName = toVal(tmpClassValue))) {\n if (result) result += ' '\n result += tmpClassName\n }\n }\n }\n\n return result\n}\n\nexport default cx\n","export function mergeProps<T extends Record<string, unknown>, P extends Record<string, unknown>>(\n defaultProps: T | undefined,\n props: P | undefined,\n omitKeys?: (keyof P)[]\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...defaultProps }\n\n if (props) {\n for (const k in props) {\n if (props[k] !== undefined && (!omitKeys || !omitKeys.includes(k))) {\n merged[k] = props[k]\n }\n }\n }\n\n return merged\n}\n","import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord } from './utils/types'\nimport { cx, ClassValue } from './cx'\nimport { mergeProps } from './utils/merge-props'\n\nexport type SlotClassRecord<S extends string> = PartialRecord<S, ClassValue>\n\nexport type SlotClassVariantRecord<S extends string> = Record<string, Record<string, SlotClassRecord<S>>>\n\nexport type SlotClassVariantExtendProps<S extends string> = { classNames: SlotClassRecord<S> }\n\nexport interface SlotClassVariantDefinition<S extends string, T extends SlotClassVariantRecord<S> | undefined> {\n slots: S[]\n base?: SlotClassRecord<S>\n variants?: T\n compoundVariants?: (ObjectKeyArrayPicker<T> & SlotClassVariantExtendProps<S>)[]\n defaultVariants?: ObjectKeyPicker<T>\n classNameResolver?: typeof cx\n}\n\nexport type SlotClassVariantFnProps<\n S extends string,\n T extends SlotClassVariantRecord<S> | undefined,\n> = T extends undefined\n ? Partial<SlotClassVariantExtendProps<S>>\n : ObjectKeyPicker<T> & Partial<SlotClassVariantExtendProps<S>>\n\nexport type SlotClassVariantFn<S extends string, T extends SlotClassVariantRecord<S> | undefined> = (\n props?: SlotClassVariantFnProps<S, T>\n) => Record<S, string>\n\nexport type SlotClassVariantCreatorFn = <S extends string, T extends SlotClassVariantRecord<S> | undefined>(\n config: SlotClassVariantDefinition<S, T>\n) => SlotClassVariantFn<S, T>\n\n/**\n * Creates a slot-based class variant function that manages class names for multiple slots with variants.\n *\n * @param config - Configuration object for creating the variant function\n * @returns A function that accepts variant props and returns class names for each slot\n *\n * @example\n * ```typescript\n * const button = scv({\n * slots: ['root', 'icon'],\n * base: {\n * root: 'btn',\n * icon: 'btn-icon'\n * },\n * variants: {\n * size: {\n * sm: {\n * root: 'btn-sm',\n * icon: 'icon-sm'\n * },\n * lg: {\n * root: 'btn-lg',\n * icon: 'icon-lg'\n * }\n * }\n * },\n * defaultVariants: {\n * size: 'sm'\n * }\n * })\n *\n * // Usage\n * const classes = button({ size: 'lg' })\n * // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }\n * ```\n */\nexport const scv: SlotClassVariantCreatorFn = (config) => {\n const { slots, base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config\n\n if (!variants) {\n return (props) => {\n const result = {} as Record<(typeof slots)[number], string>\n\n for (const slot of slots) {\n result[slot] = classNameResolver(base?.[slot], props?.classNames?.[slot])\n }\n\n return result\n }\n }\n\n return (props) => {\n const mergedProps = mergeProps(defaultVariants, props, ['classNames'])\n\n const slotClassValues = {} as Record<(typeof slots)[number], ClassValue[]>\n\n for (const slot of slots) {\n if (base?.[slot]) {\n slotClassValues[slot] = Array.isArray(base[slot]) ? [...base[slot]] : [base[slot]]\n } else {\n slotClassValues[slot] = []\n }\n }\n\n for (const key in mergedProps) {\n const cls = variants[key]?.[mergedProps[key] as string]\n\n if (cls) {\n for (const slot in cls) {\n slotClassValues[slot]?.push(cls[slot])\n }\n }\n }\n\n if (compoundVariants) {\n for (let i = 0; i < compoundVariants.length; i++) {\n const compound = compoundVariants[i]\n let matches = true\n for (const key in compound) {\n if (key === 'classNames') continue\n const value = compound[key as keyof typeof compound]\n const propValue = mergedProps[key]\n if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {\n matches = false\n break\n }\n }\n if (matches && compound.classNames) {\n for (const slot in compound.classNames) {\n slotClassValues[slot]?.push(compound.classNames[slot])\n }\n }\n }\n }\n\n if (props?.classNames) {\n for (const slot in props.classNames) {\n slotClassValues[slot]?.push(props.classNames[slot])\n }\n }\n\n const result = {} as Record<(typeof slots)[number], string>\n\n for (const slot in slotClassValues) {\n result[slot] = classNameResolver(slotClassValues[slot])\n }\n\n return result\n }\n}\n\nexport default scv\n"]}
|