clases 1.1.11 → 1.1.13

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
@@ -10,25 +10,46 @@ var clsx__default = /*#__PURE__*/_interopDefault(clsx);
10
10
  // src/index.ts
11
11
  function createCl(...plugins) {
12
12
  const registry = Object.assign({}, ...plugins);
13
- const process = (accumulatedPrefix, input) => {
14
- if (!input) return "";
13
+ const process = (accumulatedPath, input) => {
14
+ console.log(`[START] Path: "${accumulatedPath}" | Input:`, input);
15
+ if (!input) {
16
+ console.log(`[SKIP] Input is falsy`);
17
+ return "";
18
+ }
15
19
  if (typeof input === "string") {
16
- const resolved = accumulatedPrefix.split(":").map((part) => part === "base" ? null : registry[part] || null).filter(Boolean).join(":");
17
- return input.split(/[,\s\n]+/).filter(Boolean).map((cls) => resolved ? `${resolved}:${cls}` : cls).join(" ");
20
+ const resolvedPrefix = accumulatedPath.split(":").map((part) => {
21
+ if (part === "base" || part === "?") return null;
22
+ return registry[part] || part;
23
+ }).filter(Boolean).join(":");
24
+ const result = input.split(/[,\s\n]+/).filter(Boolean).map((cls) => resolvedPrefix ? `${resolvedPrefix}:${cls}` : cls).join(" ");
25
+ console.log(`[STRING] Resolved: "${resolvedPrefix}" | Out: "${result}"`);
26
+ return result;
18
27
  }
19
28
  if (Array.isArray(input)) {
20
- return input.map((i) => process(accumulatedPrefix, i)).filter(Boolean).join(" ");
29
+ console.log(`[ARRAY] Processing ${input.length} elements...`);
30
+ return input.map((i) => process(accumulatedPath, i)).filter(Boolean).join(" ");
21
31
  }
22
32
  if (typeof input === "object") {
33
+ console.log(`[OBJECT] Keys:`, Object.keys(input));
23
34
  return Object.entries(input).map(([key, value]) => {
24
- if (!value) return "";
25
- const isBase = key === "base";
26
- const isPrefix = registry[key] !== void 0;
27
- if (isBase || isPrefix) {
28
- const nextPrefix = accumulatedPrefix ? `${accumulatedPrefix}:${key}` : key;
29
- return process(nextPrefix, value);
35
+ const isTransparent = key === "base" || key === "?";
36
+ const isRegistered = registry[key] !== void 0;
37
+ console.log(
38
+ ` -> Key: "${key}" | Value: ${value} | isPrefix: ${isRegistered} | isTransparent: ${isTransparent}`
39
+ );
40
+ if (!value) {
41
+ console.log(` [SKIP KEY] "${key}" because value is falsy`);
42
+ return "";
43
+ }
44
+ if (isTransparent || isRegistered) {
45
+ const newPath = accumulatedPath ? `${accumulatedPath}:${key}` : key;
46
+ console.log(` [DIVE] Moving to path: "${newPath}"`);
47
+ return process(newPath, value);
30
48
  } else {
31
- return process(accumulatedPrefix, key);
49
+ console.log(
50
+ ` [CLASS] Treating key "${key}" as class under path "${accumulatedPath}"`
51
+ );
52
+ return process(accumulatedPath, key);
32
53
  }
33
54
  }).filter(Boolean).join(" ");
34
55
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["twMerge","clsx"],"mappings":";;;;;;;;;;AAUO,SAAS,YAAuD,OAAA,EAAmB;AACtF,EAAA,MAAM,WAAmC,MAAA,CAAO,MAAA,CAAO,EAAC,EAAG,GAAG,OAAO,CAAA;AAQrE,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,MAAM,QAAA,GAAW,kBACZ,KAAA,CAAM,GAAG,EACT,GAAA,CAAI,CAAC,SAAU,IAAA,KAAS,MAAA,GAAS,OAAO,QAAA,CAAS,IAAI,KAAK,IAAK,CAAA,CAC/D,OAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AAEb,MAAA,OAAO,MACF,KAAA,CAAM,UAAU,EAChB,MAAA,CAAO,OAAO,EACd,GAAA,CAAI,CAAC,QAAS,QAAA,GAAW,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,GAAG,KAAK,GAAI,CAAA,CACpD,KAAK,GAAG,CAAA;AAAA,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, { type ClassValue } from 'clsx';\r\n\r\n/**\r\n * Creates a customized Tailwind class engine instance with prefix registry support.\r\n * * @param plugins - Objects mapping custom aliases (e.g., 'ui') to real Tailwind prefixes (e.g., 'prefix').\r\n * @returns A recursive 'cl' function that processes strings, arrays, and objects.\r\n * * @example\r\n * const tw = createCl({ md: 'md', ui: 'prefix' });\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 /**\r\n * Recursively processes input values to apply prefixes and logic.\r\n * * @param accumulatedPrefix - The prefix path built during recursion (e.g., 'md:hover').\r\n * @param input - The value to process (string, array, or object).\r\n * @returns A string of prefixed and filtered Tailwind classes.\r\n */\r\n const process = (accumulatedPrefix: string, input: any): string => {\r\n if (!input) return '';\r\n\r\n // 1. Strings: Resolve real Tailwind prefixes and apply them\r\n if (typeof input === 'string') {\r\n const resolved = accumulatedPrefix\r\n .split(':')\r\n .map((part) => (part === 'base' ? null : registry[part] || null))\r\n .filter(Boolean)\r\n .join(':');\r\n\r\n return input\r\n .split(/[,\\s\\n]+/) // Split by commas, spaces, or newlines\r\n .filter(Boolean)\r\n .map((cls) => (resolved ? `${resolved}:${cls}` : cls))\r\n .join(' ');\r\n }\r\n\r\n // 2. Arrays: Multi-line support and recursive processing\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. Objects: Prefix navigation and Conditional Logic (clsx-style)\r\n if (typeof input === 'object') {\r\n return Object.entries(input)\r\n .map(([key, value]) => {\r\n if (!value) return '';\r\n\r\n const isBase = key === 'base';\r\n const isPrefix = registry[key] !== undefined;\r\n\r\n if (isBase || isPrefix) {\r\n // It's an organization node or a prefix: accumulate and dive deeper\r\n const nextPrefix = accumulatedPrefix ? `${accumulatedPrefix}:${key}` : key;\r\n return process(nextPrefix, value);\r\n } else {\r\n // Standard logic { 'class-name': boolean }: treat the key as the class content\r\n return process(accumulatedPrefix, key);\r\n }\r\n })\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n return '';\r\n };\r\n\r\n /**\r\n * Main utility for generating Tailwind classes.\r\n * Supports strings, nested objects with prefixes, and arrays.\r\n * * @param inputs - A list of arguments following the clsx pattern.\r\n * @returns A processed, deduplicated string of classes via twMerge.\r\n * * @example\r\n * tw('btn-base', { md: 'p-4', hover: { 'opacity-50': isDim } });\r\n */\r\n return (...inputs: ClassValue[]) => {\r\n const processed = inputs.map((input) => process('', input));\r\n return twMerge(clsx(processed));\r\n };\r\n}\r\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["twMerge","clsx"],"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,eAAA,EAAyB,KAAA,KAAuB;AAC7D,IAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,eAAA,EAAkB,eAAe,CAAA,UAAA,CAAA,EAAc,KAAK,CAAA;AAEhE,IAAA,IAAI,CAAC,KAAA,EAAO;AACR,MAAA,OAAA,CAAQ,IAAI,CAAA,qBAAA,CAAuB,CAAA;AACnC,MAAA,OAAO,EAAA;AAAA,IACX;AAGA,IAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC3B,MAAA,MAAM,iBAAiB,eAAA,CAClB,KAAA,CAAM,GAAG,CAAA,CACT,GAAA,CAAI,CAAC,IAAA,KAAS;AACX,QAAA,IAAI,IAAA,KAAS,MAAA,IAAU,IAAA,KAAS,GAAA,EAAK,OAAO,IAAA;AAC5C,QAAA,OAAO,QAAA,CAAS,IAAI,CAAA,IAAK,IAAA;AAAA,MAC7B,CAAC,CAAA,CACA,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AAEb,MAAA,MAAM,MA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,UAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,cAAA,EAAiB,GAAG,CAAA,wBAAA,CAA0B,CAAA;AAC1D,UAAA,OAAO,EAAA;AAAA,QACX;AAEA,QAAA,IAAI,iBAAiB,YAAA,EAAc;AAC/B,UAAA,MAAM,UAAU,eAAA,GAAkB,CAAA,EAAG,eAAe,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,GAAK,GAAA;AAChE,UAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,0BAAA,EAA6B,OAAO,CAAA,CAAA,CAAG,CAAA;AACnD,UAAA,OAAO,OAAA,CAAQ,SAAS,KAAK,CAAA;AAAA,QACjC,CAAA,MAAO;AACH,UAAA,OAAA,CAAQ,GAAA;AAAA,YACJ,CAAA,wBAAA,EAA2B,GAAG,CAAA,uBAAA,EAA0B,eAAe,CAAA,CAAA;AAAA,WAC3E;AACA,UAAA,OAAO,OAAA,CAAQ,iBAAiB,GAAG,CAAA;AAAA,QACvC;AAAA,MACJ,CAAC,CAAA,CACA,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,OAAO,EAAA;AAAA,EACX,CAAA;AAEA,EAAA,OAAO,IAAI,MAAA,KAAyB;AAChC,IAAA,MAAM,SAAA,GAAY,OAAO,GAAA,CAAI,CAAC,UAAU,OAAA,CAAQ,EAAA,EAAI,KAAK,CAAC,CAAA;AAC1D,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\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 = (accumulatedPath: string, input: any): string => {\r\n console.log(`[START] Path: \"${accumulatedPath}\" | Input:`, input);\r\n\r\n if (!input) {\r\n console.log(`[SKIP] Input is falsy`);\r\n return '';\r\n }\r\n\r\n // 1. Caso String\r\n if (typeof input === 'string') {\r\n const resolvedPrefix = accumulatedPath\r\n .split(':')\r\n .map((part) => {\r\n if (part === 'base' || part === '?') return null;\r\n return registry[part] || part;\r\n })\r\n .filter(Boolean)\r\n .join(':');\r\n\r\n const result = input\r\n .split(/[,\\s\\n]+/)\r\n .filter(Boolean)\r\n .map((cls) => (resolvedPrefix ? `${resolvedPrefix}:${cls}` : cls))\r\n .join(' ');\r\n\r\n console.log(`[STRING] Resolved: \"${resolvedPrefix}\" | Out: \"${result}\"`);\r\n return result;\r\n }\r\n\r\n // 2. Caso Array\r\n if (Array.isArray(input)) {\r\n console.log(`[ARRAY] Processing ${input.length} elements...`);\r\n return input\r\n .map((i) => process(accumulatedPath, i))\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n // 3. Caso Objeto\r\n if (typeof input === 'object') {\r\n console.log(`[OBJECT] Keys:`, Object.keys(input));\r\n return Object.entries(input)\r\n .map(([key, value]) => {\r\n const isTransparent = key === 'base' || key === '?';\r\n const isRegistered = registry[key] !== undefined;\r\n\r\n console.log(\r\n ` -> Key: \"${key}\" | Value: ${value} | isPrefix: ${isRegistered} | isTransparent: ${isTransparent}`\r\n );\r\n\r\n if (!value) {\r\n console.log(` [SKIP KEY] \"${key}\" because value is falsy`);\r\n return '';\r\n }\r\n\r\n if (isTransparent || isRegistered) {\r\n const newPath = accumulatedPath ? `${accumulatedPath}:${key}` : key;\r\n console.log(` [DIVE] Moving to path: \"${newPath}\"`);\r\n return process(newPath, value);\r\n } else {\r\n console.log(\r\n ` [CLASS] Treating key \"${key}\" as class under path \"${accumulatedPath}\"`\r\n );\r\n return process(accumulatedPath, key);\r\n }\r\n })\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n return '';\r\n };\r\n\r\n return (...inputs: ClassValue[]) => {\r\n const processed = inputs.map((input) => process('', input));\r\n return twMerge(clsx(processed));\r\n };\r\n}\r\n"]}
package/dist/index.d.cts CHANGED
@@ -1,12 +1,5 @@
1
1
  import { ClassValue } from 'clsx';
2
2
 
3
- /**
4
- * Creates a customized Tailwind class engine instance with prefix registry support.
5
- * * @param plugins - Objects mapping custom aliases (e.g., 'ui') to real Tailwind prefixes (e.g., 'prefix').
6
- * @returns A recursive 'cl' function that processes strings, arrays, and objects.
7
- * * @example
8
- * const tw = createCl({ md: 'md', ui: 'prefix' });
9
- */
10
3
  declare function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins): (...inputs: ClassValue[]) => string;
11
4
 
12
5
  export { createCl };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,5 @@
1
1
  import { ClassValue } from 'clsx';
2
2
 
3
- /**
4
- * Creates a customized Tailwind class engine instance with prefix registry support.
5
- * * @param plugins - Objects mapping custom aliases (e.g., 'ui') to real Tailwind prefixes (e.g., 'prefix').
6
- * @returns A recursive 'cl' function that processes strings, arrays, and objects.
7
- * * @example
8
- * const tw = createCl({ md: 'md', ui: 'prefix' });
9
- */
10
3
  declare function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins): (...inputs: ClassValue[]) => string;
11
4
 
12
5
  export { createCl };
package/dist/index.js CHANGED
@@ -4,25 +4,46 @@ import clsx from 'clsx';
4
4
  // src/index.ts
5
5
  function createCl(...plugins) {
6
6
  const registry = Object.assign({}, ...plugins);
7
- const process = (accumulatedPrefix, input) => {
8
- if (!input) return "";
7
+ const process = (accumulatedPath, input) => {
8
+ console.log(`[START] Path: "${accumulatedPath}" | Input:`, input);
9
+ if (!input) {
10
+ console.log(`[SKIP] Input is falsy`);
11
+ return "";
12
+ }
9
13
  if (typeof input === "string") {
10
- const resolved = accumulatedPrefix.split(":").map((part) => part === "base" ? null : registry[part] || null).filter(Boolean).join(":");
11
- return input.split(/[,\s\n]+/).filter(Boolean).map((cls) => resolved ? `${resolved}:${cls}` : cls).join(" ");
14
+ const resolvedPrefix = accumulatedPath.split(":").map((part) => {
15
+ if (part === "base" || part === "?") return null;
16
+ return registry[part] || part;
17
+ }).filter(Boolean).join(":");
18
+ const result = input.split(/[,\s\n]+/).filter(Boolean).map((cls) => resolvedPrefix ? `${resolvedPrefix}:${cls}` : cls).join(" ");
19
+ console.log(`[STRING] Resolved: "${resolvedPrefix}" | Out: "${result}"`);
20
+ return result;
12
21
  }
13
22
  if (Array.isArray(input)) {
14
- return input.map((i) => process(accumulatedPrefix, i)).filter(Boolean).join(" ");
23
+ console.log(`[ARRAY] Processing ${input.length} elements...`);
24
+ return input.map((i) => process(accumulatedPath, i)).filter(Boolean).join(" ");
15
25
  }
16
26
  if (typeof input === "object") {
27
+ console.log(`[OBJECT] Keys:`, Object.keys(input));
17
28
  return Object.entries(input).map(([key, value]) => {
18
- if (!value) return "";
19
- const isBase = key === "base";
20
- const isPrefix = registry[key] !== void 0;
21
- if (isBase || isPrefix) {
22
- const nextPrefix = accumulatedPrefix ? `${accumulatedPrefix}:${key}` : key;
23
- return process(nextPrefix, value);
29
+ const isTransparent = key === "base" || key === "?";
30
+ const isRegistered = registry[key] !== void 0;
31
+ console.log(
32
+ ` -> Key: "${key}" | Value: ${value} | isPrefix: ${isRegistered} | isTransparent: ${isTransparent}`
33
+ );
34
+ if (!value) {
35
+ console.log(` [SKIP KEY] "${key}" because value is falsy`);
36
+ return "";
37
+ }
38
+ if (isTransparent || isRegistered) {
39
+ const newPath = accumulatedPath ? `${accumulatedPath}:${key}` : key;
40
+ console.log(` [DIVE] Moving to path: "${newPath}"`);
41
+ return process(newPath, value);
24
42
  } else {
25
- return process(accumulatedPrefix, key);
43
+ console.log(
44
+ ` [CLASS] Treating key "${key}" as class under path "${accumulatedPath}"`
45
+ );
46
+ return process(accumulatedPath, key);
26
47
  }
27
48
  }).filter(Boolean).join(" ");
28
49
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAUO,SAAS,YAAuD,OAAA,EAAmB;AACtF,EAAA,MAAM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AAG,iBAAiB,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,GAAK,GAAA;AACvE,UAAA,OAAO,OAAA,CAAQ,YAAY,KAAK,CAAA;AAAA,QACpC,CAAA,MAAO;AAEH,UAAA,OAAO,OAAA,CAAQ,mBAAmB,GAAG,CAAA;AAAA,QACzC;AAAA,MACJ,CAAC,CAAA,CACA,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,OAAO,EAAA;AAAA,EACX,CAAA;AAUA,EAAA,OAAO,IAAI,MAAA,KAAyB;AAChC,IAAA,MAAM,SAAA,GAAY,OAAO,GAAA,CAAI,CAAC,UAAU,OAAA,CAAQ,EAAA,EAAI,KAAK,CAAC,CAAA;AAC1D,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 * Creates a customized Tailwind class engine instance with prefix registry support.\r\n * * @param plugins - Objects mapping custom aliases (e.g., 'ui') to real Tailwind prefixes (e.g., 'prefix').\r\n * @returns A recursive 'cl' function that processes strings, arrays, and objects.\r\n * * @example\r\n * const tw = createCl({ md: 'md', ui: 'prefix' });\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 /**\r\n * Recursively processes input values to apply prefixes and logic.\r\n * * @param accumulatedPrefix - The prefix path built during recursion (e.g., 'md:hover').\r\n * @param input - The value to process (string, array, or object).\r\n * @returns A string of prefixed and filtered Tailwind classes.\r\n */\r\n const process = (accumulatedPrefix: string, input: any): string => {\r\n if (!input) return '';\r\n\r\n // 1. Strings: Resolve real Tailwind prefixes and apply them\r\n if (typeof input === 'string') {\r\n const resolved = accumulatedPrefix\r\n .split(':')\r\n .map((part) => (part === 'base' ? null : registry[part] || null))\r\n .filter(Boolean)\r\n .join(':');\r\n\r\n return input\r\n .split(/[,\\s\\n]+/) // Split by commas, spaces, or newlines\r\n .filter(Boolean)\r\n .map((cls) => (resolved ? `${resolved}:${cls}` : cls))\r\n .join(' ');\r\n }\r\n\r\n // 2. Arrays: Multi-line support and recursive processing\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. Objects: Prefix navigation and Conditional Logic (clsx-style)\r\n if (typeof input === 'object') {\r\n return Object.entries(input)\r\n .map(([key, value]) => {\r\n if (!value) return '';\r\n\r\n const isBase = key === 'base';\r\n const isPrefix = registry[key] !== undefined;\r\n\r\n if (isBase || isPrefix) {\r\n // It's an organization node or a prefix: accumulate and dive deeper\r\n const nextPrefix = accumulatedPrefix ? `${accumulatedPrefix}:${key}` : key;\r\n return process(nextPrefix, value);\r\n } else {\r\n // Standard logic { 'class-name': boolean }: treat the key as the class content\r\n return process(accumulatedPrefix, key);\r\n }\r\n })\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n return '';\r\n };\r\n\r\n /**\r\n * Main utility for generating Tailwind classes.\r\n * Supports strings, nested objects with prefixes, and arrays.\r\n * * @param inputs - A list of arguments following the clsx pattern.\r\n * @returns A processed, deduplicated string of classes via twMerge.\r\n * * @example\r\n * tw('btn-base', { md: 'p-4', hover: { 'opacity-50': isDim } });\r\n */\r\n return (...inputs: ClassValue[]) => {\r\n const processed = inputs.map((input) => process('', input));\r\n return twMerge(clsx(processed));\r\n };\r\n}\r\n"]}
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,eAAA,EAAyB,KAAA,KAAuB;AAC7D,IAAA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AO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,OAAO,EAAA;AAAA,EACX,CAAA;AAEA,EAAA,OAAO,IAAI,MAAA,KAAyB;AAChC,IAAA,MAAM,SAAA,GAAY,OAAO,GAAA,CAAI,CAAC,UAAU,OAAA,CAAQ,EAAA,EAAI,KAAK,CAAC,CAAA;AAC1D,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\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 = (accumulatedPath: string, input: any): string => {\r\n console.log(`[START] Path: \"${accumulatedPath}\" | Input:`, input);\r\n\r\n if (!input) {\r\n console.log(`[SKIP] Input is falsy`);\r\n return '';\r\n }\r\n\r\n // 1. Caso String\r\n if (typeof input === 'string') {\r\n const resolvedPrefix = accumulatedPath\r\n .split(':')\r\n .map((part) => {\r\n if (part === 'base' || part === '?') return null;\r\n return registry[part] || part;\r\n })\r\n .filter(Boolean)\r\n .join(':');\r\n\r\n const result = input\r\n .split(/[,\\s\\n]+/)\r\n .filter(Boolean)\r\n .map((cls) => (resolvedPrefix ? `${resolvedPrefix}:${cls}` : cls))\r\n .join(' ');\r\n\r\n console.log(`[STRING] Resolved: \"${resolvedPrefix}\" | Out: \"${result}\"`);\r\n return result;\r\n }\r\n\r\n // 2. Caso Array\r\n if (Array.isArray(input)) {\r\n console.log(`[ARRAY] Processing ${input.length} elements...`);\r\n return input\r\n .map((i) => process(accumulatedPath, i))\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n // 3. Caso Objeto\r\n if (typeof input === 'object') {\r\n console.log(`[OBJECT] Keys:`, Object.keys(input));\r\n return Object.entries(input)\r\n .map(([key, value]) => {\r\n const isTransparent = key === 'base' || key === '?';\r\n const isRegistered = registry[key] !== undefined;\r\n\r\n console.log(\r\n ` -> Key: \"${key}\" | Value: ${value} | isPrefix: ${isRegistered} | isTransparent: ${isTransparent}`\r\n );\r\n\r\n if (!value) {\r\n console.log(` [SKIP KEY] \"${key}\" because value is falsy`);\r\n return '';\r\n }\r\n\r\n if (isTransparent || isRegistered) {\r\n const newPath = accumulatedPath ? `${accumulatedPath}:${key}` : key;\r\n console.log(` [DIVE] Moving to path: \"${newPath}\"`);\r\n return process(newPath, value);\r\n } else {\r\n console.log(\r\n ` [CLASS] Treating key \"${key}\" as class under path \"${accumulatedPath}\"`\r\n );\r\n return process(accumulatedPath, key);\r\n }\r\n })\r\n .filter(Boolean)\r\n .join(' ');\r\n }\r\n\r\n return '';\r\n };\r\n\r\n return (...inputs: ClassValue[]) => {\r\n const processed = inputs.map((input) => process('', input));\r\n return twMerge(clsx(processed));\r\n };\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clases",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "scripts": {
18
18
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
19
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
19
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
20
+ "postinstall": "node scripts/init.js"
20
21
  }
21
22
  }
package/src/index.ts CHANGED
@@ -1,64 +1,73 @@
1
1
  import { twMerge } from 'tailwind-merge';
2
2
  import clsx, { type ClassValue } from 'clsx';
3
3
 
4
- /**
5
- * Creates a customized Tailwind class engine instance with prefix registry support.
6
- * * @param plugins - Objects mapping custom aliases (e.g., 'ui') to real Tailwind prefixes (e.g., 'prefix').
7
- * @returns A recursive 'cl' function that processes strings, arrays, and objects.
8
- * * @example
9
- * const tw = createCl({ md: 'md', ui: 'prefix' });
10
- */
11
4
  export function createCl<TPlugins extends Record<string, string>[]>(...plugins: TPlugins) {
12
5
  const registry: Record<string, string> = Object.assign({}, ...plugins);
13
6
 
14
- /**
15
- * Recursively processes input values to apply prefixes and logic.
16
- * * @param accumulatedPrefix - The prefix path built during recursion (e.g., 'md:hover').
17
- * @param input - The value to process (string, array, or object).
18
- * @returns A string of prefixed and filtered Tailwind classes.
19
- */
20
- const process = (accumulatedPrefix: string, input: any): string => {
21
- if (!input) return '';
7
+ const process = (accumulatedPath: string, input: any): string => {
8
+ console.log(`[START] Path: "${accumulatedPath}" | Input:`, input);
22
9
 
23
- // 1. Strings: Resolve real Tailwind prefixes and apply them
10
+ if (!input) {
11
+ console.log(`[SKIP] Input is falsy`);
12
+ return '';
13
+ }
14
+
15
+ // 1. Caso String
24
16
  if (typeof input === 'string') {
25
- const resolved = accumulatedPrefix
17
+ const resolvedPrefix = accumulatedPath
26
18
  .split(':')
27
- .map((part) => (part === 'base' ? null : registry[part] || null))
19
+ .map((part) => {
20
+ if (part === 'base' || part === '?') return null;
21
+ return registry[part] || part;
22
+ })
28
23
  .filter(Boolean)
29
24
  .join(':');
30
25
 
31
- return input
32
- .split(/[,\s\n]+/) // Split by commas, spaces, or newlines
26
+ const result = input
27
+ .split(/[,\s\n]+/)
33
28
  .filter(Boolean)
34
- .map((cls) => (resolved ? `${resolved}:${cls}` : cls))
29
+ .map((cls) => (resolvedPrefix ? `${resolvedPrefix}:${cls}` : cls))
35
30
  .join(' ');
31
+
32
+ console.log(`[STRING] Resolved: "${resolvedPrefix}" | Out: "${result}"`);
33
+ return result;
36
34
  }
37
35
 
38
- // 2. Arrays: Multi-line support and recursive processing
36
+ // 2. Caso Array
39
37
  if (Array.isArray(input)) {
38
+ console.log(`[ARRAY] Processing ${input.length} elements...`);
40
39
  return input
41
- .map((i) => process(accumulatedPrefix, i))
40
+ .map((i) => process(accumulatedPath, i))
42
41
  .filter(Boolean)
43
42
  .join(' ');
44
43
  }
45
44
 
46
- // 3. Objects: Prefix navigation and Conditional Logic (clsx-style)
45
+ // 3. Caso Objeto
47
46
  if (typeof input === 'object') {
47
+ console.log(`[OBJECT] Keys:`, Object.keys(input));
48
48
  return Object.entries(input)
49
49
  .map(([key, value]) => {
50
- if (!value) return '';
50
+ const isTransparent = key === 'base' || key === '?';
51
+ const isRegistered = registry[key] !== undefined;
52
+
53
+ console.log(
54
+ ` -> Key: "${key}" | Value: ${value} | isPrefix: ${isRegistered} | isTransparent: ${isTransparent}`
55
+ );
51
56
 
52
- const isBase = key === 'base';
53
- const isPrefix = registry[key] !== undefined;
57
+ if (!value) {
58
+ console.log(` [SKIP KEY] "${key}" because value is falsy`);
59
+ return '';
60
+ }
54
61
 
55
- if (isBase || isPrefix) {
56
- // It's an organization node or a prefix: accumulate and dive deeper
57
- const nextPrefix = accumulatedPrefix ? `${accumulatedPrefix}:${key}` : key;
58
- return process(nextPrefix, value);
62
+ if (isTransparent || isRegistered) {
63
+ const newPath = accumulatedPath ? `${accumulatedPath}:${key}` : key;
64
+ console.log(` [DIVE] Moving to path: "${newPath}"`);
65
+ return process(newPath, value);
59
66
  } else {
60
- // Standard logic { 'class-name': boolean }: treat the key as the class content
61
- return process(accumulatedPrefix, key);
67
+ console.log(
68
+ ` [CLASS] Treating key "${key}" as class under path "${accumulatedPath}"`
69
+ );
70
+ return process(accumulatedPath, key);
62
71
  }
63
72
  })
64
73
  .filter(Boolean)
@@ -68,14 +77,6 @@ export function createCl<TPlugins extends Record<string, string>[]>(...plugins:
68
77
  return '';
69
78
  };
70
79
 
71
- /**
72
- * Main utility for generating Tailwind classes.
73
- * Supports strings, nested objects with prefixes, and arrays.
74
- * * @param inputs - A list of arguments following the clsx pattern.
75
- * @returns A processed, deduplicated string of classes via twMerge.
76
- * * @example
77
- * tw('btn-base', { md: 'p-4', hover: { 'opacity-50': isDim } });
78
- */
79
80
  return (...inputs: ClassValue[]) => {
80
81
  const processed = inputs.map((input) => process('', input));
81
82
  return twMerge(clsx(processed));
@@ -0,0 +1,28 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ // Intentamos encontrar el root del proyecto del usuario
5
+ const projectRoot = process.env.INIT_CWD || path.resolve('../../');
6
+ // Buscamos si existe la carpeta 'src' para ponerlo ahí (mejor para Tailwind/Vite)
7
+ const hasSrc = fs.existsSync(path.join(projectRoot, 'src'));
8
+ const targetDir = hasSrc ? path.join(projectRoot, 'src') : projectRoot;
9
+ const configPath = path.join(targetDir, 'clases.config.ts');
10
+
11
+ const template = `import { createCl } from 'clases';
12
+
13
+ // Instancia base agnóstica
14
+ export const cl = createCl({});
15
+ `;
16
+
17
+ try {
18
+ // Solo lo creamos si no existe para no borrar trabajo del usuario
19
+ if (!fs.existsSync(configPath)) {
20
+ fs.writeFileSync(configPath, template, 'utf8');
21
+ console.log(
22
+ '\x1b[36m%s\x1b[0m',
23
+ ' [clases] Configuración base creada en ' + (hasSrc ? 'src/' : './')
24
+ );
25
+ }
26
+ } catch (err) {
27
+ // Fallo silencioso para no romper la instalación si hay problemas de permisos
28
+ }