@fuf-stack/pixel-utils 1.1.1 → 1.3.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/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # @fuf-stack/pixel-utils
2
+
3
+ Shared helper utilities for the fuf pixels component library.
4
+
5
+ ## Exports
6
+
7
+ ### `cn(...classes)`
8
+
9
+ Combines [`classnames`](https://github.com/JedWatson/classnames) with a prose-aware [`tailwind-merge`](https://github.com/dcastil/tailwind-merge) instance. Accepts strings, arrays, and conditional objects.
10
+
11
+ ```ts
12
+ import { cn } from '@fuf-stack/pixel-utils';
13
+
14
+ cn('p-4 text-center', { 'bg-red-500': true });
15
+ // => 'p-4 text-center bg-red-500'
16
+
17
+ // prose-* deduplication built in
18
+ cn('prose prose-slate dark:prose-invert', 'prose-blue');
19
+ // => 'prose dark:prose-invert prose-blue'
20
+ ```
21
+
22
+ ### `proseTwMerge(classes)`
23
+
24
+ A standalone `tailwind-merge` instance extended with class groups for `@tailwindcss/typography`:
25
+
26
+ - **`prose-size`** — deduplicates size classes (`prose-sm`, `prose-lg`, `prose-xl`, ...)
27
+ - **`prose-color`** — deduplicates color theme classes (`prose-slate`, `prose-blue`, `prose-[#333]`, ...) while keeping `prose-invert` independent
28
+
29
+ Use it directly when you need prose-aware merging outside of `cn`.
30
+
31
+ ```ts
32
+ import { proseTwMerge } from '@fuf-stack/pixel-utils';
33
+
34
+ proseTwMerge('prose prose-lg prose-slate', 'prose-xl prose-blue');
35
+ // => 'prose prose-xl prose-blue'
36
+ ```
37
+
38
+ ### `proseTwMergeClassGroups`
39
+
40
+ The raw class group config object. Use it to build your own extended `tailwind-merge` instance.
41
+
42
+ ```ts
43
+ import { extendTailwindMerge } from 'tailwind-merge';
44
+
45
+ import { proseTwMergeClassGroups } from '@fuf-stack/pixel-utils';
46
+
47
+ const customTwMerge = extendTailwindMerge({
48
+ extend: {
49
+ classGroups: {
50
+ ...proseTwMergeClassGroups,
51
+ // add more custom groups here
52
+ },
53
+ },
54
+ });
55
+ ```
56
+
57
+ ### `tv`, `variantsToClassNames`, `TVProps`, `TVClassName`, `ClassValue`
58
+
59
+ Re-exports and helpers around [`tailwind-variants`](https://www.tailwind-variants.org/).
60
+
61
+ ```ts
62
+ import { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';
63
+
64
+ const tooltip = tv({
65
+ slots: { base: '', content: 'p-4', trigger: 'cursor-pointer' },
66
+ variants: {
67
+ size: { sm: { content: 'max-w-sm' }, lg: { content: 'max-w-lg' } },
68
+ },
69
+ });
70
+
71
+ const classes = variantsToClassNames(
72
+ tooltip({ size: 'sm' }),
73
+ 'shadow-lg',
74
+ 'base',
75
+ );
76
+ // => { base: 'shadow-lg', content: 'p-4 max-w-sm', trigger: 'cursor-pointer' }
77
+ ```
78
+
79
+ > **Why doesn't `tv` include prose-aware merging?**
80
+ > `tailwind-variants` uses a shared module-level cache for its merge function. Injecting a custom `twMergeConfig` here would corrupt the cache when the same bundle also contains HeroUI components (which set their own `twMergeConfig`). Use `cn(...)` or `proseTwMerge(...)` for prose deduplication instead.
81
+
82
+ ### `slugify(string, options?)`
83
+
84
+ URL/ID-safe slug generation via [`slug`](https://github.com/trott/slug), with sensible defaults (RFC 3986, underscores instead of hyphens).
85
+
86
+ ```ts
87
+ import { slugify } from '@fuf-stack/pixel-utils';
88
+
89
+ slugify('Hello World'); // => 'hello_world'
90
+ slugify('a.b.c', { replaceDots: true }); // => 'a_b_c'
91
+ ```
92
+
93
+ ### `isTestEnvironment()`
94
+
95
+ Returns `true` when running inside Vitest or when `NODE_ENV` is `test`. Safe for both Node.js and browser environments.
96
+
97
+ ### `heroui`
98
+
99
+ Re-export of the `heroui` Tailwind plugin from `@heroui/theme`.
package/dist/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
- //#region rolldown:runtime
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -6,16 +7,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
9
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
19
16
  }
20
17
  return to;
21
18
  };
@@ -23,16 +20,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
20
  value: mod,
24
21
  enumerable: true
25
22
  }) : target, mod));
26
-
27
23
  //#endregion
28
24
  let classnames = require("classnames");
29
- classnames = __toESM(classnames);
25
+ classnames = __toESM(classnames, 1);
30
26
  let tailwind_merge = require("tailwind-merge");
31
27
  let slug = require("slug");
32
- slug = __toESM(slug);
28
+ slug = __toESM(slug, 1);
33
29
  let tailwind_variants = require("tailwind-variants");
34
30
  let _heroui_theme = require("@heroui/theme");
35
-
31
+ //#region src/proseTwMerge.ts
32
+ /**
33
+ * Typography plugin size classes are standalone tokens like `prose-sm`
34
+ * instead of regular utilities, so we register them as a custom merge group.
35
+ */
36
+ const isProseSize = (value) => {
37
+ return value === "base" || tailwind_merge.validators.isTshirtSize(value);
38
+ };
39
+ /**
40
+ * Typography plugin color themes are also standalone `prose-*` classes.
41
+ * Keep `prose-invert` out of this group so it can coexist with a color class.
42
+ */
43
+ const isProseColor = (value) => {
44
+ return value !== "invert" && !isProseSize(value) && (tailwind_merge.validators.isAnyNonArbitrary(value) || tailwind_merge.validators.isArbitraryValue(value));
45
+ };
46
+ const proseTwMergeClassGroups = {
47
+ "prose-size": [{ prose: [isProseSize] }],
48
+ "prose-color": [{ prose: [isProseColor] }]
49
+ };
50
+ /**
51
+ * Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.
52
+ * Used by `cn(...)` internally. Also exported for direct use in components
53
+ * that need prose-aware class merging outside of `cn`.
54
+ */
55
+ const proseTwMerge = (0, tailwind_merge.extendTailwindMerge)({ extend: { classGroups: proseTwMergeClassGroups } });
56
+ //#endregion
36
57
  //#region src/cn.ts
37
58
  /**
38
59
  * A utility function that combines `classnames` and `tailwind-merge`.
@@ -50,9 +71,8 @@ let _heroui_theme = require("@heroui/theme");
50
71
  * ```
51
72
  */
52
73
  const cn = (...classes) => {
53
- return (0, tailwind_merge.twMerge)((0, classnames.default)(...classes));
74
+ return proseTwMerge((0, classnames.default)(...classes));
54
75
  };
55
-
56
76
  //#endregion
57
77
  //#region src/isTestEnvironment.ts
58
78
  /**
@@ -80,7 +100,6 @@ const cn = (...classes) => {
80
100
  const isTestEnvironment = () => {
81
101
  return typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.VITEST === "true");
82
102
  };
83
-
84
103
  //#endregion
85
104
  //#region src/slugify.ts
86
105
  const slugify = (string, options) => {
@@ -97,7 +116,6 @@ const slugify = (string, options) => {
97
116
  ...options ?? {}
98
117
  });
99
118
  };
100
-
101
119
  //#endregion
102
120
  //#region src/tv.ts
103
121
  /**
@@ -131,25 +149,27 @@ const tv = tailwind_variants.tv;
131
149
  * ```
132
150
  */
133
151
  const variantsToClassNames = (variants, className, baseSlot) => {
134
- const classNames$1 = typeof className === "object" && !Array.isArray(className) ? className : {};
152
+ const classNames = typeof className === "object" && !Array.isArray(className) ? className : {};
135
153
  return Object.entries(variants).reduce((acc, [slot, variantFn]) => {
136
154
  const slotKey = slot;
137
- const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames$1[slot];
138
- acc[slotKey] = variantFn({ className: baseSlot && slot === baseSlot ? slotClassName : classNames$1[slot] });
155
+ const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames[slot];
156
+ acc[slotKey] = variantFn({ className: baseSlot && slot === baseSlot ? slotClassName : classNames[slot] });
139
157
  return acc;
140
158
  }, {});
141
159
  };
142
-
143
160
  //#endregion
144
161
  exports.cn = cn;
145
- Object.defineProperty(exports, 'heroui', {
146
- enumerable: true,
147
- get: function () {
148
- return _heroui_theme.heroui;
149
- }
162
+ Object.defineProperty(exports, "heroui", {
163
+ enumerable: true,
164
+ get: function() {
165
+ return _heroui_theme.heroui;
166
+ }
150
167
  });
151
168
  exports.isTestEnvironment = isTestEnvironment;
169
+ exports.proseTwMerge = proseTwMerge;
170
+ exports.proseTwMergeClassGroups = proseTwMergeClassGroups;
152
171
  exports.slugify = slugify;
153
172
  exports.tv = tv;
154
173
  exports.variantsToClassNames = variantsToClassNames;
174
+
155
175
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["tailwindVariants","classNames"],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/slugify.ts","../src/tv.ts"],"sourcesContent":["/* eslint-disable import-x/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) => {\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)) as unknown as string;\n};\n","/* eslint-disable import-x/prefer-default-export */\n\n/**\n * Checks if the code is running in a test environment.\n *\n * This helper safely detects test environments by checking:\n * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`\n * - Browser: Always returns `false` (production code)\n *\n * The check is safe for both Node.js and browser environments by verifying\n * that `process` exists before accessing its properties.\n *\n * @returns `true` if running in a test environment, `false` otherwise\n *\n * @example\n * ```ts\n * if (isTestEnvironment()) {\n * // Skip debouncing in tests for immediate snapshots\n * return value;\n * }\n * // Normal production behavior with debouncing\n * return debouncedValue;\n * ```\n */\nexport const isTestEnvironment = (): boolean => {\n // Safe check: only access process if it exists (Node.js environment)\n // In browsers, process is undefined, so this returns false\n return (\n typeof process !== 'undefined' &&\n (process.env.NODE_ENV === 'test' || process.env.VITEST === 'true')\n );\n};\n\n","/* eslint-disable import-x/prefer-default-export */\n\nimport type { Options as SlugOptions } from 'slug';\n\nimport slug from 'slug';\n\ninterface SlugifyOptions extends SlugOptions {\n /** When true, dots are also replaced (default is false) */\n replaceDots?: boolean;\n}\n\nexport const slugify = (string: string, options?: SlugifyOptions) => {\n const replacement = options?.replacement ?? '_';\n const replaceDots = options?.replaceDots ?? false;\n\n return slug(string, {\n ...slug.defaults.modes.rfc3986,\n charmap: {\n ...slug.defaults.modes.rfc3986.charmap,\n // do not replace dots when replaceDots is false\n ...(!replaceDots ? { '.': '.' } : { '.': replacement }),\n // convert hyphens to underscores (when replacement is not hyphen)\n ...(replacement !== '-' ? { '-': '_' } : {}),\n },\n replacement,\n ...(options ?? {}),\n });\n};\n","import type { VariantProps } from '@heroui/theme';\nimport type { ClassProp, TV } 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 */\nexport type 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 = (slotProps?: TVSlotProps) => string;\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: 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,MAAM,GAAG,YAA2B;AAG/C,4DAA0B,GAAG,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAxC,MAAa,0BAAmC;AAG9C,QACE,OAAO,YAAY,gBAClB,QAAQ,IAAI,aAAa,UAAU,QAAQ,IAAI,WAAW;;;;;AClB/D,MAAa,WAAW,QAAgB,YAA6B;CACnE,MAAM,cAAc,SAAS,eAAe;CAC5C,MAAM,cAAc,SAAS,eAAe;AAE5C,0BAAY,QAAQ;EAClB,GAAG,aAAK,SAAS,MAAM;EACvB,SAAS;GACP,GAAG,aAAK,SAAS,MAAM,QAAQ;GAE/B,GAAI,CAAC,cAAc,EAAE,KAAK,KAAK,GAAG,EAAE,KAAK,aAAa;GAEtD,GAAI,gBAAgB,MAAM,EAAE,KAAK,KAAK,GAAG,EAAE;GAC5C;EACD;EACA,GAAI,WAAW,EAAE;EAClB,CAAC;;;;;;;;;ACUJ,MAAa,KAASA;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CtB,MAAa,wBACX,UACA,WACA,aAC4B;CAC5B,MAAMC,eACJ,OAAO,cAAc,YAAY,CAAC,MAAM,QAAQ,UAAU,GAAG,YAAY,EAAE;AAE7E,QAAO,OAAO,QAAQ,SAAS,CAAC,QAC7B,KAAK,CAAC,MAAM,eAAe;EAC1B,MAAM,UAAU;EAChB,MAAM,gBACJ,OAAO,cAAc,YAAY,MAAM,QAAQ,UAAU,GACrD,YACAA,aAAW;AAGjB,MAAI,WAAW,UAAU,EACvB,WACE,YAAY,SAAS,WAAW,gBAAgBA,aAAW,OAC9D,CAAC;AAEF,SAAO;IAET,EAAE,CACH"}
1
+ {"version":3,"file":"index.cjs","names":["validators","tailwindVariants"],"sources":["../src/proseTwMerge.ts","../src/cn.ts","../src/isTestEnvironment.ts","../src/slugify.ts","../src/tv.ts"],"sourcesContent":["import type { ConfigExtension } from 'tailwind-merge';\n\nimport { extendTailwindMerge, validators } from 'tailwind-merge';\n\ntype ProseClassGroupIds = 'prose-size' | 'prose-color';\n\n/**\n * Typography plugin size classes are standalone tokens like `prose-sm`\n * instead of regular utilities, so we register them as a custom merge group.\n */\nconst isProseSize = (value: string): boolean => {\n return value === 'base' || validators.isTshirtSize(value);\n};\n\n/**\n * Typography plugin color themes are also standalone `prose-*` classes.\n * Keep `prose-invert` out of this group so it can coexist with a color class.\n */\nconst isProseColor = (value: string): boolean => {\n return (\n value !== 'invert' &&\n !isProseSize(value) &&\n (validators.isAnyNonArbitrary(value) || validators.isArbitraryValue(value))\n );\n};\n\nexport const proseTwMergeClassGroups: NonNullable<\n NonNullable<\n ConfigExtension<ProseClassGroupIds, never>['extend']\n >['classGroups']\n> = {\n // Typography plugin sizes are mutually exclusive standalone classes.\n 'prose-size': [{ prose: [isProseSize] }],\n // Typography plugin color themes are also mutually exclusive standalone classes.\n 'prose-color': [{ prose: [isProseColor] }],\n};\n\n/**\n * Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.\n * Used by `cn(...)` internally. Also exported for direct use in components\n * that need prose-aware class merging outside of `cn`.\n */\nexport const proseTwMerge = extendTailwindMerge<ProseClassGroupIds>({\n extend: {\n classGroups: proseTwMergeClassGroups,\n },\n});\n","/* eslint-disable import-x/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\n\nimport { proseTwMerge } from './proseTwMerge';\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) => {\n // First, `classnames` merges the input class names (conditionally if needed).\n // Then, the shared prose-aware `tailwind-merge` instance resolves conflicts.\n return proseTwMerge(classNames(...classes)) as unknown as string;\n};\n","/* eslint-disable import-x/prefer-default-export */\n\n/**\n * Checks if the code is running in a test environment.\n *\n * This helper safely detects test environments by checking:\n * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`\n * - Browser: Always returns `false` (production code)\n *\n * The check is safe for both Node.js and browser environments by verifying\n * that `process` exists before accessing its properties.\n *\n * @returns `true` if running in a test environment, `false` otherwise\n *\n * @example\n * ```ts\n * if (isTestEnvironment()) {\n * // Skip debouncing in tests for immediate snapshots\n * return value;\n * }\n * // Normal production behavior with debouncing\n * return debouncedValue;\n * ```\n */\nexport const isTestEnvironment = (): boolean => {\n // Safe check: only access process if it exists (Node.js environment)\n // In browsers, process is undefined, so this returns false\n return (\n typeof process !== 'undefined' &&\n (process.env.NODE_ENV === 'test' || process.env.VITEST === 'true')\n );\n};\n\n","/* eslint-disable import-x/prefer-default-export */\n\nimport type { Options as SlugOptions } from 'slug';\n\nimport slug from 'slug';\n\ninterface SlugifyOptions extends SlugOptions {\n /** When true, dots are also replaced (default is false) */\n replaceDots?: boolean;\n}\n\nexport const slugify = (string: string, options?: SlugifyOptions) => {\n const replacement = options?.replacement ?? '_';\n const replaceDots = options?.replaceDots ?? false;\n\n return slug(string, {\n ...slug.defaults.modes.rfc3986,\n charmap: {\n ...slug.defaults.modes.rfc3986.charmap,\n // do not replace dots when replaceDots is false\n ...(!replaceDots ? { '.': '.' } : { '.': replacement }),\n // convert hyphens to underscores (when replacement is not hyphen)\n ...(replacement !== '-' ? { '-': '_' } : {}),\n },\n replacement,\n ...(options ?? {}),\n });\n};\n","import type { VariantProps } from '@heroui/theme';\nimport type { ClassProp, TV } 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 */\nexport type 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 = (slotProps?: TVSlotProps) => string;\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: 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,eAAe,UAA2B;CAC9C,OAAO,UAAU,UAAUA,eAAAA,WAAW,aAAa,KAAK;AAC1D;;;;;AAMA,MAAM,gBAAgB,UAA2B;CAC/C,OACE,UAAU,YACV,CAAC,YAAY,KAAK,MACjBA,eAAAA,WAAW,kBAAkB,KAAK,KAAKA,eAAAA,WAAW,iBAAiB,KAAK;AAE7E;AAEA,MAAa,0BAIT;CAEF,cAAc,CAAC,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;CAEvC,eAAe,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;AAC3C;;;;;;AAOA,MAAa,gBAAA,GAAA,eAAA,qBAAuD,EAClE,QAA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"tailwind-merge";
2
3
  import { Options } from "slug";
3
4
  import { VariantProps, heroui } from "@heroui/theme";
4
5
  import { ClassProp, TV } from "tailwind-variants";
5
6
 
6
7
  //#region src/cn.d.ts
7
-
8
8
  /**
9
9
  * A utility function that combines `classnames` and `tailwind-merge`.
10
10
  *
@@ -47,6 +47,16 @@ declare const cn: (...classes: ArgumentArray) => string;
47
47
  */
48
48
  declare const isTestEnvironment: () => boolean;
49
49
  //#endregion
50
+ //#region src/proseTwMerge.d.ts
51
+ type ProseClassGroupIds = 'prose-size' | 'prose-color';
52
+ declare const proseTwMergeClassGroups: NonNullable<NonNullable<ConfigExtension<ProseClassGroupIds, never>['extend']>['classGroups']>;
53
+ /**
54
+ * Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.
55
+ * Used by `cn(...)` internally. Also exported for direct use in components
56
+ * that need prose-aware class merging outside of `cn`.
57
+ */
58
+ declare const proseTwMerge: (...classLists: import("tailwind-merge").ClassNameValue[]) => string;
59
+ //#endregion
50
60
  //#region src/slugify.d.ts
51
61
  interface SlugifyOptions extends Options {
52
62
  /** When true, dots are also replaced (default is false) */
@@ -120,5 +130,5 @@ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof
120
130
  */
121
131
  declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
122
132
  //#endregion
123
- export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
133
+ export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, proseTwMerge, proseTwMergeClassGroups, slugify, tv, variantsToClassNames };
124
134
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/slugify.ts","../src/tv.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;AAqBA;;;;ACGA;;;;ACtBmD;AASnD;cF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,cAsBQ,uBAAA,EAAyB,WAAA,CACpC,WAAA,CACE,eAAA,CAAgB,kBAAA;;;;;AFNpB;cEoBa,YAAA,MAAY,UAAA,2BAAA,cAAA;;;UCpCf,cAAA,SAAuB,OAAW;;EAE1C,WAAW;AAAA;AAAA,cAGA,OAAA,GAAW,MAAA,UAAgB,OAAA,GAAU,cAAc;;;;;;;KCFpD,UAAA;AJaZ;;;;AAAA,KIPK,WAAA;EAAA,CACF,CAAA;EAAA,CACA,CAAA;AAAA,IACC,SAAS,CAAC,UAAA;AHMd;;;;AAAA,KGAK,UAAA,IAAc,SAAuB,GAAX,WAAW;;;;AFxBY;KE8BjD,QAAA,GAAW,MAAM,SAAS,UAAA;;;AF1BR;AAsBvB;cEUa,EAAA,EAAI,EAAqB;;;;;KAO1B,OAAA,uBAA8B,IAAA,iBACxC,YAAY,CAAC,SAAA;;;;;KAOH,WAAA,uBAAkC,IAAA,iBAC1C,OAAA,CAAQ,MAAA,OAAa,UAAA,CAAW,SAAA,GAAY,UAAA,KAC5C,UAAA;;;AFzBkC;AActC;;;;AAAyB;;;;ACxC0B;;;;AAMtC;AAGb;;;;;;;;AAAgE;cCqEnD,oBAAA,aAAkC,QAAA,EAC7C,QAAA,EAAU,CAAA,EACV,SAAA,GAAY,UAAA,GAAa,MAAA,SAAe,UAAA,GACxC,QAAA,SAAiB,CAAA,KAChB,MAAA,OAAa,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { ArgumentArray } from "classnames";
2
+ import { ConfigExtension } from "tailwind-merge";
2
3
  import { Options } from "slug";
3
4
  import { VariantProps, heroui } from "@heroui/theme";
4
5
  import { ClassProp, TV } from "tailwind-variants";
5
6
 
6
7
  //#region src/cn.d.ts
7
-
8
8
  /**
9
9
  * A utility function that combines `classnames` and `tailwind-merge`.
10
10
  *
@@ -47,6 +47,16 @@ declare const cn: (...classes: ArgumentArray) => string;
47
47
  */
48
48
  declare const isTestEnvironment: () => boolean;
49
49
  //#endregion
50
+ //#region src/proseTwMerge.d.ts
51
+ type ProseClassGroupIds = 'prose-size' | 'prose-color';
52
+ declare const proseTwMergeClassGroups: NonNullable<NonNullable<ConfigExtension<ProseClassGroupIds, never>['extend']>['classGroups']>;
53
+ /**
54
+ * Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.
55
+ * Used by `cn(...)` internally. Also exported for direct use in components
56
+ * that need prose-aware class merging outside of `cn`.
57
+ */
58
+ declare const proseTwMerge: (...classLists: import("tailwind-merge").ClassNameValue[]) => string;
59
+ //#endregion
50
60
  //#region src/slugify.d.ts
51
61
  interface SlugifyOptions extends Options {
52
62
  /** When true, dots are also replaced (default is false) */
@@ -120,5 +130,5 @@ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof
120
130
  */
121
131
  declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
122
132
  //#endregion
123
- export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
133
+ export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, proseTwMerge, proseTwMergeClassGroups, slugify, tv, variantsToClassNames };
124
134
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/slugify.ts","../src/tv.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;AAqBA;;;;ACGA;;;;ACtBmD;AASnD;cFUa,iBAAkB;;;;;;;;;AAA/B;;;;ACGA;;;;ACtBmD;AASnD;;;;ACFA;AAA2C;AAS9B;AAYR,cFNQ,iBEMG,EAAA,GAAA,GAAM,OAAA;;;UDxBZ,cAAA,SAAuB;;;;cAKpB,oCAAqC;;;;;;;AFUrC,KGZD,UAAA,GHYmB,MAAA,GAAa,MAAA,EAAA;;;;ACG5C;KETK,WAAA;;;ADb8C,CAAA,GCgB/C,SDZM,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CACF,CAAA;EAAA,CACA,CAAA;AAAA,IACC,SAAS,CAAC,UAAA;AHMd;;;;AAAA,KGAK,UAAA,IAAc,SAAuB,GAAX,WAAW;;;;AFxBY;KE8BjD,QAAA,GAAW,MAAM,SAAS,UAAA;;;AF1BR;AAsBvB;cEUa,EAAA,EAAI,EAAqB;;;;;KAO1B,OAAA,uBAA8B,IAAA,iBACxC,YAAY,CAAC,SAAA;;;;;KAOH,WAAA,uBAAkC,IAAA,iBAC1C,OAAA,CAAQ,MAAA,OAAa,UAAA,CAAW,SAAA,GAAY,UAAA,KAC5C,UAAA;;;AFzBkC;AActC;;;;AAAyB;;;;ACxC0B;;;;AAMtC;AAGb;;;;;;;;AAAgE;cCqEnD,oBAAA,aAAkC,QAAA,EAC7C,QAAA,EAAU,CAAA,EACV,SAAA,GAAY,UAAA,GAAa,MAAA,SAAe,UAAA,GACxC,QAAA,SAAiB,CAAA,KAChB,MAAA,OAAa,CAAA"}
package/dist/index.js CHANGED
@@ -1,9 +1,34 @@
1
1
  import classNames from "classnames";
2
- import { twMerge } from "tailwind-merge";
2
+ import { extendTailwindMerge, validators } from "tailwind-merge";
3
3
  import slug from "slug";
4
4
  import { heroui } from "@heroui/theme";
5
5
  import { tv as tv$1 } from "tailwind-variants";
6
-
6
+ //#region src/proseTwMerge.ts
7
+ /**
8
+ * Typography plugin size classes are standalone tokens like `prose-sm`
9
+ * instead of regular utilities, so we register them as a custom merge group.
10
+ */
11
+ const isProseSize = (value) => {
12
+ return value === "base" || validators.isTshirtSize(value);
13
+ };
14
+ /**
15
+ * Typography plugin color themes are also standalone `prose-*` classes.
16
+ * Keep `prose-invert` out of this group so it can coexist with a color class.
17
+ */
18
+ const isProseColor = (value) => {
19
+ return value !== "invert" && !isProseSize(value) && (validators.isAnyNonArbitrary(value) || validators.isArbitraryValue(value));
20
+ };
21
+ const proseTwMergeClassGroups = {
22
+ "prose-size": [{ prose: [isProseSize] }],
23
+ "prose-color": [{ prose: [isProseColor] }]
24
+ };
25
+ /**
26
+ * Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.
27
+ * Used by `cn(...)` internally. Also exported for direct use in components
28
+ * that need prose-aware class merging outside of `cn`.
29
+ */
30
+ const proseTwMerge = extendTailwindMerge({ extend: { classGroups: proseTwMergeClassGroups } });
31
+ //#endregion
7
32
  //#region src/cn.ts
8
33
  /**
9
34
  * A utility function that combines `classnames` and `tailwind-merge`.
@@ -21,9 +46,8 @@ import { tv as tv$1 } from "tailwind-variants";
21
46
  * ```
22
47
  */
23
48
  const cn = (...classes) => {
24
- return twMerge(classNames(...classes));
49
+ return proseTwMerge(classNames(...classes));
25
50
  };
26
-
27
51
  //#endregion
28
52
  //#region src/isTestEnvironment.ts
29
53
  /**
@@ -51,7 +75,6 @@ const cn = (...classes) => {
51
75
  const isTestEnvironment = () => {
52
76
  return typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.VITEST === "true");
53
77
  };
54
-
55
78
  //#endregion
56
79
  //#region src/slugify.ts
57
80
  const slugify = (string, options) => {
@@ -68,7 +91,6 @@ const slugify = (string, options) => {
68
91
  ...options ?? {}
69
92
  });
70
93
  };
71
-
72
94
  //#endregion
73
95
  //#region src/tv.ts
74
96
  /**
@@ -102,15 +124,15 @@ const tv = tv$1;
102
124
  * ```
103
125
  */
104
126
  const variantsToClassNames = (variants, className, baseSlot) => {
105
- const classNames$1 = typeof className === "object" && !Array.isArray(className) ? className : {};
127
+ const classNames = typeof className === "object" && !Array.isArray(className) ? className : {};
106
128
  return Object.entries(variants).reduce((acc, [slot, variantFn]) => {
107
129
  const slotKey = slot;
108
- const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames$1[slot];
109
- acc[slotKey] = variantFn({ className: baseSlot && slot === baseSlot ? slotClassName : classNames$1[slot] });
130
+ const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames[slot];
131
+ acc[slotKey] = variantFn({ className: baseSlot && slot === baseSlot ? slotClassName : classNames[slot] });
110
132
  return acc;
111
133
  }, {});
112
134
  };
113
-
114
135
  //#endregion
115
- export { cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
136
+ export { cn, heroui, isTestEnvironment, proseTwMerge, proseTwMergeClassGroups, slugify, tv, variantsToClassNames };
137
+
116
138
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["tailwindVariants","classNames"],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/slugify.ts","../src/tv.ts"],"sourcesContent":["/* eslint-disable import-x/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) => {\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)) as unknown as string;\n};\n","/* eslint-disable import-x/prefer-default-export */\n\n/**\n * Checks if the code is running in a test environment.\n *\n * This helper safely detects test environments by checking:\n * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`\n * - Browser: Always returns `false` (production code)\n *\n * The check is safe for both Node.js and browser environments by verifying\n * that `process` exists before accessing its properties.\n *\n * @returns `true` if running in a test environment, `false` otherwise\n *\n * @example\n * ```ts\n * if (isTestEnvironment()) {\n * // Skip debouncing in tests for immediate snapshots\n * return value;\n * }\n * // Normal production behavior with debouncing\n * return debouncedValue;\n * ```\n */\nexport const isTestEnvironment = (): boolean => {\n // Safe check: only access process if it exists (Node.js environment)\n // In browsers, process is undefined, so this returns false\n return (\n typeof process !== 'undefined' &&\n (process.env.NODE_ENV === 'test' || process.env.VITEST === 'true')\n );\n};\n\n","/* eslint-disable import-x/prefer-default-export */\n\nimport type { Options as SlugOptions } from 'slug';\n\nimport slug from 'slug';\n\ninterface SlugifyOptions extends SlugOptions {\n /** When true, dots are also replaced (default is false) */\n replaceDots?: boolean;\n}\n\nexport const slugify = (string: string, options?: SlugifyOptions) => {\n const replacement = options?.replacement ?? '_';\n const replaceDots = options?.replaceDots ?? false;\n\n return slug(string, {\n ...slug.defaults.modes.rfc3986,\n charmap: {\n ...slug.defaults.modes.rfc3986.charmap,\n // do not replace dots when replaceDots is false\n ...(!replaceDots ? { '.': '.' } : { '.': replacement }),\n // convert hyphens to underscores (when replacement is not hyphen)\n ...(replacement !== '-' ? { '-': '_' } : {}),\n },\n replacement,\n ...(options ?? {}),\n });\n};\n","import type { VariantProps } from '@heroui/theme';\nimport type { ClassProp, TV } 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 */\nexport type 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 = (slotProps?: TVSlotProps) => string;\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: 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":";;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,MAAM,GAAG,YAA2B;AAG/C,QAAO,QAAQ,WAAW,GAAG,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAxC,MAAa,0BAAmC;AAG9C,QACE,OAAO,YAAY,gBAClB,QAAQ,IAAI,aAAa,UAAU,QAAQ,IAAI,WAAW;;;;;AClB/D,MAAa,WAAW,QAAgB,YAA6B;CACnE,MAAM,cAAc,SAAS,eAAe;CAC5C,MAAM,cAAc,SAAS,eAAe;AAE5C,QAAO,KAAK,QAAQ;EAClB,GAAG,KAAK,SAAS,MAAM;EACvB,SAAS;GACP,GAAG,KAAK,SAAS,MAAM,QAAQ;GAE/B,GAAI,CAAC,cAAc,EAAE,KAAK,KAAK,GAAG,EAAE,KAAK,aAAa;GAEtD,GAAI,gBAAgB,MAAM,EAAE,KAAK,KAAK,GAAG,EAAE;GAC5C;EACD;EACA,GAAI,WAAW,EAAE;EAClB,CAAC;;;;;;;;;ACUJ,MAAa,KAASA;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CtB,MAAa,wBACX,UACA,WACA,aAC4B;CAC5B,MAAMC,eACJ,OAAO,cAAc,YAAY,CAAC,MAAM,QAAQ,UAAU,GAAG,YAAY,EAAE;AAE7E,QAAO,OAAO,QAAQ,SAAS,CAAC,QAC7B,KAAK,CAAC,MAAM,eAAe;EAC1B,MAAM,UAAU;EAChB,MAAM,gBACJ,OAAO,cAAc,YAAY,MAAM,QAAQ,UAAU,GACrD,YACAA,aAAW;AAGjB,MAAI,WAAW,UAAU,EACvB,WACE,YAAY,SAAS,WAAW,gBAAgBA,aAAW,OAC9D,CAAC;AAEF,SAAO;IAET,EAAE,CACH"}
1
+ {"version":3,"file":"index.js","names":["tailwindVariants"],"sources":["../src/proseTwMerge.ts","../src/cn.ts","../src/isTestEnvironment.ts","../src/slugify.ts","../src/tv.ts"],"sourcesContent":["import type { ConfigExtension } from 'tailwind-merge';\n\nimport { extendTailwindMerge, validators } from 'tailwind-merge';\n\ntype ProseClassGroupIds = 'prose-size' | 'prose-color';\n\n/**\n * Typography plugin size classes are standalone tokens like `prose-sm`\n * instead of regular utilities, so we register them as a custom merge group.\n */\nconst isProseSize = (value: string): boolean => {\n return value === 'base' || validators.isTshirtSize(value);\n};\n\n/**\n * Typography plugin color themes are also standalone `prose-*` classes.\n * Keep `prose-invert` out of this group so it can coexist with a color class.\n */\nconst isProseColor = (value: string): boolean => {\n return (\n value !== 'invert' &&\n !isProseSize(value) &&\n (validators.isAnyNonArbitrary(value) || validators.isArbitraryValue(value))\n );\n};\n\nexport const proseTwMergeClassGroups: NonNullable<\n NonNullable<\n ConfigExtension<ProseClassGroupIds, never>['extend']\n >['classGroups']\n> = {\n // Typography plugin sizes are mutually exclusive standalone classes.\n 'prose-size': [{ prose: [isProseSize] }],\n // Typography plugin color themes are also mutually exclusive standalone classes.\n 'prose-color': [{ prose: [isProseColor] }],\n};\n\n/**\n * Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.\n * Used by `cn(...)` internally. Also exported for direct use in components\n * that need prose-aware class merging outside of `cn`.\n */\nexport const proseTwMerge = extendTailwindMerge<ProseClassGroupIds>({\n extend: {\n classGroups: proseTwMergeClassGroups,\n },\n});\n","/* eslint-disable import-x/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\n\nimport { proseTwMerge } from './proseTwMerge';\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) => {\n // First, `classnames` merges the input class names (conditionally if needed).\n // Then, the shared prose-aware `tailwind-merge` instance resolves conflicts.\n return proseTwMerge(classNames(...classes)) as unknown as string;\n};\n","/* eslint-disable import-x/prefer-default-export */\n\n/**\n * Checks if the code is running in a test environment.\n *\n * This helper safely detects test environments by checking:\n * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`\n * - Browser: Always returns `false` (production code)\n *\n * The check is safe for both Node.js and browser environments by verifying\n * that `process` exists before accessing its properties.\n *\n * @returns `true` if running in a test environment, `false` otherwise\n *\n * @example\n * ```ts\n * if (isTestEnvironment()) {\n * // Skip debouncing in tests for immediate snapshots\n * return value;\n * }\n * // Normal production behavior with debouncing\n * return debouncedValue;\n * ```\n */\nexport const isTestEnvironment = (): boolean => {\n // Safe check: only access process if it exists (Node.js environment)\n // In browsers, process is undefined, so this returns false\n return (\n typeof process !== 'undefined' &&\n (process.env.NODE_ENV === 'test' || process.env.VITEST === 'true')\n );\n};\n\n","/* eslint-disable import-x/prefer-default-export */\n\nimport type { Options as SlugOptions } from 'slug';\n\nimport slug from 'slug';\n\ninterface SlugifyOptions extends SlugOptions {\n /** When true, dots are also replaced (default is false) */\n replaceDots?: boolean;\n}\n\nexport const slugify = (string: string, options?: SlugifyOptions) => {\n const replacement = options?.replacement ?? '_';\n const replaceDots = options?.replaceDots ?? false;\n\n return slug(string, {\n ...slug.defaults.modes.rfc3986,\n charmap: {\n ...slug.defaults.modes.rfc3986.charmap,\n // do not replace dots when replaceDots is false\n ...(!replaceDots ? { '.': '.' } : { '.': replacement }),\n // convert hyphens to underscores (when replacement is not hyphen)\n ...(replacement !== '-' ? { '-': '_' } : {}),\n },\n replacement,\n ...(options ?? {}),\n });\n};\n","import type { VariantProps } from '@heroui/theme';\nimport type { ClassProp, TV } 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 */\nexport type 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 = (slotProps?: TVSlotProps) => string;\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: 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":";;;;;;;;;;AAUA,MAAM,eAAe,UAA2B;CAC9C,OAAO,UAAU,UAAU,WAAW,aAAa,KAAK;AAC1D;;;;;AAMA,MAAM,gBAAgB,UAA2B;CAC/C,OACE,UAAU,YACV,CAAC,YAAY,KAAK,MACjB,WAAW,kBAAkB,KAAK,KAAK,WAAW,iBAAiB,KAAK;AAE7E;AAEA,MAAa,0BAIT;CAEF,cAAc,CAAC,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;CAEvC,eAAe,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;AAC3C;;;;;;AAOA,MAAa,eAAe,oBAAwC,EAClE,QAAQ,EACN,aAAa,wBACf,EACF,CAAC;;;;;;;;;;;;;;;;;;ACxBD,MAAa,MAAM,GAAG,YAA2B;CAG/C,OAAO,aAAa,WAAW,GAAG,OAAO,CAAC;AAC5C;;;;;;;;;;;;;;;;;;;;;;;;;ACFA,MAAa,0BAAmC;CAG9C,OACE,OAAO,YAAY,gBAClB,QAAQ,IAAI,aAAa,UAAU,QAAQ,IAAI,WAAW;AAE/D;;;ACpBA,MAAa,WAAW,QAAgB,YAA6B;CACnE,MAAM,cAAc,SAAS,eAAe;CAC5C,MAAM,cAAc,SAAS,eAAe;CAE5C,OAAO,KAAK,QAAQ;EAClB,GAAG,KAAK,SAAS,MAAM;EACvB,SAAS;GACP,GAAG,KAAK,SAAS,MAAM,QAAQ;GAE/B,GAAI,CAAC,cAAc,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,YAAY;GAErD,GAAI,gBAAgB,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC;EAC5C;EACA;EACA,GAAI,WAAW,CAAC;CAClB,CAAC;AACH;;;;;;;ACSA,MAAa,KAASA;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CtB,MAAa,wBACX,UACA,WACA,aAC4B;CAC5B,MAAM,aACJ,OAAO,cAAc,YAAY,CAAC,MAAM,QAAQ,SAAS,IAAI,YAAY,CAAC;CAE5E,OAAO,OAAO,QAAQ,QAAQ,EAAE,QAC7B,KAAK,CAAC,MAAM,eAAe;EAC1B,MAAM,UAAU;EAChB,MAAM,gBACJ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IACpD,YACA,WAAW;EAGjB,IAAI,WAAW,UAAU,EACvB,WACE,YAAY,SAAS,WAAW,gBAAgB,WAAW,MAC/D,CAAC;EAED,OAAO;CACT,GACA,CAAC,CACH;AACF"}
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": "Fröhlich ∧ Frei",
5
- "version": "1.1.1",
5
+ "version": "1.3.0",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
@@ -10,8 +10,8 @@
10
10
  "sideEffects": false,
11
11
  "exports": {
12
12
  ".": {
13
- "require": "./dist/index.cjs",
14
- "import": "./dist/index.js"
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
15
  },
16
16
  "./package.json": "./package.json"
17
17
  },
@@ -40,17 +40,15 @@
40
40
  "build": "tsdown",
41
41
  "prepack": "pnpm build"
42
42
  },
43
- "peerDependencies": {
44
- "tailwind-merge": "*",
45
- "tailwind-variants": "*"
46
- },
47
43
  "dependencies": {
48
- "@heroui/theme": "2.4.20",
44
+ "@heroui/theme": "2.4.26",
49
45
  "classnames": "2.5.1",
50
- "slug": "9.1.0"
46
+ "slug": "9.1.0",
47
+ "tailwind-merge": "3.6.0",
48
+ "tailwind-variants": "3.2.2"
51
49
  },
52
50
  "devDependencies": {
53
51
  "@types/slug": "5.0.9"
54
52
  },
55
- "gitHead": "e9e39971865a3d4fe137e26b7205ae48ea9c059b"
53
+ "gitHead": "cc422600dec1cf097eddb3700a7704c7289e4670"
56
54
  }