128 lines
2.8 KiB
Svelte
128 lines
2.8 KiB
Svelte
<script lang="ts">
|
|
import type { Ply } from '#lib/game.ts';
|
|
import type { Entity } from '#lib/mock.ts';
|
|
import Mark from './Mark.svelte';
|
|
import { tick } from 'svelte';
|
|
|
|
let {
|
|
plies,
|
|
white,
|
|
black,
|
|
current,
|
|
onselect
|
|
}: { plies: Ply[]; white: Entity; black: Entity; current: number; onselect?: (i: number) => void } = $props();
|
|
|
|
const lines = $derived(plies.filter((p) => p.m.trash));
|
|
let box: HTMLDivElement;
|
|
$effect(() => {
|
|
lines.length;
|
|
current;
|
|
tick().then(() => requestAnimationFrame(() => {
|
|
if (!box) return;
|
|
const last = lines[lines.length - 1];
|
|
if (last && current >= last.idx) box.scrollTo({ top: box.scrollHeight });
|
|
else {
|
|
// nearest line at or before current
|
|
const target = [...lines].reverse().find((l) => l.idx <= current);
|
|
const el = target ? (box.querySelector(`[data-idx="${target.idx}"]`) as HTMLElement | null) : null;
|
|
if (el) box.scrollTop = el.offsetTop - box.clientHeight / 2 + el.offsetHeight / 2;
|
|
}
|
|
}));
|
|
});
|
|
</script>
|
|
|
|
<div class="feed" bind:this={box}>
|
|
{#each lines as p (p.idx)}
|
|
<button class="line {p.color}" class:cur={p.idx === current} data-idx={p.idx} onclick={() => onselect?.(p.idx)}>
|
|
<div class="av"><Mark e={p.color === 'w' ? white : black} size={26} /></div>
|
|
<div class="bubble">
|
|
<div class="hd pixel">
|
|
<span>{p.color === 'w' ? 'P1' : 'P2'}</span>
|
|
<span class="mono mv">{p.num}{p.color === 'w' ? '.' : '…'} {p.san}</span>
|
|
</div>
|
|
<div class="txt">{p.m.trash}</div>
|
|
</div>
|
|
</button>
|
|
{/each}
|
|
</div>
|
|
|
|
<style>
|
|
.feed {
|
|
position: relative;
|
|
overflow: auto;
|
|
padding: 10px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
scrollbar-width: thin;
|
|
scrollbar-color: var(--line-2) transparent;
|
|
}
|
|
.line {
|
|
display: grid;
|
|
grid-template-columns: auto 1fr;
|
|
gap: 8px;
|
|
align-items: flex-end;
|
|
text-align: left;
|
|
max-width: 92%;
|
|
}
|
|
.line.b {
|
|
grid-template-columns: 1fr auto;
|
|
align-self: flex-end;
|
|
}
|
|
.line.b .av {
|
|
order: 2;
|
|
}
|
|
.av {
|
|
padding-bottom: 2px;
|
|
}
|
|
.bubble {
|
|
--acc: var(--p1);
|
|
position: relative;
|
|
background: var(--panel-2);
|
|
border: 1px solid var(--line-2);
|
|
padding: 6px 10px 8px;
|
|
border-bottom-left-radius: 0;
|
|
}
|
|
.b .bubble {
|
|
--acc: var(--p2);
|
|
}
|
|
.bubble::after {
|
|
content: '';
|
|
position: absolute;
|
|
bottom: -1px;
|
|
left: -7px;
|
|
border: 6px solid transparent;
|
|
border-bottom-color: var(--line-2);
|
|
border-right-color: var(--line-2);
|
|
}
|
|
.b .bubble::after {
|
|
left: auto;
|
|
right: -7px;
|
|
border-right-color: transparent;
|
|
border-left-color: var(--line-2);
|
|
}
|
|
.cur .bubble {
|
|
border-color: var(--acc);
|
|
box-shadow: 0 0 0 1px var(--acc);
|
|
}
|
|
.hd {
|
|
display: flex;
|
|
gap: 8px;
|
|
color: var(--acc);
|
|
margin-bottom: 3px;
|
|
font-size: 8px;
|
|
}
|
|
.mv {
|
|
color: var(--muted);
|
|
font-size: 10px;
|
|
}
|
|
.txt {
|
|
font-size: 13px;
|
|
line-height: 1.4;
|
|
color: var(--text);
|
|
}
|
|
.line:hover .bubble {
|
|
border-color: var(--acc);
|
|
}
|
|
</style>
|