Skip to content

Commit c26dec1

Browse files
Support fractions in theme editor
1 parent 127a5a1 commit c26dec1

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/components/DevTools/ThemeEditor.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,23 @@ const DAISYUI_THEMES = [
8787
];
8888

8989
function oklchToHex(oklch: string): string {
90-
const match = oklch.match(/oklch\(([\d.]+%?)\s+([\d.]+)\s+([\d.]+)\)/);
90+
const match = oklch.match(/oklch\(([\d.]+%?)\s+([\d.]+%?)\s+([\d.]+)\)/);
9191
if (!match) return "#000000";
9292

93-
const l = parseFloat(match[1].replace("%", "")) / 100;
94-
const c = parseFloat(match[2]);
93+
let l: number;
94+
if (match[1].includes("%")) {
95+
l = parseFloat(match[1].replace("%", "")) / 100;
96+
} else {
97+
l = parseFloat(match[1]);
98+
}
99+
100+
let c: number;
101+
if (match[2].includes("%")) {
102+
c = parseFloat(match[2].replace("%", "")) / 100;
103+
} else {
104+
c = parseFloat(match[2]);
105+
}
106+
95107
const h = parseFloat(match[3]);
96108

97109
const a = c * Math.cos((h * Math.PI) / 180);

0 commit comments

Comments
 (0)