Skip to content

Commit

Permalink
temp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shyakadavis committed Oct 2, 2024
1 parent 99000e5 commit e8832de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/routes/colors/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import PageSection from '$lib/components/shared/page-section.svelte';
import PageWrapper from '$lib/components/shared/page-wrapper.svelte';
import ColorMenu from './color-menu.svelte';
import { scales } from './data.js';
let { data } = $props();
Expand Down
9 changes: 7 additions & 2 deletions src/routes/colors/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { browser } from '$app/environment';

// function to convert hsl to hex where the input is a string like 'hsl(var(--background-200))'
export function hsl_to_hex(hsl_string: string): string {
// Extract the CSS variable name
const var_name = hsl_string.match(/var\((.*?)\)/)?.[1];
if (!var_name) {
throw new Error('Invalid HSL string format');
// throw new Error('Invalid HSL string format');
return '#000000';
}

// Get the computed style value
const hsl_value = getComputedStyle(document.documentElement).getPropertyValue(var_name).trim();
const hsl_value = browser
? getComputedStyle(document.documentElement).getPropertyValue(var_name).trim()
: '0, 0%, 0%';

// Parse the HSL values
const [h, s, l] = hsl_value.split(/[,\s]+/).map((val, index) => {
Expand Down

0 comments on commit e8832de

Please sign in to comment.