diff --git a/package.json b/package.json
index 4f14e69..3ec09d0 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"@intlify/unplugin-vue-i18n": "^2.0.0",
"@radix-icons/vue": "^1.0.0",
"@serialport/bindings-cpp": "^12.0.1",
+ "@types/color": "^3.0.6",
"@vueuse/core": "^10.9.0",
"ajv": "^8.12.0",
"class-variance-authority": "^0.7.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 46b6e6f..3d3ef42 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -20,6 +20,9 @@ dependencies:
'@serialport/bindings-cpp':
specifier: ^12.0.1
version: 12.0.1
+ '@types/color':
+ specifier: ^3.0.6
+ version: 3.0.6
'@vueuse/core':
specifier: ^10.9.0
version: 10.9.0(vue@3.4.21)
@@ -1204,6 +1207,22 @@ packages:
'@types/node': 18.19.21
'@types/responselike': 1.0.3
+ /@types/color-convert@2.0.3:
+ resolution: {integrity: sha512-2Q6wzrNiuEvYxVQqhh7sXM2mhIhvZR/Paq4FdsQkOMgWsCIkKvSGj8Le1/XalulrmgOzPMqNa0ix+ePY4hTrfg==}
+ dependencies:
+ '@types/color-name': 1.1.3
+ dev: false
+
+ /@types/color-name@1.1.3:
+ resolution: {integrity: sha512-87W6MJCKZYDhLAx/J1ikW8niMvmGRyY+rpUxWpL1cO7F8Uu5CHuQoFv+R0/L5pgNdW4jTyda42kv60uwVIPjLw==}
+ dev: false
+
+ /@types/color@3.0.6:
+ resolution: {integrity: sha512-NMiNcZFRUAiUUCCf7zkAelY8eV3aKqfbzyFQlXpPIEeoNDbsEHGpb854V3gzTsGKYj830I5zPuOwU/TP5/cW6A==}
+ dependencies:
+ '@types/color-convert': 2.0.3
+ dev: false
+
/@types/debug@4.1.12:
resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==}
dependencies:
diff --git a/src/renderer/src/components/common/HSVInput.vue b/src/renderer/src/components/common/HSVInput.vue
index b1acd1d..624c16f 100644
--- a/src/renderer/src/components/common/HSVInput.vue
+++ b/src/renderer/src/components/common/HSVInput.vue
@@ -187,13 +187,19 @@ import { SliderRoot, SliderThumb, SliderTrack } from 'radix-vue'
import { MoreHorizontal } from 'lucide-vue-next'
import { Separator } from '@renderer/components/ui/separator'
-defineProps({
+const props = defineProps({
+ color: {
+ type: Color,
+ default: () => Color.rgb(255, 0, 0)
+ },
roundedTop: {
type: Boolean,
default: false
}
})
+const emit = defineEmits(['input'])
+
const hueSliderValue = ref(0)
const saturationSliderValue = ref(100)
const valueSliderValue = ref(50)
@@ -204,7 +210,7 @@ const hueSliderModel = computed({
},
set(hue) {
hueSliderValue.value = hue[0]
- color.value = color.value.hue(hue[0])
+ emit('input', props.color.hue(hue[0]))
}
})
@@ -214,7 +220,7 @@ const saturationSliderModel = computed({
},
set(saturation) {
saturationSliderValue.value = saturation[0]
- color.value = color.value.saturationv(saturation[0])
+ emit('input', props.color.saturationv(saturation[0]))
}
})
@@ -224,15 +230,10 @@ const valueSliderModel = computed({
},
set(value) {
valueSliderValue.value = value[0]
- color.value = color.value.value(value[0])
+ emit('input', props.color.value(value[0]))
}
})
-const color = defineModel({
- type: Color,
- default: () => Color.rgb(255, 0, 0)
-})
-
const saturationSliderColor = computed(() => {
return Color.hsv(hueSliderModel.value[0], 100, valueSliderModel.value[0])
})
@@ -255,7 +256,7 @@ function onSubmitHexInput() {
input = '#' + input
}
if (input.match(/^#[0-9A-F]{6}$/i)) {
- color.value = Color(input)
+ emit('input', Color(input))
} else shake()
}
@@ -266,10 +267,10 @@ function onSubmitHueInput() {
return
}
const newHue = Math.max(0, Math.min(input, 360))
- if (newHue === color.value.hue()) {
+ if (newHue === props.color.hue()) {
updateInputs()
}
- color.value = color.value.hue(newHue)
+ emit('input', props.color.hue(newHue))
}
function onSubmitSaturationInput() {
@@ -279,10 +280,10 @@ function onSubmitSaturationInput() {
return
}
const newSaturation = Math.max(0, Math.min(input, 100))
- if (newSaturation === color.value.saturationv()) {
+ if (newSaturation === props.color.saturationv()) {
updateInputs()
}
- color.value = color.value.saturationv(newSaturation)
+ emit('input', props.color.saturationv(newSaturation))
}
function onSubmitValueInput() {
@@ -292,10 +293,10 @@ function onSubmitValueInput() {
return
}
const newValue = Math.max(0, Math.min(input, 100))
- if (newValue === color.value.value()) {
+ if (newValue === props.color.value()) {
updateInputs()
}
- color.value = color.value.value(newValue)
+ emit('input', props.color.value(newValue))
}
function onSubmitRGBInput() {
@@ -307,26 +308,27 @@ function onSubmitRGBInput() {
return
}
const newColor = Color.rgb(r, g, b)
- if (newColor.hex() === color.value.hex()) {
+ if (newColor.hex() === props.color.hex()) {
updateInputs()
}
- color.value = newColor
+ emit('input', newColor)
}
function updateInputs() {
- hexInput.value = color.value.hex().substring(1, 7)
- hueInput.value = String(parseInt(color.value.hue())).padStart(3, '0')
- saturationInput.value = String(parseInt(color.value.saturationv())).padStart(3, '0')
- valueInput.value = String(parseInt(color.value.value())).padStart(3, '0')
- rInput.value = String(parseInt(color.value.red())).padStart(3, '0')
- gInput.value = String(parseInt(color.value.green())).padStart(3, '0')
- bInput.value = String(parseInt(color.value.blue())).padStart(3, '0')
- hueSliderValue.value = color.value.hue()
- saturationSliderValue.value = color.value.saturationv()
- valueSliderValue.value = color.value.value()
+ console.log('COLORRR', props.color)
+ hexInput.value = props.color.hex().substring(1, 7)
+ hueInput.value = String(parseInt(props.color.hue())).padStart(3, '0')
+ saturationInput.value = String(parseInt(props.color.saturationv())).padStart(3, '0')
+ valueInput.value = String(parseInt(props.color.value())).padStart(3, '0')
+ rInput.value = String(parseInt(props.color.red())).padStart(3, '0')
+ gInput.value = String(parseInt(props.color.green())).padStart(3, '0')
+ bInput.value = String(parseInt(props.color.blue())).padStart(3, '0')
+ hueSliderValue.value = props.color.hue()
+ saturationSliderValue.value = props.color.saturationv()
+ valueSliderValue.value = props.color.value()
}
-watch(color, updateInputs)
+watch(props.color, updateInputs)
onBeforeMount(updateInputs)
const colorFieldText = ref(null)
diff --git a/src/renderer/src/components/common/PaletteInput.vue b/src/renderer/src/components/common/PaletteInput.vue
index b185e74..70bab85 100644
--- a/src/renderer/src/components/common/PaletteInput.vue
+++ b/src/renderer/src/components/common/PaletteInput.vue
@@ -32,40 +32,45 @@
@click="currentOption = key"
/>
-
+ $emit('input', currentOption, color)"
+ />