@teammodlr/ui-kit 2.1.63 → 2.1.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,333 +1,330 @@
1
- <template>
2
- <div ref="wrapper" class="m-color-picker">
3
- <div ref="referenceRef"
4
- @click="isOpen = !isOpen"
5
- :class="style.reference"
6
- >
7
- <div :class="style.referenceColor"
8
- :style="{ backgroundColor: `rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, ${finalColor.a})` }">
9
- </div>
10
- </div>
11
- <Teleport to="body">
12
- <transition
13
- :enter-active-class="scale.enterActive"
14
- :leave-active-class="scale.leaveActive"
15
- :enter-from-class="scale.enterFrom"
16
- :leave-to-class="scale.leaveTo"
17
- >
18
- <div :class="style.container" v-if="isOpen" ref="popper" :style="{zIndex: zIndex}">
19
- <div ref="picker" @mousedown="handleMouseDown" :class="style.colours"
20
- :style="`background: rgb(${mainColor.r}, ${mainColor.g}, ${mainColor.b});` ">
21
- <div :class="style.whiteGradient"></div>
22
- <div :class="style.blackGradient"></div>
23
- <div :class="style.sliderThumb" @mousedown="handleMouseDown" @dragover.prevent=""
24
- :style="{ left: `${position.x * 100}%`, top: `${position.y * 100}%` }"></div>
25
- </div>
26
-
27
- <div :class="style.colorActions">
28
- <template v-if="canPickColor">
29
- <button role="button" :disabled="!canPickColor" :class="style.eyeDrop" @click="openEyeDropper">
30
- <svg
31
- width="24"
32
- height="24"
33
- viewBox="0 0 24 24"
34
- fill="none"
35
- xmlns="http://www.w3.org/2000/svg"
36
- >
37
- <path
38
- d="M20.3847 2.87868C19.2132 1.70711 17.3137 1.70711 16.1421 2.87868L14.0202 5.00052L13.313 4.29332C12.9225 3.9028 12.2894 3.9028 11.8988 4.29332C11.5083 4.68385 11.5083 5.31701 11.8988 5.70754L17.5557 11.3644C17.9462 11.7549 18.5794 11.7549 18.9699 11.3644C19.3604 10.9739 19.3604 10.3407 18.9699 9.95018L18.2629 9.24316L20.3847 7.12132C21.5563 5.94975 21.5563 4.05025 20.3847 2.87868Z"
39
- fill="currentColor"
40
- />
41
- <path
42
- fill-rule="evenodd"
43
- clip-rule="evenodd"
44
- d="M11.9297 7.09116L4.1515 14.8693C3.22786 15.793 3.03239 17.169 3.5651 18.2842L1.99994 19.8493L3.41415 21.2635L4.97931 19.6984C6.09444 20.2311 7.4705 20.0356 8.39414 19.112L16.1723 11.3338L11.9297 7.09116ZM13.3439 11.3338L11.9297 9.91959L5.56571 16.2835C5.17518 16.6741 5.17518 17.3072 5.56571 17.6978C5.95623 18.0883 6.5894 18.0883 6.97992 17.6978L13.3439 11.3338Z"
45
- fill="currentColor"
46
- />
47
- </svg>
48
- </button>
49
- </template>
50
- <template v-else>
51
- <div :class="style.preview">
52
- <div
53
- :style="`width: 100%; height: 100%; background-color: rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, ${finalColor.a});`">
54
- </div>
55
- </div>
56
- </template>
57
- <div style="width: 100%; display: flex; flex-direction: column; gap: 10px;">
58
- <MSlider v-model="hueSlider"
59
- background="linear-gradient(to right, #FF0000, #FFFF00, #00FF00, #00FFFF, #0000FF, #FF00FF, #FF0000)">
60
- </MSlider>
61
-
62
- <MSlider v-model="opacitySlider"
63
- :background="`linear-gradient(to right, rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, 0), rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, 1))`">
64
- </MSlider>
65
- </div>
66
- </div>
67
-
68
- <div
69
- :class="style.colorActions">
70
- <template v-if="rgbOrHex">
71
- <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="rInputElement"
72
- v-model="rInput"
73
- name="r" placeholder="R"/>
74
- <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="gInputElement"
75
- v-model="gInput"
76
- name="g" placeholder="G"/>
77
- <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="bInputElement"
78
- v-model="bInput"
79
- name="b" placeholder="B"/>
80
- <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="aInputElement"
81
- v-model="aInput"
82
- name="a" placeholder="A"/>
83
- </template>
84
- <template v-else>
85
- <MInput @keyup.enter="updateFromHex" @blur="updateFromHex" block
86
- ref="hexInputElement"
87
- v-model="hexInput" name="hex" placeholder="#00000000"/>
88
- </template>
89
-
90
- <MButton icon @click.prevent="rgbOrHex = !rgbOrHex">
91
- <svg style="width: 18px; height: 18px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
92
- fill="currentColor" class="w-5 h-5">
93
- <path fill-rule="evenodd"
94
- d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z"
95
- clip-rule="evenodd"/>
96
- </svg>
97
- </MButton>
98
- </div>
99
- </div>
100
- </transition>
101
- </Teleport>
102
- </div>
103
- </template>
104
-
105
- <script lang="ts">
106
- import {onClickOutside, useEyeDropper, useMouseInElement, useMousePressed} from '@vueuse/core';
107
- import {computed, defineComponent, onMounted, type PropType, reactive, ref, toRef, watch} from "vue";
108
- import * as style from './style';
109
- import { scale } from "../../styles/transitions.css";
110
- import {hexToRGB, type HSV, HSVToRGBA, HueToRGBA, RGBAToHex, RGBToHSV} from './utils';
111
- import {usePopper} from "../../composables/usePopper";
112
- import type {Placement} from "@popperjs/core";
113
- import {useZIndex} from "../../composables/useZIndex";
114
- import MSlider from "../../components/slider/Slider.vue";
115
- import MButton from "../../components/button/Button.vue";
116
- import MInput from "../../components/input/Input.vue";
117
-
118
- export default defineComponent({
119
- name: "MColorPicker",
120
- props: {
121
- modelValue: {
122
- type: String,
123
- default: "#FF00FF"
124
- },
125
- transfer: {
126
- type: Boolean,
127
- default: false
128
- },
129
- placement: {
130
- type: String as PropType<Placement>,
131
- default: "bottom-start"
132
- },
133
- zIndex: {
134
- type: Number
135
- }
136
- },
137
- emits: ['update:modelValue'],
138
- components: {
139
- MSlider,
140
- MInput,
141
- MButton
142
- },
143
- setup(props, {emit}) {
144
- const {isSupported: canPickColor, open: openEyeDrop, sRGBHex: eyeDropColor} = useEyeDropper();
145
- const {nextZIndex} = useZIndex();
146
- const isOpen = ref(false);
147
- const rgbOrHex = ref<boolean>(false);
148
- const hexInput = ref("");
149
- const rInput = ref("");
150
- const gInput = ref("");
151
- const bInput = ref("");
152
- const aInput = ref("");
153
-
154
- const picker = ref<HTMLElement>();
155
- const wrapper = ref<HTMLElement>();
156
- const referenceRef = ref<HTMLElement>();
157
- const transfer = toRef(props, 'transfer');
158
- const placement = toRef(props, 'placement');
159
- const hexInputElement = ref();
160
- const hueSlider = ref(0);
161
- const opacitySlider = ref(100);
162
- const dragging = ref(false);
163
- const position = reactive({
164
- x: 0,
165
- y: 0
166
- });
167
- const zIndex = ref(props.zIndex ?? nextZIndex());
168
-
169
- const {elementX, elementY} = useMouseInElement(picker);
170
- const {pressed} = useMousePressed();
171
- const {popper, transferTo, updatePopper} = usePopper({
172
- reference: referenceRef,
173
- placement,
174
- transfer,
175
- wrapper,
176
- isDrop: false,
177
- offset: [-2, 2]
178
- });
179
- const brightness = computed(() => {
180
- return 1 - position.y;
181
- })
182
-
183
- const saturation = computed(() => {
184
- return position.x;
185
- })
186
-
187
- const finalColor = computed(() => {
188
- return HSVToRGBA(hueSlider.value * 3.6, brightness.value, saturation.value, opacitySlider.value / 100);
189
- });
190
-
191
- const mainColor = computed(() => {
192
- return HueToRGBA(hueSlider.value * 3.6, opacitySlider.value / 100);
193
- });
194
-
195
- const setInputs = () => {
196
- hexInput.value = RGBAToHex(finalColor.value.r, finalColor.value.g, finalColor.value.b, finalColor.value.a);
197
- rInput.value = finalColor.value.r.toString();
198
- gInput.value = finalColor.value.g.toString();
199
- bInput.value = finalColor.value.b.toString();
200
- aInput.value = finalColor.value.a.toFixed(2).toString();
201
-
202
- emit('update:modelValue', hexInput.value);
203
- };
204
-
205
- watch(() => finalColor.value, () => {
206
- setInputs();
207
- });
208
-
209
- const updateFromHSV = (hsv: HSV, alpha: number) => {
210
- position.x = hsv.s;
211
- position.y = 1 - hsv.v;
212
- hueSlider.value = ((1 / 360) * hsv.h) * 100;
213
- opacitySlider.value = alpha * 100;
214
- setInputs();
215
- }
216
-
217
- const updateFromHex = () => {
218
- var color = hexToRGB(hexInput.value, finalColor.value.r, finalColor.value.g, finalColor.value.b, finalColor.value.a);
219
- updateFromHSV(RGBToHSV(color.r, color.g, color.b), color.a);
220
- }
221
-
222
- const updateFromRGB = () => {
223
- var red = parseInt(rInput.value);
224
- if (isNaN(red) || red > 255 || red < 0) {
225
- red = finalColor.value.r;
226
- }
227
-
228
- var green = parseInt(gInput.value);
229
- if (isNaN(green) || green > 255 || green < 0) {
230
- green = finalColor.value.g;
231
- }
232
-
233
- var blue = parseInt(bInput.value);
234
- if (isNaN(blue) || blue > 255 || blue < 0) {
235
- blue = finalColor.value.b;
236
- }
237
-
238
- var alpha = parseFloat(aInput.value);
239
- if (isNaN(alpha) || alpha > 1 || alpha < 0) {
240
- alpha = finalColor.value.a;
241
- }
242
-
243
- updateFromHSV(RGBToHSV(red, green, blue), alpha);
244
- };
245
-
246
- watch(() => pressed.value, () => {
247
- if (!pressed.value) {
248
- dragging.value = false;
249
- }
250
- });
251
-
252
- watch(() => [elementX.value, elementY.value], () => {
253
- if (!dragging.value) {
254
- return;
255
- }
256
-
257
- setThumbPosition();
258
- });
259
-
260
- watch(() => props.modelValue, () => {
261
- hexInput.value = props.modelValue;
262
- updateFromHex();
263
- console.log('hi');
264
- });
265
-
266
- const setThumbPosition = () => {
267
- position.x = ((Math.min(Math.max(elementX.value, 0), picker.value?.clientWidth || 0) / (picker.value?.clientWidth || 0)));
268
- position.y = ((Math.min(Math.max(elementY.value, 0), picker.value?.clientHeight || 0) / (picker.value?.clientHeight || 0)));
269
- };
270
-
271
- const handleMouseDown = () => {
272
- dragging.value = true;
273
- setThumbPosition();
274
- };
275
-
276
- onMounted(() => {
277
- hexInput.value = props.modelValue;
278
- updateFromHex();
279
- });
280
-
281
- onClickOutside(popper, (e) => {
282
- isOpen.value = false;
283
- });
284
-
285
- watch(() => eyeDropColor.value, () => {
286
- hexInput.value = eyeDropColor.value;
287
- updateFromHex();
288
- });
289
-
290
- const openEyeDropper = () => {
291
- try {
292
- openEyeDrop();
293
- } catch (e) {
294
- console.log(e);
295
- }
296
- }
297
-
298
- return {
299
- isOpen,
300
- popper,
301
- transferTo,
302
- wrapper,
303
- referenceRef,
304
- updateFromRGB,
305
- updateFromHex,
306
- setInputs,
307
- rgbOrHex,
308
- hexInputElement,
309
- hexInput,
310
- rInput,
311
- gInput,
312
- bInput,
313
- aInput,
314
- finalColor,
315
- hueSlider,
316
- opacitySlider,
317
- dragging,
318
- setThumbPosition,
319
- position,
320
- elementX,
321
- pressed,
322
- handleMouseDown,
323
- picker,
324
- style,
325
- mainColor,
326
- zIndex,
327
- canPickColor,
328
- openEyeDropper,
329
- scale
330
- };
331
- }
332
- })
333
- </script>
1
+ <template>
2
+ <div ref="wrapper" class="m-color-picker">
3
+ <div ref="referenceRef" @click="isOpen = !isOpen">
4
+ <slot :r="finalColor.r" :g="finalColor.g" :b="finalColor.b" :a="finalColor.a" :hex="hexInput" :transparent="style.transparent">
5
+ <div>
6
+ <div :class="style.referenceColor"
7
+ :style="{ backgroundColor: `rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, ${finalColor.a})` }">
8
+ </div>
9
+ </div>
10
+ </slot>
11
+ </div>
12
+ <Teleport to="body">
13
+ <transition :enter-active-class="scale.enterActive" :leave-active-class="scale.leaveActive"
14
+ :enter-from-class="scale.enterFrom" :leave-to-class="scale.leaveTo">
15
+ <div :class="style.container" v-if="isOpen" ref="popper" :style="{ zIndex: zIndex }">
16
+ <div ref="picker" @mousedown="handleMouseDown" :class="style.colours"
17
+ :style="`background: rgb(${mainColor.r}, ${mainColor.g}, ${mainColor.b});`">
18
+ <div :class="style.whiteGradient"></div>
19
+ <div :class="style.blackGradient"></div>
20
+ <div :class="style.sliderThumb" @mousedown="handleMouseDown" @dragover.prevent=""
21
+ :style="{ left: `${position.x * 100}%`, top: `${position.y * 100}%` }"></div>
22
+ </div>
23
+
24
+ <div :class="style.colorActions">
25
+ <template v-if="canPickColor">
26
+ <button role="button" :disabled="!canPickColor" :class="style.eyeDrop"
27
+ @click="openEyeDropper">
28
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none"
29
+ xmlns="http://www.w3.org/2000/svg">
30
+ <path
31
+ d="M20.3847 2.87868C19.2132 1.70711 17.3137 1.70711 16.1421 2.87868L14.0202 5.00052L13.313 4.29332C12.9225 3.9028 12.2894 3.9028 11.8988 4.29332C11.5083 4.68385 11.5083 5.31701 11.8988 5.70754L17.5557 11.3644C17.9462 11.7549 18.5794 11.7549 18.9699 11.3644C19.3604 10.9739 19.3604 10.3407 18.9699 9.95018L18.2629 9.24316L20.3847 7.12132C21.5563 5.94975 21.5563 4.05025 20.3847 2.87868Z"
32
+ fill="currentColor"/>
33
+ <path fill-rule="evenodd" clip-rule="evenodd"
34
+ d="M11.9297 7.09116L4.1515 14.8693C3.22786 15.793 3.03239 17.169 3.5651 18.2842L1.99994 19.8493L3.41415 21.2635L4.97931 19.6984C6.09444 20.2311 7.4705 20.0356 8.39414 19.112L16.1723 11.3338L11.9297 7.09116ZM13.3439 11.3338L11.9297 9.91959L5.56571 16.2835C5.17518 16.6741 5.17518 17.3072 5.56571 17.6978C5.95623 18.0883 6.5894 18.0883 6.97992 17.6978L13.3439 11.3338Z"
35
+ fill="currentColor"/>
36
+ </svg>
37
+ </button>
38
+ </template>
39
+ <template v-else>
40
+ <div :class="style.preview">
41
+ <div
42
+ :style="`width: 100%; height: 100%; background-color: rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, ${finalColor.a});`">
43
+ </div>
44
+ </div>
45
+ </template>
46
+ <div style="width: 100%; display: flex; flex-direction: column; gap: 10px;">
47
+ <MSlider v-model="hueSlider"
48
+ background="linear-gradient(to right, #FF0000, #FFFF00, #00FF00, #00FFFF, #0000FF, #FF00FF, #FF0000)">
49
+ </MSlider>
50
+
51
+ <MSlider v-model="opacitySlider"
52
+ :background="`linear-gradient(to right, rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, 0), rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, 1))`">
53
+ </MSlider>
54
+ </div>
55
+ </div>
56
+
57
+ <div :class="style.colorActions">
58
+ <template v-if="rgbOrHex">
59
+ <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="rInputElement"
60
+ v-model="rInput" name="r" placeholder="R"/>
61
+ <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="gInputElement"
62
+ v-model="gInput" name="g" placeholder="G"/>
63
+ <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="bInputElement"
64
+ v-model="bInput" name="b" placeholder="B"/>
65
+ <MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="aInputElement"
66
+ v-model="aInput" name="a" placeholder="A"/>
67
+ </template>
68
+ <template v-else>
69
+ <MInput @keyup.enter="updateFromHex" @blur="updateFromHex" block ref="hexInputElement"
70
+ v-model="hexInput" name="hex" placeholder="#00000000"/>
71
+ </template>
72
+
73
+ <MButton icon @click.prevent="rgbOrHex = !rgbOrHex">
74
+
75
+ <svg style="width: 18px; height: 18px;" xmlns="http://www.w3.org/2000/svg"
76
+ viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5">
77
+ <path fill-rule="evenodd"
78
+ d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z"
79
+ clip-rule="evenodd"/>
80
+ </svg>
81
+
82
+ </MButton>
83
+ </div>
84
+ </div>
85
+ </transition>
86
+ </Teleport>
87
+ </div>
88
+ </template>
89
+
90
+ <script lang="ts">
91
+ import {onClickOutside, useEyeDropper, useMouseInElement, useMousePressed} from '@vueuse/core';
92
+ import {computed, defineComponent, onMounted, type PropType, reactive, ref, toRef, watch} from "vue";
93
+ import * as style from './style';
94
+ import {scale} from "../../styles/transitions.css";
95
+ import {hexToRGB, type HSV, HSVToRGBA, HueToRGBA, RGBAToHex, RGBToHSV} from './utils';
96
+ import {usePopper} from "../../composables/usePopper";
97
+ import type {Placement} from "@popperjs/core";
98
+ import {useZIndex} from "../../composables/useZIndex";
99
+ import MSlider from "../../components/slider/Slider.vue";
100
+ import MButton from "../../components/button/Button.vue";
101
+ import MInput from "../../components/input/Input.vue";
102
+
103
+ export default defineComponent({
104
+ name: "MColorPicker",
105
+ props: {
106
+ modelValue: {
107
+ type: String,
108
+ default: "#FFFFFF"
109
+ },
110
+ transfer: {
111
+ type: Boolean,
112
+ default: false
113
+ },
114
+ placement: {
115
+ type: String as PropType<Placement>,
116
+ default: "bottom-start"
117
+ },
118
+ zIndex: {
119
+ type: Number
120
+ },
121
+ defaultColor: {
122
+ type: String,
123
+ default: "#FFFFFF"
124
+ }
125
+ },
126
+ emits: ['update:modelValue'],
127
+ components: {
128
+ MSlider,
129
+ MInput,
130
+ MButton
131
+ },
132
+ setup(props, {emit}) {
133
+ const {isSupported: canPickColor, open: openEyeDrop, sRGBHex: eyeDropColor} = useEyeDropper();
134
+ const {nextZIndex} = useZIndex();
135
+ const isOpen = ref(false);
136
+ const rgbOrHex = ref<boolean>(false);
137
+ const hexInput = ref("");
138
+ const rInput = ref("");
139
+ const gInput = ref("");
140
+ const bInput = ref("");
141
+ const aInput = ref("");
142
+
143
+ const picker = ref<HTMLElement>();
144
+ const wrapper = ref<HTMLElement>();
145
+ const referenceRef = ref<HTMLElement>();
146
+ const transfer = toRef(props, 'transfer');
147
+ const placement = toRef(props, 'placement');
148
+ const hexInputElement = ref();
149
+ const hueSlider = ref(0);
150
+ const opacitySlider = ref(100);
151
+ const dragging = ref(false);
152
+ const position = reactive({
153
+ x: 0,
154
+ y: 0
155
+ });
156
+ const zIndex = ref(props.zIndex ?? nextZIndex());
157
+
158
+ const {elementX, elementY} = useMouseInElement(picker);
159
+ const {pressed} = useMousePressed();
160
+ const {popper, transferTo, updatePopper} = usePopper({
161
+ reference: referenceRef,
162
+ placement,
163
+ transfer,
164
+ wrapper,
165
+ isDrop: false,
166
+ offset: [-2, 2]
167
+ });
168
+ const brightness = computed(() => {
169
+ return 1 - position.y;
170
+ })
171
+
172
+ const saturation = computed(() => {
173
+ return position.x;
174
+ })
175
+
176
+ const finalColor = computed(() => {
177
+ return HSVToRGBA(hueSlider.value * 3.6, brightness.value, saturation.value, opacitySlider.value / 100);
178
+ });
179
+
180
+ const mainColor = computed(() => {
181
+ return HueToRGBA(hueSlider.value * 3.6, opacitySlider.value / 100);
182
+ });
183
+
184
+ const setInputs = () => {
185
+ hexInput.value = RGBAToHex(finalColor.value.r, finalColor.value.g, finalColor.value.b, finalColor.value.a);
186
+ rInput.value = finalColor.value.r.toString();
187
+ gInput.value = finalColor.value.g.toString();
188
+ bInput.value = finalColor.value.b.toString();
189
+ aInput.value = finalColor.value.a.toFixed(2).toString();
190
+
191
+ emit('update:modelValue', hexInput.value);
192
+ };
193
+
194
+ watch(() => finalColor.value, () => {
195
+ setInputs();
196
+ });
197
+
198
+ const updateFromHSV = (hsv: HSV, alpha: number) => {
199
+ position.x = hsv.s;
200
+ position.y = 1 - hsv.v;
201
+ hueSlider.value = ((1 / 360) * hsv.h) * 100;
202
+ opacitySlider.value = alpha * 100;
203
+ setInputs();
204
+ }
205
+
206
+ const updateFromHex = () => {
207
+ let color = hexToRGB(hexInput.value, finalColor.value.r, finalColor.value.g, finalColor.value.b, finalColor.value.a);
208
+ updateFromHSV(RGBToHSV(color.r, color.g, color.b), color.a);
209
+ }
210
+
211
+ const updateFromRGB = () => {
212
+ let red = parseInt(rInput.value);
213
+ if (isNaN(red) || red > 255 || red < 0) {
214
+ red = finalColor.value.r;
215
+ }
216
+
217
+ let green = parseInt(gInput.value);
218
+ if (isNaN(green) || green > 255 || green < 0) {
219
+ green = finalColor.value.g;
220
+ }
221
+
222
+ let blue = parseInt(bInput.value);
223
+ if (isNaN(blue) || blue > 255 || blue < 0) {
224
+ blue = finalColor.value.b;
225
+ }
226
+
227
+ let alpha = parseFloat(aInput.value);
228
+ if (isNaN(alpha) || alpha > 1 || alpha < 0) {
229
+ alpha = finalColor.value.a;
230
+ }
231
+
232
+ updateFromHSV(RGBToHSV(red, green, blue), alpha);
233
+ };
234
+
235
+ watch(() => pressed.value, () => {
236
+ if (!pressed.value) {
237
+ dragging.value = false;
238
+ }
239
+ });
240
+
241
+ watch(() => [elementX.value, elementY.value], () => {
242
+ if (!dragging.value) {
243
+ return;
244
+ }
245
+
246
+ setThumbPosition();
247
+ });
248
+
249
+ const setDefaultColor = () => {
250
+ hexInput.value
251
+ }
252
+
253
+ watch(() => props.modelValue, (newValue) => {
254
+ let val = props.modelValue;
255
+ if (!newValue || newValue.trim() === "") {
256
+ val = props.defaultColor || "#FFFFFF"
257
+ }
258
+ hexInput.value = val;
259
+ updateFromHex();
260
+
261
+ });
262
+
263
+ const setThumbPosition = () => {
264
+ position.x = ((Math.min(Math.max(elementX.value, 0), picker.value?.clientWidth || 0) / (picker.value?.clientWidth || 0)));
265
+ position.y = ((Math.min(Math.max(elementY.value, 0), picker.value?.clientHeight || 0) / (picker.value?.clientHeight || 0)));
266
+ };
267
+
268
+ const handleMouseDown = () => {
269
+ dragging.value = true;
270
+ setThumbPosition();
271
+ };
272
+
273
+ onMounted(() => {
274
+ hexInput.value = props.modelValue;
275
+ updateFromHex();
276
+ });
277
+
278
+ onClickOutside(popper, (e) => {
279
+ isOpen.value = false;
280
+ });
281
+
282
+ watch(() => eyeDropColor.value, () => {
283
+ hexInput.value = eyeDropColor.value;
284
+ updateFromHex();
285
+ });
286
+
287
+ const openEyeDropper = () => {
288
+ try {
289
+ openEyeDrop();
290
+ } catch (e) {
291
+ console.log(e);
292
+ }
293
+ }
294
+
295
+ return {
296
+ isOpen,
297
+ popper,
298
+ transferTo,
299
+ wrapper,
300
+ referenceRef,
301
+ updateFromRGB,
302
+ updateFromHex,
303
+ setInputs,
304
+ rgbOrHex,
305
+ hexInputElement,
306
+ hexInput,
307
+ rInput,
308
+ gInput,
309
+ bInput,
310
+ aInput,
311
+ finalColor,
312
+ hueSlider,
313
+ opacitySlider,
314
+ dragging,
315
+ setThumbPosition,
316
+ position,
317
+ elementX,
318
+ pressed,
319
+ handleMouseDown,
320
+ picker,
321
+ style,
322
+ mainColor,
323
+ zIndex,
324
+ canPickColor,
325
+ openEyeDropper,
326
+ scale
327
+ };
328
+ }
329
+ })
330
+ </script>