3 import { browser } from '$app/env';
4 import Background from '$lib/components/background.svelte';
5 import Palette from '$lib/components/palette.svelte';
6 import Hud from '$lib/components/hud.svelte';
8 const kCoordinateLength = 6;
9 const kMaxSize = Math.pow(16, kCoordinateLength);
13 $: shouldShowPalette = false;
17 const modulo = function modulo (number, base) {
18 return ((number % base) + base) % base
21 const moveCanvas = function moveCanvas(event) {
24 let deltaX = event.x - dragging.x;
25 let deltaY = event.y - dragging.y;
26 x = modulo(x - deltaX, kMaxSize);
27 y = modulo(y - deltaY, kMaxSize);
33 const startDragging = function startDragging(event) {
40 const stopDragging = function startDragging() {
44 const showPalette = function showPalette(event) {
45 event.preventDefault();
47 document.documentElement.style.setProperty('--palette-x', event.clientX + 'px');
48 document.documentElement.style.setProperty('--palette-y', event.clientY + 'px');
49 shouldShowPalette = true;
52 const hidePalette = function hidePalette() {
53 event.preventDefault();
54 shouldShowPalette = false;
60 on:click={hidePalette}
61 on:contextmenu={showPalette}
62 on:mousedown={startDragging}
63 on:mouseup={stopDragging}
64 on:mousemove={moveCanvas}>
66 <Background x={x} y={y}/>
69 {#if shouldShowPalette }