@fuf-stack/pixel-utils 1.1.1 → 1.2.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 +99 -0
- package/dist/index.cjs +46 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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,7 +20,6 @@ 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
25
|
classnames = __toESM(classnames);
|
|
@@ -32,7 +28,32 @@ let slug = require("slug");
|
|
|
32
28
|
slug = __toESM(slug);
|
|
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 (
|
|
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
|
|
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
|
|
138
|
-
acc[slotKey] = variantFn({ className: baseSlot && slot === baseSlot ? slotClassName : classNames
|
|
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,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
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;AAC9C,QAAO,UAAU,UAAUA,eAAAA,WAAW,aAAa,MAAM;;;;;;AAO3D,MAAM,gBAAgB,UAA2B;AAC/C,QACE,UAAU,YACV,CAAC,YAAY,MAAM,KAClBA,eAAAA,WAAW,kBAAkB,MAAM,IAAIA,eAAAA,WAAW,iBAAiB,MAAM;;AAI9E,MAAa,0BAIT;CAEF,cAAc,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;CAExC,eAAe,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC;CAC3C;;;;;;AAOD,MAAa,gBAAA,GAAA,eAAA,qBAAuD,EAClE,QAAQ,EACN,aAAa,yBACd,EACF,CAAC;;;;;;;;;;;;;;;;;;ACxBF,MAAa,MAAM,GAAG,YAA2B;AAG/C,QAAO,cAAA,GAAA,WAAA,SAAwB,GAAG,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;ACD7C,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,SAAA,GAAA,KAAA,SAAY,QAAQ;EAClB,GAAG,KAAA,QAAK,SAAS,MAAM;EACvB,SAAS;GACP,GAAG,KAAA,QAAK,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,KAASC,kBAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CtB,MAAa,wBACX,UACA,WACA,aAC4B;CAC5B,MAAM,aACJ,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,YACA,WAAW;AAGjB,MAAI,WAAW,UAAU,EACvB,WACE,YAAY,SAAS,WAAW,gBAAgB,WAAW,OAC9D,CAAC;AAEF,SAAO;IAET,EAAE,CACH"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ArgumentArray } from "classnames";
|
|
2
|
+
import * as _$tailwind_merge0 from "tailwind-merge";
|
|
3
|
+
import { ConfigExtension } from "tailwind-merge";
|
|
2
4
|
import { Options } from "slug";
|
|
3
5
|
import { VariantProps, heroui } from "@heroui/theme";
|
|
4
6
|
import { ClassProp, TV } from "tailwind-variants";
|
|
5
7
|
|
|
6
8
|
//#region src/cn.d.ts
|
|
7
|
-
|
|
8
9
|
/**
|
|
9
10
|
* A utility function that combines `classnames` and `tailwind-merge`.
|
|
10
11
|
*
|
|
@@ -47,6 +48,16 @@ declare const cn: (...classes: ArgumentArray) => string;
|
|
|
47
48
|
*/
|
|
48
49
|
declare const isTestEnvironment: () => boolean;
|
|
49
50
|
//#endregion
|
|
51
|
+
//#region src/proseTwMerge.d.ts
|
|
52
|
+
type ProseClassGroupIds = 'prose-size' | 'prose-color';
|
|
53
|
+
declare const proseTwMergeClassGroups: NonNullable<NonNullable<ConfigExtension<ProseClassGroupIds, never>['extend']>['classGroups']>;
|
|
54
|
+
/**
|
|
55
|
+
* Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.
|
|
56
|
+
* Used by `cn(...)` internally. Also exported for direct use in components
|
|
57
|
+
* that need prose-aware class merging outside of `cn`.
|
|
58
|
+
*/
|
|
59
|
+
declare const proseTwMerge: (...classLists: _$tailwind_merge0.ClassNameValue[]) => string;
|
|
60
|
+
//#endregion
|
|
50
61
|
//#region src/slugify.d.ts
|
|
51
62
|
interface SlugifyOptions extends Options {
|
|
52
63
|
/** When true, dots are also replaced (default is false) */
|
|
@@ -120,5 +131,5 @@ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof
|
|
|
120
131
|
*/
|
|
121
132
|
declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
|
|
122
133
|
//#endregion
|
|
123
|
-
export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
|
|
134
|
+
export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, proseTwMerge, proseTwMergeClassGroups, slugify, tv, variantsToClassNames };
|
|
124
135
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/proseTwMerge.ts","../src/slugify.ts","../src/tv.ts"],"mappings":";;;;;;;;;;;;;;;AAsBA;;;;;;;;cAAa,EAAA,MAAS,OAAA,EAAS,aAAA;;;;;;;;;;;AAA/B;;;;;;;;ACEA;;;;;;cAAa,iBAAA;;;KCpBR,kBAAA;AAAA,cAsBQ,uBAAA,EAAyB,WAAA,CACpC,WAAA,CACE,eAAA,CAAgB,kBAAA;;;;;;cAcP,YAAA,MAAY,UAAA,EAIvB,iBAAA,CAJuB,cAAA;;;UCpCf,cAAA,SAAuB,OAAA;;EAE/B,WAAA;AAAA;AAAA,cAGW,OAAA,GAAW,MAAA,UAAgB,OAAA,GAAU,cAAA;;;;;;;KCFtC,UAAA;;AJaZ;;;KIPK,WAAA;EAAA,CACF,CAAA;EAAA,CACA,CAAA;AAAA,IACC,SAAA,CAAU,UAAA;;AHMd;;;KGAK,UAAA,IAAc,SAAA,GAAY,WAAA;;;;;KAM1B,QAAA,GAAW,MAAA,SAAe,UAAA;;;;;cAMlB,EAAA,EAAI,EAAA;;;;;KAOL,OAAA,uBAA8B,IAAA,iBACxC,YAAA,CAAa,SAAA;;;;;KAOH,WAAA,uBAAkC,IAAA,iBAC1C,OAAA,CAAQ,MAAA,OAAa,UAAA,CAAW,SAAA,GAAY,UAAA,KAC5C,UAAA;;;;;AFXJ;;;;;;;;ACxCmD;;;;;AASnD;;;;;;;;cCqEa,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,11 @@
|
|
|
1
1
|
import { ArgumentArray } from "classnames";
|
|
2
|
+
import * as _$tailwind_merge0 from "tailwind-merge";
|
|
3
|
+
import { ConfigExtension } from "tailwind-merge";
|
|
2
4
|
import { Options } from "slug";
|
|
3
5
|
import { VariantProps, heroui } from "@heroui/theme";
|
|
4
6
|
import { ClassProp, TV } from "tailwind-variants";
|
|
5
7
|
|
|
6
8
|
//#region src/cn.d.ts
|
|
7
|
-
|
|
8
9
|
/**
|
|
9
10
|
* A utility function that combines `classnames` and `tailwind-merge`.
|
|
10
11
|
*
|
|
@@ -47,6 +48,16 @@ declare const cn: (...classes: ArgumentArray) => string;
|
|
|
47
48
|
*/
|
|
48
49
|
declare const isTestEnvironment: () => boolean;
|
|
49
50
|
//#endregion
|
|
51
|
+
//#region src/proseTwMerge.d.ts
|
|
52
|
+
type ProseClassGroupIds = 'prose-size' | 'prose-color';
|
|
53
|
+
declare const proseTwMergeClassGroups: NonNullable<NonNullable<ConfigExtension<ProseClassGroupIds, never>['extend']>['classGroups']>;
|
|
54
|
+
/**
|
|
55
|
+
* Prose-aware `tailwind-merge` instance that deduplicates `prose-*` classes.
|
|
56
|
+
* Used by `cn(...)` internally. Also exported for direct use in components
|
|
57
|
+
* that need prose-aware class merging outside of `cn`.
|
|
58
|
+
*/
|
|
59
|
+
declare const proseTwMerge: (...classLists: _$tailwind_merge0.ClassNameValue[]) => string;
|
|
60
|
+
//#endregion
|
|
50
61
|
//#region src/slugify.d.ts
|
|
51
62
|
interface SlugifyOptions extends Options {
|
|
52
63
|
/** When true, dots are also replaced (default is false) */
|
|
@@ -120,5 +131,5 @@ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof
|
|
|
120
131
|
*/
|
|
121
132
|
declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
|
|
122
133
|
//#endregion
|
|
123
|
-
export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
|
|
134
|
+
export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, proseTwMerge, proseTwMergeClassGroups, slugify, tv, variantsToClassNames };
|
|
124
135
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cn.ts","../src/isTestEnvironment.ts","../src/proseTwMerge.ts","../src/slugify.ts","../src/tv.ts"],"mappings":";;;;;;;;;;;;;;;AAsBA;;;;;;;;cAAa,EAAA,MAAS,OAAA,EAAS,aAAA;;;;;;;;;;;AAA/B;;;;;;;;ACEA;;;;;;cAAa,iBAAA;;;KCpBR,kBAAA;AAAA,cAsBQ,uBAAA,EAAyB,WAAA,CACpC,WAAA,CACE,eAAA,CAAgB,kBAAA;;;;;;cAcP,YAAA,MAAY,UAAA,EAIvB,iBAAA,CAJuB,cAAA;;;UCpCf,cAAA,SAAuB,OAAA;;EAE/B,WAAA;AAAA;AAAA,cAGW,OAAA,GAAW,MAAA,UAAgB,OAAA,GAAU,cAAA;;;;;;;KCFtC,UAAA;;AJaZ;;;KIPK,WAAA;EAAA,CACF,CAAA;EAAA,CACA,CAAA;AAAA,IACC,SAAA,CAAU,UAAA;;AHMd;;;KGAK,UAAA,IAAc,SAAA,GAAY,WAAA;;;;;KAM1B,QAAA,GAAW,MAAA,SAAe,UAAA;;;;;cAMlB,EAAA,EAAI,EAAA;;;;;KAOL,OAAA,uBAA8B,IAAA,iBACxC,YAAA,CAAa,SAAA;;;;;KAOH,WAAA,uBAAkC,IAAA,iBAC1C,OAAA,CAAQ,MAAA,OAAa,UAAA,CAAW,SAAA,GAAY,UAAA,KAC5C,UAAA;;;;;AFXJ;;;;;;;;ACxCmD;;;;;AASnD;;;;;;;;cCqEa,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 {
|
|
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
|
|
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
|
|
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
|
|
109
|
-
acc[slotKey] = variantFn({ className: baseSlot && slot === baseSlot ? slotClassName : classNames
|
|
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"
|
|
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;AAC9C,QAAO,UAAU,UAAU,WAAW,aAAa,MAAM;;;;;;AAO3D,MAAM,gBAAgB,UAA2B;AAC/C,QACE,UAAU,YACV,CAAC,YAAY,MAAM,KAClB,WAAW,kBAAkB,MAAM,IAAI,WAAW,iBAAiB,MAAM;;AAI9E,MAAa,0BAIT;CAEF,cAAc,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;CAExC,eAAe,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC;CAC3C;;;;;;AAOD,MAAa,eAAe,oBAAwC,EAClE,QAAQ,EACN,aAAa,yBACd,EACF,CAAC;;;;;;;;;;;;;;;;;;ACxBF,MAAa,MAAM,GAAG,YAA2B;AAG/C,QAAO,aAAa,WAAW,GAAG,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;ACD7C,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,MAAM,aACJ,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,YACA,WAAW;AAGjB,MAAI,WAAW,UAAU,EACvB,WACE,YAAY,SAAS,WAAW,gBAAgB,WAAW,OAC9D,CAAC;AAEF,SAAO;IAET,EAAE,CACH"}
|
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.
|
|
5
|
+
"version": "1.2.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
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
15
|
},
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/slug": "5.0.9"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c5f4c34f2ade7b4858f759fcd65ab41661b6790c"
|
|
56
56
|
}
|