tailwind-to-style 3.1.2 → 3.2.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/dist/cx.cjs ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * tailwind-to-style v3.2.0
3
+ * Runtime Tailwind CSS to inline styles converter
4
+ *
5
+ * @author Bigetion
6
+ * @license MIT
7
+ */
8
+ 'use strict';
9
+
10
+ Object.defineProperty(exports, '__esModule', { value: true });
11
+
12
+ /**
13
+ * CX - Conditional Class Name Builder
14
+ *
15
+ * A lightweight utility for conditionally joining Tailwind class names.
16
+ * Similar to `clsx`/`classnames` but designed specifically for tailwind-to-style.
17
+ *
18
+ * @module cx
19
+ */
20
+
21
+ /**
22
+ * Conditionally join class names into a single string.
23
+ *
24
+ * Accepts strings, objects (key=className, value=condition), arrays, and nested combinations.
25
+ * Falsy values (null, undefined, false, 0, '') are ignored.
26
+ *
27
+ * @param {...(string|Object|Array|boolean|null|undefined)} args - Class name inputs
28
+ * @returns {string} Joined class names string
29
+ *
30
+ * @example
31
+ * // Strings
32
+ * cx('bg-blue-500', 'text-white')
33
+ * // → 'bg-blue-500 text-white'
34
+ *
35
+ * @example
36
+ * // Conditionals
37
+ * cx('p-4', isActive && 'bg-blue-500', isDisabled && 'opacity-50')
38
+ * // → 'p-4 bg-blue-500' (if isActive=true, isDisabled=false)
39
+ *
40
+ * @example
41
+ * // Object syntax
42
+ * cx('p-4', { 'bg-blue-500': isActive, 'opacity-50': isDisabled, 'cursor-pointer': true })
43
+ * // → 'p-4 bg-blue-500 cursor-pointer'
44
+ *
45
+ * @example
46
+ * // Arrays (nested)
47
+ * cx(['p-4', 'bg-white'], isActive && ['ring-2', 'ring-blue-500'])
48
+ * // → 'p-4 bg-white ring-2 ring-blue-500'
49
+ *
50
+ * @example
51
+ * // Mixed
52
+ * cx(
53
+ * 'base-class',
54
+ * condition && 'conditional-class',
55
+ * { 'object-class': true, 'ignored-class': false },
56
+ * ['array-class-1', 'array-class-2']
57
+ * )
58
+ */
59
+ function cx() {
60
+ const classes = [];
61
+ for (let i = 0; i < arguments.length; i++) {
62
+ const arg = i < 0 || arguments.length <= i ? undefined : arguments[i];
63
+
64
+ // Skip falsy values
65
+ if (!arg) continue;
66
+ const type = typeof arg;
67
+ if (type === 'string') {
68
+ classes.push(arg);
69
+ } else if (Array.isArray(arg)) {
70
+ // Recursively process arrays
71
+ const inner = cx(...arg);
72
+ if (inner) classes.push(inner);
73
+ } else if (type === 'object') {
74
+ // Object: keys are class names, values are conditions
75
+ const keys = Object.keys(arg);
76
+ for (let j = 0; j < keys.length; j++) {
77
+ if (arg[keys[j]]) {
78
+ classes.push(keys[j]);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ return classes.join(' ');
84
+ }
85
+
86
+ /**
87
+ * Create a cx function bound with base classes.
88
+ * Useful for component-level class composition.
89
+ *
90
+ * @param {...(string|Object|Array)} baseArgs - Base class arguments always included
91
+ * @returns {Function} A cx function pre-filled with base classes
92
+ *
93
+ * @example
94
+ * const btnClasses = cx.with('px-4 py-2 rounded font-medium transition-colors')
95
+ *
96
+ * btnClasses('bg-blue-500 text-white')
97
+ * // → 'px-4 py-2 rounded font-medium transition-colors bg-blue-500 text-white'
98
+ *
99
+ * btnClasses({ 'opacity-50 cursor-not-allowed': isDisabled })
100
+ * // → 'px-4 py-2 rounded font-medium transition-colors opacity-50 cursor-not-allowed'
101
+ */
102
+ cx.with = function () {
103
+ for (var _len = arguments.length, baseArgs = new Array(_len), _key = 0; _key < _len; _key++) {
104
+ baseArgs[_key] = arguments[_key];
105
+ }
106
+ return function () {
107
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
108
+ args[_key2] = arguments[_key2];
109
+ }
110
+ return cx(...baseArgs, ...args);
111
+ };
112
+ };
113
+
114
+ exports.cx = cx;
115
+ exports.default = cx;
package/dist/cx.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ // Type definitions for tailwind-to-style/cx
2
+ // Conditional class name builder
3
+ // import { cx } from 'tailwind-to-style/cx'
4
+
5
+ type ClassValue = string | number | boolean | null | undefined | ClassObject | ClassArray;
6
+ type ClassObject = Record<string, any>;
7
+ type ClassArray = ClassValue[];
8
+
9
+ /**
10
+ * Conditionally join class names into a single string.
11
+ *
12
+ * Accepts strings, objects (key=className, value=condition), arrays, and nested combinations.
13
+ * Falsy values (null, undefined, false, 0, '') are ignored.
14
+ *
15
+ * @example
16
+ * cx('bg-blue-500', 'text-white')
17
+ * // → 'bg-blue-500 text-white'
18
+ *
19
+ * @example
20
+ * cx('p-4', isActive && 'bg-blue-500', { 'opacity-50': isDisabled })
21
+ * // → 'p-4 bg-blue-500' (when isActive=true, isDisabled=false)
22
+ *
23
+ * @example
24
+ * cx(['p-4', 'bg-white'], isActive && ['ring-2', 'ring-blue-500'])
25
+ * // → 'p-4 bg-white ring-2 ring-blue-500'
26
+ */
27
+ export function cx(...args: ClassValue[]): string;
28
+
29
+ export namespace cx {
30
+ /**
31
+ * Create a cx function pre-filled with base classes.
32
+ *
33
+ * @example
34
+ * const btnClasses = cx.with('px-4 py-2 rounded font-medium')
35
+ * btnClasses('bg-blue-500') // → 'px-4 py-2 rounded font-medium bg-blue-500'
36
+ */
37
+ function with_(...baseArgs: ClassValue[]): (...args: ClassValue[]) => string;
38
+ export { with_ as with };
39
+ }
40
+
41
+ export default cx;
package/dist/cx.esm.js ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * tailwind-to-style v3.2.0
3
+ * Runtime Tailwind CSS to inline styles converter
4
+ *
5
+ * @author Bigetion
6
+ * @license MIT
7
+ */
8
+ /**
9
+ * CX - Conditional Class Name Builder
10
+ *
11
+ * A lightweight utility for conditionally joining Tailwind class names.
12
+ * Similar to `clsx`/`classnames` but designed specifically for tailwind-to-style.
13
+ *
14
+ * @module cx
15
+ */
16
+
17
+ /**
18
+ * Conditionally join class names into a single string.
19
+ *
20
+ * Accepts strings, objects (key=className, value=condition), arrays, and nested combinations.
21
+ * Falsy values (null, undefined, false, 0, '') are ignored.
22
+ *
23
+ * @param {...(string|Object|Array|boolean|null|undefined)} args - Class name inputs
24
+ * @returns {string} Joined class names string
25
+ *
26
+ * @example
27
+ * // Strings
28
+ * cx('bg-blue-500', 'text-white')
29
+ * // → 'bg-blue-500 text-white'
30
+ *
31
+ * @example
32
+ * // Conditionals
33
+ * cx('p-4', isActive && 'bg-blue-500', isDisabled && 'opacity-50')
34
+ * // → 'p-4 bg-blue-500' (if isActive=true, isDisabled=false)
35
+ *
36
+ * @example
37
+ * // Object syntax
38
+ * cx('p-4', { 'bg-blue-500': isActive, 'opacity-50': isDisabled, 'cursor-pointer': true })
39
+ * // → 'p-4 bg-blue-500 cursor-pointer'
40
+ *
41
+ * @example
42
+ * // Arrays (nested)
43
+ * cx(['p-4', 'bg-white'], isActive && ['ring-2', 'ring-blue-500'])
44
+ * // → 'p-4 bg-white ring-2 ring-blue-500'
45
+ *
46
+ * @example
47
+ * // Mixed
48
+ * cx(
49
+ * 'base-class',
50
+ * condition && 'conditional-class',
51
+ * { 'object-class': true, 'ignored-class': false },
52
+ * ['array-class-1', 'array-class-2']
53
+ * )
54
+ */
55
+ function cx() {
56
+ const classes = [];
57
+ for (let i = 0; i < arguments.length; i++) {
58
+ const arg = i < 0 || arguments.length <= i ? undefined : arguments[i];
59
+
60
+ // Skip falsy values
61
+ if (!arg) continue;
62
+ const type = typeof arg;
63
+ if (type === 'string') {
64
+ classes.push(arg);
65
+ } else if (Array.isArray(arg)) {
66
+ // Recursively process arrays
67
+ const inner = cx(...arg);
68
+ if (inner) classes.push(inner);
69
+ } else if (type === 'object') {
70
+ // Object: keys are class names, values are conditions
71
+ const keys = Object.keys(arg);
72
+ for (let j = 0; j < keys.length; j++) {
73
+ if (arg[keys[j]]) {
74
+ classes.push(keys[j]);
75
+ }
76
+ }
77
+ }
78
+ }
79
+ return classes.join(' ');
80
+ }
81
+
82
+ /**
83
+ * Create a cx function bound with base classes.
84
+ * Useful for component-level class composition.
85
+ *
86
+ * @param {...(string|Object|Array)} baseArgs - Base class arguments always included
87
+ * @returns {Function} A cx function pre-filled with base classes
88
+ *
89
+ * @example
90
+ * const btnClasses = cx.with('px-4 py-2 rounded font-medium transition-colors')
91
+ *
92
+ * btnClasses('bg-blue-500 text-white')
93
+ * // → 'px-4 py-2 rounded font-medium transition-colors bg-blue-500 text-white'
94
+ *
95
+ * btnClasses({ 'opacity-50 cursor-not-allowed': isDisabled })
96
+ * // → 'px-4 py-2 rounded font-medium transition-colors opacity-50 cursor-not-allowed'
97
+ */
98
+ cx.with = function () {
99
+ for (var _len = arguments.length, baseArgs = new Array(_len), _key = 0; _key < _len; _key++) {
100
+ baseArgs[_key] = arguments[_key];
101
+ }
102
+ return function () {
103
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
104
+ args[_key2] = arguments[_key2];
105
+ }
106
+ return cx(...baseArgs, ...args);
107
+ };
108
+ };
109
+
110
+ export { cx, cx as default };
111
+ //# sourceMappingURL=cx.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cx.esm.js","sources":["../src/cx.js"],"sourcesContent":["/**\r\n * CX - Conditional Class Name Builder\r\n * \r\n * A lightweight utility for conditionally joining Tailwind class names.\r\n * Similar to `clsx`/`classnames` but designed specifically for tailwind-to-style.\r\n * \r\n * @module cx\r\n */\r\n\r\n/**\r\n * Conditionally join class names into a single string.\r\n * \r\n * Accepts strings, objects (key=className, value=condition), arrays, and nested combinations.\r\n * Falsy values (null, undefined, false, 0, '') are ignored.\r\n * \r\n * @param {...(string|Object|Array|boolean|null|undefined)} args - Class name inputs\r\n * @returns {string} Joined class names string\r\n * \r\n * @example\r\n * // Strings\r\n * cx('bg-blue-500', 'text-white')\r\n * // → 'bg-blue-500 text-white'\r\n * \r\n * @example\r\n * // Conditionals\r\n * cx('p-4', isActive && 'bg-blue-500', isDisabled && 'opacity-50')\r\n * // → 'p-4 bg-blue-500' (if isActive=true, isDisabled=false)\r\n * \r\n * @example\r\n * // Object syntax\r\n * cx('p-4', { 'bg-blue-500': isActive, 'opacity-50': isDisabled, 'cursor-pointer': true })\r\n * // → 'p-4 bg-blue-500 cursor-pointer'\r\n * \r\n * @example\r\n * // Arrays (nested)\r\n * cx(['p-4', 'bg-white'], isActive && ['ring-2', 'ring-blue-500'])\r\n * // → 'p-4 bg-white ring-2 ring-blue-500'\r\n * \r\n * @example\r\n * // Mixed\r\n * cx(\r\n * 'base-class',\r\n * condition && 'conditional-class',\r\n * { 'object-class': true, 'ignored-class': false },\r\n * ['array-class-1', 'array-class-2']\r\n * )\r\n */\r\nexport function cx(...args) {\r\n const classes = [];\r\n\r\n for (let i = 0; i < args.length; i++) {\r\n const arg = args[i];\r\n\r\n // Skip falsy values\r\n if (!arg) continue;\r\n\r\n const type = typeof arg;\r\n\r\n if (type === 'string') {\r\n classes.push(arg);\r\n } else if (Array.isArray(arg)) {\r\n // Recursively process arrays\r\n const inner = cx(...arg);\r\n if (inner) classes.push(inner);\r\n } else if (type === 'object') {\r\n // Object: keys are class names, values are conditions\r\n const keys = Object.keys(arg);\r\n for (let j = 0; j < keys.length; j++) {\r\n if (arg[keys[j]]) {\r\n classes.push(keys[j]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n return classes.join(' ');\r\n}\r\n\r\n/**\r\n * Create a cx function bound with base classes.\r\n * Useful for component-level class composition.\r\n * \r\n * @param {...(string|Object|Array)} baseArgs - Base class arguments always included\r\n * @returns {Function} A cx function pre-filled with base classes\r\n * \r\n * @example\r\n * const btnClasses = cx.with('px-4 py-2 rounded font-medium transition-colors')\r\n * \r\n * btnClasses('bg-blue-500 text-white')\r\n * // → 'px-4 py-2 rounded font-medium transition-colors bg-blue-500 text-white'\r\n * \r\n * btnClasses({ 'opacity-50 cursor-not-allowed': isDisabled })\r\n * // → 'px-4 py-2 rounded font-medium transition-colors opacity-50 cursor-not-allowed'\r\n */\r\ncx.with = function (...baseArgs) {\r\n return function (...args) {\r\n return cx(...baseArgs, ...args);\r\n };\r\n};\r\n\r\nexport default cx;\r\n"],"names":["cx","classes","i","arguments","length","arg","undefined","type","push","Array","isArray","inner","keys","Object","j","join","with","_len","baseArgs","_key","_len2","args","_key2"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,EAAEA,GAAU;EAC1B,MAAMC,OAAO,GAAG,EAAE;AAElB,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGC,SAAA,CAAKC,MAAM,EAAEF,CAAC,EAAE,EAAE;AACpC,IAAA,MAAMG,GAAG,GAAQH,CAAC,GAAA,CAAA,IAAAC,SAAA,CAAAC,MAAA,IAADF,CAAC,GAAAI,SAAA,GAAAH,SAAA,CAADD,CAAC,CAAC;;AAEnB;IACA,IAAI,CAACG,GAAG,EAAE;IAEV,MAAME,IAAI,GAAG,OAAOF,GAAG;IAEvB,IAAIE,IAAI,KAAK,QAAQ,EAAE;AACrBN,MAAAA,OAAO,CAACO,IAAI,CAACH,GAAG,CAAC;IACnB,CAAC,MAAM,IAAII,KAAK,CAACC,OAAO,CAACL,GAAG,CAAC,EAAE;AAC7B;AACA,MAAA,MAAMM,KAAK,GAAGX,EAAE,CAAC,GAAGK,GAAG,CAAC;AACxB,MAAA,IAAIM,KAAK,EAAEV,OAAO,CAACO,IAAI,CAACG,KAAK,CAAC;AAChC,IAAA,CAAC,MAAM,IAAIJ,IAAI,KAAK,QAAQ,EAAE;AAC5B;AACA,MAAA,MAAMK,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACP,GAAG,CAAC;AAC7B,MAAA,KAAK,IAAIS,CAAC,GAAG,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