From 5db84c1090b082217027ee68623a1fcfc81c3e0b Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 12 Sep 2023 10:35:58 -0400 Subject: [PATCH] fix(PaintControls): when clicking transparent eraser palette swatch --- src/components/PaintControls.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/PaintControls.vue b/src/components/PaintControls.vue index d2fe8cc54..e09f465fe 100644 --- a/src/components/PaintControls.vue +++ b/src/components/PaintControls.vue @@ -94,6 +94,8 @@ import { LABELMAP_PALETTE } from '../config'; import { usePaintToolStore } from '../store/tools/paint'; import { rgbaToHexa } from '../utils/color'; +const HEXA_LENGTH = 9; + // generates both the swatches for v-color-picker and the color-to-value mapping function convertToSwatches( palette: typeof LABELMAP_PALETTE, @@ -134,10 +136,14 @@ export default defineComponent({ }); const setBrushColor = (color: string) => { - const hexa = `${color}FF`.toUpperCase(); - if (hexa in hexToValue) { - paintStore.setBrushValue(hexToValue[hexa]); + // Passthrough if #RRGGBBAA, add alpha if #RRGGBB + const withAlpha = color.length === HEXA_LENGTH ? color : `${color}FF`; + const hexa = withAlpha.toUpperCase(); + const brushValue = hexToValue[hexa]; + if (brushValue == null) { + throw new Error(`Brush value invalid`); } + paintStore.setBrushValue(brushValue); }; const brushSize = computed(() => paintStore.brushSize);