Skip to content

Commit f82ab71

Browse files
committed
add tmp fish flap component
1 parent b6bc318 commit f82ab71

File tree

4 files changed

+157
-5
lines changed

4 files changed

+157
-5
lines changed

src/assets/flag.svg

Lines changed: 7 additions & 0 deletions
Loading

src/components/FishFlag.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
export let width = 200;
3+
export let height = 53;
4+
</script>
5+
6+
<svg
7+
{width}
8+
{height}
9+
viewBox="0 0 326 53"
10+
xmlns="http://www.w3.org/2000/svg"
11+
preserveAspectRatio="none"
12+
>
13+
<path d="M0 0 H80 V53 H0 Z" fill="none" />
14+
<path d="M2.55107 48.7027C1.87448 48.7027 1.22561 48.4055 0.747191 47.8765C0.268773 47.3475 0 46.6301 0 45.882V10.9377C0 9.37981 1.14207 8.11707 2.55107 8.11707C3.96007 8.11707 5.10214 9.37981 5.10214 10.9377V45.882C5.10214 47.4396 3.9598 48.7027 2.55107 48.7027Z" fill="#60A9E3"/>
15+
<g transform="translate(5,0)">
16+
<rect x="0" y="0" width="{width - 80}" height="53" fill="#ACD4F4"/>
17+
</g>
18+
<g transform="translate({width - 80},0)">
19+
<path d="M244.733 42.4168C243.495 42.1402 209.217 39.3048 175.247 40.2251C141.277 40.5312 107.617 44.5928 107.617 43.9262C101.743 43.3624 97.736 29.8168 97.512 28.3357C97.356 27.0454 99.049 19.0846 102.011 14.0943L0 20.5147C11.7955 10.8932 28.152 5.17669 45.948 2.34188C75.563 -2.28468 92.032 0.8923 101.77 3.75688C106.812 5.28012 107.363 7.90596 106.726 10.1102C108.908 10.4822 141.357 6.33491 174.226 6.93206C208.261 6.79856 242.736 11.7526 244.505 13.9665C248.04 16.6503 245.101 18.3792 237.856 17.8621C236.759 17.7931 235.65 17.7483 234.536 17.728C223.459 17.0839 196.474 17.8335 197.189 21.8786C197.887 25.2071 226.331 31.6074 237.851 35.8064C244.911 38.1877 247.916 41.0159 244.733 42.4168Z" fill="#60A9E3"/>
20+
</g>
21+
</svg>

src/components/FlagHeader.svelte

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<!-- 留着备用, 万一可以变得很可爱呢 -->
2+
3+
<script lang="ts">
4+
import {onMount, onDestroy} from 'svelte';
5+
import {currentPage} from '../store';
6+
import {wikis} from '../config';
7+
import gsap from 'gsap';
8+
import FishFlag from '../assets/flag.svg?raw';
9+
10+
let visible = true;
11+
let showModal = false;
12+
let lines: string[] = [];
13+
let ticker: gsap.core.Tween;
14+
let textEl: HTMLDivElement;
15+
16+
$: wikiText = wikis[$currentPage]?.trim() || '';
17+
$: lines = wikiText ? wikiText.split('\n').map((l) => l.trim()) : [];
18+
19+
$: if (wikiText && textEl) {
20+
gsap.killTweensOf(textEl);
21+
scroll();
22+
}
23+
24+
$: if (!currentPage) {
25+
visible = false;
26+
showModal = false;
27+
}
28+
29+
async function scroll() {
30+
if (!textEl) return;
31+
gsap.killTweensOf(textEl);
32+
33+
await gsap.delayedCall(0.02, () => {});
34+
35+
const totalWidth = textEl.scrollWidth;
36+
const singleCopyWidth = totalWidth / 2;
37+
const viewportWidth = textEl.parentElement?.clientWidth || 0;
38+
39+
if (singleCopyWidth <= viewportWidth) {
40+
gsap.set(textEl, {x: 0});
41+
return;
42+
}
43+
44+
gsap.set(textEl, {x: 0});
45+
46+
ticker = gsap.to(textEl, {
47+
x: -singleCopyWidth,
48+
duration: singleCopyWidth / 60,
49+
ease: 'linear',
50+
repeat: -1,
51+
force3D: true,
52+
roundProps: 'x',
53+
});
54+
}
55+
56+
onMount(() => {
57+
document.addEventListener('click', handleClick);
58+
setTimeout(scroll, 50);
59+
60+
setTimeout(() => {
61+
document.querySelectorAll<HTMLElement>('.koi-flag').forEach((el, i) => {
62+
gsap.to(el, {
63+
y: gsap.utils.random(-12, 12),
64+
x: gsap.utils.random(-6, 6),
65+
duration: gsap.utils.random(0.8, 1.5),
66+
yoyo: true,
67+
repeat: -1,
68+
ease: 'sine.inOut',
69+
delay: i * 0.1,
70+
});
71+
});
72+
}, 100);
73+
74+
return () => {
75+
document.removeEventListener('click', handleClick);
76+
};
77+
});
78+
79+
onDestroy(() => {
80+
if (ticker) ticker.kill();
81+
});
82+
83+
function handleClick(event: MouseEvent) {
84+
const isTextInteraction = window.getSelection()?.toString();
85+
if (showModal && (event.target as HTMLElement).closest('#wiki-modal') && !isTextInteraction) {
86+
showModal = false;
87+
}
88+
}
89+
</script>
90+
91+
{#if visible && wikiText}
92+
<div class="fixed top-0 left-0 w-full text-[var(--textColor)] backdrop-blur-sm z-10 h-12 flex items-center">
93+
<div class="relative overflow-visible flex-1 h-full -ml-2 -mr-2">
94+
<div
95+
bind:this={textEl}
96+
class="absolute whitespace-nowrap text-sm lg:text-base will-change-transform top-0 left-12 h-full flex items-center gap-2"
97+
>
98+
{#each Array(2) as _}
99+
{#each lines as line}
100+
<div class="koi-flag relative flex items-center justify-center w-48 h-[40px] mx-2">
101+
{@html FishFlag}
102+
<span class="absolute text-xs left-4 text-center top-[14px]">{line}</span>
103+
</div>
104+
{/each}
105+
{/each}
106+
</div>
107+
</div>
108+
</div>
109+
{/if}

src/components/WikiHeader.svelte

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,30 @@
7474

7575
{#if visible && wikiText}
7676
<div
77-
class="fixed top-0 left-0 w-full text-[var(--textColor)] bg-white/70 backdrop-blur-sm shadow-xs z-10 h-8 flex items-center"
77+
class="fixed top-0 left-0 w-full text-[var(--textColor)] bg-white/70 backdrop-blur-sm shadow-xs z-10 h-8 flex items-center
78+
[mask-image:linear-gradient(to_right,transparent,white_4%,white_96%,transparent)]
79+
[mask-repeat:no-repeat]
80+
[mask-size:100%_100%]
81+
[-webkit-mask-image:linear-gradient(to_right,transparent,white_4%,white_96%,transparent)]
82+
[-webkit-mask-repeat:no-repeat]
83+
[-webkit-mask-size:100%_100%]"
7884
>
7985
<button
80-
class="pl-1 w-9 cursor-pointer"
86+
class="pl-1 w-9 cursor-pointer "
8187
on:click={() => (showModal = true)}
8288
>
8389
{@html Scroll}
8490
</button>
85-
<div class="relative overflow-hidden flex-1 h-full -ml-2 -mr-2">
91+
<div
92+
class="relative overflow-hidden flex-1 h-full -ml-2 -mr-2
93+
[mask-image:linear-gradient(to_right,transparent,white_7%,white_93%,transparent)]
94+
[mask-repeat:no-repeat]
95+
[mask-size:100%_100%]
96+
[-webkit-mask-image:linear-gradient(to_right,transparent,white_7%,white_93%,transparent)]
97+
[-webkit-mask-repeat:no-repeat]
98+
[-webkit-mask-size:100%_100%]"
99+
>
100+
86101
<div
87102
bind:this={textEl}
88103
class="absolute whitespace-nowrap text-sm lg:text-base will-change-transform top-0 left-12 h-full flex items-center"
@@ -96,7 +111,7 @@
96111
</div>
97112
</div>
98113
<button
99-
class="pr-1 w-8 cursor-pointer"
114+
class="pr-1 w-8 cursor-pointer "
100115
on:click={() => (visible = false)}
101116
>
102117
{@html Close}
@@ -105,7 +120,7 @@
105120
{/if}
106121
{#if showModal}
107122
<div
108-
class="fixed inset-0 z-50 bg-black/60 flex items-center justify-center backdrop-blur-lg will-change-transform will-change-opacity"
123+
class="fixed inset-0 z-50 bg-black/60 flex items-center justify-center backdrop-blur-lg will-change-transform will-change-opacity"
109124
id="wiki-modal"
110125
transition:fade={{duration: 200}}
111126
>

0 commit comments

Comments
 (0)