css-variants 2.3.3 → 2.3.4

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 CHANGED
@@ -2,31 +2,27 @@
2
2
 
3
3
  # css-variants
4
4
 
5
- **Zero-dependency, type-safe CSS variant composition for modern JavaScript**
5
+ **Fastest CSS variant library for JavaScript and TypeScript**
6
6
 
7
- Build powerful, flexible component style systems with variants.<br/>
8
- Perfect for Tailwind CSS, vanilla CSS, or any CSS-in-JS solution.
7
+ Type-safe alternative to CVA (Class Variance Authority) and tailwind-variants.
8
+ ~1KB gzipped. 3-11x faster. Zero dependencies.
9
9
 
10
- [![test](https://github.com/timphandev/css-variants/actions/workflows/packages.css-variants.test.yml/badge.svg)](https://github.com/timphandev/css-variants/actions/workflows/packages.css-variants.test.yml)
11
10
  [![npm version](https://img.shields.io/npm/v/css-variants.svg)](https://www.npmjs.com/package/css-variants)
12
11
  [![Bundle Size](https://img.shields.io/bundlephobia/minzip/css-variants)](https://bundlephobia.com/package/css-variants)
13
12
  [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-blue)](https://www.typescriptlang.org/)
14
13
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
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/)
15
+ [Documentation](https://css-variants.vercel.app/) · [API Reference](https://css-variants.vercel.app/api/cv/) · [Comparison](https://css-variants.vercel.app/resources/comparison/)
17
16
 
18
17
  </div>
19
18
 
20
19
  ---
21
20
 
22
- ## Why css-variants?
21
+ ## What is css-variants?
22
+
23
+ css-variants is a JavaScript library for managing CSS class variants with full TypeScript support. Define style variations (color, size, state) declaratively and get the correct CSS classes at runtime.
23
24
 
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 |
25
+ Works with Tailwind CSS, vanilla CSS, CSS Modules, or any styling solution.
30
26
 
31
27
  ## Installation
32
28
 
@@ -34,9 +30,21 @@ Perfect for Tailwind CSS, vanilla CSS, or any CSS-in-JS solution.
34
30
  npm install css-variants
35
31
  ```
36
32
 
33
+ ```bash
34
+ pnpm add css-variants
35
+ ```
36
+
37
+ ```bash
38
+ yarn add css-variants
39
+ ```
40
+
41
+ ---
42
+
37
43
  ## Quick Start
38
44
 
39
- ### Single-Element Variants (`cv`)
45
+ ### cv() — Class Variants
46
+
47
+ Create type-safe variants for single-element components:
40
48
 
41
49
  ```typescript
42
50
  import { cv } from 'css-variants'
@@ -50,18 +58,24 @@ const button = cv({
50
58
  },
51
59
  size: {
52
60
  sm: 'px-3 py-1.5 text-sm',
61
+ md: 'px-4 py-2 text-base',
53
62
  lg: 'px-6 py-3 text-lg',
54
63
  },
55
64
  },
56
- defaultVariants: { color: 'primary', size: 'sm' },
65
+ defaultVariants: {
66
+ color: 'primary',
67
+ size: 'md',
68
+ },
57
69
  })
58
70
 
59
- button() // Primary + Small (defaults)
60
- button({ color: 'secondary' }) // Secondary + Small
61
- button({ size: 'lg', className: 'w-full' }) // Primary + Large + custom class
71
+ button() // Uses defaults
72
+ button({ color: 'secondary', size: 'lg' }) // Override variants
73
+ button({ className: 'w-full' }) // Add custom classes
62
74
  ```
63
75
 
64
- ### Multi-Element Components (`scv`)
76
+ ### scv() Slot Class Variants
77
+
78
+ Create variants for multi-element components (cards, modals, dropdowns):
65
79
 
66
80
  ```typescript
67
81
  import { scv } from 'css-variants'
@@ -70,78 +84,181 @@ const card = scv({
70
84
  slots: ['root', 'header', 'body', 'footer'],
71
85
  base: {
72
86
  root: 'rounded-xl border shadow-sm',
73
- header: 'px-6 py-4 border-b',
87
+ header: 'px-6 py-4 border-b font-semibold',
74
88
  body: 'px-6 py-4',
75
89
  footer: 'px-6 py-3 bg-gray-50',
76
90
  },
77
91
  variants: {
78
92
  variant: {
79
93
  default: { root: 'bg-white border-gray-200' },
80
- danger: { root: 'bg-red-50 border-red-200', header: 'text-red-900' },
94
+ primary: { root: 'bg-blue-50 border-blue-200' },
81
95
  },
82
96
  },
83
97
  })
84
98
 
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'
99
+ const classes = card({ variant: 'primary' })
100
+ // classes.root → 'rounded-xl border shadow-sm bg-blue-50 border-blue-200'
101
+ // classes.header → 'px-6 py-4 border-b font-semibold'
88
102
  ```
89
103
 
90
- ### Compound Variants
104
+ ### sv() — Style Variants
91
105
 
92
- Apply styles when multiple variants match:
106
+ Create variants that return CSS style objects:
93
107
 
94
108
  ```typescript
95
- const button = cv({
109
+ import { sv } from 'css-variants'
110
+
111
+ const box = sv({
112
+ base: { display: 'flex', borderRadius: '8px' },
96
113
  variants: {
97
- color: { primary: '...', danger: '...' },
98
- size: { sm: '...', lg: '...' },
114
+ size: {
115
+ sm: { padding: '8px' },
116
+ lg: { padding: '24px' },
117
+ },
99
118
  },
100
- compoundVariants: [
101
- { color: 'danger', size: 'lg', className: 'font-bold uppercase' },
102
- ],
103
119
  })
120
+
121
+ <div style={box({ size: 'lg' })} />
104
122
  ```
105
123
 
106
- ### Style Variants (`sv`)
124
+ ### cx() Class Merger
107
125
 
108
- For inline styles instead of class names:
126
+ Lightweight clsx alternative for conditional class merging:
109
127
 
110
128
  ```typescript
111
- import { sv } from 'css-variants'
129
+ import { cx } from 'css-variants'
112
130
 
113
- const box = sv({
114
- base: { display: 'flex', borderRadius: '8px' },
131
+ cx('btn', 'btn-primary') // 'btn btn-primary'
132
+ cx('btn', isActive && 'active') // 'btn active' or 'btn'
133
+ cx('btn', { disabled: isDisabled }) // 'btn disabled' or 'btn'
134
+ ```
135
+
136
+ ---
137
+
138
+ ## Why css-variants?
139
+
140
+ | Feature | css-variants | CVA | tailwind-variants |
141
+ |---------|:------------:|:---:|:-----------------:|
142
+ | Bundle size | **~1KB** | ~2KB | ~5KB |
143
+ | Performance | **Baseline** | 3-7x slower | 5-11x slower |
144
+ | Slot variants | Built-in | No | Yes |
145
+ | Style variants | Built-in | No | No |
146
+ | Dependencies | 0 | 1 | 1 |
147
+
148
+ ---
149
+
150
+ ## Tailwind CSS Integration
151
+
152
+ Use with tailwind-merge for class conflict resolution:
153
+
154
+ ```typescript
155
+ import { cv, cx } from 'css-variants'
156
+ import { twMerge } from 'tailwind-merge'
157
+
158
+ const button = cv({
159
+ base: 'px-4 py-2 rounded',
115
160
  variants: {
116
- size: {
117
- sm: { padding: '8px' },
118
- lg: { padding: '24px' },
119
- },
161
+ size: { lg: 'px-6 py-3' },
162
+ },
163
+ classNameResolver: (...args) => twMerge(cx(...args)),
164
+ })
165
+ ```
166
+
167
+ [Full Tailwind guide →](https://css-variants.vercel.app/guides/tailwind/)
168
+
169
+ ---
170
+
171
+ ## Framework Examples
172
+
173
+ ### React
174
+
175
+ ```tsx
176
+ import { cv } from 'css-variants'
177
+
178
+ const button = cv({
179
+ base: 'rounded font-medium',
180
+ variants: {
181
+ variant: { primary: 'bg-blue-600 text-white' },
120
182
  },
121
183
  })
122
184
 
123
- box({ size: 'lg' }) // => { display: 'flex', borderRadius: '8px', padding: '24px' }
185
+ type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> &
186
+ Parameters<typeof button>[0]
187
+
188
+ function Button({ variant, className, ...props }: ButtonProps) {
189
+ return <button className={button({ variant, className })} {...props} />
190
+ }
124
191
  ```
125
192
 
126
- ## Performance
193
+ ### Vue
127
194
 
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) |
195
+ ```vue
196
+ <script setup lang="ts">
197
+ import { cv } from 'css-variants'
132
198
 
133
- ## Documentation
199
+ const button = cv({
200
+ base: 'rounded font-medium',
201
+ variants: {
202
+ variant: { primary: 'bg-blue-600 text-white' },
203
+ },
204
+ })
134
205
 
135
- **[Full documentation →](https://css-variants.vercel.app/)**
206
+ defineProps<{ variant?: 'primary' }>()
207
+ </script>
136
208
 
137
- ## Contributing
209
+ <template>
210
+ <button :class="button({ variant })"><slot /></button>
211
+ </template>
212
+ ```
138
213
 
139
- ```bash
140
- git clone https://github.com/timphandev/css-variants.git
141
- cd css-variants && yarn install
142
- yarn css-variants test && yarn css-variants build
214
+ ---
215
+
216
+ ## Migrate from CVA
217
+
218
+ ```diff
219
+ - import { cva } from 'class-variance-authority'
220
+ + import { cv } from 'css-variants'
221
+
222
+ - const button = cva('base-classes', {
223
+ + const button = cv({
224
+ + base: 'base-classes',
225
+ variants: { /* same */ },
226
+ compoundVariants: [
227
+ - { color: 'primary', class: 'extra' }
228
+ + { color: 'primary', className: 'extra' }
229
+ ],
230
+ })
143
231
  ```
144
232
 
233
+ [Full migration guide →](https://css-variants.vercel.app/resources/migration-cva/)
234
+
235
+ ---
236
+
237
+ ## API Reference
238
+
239
+ | Function | Description |
240
+ |----------|-------------|
241
+ | [`cv()`](https://css-variants.vercel.app/api/cv/) | Class variants for single-element components |
242
+ | [`scv()`](https://css-variants.vercel.app/api/scv/) | Slot class variants for multi-element components |
243
+ | [`sv()`](https://css-variants.vercel.app/api/sv/) | Style variants for inline CSS style objects |
244
+ | [`ssv()`](https://css-variants.vercel.app/api/ssv/) | Slot style variants for multi-element inline styles |
245
+ | [`cx()`](https://css-variants.vercel.app/api/cx/) | Class merger utility (like clsx) |
246
+
247
+ ---
248
+
249
+ ## Documentation
250
+
251
+ **[css-variants.vercel.app](https://css-variants.vercel.app/)**
252
+
253
+ - [Getting Started](https://css-variants.vercel.app/getting-started/introduction/)
254
+ - [API Reference](https://css-variants.vercel.app/api/cv/)
255
+ - [Tailwind CSS Guide](https://css-variants.vercel.app/guides/tailwind/)
256
+ - [React, Vue, Svelte Guides](https://css-variants.vercel.app/guides/frameworks/)
257
+ - [css-variants vs CVA vs tailwind-variants](https://css-variants.vercel.app/resources/comparison/)
258
+ - [FAQ](https://css-variants.vercel.app/resources/faq/)
259
+
260
+ ---
261
+
145
262
  ## License
146
263
 
147
264
  MIT © [Tim Phan](https://github.com/timphandev)
@@ -1 +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,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,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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"]}
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,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAA,IAAWI,CAAAA,IAAOL,EACZA,CAAAA,CAAMK,CAAG,IACPJ,CAAAA,GAAQA,CA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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 = ssv({\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.js.map CHANGED
@@ -1 +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,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAA,IAAWI,CAAAA,IAAOL,EACZA,CAAAA,CAAMK,CAAG,IACPJ,CAAAA,GAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUI,CAAAA,CAA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AChB,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"]}
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,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUG,CAAAA,CAAAA,CAKhB,OAAOH,CACT,CAEA,IAAA,IAAWI,CAAAA,IAAOL,EACZA,CAAAA,CAAMK,CAAG,IACPJ,CAAAA,GAAQA,CAAAA,EAAU,GAAA,CAAA,CACtBA,CAAAA,EAAUI,CAAAA,CAAAA,CAId,OAAOJ,CACT,CAEO,SAASK,KAAMC,CAAAA,CAA4B,CAChD,IAAIN,CAAAA,CAAS,EAAA,CACT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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 = ssv({\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/ssv.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/merge-props.ts","../src/ssv.ts"],"names":["mergeProps","defaultProps","props","omitKeys","merged","k","ssv","config","slots","base","variants","compoundVariants","defaultVariants","mergedProps","result","slot","key","slotStyle","i","compound","matches","value","propValue","ssv_default"],"mappings":"sEAAO,SAASA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACyB,CACzB,IAAMC,CAAAA,CAAkC,CAAE,GAAGH,CAAa,CAAA,CAE1D,GAAIC,EACF,IAAA,IAAWG,CAAAA,IAAKH,CAAAA,CACVA,CAAAA,CAAMG,CAAC,CAAA,GAAM,MAAA,GAAc,CAACF,CAAAA,EAAY,CAACA,CAAAA,CAAS,QAAA,CAASE,CAAC,CAAA,CAAA,GAC9DD,EAAOC,CAAC,CAAA,CAAIH,CAAAA,CAAMG,CAAC,CAAA,CAAA,CAKzB,OAAOD,CACT,CCiDO,IAAME,CAAAA,CAAkCC,CAAAA,EAAW,CACxD,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,gBAAA,CAAAC,CAAAA,CAAkB,eAAA,CAAAC,CAAgB,CAAA,CAAIL,CAAAA,CAErE,OAAKG,CAAAA,CAYGR,GAAU,CAChB,IAAMW,CAAAA,CAAcb,CAAAA,CAAWY,CAAAA,CAAiBV,CAAAA,CAAO,CAAC,QAAQ,CAAC,CAAA,CAE3DY,CAAAA,CAAS,EAAC,CAEhB,QAAWC,CAAAA,IAAQP,CAAAA,CACjBM,CAAAA,CAAOC,CAAI,CAAA,CAAI,CAAE,GAAGN,CAAAA,GAAOM,CAAI,CAAE,CAAA,CAGnC,IAAA,IAAWC,CAAAA,IAAOH,CAAAA,CAAa,CAC7B,IAAMI,CAAAA,CAAYP,CAAAA,CAASM,CAAG,CAAA,GAAIH,CAAAA,CAAYG,CAAG,CAAW,CAAA,CAE5D,GAAIC,CAAAA,CACF,IAAA,IAAWF,CAAAA,IAAQE,EACjB,MAAA,CAAO,MAA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,CAAE,CAAA,CAG7D,OAAOD,CACT,CAsDJ,CAAA,CAEOS,CAAAA,CAAQjB","file":"ssv.cjs","sourcesContent":["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, 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"]}
1
+ {"version":3,"sources":["../src/utils/merge-props.ts","../src/ssv.ts"],"names":["mergeProps","defaultProps","props","omitKeys","merged","k","ssv","config","slots","base","variants","compoundVariants","defaultVariants","mergedProps","result","slot","key","slotStyle","i","compound","matches","value","propValue","ssv_default"],"mappings":"sEAAO,SAASA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACyB,CACzB,IAAMC,CAAAA,CAAkC,CAAE,GAAGH,CAAa,CAAA,CAE1D,GAAIC,EACF,IAAA,IAAWG,CAAAA,IAAKH,CAAAA,CACVA,CAAAA,CAAMG,CAAC,CAAA,GAAM,MAAA,GAAc,CAACF,CAAAA,EAAY,CAACA,CAAAA,CAAS,QAAA,CAASE,CAAC,CAAA,CAAA,GAC9DD,EAAOC,CAAC,CAAA,CAAIH,CAAAA,CAAMG,CAAC,CAAA,CAAA,CAKzB,OAAOD,CACT,CCiDO,IAAME,CAAAA,CAAkCC,CAAAA,EAAW,CACxD,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,gBAAA,CAAAC,CAAAA,CAAkB,eAAA,CAAAC,CAAgB,CAAA,CAAIL,CAAAA,CAErE,OAAKG,CAAAA,CAYGR,GAAU,CAChB,IAAMW,CAAAA,CAAcb,CAAAA,CAAWY,CAAAA,CAAiBV,CAAAA,CAAO,CAAC,QAAQ,CAAC,CAAA,CAE3DY,CAAAA,CAAS,EAAC,CAEhB,QAAWC,CAAAA,IAAQP,CAAAA,CACjBM,CAAAA,CAAOC,CAAI,CAAA,CAAI,CAAE,GAAGN,CAAAA,GAAOM,CAAI,CAAE,CAAA,CAGnC,IAAA,IAAWC,CAAAA,IAAOH,CAAAA,CAAa,CAC7B,IAAMI,CAAAA,CAAYP,CAAAA,CAASM,CAAG,CAAA,GAAIH,CAAAA,CAAYG,CAAG,CAAW,CAAA,CAE5D,GAAIC,CAAAA,CACF,IAAA,IAAWF,CAAAA,IAAQE,EACjB,MAAA,CAAO,MAAA,CAAOH,CAAAA,CAAOC,CAAI,CAAA,CAAGE,CAAAA,CAAUF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AAA,CAAQjB","file":"ssv.cjs","sourcesContent":["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, 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 = ssv({\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/ssv.d.cts CHANGED
@@ -24,7 +24,7 @@ type SlotStyleVariantCreatorFn = <S extends string, T extends SlotStyleVariantRe
24
24
  *
25
25
  * @example
26
26
  * ```ts
27
- * const buttonStyles = csv({
27
+ * const buttonStyles = ssv({
28
28
  * slots: ['root', 'icon'],
29
29
  * base: {
30
30
  * root: { padding: '8px' },
package/dist/ssv.d.ts CHANGED
@@ -24,7 +24,7 @@ type SlotStyleVariantCreatorFn = <S extends string, T extends SlotStyleVariantRe
24
24
  *
25
25
  * @example
26
26
  * ```ts
27
- * const buttonStyles = csv({
27
+ * const buttonStyles = ssv({
28
28
  * slots: ['root', 'icon'],
29
29
  * base: {
30
30
  * root: { padding: '8px' },
package/dist/ssv.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/merge-props.ts","../src/ssv.ts"],"names":["mergeProps","defaultProps","props","omitKeys","merged","k","ssv","config","slots","base","variants","compoundVariants","defaultVariants","mergedProps","result","slot","key","slotStyle","i","compound","matches","value","propValue","ssv_default"],"mappings":"AAAO,SAASA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACyB,CACzB,IAAMC,CAAAA,CAAkC,CAAE,GAAGH,CAAa,CAAA,CAE1D,GAAIC,EACF,IAAA,IAAWG,CAAAA,IAAKH,CAAAA,CACVA,CAAAA,CAAMG,CAAC,CAAA,GAAM,MAAA,GAAc,CAACF,CAAAA,EAAY,CAACA,CAAAA,CAAS,QAAA,CAASE,CAAC,CAAA,CAAA,GAC9DD,EAAOC,CAAC,CAAA,CAAIH,CAAAA,CAAMG,CAAC,CAAA,CAAA,CAKzB,OAAOD,CACT,CCiDO,IAAME,CAAAA,CAAkCC,CAAAA,EAAW,CACxD,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,gBAAA,CAAAC,CAAAA,CAAkB,eAAA,CAAAC,CAAgB,CAAA,CAAIL,CAAAA,CAErE,OAAKG,CAAAA,CAYGR,GAAU,CAChB,IAAMW,CAAAA,CAAcb,CAAAA,CAAWY,CAAAA,CAAiBV,CAAAA,CAAO,CAAC,QAAQ,CAAC,CAAA,CAE3DY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CAAAA,IAAQb,EAAM,MAAA,CACvB,MAAA,CAAO,MAAA,CAAOY,CAAAA,CAAOC,CAAI,CAAA,CAAGb,CAAAA,CAAM,MAAA,CAAOa,CAAI,CAAC,CAAA,CAIlD,OAAOD,CACT,CAAA,CA7DUZ,GAAU,CAChB,IAAMY,CAAAA,CAAS,EAAC,CAEhB,IAAA,IAAWC,KAAQP,CAAAA,CACjBM,CAAAA,CAAOC,CAAI,CAAA,CAAI,CAAE,GAAGN,IAAOM,CAAI,CAAA,CAAG,GAAGb,CAAAA,EAAO,MAAA,GAASa,CAAI,CAAE,CAAA,CAG7D,OAAOD,CACT,CAsDJ,CAAA,CAEOS,CAAAA,CAAQjB","file":"ssv.js","sourcesContent":["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, 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"]}
1
+ {"version":3,"sources":["../src/utils/merge-props.ts","../src/ssv.ts"],"names":["mergeProps","defaultProps","props","omitKeys","merged","k","ssv","config","slots","base","variants","compoundVariants","defaultVariants","mergedProps","result","slot","key","slotStyle","i","compound","matches","value","propValue","ssv_default"],"mappings":"AAAO,SAASA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACyB,CACzB,IAAMC,CAAAA,CAAkC,CAAE,GAAGH,CAAa,CAAA,CAE1D,GAAIC,EACF,IAAA,IAAWG,CAAAA,IAAKH,CAAAA,CACVA,CAAAA,CAAMG,CAAC,CAAA,GAAM,MAAA,GAAc,CAACF,CAAAA,EAAY,CAACA,CAAAA,CAAS,QAAA,CAASE,CAAC,CAAA,CAAA,GAC9DD,EAAOC,CAAC,CAAA,CAAIH,CAAAA,CAAMG,CAAC,CAAA,CAAA,CAKzB,OAAOD,CACT,CCiDO,IAAME,CAAAA,CAAkCC,CAAAA,EAAW,CACxD,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,IAAA,CAAAC,CAAAA,CAAM,QAAA,CAAAC,CAAAA,CAAU,gBAAA,CAAAC,CAAAA,CAAkB,eAAA,CAAAC,CAAgB,CAAA,CAAIL,CAAAA,CAErE,OAAKG,CAAAA,CAYGR,GAAU,CAChB,IAAMW,CAAAA,CAAcb,CAAAA,CAAWY,CAAAA,CAAiBV,CAAAA,CAAO,CAAC,QAAQ,CAAC,CAAA,CAE3DY,CAAAA,CAAS,EAAC,CAEhB,QAAWC,CAAAA,IAAQP,CAAAA,CACj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AAA,CAAOC,CAAI,CAAA,CAAGb,CAAAA,CAAM,MAAA,CAAOa,CAAI,CAAC,CAAA,CAIlD,OAAOD,CACT,CAAA,CA7DUZ,GAAU,CAChB,IAAMY,CAAAA,CAAS,EAAC,CAEhB,IAAA,IAAWC,KAAQP,CAAAA,CACjBM,CAAAA,CAAOC,CAAI,CAAA,CAAI,CAAE,GAAGN,IAAOM,CAAI,CAAA,CAAG,GAAGb,CAAAA,EAAO,MAAA,GAASa,CAAI,CAAE,CAAA,CAG7D,OAAOD,CACT,CAsDJ,CAAA,CAEOS,CAAAA,CAAQjB","file":"ssv.js","sourcesContent":["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, 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 = ssv({\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-variants",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "Lightweight helpers to compose class names and inline styles using variants. Zero runtime deps, small bundle, and first-class TypeScript support.",
5
5
  "homepage": "https://css-variants.vercel.app",
6
6
  "type": "module",