@opentiny/vue-renderless 3.19.4 → 3.20.0
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/base-select/index.js +11 -74
- package/base-select/vue.js +10 -10
- package/bulletin-board/index.js +5 -1
- package/bulletin-board/vue.js +5 -4
- package/button/index.js +11 -3
- package/button/vue.js +6 -2
- package/button-group/index.js +1 -1
- package/color-picker/index.js +4 -4
- package/color-picker/utils/color.js +358 -83
- package/color-picker/utils/hsv-to-rgb.js +59 -0
- package/color-picker/vue.js +27 -8
- package/color-select-panel/alpha-select/index.js +65 -14
- package/color-select-panel/alpha-select/vue.js +29 -44
- package/color-select-panel/hue-select/index.js +47 -61
- package/color-select-panel/hue-select/vue.js +29 -47
- package/color-select-panel/index.js +230 -80
- package/color-select-panel/sv-select/index.js +68 -0
- package/color-select-panel/sv-select/vue.js +32 -0
- package/color-select-panel/utils/color.js +345 -82
- package/color-select-panel/utils/getClientXY.js +54 -0
- package/color-select-panel/vue.js +48 -72
- package/common/deps/popper.js +1 -1
- package/common/deps/useUserAgent.js +16 -0
- package/common/event.js +21 -0
- package/common/index.js +1 -1
- package/common/runtime.js +1 -1
- package/date-picker-mobile/index.js +4 -4
- package/dialog-box/index.js +1 -1
- package/dropdown/index.js +5 -1
- package/dropdown/vue.js +2 -2
- package/file-upload/vue.js +1 -0
- package/flowchart/index.js +3 -2
- package/form/index.js +2 -2
- package/form-item/index.js +4 -1
- package/grid-select/index.js +82 -0
- package/grid-select/vue.js +30 -0
- package/input/index.js +2 -2
- package/menu/vue.js +5 -1
- package/modal/index.js +2 -0
- package/numeric/index.js +29 -9
- package/option/index.js +6 -0
- package/option/vue.js +12 -2
- package/package.json +1 -1
- package/picker/index.js +1 -1
- package/recycle-scroller/index.js +43 -27
- package/recycle-scroller/vue.js +9 -4
- package/rich-text/index.js +13 -0
- package/rich-text/vue.js +4 -2
- package/select/index.js +71 -23
- package/select/vue.js +12 -4
- package/select-dropdown/vue.js +1 -1
- package/tabbar/index.js +4 -1
- package/tabbar/vue.js +1 -1
- package/tabs/index.js +8 -5
- package/tabs/vue.js +4 -1
- package/time-panel/vue.js +1 -1
- package/tooltip/vue.js +1 -0
- package/transfer/index.js +4 -2
- package/transfer/vue.js +2 -2
- package/tree-menu/index.js +5 -1
- package/tree-node/index.js +5 -4
- package/tree-select/index.js +77 -1
- package/tree-select/vue.js +21 -7
- package/types/button.type.d.ts +7 -3
- package/types/color-select-panel.type.d.ts +23 -1
- package/types/file-upload.type.d.ts +1 -1
- package/types/input.type.d.ts +1 -1
- package/types/numeric.type.d.ts +5 -5
- package/types/popover.type.d.ts +1 -1
- package/types/transfer.type.d.ts +4 -4
- package/types/tree-menu.type.d.ts +1 -1
- package/types/upload-dragger.type.d.ts +1 -1
- package/types/{upload-list.type-8d9e2600.d.ts → upload-list.type-1257e07a.d.ts} +7 -3
- package/types/upload-list.type.d.ts +1 -1
- package/types/upload.type.d.ts +1 -1
- package/types/user-head.type.d.ts +4 -0
- package/user-head/index.js +1 -1
- package/year-table/index.js +14 -29
- package/year-table/vue.js +17 -5
|
@@ -1,102 +1,377 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "../../chunk-G2ADBYYC.js";
|
|
5
|
+
const INT_HEX_MAP = {
|
|
6
|
+
10: "A",
|
|
7
|
+
11: "B",
|
|
8
|
+
12: "C",
|
|
9
|
+
13: "D",
|
|
10
|
+
14: "E",
|
|
11
|
+
15: "F"
|
|
12
|
+
};
|
|
13
|
+
const HEX_INT_MAP = {
|
|
14
|
+
A: 10,
|
|
15
|
+
B: 11,
|
|
16
|
+
C: 12,
|
|
17
|
+
D: 13,
|
|
18
|
+
E: 14,
|
|
19
|
+
F: 15
|
|
20
|
+
};
|
|
21
|
+
const parseHex = function(hex) {
|
|
22
|
+
if (hex.length === 2) {
|
|
23
|
+
return (HEX_INT_MAP[hex[0].toUpperCase()] || +hex[0]) * 16 + (HEX_INT_MAP[hex[1].toUpperCase()] || +hex[1]);
|
|
24
|
+
}
|
|
25
|
+
return HEX_INT_MAP[hex[1].toUpperCase()] || +hex[1];
|
|
26
|
+
};
|
|
27
|
+
const hsv2hsl = ({ hue, sat, val }) => {
|
|
28
|
+
const hue_ = (2 - sat) * val;
|
|
29
|
+
return [hue, sat * val / (hue_ < 1 ? hue_ : 2 - hue_) || 0, hue_ / 2];
|
|
30
|
+
};
|
|
31
|
+
const isString = (val) => typeof val === "string";
|
|
32
|
+
const isOnePointZero = (n) => {
|
|
33
|
+
return isString(n) && n.includes(".") && Number.parseFloat(n) === 1;
|
|
34
|
+
};
|
|
35
|
+
const isPercentage = (n) => {
|
|
36
|
+
return isString(n) && n.includes("%");
|
|
37
|
+
};
|
|
38
|
+
const normalized = (value, max) => {
|
|
39
|
+
if (isOnePointZero(value))
|
|
40
|
+
value = "100%";
|
|
41
|
+
const processPercent = isPercentage(value);
|
|
42
|
+
value = Math.min(max, Math.max(0, Number.parseFloat(`${value}`)));
|
|
43
|
+
if (processPercent) {
|
|
44
|
+
value = Number.parseInt(`${value * max}`, 10) / 100;
|
|
45
|
+
}
|
|
46
|
+
if (Math.abs(value - max) < 1e-6) {
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
return value % max / Number.parseFloat(max);
|
|
50
|
+
};
|
|
51
|
+
const hexOne = (value) => {
|
|
52
|
+
value = Math.min(Math.round(value), 255);
|
|
53
|
+
const high = Math.floor(value / 16);
|
|
54
|
+
const low = value % 16;
|
|
55
|
+
return `${INT_HEX_MAP[high] || high}${INT_HEX_MAP[low] || low}`;
|
|
56
|
+
};
|
|
57
|
+
const toHex = ({ r, g, b }) => {
|
|
58
|
+
if (Number.isNaN(+r) || Number.isNaN(+g) || Number.isNaN(+b))
|
|
59
|
+
return "";
|
|
60
|
+
return `#${hexOne(r)}${hexOne(g)}${hexOne(b)}`;
|
|
61
|
+
};
|
|
62
|
+
const hsl2hsv = ({ hue, sat, light }) => {
|
|
63
|
+
sat = sat / 100;
|
|
64
|
+
light = light / 100;
|
|
65
|
+
let smin = sat;
|
|
66
|
+
const lmin = Math.max(light, 0.01);
|
|
67
|
+
light *= 2;
|
|
68
|
+
sat *= light <= 1 ? light : 2 - light;
|
|
69
|
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
70
|
+
const v = (light + sat) / 2;
|
|
71
|
+
const sv = light === 0 ? 2 * smin / (lmin + smin) : 2 * sat / (light + sat);
|
|
72
|
+
return {
|
|
73
|
+
h: hue,
|
|
74
|
+
s: sv * 100,
|
|
75
|
+
v: v * 100
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const rgb2hsv = ({ r, g, b }) => {
|
|
79
|
+
r = normalized(r, 255);
|
|
80
|
+
g = normalized(g, 255);
|
|
81
|
+
b = normalized(b, 255);
|
|
82
|
+
const max = Math.max(r, g, b);
|
|
83
|
+
const min = Math.min(r, g, b);
|
|
84
|
+
let h;
|
|
85
|
+
const v = max;
|
|
86
|
+
const d = max - min;
|
|
87
|
+
const s = max === 0 ? 0 : d / max;
|
|
88
|
+
if (max === min) {
|
|
89
|
+
h = 0;
|
|
90
|
+
} else {
|
|
91
|
+
switch (max) {
|
|
92
|
+
case r: {
|
|
93
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case g: {
|
|
97
|
+
h = (b - r) / d + 2;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case b: {
|
|
101
|
+
h = (r - g) / d + 4;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
h /= 6;
|
|
106
|
+
}
|
|
107
|
+
return { h: h * 360, s: s * 100, v: v * 100 };
|
|
108
|
+
};
|
|
109
|
+
const hsv2rgb = ({ h, s, v }) => {
|
|
110
|
+
h = normalized(h, 360) * 6;
|
|
111
|
+
s = normalized(s, 100);
|
|
112
|
+
v = normalized(v, 100);
|
|
113
|
+
const i = Math.floor(h);
|
|
114
|
+
const f = h - i;
|
|
115
|
+
const p = v * (1 - s);
|
|
116
|
+
const q = v * (1 - f * s);
|
|
117
|
+
const t = v * (1 - (1 - f) * s);
|
|
118
|
+
const mod = i % 6;
|
|
119
|
+
const r = [v, q, p, p, t, v][mod];
|
|
120
|
+
const g = [t, v, v, q, p, p][mod];
|
|
121
|
+
const b = [p, p, t, v, v, q][mod];
|
|
122
|
+
return {
|
|
123
|
+
r: Math.round(r * 255),
|
|
124
|
+
g: Math.round(g * 255),
|
|
125
|
+
b: Math.round(b * 255)
|
|
126
|
+
};
|
|
28
127
|
};
|
|
29
128
|
class Color {
|
|
30
|
-
constructor(
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.a = 100;
|
|
36
|
-
this.preH = 0;
|
|
129
|
+
constructor(opts) {
|
|
130
|
+
this._hue = 0;
|
|
131
|
+
this._sat = 100;
|
|
132
|
+
this._value = 100;
|
|
133
|
+
this._alpha = 100;
|
|
37
134
|
this.enableAlpha = false;
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.
|
|
135
|
+
this.format = "hex";
|
|
136
|
+
this.value = "";
|
|
137
|
+
for (const opt in opts) {
|
|
138
|
+
if (opt in opts) {
|
|
139
|
+
this[opt] = opts[opt];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (opts.value) {
|
|
143
|
+
this.fromString(opts.value);
|
|
144
|
+
} else {
|
|
145
|
+
this.onChange();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
get(prop) {
|
|
149
|
+
if (prop === "alpha") {
|
|
150
|
+
return Math.floor(this._alpha);
|
|
151
|
+
}
|
|
152
|
+
return this[`_${prop}`];
|
|
153
|
+
}
|
|
154
|
+
set(props, value) {
|
|
155
|
+
if (arguments.length === 1 && typeof props === "object") {
|
|
156
|
+
for (const p in props) {
|
|
157
|
+
if (Object.hasOwn(props, p)) {
|
|
158
|
+
this.set(p, props[p]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
47
161
|
return;
|
|
48
162
|
}
|
|
49
|
-
this
|
|
50
|
-
|
|
51
|
-
const { h, s, v } = rgb([r, g, b, a]).hsv().object();
|
|
52
|
-
this.h = h;
|
|
53
|
-
this.s = s;
|
|
54
|
-
this.v = v;
|
|
55
|
-
this.a = a;
|
|
56
|
-
this.preH = h;
|
|
163
|
+
this[`_${props}`] = value;
|
|
164
|
+
this.onChange();
|
|
57
165
|
}
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
this.s = s != null ? s : this.s;
|
|
61
|
-
this.v = v != null ? v : this.v;
|
|
62
|
-
this.a = a != null ? a : this.a;
|
|
166
|
+
compare(color) {
|
|
167
|
+
return Math.abs(color._hue - this._hue) < 2 && Math.abs(color._sat - this._sat) < 1 && Math.abs(color._value - this._value) < 1 && Math.abs(color._alpha - this._alpha) < 1;
|
|
63
168
|
}
|
|
64
|
-
|
|
65
|
-
|
|
169
|
+
isHSL(value) {
|
|
170
|
+
return value.includes("hsl");
|
|
66
171
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return hsv(this.h, this.s, this.v).rgb().array();
|
|
172
|
+
isHsv(value) {
|
|
173
|
+
return value.includes("hsv");
|
|
174
|
+
}
|
|
175
|
+
isRgb(value) {
|
|
176
|
+
return value.includes("rgb");
|
|
73
177
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
178
|
+
isHex(value) {
|
|
179
|
+
return value.includes("#");
|
|
180
|
+
}
|
|
181
|
+
splitPart(value, regExp) {
|
|
182
|
+
return value.replace(regExp, "").split(/\s|,/g).filter((v) => v).map((val, idx) => {
|
|
183
|
+
return idx > 2 ? Number.parseFloat(val) : Number.parseInt(val, 10);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
onHsv(value) {
|
|
187
|
+
const parts = this.splitPart(value, /hsva|hsv|\(|\)/gm);
|
|
188
|
+
if (parts.length === 4) {
|
|
189
|
+
this._alpha = Number.parseFloat(String(parts[3])) * 100;
|
|
190
|
+
} else {
|
|
191
|
+
this._alpha = 100;
|
|
192
|
+
}
|
|
193
|
+
if (parts.length >= 3) {
|
|
194
|
+
this.fromHSV({
|
|
195
|
+
h: parts[0],
|
|
196
|
+
s: parts[1],
|
|
197
|
+
v: parts[2]
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
onRgb(value) {
|
|
202
|
+
const rgbRegExp = /rgba|rgb|\(|\)/gm;
|
|
203
|
+
const parts = this.splitPart(value, rgbRegExp);
|
|
204
|
+
if (parts.length === 4) {
|
|
205
|
+
this._alpha = Number.parseFloat(String(parts[3])) * 100;
|
|
206
|
+
} else {
|
|
207
|
+
this._alpha = 100;
|
|
208
|
+
}
|
|
209
|
+
if (parts.length >= 3) {
|
|
210
|
+
const { h, s, v } = rgb2hsv({ r: parts[0], g: parts[1], b: parts[2] });
|
|
211
|
+
this.fromHSV({ h, s, v });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
onHex(value) {
|
|
215
|
+
const hex = value.replace("#", "").trim();
|
|
216
|
+
const isValidHex = (hex2) => /^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$/.test(hex2);
|
|
217
|
+
if (!isValidHex(hex)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
let [r, g, b] = [0, 0, 0];
|
|
221
|
+
if (hex.length === 3) {
|
|
222
|
+
r = parseHex(hex[0] + hex[0]);
|
|
223
|
+
g = parseHex(hex[1] + hex[1]);
|
|
224
|
+
b = parseHex(hex[2] + hex[2]);
|
|
225
|
+
} else if (hex.length === 6 || hex.length === 8) {
|
|
226
|
+
r = parseHex(hex.slice(0, 2));
|
|
227
|
+
g = parseHex(hex.slice(2, 4));
|
|
228
|
+
b = parseHex(hex.slice(4, 6));
|
|
229
|
+
}
|
|
230
|
+
if (hex.length === 8) {
|
|
231
|
+
this._alpha = parseHex(hex.slice(6)) / 255 * 100;
|
|
232
|
+
} else if (hex.length === 3 || hex.length === 6) {
|
|
233
|
+
this._alpha = 100;
|
|
234
|
+
}
|
|
235
|
+
const { h, s, v } = rgb2hsv({ r, g, b });
|
|
236
|
+
this.fromHSV({ h, s, v });
|
|
237
|
+
}
|
|
238
|
+
onHsl(value) {
|
|
239
|
+
const parts = value.replace(/hsla|hsl\(|\)gm/, "").split(/\s|,/g).filter((val) => val).map((val, idx) => {
|
|
240
|
+
return idx > 2 ? Number.parseFloat(val) : Number.parseInt(val, 10);
|
|
241
|
+
});
|
|
242
|
+
if (parts.length === 4) {
|
|
243
|
+
this._alpha = Number.parseFloat(String(parts[3])) * 100;
|
|
244
|
+
} else {
|
|
245
|
+
this._alpha = 100;
|
|
246
|
+
}
|
|
247
|
+
if (parent.length >= 3) {
|
|
248
|
+
const { h, s, v } = hsl2hsv({
|
|
249
|
+
hue: parts[0],
|
|
250
|
+
sat: parts[1],
|
|
251
|
+
light: parts[2]
|
|
252
|
+
});
|
|
253
|
+
this.fromHSV({ h, s, v });
|
|
77
254
|
}
|
|
78
|
-
return hsv(this.h, this.s, this.v, this.a / 100).hexa().toString();
|
|
79
255
|
}
|
|
80
256
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @returns [h,s,l]
|
|
257
|
+
* @effect 会修改 this._hue, this._sat, this._value
|
|
83
258
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
259
|
+
fromHSV({ h, s, v }) {
|
|
260
|
+
this._hue = Math.max(0, Math.min(360, h));
|
|
261
|
+
this._sat = Math.max(0, Math.min(100, s));
|
|
262
|
+
this._value = Math.max(0, Math.min(100, v));
|
|
263
|
+
this.onChange();
|
|
264
|
+
}
|
|
265
|
+
fromString(value) {
|
|
266
|
+
if (!value) {
|
|
267
|
+
this._hue = 0;
|
|
268
|
+
this._sat = 0;
|
|
269
|
+
this._value = 0;
|
|
270
|
+
this.onChange();
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (this.isHSL(value)) {
|
|
274
|
+
this.onHsl(value);
|
|
275
|
+
}
|
|
276
|
+
if (this.isHsv(value)) {
|
|
277
|
+
this.onHsv(value);
|
|
278
|
+
}
|
|
279
|
+
if (this.isRgb(value)) {
|
|
280
|
+
this.onRgb(value);
|
|
281
|
+
}
|
|
282
|
+
if (this.isHex(value)) {
|
|
283
|
+
this.onHex(value);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
toRgb() {
|
|
287
|
+
return hsv2rgb({
|
|
288
|
+
h: this._hue,
|
|
289
|
+
s: this._sat,
|
|
290
|
+
v: this._value
|
|
291
|
+
});
|
|
86
292
|
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
h: this.
|
|
90
|
-
s: this.
|
|
91
|
-
v: this.
|
|
92
|
-
|
|
93
|
-
|
|
293
|
+
toRgba() {
|
|
294
|
+
return __spreadProps(__spreadValues({}, hsv2rgb({
|
|
295
|
+
h: this._hue,
|
|
296
|
+
s: this._sat,
|
|
297
|
+
v: this._value
|
|
298
|
+
})), {
|
|
299
|
+
a: this._alpha / 100
|
|
300
|
+
});
|
|
94
301
|
}
|
|
95
|
-
|
|
96
|
-
|
|
302
|
+
onChange() {
|
|
303
|
+
const { _hue, _sat, _value, _alpha, format, enableAlpha } = this;
|
|
304
|
+
if (!enableAlpha) {
|
|
305
|
+
switch (format) {
|
|
306
|
+
case "hsl": {
|
|
307
|
+
let [_, sat, light] = hsv2hsl({
|
|
308
|
+
hue: _hue,
|
|
309
|
+
sat: _sat / 100,
|
|
310
|
+
val: _value / 100
|
|
311
|
+
});
|
|
312
|
+
sat = Math.round(sat * 100);
|
|
313
|
+
light = Math.round(light * 100);
|
|
314
|
+
this.value = `hsl(${_hue}, ${sat}%, ${light}%)`;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case "hsv": {
|
|
318
|
+
this.value = `hsv(${_hue}, ${Math.round(_sat)}%, ${Math.round(_value)}%)`;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case "rgb": {
|
|
322
|
+
const { r, g, b } = hsv2rgb({ h: _hue, s: _sat, v: _value });
|
|
323
|
+
this.value = `rgb(${r},${g},${b})`;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
default: {
|
|
327
|
+
this.value = toHex(
|
|
328
|
+
hsv2rgb({
|
|
329
|
+
h: _hue,
|
|
330
|
+
s: _sat,
|
|
331
|
+
v: _value
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
switch (format) {
|
|
339
|
+
case "hsl": {
|
|
340
|
+
let [_, sat, light] = hsv2hsl({
|
|
341
|
+
hue: _hue,
|
|
342
|
+
sat: _sat / 100,
|
|
343
|
+
val: _value / 100
|
|
344
|
+
});
|
|
345
|
+
sat = Math.round(sat * 100);
|
|
346
|
+
light = Math.round(light * 100);
|
|
347
|
+
this.value = `hsla(${_hue}, ${sat}%, ${light}%, ${this.get("alpha") / 100})`;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case "hsv": {
|
|
351
|
+
this.value = `hsva(${_hue}, ${Math.round(_sat)}%, ${Math.round(_value)}%, ${this.get("alpha") / 100})`;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
case "hex": {
|
|
355
|
+
this.value = `${toHex(
|
|
356
|
+
hsv2rgb({
|
|
357
|
+
h: _hue,
|
|
358
|
+
s: _sat,
|
|
359
|
+
v: _value
|
|
360
|
+
})
|
|
361
|
+
)}${hexOne(_alpha * 255 / 100)}`;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
default: {
|
|
365
|
+
const { r, g, b } = hsv2rgb({
|
|
366
|
+
h: _hue,
|
|
367
|
+
s: _sat,
|
|
368
|
+
v: _value
|
|
369
|
+
});
|
|
370
|
+
this.value = `rgba(${r}, ${g}, ${b}, ${this.get("alpha") / 100})`;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
97
373
|
}
|
|
98
374
|
}
|
|
99
375
|
export {
|
|
100
|
-
Color
|
|
101
|
-
normalizeHexColor
|
|
376
|
+
Color
|
|
102
377
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import "../../chunk-G2ADBYYC.js";
|
|
2
|
+
const splitPart = (value, regExp) => {
|
|
3
|
+
return value.replace(regExp, "").split(/\s|,/g).filter((v) => v).map((val, idx) => {
|
|
4
|
+
return idx > 2 ? Number.parseFloat(val) : Number.parseInt(val, 10);
|
|
5
|
+
});
|
|
6
|
+
};
|
|
7
|
+
const parseHSV = (value) => {
|
|
8
|
+
const parts = splitPart(value, /hsva|hsv|\(|\)/gm);
|
|
9
|
+
if (parts.length >= 3) {
|
|
10
|
+
return hsv2rgb({
|
|
11
|
+
h: parts[0],
|
|
12
|
+
s: parts[1],
|
|
13
|
+
v: parts[2]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return { r: 0, g: 0, b: 0 };
|
|
17
|
+
};
|
|
18
|
+
const isString = (val) => typeof val === "string";
|
|
19
|
+
const isOnePointZero = (n) => {
|
|
20
|
+
return isString(n) && n.includes(".") && Number.parseFloat(n) === 1;
|
|
21
|
+
};
|
|
22
|
+
const isPercentage = (n) => {
|
|
23
|
+
return isString(n) && n.includes("%");
|
|
24
|
+
};
|
|
25
|
+
const normalized = (value, max) => {
|
|
26
|
+
if (isOnePointZero(value))
|
|
27
|
+
value = "100%";
|
|
28
|
+
const processPercent = isPercentage(value);
|
|
29
|
+
value = Math.min(max, Math.max(0, Number.parseFloat(`${value}`)));
|
|
30
|
+
if (processPercent) {
|
|
31
|
+
value = Number.parseInt(`${value * max}`, 10) / 100;
|
|
32
|
+
}
|
|
33
|
+
if (Math.abs(value - max) < 1e-6) {
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
return value % max / Number.parseFloat(max);
|
|
37
|
+
};
|
|
38
|
+
const hsv2rgb = ({ h, s, v }) => {
|
|
39
|
+
h = normalized(h, 360) * 6;
|
|
40
|
+
s = normalized(s, 100);
|
|
41
|
+
v = normalized(v, 100);
|
|
42
|
+
const i = Math.floor(h);
|
|
43
|
+
const f = h - i;
|
|
44
|
+
const p = v * (1 - s);
|
|
45
|
+
const q = v * (1 - f * s);
|
|
46
|
+
const t = v * (1 - (1 - f) * s);
|
|
47
|
+
const mod = i % 6;
|
|
48
|
+
const r = [v, q, p, p, t, v][mod];
|
|
49
|
+
const g = [t, v, v, q, p, p][mod];
|
|
50
|
+
const b = [p, p, t, v, v, q][mod];
|
|
51
|
+
return {
|
|
52
|
+
r: Math.round(r * 255),
|
|
53
|
+
g: Math.round(g * 255),
|
|
54
|
+
b: Math.round(b * 255)
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
parseHSV
|
|
59
|
+
};
|
package/color-picker/vue.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "../chunk-G2ADBYYC.js";
|
|
2
|
-
import { toggleVisible, useEvent } from "./index";
|
|
2
|
+
import { updateModelValue, toggleVisible, useEvent } from "./index";
|
|
3
|
+
import { Color } from "./utils/color";
|
|
3
4
|
const api = ["state", "changeVisible", "onConfirm", "onCancel", "onHueUpdate", "onSVUpdate", "onColorUpdate"];
|
|
4
5
|
const renderless = (props, ctx, { emit }) => {
|
|
5
6
|
var _a, _b, _c;
|
|
@@ -28,16 +29,34 @@ const renderless = (props, ctx, { emit }) => {
|
|
|
28
29
|
triggerBg: ctx.ref(modelValue.value),
|
|
29
30
|
size,
|
|
30
31
|
stack,
|
|
31
|
-
predefineStack
|
|
32
|
+
predefineStack,
|
|
33
|
+
enablePredefineColor: ctx.computed(() => props.enablePredefineColor),
|
|
34
|
+
enableHistory: ctx.computed(() => props.enableHistory)
|
|
32
35
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
emit("update:modelValue", hex.value);
|
|
36
|
+
const color = new Color({
|
|
37
|
+
value: props.modelValue,
|
|
38
|
+
format: props.format,
|
|
39
|
+
enableAlpha: props.alpha
|
|
38
40
|
});
|
|
41
|
+
ctx.watch(
|
|
42
|
+
() => [props.alpha, props.format],
|
|
43
|
+
() => {
|
|
44
|
+
color.enableAlpha = props.alpha;
|
|
45
|
+
color.format = props.format || color.format;
|
|
46
|
+
color.onChange();
|
|
47
|
+
updateModelValue(color.value, emit);
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
ctx.watch(
|
|
51
|
+
() => props.modelValue,
|
|
52
|
+
() => {
|
|
53
|
+
color.fromString(props.modelValue);
|
|
54
|
+
const { r, g, b, a } = color.toRgba();
|
|
55
|
+
state.hex = `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
56
|
+
}
|
|
57
|
+
);
|
|
39
58
|
const changeVisible = toggleVisible(isShow);
|
|
40
|
-
const { onConfirm, onCancel } = useEvent(
|
|
59
|
+
const { onConfirm, onCancel } = useEvent(state, emit, changeVisible, color);
|
|
41
60
|
const api2 = {
|
|
42
61
|
state,
|
|
43
62
|
changeVisible,
|
|
@@ -1,20 +1,71 @@
|
|
|
1
1
|
import "../../chunk-G2ADBYYC.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { getClientXY } from "../utils/getClientXY";
|
|
3
|
+
const initState = ({ ref, reactive }) => {
|
|
4
|
+
const background = ref("");
|
|
5
|
+
const left = ref(0);
|
|
6
|
+
const state = reactive({ background, left });
|
|
7
|
+
return state;
|
|
4
8
|
};
|
|
5
|
-
const
|
|
6
|
-
|
|
9
|
+
const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
|
|
10
|
+
const onDrag = (event) => {
|
|
11
|
+
if (!slider.value || !alphaThumb.value) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const el = alphaWrapper.value;
|
|
15
|
+
const rect = el.getBoundingClientRect();
|
|
16
|
+
const { clientX } = getClientXY(event);
|
|
17
|
+
let left = clientX - rect.left;
|
|
18
|
+
left = Math.max(alphaThumb.value.offsetWidth / 2, left);
|
|
19
|
+
left = Math.min(left, rect.width - alphaThumb.value.offsetWidth / 2);
|
|
20
|
+
const alpha = Math.round(
|
|
21
|
+
(left - alphaThumb.value.offsetWidth / 2) / (rect.width - alphaThumb.value.offsetWidth) * 100
|
|
22
|
+
);
|
|
23
|
+
props.color.set("alpha", alpha);
|
|
24
|
+
};
|
|
25
|
+
const onClick = (event) => {
|
|
26
|
+
if (event.target !== alphaThumb.value) {
|
|
27
|
+
onDrag(event);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const getLeft = () => {
|
|
31
|
+
const thumb = alphaThumb.value;
|
|
32
|
+
if (!thumb) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
const el = alphaWrapper.value;
|
|
36
|
+
if (!el) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
const alpha = props.color.get("alpha");
|
|
40
|
+
return alpha * (el.offsetWidth - thumb.offsetWidth / 2) / 100;
|
|
41
|
+
};
|
|
42
|
+
const getBackground = () => {
|
|
43
|
+
if (props.color && props.color.value) {
|
|
44
|
+
const { r, g, b } = props.color.toRgb();
|
|
45
|
+
return `linear-gradient(to right, rgba(${r}, ${g}, ${b}, 0) 0%, rgba(${r}, ${g}, ${b}, 1) 100%)`;
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
48
|
+
};
|
|
49
|
+
const update = () => {
|
|
50
|
+
state.left = getLeft();
|
|
51
|
+
state.background = getBackground();
|
|
52
|
+
};
|
|
53
|
+
return { onDrag, onClick, update };
|
|
7
54
|
};
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
55
|
+
const initWatch = (props, update, { watch }) => {
|
|
56
|
+
watch(
|
|
57
|
+
() => props.color.get("alpha"),
|
|
58
|
+
() => update(),
|
|
59
|
+
{ deep: true }
|
|
60
|
+
);
|
|
61
|
+
watch(
|
|
62
|
+
() => props.color,
|
|
63
|
+
() => update(),
|
|
64
|
+
{ deep: true }
|
|
65
|
+
);
|
|
15
66
|
};
|
|
16
67
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
68
|
+
initState,
|
|
69
|
+
initWatch,
|
|
70
|
+
useEvent
|
|
20
71
|
};
|