css-variants 2.2.2 → 2.3.1
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/dist/cv.cjs +2 -0
- package/dist/cv.cjs.map +1 -0
- package/dist/{esm/cv.d.ts → cv.d.cts} +13 -10
- package/dist/{cjs/cv.d.ts → cv.d.ts} +13 -10
- package/dist/cv.js +2 -0
- package/dist/cv.js.map +1 -0
- package/dist/cx.cjs +2 -0
- package/dist/cx.cjs.map +1 -0
- package/dist/cx.d.cts +6 -0
- package/dist/cx.d.ts +6 -0
- package/dist/cx.js +2 -0
- package/dist/cx.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/scv.cjs +2 -0
- package/dist/scv.cjs.map +1 -0
- package/dist/scv.d.cts +59 -0
- package/dist/scv.d.ts +59 -0
- package/dist/scv.js +2 -0
- package/dist/scv.js.map +1 -0
- package/dist/ssv.cjs +2 -0
- package/dist/ssv.cjs.map +1 -0
- package/dist/ssv.d.cts +54 -0
- package/dist/ssv.d.ts +54 -0
- package/dist/ssv.js +2 -0
- package/dist/ssv.js.map +1 -0
- package/dist/sv.cjs +2 -0
- package/dist/sv.cjs.map +1 -0
- package/dist/{cjs/sv.d.ts → sv.d.cts} +12 -9
- package/dist/{esm/sv.d.ts → sv.d.ts} +12 -9
- package/dist/sv.js +2 -0
- package/dist/sv.js.map +1 -0
- package/dist/types-BXKyjXhG.d.cts +16 -0
- package/dist/types-BXKyjXhG.d.ts +16 -0
- package/package.json +36 -18
- package/dist/cjs/cv.js +0 -75
- package/dist/cjs/cv.js.map +0 -1
- package/dist/cjs/cx.d.ts +0 -5
- package/dist/cjs/cx.js +0 -57
- package/dist/cjs/cx.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/scv.d.ts +0 -56
- package/dist/cjs/scv.js +0 -107
- package/dist/cjs/scv.js.map +0 -1
- package/dist/cjs/ssv.d.ts +0 -51
- package/dist/cjs/ssv.js +0 -94
- package/dist/cjs/ssv.js.map +0 -1
- package/dist/cjs/sv.js +0 -74
- package/dist/cjs/sv.js.map +0 -1
- package/dist/cjs/utils/merge-props.d.ts +0 -1
- package/dist/cjs/utils/merge-props.js +0 -15
- package/dist/cjs/utils/merge-props.js.map +0 -1
- package/dist/cjs/utils/types.d.ts +0 -16
- package/dist/cjs/utils/types.js +0 -3
- package/dist/cjs/utils/types.js.map +0 -1
- package/dist/esm/cv.js +0 -71
- package/dist/esm/cv.js.map +0 -1
- package/dist/esm/cx.d.ts +0 -5
- package/dist/esm/cx.js +0 -54
- package/dist/esm/cx.js.map +0 -1
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/scv.d.ts +0 -56
- package/dist/esm/scv.js +0 -103
- package/dist/esm/scv.js.map +0 -1
- package/dist/esm/ssv.d.ts +0 -51
- package/dist/esm/ssv.js +0 -90
- package/dist/esm/ssv.js.map +0 -1
- package/dist/esm/sv.js +0 -70
- package/dist/esm/sv.js.map +0 -1
- package/dist/esm/utils/merge-props.d.ts +0 -1
- package/dist/esm/utils/merge-props.js +0 -12
- package/dist/esm/utils/merge-props.js.map +0 -1
- package/dist/esm/utils/types.d.ts +0 -16
- package/dist/esm/utils/types.js +0 -2
- package/dist/esm/utils/types.js.map +0 -1
package/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
|
package/dist/ssv.js.map
ADDED
|
@@ -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,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,C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A,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
|
package/dist/sv.cjs.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","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 './
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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 './
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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","matches","value","propValue","sv_default"],"mappings":"AAAO,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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AGN,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,19 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-variants",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
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
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.cjs",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"import": "./dist/index.js"
|
|
13
15
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
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"
|
|
17
40
|
}
|
|
18
41
|
},
|
|
19
42
|
"files": [
|
|
@@ -23,11 +46,9 @@
|
|
|
23
46
|
"lint": "eslint .",
|
|
24
47
|
"test": "vitest run --coverage",
|
|
25
48
|
"bench": "vitest bench ./src",
|
|
26
|
-
"bench:cva": "
|
|
27
|
-
"bench:tailwind-variants": "
|
|
28
|
-
"build
|
|
29
|
-
"build:esm": "tsc --project tsconfig.esm.json",
|
|
30
|
-
"build": "rimraf ./dist && yarn build:cjs && yarn build:esm"
|
|
49
|
+
"bench:cva": "npm install class-variance-authority --no-save --no-package-lock && vitest bench ./benchmark/cva.bench.ts --outputJson ./benchmark/cva.bench.json --run",
|
|
50
|
+
"bench:tailwind-variants": "npm install tailwind-variants --no-save --no-package-lock && vitest bench ./benchmark/tailwind-variants.bench.ts --outputJson ./benchmark/tailwind-variants.bench.json --run",
|
|
51
|
+
"build": "tsup"
|
|
31
52
|
},
|
|
32
53
|
"repository": {
|
|
33
54
|
"type": "git",
|
|
@@ -65,12 +86,9 @@
|
|
|
65
86
|
"eslint-config-prettier": "^10.1.8",
|
|
66
87
|
"eslint-plugin-prettier": "^5.5.4",
|
|
67
88
|
"prettier": "^3.7.4",
|
|
68
|
-
"
|
|
89
|
+
"tsup": "^8.5.1",
|
|
69
90
|
"typescript": "^5.9.3",
|
|
70
91
|
"typescript-eslint": "^8.49.0",
|
|
71
92
|
"vitest": "^4.0.15"
|
|
72
|
-
},
|
|
73
|
-
"dependencies": {
|
|
74
|
-
"tailwind-variants": "^3.2.2"
|
|
75
93
|
}
|
|
76
94
|
}
|
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
|
package/dist/cjs/cv.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/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M,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;
|
package/dist/cjs/cx.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// credit: https://github.com/lukeed/clsx
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.cx = cx;
|
|
5
|
-
function toVal(input) {
|
|
6
|
-
if (typeof input === 'string') {
|
|
7
|
-
return input;
|
|
8
|
-
}
|
|
9
|
-
if (typeof input === 'number' || typeof input === 'bigint') {
|
|
10
|
-
return String(input);
|
|
11
|
-
}
|
|
12
|
-
if (input === null || input === undefined || typeof input === 'boolean') {
|
|
13
|
-
return '';
|
|
14
|
-
}
|
|
15
|
-
let result = '';
|
|
16
|
-
if (Array.isArray(input)) {
|
|
17
|
-
let i = 0;
|
|
18
|
-
let tmpClassValue;
|
|
19
|
-
let tmpClassName;
|
|
20
|
-
for (; i < input.length; i++) {
|
|
21
|
-
if ((tmpClassValue = input[i])) {
|
|
22
|
-
if ((tmpClassName = toVal(tmpClassValue))) {
|
|
23
|
-
if (result)
|
|
24
|
-
result += ' ';
|
|
25
|
-
result += tmpClassName;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
for (const key in input) {
|
|
32
|
-
if (input[key]) {
|
|
33
|
-
if (result)
|
|
34
|
-
result += ' ';
|
|
35
|
-
result += key;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
function cx(...args) {
|
|
41
|
-
let result = '';
|
|
42
|
-
let i = 0;
|
|
43
|
-
let tmpClassValue;
|
|
44
|
-
let tmpClassName;
|
|
45
|
-
for (; i < args.length; i++) {
|
|
46
|
-
if ((tmpClassValue = args[i])) {
|
|
47
|
-
if ((tmpClassName = toVal(tmpClassValue))) {
|
|
48
|
-
if (result)
|
|
49
|
-
result += ' ';
|
|
50
|
-
result += tmpClassName;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
exports.default = cx;
|
|
57
|
-
//# sourceMappingURL=cx.js.map
|
package/dist/cjs/cx.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cx.js","sourceRoot":"","sources":["../../src/cx.ts"],"names":[],"mappings":";AAAA,yCAAyC;;AA+CzC,gBAgBC;AAzDD,SAAS,KAAK,CAAC,KAAiB;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,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AAE,EAAE,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;gBAC1C,IAAI,MAAM;oBAAE,MAAM,IAAI,GAAG,CAAA;gBACzB,MAAM,IAAI,YAAY,CAAA;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,kBAAe,EAAE,CAAA"}
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cx"), exports);
|
|
18
|
-
__exportStar(require("./cv"), exports);
|
|
19
|
-
__exportStar(require("./scv"), exports);
|
|
20
|
-
__exportStar(require("./sv"), exports);
|
|
21
|
-
__exportStar(require("./ssv"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAoB;AACpB,uCAAoB;AACpB,wCAAqB;AACrB,uCAAoB;AACpB,wCAAqB"}
|
package/dist/cjs/scv.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord } from './utils/types';
|
|
2
|
-
import { cx, ClassValue } from './cx';
|
|
3
|
-
export type SlotClassRecord<S extends string> = PartialRecord<S, ClassValue>;
|
|
4
|
-
export type SlotClassVariantRecord<S extends string> = Record<string, Record<string, SlotClassRecord<S>>>;
|
|
5
|
-
export type SlotClassVariantExtendProps<S extends string> = {
|
|
6
|
-
classNames: SlotClassRecord<S>;
|
|
7
|
-
};
|
|
8
|
-
export interface SlotClassVariantDefinition<S extends string, T extends SlotClassVariantRecord<S> | undefined> {
|
|
9
|
-
slots: S[];
|
|
10
|
-
base?: SlotClassRecord<S>;
|
|
11
|
-
variants?: T;
|
|
12
|
-
compoundVariants?: (ObjectKeyArrayPicker<T> & SlotClassVariantExtendProps<S>)[];
|
|
13
|
-
defaultVariants?: ObjectKeyPicker<T>;
|
|
14
|
-
classNameResolver?: typeof cx;
|
|
15
|
-
}
|
|
16
|
-
export type SlotClassVariantFnProps<S extends string, T extends SlotClassVariantRecord<S> | undefined> = T extends undefined ? Partial<SlotClassVariantExtendProps<S>> : ObjectKeyPicker<T> & Partial<SlotClassVariantExtendProps<S>>;
|
|
17
|
-
export type SlotClassVariantFn<S extends string, T extends SlotClassVariantRecord<S> | undefined> = (props?: SlotClassVariantFnProps<S, T>) => Record<S, string>;
|
|
18
|
-
export type SlotClassVariantCreatorFn = <S extends string, T extends SlotClassVariantRecord<S> | undefined>(config: SlotClassVariantDefinition<S, T>) => SlotClassVariantFn<S, T>;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a slot-based class variant function that manages class names for multiple slots with variants.
|
|
21
|
-
*
|
|
22
|
-
* @param config - Configuration object for creating the variant function
|
|
23
|
-
* @returns A function that accepts variant props and returns class names for each slot
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const button = scv({
|
|
28
|
-
* slots: ['root', 'icon'],
|
|
29
|
-
* base: {
|
|
30
|
-
* root: 'btn',
|
|
31
|
-
* icon: 'btn-icon'
|
|
32
|
-
* },
|
|
33
|
-
* variants: {
|
|
34
|
-
* size: {
|
|
35
|
-
* sm: {
|
|
36
|
-
* root: 'btn-sm',
|
|
37
|
-
* icon: 'icon-sm'
|
|
38
|
-
* },
|
|
39
|
-
* lg: {
|
|
40
|
-
* root: 'btn-lg',
|
|
41
|
-
* icon: 'icon-lg'
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
* },
|
|
45
|
-
* defaultVariants: {
|
|
46
|
-
* size: 'sm'
|
|
47
|
-
* }
|
|
48
|
-
* })
|
|
49
|
-
*
|
|
50
|
-
* // Usage
|
|
51
|
-
* const classes = button({ size: 'lg' })
|
|
52
|
-
* // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare const scv: SlotClassVariantCreatorFn;
|
|
56
|
-
export default scv;
|