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

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,54 @@
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');
16
- function _interopDefaultCompat(e) {
17
- return e && typeof e === 'object' && 'default' in e ? e : {
18
- default: e
19
- };
20
- }
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.
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"), react = require("react"), useEffectEvent = require("use-effect-event"), reactColor = require("react-color"), common = require("react-color/lib/components/common"), styledComponents = require("styled-components"), color$1 = require("react-color/lib/helpers/color");
188
4
  function _typeof(obj) {
189
5
  "@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;
6
+ return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) {
7
+ return typeof obj2;
8
+ } : function(obj2) {
9
+ return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
195
10
  }, _typeof(obj);
196
11
  }
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;
12
+ var trimLeft = /^\s+/, trimRight = /\s+$/;
13
+ function tinycolor(color2, opts) {
14
+ if (color2 = color2 || "", opts = opts || {}, color2 instanceof tinycolor)
15
+ return color2;
16
+ if (!(this instanceof tinycolor))
17
+ return new tinycolor(color2, opts);
18
+ var rgb = inputToRGB(color2);
19
+ 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
20
  }
228
21
  tinycolor.prototype = {
229
- isDark: function isDark() {
22
+ isDark: function() {
230
23
  return this.getBrightness() < 128;
231
24
  },
232
- isLight: function isLight() {
25
+ isLight: function() {
233
26
  return !this.isDark();
234
27
  },
235
- isValid: function isValid() {
28
+ isValid: function() {
236
29
  return this._ok;
237
30
  },
238
- getOriginalInput: function getOriginalInput() {
31
+ getOriginalInput: function() {
239
32
  return this._originalInput;
240
33
  },
241
- getFormat: function getFormat() {
34
+ getFormat: function() {
242
35
  return this._format;
243
36
  },
244
- getAlpha: function getAlpha() {
37
+ getAlpha: function() {
245
38
  return this._a;
246
39
  },
247
- getBrightness: function getBrightness() {
248
- //http://www.w3.org/TR/AERT#color-contrast
40
+ getBrightness: function() {
249
41
  var rgb = this.toRgb();
250
- return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
42
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
251
43
  },
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;
44
+ getLuminance: function() {
45
+ var rgb = this.toRgb(), RsRGB, GsRGB, BsRGB, R, G, B;
46
+ 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
47
  },
264
- setAlpha: function setAlpha(value) {
265
- this._a = boundAlpha(value);
266
- this._roundA = Math.round(100 * this._a) / 100;
267
- return this;
48
+ setAlpha: function(value) {
49
+ return this._a = boundAlpha(value), this._roundA = Math.round(100 * this._a) / 100, this;
268
50
  },
269
- toHsv: function toHsv() {
51
+ toHsv: function() {
270
52
  var hsv = rgbToHsv(this._r, this._g, this._b);
271
53
  return {
272
54
  h: hsv.h * 360,
@@ -275,14 +57,11 @@ tinycolor.prototype = {
275
57
  a: this._a
276
58
  };
277
59
  },
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);
60
+ toHsvString: function() {
61
+ 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
62
  return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
284
63
  },
285
- toHsl: function toHsl() {
64
+ toHsl: function() {
286
65
  var hsl = rgbToHsl(this._r, this._g, this._b);
287
66
  return {
288
67
  h: hsl.h * 360,
@@ -291,26 +70,23 @@ tinycolor.prototype = {
291
70
  a: this._a
292
71
  };
293
72
  },
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);
73
+ toHslString: function() {
74
+ 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
75
  return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
300
76
  },
301
- toHex: function toHex(allow3Char) {
77
+ toHex: function(allow3Char) {
302
78
  return rgbToHex(this._r, this._g, this._b, allow3Char);
303
79
  },
304
- toHexString: function toHexString(allow3Char) {
80
+ toHexString: function(allow3Char) {
305
81
  return "#" + this.toHex(allow3Char);
306
82
  },
307
- toHex8: function toHex8(allow4Char) {
83
+ toHex8: function(allow4Char) {
308
84
  return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
309
85
  },
310
- toHex8String: function toHex8String(allow4Char) {
86
+ toHex8String: function(allow4Char) {
311
87
  return "#" + this.toHex8(allow4Char);
312
88
  },
313
- toRgb: function toRgb() {
89
+ toRgb: function() {
314
90
  return {
315
91
  r: Math.round(this._r),
316
92
  g: Math.round(this._g),
@@ -318,10 +94,10 @@ tinycolor.prototype = {
318
94
  a: this._a
319
95
  };
320
96
  },
321
- toRgbString: function toRgbString() {
97
+ toRgbString: function() {
322
98
  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
99
  },
324
- toPercentageRgb: function toPercentageRgb() {
100
+ toPercentageRgb: function() {
325
101
  return {
326
102
  r: Math.round(bound01(this._r, 255) * 100) + "%",
327
103
  g: Math.round(bound01(this._g, 255) * 100) + "%",
@@ -329,223 +105,104 @@ tinycolor.prototype = {
329
105
  a: this._a
330
106
  };
331
107
  },
332
- toPercentageRgbString: function toPercentageRgbString() {
108
+ toPercentageRgbString: function() {
333
109
  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
110
  },
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;
111
+ toName: function() {
112
+ return this._a === 0 ? "transparent" : this._a < 1 ? !1 : hexNames[rgbToHex(this._r, this._g, this._b, !0)] || !1;
343
113
  },
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, " : "";
114
+ toFilter: function(secondColor) {
115
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a), secondHex8String = hex8String, gradientType = this._gradientType ? "GradientType = 1, " : "";
348
116
  if (secondColor) {
349
117
  var s = tinycolor(secondColor);
350
118
  secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
351
119
  }
352
120
  return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
353
121
  },
354
- toString: function toString(format) {
122
+ toString: function(format) {
355
123
  var formatSet = !!format;
356
124
  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();
125
+ 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");
126
+ 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
127
  },
397
- clone: function clone() {
128
+ clone: function() {
398
129
  return tinycolor(this.toString());
399
130
  },
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;
131
+ _applyModification: function(fn, args) {
132
+ var color2 = fn.apply(null, [this].concat([].slice.call(args)));
133
+ return this._r = color2._r, this._g = color2._g, this._b = color2._b, this.setAlpha(color2._a), this;
407
134
  },
408
- lighten: function lighten() {
135
+ lighten: function() {
409
136
  return this._applyModification(_lighten, arguments);
410
137
  },
411
- brighten: function brighten() {
138
+ brighten: function() {
412
139
  return this._applyModification(_brighten, arguments);
413
140
  },
414
- darken: function darken() {
141
+ darken: function() {
415
142
  return this._applyModification(_darken, arguments);
416
143
  },
417
- desaturate: function desaturate() {
144
+ desaturate: function() {
418
145
  return this._applyModification(_desaturate, arguments);
419
146
  },
420
- saturate: function saturate() {
147
+ saturate: function() {
421
148
  return this._applyModification(_saturate, arguments);
422
149
  },
423
- greyscale: function greyscale() {
150
+ greyscale: function() {
424
151
  return this._applyModification(_greyscale, arguments);
425
152
  },
426
- spin: function spin() {
153
+ spin: function() {
427
154
  return this._applyModification(_spin, arguments);
428
155
  },
429
- _applyCombination: function _applyCombination(fn, args) {
156
+ _applyCombination: function(fn, args) {
430
157
  return fn.apply(null, [this].concat([].slice.call(args)));
431
158
  },
432
- analogous: function analogous() {
159
+ analogous: function() {
433
160
  return this._applyCombination(_analogous, arguments);
434
161
  },
435
- complement: function complement() {
162
+ complement: function() {
436
163
  return this._applyCombination(_complement, arguments);
437
164
  },
438
- monochromatic: function monochromatic() {
165
+ monochromatic: function() {
439
166
  return this._applyCombination(_monochromatic, arguments);
440
167
  },
441
- splitcomplement: function splitcomplement() {
168
+ splitcomplement: function() {
442
169
  return this._applyCombination(_splitcomplement, arguments);
443
170
  },
444
171
  // Disabled until https://github.com/bgrins/TinyColor/issues/254
445
172
  // polyad: function (number) {
446
173
  // return this._applyCombination(polyad, [number]);
447
174
  // },
448
- triad: function triad() {
175
+ triad: function() {
449
176
  return this._applyCombination(polyad, [3]);
450
177
  },
451
- tetrad: function tetrad() {
178
+ tetrad: function() {
452
179
  return this._applyCombination(polyad, [4]);
453
180
  }
454
181
  };
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") {
182
+ tinycolor.fromRatio = function(color2, opts) {
183
+ if (_typeof(color2) == "object") {
460
184
  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;
185
+ for (var i in color2)
186
+ color2.hasOwnProperty(i) && (i === "a" ? newColor[i] = color2[i] : newColor[i] = convertToPercentage(color2[i]));
187
+ color2 = newColor;
471
188
  }
472
- return tinycolor(color, opts);
189
+ return tinycolor(color2, opts);
473
190
  };
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) {
191
+ function inputToRGB(color2) {
491
192
  var rgb = {
492
193
  r: 0,
493
194
  g: 0,
494
195
  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,
196
+ }, a = 1, s = null, v = null, l = null, ok = !1, format = !1;
197
+ 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), {
198
+ ok,
199
+ format: color2.format || format,
531
200
  r: Math.min(255, Math.max(rgb.r, 0)),
532
201
  g: Math.min(255, Math.max(rgb.g, 0)),
533
202
  b: Math.min(255, Math.max(rgb.b, 0)),
534
- a: a
203
+ a
535
204
  };
536
205
  }
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
206
  function rgbToRgb(r, g, b) {
550
207
  return {
551
208
  r: bound01(r, 255) * 255,
@@ -553,26 +210,14 @@ function rgbToRgb(r, g, b) {
553
210
  b: bound01(b, 255) * 255
554
211
  };
555
212
  }
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
213
  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 {
214
+ r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
215
+ var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, l = (max + min) / 2;
216
+ if (max == min)
217
+ h = s = 0;
218
+ else {
573
219
  var d = max - min;
574
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
575
- switch (max) {
220
+ switch (s = l > 0.5 ? d / (2 - max - min) : d / (max + min), max) {
576
221
  case r:
577
222
  h = (g - b) / d + (g < b ? 6 : 0);
578
223
  break;
@@ -586,37 +231,22 @@ function rgbToHsl(r, g, b) {
586
231
  h /= 6;
587
232
  }
588
233
  return {
589
- h: h,
590
- s: s,
591
- l: l
234
+ h,
235
+ s,
236
+ l
592
237
  };
593
238
  }
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
239
  function hslToRgb(h, s, l) {
600
240
  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;
241
+ h = bound01(h, 360), s = bound01(s, 100), l = bound01(l, 100);
242
+ function hue2rgb(p2, q2, t) {
243
+ 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
244
  }
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);
245
+ if (s === 0)
246
+ r = g = b = l;
247
+ else {
248
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q;
249
+ r = hue2rgb(p, q, h + 1 / 3), g = hue2rgb(p, q, h), b = hue2rgb(p, q, h - 1 / 3);
620
250
  }
621
251
  return {
622
252
  r: r * 255,
@@ -624,25 +254,12 @@ function hslToRgb(h, s, l) {
624
254
  b: b * 255
625
255
  };
626
256
  }
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
257
  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 {
258
+ r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
259
+ var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, v = max, d = max - min;
260
+ if (s = max === 0 ? 0 : d / max, max == min)
261
+ h = 0;
262
+ else {
646
263
  switch (max) {
647
264
  case r:
648
265
  h = (g - b) / d + (g < b ? 6 : 0);
@@ -657,170 +274,92 @@ function rgbToHsv(r, g, b) {
657
274
  h /= 6;
658
275
  }
659
276
  return {
660
- h: h,
661
- s: s,
662
- v: v
277
+ h,
278
+ s,
279
+ v
663
280
  };
664
281
  }
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
282
  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];
283
+ h = bound01(h, 360) * 6, s = bound01(s, 100), v = bound01(v, 100);
284
+ 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
285
  return {
684
286
  r: r * 255,
685
287
  g: g * 255,
686
288
  b: b * 255
687
289
  };
688
290
  }
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
291
  function rgbToHex(r, g, b, allow3Char) {
695
292
  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("");
293
+ 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
294
  }
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
295
  function rgbaToHex(r, g, b, a, allow4Char) {
709
296
  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("");
297
+ 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
298
  }
717
-
718
- // `rgbaToArgbHex`
719
- // Converts an RGBA color to an ARGB Hex8 string
720
- // Rarely used, but required for "toFilter()"
721
299
  function rgbaToArgbHex(r, g, b, a) {
722
300
  var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
723
301
  return hex.join("");
724
302
  }
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();
303
+ tinycolor.equals = function(color1, color2) {
304
+ return !color1 || !color2 ? !1 : tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
731
305
  };
732
- tinycolor.random = function () {
306
+ tinycolor.random = function() {
733
307
  return tinycolor.fromRatio({
734
308
  r: Math.random(),
735
309
  g: Math.random(),
736
310
  b: Math.random()
737
311
  });
738
312
  };
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) {
313
+ function _desaturate(color2, amount) {
746
314
  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);
315
+ var hsl = tinycolor(color2).toHsl();
316
+ return hsl.s -= amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
751
317
  }
752
- function _saturate(color, amount) {
318
+ function _saturate(color2, amount) {
753
319
  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);
320
+ var hsl = tinycolor(color2).toHsl();
321
+ return hsl.s += amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
758
322
  }
759
- function _greyscale(color) {
760
- return tinycolor(color).desaturate(100);
323
+ function _greyscale(color2) {
324
+ return tinycolor(color2).desaturate(100);
761
325
  }
762
- function _lighten(color, amount) {
326
+ function _lighten(color2, amount) {
763
327
  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);
328
+ var hsl = tinycolor(color2).toHsl();
329
+ return hsl.l += amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
768
330
  }
769
- function _brighten(color, amount) {
331
+ function _brighten(color2, amount) {
770
332
  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);
333
+ var rgb = tinycolor(color2).toRgb();
334
+ 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
335
  }
777
- function _darken(color, amount) {
336
+ function _darken(color2, amount) {
778
337
  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);
338
+ var hsl = tinycolor(color2).toHsl();
339
+ return hsl.l -= amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
783
340
  }
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);
341
+ function _spin(color2, amount) {
342
+ var hsl = tinycolor(color2).toHsl(), hue = (hsl.h + amount) % 360;
343
+ return hsl.h = hue < 0 ? 360 + hue : hue, tinycolor(hsl);
792
344
  }
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);
345
+ function _complement(color2) {
346
+ var hsl = tinycolor(color2).toHsl();
347
+ return hsl.h = (hsl.h + 180) % 360, tinycolor(hsl);
803
348
  }
804
- function polyad(color, number) {
805
- if (isNaN(number) || number <= 0) {
349
+ function polyad(color2, number) {
350
+ if (isNaN(number) || number <= 0)
806
351
  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++) {
352
+ for (var hsl = tinycolor(color2).toHsl(), result = [tinycolor(color2)], step = 360 / number, i = 1; i < number; i++)
812
353
  result.push(tinycolor({
813
354
  h: (hsl.h + i * step) % 360,
814
355
  s: hsl.s,
815
356
  l: hsl.l
816
357
  }));
817
- }
818
358
  return result;
819
359
  }
820
- function _splitcomplement(color) {
821
- var hsl = tinycolor(color).toHsl();
822
- var h = hsl.h;
823
- return [tinycolor(color), tinycolor({
360
+ function _splitcomplement(color2) {
361
+ var hsl = tinycolor(color2).toHsl(), h = hsl.h;
362
+ return [tinycolor(color2), tinycolor({
824
363
  h: (h + 72) % 360,
825
364
  s: hsl.s,
826
365
  l: hsl.l
@@ -830,46 +369,26 @@ function _splitcomplement(color) {
830
369
  l: hsl.l
831
370
  })];
832
371
  }
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
- }
372
+ function _analogous(color2, results, slices) {
373
+ results = results || 6, slices = slices || 30;
374
+ var hsl = tinycolor(color2).toHsl(), part = 360 / slices, ret = [tinycolor(color2)];
375
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; )
376
+ hsl.h = (hsl.h + part) % 360, ret.push(tinycolor(hsl));
843
377
  return ret;
844
378
  }
845
- function _monochromatic(color, results) {
379
+ function _monochromatic(color2, results) {
846
380
  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--) {
381
+ for (var hsv = tinycolor(color2).toHsv(), h = hsv.h, s = hsv.s, v = hsv.v, ret = [], modification = 1 / results; results--; )
854
382
  ret.push(tinycolor({
855
- h: h,
856
- s: s,
857
- v: v
858
- }));
859
- v = (v + modification) % 1;
860
- }
383
+ h,
384
+ s,
385
+ v
386
+ })), v = (v + modification) % 1;
861
387
  return ret;
862
388
  }
863
-
864
- // Utility Functions
865
- // ---------------------
866
-
867
- tinycolor.mix = function (color1, color2, amount) {
389
+ tinycolor.mix = function(color1, color2, amount) {
868
390
  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 = {
391
+ var rgb1 = tinycolor(color1).toRgb(), rgb2 = tinycolor(color2).toRgb(), p = amount / 100, rgba = {
873
392
  r: (rgb2.r - rgb1.r) * p + rgb1.r,
874
393
  g: (rgb2.g - rgb1.g) * p + rgb1.g,
875
394
  b: (rgb2.b - rgb1.b) * p + rgb1.b,
@@ -877,35 +396,13 @@ tinycolor.mix = function (color1, color2, amount) {
877
396
  };
878
397
  return tinycolor(rgba);
879
398
  };
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);
399
+ tinycolor.readability = function(color1, color2) {
400
+ var c1 = tinycolor(color1), c2 = tinycolor(color2);
890
401
  return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
891
402
  };
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) {
403
+ tinycolor.isReadable = function(color1, color2, wcag2) {
404
+ var readability = tinycolor.readability(color1, color2), wcag2Parms, out;
405
+ switch (out = !1, wcag2Parms = validateWCAG2Parms(wcag2), wcag2Parms.level + wcag2Parms.size) {
909
406
  case "AAsmall":
910
407
  case "AAAlarge":
911
408
  out = readability >= 4.5;
@@ -919,46 +416,16 @@ tinycolor.isReadable = function (color1, color2, wcag2) {
919
416
  }
920
417
  return out;
921
418
  };
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
- }
419
+ tinycolor.mostReadable = function(baseColor, colorList, args) {
420
+ var bestColor = null, bestScore = 0, readability, includeFallbackColors, level, size;
421
+ args = args || {}, includeFallbackColors = args.includeFallbackColors, level = args.level, size = args.size;
422
+ for (var i = 0; i < colorList.length; i++)
423
+ readability = tinycolor.readability(baseColor, colorList[i]), readability > bestScore && (bestScore = readability, bestColor = tinycolor(colorList[i]));
424
+ return tinycolor.isReadable(baseColor, bestColor, {
425
+ level,
426
+ size
427
+ }) || !includeFallbackColors ? bestColor : (args.includeFallbackColors = !1, tinycolor.mostReadable(baseColor, ["#fff", "#000"], args));
957
428
  };
958
-
959
- // Big List of Colors
960
- // ------------------
961
- // <https://www.w3.org/TR/css-color-4/#named-colors>
962
429
  var names = tinycolor.names = {
963
430
  aliceblue: "f0f8ff",
964
431
  antiquewhite: "faebd7",
@@ -1109,111 +576,47 @@ var names = tinycolor.names = {
1109
576
  whitesmoke: "f5f5f5",
1110
577
  yellow: "ff0",
1111
578
  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' }`
579
+ }, hexNames = tinycolor.hexNames = flip(names);
1121
580
  function flip(o) {
1122
581
  var flipped = {};
1123
- for (var i in o) {
1124
- if (o.hasOwnProperty(i)) {
1125
- flipped[o[i]] = i;
1126
- }
1127
- }
582
+ for (var i in o)
583
+ o.hasOwnProperty(i) && (flipped[o[i]] = i);
1128
584
  return flipped;
1129
585
  }
1130
-
1131
- // Return a valid alpha value [0,1] with all invalid values being set to 1
1132
586
  function boundAlpha(a) {
1133
- a = parseFloat(a);
1134
- if (isNaN(a) || a < 0 || a > 1) {
1135
- a = 1;
1136
- }
1137
- return a;
587
+ return a = parseFloat(a), (isNaN(a) || a < 0 || a > 1) && (a = 1), a;
1138
588
  }
1139
-
1140
- // Take input from [0, n] and return it as [0, 1]
1141
589
  function bound01(n, max) {
1142
- if (isOnePointZero(n)) n = "100%";
590
+ isOnePointZero(n) && (n = "100%");
1143
591
  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);
592
+ 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
593
  }
1159
-
1160
- // Force a number between 0 and 1
1161
594
  function clamp01(val) {
1162
595
  return Math.min(1, Math.max(0, val));
1163
596
  }
1164
-
1165
- // Parse a base-16 hex value into a base-10 integer
1166
597
  function parseIntFromHex(val) {
1167
598
  return parseInt(val, 16);
1168
599
  }
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
600
  function isOnePointZero(n) {
1173
601
  return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
1174
602
  }
1175
-
1176
- // Check to see if string passed in is a percentage
1177
603
  function isPercentage(n) {
1178
- return typeof n === "string" && n.indexOf("%") != -1;
604
+ return typeof n == "string" && n.indexOf("%") != -1;
1179
605
  }
1180
-
1181
- // Force a hex value to have 2 characters
1182
606
  function pad2(c) {
1183
607
  return c.length == 1 ? "0" + c : "" + c;
1184
608
  }
1185
-
1186
- // Replace a decimal with it's percentage value
1187
609
  function convertToPercentage(n) {
1188
- if (n <= 1) {
1189
- n = n * 100 + "%";
1190
- }
1191
- return n;
610
+ return n <= 1 && (n = n * 100 + "%"), n;
1192
611
  }
1193
-
1194
- // Converts a decimal to a hex value
1195
612
  function convertDecimalToHex(d) {
1196
613
  return Math.round(parseFloat(d) * 255).toString(16);
1197
614
  }
1198
- // Converts a hex value to a decimal
1199
615
  function convertHexToDecimal(h) {
1200
616
  return parseIntFromHex(h) / 255;
1201
617
  }
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*\\)?";
618
+ var matchers = function() {
619
+ 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
620
  return {
1218
621
  CSS_UNIT: new RegExp(CSS_UNIT),
1219
622
  rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
@@ -1228,24 +631,15 @@ var matchers = function () {
1228
631
  hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1229
632
  };
1230
633
  }();
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);
634
+ function isValidCSSUnit(color2) {
635
+ return !!matchers.CSS_UNIT.exec(color2);
1237
636
  }
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") {
637
+ function stringInputToObject(color2) {
638
+ color2 = color2.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
639
+ var named = !1;
640
+ if (names[color2])
641
+ color2 = names[color2], named = !0;
642
+ else if (color2 == "transparent")
1249
643
  return {
1250
644
  r: 0,
1251
645
  g: 0,
@@ -1253,421 +647,419 @@ function stringInputToObject(color) {
1253
647
  a: 0,
1254
648
  format: "name"
1255
649
  };
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
650
  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;
651
+ return (match = matchers.rgb.exec(color2)) ? {
652
+ r: match[1],
653
+ g: match[2],
654
+ b: match[3]
655
+ } : (match = matchers.rgba.exec(color2)) ? {
656
+ r: match[1],
657
+ g: match[2],
658
+ b: match[3],
659
+ a: match[4]
660
+ } : (match = matchers.hsl.exec(color2)) ? {
661
+ h: match[1],
662
+ s: match[2],
663
+ l: match[3]
664
+ } : (match = matchers.hsla.exec(color2)) ? {
665
+ h: match[1],
666
+ s: match[2],
667
+ l: match[3],
668
+ a: match[4]
669
+ } : (match = matchers.hsv.exec(color2)) ? {
670
+ h: match[1],
671
+ s: match[2],
672
+ v: match[3]
673
+ } : (match = matchers.hsva.exec(color2)) ? {
674
+ h: match[1],
675
+ s: match[2],
676
+ v: match[3],
677
+ a: match[4]
678
+ } : (match = matchers.hex8.exec(color2)) ? {
679
+ r: parseIntFromHex(match[1]),
680
+ g: parseIntFromHex(match[2]),
681
+ b: parseIntFromHex(match[3]),
682
+ a: convertHexToDecimal(match[4]),
683
+ format: named ? "name" : "hex8"
684
+ } : (match = matchers.hex6.exec(color2)) ? {
685
+ r: parseIntFromHex(match[1]),
686
+ g: parseIntFromHex(match[2]),
687
+ b: parseIntFromHex(match[3]),
688
+ format: named ? "name" : "hex"
689
+ } : (match = matchers.hex4.exec(color2)) ? {
690
+ r: parseIntFromHex(match[1] + "" + match[1]),
691
+ g: parseIntFromHex(match[2] + "" + match[2]),
692
+ b: parseIntFromHex(match[3] + "" + match[3]),
693
+ a: convertHexToDecimal(match[4] + "" + match[4]),
694
+ format: named ? "name" : "hex8"
695
+ } : (match = matchers.hex3.exec(color2)) ? {
696
+ r: parseIntFromHex(match[1] + "" + match[1]),
697
+ g: parseIntFromHex(match[2] + "" + match[2]),
698
+ b: parseIntFromHex(match[3] + "" + match[3]),
699
+ format: named ? "name" : "hex"
700
+ } : !1;
1343
701
  }
1344
702
  function validateWCAG2Parms(parms) {
1345
- // return valid WCAG2 parms for isReadable.
1346
- // If input parms are invalid, return {"level":"AA", "size":"small"}
1347
703
  var level, size;
1348
- parms = parms || {
704
+ return parms = parms || {
1349
705
  level: "AA",
1350
706
  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
707
+ }, level = (parms.level || "AA").toUpperCase(), size = (parms.size || "small").toLowerCase(), level !== "AA" && level !== "AAA" && (level = "AA"), size !== "small" && size !== "large" && (size = "small"), {
708
+ level,
709
+ size
1363
710
  };
1364
711
  }
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;
712
+ const ColorListWrap = styledComponents.styled(ui.Flex)`
713
+ gap: 0.25em;
714
+ `, ColorBoxContainer = styledComponents.styled.div`
715
+ width: 2.1em;
716
+ height: 2.1em;
717
+ cursor: pointer;
718
+ position: relative;
719
+ overflow: hidden;
720
+ border-radius: 3px;
721
+ background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')
722
+ left center #fff;
723
+ `, ColorBox$1 = styledComponents.styled.div`
724
+ border-radius: inherit;
725
+ box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);
726
+ content: '';
727
+ position: absolute;
728
+ inset: 0;
729
+ z-index: 1;
730
+ `, validateColors = (colors) => colors.reduce((cls, c) => {
731
+ const color2 = c.hex ? tinycolor(c.hex) : tinycolor(c);
732
+ return color2.isValid() && cls.push({
733
+ color: c,
734
+ backgroundColor: color2.toRgbString()
735
+ }), cls;
736
+ }, []), ColorList = react.memo(function({ colors, onChange }) {
737
+ return colors ? /* @__PURE__ */ jsxRuntime.jsx(ColorListWrap, { wrap: "wrap", children: validateColors(colors).map(({ color: color2, backgroundColor }, idx) => /* @__PURE__ */ jsxRuntime.jsx(
738
+ ColorBoxContainer,
739
+ {
740
+ onClick: () => {
741
+ onChange(color2);
742
+ },
743
+ children: /* @__PURE__ */ jsxRuntime.jsx(ColorBox$1, { style: { background: backgroundColor } })
744
+ },
745
+ `${backgroundColor}-${idx}`
746
+ )) }) : null;
747
+ }), ColorPickerFields = ({
748
+ onChange,
749
+ rgb,
750
+ hsl,
751
+ hex,
752
+ disableAlpha
753
+ }) => {
754
+ const { sanity: sanity2 } = ui.useTheme(), inputStyles = react.useMemo(
755
+ () => ({
756
+ input: {
757
+ width: "80%",
758
+ padding: "4px 10% 3px",
759
+ border: "none",
760
+ boxShadow: `inset 0 0 0 1px ${sanity2.color.input.default.enabled.border}`,
761
+ color: sanity2.color.input.default.enabled.fg,
762
+ backgroundColor: sanity2.color.input.default.enabled.bg,
763
+ fontSize: sanity2.fonts.text.sizes[0].fontSize,
764
+ textAlign: "center"
765
+ },
766
+ label: {
767
+ display: "block",
768
+ textAlign: "center",
769
+ fontSize: sanity2.fonts.label.sizes[0].fontSize,
770
+ color: sanity2.color.base.fg,
771
+ paddingTop: "3px",
772
+ paddingBottom: "4px",
773
+ textTransform: "capitalize"
774
+ }
775
+ }),
776
+ [sanity2]
777
+ ), handleChange = react.useCallback(
778
+ (data) => {
779
+ if ("hex" in data && data.hex && color$1.isValidHex(data.hex))
780
+ onChange({
781
+ hex: data.hex,
782
+ source: "hex"
783
+ });
784
+ else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b))
785
+ onChange({
786
+ r: Number(data.r) || rgb.r,
787
+ g: Number(data.g) || rgb.g,
788
+ b: Number(data.b) || rgb.b,
789
+ a: rgb.a,
790
+ source: "rgb"
791
+ });
792
+ else if (hsl && "a" in data && data.a) {
793
+ let alpha = Number(data.a);
794
+ alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha /= 100, onChange({
795
+ h: hsl.h,
796
+ s: hsl.s,
797
+ l: hsl.l,
798
+ a: alpha,
799
+ source: "hsl"
800
+ });
801
+ }
802
+ },
803
+ [onChange, hsl, rgb]
804
+ );
805
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
806
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 2, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
807
+ common.EditableInput,
808
+ {
809
+ style: inputStyles,
810
+ label: "hex",
811
+ value: hex?.replace("#", ""),
812
+ onChange: handleChange
813
+ }
814
+ ) }),
815
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
816
+ common.EditableInput,
817
+ {
818
+ style: inputStyles,
819
+ label: "r",
820
+ value: rgb?.r,
821
+ onChange: handleChange,
822
+ dragLabel: !0,
823
+ dragMax: 255
824
+ }
825
+ ) }),
826
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
827
+ common.EditableInput,
828
+ {
829
+ style: inputStyles,
830
+ label: "g",
831
+ value: rgb?.g,
832
+ onChange: handleChange,
833
+ dragLabel: !0,
834
+ dragMax: 255
835
+ }
836
+ ) }),
837
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
838
+ common.EditableInput,
839
+ {
840
+ style: inputStyles,
841
+ label: "b",
842
+ value: rgb?.b,
843
+ onChange: handleChange,
844
+ dragLabel: !0,
845
+ dragMax: 255
846
+ }
847
+ ) }),
848
+ !disableAlpha && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
849
+ common.EditableInput,
850
+ {
851
+ style: inputStyles,
852
+ label: "a",
853
+ value: Math.round((rgb?.a ?? 1) * 100),
854
+ onChange: handleChange,
855
+ dragLabel: !0,
856
+ dragMax: 100
857
+ }
858
+ ) })
859
+ ] });
860
+ }, ColorBox = styledComponents.styled(ui.Box)`
861
+ position: absolute;
862
+ top: 0;
863
+ left: 0;
864
+ width: 100%;
865
+ height: 100%;
866
+ `, ReadOnlyContainer = styledComponents.styled(ui.Flex)`
867
+ margin-top: 6rem;
868
+ background-color: var(--card-bg-color);
869
+ position: relative;
870
+ width: 100%;
871
+ `, ColorPickerInner = (props) => {
1420
872
  const {
1421
873
  width,
1422
- color: {
1423
- rgb,
1424
- hex,
1425
- hsv,
1426
- hsl
1427
- },
874
+ color: { rgb, hex, hsv, hsl },
1428
875
  onChange,
1429
876
  onUnset,
1430
877
  disableAlpha,
1431
878
  colorList,
1432
879
  readOnly
1433
880
  } = 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, ")")
881
+ 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: [
882
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
883
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { overflow: "hidden", style: { position: "relative", height: "5em" }, children: /* @__PURE__ */ jsxRuntime.jsx(common.Saturation, { onChange, hsl, hsv }) }),
884
+ /* @__PURE__ */ jsxRuntime.jsx(
885
+ ui.Card,
886
+ {
887
+ shadow: 1,
888
+ radius: 3,
889
+ overflow: "hidden",
890
+ style: { position: "relative", height: "10px" },
891
+ children: /* @__PURE__ */ jsxRuntime.jsx(common.Hue, { hsl, onChange: !readOnly && onChange })
892
+ }
893
+ ),
894
+ !disableAlpha && /* @__PURE__ */ jsxRuntime.jsx(
895
+ ui.Card,
896
+ {
897
+ shadow: 1,
898
+ radius: 3,
899
+ overflow: "hidden",
900
+ style: { position: "relative", height: "10px", background: "#fff" },
901
+ children: /* @__PURE__ */ jsxRuntime.jsx(common.Alpha, { rgb, hsl, onChange })
902
+ }
903
+ )
904
+ ] }),
905
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
906
+ /* @__PURE__ */ jsxRuntime.jsxs(
907
+ ui.Card,
908
+ {
909
+ flex: 1,
910
+ radius: 2,
911
+ overflow: "hidden",
912
+ style: { position: "relative", minWidth: "4em", background: "#fff" },
913
+ children: [
914
+ /* @__PURE__ */ jsxRuntime.jsx(common.Checkboard, {}),
915
+ /* @__PURE__ */ jsxRuntime.jsx(
916
+ ColorBox,
917
+ {
918
+ style: {
919
+ backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`
920
+ }
1499
921
  }
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 = {
922
+ ),
923
+ readOnly && /* @__PURE__ */ jsxRuntime.jsx(
924
+ ReadOnlyContainer,
925
+ {
926
+ padding: 2,
927
+ paddingBottom: 1,
928
+ sizing: "border",
929
+ justify: "space-between",
930
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, marginTop: 1, children: [
931
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 3, weight: "bold", children: hex }),
932
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Inline, { space: 3, children: [
933
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
934
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "RGB: " }),
935
+ rgb?.r,
936
+ " ",
937
+ rgb?.g,
938
+ " ",
939
+ rgb?.b
940
+ ] }),
941
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
942
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "HSL: " }),
943
+ " ",
944
+ Math.round(hsl?.h ?? 0),
945
+ " ",
946
+ Math.round((hsl?.s ?? 0) * 100),
947
+ "% ",
948
+ Math.round((hsl?.l ?? 0) * 100),
949
+ "%"
950
+ ] })
951
+ ] })
952
+ ] })
953
+ }
954
+ )
955
+ ]
956
+ }
957
+ ),
958
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "flex-start", marginLeft: 2, children: [
959
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { width: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx(
960
+ ColorPickerFields,
961
+ {
962
+ rgb,
963
+ hsl,
964
+ hex,
965
+ onChange,
966
+ disableAlpha
967
+ }
968
+ ) }),
969
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginLeft: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: onUnset, title: "Delete color", icon: icons.TrashIcon, tone: "critical" }) })
970
+ ] })
971
+ ] }),
972
+ colorList && /* @__PURE__ */ jsxRuntime.jsx(ColorList, { colors: colorList, onChange })
973
+ ] }) }) });
974
+ }, ColorPicker = reactColor.CustomPicker(ColorPickerInner), DEFAULT_COLOR = {
1562
975
  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
- },
976
+ hsl: { h: 200, s: 0.7732, l: 0.5156, a: 1 },
977
+ hsv: { h: 200, s: 0.8414, v: 0.8901, a: 1 },
978
+ rgb: { r: 46, g: 163, b: 227, a: 1 },
1581
979
  source: "hex"
1582
980
  };
1583
981
  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);
1593
- 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]);
982
+ const { onChange, readOnly } = props, value = props.value, type = props.schemaType, focusRef = react.useRef(null), [color2, setColor] = react.useState(value);
983
+ react.useEffect(() => react.startTransition(() => setColor(value)), [value]);
984
+ const debouncedColor = react.useDeferredValue(color2), handleChange = useEffectEvent.useEffectEvent((nextColor) => {
985
+ const fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field) => {
986
+ const nextFieldValue = nextColor[field.name], isObject = field.type.jsonType === "object";
987
+ return sanity.set(
988
+ isObject ? Object.assign({ _type: field.type.name }, nextFieldValue) : nextFieldValue,
989
+ [field.name]
990
+ );
1602
991
  });
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]);
992
+ onChange([
993
+ sanity.setIfMissing({ _type: type.name }),
994
+ sanity.set(type.name, ["_type"]),
995
+ sanity.set(nextColor.rgb?.a, ["alpha"]),
996
+ ...fieldPatches
997
+ ]);
998
+ });
999
+ react.useEffect(() => {
1000
+ if (!debouncedColor) return;
1001
+ const raf = requestAnimationFrame(() => handleChange(debouncedColor));
1002
+ return () => cancelAnimationFrame(raf);
1003
+ }, [debouncedColor, handleChange]);
1612
1004
  const handleCreateColor = react.useCallback(() => {
1613
1005
  setColor(DEFAULT_COLOR);
1614
- emitSetColor(DEFAULT_COLOR);
1615
- }, [emitSetColor]);
1616
- const handleUnset = react.useCallback(() => {
1617
- setColor(void 0);
1618
- onChange(sanity.unset());
1006
+ }, []), handleUnset = react.useCallback(() => {
1007
+ setColor(void 0), onChange(sanity.unset());
1619
1008
  }, [onChange]);
1620
- return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
1621
- children: value && value.hex ? /* @__PURE__ */jsxRuntime.jsx(ColorPicker, {
1622
- color,
1623
- 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,
1009
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value && value.hex ? /* @__PURE__ */ jsxRuntime.jsx(
1010
+ ColorPicker,
1011
+ {
1012
+ color: color2,
1013
+ onChange: setColor,
1014
+ readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly,
1015
+ disableAlpha: !!type.options?.disableAlpha,
1016
+ colorList: type.options?.colorList,
1627
1017
  onUnset: handleUnset
1628
- }) : /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
1018
+ }
1019
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1020
+ ui.Button,
1021
+ {
1629
1022
  icon: icons.AddIcon,
1630
1023
  mode: "ghost",
1631
1024
  text: "Create color",
1632
1025
  ref: focusRef,
1633
- disabled: Boolean(readOnly),
1026
+ disabled: !!readOnly,
1634
1027
  onClick: handleCreateColor
1635
- })
1636
- });
1028
+ }
1029
+ ) });
1637
1030
  }
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({
1031
+ const round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = sanity.defineType({
1644
1032
  name: colorTypeName,
1645
1033
  type: "object",
1646
1034
  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
- }],
1035
+ components: { input: ColorInput },
1036
+ fields: [
1037
+ {
1038
+ title: "Hex",
1039
+ name: "hex",
1040
+ type: "string"
1041
+ },
1042
+ {
1043
+ title: "Alpha",
1044
+ name: "alpha",
1045
+ type: "number"
1046
+ },
1047
+ {
1048
+ title: "Hue Saturation Lightness",
1049
+ name: "hsl",
1050
+ type: "hslaColor"
1051
+ },
1052
+ {
1053
+ title: "Hue Saturation Value",
1054
+ name: "hsv",
1055
+ type: "hsvaColor"
1056
+ },
1057
+ {
1058
+ title: "Red Green Blue (rgb)",
1059
+ name: "rgb",
1060
+ type: "rgbaColor"
1061
+ }
1062
+ ],
1671
1063
  preview: {
1672
1064
  select: {
1673
1065
  title: "hex",
@@ -1675,58 +1067,64 @@ const color = sanity.defineType({
1675
1067
  hex: "hex",
1676
1068
  hsl: "hsl"
1677
1069
  },
1678
- prepare(_ref4) {
1679
- let {
1680
- title,
1681
- hex,
1682
- hsl,
1683
- alpha
1684
- } = _ref4;
1070
+ prepare({
1071
+ title,
1072
+ hex,
1073
+ hsl,
1074
+ alpha
1075
+ }) {
1685
1076
  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 {
1077
+ return hsl && (subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`), {
1690
1078
  title,
1691
1079
  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"
1080
+ media: () => /* @__PURE__ */ jsxRuntime.jsx(
1081
+ "div",
1082
+ {
1083
+ style: {
1084
+ backgroundColor: hex ?? "#000",
1085
+ opacity: alpha ?? 1,
1086
+ position: "absolute",
1087
+ height: "100%",
1088
+ width: "100%",
1089
+ top: "0",
1090
+ left: "0"
1091
+ }
1701
1092
  }
1702
- })
1093
+ )
1703
1094
  };
1704
1095
  }
1705
1096
  }
1706
- });
1707
- const hsvaColor = sanity.defineType({
1097
+ }), hslaColor = sanity.defineType({
1098
+ title: "Hue Saturation Lightness",
1099
+ name: "hslaColor",
1100
+ type: "object",
1101
+ fields: [
1102
+ { name: "h", type: "number", title: "Hue" },
1103
+ { name: "s", type: "number", title: "Saturation" },
1104
+ { name: "l", type: "number", title: "Lightness" },
1105
+ { name: "a", type: "number", title: "Alpha" }
1106
+ ]
1107
+ }), hsvaColor = sanity.defineType({
1708
1108
  title: "Hue Saturation Value",
1709
1109
  name: "hsvaColor",
1710
1110
  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({
1111
+ fields: [
1112
+ { name: "h", type: "number", title: "Hue" },
1113
+ { name: "s", type: "number", title: "Saturation" },
1114
+ { name: "v", type: "number", title: "Value" },
1115
+ { name: "a", type: "number", title: "Alpha" }
1116
+ ]
1117
+ }), rgbaColor = sanity.defineType({
1118
+ title: "Red Green Blue (rgb)",
1119
+ name: "rgbaColor",
1120
+ type: "object",
1121
+ fields: [
1122
+ { name: "r", type: "number", title: "Red" },
1123
+ { name: "g", type: "number", title: "Green" },
1124
+ { name: "b", type: "number", title: "Blue" },
1125
+ { name: "a", type: "number", title: "Alpha" }
1126
+ ]
1127
+ }), colorInput = sanity.definePlugin({
1730
1128
  name: "@sanity/color-input",
1731
1129
  schema: {
1732
1130
  types: [hslaColor, hsvaColor, rgbaColor, color]