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 Minimap from '$lib/components/minimap.svelte';
7 import Widget from '$lib/components/widget.svelte';
8 import { modulo } from '$lib/math';
9 import { widgets } from '$lib/stores/widgets';
10 import { canvas } from '$lib/stores/canvas';
12 import { maxSize } from '$lib/config';
14 $: shouldShowPalette = false;
18 const moveCanvas = function moveCanvas(event) {
20 let deltaX = event.x - dragging.x;
21 let deltaY = event.y - dragging.y;
22 let x = modulo($canvas.x - deltaX, maxSize);
23 let y = modulo($canvas.y - deltaY, maxSize);
30 const startDragging = function startDragging(event) {
37 const stopDragging = function startDragging() {
41 const showPalette = function showPalette(event) {
42 event.preventDefault();
44 document.documentElement.style.setProperty('--palette-x', event.clientX + 'px');
45 document.documentElement.style.setProperty('--palette-y', event.clientY + 'px');
46 shouldShowPalette = true;
49 const hidePalette = function hidePalette() {
50 event.preventDefault();
51 shouldShowPalette = false;
57 on:click={hidePalette}
58 on:contextmenu={showPalette}
59 on:mousedown={startDragging}
60 on:mouseup={stopDragging}
61 on:mousemove={moveCanvas}
68 {#if shouldShowPalette}
73 {#each $widgets as widget}