@havue/components 1.0.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.
@@ -0,0 +1,3217 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue")) : typeof define === "function" && define.amd ? define(["exports", "vue"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.components = {}, global.Vue));
3
+ })(this, function(exports2, vue) {
4
+ "use strict";var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+
8
+ const withInstall = (main, extra) => {
9
+ main.install = (app) => {
10
+ for (const comp of [main, ...Object.values({})]) {
11
+ app.component(comp.name, comp);
12
+ }
13
+ };
14
+ return main;
15
+ };
16
+ function getDefaultExportFromCjs(x) {
17
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
18
+ }
19
+ var colorString$1 = { exports: {} };
20
+ var colorName = {
21
+ "aliceblue": [240, 248, 255],
22
+ "antiquewhite": [250, 235, 215],
23
+ "aqua": [0, 255, 255],
24
+ "aquamarine": [127, 255, 212],
25
+ "azure": [240, 255, 255],
26
+ "beige": [245, 245, 220],
27
+ "bisque": [255, 228, 196],
28
+ "black": [0, 0, 0],
29
+ "blanchedalmond": [255, 235, 205],
30
+ "blue": [0, 0, 255],
31
+ "blueviolet": [138, 43, 226],
32
+ "brown": [165, 42, 42],
33
+ "burlywood": [222, 184, 135],
34
+ "cadetblue": [95, 158, 160],
35
+ "chartreuse": [127, 255, 0],
36
+ "chocolate": [210, 105, 30],
37
+ "coral": [255, 127, 80],
38
+ "cornflowerblue": [100, 149, 237],
39
+ "cornsilk": [255, 248, 220],
40
+ "crimson": [220, 20, 60],
41
+ "cyan": [0, 255, 255],
42
+ "darkblue": [0, 0, 139],
43
+ "darkcyan": [0, 139, 139],
44
+ "darkgoldenrod": [184, 134, 11],
45
+ "darkgray": [169, 169, 169],
46
+ "darkgreen": [0, 100, 0],
47
+ "darkgrey": [169, 169, 169],
48
+ "darkkhaki": [189, 183, 107],
49
+ "darkmagenta": [139, 0, 139],
50
+ "darkolivegreen": [85, 107, 47],
51
+ "darkorange": [255, 140, 0],
52
+ "darkorchid": [153, 50, 204],
53
+ "darkred": [139, 0, 0],
54
+ "darksalmon": [233, 150, 122],
55
+ "darkseagreen": [143, 188, 143],
56
+ "darkslateblue": [72, 61, 139],
57
+ "darkslategray": [47, 79, 79],
58
+ "darkslategrey": [47, 79, 79],
59
+ "darkturquoise": [0, 206, 209],
60
+ "darkviolet": [148, 0, 211],
61
+ "deeppink": [255, 20, 147],
62
+ "deepskyblue": [0, 191, 255],
63
+ "dimgray": [105, 105, 105],
64
+ "dimgrey": [105, 105, 105],
65
+ "dodgerblue": [30, 144, 255],
66
+ "firebrick": [178, 34, 34],
67
+ "floralwhite": [255, 250, 240],
68
+ "forestgreen": [34, 139, 34],
69
+ "fuchsia": [255, 0, 255],
70
+ "gainsboro": [220, 220, 220],
71
+ "ghostwhite": [248, 248, 255],
72
+ "gold": [255, 215, 0],
73
+ "goldenrod": [218, 165, 32],
74
+ "gray": [128, 128, 128],
75
+ "green": [0, 128, 0],
76
+ "greenyellow": [173, 255, 47],
77
+ "grey": [128, 128, 128],
78
+ "honeydew": [240, 255, 240],
79
+ "hotpink": [255, 105, 180],
80
+ "indianred": [205, 92, 92],
81
+ "indigo": [75, 0, 130],
82
+ "ivory": [255, 255, 240],
83
+ "khaki": [240, 230, 140],
84
+ "lavender": [230, 230, 250],
85
+ "lavenderblush": [255, 240, 245],
86
+ "lawngreen": [124, 252, 0],
87
+ "lemonchiffon": [255, 250, 205],
88
+ "lightblue": [173, 216, 230],
89
+ "lightcoral": [240, 128, 128],
90
+ "lightcyan": [224, 255, 255],
91
+ "lightgoldenrodyellow": [250, 250, 210],
92
+ "lightgray": [211, 211, 211],
93
+ "lightgreen": [144, 238, 144],
94
+ "lightgrey": [211, 211, 211],
95
+ "lightpink": [255, 182, 193],
96
+ "lightsalmon": [255, 160, 122],
97
+ "lightseagreen": [32, 178, 170],
98
+ "lightskyblue": [135, 206, 250],
99
+ "lightslategray": [119, 136, 153],
100
+ "lightslategrey": [119, 136, 153],
101
+ "lightsteelblue": [176, 196, 222],
102
+ "lightyellow": [255, 255, 224],
103
+ "lime": [0, 255, 0],
104
+ "limegreen": [50, 205, 50],
105
+ "linen": [250, 240, 230],
106
+ "magenta": [255, 0, 255],
107
+ "maroon": [128, 0, 0],
108
+ "mediumaquamarine": [102, 205, 170],
109
+ "mediumblue": [0, 0, 205],
110
+ "mediumorchid": [186, 85, 211],
111
+ "mediumpurple": [147, 112, 219],
112
+ "mediumseagreen": [60, 179, 113],
113
+ "mediumslateblue": [123, 104, 238],
114
+ "mediumspringgreen": [0, 250, 154],
115
+ "mediumturquoise": [72, 209, 204],
116
+ "mediumvioletred": [199, 21, 133],
117
+ "midnightblue": [25, 25, 112],
118
+ "mintcream": [245, 255, 250],
119
+ "mistyrose": [255, 228, 225],
120
+ "moccasin": [255, 228, 181],
121
+ "navajowhite": [255, 222, 173],
122
+ "navy": [0, 0, 128],
123
+ "oldlace": [253, 245, 230],
124
+ "olive": [128, 128, 0],
125
+ "olivedrab": [107, 142, 35],
126
+ "orange": [255, 165, 0],
127
+ "orangered": [255, 69, 0],
128
+ "orchid": [218, 112, 214],
129
+ "palegoldenrod": [238, 232, 170],
130
+ "palegreen": [152, 251, 152],
131
+ "paleturquoise": [175, 238, 238],
132
+ "palevioletred": [219, 112, 147],
133
+ "papayawhip": [255, 239, 213],
134
+ "peachpuff": [255, 218, 185],
135
+ "peru": [205, 133, 63],
136
+ "pink": [255, 192, 203],
137
+ "plum": [221, 160, 221],
138
+ "powderblue": [176, 224, 230],
139
+ "purple": [128, 0, 128],
140
+ "rebeccapurple": [102, 51, 153],
141
+ "red": [255, 0, 0],
142
+ "rosybrown": [188, 143, 143],
143
+ "royalblue": [65, 105, 225],
144
+ "saddlebrown": [139, 69, 19],
145
+ "salmon": [250, 128, 114],
146
+ "sandybrown": [244, 164, 96],
147
+ "seagreen": [46, 139, 87],
148
+ "seashell": [255, 245, 238],
149
+ "sienna": [160, 82, 45],
150
+ "silver": [192, 192, 192],
151
+ "skyblue": [135, 206, 235],
152
+ "slateblue": [106, 90, 205],
153
+ "slategray": [112, 128, 144],
154
+ "slategrey": [112, 128, 144],
155
+ "snow": [255, 250, 250],
156
+ "springgreen": [0, 255, 127],
157
+ "steelblue": [70, 130, 180],
158
+ "tan": [210, 180, 140],
159
+ "teal": [0, 128, 128],
160
+ "thistle": [216, 191, 216],
161
+ "tomato": [255, 99, 71],
162
+ "turquoise": [64, 224, 208],
163
+ "violet": [238, 130, 238],
164
+ "wheat": [245, 222, 179],
165
+ "white": [255, 255, 255],
166
+ "whitesmoke": [245, 245, 245],
167
+ "yellow": [255, 255, 0],
168
+ "yellowgreen": [154, 205, 50]
169
+ };
170
+ var simpleSwizzle = { exports: {} };
171
+ var isArrayish$1 = function isArrayish2(obj) {
172
+ if (!obj || typeof obj === "string") {
173
+ return false;
174
+ }
175
+ return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && (obj.splice instanceof Function || Object.getOwnPropertyDescriptor(obj, obj.length - 1) && obj.constructor.name !== "String");
176
+ };
177
+ var isArrayish = isArrayish$1;
178
+ var concat = Array.prototype.concat;
179
+ var slice = Array.prototype.slice;
180
+ var swizzle$1 = simpleSwizzle.exports = function swizzle2(args) {
181
+ var results = [];
182
+ for (var i = 0, len = args.length; i < len; i++) {
183
+ var arg = args[i];
184
+ if (isArrayish(arg)) {
185
+ results = concat.call(results, slice.call(arg));
186
+ } else {
187
+ results.push(arg);
188
+ }
189
+ }
190
+ return results;
191
+ };
192
+ swizzle$1.wrap = function(fn) {
193
+ return function() {
194
+ return fn(swizzle$1(arguments));
195
+ };
196
+ };
197
+ var simpleSwizzleExports = simpleSwizzle.exports;
198
+ var colorNames = colorName;
199
+ var swizzle = simpleSwizzleExports;
200
+ var hasOwnProperty = Object.hasOwnProperty;
201
+ var reverseNames = /* @__PURE__ */ Object.create(null);
202
+ for (var name in colorNames) {
203
+ if (hasOwnProperty.call(colorNames, name)) {
204
+ reverseNames[colorNames[name]] = name;
205
+ }
206
+ }
207
+ var cs = colorString$1.exports = {
208
+ to: {},
209
+ get: {}
210
+ };
211
+ cs.get = function(string) {
212
+ var prefix = string.substring(0, 3).toLowerCase();
213
+ var val;
214
+ var model;
215
+ switch (prefix) {
216
+ case "hsl":
217
+ val = cs.get.hsl(string);
218
+ model = "hsl";
219
+ break;
220
+ case "hwb":
221
+ val = cs.get.hwb(string);
222
+ model = "hwb";
223
+ break;
224
+ default:
225
+ val = cs.get.rgb(string);
226
+ model = "rgb";
227
+ break;
228
+ }
229
+ if (!val) {
230
+ return null;
231
+ }
232
+ return { model, value: val };
233
+ };
234
+ cs.get.rgb = function(string) {
235
+ if (!string) {
236
+ return null;
237
+ }
238
+ var abbr = /^#([a-f0-9]{3,4})$/i;
239
+ var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
240
+ var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
241
+ var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
242
+ var keyword = /^(\w+)$/;
243
+ var rgb = [0, 0, 0, 1];
244
+ var match;
245
+ var i;
246
+ var hexAlpha;
247
+ if (match = string.match(hex)) {
248
+ hexAlpha = match[2];
249
+ match = match[1];
250
+ for (i = 0; i < 3; i++) {
251
+ var i2 = i * 2;
252
+ rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
253
+ }
254
+ if (hexAlpha) {
255
+ rgb[3] = parseInt(hexAlpha, 16) / 255;
256
+ }
257
+ } else if (match = string.match(abbr)) {
258
+ match = match[1];
259
+ hexAlpha = match[3];
260
+ for (i = 0; i < 3; i++) {
261
+ rgb[i] = parseInt(match[i] + match[i], 16);
262
+ }
263
+ if (hexAlpha) {
264
+ rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
265
+ }
266
+ } else if (match = string.match(rgba)) {
267
+ for (i = 0; i < 3; i++) {
268
+ rgb[i] = parseInt(match[i + 1], 0);
269
+ }
270
+ if (match[4]) {
271
+ if (match[5]) {
272
+ rgb[3] = parseFloat(match[4]) * 0.01;
273
+ } else {
274
+ rgb[3] = parseFloat(match[4]);
275
+ }
276
+ }
277
+ } else if (match = string.match(per)) {
278
+ for (i = 0; i < 3; i++) {
279
+ rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
280
+ }
281
+ if (match[4]) {
282
+ if (match[5]) {
283
+ rgb[3] = parseFloat(match[4]) * 0.01;
284
+ } else {
285
+ rgb[3] = parseFloat(match[4]);
286
+ }
287
+ }
288
+ } else if (match = string.match(keyword)) {
289
+ if (match[1] === "transparent") {
290
+ return [0, 0, 0, 0];
291
+ }
292
+ if (!hasOwnProperty.call(colorNames, match[1])) {
293
+ return null;
294
+ }
295
+ rgb = colorNames[match[1]];
296
+ rgb[3] = 1;
297
+ return rgb;
298
+ } else {
299
+ return null;
300
+ }
301
+ for (i = 0; i < 3; i++) {
302
+ rgb[i] = clamp(rgb[i], 0, 255);
303
+ }
304
+ rgb[3] = clamp(rgb[3], 0, 1);
305
+ return rgb;
306
+ };
307
+ cs.get.hsl = function(string) {
308
+ if (!string) {
309
+ return null;
310
+ }
311
+ var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
312
+ var match = string.match(hsl);
313
+ if (match) {
314
+ var alpha = parseFloat(match[4]);
315
+ var h = (parseFloat(match[1]) % 360 + 360) % 360;
316
+ var s = clamp(parseFloat(match[2]), 0, 100);
317
+ var l = clamp(parseFloat(match[3]), 0, 100);
318
+ var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
319
+ return [h, s, l, a];
320
+ }
321
+ return null;
322
+ };
323
+ cs.get.hwb = function(string) {
324
+ if (!string) {
325
+ return null;
326
+ }
327
+ var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
328
+ var match = string.match(hwb);
329
+ if (match) {
330
+ var alpha = parseFloat(match[4]);
331
+ var h = (parseFloat(match[1]) % 360 + 360) % 360;
332
+ var w = clamp(parseFloat(match[2]), 0, 100);
333
+ var b = clamp(parseFloat(match[3]), 0, 100);
334
+ var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
335
+ return [h, w, b, a];
336
+ }
337
+ return null;
338
+ };
339
+ cs.to.hex = function() {
340
+ var rgba = swizzle(arguments);
341
+ return "#" + hexDouble(rgba[0]) + hexDouble(rgba[1]) + hexDouble(rgba[2]) + (rgba[3] < 1 ? hexDouble(Math.round(rgba[3] * 255)) : "");
342
+ };
343
+ cs.to.rgb = function() {
344
+ var rgba = swizzle(arguments);
345
+ return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ")" : "rgba(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ", " + rgba[3] + ")";
346
+ };
347
+ cs.to.rgb.percent = function() {
348
+ var rgba = swizzle(arguments);
349
+ var r = Math.round(rgba[0] / 255 * 100);
350
+ var g = Math.round(rgba[1] / 255 * 100);
351
+ var b = Math.round(rgba[2] / 255 * 100);
352
+ return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + r + "%, " + g + "%, " + b + "%)" : "rgba(" + r + "%, " + g + "%, " + b + "%, " + rgba[3] + ")";
353
+ };
354
+ cs.to.hsl = function() {
355
+ var hsla = swizzle(arguments);
356
+ return hsla.length < 4 || hsla[3] === 1 ? "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)" : "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " + hsla[3] + ")";
357
+ };
358
+ cs.to.hwb = function() {
359
+ var hwba = swizzle(arguments);
360
+ var a = "";
361
+ if (hwba.length >= 4 && hwba[3] !== 1) {
362
+ a = ", " + hwba[3];
363
+ }
364
+ return "hwb(" + hwba[0] + ", " + hwba[1] + "%, " + hwba[2] + "%" + a + ")";
365
+ };
366
+ cs.to.keyword = function(rgb) {
367
+ return reverseNames[rgb.slice(0, 3)];
368
+ };
369
+ function clamp(num, min, max) {
370
+ return Math.min(Math.max(min, num), max);
371
+ }
372
+ function hexDouble(num) {
373
+ var str = Math.round(num).toString(16).toUpperCase();
374
+ return str.length < 2 ? "0" + str : str;
375
+ }
376
+ var colorStringExports = colorString$1.exports;
377
+ const cssKeywords = colorName;
378
+ const reverseKeywords = {};
379
+ for (const key of Object.keys(cssKeywords)) {
380
+ reverseKeywords[cssKeywords[key]] = key;
381
+ }
382
+ const convert$2 = {
383
+ rgb: { channels: 3, labels: "rgb" },
384
+ hsl: { channels: 3, labels: "hsl" },
385
+ hsv: { channels: 3, labels: "hsv" },
386
+ hwb: { channels: 3, labels: "hwb" },
387
+ cmyk: { channels: 4, labels: "cmyk" },
388
+ xyz: { channels: 3, labels: "xyz" },
389
+ lab: { channels: 3, labels: "lab" },
390
+ lch: { channels: 3, labels: "lch" },
391
+ hex: { channels: 1, labels: ["hex"] },
392
+ keyword: { channels: 1, labels: ["keyword"] },
393
+ ansi16: { channels: 1, labels: ["ansi16"] },
394
+ ansi256: { channels: 1, labels: ["ansi256"] },
395
+ hcg: { channels: 3, labels: ["h", "c", "g"] },
396
+ apple: { channels: 3, labels: ["r16", "g16", "b16"] },
397
+ gray: { channels: 1, labels: ["gray"] }
398
+ };
399
+ var conversions$2 = convert$2;
400
+ for (const model of Object.keys(convert$2)) {
401
+ if (!("channels" in convert$2[model])) {
402
+ throw new Error("missing channels property: " + model);
403
+ }
404
+ if (!("labels" in convert$2[model])) {
405
+ throw new Error("missing channel labels property: " + model);
406
+ }
407
+ if (convert$2[model].labels.length !== convert$2[model].channels) {
408
+ throw new Error("channel and label counts mismatch: " + model);
409
+ }
410
+ const { channels, labels } = convert$2[model];
411
+ delete convert$2[model].channels;
412
+ delete convert$2[model].labels;
413
+ Object.defineProperty(convert$2[model], "channels", { value: channels });
414
+ Object.defineProperty(convert$2[model], "labels", { value: labels });
415
+ }
416
+ convert$2.rgb.hsl = function(rgb) {
417
+ const r = rgb[0] / 255;
418
+ const g = rgb[1] / 255;
419
+ const b = rgb[2] / 255;
420
+ const min = Math.min(r, g, b);
421
+ const max = Math.max(r, g, b);
422
+ const delta = max - min;
423
+ let h;
424
+ let s;
425
+ if (max === min) {
426
+ h = 0;
427
+ } else if (r === max) {
428
+ h = (g - b) / delta;
429
+ } else if (g === max) {
430
+ h = 2 + (b - r) / delta;
431
+ } else if (b === max) {
432
+ h = 4 + (r - g) / delta;
433
+ }
434
+ h = Math.min(h * 60, 360);
435
+ if (h < 0) {
436
+ h += 360;
437
+ }
438
+ const l = (min + max) / 2;
439
+ if (max === min) {
440
+ s = 0;
441
+ } else if (l <= 0.5) {
442
+ s = delta / (max + min);
443
+ } else {
444
+ s = delta / (2 - max - min);
445
+ }
446
+ return [h, s * 100, l * 100];
447
+ };
448
+ convert$2.rgb.hsv = function(rgb) {
449
+ let rdif;
450
+ let gdif;
451
+ let bdif;
452
+ let h;
453
+ let s;
454
+ const r = rgb[0] / 255;
455
+ const g = rgb[1] / 255;
456
+ const b = rgb[2] / 255;
457
+ const v = Math.max(r, g, b);
458
+ const diff = v - Math.min(r, g, b);
459
+ const diffc = function(c) {
460
+ return (v - c) / 6 / diff + 1 / 2;
461
+ };
462
+ if (diff === 0) {
463
+ h = 0;
464
+ s = 0;
465
+ } else {
466
+ s = diff / v;
467
+ rdif = diffc(r);
468
+ gdif = diffc(g);
469
+ bdif = diffc(b);
470
+ if (r === v) {
471
+ h = bdif - gdif;
472
+ } else if (g === v) {
473
+ h = 1 / 3 + rdif - bdif;
474
+ } else if (b === v) {
475
+ h = 2 / 3 + gdif - rdif;
476
+ }
477
+ if (h < 0) {
478
+ h += 1;
479
+ } else if (h > 1) {
480
+ h -= 1;
481
+ }
482
+ }
483
+ return [
484
+ h * 360,
485
+ s * 100,
486
+ v * 100
487
+ ];
488
+ };
489
+ convert$2.rgb.hwb = function(rgb) {
490
+ const r = rgb[0];
491
+ const g = rgb[1];
492
+ let b = rgb[2];
493
+ const h = convert$2.rgb.hsl(rgb)[0];
494
+ const w = 1 / 255 * Math.min(r, Math.min(g, b));
495
+ b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
496
+ return [h, w * 100, b * 100];
497
+ };
498
+ convert$2.rgb.cmyk = function(rgb) {
499
+ const r = rgb[0] / 255;
500
+ const g = rgb[1] / 255;
501
+ const b = rgb[2] / 255;
502
+ const k = Math.min(1 - r, 1 - g, 1 - b);
503
+ const c = (1 - r - k) / (1 - k) || 0;
504
+ const m = (1 - g - k) / (1 - k) || 0;
505
+ const y = (1 - b - k) / (1 - k) || 0;
506
+ return [c * 100, m * 100, y * 100, k * 100];
507
+ };
508
+ function comparativeDistance(x, y) {
509
+ return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
510
+ }
511
+ convert$2.rgb.keyword = function(rgb) {
512
+ const reversed = reverseKeywords[rgb];
513
+ if (reversed) {
514
+ return reversed;
515
+ }
516
+ let currentClosestDistance = Infinity;
517
+ let currentClosestKeyword;
518
+ for (const keyword of Object.keys(cssKeywords)) {
519
+ const value = cssKeywords[keyword];
520
+ const distance = comparativeDistance(rgb, value);
521
+ if (distance < currentClosestDistance) {
522
+ currentClosestDistance = distance;
523
+ currentClosestKeyword = keyword;
524
+ }
525
+ }
526
+ return currentClosestKeyword;
527
+ };
528
+ convert$2.keyword.rgb = function(keyword) {
529
+ return cssKeywords[keyword];
530
+ };
531
+ convert$2.rgb.xyz = function(rgb) {
532
+ let r = rgb[0] / 255;
533
+ let g = rgb[1] / 255;
534
+ let b = rgb[2] / 255;
535
+ r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
536
+ g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
537
+ b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
538
+ const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
539
+ const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
540
+ const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
541
+ return [x * 100, y * 100, z * 100];
542
+ };
543
+ convert$2.rgb.lab = function(rgb) {
544
+ const xyz = convert$2.rgb.xyz(rgb);
545
+ let x = xyz[0];
546
+ let y = xyz[1];
547
+ let z = xyz[2];
548
+ x /= 95.047;
549
+ y /= 100;
550
+ z /= 108.883;
551
+ x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
552
+ y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
553
+ z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
554
+ const l = 116 * y - 16;
555
+ const a = 500 * (x - y);
556
+ const b = 200 * (y - z);
557
+ return [l, a, b];
558
+ };
559
+ convert$2.hsl.rgb = function(hsl) {
560
+ const h = hsl[0] / 360;
561
+ const s = hsl[1] / 100;
562
+ const l = hsl[2] / 100;
563
+ let t2;
564
+ let t3;
565
+ let val;
566
+ if (s === 0) {
567
+ val = l * 255;
568
+ return [val, val, val];
569
+ }
570
+ if (l < 0.5) {
571
+ t2 = l * (1 + s);
572
+ } else {
573
+ t2 = l + s - l * s;
574
+ }
575
+ const t1 = 2 * l - t2;
576
+ const rgb = [0, 0, 0];
577
+ for (let i = 0; i < 3; i++) {
578
+ t3 = h + 1 / 3 * -(i - 1);
579
+ if (t3 < 0) {
580
+ t3++;
581
+ }
582
+ if (t3 > 1) {
583
+ t3--;
584
+ }
585
+ if (6 * t3 < 1) {
586
+ val = t1 + (t2 - t1) * 6 * t3;
587
+ } else if (2 * t3 < 1) {
588
+ val = t2;
589
+ } else if (3 * t3 < 2) {
590
+ val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
591
+ } else {
592
+ val = t1;
593
+ }
594
+ rgb[i] = val * 255;
595
+ }
596
+ return rgb;
597
+ };
598
+ convert$2.hsl.hsv = function(hsl) {
599
+ const h = hsl[0];
600
+ let s = hsl[1] / 100;
601
+ let l = hsl[2] / 100;
602
+ let smin = s;
603
+ const lmin = Math.max(l, 0.01);
604
+ l *= 2;
605
+ s *= l <= 1 ? l : 2 - l;
606
+ smin *= lmin <= 1 ? lmin : 2 - lmin;
607
+ const v = (l + s) / 2;
608
+ const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
609
+ return [h, sv * 100, v * 100];
610
+ };
611
+ convert$2.hsv.rgb = function(hsv) {
612
+ const h = hsv[0] / 60;
613
+ const s = hsv[1] / 100;
614
+ let v = hsv[2] / 100;
615
+ const hi = Math.floor(h) % 6;
616
+ const f = h - Math.floor(h);
617
+ const p = 255 * v * (1 - s);
618
+ const q = 255 * v * (1 - s * f);
619
+ const t = 255 * v * (1 - s * (1 - f));
620
+ v *= 255;
621
+ switch (hi) {
622
+ case 0:
623
+ return [v, t, p];
624
+ case 1:
625
+ return [q, v, p];
626
+ case 2:
627
+ return [p, v, t];
628
+ case 3:
629
+ return [p, q, v];
630
+ case 4:
631
+ return [t, p, v];
632
+ case 5:
633
+ return [v, p, q];
634
+ }
635
+ };
636
+ convert$2.hsv.hsl = function(hsv) {
637
+ const h = hsv[0];
638
+ const s = hsv[1] / 100;
639
+ const v = hsv[2] / 100;
640
+ const vmin = Math.max(v, 0.01);
641
+ let sl;
642
+ let l;
643
+ l = (2 - s) * v;
644
+ const lmin = (2 - s) * vmin;
645
+ sl = s * vmin;
646
+ sl /= lmin <= 1 ? lmin : 2 - lmin;
647
+ sl = sl || 0;
648
+ l /= 2;
649
+ return [h, sl * 100, l * 100];
650
+ };
651
+ convert$2.hwb.rgb = function(hwb) {
652
+ const h = hwb[0] / 360;
653
+ let wh = hwb[1] / 100;
654
+ let bl = hwb[2] / 100;
655
+ const ratio = wh + bl;
656
+ let f;
657
+ if (ratio > 1) {
658
+ wh /= ratio;
659
+ bl /= ratio;
660
+ }
661
+ const i = Math.floor(6 * h);
662
+ const v = 1 - bl;
663
+ f = 6 * h - i;
664
+ if ((i & 1) !== 0) {
665
+ f = 1 - f;
666
+ }
667
+ const n = wh + f * (v - wh);
668
+ let r;
669
+ let g;
670
+ let b;
671
+ switch (i) {
672
+ default:
673
+ case 6:
674
+ case 0:
675
+ r = v;
676
+ g = n;
677
+ b = wh;
678
+ break;
679
+ case 1:
680
+ r = n;
681
+ g = v;
682
+ b = wh;
683
+ break;
684
+ case 2:
685
+ r = wh;
686
+ g = v;
687
+ b = n;
688
+ break;
689
+ case 3:
690
+ r = wh;
691
+ g = n;
692
+ b = v;
693
+ break;
694
+ case 4:
695
+ r = n;
696
+ g = wh;
697
+ b = v;
698
+ break;
699
+ case 5:
700
+ r = v;
701
+ g = wh;
702
+ b = n;
703
+ break;
704
+ }
705
+ return [r * 255, g * 255, b * 255];
706
+ };
707
+ convert$2.cmyk.rgb = function(cmyk) {
708
+ const c = cmyk[0] / 100;
709
+ const m = cmyk[1] / 100;
710
+ const y = cmyk[2] / 100;
711
+ const k = cmyk[3] / 100;
712
+ const r = 1 - Math.min(1, c * (1 - k) + k);
713
+ const g = 1 - Math.min(1, m * (1 - k) + k);
714
+ const b = 1 - Math.min(1, y * (1 - k) + k);
715
+ return [r * 255, g * 255, b * 255];
716
+ };
717
+ convert$2.xyz.rgb = function(xyz) {
718
+ const x = xyz[0] / 100;
719
+ const y = xyz[1] / 100;
720
+ const z = xyz[2] / 100;
721
+ let r;
722
+ let g;
723
+ let b;
724
+ r = x * 3.2406 + y * -1.5372 + z * -0.4986;
725
+ g = x * -0.9689 + y * 1.8758 + z * 0.0415;
726
+ b = x * 0.0557 + y * -0.204 + z * 1.057;
727
+ r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
728
+ g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
729
+ b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
730
+ r = Math.min(Math.max(0, r), 1);
731
+ g = Math.min(Math.max(0, g), 1);
732
+ b = Math.min(Math.max(0, b), 1);
733
+ return [r * 255, g * 255, b * 255];
734
+ };
735
+ convert$2.xyz.lab = function(xyz) {
736
+ let x = xyz[0];
737
+ let y = xyz[1];
738
+ let z = xyz[2];
739
+ x /= 95.047;
740
+ y /= 100;
741
+ z /= 108.883;
742
+ x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
743
+ y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
744
+ z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
745
+ const l = 116 * y - 16;
746
+ const a = 500 * (x - y);
747
+ const b = 200 * (y - z);
748
+ return [l, a, b];
749
+ };
750
+ convert$2.lab.xyz = function(lab) {
751
+ const l = lab[0];
752
+ const a = lab[1];
753
+ const b = lab[2];
754
+ let x;
755
+ let y;
756
+ let z;
757
+ y = (l + 16) / 116;
758
+ x = a / 500 + y;
759
+ z = y - b / 200;
760
+ const y2 = y ** 3;
761
+ const x2 = x ** 3;
762
+ const z2 = z ** 3;
763
+ y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
764
+ x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
765
+ z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
766
+ x *= 95.047;
767
+ y *= 100;
768
+ z *= 108.883;
769
+ return [x, y, z];
770
+ };
771
+ convert$2.lab.lch = function(lab) {
772
+ const l = lab[0];
773
+ const a = lab[1];
774
+ const b = lab[2];
775
+ let h;
776
+ const hr = Math.atan2(b, a);
777
+ h = hr * 360 / 2 / Math.PI;
778
+ if (h < 0) {
779
+ h += 360;
780
+ }
781
+ const c = Math.sqrt(a * a + b * b);
782
+ return [l, c, h];
783
+ };
784
+ convert$2.lch.lab = function(lch) {
785
+ const l = lch[0];
786
+ const c = lch[1];
787
+ const h = lch[2];
788
+ const hr = h / 360 * 2 * Math.PI;
789
+ const a = c * Math.cos(hr);
790
+ const b = c * Math.sin(hr);
791
+ return [l, a, b];
792
+ };
793
+ convert$2.rgb.ansi16 = function(args, saturation = null) {
794
+ const [r, g, b] = args;
795
+ let value = saturation === null ? convert$2.rgb.hsv(args)[2] : saturation;
796
+ value = Math.round(value / 50);
797
+ if (value === 0) {
798
+ return 30;
799
+ }
800
+ let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
801
+ if (value === 2) {
802
+ ansi += 60;
803
+ }
804
+ return ansi;
805
+ };
806
+ convert$2.hsv.ansi16 = function(args) {
807
+ return convert$2.rgb.ansi16(convert$2.hsv.rgb(args), args[2]);
808
+ };
809
+ convert$2.rgb.ansi256 = function(args) {
810
+ const r = args[0];
811
+ const g = args[1];
812
+ const b = args[2];
813
+ if (r === g && g === b) {
814
+ if (r < 8) {
815
+ return 16;
816
+ }
817
+ if (r > 248) {
818
+ return 231;
819
+ }
820
+ return Math.round((r - 8) / 247 * 24) + 232;
821
+ }
822
+ const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
823
+ return ansi;
824
+ };
825
+ convert$2.ansi16.rgb = function(args) {
826
+ let color2 = args % 10;
827
+ if (color2 === 0 || color2 === 7) {
828
+ if (args > 50) {
829
+ color2 += 3.5;
830
+ }
831
+ color2 = color2 / 10.5 * 255;
832
+ return [color2, color2, color2];
833
+ }
834
+ const mult = (~~(args > 50) + 1) * 0.5;
835
+ const r = (color2 & 1) * mult * 255;
836
+ const g = (color2 >> 1 & 1) * mult * 255;
837
+ const b = (color2 >> 2 & 1) * mult * 255;
838
+ return [r, g, b];
839
+ };
840
+ convert$2.ansi256.rgb = function(args) {
841
+ if (args >= 232) {
842
+ const c = (args - 232) * 10 + 8;
843
+ return [c, c, c];
844
+ }
845
+ args -= 16;
846
+ let rem;
847
+ const r = Math.floor(args / 36) / 5 * 255;
848
+ const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
849
+ const b = rem % 6 / 5 * 255;
850
+ return [r, g, b];
851
+ };
852
+ convert$2.rgb.hex = function(args) {
853
+ const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
854
+ const string = integer.toString(16).toUpperCase();
855
+ return "000000".substring(string.length) + string;
856
+ };
857
+ convert$2.hex.rgb = function(args) {
858
+ const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
859
+ if (!match) {
860
+ return [0, 0, 0];
861
+ }
862
+ let colorString2 = match[0];
863
+ if (match[0].length === 3) {
864
+ colorString2 = colorString2.split("").map((char) => {
865
+ return char + char;
866
+ }).join("");
867
+ }
868
+ const integer = parseInt(colorString2, 16);
869
+ const r = integer >> 16 & 255;
870
+ const g = integer >> 8 & 255;
871
+ const b = integer & 255;
872
+ return [r, g, b];
873
+ };
874
+ convert$2.rgb.hcg = function(rgb) {
875
+ const r = rgb[0] / 255;
876
+ const g = rgb[1] / 255;
877
+ const b = rgb[2] / 255;
878
+ const max = Math.max(Math.max(r, g), b);
879
+ const min = Math.min(Math.min(r, g), b);
880
+ const chroma = max - min;
881
+ let grayscale;
882
+ let hue;
883
+ if (chroma < 1) {
884
+ grayscale = min / (1 - chroma);
885
+ } else {
886
+ grayscale = 0;
887
+ }
888
+ if (chroma <= 0) {
889
+ hue = 0;
890
+ } else if (max === r) {
891
+ hue = (g - b) / chroma % 6;
892
+ } else if (max === g) {
893
+ hue = 2 + (b - r) / chroma;
894
+ } else {
895
+ hue = 4 + (r - g) / chroma;
896
+ }
897
+ hue /= 6;
898
+ hue %= 1;
899
+ return [hue * 360, chroma * 100, grayscale * 100];
900
+ };
901
+ convert$2.hsl.hcg = function(hsl) {
902
+ const s = hsl[1] / 100;
903
+ const l = hsl[2] / 100;
904
+ const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
905
+ let f = 0;
906
+ if (c < 1) {
907
+ f = (l - 0.5 * c) / (1 - c);
908
+ }
909
+ return [hsl[0], c * 100, f * 100];
910
+ };
911
+ convert$2.hsv.hcg = function(hsv) {
912
+ const s = hsv[1] / 100;
913
+ const v = hsv[2] / 100;
914
+ const c = s * v;
915
+ let f = 0;
916
+ if (c < 1) {
917
+ f = (v - c) / (1 - c);
918
+ }
919
+ return [hsv[0], c * 100, f * 100];
920
+ };
921
+ convert$2.hcg.rgb = function(hcg) {
922
+ const h = hcg[0] / 360;
923
+ const c = hcg[1] / 100;
924
+ const g = hcg[2] / 100;
925
+ if (c === 0) {
926
+ return [g * 255, g * 255, g * 255];
927
+ }
928
+ const pure = [0, 0, 0];
929
+ const hi = h % 1 * 6;
930
+ const v = hi % 1;
931
+ const w = 1 - v;
932
+ let mg = 0;
933
+ switch (Math.floor(hi)) {
934
+ case 0:
935
+ pure[0] = 1;
936
+ pure[1] = v;
937
+ pure[2] = 0;
938
+ break;
939
+ case 1:
940
+ pure[0] = w;
941
+ pure[1] = 1;
942
+ pure[2] = 0;
943
+ break;
944
+ case 2:
945
+ pure[0] = 0;
946
+ pure[1] = 1;
947
+ pure[2] = v;
948
+ break;
949
+ case 3:
950
+ pure[0] = 0;
951
+ pure[1] = w;
952
+ pure[2] = 1;
953
+ break;
954
+ case 4:
955
+ pure[0] = v;
956
+ pure[1] = 0;
957
+ pure[2] = 1;
958
+ break;
959
+ default:
960
+ pure[0] = 1;
961
+ pure[1] = 0;
962
+ pure[2] = w;
963
+ }
964
+ mg = (1 - c) * g;
965
+ return [
966
+ (c * pure[0] + mg) * 255,
967
+ (c * pure[1] + mg) * 255,
968
+ (c * pure[2] + mg) * 255
969
+ ];
970
+ };
971
+ convert$2.hcg.hsv = function(hcg) {
972
+ const c = hcg[1] / 100;
973
+ const g = hcg[2] / 100;
974
+ const v = c + g * (1 - c);
975
+ let f = 0;
976
+ if (v > 0) {
977
+ f = c / v;
978
+ }
979
+ return [hcg[0], f * 100, v * 100];
980
+ };
981
+ convert$2.hcg.hsl = function(hcg) {
982
+ const c = hcg[1] / 100;
983
+ const g = hcg[2] / 100;
984
+ const l = g * (1 - c) + 0.5 * c;
985
+ let s = 0;
986
+ if (l > 0 && l < 0.5) {
987
+ s = c / (2 * l);
988
+ } else if (l >= 0.5 && l < 1) {
989
+ s = c / (2 * (1 - l));
990
+ }
991
+ return [hcg[0], s * 100, l * 100];
992
+ };
993
+ convert$2.hcg.hwb = function(hcg) {
994
+ const c = hcg[1] / 100;
995
+ const g = hcg[2] / 100;
996
+ const v = c + g * (1 - c);
997
+ return [hcg[0], (v - c) * 100, (1 - v) * 100];
998
+ };
999
+ convert$2.hwb.hcg = function(hwb) {
1000
+ const w = hwb[1] / 100;
1001
+ const b = hwb[2] / 100;
1002
+ const v = 1 - b;
1003
+ const c = v - w;
1004
+ let g = 0;
1005
+ if (c < 1) {
1006
+ g = (v - c) / (1 - c);
1007
+ }
1008
+ return [hwb[0], c * 100, g * 100];
1009
+ };
1010
+ convert$2.apple.rgb = function(apple) {
1011
+ return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
1012
+ };
1013
+ convert$2.rgb.apple = function(rgb) {
1014
+ return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
1015
+ };
1016
+ convert$2.gray.rgb = function(args) {
1017
+ return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
1018
+ };
1019
+ convert$2.gray.hsl = function(args) {
1020
+ return [0, 0, args[0]];
1021
+ };
1022
+ convert$2.gray.hsv = convert$2.gray.hsl;
1023
+ convert$2.gray.hwb = function(gray) {
1024
+ return [0, 100, gray[0]];
1025
+ };
1026
+ convert$2.gray.cmyk = function(gray) {
1027
+ return [0, 0, 0, gray[0]];
1028
+ };
1029
+ convert$2.gray.lab = function(gray) {
1030
+ return [gray[0], 0, 0];
1031
+ };
1032
+ convert$2.gray.hex = function(gray) {
1033
+ const val = Math.round(gray[0] / 100 * 255) & 255;
1034
+ const integer = (val << 16) + (val << 8) + val;
1035
+ const string = integer.toString(16).toUpperCase();
1036
+ return "000000".substring(string.length) + string;
1037
+ };
1038
+ convert$2.rgb.gray = function(rgb) {
1039
+ const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
1040
+ return [val / 255 * 100];
1041
+ };
1042
+ const conversions$1 = conversions$2;
1043
+ function buildGraph() {
1044
+ const graph = {};
1045
+ const models2 = Object.keys(conversions$1);
1046
+ for (let len = models2.length, i = 0; i < len; i++) {
1047
+ graph[models2[i]] = {
1048
+ // http://jsperf.com/1-vs-infinity
1049
+ // micro-opt, but this is simple.
1050
+ distance: -1,
1051
+ parent: null
1052
+ };
1053
+ }
1054
+ return graph;
1055
+ }
1056
+ function deriveBFS(fromModel) {
1057
+ const graph = buildGraph();
1058
+ const queue = [fromModel];
1059
+ graph[fromModel].distance = 0;
1060
+ while (queue.length) {
1061
+ const current = queue.pop();
1062
+ const adjacents = Object.keys(conversions$1[current]);
1063
+ for (let len = adjacents.length, i = 0; i < len; i++) {
1064
+ const adjacent = adjacents[i];
1065
+ const node = graph[adjacent];
1066
+ if (node.distance === -1) {
1067
+ node.distance = graph[current].distance + 1;
1068
+ node.parent = current;
1069
+ queue.unshift(adjacent);
1070
+ }
1071
+ }
1072
+ }
1073
+ return graph;
1074
+ }
1075
+ function link(from, to) {
1076
+ return function(args) {
1077
+ return to(from(args));
1078
+ };
1079
+ }
1080
+ function wrapConversion(toModel, graph) {
1081
+ const path = [graph[toModel].parent, toModel];
1082
+ let fn = conversions$1[graph[toModel].parent][toModel];
1083
+ let cur = graph[toModel].parent;
1084
+ while (graph[cur].parent) {
1085
+ path.unshift(graph[cur].parent);
1086
+ fn = link(conversions$1[graph[cur].parent][cur], fn);
1087
+ cur = graph[cur].parent;
1088
+ }
1089
+ fn.conversion = path;
1090
+ return fn;
1091
+ }
1092
+ var route$1 = function(fromModel) {
1093
+ const graph = deriveBFS(fromModel);
1094
+ const conversion = {};
1095
+ const models2 = Object.keys(graph);
1096
+ for (let len = models2.length, i = 0; i < len; i++) {
1097
+ const toModel = models2[i];
1098
+ const node = graph[toModel];
1099
+ if (node.parent === null) {
1100
+ continue;
1101
+ }
1102
+ conversion[toModel] = wrapConversion(toModel, graph);
1103
+ }
1104
+ return conversion;
1105
+ };
1106
+ const conversions = conversions$2;
1107
+ const route = route$1;
1108
+ const convert$1 = {};
1109
+ const models = Object.keys(conversions);
1110
+ function wrapRaw(fn) {
1111
+ const wrappedFn = function(...args) {
1112
+ const arg0 = args[0];
1113
+ if (arg0 === void 0 || arg0 === null) {
1114
+ return arg0;
1115
+ }
1116
+ if (arg0.length > 1) {
1117
+ args = arg0;
1118
+ }
1119
+ return fn(args);
1120
+ };
1121
+ if ("conversion" in fn) {
1122
+ wrappedFn.conversion = fn.conversion;
1123
+ }
1124
+ return wrappedFn;
1125
+ }
1126
+ function wrapRounded(fn) {
1127
+ const wrappedFn = function(...args) {
1128
+ const arg0 = args[0];
1129
+ if (arg0 === void 0 || arg0 === null) {
1130
+ return arg0;
1131
+ }
1132
+ if (arg0.length > 1) {
1133
+ args = arg0;
1134
+ }
1135
+ const result = fn(args);
1136
+ if (typeof result === "object") {
1137
+ for (let len = result.length, i = 0; i < len; i++) {
1138
+ result[i] = Math.round(result[i]);
1139
+ }
1140
+ }
1141
+ return result;
1142
+ };
1143
+ if ("conversion" in fn) {
1144
+ wrappedFn.conversion = fn.conversion;
1145
+ }
1146
+ return wrappedFn;
1147
+ }
1148
+ models.forEach((fromModel) => {
1149
+ convert$1[fromModel] = {};
1150
+ Object.defineProperty(convert$1[fromModel], "channels", { value: conversions[fromModel].channels });
1151
+ Object.defineProperty(convert$1[fromModel], "labels", { value: conversions[fromModel].labels });
1152
+ const routes = route(fromModel);
1153
+ const routeModels = Object.keys(routes);
1154
+ routeModels.forEach((toModel) => {
1155
+ const fn = routes[toModel];
1156
+ convert$1[fromModel][toModel] = wrapRounded(fn);
1157
+ convert$1[fromModel][toModel].raw = wrapRaw(fn);
1158
+ });
1159
+ });
1160
+ var colorConvert = convert$1;
1161
+ const colorString = colorStringExports;
1162
+ const convert = colorConvert;
1163
+ const skippedModels = [
1164
+ // To be honest, I don't really feel like keyword belongs in color convert, but eh.
1165
+ "keyword",
1166
+ // Gray conflicts with some method names, and has its own method defined.
1167
+ "gray",
1168
+ // Shouldn't really be in color-convert either...
1169
+ "hex"
1170
+ ];
1171
+ const hashedModelKeys = {};
1172
+ for (const model of Object.keys(convert)) {
1173
+ hashedModelKeys[[...convert[model].labels].sort().join("")] = model;
1174
+ }
1175
+ const limiters = {};
1176
+ function Color(object, model) {
1177
+ if (!(this instanceof Color)) {
1178
+ return new Color(object, model);
1179
+ }
1180
+ if (model && model in skippedModels) {
1181
+ model = null;
1182
+ }
1183
+ if (model && !(model in convert)) {
1184
+ throw new Error("Unknown model: " + model);
1185
+ }
1186
+ let i;
1187
+ let channels;
1188
+ if (object == null) {
1189
+ this.model = "rgb";
1190
+ this.color = [0, 0, 0];
1191
+ this.valpha = 1;
1192
+ } else if (object instanceof Color) {
1193
+ this.model = object.model;
1194
+ this.color = [...object.color];
1195
+ this.valpha = object.valpha;
1196
+ } else if (typeof object === "string") {
1197
+ const result = colorString.get(object);
1198
+ if (result === null) {
1199
+ throw new Error("Unable to parse color from string: " + object);
1200
+ }
1201
+ this.model = result.model;
1202
+ channels = convert[this.model].channels;
1203
+ this.color = result.value.slice(0, channels);
1204
+ this.valpha = typeof result.value[channels] === "number" ? result.value[channels] : 1;
1205
+ } else if (object.length > 0) {
1206
+ this.model = model || "rgb";
1207
+ channels = convert[this.model].channels;
1208
+ const newArray = Array.prototype.slice.call(object, 0, channels);
1209
+ this.color = zeroArray(newArray, channels);
1210
+ this.valpha = typeof object[channels] === "number" ? object[channels] : 1;
1211
+ } else if (typeof object === "number") {
1212
+ this.model = "rgb";
1213
+ this.color = [
1214
+ object >> 16 & 255,
1215
+ object >> 8 & 255,
1216
+ object & 255
1217
+ ];
1218
+ this.valpha = 1;
1219
+ } else {
1220
+ this.valpha = 1;
1221
+ const keys = Object.keys(object);
1222
+ if ("alpha" in object) {
1223
+ keys.splice(keys.indexOf("alpha"), 1);
1224
+ this.valpha = typeof object.alpha === "number" ? object.alpha : 0;
1225
+ }
1226
+ const hashedKeys = keys.sort().join("");
1227
+ if (!(hashedKeys in hashedModelKeys)) {
1228
+ throw new Error("Unable to parse color from object: " + JSON.stringify(object));
1229
+ }
1230
+ this.model = hashedModelKeys[hashedKeys];
1231
+ const { labels } = convert[this.model];
1232
+ const color2 = [];
1233
+ for (i = 0; i < labels.length; i++) {
1234
+ color2.push(object[labels[i]]);
1235
+ }
1236
+ this.color = zeroArray(color2);
1237
+ }
1238
+ if (limiters[this.model]) {
1239
+ channels = convert[this.model].channels;
1240
+ for (i = 0; i < channels; i++) {
1241
+ const limit = limiters[this.model][i];
1242
+ if (limit) {
1243
+ this.color[i] = limit(this.color[i]);
1244
+ }
1245
+ }
1246
+ }
1247
+ this.valpha = Math.max(0, Math.min(1, this.valpha));
1248
+ if (Object.freeze) {
1249
+ Object.freeze(this);
1250
+ }
1251
+ }
1252
+ Color.prototype = {
1253
+ toString() {
1254
+ return this.string();
1255
+ },
1256
+ toJSON() {
1257
+ return this[this.model]();
1258
+ },
1259
+ string(places) {
1260
+ let self2 = this.model in colorString.to ? this : this.rgb();
1261
+ self2 = self2.round(typeof places === "number" ? places : 1);
1262
+ const args = self2.valpha === 1 ? self2.color : [...self2.color, this.valpha];
1263
+ return colorString.to[self2.model](args);
1264
+ },
1265
+ percentString(places) {
1266
+ const self2 = this.rgb().round(typeof places === "number" ? places : 1);
1267
+ const args = self2.valpha === 1 ? self2.color : [...self2.color, this.valpha];
1268
+ return colorString.to.rgb.percent(args);
1269
+ },
1270
+ array() {
1271
+ return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha];
1272
+ },
1273
+ object() {
1274
+ const result = {};
1275
+ const { channels } = convert[this.model];
1276
+ const { labels } = convert[this.model];
1277
+ for (let i = 0; i < channels; i++) {
1278
+ result[labels[i]] = this.color[i];
1279
+ }
1280
+ if (this.valpha !== 1) {
1281
+ result.alpha = this.valpha;
1282
+ }
1283
+ return result;
1284
+ },
1285
+ unitArray() {
1286
+ const rgb = this.rgb().color;
1287
+ rgb[0] /= 255;
1288
+ rgb[1] /= 255;
1289
+ rgb[2] /= 255;
1290
+ if (this.valpha !== 1) {
1291
+ rgb.push(this.valpha);
1292
+ }
1293
+ return rgb;
1294
+ },
1295
+ unitObject() {
1296
+ const rgb = this.rgb().object();
1297
+ rgb.r /= 255;
1298
+ rgb.g /= 255;
1299
+ rgb.b /= 255;
1300
+ if (this.valpha !== 1) {
1301
+ rgb.alpha = this.valpha;
1302
+ }
1303
+ return rgb;
1304
+ },
1305
+ round(places) {
1306
+ places = Math.max(places || 0, 0);
1307
+ return new Color([...this.color.map(roundToPlace(places)), this.valpha], this.model);
1308
+ },
1309
+ alpha(value) {
1310
+ if (value !== void 0) {
1311
+ return new Color([...this.color, Math.max(0, Math.min(1, value))], this.model);
1312
+ }
1313
+ return this.valpha;
1314
+ },
1315
+ // Rgb
1316
+ red: getset("rgb", 0, maxfn(255)),
1317
+ green: getset("rgb", 1, maxfn(255)),
1318
+ blue: getset("rgb", 2, maxfn(255)),
1319
+ hue: getset(["hsl", "hsv", "hsl", "hwb", "hcg"], 0, (value) => (value % 360 + 360) % 360),
1320
+ saturationl: getset("hsl", 1, maxfn(100)),
1321
+ lightness: getset("hsl", 2, maxfn(100)),
1322
+ saturationv: getset("hsv", 1, maxfn(100)),
1323
+ value: getset("hsv", 2, maxfn(100)),
1324
+ chroma: getset("hcg", 1, maxfn(100)),
1325
+ gray: getset("hcg", 2, maxfn(100)),
1326
+ white: getset("hwb", 1, maxfn(100)),
1327
+ wblack: getset("hwb", 2, maxfn(100)),
1328
+ cyan: getset("cmyk", 0, maxfn(100)),
1329
+ magenta: getset("cmyk", 1, maxfn(100)),
1330
+ yellow: getset("cmyk", 2, maxfn(100)),
1331
+ black: getset("cmyk", 3, maxfn(100)),
1332
+ x: getset("xyz", 0, maxfn(95.047)),
1333
+ y: getset("xyz", 1, maxfn(100)),
1334
+ z: getset("xyz", 2, maxfn(108.833)),
1335
+ l: getset("lab", 0, maxfn(100)),
1336
+ a: getset("lab", 1),
1337
+ b: getset("lab", 2),
1338
+ keyword(value) {
1339
+ if (value !== void 0) {
1340
+ return new Color(value);
1341
+ }
1342
+ return convert[this.model].keyword(this.color);
1343
+ },
1344
+ hex(value) {
1345
+ if (value !== void 0) {
1346
+ return new Color(value);
1347
+ }
1348
+ return colorString.to.hex(this.rgb().round().color);
1349
+ },
1350
+ hexa(value) {
1351
+ if (value !== void 0) {
1352
+ return new Color(value);
1353
+ }
1354
+ const rgbArray = this.rgb().round().color;
1355
+ let alphaHex = Math.round(this.valpha * 255).toString(16).toUpperCase();
1356
+ if (alphaHex.length === 1) {
1357
+ alphaHex = "0" + alphaHex;
1358
+ }
1359
+ return colorString.to.hex(rgbArray) + alphaHex;
1360
+ },
1361
+ rgbNumber() {
1362
+ const rgb = this.rgb().color;
1363
+ return (rgb[0] & 255) << 16 | (rgb[1] & 255) << 8 | rgb[2] & 255;
1364
+ },
1365
+ luminosity() {
1366
+ const rgb = this.rgb().color;
1367
+ const lum = [];
1368
+ for (const [i, element] of rgb.entries()) {
1369
+ const chan = element / 255;
1370
+ lum[i] = chan <= 0.04045 ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
1371
+ }
1372
+ return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
1373
+ },
1374
+ contrast(color2) {
1375
+ const lum1 = this.luminosity();
1376
+ const lum2 = color2.luminosity();
1377
+ if (lum1 > lum2) {
1378
+ return (lum1 + 0.05) / (lum2 + 0.05);
1379
+ }
1380
+ return (lum2 + 0.05) / (lum1 + 0.05);
1381
+ },
1382
+ level(color2) {
1383
+ const contrastRatio = this.contrast(color2);
1384
+ if (contrastRatio >= 7) {
1385
+ return "AAA";
1386
+ }
1387
+ return contrastRatio >= 4.5 ? "AA" : "";
1388
+ },
1389
+ isDark() {
1390
+ const rgb = this.rgb().color;
1391
+ const yiq = (rgb[0] * 2126 + rgb[1] * 7152 + rgb[2] * 722) / 1e4;
1392
+ return yiq < 128;
1393
+ },
1394
+ isLight() {
1395
+ return !this.isDark();
1396
+ },
1397
+ negate() {
1398
+ const rgb = this.rgb();
1399
+ for (let i = 0; i < 3; i++) {
1400
+ rgb.color[i] = 255 - rgb.color[i];
1401
+ }
1402
+ return rgb;
1403
+ },
1404
+ lighten(ratio) {
1405
+ const hsl = this.hsl();
1406
+ hsl.color[2] += hsl.color[2] * ratio;
1407
+ return hsl;
1408
+ },
1409
+ darken(ratio) {
1410
+ const hsl = this.hsl();
1411
+ hsl.color[2] -= hsl.color[2] * ratio;
1412
+ return hsl;
1413
+ },
1414
+ saturate(ratio) {
1415
+ const hsl = this.hsl();
1416
+ hsl.color[1] += hsl.color[1] * ratio;
1417
+ return hsl;
1418
+ },
1419
+ desaturate(ratio) {
1420
+ const hsl = this.hsl();
1421
+ hsl.color[1] -= hsl.color[1] * ratio;
1422
+ return hsl;
1423
+ },
1424
+ whiten(ratio) {
1425
+ const hwb = this.hwb();
1426
+ hwb.color[1] += hwb.color[1] * ratio;
1427
+ return hwb;
1428
+ },
1429
+ blacken(ratio) {
1430
+ const hwb = this.hwb();
1431
+ hwb.color[2] += hwb.color[2] * ratio;
1432
+ return hwb;
1433
+ },
1434
+ grayscale() {
1435
+ const rgb = this.rgb().color;
1436
+ const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
1437
+ return Color.rgb(value, value, value);
1438
+ },
1439
+ fade(ratio) {
1440
+ return this.alpha(this.valpha - this.valpha * ratio);
1441
+ },
1442
+ opaquer(ratio) {
1443
+ return this.alpha(this.valpha + this.valpha * ratio);
1444
+ },
1445
+ rotate(degrees) {
1446
+ const hsl = this.hsl();
1447
+ let hue = hsl.color[0];
1448
+ hue = (hue + degrees) % 360;
1449
+ hue = hue < 0 ? 360 + hue : hue;
1450
+ hsl.color[0] = hue;
1451
+ return hsl;
1452
+ },
1453
+ mix(mixinColor, weight) {
1454
+ if (!mixinColor || !mixinColor.rgb) {
1455
+ throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
1456
+ }
1457
+ const color1 = mixinColor.rgb();
1458
+ const color2 = this.rgb();
1459
+ const p = weight === void 0 ? 0.5 : weight;
1460
+ const w = 2 * p - 1;
1461
+ const a = color1.alpha() - color2.alpha();
1462
+ const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
1463
+ const w2 = 1 - w1;
1464
+ return Color.rgb(
1465
+ w1 * color1.red() + w2 * color2.red(),
1466
+ w1 * color1.green() + w2 * color2.green(),
1467
+ w1 * color1.blue() + w2 * color2.blue(),
1468
+ color1.alpha() * p + color2.alpha() * (1 - p)
1469
+ );
1470
+ }
1471
+ };
1472
+ for (const model of Object.keys(convert)) {
1473
+ if (skippedModels.includes(model)) {
1474
+ continue;
1475
+ }
1476
+ const { channels } = convert[model];
1477
+ Color.prototype[model] = function(...args) {
1478
+ if (this.model === model) {
1479
+ return new Color(this);
1480
+ }
1481
+ if (args.length > 0) {
1482
+ return new Color(args, model);
1483
+ }
1484
+ return new Color([...assertArray(convert[this.model][model].raw(this.color)), this.valpha], model);
1485
+ };
1486
+ Color[model] = function(...args) {
1487
+ let color2 = args[0];
1488
+ if (typeof color2 === "number") {
1489
+ color2 = zeroArray(args, channels);
1490
+ }
1491
+ return new Color(color2, model);
1492
+ };
1493
+ }
1494
+ function roundTo(number, places) {
1495
+ return Number(number.toFixed(places));
1496
+ }
1497
+ function roundToPlace(places) {
1498
+ return function(number) {
1499
+ return roundTo(number, places);
1500
+ };
1501
+ }
1502
+ function getset(model, channel, modifier) {
1503
+ model = Array.isArray(model) ? model : [model];
1504
+ for (const m of model) {
1505
+ (limiters[m] || (limiters[m] = []))[channel] = modifier;
1506
+ }
1507
+ model = model[0];
1508
+ return function(value) {
1509
+ let result;
1510
+ if (value !== void 0) {
1511
+ if (modifier) {
1512
+ value = modifier(value);
1513
+ }
1514
+ result = this[model]();
1515
+ result.color[channel] = value;
1516
+ return result;
1517
+ }
1518
+ result = this[model]().color[channel];
1519
+ if (modifier) {
1520
+ result = modifier(result);
1521
+ }
1522
+ return result;
1523
+ };
1524
+ }
1525
+ function maxfn(max) {
1526
+ return function(v) {
1527
+ return Math.max(0, Math.min(max, v));
1528
+ };
1529
+ }
1530
+ function assertArray(value) {
1531
+ return Array.isArray(value) ? value : [value];
1532
+ }
1533
+ function zeroArray(array, length) {
1534
+ for (let i = 0; i < length; i++) {
1535
+ if (typeof array[i] !== "number") {
1536
+ array[i] = 0;
1537
+ }
1538
+ }
1539
+ return array;
1540
+ }
1541
+ var color = Color;
1542
+ const Color$1 = /* @__PURE__ */ getDefaultExportFromCjs(color);
1543
+ function hexToColor(hex) {
1544
+ const colorIns = Color$1(hex);
1545
+ return colorIns;
1546
+ }
1547
+ function colorToHex(color2) {
1548
+ return color2.hex();
1549
+ }
1550
+ function getLightColorAndDepth(color2) {
1551
+ const { h, s, v } = color2.hsv().object();
1552
+ return {
1553
+ color: Color$1.hsv(h, s, 100),
1554
+ value: v
1555
+ };
1556
+ }
1557
+ function getOriginColorByLightAndDepth(color2, value) {
1558
+ const { h, s } = color2.hsv().object();
1559
+ return Color$1.hsv(h, s, value);
1560
+ }
1561
+ function getOriginHexByLightAndDepth(color2, value) {
1562
+ const originColor = getOriginColorByLightAndDepth(color2, value);
1563
+ return colorToHex(originColor);
1564
+ }
1565
+ function useColorArea() {
1566
+ const colorAreaCanvas = vue.ref();
1567
+ const canvasWidth = 255 * 6 + 1;
1568
+ const canvasHeight = 256;
1569
+ function drawColorArea() {
1570
+ if (!colorAreaCanvas.value) {
1571
+ return;
1572
+ }
1573
+ const canvas = colorAreaCanvas.value;
1574
+ canvas.width = canvasWidth;
1575
+ canvas.height = canvasHeight;
1576
+ const ctx = canvas.getContext("2d");
1577
+ if (!ctx) {
1578
+ return;
1579
+ }
1580
+ ctx.clearRect(0, 0, canvasWidth, canvasHeight);
1581
+ const colorGradient = ctx.createLinearGradient(0, 0, canvasWidth, 0);
1582
+ colorGradient.addColorStop(0, "#FF0000");
1583
+ colorGradient.addColorStop(1 / 6, "#FFFF00");
1584
+ colorGradient.addColorStop(1 / 3, "#00FF00");
1585
+ colorGradient.addColorStop(1 / 2, "#00FFFF");
1586
+ colorGradient.addColorStop(2 / 3, "#0000FF");
1587
+ colorGradient.addColorStop(5 / 6, "#FF00FF");
1588
+ colorGradient.addColorStop(1, "#FF0000");
1589
+ ctx.fillStyle = colorGradient;
1590
+ ctx.fillRect(0, 0, canvasWidth, canvasHeight);
1591
+ const whiteGradient = ctx.createLinearGradient(0, canvasHeight, 0, 0);
1592
+ whiteGradient.addColorStop(0, "rgb(255 255 255 / 100%)");
1593
+ whiteGradient.addColorStop(1, "rgb(255 255 255 / 0%)");
1594
+ ctx.fillStyle = whiteGradient;
1595
+ ctx.fillRect(0, 0, canvasWidth, canvasHeight);
1596
+ }
1597
+ function getCoordinateByHex(hex) {
1598
+ const color2 = hexToColor(hex);
1599
+ return getCoordinateByColor(color2);
1600
+ }
1601
+ function getCoordinateByColor(color2) {
1602
+ const { r, g, b } = color2.rgb().object();
1603
+ const colorItems = [
1604
+ {
1605
+ type: "r",
1606
+ value: r
1607
+ },
1608
+ {
1609
+ type: "g",
1610
+ value: g
1611
+ },
1612
+ {
1613
+ type: "b",
1614
+ value: b
1615
+ }
1616
+ ];
1617
+ colorItems.sort((a, b2) => b2.value - a.value);
1618
+ const maxColor = colorItems[0];
1619
+ const secondColor = colorItems[1];
1620
+ const curColorType = maxColor.type + secondColor.type;
1621
+ let coordinateX = 0;
1622
+ let coordinateY = colorItems[2].value;
1623
+ if (curColorType === "rg" || curColorType === "gr") {
1624
+ coordinateX = 255;
1625
+ if (secondColor.type === "r") {
1626
+ coordinateX += 255 - getSecondColorDistance(coordinateY, secondColor.value);
1627
+ } else {
1628
+ coordinateX -= 255 - getSecondColorDistance(coordinateY, secondColor.value);
1629
+ }
1630
+ } else if (curColorType === "gb" || curColorType === "bg") {
1631
+ coordinateX = 255 * 3;
1632
+ if (secondColor.type === "g") {
1633
+ coordinateX += 255 - getSecondColorDistance(coordinateY, secondColor.value);
1634
+ } else {
1635
+ coordinateX -= 255 - getSecondColorDistance(coordinateY, secondColor.value);
1636
+ }
1637
+ } else if (curColorType === "rb" || curColorType === "br") {
1638
+ coordinateX = 255 * 5;
1639
+ if (secondColor.type === "b") {
1640
+ coordinateX += 255 - getSecondColorDistance(coordinateY, secondColor.value);
1641
+ } else {
1642
+ coordinateX -= 255 - getSecondColorDistance(coordinateY, secondColor.value);
1643
+ }
1644
+ }
1645
+ return {
1646
+ x: coordinateX,
1647
+ y: coordinateY
1648
+ };
1649
+ }
1650
+ function getSecondColorDistance(y, target) {
1651
+ return y === 255 ? 255 : (255 * target - 255 * y) / (255 - y);
1652
+ }
1653
+ function getColorByCoordinate(x, y, width, height) {
1654
+ if (!colorAreaCanvas.value) {
1655
+ return Color$1();
1656
+ }
1657
+ const scaleX = canvasWidth / width;
1658
+ const scaleY = canvasHeight / height;
1659
+ x = Math.min(x * scaleX, canvasWidth - 1);
1660
+ y = Math.min(y * scaleY, canvasHeight - 1);
1661
+ const color2 = getBaseColorFromCoodinage(x, y);
1662
+ return color2;
1663
+ }
1664
+ function getBaseColorFromCoodinage(x, y) {
1665
+ let r = 0;
1666
+ let g = 0;
1667
+ let b = 0;
1668
+ const COLOR_GAP = 255;
1669
+ const redRange = numberInGap(x, 0, COLOR_GAP) || numberInGap(x, COLOR_GAP * 5, COLOR_GAP * 6);
1670
+ const greenRange = numberInGap(x, COLOR_GAP, COLOR_GAP * 3);
1671
+ const blueRange = numberInGap(x, COLOR_GAP * 3, COLOR_GAP * 5);
1672
+ if (redRange) {
1673
+ r = 255;
1674
+ } else if (x <= COLOR_GAP * 2) {
1675
+ r = Math.max(2 * COLOR_GAP - x, 0);
1676
+ } else if (x >= COLOR_GAP * 4) {
1677
+ r = Math.max(x - COLOR_GAP * 4, 0);
1678
+ }
1679
+ if (greenRange) {
1680
+ g = 255;
1681
+ } else if (x < COLOR_GAP) {
1682
+ g = Math.max(x, 0);
1683
+ } else {
1684
+ g = Math.max(COLOR_GAP * 4 - x, 0);
1685
+ }
1686
+ if (blueRange) {
1687
+ b = 255;
1688
+ } else if (x < COLOR_GAP * 3) {
1689
+ b = Math.max(x - COLOR_GAP * 2, 0);
1690
+ } else {
1691
+ b = Math.max(COLOR_GAP * 6 - x, 0);
1692
+ }
1693
+ const rGap = COLOR_GAP - r;
1694
+ const gGap = COLOR_GAP - g;
1695
+ const bGap = COLOR_GAP - b;
1696
+ const scale = y / COLOR_GAP;
1697
+ r += rGap * scale;
1698
+ g += gGap * scale;
1699
+ b += bGap * scale;
1700
+ return Color$1.rgb(r, g, b);
1701
+ }
1702
+ function numberInGap(num, begin, end) {
1703
+ return num >= begin && num <= end;
1704
+ }
1705
+ vue.onMounted(() => {
1706
+ drawColorArea();
1707
+ });
1708
+ return {
1709
+ canvasWidth,
1710
+ canvasHeight,
1711
+ colorAreaCanvas,
1712
+ drawColorArea,
1713
+ getCoordinateByColor,
1714
+ getCoordinateByHex,
1715
+ getColorByCoordinate
1716
+ };
1717
+ }
1718
+ function throttle(fn, time = 200) {
1719
+ let timer = null;
1720
+ return function(...args) {
1721
+ const ctx = this;
1722
+ if (timer) {
1723
+ return;
1724
+ } else {
1725
+ timer = window.setTimeout(() => {
1726
+ fn.apply(ctx, args);
1727
+ timer = null;
1728
+ }, time);
1729
+ }
1730
+ };
1731
+ }
1732
+ class EventBus {
1733
+ constructor() {
1734
+ __publicField(this, "_eventMap");
1735
+ this._eventMap = /* @__PURE__ */ new Map();
1736
+ }
1737
+ on(key, handler) {
1738
+ const handlers = this._eventMap.get(key);
1739
+ if (handlers) {
1740
+ handlers.add(handler);
1741
+ } else {
1742
+ const set = /* @__PURE__ */ new Set();
1743
+ set.add(handler);
1744
+ this._eventMap.set(key, set);
1745
+ }
1746
+ }
1747
+ off(key, handler) {
1748
+ const handlers = this._eventMap.get(key);
1749
+ if (!handlers) return;
1750
+ if (handler) {
1751
+ handlers.delete(handler);
1752
+ } else {
1753
+ handlers.clear();
1754
+ }
1755
+ }
1756
+ emit(key, ...payload) {
1757
+ const handlers = this._eventMap.get(key);
1758
+ if (!handlers) return;
1759
+ for (const callback of handlers.values()) {
1760
+ callback(...payload);
1761
+ }
1762
+ }
1763
+ }
1764
+ const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
1765
+ function useOperateEvent() {
1766
+ const colorAreaRef = vue.ref();
1767
+ const circlePickerCoordinate = vue.reactive({
1768
+ x: 0,
1769
+ y: 0
1770
+ });
1771
+ function handleTouchStart(e) {
1772
+ if (e.touches.length === 0) {
1773
+ return;
1774
+ }
1775
+ e.preventDefault();
1776
+ const { clientX, clientY } = e.touches[0];
1777
+ handleCirclePickerCoordinateChange({
1778
+ x: clientX,
1779
+ y: clientY
1780
+ });
1781
+ document.body.addEventListener("touchmove", handleTouchMove);
1782
+ document.body.addEventListener("touchend", handleTouchEnd);
1783
+ }
1784
+ function handleTouchMove(e) {
1785
+ if (e.touches.length > 1) {
1786
+ return;
1787
+ }
1788
+ const { clientX, clientY } = e.touches[0];
1789
+ handleCirclePickerCoordinateChange({
1790
+ x: clientX,
1791
+ y: clientY
1792
+ });
1793
+ }
1794
+ function handleTouchEnd() {
1795
+ document.body.removeEventListener("touchmove", handleTouchMove);
1796
+ document.body.removeEventListener("touchend", handleTouchEnd);
1797
+ }
1798
+ function handleMounseDown(e) {
1799
+ document.body.addEventListener("mousemove", handleMouseMove);
1800
+ document.body.addEventListener("mouseup", handleMouseUp);
1801
+ handleCirclePickerCoordinateChange({
1802
+ x: e.clientX,
1803
+ y: e.clientY
1804
+ });
1805
+ }
1806
+ function handleMouseMove(e) {
1807
+ handleCirclePickerCoordinateChange({
1808
+ x: e.clientX,
1809
+ y: e.clientY
1810
+ });
1811
+ }
1812
+ const handleCirclePickerCoordinateChange = throttle(handleCirclePickerCoordinateChangeFn, 20);
1813
+ function handleCirclePickerCoordinateChangeFn(point) {
1814
+ var _a;
1815
+ const { x: clientX, y: clientY } = point;
1816
+ const colorAreaRect = (_a = colorAreaRef.value) == null ? void 0 : _a.getBoundingClientRect();
1817
+ if (!colorAreaRect) {
1818
+ return;
1819
+ }
1820
+ const { left, top, width, height } = colorAreaRect;
1821
+ let x = 0;
1822
+ let y = 0;
1823
+ if (clientX <= left) {
1824
+ x = 0;
1825
+ } else if (clientX >= left + width) {
1826
+ x = width;
1827
+ } else {
1828
+ x = clientX - left;
1829
+ }
1830
+ if (clientY <= top) {
1831
+ y = 0;
1832
+ } else if (clientY >= top + height) {
1833
+ y = height;
1834
+ } else {
1835
+ y = clientY - top;
1836
+ }
1837
+ circlePickerCoordinate.x = Math.round(x);
1838
+ circlePickerCoordinate.y = Math.round(y);
1839
+ }
1840
+ function handleMouseUp() {
1841
+ document.body.removeEventListener("mousemove", handleMouseMove);
1842
+ document.body.removeEventListener("mouseup", handleMouseUp);
1843
+ }
1844
+ function setCirclePickerCoordinate(x, y, width, height) {
1845
+ var _a;
1846
+ const colorAreaRect = (_a = colorAreaRef.value) == null ? void 0 : _a.getBoundingClientRect();
1847
+ if (!colorAreaRect) {
1848
+ return;
1849
+ }
1850
+ const { width: AreaWidth, height: AreaHeight } = colorAreaRect;
1851
+ const scaleX = AreaWidth / width;
1852
+ const scaleY = AreaHeight / height;
1853
+ circlePickerCoordinate.x = x * scaleX;
1854
+ circlePickerCoordinate.y = y * scaleY;
1855
+ }
1856
+ vue.onMounted(() => {
1857
+ var _a, _b;
1858
+ if (isMobile) {
1859
+ (_a = colorAreaRef.value) == null ? void 0 : _a.addEventListener("touchstart", handleTouchStart);
1860
+ } else {
1861
+ (_b = colorAreaRef.value) == null ? void 0 : _b.addEventListener("mousedown", handleMounseDown);
1862
+ }
1863
+ });
1864
+ vue.onBeforeUnmount(() => {
1865
+ var _a, _b;
1866
+ if (isMobile) {
1867
+ (_a = colorAreaRef.value) == null ? void 0 : _a.removeEventListener("touchstart", handleTouchStart);
1868
+ document.body.removeEventListener("touchmove", handleTouchMove);
1869
+ document.body.removeEventListener("touchend", handleTouchEnd);
1870
+ } else {
1871
+ (_b = colorAreaRef.value) == null ? void 0 : _b.removeEventListener("mousedown", handleMounseDown);
1872
+ document.body.removeEventListener("mousemove", handleMouseMove);
1873
+ document.body.removeEventListener("mouseup", handleMouseUp);
1874
+ }
1875
+ });
1876
+ return {
1877
+ colorAreaRef,
1878
+ circlePickerCoordinate,
1879
+ setCirclePickerCoordinate
1880
+ };
1881
+ }
1882
+ const _hoisted_1$3 = { class: "color-form" };
1883
+ const _hoisted_2$2 = { class: "hex-color mb-12" };
1884
+ const _hoisted_3$2 = { class: "form-group mb-12" };
1885
+ const _hoisted_4$2 = { class: "form-group mb-12" };
1886
+ const DEFAULT_COLOR$1 = "#ffffff";
1887
+ const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
1888
+ __name: "ColorForm",
1889
+ props: {
1890
+ modelValue: {}
1891
+ },
1892
+ emits: ["change"],
1893
+ setup(__props, { emit: __emit }) {
1894
+ const props = __props;
1895
+ const emits = __emit;
1896
+ const hexColor = vue.ref(Color$1(props.modelValue || DEFAULT_COLOR$1).hex());
1897
+ const formInputRGB = vue.reactive(
1898
+ Color$1(hexColor.value || DEFAULT_COLOR$1).rgb().object()
1899
+ );
1900
+ const formInputHSV = vue.reactive(
1901
+ Color$1(hexColor.value || DEFAULT_COLOR$1).hsv().object()
1902
+ );
1903
+ function hexFormater(value) {
1904
+ return `#${value.replace(/[^0-9A-F]/gi, "").slice(0, 6).toUpperCase()}`;
1905
+ }
1906
+ vue.watch(
1907
+ () => props.modelValue,
1908
+ (value) => {
1909
+ const colorIns = Color$1(value);
1910
+ hexColor.value = colorIns.hex();
1911
+ const { r, g, b } = colorIns.rgb().object();
1912
+ const { h, s, v } = colorIns.hsv().object();
1913
+ Object.assign(formInputRGB, {
1914
+ r,
1915
+ g,
1916
+ b
1917
+ });
1918
+ Object.assign(formInputHSV, {
1919
+ h,
1920
+ s,
1921
+ v
1922
+ });
1923
+ }
1924
+ );
1925
+ function handleHexColorChange() {
1926
+ let value = hexColor.value || "";
1927
+ const len = value.replace(/[^0-9A-F]/gi, "").length;
1928
+ if (len === 6) {
1929
+ emits("change", hexColor.value);
1930
+ } else {
1931
+ hexColor.value = props.modelValue;
1932
+ }
1933
+ }
1934
+ function handleRgbColorChange() {
1935
+ const { r, g, b } = formInputRGB;
1936
+ emits("change", Color$1.rgb(r, g, b).hex().toString());
1937
+ }
1938
+ function handleHsvColorChange() {
1939
+ const { h, s, v } = formInputHSV;
1940
+ emits("change", Color$1.hsv(h, s, v).hex().toString());
1941
+ }
1942
+ return (_ctx, _cache) => {
1943
+ const _component_el_input = vue.resolveComponent("el-input");
1944
+ const _component_el_input_number = vue.resolveComponent("el-input-number");
1945
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$3, [
1946
+ vue.createElementVNode("div", _hoisted_2$2, [
1947
+ vue.createVNode(_component_el_input, {
1948
+ modelValue: hexColor.value,
1949
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => hexColor.value = $event),
1950
+ formatter: hexFormater,
1951
+ onChange: handleHexColorChange
1952
+ }, null, 8, ["modelValue"])
1953
+ ]),
1954
+ vue.createElementVNode("div", _hoisted_3$2, [
1955
+ _cache[7] || (_cache[7] = vue.createElementVNode("div", { class: "label" }, "RGB", -1)),
1956
+ vue.createVNode(_component_el_input_number, {
1957
+ modelValue: formInputRGB.r,
1958
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => formInputRGB.r = $event),
1959
+ onChange: handleRgbColorChange,
1960
+ "step-strictly": "",
1961
+ min: 0,
1962
+ max: 255,
1963
+ step: 1,
1964
+ controls: false
1965
+ }, null, 8, ["modelValue"]),
1966
+ vue.createVNode(_component_el_input_number, {
1967
+ modelValue: formInputRGB.g,
1968
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => formInputRGB.g = $event),
1969
+ onChange: handleRgbColorChange,
1970
+ "step-strictly": "",
1971
+ min: 0,
1972
+ max: 255,
1973
+ step: 1,
1974
+ controls: false
1975
+ }, null, 8, ["modelValue"]),
1976
+ vue.createVNode(_component_el_input_number, {
1977
+ modelValue: formInputRGB.b,
1978
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => formInputRGB.b = $event),
1979
+ onChange: handleRgbColorChange,
1980
+ "step-strictly": "",
1981
+ min: 0,
1982
+ max: 255,
1983
+ step: 1,
1984
+ controls: false
1985
+ }, null, 8, ["modelValue"])
1986
+ ]),
1987
+ vue.createElementVNode("div", _hoisted_4$2, [
1988
+ _cache[8] || (_cache[8] = vue.createElementVNode("div", { class: "label" }, "HSV", -1)),
1989
+ vue.createVNode(_component_el_input_number, {
1990
+ modelValue: formInputHSV.h,
1991
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => formInputHSV.h = $event),
1992
+ onChange: handleHsvColorChange,
1993
+ min: 0,
1994
+ max: 360,
1995
+ "step-strictly": "",
1996
+ step: 1,
1997
+ controls: false
1998
+ }, null, 8, ["modelValue"]),
1999
+ vue.createVNode(_component_el_input_number, {
2000
+ modelValue: formInputHSV.s,
2001
+ "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => formInputHSV.s = $event),
2002
+ onChange: handleHsvColorChange,
2003
+ min: 0,
2004
+ max: 100,
2005
+ "step-strictly": "",
2006
+ step: 1,
2007
+ controls: false
2008
+ }, null, 8, ["modelValue"]),
2009
+ vue.createVNode(_component_el_input_number, {
2010
+ modelValue: formInputHSV.v,
2011
+ "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => formInputHSV.v = $event),
2012
+ onChange: handleHsvColorChange,
2013
+ "step-strictly": "",
2014
+ min: 0,
2015
+ max: 100,
2016
+ controls: false
2017
+ }, null, 8, ["modelValue"])
2018
+ ])
2019
+ ]);
2020
+ };
2021
+ }
2022
+ });
2023
+ const _export_sfc = (sfc, props) => {
2024
+ const target = sfc.__vccOpts || sfc;
2025
+ for (const [key, val] of props) {
2026
+ target[key] = val;
2027
+ }
2028
+ return target;
2029
+ };
2030
+ const ColorForm = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-30715da5"]]);
2031
+ const _hoisted_1$2 = { class: "preset-colors" };
2032
+ const _hoisted_2$1 = { class: "preset-colors_title" };
2033
+ const _hoisted_3$1 = { class: "preset-color_list" };
2034
+ const _hoisted_4$1 = ["onClick"];
2035
+ const _sfc_main$4 = /* @__PURE__ */ vue.defineComponent({
2036
+ __name: "PresetColors",
2037
+ props: {
2038
+ title: {},
2039
+ presetColors: {}
2040
+ },
2041
+ emits: ["change"],
2042
+ setup(__props, { emit: __emit }) {
2043
+ const defaultPresetColors = [
2044
+ "#000000",
2045
+ "#FFFFFF",
2046
+ "#E3822D",
2047
+ "#DCE24F",
2048
+ "#1DCF69",
2049
+ "#6DE5B9",
2050
+ "#11A1F2",
2051
+ "#AA43FF",
2052
+ "#F0689C",
2053
+ "#F8D28B",
2054
+ "#606368",
2055
+ "#E83C34",
2056
+ "#EEBE29",
2057
+ "#89F0AC",
2058
+ "#2FBC9E",
2059
+ "#56CCF2",
2060
+ "#1C1DFA",
2061
+ "#DC88F5",
2062
+ "#D4C595",
2063
+ "#C52F65"
2064
+ ];
2065
+ const props = __props;
2066
+ const preColors = vue.computed(() => {
2067
+ return !props.presetColors ? defaultPresetColors : props.presetColors;
2068
+ });
2069
+ const emits = __emit;
2070
+ function handleClickColor(color2) {
2071
+ emits("change", color2);
2072
+ }
2073
+ return (_ctx, _cache) => {
2074
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$2, [
2075
+ vue.createElementVNode("div", _hoisted_2$1, vue.toDisplayString(props.title || "系统预设色彩"), 1),
2076
+ vue.createElementVNode("div", _hoisted_3$1, [
2077
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(preColors.value, (color2) => {
2078
+ return vue.openBlock(), vue.createElementBlock("div", {
2079
+ class: "preset-color_list-item",
2080
+ onClick: ($event) => handleClickColor(color2),
2081
+ key: color2,
2082
+ style: vue.normalizeStyle({ backgroundColor: color2 })
2083
+ }, null, 12, _hoisted_4$1);
2084
+ }), 128))
2085
+ ])
2086
+ ]);
2087
+ };
2088
+ }
2089
+ });
2090
+ const PresetColors = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-bf94ca7c"]]);
2091
+ const _hoisted_1$1 = { class: "color-picker" };
2092
+ const _hoisted_2 = { class: "title" };
2093
+ const _hoisted_3 = { class: "color-area__wrapper" };
2094
+ const _hoisted_4 = { class: "slider-color" };
2095
+ const DEFAULT_COLOR = "#ffffff";
2096
+ const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
2097
+ ...{
2098
+ name: "HvColorPicker"
2099
+ },
2100
+ __name: "ColorPicker",
2101
+ props: /* @__PURE__ */ vue.mergeModels({
2102
+ title: {},
2103
+ presetTitle: {},
2104
+ presetColors: {}
2105
+ }, {
2106
+ "modelValue": {
2107
+ type: String,
2108
+ default: DEFAULT_COLOR
2109
+ },
2110
+ "modelModifiers": {}
2111
+ }),
2112
+ emits: /* @__PURE__ */ vue.mergeModels(["update:model-value"], ["update:modelValue"]),
2113
+ setup(__props, { emit: __emit }) {
2114
+ const props = __props;
2115
+ const emits = __emit;
2116
+ const { colorAreaCanvas, getColorByCoordinate, getCoordinateByColor, canvasWidth, canvasHeight } = useColorArea();
2117
+ const { colorAreaRef, circlePickerCoordinate, setCirclePickerCoordinate } = useOperateEvent();
2118
+ const color2 = vue.useModel(__props, "modelValue");
2119
+ const lightColor = vue.ref(Color$1(DEFAULT_COLOR));
2120
+ const colorDepth = vue.ref(100);
2121
+ const originHexColor = vue.computed(() => {
2122
+ if (lightColor.value) {
2123
+ const hex = getOriginHexByLightAndDepth(lightColor.value, colorDepth.value);
2124
+ return hex;
2125
+ }
2126
+ return DEFAULT_COLOR;
2127
+ });
2128
+ vue.watch(color2, (val) => {
2129
+ const hex = getOriginHexByLightAndDepth(lightColor.value, colorDepth.value);
2130
+ if (hex === val) {
2131
+ return;
2132
+ }
2133
+ handleColorChange(val);
2134
+ });
2135
+ vue.watch(
2136
+ () => circlePickerCoordinate,
2137
+ (coordianate) => {
2138
+ var _a;
2139
+ const rect = (_a = colorAreaRef.value) == null ? void 0 : _a.getBoundingClientRect();
2140
+ if (!rect) {
2141
+ return;
2142
+ }
2143
+ const color22 = getColorByCoordinate(coordianate.x, coordianate.y, rect.width, rect.height);
2144
+ lightColor.value = color22;
2145
+ },
2146
+ {
2147
+ deep: true
2148
+ }
2149
+ );
2150
+ const cilcleStyle = vue.computed(() => {
2151
+ if (!color2.value) {
2152
+ return {
2153
+ top: "100%",
2154
+ left: "0",
2155
+ backgroundColor: "#ffffff"
2156
+ };
2157
+ }
2158
+ return {
2159
+ top: circlePickerCoordinate.y + "px",
2160
+ left: circlePickerCoordinate.x + "px",
2161
+ backgroundColor: lightColor.value.hex()
2162
+ };
2163
+ });
2164
+ const sliderBackStyle = vue.computed(() => {
2165
+ const lightHex = colorToHex(lightColor.value);
2166
+ return {
2167
+ "--el-slider-runway-bg-color": `linear-gradient(to right, #000000, ${lightHex})`,
2168
+ "--el-slider-main-bg-color": lightHex
2169
+ };
2170
+ });
2171
+ vue.watch(
2172
+ () => originHexColor.value,
2173
+ (value, oldValue) => {
2174
+ if (value !== oldValue) {
2175
+ emits("update:model-value", value);
2176
+ return;
2177
+ }
2178
+ }
2179
+ );
2180
+ function handleColorChange(hex) {
2181
+ const color22 = hexToColor(hex);
2182
+ const { color: lightRgb, value: depth } = getLightColorAndDepth(color22);
2183
+ lightColor.value = lightRgb;
2184
+ colorDepth.value = depth;
2185
+ const coordin = getCoordinateByColor(lightRgb);
2186
+ setCirclePickerCoordinate(coordin.x, coordin.y, canvasWidth, canvasHeight);
2187
+ }
2188
+ vue.onMounted(() => {
2189
+ handleColorChange(color2.value);
2190
+ });
2191
+ return (_ctx, _cache) => {
2192
+ const _component_ElSlider = vue.resolveComponent("ElSlider");
2193
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
2194
+ vue.createElementVNode("div", _hoisted_2, vue.toDisplayString(props.title || "颜色编辑器"), 1),
2195
+ vue.createElementVNode("div", _hoisted_3, [
2196
+ vue.createElementVNode("div", {
2197
+ class: "color-area",
2198
+ ref_key: "colorAreaRef",
2199
+ ref: colorAreaRef
2200
+ }, [
2201
+ vue.createElementVNode("canvas", {
2202
+ ref_key: "colorAreaCanvas",
2203
+ ref: colorAreaCanvas
2204
+ }, null, 512),
2205
+ vue.createElementVNode("div", {
2206
+ class: "cur-color-circle",
2207
+ style: vue.normalizeStyle(cilcleStyle.value)
2208
+ }, null, 4)
2209
+ ], 512)
2210
+ ]),
2211
+ vue.createElementVNode("div", _hoisted_4, [
2212
+ vue.createVNode(_component_ElSlider, {
2213
+ modelValue: colorDepth.value,
2214
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => colorDepth.value = $event),
2215
+ min: 0,
2216
+ max: 100,
2217
+ "show-tooltip": false,
2218
+ style: vue.normalizeStyle(sliderBackStyle.value)
2219
+ }, null, 8, ["modelValue", "style"]),
2220
+ vue.createElementVNode("div", {
2221
+ class: "origin-color",
2222
+ style: vue.normalizeStyle({ backgroundColor: originHexColor.value })
2223
+ }, null, 4)
2224
+ ]),
2225
+ vue.createVNode(ColorForm, {
2226
+ "model-value": color2.value,
2227
+ onChange: handleColorChange
2228
+ }, null, 8, ["model-value"]),
2229
+ vue.createVNode(PresetColors, {
2230
+ onChange: handleColorChange,
2231
+ title: props.presetTitle,
2232
+ presetColors: props.presetColors
2233
+ }, null, 8, ["title", "presetColors"])
2234
+ ]);
2235
+ };
2236
+ }
2237
+ });
2238
+ const ColorPicker = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-e1675222"]]);
2239
+ const HvColorPicker = withInstall(ColorPicker);
2240
+ class DnDManager extends EventBus {
2241
+ constructor() {
2242
+ super();
2243
+ /** 是否开始拖动 */
2244
+ __publicField(this, "isDragStart", false);
2245
+ /** 拖动元素类型 */
2246
+ __publicField(this, "dragType");
2247
+ /** Draggable传递的数据,
2248
+ * 供Droppable使用
2249
+ */
2250
+ __publicField(this, "dragData");
2251
+ __publicField(this, "isSendFirstMovePos", false);
2252
+ /** 移动端长按一定时间才触发 onStart */
2253
+ __publicField(this, "touchStartPressTime", 300);
2254
+ /** touchstart事件触发的时的时间 */
2255
+ __publicField(this, "touchStartTime", 0);
2256
+ /** touchstart时间触发的位置 */
2257
+ __publicField(this, "touchStartPosition", { x: 0, y: 0 });
2258
+ /** onMove最后位置 */
2259
+ __publicField(this, "lastMovePoint", { x: 0, y: 0 });
2260
+ __publicField(this, "emitTouchStartTimer");
2261
+ __publicField(this, "destroy", () => {
2262
+ });
2263
+ this.bindEventListener();
2264
+ }
2265
+ updateDargInfo(type, data) {
2266
+ if (type === void 0 || type === null) {
2267
+ throw new Error("请传入拖动元素 type");
2268
+ }
2269
+ this.isDragStart = true;
2270
+ this.dragType = type;
2271
+ this.dragData = data;
2272
+ this.emitTouchStartTimer && clearTimeout(this.emitTouchStartTimer);
2273
+ this.emitTouchStartTimer = void 0;
2274
+ }
2275
+ /**
2276
+ * 通知 Draggable 开始点击
2277
+ * @param point
2278
+ */
2279
+ onDown(point) {
2280
+ this.emit("down", point);
2281
+ }
2282
+ /**
2283
+ * 通知 Draggable 拖拽开始
2284
+ * @param point
2285
+ */
2286
+ onFirstMove(point, e) {
2287
+ if (this.isDragStart) {
2288
+ return;
2289
+ }
2290
+ this.isSendFirstMovePos = true;
2291
+ this.emit("first-move", point, e);
2292
+ }
2293
+ /**
2294
+ * 通知 Draggable 拖拽开始
2295
+ * @param point
2296
+ */
2297
+ onStart(point) {
2298
+ if (this.isDragStart) {
2299
+ return;
2300
+ }
2301
+ this.emit("start", point);
2302
+ }
2303
+ /**
2304
+ * 通知 Draggable 移动
2305
+ * @param point
2306
+ * @returns
2307
+ */
2308
+ onMove(point) {
2309
+ if (!this.isDragStart || !this.dragType) {
2310
+ return;
2311
+ }
2312
+ this.lastMovePoint = point;
2313
+ this.emit("move", {
2314
+ type: this.dragType,
2315
+ data: this.dragData,
2316
+ point
2317
+ });
2318
+ }
2319
+ /**
2320
+ * 结束拖拽
2321
+ * @returns
2322
+ */
2323
+ onEnd() {
2324
+ this.emitTouchStartTimer && clearTimeout(this.emitTouchStartTimer);
2325
+ this.emitTouchStartTimer = void 0;
2326
+ this.isSendFirstMovePos = false;
2327
+ if (!this.isDragStart || !this.dragType) {
2328
+ return;
2329
+ }
2330
+ this.isDragStart = false;
2331
+ this.emit("end", {
2332
+ point: this.lastMovePoint,
2333
+ type: this.dragType,
2334
+ data: this.dragData
2335
+ });
2336
+ }
2337
+ onMouseDown(e) {
2338
+ if (e.buttons !== 1) {
2339
+ this.onEnd();
2340
+ return;
2341
+ }
2342
+ const { clientX, clientY } = e;
2343
+ const position = {
2344
+ x: clientX,
2345
+ y: clientY
2346
+ };
2347
+ this.touchStartTime = Date.now();
2348
+ this.touchStartPosition = position;
2349
+ this.emitTouchStartTimer && clearTimeout(this.emitTouchStartTimer);
2350
+ this.onDown(position);
2351
+ this.emitTouchStartTimer = window.setTimeout(() => {
2352
+ this.onStart(position);
2353
+ }, this.touchStartPressTime);
2354
+ }
2355
+ onMouseMove(e) {
2356
+ if (e.buttons !== 1) {
2357
+ this.onEnd();
2358
+ return;
2359
+ }
2360
+ const { clientX, clientY } = e;
2361
+ if (this.isDragStart) {
2362
+ e.preventDefault();
2363
+ e.stopPropagation();
2364
+ this.onMove({
2365
+ x: clientX,
2366
+ y: clientY
2367
+ });
2368
+ } else {
2369
+ if (!this.isSendFirstMovePos) {
2370
+ this.onFirstMove(
2371
+ {
2372
+ x: clientX,
2373
+ y: clientY
2374
+ },
2375
+ e
2376
+ );
2377
+ }
2378
+ const { x, y } = this.touchStartPosition;
2379
+ const timeInLimit = Date.now() - this.touchStartTime < this.touchStartPressTime;
2380
+ if (timeInLimit && (Math.abs(x - clientX) > 30 || Math.abs(y - clientY) > 30)) {
2381
+ clearTimeout(this.emitTouchStartTimer);
2382
+ this.emitTouchStartTimer = void 0;
2383
+ }
2384
+ }
2385
+ }
2386
+ onMouseUp() {
2387
+ this.onEnd();
2388
+ }
2389
+ onTouchStart(e) {
2390
+ if (e.touches.length > 1) {
2391
+ return;
2392
+ }
2393
+ const { clientX, clientY } = e.touches[0];
2394
+ const position = {
2395
+ x: clientX,
2396
+ y: clientY
2397
+ };
2398
+ this.touchStartTime = Date.now();
2399
+ this.touchStartPosition = position;
2400
+ this.onDown(position);
2401
+ this.emitTouchStartTimer = window.setTimeout(() => {
2402
+ this.onStart(position);
2403
+ }, this.touchStartPressTime);
2404
+ }
2405
+ onTouchMove(e) {
2406
+ if (e.touches.length > 1) {
2407
+ return;
2408
+ }
2409
+ const { clientX, clientY } = e.touches[0];
2410
+ if (this.isDragStart) {
2411
+ e.preventDefault();
2412
+ e.stopPropagation();
2413
+ this.onMove({
2414
+ x: clientX,
2415
+ y: clientY
2416
+ });
2417
+ } else {
2418
+ if (!this.isSendFirstMovePos) {
2419
+ this.onFirstMove(
2420
+ {
2421
+ x: clientX,
2422
+ y: clientY
2423
+ },
2424
+ e
2425
+ );
2426
+ }
2427
+ const { x, y } = this.touchStartPosition;
2428
+ const timeInLimit = Date.now() - this.touchStartTime < this.touchStartPressTime;
2429
+ if (timeInLimit && (Math.abs(x - clientX) > 30 || Math.abs(y - clientY) > 30)) {
2430
+ clearTimeout(this.emitTouchStartTimer);
2431
+ }
2432
+ }
2433
+ }
2434
+ onTouchEnd() {
2435
+ this.onEnd();
2436
+ }
2437
+ bindEventListener() {
2438
+ if (document.body) {
2439
+ const onTouchStart = this.onTouchStart.bind(this);
2440
+ const onTouchMove = this.onTouchMove.bind(this);
2441
+ const onTouchEnd = this.onTouchEnd.bind(this);
2442
+ const onMouseDown = this.onMouseDown.bind(this);
2443
+ const onMouseMove = this.onMouseMove.bind(this);
2444
+ const onMouseUp = this.onMouseUp.bind(this);
2445
+ if (isMobile) {
2446
+ document.body.addEventListener("touchstart", onTouchStart, { passive: false });
2447
+ document.body.addEventListener("touchmove", onTouchMove, { passive: false });
2448
+ document.body.addEventListener("touchend", onTouchEnd, { passive: false });
2449
+ } else {
2450
+ document.body.addEventListener("mousedown", onMouseDown);
2451
+ document.body.addEventListener("mousemove", onMouseMove);
2452
+ document.body.addEventListener("mouseup", onMouseUp);
2453
+ }
2454
+ this.destroy = () => {
2455
+ document.body.removeEventListener("touchstart", onTouchStart);
2456
+ document.body.removeEventListener("touchmove", onTouchMove);
2457
+ document.body.removeEventListener("touchend", onTouchEnd);
2458
+ document.body.removeEventListener("mousedown", onMouseDown);
2459
+ document.body.removeEventListener("mousemove", onMouseMove);
2460
+ document.body.removeEventListener("mouseup", onMouseUp);
2461
+ };
2462
+ } else {
2463
+ document.addEventListener("DOMContentLoaded", this.bindEventListener);
2464
+ }
2465
+ }
2466
+ removeEventListener() {
2467
+ this.destroy();
2468
+ }
2469
+ destroyed() {
2470
+ this.isDragStart = false;
2471
+ this.dragType = void 0;
2472
+ this.dragData = void 0;
2473
+ this.removeEventListener();
2474
+ }
2475
+ }
2476
+ const DnDManagerInstance = new DnDManager();
2477
+ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
2478
+ ...{
2479
+ name: "HvDraggable"
2480
+ },
2481
+ __name: "Draggable",
2482
+ props: {
2483
+ type: {},
2484
+ immediate: {},
2485
+ disabled: { type: Boolean, default: false },
2486
+ data: {}
2487
+ },
2488
+ setup(__props) {
2489
+ const ImmediateEnumType = {
2490
+ LEFT: "left",
2491
+ RIGHT: "right",
2492
+ TOP: "top",
2493
+ BOTTOM: "bottom",
2494
+ ALL: "all"
2495
+ };
2496
+ const props = __props;
2497
+ const dragItemRef = vue.ref();
2498
+ const isDownThis = vue.ref(false);
2499
+ const downPosition = vue.reactive({
2500
+ x: 0,
2501
+ y: 0
2502
+ });
2503
+ const isDragThis = vue.ref(false);
2504
+ const cloneNodePosition = vue.reactive({
2505
+ x: 0,
2506
+ y: 0
2507
+ });
2508
+ const immediateDirections = vue.computed(() => {
2509
+ if (Array.isArray(props.immediate)) {
2510
+ return props.immediate;
2511
+ }
2512
+ return props.immediate ? [props.immediate] : [];
2513
+ });
2514
+ const cloneNodeStyle = vue.computed(() => {
2515
+ return {
2516
+ transform: `translate(${cloneNodePosition.x}px, ${cloneNodePosition.y}px) translate(-50%, -50%)`
2517
+ };
2518
+ });
2519
+ DnDManagerInstance.on("down", (params) => {
2520
+ const { x, y } = params;
2521
+ const startEl = document.elementFromPoint(x, y);
2522
+ if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
2523
+ if (immediateDirections.value.includes(ImmediateEnumType.ALL)) {
2524
+ handleStart(params);
2525
+ return;
2526
+ }
2527
+ isDownThis.value = true;
2528
+ downPosition.x = x;
2529
+ downPosition.y = y;
2530
+ }
2531
+ });
2532
+ DnDManagerInstance.on("first-move", (params, event) => {
2533
+ const { x, y } = params;
2534
+ const directions = immediateDirections.value.filter((item) => item !== ImmediateEnumType.ALL);
2535
+ if (isDownThis.value && !props.disabled && directions.length) {
2536
+ const distanceH = x - downPosition.x;
2537
+ const distanceHAbs = Math.abs(distanceH);
2538
+ const distanceV = y - downPosition.y;
2539
+ const distanceVAbs = Math.abs(distanceV);
2540
+ const max = Math.max(distanceHAbs, distanceVAbs);
2541
+ const isMaxH = distanceHAbs === max;
2542
+ const isMaxV = distanceVAbs === max;
2543
+ let isImmediate = false;
2544
+ if (isMaxH) {
2545
+ isImmediate = directions.includes(ImmediateEnumType.LEFT) && distanceH < 0 || directions.includes(ImmediateEnumType.RIGHT) && distanceH > 0;
2546
+ }
2547
+ if (isMaxV && !isImmediate) {
2548
+ isImmediate = directions.includes(ImmediateEnumType.TOP) && distanceV < 0 || directions.includes(ImmediateEnumType.BOTTOM) && distanceV > 0;
2549
+ }
2550
+ if (isImmediate) {
2551
+ event.preventDefault();
2552
+ event.stopPropagation();
2553
+ handleStart(downPosition);
2554
+ handleMove(params);
2555
+ return;
2556
+ }
2557
+ }
2558
+ });
2559
+ DnDManagerInstance.on("start", (params) => {
2560
+ const { x, y } = params;
2561
+ const startEl = document.elementFromPoint(x, y);
2562
+ if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
2563
+ handleStart(params);
2564
+ }
2565
+ });
2566
+ DnDManagerInstance.on("move", (params) => {
2567
+ const { point } = params;
2568
+ if (isDragThis.value) {
2569
+ handleMove(point);
2570
+ }
2571
+ });
2572
+ DnDManagerInstance.on("end", () => {
2573
+ isDownThis.value = false;
2574
+ isDragThis.value = false;
2575
+ Object.assign(downPosition, {
2576
+ x: 0,
2577
+ y: 0
2578
+ });
2579
+ Object.assign(cloneNodePosition, {
2580
+ x: 0,
2581
+ y: 0
2582
+ });
2583
+ });
2584
+ function handleStart(point) {
2585
+ isDragThis.value = true;
2586
+ cloneNodePosition.x = point.x;
2587
+ cloneNodePosition.y = point.y;
2588
+ DnDManagerInstance.updateDargInfo(props.type, props.data);
2589
+ }
2590
+ function handleMove(point) {
2591
+ cloneNodePosition.x = point.x;
2592
+ cloneNodePosition.y = point.y;
2593
+ }
2594
+ return (_ctx, _cache) => {
2595
+ return vue.openBlock(), vue.createElementBlock("div", {
2596
+ ref_key: "dragItemRef",
2597
+ ref: dragItemRef,
2598
+ class: vue.normalizeClass(["draggable-area", _ctx.disabled ? "disabled" : ""])
2599
+ }, [
2600
+ vue.renderSlot(_ctx.$slots, "default", {}, void 0, true),
2601
+ isDragThis.value ? (vue.openBlock(), vue.createElementBlock("div", {
2602
+ key: 0,
2603
+ class: "draggable-clone-item",
2604
+ style: vue.normalizeStyle(cloneNodeStyle.value)
2605
+ }, [
2606
+ vue.renderSlot(_ctx.$slots, "drag-item", {}, () => [
2607
+ vue.renderSlot(_ctx.$slots, "default", {}, void 0, true)
2608
+ ], true)
2609
+ ], 4)) : vue.createCommentVNode("", true)
2610
+ ], 2);
2611
+ };
2612
+ }
2613
+ });
2614
+ const Draggable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-8361cd1f"]]);
2615
+ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
2616
+ ...{
2617
+ name: "HvDroppable"
2618
+ },
2619
+ __name: "Droppable",
2620
+ props: {
2621
+ acceptDragType: {}
2622
+ },
2623
+ emits: ["enter", "move", "drop", "leave"],
2624
+ setup(__props, { emit: __emit }) {
2625
+ const emits = __emit;
2626
+ const props = __props;
2627
+ const dropAreaRef = vue.ref();
2628
+ const isEntered = vue.ref(false);
2629
+ const acceptDragTypeList = vue.computed(() => {
2630
+ return Array.isArray(props.acceptDragType) ? props.acceptDragType : [props.acceptDragType];
2631
+ });
2632
+ function getPositionInArea(point) {
2633
+ if (!dropAreaRef.value) {
2634
+ return {
2635
+ isInArea: false,
2636
+ position: {
2637
+ x: 0,
2638
+ y: 0
2639
+ }
2640
+ };
2641
+ }
2642
+ const { x: pointX, y: pointY } = point;
2643
+ const { x, y, width, height } = dropAreaRef.value.getBoundingClientRect();
2644
+ const posX = pointX - x;
2645
+ const posY = pointY - y;
2646
+ return {
2647
+ isInArea: posX >= 0 && posX <= width && posY >= 0 && posY <= height,
2648
+ position: {
2649
+ x: posX,
2650
+ y: posY
2651
+ }
2652
+ };
2653
+ }
2654
+ DnDManagerInstance.on("move", (params) => {
2655
+ const { type, data, point } = params;
2656
+ if (dropAreaRef.value && acceptDragTypeList.value.includes(type)) {
2657
+ const { isInArea, position } = getPositionInArea(point);
2658
+ if (isInArea) {
2659
+ if (isEntered.value) {
2660
+ emits("move", type, position, data);
2661
+ } else {
2662
+ isEntered.value = true;
2663
+ emits("enter", type, position, data);
2664
+ }
2665
+ } else if (isEntered.value) {
2666
+ isEntered.value = false;
2667
+ emits("leave", type, data);
2668
+ }
2669
+ }
2670
+ });
2671
+ DnDManagerInstance.on("end", ({ type, point, data }) => {
2672
+ if (dropAreaRef.value && acceptDragTypeList.value.includes(type) && isEntered.value) {
2673
+ const { position } = getPositionInArea(point);
2674
+ emits("drop", type, position, data);
2675
+ }
2676
+ });
2677
+ return (_ctx, _cache) => {
2678
+ return vue.openBlock(), vue.createElementBlock("div", {
2679
+ ref_key: "dropAreaRef",
2680
+ ref: dropAreaRef,
2681
+ class: "droppable-area"
2682
+ }, [
2683
+ vue.renderSlot(_ctx.$slots, "default", {}, void 0, true)
2684
+ ], 512);
2685
+ };
2686
+ }
2687
+ });
2688
+ const Droppable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-a40b9a59"]]);
2689
+ const HvDraggable = withInstall(Draggable);
2690
+ const HvDroppable = withInstall(Droppable);
2691
+ function useDragAndScale(target, operateTarget, options) {
2692
+ const _options = vue.computed(() => {
2693
+ return vue.isRef(options) ? vue.toValue(options) : options;
2694
+ });
2695
+ const _containerRealSize = vue.computed(() => {
2696
+ return _options.value.containerRealSize;
2697
+ });
2698
+ const _keepRatio = vue.computed(() => {
2699
+ const krOption = typeof _options.value.keepRatio === "boolean" ? {
2700
+ enable: _options.value.keepRatio,
2701
+ scaleCase: "min"
2702
+ /* MIN */
2703
+ } : _options.value.keepRatio;
2704
+ return Object.assign(
2705
+ {
2706
+ scaleCase: "min",
2707
+ enable: false
2708
+ },
2709
+ krOption || {}
2710
+ );
2711
+ });
2712
+ const _limit = vue.computed(() => {
2713
+ const limitOpt = Object.assign(
2714
+ {
2715
+ inContainer: true,
2716
+ minWidth: 0,
2717
+ minHeight: 0,
2718
+ maxWidth: Infinity,
2719
+ maxHeight: Infinity
2720
+ },
2721
+ _options.value.limit || {}
2722
+ );
2723
+ if (limitOpt.minWidth > limitOpt.maxWidth) {
2724
+ limitOpt.maxWidth = limitOpt.minWidth;
2725
+ }
2726
+ if (limitOpt.minHeight > limitOpt.maxHeight) {
2727
+ limitOpt.maxHeight = limitOpt.minHeight;
2728
+ }
2729
+ return limitOpt;
2730
+ });
2731
+ const _disabled = vue.computed(() => {
2732
+ return _options.value.disabled || false;
2733
+ });
2734
+ const _targetEl = vue.computed(() => {
2735
+ return vue.isRef(target) ? vue.toValue(target) : target;
2736
+ });
2737
+ const _containerEl = vue.computed(() => {
2738
+ return _options.value.container;
2739
+ });
2740
+ const _operateEl = vue.computed(() => {
2741
+ return vue.isRef(operateTarget) ? vue.toValue(operateTarget) : operateTarget;
2742
+ });
2743
+ let startPoint = {
2744
+ x: 0,
2745
+ y: 0
2746
+ };
2747
+ let lastOperatePoint = {
2748
+ x: 0,
2749
+ y: 0
2750
+ };
2751
+ let curOperatePoint = {
2752
+ x: 0,
2753
+ y: 0
2754
+ };
2755
+ const containerElSize = {
2756
+ width: 0,
2757
+ height: 0
2758
+ };
2759
+ const startArea = {
2760
+ elX: 0,
2761
+ elY: 0,
2762
+ elWidth: 0,
2763
+ elHeight: 0
2764
+ };
2765
+ const effectDirection = {
2766
+ leftSide: false,
2767
+ rightSide: false,
2768
+ topSide: false,
2769
+ bottomSide: false,
2770
+ center: false
2771
+ };
2772
+ let isOperateStart = false;
2773
+ let isMoved = false;
2774
+ let realRateEl_w = 1;
2775
+ let realRateEl_h = 1;
2776
+ vue.watch(
2777
+ () => _targetEl.value && _containerEl.value && _operateEl.value,
2778
+ (value) => {
2779
+ if (value) {
2780
+ bindEvent();
2781
+ } else {
2782
+ removeEvent();
2783
+ }
2784
+ }
2785
+ );
2786
+ function onStart(point) {
2787
+ if (_disabled.value) {
2788
+ return;
2789
+ }
2790
+ startPoint = point;
2791
+ curOperatePoint = point;
2792
+ if (!_containerEl.value || !_targetEl.value) {
2793
+ return;
2794
+ }
2795
+ const {
2796
+ x: containerX,
2797
+ y: containerY,
2798
+ width: containerWidth,
2799
+ height: containerHeight
2800
+ } = _containerEl.value.getBoundingClientRect();
2801
+ Object.assign(containerElSize, {
2802
+ width: containerWidth,
2803
+ height: containerHeight
2804
+ });
2805
+ if (_containerRealSize.value) {
2806
+ const { width: realWdith, height: realHeight } = _containerRealSize.value;
2807
+ realRateEl_w = realWdith / containerWidth;
2808
+ realRateEl_h = realHeight / containerHeight;
2809
+ } else {
2810
+ realRateEl_w = 1;
2811
+ realRateEl_h = 1;
2812
+ }
2813
+ const { x: targetX, y: targetY, width: targetW, height: targetH } = _targetEl.value.getBoundingClientRect();
2814
+ const { x: startX, y: startY } = point;
2815
+ Object.assign(startArea, {
2816
+ elX: targetX - containerX,
2817
+ elY: targetY - containerY,
2818
+ elWidth: targetW,
2819
+ elHeight: targetH
2820
+ });
2821
+ const touchEl = document.elementFromPoint(startX, startY);
2822
+ if (!touchEl) {
2823
+ return;
2824
+ }
2825
+ const sides = (touchEl.dataset["scaleSide"] || "").split(",").filter((item) => !!item);
2826
+ if (!sides.length) {
2827
+ return;
2828
+ }
2829
+ let leftSide = sides.includes("left");
2830
+ let topSide = sides.includes("top");
2831
+ let rightSide = sides.includes("right");
2832
+ let bottomSide = sides.includes("bottom");
2833
+ const center = sides.includes("center");
2834
+ isOperateStart = true;
2835
+ if (_keepRatio.value.enable && !center) {
2836
+ if (startX - targetX <= targetW / 2 && startY - targetY <= targetH / 2) {
2837
+ leftSide = true;
2838
+ topSide = true;
2839
+ }
2840
+ if (startX - targetX > targetW / 2 && startY - targetY <= targetH / 2) {
2841
+ rightSide = true;
2842
+ topSide = true;
2843
+ }
2844
+ if (startX - targetX <= targetW / 2 && startY - targetY > targetH / 2) {
2845
+ leftSide = true;
2846
+ bottomSide = true;
2847
+ }
2848
+ if (startX - targetX > targetW / 2 && startY - targetY > targetH / 2) {
2849
+ rightSide = true;
2850
+ bottomSide = true;
2851
+ }
2852
+ }
2853
+ Object.assign(effectDirection, {
2854
+ leftSide,
2855
+ rightSide,
2856
+ topSide,
2857
+ bottomSide,
2858
+ center
2859
+ });
2860
+ }
2861
+ function onMove(point) {
2862
+ if (_disabled.value || isOperateStart !== true) {
2863
+ isOperateStart = false;
2864
+ return;
2865
+ }
2866
+ isMoved = true;
2867
+ lastOperatePoint = curOperatePoint;
2868
+ curOperatePoint = point;
2869
+ const deltaX = point.x - startPoint.x;
2870
+ const deltaY = point.y - startPoint.y;
2871
+ let dX = 0;
2872
+ let dY = 0;
2873
+ let dW = 0;
2874
+ let dH = 0;
2875
+ const { elX, elY, elWidth, elHeight } = startArea;
2876
+ const { minWidth, minHeight, maxWidth, maxHeight } = _limit.value;
2877
+ const minElWidth = minWidth / realRateEl_w;
2878
+ const minElHeight = minHeight / realRateEl_h;
2879
+ const maxElWidth = maxWidth / realRateEl_w;
2880
+ const maxElHeight = maxHeight / realRateEl_h;
2881
+ if (effectDirection.center) {
2882
+ const containerWidth = containerElSize.width;
2883
+ const containerHeight = containerElSize.height;
2884
+ if (_limit.value.inContainer) {
2885
+ const distanceX = elX + deltaX < 0 ? -elX : elX + elWidth + deltaX > containerWidth ? containerWidth - elWidth - elX : deltaX;
2886
+ const distanceY = elY + deltaY < 0 ? -elY : elY + elHeight + deltaY > containerHeight ? containerHeight - elHeight - elY : deltaY;
2887
+ dX = distanceX;
2888
+ dY = distanceY;
2889
+ } else {
2890
+ dX = deltaX;
2891
+ dY = deltaY;
2892
+ }
2893
+ } else {
2894
+ const { leftSide, rightSide, topSide, bottomSide } = effectDirection;
2895
+ if (leftSide) {
2896
+ let distance = _limit.value.inContainer && elX + deltaX < 0 ? -elX : deltaX;
2897
+ if (elWidth - distance < minElWidth) {
2898
+ distance = elWidth - minElWidth;
2899
+ }
2900
+ if (elWidth - distance > maxElWidth) {
2901
+ distance = elWidth - maxElWidth;
2902
+ }
2903
+ dX = distance;
2904
+ dW = -distance;
2905
+ }
2906
+ if (rightSide) {
2907
+ const containerWidth = containerElSize.width;
2908
+ let distance = _limit.value.inContainer && elX + elWidth + deltaX > containerWidth ? containerWidth - elWidth - elX : deltaX;
2909
+ if (elWidth + distance < minElWidth) {
2910
+ distance = minElWidth - elWidth;
2911
+ }
2912
+ if (elWidth + distance > maxElWidth) {
2913
+ distance = maxElWidth - elWidth;
2914
+ }
2915
+ dW = distance;
2916
+ }
2917
+ if (topSide) {
2918
+ let distance = _limit.value.inContainer && elY + deltaY < 0 ? -elY : deltaY;
2919
+ if (elHeight - distance < minElHeight) {
2920
+ distance = elHeight - minElHeight;
2921
+ }
2922
+ if (elHeight - distance > maxElHeight) {
2923
+ distance = elHeight - maxElHeight;
2924
+ }
2925
+ dY = distance;
2926
+ dH = -distance;
2927
+ }
2928
+ if (bottomSide) {
2929
+ const containerHeight = containerElSize.height;
2930
+ let distance = _limit.value.inContainer && elY + elHeight + deltaY > containerHeight ? containerHeight - elHeight - elY : deltaY;
2931
+ if (elHeight + distance < minElHeight) {
2932
+ distance = minElHeight - elHeight;
2933
+ }
2934
+ if (elHeight + distance > maxElHeight) {
2935
+ distance = maxElHeight - elHeight;
2936
+ }
2937
+ dH = distance;
2938
+ }
2939
+ if (_keepRatio.value.enable) {
2940
+ const dwR = dW / elWidth;
2941
+ const dhR = dH / elHeight;
2942
+ if (dwR < dhR && _keepRatio.value.scaleCase === "min" || dwR > dhR && _keepRatio.value.scaleCase === "max") {
2943
+ dH = dwR * elHeight;
2944
+ if (elHeight + dH < minElHeight) {
2945
+ const originDw = dW;
2946
+ dH = minElHeight - elHeight;
2947
+ dW = dH / elHeight * elWidth;
2948
+ dX = dX * (dW / originDw);
2949
+ }
2950
+ if (elHeight + dH > maxElHeight) {
2951
+ const originDw = dW;
2952
+ dH = maxElHeight - elHeight;
2953
+ dW = dH / elHeight * elWidth;
2954
+ dX = dX * (dW / originDw);
2955
+ }
2956
+ if (effectDirection.topSide) {
2957
+ dY = -dH;
2958
+ }
2959
+ } else if (dhR < dwR && _keepRatio.value.scaleCase === "min" || dhR > dwR && _keepRatio.value.scaleCase === "max") {
2960
+ dW = dhR * elWidth;
2961
+ if (elWidth + dW < minElWidth) {
2962
+ const originDh = dH;
2963
+ dW = minElWidth - elWidth;
2964
+ dH = dW / elWidth * elHeight;
2965
+ dY = dY * (dH / originDh);
2966
+ }
2967
+ if (elWidth + dW > maxElWidth) {
2968
+ const originDh = dH;
2969
+ dW = maxElWidth - elWidth;
2970
+ dH = dW / elWidth * elHeight;
2971
+ dY = dY * (dH / originDh);
2972
+ }
2973
+ if (effectDirection.leftSide) {
2974
+ dX = -dW;
2975
+ }
2976
+ }
2977
+ const currentElX2 = elX + dX;
2978
+ const currentElY2 = elY + dY;
2979
+ const currentElW2 = elWidth + dW;
2980
+ const currentElH2 = elHeight + dH;
2981
+ if (_limit.value.inContainer && (currentElX2 < 0 || currentElY2 < 0 || currentElX2 + currentElW2 > containerElSize.width || currentElY2 + currentElH2 > containerElSize.height)) {
2982
+ let clipX = currentElX2 < 0 ? 0 : currentElX2;
2983
+ let clipY = currentElY2 < 0 ? 0 : currentElY2;
2984
+ let clipW = currentElX2 + currentElW2 > containerElSize.width ? containerElSize.width - clipX : currentElX2 + currentElW2 - clipX;
2985
+ let clipH = currentElY2 + currentElH2 > containerElSize.height ? containerElSize.height - clipY : currentElY2 + currentElH2 - clipY;
2986
+ const clipX2 = clipX + clipW;
2987
+ const clipY2 = clipY + clipH;
2988
+ const clipRate = clipW / clipH;
2989
+ const elRate = elWidth / elHeight;
2990
+ if (clipRate < elRate) {
2991
+ clipH = clipW / elRate;
2992
+ } else if (clipRate > elRate) {
2993
+ clipW = clipH * elRate;
2994
+ }
2995
+ const { topSide: topSide2, leftSide: leftSide2 } = effectDirection;
2996
+ if (leftSide2) {
2997
+ clipX = clipX2 - clipW;
2998
+ }
2999
+ if (topSide2) {
3000
+ clipY = clipY2 - clipH;
3001
+ }
3002
+ dX = clipX - elX;
3003
+ dY = clipY - elY;
3004
+ dW = clipW - elWidth;
3005
+ dH = clipH - elHeight;
3006
+ }
3007
+ }
3008
+ }
3009
+ const currentElX = elX + dX;
3010
+ const currentElY = elY + dY;
3011
+ const currentElW = elWidth + dW;
3012
+ const currentElH = elHeight + dH;
3013
+ _options.value.onChange && _options.value.onChange({
3014
+ type: effectDirection.center ? "move" : "scale",
3015
+ deltaX: curOperatePoint.x - lastOperatePoint.x,
3016
+ deltaY: curOperatePoint.y - lastOperatePoint.y,
3017
+ elX: currentElX,
3018
+ elY: currentElY,
3019
+ elWidth: currentElW,
3020
+ elHeight: currentElH,
3021
+ realX: currentElX * realRateEl_w,
3022
+ realY: currentElY * realRateEl_h,
3023
+ realWidth: currentElW * realRateEl_w,
3024
+ realHeight: currentElH * realRateEl_h
3025
+ });
3026
+ }
3027
+ function onEnd() {
3028
+ lastOperatePoint = {
3029
+ x: 0,
3030
+ y: 0
3031
+ };
3032
+ curOperatePoint = {
3033
+ x: 0,
3034
+ y: 0
3035
+ };
3036
+ if (_disabled.value || isOperateStart !== true || !isMoved) {
3037
+ isOperateStart = false;
3038
+ isMoved = false;
3039
+ return;
3040
+ }
3041
+ isOperateStart = false;
3042
+ isMoved = false;
3043
+ _options.value.onFinish && _options.value.onFinish();
3044
+ }
3045
+ function onTouchStart(e) {
3046
+ e.preventDefault();
3047
+ if (e.touches.length > 1) {
3048
+ return;
3049
+ }
3050
+ const { clientX, clientY } = e.touches[0];
3051
+ onStart({
3052
+ x: clientX,
3053
+ y: clientY
3054
+ });
3055
+ document.body.addEventListener("touchcancel", onTouchEnd, { capture: true });
3056
+ document.body.addEventListener("touchmove", onTouchMove, { capture: true });
3057
+ document.body.addEventListener("touchend", onTouchEnd, { capture: true });
3058
+ }
3059
+ function onTouchMove(e) {
3060
+ if (_disabled.value || isOperateStart !== true) {
3061
+ isOperateStart = false;
3062
+ return;
3063
+ }
3064
+ e.preventDefault();
3065
+ e.stopPropagation();
3066
+ if (e.touches.length > 1) {
3067
+ onEnd();
3068
+ return;
3069
+ }
3070
+ const { clientX, clientY } = e.touches[0];
3071
+ if (clientX === startPoint.x && clientY === startPoint.y) {
3072
+ return;
3073
+ }
3074
+ onMove({
3075
+ x: clientX,
3076
+ y: clientY
3077
+ });
3078
+ }
3079
+ function onTouchEnd() {
3080
+ document.body.removeEventListener("touchmove", onTouchMove);
3081
+ document.body.removeEventListener("touchend", onTouchEnd);
3082
+ document.body.removeEventListener("touchcancel", onTouchEnd);
3083
+ if (_disabled.value || isOperateStart !== true) {
3084
+ isOperateStart = false;
3085
+ isMoved = false;
3086
+ return;
3087
+ }
3088
+ onEnd();
3089
+ }
3090
+ function onMouseDown(e) {
3091
+ e.preventDefault();
3092
+ if ((e.buttons & 1) === 0) {
3093
+ return;
3094
+ }
3095
+ const { clientX, clientY } = e;
3096
+ onStart({
3097
+ x: clientX,
3098
+ y: clientY
3099
+ });
3100
+ document.body.addEventListener("mousemove", onMouseMove, { capture: true });
3101
+ document.body.addEventListener("mouseup", onMouseUp, { capture: true });
3102
+ }
3103
+ function onMouseMove(e) {
3104
+ if (_disabled.value || isOperateStart !== true) {
3105
+ isOperateStart = false;
3106
+ return;
3107
+ }
3108
+ e.preventDefault();
3109
+ if ((e.buttons & 1) === 0) {
3110
+ onEnd();
3111
+ return;
3112
+ }
3113
+ const { clientX, clientY } = e;
3114
+ onMove({
3115
+ x: clientX,
3116
+ y: clientY
3117
+ });
3118
+ }
3119
+ function onMouseUp() {
3120
+ document.body.removeEventListener("mousemove", onMouseMove);
3121
+ document.body.removeEventListener("mouseup", onMouseUp);
3122
+ if (_disabled.value || isOperateStart !== true) {
3123
+ isOperateStart = false;
3124
+ return;
3125
+ }
3126
+ onEnd();
3127
+ }
3128
+ function bindEvent() {
3129
+ removeEvent();
3130
+ if (isMobile) {
3131
+ _operateEl.value.addEventListener("touchstart", onTouchStart, { capture: true });
3132
+ } else {
3133
+ _operateEl.value.addEventListener("mousedown", onMouseDown);
3134
+ }
3135
+ }
3136
+ function removeEvent() {
3137
+ if (isMobile) {
3138
+ _operateEl.value.removeEventListener("touchstart", onTouchStart);
3139
+ document.body.removeEventListener("touchmove", onTouchMove);
3140
+ document.body.removeEventListener("touchend", onTouchEnd);
3141
+ document.body.removeEventListener("touchcancel", onTouchEnd);
3142
+ } else {
3143
+ _operateEl.value.removeEventListener("mousedown", onMouseDown);
3144
+ document.body.removeEventListener("mousemove", onMouseMove);
3145
+ document.body.removeEventListener("mouseup", onMouseUp);
3146
+ }
3147
+ }
3148
+ vue.onBeforeUnmount(() => {
3149
+ isOperateStart = false;
3150
+ removeEvent();
3151
+ });
3152
+ }
3153
+ const _hoisted_1 = { class: "zoom-mark-box" };
3154
+ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
3155
+ ...{
3156
+ name: "HvDragAndScale"
3157
+ },
3158
+ __name: "DragAndScale",
3159
+ props: {
3160
+ container: {},
3161
+ containerRealSize: {},
3162
+ keepRatio: { type: [Boolean, Object] },
3163
+ limit: {},
3164
+ disabled: { type: Boolean }
3165
+ },
3166
+ emits: ["change", "finish"],
3167
+ setup(__props, { emit: __emit }) {
3168
+ const emits = __emit;
3169
+ const props = __props;
3170
+ const targetRef = vue.ref();
3171
+ const operateRef = vue.ref();
3172
+ function onChange(params) {
3173
+ emits("change", params);
3174
+ }
3175
+ function onFinish() {
3176
+ emits("finish");
3177
+ }
3178
+ const useDragAndScaleOptions = vue.computed(() => {
3179
+ return {
3180
+ container: props.container,
3181
+ containerRealSize: props.containerRealSize,
3182
+ keepRatio: props.keepRatio,
3183
+ limit: props.limit,
3184
+ disabled: props.disabled,
3185
+ onChange,
3186
+ onFinish
3187
+ };
3188
+ });
3189
+ useDragAndScale(targetRef, operateRef, useDragAndScaleOptions);
3190
+ return (_ctx, _cache) => {
3191
+ return vue.openBlock(), vue.createElementBlock("div", {
3192
+ class: "drag-and-scale-box",
3193
+ ref_key: "targetRef",
3194
+ ref: targetRef
3195
+ }, [
3196
+ vue.renderSlot(_ctx.$slots, "default", {}, void 0, true),
3197
+ vue.createElementVNode("div", _hoisted_1, [
3198
+ vue.createElementVNode("div", {
3199
+ class: vue.normalizeClass(["zoom-operate-box", props.disabled ? "disabled" : ""]),
3200
+ ref_key: "operateRef",
3201
+ ref: operateRef
3202
+ }, _cache[0] || (_cache[0] = [
3203
+ vue.createStaticVNode('<div class="top-box block" data-v-91217104><div class="left-box" data-scale-side="left,top" data-v-91217104></div><div class="center-box" data-scale-side="top" data-v-91217104></div><div class="right-box" data-scale-side="right,top" data-v-91217104></div></div><div class="middle-box block" data-v-91217104><div class="left-box" data-scale-side="left" data-v-91217104></div><div class="center-box" data-scale-side="center" data-v-91217104></div><div class="right-box" data-scale-side="right" data-v-91217104></div></div><div class="bottom-box block" data-v-91217104><div class="left-box" data-scale-side="left,bottom" data-v-91217104></div><div class="center-box" data-scale-side="bottom" data-v-91217104></div><div class="right-box" data-scale-side="right,bottom" data-v-91217104></div></div>', 3)
3204
+ ]), 2)
3205
+ ])
3206
+ ], 512);
3207
+ };
3208
+ }
3209
+ });
3210
+ const DragAndScale = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-91217104"]]);
3211
+ const HvDragAndScale = withInstall(DragAndScale);
3212
+ exports2.HvColorPicker = HvColorPicker;
3213
+ exports2.HvDragAndScale = HvDragAndScale;
3214
+ exports2.HvDraggable = HvDraggable;
3215
+ exports2.HvDroppable = HvDroppable;
3216
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
3217
+ });