@yaredfall/class-variants 0.0.8 → 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 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
- "name": "@yaredfall/class-variants",
3
- "author": "yaredfall",
4
- "private": false,
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "version": "0.0.8",
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
- "./utils": {
25
- "import": {
26
- "types": "./build/utils.d.ts",
27
- "default": "./build/utils.js"
28
- },
29
- "require": {
30
- "types": "./build/utils.d.cts",
31
- "default": "./build/utils.cjs"
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
- "./vue": {
35
- "import": {
36
- "types": "./build/vue.d.ts",
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
- "./package.json": "./package.json"
45
- },
46
- "scripts": {
47
- "build": "tsc && tsup"
48
- },
49
- "devDependencies": {
50
- "tsup": "^8.1.0",
51
- "typescript": "^5.2.2",
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
  }
@@ -1,39 +0,0 @@
1
- import {
2
- getEntries,
3
- getKeys
4
- } from "./chunk-AQSN2Y5C.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-5UWIPH6K.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { MarkRequired, Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, \"class\">>;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type WithClassProp<T extends Record<string, any>> = 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 extends keyof V> {\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 requiredProps?: R[];\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> =\r\nWithClassProp<MarkRequired<{ [K in keyof V]?: keyof V[K] }, R>>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => 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, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;\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;AAwC1B,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":[]}
@@ -1,21 +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
- function objectFromEntries(entries) {
12
- return Object.fromEntries(entries);
13
- }
14
-
15
- export {
16
- getKeys,
17
- getEntries,
18
- getVariantsOptions,
19
- objectFromEntries
20
- };
21
- //# sourceMappingURL=chunk-AQSN2Y5C.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { 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 EntriesOf<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 (EntriesOf<O>[keyof EntriesOf<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\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";AAGO,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;AAQO,SAAS,kBAAqC,SAAY;AAC7D,SAAO,OAAO,YAAY,OAAO;AACrC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { ClassValue, clsx } from \"clsx\";\r\nimport { MarkRequired, Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, \"class\">>;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type WithClassProp<T extends Record<string, any>> = 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 extends keyof V> {\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 requiredProps?: R[];\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> =\r\nWithClassProp<MarkRequired<{ [K in keyof V]?: keyof V[K] }, R>>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => 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, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;\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 { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { 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 EntriesOf<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 (EntriesOf<O>[keyof EntriesOf<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\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;;;ACG1B,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;;;AD8BO,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,33 +0,0 @@
1
- import { ClassValue } from 'clsx';
2
- import { Prettify, MarkRequired } from 'ts-essentials';
3
-
4
- type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, "class">>;
5
- type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
6
- type WithClassProp<T extends Record<string, any>> = 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, R extends keyof V> {
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
- requiredProps?: R[];
20
- }
21
- type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> = WithClassProp<MarkRequired<{
22
- [K in keyof V]?: keyof V[K];
23
- }, R>>;
24
- type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;
25
- interface CVOptions {
26
- merge?: (...args: ClassValue[]) => string;
27
- }
28
- interface CV {
29
- <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;
30
- }
31
- declare const cv: CV;
32
-
33
- 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,33 +0,0 @@
1
- import { ClassValue } from 'clsx';
2
- import { Prettify, MarkRequired } from 'ts-essentials';
3
-
4
- type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, "class">>;
5
- type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
6
- type WithClassProp<T extends Record<string, any>> = 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, R extends keyof V> {
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
- requiredProps?: R[];
20
- }
21
- type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> = WithClassProp<MarkRequired<{
22
- [K in keyof V]?: keyof V[K];
23
- }, R>>;
24
- type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;
25
- interface CVOptions {
26
- merge?: (...args: ClassValue[]) => string;
27
- }
28
- interface CV {
29
- <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;
30
- }
31
- declare const cv: CV;
32
-
33
- 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
@@ -1,8 +0,0 @@
1
- import {
2
- cv
3
- } from "./chunk-5UWIPH6K.js";
4
- import "./chunk-AQSN2Y5C.js";
5
- export {
6
- cv
7
- };
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/build/utils.cjs DELETED
@@ -1,48 +0,0 @@
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/utils.ts
21
- var utils_exports = {};
22
- __export(utils_exports, {
23
- getEntries: () => getEntries,
24
- getKeys: () => getKeys,
25
- getVariantsOptions: () => getVariantsOptions,
26
- objectFromEntries: () => objectFromEntries
27
- });
28
- module.exports = __toCommonJS(utils_exports);
29
- function getKeys(obj) {
30
- return Object.keys(obj);
31
- }
32
- function getEntries(obj) {
33
- return Object.entries(obj);
34
- }
35
- function getVariantsOptions(variants) {
36
- return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)]));
37
- }
38
- function objectFromEntries(entries) {
39
- return Object.fromEntries(entries);
40
- }
41
- // Annotate the CommonJS export names for ESM import in node:
42
- 0 && (module.exports = {
43
- getEntries,
44
- getKeys,
45
- getVariantsOptions,
46
- objectFromEntries
47
- });
48
- //# sourceMappingURL=utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { 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 EntriesOf<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 (EntriesOf<O>[keyof EntriesOf<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\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,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;AAQO,SAAS,kBAAqC,SAAY;AAC7D,SAAO,OAAO,YAAY,OAAO;AACrC;","names":[]}
package/build/utils.d.cts DELETED
@@ -1,20 +0,0 @@
1
- import { Prettify, UnionToIntersection, DeepReadonly, DeepWritable } from 'ts-essentials';
2
- import { CVVariantsSchema } from './index.cjs';
3
- import 'clsx';
4
-
5
- declare function getKeys<O extends Record<string, unknown>>(obj: O): (keyof O)[];
6
- type EntriesOf<O extends Record<string, unknown>> = {
7
- [K in keyof O]: [K, O[K]];
8
- };
9
- declare function getEntries<O extends Record<string, unknown>>(obj: O): (EntriesOf<O>[keyof EntriesOf<O>])[];
10
- declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): { [K in keyof V]: (keyof V[K])[]; };
11
- type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
12
- type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? {
13
- [prop in key & PropertyKey]: val;
14
- } : never : never;
15
- type MergeIntersectingObjects<O> = {
16
- [K in keyof O]: O[K];
17
- };
18
- declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
19
-
20
- export { getEntries, getKeys, getVariantsOptions, objectFromEntries };
package/build/utils.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import { Prettify, UnionToIntersection, DeepReadonly, DeepWritable } from 'ts-essentials';
2
- import { CVVariantsSchema } from './index.js';
3
- import 'clsx';
4
-
5
- declare function getKeys<O extends Record<string, unknown>>(obj: O): (keyof O)[];
6
- type EntriesOf<O extends Record<string, unknown>> = {
7
- [K in keyof O]: [K, O[K]];
8
- };
9
- declare function getEntries<O extends Record<string, unknown>>(obj: O): (EntriesOf<O>[keyof EntriesOf<O>])[];
10
- declare function getVariantsOptions<V extends CVVariantsSchema>(variants: V): { [K in keyof V]: (keyof V[K])[]; };
11
- type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
12
- type UnionFromPairs<TArr extends Entries> = DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? {
13
- [prop in key & PropertyKey]: val;
14
- } : never : never;
15
- type MergeIntersectingObjects<O> = {
16
- [K in keyof O]: O[K];
17
- };
18
- declare function objectFromEntries<E extends Entries>(entries: E): Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
19
-
20
- export { getEntries, getKeys, getVariantsOptions, objectFromEntries };
package/build/utils.js DELETED
@@ -1,13 +0,0 @@
1
- import {
2
- getEntries,
3
- getKeys,
4
- getVariantsOptions,
5
- objectFromEntries
6
- } from "./chunk-AQSN2Y5C.js";
7
- export {
8
- getEntries,
9
- getKeys,
10
- getVariantsOptions,
11
- objectFromEntries
12
- };
13
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/build/vue.cjs DELETED
@@ -1,96 +0,0 @@
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/vue.ts
21
- var vue_exports = {};
22
- __export(vue_exports, {
23
- cvWithProps: () => cvWithProps,
24
- getPropsDeclaration: () => getPropsDeclaration
25
- });
26
- module.exports = __toCommonJS(vue_exports);
27
-
28
- // src/index.ts
29
- var import_clsx = require("clsx");
30
-
31
- // src/utils.ts
32
- function getKeys(obj) {
33
- return Object.keys(obj);
34
- }
35
- function getEntries(obj) {
36
- return Object.entries(obj);
37
- }
38
- function objectFromEntries(entries) {
39
- return Object.fromEntries(entries);
40
- }
41
-
42
- // src/index.ts
43
- var cv = (config, options = {}) => {
44
- const { variants, defaultVariant, baseClass } = config;
45
- const merge = options.merge ?? import_clsx.clsx;
46
- if (variants == null) return (props) => merge(baseClass, props?.class);
47
- const compoundVariants = typeof config.compoundVariants === "function" ? config.compoundVariants(variants) : config.compoundVariants;
48
- return (props) => {
49
- const variantClassNames = getKeys(variants).map((variant) => {
50
- const variantProp = props?.[variant];
51
- const defaultVariantProp = defaultVariant?.[variant];
52
- const variantKey = variantProp || defaultVariantProp;
53
- return variants[variant][variantKey];
54
- });
55
- const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {
56
- const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {
57
- const defaultsSelector = defaultVariant?.[cvKey];
58
- const propsSelector = props?.[cvKey];
59
- if (cvSelector === true) return propsSelector !== void 0;
60
- else if (cvSelector === false) return propsSelector === void 0;
61
- const selector = propsSelector ?? defaultsSelector;
62
- return Array.isArray(cvSelector) ? cvSelector.includes(selector) : selector === cvSelector;
63
- });
64
- if (shouldApplyCompoundVariant) acc.push(cvClass);
65
- return acc;
66
- }, new Array());
67
- return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);
68
- };
69
- };
70
-
71
- // src/vue.ts
72
- function getPropsDeclaration(config) {
73
- if (typeof config?.variants === "undefined") {
74
- return {};
75
- }
76
- return objectFromEntries(
77
- getKeys(config.variants).map((key) => [
78
- key,
79
- {
80
- type: String,
81
- required: config.requiredProps?.includes(key)
82
- }
83
- ])
84
- );
85
- }
86
- var cvWithProps = (config, options) => {
87
- const getClass = cv(config, options);
88
- const props = getPropsDeclaration(config);
89
- return { getClass, props };
90
- };
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- cvWithProps,
94
- getPropsDeclaration
95
- });
96
- //# sourceMappingURL=vue.cjs.map
package/build/vue.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/vue.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\r\nimport { PropType } from \"vue\";\r\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\r\nimport { getKeys, objectFromEntries } from \"./utils\";\r\n\r\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{ [K in keyof V]: {\r\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\r\n required: K extends R ? true : false;\r\n} }>;\r\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\r\n getClass: CVReturn<V, R>;\r\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\r\n}\r\n\r\nexport interface CVWithProps {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;\r\n}\r\n\r\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>) {\r\n if (typeof config?.variants === \"undefined\") {\r\n return {};\r\n }\r\n\r\n return objectFromEntries(\r\n getKeys(config.variants).map(key => [\r\n key,\r\n {\r\n type: String,\r\n required: config.requiredProps?.includes(key as R),\r\n },\r\n ] as const),\r\n );\r\n}\r\n\r\nexport const cvWithProps: CVWithProps = ((config, options) => {\r\n const getClass = cv(config, options);\r\n const props = getPropsDeclaration(config);\r\n\r\n return { getClass, props };\r\n}) as CVWithProps;\r\n","import { ClassValue, clsx } from \"clsx\";\r\nimport { MarkRequired, Prettify } from \"ts-essentials\";\r\nimport { getEntries, getKeys } from \"./utils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, \"class\">>;\r\n\r\nexport type CVVariantsSchema = Record<string, Record<string, ClassValue>>;\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type WithClassProp<T extends Record<string, any>> = 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 extends keyof V> {\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 requiredProps?: R[];\r\n}\r\n\r\nexport type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> =\r\nWithClassProp<MarkRequired<{ [K in keyof V]?: keyof V[K] }, R>>;\r\n\r\nexport type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => 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, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;\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 { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from \"ts-essentials\";\r\nimport { 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 EntriesOf<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 (EntriesOf<O>[keyof EntriesOf<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\r\ntype Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;\r\ntype UnionFromPairs<TArr extends Entries> =\r\n DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;\r\n\r\ntype MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };\r\n\r\nexport function objectFromEntries<E extends Entries>(entries: E) {\r\n return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAiC;;;ACG1B,SAAS,QAA2C,KAAQ;AAC/D,SAAO,OAAO,KAAK,GAAG;AAC1B;AAGO,SAAS,WAA8C,KAAQ;AAClE,SAAO,OAAO,QAAQ,GAAG;AAC7B;AAYO,SAAS,kBAAqC,SAAY;AAC7D,SAAO,OAAO,YAAY,OAAO;AACrC;;;ADgBO,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;;;AD3DO,SAAS,oBAA2E,QAAwB;AAC/G,MAAI,OAAO,QAAQ,aAAa,aAAa;AACzC,WAAO,CAAC;AAAA,EACZ;AAEA,SAAO;AAAA,IACH,QAAQ,OAAO,QAAQ,EAAE,IAAI,SAAO;AAAA,MAChC;AAAA,MACA;AAAA,QACI,MAAM;AAAA,QACN,UAAU,OAAO,eAAe,SAAS,GAAQ;AAAA,MACrD;AAAA,IACJ,CAAU;AAAA,EACd;AACJ;AAEO,IAAM,cAA4B,CAAC,QAAQ,YAAY;AAC1D,QAAM,WAAW,GAAG,QAAQ,OAAO;AACnC,QAAM,QAAQ,oBAAoB,MAAM;AAExC,SAAO,EAAE,UAAU,MAAM;AAC7B;","names":[]}
package/build/vue.d.cts DELETED
@@ -1,22 +0,0 @@
1
- import { Prettify } from 'ts-essentials';
2
- import { PropType } from 'vue';
3
- import { CVVariantsSchema, CVReturn, CVConfig, CVOptions } from './index.cjs';
4
- import 'clsx';
5
-
6
- type PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{
7
- [K in keyof V]: {
8
- type: PropType<keyof V[K] | (K extends R ? never : undefined)>;
9
- required: K extends R ? true : false;
10
- };
11
- }>;
12
- interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {
13
- getClass: CVReturn<V, R>;
14
- props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;
15
- }
16
- interface CVWithProps {
17
- <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;
18
- }
19
- declare function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>): {};
20
- declare const cvWithProps: CVWithProps;
21
-
22
- export { type CVWithProps, type CVWithPropsReturn, cvWithProps, getPropsDeclaration };
package/build/vue.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import { Prettify } from 'ts-essentials';
2
- import { PropType } from 'vue';
3
- import { CVVariantsSchema, CVReturn, CVConfig, CVOptions } from './index.js';
4
- import 'clsx';
5
-
6
- type PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{
7
- [K in keyof V]: {
8
- type: PropType<keyof V[K] | (K extends R ? never : undefined)>;
9
- required: K extends R ? true : false;
10
- };
11
- }>;
12
- interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {
13
- getClass: CVReturn<V, R>;
14
- props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;
15
- }
16
- interface CVWithProps {
17
- <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;
18
- }
19
- declare function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>): {};
20
- declare const cvWithProps: CVWithProps;
21
-
22
- export { type CVWithProps, type CVWithPropsReturn, cvWithProps, getPropsDeclaration };
package/build/vue.js DELETED
@@ -1,33 +0,0 @@
1
- import {
2
- cv
3
- } from "./chunk-5UWIPH6K.js";
4
- import {
5
- getKeys,
6
- objectFromEntries
7
- } from "./chunk-AQSN2Y5C.js";
8
-
9
- // src/vue.ts
10
- function getPropsDeclaration(config) {
11
- if (typeof config?.variants === "undefined") {
12
- return {};
13
- }
14
- return objectFromEntries(
15
- getKeys(config.variants).map((key) => [
16
- key,
17
- {
18
- type: String,
19
- required: config.requiredProps?.includes(key)
20
- }
21
- ])
22
- );
23
- }
24
- var cvWithProps = (config, options) => {
25
- const getClass = cv(config, options);
26
- const props = getPropsDeclaration(config);
27
- return { getClass, props };
28
- };
29
- export {
30
- cvWithProps,
31
- getPropsDeclaration
32
- };
33
- //# sourceMappingURL=vue.js.map
package/build/vue.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/vue.ts"],"sourcesContent":["import { Prettify } from \"ts-essentials\";\r\nimport { PropType } from \"vue\";\r\nimport { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from \".\";\r\nimport { getKeys, objectFromEntries } from \"./utils\";\r\n\r\ntype PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{ [K in keyof V]: {\r\n type: PropType<keyof V[K] | (K extends R ? never : undefined)>;\r\n required: K extends R ? true : false;\r\n} }>;\r\nexport interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {\r\n getClass: CVReturn<V, R>;\r\n props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;\r\n}\r\n\r\nexport interface CVWithProps {\r\n // eslint-disable-next-line @typescript-eslint/prefer-function-type\r\n <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;\r\n}\r\n\r\nexport function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>) {\r\n if (typeof config?.variants === \"undefined\") {\r\n return {};\r\n }\r\n\r\n return objectFromEntries(\r\n getKeys(config.variants).map(key => [\r\n key,\r\n {\r\n type: String,\r\n required: config.requiredProps?.includes(key as R),\r\n },\r\n ] as const),\r\n );\r\n}\r\n\r\nexport const cvWithProps: CVWithProps = ((config, options) => {\r\n const getClass = cv(config, options);\r\n const props = getPropsDeclaration(config);\r\n\r\n return { getClass, props };\r\n}) as CVWithProps;\r\n"],"mappings":";;;;;;;;;AAmBO,SAAS,oBAA2E,QAAwB;AAC/G,MAAI,OAAO,QAAQ,aAAa,aAAa;AACzC,WAAO,CAAC;AAAA,EACZ;AAEA,SAAO;AAAA,IACH,QAAQ,OAAO,QAAQ,EAAE,IAAI,SAAO;AAAA,MAChC;AAAA,MACA;AAAA,QACI,MAAM;AAAA,QACN,UAAU,OAAO,eAAe,SAAS,GAAQ;AAAA,MACrD;AAAA,IACJ,CAAU;AAAA,EACd;AACJ;AAEO,IAAM,cAA4B,CAAC,QAAQ,YAAY;AAC1D,QAAM,WAAW,GAAG,QAAQ,OAAO;AACnC,QAAM,QAAQ,oBAAoB,MAAM;AAExC,SAAO,EAAE,UAAU,MAAM;AAC7B;","names":[]}
package/src/index.ts DELETED
@@ -1,79 +0,0 @@
1
- import { ClassValue, clsx } from "clsx";
2
- import { MarkRequired, Prettify } from "ts-essentials";
3
- import { getEntries, getKeys } from "./utils";
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- export type VariantProps<CVR extends (args?: any) => string> = Prettify<Omit<NonNullable<Exclude<Parameters<CVR>[0], void>>, "class">>;
7
-
8
- export type CVVariantsSchema = Record<string, Record<string, ClassValue>>;
9
-
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- export type WithClassProp<T extends Record<string, any>> = T & {
12
- class?: ClassValue;
13
- };
14
-
15
- export type CVCompoundVariantsSchema<V extends CVVariantsSchema> = WithClassProp<{
16
- [K in keyof V]?: (keyof V[K] & string) | (keyof V[K])[] | boolean
17
- }>[];
18
-
19
- export interface CVConfig<V extends CVVariantsSchema, R extends keyof V> {
20
- baseClass?: ClassValue;
21
- variants?: V;
22
- compoundVariants?: CVCompoundVariantsSchema<NoInfer<V>> | ((variants: NoInfer<V>) => CVCompoundVariantsSchema<NoInfer<V>>);
23
- defaultVariant?: Partial<{ [K in keyof V]?: keyof V[K] }>;
24
- requiredProps?: R[];
25
- }
26
-
27
- export type CVVariantProps<V extends CVVariantsSchema, R extends (keyof V)> =
28
- WithClassProp<MarkRequired<{ [K in keyof V]?: keyof V[K] }, R>>;
29
-
30
- export type CVReturn<V extends CVVariantsSchema, R extends keyof V = never> = (props: Prettify<CVVariantProps<V, R>> | ([R] extends [never] ? void : never)) => string;
31
-
32
- export interface CVOptions {
33
- merge?: (...args: ClassValue[]) => string;
34
- }
35
-
36
- export interface CV {
37
- // eslint-disable-next-line @typescript-eslint/prefer-function-type
38
- <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVReturn<V, R>;
39
- }
40
-
41
- export const cv: CV = (config, options = {}) => {
42
- const { variants, defaultVariant, baseClass } = config;
43
-
44
- const merge = options.merge ?? clsx;
45
-
46
- if (variants == null) return props => merge(baseClass, props?.class);
47
-
48
- const compoundVariants = typeof config.compoundVariants === "function" ? config.compoundVariants(variants) : config.compoundVariants;
49
-
50
- return (props) => {
51
- const variantClassNames = getKeys(variants).map((variant) => {
52
- const variantProp = props?.[variant];
53
- const defaultVariantProp = defaultVariant?.[variant];
54
-
55
- const variantKey = (variantProp || defaultVariantProp) as keyof (typeof variants)[typeof variant];
56
-
57
- return variants[variant][variantKey];
58
- });
59
-
60
- const compoundVariantClassNames = compoundVariants?.reduce((acc, { class: cvClass, ...cvConfig }) => {
61
- const shouldApplyCompoundVariant = getEntries(cvConfig).every(([cvKey, cvSelector]) => {
62
- const defaultsSelector = defaultVariant?.[cvKey as keyof typeof defaultVariant];
63
- const propsSelector = props?.[cvKey as keyof typeof props];
64
-
65
- if (cvSelector === true) return propsSelector !== undefined; // only when prop is defined
66
- else if (cvSelector === false) return propsSelector === undefined; // only when prop is not defined
67
-
68
- const selector = propsSelector ?? defaultsSelector;
69
-
70
- return Array.isArray(cvSelector) ? cvSelector.includes(selector as string) : selector === cvSelector;
71
- });
72
-
73
- if (shouldApplyCompoundVariant) acc.push(cvClass);
74
- return acc;
75
- }, new Array<ClassValue>());
76
-
77
- return merge(config?.baseClass, variantClassNames, compoundVariantClassNames, props?.class);
78
- };
79
- };
package/src/utils.ts DELETED
@@ -1,25 +0,0 @@
1
- import { DeepReadonly, DeepWritable, Prettify, UnionToIntersection } from "ts-essentials";
2
- import { CVVariantsSchema } from ".";
3
-
4
- export function getKeys<O extends Record<string, unknown>>(obj: O) {
5
- return Object.keys(obj) as (keyof O)[];
6
- }
7
-
8
- type EntriesOf<O extends Record<string, unknown>> = { [K in keyof O]: [K, O[K]] };
9
- export function getEntries<O extends Record<string, unknown>>(obj: O) {
10
- return Object.entries(obj) as (EntriesOf<O>[keyof EntriesOf<O>])[];
11
- }
12
-
13
- export function getVariantsOptions<V extends CVVariantsSchema>(variants: V) {
14
- return Object.fromEntries(getEntries(variants).map(([cvKey, cvVal]) => [cvKey, getKeys(cvVal)])) as { [K in keyof V]: (keyof V[K])[] };
15
- }
16
-
17
- type Entries = [PropertyKey, unknown][] | DeepReadonly<[PropertyKey, unknown][]>;
18
- type UnionFromPairs<TArr extends Entries> =
19
- DeepWritable<TArr> extends (infer R)[] ? R extends [infer key, infer val] ? { [prop in key & PropertyKey]: val } : never : never;
20
-
21
- type MergeIntersectingObjects<O> = { [K in keyof O]: O[K] };
22
-
23
- export function objectFromEntries<E extends Entries>(entries: E) {
24
- return Object.fromEntries(entries) as Prettify<MergeIntersectingObjects<UnionToIntersection<UnionFromPairs<E>>>>;
25
- }
package/src/vue.ts DELETED
@@ -1,41 +0,0 @@
1
- import { Prettify } from "ts-essentials";
2
- import { PropType } from "vue";
3
- import { CVConfig, CVOptions, CVReturn, CVVariantsSchema, cv } from ".";
4
- import { getKeys, objectFromEntries } from "./utils";
5
-
6
- type PropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never> = Prettify<{ [K in keyof V]: {
7
- type: PropType<keyof V[K] | (K extends R ? never : undefined)>;
8
- required: K extends R ? true : false;
9
- } }>;
10
- export interface CVWithPropsReturn<V extends CVVariantsSchema, R extends keyof V = never> {
11
- getClass: CVReturn<V, R>;
12
- props: PropsDeclaration<NoInfer<V>, NoInfer<R>>;
13
- }
14
-
15
- export interface CVWithProps {
16
- // eslint-disable-next-line @typescript-eslint/prefer-function-type
17
- <V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>, options?: CVOptions): CVWithPropsReturn<V, R>;
18
- }
19
-
20
- export function getPropsDeclaration<V extends CVVariantsSchema, R extends keyof V = never>(config: CVConfig<V, R>) {
21
- if (typeof config?.variants === "undefined") {
22
- return {};
23
- }
24
-
25
- return objectFromEntries(
26
- getKeys(config.variants).map(key => [
27
- key,
28
- {
29
- type: String,
30
- required: config.requiredProps?.includes(key as R),
31
- },
32
- ] as const),
33
- );
34
- }
35
-
36
- export const cvWithProps: CVWithProps = ((config, options) => {
37
- const getClass = cv(config, options);
38
- const props = getPropsDeclaration(config);
39
-
40
- return { getClass, props };
41
- }) as CVWithProps;
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "module": "ESNext",
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
- "skipLibCheck": true,
8
-
9
- /* Bundler mode */
10
- "moduleResolution": "bundler",
11
- "allowImportingTsExtensions": true,
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "noEmit": true,
15
-
16
- /* Linting */
17
- "strict": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "noFallthroughCasesInSwitch": true
21
- },
22
- "include": ["src"]
23
- }
package/tsup.config.js DELETED
@@ -1,13 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig(
4
- {
5
- entry: ["src/*.ts"],
6
- format: ["cjs", "esm"],
7
- target: ["chrome91", "firefox90", "edge91", "safari15", "ios15", "opera77"],
8
- outDir: "build",
9
- dts: true,
10
- sourcemap: true,
11
- clean: true,
12
- },
13
- );