@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.js CHANGED
@@ -1,272 +1,58 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- });
6
- var sanity = require('sanity');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var react = require('react');
9
- var lodash = require('lodash');
10
- var ui = require('@sanity/ui');
11
- var icons = require('@sanity/icons');
12
- var common = require('react-color/lib/components/common');
13
- var reactColor = require('react-color');
14
- var styled = require('styled-components');
15
- var color$1 = require('react-color/lib/helpers/color');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: !0 });
3
+ var sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), icons = require("@sanity/icons"), ui = require("@sanity/ui"), debounce = require("lodash/debounce.js"), react = require("react"), reactColor = require("react-color"), common = require("react-color/lib/components/common"), styledComponents = require("styled-components"), color$1 = require("react-color/lib/helpers/color");
16
4
  function _interopDefaultCompat(e) {
17
- return e && typeof e === 'object' && 'default' in e ? e : {
18
- default: e
19
- };
5
+ return e && typeof e == "object" && "default" in e ? e : { default: e };
20
6
  }
21
- var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
22
- const hslaColor = sanity.defineType({
23
- title: "Hue Saturation Lightness",
24
- name: "hslaColor",
25
- type: "object",
26
- fields: [{
27
- name: "h",
28
- type: "number",
29
- title: "Hue"
30
- }, {
31
- name: "s",
32
- type: "number",
33
- title: "Saturation"
34
- }, {
35
- name: "l",
36
- type: "number",
37
- title: "Lightness"
38
- }, {
39
- name: "a",
40
- type: "number",
41
- title: "Alpha"
42
- }]
43
- });
44
- const rgbaColor = sanity.defineType({
45
- title: "Red Green Blue (rgb)",
46
- name: "rgbaColor",
47
- type: "object",
48
- fields: [{
49
- name: "r",
50
- type: "number",
51
- title: "Red"
52
- }, {
53
- name: "g",
54
- type: "number",
55
- title: "Green"
56
- }, {
57
- name: "b",
58
- type: "number",
59
- title: "Blue"
60
- }, {
61
- name: "a",
62
- type: "number",
63
- title: "Alpha"
64
- }]
65
- });
66
- const ColorPickerFields = _ref => {
67
- let {
68
- onChange,
69
- rgb,
70
- hsl,
71
- hex,
72
- disableAlpha
73
- } = _ref;
74
- var _a;
75
- const {
76
- sanity
77
- } = ui.useTheme();
78
- const inputStyles = react.useMemo(() => ({
79
- input: {
80
- width: "80%",
81
- padding: "4px 10% 3px",
82
- border: "none",
83
- boxShadow: "inset 0 0 0 1px ".concat(sanity.color.input.default.enabled.border),
84
- color: sanity.color.input.default.enabled.fg,
85
- backgroundColor: sanity.color.input.default.enabled.bg,
86
- fontSize: sanity.fonts.text.sizes[0].fontSize,
87
- textAlign: "center"
88
- },
89
- label: {
90
- display: "block",
91
- textAlign: "center",
92
- fontSize: sanity.fonts.label.sizes[0].fontSize,
93
- color: sanity.color.base.fg,
94
- paddingTop: "3px",
95
- paddingBottom: "4px",
96
- textTransform: "capitalize"
97
- }
98
- }), [sanity]);
99
- const handleChange = react.useCallback(data => {
100
- if ("hex" in data && data.hex && color$1.isValidHex(data.hex)) {
101
- onChange({
102
- hex: data.hex,
103
- source: "hex"
104
- });
105
- } else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b)) {
106
- onChange({
107
- r: Number(data.r) || rgb.r,
108
- g: Number(data.g) || rgb.g,
109
- b: Number(data.b) || rgb.b,
110
- a: rgb.a,
111
- source: "rgb"
112
- });
113
- } else if (hsl && "a" in data && data.a) {
114
- let alpha = Number(data.a);
115
- if (alpha < 0) {
116
- alpha = 0;
117
- } else if (alpha > 100) {
118
- alpha = 100;
119
- }
120
- alpha /= 100;
121
- onChange({
122
- h: hsl.h,
123
- s: hsl.s,
124
- l: hsl.l,
125
- a: alpha,
126
- source: "hsl"
127
- });
128
- }
129
- }, [onChange, hsl, rgb]);
130
- return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
131
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
132
- flex: 2,
133
- marginRight: 1,
134
- children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
135
- style: inputStyles,
136
- label: "hex",
137
- value: hex == null ? void 0 : hex.replace("#", ""),
138
- onChange: handleChange
139
- })
140
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
141
- flex: 1,
142
- marginRight: 1,
143
- children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
144
- style: inputStyles,
145
- label: "r",
146
- value: rgb == null ? void 0 : rgb.r,
147
- onChange: handleChange,
148
- dragLabel: true,
149
- dragMax: 255
150
- })
151
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
152
- flex: 1,
153
- marginRight: 1,
154
- children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
155
- style: inputStyles,
156
- label: "g",
157
- value: rgb == null ? void 0 : rgb.g,
158
- onChange: handleChange,
159
- dragLabel: true,
160
- dragMax: 255
161
- })
162
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
163
- flex: 1,
164
- marginRight: 1,
165
- children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
166
- style: inputStyles,
167
- label: "b",
168
- value: rgb == null ? void 0 : rgb.b,
169
- onChange: handleChange,
170
- dragLabel: true,
171
- dragMax: 255
172
- })
173
- }), !disableAlpha && /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
174
- flex: 1,
175
- children: /* @__PURE__ */jsxRuntime.jsx(common.EditableInput, {
176
- style: inputStyles,
177
- label: "a",
178
- value: Math.round(((_a = rgb == null ? void 0 : rgb.a) != null ? _a : 1) * 100),
179
- onChange: handleChange,
180
- dragLabel: true,
181
- dragMax: 100
182
- })
183
- })]
184
- });
185
- };
186
-
187
- // This file is autogenerated. It's used to publish ESM to npm.
7
+ var debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce);
188
8
  function _typeof(obj) {
189
9
  "@babel/helpers - typeof";
190
-
191
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
192
- return typeof obj;
193
- } : function (obj) {
194
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
10
+ return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) {
11
+ return typeof obj2;
12
+ } : function(obj2) {
13
+ return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
195
14
  }, _typeof(obj);
196
15
  }
197
-
198
- // https://github.com/bgrins/TinyColor
199
- // Brian Grinstead, MIT License
200
-
201
- var trimLeft = /^\s+/;
202
- var trimRight = /\s+$/;
203
- function tinycolor(color, opts) {
204
- color = color ? color : "";
205
- opts = opts || {};
206
-
207
- // If input is already a tinycolor, return itself
208
- if (color instanceof tinycolor) {
209
- return color;
210
- }
211
- // If we are called as a function, call using new instead
212
- if (!(this instanceof tinycolor)) {
213
- return new tinycolor(color, opts);
214
- }
215
- var rgb = inputToRGB(color);
216
- this._originalInput = color, 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;
217
- this._gradientType = opts.gradientType;
218
-
219
- // Don't let the range of [0,255] come back in [0,1].
220
- // Potentially lose a little bit of precision here, but will fix issues where
221
- // .5 gets interpreted as half of the total, instead of half of 1
222
- // If it was supposed to be 128, this was already taken care of by `inputToRgb`
223
- if (this._r < 1) this._r = Math.round(this._r);
224
- if (this._g < 1) this._g = Math.round(this._g);
225
- if (this._b < 1) this._b = Math.round(this._b);
226
- this._ok = rgb.ok;
16
+ var trimLeft = /^\s+/, trimRight = /\s+$/;
17
+ function tinycolor(color2, opts) {
18
+ if (color2 = color2 || "", opts = opts || {}, color2 instanceof tinycolor)
19
+ return color2;
20
+ if (!(this instanceof tinycolor))
21
+ return new tinycolor(color2, opts);
22
+ var rgb = inputToRGB(color2);
23
+ 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;
227
24
  }
228
25
  tinycolor.prototype = {
229
- isDark: function isDark() {
26
+ isDark: function() {
230
27
  return this.getBrightness() < 128;
231
28
  },
232
- isLight: function isLight() {
29
+ isLight: function() {
233
30
  return !this.isDark();
234
31
  },
235
- isValid: function isValid() {
32
+ isValid: function() {
236
33
  return this._ok;
237
34
  },
238
- getOriginalInput: function getOriginalInput() {
35
+ getOriginalInput: function() {
239
36
  return this._originalInput;
240
37
  },
241
- getFormat: function getFormat() {
38
+ getFormat: function() {
242
39
  return this._format;
243
40
  },
244
- getAlpha: function getAlpha() {
41
+ getAlpha: function() {
245
42
  return this._a;
246
43
  },
247
- getBrightness: function getBrightness() {
248
- //http://www.w3.org/TR/AERT#color-contrast
44
+ getBrightness: function() {
249
45
  var rgb = this.toRgb();
250
- return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
46
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
251
47
  },
252
- getLuminance: function getLuminance() {
253
- //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
254
- var rgb = this.toRgb();
255
- var RsRGB, GsRGB, BsRGB, R, G, B;
256
- RsRGB = rgb.r / 255;
257
- GsRGB = rgb.g / 255;
258
- BsRGB = rgb.b / 255;
259
- if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
260
- if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
261
- if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
262
- return 0.2126 * R + 0.7152 * G + 0.0722 * B;
48
+ getLuminance: function() {
49
+ var rgb = this.toRgb(), RsRGB, GsRGB, BsRGB, R, G, B;
50
+ 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;
263
51
  },
264
- setAlpha: function setAlpha(value) {
265
- this._a = boundAlpha(value);
266
- this._roundA = Math.round(100 * this._a) / 100;
267
- return this;
52
+ setAlpha: function(value) {
53
+ return this._a = boundAlpha(value), this._roundA = Math.round(100 * this._a) / 100, this;
268
54
  },
269
- toHsv: function toHsv() {
55
+ toHsv: function() {
270
56
  var hsv = rgbToHsv(this._r, this._g, this._b);
271
57
  return {
272
58
  h: hsv.h * 360,
@@ -275,14 +61,11 @@ tinycolor.prototype = {
275
61
  a: this._a
276
62
  };
277
63
  },
278
- toHsvString: function toHsvString() {
279
- var hsv = rgbToHsv(this._r, this._g, this._b);
280
- var h = Math.round(hsv.h * 360),
281
- s = Math.round(hsv.s * 100),
282
- v = Math.round(hsv.v * 100);
64
+ toHsvString: function() {
65
+ 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);
283
66
  return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
284
67
  },
285
- toHsl: function toHsl() {
68
+ toHsl: function() {
286
69
  var hsl = rgbToHsl(this._r, this._g, this._b);
287
70
  return {
288
71
  h: hsl.h * 360,
@@ -291,26 +74,23 @@ tinycolor.prototype = {
291
74
  a: this._a
292
75
  };
293
76
  },
294
- toHslString: function toHslString() {
295
- var hsl = rgbToHsl(this._r, this._g, this._b);
296
- var h = Math.round(hsl.h * 360),
297
- s = Math.round(hsl.s * 100),
298
- l = Math.round(hsl.l * 100);
77
+ toHslString: function() {
78
+ 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);
299
79
  return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
300
80
  },
301
- toHex: function toHex(allow3Char) {
81
+ toHex: function(allow3Char) {
302
82
  return rgbToHex(this._r, this._g, this._b, allow3Char);
303
83
  },
304
- toHexString: function toHexString(allow3Char) {
84
+ toHexString: function(allow3Char) {
305
85
  return "#" + this.toHex(allow3Char);
306
86
  },
307
- toHex8: function toHex8(allow4Char) {
87
+ toHex8: function(allow4Char) {
308
88
  return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
309
89
  },
310
- toHex8String: function toHex8String(allow4Char) {
90
+ toHex8String: function(allow4Char) {
311
91
  return "#" + this.toHex8(allow4Char);
312
92
  },
313
- toRgb: function toRgb() {
93
+ toRgb: function() {
314
94
  return {
315
95
  r: Math.round(this._r),
316
96
  g: Math.round(this._g),
@@ -318,10 +98,10 @@ tinycolor.prototype = {
318
98
  a: this._a
319
99
  };
320
100
  },
321
- toRgbString: function toRgbString() {
101
+ toRgbString: function() {
322
102
  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 + ")";
323
103
  },
324
- toPercentageRgb: function toPercentageRgb() {
104
+ toPercentageRgb: function() {
325
105
  return {
326
106
  r: Math.round(bound01(this._r, 255) * 100) + "%",
327
107
  g: Math.round(bound01(this._g, 255) * 100) + "%",
@@ -329,223 +109,104 @@ tinycolor.prototype = {
329
109
  a: this._a
330
110
  };
331
111
  },
332
- toPercentageRgbString: function toPercentageRgbString() {
112
+ toPercentageRgbString: function() {
333
113
  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 + ")";
334
114
  },
335
- toName: function toName() {
336
- if (this._a === 0) {
337
- return "transparent";
338
- }
339
- if (this._a < 1) {
340
- return false;
341
- }
342
- return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
115
+ toName: function() {
116
+ return this._a === 0 ? "transparent" : this._a < 1 ? !1 : hexNames[rgbToHex(this._r, this._g, this._b, !0)] || !1;
343
117
  },
344
- toFilter: function toFilter(secondColor) {
345
- var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
346
- var secondHex8String = hex8String;
347
- var gradientType = this._gradientType ? "GradientType = 1, " : "";
118
+ toFilter: function(secondColor) {
119
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a), secondHex8String = hex8String, gradientType = this._gradientType ? "GradientType = 1, " : "";
348
120
  if (secondColor) {
349
121
  var s = tinycolor(secondColor);
350
122
  secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
351
123
  }
352
124
  return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
353
125
  },
354
- toString: function toString(format) {
126
+ toString: function(format) {
355
127
  var formatSet = !!format;
356
128
  format = format || this._format;
357
- var formattedString = false;
358
- var hasAlpha = this._a < 1 && this._a >= 0;
359
- var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
360
- if (needsAlphaFormat) {
361
- // Special case for "transparent", all other non-alpha formats
362
- // will return rgba when there is transparency.
363
- if (format === "name" && this._a === 0) {
364
- return this.toName();
365
- }
366
- return this.toRgbString();
367
- }
368
- if (format === "rgb") {
369
- formattedString = this.toRgbString();
370
- }
371
- if (format === "prgb") {
372
- formattedString = this.toPercentageRgbString();
373
- }
374
- if (format === "hex" || format === "hex6") {
375
- formattedString = this.toHexString();
376
- }
377
- if (format === "hex3") {
378
- formattedString = this.toHexString(true);
379
- }
380
- if (format === "hex4") {
381
- formattedString = this.toHex8String(true);
382
- }
383
- if (format === "hex8") {
384
- formattedString = this.toHex8String();
385
- }
386
- if (format === "name") {
387
- formattedString = this.toName();
388
- }
389
- if (format === "hsl") {
390
- formattedString = this.toHslString();
391
- }
392
- if (format === "hsv") {
393
- formattedString = this.toHsvString();
394
- }
395
- return formattedString || this.toHexString();
129
+ 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");
130
+ 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());
396
131
  },
397
- clone: function clone() {
132
+ clone: function() {
398
133
  return tinycolor(this.toString());
399
134
  },
400
- _applyModification: function _applyModification(fn, args) {
401
- var color = fn.apply(null, [this].concat([].slice.call(args)));
402
- this._r = color._r;
403
- this._g = color._g;
404
- this._b = color._b;
405
- this.setAlpha(color._a);
406
- return this;
135
+ _applyModification: function(fn, args) {
136
+ var color2 = fn.apply(null, [this].concat([].slice.call(args)));
137
+ return this._r = color2._r, this._g = color2._g, this._b = color2._b, this.setAlpha(color2._a), this;
407
138
  },
408
- lighten: function lighten() {
139
+ lighten: function() {
409
140
  return this._applyModification(_lighten, arguments);
410
141
  },
411
- brighten: function brighten() {
142
+ brighten: function() {
412
143
  return this._applyModification(_brighten, arguments);
413
144
  },
414
- darken: function darken() {
145
+ darken: function() {
415
146
  return this._applyModification(_darken, arguments);
416
147
  },
417
- desaturate: function desaturate() {
148
+ desaturate: function() {
418
149
  return this._applyModification(_desaturate, arguments);
419
150
  },
420
- saturate: function saturate() {
151
+ saturate: function() {
421
152
  return this._applyModification(_saturate, arguments);
422
153
  },
423
- greyscale: function greyscale() {
154
+ greyscale: function() {
424
155
  return this._applyModification(_greyscale, arguments);
425
156
  },
426
- spin: function spin() {
157
+ spin: function() {
427
158
  return this._applyModification(_spin, arguments);
428
159
  },
429
- _applyCombination: function _applyCombination(fn, args) {
160
+ _applyCombination: function(fn, args) {
430
161
  return fn.apply(null, [this].concat([].slice.call(args)));
431
162
  },
432
- analogous: function analogous() {
163
+ analogous: function() {
433
164
  return this._applyCombination(_analogous, arguments);
434
165
  },
435
- complement: function complement() {
166
+ complement: function() {
436
167
  return this._applyCombination(_complement, arguments);
437
168
  },
438
- monochromatic: function monochromatic() {
169
+ monochromatic: function() {
439
170
  return this._applyCombination(_monochromatic, arguments);
440
171
  },
441
- splitcomplement: function splitcomplement() {
172
+ splitcomplement: function() {
442
173
  return this._applyCombination(_splitcomplement, arguments);
443
174
  },
444
175
  // Disabled until https://github.com/bgrins/TinyColor/issues/254
445
176
  // polyad: function (number) {
446
177
  // return this._applyCombination(polyad, [number]);
447
178
  // },
448
- triad: function triad() {
179
+ triad: function() {
449
180
  return this._applyCombination(polyad, [3]);
450
181
  },
451
- tetrad: function tetrad() {
182
+ tetrad: function() {
452
183
  return this._applyCombination(polyad, [4]);
453
184
  }
454
185
  };
455
-
456
- // If input is an object, force 1 into "1.0" to handle ratios properly
457
- // String input requires "1.0" as input, so 1 will be treated as 1
458
- tinycolor.fromRatio = function (color, opts) {
459
- if (_typeof(color) == "object") {
186
+ tinycolor.fromRatio = function(color2, opts) {
187
+ if (_typeof(color2) == "object") {
460
188
  var newColor = {};
461
- for (var i in color) {
462
- if (color.hasOwnProperty(i)) {
463
- if (i === "a") {
464
- newColor[i] = color[i];
465
- } else {
466
- newColor[i] = convertToPercentage(color[i]);
467
- }
468
- }
469
- }
470
- color = newColor;
189
+ for (var i in color2)
190
+ color2.hasOwnProperty(i) && (i === "a" ? newColor[i] = color2[i] : newColor[i] = convertToPercentage(color2[i]));
191
+ color2 = newColor;
471
192
  }
472
- return tinycolor(color, opts);
193
+ return tinycolor(color2, opts);
473
194
  };
474
-
475
- // Given a string or object, convert that input to RGB
476
- // Possible string inputs:
477
- //
478
- // "red"
479
- // "#f00" or "f00"
480
- // "#ff0000" or "ff0000"
481
- // "#ff000000" or "ff000000"
482
- // "rgb 255 0 0" or "rgb (255, 0, 0)"
483
- // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
484
- // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
485
- // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
486
- // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
487
- // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
488
- // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
489
- //
490
- function inputToRGB(color) {
195
+ function inputToRGB(color2) {
491
196
  var rgb = {
492
197
  r: 0,
493
198
  g: 0,
494
199
  b: 0
495
- };
496
- var a = 1;
497
- var s = null;
498
- var v = null;
499
- var l = null;
500
- var ok = false;
501
- var format = false;
502
- if (typeof color == "string") {
503
- color = stringInputToObject(color);
504
- }
505
- if (_typeof(color) == "object") {
506
- if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
507
- rgb = rgbToRgb(color.r, color.g, color.b);
508
- ok = true;
509
- format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
510
- } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
511
- s = convertToPercentage(color.s);
512
- v = convertToPercentage(color.v);
513
- rgb = hsvToRgb(color.h, s, v);
514
- ok = true;
515
- format = "hsv";
516
- } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
517
- s = convertToPercentage(color.s);
518
- l = convertToPercentage(color.l);
519
- rgb = hslToRgb(color.h, s, l);
520
- ok = true;
521
- format = "hsl";
522
- }
523
- if (color.hasOwnProperty("a")) {
524
- a = color.a;
525
- }
526
- }
527
- a = boundAlpha(a);
528
- return {
529
- ok: ok,
530
- format: color.format || format,
200
+ }, a = 1, s = null, v = null, l = null, ok = !1, format = !1;
201
+ 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), {
202
+ ok,
203
+ format: color2.format || format,
531
204
  r: Math.min(255, Math.max(rgb.r, 0)),
532
205
  g: Math.min(255, Math.max(rgb.g, 0)),
533
206
  b: Math.min(255, Math.max(rgb.b, 0)),
534
- a: a
207
+ a
535
208
  };
536
209
  }
537
-
538
- // Conversion Functions
539
- // --------------------
540
-
541
- // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
542
- // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
543
-
544
- // `rgbToRgb`
545
- // Handle bounds / percentage checking to conform to CSS color spec
546
- // <http://www.w3.org/TR/css3-color/>
547
- // *Assumes:* r, g, b in [0, 255] or [0, 1]
548
- // *Returns:* { r, g, b } in [0, 255]
549
210
  function rgbToRgb(r, g, b) {
550
211
  return {
551
212
  r: bound01(r, 255) * 255,
@@ -553,26 +214,14 @@ function rgbToRgb(r, g, b) {
553
214
  b: bound01(b, 255) * 255
554
215
  };
555
216
  }
556
-
557
- // `rgbToHsl`
558
- // Converts an RGB color value to HSL.
559
- // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
560
- // *Returns:* { h, s, l } in [0,1]
561
217
  function rgbToHsl(r, g, b) {
562
- r = bound01(r, 255);
563
- g = bound01(g, 255);
564
- b = bound01(b, 255);
565
- var max = Math.max(r, g, b),
566
- min = Math.min(r, g, b);
567
- var h,
568
- s,
569
- l = (max + min) / 2;
570
- if (max == min) {
571
- h = s = 0; // achromatic
572
- } else {
218
+ r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
219
+ var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, l = (max + min) / 2;
220
+ if (max == min)
221
+ h = s = 0;
222
+ else {
573
223
  var d = max - min;
574
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
575
- switch (max) {
224
+ switch (s = l > 0.5 ? d / (2 - max - min) : d / (max + min), max) {
576
225
  case r:
577
226
  h = (g - b) / d + (g < b ? 6 : 0);
578
227
  break;
@@ -586,37 +235,22 @@ function rgbToHsl(r, g, b) {
586
235
  h /= 6;
587
236
  }
588
237
  return {
589
- h: h,
590
- s: s,
591
- l: l
238
+ h,
239
+ s,
240
+ l
592
241
  };
593
242
  }
594
-
595
- // `hslToRgb`
596
- // Converts an HSL color value to RGB.
597
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
598
- // *Returns:* { r, g, b } in the set [0, 255]
599
243
  function hslToRgb(h, s, l) {
600
244
  var r, g, b;
601
- h = bound01(h, 360);
602
- s = bound01(s, 100);
603
- l = bound01(l, 100);
604
- function hue2rgb(p, q, t) {
605
- if (t < 0) t += 1;
606
- if (t > 1) t -= 1;
607
- if (t < 1 / 6) return p + (q - p) * 6 * t;
608
- if (t < 1 / 2) return q;
609
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
610
- return p;
245
+ h = bound01(h, 360), s = bound01(s, 100), l = bound01(l, 100);
246
+ function hue2rgb(p2, q2, t) {
247
+ 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;
611
248
  }
612
- if (s === 0) {
613
- r = g = b = l; // achromatic
614
- } else {
615
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
616
- var p = 2 * l - q;
617
- r = hue2rgb(p, q, h + 1 / 3);
618
- g = hue2rgb(p, q, h);
619
- b = hue2rgb(p, q, h - 1 / 3);
249
+ if (s === 0)
250
+ r = g = b = l;
251
+ else {
252
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q;
253
+ r = hue2rgb(p, q, h + 1 / 3), g = hue2rgb(p, q, h), b = hue2rgb(p, q, h - 1 / 3);
620
254
  }
621
255
  return {
622
256
  r: r * 255,
@@ -624,25 +258,12 @@ function hslToRgb(h, s, l) {
624
258
  b: b * 255
625
259
  };
626
260
  }
627
-
628
- // `rgbToHsv`
629
- // Converts an RGB color value to HSV
630
- // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
631
- // *Returns:* { h, s, v } in [0,1]
632
261
  function rgbToHsv(r, g, b) {
633
- r = bound01(r, 255);
634
- g = bound01(g, 255);
635
- b = bound01(b, 255);
636
- var max = Math.max(r, g, b),
637
- min = Math.min(r, g, b);
638
- var h,
639
- s,
640
- v = max;
641
- var d = max - min;
642
- s = max === 0 ? 0 : d / max;
643
- if (max == min) {
644
- h = 0; // achromatic
645
- } else {
262
+ r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
263
+ var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, v = max, d = max - min;
264
+ if (s = max === 0 ? 0 : d / max, max == min)
265
+ h = 0;
266
+ else {
646
267
  switch (max) {
647
268
  case r:
648
269
  h = (g - b) / d + (g < b ? 6 : 0);
@@ -657,170 +278,92 @@ function rgbToHsv(r, g, b) {
657
278
  h /= 6;
658
279
  }
659
280
  return {
660
- h: h,
661
- s: s,
662
- v: v
281
+ h,
282
+ s,
283
+ v
663
284
  };
664
285
  }
665
-
666
- // `hsvToRgb`
667
- // Converts an HSV color value to RGB.
668
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
669
- // *Returns:* { r, g, b } in the set [0, 255]
670
286
  function hsvToRgb(h, s, v) {
671
- h = bound01(h, 360) * 6;
672
- s = bound01(s, 100);
673
- v = bound01(v, 100);
674
- var i = Math.floor(h),
675
- f = h - i,
676
- p = v * (1 - s),
677
- q = v * (1 - f * s),
678
- t = v * (1 - (1 - f) * s),
679
- mod = i % 6,
680
- r = [v, q, p, p, t, v][mod],
681
- g = [t, v, v, q, p, p][mod],
682
- b = [p, p, t, v, v, q][mod];
287
+ h = bound01(h, 360) * 6, s = bound01(s, 100), v = bound01(v, 100);
288
+ 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];
683
289
  return {
684
290
  r: r * 255,
685
291
  g: g * 255,
686
292
  b: b * 255
687
293
  };
688
294
  }
689
-
690
- // `rgbToHex`
691
- // Converts an RGB color to hex
692
- // Assumes r, g, and b are contained in the set [0, 255]
693
- // Returns a 3 or 6 character hex
694
295
  function rgbToHex(r, g, b, allow3Char) {
695
296
  var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
696
-
697
- // Return a 3 character hex if possible
698
- if (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)) {
699
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
700
- }
701
- return hex.join("");
297
+ 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("");
702
298
  }
703
-
704
- // `rgbaToHex`
705
- // Converts an RGBA color plus alpha transparency to hex
706
- // Assumes r, g, b are contained in the set [0, 255] and
707
- // a in [0, 1]. Returns a 4 or 8 character rgba hex
708
299
  function rgbaToHex(r, g, b, a, allow4Char) {
709
300
  var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
710
-
711
- // Return a 4 character hex if possible
712
- if (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)) {
713
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
714
- }
715
- return hex.join("");
301
+ 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("");
716
302
  }
717
-
718
- // `rgbaToArgbHex`
719
- // Converts an RGBA color to an ARGB Hex8 string
720
- // Rarely used, but required for "toFilter()"
721
303
  function rgbaToArgbHex(r, g, b, a) {
722
304
  var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
723
305
  return hex.join("");
724
306
  }
725
-
726
- // `equals`
727
- // Can be called with any tinycolor input
728
- tinycolor.equals = function (color1, color2) {
729
- if (!color1 || !color2) return false;
730
- return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
307
+ tinycolor.equals = function(color1, color2) {
308
+ return !color1 || !color2 ? !1 : tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
731
309
  };
732
- tinycolor.random = function () {
310
+ tinycolor.random = function() {
733
311
  return tinycolor.fromRatio({
734
312
  r: Math.random(),
735
313
  g: Math.random(),
736
314
  b: Math.random()
737
315
  });
738
316
  };
739
-
740
- // Modification Functions
741
- // ----------------------
742
- // Thanks to less.js for some of the basics here
743
- // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
744
-
745
- function _desaturate(color, amount) {
317
+ function _desaturate(color2, amount) {
746
318
  amount = amount === 0 ? 0 : amount || 10;
747
- var hsl = tinycolor(color).toHsl();
748
- hsl.s -= amount / 100;
749
- hsl.s = clamp01(hsl.s);
750
- return tinycolor(hsl);
319
+ var hsl = tinycolor(color2).toHsl();
320
+ return hsl.s -= amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
751
321
  }
752
- function _saturate(color, amount) {
322
+ function _saturate(color2, amount) {
753
323
  amount = amount === 0 ? 0 : amount || 10;
754
- var hsl = tinycolor(color).toHsl();
755
- hsl.s += amount / 100;
756
- hsl.s = clamp01(hsl.s);
757
- return tinycolor(hsl);
324
+ var hsl = tinycolor(color2).toHsl();
325
+ return hsl.s += amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
758
326
  }
759
- function _greyscale(color) {
760
- return tinycolor(color).desaturate(100);
327
+ function _greyscale(color2) {
328
+ return tinycolor(color2).desaturate(100);
761
329
  }
762
- function _lighten(color, amount) {
330
+ function _lighten(color2, amount) {
763
331
  amount = amount === 0 ? 0 : amount || 10;
764
- var hsl = tinycolor(color).toHsl();
765
- hsl.l += amount / 100;
766
- hsl.l = clamp01(hsl.l);
767
- return tinycolor(hsl);
332
+ var hsl = tinycolor(color2).toHsl();
333
+ return hsl.l += amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
768
334
  }
769
- function _brighten(color, amount) {
335
+ function _brighten(color2, amount) {
770
336
  amount = amount === 0 ? 0 : amount || 10;
771
- var rgb = tinycolor(color).toRgb();
772
- rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
773
- rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
774
- rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
775
- return tinycolor(rgb);
337
+ var rgb = tinycolor(color2).toRgb();
338
+ 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);
776
339
  }
777
- function _darken(color, amount) {
340
+ function _darken(color2, amount) {
778
341
  amount = amount === 0 ? 0 : amount || 10;
779
- var hsl = tinycolor(color).toHsl();
780
- hsl.l -= amount / 100;
781
- hsl.l = clamp01(hsl.l);
782
- return tinycolor(hsl);
342
+ var hsl = tinycolor(color2).toHsl();
343
+ return hsl.l -= amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
783
344
  }
784
-
785
- // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
786
- // Values outside of this range will be wrapped into this range.
787
- function _spin(color, amount) {
788
- var hsl = tinycolor(color).toHsl();
789
- var hue = (hsl.h + amount) % 360;
790
- hsl.h = hue < 0 ? 360 + hue : hue;
791
- return tinycolor(hsl);
345
+ function _spin(color2, amount) {
346
+ var hsl = tinycolor(color2).toHsl(), hue = (hsl.h + amount) % 360;
347
+ return hsl.h = hue < 0 ? 360 + hue : hue, tinycolor(hsl);
792
348
  }
793
-
794
- // Combination Functions
795
- // ---------------------
796
- // Thanks to jQuery xColor for some of the ideas behind these
797
- // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
798
-
799
- function _complement(color) {
800
- var hsl = tinycolor(color).toHsl();
801
- hsl.h = (hsl.h + 180) % 360;
802
- return tinycolor(hsl);
349
+ function _complement(color2) {
350
+ var hsl = tinycolor(color2).toHsl();
351
+ return hsl.h = (hsl.h + 180) % 360, tinycolor(hsl);
803
352
  }
804
- function polyad(color, number) {
805
- if (isNaN(number) || number <= 0) {
353
+ function polyad(color2, number) {
354
+ if (isNaN(number) || number <= 0)
806
355
  throw new Error("Argument to polyad must be a positive number");
807
- }
808
- var hsl = tinycolor(color).toHsl();
809
- var result = [tinycolor(color)];
810
- var step = 360 / number;
811
- for (var i = 1; i < number; i++) {
356
+ for (var hsl = tinycolor(color2).toHsl(), result = [tinycolor(color2)], step = 360 / number, i = 1; i < number; i++)
812
357
  result.push(tinycolor({
813
358
  h: (hsl.h + i * step) % 360,
814
359
  s: hsl.s,
815
360
  l: hsl.l
816
361
  }));
817
- }
818
362
  return result;
819
363
  }
820
- function _splitcomplement(color) {
821
- var hsl = tinycolor(color).toHsl();
822
- var h = hsl.h;
823
- return [tinycolor(color), tinycolor({
364
+ function _splitcomplement(color2) {
365
+ var hsl = tinycolor(color2).toHsl(), h = hsl.h;
366
+ return [tinycolor(color2), tinycolor({
824
367
  h: (h + 72) % 360,
825
368
  s: hsl.s,
826
369
  l: hsl.l
@@ -830,46 +373,26 @@ function _splitcomplement(color) {
830
373
  l: hsl.l
831
374
  })];
832
375
  }
833
- function _analogous(color, results, slices) {
834
- results = results || 6;
835
- slices = slices || 30;
836
- var hsl = tinycolor(color).toHsl();
837
- var part = 360 / slices;
838
- var ret = [tinycolor(color)];
839
- for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
840
- hsl.h = (hsl.h + part) % 360;
841
- ret.push(tinycolor(hsl));
842
- }
376
+ function _analogous(color2, results, slices) {
377
+ results = results || 6, slices = slices || 30;
378
+ var hsl = tinycolor(color2).toHsl(), part = 360 / slices, ret = [tinycolor(color2)];
379
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; )
380
+ hsl.h = (hsl.h + part) % 360, ret.push(tinycolor(hsl));
843
381
  return ret;
844
382
  }
845
- function _monochromatic(color, results) {
383
+ function _monochromatic(color2, results) {
846
384
  results = results || 6;
847
- var hsv = tinycolor(color).toHsv();
848
- var h = hsv.h,
849
- s = hsv.s,
850
- v = hsv.v;
851
- var ret = [];
852
- var modification = 1 / results;
853
- while (results--) {
385
+ for (var hsv = tinycolor(color2).toHsv(), h = hsv.h, s = hsv.s, v = hsv.v, ret = [], modification = 1 / results; results--; )
854
386
  ret.push(tinycolor({
855
- h: h,
856
- s: s,
857
- v: v
858
- }));
859
- v = (v + modification) % 1;
860
- }
387
+ h,
388
+ s,
389
+ v
390
+ })), v = (v + modification) % 1;
861
391
  return ret;
862
392
  }
863
-
864
- // Utility Functions
865
- // ---------------------
866
-
867
- tinycolor.mix = function (color1, color2, amount) {
393
+ tinycolor.mix = function(color1, color2, amount) {
868
394
  amount = amount === 0 ? 0 : amount || 50;
869
- var rgb1 = tinycolor(color1).toRgb();
870
- var rgb2 = tinycolor(color2).toRgb();
871
- var p = amount / 100;
872
- var rgba = {
395
+ var rgb1 = tinycolor(color1).toRgb(), rgb2 = tinycolor(color2).toRgb(), p = amount / 100, rgba = {
873
396
  r: (rgb2.r - rgb1.r) * p + rgb1.r,
874
397
  g: (rgb2.g - rgb1.g) * p + rgb1.g,
875
398
  b: (rgb2.b - rgb1.b) * p + rgb1.b,
@@ -877,35 +400,13 @@ tinycolor.mix = function (color1, color2, amount) {
877
400
  };
878
401
  return tinycolor(rgba);
879
402
  };
880
-
881
- // Readability Functions
882
- // ---------------------
883
- // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
884
-
885
- // `contrast`
886
- // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
887
- tinycolor.readability = function (color1, color2) {
888
- var c1 = tinycolor(color1);
889
- var c2 = tinycolor(color2);
403
+ tinycolor.readability = function(color1, color2) {
404
+ var c1 = tinycolor(color1), c2 = tinycolor(color2);
890
405
  return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
891
406
  };
892
-
893
- // `isReadable`
894
- // Ensure that foreground and background color combinations meet WCAG2 guidelines.
895
- // The third argument is an optional Object.
896
- // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
897
- // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
898
- // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
899
-
900
- // *Example*
901
- // tinycolor.isReadable("#000", "#111") => false
902
- // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
903
- tinycolor.isReadable = function (color1, color2, wcag2) {
904
- var readability = tinycolor.readability(color1, color2);
905
- var wcag2Parms, out;
906
- out = false;
907
- wcag2Parms = validateWCAG2Parms(wcag2);
908
- switch (wcag2Parms.level + wcag2Parms.size) {
407
+ tinycolor.isReadable = function(color1, color2, wcag2) {
408
+ var readability = tinycolor.readability(color1, color2), wcag2Parms, out;
409
+ switch (out = !1, wcag2Parms = validateWCAG2Parms(wcag2), wcag2Parms.level + wcag2Parms.size) {
909
410
  case "AAsmall":
910
411
  case "AAAlarge":
911
412
  out = readability >= 4.5;
@@ -919,46 +420,16 @@ tinycolor.isReadable = function (color1, color2, wcag2) {
919
420
  }
920
421
  return out;
921
422
  };
922
-
923
- // `mostReadable`
924
- // Given a base color and a list of possible foreground or background
925
- // colors for that base, returns the most readable color.
926
- // Optionally returns Black or White if the most readable color is unreadable.
927
- // *Example*
928
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
929
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
930
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
931
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
932
- tinycolor.mostReadable = function (baseColor, colorList, args) {
933
- var bestColor = null;
934
- var bestScore = 0;
935
- var readability;
936
- var includeFallbackColors, level, size;
937
- args = args || {};
938
- includeFallbackColors = args.includeFallbackColors;
939
- level = args.level;
940
- size = args.size;
941
- for (var i = 0; i < colorList.length; i++) {
942
- readability = tinycolor.readability(baseColor, colorList[i]);
943
- if (readability > bestScore) {
944
- bestScore = readability;
945
- bestColor = tinycolor(colorList[i]);
946
- }
947
- }
948
- if (tinycolor.isReadable(baseColor, bestColor, {
949
- level: level,
950
- size: size
951
- }) || !includeFallbackColors) {
952
- return bestColor;
953
- } else {
954
- args.includeFallbackColors = false;
955
- return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
956
- }
423
+ tinycolor.mostReadable = function(baseColor, colorList, args) {
424
+ var bestColor = null, bestScore = 0, readability, includeFallbackColors, level, size;
425
+ args = args || {}, includeFallbackColors = args.includeFallbackColors, level = args.level, size = args.size;
426
+ for (var i = 0; i < colorList.length; i++)
427
+ readability = tinycolor.readability(baseColor, colorList[i]), readability > bestScore && (bestScore = readability, bestColor = tinycolor(colorList[i]));
428
+ return tinycolor.isReadable(baseColor, bestColor, {
429
+ level,
430
+ size
431
+ }) || !includeFallbackColors ? bestColor : (args.includeFallbackColors = !1, tinycolor.mostReadable(baseColor, ["#fff", "#000"], args));
957
432
  };
958
-
959
- // Big List of Colors
960
- // ------------------
961
- // <https://www.w3.org/TR/css-color-4/#named-colors>
962
433
  var names = tinycolor.names = {
963
434
  aliceblue: "f0f8ff",
964
435
  antiquewhite: "faebd7",
@@ -1109,111 +580,47 @@ var names = tinycolor.names = {
1109
580
  whitesmoke: "f5f5f5",
1110
581
  yellow: "ff0",
1111
582
  yellowgreen: "9acd32"
1112
- };
1113
-
1114
- // Make it easy to access colors via `hexNames[hex]`
1115
- var hexNames = tinycolor.hexNames = flip(names);
1116
-
1117
- // Utilities
1118
- // ---------
1119
-
1120
- // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
583
+ }, hexNames = tinycolor.hexNames = flip(names);
1121
584
  function flip(o) {
1122
585
  var flipped = {};
1123
- for (var i in o) {
1124
- if (o.hasOwnProperty(i)) {
1125
- flipped[o[i]] = i;
1126
- }
1127
- }
586
+ for (var i in o)
587
+ o.hasOwnProperty(i) && (flipped[o[i]] = i);
1128
588
  return flipped;
1129
589
  }
1130
-
1131
- // Return a valid alpha value [0,1] with all invalid values being set to 1
1132
590
  function boundAlpha(a) {
1133
- a = parseFloat(a);
1134
- if (isNaN(a) || a < 0 || a > 1) {
1135
- a = 1;
1136
- }
1137
- return a;
591
+ return a = parseFloat(a), (isNaN(a) || a < 0 || a > 1) && (a = 1), a;
1138
592
  }
1139
-
1140
- // Take input from [0, n] and return it as [0, 1]
1141
593
  function bound01(n, max) {
1142
- if (isOnePointZero(n)) n = "100%";
594
+ isOnePointZero(n) && (n = "100%");
1143
595
  var processPercent = isPercentage(n);
1144
- n = Math.min(max, Math.max(0, parseFloat(n)));
1145
-
1146
- // Automatically convert percentage into number
1147
- if (processPercent) {
1148
- n = parseInt(n * max, 10) / 100;
1149
- }
1150
-
1151
- // Handle floating point rounding errors
1152
- if (Math.abs(n - max) < 0.000001) {
1153
- return 1;
1154
- }
1155
-
1156
- // Convert into [0, 1] range if it isn't already
1157
- return n % max / parseFloat(max);
596
+ 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);
1158
597
  }
1159
-
1160
- // Force a number between 0 and 1
1161
598
  function clamp01(val) {
1162
599
  return Math.min(1, Math.max(0, val));
1163
600
  }
1164
-
1165
- // Parse a base-16 hex value into a base-10 integer
1166
601
  function parseIntFromHex(val) {
1167
602
  return parseInt(val, 16);
1168
603
  }
1169
-
1170
- // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
1171
- // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
1172
604
  function isOnePointZero(n) {
1173
605
  return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
1174
606
  }
1175
-
1176
- // Check to see if string passed in is a percentage
1177
607
  function isPercentage(n) {
1178
- return typeof n === "string" && n.indexOf("%") != -1;
608
+ return typeof n == "string" && n.indexOf("%") != -1;
1179
609
  }
1180
-
1181
- // Force a hex value to have 2 characters
1182
610
  function pad2(c) {
1183
611
  return c.length == 1 ? "0" + c : "" + c;
1184
612
  }
1185
-
1186
- // Replace a decimal with it's percentage value
1187
613
  function convertToPercentage(n) {
1188
- if (n <= 1) {
1189
- n = n * 100 + "%";
1190
- }
1191
- return n;
614
+ return n <= 1 && (n = n * 100 + "%"), n;
1192
615
  }
1193
-
1194
- // Converts a decimal to a hex value
1195
616
  function convertDecimalToHex(d) {
1196
617
  return Math.round(parseFloat(d) * 255).toString(16);
1197
618
  }
1198
- // Converts a hex value to a decimal
1199
619
  function convertHexToDecimal(h) {
1200
620
  return parseIntFromHex(h) / 255;
1201
621
  }
1202
- var matchers = function () {
1203
- // <http://www.w3.org/TR/css3-values/#integers>
1204
- var CSS_INTEGER = "[-\\+]?\\d+%?";
1205
-
1206
- // <http://www.w3.org/TR/css3-values/#number-value>
1207
- var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
1208
-
1209
- // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
1210
- var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
1211
-
1212
- // Actual matching.
1213
- // Parentheses and commas are optional, but not required.
1214
- // Whitespace can take the place of commas or opening paren
1215
- var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1216
- var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
622
+ var matchers = function() {
623
+ 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*\\)?";
1217
624
  return {
1218
625
  CSS_UNIT: new RegExp(CSS_UNIT),
1219
626
  rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
@@ -1228,24 +635,15 @@ var matchers = function () {
1228
635
  hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1229
636
  };
1230
637
  }();
1231
-
1232
- // `isValidCSSUnit`
1233
- // Take in a single string / number and check to see if it looks like a CSS unit
1234
- // (see `matchers` above for definition).
1235
- function isValidCSSUnit(color) {
1236
- return !!matchers.CSS_UNIT.exec(color);
638
+ function isValidCSSUnit(color2) {
639
+ return !!matchers.CSS_UNIT.exec(color2);
1237
640
  }
1238
-
1239
- // `stringInputToObject`
1240
- // Permissive string parsing. Take in a number of formats, and output an object
1241
- // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
1242
- function stringInputToObject(color) {
1243
- color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
1244
- var named = false;
1245
- if (names[color]) {
1246
- color = names[color];
1247
- named = true;
1248
- } else if (color == "transparent") {
641
+ function stringInputToObject(color2) {
642
+ color2 = color2.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
643
+ var named = !1;
644
+ if (names[color2])
645
+ color2 = names[color2], named = !0;
646
+ else if (color2 == "transparent")
1249
647
  return {
1250
648
  r: 0,
1251
649
  g: 0,
@@ -1253,421 +651,421 @@ function stringInputToObject(color) {
1253
651
  a: 0,
1254
652
  format: "name"
1255
653
  };
1256
- }
1257
-
1258
- // Try to match string input using regular expressions.
1259
- // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1260
- // Just return an object and let the conversion functions handle that.
1261
- // This way the result will be the same whether the tinycolor is initialized with string or object.
1262
654
  var match;
1263
- if (match = matchers.rgb.exec(color)) {
1264
- return {
1265
- r: match[1],
1266
- g: match[2],
1267
- b: match[3]
1268
- };
1269
- }
1270
- if (match = matchers.rgba.exec(color)) {
1271
- return {
1272
- r: match[1],
1273
- g: match[2],
1274
- b: match[3],
1275
- a: match[4]
1276
- };
1277
- }
1278
- if (match = matchers.hsl.exec(color)) {
1279
- return {
1280
- h: match[1],
1281
- s: match[2],
1282
- l: match[3]
1283
- };
1284
- }
1285
- if (match = matchers.hsla.exec(color)) {
1286
- return {
1287
- h: match[1],
1288
- s: match[2],
1289
- l: match[3],
1290
- a: match[4]
1291
- };
1292
- }
1293
- if (match = matchers.hsv.exec(color)) {
1294
- return {
1295
- h: match[1],
1296
- s: match[2],
1297
- v: match[3]
1298
- };
1299
- }
1300
- if (match = matchers.hsva.exec(color)) {
1301
- return {
1302
- h: match[1],
1303
- s: match[2],
1304
- v: match[3],
1305
- a: match[4]
1306
- };
1307
- }
1308
- if (match = matchers.hex8.exec(color)) {
1309
- return {
1310
- r: parseIntFromHex(match[1]),
1311
- g: parseIntFromHex(match[2]),
1312
- b: parseIntFromHex(match[3]),
1313
- a: convertHexToDecimal(match[4]),
1314
- format: named ? "name" : "hex8"
1315
- };
1316
- }
1317
- if (match = matchers.hex6.exec(color)) {
1318
- return {
1319
- r: parseIntFromHex(match[1]),
1320
- g: parseIntFromHex(match[2]),
1321
- b: parseIntFromHex(match[3]),
1322
- format: named ? "name" : "hex"
1323
- };
1324
- }
1325
- if (match = matchers.hex4.exec(color)) {
1326
- return {
1327
- r: parseIntFromHex(match[1] + "" + match[1]),
1328
- g: parseIntFromHex(match[2] + "" + match[2]),
1329
- b: parseIntFromHex(match[3] + "" + match[3]),
1330
- a: convertHexToDecimal(match[4] + "" + match[4]),
1331
- format: named ? "name" : "hex8"
1332
- };
1333
- }
1334
- if (match = matchers.hex3.exec(color)) {
1335
- return {
1336
- r: parseIntFromHex(match[1] + "" + match[1]),
1337
- g: parseIntFromHex(match[2] + "" + match[2]),
1338
- b: parseIntFromHex(match[3] + "" + match[3]),
1339
- format: named ? "name" : "hex"
1340
- };
1341
- }
1342
- return false;
655
+ return (match = matchers.rgb.exec(color2)) ? {
656
+ r: match[1],
657
+ g: match[2],
658
+ b: match[3]
659
+ } : (match = matchers.rgba.exec(color2)) ? {
660
+ r: match[1],
661
+ g: match[2],
662
+ b: match[3],
663
+ a: match[4]
664
+ } : (match = matchers.hsl.exec(color2)) ? {
665
+ h: match[1],
666
+ s: match[2],
667
+ l: match[3]
668
+ } : (match = matchers.hsla.exec(color2)) ? {
669
+ h: match[1],
670
+ s: match[2],
671
+ l: match[3],
672
+ a: match[4]
673
+ } : (match = matchers.hsv.exec(color2)) ? {
674
+ h: match[1],
675
+ s: match[2],
676
+ v: match[3]
677
+ } : (match = matchers.hsva.exec(color2)) ? {
678
+ h: match[1],
679
+ s: match[2],
680
+ v: match[3],
681
+ a: match[4]
682
+ } : (match = matchers.hex8.exec(color2)) ? {
683
+ r: parseIntFromHex(match[1]),
684
+ g: parseIntFromHex(match[2]),
685
+ b: parseIntFromHex(match[3]),
686
+ a: convertHexToDecimal(match[4]),
687
+ format: named ? "name" : "hex8"
688
+ } : (match = matchers.hex6.exec(color2)) ? {
689
+ r: parseIntFromHex(match[1]),
690
+ g: parseIntFromHex(match[2]),
691
+ b: parseIntFromHex(match[3]),
692
+ format: named ? "name" : "hex"
693
+ } : (match = matchers.hex4.exec(color2)) ? {
694
+ r: parseIntFromHex(match[1] + "" + match[1]),
695
+ g: parseIntFromHex(match[2] + "" + match[2]),
696
+ b: parseIntFromHex(match[3] + "" + match[3]),
697
+ a: convertHexToDecimal(match[4] + "" + match[4]),
698
+ format: named ? "name" : "hex8"
699
+ } : (match = matchers.hex3.exec(color2)) ? {
700
+ r: parseIntFromHex(match[1] + "" + match[1]),
701
+ g: parseIntFromHex(match[2] + "" + match[2]),
702
+ b: parseIntFromHex(match[3] + "" + match[3]),
703
+ format: named ? "name" : "hex"
704
+ } : !1;
1343
705
  }
1344
706
  function validateWCAG2Parms(parms) {
1345
- // return valid WCAG2 parms for isReadable.
1346
- // If input parms are invalid, return {"level":"AA", "size":"small"}
1347
707
  var level, size;
1348
- parms = parms || {
708
+ return parms = parms || {
1349
709
  level: "AA",
1350
710
  size: "small"
1351
- };
1352
- level = (parms.level || "AA").toUpperCase();
1353
- size = (parms.size || "small").toLowerCase();
1354
- if (level !== "AA" && level !== "AAA") {
1355
- level = "AA";
1356
- }
1357
- if (size !== "small" && size !== "large") {
1358
- size = "small";
1359
- }
1360
- return {
1361
- level: level,
1362
- size: size
711
+ }, level = (parms.level || "AA").toUpperCase(), size = (parms.size || "small").toLowerCase(), level !== "AA" && level !== "AAA" && (level = "AA"), size !== "small" && size !== "large" && (size = "small"), {
712
+ level,
713
+ size
1363
714
  };
1364
715
  }
1365
- var __freeze$1 = Object.freeze;
1366
- var __defProp$1 = Object.defineProperty;
1367
- var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
1368
- value: __freeze$1(raw || cooked.slice())
1369
- }));
1370
- var _a$1, _b$1, _c;
1371
- const ColorListWrap = styled__default.default(ui.Flex)(_a$1 || (_a$1 = __template$1(["\n gap: 0.25em;\n"])));
1372
- const ColorBoxContainer = styled__default.default.div(_b$1 || (_b$1 = __template$1(["\n width: 2.1em;\n height: 2.1em;\n cursor: pointer;\n position: relative;\n overflow: hidden;\n border-radius: 3px;\n background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=') left center #fff;\n"])));
1373
- const ColorBox$1 = styled__default.default.div(_c || (_c = __template$1(["\n border-radius: inherit;\n box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);\n content: '';\n position: absolute;\n inset: 0;\n z-index: 1;\n"])));
1374
- const validateColors = colors => colors.reduce((cls, c) => {
1375
- const color = c.hex ? tinycolor(c.hex) : tinycolor(c);
1376
- if (color.isValid()) {
1377
- cls.push({
1378
- color: c,
1379
- backgroundColor: color.toRgbString()
1380
- });
1381
- }
1382
- return cls;
1383
- }, []);
1384
- const ColorList = _ref2 => {
1385
- let {
1386
- colors,
1387
- onChange
1388
- } = _ref2;
1389
- if (!colors) return null;
1390
- return /* @__PURE__ */jsxRuntime.jsx(ColorListWrap, {
1391
- wrap: "wrap",
1392
- children: validateColors(colors).map((_ref3, idx) => {
1393
- let {
1394
- color,
1395
- backgroundColor
1396
- } = _ref3;
1397
- return /* @__PURE__ */jsxRuntime.jsx(ColorBoxContainer, {
1398
- onClick: () => {
1399
- onChange(color);
1400
- },
1401
- children: /* @__PURE__ */jsxRuntime.jsx(ColorBox$1, {
1402
- style: {
1403
- background: backgroundColor
1404
- }
1405
- })
1406
- }, "".concat(backgroundColor, "-").concat(idx));
1407
- })
1408
- });
1409
- };
1410
- var __freeze = Object.freeze;
1411
- var __defProp = Object.defineProperty;
1412
- var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
1413
- value: __freeze(raw || cooked.slice())
1414
- }));
1415
- var _a, _b;
1416
- const ColorBox = styled__default.default(ui.Box)(_a || (_a = __template(["\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n"])));
1417
- const ReadOnlyContainer = styled__default.default(ui.Flex)(_b || (_b = __template(["\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n"])));
1418
- const ColorPickerInner = props => {
1419
- var _a2, _b2, _c;
716
+ const ColorListWrap = styledComponents.styled(ui.Flex)`
717
+ gap: 0.25em;
718
+ `, ColorBoxContainer = styledComponents.styled.div`
719
+ width: 2.1em;
720
+ height: 2.1em;
721
+ cursor: pointer;
722
+ position: relative;
723
+ overflow: hidden;
724
+ border-radius: 3px;
725
+ background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')
726
+ left center #fff;
727
+ `, ColorBox$1 = styledComponents.styled.div`
728
+ border-radius: inherit;
729
+ box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);
730
+ content: '';
731
+ position: absolute;
732
+ inset: 0;
733
+ z-index: 1;
734
+ `, validateColors = (colors) => colors.reduce((cls, c) => {
735
+ const color2 = c.hex ? tinycolor(c.hex) : tinycolor(c);
736
+ return color2.isValid() && cls.push({
737
+ color: c,
738
+ backgroundColor: color2.toRgbString()
739
+ }), cls;
740
+ }, []), ColorList = react.memo(function({ colors, onChange }) {
741
+ return colors ? /* @__PURE__ */ jsxRuntime.jsx(ColorListWrap, { wrap: "wrap", children: validateColors(colors).map(({ color: color2, backgroundColor }, idx) => /* @__PURE__ */ jsxRuntime.jsx(
742
+ ColorBoxContainer,
743
+ {
744
+ onClick: () => {
745
+ onChange(color2);
746
+ },
747
+ children: /* @__PURE__ */ jsxRuntime.jsx(ColorBox$1, { style: { background: backgroundColor } })
748
+ },
749
+ `${backgroundColor}-${idx}`
750
+ )) }) : null;
751
+ }), ColorPickerFields = ({
752
+ onChange,
753
+ rgb,
754
+ hsl,
755
+ hex,
756
+ disableAlpha
757
+ }) => {
758
+ const { sanity: sanity2 } = ui.useTheme(), inputStyles = react.useMemo(
759
+ () => ({
760
+ input: {
761
+ width: "80%",
762
+ padding: "4px 10% 3px",
763
+ border: "none",
764
+ boxShadow: `inset 0 0 0 1px ${sanity2.color.input.default.enabled.border}`,
765
+ color: sanity2.color.input.default.enabled.fg,
766
+ backgroundColor: sanity2.color.input.default.enabled.bg,
767
+ fontSize: sanity2.fonts.text.sizes[0].fontSize,
768
+ textAlign: "center"
769
+ },
770
+ label: {
771
+ display: "block",
772
+ textAlign: "center",
773
+ fontSize: sanity2.fonts.label.sizes[0].fontSize,
774
+ color: sanity2.color.base.fg,
775
+ paddingTop: "3px",
776
+ paddingBottom: "4px",
777
+ textTransform: "capitalize"
778
+ }
779
+ }),
780
+ [sanity2]
781
+ ), handleChange = react.useCallback(
782
+ (data) => {
783
+ if ("hex" in data && data.hex && color$1.isValidHex(data.hex))
784
+ onChange({
785
+ hex: data.hex,
786
+ source: "hex"
787
+ });
788
+ else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b))
789
+ onChange({
790
+ r: Number(data.r) || rgb.r,
791
+ g: Number(data.g) || rgb.g,
792
+ b: Number(data.b) || rgb.b,
793
+ a: rgb.a,
794
+ source: "rgb"
795
+ });
796
+ else if (hsl && "a" in data && data.a) {
797
+ let alpha = Number(data.a);
798
+ alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha /= 100, onChange({
799
+ h: hsl.h,
800
+ s: hsl.s,
801
+ l: hsl.l,
802
+ a: alpha,
803
+ source: "hsl"
804
+ });
805
+ }
806
+ },
807
+ [onChange, hsl, rgb]
808
+ );
809
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
810
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 2, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
811
+ common.EditableInput,
812
+ {
813
+ style: inputStyles,
814
+ label: "hex",
815
+ value: hex?.replace("#", ""),
816
+ onChange: handleChange
817
+ }
818
+ ) }),
819
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
820
+ common.EditableInput,
821
+ {
822
+ style: inputStyles,
823
+ label: "r",
824
+ value: rgb?.r,
825
+ onChange: handleChange,
826
+ dragLabel: !0,
827
+ dragMax: 255
828
+ }
829
+ ) }),
830
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
831
+ common.EditableInput,
832
+ {
833
+ style: inputStyles,
834
+ label: "g",
835
+ value: rgb?.g,
836
+ onChange: handleChange,
837
+ dragLabel: !0,
838
+ dragMax: 255
839
+ }
840
+ ) }),
841
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
842
+ common.EditableInput,
843
+ {
844
+ style: inputStyles,
845
+ label: "b",
846
+ value: rgb?.b,
847
+ onChange: handleChange,
848
+ dragLabel: !0,
849
+ dragMax: 255
850
+ }
851
+ ) }),
852
+ !disableAlpha && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
853
+ common.EditableInput,
854
+ {
855
+ style: inputStyles,
856
+ label: "a",
857
+ value: Math.round((rgb?.a ?? 1) * 100),
858
+ onChange: handleChange,
859
+ dragLabel: !0,
860
+ dragMax: 100
861
+ }
862
+ ) })
863
+ ] });
864
+ }, ColorBox = styledComponents.styled(ui.Box)`
865
+ position: absolute;
866
+ top: 0;
867
+ left: 0;
868
+ width: 100%;
869
+ height: 100%;
870
+ `, ReadOnlyContainer = styledComponents.styled(ui.Flex)`
871
+ margin-top: 6rem;
872
+ background-color: var(--card-bg-color);
873
+ position: relative;
874
+ width: 100%;
875
+ `, ColorPickerInner = (props) => {
1420
876
  const {
1421
877
  width,
1422
- color: {
1423
- rgb,
1424
- hex,
1425
- hsv,
1426
- hsl
1427
- },
878
+ color: { rgb, hex, hsv, hsl },
1428
879
  onChange,
1429
880
  onUnset,
1430
881
  disableAlpha,
1431
882
  colorList,
1432
883
  readOnly
1433
884
  } = props;
1434
- if (!hsl || !hsv) {
1435
- return null;
1436
- }
1437
- return /* @__PURE__ */jsxRuntime.jsx("div", {
1438
- style: {
1439
- width
1440
- },
1441
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
1442
- padding: 1,
1443
- border: true,
1444
- radius: 1,
1445
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
1446
- space: 2,
1447
- children: [!readOnly && /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
1448
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
1449
- overflow: "hidden",
1450
- style: {
1451
- position: "relative",
1452
- height: "5em"
1453
- },
1454
- children: /* @__PURE__ */jsxRuntime.jsx(common.Saturation, {
1455
- onChange,
1456
- hsl,
1457
- hsv
1458
- })
1459
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
1460
- shadow: 1,
1461
- radius: 3,
1462
- overflow: "hidden",
1463
- style: {
1464
- position: "relative",
1465
- height: "10px"
1466
- },
1467
- children: /* @__PURE__ */jsxRuntime.jsx(common.Hue, {
1468
- hsl,
1469
- onChange: !readOnly && onChange
1470
- })
1471
- }), !disableAlpha && /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
1472
- shadow: 1,
1473
- radius: 3,
1474
- overflow: "hidden",
1475
- style: {
1476
- position: "relative",
1477
- height: "10px",
1478
- background: "#fff"
1479
- },
1480
- children: /* @__PURE__ */jsxRuntime.jsx(common.Alpha, {
1481
- rgb,
1482
- hsl,
1483
- onChange
1484
- })
1485
- })]
1486
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
1487
- children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Card, {
1488
- flex: 1,
1489
- radius: 2,
1490
- overflow: "hidden",
1491
- style: {
1492
- position: "relative",
1493
- minWidth: "4em",
1494
- background: "#fff"
1495
- },
1496
- children: [/* @__PURE__ */jsxRuntime.jsx(common.Checkboard, {}), /* @__PURE__ */jsxRuntime.jsx(ColorBox, {
1497
- style: {
1498
- backgroundColor: "rgba(".concat(rgb == null ? void 0 : rgb.r, ",").concat(rgb == null ? void 0 : rgb.g, ",").concat(rgb == null ? void 0 : rgb.b, ",").concat(rgb == null ? void 0 : rgb.a, ")")
885
+ return !hsl || !hsv ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 1, border: !0, radius: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
886
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
887
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { overflow: "hidden", style: { position: "relative", height: "5em" }, children: /* @__PURE__ */ jsxRuntime.jsx(common.Saturation, { onChange, hsl, hsv }) }),
888
+ /* @__PURE__ */ jsxRuntime.jsx(
889
+ ui.Card,
890
+ {
891
+ shadow: 1,
892
+ radius: 3,
893
+ overflow: "hidden",
894
+ style: { position: "relative", height: "10px" },
895
+ children: /* @__PURE__ */ jsxRuntime.jsx(common.Hue, { hsl, onChange: !readOnly && onChange })
896
+ }
897
+ ),
898
+ !disableAlpha && /* @__PURE__ */ jsxRuntime.jsx(
899
+ ui.Card,
900
+ {
901
+ shadow: 1,
902
+ radius: 3,
903
+ overflow: "hidden",
904
+ style: { position: "relative", height: "10px", background: "#fff" },
905
+ children: /* @__PURE__ */ jsxRuntime.jsx(common.Alpha, { rgb, hsl, onChange })
906
+ }
907
+ )
908
+ ] }),
909
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
910
+ /* @__PURE__ */ jsxRuntime.jsxs(
911
+ ui.Card,
912
+ {
913
+ flex: 1,
914
+ radius: 2,
915
+ overflow: "hidden",
916
+ style: { position: "relative", minWidth: "4em", background: "#fff" },
917
+ children: [
918
+ /* @__PURE__ */ jsxRuntime.jsx(common.Checkboard, {}),
919
+ /* @__PURE__ */ jsxRuntime.jsx(
920
+ ColorBox,
921
+ {
922
+ style: {
923
+ backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`
924
+ }
1499
925
  }
1500
- }), readOnly && /* @__PURE__ */jsxRuntime.jsx(ReadOnlyContainer, {
1501
- padding: 2,
1502
- paddingBottom: 1,
1503
- sizing: "border",
1504
- justify: "space-between",
1505
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
1506
- space: 3,
1507
- marginTop: 1,
1508
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
1509
- size: 3,
1510
- weight: "bold",
1511
- children: hex
1512
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Inline, {
1513
- space: 3,
1514
- children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
1515
- size: 1,
1516
- children: [/* @__PURE__ */jsxRuntime.jsx("strong", {
1517
- children: "RGB: "
1518
- }), rgb == null ? void 0 : rgb.r, " ", rgb == null ? void 0 : rgb.g, " ", rgb == null ? void 0 : rgb.b]
1519
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
1520
- size: 1,
1521
- children: [/* @__PURE__ */jsxRuntime.jsx("strong", {
1522
- children: "HSL: "
1523
- }), " ", Math.round((_a2 = hsl == null ? void 0 : hsl.h) != null ? _a2 : 0), " ", Math.round(((_b2 = hsl == null ? void 0 : hsl.s) != null ? _b2 : 0) * 100), "% ", Math.round(((_c = hsl == null ? void 0 : hsl.l) != null ? _c : 0) * 100), "%"]
1524
- })]
1525
- })]
1526
- })
1527
- })]
1528
- }), !readOnly && /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
1529
- align: "flex-start",
1530
- marginLeft: 2,
1531
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
1532
- style: {
1533
- width: 200
1534
- },
1535
- children: /* @__PURE__ */jsxRuntime.jsx(ColorPickerFields, {
1536
- rgb,
1537
- hsl,
1538
- hex,
1539
- onChange,
1540
- disableAlpha
1541
- })
1542
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
1543
- marginLeft: 2,
1544
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
1545
- onClick: onUnset,
1546
- title: "Delete color",
1547
- icon: icons.TrashIcon,
1548
- tone: "critical"
1549
- })
1550
- })]
1551
- })]
1552
- }), colorList && /* @__PURE__ */jsxRuntime.jsx(ColorList, {
1553
- colors: colorList,
1554
- onChange
1555
- })]
1556
- })
1557
- })
1558
- });
1559
- };
1560
- const ColorPicker = reactColor.CustomPicker(ColorPickerInner);
1561
- const DEFAULT_COLOR = {
926
+ ),
927
+ readOnly && /* @__PURE__ */ jsxRuntime.jsx(
928
+ ReadOnlyContainer,
929
+ {
930
+ padding: 2,
931
+ paddingBottom: 1,
932
+ sizing: "border",
933
+ justify: "space-between",
934
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, marginTop: 1, children: [
935
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 3, weight: "bold", children: hex }),
936
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Inline, { space: 3, children: [
937
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
938
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "RGB: " }),
939
+ rgb?.r,
940
+ " ",
941
+ rgb?.g,
942
+ " ",
943
+ rgb?.b
944
+ ] }),
945
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
946
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "HSL: " }),
947
+ " ",
948
+ Math.round(hsl?.h ?? 0),
949
+ " ",
950
+ Math.round((hsl?.s ?? 0) * 100),
951
+ "% ",
952
+ Math.round((hsl?.l ?? 0) * 100),
953
+ "%"
954
+ ] })
955
+ ] })
956
+ ] })
957
+ }
958
+ )
959
+ ]
960
+ }
961
+ ),
962
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "flex-start", marginLeft: 2, children: [
963
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { width: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx(
964
+ ColorPickerFields,
965
+ {
966
+ rgb,
967
+ hsl,
968
+ hex,
969
+ onChange,
970
+ disableAlpha
971
+ }
972
+ ) }),
973
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginLeft: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: onUnset, title: "Delete color", icon: icons.TrashIcon, tone: "critical" }) })
974
+ ] })
975
+ ] }),
976
+ colorList && /* @__PURE__ */ jsxRuntime.jsx(ColorList, { colors: colorList, onChange })
977
+ ] }) }) });
978
+ }, ColorPicker = reactColor.CustomPicker(ColorPickerInner), DEFAULT_COLOR = {
1562
979
  hex: "#24a3e3",
1563
- hsl: {
1564
- h: 200,
1565
- s: 0.7732,
1566
- l: 0.5156,
1567
- a: 1
1568
- },
1569
- hsv: {
1570
- h: 200,
1571
- s: 0.8414,
1572
- v: 0.8901,
1573
- a: 1
1574
- },
1575
- rgb: {
1576
- r: 46,
1577
- g: 163,
1578
- b: 227,
1579
- a: 1
1580
- },
980
+ hsl: { h: 200, s: 0.7732, l: 0.5156, a: 1 },
981
+ hsv: { h: 200, s: 0.8414, v: 0.8901, a: 1 },
982
+ rgb: { r: 46, g: 163, b: 227, a: 1 },
1581
983
  source: "hex"
1582
984
  };
1583
985
  function ColorInput(props) {
1584
- var _a, _b;
1585
- const {
1586
- onChange,
1587
- readOnly
1588
- } = props;
1589
- const value = props.value;
1590
- const type = props.schemaType;
1591
- const focusRef = react.useRef(null);
1592
- const [color, setColor] = react.useState(value);
986
+ const { onChange, readOnly } = props, value = props.value, type = props.schemaType, focusRef = react.useRef(null), [color2, setColor] = react.useState(value);
1593
987
  react.useEffect(() => setColor(value), [value]);
1594
- const emitSetColor = react.useCallback(nextColor => {
1595
- var _a2;
1596
- const fieldPatches = type.fields.filter(field => field.name in nextColor).map(field => {
1597
- const nextFieldValue = nextColor[field.name];
1598
- const isObject = field.type.jsonType === "object";
1599
- return sanity.set(isObject ? Object.assign({
1600
- _type: field.type.name
1601
- }, nextFieldValue) : nextFieldValue, [field.name]);
1602
- });
1603
- onChange([sanity.setIfMissing({
1604
- _type: type.name
1605
- }), sanity.set(type.name, ["_type"]), sanity.set((_a2 = nextColor.rgb) == null ? void 0 : _a2.a, ["alpha"]), ...fieldPatches]);
1606
- }, [onChange, type]);
1607
- const debouncedColorChange = react.useMemo(() => lodash.debounce(emitSetColor, 100), [emitSetColor]);
1608
- const handleColorChange = react.useCallback(nextColor => {
1609
- setColor(nextColor);
1610
- debouncedColorChange(nextColor);
1611
- }, [debouncedColorChange, setColor]);
1612
- const handleCreateColor = react.useCallback(() => {
1613
- setColor(DEFAULT_COLOR);
1614
- emitSetColor(DEFAULT_COLOR);
1615
- }, [emitSetColor]);
1616
- const handleUnset = react.useCallback(() => {
1617
- setColor(void 0);
1618
- onChange(sanity.unset());
988
+ const emitSetColor = react.useCallback(
989
+ (nextColor) => {
990
+ const fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field) => {
991
+ const nextFieldValue = nextColor[field.name], isObject = field.type.jsonType === "object";
992
+ return sanity.set(
993
+ isObject ? Object.assign({ _type: field.type.name }, nextFieldValue) : nextFieldValue,
994
+ [field.name]
995
+ );
996
+ });
997
+ onChange([
998
+ sanity.setIfMissing({ _type: type.name }),
999
+ sanity.set(type.name, ["_type"]),
1000
+ sanity.set(nextColor.rgb?.a, ["alpha"]),
1001
+ ...fieldPatches
1002
+ ]);
1003
+ },
1004
+ [onChange, type]
1005
+ ), debouncedColorChange = react.useMemo(() => debounce__default.default(emitSetColor, 100), [emitSetColor]), handleColorChange = react.useCallback(
1006
+ (nextColor) => {
1007
+ setColor(nextColor), debouncedColorChange(nextColor);
1008
+ },
1009
+ [debouncedColorChange, setColor]
1010
+ ), handleCreateColor = react.useCallback(() => {
1011
+ setColor(DEFAULT_COLOR), emitSetColor(DEFAULT_COLOR);
1012
+ }, [emitSetColor]), handleUnset = react.useCallback(() => {
1013
+ setColor(void 0), onChange(sanity.unset());
1619
1014
  }, [onChange]);
1620
- return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
1621
- children: value && value.hex ? /* @__PURE__ */jsxRuntime.jsx(ColorPicker, {
1622
- color,
1015
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value && value.hex ? /* @__PURE__ */ jsxRuntime.jsx(
1016
+ ColorPicker,
1017
+ {
1018
+ color: color2,
1623
1019
  onChange: handleColorChange,
1624
- readOnly: readOnly || typeof type.readOnly === "boolean" && type.readOnly,
1625
- disableAlpha: !!((_a = type.options) == null ? void 0 : _a.disableAlpha),
1626
- colorList: (_b = type.options) == null ? void 0 : _b.colorList,
1020
+ readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly,
1021
+ disableAlpha: !!type.options?.disableAlpha,
1022
+ colorList: type.options?.colorList,
1627
1023
  onUnset: handleUnset
1628
- }) : /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
1024
+ }
1025
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1026
+ ui.Button,
1027
+ {
1629
1028
  icon: icons.AddIcon,
1630
1029
  mode: "ghost",
1631
1030
  text: "Create color",
1632
1031
  ref: focusRef,
1633
- disabled: Boolean(readOnly),
1032
+ disabled: !!readOnly,
1634
1033
  onClick: handleCreateColor
1635
- })
1636
- });
1034
+ }
1035
+ ) });
1637
1036
  }
1638
- const round = function () {
1639
- let val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
1640
- return Math.round(val * 100);
1641
- };
1642
- const colorTypeName = "color";
1643
- const color = sanity.defineType({
1037
+ const round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = sanity.defineType({
1644
1038
  name: colorTypeName,
1645
1039
  type: "object",
1646
1040
  title: "Color",
1647
- components: {
1648
- input: ColorInput
1649
- },
1650
- fields: [{
1651
- title: "Hex",
1652
- name: "hex",
1653
- type: "string"
1654
- }, {
1655
- title: "Alpha",
1656
- name: "alpha",
1657
- type: "number"
1658
- }, {
1659
- title: "Hue Saturation Lightness",
1660
- name: "hsl",
1661
- type: "hslaColor"
1662
- }, {
1663
- title: "Hue Saturation Value",
1664
- name: "hsv",
1665
- type: "hsvaColor"
1666
- }, {
1667
- title: "Red Green Blue (rgb)",
1668
- name: "rgb",
1669
- type: "rgbaColor"
1670
- }],
1041
+ components: { input: ColorInput },
1042
+ fields: [
1043
+ {
1044
+ title: "Hex",
1045
+ name: "hex",
1046
+ type: "string"
1047
+ },
1048
+ {
1049
+ title: "Alpha",
1050
+ name: "alpha",
1051
+ type: "number"
1052
+ },
1053
+ {
1054
+ title: "Hue Saturation Lightness",
1055
+ name: "hsl",
1056
+ type: "hslaColor"
1057
+ },
1058
+ {
1059
+ title: "Hue Saturation Value",
1060
+ name: "hsv",
1061
+ type: "hsvaColor"
1062
+ },
1063
+ {
1064
+ title: "Red Green Blue (rgb)",
1065
+ name: "rgb",
1066
+ type: "rgbaColor"
1067
+ }
1068
+ ],
1671
1069
  preview: {
1672
1070
  select: {
1673
1071
  title: "hex",
@@ -1675,58 +1073,64 @@ const color = sanity.defineType({
1675
1073
  hex: "hex",
1676
1074
  hsl: "hsl"
1677
1075
  },
1678
- prepare(_ref4) {
1679
- let {
1680
- title,
1681
- hex,
1682
- hsl,
1683
- alpha
1684
- } = _ref4;
1076
+ prepare({
1077
+ title,
1078
+ hex,
1079
+ hsl,
1080
+ alpha
1081
+ }) {
1685
1082
  let subtitle = hex || "No color set";
1686
- if (hsl) {
1687
- subtitle = "H:".concat(round(hsl.h), " S:").concat(round(hsl.s), " L:").concat(round(hsl.l), " A:").concat(round(alpha));
1688
- }
1689
- return {
1083
+ return hsl && (subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`), {
1690
1084
  title,
1691
1085
  subtitle,
1692
- media: () => /* @__PURE__ */jsxRuntime.jsx("div", {
1693
- style: {
1694
- backgroundColor: hex != null ? hex : "#000",
1695
- opacity: alpha != null ? alpha : 1,
1696
- position: "absolute",
1697
- height: "100%",
1698
- width: "100%",
1699
- top: "0",
1700
- left: "0"
1086
+ media: () => /* @__PURE__ */ jsxRuntime.jsx(
1087
+ "div",
1088
+ {
1089
+ style: {
1090
+ backgroundColor: hex ?? "#000",
1091
+ opacity: alpha ?? 1,
1092
+ position: "absolute",
1093
+ height: "100%",
1094
+ width: "100%",
1095
+ top: "0",
1096
+ left: "0"
1097
+ }
1701
1098
  }
1702
- })
1099
+ )
1703
1100
  };
1704
1101
  }
1705
1102
  }
1706
- });
1707
- const hsvaColor = sanity.defineType({
1103
+ }), hslaColor = sanity.defineType({
1104
+ title: "Hue Saturation Lightness",
1105
+ name: "hslaColor",
1106
+ type: "object",
1107
+ fields: [
1108
+ { name: "h", type: "number", title: "Hue" },
1109
+ { name: "s", type: "number", title: "Saturation" },
1110
+ { name: "l", type: "number", title: "Lightness" },
1111
+ { name: "a", type: "number", title: "Alpha" }
1112
+ ]
1113
+ }), hsvaColor = sanity.defineType({
1708
1114
  title: "Hue Saturation Value",
1709
1115
  name: "hsvaColor",
1710
1116
  type: "object",
1711
- fields: [{
1712
- name: "h",
1713
- type: "number",
1714
- title: "Hue"
1715
- }, {
1716
- name: "s",
1717
- type: "number",
1718
- title: "Saturation"
1719
- }, {
1720
- name: "v",
1721
- type: "number",
1722
- title: "Value"
1723
- }, {
1724
- name: "a",
1725
- type: "number",
1726
- title: "Alpha"
1727
- }]
1728
- });
1729
- const colorInput = sanity.definePlugin({
1117
+ fields: [
1118
+ { name: "h", type: "number", title: "Hue" },
1119
+ { name: "s", type: "number", title: "Saturation" },
1120
+ { name: "v", type: "number", title: "Value" },
1121
+ { name: "a", type: "number", title: "Alpha" }
1122
+ ]
1123
+ }), rgbaColor = sanity.defineType({
1124
+ title: "Red Green Blue (rgb)",
1125
+ name: "rgbaColor",
1126
+ type: "object",
1127
+ fields: [
1128
+ { name: "r", type: "number", title: "Red" },
1129
+ { name: "g", type: "number", title: "Green" },
1130
+ { name: "b", type: "number", title: "Blue" },
1131
+ { name: "a", type: "number", title: "Alpha" }
1132
+ ]
1133
+ }), colorInput = sanity.definePlugin({
1730
1134
  name: "@sanity/color-input",
1731
1135
  schema: {
1732
1136
  types: [hslaColor, hsvaColor, rgbaColor, color]