2025-11-21 12:18:04 +01:00
|
|
|
<script lang="ts">
|
2026-03-09 11:18:22 +01:00
|
|
|
import { THEMES, type ChartConfig } from './chart-utils';
|
2025-11-21 12:18:04 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
let { id, config }: { id: string; config: ChartConfig } = $props();
|
2025-11-21 12:18:04 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
const colorConfig = $derived(
|
|
|
|
|
config ? Object.entries(config).filter(([, config]) => config.theme || config.color) : null
|
|
|
|
|
);
|
2025-11-21 12:18:04 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
const themeContents = $derived.by(() => {
|
|
|
|
|
if (!colorConfig || !colorConfig.length) return;
|
2025-11-21 12:18:04 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
const themeContents = [];
|
|
|
|
|
for (let [_theme, prefix] of Object.entries(THEMES)) {
|
|
|
|
|
let content = `${prefix} [data-chart=${id}] {\n`;
|
|
|
|
|
const color = colorConfig.map(([key, itemConfig]) => {
|
|
|
|
|
const theme = _theme as keyof typeof itemConfig.theme;
|
|
|
|
|
const color = itemConfig.theme?.[theme] || itemConfig.color;
|
|
|
|
|
return color ? `\t--color-${key}: ${color};` : null;
|
|
|
|
|
});
|
2025-11-21 12:18:04 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
content += color.join('\n') + '\n}';
|
2025-11-21 12:18:04 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
themeContents.push(content);
|
|
|
|
|
}
|
2025-11-21 12:18:04 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
return themeContents.join('\n');
|
|
|
|
|
});
|
2025-11-21 12:18:04 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if themeContents}
|
2025-11-24 01:00:50 +01:00
|
|
|
{#key id}
|
|
|
|
|
<svelte:element this={'style'}>
|
|
|
|
|
{themeContents}
|
|
|
|
|
</svelte:element>
|
|
|
|
|
{/key}
|
2025-11-21 12:18:04 +01:00
|
|
|
{/if}
|