clases 1.0.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/index.cjs ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var tailwindMerge = require('tailwind-merge');
4
+ var clsx = require('clsx');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var clsx__default = /*#__PURE__*/_interopDefault(clsx);
9
+
10
+ // src/index.ts
11
+ function createCl(...plugins) {
12
+ const registry = Object.assign({ base: "base" }, ...plugins);
13
+ const process = (key, value) => {
14
+ if (!value) return "";
15
+ if (Array.isArray(value)) {
16
+ return value.map((v) => process(key, v)).filter(Boolean).join(" ");
17
+ }
18
+ if (typeof value === "object") {
19
+ return Object.entries(value).map(([nestedKey, nestedValue]) => {
20
+ const combinedKey = key === "base" ? nestedKey : nestedKey === "base" ? key : `${key}:${nestedKey}`;
21
+ return process(combinedKey, nestedValue);
22
+ }).join(" ");
23
+ }
24
+ const prefix = registry[key] || key;
25
+ if (typeof value === "string") {
26
+ return value.split(/[,\s\n]+/).filter(Boolean).map((cls) => prefix === "base" ? cls : `${prefix}:${cls}`).join(" ");
27
+ }
28
+ return "";
29
+ };
30
+ return (...inputs) => {
31
+ const processed = inputs.map((input) => {
32
+ if (input !== null && typeof input === "object" && !Array.isArray(input)) {
33
+ return Object.entries(input).map(([k, v]) => v === true ? k : process(k, v)).join(" ");
34
+ }
35
+ return input;
36
+ });
37
+ return tailwindMerge.twMerge(clsx__default.default(processed));
38
+ };
39
+ }
40
+
41
+ exports.createCl = createCl;
42
+ //# sourceMappingURL=index.cjs.map
43
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["twMerge","clsx"],"mappings":";;;;;;;;;;AAWO,SAAS,YAAuD,OAAA,EAAmB;AAEtF,EAAA,MAAM,QAAA,GAAmC,OAAO,MAAA,CAAO,EAAE,MAA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AO,GAAA,CAAI,CAAC,KAAA,KAAU;AACpC,MAAA,IAAI,KAAA,KAAU,QAAQ,OAAO,KAAA,KAAU,YAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACtE,QAAA,OAAO,OAAO,OAAA,CAAQ,KAAK,EACtB,GAAA,CAAI,CAAC,CAAC,CAAA,EAAG,CAAC,MAAO,CAAA,KAAM,IAAA,GAAO,IAAI,OAAA,CAAQ,CAAA,EAAG,CAAC,CAAE,CAAA,CAChD,KAAK,GAAG,CAAA;AAAA,MACjB;AACA,MAAA,OAAO,KAAA;AAAA,IACX,CAAC,CAAA;AACD,IAAA,OAAOA,qBAAA,CAAQC,qBAAA,CAAK,SAAS,CAAC,CAAA;AAAA,EAClC,CAAA;AACJ","file":"index.cjs","sourcesContent":["import { twMerge } from 'tailwind-merge';\r\nimport clsx, { type ClassValue } from 'clsx';\r\n\r\n/**\r\n * Helper type to merge an array of objects into one single type\r\n * This is what gives the user autocomplete for ALL plugins combined.\r\n */\r\ntype MergePlugins<T extends Record<string, string>[]> = T extends [infer First, ...infer Rest]\r\n ? First & (Rest extends Record<string, string>[] ? MergePlugins<Rest> : {})\r\n : {};\r\n\r\nexport function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins) {\r\n // Core merges all plugins into a single registry automatically\r\n const registry: Record<string, string> = Object.assign({ base: 'base' }, ...plugins);\r\n\r\n type CombinedKeys = keyof MergePlugins<TPlugins>;\r\n\r\n const process = (key: string, value: any): string => {\r\n if (!value) return '';\r\n\r\n if (Array.isArray(value)) {\r\n return value\r\n .map((v) => process(key, v))\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\nif (typeof value === 'object') {\r\n return Object.entries(value)\r\n .map(([nestedKey, nestedValue]) => {\r\n // FIX: If the nested key is 'base', it doesn't add to the prefix chain\r\n const combinedKey =\r\n key === 'base'\r\n ? nestedKey\r\n : nestedKey === 'base'\r\n ? key // If nested is base, keep the parent key\r\n : `${key}:${nestedKey}`;\r\n\r\n return process(combinedKey, nestedValue);\r\n })\r\n .join(' ');\r\n}\r\n\r\n const prefix = registry[key] || key;\r\n\r\n if (typeof value === 'string') {\r\n return value\r\n .split(/[,\\s\\n]+/)\r\n .filter(Boolean)\r\n .map((cls) => (prefix === 'base' ? cls : `${prefix}:${cls}`))\r\n .join(' ');\r\n }\r\n return '';\r\n };\r\n\r\n return (...inputs: (ClassValue | { [K in CombinedKeys | 'base' | (string & {})]?: any })[]) => {\r\n const processed = inputs.map((input) => {\r\n if (input !== null && typeof input === 'object' && !Array.isArray(input)) {\r\n return Object.entries(input)\r\n .map(([k, v]) => (v === true ? k : process(k, v)))\r\n .join(' ');\r\n }\r\n return input;\r\n });\r\n return twMerge(clsx(processed));\r\n };\r\n}\r\n"]}
@@ -0,0 +1,10 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ /**
4
+ * Helper type to merge an array of objects into one single type
5
+ * This is what gives the user autocomplete for ALL plugins combined.
6
+ */
7
+ type MergePlugins<T extends Record<string, string>[]> = T extends [infer First, ...infer Rest] ? First & (Rest extends Record<string, string>[] ? MergePlugins<Rest> : {}) : {};
8
+ declare function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins): (...inputs: (ClassValue | { [K in keyof MergePlugins<TPlugins> | "base" | (string & {})]?: any; })[]) => string;
9
+
10
+ export { createCl };
@@ -0,0 +1,10 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ /**
4
+ * Helper type to merge an array of objects into one single type
5
+ * This is what gives the user autocomplete for ALL plugins combined.
6
+ */
7
+ type MergePlugins<T extends Record<string, string>[]> = T extends [infer First, ...infer Rest] ? First & (Rest extends Record<string, string>[] ? MergePlugins<Rest> : {}) : {};
8
+ declare function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins): (...inputs: (ClassValue | { [K in keyof MergePlugins<TPlugins> | "base" | (string & {})]?: any; })[]) => string;
9
+
10
+ export { createCl };
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ import { twMerge } from 'tailwind-merge';
2
+ import clsx from 'clsx';
3
+
4
+ // src/index.ts
5
+ function createCl(...plugins) {
6
+ const registry = Object.assign({ base: "base" }, ...plugins);
7
+ const process = (key, value) => {
8
+ if (!value) return "";
9
+ if (Array.isArray(value)) {
10
+ return value.map((v) => process(key, v)).filter(Boolean).join(" ");
11
+ }
12
+ if (typeof value === "object") {
13
+ return Object.entries(value).map(([nestedKey, nestedValue]) => {
14
+ const combinedKey = key === "base" ? nestedKey : nestedKey === "base" ? key : `${key}:${nestedKey}`;
15
+ return process(combinedKey, nestedValue);
16
+ }).join(" ");
17
+ }
18
+ const prefix = registry[key] || key;
19
+ if (typeof value === "string") {
20
+ return value.split(/[,\s\n]+/).filter(Boolean).map((cls) => prefix === "base" ? cls : `${prefix}:${cls}`).join(" ");
21
+ }
22
+ return "";
23
+ };
24
+ return (...inputs) => {
25
+ const processed = inputs.map((input) => {
26
+ if (input !== null && typeof input === "object" && !Array.isArray(input)) {
27
+ return Object.entries(input).map(([k, v]) => v === true ? k : process(k, v)).join(" ");
28
+ }
29
+ return input;
30
+ });
31
+ return twMerge(clsx(processed));
32
+ };
33
+ }
34
+
35
+ export { createCl };
36
+ //# sourceMappingURL=index.js.map
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAWO,SAAS,YAAuD,OAAA,EAAmB;AAEtF,EAAA,MAAM,QAAA,GAAmC,OAAO,MAAA,CAAO,EAAE,MAAM,MAAA,EAAO,EAAG,GAAG,OAAO,CAAA;AAInF,EAAA,MAAM,OAAA,GAAU,CAAC,GAAA,EAAa,KAAA,KAAuB;AACjD,IAAA,IAAI,CAAC,OAAO,OAAO,EAAA;AAEnB,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACtB,MAAA,OAAO,KAAA,CACF,GAAA,CAAI,CAAC,CAAA,KAAM,OAAA,CAAQ,GAAA,E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,CAAA,EAAG,CAAC,CAAE,CAAA,CAChD,KAAK,GAAG,CAAA;AAAA,MACjB;AACA,MAAA,OAAO,KAAA;AAAA,IACX,CAAC,CAAA;AACD,IAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,SAAS,CAAC,CAAA;AAAA,EAClC,CAAA;AACJ","file":"index.js","sourcesContent":["import { twMerge } from 'tailwind-merge';\r\nimport clsx, { type ClassValue } from 'clsx';\r\n\r\n/**\r\n * Helper type to merge an array of objects into one single type\r\n * This is what gives the user autocomplete for ALL plugins combined.\r\n */\r\ntype MergePlugins<T extends Record<string, string>[]> = T extends [infer First, ...infer Rest]\r\n ? First & (Rest extends Record<string, string>[] ? MergePlugins<Rest> : {})\r\n : {};\r\n\r\nexport function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins) {\r\n // Core merges all plugins into a single registry automatically\r\n const registry: Record<string, string> = Object.assign({ base: 'base' }, ...plugins);\r\n\r\n type CombinedKeys = keyof MergePlugins<TPlugins>;\r\n\r\n const process = (key: string, value: any): string => {\r\n if (!value) return '';\r\n\r\n if (Array.isArray(value)) {\r\n return value\r\n .map((v) => process(key, v))\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\nif (typeof value === 'object') {\r\n return Object.entries(value)\r\n .map(([nestedKey, nestedValue]) => {\r\n // FIX: If the nested key is 'base', it doesn't add to the prefix chain\r\n const combinedKey =\r\n key === 'base'\r\n ? nestedKey\r\n : nestedKey === 'base'\r\n ? key // If nested is base, keep the parent key\r\n : `${key}:${nestedKey}`;\r\n\r\n return process(combinedKey, nestedValue);\r\n })\r\n .join(' ');\r\n}\r\n\r\n const prefix = registry[key] || key;\r\n\r\n if (typeof value === 'string') {\r\n return value\r\n .split(/[,\\s\\n]+/)\r\n .filter(Boolean)\r\n .map((cls) => (prefix === 'base' ? cls : `${prefix}:${cls}`))\r\n .join(' ');\r\n }\r\n return '';\r\n };\r\n\r\n return (...inputs: (ClassValue | { [K in CombinedKeys | 'base' | (string & {})]?: any })[]) => {\r\n const processed = inputs.map((input) => {\r\n if (input !== null && typeof input === 'object' && !Array.isArray(input)) {\r\n return Object.entries(input)\r\n .map(([k, v]) => (v === true ? k : process(k, v)))\r\n .join(' ');\r\n }\r\n return input;\r\n });\r\n return twMerge(clsx(processed));\r\n };\r\n}\r\n"]}
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "clases",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "clsx": "^2.1.1",
15
+ "tailwind-merge": "^2.6.0"
16
+ },
17
+ "scripts": {
18
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
19
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
20
+ }
21
+ }
package/src/index.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { twMerge } from 'tailwind-merge';
2
+ import clsx, { type ClassValue } from 'clsx';
3
+
4
+ /**
5
+ * Helper type to merge an array of objects into one single type
6
+ * This is what gives the user autocomplete for ALL plugins combined.
7
+ */
8
+ type MergePlugins<T extends Record<string, string>[]> = T extends [infer First, ...infer Rest]
9
+ ? First & (Rest extends Record<string, string>[] ? MergePlugins<Rest> : {})
10
+ : {};
11
+
12
+ export function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins) {
13
+ // Core merges all plugins into a single registry automatically
14
+ const registry: Record<string, string> = Object.assign({ base: 'base' }, ...plugins);
15
+
16
+ type CombinedKeys = keyof MergePlugins<TPlugins>;
17
+
18
+ const process = (key: string, value: any): string => {
19
+ if (!value) return '';
20
+
21
+ if (Array.isArray(value)) {
22
+ return value
23
+ .map((v) => process(key, v))
24
+ .filter(Boolean)
25
+ .join(' ');
26
+ }
27
+
28
+ if (typeof value === 'object') {
29
+ return Object.entries(value)
30
+ .map(([nestedKey, nestedValue]) => {
31
+ // FIX: If the nested key is 'base', it doesn't add to the prefix chain
32
+ const combinedKey =
33
+ key === 'base'
34
+ ? nestedKey
35
+ : nestedKey === 'base'
36
+ ? key // If nested is base, keep the parent key
37
+ : `${key}:${nestedKey}`;
38
+
39
+ return process(combinedKey, nestedValue);
40
+ })
41
+ .join(' ');
42
+ }
43
+
44
+ const prefix = registry[key] || key;
45
+
46
+ if (typeof value === 'string') {
47
+ return value
48
+ .split(/[,\s\n]+/)
49
+ .filter(Boolean)
50
+ .map((cls) => (prefix === 'base' ? cls : `${prefix}:${cls}`))
51
+ .join(' ');
52
+ }
53
+ return '';
54
+ };
55
+
56
+ return (...inputs: (ClassValue | { [K in CombinedKeys | 'base' | (string & {})]?: any })[]) => {
57
+ const processed = inputs.map((input) => {
58
+ if (input !== null && typeof input === 'object' && !Array.isArray(input)) {
59
+ return Object.entries(input)
60
+ .map(([k, v]) => (v === true ? k : process(k, v)))
61
+ .join(' ');
62
+ }
63
+ return input;
64
+ });
65
+ return twMerge(clsx(processed));
66
+ };
67
+ }
@@ -0,0 +1,60 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { createCl } from '../index';
3
+
4
+ describe('Core cl utility', () => {
5
+ // 1. Test basic plugin merging
6
+ it('should merge multiple plugins and apply prefixes', () => {
7
+ const tailwind = { md: 'md', hover: 'hover' };
8
+ const custom = { hocus: 'hover:focus' };
9
+
10
+ const cl = createCl(tailwind, custom);
11
+
12
+ const result = cl({
13
+ md: 'p-4',
14
+ hocus: 'scale-110'
15
+ });
16
+
17
+ expect(result).toBe('md:p-4 hover:focus:scale-110');
18
+ });
19
+
20
+ // 2. Test Recursion (Nesting)
21
+ it('should stack prefixes when objects are nested', () => {
22
+ const cl = createCl({ md: 'md', hover: 'hover', dark: 'dark' });
23
+
24
+ const result = cl({
25
+ md: {
26
+ hover: 'bg-blue-500',
27
+ base: 'text-black',
28
+ dark: {
29
+ base: 'text-white',
30
+ focus: 'ring-2'
31
+ }
32
+ }
33
+ });
34
+
35
+ expect(result).toContain('md:hover:bg-blue-500');
36
+ expect(result).toContain('md:text-black');
37
+ expect(result).toContain('md:dark:text-white'); // Deep base check
38
+ expect(result).toContain('md:dark:focus:ring-2'); // Deep stack check
39
+ });
40
+
41
+ // 3. Test Recursive Arrays
42
+ it('should flatten and prefix arrays deep in the tree', () => {
43
+ const cl = createCl({ lg: 'lg' });
44
+
45
+ const result = cl({
46
+ lg: ['flex', ['items-center', 'gap-2']]
47
+ });
48
+
49
+ expect(result).toBe('lg:flex lg:items-center lg:gap-2');
50
+ });
51
+
52
+ // 4. Test tailwind-merge logic
53
+ it('should resolve conflicts using tailwind-merge', () => {
54
+ const cl = createCl({ md: 'md' });
55
+
56
+ // p-8 should override p-4 even inside the object
57
+ const result = cl('p-4', { base: 'p-8' });
58
+ expect(result).toBe('p-8');
59
+ });
60
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ // Add these to fix the "not under rootDir" error
7
+ "rootDirs": ["src", "../core/src"],
8
+ "composite": true
9
+ },
10
+ "include": ["src/**/*"]
11
+ }