clases 1.1.8 → 1.1.10
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 +20 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +37 -47
package/dist/index.cjs
CHANGED
|
@@ -1,46 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
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
4
|
|
|
10
5
|
// src/index.ts
|
|
11
6
|
function createCl(...plugins) {
|
|
12
7
|
const registry = Object.assign({}, ...plugins);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!value) return "";
|
|
18
|
-
if (Array.isArray(value)) {
|
|
19
|
-
return value.map((v) => process(accumulatedKey, v)).filter(Boolean).join(" ");
|
|
8
|
+
const process = (accumulatedPrefix, input) => {
|
|
9
|
+
if (!input) return "";
|
|
10
|
+
if (typeof input === "string") {
|
|
11
|
+
return input.split(/[,\s\n]+/).filter(Boolean).map((cls) => accumulatedPrefix ? `${accumulatedPrefix}:${cls}` : cls).join(" ");
|
|
20
12
|
}
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
23
|
-
if (!v) return "";
|
|
24
|
-
if (registry[k] !== void 0) {
|
|
25
|
-
const nextKey = accumulatedKey ? `${accumulatedKey}:${k}` : k;
|
|
26
|
-
return process(nextKey, v);
|
|
27
|
-
}
|
|
28
|
-
return applyPrefix(accumulatedKey, k);
|
|
29
|
-
}).join(" ");
|
|
13
|
+
if (Array.isArray(input)) {
|
|
14
|
+
return input.map((i) => process(accumulatedPrefix, i)).filter(Boolean).join(" ");
|
|
30
15
|
}
|
|
31
|
-
if (typeof
|
|
32
|
-
|
|
16
|
+
if (typeof input === "object") {
|
|
17
|
+
let results = [];
|
|
18
|
+
for (const [key, value] of Object.entries(input)) {
|
|
19
|
+
if (!value) continue;
|
|
20
|
+
const registeredPrefix = registry[key];
|
|
21
|
+
if (registeredPrefix) {
|
|
22
|
+
const nextPrefix = accumulatedPrefix ? `${accumulatedPrefix}:${registeredPrefix}` : registeredPrefix;
|
|
23
|
+
results.push(process(nextPrefix, value));
|
|
24
|
+
} else {
|
|
25
|
+
results.push(process(accumulatedPrefix, key));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return results.join(" ");
|
|
33
29
|
}
|
|
34
30
|
return "";
|
|
35
31
|
};
|
|
36
|
-
const applyPrefix = (key, classString) => {
|
|
37
|
-
const resolved = getPrefix(key);
|
|
38
|
-
if (!resolved) return classString;
|
|
39
|
-
return classString.split(/[,\s\n]+/).filter(Boolean).map((cls) => `${resolved}:${cls}`).join(" ");
|
|
40
|
-
};
|
|
41
32
|
return (...inputs) => {
|
|
42
33
|
const processed = inputs.map((input) => process("", input));
|
|
43
|
-
return tailwindMerge.twMerge(
|
|
34
|
+
return tailwindMerge.twMerge(processed.filter(Boolean).join(" "));
|
|
44
35
|
};
|
|
45
36
|
}
|
|
46
37
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["twMerge"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["twMerge"],"mappings":";;;;;AAGO,SAAS,YAAuD,OAAA,EAAmB;AACtF,EAAA,MAAM,WAAmC,MAAA,CAAO,MAAA,CAAO,EAAC,EAAG,GAAG,OAAO,CAAA;AAErE,EAAA,MAAM,OAAA,GAAU,CAAC,iBAAA,EAA2B,KAAA,KAAuB;AAC/D,IAAA,IAAI,CAAC,OAAO,OAAO,EAAA;AAGnB,IAAA,IAAI,OAAO,UAAU,QAAA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OAAO,GAAA,CAAI,CAAC,UAAU,OAAA,CAAQ,EAAA,EAAI,KAAK,CAAC,CAAA;AAE1D,IAAA,OAAOA,sBAAQ,SAAA,CAAU,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,EACtD,CAAA;AACJ","file":"index.cjs","sourcesContent":["import { twMerge } from 'tailwind-merge';\r\nimport clsx, { type ClassValue } from 'clsx';\r\n\r\nexport function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins) {\r\n const registry: Record<string, string> = Object.assign({}, ...plugins);\r\n\r\n const process = (accumulatedPrefix: string, input: any): string => {\r\n if (!input) return '';\r\n\r\n // 1. Strings: Aplicar prefijo acumulado\r\n if (typeof input === 'string') {\r\n return input\r\n .split(/[,\\s\\n]+/)\r\n .filter(Boolean)\r\n .map((cls) => (accumulatedPrefix ? `${accumulatedPrefix}:${cls}` : cls))\r\n .join(' ');\r\n }\r\n\r\n // 2. Arrays: Procesar cada elemento\r\n if (Array.isArray(input)) {\r\n return input\r\n .map((i) => process(accumulatedPrefix, i))\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n // 3. Objetos: El corazón del problema\r\n if (typeof input === 'object') {\r\n let results: string[] = [];\r\n\r\n for (const [key, value] of Object.entries(input)) {\r\n if (!value) continue;\r\n\r\n const registeredPrefix = registry[key];\r\n\r\n if (registeredPrefix) {\r\n // Es un prefijo: acumulamos y bajamos un nivel\r\n const nextPrefix = accumulatedPrefix\r\n ? `${accumulatedPrefix}:${registeredPrefix}`\r\n : registeredPrefix;\r\n results.push(process(nextPrefix, value));\r\n } else {\r\n // NO es prefijo: es lógica { 'clase': true }\r\n // Procesamos la llave 'key' como el contenido, bajo el prefijo actual\r\n results.push(process(accumulatedPrefix, key));\r\n }\r\n }\r\n return results.join(' ');\r\n }\r\n\r\n return '';\r\n };\r\n\r\n return (...inputs: ClassValue[]) => {\r\n // Ejecutamos nuestro motor en cada input\r\n const processed = inputs.map((input) => process('', input));\r\n // twMerge se encarga de limpiar el string final\r\n return twMerge(processed.filter(Boolean).join(' '));\r\n };\r\n}\r\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,35 @@
|
|
|
1
1
|
import { twMerge } from 'tailwind-merge';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
2
|
|
|
4
3
|
// src/index.ts
|
|
5
4
|
function createCl(...plugins) {
|
|
6
5
|
const registry = Object.assign({}, ...plugins);
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (!value) return "";
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
return value.map((v) => process(accumulatedKey, v)).filter(Boolean).join(" ");
|
|
6
|
+
const process = (accumulatedPrefix, input) => {
|
|
7
|
+
if (!input) return "";
|
|
8
|
+
if (typeof input === "string") {
|
|
9
|
+
return input.split(/[,\s\n]+/).filter(Boolean).map((cls) => accumulatedPrefix ? `${accumulatedPrefix}:${cls}` : cls).join(" ");
|
|
14
10
|
}
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
17
|
-
if (!v) return "";
|
|
18
|
-
if (registry[k] !== void 0) {
|
|
19
|
-
const nextKey = accumulatedKey ? `${accumulatedKey}:${k}` : k;
|
|
20
|
-
return process(nextKey, v);
|
|
21
|
-
}
|
|
22
|
-
return applyPrefix(accumulatedKey, k);
|
|
23
|
-
}).join(" ");
|
|
11
|
+
if (Array.isArray(input)) {
|
|
12
|
+
return input.map((i) => process(accumulatedPrefix, i)).filter(Boolean).join(" ");
|
|
24
13
|
}
|
|
25
|
-
if (typeof
|
|
26
|
-
|
|
14
|
+
if (typeof input === "object") {
|
|
15
|
+
let results = [];
|
|
16
|
+
for (const [key, value] of Object.entries(input)) {
|
|
17
|
+
if (!value) continue;
|
|
18
|
+
const registeredPrefix = registry[key];
|
|
19
|
+
if (registeredPrefix) {
|
|
20
|
+
const nextPrefix = accumulatedPrefix ? `${accumulatedPrefix}:${registeredPrefix}` : registeredPrefix;
|
|
21
|
+
results.push(process(nextPrefix, value));
|
|
22
|
+
} else {
|
|
23
|
+
results.push(process(accumulatedPrefix, key));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return results.join(" ");
|
|
27
27
|
}
|
|
28
28
|
return "";
|
|
29
29
|
};
|
|
30
|
-
const applyPrefix = (key, classString) => {
|
|
31
|
-
const resolved = getPrefix(key);
|
|
32
|
-
if (!resolved) return classString;
|
|
33
|
-
return classString.split(/[,\s\n]+/).filter(Boolean).map((cls) => `${resolved}:${cls}`).join(" ");
|
|
34
|
-
};
|
|
35
30
|
return (...inputs) => {
|
|
36
31
|
const processed = inputs.map((input) => process("", input));
|
|
37
|
-
return twMerge(
|
|
32
|
+
return twMerge(processed.filter(Boolean).join(" "));
|
|
38
33
|
};
|
|
39
34
|
}
|
|
40
35
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAGO,SAAS,YAAuD,OAAA,EAAmB;AACtF,EAAA,MAAM,WAAmC,MAAA,CAAO,MAAA,CAAO,EAAC,EAAG,GAAG,OAAO,CAAA;AAErE,EAAA,MAAM,OAAA,GAAU,CAAC,iBAAA,EAA2B,KAAA,KAAuB;AAC/D,IAAA,IAAI,CAAC,OAAO,OAAO,EAAA;AAGnB,IAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC3B,MAAA,OAAO,MACF,KAAA,CAAM,UAAU,EAChB,MAAA,CAAO,OAAO,EACd,GAAA,CAAI,CAAC,QAAS,iBAAA,GAAoB,CAAA,EAAG,iBAAiB,CAAA,CAAA,EAAI,GAAG,KAAK,GAAI,CAAA,CACtE,KAAK,GAAG,CAAA;AAAA,IACjB;AAGA,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACtB,MAAA,OAAO,KAAA,CACF,GAAA,CAAI,CAAC,CAAA,KAAM,OAAA,CAAQ,iBAAA,EAAmB,CAAC,CAAC,CAAA,CACxC,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AAAA,IACjB;AAGA,IAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC3B,MAAA,IAAI,UAAoB,EAAC;AAEzB,MAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC9C,QAAA,IAAI,CAAC,KAAA,EAAO;AAEZ,QAAA,MAAM,gBAAA,GAAmB,SAAS,GAAG,CAAA;AAErC,QAAA,IAAI,gBAAA,EAAkB;AAElB,UAAA,MAAM,aAAa,iBAAA,GACb,CAAA,EAAG,iBAAiB,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA,GACxC,gBAAA;AACN,UAAA,OAAA,CAAQ,IAAA,CAAK,OAAA,CAAQ,UAAA,EAAY,KAAK,CAAC,CAAA;AAAA,QAC3C,CAAA,MAAO;AAGH,UAAA,OAAA,CAAQ,IAAA,CAAK,OAAA,CAAQ,iBAAA,EAAmB,GAAG,CAAC,CAAA;AAAA,QAChD;AAAA,MACJ;AACA,MAAA,OAAO,OAAA,CAAQ,KAAK,GAAG,CAAA;AAAA,IAC3B;AAEA,IAAA,OAAO,EAAA;AAAA,EACX,CAAA;AAEA,EAAA,OAAO,IAAI,MAAA,KAAyB;AAEhC,IAAA,MAAM,SAAA,GAAY,OAAO,GAAA,CAAI,CAAC,UAAU,OAAA,CAAQ,EAAA,EAAI,KAAK,CAAC,CAAA;AAE1D,IAAA,OAAO,QAAQ,SAAA,CAAU,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,EACtD,CAAA;AACJ","file":"index.js","sourcesContent":["import { twMerge } from 'tailwind-merge';\r\nimport clsx, { type ClassValue } from 'clsx';\r\n\r\nexport function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins) {\r\n const registry: Record<string, string> = Object.assign({}, ...plugins);\r\n\r\n const process = (accumulatedPrefix: string, input: any): string => {\r\n if (!input) return '';\r\n\r\n // 1. Strings: Aplicar prefijo acumulado\r\n if (typeof input === 'string') {\r\n return input\r\n .split(/[,\\s\\n]+/)\r\n .filter(Boolean)\r\n .map((cls) => (accumulatedPrefix ? `${accumulatedPrefix}:${cls}` : cls))\r\n .join(' ');\r\n }\r\n\r\n // 2. Arrays: Procesar cada elemento\r\n if (Array.isArray(input)) {\r\n return input\r\n .map((i) => process(accumulatedPrefix, i))\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n // 3. Objetos: El corazón del problema\r\n if (typeof input === 'object') {\r\n let results: string[] = [];\r\n\r\n for (const [key, value] of Object.entries(input)) {\r\n if (!value) continue;\r\n\r\n const registeredPrefix = registry[key];\r\n\r\n if (registeredPrefix) {\r\n // Es un prefijo: acumulamos y bajamos un nivel\r\n const nextPrefix = accumulatedPrefix\r\n ? `${accumulatedPrefix}:${registeredPrefix}`\r\n : registeredPrefix;\r\n results.push(process(nextPrefix, value));\r\n } else {\r\n // NO es prefijo: es lógica { 'clase': true }\r\n // Procesamos la llave 'key' como el contenido, bajo el prefijo actual\r\n results.push(process(accumulatedPrefix, key));\r\n }\r\n }\r\n return results.join(' ');\r\n }\r\n\r\n return '';\r\n };\r\n\r\n return (...inputs: ClassValue[]) => {\r\n // Ejecutamos nuestro motor en cada input\r\n const processed = inputs.map((input) => process('', input));\r\n // twMerge se encarga de limpiar el string final\r\n return twMerge(processed.filter(Boolean).join(' '));\r\n };\r\n}\r\n"]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,67 +4,57 @@ import clsx, { type ClassValue } from 'clsx';
|
|
|
4
4
|
export function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins) {
|
|
5
5
|
const registry: Record<string, string> = Object.assign({}, ...plugins);
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return key
|
|
10
|
-
.split(':')
|
|
11
|
-
.map((part) => registry[part])
|
|
12
|
-
.filter(Boolean)
|
|
13
|
-
.join(':');
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const process = (accumulatedKey: string, value: any): string => {
|
|
17
|
-
if (!value) return '';
|
|
7
|
+
const process = (accumulatedPrefix: string, input: any): string => {
|
|
8
|
+
if (!input) return '';
|
|
18
9
|
|
|
19
|
-
// 1.
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
22
|
-
.
|
|
10
|
+
// 1. Strings: Aplicar prefijo acumulado
|
|
11
|
+
if (typeof input === 'string') {
|
|
12
|
+
return input
|
|
13
|
+
.split(/[,\s\n]+/)
|
|
23
14
|
.filter(Boolean)
|
|
15
|
+
.map((cls) => (accumulatedPrefix ? `${accumulatedPrefix}:${cls}` : cls))
|
|
24
16
|
.join(' ');
|
|
25
17
|
}
|
|
26
18
|
|
|
27
|
-
// 2.
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
30
|
-
.map((
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// Si la llave es un prefijo (md, hover), profundizamos
|
|
34
|
-
if (registry[k] !== undefined) {
|
|
35
|
-
const nextKey = accumulatedKey ? `${accumulatedKey}:${k}` : k;
|
|
36
|
-
return process(nextKey, v);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Si NO es prefijo, tratamos la llave 'k' como la clase final
|
|
40
|
-
// Pero le aplicamos el prefijo acumulado hasta ahora
|
|
41
|
-
return applyPrefix(accumulatedKey, k);
|
|
42
|
-
})
|
|
19
|
+
// 2. Arrays: Procesar cada elemento
|
|
20
|
+
if (Array.isArray(input)) {
|
|
21
|
+
return input
|
|
22
|
+
.map((i) => process(accumulatedPrefix, i))
|
|
23
|
+
.filter(Boolean)
|
|
43
24
|
.join(' ');
|
|
44
25
|
}
|
|
45
26
|
|
|
46
|
-
// 3.
|
|
47
|
-
if (typeof
|
|
48
|
-
|
|
27
|
+
// 3. Objetos: El corazón del problema
|
|
28
|
+
if (typeof input === 'object') {
|
|
29
|
+
let results: string[] = [];
|
|
30
|
+
|
|
31
|
+
for (const [key, value] of Object.entries(input)) {
|
|
32
|
+
if (!value) continue;
|
|
33
|
+
|
|
34
|
+
const registeredPrefix = registry[key];
|
|
35
|
+
|
|
36
|
+
if (registeredPrefix) {
|
|
37
|
+
// Es un prefijo: acumulamos y bajamos un nivel
|
|
38
|
+
const nextPrefix = accumulatedPrefix
|
|
39
|
+
? `${accumulatedPrefix}:${registeredPrefix}`
|
|
40
|
+
: registeredPrefix;
|
|
41
|
+
results.push(process(nextPrefix, value));
|
|
42
|
+
} else {
|
|
43
|
+
// NO es prefijo: es lógica { 'clase': true }
|
|
44
|
+
// Procesamos la llave 'key' como el contenido, bajo el prefijo actual
|
|
45
|
+
results.push(process(accumulatedPrefix, key));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return results.join(' ');
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
return '';
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
// Función para aplicar el prefijo resuelto a un string de clases
|
|
55
|
-
const applyPrefix = (key: string, classString: string): string => {
|
|
56
|
-
const resolved = getPrefix(key);
|
|
57
|
-
if (!resolved) return classString;
|
|
58
|
-
|
|
59
|
-
return classString
|
|
60
|
-
.split(/[,\s\n]+/)
|
|
61
|
-
.filter(Boolean)
|
|
62
|
-
.map((cls) => `${resolved}:${cls}`)
|
|
63
|
-
.join(' ');
|
|
64
|
-
};
|
|
65
|
-
|
|
66
54
|
return (...inputs: ClassValue[]) => {
|
|
55
|
+
// Ejecutamos nuestro motor en cada input
|
|
67
56
|
const processed = inputs.map((input) => process('', input));
|
|
68
|
-
|
|
57
|
+
// twMerge se encarga de limpiar el string final
|
|
58
|
+
return twMerge(processed.filter(Boolean).join(' '));
|
|
69
59
|
};
|
|
70
60
|
}
|