@fuf-stack/pixel-utils 0.3.2 → 0.4.1

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,21 +10,19 @@ var _theme = require('@nextui-org/theme');
10
10
 
11
11
  // src/tv.ts
12
12
  var _tailwindvariants = require('tailwind-variants');
13
+ var tv = _tailwindvariants.tv;
13
14
  var variantsToClassNames = (variants, className, baseSlot) => {
14
- const classNameObj = typeof className === "object" && className || {};
15
- return Object.fromEntries(
16
- Object.entries(variants).map(([slot, variantFn]) => [
17
- slot,
18
- baseSlot && slot === baseSlot ? (
19
- // @ts-expect-error could be improved
20
- variantFn({
21
- className: typeof className === "string" ? className : classNameObj[slot]
22
- })
23
- ) : (
24
- // @ts-expect-error could be improved
25
- variantFn({ className: classNameObj[slot] })
26
- )
27
- ])
15
+ const classNames2 = typeof className === "object" && !Array.isArray(className) ? className : {};
16
+ return Object.entries(variants).reduce(
17
+ (acc, [slot, variantFn]) => {
18
+ const slotKey = slot;
19
+ const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames2[slot];
20
+ acc[slotKey] = variantFn({
21
+ className: baseSlot && slot === baseSlot ? slotClassName : classNames2[slot]
22
+ });
23
+ return acc;
24
+ },
25
+ {}
28
26
  );
29
27
  };
30
28
 
@@ -32,5 +30,5 @@ var variantsToClassNames = (variants, className, baseSlot) => {
32
30
 
33
31
 
34
32
 
35
- exports.cn = cn; exports.nextui = _theme.nextui; exports.tv = _tailwindvariants.tv; exports.variantsToClassNames = variantsToClassNames;
33
+ exports.cn = cn; exports.nextui = _theme.nextui; exports.tv = tv; exports.variantsToClassNames = variantsToClassNames;
36
34
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/uniform/uniform/packages/pixel-utils/dist/index.cjs","../src/cn.ts","../src/theme.ts","../src/tv.ts"],"names":[],"mappings":"AAAA;ACGA,gGAAuB;AACvB,+CAAwB;AAiBjB,IAAM,GAAA,EAAK,CAAA,GAAI,OAAA,EAAA,GAAmC;AAGvD,EAAA,OAAO,oCAAA,kCAAQ,GAAc,OAAO,CAAC,CAAA;AACvC,CAAA;ADnBA;AACA;AENA,0CAAuB;AFQvB;AACA;AGRA,qDAAmB;AAYZ,IAAM,qBAAA,EAAuB,CAClC,QAAA,EACA,SAAA,EACA,QAAA,EAAA,GAC4B;AAC5B,EAAA,MAAM,aAAA,EAAgB,OAAO,UAAA,IAAc,SAAA,GAAY,UAAA,GAAc,CAAC,CAAA;AAEtE,EAAA,OAAO,MAAA,CAAO,WAAA;AAAA,IACZ,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,SAAS,CAAA,EAAA,GAAM;AAAA,MAClD,IAAA;AAAA,MACA,SAAA,GAAY,KAAA,IAAS,SAAA,EAAA;AAAA;AAAA,QAEhB,SAAA,CAAU;AAAA,UACT,SAAA,EACE,OAAO,UAAA,IAAc,SAAA,EAAW,UAAA,EAAY,YAAA,CAAa,IAAI;AAAA,QACjE,CAAC;AAAA,MAAA,EAAA,EAAA;AAAA;AAAA,QAEA,SAAA,CAAU,EAAE,SAAA,EAAW,YAAA,CAAa,IAAI,EAAE,CAAC;AAAA,MAAA;AAAA,IAClD,CAAC;AAAA,EACH,CAAA;AACF,CAAA;AHLA;AACE;AACA;AACA;AACA;AACF,wIAAC","file":"/home/runner/work/uniform/uniform/packages/pixel-utils/dist/index.cjs","sourcesContent":[null,"/* eslint-disable import/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function that combines `classnames` and `tailwind-merge`.\n *\n * It takes multiple class values (strings, arrays, or objects), merges them,\n * and ensures Tailwind CSS classes are handled properly by resolving conflicts.\n *\n * @param classes - A list of class names that can be strings, objects, or arrays.\n * @returns A string of combined class names with Tailwind CSS conflict resolution.\n *\n * Example usage:\n * ```\n * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });\n * // Output: 'text-center bg-red-500 p-4'\n * ```\n */\nexport const cn = (...classes: ArgumentArray): string => {\n // First, `classnames` merges the input class names (conditionally if needed).\n // Then, `twMerge` is used to resolve any Tailwind CSS conflicts.\n return twMerge(classNames(...classes));\n};\n","/* eslint-disable import/prefer-default-export */\nexport { nextui } from '@nextui-org/theme';\n","import type { VariantProps } from '@nextui-org/theme';\n\nexport { tv } from 'tailwind-variants';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVProps<Component extends (...args: any) => any> =\n VariantProps<Component>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVClassName<Component extends (...args: any) => any> =\n | Partial<Record<keyof ReturnType<Component>, string>>\n | string;\n\n// converts tailwind-variants slots instance to actual classnames object\nexport const variantsToClassNames = <T extends Record<string, unknown>>(\n variants: T,\n className?: string | Record<string, string>,\n baseSlot?: keyof T,\n): Record<keyof T, string> => {\n const classNameObj = (typeof className === 'object' && className) || {};\n // @ts-expect-error could be improved\n return Object.fromEntries(\n Object.entries(variants).map(([slot, variantFn]) => [\n slot as keyof T,\n baseSlot && slot === baseSlot\n ? // @ts-expect-error could be improved\n (variantFn({\n className:\n typeof className === 'string' ? className : classNameObj[slot],\n }) as string)\n : // @ts-expect-error could be improved\n (variantFn({ className: classNameObj[slot] }) as string),\n ]),\n );\n};\n"]}
1
+ {"version":3,"sources":["/home/runner/work/pixels/pixels/packages/pixel-utils/dist/index.cjs","../src/cn.ts","../src/theme.ts","../src/tv.ts"],"names":["classNames"],"mappings":"AAAA;ACGA,gGAAuB;AACvB,+CAAwB;AAiBjB,IAAM,GAAA,EAAK,CAAA,GAAI,OAAA,EAAA,GAAmC;AAGvD,EAAA,OAAO,oCAAA,kCAAQ,GAAc,OAAO,CAAC,CAAA;AACvC,CAAA;ADnBA;AACA;AENA,0CAAuB;AFQvB;AACA;AGPA,qDAAuC;AAmChC,IAAM,GAAA,EAAK,oBAAA;AA4CX,IAAM,qBAAA,EAAuB,CAClC,QAAA,EACA,SAAA,EACA,QAAA,EAAA,GAC4B;AAC5B,EAAA,MAAMA,YAAAA,EACJ,OAAO,UAAA,IAAc,SAAA,GAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,SAAS,EAAA,EAAI,UAAA,EAAY,CAAC,CAAA;AAE5E,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAA,CAAE,MAAA;AAAA,IAC9B,CAAC,GAAA,EAAK,CAAC,IAAA,EAAM,SAAS,CAAA,EAAA,GAAM;AAC1B,MAAA,MAAM,QAAA,EAAU,IAAA;AAChB,MAAA,MAAM,cAAA,EACJ,OAAO,UAAA,IAAc,SAAA,GAAY,KAAA,CAAM,OAAA,CAAQ,SAAS,EAAA,EACpD,UAAA,EACAA,WAAAA,CAAW,IAAI,CAAA;AAGrB,MAAA,GAAA,CAAI,OAAO,EAAA,EAAI,SAAA,CAAU;AAAA,QACvB,SAAA,EACE,SAAA,GAAY,KAAA,IAAS,SAAA,EAAW,cAAA,EAAgBA,WAAAA,CAAW,IAAI;AAAA,MACnE,CAAC,CAAA;AAED,MAAA,OAAO,GAAA;AAAA,IACT,CAAA;AAAA,IACA,CAAC;AAAA,EACH,CAAA;AACF,CAAA;AHjFA;AACE;AACA;AACA;AACA;AACF,sHAAC","file":"/home/runner/work/pixels/pixels/packages/pixel-utils/dist/index.cjs","sourcesContent":[null,"/* eslint-disable import/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function that combines `classnames` and `tailwind-merge`.\n *\n * It takes multiple class values (strings, arrays, or objects), merges them,\n * and ensures Tailwind CSS classes are handled properly by resolving conflicts.\n *\n * @param classes - A list of class names that can be strings, objects, or arrays.\n * @returns A string of combined class names with Tailwind CSS conflict resolution.\n *\n * Example usage:\n * ```\n * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });\n * // Output: 'text-center bg-red-500 p-4'\n * ```\n */\nexport const cn = (...classes: ArgumentArray): string => {\n // First, `classnames` merges the input class names (conditionally if needed).\n // Then, `twMerge` is used to resolve any Tailwind CSS conflicts.\n return twMerge(classNames(...classes));\n};\n","/* eslint-disable import/prefer-default-export */\nexport { nextui } from '@nextui-org/theme';\n","import type { VariantProps } from '@nextui-org/theme';\nimport type { ClassProp } from 'tailwind-variants';\n\nimport { tv as tailwindVariants } from 'tailwind-variants';\n\n/**\n * Represents a class value which can be either a string or an array of strings\n * Used for handling both single class names and multiple class names\n */\ntype ClassValue = string | string[];\n\n/**\n * Props accepted by tailwind-variants slot functions\n * Combines a dynamic record of string/number values with the ClassProp from tailwind-variants\n */\ntype TVSlotProps = {\n [x: string]: string | number | undefined;\n [x: number]: string | number | undefined;\n} & ClassProp<ClassValue>;\n\n/**\n * Represents a tailwind-variants slot function\n * Takes optional TVSlotProps and returns a string of class names\n */\ntype TVFunction = {\n (slotProps?: TVSlotProps | undefined): string;\n};\n\n/**\n * A record of slot names to their corresponding tailwind-variants functions\n * Used to type the variants parameter in variantsToClassNames\n */\ntype TVRecord = Record<string, TVFunction>;\n\n/**\n * Re-export of tailwind-variants tv function\n * Used to create variant definitions with slots and variants\n */\nexport const tv = tailwindVariants;\n\n/**\n * Extracts variant props from a tailwind-variants component\n * Used for typing component props that use variants\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVProps<Component extends (...args: any) => any> =\n VariantProps<Component>;\n\n/**\n * Extracts className type from a tailwind-variants component\n * Can be either a partial record of slot names to class values, or a single class value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVClassName<Component extends (...args: any) => any> =\n | Partial<Record<keyof ReturnType<Component>, ClassValue>>\n | ClassValue;\n\n/**\n * Converts tailwind-variants slots instance to actual classnames object\n *\n * @param variants - Object containing slot variant functions from tailwind-variants\n * @param className - Optional class names to merge with variant classes. Can be string, array, or record\n * @param baseSlot - Optional slot name to apply global className to\n * @returns Record mapping slot names to their final class name strings\n *\n * @example\n * ```tsx\n * const variants = tv({ slots: { base: 'bg-white', content: 'p-4' } });\n * const classes = variantsToClassNames(variants(), 'shadow-lg', 'base');\n * // Result: { base: 'bg-white shadow-lg', content: 'p-4' }\n * ```\n *\n * @example\n * ```tsx\n * const variants = tv({ slots: { base: '', content: '' } });\n * const classes = variantsToClassNames(variants(), {\n * base: 'bg-white',\n * content: ['p-4', 'text-gray-700']\n * });\n * // Result: { base: 'bg-white', content: 'p-4 text-gray-700' }\n * ```\n */\nexport const variantsToClassNames = <T extends TVRecord>(\n variants: T,\n className?: ClassValue | Record<string, ClassValue>,\n baseSlot?: keyof T,\n): Record<keyof T, string> => {\n const classNames =\n typeof className === 'object' && !Array.isArray(className) ? className : {};\n\n return Object.entries(variants).reduce(\n (acc, [slot, variantFn]) => {\n const slotKey = slot as keyof T;\n const slotClassName =\n typeof className === 'string' || Array.isArray(className)\n ? className\n : classNames[slot];\n\n // @ts-expect-error not sure here\n acc[slotKey] = variantFn({\n className:\n baseSlot && slot === baseSlot ? slotClassName : classNames[slot],\n });\n\n return acc;\n },\n {} as Record<keyof T, string>,\n );\n};\n"]}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ArgumentArray } from 'classnames';
2
2
  import { VariantProps } from '@nextui-org/theme';
3
3
  export { nextui } from '@nextui-org/theme';
4
- export { tv } from 'tailwind-variants';
4
+ import * as tailwind_variants from 'tailwind-variants';
5
+ import { ClassProp } from 'tailwind-variants';
5
6
 
6
7
  /**
7
8
  * A utility function that combines `classnames` and `tailwind-merge`.
@@ -20,8 +21,71 @@ export { tv } from 'tailwind-variants';
20
21
  */
21
22
  declare const cn: (...classes: ArgumentArray) => string;
22
23
 
24
+ /**
25
+ * Represents a class value which can be either a string or an array of strings
26
+ * Used for handling both single class names and multiple class names
27
+ */
28
+ type ClassValue = string | string[];
29
+ /**
30
+ * Props accepted by tailwind-variants slot functions
31
+ * Combines a dynamic record of string/number values with the ClassProp from tailwind-variants
32
+ */
33
+ type TVSlotProps = {
34
+ [x: string]: string | number | undefined;
35
+ [x: number]: string | number | undefined;
36
+ } & ClassProp<ClassValue>;
37
+ /**
38
+ * Represents a tailwind-variants slot function
39
+ * Takes optional TVSlotProps and returns a string of class names
40
+ */
41
+ type TVFunction = {
42
+ (slotProps?: TVSlotProps | undefined): string;
43
+ };
44
+ /**
45
+ * A record of slot names to their corresponding tailwind-variants functions
46
+ * Used to type the variants parameter in variantsToClassNames
47
+ */
48
+ type TVRecord = Record<string, TVFunction>;
49
+ /**
50
+ * Re-export of tailwind-variants tv function
51
+ * Used to create variant definitions with slots and variants
52
+ */
53
+ declare const tv: tailwind_variants.TV;
54
+ /**
55
+ * Extracts variant props from a tailwind-variants component
56
+ * Used for typing component props that use variants
57
+ */
23
58
  type TVProps<Component extends (...args: any) => any> = VariantProps<Component>;
24
- type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof ReturnType<Component>, string>> | string;
25
- declare const variantsToClassNames: <T extends Record<string, unknown>>(variants: T, className?: string | Record<string, string>, baseSlot?: keyof T) => Record<keyof T, string>;
59
+ /**
60
+ * Extracts className type from a tailwind-variants component
61
+ * Can be either a partial record of slot names to class values, or a single class value
62
+ */
63
+ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof ReturnType<Component>, ClassValue>> | ClassValue;
64
+ /**
65
+ * Converts tailwind-variants slots instance to actual classnames object
66
+ *
67
+ * @param variants - Object containing slot variant functions from tailwind-variants
68
+ * @param className - Optional class names to merge with variant classes. Can be string, array, or record
69
+ * @param baseSlot - Optional slot name to apply global className to
70
+ * @returns Record mapping slot names to their final class name strings
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * const variants = tv({ slots: { base: 'bg-white', content: 'p-4' } });
75
+ * const classes = variantsToClassNames(variants(), 'shadow-lg', 'base');
76
+ * // Result: { base: 'bg-white shadow-lg', content: 'p-4' }
77
+ * ```
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * const variants = tv({ slots: { base: '', content: '' } });
82
+ * const classes = variantsToClassNames(variants(), {
83
+ * base: 'bg-white',
84
+ * content: ['p-4', 'text-gray-700']
85
+ * });
86
+ * // Result: { base: 'bg-white', content: 'p-4 text-gray-700' }
87
+ * ```
88
+ */
89
+ declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
26
90
 
27
- export { type TVClassName, type TVProps, cn, variantsToClassNames };
91
+ export { type TVClassName, type TVProps, cn, tv, variantsToClassNames };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ArgumentArray } from 'classnames';
2
2
  import { VariantProps } from '@nextui-org/theme';
3
3
  export { nextui } from '@nextui-org/theme';
4
- export { tv } from 'tailwind-variants';
4
+ import * as tailwind_variants from 'tailwind-variants';
5
+ import { ClassProp } from 'tailwind-variants';
5
6
 
6
7
  /**
7
8
  * A utility function that combines `classnames` and `tailwind-merge`.
@@ -20,8 +21,71 @@ export { tv } from 'tailwind-variants';
20
21
  */
21
22
  declare const cn: (...classes: ArgumentArray) => string;
22
23
 
24
+ /**
25
+ * Represents a class value which can be either a string or an array of strings
26
+ * Used for handling both single class names and multiple class names
27
+ */
28
+ type ClassValue = string | string[];
29
+ /**
30
+ * Props accepted by tailwind-variants slot functions
31
+ * Combines a dynamic record of string/number values with the ClassProp from tailwind-variants
32
+ */
33
+ type TVSlotProps = {
34
+ [x: string]: string | number | undefined;
35
+ [x: number]: string | number | undefined;
36
+ } & ClassProp<ClassValue>;
37
+ /**
38
+ * Represents a tailwind-variants slot function
39
+ * Takes optional TVSlotProps and returns a string of class names
40
+ */
41
+ type TVFunction = {
42
+ (slotProps?: TVSlotProps | undefined): string;
43
+ };
44
+ /**
45
+ * A record of slot names to their corresponding tailwind-variants functions
46
+ * Used to type the variants parameter in variantsToClassNames
47
+ */
48
+ type TVRecord = Record<string, TVFunction>;
49
+ /**
50
+ * Re-export of tailwind-variants tv function
51
+ * Used to create variant definitions with slots and variants
52
+ */
53
+ declare const tv: tailwind_variants.TV;
54
+ /**
55
+ * Extracts variant props from a tailwind-variants component
56
+ * Used for typing component props that use variants
57
+ */
23
58
  type TVProps<Component extends (...args: any) => any> = VariantProps<Component>;
24
- type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof ReturnType<Component>, string>> | string;
25
- declare const variantsToClassNames: <T extends Record<string, unknown>>(variants: T, className?: string | Record<string, string>, baseSlot?: keyof T) => Record<keyof T, string>;
59
+ /**
60
+ * Extracts className type from a tailwind-variants component
61
+ * Can be either a partial record of slot names to class values, or a single class value
62
+ */
63
+ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof ReturnType<Component>, ClassValue>> | ClassValue;
64
+ /**
65
+ * Converts tailwind-variants slots instance to actual classnames object
66
+ *
67
+ * @param variants - Object containing slot variant functions from tailwind-variants
68
+ * @param className - Optional class names to merge with variant classes. Can be string, array, or record
69
+ * @param baseSlot - Optional slot name to apply global className to
70
+ * @returns Record mapping slot names to their final class name strings
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * const variants = tv({ slots: { base: 'bg-white', content: 'p-4' } });
75
+ * const classes = variantsToClassNames(variants(), 'shadow-lg', 'base');
76
+ * // Result: { base: 'bg-white shadow-lg', content: 'p-4' }
77
+ * ```
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * const variants = tv({ slots: { base: '', content: '' } });
82
+ * const classes = variantsToClassNames(variants(), {
83
+ * base: 'bg-white',
84
+ * content: ['p-4', 'text-gray-700']
85
+ * });
86
+ * // Result: { base: 'bg-white', content: 'p-4 text-gray-700' }
87
+ * ```
88
+ */
89
+ declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
26
90
 
27
- export { type TVClassName, type TVProps, cn, variantsToClassNames };
91
+ export { type TVClassName, type TVProps, cn, tv, variantsToClassNames };
package/dist/index.js CHANGED
@@ -9,22 +9,20 @@ var cn = (...classes) => {
9
9
  import { nextui } from "@nextui-org/theme";
10
10
 
11
11
  // src/tv.ts
12
- import { tv } from "tailwind-variants";
12
+ import { tv as tailwindVariants } from "tailwind-variants";
13
+ var tv = tailwindVariants;
13
14
  var variantsToClassNames = (variants, className, baseSlot) => {
14
- const classNameObj = typeof className === "object" && className || {};
15
- return Object.fromEntries(
16
- Object.entries(variants).map(([slot, variantFn]) => [
17
- slot,
18
- baseSlot && slot === baseSlot ? (
19
- // @ts-expect-error could be improved
20
- variantFn({
21
- className: typeof className === "string" ? className : classNameObj[slot]
22
- })
23
- ) : (
24
- // @ts-expect-error could be improved
25
- variantFn({ className: classNameObj[slot] })
26
- )
27
- ])
15
+ const classNames2 = typeof className === "object" && !Array.isArray(className) ? className : {};
16
+ return Object.entries(variants).reduce(
17
+ (acc, [slot, variantFn]) => {
18
+ const slotKey = slot;
19
+ const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames2[slot];
20
+ acc[slotKey] = variantFn({
21
+ className: baseSlot && slot === baseSlot ? slotClassName : classNames2[slot]
22
+ });
23
+ return acc;
24
+ },
25
+ {}
28
26
  );
29
27
  };
30
28
  export {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cn.ts","../src/theme.ts","../src/tv.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function that combines `classnames` and `tailwind-merge`.\n *\n * It takes multiple class values (strings, arrays, or objects), merges them,\n * and ensures Tailwind CSS classes are handled properly by resolving conflicts.\n *\n * @param classes - A list of class names that can be strings, objects, or arrays.\n * @returns A string of combined class names with Tailwind CSS conflict resolution.\n *\n * Example usage:\n * ```\n * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });\n * // Output: 'text-center bg-red-500 p-4'\n * ```\n */\nexport const cn = (...classes: ArgumentArray): string => {\n // First, `classnames` merges the input class names (conditionally if needed).\n // Then, `twMerge` is used to resolve any Tailwind CSS conflicts.\n return twMerge(classNames(...classes));\n};\n","/* eslint-disable import/prefer-default-export */\nexport { nextui } from '@nextui-org/theme';\n","import type { VariantProps } from '@nextui-org/theme';\n\nexport { tv } from 'tailwind-variants';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVProps<Component extends (...args: any) => any> =\n VariantProps<Component>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVClassName<Component extends (...args: any) => any> =\n | Partial<Record<keyof ReturnType<Component>, string>>\n | string;\n\n// converts tailwind-variants slots instance to actual classnames object\nexport const variantsToClassNames = <T extends Record<string, unknown>>(\n variants: T,\n className?: string | Record<string, string>,\n baseSlot?: keyof T,\n): Record<keyof T, string> => {\n const classNameObj = (typeof className === 'object' && className) || {};\n // @ts-expect-error could be improved\n return Object.fromEntries(\n Object.entries(variants).map(([slot, variantFn]) => [\n slot as keyof T,\n baseSlot && slot === baseSlot\n ? // @ts-expect-error could be improved\n (variantFn({\n className:\n typeof className === 'string' ? className : classNameObj[slot],\n }) as string)\n : // @ts-expect-error could be improved\n (variantFn({ className: classNameObj[slot] }) as string),\n ]),\n );\n};\n"],"mappings":";AAGA,OAAO,gBAAgB;AACvB,SAAS,eAAe;AAiBjB,IAAM,KAAK,IAAI,YAAmC;AAGvD,SAAO,QAAQ,WAAW,GAAG,OAAO,CAAC;AACvC;;;ACxBA,SAAS,cAAc;;;ACCvB,SAAS,UAAU;AAYZ,IAAM,uBAAuB,CAClC,UACA,WACA,aAC4B;AAC5B,QAAM,eAAgB,OAAO,cAAc,YAAY,aAAc,CAAC;AAEtE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,SAAS,MAAM;AAAA,MAClD;AAAA,MACA,YAAY,SAAS;AAAA;AAAA,QAEhB,UAAU;AAAA,UACT,WACE,OAAO,cAAc,WAAW,YAAY,aAAa,IAAI;AAAA,QACjE,CAAC;AAAA;AAAA;AAAA,QAEA,UAAU,EAAE,WAAW,aAAa,IAAI,EAAE,CAAC;AAAA;AAAA,IAClD,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/cn.ts","../src/theme.ts","../src/tv.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function that combines `classnames` and `tailwind-merge`.\n *\n * It takes multiple class values (strings, arrays, or objects), merges them,\n * and ensures Tailwind CSS classes are handled properly by resolving conflicts.\n *\n * @param classes - A list of class names that can be strings, objects, or arrays.\n * @returns A string of combined class names with Tailwind CSS conflict resolution.\n *\n * Example usage:\n * ```\n * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });\n * // Output: 'text-center bg-red-500 p-4'\n * ```\n */\nexport const cn = (...classes: ArgumentArray): string => {\n // First, `classnames` merges the input class names (conditionally if needed).\n // Then, `twMerge` is used to resolve any Tailwind CSS conflicts.\n return twMerge(classNames(...classes));\n};\n","/* eslint-disable import/prefer-default-export */\nexport { nextui } from '@nextui-org/theme';\n","import type { VariantProps } from '@nextui-org/theme';\nimport type { ClassProp } from 'tailwind-variants';\n\nimport { tv as tailwindVariants } from 'tailwind-variants';\n\n/**\n * Represents a class value which can be either a string or an array of strings\n * Used for handling both single class names and multiple class names\n */\ntype ClassValue = string | string[];\n\n/**\n * Props accepted by tailwind-variants slot functions\n * Combines a dynamic record of string/number values with the ClassProp from tailwind-variants\n */\ntype TVSlotProps = {\n [x: string]: string | number | undefined;\n [x: number]: string | number | undefined;\n} & ClassProp<ClassValue>;\n\n/**\n * Represents a tailwind-variants slot function\n * Takes optional TVSlotProps and returns a string of class names\n */\ntype TVFunction = {\n (slotProps?: TVSlotProps | undefined): string;\n};\n\n/**\n * A record of slot names to their corresponding tailwind-variants functions\n * Used to type the variants parameter in variantsToClassNames\n */\ntype TVRecord = Record<string, TVFunction>;\n\n/**\n * Re-export of tailwind-variants tv function\n * Used to create variant definitions with slots and variants\n */\nexport const tv = tailwindVariants;\n\n/**\n * Extracts variant props from a tailwind-variants component\n * Used for typing component props that use variants\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVProps<Component extends (...args: any) => any> =\n VariantProps<Component>;\n\n/**\n * Extracts className type from a tailwind-variants component\n * Can be either a partial record of slot names to class values, or a single class value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TVClassName<Component extends (...args: any) => any> =\n | Partial<Record<keyof ReturnType<Component>, ClassValue>>\n | ClassValue;\n\n/**\n * Converts tailwind-variants slots instance to actual classnames object\n *\n * @param variants - Object containing slot variant functions from tailwind-variants\n * @param className - Optional class names to merge with variant classes. Can be string, array, or record\n * @param baseSlot - Optional slot name to apply global className to\n * @returns Record mapping slot names to their final class name strings\n *\n * @example\n * ```tsx\n * const variants = tv({ slots: { base: 'bg-white', content: 'p-4' } });\n * const classes = variantsToClassNames(variants(), 'shadow-lg', 'base');\n * // Result: { base: 'bg-white shadow-lg', content: 'p-4' }\n * ```\n *\n * @example\n * ```tsx\n * const variants = tv({ slots: { base: '', content: '' } });\n * const classes = variantsToClassNames(variants(), {\n * base: 'bg-white',\n * content: ['p-4', 'text-gray-700']\n * });\n * // Result: { base: 'bg-white', content: 'p-4 text-gray-700' }\n * ```\n */\nexport const variantsToClassNames = <T extends TVRecord>(\n variants: T,\n className?: ClassValue | Record<string, ClassValue>,\n baseSlot?: keyof T,\n): Record<keyof T, string> => {\n const classNames =\n typeof className === 'object' && !Array.isArray(className) ? className : {};\n\n return Object.entries(variants).reduce(\n (acc, [slot, variantFn]) => {\n const slotKey = slot as keyof T;\n const slotClassName =\n typeof className === 'string' || Array.isArray(className)\n ? className\n : classNames[slot];\n\n // @ts-expect-error not sure here\n acc[slotKey] = variantFn({\n className:\n baseSlot && slot === baseSlot ? slotClassName : classNames[slot],\n });\n\n return acc;\n },\n {} as Record<keyof T, string>,\n );\n};\n"],"mappings":";AAGA,OAAO,gBAAgB;AACvB,SAAS,eAAe;AAiBjB,IAAM,KAAK,IAAI,YAAmC;AAGvD,SAAO,QAAQ,WAAW,GAAG,OAAO,CAAC;AACvC;;;ACxBA,SAAS,cAAc;;;ACEvB,SAAS,MAAM,wBAAwB;AAmChC,IAAM,KAAK;AA4CX,IAAM,uBAAuB,CAClC,UACA,WACA,aAC4B;AAC5B,QAAMA,cACJ,OAAO,cAAc,YAAY,CAAC,MAAM,QAAQ,SAAS,IAAI,YAAY,CAAC;AAE5E,SAAO,OAAO,QAAQ,QAAQ,EAAE;AAAA,IAC9B,CAAC,KAAK,CAAC,MAAM,SAAS,MAAM;AAC1B,YAAM,UAAU;AAChB,YAAM,gBACJ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IACpD,YACAA,YAAW,IAAI;AAGrB,UAAI,OAAO,IAAI,UAAU;AAAA,QACvB,WACE,YAAY,SAAS,WAAW,gBAAgBA,YAAW,IAAI;AAAA,MACnE,CAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":["classNames"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@fuf-stack/pixel-utils",
3
3
  "description": "fuf pixels helper utils",
4
4
  "author": "Hannes Tiede",
5
- "version": "0.3.2",
5
+ "version": "0.4.1",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "files": [
19
19
  "./dist"
20
20
  ],
21
- "homepage": "https://github.com/fuf-stack/uniform/tree/main/packages/pixel-utils",
21
+ "homepage": "https://github.com/fuf-stack/pixels/tree/main/packages/pixel-utils",
22
22
  "license": "MIT",
23
23
  "publishConfig": {
24
24
  "access": "public"
@@ -30,16 +30,16 @@
30
30
  ],
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/fuf-stack/uniform.git",
33
+ "url": "https://github.com/fuf-stack/pixels.git",
34
34
  "directory": "packages/pixel-utils"
35
35
  },
36
36
  "bugs": {
37
- "url": "https://github.com/fuf-stack/uniform/issues"
37
+ "url": "https://github.com/fuf-stack/pixels/issues"
38
38
  },
39
39
  "dependencies": {
40
40
  "@nextui-org/theme": "2.2.11",
41
41
  "classnames": "2.5.1",
42
- "tailwind-merge": "2.5.4",
42
+ "tailwind-merge": "2.5.5",
43
43
  "tailwind-variants": "0.3.0"
44
44
  },
45
45
  "devDependencies": {