🛠️ Improve svgCard component to support theme-based image rendering

This commit is contained in:
pheralb
2025-08-31 13:43:31 +01:00
parent 73bd5a4f78
commit d06c87037a
+41 -13
View File
@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import type { iSVG } from "@/types/svg"; import type { iSVG } from "@/types/svg";
import { cn } from "@/utils/cn"; import { cn } from "@/utils/cn";
import { mode } from "mode-watcher";
// Icons: // Icons:
import XIcon from "@lucide/svelte/icons/x"; import XIcon from "@lucide/svelte/icons/x";
@@ -31,6 +32,7 @@
// States: // States:
let wordmarkSvg = $state<boolean>(false); let wordmarkSvg = $state<boolean>(false);
let moreTagsOptions = $state<boolean>(false); let moreTagsOptions = $state<boolean>(false);
let changeThemeMode = $state<boolean>(false);
// Icon Stroke & Size: // Icon Stroke & Size:
let iconStroke = 1.8; let iconStroke = 1.8;
@@ -68,20 +70,46 @@
</div> </div>
<!-- Image --> <!-- Image -->
{#if wordmarkSvg == true && svgInfo.wordmark !== undefined} {#if wordmarkSvg == true && svgInfo.wordmark !== undefined}
{#if changeThemeMode}
<img
class={cn("block", globalImageStyles)}
src={typeof svgInfo.wordmark !== "string"
? mode.current === "dark"
? svgInfo.wordmark?.light || ""
: svgInfo.wordmark?.dark || ""
: svgInfo.wordmark || ""}
alt={svgInfo.title}
title={svgInfo.title}
loading="lazy"
/>
{:else}
<img
class={cn("hidden dark:block", globalImageStyles)}
src={typeof svgInfo.wordmark !== "string"
? svgInfo.wordmark?.dark || ""
: svgInfo.wordmark || ""}
alt={svgInfo.title}
title={svgInfo.title}
loading="lazy"
/>
<img
class={cn("block dark:hidden", globalImageStyles)}
src={typeof svgInfo.wordmark !== "string"
? svgInfo.wordmark?.light || ""
: svgInfo.wordmark || ""}
alt={svgInfo.title}
title={svgInfo.title}
loading="lazy"
/>
{/if}
{:else if changeThemeMode}
<img <img
class={cn("hidden dark:block", globalImageStyles)} class={cn("block", globalImageStyles)}
src={typeof svgInfo.wordmark !== "string" src={typeof svgInfo.route !== "string"
? svgInfo.wordmark?.dark || "" ? mode.current === "dark"
: svgInfo.wordmark || ""} ? svgInfo.route.light
alt={svgInfo.title} : svgInfo.route.dark
title={svgInfo.title} : svgInfo.route}
loading="lazy"
/>
<img
class={cn("block dark:hidden", globalImageStyles)}
src={typeof svgInfo.wordmark !== "string"
? svgInfo.wordmark?.light || ""
: svgInfo.wordmark || ""}
alt={svgInfo.title} alt={svgInfo.title}
title={svgInfo.title} title={svgInfo.title}
loading="lazy" loading="lazy"