3 import { browser } from '$app/env';
4 import { blink } from '$lib/animations/blink';
9 $: shouldShowPalette = false;
12 document.documentElement.style.setProperty('--dot-size', dotSize + 'px');
18 document.documentElement.style.setProperty('--dot-x', dotSize - x % dotSize + 'px');
19 document.documentElement.style.setProperty('--dot-y', dotSize - y % dotSize + 'px');
25 const moveCanvas = function moveCanvas(event) {
28 x -= event.x - dragging.x;
29 y -= event.y - dragging.y;
35 const startDragging = function startDragging(event) {
42 const stopDragging = function startDragging() {
46 const formatCoordinate = function formatCoordinate(coordinate) {
47 const sign = Math.sign(coordinate) === 1 ? '' : '-';
48 const value = Math.abs(coordinate).toString(16).padStart(4, 0);
52 const showPalette = function showPalette(event) {
53 event.preventDefault();
55 document.documentElement.style.setProperty('--palette-x', event.clientX + 'px');
56 document.documentElement.style.setProperty('--palette-y', event.clientY + 'px');
57 shouldShowPalette = true;
60 const hidePalette = function hidePalette() {
61 event.preventDefault();
62 shouldShowPalette = false;
68 on:contextmenu={showPalette}
69 on:mousedown={startDragging}
70 on:mouseup={stopDragging}
71 on:mousemove={moveCanvas}>
75 ({ formatCoordinate(x) }, { formatCoordinate(y) })
78 {#if shouldShowPalette }
79 <div class="palette-container" on:click={hidePalette}>
81 <div class="palette" transition:blink>
83 palette palette palette palette palette palette <br/>
84 palette palette palette palette palette palette <br/>
85 palette palette palette palette palette palette <br/>
86 palette palette palette palette palette palette <br/>
87 palette palette palette palette palette palette <br/>
88 palette palette palette palette palette palette <br/>
96 background: radial-gradient(#aaa, #aaa 1px, #fff 1px, #fff var(--dot-size));
97 background-size: var(--dot-size) var(--dot-size);
98 background-position: var(--dot-x) var(--dot-y);
106 background-color: #fff;
112 -webkit-font-smoothing : none;
117 top: var(--palette-y);
118 left: var(--palette-x);
119 border: 1px solid black;
120 background-color: #fff;
127 background-color: #f0f;