@sanity/color-input 3.1.2 → 4.0.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.mjs ADDED
@@ -0,0 +1,1150 @@
1
+ import { set, setIfMissing, unset, defineType, definePlugin } from "sanity";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import { TrashIcon, AddIcon } from "@sanity/icons";
4
+ import { Flex, useTheme, Box, Card, Stack, Text, Inline, Button } from "@sanity/ui";
5
+ import debounce from "lodash/debounce.js";
6
+ import { memo, useMemo, useCallback, useRef, useState, useEffect } from "react";
7
+ import { CustomPicker } from "react-color";
8
+ import { EditableInput, Saturation, Hue, Alpha, Checkboard } from "react-color/lib/components/common";
9
+ import { styled } from "styled-components";
10
+ import { isValidHex } from "react-color/lib/helpers/color";
11
+ function _typeof(obj) {
12
+ "@babel/helpers - typeof";
13
+ return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) {
14
+ return typeof obj2;
15
+ } : function(obj2) {
16
+ return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
17
+ }, _typeof(obj);
18
+ }
19
+ var trimLeft = /^\s+/, trimRight = /\s+$/;
20
+ function tinycolor(color2, opts) {
21
+ if (color2 = color2 || "", opts = opts || {}, color2 instanceof tinycolor)
22
+ return color2;
23
+ if (!(this instanceof tinycolor))
24
+ return new tinycolor(color2, opts);
25
+ var rgb = inputToRGB(color2);
26
+ this._originalInput = color2, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format, this._gradientType = opts.gradientType, this._r < 1 && (this._r = Math.round(this._r)), this._g < 1 && (this._g = Math.round(this._g)), this._b < 1 && (this._b = Math.round(this._b)), this._ok = rgb.ok;
27
+ }
28
+ tinycolor.prototype = {
29
+ isDark: function() {
30
+ return this.getBrightness() < 128;
31
+ },
32
+ isLight: function() {
33
+ return !this.isDark();
34
+ },
35
+ isValid: function() {
36
+ return this._ok;
37
+ },
38
+ getOriginalInput: function() {
39
+ return this._originalInput;
40
+ },
41
+ getFormat: function() {
42
+ return this._format;
43
+ },
44
+ getAlpha: function() {
45
+ return this._a;
46
+ },
47
+ getBrightness: function() {
48
+ var rgb = this.toRgb();
49
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
50
+ },
51
+ getLuminance: function() {
52
+ var rgb = this.toRgb(), RsRGB, GsRGB, BsRGB, R, G, B;
53
+ return RsRGB = rgb.r / 255, GsRGB = rgb.g / 255, BsRGB = rgb.b / 255, RsRGB <= 0.03928 ? R = RsRGB / 12.92 : R = Math.pow((RsRGB + 0.055) / 1.055, 2.4), GsRGB <= 0.03928 ? G = GsRGB / 12.92 : G = Math.pow((GsRGB + 0.055) / 1.055, 2.4), BsRGB <= 0.03928 ? B = BsRGB / 12.92 : B = Math.pow((BsRGB + 0.055) / 1.055, 2.4), 0.2126 * R + 0.7152 * G + 0.0722 * B;
54
+ },
55
+ setAlpha: function(value) {
56
+ return this._a = boundAlpha(value), this._roundA = Math.round(100 * this._a) / 100, this;
57
+ },
58
+ toHsv: function() {
59
+ var hsv = rgbToHsv(this._r, this._g, this._b);
60
+ return {
61
+ h: hsv.h * 360,
62
+ s: hsv.s,
63
+ v: hsv.v,
64
+ a: this._a
65
+ };
66
+ },
67
+ toHsvString: function() {
68
+ var hsv = rgbToHsv(this._r, this._g, this._b), h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
69
+ return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
70
+ },
71
+ toHsl: function() {
72
+ var hsl = rgbToHsl(this._r, this._g, this._b);
73
+ return {
74
+ h: hsl.h * 360,
75
+ s: hsl.s,
76
+ l: hsl.l,
77
+ a: this._a
78
+ };
79
+ },
80
+ toHslString: function() {
81
+ var hsl = rgbToHsl(this._r, this._g, this._b), h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
82
+ return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
83
+ },
84
+ toHex: function(allow3Char) {
85
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
86
+ },
87
+ toHexString: function(allow3Char) {
88
+ return "#" + this.toHex(allow3Char);
89
+ },
90
+ toHex8: function(allow4Char) {
91
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
92
+ },
93
+ toHex8String: function(allow4Char) {
94
+ return "#" + this.toHex8(allow4Char);
95
+ },
96
+ toRgb: function() {
97
+ return {
98
+ r: Math.round(this._r),
99
+ g: Math.round(this._g),
100
+ b: Math.round(this._b),
101
+ a: this._a
102
+ };
103
+ },
104
+ toRgbString: function() {
105
+ return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
106
+ },
107
+ toPercentageRgb: function() {
108
+ return {
109
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
110
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
111
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
112
+ a: this._a
113
+ };
114
+ },
115
+ toPercentageRgbString: function() {
116
+ return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
117
+ },
118
+ toName: function() {
119
+ return this._a === 0 ? "transparent" : this._a < 1 ? !1 : hexNames[rgbToHex(this._r, this._g, this._b, !0)] || !1;
120
+ },
121
+ toFilter: function(secondColor) {
122
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a), secondHex8String = hex8String, gradientType = this._gradientType ? "GradientType = 1, " : "";
123
+ if (secondColor) {
124
+ var s = tinycolor(secondColor);
125
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
126
+ }
127
+ return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
128
+ },
129
+ toString: function(format) {
130
+ var formatSet = !!format;
131
+ format = format || this._format;
132
+ var formattedString = !1, hasAlpha = this._a < 1 && this._a >= 0, needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
133
+ return needsAlphaFormat ? format === "name" && this._a === 0 ? this.toName() : this.toRgbString() : (format === "rgb" && (formattedString = this.toRgbString()), format === "prgb" && (formattedString = this.toPercentageRgbString()), (format === "hex" || format === "hex6") && (formattedString = this.toHexString()), format === "hex3" && (formattedString = this.toHexString(!0)), format === "hex4" && (formattedString = this.toHex8String(!0)), format === "hex8" && (formattedString = this.toHex8String()), format === "name" && (formattedString = this.toName()), format === "hsl" && (formattedString = this.toHslString()), format === "hsv" && (formattedString = this.toHsvString()), formattedString || this.toHexString());
134
+ },
135
+ clone: function() {
136
+ return tinycolor(this.toString());
137
+ },
138
+ _applyModification: function(fn, args) {
139
+ var color2 = fn.apply(null, [this].concat([].slice.call(args)));
140
+ return this._r = color2._r, this._g = color2._g, this._b = color2._b, this.setAlpha(color2._a), this;
141
+ },
142
+ lighten: function() {
143
+ return this._applyModification(_lighten, arguments);
144
+ },
145
+ brighten: function() {
146
+ return this._applyModification(_brighten, arguments);
147
+ },
148
+ darken: function() {
149
+ return this._applyModification(_darken, arguments);
150
+ },
151
+ desaturate: function() {
152
+ return this._applyModification(_desaturate, arguments);
153
+ },
154
+ saturate: function() {
155
+ return this._applyModification(_saturate, arguments);
156
+ },
157
+ greyscale: function() {
158
+ return this._applyModification(_greyscale, arguments);
159
+ },
160
+ spin: function() {
161
+ return this._applyModification(_spin, arguments);
162
+ },
163
+ _applyCombination: function(fn, args) {
164
+ return fn.apply(null, [this].concat([].slice.call(args)));
165
+ },
166
+ analogous: function() {
167
+ return this._applyCombination(_analogous, arguments);
168
+ },
169
+ complement: function() {
170
+ return this._applyCombination(_complement, arguments);
171
+ },
172
+ monochromatic: function() {
173
+ return this._applyCombination(_monochromatic, arguments);
174
+ },
175
+ splitcomplement: function() {
176
+ return this._applyCombination(_splitcomplement, arguments);
177
+ },
178
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
179
+ // polyad: function (number) {
180
+ // return this._applyCombination(polyad, [number]);
181
+ // },
182
+ triad: function() {
183
+ return this._applyCombination(polyad, [3]);
184
+ },
185
+ tetrad: function() {
186
+ return this._applyCombination(polyad, [4]);
187
+ }
188
+ };
189
+ tinycolor.fromRatio = function(color2, opts) {
190
+ if (_typeof(color2) == "object") {
191
+ var newColor = {};
192
+ for (var i in color2)
193
+ color2.hasOwnProperty(i) && (i === "a" ? newColor[i] = color2[i] : newColor[i] = convertToPercentage(color2[i]));
194
+ color2 = newColor;
195
+ }
196
+ return tinycolor(color2, opts);
197
+ };
198
+ function inputToRGB(color2) {
199
+ var rgb = {
200
+ r: 0,
201
+ g: 0,
202
+ b: 0
203
+ }, a = 1, s = null, v = null, l = null, ok = !1, format = !1;
204
+ return typeof color2 == "string" && (color2 = stringInputToObject(color2)), _typeof(color2) == "object" && (isValidCSSUnit(color2.r) && isValidCSSUnit(color2.g) && isValidCSSUnit(color2.b) ? (rgb = rgbToRgb(color2.r, color2.g, color2.b), ok = !0, format = String(color2.r).substr(-1) === "%" ? "prgb" : "rgb") : isValidCSSUnit(color2.h) && isValidCSSUnit(color2.s) && isValidCSSUnit(color2.v) ? (s = convertToPercentage(color2.s), v = convertToPercentage(color2.v), rgb = hsvToRgb(color2.h, s, v), ok = !0, format = "hsv") : isValidCSSUnit(color2.h) && isValidCSSUnit(color2.s) && isValidCSSUnit(color2.l) && (s = convertToPercentage(color2.s), l = convertToPercentage(color2.l), rgb = hslToRgb(color2.h, s, l), ok = !0, format = "hsl"), color2.hasOwnProperty("a") && (a = color2.a)), a = boundAlpha(a), {
205
+ ok,
206
+ format: color2.format || format,
207
+ r: Math.min(255, Math.max(rgb.r, 0)),
208
+ g: Math.min(255, Math.max(rgb.g, 0)),
209
+ b: Math.min(255, Math.max(rgb.b, 0)),
210
+ a
211
+ };
212
+ }
213
+ function rgbToRgb(r, g, b) {
214
+ return {
215
+ r: bound01(r, 255) * 255,
216
+ g: bound01(g, 255) * 255,
217
+ b: bound01(b, 255) * 255
218
+ };
219
+ }
220
+ function rgbToHsl(r, g, b) {
221
+ r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
222
+ var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, l = (max + min) / 2;
223
+ if (max == min)
224
+ h = s = 0;
225
+ else {
226
+ var d = max - min;
227
+ switch (s = l > 0.5 ? d / (2 - max - min) : d / (max + min), max) {
228
+ case r:
229
+ h = (g - b) / d + (g < b ? 6 : 0);
230
+ break;
231
+ case g:
232
+ h = (b - r) / d + 2;
233
+ break;
234
+ case b:
235
+ h = (r - g) / d + 4;
236
+ break;
237
+ }
238
+ h /= 6;
239
+ }
240
+ return {
241
+ h,
242
+ s,
243
+ l
244
+ };
245
+ }
246
+ function hslToRgb(h, s, l) {
247
+ var r, g, b;
248
+ h = bound01(h, 360), s = bound01(s, 100), l = bound01(l, 100);
249
+ function hue2rgb(p2, q2, t) {
250
+ return t < 0 && (t += 1), t > 1 && (t -= 1), t < 1 / 6 ? p2 + (q2 - p2) * 6 * t : t < 1 / 2 ? q2 : t < 2 / 3 ? p2 + (q2 - p2) * (2 / 3 - t) * 6 : p2;
251
+ }
252
+ if (s === 0)
253
+ r = g = b = l;
254
+ else {
255
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q;
256
+ r = hue2rgb(p, q, h + 1 / 3), g = hue2rgb(p, q, h), b = hue2rgb(p, q, h - 1 / 3);
257
+ }
258
+ return {
259
+ r: r * 255,
260
+ g: g * 255,
261
+ b: b * 255
262
+ };
263
+ }
264
+ function rgbToHsv(r, g, b) {
265
+ r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
266
+ var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, v = max, d = max - min;
267
+ if (s = max === 0 ? 0 : d / max, max == min)
268
+ h = 0;
269
+ else {
270
+ switch (max) {
271
+ case r:
272
+ h = (g - b) / d + (g < b ? 6 : 0);
273
+ break;
274
+ case g:
275
+ h = (b - r) / d + 2;
276
+ break;
277
+ case b:
278
+ h = (r - g) / d + 4;
279
+ break;
280
+ }
281
+ h /= 6;
282
+ }
283
+ return {
284
+ h,
285
+ s,
286
+ v
287
+ };
288
+ }
289
+ function hsvToRgb(h, s, v) {
290
+ h = bound01(h, 360) * 6, s = bound01(s, 100), v = bound01(v, 100);
291
+ var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
292
+ return {
293
+ r: r * 255,
294
+ g: g * 255,
295
+ b: b * 255
296
+ };
297
+ }
298
+ function rgbToHex(r, g, b, allow3Char) {
299
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
300
+ return allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) ? hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) : hex.join("");
301
+ }
302
+ function rgbaToHex(r, g, b, a, allow4Char) {
303
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
304
+ return allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1) ? hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0) : hex.join("");
305
+ }
306
+ function rgbaToArgbHex(r, g, b, a) {
307
+ var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
308
+ return hex.join("");
309
+ }
310
+ tinycolor.equals = function(color1, color2) {
311
+ return !color1 || !color2 ? !1 : tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
312
+ };
313
+ tinycolor.random = function() {
314
+ return tinycolor.fromRatio({
315
+ r: Math.random(),
316
+ g: Math.random(),
317
+ b: Math.random()
318
+ });
319
+ };
320
+ function _desaturate(color2, amount) {
321
+ amount = amount === 0 ? 0 : amount || 10;
322
+ var hsl = tinycolor(color2).toHsl();
323
+ return hsl.s -= amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
324
+ }
325
+ function _saturate(color2, amount) {
326
+ amount = amount === 0 ? 0 : amount || 10;
327
+ var hsl = tinycolor(color2).toHsl();
328
+ return hsl.s += amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
329
+ }
330
+ function _greyscale(color2) {
331
+ return tinycolor(color2).desaturate(100);
332
+ }
333
+ function _lighten(color2, amount) {
334
+ amount = amount === 0 ? 0 : amount || 10;
335
+ var hsl = tinycolor(color2).toHsl();
336
+ return hsl.l += amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
337
+ }
338
+ function _brighten(color2, amount) {
339
+ amount = amount === 0 ? 0 : amount || 10;
340
+ var rgb = tinycolor(color2).toRgb();
341
+ return rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100)))), rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100)))), rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100)))), tinycolor(rgb);
342
+ }
343
+ function _darken(color2, amount) {
344
+ amount = amount === 0 ? 0 : amount || 10;
345
+ var hsl = tinycolor(color2).toHsl();
346
+ return hsl.l -= amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
347
+ }
348
+ function _spin(color2, amount) {
349
+ var hsl = tinycolor(color2).toHsl(), hue = (hsl.h + amount) % 360;
350
+ return hsl.h = hue < 0 ? 360 + hue : hue, tinycolor(hsl);
351
+ }
352
+ function _complement(color2) {
353
+ var hsl = tinycolor(color2).toHsl();
354
+ return hsl.h = (hsl.h + 180) % 360, tinycolor(hsl);
355
+ }
356
+ function polyad(color2, number) {
357
+ if (isNaN(number) || number <= 0)
358
+ throw new Error("Argument to polyad must be a positive number");
359
+ for (var hsl = tinycolor(color2).toHsl(), result = [tinycolor(color2)], step = 360 / number, i = 1; i < number; i++)
360
+ result.push(tinycolor({
361
+ h: (hsl.h + i * step) % 360,
362
+ s: hsl.s,
363
+ l: hsl.l
364
+ }));
365
+ return result;
366
+ }
367
+ function _splitcomplement(color2) {
368
+ var hsl = tinycolor(color2).toHsl(), h = hsl.h;
369
+ return [tinycolor(color2), tinycolor({
370
+ h: (h + 72) % 360,
371
+ s: hsl.s,
372
+ l: hsl.l
373
+ }), tinycolor({
374
+ h: (h + 216) % 360,
375
+ s: hsl.s,
376
+ l: hsl.l
377
+ })];
378
+ }
379
+ function _analogous(color2, results, slices) {
380
+ results = results || 6, slices = slices || 30;
381
+ var hsl = tinycolor(color2).toHsl(), part = 360 / slices, ret = [tinycolor(color2)];
382
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; )
383
+ hsl.h = (hsl.h + part) % 360, ret.push(tinycolor(hsl));
384
+ return ret;
385
+ }
386
+ function _monochromatic(color2, results) {
387
+ results = results || 6;
388
+ for (var hsv = tinycolor(color2).toHsv(), h = hsv.h, s = hsv.s, v = hsv.v, ret = [], modification = 1 / results; results--; )
389
+ ret.push(tinycolor({
390
+ h,
391
+ s,
392
+ v
393
+ })), v = (v + modification) % 1;
394
+ return ret;
395
+ }
396
+ tinycolor.mix = function(color1, color2, amount) {
397
+ amount = amount === 0 ? 0 : amount || 50;
398
+ var rgb1 = tinycolor(color1).toRgb(), rgb2 = tinycolor(color2).toRgb(), p = amount / 100, rgba = {
399
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
400
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
401
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
402
+ a: (rgb2.a - rgb1.a) * p + rgb1.a
403
+ };
404
+ return tinycolor(rgba);
405
+ };
406
+ tinycolor.readability = function(color1, color2) {
407
+ var c1 = tinycolor(color1), c2 = tinycolor(color2);
408
+ return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
409
+ };
410
+ tinycolor.isReadable = function(color1, color2, wcag2) {
411
+ var readability = tinycolor.readability(color1, color2), wcag2Parms, out;
412
+ switch (out = !1, wcag2Parms = validateWCAG2Parms(wcag2), wcag2Parms.level + wcag2Parms.size) {
413
+ case "AAsmall":
414
+ case "AAAlarge":
415
+ out = readability >= 4.5;
416
+ break;
417
+ case "AAlarge":
418
+ out = readability >= 3;
419
+ break;
420
+ case "AAAsmall":
421
+ out = readability >= 7;
422
+ break;
423
+ }
424
+ return out;
425
+ };
426
+ tinycolor.mostReadable = function(baseColor, colorList, args) {
427
+ var bestColor = null, bestScore = 0, readability, includeFallbackColors, level, size;
428
+ args = args || {}, includeFallbackColors = args.includeFallbackColors, level = args.level, size = args.size;
429
+ for (var i = 0; i < colorList.length; i++)
430
+ readability = tinycolor.readability(baseColor, colorList[i]), readability > bestScore && (bestScore = readability, bestColor = tinycolor(colorList[i]));
431
+ return tinycolor.isReadable(baseColor, bestColor, {
432
+ level,
433
+ size
434
+ }) || !includeFallbackColors ? bestColor : (args.includeFallbackColors = !1, tinycolor.mostReadable(baseColor, ["#fff", "#000"], args));
435
+ };
436
+ var names = tinycolor.names = {
437
+ aliceblue: "f0f8ff",
438
+ antiquewhite: "faebd7",
439
+ aqua: "0ff",
440
+ aquamarine: "7fffd4",
441
+ azure: "f0ffff",
442
+ beige: "f5f5dc",
443
+ bisque: "ffe4c4",
444
+ black: "000",
445
+ blanchedalmond: "ffebcd",
446
+ blue: "00f",
447
+ blueviolet: "8a2be2",
448
+ brown: "a52a2a",
449
+ burlywood: "deb887",
450
+ burntsienna: "ea7e5d",
451
+ cadetblue: "5f9ea0",
452
+ chartreuse: "7fff00",
453
+ chocolate: "d2691e",
454
+ coral: "ff7f50",
455
+ cornflowerblue: "6495ed",
456
+ cornsilk: "fff8dc",
457
+ crimson: "dc143c",
458
+ cyan: "0ff",
459
+ darkblue: "00008b",
460
+ darkcyan: "008b8b",
461
+ darkgoldenrod: "b8860b",
462
+ darkgray: "a9a9a9",
463
+ darkgreen: "006400",
464
+ darkgrey: "a9a9a9",
465
+ darkkhaki: "bdb76b",
466
+ darkmagenta: "8b008b",
467
+ darkolivegreen: "556b2f",
468
+ darkorange: "ff8c00",
469
+ darkorchid: "9932cc",
470
+ darkred: "8b0000",
471
+ darksalmon: "e9967a",
472
+ darkseagreen: "8fbc8f",
473
+ darkslateblue: "483d8b",
474
+ darkslategray: "2f4f4f",
475
+ darkslategrey: "2f4f4f",
476
+ darkturquoise: "00ced1",
477
+ darkviolet: "9400d3",
478
+ deeppink: "ff1493",
479
+ deepskyblue: "00bfff",
480
+ dimgray: "696969",
481
+ dimgrey: "696969",
482
+ dodgerblue: "1e90ff",
483
+ firebrick: "b22222",
484
+ floralwhite: "fffaf0",
485
+ forestgreen: "228b22",
486
+ fuchsia: "f0f",
487
+ gainsboro: "dcdcdc",
488
+ ghostwhite: "f8f8ff",
489
+ gold: "ffd700",
490
+ goldenrod: "daa520",
491
+ gray: "808080",
492
+ green: "008000",
493
+ greenyellow: "adff2f",
494
+ grey: "808080",
495
+ honeydew: "f0fff0",
496
+ hotpink: "ff69b4",
497
+ indianred: "cd5c5c",
498
+ indigo: "4b0082",
499
+ ivory: "fffff0",
500
+ khaki: "f0e68c",
501
+ lavender: "e6e6fa",
502
+ lavenderblush: "fff0f5",
503
+ lawngreen: "7cfc00",
504
+ lemonchiffon: "fffacd",
505
+ lightblue: "add8e6",
506
+ lightcoral: "f08080",
507
+ lightcyan: "e0ffff",
508
+ lightgoldenrodyellow: "fafad2",
509
+ lightgray: "d3d3d3",
510
+ lightgreen: "90ee90",
511
+ lightgrey: "d3d3d3",
512
+ lightpink: "ffb6c1",
513
+ lightsalmon: "ffa07a",
514
+ lightseagreen: "20b2aa",
515
+ lightskyblue: "87cefa",
516
+ lightslategray: "789",
517
+ lightslategrey: "789",
518
+ lightsteelblue: "b0c4de",
519
+ lightyellow: "ffffe0",
520
+ lime: "0f0",
521
+ limegreen: "32cd32",
522
+ linen: "faf0e6",
523
+ magenta: "f0f",
524
+ maroon: "800000",
525
+ mediumaquamarine: "66cdaa",
526
+ mediumblue: "0000cd",
527
+ mediumorchid: "ba55d3",
528
+ mediumpurple: "9370db",
529
+ mediumseagreen: "3cb371",
530
+ mediumslateblue: "7b68ee",
531
+ mediumspringgreen: "00fa9a",
532
+ mediumturquoise: "48d1cc",
533
+ mediumvioletred: "c71585",
534
+ midnightblue: "191970",
535
+ mintcream: "f5fffa",
536
+ mistyrose: "ffe4e1",
537
+ moccasin: "ffe4b5",
538
+ navajowhite: "ffdead",
539
+ navy: "000080",
540
+ oldlace: "fdf5e6",
541
+ olive: "808000",
542
+ olivedrab: "6b8e23",
543
+ orange: "ffa500",
544
+ orangered: "ff4500",
545
+ orchid: "da70d6",
546
+ palegoldenrod: "eee8aa",
547
+ palegreen: "98fb98",
548
+ paleturquoise: "afeeee",
549
+ palevioletred: "db7093",
550
+ papayawhip: "ffefd5",
551
+ peachpuff: "ffdab9",
552
+ peru: "cd853f",
553
+ pink: "ffc0cb",
554
+ plum: "dda0dd",
555
+ powderblue: "b0e0e6",
556
+ purple: "800080",
557
+ rebeccapurple: "663399",
558
+ red: "f00",
559
+ rosybrown: "bc8f8f",
560
+ royalblue: "4169e1",
561
+ saddlebrown: "8b4513",
562
+ salmon: "fa8072",
563
+ sandybrown: "f4a460",
564
+ seagreen: "2e8b57",
565
+ seashell: "fff5ee",
566
+ sienna: "a0522d",
567
+ silver: "c0c0c0",
568
+ skyblue: "87ceeb",
569
+ slateblue: "6a5acd",
570
+ slategray: "708090",
571
+ slategrey: "708090",
572
+ snow: "fffafa",
573
+ springgreen: "00ff7f",
574
+ steelblue: "4682b4",
575
+ tan: "d2b48c",
576
+ teal: "008080",
577
+ thistle: "d8bfd8",
578
+ tomato: "ff6347",
579
+ turquoise: "40e0d0",
580
+ violet: "ee82ee",
581
+ wheat: "f5deb3",
582
+ white: "fff",
583
+ whitesmoke: "f5f5f5",
584
+ yellow: "ff0",
585
+ yellowgreen: "9acd32"
586
+ }, hexNames = tinycolor.hexNames = flip(names);
587
+ function flip(o) {
588
+ var flipped = {};
589
+ for (var i in o)
590
+ o.hasOwnProperty(i) && (flipped[o[i]] = i);
591
+ return flipped;
592
+ }
593
+ function boundAlpha(a) {
594
+ return a = parseFloat(a), (isNaN(a) || a < 0 || a > 1) && (a = 1), a;
595
+ }
596
+ function bound01(n, max) {
597
+ isOnePointZero(n) && (n = "100%");
598
+ var processPercent = isPercentage(n);
599
+ return n = Math.min(max, Math.max(0, parseFloat(n))), processPercent && (n = parseInt(n * max, 10) / 100), Math.abs(n - max) < 1e-6 ? 1 : n % max / parseFloat(max);
600
+ }
601
+ function clamp01(val) {
602
+ return Math.min(1, Math.max(0, val));
603
+ }
604
+ function parseIntFromHex(val) {
605
+ return parseInt(val, 16);
606
+ }
607
+ function isOnePointZero(n) {
608
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
609
+ }
610
+ function isPercentage(n) {
611
+ return typeof n == "string" && n.indexOf("%") != -1;
612
+ }
613
+ function pad2(c) {
614
+ return c.length == 1 ? "0" + c : "" + c;
615
+ }
616
+ function convertToPercentage(n) {
617
+ return n <= 1 && (n = n * 100 + "%"), n;
618
+ }
619
+ function convertDecimalToHex(d) {
620
+ return Math.round(parseFloat(d) * 255).toString(16);
621
+ }
622
+ function convertHexToDecimal(h) {
623
+ return parseIntFromHex(h) / 255;
624
+ }
625
+ var matchers = function() {
626
+ var CSS_INTEGER = "[-\\+]?\\d+%?", CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?", CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")", PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?", PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
627
+ return {
628
+ CSS_UNIT: new RegExp(CSS_UNIT),
629
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
630
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
631
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
632
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
633
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
634
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
635
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
636
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
637
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
638
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
639
+ };
640
+ }();
641
+ function isValidCSSUnit(color2) {
642
+ return !!matchers.CSS_UNIT.exec(color2);
643
+ }
644
+ function stringInputToObject(color2) {
645
+ color2 = color2.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
646
+ var named = !1;
647
+ if (names[color2])
648
+ color2 = names[color2], named = !0;
649
+ else if (color2 == "transparent")
650
+ return {
651
+ r: 0,
652
+ g: 0,
653
+ b: 0,
654
+ a: 0,
655
+ format: "name"
656
+ };
657
+ var match;
658
+ return (match = matchers.rgb.exec(color2)) ? {
659
+ r: match[1],
660
+ g: match[2],
661
+ b: match[3]
662
+ } : (match = matchers.rgba.exec(color2)) ? {
663
+ r: match[1],
664
+ g: match[2],
665
+ b: match[3],
666
+ a: match[4]
667
+ } : (match = matchers.hsl.exec(color2)) ? {
668
+ h: match[1],
669
+ s: match[2],
670
+ l: match[3]
671
+ } : (match = matchers.hsla.exec(color2)) ? {
672
+ h: match[1],
673
+ s: match[2],
674
+ l: match[3],
675
+ a: match[4]
676
+ } : (match = matchers.hsv.exec(color2)) ? {
677
+ h: match[1],
678
+ s: match[2],
679
+ v: match[3]
680
+ } : (match = matchers.hsva.exec(color2)) ? {
681
+ h: match[1],
682
+ s: match[2],
683
+ v: match[3],
684
+ a: match[4]
685
+ } : (match = matchers.hex8.exec(color2)) ? {
686
+ r: parseIntFromHex(match[1]),
687
+ g: parseIntFromHex(match[2]),
688
+ b: parseIntFromHex(match[3]),
689
+ a: convertHexToDecimal(match[4]),
690
+ format: named ? "name" : "hex8"
691
+ } : (match = matchers.hex6.exec(color2)) ? {
692
+ r: parseIntFromHex(match[1]),
693
+ g: parseIntFromHex(match[2]),
694
+ b: parseIntFromHex(match[3]),
695
+ format: named ? "name" : "hex"
696
+ } : (match = matchers.hex4.exec(color2)) ? {
697
+ r: parseIntFromHex(match[1] + "" + match[1]),
698
+ g: parseIntFromHex(match[2] + "" + match[2]),
699
+ b: parseIntFromHex(match[3] + "" + match[3]),
700
+ a: convertHexToDecimal(match[4] + "" + match[4]),
701
+ format: named ? "name" : "hex8"
702
+ } : (match = matchers.hex3.exec(color2)) ? {
703
+ r: parseIntFromHex(match[1] + "" + match[1]),
704
+ g: parseIntFromHex(match[2] + "" + match[2]),
705
+ b: parseIntFromHex(match[3] + "" + match[3]),
706
+ format: named ? "name" : "hex"
707
+ } : !1;
708
+ }
709
+ function validateWCAG2Parms(parms) {
710
+ var level, size;
711
+ return parms = parms || {
712
+ level: "AA",
713
+ size: "small"
714
+ }, level = (parms.level || "AA").toUpperCase(), size = (parms.size || "small").toLowerCase(), level !== "AA" && level !== "AAA" && (level = "AA"), size !== "small" && size !== "large" && (size = "small"), {
715
+ level,
716
+ size
717
+ };
718
+ }
719
+ const ColorListWrap = styled(Flex)`
720
+ gap: 0.25em;
721
+ `, ColorBoxContainer = styled.div`
722
+ width: 2.1em;
723
+ height: 2.1em;
724
+ cursor: pointer;
725
+ position: relative;
726
+ overflow: hidden;
727
+ border-radius: 3px;
728
+ background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')
729
+ left center #fff;
730
+ `, ColorBox$1 = styled.div`
731
+ border-radius: inherit;
732
+ box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);
733
+ content: '';
734
+ position: absolute;
735
+ inset: 0;
736
+ z-index: 1;
737
+ `, validateColors = (colors) => colors.reduce((cls, c) => {
738
+ const color2 = c.hex ? tinycolor(c.hex) : tinycolor(c);
739
+ return color2.isValid() && cls.push({
740
+ color: c,
741
+ backgroundColor: color2.toRgbString()
742
+ }), cls;
743
+ }, []), ColorList = memo(function({ colors, onChange }) {
744
+ return colors ? /* @__PURE__ */ jsx(ColorListWrap, { wrap: "wrap", children: validateColors(colors).map(({ color: color2, backgroundColor }, idx) => /* @__PURE__ */ jsx(
745
+ ColorBoxContainer,
746
+ {
747
+ onClick: () => {
748
+ onChange(color2);
749
+ },
750
+ children: /* @__PURE__ */ jsx(ColorBox$1, { style: { background: backgroundColor } })
751
+ },
752
+ `${backgroundColor}-${idx}`
753
+ )) }) : null;
754
+ }), ColorPickerFields = ({
755
+ onChange,
756
+ rgb,
757
+ hsl,
758
+ hex,
759
+ disableAlpha
760
+ }) => {
761
+ const { sanity } = useTheme(), inputStyles = useMemo(
762
+ () => ({
763
+ input: {
764
+ width: "80%",
765
+ padding: "4px 10% 3px",
766
+ border: "none",
767
+ boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,
768
+ color: sanity.color.input.default.enabled.fg,
769
+ backgroundColor: sanity.color.input.default.enabled.bg,
770
+ fontSize: sanity.fonts.text.sizes[0].fontSize,
771
+ textAlign: "center"
772
+ },
773
+ label: {
774
+ display: "block",
775
+ textAlign: "center",
776
+ fontSize: sanity.fonts.label.sizes[0].fontSize,
777
+ color: sanity.color.base.fg,
778
+ paddingTop: "3px",
779
+ paddingBottom: "4px",
780
+ textTransform: "capitalize"
781
+ }
782
+ }),
783
+ [sanity]
784
+ ), handleChange = useCallback(
785
+ (data) => {
786
+ if ("hex" in data && data.hex && isValidHex(data.hex))
787
+ onChange({
788
+ hex: data.hex,
789
+ source: "hex"
790
+ });
791
+ else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b))
792
+ onChange({
793
+ r: Number(data.r) || rgb.r,
794
+ g: Number(data.g) || rgb.g,
795
+ b: Number(data.b) || rgb.b,
796
+ a: rgb.a,
797
+ source: "rgb"
798
+ });
799
+ else if (hsl && "a" in data && data.a) {
800
+ let alpha = Number(data.a);
801
+ alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha /= 100, onChange({
802
+ h: hsl.h,
803
+ s: hsl.s,
804
+ l: hsl.l,
805
+ a: alpha,
806
+ source: "hsl"
807
+ });
808
+ }
809
+ },
810
+ [onChange, hsl, rgb]
811
+ );
812
+ return /* @__PURE__ */ jsxs(Flex, { children: [
813
+ /* @__PURE__ */ jsx(Box, { flex: 2, marginRight: 1, children: /* @__PURE__ */ jsx(
814
+ EditableInput,
815
+ {
816
+ style: inputStyles,
817
+ label: "hex",
818
+ value: hex?.replace("#", ""),
819
+ onChange: handleChange
820
+ }
821
+ ) }),
822
+ /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
823
+ EditableInput,
824
+ {
825
+ style: inputStyles,
826
+ label: "r",
827
+ value: rgb?.r,
828
+ onChange: handleChange,
829
+ dragLabel: !0,
830
+ dragMax: 255
831
+ }
832
+ ) }),
833
+ /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
834
+ EditableInput,
835
+ {
836
+ style: inputStyles,
837
+ label: "g",
838
+ value: rgb?.g,
839
+ onChange: handleChange,
840
+ dragLabel: !0,
841
+ dragMax: 255
842
+ }
843
+ ) }),
844
+ /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
845
+ EditableInput,
846
+ {
847
+ style: inputStyles,
848
+ label: "b",
849
+ value: rgb?.b,
850
+ onChange: handleChange,
851
+ dragLabel: !0,
852
+ dragMax: 255
853
+ }
854
+ ) }),
855
+ !disableAlpha && /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(
856
+ EditableInput,
857
+ {
858
+ style: inputStyles,
859
+ label: "a",
860
+ value: Math.round((rgb?.a ?? 1) * 100),
861
+ onChange: handleChange,
862
+ dragLabel: !0,
863
+ dragMax: 100
864
+ }
865
+ ) })
866
+ ] });
867
+ }, ColorBox = styled(Box)`
868
+ position: absolute;
869
+ top: 0;
870
+ left: 0;
871
+ width: 100%;
872
+ height: 100%;
873
+ `, ReadOnlyContainer = styled(Flex)`
874
+ margin-top: 6rem;
875
+ background-color: var(--card-bg-color);
876
+ position: relative;
877
+ width: 100%;
878
+ `, ColorPickerInner = (props) => {
879
+ const {
880
+ width,
881
+ color: { rgb, hex, hsv, hsl },
882
+ onChange,
883
+ onUnset,
884
+ disableAlpha,
885
+ colorList,
886
+ readOnly
887
+ } = props;
888
+ return !hsl || !hsv ? null : /* @__PURE__ */ jsx("div", { style: { width }, children: /* @__PURE__ */ jsx(Card, { padding: 1, border: !0, radius: 1, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
889
+ !readOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
890
+ /* @__PURE__ */ jsx(Card, { overflow: "hidden", style: { position: "relative", height: "5em" }, children: /* @__PURE__ */ jsx(Saturation, { onChange, hsl, hsv }) }),
891
+ /* @__PURE__ */ jsx(
892
+ Card,
893
+ {
894
+ shadow: 1,
895
+ radius: 3,
896
+ overflow: "hidden",
897
+ style: { position: "relative", height: "10px" },
898
+ children: /* @__PURE__ */ jsx(Hue, { hsl, onChange: !readOnly && onChange })
899
+ }
900
+ ),
901
+ !disableAlpha && /* @__PURE__ */ jsx(
902
+ Card,
903
+ {
904
+ shadow: 1,
905
+ radius: 3,
906
+ overflow: "hidden",
907
+ style: { position: "relative", height: "10px", background: "#fff" },
908
+ children: /* @__PURE__ */ jsx(Alpha, { rgb, hsl, onChange })
909
+ }
910
+ )
911
+ ] }),
912
+ /* @__PURE__ */ jsxs(Flex, { children: [
913
+ /* @__PURE__ */ jsxs(
914
+ Card,
915
+ {
916
+ flex: 1,
917
+ radius: 2,
918
+ overflow: "hidden",
919
+ style: { position: "relative", minWidth: "4em", background: "#fff" },
920
+ children: [
921
+ /* @__PURE__ */ jsx(Checkboard, {}),
922
+ /* @__PURE__ */ jsx(
923
+ ColorBox,
924
+ {
925
+ style: {
926
+ backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`
927
+ }
928
+ }
929
+ ),
930
+ readOnly && /* @__PURE__ */ jsx(
931
+ ReadOnlyContainer,
932
+ {
933
+ padding: 2,
934
+ paddingBottom: 1,
935
+ sizing: "border",
936
+ justify: "space-between",
937
+ children: /* @__PURE__ */ jsxs(Stack, { space: 3, marginTop: 1, children: [
938
+ /* @__PURE__ */ jsx(Text, { size: 3, weight: "bold", children: hex }),
939
+ /* @__PURE__ */ jsxs(Inline, { space: 3, children: [
940
+ /* @__PURE__ */ jsxs(Text, { size: 1, children: [
941
+ /* @__PURE__ */ jsx("strong", { children: "RGB: " }),
942
+ rgb?.r,
943
+ " ",
944
+ rgb?.g,
945
+ " ",
946
+ rgb?.b
947
+ ] }),
948
+ /* @__PURE__ */ jsxs(Text, { size: 1, children: [
949
+ /* @__PURE__ */ jsx("strong", { children: "HSL: " }),
950
+ " ",
951
+ Math.round(hsl?.h ?? 0),
952
+ " ",
953
+ Math.round((hsl?.s ?? 0) * 100),
954
+ "% ",
955
+ Math.round((hsl?.l ?? 0) * 100),
956
+ "%"
957
+ ] })
958
+ ] })
959
+ ] })
960
+ }
961
+ )
962
+ ]
963
+ }
964
+ ),
965
+ !readOnly && /* @__PURE__ */ jsxs(Flex, { align: "flex-start", marginLeft: 2, children: [
966
+ /* @__PURE__ */ jsx(Box, { style: { width: 200 }, children: /* @__PURE__ */ jsx(
967
+ ColorPickerFields,
968
+ {
969
+ rgb,
970
+ hsl,
971
+ hex,
972
+ onChange,
973
+ disableAlpha
974
+ }
975
+ ) }),
976
+ /* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Button, { onClick: onUnset, title: "Delete color", icon: TrashIcon, tone: "critical" }) })
977
+ ] })
978
+ ] }),
979
+ colorList && /* @__PURE__ */ jsx(ColorList, { colors: colorList, onChange })
980
+ ] }) }) });
981
+ }, ColorPicker = CustomPicker(ColorPickerInner), DEFAULT_COLOR = {
982
+ hex: "#24a3e3",
983
+ hsl: { h: 200, s: 0.7732, l: 0.5156, a: 1 },
984
+ hsv: { h: 200, s: 0.8414, v: 0.8901, a: 1 },
985
+ rgb: { r: 46, g: 163, b: 227, a: 1 },
986
+ source: "hex"
987
+ };
988
+ function ColorInput(props) {
989
+ const { onChange, readOnly } = props, value = props.value, type = props.schemaType, focusRef = useRef(null), [color2, setColor] = useState(value);
990
+ useEffect(() => setColor(value), [value]);
991
+ const emitSetColor = useCallback(
992
+ (nextColor) => {
993
+ const fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field) => {
994
+ const nextFieldValue = nextColor[field.name], isObject = field.type.jsonType === "object";
995
+ return set(
996
+ isObject ? Object.assign({ _type: field.type.name }, nextFieldValue) : nextFieldValue,
997
+ [field.name]
998
+ );
999
+ });
1000
+ onChange([
1001
+ setIfMissing({ _type: type.name }),
1002
+ set(type.name, ["_type"]),
1003
+ set(nextColor.rgb?.a, ["alpha"]),
1004
+ ...fieldPatches
1005
+ ]);
1006
+ },
1007
+ [onChange, type]
1008
+ ), debouncedColorChange = useMemo(() => debounce(emitSetColor, 100), [emitSetColor]), handleColorChange = useCallback(
1009
+ (nextColor) => {
1010
+ setColor(nextColor), debouncedColorChange(nextColor);
1011
+ },
1012
+ [debouncedColorChange, setColor]
1013
+ ), handleCreateColor = useCallback(() => {
1014
+ setColor(DEFAULT_COLOR), emitSetColor(DEFAULT_COLOR);
1015
+ }, [emitSetColor]), handleUnset = useCallback(() => {
1016
+ setColor(void 0), onChange(unset());
1017
+ }, [onChange]);
1018
+ return /* @__PURE__ */ jsx(Fragment, { children: value && value.hex ? /* @__PURE__ */ jsx(
1019
+ ColorPicker,
1020
+ {
1021
+ color: color2,
1022
+ onChange: handleColorChange,
1023
+ readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly,
1024
+ disableAlpha: !!type.options?.disableAlpha,
1025
+ colorList: type.options?.colorList,
1026
+ onUnset: handleUnset
1027
+ }
1028
+ ) : /* @__PURE__ */ jsx(
1029
+ Button,
1030
+ {
1031
+ icon: AddIcon,
1032
+ mode: "ghost",
1033
+ text: "Create color",
1034
+ ref: focusRef,
1035
+ disabled: !!readOnly,
1036
+ onClick: handleCreateColor
1037
+ }
1038
+ ) });
1039
+ }
1040
+ const round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = defineType({
1041
+ name: colorTypeName,
1042
+ type: "object",
1043
+ title: "Color",
1044
+ components: { input: ColorInput },
1045
+ fields: [
1046
+ {
1047
+ title: "Hex",
1048
+ name: "hex",
1049
+ type: "string"
1050
+ },
1051
+ {
1052
+ title: "Alpha",
1053
+ name: "alpha",
1054
+ type: "number"
1055
+ },
1056
+ {
1057
+ title: "Hue Saturation Lightness",
1058
+ name: "hsl",
1059
+ type: "hslaColor"
1060
+ },
1061
+ {
1062
+ title: "Hue Saturation Value",
1063
+ name: "hsv",
1064
+ type: "hsvaColor"
1065
+ },
1066
+ {
1067
+ title: "Red Green Blue (rgb)",
1068
+ name: "rgb",
1069
+ type: "rgbaColor"
1070
+ }
1071
+ ],
1072
+ preview: {
1073
+ select: {
1074
+ title: "hex",
1075
+ alpha: "alpha",
1076
+ hex: "hex",
1077
+ hsl: "hsl"
1078
+ },
1079
+ prepare({
1080
+ title,
1081
+ hex,
1082
+ hsl,
1083
+ alpha
1084
+ }) {
1085
+ let subtitle = hex || "No color set";
1086
+ return hsl && (subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`), {
1087
+ title,
1088
+ subtitle,
1089
+ media: () => /* @__PURE__ */ jsx(
1090
+ "div",
1091
+ {
1092
+ style: {
1093
+ backgroundColor: hex ?? "#000",
1094
+ opacity: alpha ?? 1,
1095
+ position: "absolute",
1096
+ height: "100%",
1097
+ width: "100%",
1098
+ top: "0",
1099
+ left: "0"
1100
+ }
1101
+ }
1102
+ )
1103
+ };
1104
+ }
1105
+ }
1106
+ }), hslaColor = defineType({
1107
+ title: "Hue Saturation Lightness",
1108
+ name: "hslaColor",
1109
+ type: "object",
1110
+ fields: [
1111
+ { name: "h", type: "number", title: "Hue" },
1112
+ { name: "s", type: "number", title: "Saturation" },
1113
+ { name: "l", type: "number", title: "Lightness" },
1114
+ { name: "a", type: "number", title: "Alpha" }
1115
+ ]
1116
+ }), hsvaColor = defineType({
1117
+ title: "Hue Saturation Value",
1118
+ name: "hsvaColor",
1119
+ type: "object",
1120
+ fields: [
1121
+ { name: "h", type: "number", title: "Hue" },
1122
+ { name: "s", type: "number", title: "Saturation" },
1123
+ { name: "v", type: "number", title: "Value" },
1124
+ { name: "a", type: "number", title: "Alpha" }
1125
+ ]
1126
+ }), rgbaColor = defineType({
1127
+ title: "Red Green Blue (rgb)",
1128
+ name: "rgbaColor",
1129
+ type: "object",
1130
+ fields: [
1131
+ { name: "r", type: "number", title: "Red" },
1132
+ { name: "g", type: "number", title: "Green" },
1133
+ { name: "b", type: "number", title: "Blue" },
1134
+ { name: "a", type: "number", title: "Alpha" }
1135
+ ]
1136
+ }), colorInput = definePlugin({
1137
+ name: "@sanity/color-input",
1138
+ schema: {
1139
+ types: [hslaColor, hsvaColor, rgbaColor, color]
1140
+ }
1141
+ });
1142
+ export {
1143
+ ColorInput,
1144
+ color,
1145
+ colorInput,
1146
+ hslaColor,
1147
+ hsvaColor,
1148
+ rgbaColor
1149
+ };
1150
+ //# sourceMappingURL=index.mjs.map