2 import Sensor from '$lib/components/sensor.svelte';
3 import Background from '$lib/components/background.svelte';
4 import Palette from '$lib/components/palette.svelte';
5 import Hud from '$lib/components/hud.svelte';
6 import { modulo } from '$lib/math';
8 import { coordinateLength, maxSize } from '$lib/config';
12 $: shouldShowPalette = false;
16 const moveCanvas = function moveCanvas(event) {
19 let deltaX = event.x - dragging.x;
20 let deltaY = event.y - dragging.y;
21 x = modulo(x - deltaX, maxSize);
22 y = modulo(y - deltaY, maxSize);
28 const startDragging = function startDragging(event) {
35 const stopDragging = function startDragging() {
39 const showPalette = function showPalette(event) {
40 event.preventDefault();
42 document.documentElement.style.setProperty('--palette-x', event.clientX + 'px');
43 document.documentElement.style.setProperty('--palette-y', event.clientY + 'px');
44 shouldShowPalette = true;
47 const hidePalette = function hidePalette() {
48 event.preventDefault();
49 shouldShowPalette = false;
55 on:click={hidePalette}
56 on:contextmenu={showPalette}
57 on:mousedown={startDragging}
58 on:mouseup={stopDragging}
59 on:mousemove={moveCanvas}>
61 <Sensor x={x} y={y} />
62 <Background x={x} y={y} />
65 {#if shouldShowPalette }