css-variants 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +95 -39
  2. package/dist/cv.cjs +2 -0
  3. package/dist/cv.cjs.map +1 -0
  4. package/dist/{esm/cv.d.ts → cv.d.cts} +13 -10
  5. package/dist/{cjs/cv.d.ts → cv.d.ts} +13 -10
  6. package/dist/cv.js +2 -0
  7. package/dist/cv.js.map +1 -0
  8. package/dist/cx.cjs +2 -0
  9. package/dist/cx.cjs.map +1 -0
  10. package/dist/cx.d.cts +6 -0
  11. package/dist/cx.d.ts +6 -0
  12. package/dist/cx.js +2 -0
  13. package/dist/cx.js.map +1 -0
  14. package/dist/index.cjs +2 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/index.d.cts +7 -0
  17. package/dist/index.d.ts +7 -0
  18. package/dist/index.js +2 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/scv.cjs +2 -0
  21. package/dist/scv.cjs.map +1 -0
  22. package/dist/scv.d.cts +59 -0
  23. package/dist/scv.d.ts +59 -0
  24. package/dist/scv.js +2 -0
  25. package/dist/scv.js.map +1 -0
  26. package/dist/ssv.cjs +2 -0
  27. package/dist/ssv.cjs.map +1 -0
  28. package/dist/ssv.d.cts +54 -0
  29. package/dist/ssv.d.ts +54 -0
  30. package/dist/ssv.js +2 -0
  31. package/dist/ssv.js.map +1 -0
  32. package/dist/sv.cjs +2 -0
  33. package/dist/sv.cjs.map +1 -0
  34. package/dist/{cjs/sv.d.ts → sv.d.cts} +12 -9
  35. package/dist/{esm/sv.d.ts → sv.d.ts} +12 -9
  36. package/dist/sv.js +2 -0
  37. package/dist/sv.js.map +1 -0
  38. package/dist/types-BXKyjXhG.d.cts +16 -0
  39. package/dist/types-BXKyjXhG.d.ts +16 -0
  40. package/package.json +35 -13
  41. package/dist/cjs/cv.js +0 -75
  42. package/dist/cjs/cv.js.map +0 -1
  43. package/dist/cjs/cx.d.ts +0 -5
  44. package/dist/cjs/cx.js +0 -57
  45. package/dist/cjs/cx.js.map +0 -1
  46. package/dist/cjs/index.d.ts +0 -5
  47. package/dist/cjs/index.js +0 -22
  48. package/dist/cjs/index.js.map +0 -1
  49. package/dist/cjs/scv.d.ts +0 -56
  50. package/dist/cjs/scv.js +0 -107
  51. package/dist/cjs/scv.js.map +0 -1
  52. package/dist/cjs/ssv.d.ts +0 -51
  53. package/dist/cjs/ssv.js +0 -94
  54. package/dist/cjs/ssv.js.map +0 -1
  55. package/dist/cjs/sv.js +0 -74
  56. package/dist/cjs/sv.js.map +0 -1
  57. package/dist/cjs/utils/merge-props.d.ts +0 -1
  58. package/dist/cjs/utils/merge-props.js +0 -15
  59. package/dist/cjs/utils/merge-props.js.map +0 -1
  60. package/dist/cjs/utils/types.d.ts +0 -16
  61. package/dist/cjs/utils/types.js +0 -3
  62. package/dist/cjs/utils/types.js.map +0 -1
  63. package/dist/esm/cv.js +0 -71
  64. package/dist/esm/cv.js.map +0 -1
  65. package/dist/esm/cx.d.ts +0 -5
  66. package/dist/esm/cx.js +0 -54
  67. package/dist/esm/cx.js.map +0 -1
  68. package/dist/esm/index.d.ts +0 -5
  69. package/dist/esm/index.js +0 -6
  70. package/dist/esm/index.js.map +0 -1
  71. package/dist/esm/scv.d.ts +0 -56
  72. package/dist/esm/scv.js +0 -103
  73. package/dist/esm/scv.js.map +0 -1
  74. package/dist/esm/ssv.d.ts +0 -51
  75. package/dist/esm/ssv.js +0 -90
  76. package/dist/esm/ssv.js.map +0 -1
  77. package/dist/esm/sv.js +0 -70
  78. package/dist/esm/sv.js.map +0 -1
  79. package/dist/esm/utils/merge-props.d.ts +0 -1
  80. package/dist/esm/utils/merge-props.js +0 -12
  81. package/dist/esm/utils/merge-props.js.map +0 -1
  82. package/dist/esm/utils/types.d.ts +0 -16
  83. package/dist/esm/utils/types.js +0 -2
  84. package/dist/esm/utils/types.js.map +0 -1
package/dist/scv.d.cts ADDED
@@ -0,0 +1,59 @@
1
+ import { P as PartialRecord, O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.cjs';
2
+ import cx, { ClassValue } from './cx.cjs';
3
+ import 'csstype';
4
+
5
+ type SlotClassRecord<S extends string> = PartialRecord<S, ClassValue>;
6
+ type SlotClassVariantRecord<S extends string> = Record<string, Record<string, SlotClassRecord<S>>>;
7
+ type SlotClassVariantExtendProps<S extends string> = {
8
+ classNames: SlotClassRecord<S>;
9
+ };
10
+ interface SlotClassVariantDefinition<S extends string, T extends SlotClassVariantRecord<S> | undefined> {
11
+ slots: S[];
12
+ base?: SlotClassRecord<S>;
13
+ variants?: T;
14
+ compoundVariants?: (ObjectKeyArrayPicker<T> & SlotClassVariantExtendProps<S>)[];
15
+ defaultVariants?: ObjectKeyPicker<T>;
16
+ classNameResolver?: typeof cx;
17
+ }
18
+ type SlotClassVariantFnProps<S extends string, T extends SlotClassVariantRecord<S> | undefined> = T extends undefined ? Partial<SlotClassVariantExtendProps<S>> : ObjectKeyPicker<T> & Partial<SlotClassVariantExtendProps<S>>;
19
+ type SlotClassVariantFn<S extends string, T extends SlotClassVariantRecord<S> | undefined> = (props?: SlotClassVariantFnProps<S, T>) => Record<S, string>;
20
+ type SlotClassVariantCreatorFn = <S extends string, T extends SlotClassVariantRecord<S> | undefined>(config: SlotClassVariantDefinition<S, T>) => SlotClassVariantFn<S, T>;
21
+ /**
22
+ * Creates a slot-based class variant function that manages class names for multiple slots with variants.
23
+ *
24
+ * @param config - Configuration object for creating the variant function
25
+ * @returns A function that accepts variant props and returns class names for each slot
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const button = scv({
30
+ * slots: ['root', 'icon'],
31
+ * base: {
32
+ * root: 'btn',
33
+ * icon: 'btn-icon'
34
+ * },
35
+ * variants: {
36
+ * size: {
37
+ * sm: {
38
+ * root: 'btn-sm',
39
+ * icon: 'icon-sm'
40
+ * },
41
+ * lg: {
42
+ * root: 'btn-lg',
43
+ * icon: 'icon-lg'
44
+ * }
45
+ * }
46
+ * },
47
+ * defaultVariants: {
48
+ * size: 'sm'
49
+ * }
50
+ * })
51
+ *
52
+ * // Usage
53
+ * const classes = button({ size: 'lg' })
54
+ * // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }
55
+ * ```
56
+ */
57
+ declare const scv: SlotClassVariantCreatorFn;
58
+
59
+ export { type SlotClassRecord, type SlotClassVariantCreatorFn, type SlotClassVariantDefinition, type SlotClassVariantExtendProps, type SlotClassVariantFn, type SlotClassVariantFnProps, type SlotClassVariantRecord, scv as default, scv };
package/dist/scv.d.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { P as PartialRecord, O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.js';
2
+ import cx, { ClassValue } from './cx.js';
3
+ import 'csstype';
4
+
5
+ type SlotClassRecord<S extends string> = PartialRecord<S, ClassValue>;
6
+ type SlotClassVariantRecord<S extends string> = Record<string, Record<string, SlotClassRecord<S>>>;
7
+ type SlotClassVariantExtendProps<S extends string> = {
8
+ classNames: SlotClassRecord<S>;
9
+ };
10
+ interface SlotClassVariantDefinition<S extends string, T extends SlotClassVariantRecord<S> | undefined> {
11
+ slots: S[];
12
+ base?: SlotClassRecord<S>;
13
+ variants?: T;
14
+ compoundVariants?: (ObjectKeyArrayPicker<T> & SlotClassVariantExtendProps<S>)[];
15
+ defaultVariants?: ObjectKeyPicker<T>;
16
+ classNameResolver?: typeof cx;
17
+ }
18
+ type SlotClassVariantFnProps<S extends string, T extends SlotClassVariantRecord<S> | undefined> = T extends undefined ? Partial<SlotClassVariantExtendProps<S>> : ObjectKeyPicker<T> & Partial<SlotClassVariantExtendProps<S>>;
19
+ type SlotClassVariantFn<S extends string, T extends SlotClassVariantRecord<S> | undefined> = (props?: SlotClassVariantFnProps<S, T>) => Record<S, string>;
20
+ type SlotClassVariantCreatorFn = <S extends string, T extends SlotClassVariantRecord<S> | undefined>(config: SlotClassVariantDefinition<S, T>) => SlotClassVariantFn<S, T>;
21
+ /**
22
+ * Creates a slot-based class variant function that manages class names for multiple slots with variants.
23
+ *
24
+ * @param config - Configuration object for creating the variant function
25
+ * @returns A function that accepts variant props and returns class names for each slot
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const button = scv({
30
+ * slots: ['root', 'icon'],
31
+ * base: {
32
+ * root: 'btn',
33
+ * icon: 'btn-icon'
34
+ * },
35
+ * variants: {
36
+ * size: {
37
+ * sm: {
38
+ * root: 'btn-sm',
39
+ * icon: 'icon-sm'
40
+ * },
41
+ * lg: {
42
+ * root: 'btn-lg',
43
+ * icon: 'icon-lg'
44
+ * }
45
+ * }
46
+ * },
47
+ * defaultVariants: {
48
+ * size: 'sm'
49
+ * }
50
+ * })
51
+ *
52
+ * // Usage
53
+ * const classes = button({ size: 'lg' })
54
+ * // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }
55
+ * ```
56
+ */
57
+ declare const scv: SlotClassVariantCreatorFn;
58
+
59
+ export { type SlotClassRecord, type SlotClassVariantCreatorFn, type SlotClassVariantDefinition, type SlotClassVariantExtendProps, type SlotClassVariantFn, type SlotClassVariantFnProps, type SlotClassVariantRecord, scv as default, scv };
package/dist/scv.js ADDED
@@ -0,0 +1,2 @@
1
+ function m(s){if(typeof s=="string")return s;if(typeof s=="number"||typeof s=="bigint")return String(s);if(s==null||typeof s=="boolean")return "";let e="";if(Array.isArray(s)){let t=0,a,n;for(;t<s.length;t++)(a=s[t])&&(n=m(a))&&(e&&(e+=" "),e+=n);return e}for(let t in s)s[t]&&(e&&(e+=" "),e+=t);return e}function p(...s){let e="",t=0,a,n;for(;t<s.length;t++)(a=s[t])&&(n=m(a))&&(e&&(e+=" "),e+=n);return e}function x(s,e,t){let a={...s};if(e)for(let n in e)e[n]!==void 0&&(!t||!t.includes(n))&&(a[n]=e[n]);return a}var g=s=>{let{slots:e,base:t,variants:a,compoundVariants:n,defaultVariants:V,classNameResolver:S=p}=s;return a?i=>{let c=x(V,i,["classNames"]),o={};for(let r of e)t?.[r]?o[r]=Array.isArray(t[r])?[...t[r]]:[t[r]]:o[r]=[];for(let r in c){let l=a[r]?.[c[r]];if(l)for(let d in l)o[d]?.push(l[d]);}if(n)for(let r=0;r<n.length;r++){let l=n[r],d=true;for(let f in l){if(f==="classNames")continue;let u=l[f],y=c[f];if(Array.isArray(u)?!u.includes(y):u!==y){d=false;break}}if(d&&l.classNames)for(let f in l.classNames)o[f]?.push(l.classNames[f]);}if(i?.classNames)for(let r in i.classNames)o[r]?.push(i.classNames[r]);let C={};for(let r in o)C[r]=S(o[r]);return C}:i=>{let c={};for(let o of e)c[o]=S(t?.[o],i?.classNames?.[o]);return c}},T=g;export{T as default,g as scv};//# sourceMappingURL=scv.js.map
2
+ //# sourceMappingURL=scv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cx.ts","../src/utils/merge-props.ts","../src/scv.ts"],"names":["toVal","input","result","i","tmpClassValue","tmpClassName","key","cx","args","mergeProps","defaultProps","props","omitKeys","merged","k","scv","config","slots","base","variants","compoundVariants","defaultVariants","classNameResolver","mergedProps","slotClassValues","slot","cls","compound","matches","value","propValue","scv_default"],"mappings":"AAMA,SAASA,EAAMC,CAAAA,CAA2B,CACxC,GAAI,OAAOA,CAAAA,EAAU,SACnB,OAAOA,CAAAA,CAGT,GAAI,OAAOA,CAAAA,EAAU,UAAY,OAAOA,CAAAA,EAAU,SAChD,OAAO,MAAA,CAAOA,CAAK,CAAA,CAGrB,GAAIA,CAAAA,EAAU,IAAA,EAA+B,OAAOA,CAAAA,EAAU,SAAA,CAC5D,OAAO,EAAA,CAGT,IAAIC,EAAS,EAAA,CAEb,GAAI,MAAM,OAAA,CAAQD,CAAK,EAAG,CACxB,IAAIE,EAAI,CAAA,CACJC,CAAAA,CACAC,EACJ,KAAOF,CAAAA,CAAIF,CAAAA,CAAM,MAAA,CAAQE,KAClBC,CAAAA,CAAgBH,CAAAA,CAAME,CAAC,CAAA,IACrBE,CAAAA,CAAe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UAAA,CACtB,IAAA,IAAWF,KAAQE,CAAAA,CAAS,UAAA,CAC1BH,EAAgBC,CAAI,CAAA,EAAG,KAAKE,CAAAA,CAAS,UAAA,CAAWF,CAAI,CAAC,EAG3D,CAGF,GAAId,CAAAA,EAAO,WACT,IAAA,IAAWc,CAAAA,IAAQd,EAAM,UAAA,CACvBa,CAAAA,CAAgBC,CAAI,CAAA,EAAG,IAAA,CAAKd,EAAM,UAAA,CAAWc,CAAI,CAAC,CAAA,CAItD,IAAMvB,CAAAA,CAAS,GAEf,IAAA,IAAWuB,CAAAA,IAAQD,EACjBtB,CAAAA,CAAOuB,CAAI,EAAIH,CAAAA,CAAkBE,CAAAA,CAAgBC,CAAI,CAAC,CAAA,CAGxD,OAAOvB,CACT,CAAA,CApEUS,GAAU,CAChB,IAAMT,EAAS,EAAC,CAEhB,QAAWuB,CAAAA,IAAQR,CAAAA,CACjBf,EAAOuB,CAAI,CAAA,CAAIH,EAAkBJ,CAAAA,GAAOO,CAAI,EAAGd,CAAAA,EAAO,UAAA,GAAac,CAAI,CAAC,CAAA,CAG1E,OAAOvB,CACT,CA6DJ,EAEO6B,CAAAA,CAAQhB","file":"scv.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, 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"]}
package/dist/ssv.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});function u(c,o,a){let S={...c};if(o)for(let r in o)o[r]!==void 0&&(!a||!a.includes(r))&&(S[r]=o[r]);return S}var x=c=>{let{slots:o,base:a,variants:S,compoundVariants:r,defaultVariants:p}=c;return S?s=>{let i=u(p,s,["styles"]),e={};for(let t of o)e[t]={...a?.[t]};for(let t in i){let n=S[t]?.[i[t]];if(n)for(let d in n)Object.assign(e[d],n[d]);}if(r)for(let t=0;t<r.length;t++){let n=r[t],d=true;for(let l in n){if(l==="styles")continue;let y=n[l],f=i[l];if(Array.isArray(y)?!y.includes(f):y!==f){d=false;break}}if(d&&n.styles)for(let l in n.styles)Object.assign(e[l],n.styles[l]);}if(s?.styles)for(let t in s.styles)Object.assign(e[t],s.styles[t]);return e}:s=>{let i={};for(let e of o)i[e]={...a?.[e],...s?.styles?.[e]};return i}},V=x;exports.default=V;exports.ssv=x;//# sourceMappingURL=ssv.cjs.map
2
+ //# sourceMappingURL=ssv.cjs.map
@@ -0,0 +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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AU,IAAA,CAEd,IAAA,IAAWJ,KAAOG,CAAAA,CAAU,CAC1B,GAAIH,CAAAA,GAAQ,QAAA,CAAU,SACtB,IAAMK,CAAAA,CAAQF,CAAAA,CAASH,CAA4B,CAAA,CAC7CM,CAAAA,CAAYT,CAAAA,CAAYG,CAAG,EAEjC,GAAI,KAAA,CAAM,OAAA,CAAQK,CAAK,CAAA,CAAI,CAACA,EAAM,QAAA,CAASC,CAAS,CAAA,CAAID,CAAAA,GAAUC,CAAAA,CAAW,CAC3EF,EAAU,KAAA,CACV,KACF,CACF,CAEA,GAAIA,CAAAA,EAAWD,CAAAA,CAAS,MAAA,CACtB,IAAA,IAAWJ,CAAAA,IAAQI,CAAAA,CAAS,MAAA,CAC1B,MAAA,CAAO,MAAA,CAAOL,EAAOC,CAAI,CAAA,CAAGI,CAAAA,CAAS,MAAA,CAAOJ,CAAI,CAAC,EAGvD,CAGF,GAAIb,CAAAA,EAAO,MAAA,CACT,IAAA,IAAWa,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.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"]}
package/dist/ssv.d.cts ADDED
@@ -0,0 +1,54 @@
1
+ import { P as PartialRecord, C as CssProperties, O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.cjs';
2
+ import 'csstype';
3
+
4
+ type SlotStyleRecord<S extends string> = PartialRecord<S, CssProperties>;
5
+ type SlotStyleVariantRecord<S extends string> = Record<string, Record<string, SlotStyleRecord<S>>>;
6
+ type SlotStyleVariantExtendProps<S extends string> = {
7
+ styles: SlotStyleRecord<S>;
8
+ };
9
+ interface SlotStyleVariantDefinition<S extends string, T extends SlotStyleVariantRecord<S> | undefined> {
10
+ slots: S[];
11
+ base?: SlotStyleRecord<S>;
12
+ variants?: T;
13
+ compoundVariants?: (ObjectKeyArrayPicker<T> & SlotStyleVariantExtendProps<S>)[];
14
+ defaultVariants?: ObjectKeyPicker<T>;
15
+ }
16
+ type SlotStyleVariantFnProps<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = T extends undefined ? Partial<SlotStyleVariantExtendProps<S>> : ObjectKeyPicker<T> & Partial<SlotStyleVariantExtendProps<S>>;
17
+ type SlotStyleVariantFn<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = (props?: SlotStyleVariantFnProps<S, T>) => Record<S, CssProperties>;
18
+ type SlotStyleVariantCreatorFn = <S extends string, T extends SlotStyleVariantRecord<S> | undefined>(config: SlotStyleVariantDefinition<S, T>) => SlotStyleVariantFn<S, T>;
19
+ /**
20
+ * Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.
21
+ *
22
+ * @param config - Configuration object for creating style variants
23
+ * @returns A function that accepts variant props and returns composed styles for each slot
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const buttonStyles = csv({
28
+ * slots: ['root', 'icon'],
29
+ * base: {
30
+ * root: { padding: '8px' },
31
+ * icon: { size: '16px' }
32
+ * },
33
+ * variants: {
34
+ * size: {
35
+ * small: {
36
+ * root: { padding: '4px' },
37
+ * icon: { size: '12px' }
38
+ * },
39
+ * large: {
40
+ * root: { padding: '12px' },
41
+ * icon: { size: '20px' }
42
+ * }
43
+ * }
44
+ * }
45
+ * });
46
+ *
47
+ * // Usage
48
+ * const styles = buttonStyles({ size: 'small' });
49
+ * // => { root: { padding: '4px' }, icon: { size: '12px' } }
50
+ * ```
51
+ */
52
+ declare const ssv: SlotStyleVariantCreatorFn;
53
+
54
+ export { type SlotStyleRecord, type SlotStyleVariantCreatorFn, type SlotStyleVariantDefinition, type SlotStyleVariantExtendProps, type SlotStyleVariantFn, type SlotStyleVariantFnProps, type SlotStyleVariantRecord, ssv as default, ssv };
package/dist/ssv.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { P as PartialRecord, C as CssProperties, O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.js';
2
+ import 'csstype';
3
+
4
+ type SlotStyleRecord<S extends string> = PartialRecord<S, CssProperties>;
5
+ type SlotStyleVariantRecord<S extends string> = Record<string, Record<string, SlotStyleRecord<S>>>;
6
+ type SlotStyleVariantExtendProps<S extends string> = {
7
+ styles: SlotStyleRecord<S>;
8
+ };
9
+ interface SlotStyleVariantDefinition<S extends string, T extends SlotStyleVariantRecord<S> | undefined> {
10
+ slots: S[];
11
+ base?: SlotStyleRecord<S>;
12
+ variants?: T;
13
+ compoundVariants?: (ObjectKeyArrayPicker<T> & SlotStyleVariantExtendProps<S>)[];
14
+ defaultVariants?: ObjectKeyPicker<T>;
15
+ }
16
+ type SlotStyleVariantFnProps<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = T extends undefined ? Partial<SlotStyleVariantExtendProps<S>> : ObjectKeyPicker<T> & Partial<SlotStyleVariantExtendProps<S>>;
17
+ type SlotStyleVariantFn<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = (props?: SlotStyleVariantFnProps<S, T>) => Record<S, CssProperties>;
18
+ type SlotStyleVariantCreatorFn = <S extends string, T extends SlotStyleVariantRecord<S> | undefined>(config: SlotStyleVariantDefinition<S, T>) => SlotStyleVariantFn<S, T>;
19
+ /**
20
+ * Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.
21
+ *
22
+ * @param config - Configuration object for creating style variants
23
+ * @returns A function that accepts variant props and returns composed styles for each slot
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const buttonStyles = csv({
28
+ * slots: ['root', 'icon'],
29
+ * base: {
30
+ * root: { padding: '8px' },
31
+ * icon: { size: '16px' }
32
+ * },
33
+ * variants: {
34
+ * size: {
35
+ * small: {
36
+ * root: { padding: '4px' },
37
+ * icon: { size: '12px' }
38
+ * },
39
+ * large: {
40
+ * root: { padding: '12px' },
41
+ * icon: { size: '20px' }
42
+ * }
43
+ * }
44
+ * }
45
+ * });
46
+ *
47
+ * // Usage
48
+ * const styles = buttonStyles({ size: 'small' });
49
+ * // => { root: { padding: '4px' }, icon: { size: '12px' } }
50
+ * ```
51
+ */
52
+ declare const ssv: SlotStyleVariantCreatorFn;
53
+
54
+ export { type SlotStyleRecord, type SlotStyleVariantCreatorFn, type SlotStyleVariantDefinition, type SlotStyleVariantExtendProps, type SlotStyleVariantFn, type SlotStyleVariantFnProps, type SlotStyleVariantRecord, ssv as default, ssv };
package/dist/ssv.js ADDED
@@ -0,0 +1,2 @@
1
+ function u(c,o,a){let S={...c};if(o)for(let r in o)o[r]!==void 0&&(!a||!a.includes(r))&&(S[r]=o[r]);return S}var x=c=>{let{slots:o,base:a,variants:S,compoundVariants:r,defaultVariants:p}=c;return S?s=>{let i=u(p,s,["styles"]),e={};for(let t of o)e[t]={...a?.[t]};for(let t in i){let n=S[t]?.[i[t]];if(n)for(let d in n)Object.assign(e[d],n[d]);}if(r)for(let t=0;t<r.length;t++){let n=r[t],d=true;for(let l in n){if(l==="styles")continue;let y=n[l],f=i[l];if(Array.isArray(y)?!y.includes(f):y!==f){d=false;break}}if(d&&n.styles)for(let l in n.styles)Object.assign(e[l],n.styles[l]);}if(s?.styles)for(let t in s.styles)Object.assign(e[t],s.styles[t]);return e}:s=>{let i={};for(let e of o)i[e]={...a?.[e],...s?.styles?.[e]};return i}},V=x;export{V as default,x as ssv};//# sourceMappingURL=ssv.js.map
2
+ //# sourceMappingURL=ssv.js.map
@@ -0,0 +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,CACz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R,CAAAA,CAAiBO,CAAC,CAAA,CAC/BE,CAAAA,CAAU,IAAA,CAEd,IAAA,IAAWJ,KAAOG,CAAAA,CAAU,CAC1B,GAAIH,CAAAA,GAAQ,QAAA,CAAU,SACtB,IAAMK,CAAAA,CAAQF,CAAAA,CAASH,CAA4B,CAAA,CAC7CM,CAAAA,CAAYT,CAAAA,CAAYG,CAAG,EAEjC,GAAI,KAAA,CAAM,OAAA,CAAQK,CAAK,CAAA,CAAI,CAACA,EAAM,QAAA,CAASC,CAAS,CAAA,CAAID,CAAAA,GAAUC,CAAAA,CAAW,CAC3EF,EAAU,KAAA,CACV,KACF,CACF,CAEA,GAAIA,CAAAA,EAAWD,CAAAA,CAAS,MAAA,CACtB,IAAA,IAAWJ,CAAAA,IAAQI,CAAAA,CAAS,MAAA,CAC1B,MAAA,CAAO,MAAA,CAAOL,EAAOC,CAAI,CAAA,CAAGI,CAAAA,CAAS,MAAA,CAAOJ,CAAI,CAAC,EAGvD,CAGF,GAAIb,CAAAA,EAAO,MAAA,CACT,IAAA,IAAWa,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"]}
package/dist/sv.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});function p(d,e,s){let n={...d};if(e)for(let r in e)e[r]!==void 0&&(!s||!s.includes(r))&&(n[r]=e[r]);return n}var P=d=>{let{base:e,variants:s,compoundVariants:n,defaultVariants:r}=d;return s?a=>{let o={...e},c=p(r,a,["style"]);for(let i in c){let t=s[i]?.[c[i]];t&&Object.assign(o,t);}if(n)for(let i=0;i<n.length;i++){let t=n[i],f=true;for(let y in t){if(y==="style")continue;let l=t[y],u=c[y];if(Array.isArray(l)?!l.includes(u):l!==u){f=false;break}}f&&t.style&&Object.assign(o,t.style);}return a?.style&&Object.assign(o,a.style),o}:a=>({...e,...a?.style})},S=P;exports.default=S;exports.sv=P;//# sourceMappingURL=sv.cjs.map
2
+ //# sourceMappingURL=sv.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/merge-props.ts","../src/sv.ts"],"names":["mergeProps","defaultProps","props","omitKeys","merged","k","sv","config","base","variants","compoundVariants","defaultVariants","result","mergedProps","key","styleValue","compound","matches","value","propValue","sv_default"],"mappings":"sEAAO,SAASA,EACdC,CAAAA,CACAC,CAAAA,CACAC,EACyB,CACzB,IAAMC,EAAkC,CAAE,GAAGH,CAAa,CAAA,CAE1D,GAAIC,CAAAA,CACF,IAAA,IAAWG,KAAKH,CAAAA,CACVA,CAAAA,CAAMG,CAAC,CAAA,GAAM,MAAA,GAAc,CAACF,CAAAA,EAAY,CAACA,CAAAA,CAAS,QAAA,CAASE,CAAC,CAAA,CAAA,GAC9DD,CAAAA,CAAOC,CAAC,CAAA,CAAIH,CAAAA,CAAMG,CAAC,CAAA,CAAA,CAKzB,OAAOD,CACT,KCoCaE,CAAAA,CAA6BC,CAAAA,EAAW,CACnD,GAAM,CAAE,IAAA,CAAAC,CAAAA,CAAM,SAAAC,CAAAA,CAAU,gBAAA,CAAAC,EAAkB,eAAA,CAAAC,CAAgB,EAAIJ,CAAAA,CAE9D,OAAKE,CAAAA,CAIGP,CAAAA,EAAU,CAChB,IAAMU,CAAAA,CAAwB,CAAE,GAAGJ,CAAK,EAElCK,CAAAA,CAAcb,CAAAA,CAAWW,CAAAA,CAAiBT,CAAAA,CAAO,CAAC,OAAO,CAAC,EAEhE,IAAA,IAAWY,CAAAA,IAAOD,EAAa,CAC7B,IAAME,CAAAA,CAAaN,CAAAA,CAASK,CAAG,CAAA,GAAID,CAAAA,CAAYC,CAAG,CAAW,CAAA,CACzDC,GACF,MAAA,CAAO,MAAA,CAAOH,CAAAA,CAAQG,CAAU,EAEpC,CAEA,GAAIL,EACF,IAAA,IAAS,CAAA,CAAI,EAAG,CAAA,CAAIA,CAAAA,CAAiB,MAAA,CAAQ,CAAA,EAAA,CAAK,CAChD,IAAMM,CAAAA,CAAWN,EAAiB,CAAC,CAAA,CAC/BO,EAAU,IAAA,CACd,IAAA,IAAWH,CAAAA,IAAOE,CAAAA,CAAU,CAC1B,GAAIF,CAAAA,GAAQ,QAAS,SACrB,IAAMI,EAAQF,CAAAA,CAASF,CAA4B,CAAA,CAC7CK,CAAAA,CAAYN,EAAYC,CAAG,CAAA,CACjC,GAAI,KAAA,CAAM,OAAA,CAAQI,CAAK,CAAA,CAAI,CAACA,CAAAA,CAAM,QAAA,CAASC,CAAS,CAAA,CAAID,CAAAA,GAAUC,EAAW,CAC3EF,CAAAA,CAAU,MACV,KACF,CACF,CACIA,CAAAA,EAAWD,EAAS,KAAA,EACtB,MAAA,CAAO,OAAOJ,CAAAA,CAAQI,CAAAA,CAAS,KAAK,EAExC,CAGF,OAAId,CAAAA,EAAO,OACT,MAAA,CAAO,MAAA,CAAOU,EAAQV,CAAAA,CAAM,KAAK,EAG5BU,CACT,CAAA,CAvCUV,CAAAA,GAAW,CAAE,GAAGM,CAAAA,CAAM,GAAGN,GAAO,KAAM,CAAA,CAwClD,EAEOkB,CAAAA,CAAQd","file":"sv.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 { 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"]}
@@ -1,17 +1,19 @@
1
- import { CssProperties, ObjectKeyArrayPicker, ObjectKeyPicker } from './utils/types';
2
- export type StyleVariantRecord = Record<string, Record<string, CssProperties>>;
3
- export type StyleVariantExtendProps = {
1
+ import { C as CssProperties, O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.cjs';
2
+ import 'csstype';
3
+
4
+ type StyleVariantRecord = Record<string, Record<string, CssProperties>>;
5
+ type StyleVariantExtendProps = {
4
6
  style: CssProperties;
5
7
  };
6
- export interface StyleVariantDefinition<T extends StyleVariantRecord | undefined> {
8
+ interface StyleVariantDefinition<T extends StyleVariantRecord | undefined> {
7
9
  base?: CssProperties;
8
10
  variants?: T;
9
11
  compoundVariants?: (ObjectKeyArrayPicker<T> & StyleVariantExtendProps)[];
10
12
  defaultVariants?: ObjectKeyPicker<T>;
11
13
  }
12
- export type StyleVariantFnProps<T extends StyleVariantRecord | undefined> = T extends undefined ? Partial<StyleVariantExtendProps> : ObjectKeyPicker<T> & Partial<StyleVariantExtendProps>;
13
- export type StyleVariantFn<T extends StyleVariantRecord | undefined> = (props?: StyleVariantFnProps<T>) => CssProperties;
14
- export type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(config: StyleVariantDefinition<T>) => StyleVariantFn<T>;
14
+ type StyleVariantFnProps<T extends StyleVariantRecord | undefined> = T extends undefined ? Partial<StyleVariantExtendProps> : ObjectKeyPicker<T> & Partial<StyleVariantExtendProps>;
15
+ type StyleVariantFn<T extends StyleVariantRecord | undefined> = (props?: StyleVariantFnProps<T>) => CssProperties;
16
+ type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(config: StyleVariantDefinition<T>) => StyleVariantFn<T>;
15
17
  /**
16
18
  * Creates a style variant function based on the provided configuration.
17
19
  *
@@ -40,5 +42,6 @@ export type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(c
40
42
  * // style = { color: 'black', fontSize: '24px', fontWeight: 'bold' }
41
43
  * ```
42
44
  */
43
- export declare const sv: StyleVariantCreatorFn;
44
- export default sv;
45
+ declare const sv: StyleVariantCreatorFn;
46
+
47
+ export { type StyleVariantCreatorFn, type StyleVariantDefinition, type StyleVariantExtendProps, type StyleVariantFn, type StyleVariantFnProps, type StyleVariantRecord, sv as default, sv };
@@ -1,17 +1,19 @@
1
- import { CssProperties, ObjectKeyArrayPicker, ObjectKeyPicker } from './utils/types';
2
- export type StyleVariantRecord = Record<string, Record<string, CssProperties>>;
3
- export type StyleVariantExtendProps = {
1
+ import { C as CssProperties, O as ObjectKeyArrayPicker, a as ObjectKeyPicker } from './types-BXKyjXhG.js';
2
+ import 'csstype';
3
+
4
+ type StyleVariantRecord = Record<string, Record<string, CssProperties>>;
5
+ type StyleVariantExtendProps = {
4
6
  style: CssProperties;
5
7
  };
6
- export interface StyleVariantDefinition<T extends StyleVariantRecord | undefined> {
8
+ interface StyleVariantDefinition<T extends StyleVariantRecord | undefined> {
7
9
  base?: CssProperties;
8
10
  variants?: T;
9
11
  compoundVariants?: (ObjectKeyArrayPicker<T> & StyleVariantExtendProps)[];
10
12
  defaultVariants?: ObjectKeyPicker<T>;
11
13
  }
12
- export type StyleVariantFnProps<T extends StyleVariantRecord | undefined> = T extends undefined ? Partial<StyleVariantExtendProps> : ObjectKeyPicker<T> & Partial<StyleVariantExtendProps>;
13
- export type StyleVariantFn<T extends StyleVariantRecord | undefined> = (props?: StyleVariantFnProps<T>) => CssProperties;
14
- export type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(config: StyleVariantDefinition<T>) => StyleVariantFn<T>;
14
+ type StyleVariantFnProps<T extends StyleVariantRecord | undefined> = T extends undefined ? Partial<StyleVariantExtendProps> : ObjectKeyPicker<T> & Partial<StyleVariantExtendProps>;
15
+ type StyleVariantFn<T extends StyleVariantRecord | undefined> = (props?: StyleVariantFnProps<T>) => CssProperties;
16
+ type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(config: StyleVariantDefinition<T>) => StyleVariantFn<T>;
15
17
  /**
16
18
  * Creates a style variant function based on the provided configuration.
17
19
  *
@@ -40,5 +42,6 @@ export type StyleVariantCreatorFn = <T extends StyleVariantRecord | undefined>(c
40
42
  * // style = { color: 'black', fontSize: '24px', fontWeight: 'bold' }
41
43
  * ```
42
44
  */
43
- export declare const sv: StyleVariantCreatorFn;
44
- export default sv;
45
+ declare const sv: StyleVariantCreatorFn;
46
+
47
+ export { type StyleVariantCreatorFn, type StyleVariantDefinition, type StyleVariantExtendProps, type StyleVariantFn, type StyleVariantFnProps, type StyleVariantRecord, sv as default, sv };
package/dist/sv.js ADDED
@@ -0,0 +1,2 @@
1
+ function p(d,e,s){let n={...d};if(e)for(let r in e)e[r]!==void 0&&(!s||!s.includes(r))&&(n[r]=e[r]);return n}var P=d=>{let{base:e,variants:s,compoundVariants:n,defaultVariants:r}=d;return s?a=>{let o={...e},c=p(r,a,["style"]);for(let i in c){let t=s[i]?.[c[i]];t&&Object.assign(o,t);}if(n)for(let i=0;i<n.length;i++){let t=n[i],f=true;for(let y in t){if(y==="style")continue;let l=t[y],u=c[y];if(Array.isArray(l)?!l.includes(u):l!==u){f=false;break}}f&&t.style&&Object.assign(o,t.style);}return a?.style&&Object.assign(o,a.style),o}:a=>({...e,...a?.style})},S=P;export{S as default,P as sv};//# sourceMappingURL=sv.js.map
2
+ //# sourceMappingURL=sv.js.map
package/dist/sv.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/merge-props.ts","../src/sv.ts"],"names":["mergeProps","defaultProps","props","omitKeys","merged","k","sv","config","base","variants","compoundVariants","defaultVariants","result","mergedProps","key","styleValue","compound","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AAA,CAAYN,EAAYC,CAAG,CAAA,CACjC,GAAI,KAAA,CAAM,OAAA,CAAQI,CAAK,CAAA,CAAI,CAACA,CAAAA,CAAM,QAAA,CAASC,CAAS,CAAA,CAAID,CAAAA,GAAUC,EAAW,CAC3EF,CAAAA,CAAU,MACV,KACF,CACF,CACIA,CAAAA,EAAWD,EAAS,KAAA,EACtB,MAAA,CAAO,OAAOJ,CAAAA,CAAQI,CAAAA,CAAS,KAAK,EAExC,CAGF,OAAId,CAAAA,EAAO,OACT,MAAA,CAAO,MAAA,CAAOU,EAAQV,CAAAA,CAAM,KAAK,EAG5BU,CACT,CAAA,CAvCUV,CAAAA,GAAW,CAAE,GAAGM,CAAAA,CAAM,GAAGN,GAAO,KAAM,CAAA,CAwClD,EAEOkB,CAAAA,CAAQd","file":"sv.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 { 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"]}
@@ -0,0 +1,16 @@
1
+ import { Properties } from 'csstype';
2
+
3
+ type OneOrMore<T> = T | T[];
4
+ type PartialRecord<S extends string, T> = Partial<Record<S, T>>;
5
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
6
+ type ObjectKeyPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
7
+ [K in keyof T]?: StringToBoolean<keyof T[K]> | undefined;
8
+ };
9
+ type ObjectKeyArrayPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
10
+ [K in keyof T]?: OneOrMore<StringToBoolean<keyof T[K]>> | undefined;
11
+ };
12
+ type CssProperties = Properties<string | number> & {
13
+ [key: `--${string}`]: string | number;
14
+ };
15
+
16
+ export type { CssProperties as C, ObjectKeyArrayPicker as O, PartialRecord as P, ObjectKeyPicker as a };
@@ -0,0 +1,16 @@
1
+ import { Properties } from 'csstype';
2
+
3
+ type OneOrMore<T> = T | T[];
4
+ type PartialRecord<S extends string, T> = Partial<Record<S, T>>;
5
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
6
+ type ObjectKeyPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
7
+ [K in keyof T]?: StringToBoolean<keyof T[K]> | undefined;
8
+ };
9
+ type ObjectKeyArrayPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
10
+ [K in keyof T]?: OneOrMore<StringToBoolean<keyof T[K]>> | undefined;
11
+ };
12
+ type CssProperties = Properties<string | number> & {
13
+ [key: `--${string}`]: string | number;
14
+ };
15
+
16
+ export type { CssProperties as C, ObjectKeyArrayPicker as O, PartialRecord as P, ObjectKeyPicker as a };
package/package.json CHANGED
@@ -1,18 +1,42 @@
1
1
  {
2
2
  "name": "css-variants",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
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
- "main": "dist/cjs/index.js",
6
- "module": "dist/esm/index.js",
7
- "types": "dist/esm/index.d.ts",
5
+ "homepage": "https://css-variants.vercel.app",
6
+ "type": "module",
7
+ "main": "dist/index.cjs",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
8
10
  "exports": {
9
11
  ".": {
10
- "require": "./dist/cjs/index.js",
11
- "import": "./dist/esm/index.js"
12
+ "types": "./dist/index.d.ts",
13
+ "require": "./dist/index.cjs",
14
+ "import": "./dist/index.js"
12
15
  },
13
- "./*": {
14
- "require": "./dist/cjs/*.js",
15
- "import": "./dist/esm/*.js"
16
+ "./cx": {
17
+ "types": "./dist/cx.d.ts",
18
+ "require": "./dist/cx.cjs",
19
+ "import": "./dist/cx.js"
20
+ },
21
+ "./cv": {
22
+ "types": "./dist/cv.d.ts",
23
+ "require": "./dist/cv.cjs",
24
+ "import": "./dist/cv.js"
25
+ },
26
+ "./scv": {
27
+ "types": "./dist/scv.d.ts",
28
+ "require": "./dist/scv.cjs",
29
+ "import": "./dist/scv.js"
30
+ },
31
+ "./sv": {
32
+ "types": "./dist/sv.d.ts",
33
+ "require": "./dist/sv.cjs",
34
+ "import": "./dist/sv.js"
35
+ },
36
+ "./ssv": {
37
+ "types": "./dist/ssv.d.ts",
38
+ "require": "./dist/ssv.cjs",
39
+ "import": "./dist/ssv.js"
16
40
  }
17
41
  },
18
42
  "files": [
@@ -24,9 +48,7 @@
24
48
  "bench": "vitest bench ./src",
25
49
  "bench:cva": "yarn add class-variance-authority --no-save && vitest bench ./benchmark/cva.bench.ts --outputJson ./benchmark/cva.bench.json --run",
26
50
  "bench:tailwind-variants": "yarn add tailwind-variants --no-save && vitest bench ./benchmark/tailwind-variants.bench.ts --outputJson ./benchmark/tailwind-variants.bench.json --run",
27
- "build:cjs": "tsc --project tsconfig.cjs.json",
28
- "build:esm": "tsc --project tsconfig.esm.json",
29
- "build": "rimraf ./dist && yarn build:cjs && yarn build:esm"
51
+ "build": "tsup"
30
52
  },
31
53
  "repository": {
32
54
  "type": "git",
@@ -64,7 +86,7 @@
64
86
  "eslint-config-prettier": "^10.1.8",
65
87
  "eslint-plugin-prettier": "^5.5.4",
66
88
  "prettier": "^3.7.4",
67
- "rimraf": "^5.0.7",
89
+ "tsup": "^8.5.1",
68
90
  "typescript": "^5.9.3",
69
91
  "typescript-eslint": "^8.49.0",
70
92
  "vitest": "^4.0.15"
package/dist/cjs/cv.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cv = void 0;
4
- const cx_1 = require("./cx");
5
- const merge_props_1 = require("./utils/merge-props");
6
- /**
7
- * Creates a class variant function that combines base classes, variants, compound variants, and default variants.
8
- *
9
- * @template T - Type of the variant record
10
- * @param config - Configuration object for creating class variants
11
- * @returns A function that accepts variant props and returns a combined class string
12
- *
13
- * @example
14
- * ```typescript
15
- * const button = cv({
16
- * base: 'px-4 py-2 rounded',
17
- * variants: {
18
- * color: {
19
- * primary: 'bg-blue-500 text-white',
20
- * secondary: 'bg-gray-500 text-white'
21
- * },
22
- * size: {
23
- * sm: 'text-sm',
24
- * lg: 'text-lg'
25
- * }
26
- * },
27
- * defaultVariants: {
28
- * color: 'primary',
29
- * size: 'sm'
30
- * }
31
- * });
32
- *
33
- * button(); // => 'px-4 py-2 rounded bg-blue-500 text-white text-sm'
34
- * button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'
35
- * ```
36
- */
37
- const cv = (config) => {
38
- const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx_1.cx } = config;
39
- if (!variants) {
40
- return (props) => classNameResolver(base, props?.className);
41
- }
42
- return (props) => {
43
- const mergedProps = (0, merge_props_1.mergeProps)(defaultVariants, props, ['className']);
44
- const classValues = [];
45
- for (const key in mergedProps) {
46
- const classValue = variants[key]?.[mergedProps[key]];
47
- if (classValue) {
48
- classValues.push(classValue);
49
- }
50
- }
51
- if (compoundVariants) {
52
- for (let i = 0; i < compoundVariants.length; i++) {
53
- const compound = compoundVariants[i];
54
- let matches = true;
55
- for (const key in compound) {
56
- if (key === 'className')
57
- continue;
58
- const value = compound[key];
59
- const propValue = mergedProps[key];
60
- if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
61
- matches = false;
62
- break;
63
- }
64
- }
65
- if (matches && compound.className) {
66
- classValues.push(compound.className);
67
- }
68
- }
69
- }
70
- return classNameResolver(base, classValues, props?.className);
71
- };
72
- };
73
- exports.cv = cv;
74
- exports.default = exports.cv;
75
- //# sourceMappingURL=cv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/cv.ts"],"names":[],"mappings":";;;AACA,6BAAqC;AACrC,qDAAgD;AAwBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACI,MAAM,EAAE,GAA0B,CAAC,MAAM,EAAE,EAAE;IAClD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,GAAG,OAAE,EAAE,GAAG,MAAM,CAAA;IAE5F,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;IAC7D,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,WAAW,GAAG,IAAA,wBAAU,EAAC,eAAe,EAAE,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;QAErE,MAAM,WAAW,GAAiB,EAAE,CAAA;QAEpC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAW,CAAC,CAAA;YAC9D,IAAI,UAAU,EAAE,CAAC;gBACf,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,gBAAgB,EAAE,CAAC;YACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACjD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA;gBACpC,IAAI,OAAO,GAAG,IAAI,CAAA;gBAClB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;oBAC3B,IAAI,GAAG,KAAK,WAAW;wBAAE,SAAQ;oBACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAA4B,CAAC,CAAA;oBACpD,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;oBAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;wBAC5E,OAAO,GAAG,KAAK,CAAA;wBACf,MAAK;oBACP,CAAC;gBACH,CAAC;gBACD,IAAI,OAAO,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;oBAClC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;gBACtC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;IAC/D,CAAC,CAAA;AACH,CAAC,CAAA;AAxCY,QAAA,EAAE,MAwCd;AAED,kBAAe,UAAE,CAAA"}
package/dist/cjs/cx.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export type ClassDictionary = Record<string, unknown>;
2
- export type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined;
3
- export type ClassArray = ClassValue[];
4
- export declare function cx(...args: ClassValue[]): string;
5
- export default cx;