diff --git a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte index db70f3ad64..4ca425bcb0 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte @@ -1,13 +1,49 @@ -
-
+
+
diff --git a/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte b/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte index 82e00baa93..13254c29c8 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte @@ -2,35 +2,30 @@ import { onMount, createEventDispatcher } from "svelte"; import dragable from "./drag.js"; + export let value = 1 export let type = "hue"; const dispatch = createEventDispatcher(); let slider; - let dimensions = {}; - let thumbPosition = 0; - - onMount(() => { - if (slider) { - dimensions = slider.getBoundingClientRect(); - } - }); + let sliderWidth = 0; function handleClick(mouseX) { - const { left, width } = dimensions; + const { left } = slider.getBoundingClientRect(); let clickPosition = mouseX - left; - debugger; - if (clickPosition >= 0 && clickPosition <= width) { - thumbPosition = clickPosition; - let percentageClick = thumbPosition / width; + + if (clickPosition >= 0 && clickPosition <= sliderWidth) { + let percentageClick = clickPosition / sliderWidth; let value = type === "hue" - ? Math.round(360 * percentageClick).toString() - : percentageClick.toFixed(2); + ? 360 * percentageClick.toString() + : percentageClick.toString(); dispatch("change", value); } } + $: thumbPosition = type === "hue" ? sliderWidth * (value / 360) : sliderWidth * (value) + $: style = `transform: translateX(${thumbPosition - 6}px);`; @@ -75,6 +70,7 @@
handleClick(event.clientX)} class="color-format-slider" class:hue={type === 'hue'} diff --git a/packages/builder/src/components/userInterface/Colorpicker/drag.js b/packages/builder/src/components/userInterface/Colorpicker/drag.js index eb15c8d4fb..842d157ad2 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/drag.js +++ b/packages/builder/src/components/userInterface/Colorpicker/drag.js @@ -6,7 +6,6 @@ export default function(node) { function handleMouseMove(event) { let mouseX = event.clientX; - console.log(mouseX); node.dispatchEvent( new CustomEvent('drag', { detail: mouseX diff --git a/packages/builder/src/components/userInterface/Colorpicker/utils.js b/packages/builder/src/components/userInterface/Colorpicker/utils.js index 98bb96d259..6c8c8d48ed 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/utils.js +++ b/packages/builder/src/components/userInterface/Colorpicker/utils.js @@ -12,19 +12,19 @@ export const isValidRgba = (rgba) => { return isValidLengthRange && isValidColorRange && isValidAlphaRange; }; -export const determineColorType = (color) => { - let hsva = []; - if (color.startsWith('#')) { - let [ rHex, gHex, bHex, aHex ] = getHexaValues(color); - hsva = hexaToHSVA([ rHex, gHex, bHex ], aHex); - } else if (color.startsWith('rgb')) { - let rgba = getRgbaValues(color); - hsva = rgbaToHSVA(rgba); - } -}; -export const getHSLA = (hsv, a) => { - const [ h, s, l ] = hsvToHSL(hsv); +export const getAndConvertHexa = (color) => { + let [ rHex, gHex, bHex, aHex ] = getHexaValues(color); + return hexaToHSVA([ rHex, gHex, bHex ], aHex); +} + +export const getAndConvertRgba = color => { + let rgba = getRgbaValues(color); + return rgbaToHSVA(rgba); +} + +export const getHSLA = ([hue, sat, val, a]) => { + const [ h, s, l ] = _hsvToHSL([hue, sat, val]); return `hsla(${h}, ${s}, ${l}, ${a})`; }; @@ -36,20 +36,21 @@ export const hexaToHSVA = (hex, alpha = 'FF') => { export const rgbaToHSVA = (rgba) => { if (isValidRgba(rgba)) { const [ r, g, b, a = '1' ] = rgba; - let hsv = rgbToHSV([ r, g, b ]); + let hsv = _rgbToHSV([ r, g, b ]); return [ ...hsv, a ]; } }; -export const hsvaToHexa = () => { - const [ r, g, b, a ] = hsvaToRgba(); +export const hsvaToHexa = (hsva) => { + const [ r, g, b, a ] = hsvaToRgba(hsva); const hexa = [ r, g, b ].map((v) => v.toString(16)).concat((a * 255).toFixed(1).toString(16)); - return hexa; + return `#${hexa.join()}` }; -export const hsvaToRgba = (h, s, v, a) => { +export const hsvaToRgba = ([h, s, v, a]) => { let rgb = _hsvToRgb([ h, s, v ]); - return [ ...rgb, a ]; + let rgba = [ ...rgb, a ]; + return `rgba(${rgba.join(",")})` }; //Credit : https://github.com/Qix-/color-convert