Skip to content

Commit 1ee7ae3

Browse files
committed
Merge branch 'develop' of https://github.com/OpenNBS/NoteBlockWorld into develop
2 parents 6376466 + 0398f6b commit 1ee7ae3

File tree

2 files changed

+2
-61
lines changed

2 files changed

+2
-61
lines changed

apps/frontend/src/lib/utils.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,3 @@ import { twMerge } from 'tailwind-merge';
44
export function cn(...inputs: ClassValue[]) {
55
return twMerge(clsx(inputs));
66
}
7-
8-
/**
9-
* Converts OKLCH color format to RGB hex code
10-
* @param oklchString - OKLCH color string (e.g., "oklch(38% 0.189 293.745)")
11-
* @returns RGB hex code (e.g., "#1a1a1a")
12-
*/
13-
export function oklchToRgb(oklchString: string): string {
14-
// Parse OKLCH values from string like "oklch(38% 0.189 293.745)"
15-
const match = oklchString.match(/oklch\(([^)]+)\)/);
16-
if (!match) {
17-
throw new Error(`Invalid OKLCH format: ${oklchString}`);
18-
}
19-
20-
const parts = match[1].trim().split(/\s+/);
21-
const l = parseFloat(parts[0].replace('%', '')) / 100; // Convert percentage to 0-1
22-
const c = parseFloat(parts[1]);
23-
const h = parseFloat(parts[2]) * (Math.PI / 180); // Convert degrees to radians
24-
25-
// Convert OKLCH to OKLab
26-
const a = c * Math.cos(h);
27-
const bLab = c * Math.sin(h);
28-
29-
// Convert OKLab to linear RGB
30-
// OKLab to linear sRGB matrix (inverse of sRGB to OKLab)
31-
const l_ = l + 0.3963377774 * a + 0.2158037573 * bLab;
32-
const m_ = l - 0.1055613458 * a - 0.0638541728 * bLab;
33-
const s_ = l - 0.0894841775 * a - 1.291485548 * bLab;
34-
35-
const l3 = l_ * l_ * l_;
36-
const m3 = m_ * m_ * m_;
37-
const s3 = s_ * s_ * s_;
38-
39-
const r_ = 4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3;
40-
const g_ = -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3;
41-
const b_ = -0.0041960863 * l3 - 0.7034186147 * m3 + 1.707614701 * s3;
42-
43-
// Convert linear RGB to sRGB (gamma correction)
44-
const gamma = (c: number) => {
45-
if (c <= 0.0031308) {
46-
return 12.92 * c;
47-
}
48-
return 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
49-
};
50-
51-
const r = Math.max(0, Math.min(1, gamma(r_)));
52-
const g = Math.max(0, Math.min(1, gamma(g_)));
53-
const b = Math.max(0, Math.min(1, gamma(b_)));
54-
55-
// Convert to 0-255 range and then to hex
56-
const toHex = (n: number) => {
57-
const hex = Math.round(n * 255).toString(16);
58-
return hex.length === 1 ? '0' + hex : hex;
59-
};
60-
61-
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
62-
}

apps/frontend/src/modules/song/components/client/SongThumbnailInput.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
22
import { UseFormReturn } from 'react-hook-form';
33

44
import { BG_COLORS, THUMBNAIL_CONSTANTS } from '@nbw/config';
5-
import { cn, oklchToRgb } from '@web/lib/utils';
5+
import { cn } from '@web/lib/utils';
66
import {
77
Tooltip,
88
TooltipContent,
@@ -183,10 +183,7 @@ export const SongThumbnailInput: React.FC<SongThumbnailInputProps> = ({
183183
}
184184
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
185185
e.preventDefault();
186-
formMethods.setValue(
187-
'thumbnailData.backgroundColor',
188-
oklchToRgb(dark),
189-
);
186+
formMethods.setValue('thumbnailData.backgroundColor', dark);
190187
}}
191188
/>
192189
))}

0 commit comments

Comments
 (0)