@sohanemon/utils 1.0.2 → 2.0.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.d.ts +0 -10
- package/dist/index.js +0 -61
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import { type ClassValue } from 'clsx';
|
|
2
|
-
interface ColorObject {
|
|
3
|
-
[key: string]: string | {
|
|
4
|
-
DEFAULT: string;
|
|
5
|
-
foreground?: string;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
2
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
9
3
|
export declare function isNavActive(href: string, path: string): boolean;
|
|
10
|
-
export declare function kebabCase(camelCase: string): string;
|
|
11
|
-
export declare function cssColorVariable(colors: Record<string, string>): Record<string, string>;
|
|
12
4
|
export declare function cleanSrc(src: string): string;
|
|
13
|
-
export declare function tailwindColorObject(input: Record<string, string>): ColorObject;
|
|
14
|
-
export {};
|
package/dist/index.js
CHANGED
|
@@ -6,69 +6,8 @@ export function cn(...inputs) {
|
|
|
6
6
|
export function isNavActive(href, path) {
|
|
7
7
|
return href === '/' ? path === '/' : path?.includes(href);
|
|
8
8
|
}
|
|
9
|
-
function hexToHSLFormatted(hexColor) {
|
|
10
|
-
const [r, g, b] = hexColor.match(/\w\w/g)?.map((c) => parseInt(c, 16) / 255);
|
|
11
|
-
const maxVal = Math.max(r, g, b), minVal = Math.min(r, g, b);
|
|
12
|
-
const lightness = (maxVal + minVal) / 2;
|
|
13
|
-
const delta = maxVal - minVal;
|
|
14
|
-
const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
|
|
15
|
-
let hue = delta !== 0
|
|
16
|
-
? maxVal === r
|
|
17
|
-
? ((g - b) / delta + (g < b ? 6 : 0)) * 60
|
|
18
|
-
: maxVal === g
|
|
19
|
-
? ((b - r) / delta + 2) * 60
|
|
20
|
-
: ((r - g) / delta + 4) * 60
|
|
21
|
-
: 0;
|
|
22
|
-
if (hue < 0)
|
|
23
|
-
hue += 360;
|
|
24
|
-
return `${Math.round(hue)} ${Math.round(saturation * 100)}% ${Math.round(lightness * 100)}%`;
|
|
25
|
-
}
|
|
26
|
-
function extractHSLValues(input) {
|
|
27
|
-
if (input.includes('#'))
|
|
28
|
-
return hexToHSLFormatted(input);
|
|
29
|
-
const matches = input.match(/hsla?\(([\d.]+),\s*([\d.]+)%,\s*([\d.]+)%(?:,\s*[\d.]+)?\)/);
|
|
30
|
-
if (!matches)
|
|
31
|
-
throw new Error(`Invalid HSL format: ${input}`);
|
|
32
|
-
return `${matches[1]} ${matches[2]}% ${matches[3]}%`;
|
|
33
|
-
}
|
|
34
|
-
export function kebabCase(camelCase) {
|
|
35
|
-
return camelCase.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
|
|
36
|
-
}
|
|
37
|
-
export function cssColorVariable(colors) {
|
|
38
|
-
const temp = {};
|
|
39
|
-
Object.keys(colors).map((key) => {
|
|
40
|
-
temp[`--${kebabCase(key)}`] = extractHSLValues(colors[key]);
|
|
41
|
-
});
|
|
42
|
-
return temp;
|
|
43
|
-
}
|
|
44
9
|
export function cleanSrc(src) {
|
|
45
10
|
if (src.includes('/public/'))
|
|
46
11
|
return src.replace('/public/', '/');
|
|
47
12
|
return src;
|
|
48
13
|
}
|
|
49
|
-
export function tailwindColorObject(input) {
|
|
50
|
-
const transformed = {};
|
|
51
|
-
for (const key in input) {
|
|
52
|
-
if (Object.prototype.hasOwnProperty.call(input, key)) {
|
|
53
|
-
if (key.endsWith('Foreground')) {
|
|
54
|
-
const baseKey = key.replace(/Foreground$/, '');
|
|
55
|
-
if (!transformed[baseKey]) {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
transformed[baseKey] = {};
|
|
58
|
-
}
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
transformed[baseKey].foreground = `hsl(var(--${key}))`;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
if (!transformed[key]) {
|
|
64
|
-
transformed[key] = { DEFAULT: `hsl(var(--${key}))` };
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
transformed[key].DEFAULT = `hsl(var(--${key}))`;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return transformed;
|
|
74
|
-
}
|