Papure/src/lib/components/InkLayer.svelte
2026-09-26 19:13:02 +02:00

57 lines
1.3 KiB
Svelte

<script lang="ts">
import { svgPath, HIGHLIGHTER_OPACITY } from '$lib/ink/stroke';
import type { Stroke } from '$lib/model/types';
interface Props {
width: number;
height: number;
strokes: Stroke[];
/** Stroke being drawn right now (points mutate; `tick` changes). */
live?: Stroke | null;
tick?: number;
/** Strokes hidden while an eraser gesture is in progress. */
erasing?: Set<string>;
}
let { width, height, strokes, live = null, tick = 0, erasing }: Props = $props();
const livePath = $derived.by(() => {
void tick;
return live ? svgPath(live, true) : '';
});
</script>
<svg class="ink" viewBox="0 0 {width} {height}" preserveAspectRatio="none" aria-hidden="true">
{#each strokes as s (s.id)}
{#if !erasing?.has(s.id)}
<path
d={svgPath(s)}
fill={s.color}
fill-opacity={s.tool === 'highlighter' ? HIGHLIGHTER_OPACITY : 1}
class:hl={s.tool === 'highlighter'}
/>
{/if}
{/each}
{#if live}
<path
d={livePath}
fill={live.color}
fill-opacity={live.tool === 'highlighter' ? HIGHLIGHTER_OPACITY : 1}
class:hl={live.tool === 'highlighter'}
/>
{/if}
</svg>
<style>
.ink {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: hidden;
}
.hl {
mix-blend-mode: multiply;
}
</style>