|
|
@ -13,16 +13,18 @@ |
|
|
import Palette from "./Palette.svelte" |
|
|
import Palette from "./Palette.svelte" |
|
|
import ButtonGroup from "./ButtonGroup.svelte" |
|
|
import ButtonGroup from "./ButtonGroup.svelte" |
|
|
import Input from "./Input.svelte" |
|
|
import Input from "./Input.svelte" |
|
|
|
|
|
import Portal from "./Portal.svelte" |
|
|
|
|
|
|
|
|
export let value = "#3ec1d3ff" |
|
|
export let value = "#3ec1d3ff" |
|
|
|
|
|
export let open = false; |
|
|
export let swatches = [] //TODO: Safe swatches - limit to 12. warn in console |
|
|
export let swatches = [] //TODO: Safe swatches - limit to 12. warn in console |
|
|
export let disableSwatches = false |
|
|
export let disableSwatches = false |
|
|
export let format = "hexa" |
|
|
export let format = "hexa" |
|
|
export let open = false |
|
|
export let style = "" |
|
|
|
|
|
|
|
|
export let pickerHeight = 0 |
|
|
export let pickerHeight = 0 |
|
|
export let pickerWidth = 0 |
|
|
export let pickerWidth = 0 |
|
|
|
|
|
|
|
|
|
|
|
let colorPicker = null |
|
|
let adder = null |
|
|
let adder = null |
|
|
|
|
|
|
|
|
let h = null |
|
|
let h = null |
|
|
@ -38,6 +40,10 @@ |
|
|
getRecentColors() |
|
|
getRecentColors() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(colorPicker) { |
|
|
|
|
|
colorPicker.focus() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (format) { |
|
|
if (format) { |
|
|
convertAndSetHSVA() |
|
|
convertAndSetHSVA() |
|
|
} |
|
|
} |
|
|
@ -50,6 +56,12 @@ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleEscape(e) { |
|
|
|
|
|
if(open && e.key === "Escape") { |
|
|
|
|
|
open = false |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function setRecentColor(color) { |
|
|
function setRecentColor(color) { |
|
|
if (swatches.length === 12) { |
|
|
if (swatches.length === 12) { |
|
|
swatches.splice(0, 1) |
|
|
swatches.splice(0, 1) |
|
|
@ -145,85 +157,97 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$: border = v > 90 && s < 5 ? "1px dashed #dedada" : "" |
|
|
$: border = v > 90 && s < 5 ? "1px dashed #dedada" : "" |
|
|
$: style = buildStyle({ background: value, border }) |
|
|
$: selectedColorStyle = buildStyle({ background: value, border }) |
|
|
$: shrink = swatches.length > 0 |
|
|
$: shrink = swatches.length > 0 |
|
|
|
|
|
|
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<div |
|
|
|
|
|
class="colorpicker-container" |
|
|
|
|
|
bind:clientHeight={pickerHeight} |
|
|
|
|
|
bind:clientWidth={pickerWidth}> |
|
|
|
|
|
|
|
|
|
|
|
<div class="palette-panel"> |
|
|
<Portal> |
|
|
<Palette on:change={setSaturationAndValue} {h} {s} {v} {a} /> |
|
|
<div |
|
|
</div> |
|
|
class="colorpicker-container" |
|
|
|
|
|
transition:fade |
|
|
|
|
|
bind:this={colorPicker} |
|
|
|
|
|
{style} |
|
|
|
|
|
tabindex="0" |
|
|
|
|
|
on:keydown={handleEscape} |
|
|
|
|
|
bind:clientHeight={pickerHeight} |
|
|
|
|
|
bind:clientWidth={pickerWidth}> |
|
|
|
|
|
|
|
|
<div class="control-panel"> |
|
|
<div class="palette-panel"> |
|
|
<div class="alpha-hue-panel"> |
|
|
<Palette on:change={setSaturationAndValue} {h} {s} {v} {a} /> |
|
|
<div> |
|
|
</div> |
|
|
<CheckedBackground borderRadius="50%" backgroundSize="8px"> |
|
|
|
|
|
<div class="selected-color" {style} /> |
|
|
<div class="control-panel"> |
|
|
</CheckedBackground> |
|
|
<div class="alpha-hue-panel"> |
|
|
</div> |
|
|
<div> |
|
|
<div> |
|
|
<CheckedBackground borderRadius="50%" backgroundSize="8px"> |
|
|
<Slider |
|
|
<div class="selected-color" style={selectedColorStyle} /> |
|
|
type="hue" |
|
|
</CheckedBackground> |
|
|
value={h} |
|
|
</div> |
|
|
on:change={hue => setHue(hue.detail)} |
|
|
<div> |
|
|
on:dragend={dispatchValue} /> |
|
|
|
|
|
|
|
|
|
|
|
<CheckedBackground borderRadius="10px" backgroundSize="7px"> |
|
|
|
|
|
<Slider |
|
|
<Slider |
|
|
type="alpha" |
|
|
type="hue" |
|
|
value={a} |
|
|
value={h} |
|
|
on:change={(alpha, isDrag) => setAlpha(alpha.detail, isDrag)} |
|
|
on:change={hue => setHue(hue.detail)} |
|
|
on:dragend={dispatchValue} /> |
|
|
on:dragend={dispatchValue} /> |
|
|
</CheckedBackground> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<CheckedBackground borderRadius="10px" backgroundSize="7px"> |
|
|
|
|
|
<Slider |
|
|
|
|
|
type="alpha" |
|
|
|
|
|
value={a} |
|
|
|
|
|
on:change={(alpha, isDrag) => setAlpha(alpha.detail, isDrag)} |
|
|
|
|
|
on:dragend={dispatchValue} /> |
|
|
|
|
|
</CheckedBackground> |
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
{#if !disableSwatches} |
|
|
{#if !disableSwatches} |
|
|
<div transition:fade class="swatch-panel"> |
|
|
<div transition:fade class="swatch-panel"> |
|
|
{#if swatches.length > 0} |
|
|
{#if swatches.length > 0} |
|
|
{#each swatches as color, idx} |
|
|
{#each swatches as color, idx} |
|
|
<Swatch |
|
|
<Swatch |
|
|
{color} |
|
|
{color} |
|
|
on:click={() => applySwatch(color)} |
|
|
on:click={() => applySwatch(color)} |
|
|
on:removeswatch={() => removeSwatch(idx)} /> |
|
|
on:removeswatch={() => removeSwatch(idx)} /> |
|
|
{/each} |
|
|
{/each} |
|
|
{/if} |
|
|
{/if} |
|
|
{#if swatches.length !== 12} |
|
|
{#if swatches.length !== 12} |
|
|
<div |
|
|
<div |
|
|
bind:this={adder} |
|
|
bind:this={adder} |
|
|
transition:fade |
|
|
transition:fade |
|
|
class="adder" |
|
|
class="adder" |
|
|
on:click={addSwatch} |
|
|
on:click={addSwatch} |
|
|
class:shrink> |
|
|
class:shrink> |
|
|
<span>+</span> |
|
|
<span>+</span> |
|
|
</div> |
|
|
</div> |
|
|
{/if} |
|
|
{/if} |
|
|
|
|
|
</div> |
|
|
|
|
|
{/if} |
|
|
|
|
|
|
|
|
|
|
|
<div class="format-input-panel"> |
|
|
|
|
|
<ButtonGroup {format} onclick={changeFormatAndConvert} /> |
|
|
|
|
|
<Input |
|
|
|
|
|
{value} |
|
|
|
|
|
on:input={event => handleColorInput(event.target.value)} |
|
|
|
|
|
on:change={dispatchInputChange} /> |
|
|
</div> |
|
|
</div> |
|
|
{/if} |
|
|
|
|
|
|
|
|
|
|
|
<div class="format-input-panel"> |
|
|
|
|
|
<ButtonGroup {format} onclick={changeFormatAndConvert} /> |
|
|
|
|
|
<Input |
|
|
|
|
|
{value} |
|
|
|
|
|
on:input={event => handleColorInput(event.target.value)} |
|
|
|
|
|
on:change={dispatchInputChange} /> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
</div> |
|
|
|
|
|
</Portal> |
|
|
|
|
|
|
|
|
<style> |
|
|
<style> |
|
|
.colorpicker-container { |
|
|
.colorpicker-container { |
|
|
|
|
|
position: absolute; |
|
|
|
|
|
outline: none; |
|
|
|
|
|
z-index: 3; |
|
|
display: flex; |
|
|
display: flex; |
|
|
font-size: 11px; |
|
|
font-size: 11px; |
|
|
font-weight: 400; |
|
|
font-weight: 400; |
|
|
flex-direction: column; |
|
|
flex-direction: column; |
|
|
/* height: 265px; */ |
|
|
margin: 5px 0px; |
|
|
height: auto; |
|
|
height: auto; |
|
|
width: 220px; |
|
|
width: 220px; |
|
|
background: #ffffff; |
|
|
background: #ffffff; |
|
|
|