@teammodlr/ui-kit 2.3.7 → 2.3.10
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.
package/package.json
CHANGED
|
@@ -72,15 +72,8 @@
|
|
|
72
72
|
v-model="aInput" name="a" placeholder="A" />
|
|
73
73
|
</template>
|
|
74
74
|
<template v-else>
|
|
75
|
-
<MInput
|
|
76
|
-
|
|
77
|
-
@blur="commitHexInput"
|
|
78
|
-
v-model="hexInputUser"
|
|
79
|
-
block
|
|
80
|
-
ref="hexInputElement"
|
|
81
|
-
name="hex"
|
|
82
|
-
placeholder="#00000000"
|
|
83
|
-
/>
|
|
75
|
+
<MInput @keyup.enter="commitHexInput" @blur="commitHexInput" v-model="hexInputUser" block
|
|
76
|
+
ref="hexInputElement" name="hex" placeholder="#00000000" />
|
|
84
77
|
</template>
|
|
85
78
|
|
|
86
79
|
<MButton icon @click.prevent="rgbOrHex = !rgbOrHex">
|
|
@@ -253,13 +246,14 @@ export default defineComponent({
|
|
|
253
246
|
}
|
|
254
247
|
|
|
255
248
|
let hex = hexInput.value.replace("#", "");
|
|
249
|
+
debugger;
|
|
256
250
|
if (hex.length === 3) {
|
|
257
251
|
hex = hex.split("").map(char => char + char).join("");
|
|
258
252
|
}
|
|
259
253
|
const color = hexToRGB(`#${hex}`);
|
|
260
254
|
if (color.a === 0) {
|
|
261
|
-
color.a =
|
|
262
|
-
opacitySlider.value =
|
|
255
|
+
color.a = 0;
|
|
256
|
+
opacitySlider.value = 0;
|
|
263
257
|
}
|
|
264
258
|
|
|
265
259
|
updateFromHSV(RGBToHSV(color.r, color.g, color.b), color.a);
|
|
@@ -353,10 +347,26 @@ export default defineComponent({
|
|
|
353
347
|
};
|
|
354
348
|
|
|
355
349
|
onMounted(() => {
|
|
356
|
-
|
|
350
|
+
const match = props.modelValue.match(/rgba?\s*\(\s*(\d{1,3})\s*[,\s]\s*(\d{1,3})\s*[,\s]\s*(\d{1,3})\s*(?:[,\s]\s*([\d.]+%?))?\s*\)/i);
|
|
351
|
+
|
|
352
|
+
if (match) {
|
|
353
|
+
const [_, r, g, b, a] = match;
|
|
354
|
+
const alpha = a !== undefined
|
|
355
|
+
? a.endsWith('%')
|
|
356
|
+
? parseFloat(a) / 100
|
|
357
|
+
: parseFloat(a)
|
|
358
|
+
: 1.0;
|
|
359
|
+
|
|
360
|
+
hexInput.value = RGBAToHex(parseInt(r), parseInt(g), parseInt(b), alpha);
|
|
361
|
+
|
|
362
|
+
} else {
|
|
363
|
+
hexInput.value = props.modelValue;
|
|
364
|
+
}
|
|
365
|
+
|
|
357
366
|
updateFromHex();
|
|
358
367
|
});
|
|
359
368
|
|
|
369
|
+
|
|
360
370
|
onClickOutside(popper, (e) => {
|
|
361
371
|
isOpen.value = false;
|
|
362
372
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<MColorPicker v-model.lazy="colorValue" style="display: inline-block;">
|
|
5
5
|
<template #default="{ r, g, b, hex, transparent }">
|
|
6
6
|
<div :class="transparent"
|
|
7
|
-
|
|
7
|
+
style="width: 100px; height: 100px; border: 1px solid black; position: relative; overflow: hidden;">
|
|
8
8
|
<div style="position: absolute; inset: 0" :style="{ backgroundColor: hex }"></div>
|
|
9
9
|
</div>
|
|
10
10
|
</template>
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
export default {
|
|
17
17
|
data() {
|
|
18
18
|
return {
|
|
19
|
-
colorValue: '
|
|
19
|
+
colorValue: 'rgba(0,0,0,50%)' // Initial color value
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
};
|
|
@@ -1,206 +1,205 @@
|
|
|
1
|
-
export interface Color {
|
|
2
|
-
r: number;
|
|
3
|
-
g: number;
|
|
4
|
-
b: number;
|
|
5
|
-
a: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface HSV {
|
|
9
|
-
h: number;
|
|
10
|
-
s: number;
|
|
11
|
-
v: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const RGBAToHex = (
|
|
15
|
-
r: number,
|
|
16
|
-
g: number,
|
|
17
|
-
b: number,
|
|
18
|
-
a: number
|
|
19
|
-
): string => {
|
|
20
|
-
const hexR
|
|
21
|
-
const hexG
|
|
22
|
-
const hexB
|
|
23
|
-
const hexA
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
let
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
hue
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
let
|
|
126
|
-
let
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
let
|
|
165
|
-
let
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
};
|
|
1
|
+
export interface Color {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface HSV {
|
|
9
|
+
h: number;
|
|
10
|
+
s: number;
|
|
11
|
+
v: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const RGBAToHex = (
|
|
15
|
+
r: number,
|
|
16
|
+
g: number,
|
|
17
|
+
b: number,
|
|
18
|
+
a: number
|
|
19
|
+
): string => {
|
|
20
|
+
const hexR = r.toString(16).padStart(2, '0');
|
|
21
|
+
const hexG = g.toString(16).padStart(2, '0');
|
|
22
|
+
const hexB = b.toString(16).padStart(2, '0');
|
|
23
|
+
const hexA = Math.round(a * 255).toString(16).padStart(2, '0');
|
|
24
|
+
|
|
25
|
+
return a === 1 ? `#${hexR}${hexG}${hexB}` : `#${hexR}${hexG}${hexB}${hexA}`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export const hexToRGB = (
|
|
30
|
+
hexColor: string,
|
|
31
|
+
defaultR = 0,
|
|
32
|
+
defaultG = 0,
|
|
33
|
+
defaultB = 0,
|
|
34
|
+
defaultA = 0
|
|
35
|
+
): Color => {
|
|
36
|
+
hexColor = hexColor.replace('#', '');
|
|
37
|
+
|
|
38
|
+
let r = defaultR;
|
|
39
|
+
let g = defaultG;
|
|
40
|
+
let b = defaultB;
|
|
41
|
+
let a = defaultA;
|
|
42
|
+
|
|
43
|
+
if (hexColor.length >= 2) {
|
|
44
|
+
r = parseInt(hexColor.substring(0, 2), 16);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (hexColor.length >= 4) {
|
|
48
|
+
g = parseInt(hexColor.substring(2, 4), 16);
|
|
49
|
+
} else {
|
|
50
|
+
g = 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (hexColor.length >= 6) {
|
|
54
|
+
b = parseInt(hexColor.substring(4, 6), 16);
|
|
55
|
+
} else {
|
|
56
|
+
b = 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (hexColor.length >= 8) {
|
|
60
|
+
a = parseInt(hexColor.substring(6, 8), 16) / 255;
|
|
61
|
+
} else {
|
|
62
|
+
a = 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (isNaN(r) || isNaN(g) || isNaN(b) || isNaN(a)) {
|
|
66
|
+
r = 0;
|
|
67
|
+
b = 0;
|
|
68
|
+
g = 0;
|
|
69
|
+
a = 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
r,
|
|
74
|
+
g,
|
|
75
|
+
b,
|
|
76
|
+
a
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const RGBToHSV = (r: number, g: number, b: number): HSV => {
|
|
81
|
+
const max = Math.max(r, g, b);
|
|
82
|
+
const min = Math.min(r, g, b);
|
|
83
|
+
|
|
84
|
+
const delta = max - min;
|
|
85
|
+
const brightness = max;
|
|
86
|
+
let saturation = 0;
|
|
87
|
+
if (max !== 0) {
|
|
88
|
+
saturation = delta / max;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let hue = 0;
|
|
92
|
+
if (delta !== 0) {
|
|
93
|
+
if (max === r) {
|
|
94
|
+
hue = ((g - b) / delta) % 6;
|
|
95
|
+
} else if (max === g) {
|
|
96
|
+
hue = (b - r) / delta + 2;
|
|
97
|
+
} else {
|
|
98
|
+
hue = (r - g) / delta + 4;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
hue *= 60;
|
|
102
|
+
if (hue < 0) {
|
|
103
|
+
hue += 360;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
h: hue,
|
|
109
|
+
s: saturation,
|
|
110
|
+
v: brightness / 255
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const HSVToRGBA = (
|
|
115
|
+
hue: number,
|
|
116
|
+
brightness: number,
|
|
117
|
+
saturation: number,
|
|
118
|
+
alpha: number
|
|
119
|
+
): Color => {
|
|
120
|
+
const hueInDegrees = hue;
|
|
121
|
+
const chroma = brightness * saturation;
|
|
122
|
+
const hue1 = hueInDegrees / 60;
|
|
123
|
+
const x = chroma * (1 - Math.abs((hue1 % 2) - 1));
|
|
124
|
+
let r1 = 0;
|
|
125
|
+
let g1 = 0;
|
|
126
|
+
let b1 = 0;
|
|
127
|
+
if (hue1 >= 0 && hue1 < 1) {
|
|
128
|
+
r1 = chroma;
|
|
129
|
+
g1 = x;
|
|
130
|
+
} else if (hue1 >= 1 && hue1 < 2) {
|
|
131
|
+
r1 = x;
|
|
132
|
+
g1 = chroma;
|
|
133
|
+
} else if (hue1 >= 2 && hue1 < 3) {
|
|
134
|
+
g1 = chroma;
|
|
135
|
+
b1 = x;
|
|
136
|
+
} else if (hue1 >= 3 && hue1 < 4) {
|
|
137
|
+
g1 = x;
|
|
138
|
+
b1 = chroma;
|
|
139
|
+
} else if (hue1 >= 4 && hue1 < 5) {
|
|
140
|
+
r1 = x;
|
|
141
|
+
b1 = chroma;
|
|
142
|
+
} else {
|
|
143
|
+
r1 = chroma;
|
|
144
|
+
b1 = x;
|
|
145
|
+
}
|
|
146
|
+
const m = brightness - chroma;
|
|
147
|
+
const r = Math.round((r1 + m) * 255);
|
|
148
|
+
const g = Math.round((g1 + m) * 255);
|
|
149
|
+
const b = Math.round((b1 + m) * 255);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
r,
|
|
153
|
+
g,
|
|
154
|
+
b,
|
|
155
|
+
a: alpha
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const HueToRGBA = (hue: number, alpha: number): Color => {
|
|
160
|
+
const chroma = 1 - Math.abs(2 * 0.5 - 1);
|
|
161
|
+
const huePrime = (hue / 360) * 6;
|
|
162
|
+
const intermediateValue = chroma * (1 - Math.abs((huePrime % 2) - 1));
|
|
163
|
+
let red = 0;
|
|
164
|
+
let green = 0;
|
|
165
|
+
let blue = 0;
|
|
166
|
+
|
|
167
|
+
if (huePrime >= 0 && huePrime < 1) {
|
|
168
|
+
red = chroma;
|
|
169
|
+
green = intermediateValue;
|
|
170
|
+
blue = 0;
|
|
171
|
+
} else if (huePrime >= 1 && huePrime < 2) {
|
|
172
|
+
red = intermediateValue;
|
|
173
|
+
green = chroma;
|
|
174
|
+
blue = 0;
|
|
175
|
+
} else if (huePrime >= 2 && huePrime < 3) {
|
|
176
|
+
red = 0;
|
|
177
|
+
green = chroma;
|
|
178
|
+
blue = intermediateValue;
|
|
179
|
+
} else if (huePrime >= 3 && huePrime < 4) {
|
|
180
|
+
red = 0;
|
|
181
|
+
green = intermediateValue;
|
|
182
|
+
blue = chroma;
|
|
183
|
+
} else if (huePrime >= 4 && huePrime < 5) {
|
|
184
|
+
red = intermediateValue;
|
|
185
|
+
green = 0;
|
|
186
|
+
blue = chroma;
|
|
187
|
+
} else {
|
|
188
|
+
red = chroma;
|
|
189
|
+
green = 0;
|
|
190
|
+
blue = intermediateValue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const lightnessDecimal = 0.5;
|
|
194
|
+
const lightnessAdjustment = (1 - chroma) * (lightnessDecimal - 0.5);
|
|
195
|
+
const finalRed = Math.round((red + lightnessAdjustment) * 255);
|
|
196
|
+
const finalGreen = Math.round((green + lightnessAdjustment) * 255);
|
|
197
|
+
const finalBlue = Math.round((blue + lightnessAdjustment) * 255);
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
r: finalRed,
|
|
201
|
+
g: finalGreen,
|
|
202
|
+
b: finalBlue,
|
|
203
|
+
a: alpha
|
|
204
|
+
};
|
|
205
|
+
};
|