|
|
|
@ -1,5 +1,6 @@ |
|
|
|
<script> |
|
|
|
import { onMount, createEventDispatcher } from "svelte" |
|
|
|
import { drag } from "../actions" |
|
|
|
import CheckedBackground from "./CheckedBackground.svelte" |
|
|
|
|
|
|
|
const dispatch = createEventDispatcher() |
|
|
|
@ -10,22 +11,18 @@ |
|
|
|
export let a = 1 |
|
|
|
|
|
|
|
let palette |
|
|
|
let cursor = "grab" |
|
|
|
|
|
|
|
let paletteHeight, |
|
|
|
paletteWidth = 0 |
|
|
|
|
|
|
|
function handleClick(event) { |
|
|
|
function handePaletteChange({ mouseX, mouseY }) { |
|
|
|
const { left, top } = palette.getBoundingClientRect() |
|
|
|
let clickX = event.clientX - left |
|
|
|
let clickY = event.clientY - top |
|
|
|
if ( |
|
|
|
clickX > 0 && |
|
|
|
clickY > 0 && |
|
|
|
clickX < paletteWidth && |
|
|
|
clickY < paletteHeight |
|
|
|
) { |
|
|
|
let s = (clickX / paletteWidth) * 100 |
|
|
|
let v = 100 - (clickY / paletteHeight) * 100 |
|
|
|
let x = mouseX - left |
|
|
|
let y = mouseY - top |
|
|
|
if (x > 0 && y > 0 && x < paletteWidth && y < paletteHeight) { |
|
|
|
let s = (x / paletteWidth) * 100 |
|
|
|
let v = 100 - (y / paletteHeight) * 100 |
|
|
|
dispatch("change", { s, v }) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -38,7 +35,8 @@ |
|
|
|
` |
|
|
|
$: style = `background: ${paletteGradient};` |
|
|
|
|
|
|
|
$: pickerStyle = `transform: translate(${pickerX - 8}px, ${pickerY - 8}px);` |
|
|
|
$: pickerStyle = `transform: translate(${pickerX - 8}px, ${pickerY - |
|
|
|
8}px); cursor: ${cursor};` |
|
|
|
</script> |
|
|
|
|
|
|
|
<CheckedBackground width="100%"> |
|
|
|
@ -46,10 +44,19 @@ |
|
|
|
bind:this={palette} |
|
|
|
bind:clientHeight={paletteHeight} |
|
|
|
bind:clientWidth={paletteWidth} |
|
|
|
on:click={handleClick} |
|
|
|
on:click={event => handePaletteChange({ |
|
|
|
mouseX: event.clientX, |
|
|
|
mouseY: event.clientY, |
|
|
|
})} |
|
|
|
class="palette" |
|
|
|
{style}> |
|
|
|
<div class="picker" style={pickerStyle} /> |
|
|
|
<div |
|
|
|
use:drag |
|
|
|
on:dragstart={() => (cursor = 'grabbing')} |
|
|
|
on:drag={event => handePaletteChange(event.detail)} |
|
|
|
on:dragend={() => (cursor = 'grab')} |
|
|
|
class="picker" |
|
|
|
style={pickerStyle} /> |
|
|
|
</div> |
|
|
|
</CheckedBackground> |
|
|
|
|
|
|
|
|