fix(ColorPicker): update color conversion logic (#4550)

This commit is contained in:
Alex
2025-07-19 22:49:18 +05:00
committed by GitHub
parent e2695ee7e4
commit 6b6ec8cb2c
2 changed files with 7 additions and 4 deletions

View File

@@ -1,12 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
const colorHex = ref('#9C27B0') const colorHex = ref('#9C27B0')
function handleColorChange(event: Event) {
colorHex.value = (event.target as HTMLInputElement).value
}
</script> </script>
<template> <template>
<div class="flex flex-col gap-5"> <div class="flex flex-col gap-5">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span :style="{ backgroundColor: colorHex }" class="inline-flex w-5 h-5 rounded" /> <span :style="{ backgroundColor: colorHex }" class="inline-flex w-5 h-5 rounded" />
<code class="font-mono">{{ colorHex }}</code> <UInput :model-value="colorHex" @change="handleColorChange" />
</div> </div>
<USeparator /> <USeparator />
<div class="flex justify-between gap-2"> <div class="flex justify-between gap-2">
@@ -21,6 +25,6 @@ const colorHex = ref('#9C27B0')
</UButton> </UButton>
</div> </div>
<USeparator /> <USeparator />
<UColorPicker v-model="colorHex" @update:model-value="() => console.log('model update')" /> <UColorPicker v-model="colorHex" />
</div> </div>
</template> </template>

View File

@@ -31,7 +31,7 @@ function HSVtoHSL(hsv: HSVColor): HSLObject {
return { return {
H: hsv.h, H: hsv.h,
S: x === 0 || x === 200 ? 0 : Math.round(hsv.s * hsv.v / (x <= 100 ? x : 200 - x)), S: x === 0 || x === 200 ? 0 : Math.round(hsv.s * hsv.v / (x <= 100 ? x : 200 - x)),
L: Math.round(x / 2) L: x / 2
} }
} }
@@ -102,7 +102,6 @@ const pickedColor = computed<HSVColor>({
}, },
set(value) { set(value) {
const color = new ColorTranslator(HSVtoHSL(value), { const color = new ColorTranslator(HSVtoHSL(value), {
decimals: 2,
labUnit: 'percent', labUnit: 'percent',
cmykUnit: 'percent', cmykUnit: 'percent',
cmykFunction: 'cmyk' cmykFunction: 'cmyk'