@yaredfall/class-variants 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +1 -67
- package/package.json +56 -52
- package/build/chunk-3RDDXOQ3.js +0 -17
- package/build/chunk-3RDDXOQ3.js.map +0 -1
- package/build/chunk-BNE2ZOTW.js +0 -39
- package/build/chunk-BNE2ZOTW.js.map +0 -1
- package/build/chunk-PLDDJCW6.js +0 -49
- package/build/chunk-PLDDJCW6.js.map +0 -1
- package/build/index.cjs.map +0 -1
- package/build/index.d.cts +0 -32
- package/build/index.d.ts +0 -32
- package/build/index.js +0 -9
- package/build/index.js.map +0 -1
- package/build/index.test.cjs +0 -16251
- package/build/index.test.cjs.map +0 -1
- package/build/index.test.d.cts +0 -2
- package/build/index.test.d.ts +0 -2
- package/build/index.test.js +0 -14902
- package/build/index.test.js.map +0 -1
- package/build/magic-string.es-4OEJ3555.js +0 -1275
- package/build/magic-string.es-4OEJ3555.js.map +0 -1
- package/build/utils.cjs +0 -43
- package/build/utils.cjs.map +0 -1
- package/build/utils.d.cts +0 -12
- package/build/utils.d.ts +0 -12
- package/build/utils.js +0 -12
- package/build/utils.js.map +0 -1
- package/build/vue.cjs +0 -88
- package/build/vue.cjs.map +0 -1
- package/build/vue.d.cts +0 -18
- package/build/vue.d.ts +0 -18
- package/build/vue.js +0 -27
- package/build/vue.js.map +0 -1
- package/src/index.ts +0 -79
- package/src/utils.ts +0 -25
- package/src/vue.ts +0 -42
- package/tsconfig.json +0 -23
- package/tsup.config.js +0 -13
package/build/index.cjs
CHANGED
|
@@ -1,68 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
cv: () => cv
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
var import_clsx = require("clsx");
|
|
27
|
-
|
|
28
|
-
// src/utils.ts
|
|
29
|
-
function getKeys(obj) {
|
|
30
|
-
return Object.keys(obj);
|
|
31
|
-
}
|
|
32
|
-
function getEntries(obj) {
|
|
33
|
-
return Object.entries(obj);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// src/index.ts
|
|
37
|
-
var cv = (config, options = {}) => {
|
|
38
|
-
const { variants, defaultVariant, baseClass } = config;
|
|
39
|
-
const merge = options.merge ?? import_clsx.clsx;
|
|
40
|
-
if (variants == null) return (props) => merge(baseClass, props?.class);
|
|
41
|
-
const compoundVariants = typeof config.compoundVariants === "function" ? config.compoundVariants(variants) : config.compoundVariants;
|
|
42
|
-
return (props) => {
|
|
43
|
-
const variantClassNames = getKeys(variants).map((variant) => {
|
|
44
|
-
const variantProp = props?.[variant];
|
|
45
|
-
const defaultVariantProp = defaultVariant?.[variant];
|
|
46
|
-
const variantKey = variantProp || defaultVariantProp;
|
|
47
|
-
return variants[variant][variantKey];
|
|
48
|
-
});
|
|
49
|
-
const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {
|
|
50
|
-
const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {
|
|
51
|
-
const defaultsSelector = defaultVariant?.[cvKey];
|
|
52
|
-
const propsSelector = props?.[cvKey];
|
|
53
|
-
if (cvSelector === true) return propsSelector !== void 0;
|
|
54
|
-
else if (cvSelector === false) return propsSelector === void 0;
|
|
55
|
-
const selector = propsSelector ?? defaultsSelector;
|
|
56
|
-
return Array.isArray(cvSelector) ? cvSelector.includes(selector) : selector === cvSelector;
|
|
57
|
-
});
|
|
58
|
-
if (shouldApplyCompoundVariant) acc.push(cvClass);
|
|
59
|
-
return acc;
|
|
60
|
-
}, new Array());
|
|
61
|
-
return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
-
0 && (module.exports = {
|
|
66
|
-
cv
|
|
67
|
-
});
|
|
1
|
+
"use strict";var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var s in n)l(e,s,{get:n[s],enumerable:!0})},D=(e,n,s,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of E(n))!T.call(e,r)&&r!==s&&l(e,r,{get:()=>n[r],enumerable:!(t=b(n,r))||t.enumerable});return e};var U=e=>D(l({},"__esModule",{value:!0}),e);var B={};N(B,{cv:()=>j,onlyWhenDefined:()=>R,onlyWhenUndefined:()=>h});module.exports=U(B);var g=require("clsx");function u(e){return Object.keys(e)}function c(e){return Object.entries(e)}function k(e){return Object.fromEntries(c(e).map(([n,s])=>[n,u(s)]))}var j=(e,n={})=>{let s=n.merge??g.clsx,{variants:t,defaultVariant:r,base:K}=e,p=t?u(t):[],C=t?k(t):{},m=r??{},P=t?typeof e.compoundVariants=="function"?e.compoundVariants({variants:t,keys:p,options:C,defaults:m}):e.compoundVariants:void 0;return Object.assign(i=>{let v=t?p.map(o=>{let d=i?.[o],y=r?.[o],V=d?.toString()||y?.toString();return V?t[o][V]:void 0}):void 0,S=P?.reduce((o,{class:d,className:y,...V})=>(c(V).every(([O,a])=>{let _=r?.[O],f=i?.[O];if(typeof a=="object"&&"__token"in a){if(a.__token===R.__token)return f!==void 0;if(a.__token===h.__token)return f===void 0}let x=f??_;return Array.isArray(a)?a.some(W=>x===W):x===a})&&o.push(d,y),o),new Array);return s(K,v,S,i?.class,i?.className)},{keys:p,options:C,defaults:m})},R={__token:"OnlyWhenDefined"},h={__token:"OnlyWhenUndefined"};0&&(module.exports={cv,onlyWhenDefined,onlyWhenUndefined});
|
|
68
2
|
//# sourceMappingURL=index.cjs.map
|
package/package.json
CHANGED
|
@@ -1,57 +1,61 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
},
|
|
8
|
-
"version": "0.0.7",
|
|
9
|
-
"type": "module",
|
|
10
|
-
"main": "build/index.cjs",
|
|
11
|
-
"module": "build/index.js",
|
|
12
|
-
"types": "build/index.d.ts",
|
|
13
|
-
"exports": {
|
|
14
|
-
".": {
|
|
15
|
-
"import": {
|
|
16
|
-
"types": "./build/index.d.ts",
|
|
17
|
-
"default": "./build/index.js"
|
|
18
|
-
},
|
|
19
|
-
"require": {
|
|
20
|
-
"types": "./build/index.d.cts",
|
|
21
|
-
"default": "./build/index.cjs"
|
|
22
|
-
}
|
|
2
|
+
"name": "@yaredfall/class-variants",
|
|
3
|
+
"author": "yaredfall",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
23
7
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
"version": "0.1.0",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"main": "build/index.cjs",
|
|
14
|
+
"module": "build/index.js",
|
|
15
|
+
"types": "build/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./build/index.d.ts",
|
|
20
|
+
"default": "./build/index.js"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./build/index.d.cts",
|
|
24
|
+
"default": "./build/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"./utils": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./build/utils.d.ts",
|
|
30
|
+
"default": "./build/utils.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./build/utils.d.cts",
|
|
34
|
+
"default": "./build/utils.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./vue": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./build/vue.d.ts",
|
|
40
|
+
"default": "./build/vue.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./build/vue.d.cts",
|
|
44
|
+
"default": "./build/vue.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
33
48
|
},
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"default": "./build/vue.js"
|
|
38
|
-
},
|
|
39
|
-
"require": {
|
|
40
|
-
"types": "./build/vue.d.cts",
|
|
41
|
-
"default": "./build/vue.cjs"
|
|
42
|
-
}
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc && tsup",
|
|
51
|
+
"prepack": "npm run build"
|
|
43
52
|
},
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"vue": "^3.4.29"
|
|
53
|
-
},
|
|
54
|
-
"dependencies": {
|
|
55
|
-
"clsx": "^2.1.1"
|
|
56
|
-
}
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"tsup": "^8.1.0",
|
|
55
|
+
"typescript": "^5.2.2",
|
|
56
|
+
"vue": "^3.4.29"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"clsx": "^2.1.1"
|
|
60
|
+
}
|
|
57
61
|
}
|
package/build/chunk-3RDDXOQ3.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
function getKeys(obj) {
|
|
3
|
-
return Object.keys(obj);
|
|
4
|
-
}
|
|
5
|
-
function getEntries(obj) {
|
|
6
|
-
return Object.entries(obj);
|
|
7
|
-
}
|
|
8
|
-
function getVariantsOptions(variants) {
|
|
9
|
-
return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
getKeys,
|
|
14
|
-
getEntries,
|
|
15
|
-
getVariantsOptions
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=chunk-3RDDXOQ3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype Entries<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as (Entries<O>[keyof Entries<O>])[];\r\n}\r\n\r\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n"],"mappings":";AAEO,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;AAEO,SAAS,mBAA+C,UAAa;AACxE,SAAO,OAAO,YAAY,WAAW,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC;AACnG;","names":[]}
|
package/build/chunk-BNE2ZOTW.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getEntries,
|
|
3
|
-
getKeys
|
|
4
|
-
} from "./chunk-3RDDXOQ3.js";
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
import { clsx } from "clsx";
|
|
8
|
-
var cv = (config, options = {}) => {
|
|
9
|
-
const { variants, defaultVariant, baseClass } = config;
|
|
10
|
-
const merge = options.merge ?? clsx;
|
|
11
|
-
if (variants == null) return (props) => merge(baseClass, props?.class);
|
|
12
|
-
const compoundVariants = typeof config.compoundVariants === "function" ? config.compoundVariants(variants) : config.compoundVariants;
|
|
13
|
-
return (props) => {
|
|
14
|
-
const variantClassNames = getKeys(variants).map((variant) => {
|
|
15
|
-
const variantProp = props?.[variant];
|
|
16
|
-
const defaultVariantProp = defaultVariant?.[variant];
|
|
17
|
-
const variantKey = variantProp || defaultVariantProp;
|
|
18
|
-
return variants[variant][variantKey];
|
|
19
|
-
});
|
|
20
|
-
const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {
|
|
21
|
-
const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {
|
|
22
|
-
const defaultsSelector = defaultVariant?.[cvKey];
|
|
23
|
-
const propsSelector = props?.[cvKey];
|
|
24
|
-
if (cvSelector === true) return propsSelector !== void 0;
|
|
25
|
-
else if (cvSelector === false) return propsSelector === void 0;
|
|
26
|
-
const selector = propsSelector ?? defaultsSelector;
|
|
27
|
-
return Array.isArray(cvSelector) ? cvSelector.includes(selector) : selector === cvSelector;
|
|
28
|
-
});
|
|
29
|
-
if (shouldApplyCompoundVariant) acc.push(cvClass);
|
|
30
|
-
return acc;
|
|
31
|
-
}, new Array());
|
|
32
|
-
return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
cv
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=chunk-BNE2ZOTW.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\nexport type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, \"class\">> | undefined;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\nexport type WithClassProp<T extends Record<string, unknown>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{ [K in keyof V]?: keyof V[K] }>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n"],"mappings":";;;;;;AAAA,SAAqB,YAAY;AAoC1B,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;","names":[]}
|
package/build/chunk-PLDDJCW6.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
|
-
var __esm = (fn, res) => function __init() {
|
|
14
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
-
};
|
|
16
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
17
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
-
};
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
-
};
|
|
23
|
-
var __copyProps = (to, from, except, desc) => {
|
|
24
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
-
for (let key of __getOwnPropNames(from))
|
|
26
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
-
}
|
|
29
|
-
return to;
|
|
30
|
-
};
|
|
31
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
-
mod
|
|
38
|
-
));
|
|
39
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
-
|
|
41
|
-
export {
|
|
42
|
-
__require,
|
|
43
|
-
__esm,
|
|
44
|
-
__commonJS,
|
|
45
|
-
__export,
|
|
46
|
-
__toESM,
|
|
47
|
-
__toCommonJS
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=chunk-PLDDJCW6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/build/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\nexport type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, \"class\">> | undefined;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\nexport type WithClassProp<T extends Record<string, unknown>> = T & {\r\n class?: ClassValue;\r\n};\r\n\r\nexport type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{\r\n [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean\r\n}>[];\r\n\r\nexport interface CVConfig<V extends CVVariantsSchema> {\r\n baseClass?: ClassValue;\r\n variants?: V;\r\n compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);\r\n defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{ [K in keyof V]?: keyof V[K] }>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;\r\n\r\nexport interface CVOptions {\r\n merge?: (...args: ClassValue[]) => string;\r\n}\r\n\r\nexport interface CV {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;\r\n}\r\n\r\nexport const cv: CV = (config, options = {}) => {\r\n const { variants, defaultVariant, baseClass } = config;\r\n\r\n const merge = options.merge ?? clsx;\r\n\r\n if (variants == null) return props => merge(baseClass, props?.class);\r\n\r\n const compoundVariants = typeof config.compoundVariants === \"function\" ? config.compoundVariants(variants) : config.compoundVariants;\r\n\r\n return (props) => {\r\n const variantClassNames = getKeys(variants).map((variant) => {\r\n const variantProp = props?.[variant];\r\n const defaultVariantProp = defaultVariant?.[variant];\r\n\r\n const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];\r\n\r\n return variants[variant][variantKey];\r\n });\r\n\r\n const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {\r\n const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {\r\n const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];\r\n const propsSelector = props?.[cvKey as keyof typeof props];\r\n\r\n if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined\r\n else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined\r\n\r\n const selector = propsSelector ?? defaultsSelector;\r\n\r\n return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;\r\n });\r\n\r\n if (shouldApplyCompoundVariant) acc.push(cvClass);\r\n return acc;\r\n }, new Array<ClassValue>());\r\n\r\n return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);\r\n };\r\n};\r\n","import { CVVariantsSchema } from \".\";\r\n\r\nexport function getKeys<O extends Record<string, unknown>>(obj: O) {\r\n return Object.keys(obj) as (keyof O)[];\r\n}\r\n\r\ntype Entries<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };\r\nexport function getEntries<O extends Record<string, unknown>>(obj: O) {\r\n return Object.entries(obj) as (Entries<O>[keyof Entries<O>])[];\r\n}\r\n\r\nexport function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {\r\n return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;;;ACE1B,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;;;AD2BO,IAAM,KAAS,CAAC,QAAQ,UAAU,CAAC,MAAM;AAC5C,QAAM,EAAE,UAAU,gBAAgB,UAAU,IAAI;AAEhD,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,YAAY,KAAM,QAAO,WAAS,MAAM,WAAW,OAAO,KAAK;AAEnE,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,aAAa,OAAO,iBAAiB,QAAQ,IAAI,OAAO;AAEpH,SAAO,CAAC,UAAU;AACd,UAAM,oBAAoB,QAAQ,QAAQ,EAAE,IAAI,CAAC,YAAY;AACzD,YAAM,cAAc,QAAQ,OAAO;AACnC,YAAM,qBAAqB,iBAAiB,OAAO;AAEnD,YAAM,aAAc,eAAe;AAEnC,aAAO,SAAS,OAAO,EAAE,UAAU;AAAA,IACvC,CAAC;AAED,UAAM,4BAA4B,kBAAkB,OAAO,CAAC,KAAK,EAAE,OAAO,SAAS,GAAG,SAAS,MAAM;AACjG,YAAM,6BAA6B,WAAW,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,UAAU,MAAM;AACnF,cAAM,mBAAmB,iBAAiB,KAAoC;AAC9E,cAAM,gBAAgB,QAAQ,KAA2B;AAEzD,YAAI,eAAe,KAAM,QAAO,kBAAkB;AAAA,iBACzC,eAAe,MAAO,QAAO,kBAAkB;AAExD,cAAM,WAAW,iBAAiB;AAElC,eAAO,MAAM,QAAQ,UAAU,IAAI,WAAW,SAAS,QAAkB,IAAI,aAAa;AAAA,MAC9F,CAAC;AAED,UAAI,2BAA4B,KAAI,KAAK,OAAO;AAChD,aAAO;AAAA,IACX,GAAG,IAAI,MAAkB,CAAC;AAE1B,WAAO,MAAM,QAAQ,WAAW,mBAAmB,2BAA2B,OAAO,KAAK;AAAA,EAC9F;AACJ;","names":[]}
|
package/build/index.d.cts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ClassValue } from 'clsx';
|
|
2
|
-
import { Prettify } from 'ts-essentials';
|
|
3
|
-
|
|
4
|
-
type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, "class">> | undefined;
|
|
5
|
-
type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
|
|
6
|
-
type WithClassProp<T extends Record<string, unknown>> = T & {
|
|
7
|
-
class?: ClassValue;
|
|
8
|
-
};
|
|
9
|
-
type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{
|
|
10
|
-
[K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean;
|
|
11
|
-
}>[];
|
|
12
|
-
interface CVConfig<V extends CVVariantsSchema> {
|
|
13
|
-
baseClass?: ClassValue;
|
|
14
|
-
variants?: V;
|
|
15
|
-
compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);
|
|
16
|
-
defaultVariant?: Partial<{
|
|
17
|
-
[K in keyof V]?: keyof V[K];
|
|
18
|
-
}>;
|
|
19
|
-
}
|
|
20
|
-
type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{
|
|
21
|
-
[K in keyof V]?: keyof V[K];
|
|
22
|
-
}>;
|
|
23
|
-
type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;
|
|
24
|
-
interface CVOptions {
|
|
25
|
-
merge?: (...args: ClassValue[]) => string;
|
|
26
|
-
}
|
|
27
|
-
interface CV {
|
|
28
|
-
<V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;
|
|
29
|
-
}
|
|
30
|
-
declare const cv: CV;
|
|
31
|
-
|
|
32
|
-
export { type CV, type CVCompoundVariantsSchema, type CVConfig, type CVOptions, type CVReturn, type CVVariantProps, type CVVariantsSchema, type VariantProps, type WithClassProp, cv };
|
package/build/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ClassValue } from 'clsx';
|
|
2
|
-
import { Prettify } from 'ts-essentials';
|
|
3
|
-
|
|
4
|
-
type VariantProps<Component extends CVReturn<CVVariantsSchema>> = Prettify<Omit<NonNullable<Parameters<Component>[0]>, "class">> | undefined;
|
|
5
|
-
type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
|
|
6
|
-
type WithClassProp<T extends Record<string, unknown>> = T & {
|
|
7
|
-
class?: ClassValue;
|
|
8
|
-
};
|
|
9
|
-
type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{
|
|
10
|
-
[K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean;
|
|
11
|
-
}>[];
|
|
12
|
-
interface CVConfig<V extends CVVariantsSchema> {
|
|
13
|
-
baseClass?: ClassValue;
|
|
14
|
-
variants?: V;
|
|
15
|
-
compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);
|
|
16
|
-
defaultVariant?: Partial<{
|
|
17
|
-
[K in keyof V]?: keyof V[K];
|
|
18
|
-
}>;
|
|
19
|
-
}
|
|
20
|
-
type CVVariantProps<V extends CVVariantsSchema> = WithClassProp<{
|
|
21
|
-
[K in keyof V]?: keyof V[K];
|
|
22
|
-
}>;
|
|
23
|
-
type CVReturn<V extends CVVariantsSchema> = (props?: CVVariantProps<V>) => string;
|
|
24
|
-
interface CVOptions {
|
|
25
|
-
merge?: (...args: ClassValue[]) => string;
|
|
26
|
-
}
|
|
27
|
-
interface CV {
|
|
28
|
-
<V extends CVVariantsSchema>(config: CVConfig<V>, options?: CVOptions): CVReturn<V>;
|
|
29
|
-
}
|
|
30
|
-
declare const cv: CV;
|
|
31
|
-
|
|
32
|
-
export { type CV, type CVCompoundVariantsSchema, type CVConfig, type CVOptions, type CVReturn, type CVVariantProps, type CVVariantsSchema, type VariantProps, type WithClassProp, cv };
|
package/build/index.js
DELETED
package/build/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|