tailwind-variants 0.0.5 → 0.0.7

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/index.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
  var classVarianceAuthority = require('class-variance-authority');
4
4
  var tailwindMerge = require('tailwind-merge');
5
5
 
6
- var g=e=>e.filter(c=>c),C=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,D=e=>e&&Object.keys(e).length>0,b=(...e)=>(c={})=>c.twMerge?(D(c.twMergeConfig)?tailwindMerge.extendTailwindMerge(c.twMergeConfig):tailwindMerge.twMerge)(classVarianceAuthority.cx(e)):classVarianceAuthority.cx(e),S=e=>Array.from(new Set(e));var U=(e,c={twMerge:!0,twMergeConfig:{}})=>n=>{var V;if((e==null?void 0:e.variants)==null)return b(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(c);let{slots:w=[],variants:d,defaultVariants:f}=e,x=Array.isArray(w)?S(["base",...w]):[],M=a=>{let t=n==null?void 0:n[a],r=f==null?void 0:f[a];if(t===null)return null;let i=C(t)||C(r);return d[a][i]},h=Object.keys(d).map(M),N=a=>g(Object.keys(d).map(t=>{let r=M(t);return !r||typeof r!="object"?null:r[a]})),A=n&&Object.entries(n).reduce((a,[t,r])=>(r===void 0||(a[t]=r),a),{}),j=(V=e==null?void 0:e.compoundVariants)==null?void 0:V.reduce((a,{class:t,className:r,...i})=>Object.entries(i).every(([m,u])=>Array.isArray(u)?u.includes({...f,...A}[m]):{...f,...A}[m]===u)?[...a,t,r]:a,[]),B=()=>{let a=g(j);return Array.isArray(a)?a.reduce((t,r)=>(typeof r=="string"&&(t.base=b(t.base,r)(c)),typeof r=="object"&&Object.entries(r).forEach(([i,m])=>{t[i]=b(t[i],m)(c);}),t),{}):a};if(x.length>1){let a=N("base"),t=B(),r=x.slice(1).reduce((i,m)=>(i[m]=u=>b(N(m),t[m],u==null?void 0:u.class,u==null?void 0:u.className)(c),i),{});return {base:i=>b(e==null?void 0:e.base,a,t.base,i==null?void 0:i.class,i==null?void 0:i.className)(c),...r}}return b(e==null?void 0:e.base,h,j,n==null?void 0:n.class,n==null?void 0:n.className)(c)};
6
+ var O=e=>{var i;return (i=e==null?void 0:e.filter)==null?void 0:i.call(e,n=>n&&String(n).match(/^[\w\s]*$/))},o=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,D=e=>e&&Object.keys(e).length>0,f=(...e)=>(i={})=>i.twMerge?(D(i.twMergeConfig)?tailwindMerge.extendTailwindMerge(i.twMergeConfig):tailwindMerge.twMerge)(classVarianceAuthority.cx(e)):classVarianceAuthority.cx(e),S=e=>Array.from(new Set(e));var K=(e,i={twMerge:!0,twMergeConfig:{}})=>n=>{var j,V;if((e==null?void 0:e.variants)==null)return f(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(i);let{slots:d=[],variants:g,defaultVariants:b}=e,w=Array.isArray(d)?S(["base",...d]):[],x=t=>{let r=n==null?void 0:n[t],a=b==null?void 0:b[t];if(r===null)return null;let u=o(r)||o(a);return g[t][u]},h=Object.keys(g).map(x),C=t=>Object.keys(g).map(r=>{let a=x(r);return !a||typeof a!="object"?null:a[t]}),M=n&&Object.entries(n).reduce((t,[r,a])=>(a===void 0||(t[r]=a),t),{}),A=(j=e==null?void 0:e.compoundVariants)==null?void 0:j.reduce((t,{class:r,className:a,...u})=>Object.entries(u).every(([m,c])=>Array.isArray(c)?c.includes({...b,...M}[m]):{...b,...M}[m]===c)?[...t,r,a]:t,[]),B=()=>{let t=O(A);return Array.isArray(t)?t.reduce((r,a)=>(typeof a=="string"&&(r.base=f(r.base,a)(i)),typeof a=="object"&&Object.entries(a).forEach(([u,m])=>{r[u]=f(r[u],m)(i);}),r),{}):t};if(w.length>1){let t=C("base"),r=(V=B())!=null?V:[];return {...w.reduce((u,m)=>(u[m]=c=>f(m==="base"?[e==null?void 0:e.base,t]:[],C(m),r==null?void 0:r[m],c==null?void 0:c.class,c==null?void 0:c.className)(i),u),{})}}return f(e==null?void 0:e.base,h,A,n==null?void 0:n.class,n==null?void 0:n.className)(i)};
7
7
 
8
- exports.tv = U;
8
+ exports.tv = K;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { cx } from 'class-variance-authority';
2
2
  import { extendTailwindMerge, twMerge } from 'tailwind-merge';
3
3
 
4
- var g=e=>e.filter(c=>c),C=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,D=e=>e&&Object.keys(e).length>0,b=(...e)=>(c={})=>c.twMerge?(D(c.twMergeConfig)?extendTailwindMerge(c.twMergeConfig):twMerge)(cx(e)):cx(e),S=e=>Array.from(new Set(e));var U=(e,c={twMerge:!0,twMergeConfig:{}})=>n=>{var V;if((e==null?void 0:e.variants)==null)return b(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(c);let{slots:w=[],variants:d,defaultVariants:f}=e,x=Array.isArray(w)?S(["base",...w]):[],M=a=>{let t=n==null?void 0:n[a],r=f==null?void 0:f[a];if(t===null)return null;let i=C(t)||C(r);return d[a][i]},h=Object.keys(d).map(M),N=a=>g(Object.keys(d).map(t=>{let r=M(t);return !r||typeof r!="object"?null:r[a]})),A=n&&Object.entries(n).reduce((a,[t,r])=>(r===void 0||(a[t]=r),a),{}),j=(V=e==null?void 0:e.compoundVariants)==null?void 0:V.reduce((a,{class:t,className:r,...i})=>Object.entries(i).every(([m,u])=>Array.isArray(u)?u.includes({...f,...A}[m]):{...f,...A}[m]===u)?[...a,t,r]:a,[]),B=()=>{let a=g(j);return Array.isArray(a)?a.reduce((t,r)=>(typeof r=="string"&&(t.base=b(t.base,r)(c)),typeof r=="object"&&Object.entries(r).forEach(([i,m])=>{t[i]=b(t[i],m)(c);}),t),{}):a};if(x.length>1){let a=N("base"),t=B(),r=x.slice(1).reduce((i,m)=>(i[m]=u=>b(N(m),t[m],u==null?void 0:u.class,u==null?void 0:u.className)(c),i),{});return {base:i=>b(e==null?void 0:e.base,a,t.base,i==null?void 0:i.class,i==null?void 0:i.className)(c),...r}}return b(e==null?void 0:e.base,h,j,n==null?void 0:n.class,n==null?void 0:n.className)(c)};
4
+ var O=e=>{var i;return (i=e==null?void 0:e.filter)==null?void 0:i.call(e,n=>n&&String(n).match(/^[\w\s]*$/))},o=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,D=e=>e&&Object.keys(e).length>0,f=(...e)=>(i={})=>i.twMerge?(D(i.twMergeConfig)?extendTailwindMerge(i.twMergeConfig):twMerge)(cx(e)):cx(e),S=e=>Array.from(new Set(e));var K=(e,i={twMerge:!0,twMergeConfig:{}})=>n=>{var j,V;if((e==null?void 0:e.variants)==null)return f(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(i);let{slots:d=[],variants:g,defaultVariants:b}=e,w=Array.isArray(d)?S(["base",...d]):[],x=t=>{let r=n==null?void 0:n[t],a=b==null?void 0:b[t];if(r===null)return null;let u=o(r)||o(a);return g[t][u]},h=Object.keys(g).map(x),C=t=>Object.keys(g).map(r=>{let a=x(r);return !a||typeof a!="object"?null:a[t]}),M=n&&Object.entries(n).reduce((t,[r,a])=>(a===void 0||(t[r]=a),t),{}),A=(j=e==null?void 0:e.compoundVariants)==null?void 0:j.reduce((t,{class:r,className:a,...u})=>Object.entries(u).every(([m,c])=>Array.isArray(c)?c.includes({...b,...M}[m]):{...b,...M}[m]===c)?[...t,r,a]:t,[]),B=()=>{let t=O(A);return Array.isArray(t)?t.reduce((r,a)=>(typeof a=="string"&&(r.base=f(r.base,a)(i)),typeof a=="object"&&Object.entries(a).forEach(([u,m])=>{r[u]=f(r[u],m)(i);}),r),{}):t};if(w.length>1){let t=C("base"),r=(V=B())!=null?V:[];return {...w.reduce((u,m)=>(u[m]=c=>f(m==="base"?[e==null?void 0:e.base,t]:[],C(m),r==null?void 0:r[m],c==null?void 0:c.class,c==null?void 0:c.className)(i),u),{})}}return f(e==null?void 0:e.base,h,A,n==null?void 0:n.class,n==null?void 0:n.className)(i)};
5
5
 
6
- export { U as tv };
6
+ export { K as tv };
package/dist/utils.d.ts CHANGED
@@ -2,7 +2,7 @@ import {CxOptions, CxReturn} from "class-variance-authority";
2
2
 
3
3
  import {TVConfig} from "./config";
4
4
 
5
- export declare const cleanArray: (array: string[]) => string[];
5
+ export declare const cleanArray: (array: string[]) => string[] | undefined;
6
6
 
7
7
  export declare const falsyToString: <T extends unknown>(value: T) => string | T;
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-variants",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "🦄 Tailwindcss first-class variant API",
5
5
  "author": "Junior Garcia <jrgarciadev@gmail.com>",
6
6
  "license": "MIT",
@@ -21,10 +21,6 @@
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
- "dependencies": {
25
- "class-variance-authority": "0.4.0",
26
- "tailwind-merge": "^1.8.1"
27
- },
28
24
  "scripts": {
29
25
  "build": "tsup src/index.js && node copy-types.cjs",
30
26
  "dev": "pnpm build:fast -- --watch",
@@ -32,13 +28,45 @@
32
28
  "typecheck": "tsc --noEmit",
33
29
  "dry-run": "node ./scripts/dry-run.js",
34
30
  "prepack": "clean-package",
35
- "new:pack": "npm pack && clean-package restore",
36
- "new:publish:dry": "pnpm prepack && npm publish --dry-run && clean-package restore",
37
- "new:publish:prod": "pnpm prepack && npm publish && clean-package restore",
31
+ "postpack": "clean-package restore",
38
32
  "lint": "eslint -c .eslintrc.json ./src/**/*.{ts,tsx}",
39
33
  "lint:fix": "eslint --fix -c .eslintrc.json ./src/**/*.{ts,tsx}",
40
34
  "test": "jest --verbose"
41
35
  },
36
+ "dependencies": {
37
+ "class-variance-authority": "0.4.0",
38
+ "tailwind-merge": "^1.8.1"
39
+ },
40
+ "devDependencies": {
41
+ "@commitlint/cli": "^17.2.0",
42
+ "@commitlint/config-conventional": "^17.2.0",
43
+ "@swc-node/jest": "^1.5.2",
44
+ "@swc/cli": "0.1.57",
45
+ "@swc/core": "1.2.198",
46
+ "@types/jest": "28.1.1",
47
+ "@types/node": "^18.11.18",
48
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
49
+ "@typescript-eslint/parser": "^5.42.0",
50
+ "clean-package": "2.1.1",
51
+ "eslint": "^7.29.0",
52
+ "eslint-config-prettier": "^8.2.0",
53
+ "eslint-config-ts-lambdas": "^1.2.3",
54
+ "eslint-import-resolver-typescript": "^2.4.0",
55
+ "eslint-loader": "^4.0.2",
56
+ "eslint-plugin-import": "^2.26.0",
57
+ "eslint-plugin-jest": "^24.3.6",
58
+ "eslint-plugin-node": "^11.1.0",
59
+ "eslint-plugin-prettier": "^4.0.0",
60
+ "eslint-plugin-promise": "^6.0.0",
61
+ "prettier": "^2.2.1",
62
+ "prettier-eslint": "^12.0.0",
63
+ "prettier-eslint-cli": "^5.0.1",
64
+ "ts-node": "^10.9.1",
65
+ "tslib": "^2.4.1",
66
+ "tsup": "6.4.0",
67
+ "typescript": "4.6.2",
68
+ "webpack": "^5.53.0"
69
+ },
42
70
  "keywords": [
43
71
  "tailwindcss",
44
72
  "classes",
package/dist/types.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import type {Config as TwMergeConfig} from "tailwind-merge";
2
-
3
- export type ClassPropKey = "class" | "className";
4
- export type ClassValue = string | null | undefined | ClassValue[];
5
-
6
- export type ClassProp =
7
- | {
8
- class: ClassValue;
9
- className?: never;
10
- }
11
- | {class?: never; className: ClassValue}
12
- | {class?: never; className?: never};
13
-
14
- export type OmitUndefined<T> = T extends undefined ? never : T;
15
- export type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
16
-
17
- export type Config = {
18
- /**
19
- * Whether to merge the class names with `tailwind-merge` library.
20
- * It's avoid to have duplicate tailwind classes. (Recommended)
21
- * @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/README.md
22
- * @default true
23
- */
24
- twMerge?: boolean;
25
- /**
26
- * The config object for `tailwind-merge` library.
27
- * @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/docs/configuration.md
28
- */
29
- twMergeConfig?: TwMergeConfig;
30
- };
31
-
32
- type StylesSchema = Record<string, Record<string, ClassValue>>;
33
-
34
- export type SlotVariants<T extends StylesConfig> = {
35
- [Slot in keyof T["slots"]]?: ClassValue;
36
- };
37
-
38
- type StylesVariants<T extends StylesSchema> = {
39
- [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null;
40
- };
41
-
42
- type StylesVariantsMulti<T extends StylesSchema> = {
43
- [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[];
44
- };
45
-
46
- export type StylesConfig<T = {}> = T extends StylesSchema
47
- ? {
48
- base?: ClassValue;
49
- slots?: string[];
50
- variants?: T;
51
- defaultVariants?: StylesVariants<T>;
52
- compoundVariants?: (T extends StylesSchema
53
- ? (StylesVariants<T> | StylesVariantsMulti<T>) & ClassProp
54
- : ClassProp)[];
55
- }
56
- : never;
57
-
58
- export type TvVariantsProps = StylesVariants<StylesSchema> & ClassProp;