@fuf-stack/pixel-utils 1.0.5 → 1.1.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/dist/index.cjs CHANGED
@@ -1,67 +1,155 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
8
+ 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
+ }
19
+ }
20
+ return to;
18
21
  };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
20
26
 
21
- // src/cn.ts
22
- var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames);
23
- var _tailwindmerge = require('tailwind-merge');
24
- var cn = (...classes) => {
25
- return _tailwindmerge.twMerge.call(void 0, _classnames2.default.call(void 0, ...classes));
26
- };
27
-
28
- // src/theme.ts
29
- var _theme = require('@heroui/theme');
27
+ //#endregion
28
+ let classnames = require("classnames");
29
+ classnames = __toESM(classnames);
30
+ let tailwind_merge = require("tailwind-merge");
31
+ let slug = require("slug");
32
+ slug = __toESM(slug);
33
+ let tailwind_variants = require("tailwind-variants");
34
+ let __heroui_theme = require("@heroui/theme");
30
35
 
31
- // src/tv.ts
32
- var _tailwindvariants = require('tailwind-variants');
33
- var tv = _tailwindvariants.tv;
34
- var variantsToClassNames = (variants, className, baseSlot) => {
35
- const classNames2 = typeof className === "object" && !Array.isArray(className) ? className : {};
36
- return Object.entries(variants).reduce(
37
- (acc, [slot, variantFn]) => {
38
- const slotKey = slot;
39
- const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames2[slot];
40
- acc[slotKey] = variantFn({
41
- className: baseSlot && slot === baseSlot ? slotClassName : classNames2[slot]
42
- });
43
- return acc;
44
- },
45
- {}
46
- );
36
+ //#region src/cn.ts
37
+ /**
38
+ * A utility function that combines `classnames` and `tailwind-merge`.
39
+ *
40
+ * It takes multiple class values (strings, arrays, or objects), merges them,
41
+ * and ensures Tailwind CSS classes are handled properly by resolving conflicts.
42
+ *
43
+ * @param classes - A list of class names that can be strings, objects, or arrays.
44
+ * @returns A string of combined class names with Tailwind CSS conflict resolution.
45
+ *
46
+ * Example usage:
47
+ * ```
48
+ * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });
49
+ * // Output: 'text-center bg-red-500 p-4'
50
+ * ```
51
+ */
52
+ const cn = (...classes) => {
53
+ return (0, tailwind_merge.twMerge)((0, classnames.default)(...classes));
47
54
  };
48
55
 
49
- // src/slugify.ts
50
- var _slug = require('slug'); var _slug2 = _interopRequireDefault(_slug);
51
- var slugify = (string, options) => {
52
- var _a, _b;
53
- const replacement = (_a = options == null ? void 0 : options.replacement) != null ? _a : "_";
54
- const replaceDots = (_b = options == null ? void 0 : options.replaceDots) != null ? _b : false;
55
- return _slug2.default.call(void 0, string, __spreadValues(__spreadProps(__spreadValues({}, _slug2.default.defaults.modes.rfc3986), {
56
- charmap: __spreadValues(__spreadValues(__spreadValues({}, _slug2.default.defaults.modes.rfc3986.charmap), !replaceDots ? { ".": "." } : { ".": replacement }), replacement !== "-" ? { "-": "_" } : {}),
57
- replacement
58
- }), options != null ? options : {}));
56
+ //#endregion
57
+ //#region src/isTestEnvironment.ts
58
+ /**
59
+ * Checks if the code is running in a test environment.
60
+ *
61
+ * This helper safely detects test environments by checking:
62
+ * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`
63
+ * - Browser: Always returns `false` (production code)
64
+ *
65
+ * The check is safe for both Node.js and browser environments by verifying
66
+ * that `process` exists before accessing its properties.
67
+ *
68
+ * @returns `true` if running in a test environment, `false` otherwise
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * if (isTestEnvironment()) {
73
+ * // Skip debouncing in tests for immediate snapshots
74
+ * return value;
75
+ * }
76
+ * // Normal production behavior with debouncing
77
+ * return debouncedValue;
78
+ * ```
79
+ */
80
+ const isTestEnvironment = () => {
81
+ return typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.VITEST === "true");
59
82
  };
60
83
 
84
+ //#endregion
85
+ //#region src/slugify.ts
86
+ const slugify = (string, options) => {
87
+ const replacement = options?.replacement ?? "_";
88
+ const replaceDots = options?.replaceDots ?? false;
89
+ return (0, slug.default)(string, {
90
+ ...slug.default.defaults.modes.rfc3986,
91
+ charmap: {
92
+ ...slug.default.defaults.modes.rfc3986.charmap,
93
+ ...!replaceDots ? { ".": "." } : { ".": replacement },
94
+ ...replacement !== "-" ? { "-": "_" } : {}
95
+ },
96
+ replacement,
97
+ ...options ?? {}
98
+ });
99
+ };
61
100
 
101
+ //#endregion
102
+ //#region src/tv.ts
103
+ /**
104
+ * Re-export of tailwind-variants tv function
105
+ * Used to create variant definitions with slots and variants
106
+ */
107
+ const tv = tailwind_variants.tv;
108
+ /**
109
+ * Converts tailwind-variants slots instance to actual classnames object
110
+ *
111
+ * @param variants - Object containing slot variant functions from tailwind-variants
112
+ * @param className - Optional class names to merge with variant classes. Can be string, array, or record
113
+ * @param baseSlot - Optional slot name to apply global className to
114
+ * @returns Record mapping slot names to their final class name strings
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * const variants = tv({ slots: { base: 'bg-white', content: 'p-4' } });
119
+ * const classes = variantsToClassNames(variants(), 'shadow-lg', 'base');
120
+ * // Result: { base: 'bg-white shadow-lg', content: 'p-4' }
121
+ * ```
122
+ *
123
+ * @example
124
+ * ```tsx
125
+ * const variants = tv({ slots: { base: '', content: '' } });
126
+ * const classes = variantsToClassNames(variants(), {
127
+ * base: 'bg-white',
128
+ * content: ['p-4', 'text-gray-700']
129
+ * });
130
+ * // Result: { base: 'bg-white', content: 'p-4 text-gray-700' }
131
+ * ```
132
+ */
133
+ const variantsToClassNames = (variants, className, baseSlot) => {
134
+ const classNames$1 = typeof className === "object" && !Array.isArray(className) ? className : {};
135
+ return Object.entries(variants).reduce((acc, [slot, variantFn]) => {
136
+ 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] });
139
+ return acc;
140
+ }, {});
141
+ };
62
142
 
63
-
64
-
65
-
66
- exports.cn = cn; exports.heroui = _theme.heroui; exports.slugify = slugify; exports.tv = tv; exports.variantsToClassNames = variantsToClassNames;
143
+ //#endregion
144
+ exports.cn = cn;
145
+ Object.defineProperty(exports, 'heroui', {
146
+ enumerable: true,
147
+ get: function () {
148
+ return __heroui_theme.heroui;
149
+ }
150
+ });
151
+ exports.isTestEnvironment = isTestEnvironment;
152
+ exports.slugify = slugify;
153
+ exports.tv = tv;
154
+ exports.variantsToClassNames = variantsToClassNames;
67
155
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/pixels/pixels/packages/pixel-utils/dist/index.cjs","../src/cn.ts","../src/theme.ts","../src/tv.ts","../src/slugify.ts"],"names":["classNames"],"mappings":"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","file":"/home/runner/work/pixels/pixels/packages/pixel-utils/dist/index.cjs","sourcesContent":[null,"/* eslint-disable import/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function that combines `classnames` and `tailwind-merge`.\n *\n * It takes multiple class values (strings, arrays, or objects), merges them,\n * and ensures Tailwind CSS classes are handled properly by resolving conflicts.\n *\n * @param classes - A list of class names that can be strings, objects, or arrays.\n * @returns A string of combined class names with Tailwind CSS conflict resolution.\n *\n * Example usage:\n * ```\n * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });\n * // Output: 'text-center bg-red-500 p-4'\n * ```\n */\nexport const cn = (...classes: ArgumentArray) => {\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/prefer-default-export */\nexport { heroui } from '@heroui/theme';\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","/* 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"]}
1
+ {"version":3,"file":"index.cjs","names":["tv: TV","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,MAAaA,KAASC;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
- import { ArgumentArray } from 'classnames';
2
- import { VariantProps } from '@heroui/theme';
3
- export { heroui } from '@heroui/theme';
4
- import { TV, ClassProp } from 'tailwind-variants';
5
- import { Options } from 'slug';
1
+ import { ArgumentArray } from "classnames";
2
+ import { Options } from "slug";
3
+ import { VariantProps, heroui } from "@heroui/theme";
4
+ import { ClassProp, TV } from "tailwind-variants";
5
+
6
+ //#region src/cn.d.ts
6
7
 
7
8
  /**
8
9
  * A utility function that combines `classnames` and `tailwind-merge`.
@@ -20,7 +21,40 @@ import { Options } from 'slug';
20
21
  * ```
21
22
  */
22
23
  declare const cn: (...classes: ArgumentArray) => string;
23
-
24
+ //#endregion
25
+ //#region src/isTestEnvironment.d.ts
26
+ /**
27
+ * Checks if the code is running in a test environment.
28
+ *
29
+ * This helper safely detects test environments by checking:
30
+ * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`
31
+ * - Browser: Always returns `false` (production code)
32
+ *
33
+ * The check is safe for both Node.js and browser environments by verifying
34
+ * that `process` exists before accessing its properties.
35
+ *
36
+ * @returns `true` if running in a test environment, `false` otherwise
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * if (isTestEnvironment()) {
41
+ * // Skip debouncing in tests for immediate snapshots
42
+ * return value;
43
+ * }
44
+ * // Normal production behavior with debouncing
45
+ * return debouncedValue;
46
+ * ```
47
+ */
48
+ declare const isTestEnvironment: () => boolean;
49
+ //#endregion
50
+ //#region src/slugify.d.ts
51
+ interface SlugifyOptions extends Options {
52
+ /** When true, dots are also replaced (default is false) */
53
+ replaceDots?: boolean;
54
+ }
55
+ declare const slugify: (string: string, options?: SlugifyOptions) => string;
56
+ //#endregion
57
+ //#region src/tv.d.ts
24
58
  /**
25
59
  * Represents a class value which can be either a string or an array of strings
26
60
  * Used for handling both single class names and multiple class names
@@ -31,8 +65,8 @@ type ClassValue = string | string[];
31
65
  * Combines a dynamic record of string/number values with the ClassProp from tailwind-variants
32
66
  */
33
67
  type TVSlotProps = {
34
- [x: string]: string | number | undefined;
35
- [x: number]: string | number | undefined;
68
+ [x: string]: string | number | undefined;
69
+ [x: number]: string | number | undefined;
36
70
  } & ClassProp<ClassValue>;
37
71
  /**
38
72
  * Represents a tailwind-variants slot function
@@ -85,11 +119,6 @@ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof
85
119
  * ```
86
120
  */
87
121
  declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
88
-
89
- interface SlugifyOptions extends Options {
90
- /** When true, dots are also replaced (default is false) */
91
- replaceDots?: boolean;
92
- }
93
- declare const slugify: (string: string, options?: SlugifyOptions) => string;
94
-
95
- export { type ClassValue, type TVClassName, type TVProps, cn, slugify, tv, variantsToClassNames };
122
+ //#endregion
123
+ export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
124
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +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;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,CCYI,UDZW,CAAA;AAKzB;;;;ACFA,KAeK,UAAA,GAfiB,CAAA,SAAA,CAAA,EAeS,WAfT,EAAA,GAAA,MAAA;AAAqB;AAS9B;AAM6B;AAY1C;AAOA,KAbK,QAAA,GAAW,MAaG,CAAA,MAAA,EAbY,UAchB,CAAA;AAOf;;;;AACY,cAhBC,EAgBD,EAhBK,EAgBL;;;;AA4BZ;AAA+C,KArCnC,OAqCmC,CAAA,kBAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,GAAA,GAAA,CAAA,GApC7C,YAoC6C,CApChC,SAoCgC,CAAA;;;;;AAG5B,KAhCP,WAgCO,CAAA,kBAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,GAAA,GAAA,CAAA,GA/Bf,OA+Be,CA/BP,MA+BO,CAAA,MA/BM,UA+BN,CA/BiB,SA+BjB,CAAA,EA/B6B,UA+B7B,CAAA,CAAA,GA9Bf,UA8Be;;;;;;;;;;;;;;;;;;;;;;;;;;cAHN,iCAAkC,oBACnC,eACE,aAAa,eAAe,8BACvB,MAChB,aAAa"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { ArgumentArray } from 'classnames';
2
- import { VariantProps } from '@heroui/theme';
3
- export { heroui } from '@heroui/theme';
4
- import { TV, ClassProp } from 'tailwind-variants';
5
- import { Options } from 'slug';
1
+ import { ArgumentArray } from "classnames";
2
+ import { Options } from "slug";
3
+ import { VariantProps, heroui } from "@heroui/theme";
4
+ import { ClassProp, TV } from "tailwind-variants";
5
+
6
+ //#region src/cn.d.ts
6
7
 
7
8
  /**
8
9
  * A utility function that combines `classnames` and `tailwind-merge`.
@@ -20,7 +21,40 @@ import { Options } from 'slug';
20
21
  * ```
21
22
  */
22
23
  declare const cn: (...classes: ArgumentArray) => string;
23
-
24
+ //#endregion
25
+ //#region src/isTestEnvironment.d.ts
26
+ /**
27
+ * Checks if the code is running in a test environment.
28
+ *
29
+ * This helper safely detects test environments by checking:
30
+ * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`
31
+ * - Browser: Always returns `false` (production code)
32
+ *
33
+ * The check is safe for both Node.js and browser environments by verifying
34
+ * that `process` exists before accessing its properties.
35
+ *
36
+ * @returns `true` if running in a test environment, `false` otherwise
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * if (isTestEnvironment()) {
41
+ * // Skip debouncing in tests for immediate snapshots
42
+ * return value;
43
+ * }
44
+ * // Normal production behavior with debouncing
45
+ * return debouncedValue;
46
+ * ```
47
+ */
48
+ declare const isTestEnvironment: () => boolean;
49
+ //#endregion
50
+ //#region src/slugify.d.ts
51
+ interface SlugifyOptions extends Options {
52
+ /** When true, dots are also replaced (default is false) */
53
+ replaceDots?: boolean;
54
+ }
55
+ declare const slugify: (string: string, options?: SlugifyOptions) => string;
56
+ //#endregion
57
+ //#region src/tv.d.ts
24
58
  /**
25
59
  * Represents a class value which can be either a string or an array of strings
26
60
  * Used for handling both single class names and multiple class names
@@ -31,8 +65,8 @@ type ClassValue = string | string[];
31
65
  * Combines a dynamic record of string/number values with the ClassProp from tailwind-variants
32
66
  */
33
67
  type TVSlotProps = {
34
- [x: string]: string | number | undefined;
35
- [x: number]: string | number | undefined;
68
+ [x: string]: string | number | undefined;
69
+ [x: number]: string | number | undefined;
36
70
  } & ClassProp<ClassValue>;
37
71
  /**
38
72
  * Represents a tailwind-variants slot function
@@ -85,11 +119,6 @@ type TVClassName<Component extends (...args: any) => any> = Partial<Record<keyof
85
119
  * ```
86
120
  */
87
121
  declare const variantsToClassNames: <T extends TVRecord>(variants: T, className?: ClassValue | Record<string, ClassValue>, baseSlot?: keyof T) => Record<keyof T, string>;
88
-
89
- interface SlugifyOptions extends Options {
90
- /** When true, dots are also replaced (default is false) */
91
- replaceDots?: boolean;
92
- }
93
- declare const slugify: (string: string, options?: SlugifyOptions) => string;
94
-
95
- export { type ClassValue, type TVClassName, type TVProps, cn, slugify, tv, variantsToClassNames };
122
+ //#endregion
123
+ export { ClassValue, TVClassName, TVProps, cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
124
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,CCYI,UDZW,CAAA;AAKzB;;;;ACFA,KAeK,UAAA,GAfiB,CAAA,SAAA,CAAA,EAeS,WAfT,EAAA,GAAA,MAAA;AAAqB;AAS9B;AAM6B;AAY1C;AAOA,KAbK,QAAA,GAAW,MAaG,CAAA,MAAA,EAbY,UAchB,CAAA;AAOf;;;;AACY,cAhBC,EAgBD,EAhBK,EAgBL;;;;AA4BZ;AAA+C,KArCnC,OAqCmC,CAAA,kBAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,GAAA,GAAA,CAAA,GApC7C,YAoC6C,CApChC,SAoCgC,CAAA;;;;;AAG5B,KAhCP,WAgCO,CAAA,kBAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,GAAA,GAAA,CAAA,GA/Bf,OA+Be,CA/BP,MA+BO,CAAA,MA/BM,UA+BN,CA/BiB,SA+BjB,CAAA,EA/B6B,UA+B7B,CAAA,CAAA,GA9Bf,UA8Be;;;;;;;;;;;;;;;;;;;;;;;;;;cAHN,iCAAkC,oBACnC,eACE,aAAa,eAAe,8BACvB,MAChB,aAAa"}
package/dist/index.js CHANGED
@@ -1,67 +1,116 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
-
21
- // src/cn.ts
22
1
  import classNames from "classnames";
23
2
  import { twMerge } from "tailwind-merge";
24
- var cn = (...classes) => {
25
- return twMerge(classNames(...classes));
26
- };
27
-
28
- // src/theme.ts
3
+ import slug from "slug";
29
4
  import { heroui } from "@heroui/theme";
5
+ import { tv as tv$1 } from "tailwind-variants";
30
6
 
31
- // src/tv.ts
32
- import { tv as tailwindVariants } from "tailwind-variants";
33
- var tv = tailwindVariants;
34
- var variantsToClassNames = (variants, className, baseSlot) => {
35
- const classNames2 = typeof className === "object" && !Array.isArray(className) ? className : {};
36
- return Object.entries(variants).reduce(
37
- (acc, [slot, variantFn]) => {
38
- const slotKey = slot;
39
- const slotClassName = typeof className === "string" || Array.isArray(className) ? className : classNames2[slot];
40
- acc[slotKey] = variantFn({
41
- className: baseSlot && slot === baseSlot ? slotClassName : classNames2[slot]
42
- });
43
- return acc;
44
- },
45
- {}
46
- );
7
+ //#region src/cn.ts
8
+ /**
9
+ * A utility function that combines `classnames` and `tailwind-merge`.
10
+ *
11
+ * It takes multiple class values (strings, arrays, or objects), merges them,
12
+ * and ensures Tailwind CSS classes are handled properly by resolving conflicts.
13
+ *
14
+ * @param classes - A list of class names that can be strings, objects, or arrays.
15
+ * @returns A string of combined class names with Tailwind CSS conflict resolution.
16
+ *
17
+ * Example usage:
18
+ * ```
19
+ * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });
20
+ * // Output: 'text-center bg-red-500 p-4'
21
+ * ```
22
+ */
23
+ const cn = (...classes) => {
24
+ return twMerge(classNames(...classes));
47
25
  };
48
26
 
49
- // src/slugify.ts
50
- import slug from "slug";
51
- var slugify = (string, options) => {
52
- var _a, _b;
53
- const replacement = (_a = options == null ? void 0 : options.replacement) != null ? _a : "_";
54
- const replaceDots = (_b = options == null ? void 0 : options.replaceDots) != null ? _b : false;
55
- return slug(string, __spreadValues(__spreadProps(__spreadValues({}, slug.defaults.modes.rfc3986), {
56
- charmap: __spreadValues(__spreadValues(__spreadValues({}, slug.defaults.modes.rfc3986.charmap), !replaceDots ? { ".": "." } : { ".": replacement }), replacement !== "-" ? { "-": "_" } : {}),
57
- replacement
58
- }), options != null ? options : {}));
27
+ //#endregion
28
+ //#region src/isTestEnvironment.ts
29
+ /**
30
+ * Checks if the code is running in a test environment.
31
+ *
32
+ * This helper safely detects test environments by checking:
33
+ * - Node.js: `process.env.NODE_ENV === 'test'` or `process.env.VITEST === 'true'`
34
+ * - Browser: Always returns `false` (production code)
35
+ *
36
+ * The check is safe for both Node.js and browser environments by verifying
37
+ * that `process` exists before accessing its properties.
38
+ *
39
+ * @returns `true` if running in a test environment, `false` otherwise
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * if (isTestEnvironment()) {
44
+ * // Skip debouncing in tests for immediate snapshots
45
+ * return value;
46
+ * }
47
+ * // Normal production behavior with debouncing
48
+ * return debouncedValue;
49
+ * ```
50
+ */
51
+ const isTestEnvironment = () => {
52
+ return typeof process !== "undefined" && (process.env.NODE_ENV === "test" || process.env.VITEST === "true");
59
53
  };
60
- export {
61
- cn,
62
- heroui,
63
- slugify,
64
- tv,
65
- variantsToClassNames
54
+
55
+ //#endregion
56
+ //#region src/slugify.ts
57
+ const slugify = (string, options) => {
58
+ const replacement = options?.replacement ?? "_";
59
+ const replaceDots = options?.replaceDots ?? false;
60
+ return slug(string, {
61
+ ...slug.defaults.modes.rfc3986,
62
+ charmap: {
63
+ ...slug.defaults.modes.rfc3986.charmap,
64
+ ...!replaceDots ? { ".": "." } : { ".": replacement },
65
+ ...replacement !== "-" ? { "-": "_" } : {}
66
+ },
67
+ replacement,
68
+ ...options ?? {}
69
+ });
66
70
  };
71
+
72
+ //#endregion
73
+ //#region src/tv.ts
74
+ /**
75
+ * Re-export of tailwind-variants tv function
76
+ * Used to create variant definitions with slots and variants
77
+ */
78
+ const tv = tv$1;
79
+ /**
80
+ * Converts tailwind-variants slots instance to actual classnames object
81
+ *
82
+ * @param variants - Object containing slot variant functions from tailwind-variants
83
+ * @param className - Optional class names to merge with variant classes. Can be string, array, or record
84
+ * @param baseSlot - Optional slot name to apply global className to
85
+ * @returns Record mapping slot names to their final class name strings
86
+ *
87
+ * @example
88
+ * ```tsx
89
+ * const variants = tv({ slots: { base: 'bg-white', content: 'p-4' } });
90
+ * const classes = variantsToClassNames(variants(), 'shadow-lg', 'base');
91
+ * // Result: { base: 'bg-white shadow-lg', content: 'p-4' }
92
+ * ```
93
+ *
94
+ * @example
95
+ * ```tsx
96
+ * const variants = tv({ slots: { base: '', content: '' } });
97
+ * const classes = variantsToClassNames(variants(), {
98
+ * base: 'bg-white',
99
+ * content: ['p-4', 'text-gray-700']
100
+ * });
101
+ * // Result: { base: 'bg-white', content: 'p-4 text-gray-700' }
102
+ * ```
103
+ */
104
+ const variantsToClassNames = (variants, className, baseSlot) => {
105
+ const classNames$1 = typeof className === "object" && !Array.isArray(className) ? className : {};
106
+ return Object.entries(variants).reduce((acc, [slot, variantFn]) => {
107
+ 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] });
110
+ return acc;
111
+ }, {});
112
+ };
113
+
114
+ //#endregion
115
+ export { cn, heroui, isTestEnvironment, slugify, tv, variantsToClassNames };
67
116
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cn.ts","../src/theme.ts","../src/tv.ts","../src/slugify.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport type { ArgumentArray } from 'classnames';\n\nimport classNames from 'classnames';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * A utility function that combines `classnames` and `tailwind-merge`.\n *\n * It takes multiple class values (strings, arrays, or objects), merges them,\n * and ensures Tailwind CSS classes are handled properly by resolving conflicts.\n *\n * @param classes - A list of class names that can be strings, objects, or arrays.\n * @returns A string of combined class names with Tailwind CSS conflict resolution.\n *\n * Example usage:\n * ```\n * cn('p-4', 'text-center', { 'bg-red-500': true, 'p-2': false });\n * // Output: 'text-center bg-red-500 p-4'\n * ```\n */\nexport const cn = (...classes: ArgumentArray) => {\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/prefer-default-export */\nexport { heroui } from '@heroui/theme';\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","/* 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,gBAAgB;AACvB,SAAS,eAAe;AAiBjB,IAAM,KAAK,IAAI,YAA2B;AAG/C,SAAO,QAAQ,WAAW,GAAG,OAAO,CAAC;AACvC;;;ACxBA,SAAS,cAAc;;;ACEvB,SAAS,MAAM,wBAAwB;AAiChC,IAAM,KAAS;AA4Cf,IAAM,uBAAuB,CAClC,UACA,WACA,aAC4B;AAC5B,QAAMA,cACJ,OAAO,cAAc,YAAY,CAAC,MAAM,QAAQ,SAAS,IAAI,YAAY,CAAC;AAE5E,SAAO,OAAO,QAAQ,QAAQ,EAAE;AAAA,IAC9B,CAAC,KAAK,CAAC,MAAM,SAAS,MAAM;AAC1B,YAAM,UAAU;AAChB,YAAM,gBACJ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IACpD,YACAA,YAAW,IAAI;AAGrB,UAAI,OAAO,IAAI,UAAU;AAAA,QACvB,WACE,YAAY,SAAS,WAAW,gBAAgBA,YAAW,IAAI;AAAA,MACnE,CAAC;AAED,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;;;ACtGA,OAAO,UAAU;AAOV,IAAM,UAAU,CAAC,QAAgB,YAA6B;AAXrE;AAYE,QAAM,eAAc,wCAAS,gBAAT,YAAwB;AAC5C,QAAM,eAAc,wCAAS,gBAAT,YAAwB;AAE5C,SAAO,KAAK,QAAQ,gDACf,KAAK,SAAS,MAAM,UADL;AAAA,IAElB,SAAS,iDACJ,KAAK,SAAS,MAAM,QAAQ,UAE3B,CAAC,cAAc,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,YAAY,IAEjD,gBAAgB,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC;AAAA,IAE5C;AAAA,MACI,4BAAW,CAAC,EACjB;AACH;","names":["classNames"]}
1
+ {"version":3,"file":"index.js","names":["tv: TV","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,MAAaA,KAASC;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
package/package.json CHANGED
@@ -2,18 +2,18 @@
2
2
  "name": "@fuf-stack/pixel-utils",
3
3
  "description": "fuf pixels helper utils",
4
4
  "author": "Fröhlich ∧ Frei",
5
- "version": "1.0.5",
5
+ "version": "1.1.0",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
9
+ "types": "./dist/index.d.cts",
10
10
  "sideEffects": false,
11
11
  "exports": {
12
12
  ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js",
15
- "require": "./dist/index.cjs"
16
- }
13
+ "require": "./dist/index.cjs",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./package.json": "./package.json"
17
17
  },
18
18
  "files": [
19
19
  "./dist"
@@ -36,6 +36,10 @@
36
36
  "bugs": {
37
37
  "url": "https://github.com/fuf-stack/pixels/issues"
38
38
  },
39
+ "scripts": {
40
+ "build": "tsdown",
41
+ "prepack": "pnpm build"
42
+ },
39
43
  "peerDependencies": {
40
44
  "tailwind-merge": "*",
41
45
  "tailwind-variants": "*"
@@ -48,7 +52,5 @@
48
52
  "devDependencies": {
49
53
  "@types/slug": "5.0.9"
50
54
  },
51
- "scripts": {
52
- "build": "tsup --config node_modules/@repo/tsup-config/config.ts"
53
- }
54
- }
55
+ "gitHead": "807229f5bce07ed56bcfc5e8197d4a276f1b492f"
56
+ }