aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/components/ParticleBackground.svelte
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2026-01-15 17:49:26 +0800
committerGitHub <noreply@github.com>2026-01-15 17:49:26 +0800
commit32a9aceee42a2261b64f9e6effda522639576a5e (patch)
tree4cae8d216c3093421addaa0450bc8004c537e373 /ui/src/components/ParticleBackground.svelte
parentce4b0c2053d5d16f7091d74840d4a502401f1a4e (diff)
parent31077dbd39a25eecd24a1dca0f8c9d1879265277 (diff)
downloadDropOut-32a9aceee42a2261b64f9e6effda522639576a5e.tar.gz
DropOut-32a9aceee42a2261b64f9e6effda522639576a5e.zip
Merge pull request #30 from HsiangNianian/main
Diffstat (limited to 'ui/src/components/ParticleBackground.svelte')
-rw-r--r--ui/src/components/ParticleBackground.svelte57
1 files changed, 57 insertions, 0 deletions
diff --git a/ui/src/components/ParticleBackground.svelte b/ui/src/components/ParticleBackground.svelte
new file mode 100644
index 0000000..080f1f2
--- /dev/null
+++ b/ui/src/components/ParticleBackground.svelte
@@ -0,0 +1,57 @@
+<script lang="ts">
+ import { onMount, onDestroy } from "svelte";
+ import { ConstellationEffect } from "../lib/effects/ConstellationEffect";
+ import { SaturnEffect } from "../lib/effects/SaturnEffect";
+ import { settingsState } from "../stores/settings.svelte";
+
+ let canvas: HTMLCanvasElement;
+ let activeEffect: any;
+
+ function loadEffect() {
+ if (activeEffect) {
+ activeEffect.destroy();
+ }
+
+ if (!canvas) return;
+
+ if (settingsState.settings.active_effect === "saturn") {
+ activeEffect = new SaturnEffect(canvas);
+ } else {
+ activeEffect = new ConstellationEffect(canvas);
+ }
+
+ // Ensure correct size immediately
+ activeEffect.resize(window.innerWidth, window.innerHeight);
+ }
+
+ $effect(() => {
+ const _ = settingsState.settings.active_effect;
+ if (canvas) {
+ loadEffect();
+ }
+ });
+
+ onMount(() => {
+ const resizeObserver = new ResizeObserver(() => {
+ if (canvas && activeEffect) {
+ activeEffect.resize(window.innerWidth, window.innerHeight);
+ }
+ });
+
+ resizeObserver.observe(document.body);
+
+ return () => {
+ resizeObserver.disconnect();
+ if (activeEffect) activeEffect.destroy();
+ };
+ });
+
+ onDestroy(() => {
+ if (activeEffect) activeEffect.destroy();
+ });
+</script>
+
+<canvas
+ bind:this={canvas}
+ class="absolute inset-0 z-0 pointer-events-none"
+></canvas>