@sanity/color-input 3.0.2 → 3.1.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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var _templateObject, _templateObject2;
3
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
4
4
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
5
5
  Object.defineProperty(exports, '__esModule', {
6
6
  value: true
@@ -185,8 +185,1226 @@ const ColorPickerFields = _ref => {
185
185
  })]
186
186
  });
187
187
  };
188
- const ColorBox = styled__default.default(ui.Box)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n"])));
189
- const ReadOnlyContainer = styled__default.default(ui.Flex)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n"])));
188
+
189
+ // This file is autogenerated. It's used to publish ESM to npm.
190
+ function _typeof(obj) {
191
+ "@babel/helpers - typeof";
192
+
193
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
194
+ return typeof obj;
195
+ } : function (obj) {
196
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
197
+ }, _typeof(obj);
198
+ }
199
+
200
+ // https://github.com/bgrins/TinyColor
201
+ // Brian Grinstead, MIT License
202
+
203
+ var trimLeft = /^\s+/;
204
+ var trimRight = /\s+$/;
205
+ function tinycolor(color, opts) {
206
+ color = color ? color : "";
207
+ opts = opts || {};
208
+
209
+ // If input is already a tinycolor, return itself
210
+ if (color instanceof tinycolor) {
211
+ return color;
212
+ }
213
+ // If we are called as a function, call using new instead
214
+ if (!(this instanceof tinycolor)) {
215
+ return new tinycolor(color, opts);
216
+ }
217
+ var rgb = inputToRGB(color);
218
+ 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;
219
+ this._gradientType = opts.gradientType;
220
+
221
+ // Don't let the range of [0,255] come back in [0,1].
222
+ // Potentially lose a little bit of precision here, but will fix issues where
223
+ // .5 gets interpreted as half of the total, instead of half of 1
224
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
225
+ if (this._r < 1) this._r = Math.round(this._r);
226
+ if (this._g < 1) this._g = Math.round(this._g);
227
+ if (this._b < 1) this._b = Math.round(this._b);
228
+ this._ok = rgb.ok;
229
+ }
230
+ tinycolor.prototype = {
231
+ isDark: function isDark() {
232
+ return this.getBrightness() < 128;
233
+ },
234
+ isLight: function isLight() {
235
+ return !this.isDark();
236
+ },
237
+ isValid: function isValid() {
238
+ return this._ok;
239
+ },
240
+ getOriginalInput: function getOriginalInput() {
241
+ return this._originalInput;
242
+ },
243
+ getFormat: function getFormat() {
244
+ return this._format;
245
+ },
246
+ getAlpha: function getAlpha() {
247
+ return this._a;
248
+ },
249
+ getBrightness: function getBrightness() {
250
+ //http://www.w3.org/TR/AERT#color-contrast
251
+ var rgb = this.toRgb();
252
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
253
+ },
254
+ getLuminance: function getLuminance() {
255
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
256
+ var rgb = this.toRgb();
257
+ var RsRGB, GsRGB, BsRGB, R, G, B;
258
+ RsRGB = rgb.r / 255;
259
+ GsRGB = rgb.g / 255;
260
+ BsRGB = rgb.b / 255;
261
+ if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
262
+ if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
263
+ if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
264
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
265
+ },
266
+ setAlpha: function setAlpha(value) {
267
+ this._a = boundAlpha(value);
268
+ this._roundA = Math.round(100 * this._a) / 100;
269
+ return this;
270
+ },
271
+ toHsv: function toHsv() {
272
+ var hsv = rgbToHsv(this._r, this._g, this._b);
273
+ return {
274
+ h: hsv.h * 360,
275
+ s: hsv.s,
276
+ v: hsv.v,
277
+ a: this._a
278
+ };
279
+ },
280
+ toHsvString: function toHsvString() {
281
+ var hsv = rgbToHsv(this._r, this._g, this._b);
282
+ var h = Math.round(hsv.h * 360),
283
+ s = Math.round(hsv.s * 100),
284
+ v = Math.round(hsv.v * 100);
285
+ return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
286
+ },
287
+ toHsl: function toHsl() {
288
+ var hsl = rgbToHsl(this._r, this._g, this._b);
289
+ return {
290
+ h: hsl.h * 360,
291
+ s: hsl.s,
292
+ l: hsl.l,
293
+ a: this._a
294
+ };
295
+ },
296
+ toHslString: function toHslString() {
297
+ var hsl = rgbToHsl(this._r, this._g, this._b);
298
+ var h = Math.round(hsl.h * 360),
299
+ s = Math.round(hsl.s * 100),
300
+ l = Math.round(hsl.l * 100);
301
+ return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
302
+ },
303
+ toHex: function toHex(allow3Char) {
304
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
305
+ },
306
+ toHexString: function toHexString(allow3Char) {
307
+ return "#" + this.toHex(allow3Char);
308
+ },
309
+ toHex8: function toHex8(allow4Char) {
310
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
311
+ },
312
+ toHex8String: function toHex8String(allow4Char) {
313
+ return "#" + this.toHex8(allow4Char);
314
+ },
315
+ toRgb: function toRgb() {
316
+ return {
317
+ r: Math.round(this._r),
318
+ g: Math.round(this._g),
319
+ b: Math.round(this._b),
320
+ a: this._a
321
+ };
322
+ },
323
+ toRgbString: function toRgbString() {
324
+ 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 + ")";
325
+ },
326
+ toPercentageRgb: function toPercentageRgb() {
327
+ return {
328
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
329
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
330
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
331
+ a: this._a
332
+ };
333
+ },
334
+ toPercentageRgbString: function toPercentageRgbString() {
335
+ 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 + ")";
336
+ },
337
+ toName: function toName() {
338
+ if (this._a === 0) {
339
+ return "transparent";
340
+ }
341
+ if (this._a < 1) {
342
+ return false;
343
+ }
344
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
345
+ },
346
+ toFilter: function toFilter(secondColor) {
347
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
348
+ var secondHex8String = hex8String;
349
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
350
+ if (secondColor) {
351
+ var s = tinycolor(secondColor);
352
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
353
+ }
354
+ return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
355
+ },
356
+ toString: function toString(format) {
357
+ var formatSet = !!format;
358
+ format = format || this._format;
359
+ var formattedString = false;
360
+ var hasAlpha = this._a < 1 && this._a >= 0;
361
+ var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
362
+ if (needsAlphaFormat) {
363
+ // Special case for "transparent", all other non-alpha formats
364
+ // will return rgba when there is transparency.
365
+ if (format === "name" && this._a === 0) {
366
+ return this.toName();
367
+ }
368
+ return this.toRgbString();
369
+ }
370
+ if (format === "rgb") {
371
+ formattedString = this.toRgbString();
372
+ }
373
+ if (format === "prgb") {
374
+ formattedString = this.toPercentageRgbString();
375
+ }
376
+ if (format === "hex" || format === "hex6") {
377
+ formattedString = this.toHexString();
378
+ }
379
+ if (format === "hex3") {
380
+ formattedString = this.toHexString(true);
381
+ }
382
+ if (format === "hex4") {
383
+ formattedString = this.toHex8String(true);
384
+ }
385
+ if (format === "hex8") {
386
+ formattedString = this.toHex8String();
387
+ }
388
+ if (format === "name") {
389
+ formattedString = this.toName();
390
+ }
391
+ if (format === "hsl") {
392
+ formattedString = this.toHslString();
393
+ }
394
+ if (format === "hsv") {
395
+ formattedString = this.toHsvString();
396
+ }
397
+ return formattedString || this.toHexString();
398
+ },
399
+ clone: function clone() {
400
+ return tinycolor(this.toString());
401
+ },
402
+ _applyModification: function _applyModification(fn, args) {
403
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
404
+ this._r = color._r;
405
+ this._g = color._g;
406
+ this._b = color._b;
407
+ this.setAlpha(color._a);
408
+ return this;
409
+ },
410
+ lighten: function lighten() {
411
+ return this._applyModification(_lighten, arguments);
412
+ },
413
+ brighten: function brighten() {
414
+ return this._applyModification(_brighten, arguments);
415
+ },
416
+ darken: function darken() {
417
+ return this._applyModification(_darken, arguments);
418
+ },
419
+ desaturate: function desaturate() {
420
+ return this._applyModification(_desaturate, arguments);
421
+ },
422
+ saturate: function saturate() {
423
+ return this._applyModification(_saturate, arguments);
424
+ },
425
+ greyscale: function greyscale() {
426
+ return this._applyModification(_greyscale, arguments);
427
+ },
428
+ spin: function spin() {
429
+ return this._applyModification(_spin, arguments);
430
+ },
431
+ _applyCombination: function _applyCombination(fn, args) {
432
+ return fn.apply(null, [this].concat([].slice.call(args)));
433
+ },
434
+ analogous: function analogous() {
435
+ return this._applyCombination(_analogous, arguments);
436
+ },
437
+ complement: function complement() {
438
+ return this._applyCombination(_complement, arguments);
439
+ },
440
+ monochromatic: function monochromatic() {
441
+ return this._applyCombination(_monochromatic, arguments);
442
+ },
443
+ splitcomplement: function splitcomplement() {
444
+ return this._applyCombination(_splitcomplement, arguments);
445
+ },
446
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
447
+ // polyad: function (number) {
448
+ // return this._applyCombination(polyad, [number]);
449
+ // },
450
+ triad: function triad() {
451
+ return this._applyCombination(polyad, [3]);
452
+ },
453
+ tetrad: function tetrad() {
454
+ return this._applyCombination(polyad, [4]);
455
+ }
456
+ };
457
+
458
+ // If input is an object, force 1 into "1.0" to handle ratios properly
459
+ // String input requires "1.0" as input, so 1 will be treated as 1
460
+ tinycolor.fromRatio = function (color, opts) {
461
+ if (_typeof(color) == "object") {
462
+ var newColor = {};
463
+ for (var i in color) {
464
+ if (color.hasOwnProperty(i)) {
465
+ if (i === "a") {
466
+ newColor[i] = color[i];
467
+ } else {
468
+ newColor[i] = convertToPercentage(color[i]);
469
+ }
470
+ }
471
+ }
472
+ color = newColor;
473
+ }
474
+ return tinycolor(color, opts);
475
+ };
476
+
477
+ // Given a string or object, convert that input to RGB
478
+ // Possible string inputs:
479
+ //
480
+ // "red"
481
+ // "#f00" or "f00"
482
+ // "#ff0000" or "ff0000"
483
+ // "#ff000000" or "ff000000"
484
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
485
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
486
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
487
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
488
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
489
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
490
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
491
+ //
492
+ function inputToRGB(color) {
493
+ var rgb = {
494
+ r: 0,
495
+ g: 0,
496
+ b: 0
497
+ };
498
+ var a = 1;
499
+ var s = null;
500
+ var v = null;
501
+ var l = null;
502
+ var ok = false;
503
+ var format = false;
504
+ if (typeof color == "string") {
505
+ color = stringInputToObject(color);
506
+ }
507
+ if (_typeof(color) == "object") {
508
+ if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
509
+ rgb = rgbToRgb(color.r, color.g, color.b);
510
+ ok = true;
511
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
512
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
513
+ s = convertToPercentage(color.s);
514
+ v = convertToPercentage(color.v);
515
+ rgb = hsvToRgb(color.h, s, v);
516
+ ok = true;
517
+ format = "hsv";
518
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
519
+ s = convertToPercentage(color.s);
520
+ l = convertToPercentage(color.l);
521
+ rgb = hslToRgb(color.h, s, l);
522
+ ok = true;
523
+ format = "hsl";
524
+ }
525
+ if (color.hasOwnProperty("a")) {
526
+ a = color.a;
527
+ }
528
+ }
529
+ a = boundAlpha(a);
530
+ return {
531
+ ok: ok,
532
+ format: color.format || format,
533
+ r: Math.min(255, Math.max(rgb.r, 0)),
534
+ g: Math.min(255, Math.max(rgb.g, 0)),
535
+ b: Math.min(255, Math.max(rgb.b, 0)),
536
+ a: a
537
+ };
538
+ }
539
+
540
+ // Conversion Functions
541
+ // --------------------
542
+
543
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
544
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
545
+
546
+ // `rgbToRgb`
547
+ // Handle bounds / percentage checking to conform to CSS color spec
548
+ // <http://www.w3.org/TR/css3-color/>
549
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
550
+ // *Returns:* { r, g, b } in [0, 255]
551
+ function rgbToRgb(r, g, b) {
552
+ return {
553
+ r: bound01(r, 255) * 255,
554
+ g: bound01(g, 255) * 255,
555
+ b: bound01(b, 255) * 255
556
+ };
557
+ }
558
+
559
+ // `rgbToHsl`
560
+ // Converts an RGB color value to HSL.
561
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
562
+ // *Returns:* { h, s, l } in [0,1]
563
+ function rgbToHsl(r, g, b) {
564
+ r = bound01(r, 255);
565
+ g = bound01(g, 255);
566
+ b = bound01(b, 255);
567
+ var max = Math.max(r, g, b),
568
+ min = Math.min(r, g, b);
569
+ var h,
570
+ s,
571
+ l = (max + min) / 2;
572
+ if (max == min) {
573
+ h = s = 0; // achromatic
574
+ } else {
575
+ var d = max - min;
576
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
577
+ switch (max) {
578
+ case r:
579
+ h = (g - b) / d + (g < b ? 6 : 0);
580
+ break;
581
+ case g:
582
+ h = (b - r) / d + 2;
583
+ break;
584
+ case b:
585
+ h = (r - g) / d + 4;
586
+ break;
587
+ }
588
+ h /= 6;
589
+ }
590
+ return {
591
+ h: h,
592
+ s: s,
593
+ l: l
594
+ };
595
+ }
596
+
597
+ // `hslToRgb`
598
+ // Converts an HSL color value to RGB.
599
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
600
+ // *Returns:* { r, g, b } in the set [0, 255]
601
+ function hslToRgb(h, s, l) {
602
+ var r, g, b;
603
+ h = bound01(h, 360);
604
+ s = bound01(s, 100);
605
+ l = bound01(l, 100);
606
+ function hue2rgb(p, q, t) {
607
+ if (t < 0) t += 1;
608
+ if (t > 1) t -= 1;
609
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
610
+ if (t < 1 / 2) return q;
611
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
612
+ return p;
613
+ }
614
+ if (s === 0) {
615
+ r = g = b = l; // achromatic
616
+ } else {
617
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
618
+ var p = 2 * l - q;
619
+ r = hue2rgb(p, q, h + 1 / 3);
620
+ g = hue2rgb(p, q, h);
621
+ b = hue2rgb(p, q, h - 1 / 3);
622
+ }
623
+ return {
624
+ r: r * 255,
625
+ g: g * 255,
626
+ b: b * 255
627
+ };
628
+ }
629
+
630
+ // `rgbToHsv`
631
+ // Converts an RGB color value to HSV
632
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
633
+ // *Returns:* { h, s, v } in [0,1]
634
+ function rgbToHsv(r, g, b) {
635
+ r = bound01(r, 255);
636
+ g = bound01(g, 255);
637
+ b = bound01(b, 255);
638
+ var max = Math.max(r, g, b),
639
+ min = Math.min(r, g, b);
640
+ var h,
641
+ s,
642
+ v = max;
643
+ var d = max - min;
644
+ s = max === 0 ? 0 : d / max;
645
+ if (max == min) {
646
+ h = 0; // achromatic
647
+ } else {
648
+ switch (max) {
649
+ case r:
650
+ h = (g - b) / d + (g < b ? 6 : 0);
651
+ break;
652
+ case g:
653
+ h = (b - r) / d + 2;
654
+ break;
655
+ case b:
656
+ h = (r - g) / d + 4;
657
+ break;
658
+ }
659
+ h /= 6;
660
+ }
661
+ return {
662
+ h: h,
663
+ s: s,
664
+ v: v
665
+ };
666
+ }
667
+
668
+ // `hsvToRgb`
669
+ // Converts an HSV color value to RGB.
670
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
671
+ // *Returns:* { r, g, b } in the set [0, 255]
672
+ function hsvToRgb(h, s, v) {
673
+ h = bound01(h, 360) * 6;
674
+ s = bound01(s, 100);
675
+ v = bound01(v, 100);
676
+ var i = Math.floor(h),
677
+ f = h - i,
678
+ p = v * (1 - s),
679
+ q = v * (1 - f * s),
680
+ t = v * (1 - (1 - f) * s),
681
+ mod = i % 6,
682
+ r = [v, q, p, p, t, v][mod],
683
+ g = [t, v, v, q, p, p][mod],
684
+ b = [p, p, t, v, v, q][mod];
685
+ return {
686
+ r: r * 255,
687
+ g: g * 255,
688
+ b: b * 255
689
+ };
690
+ }
691
+
692
+ // `rgbToHex`
693
+ // Converts an RGB color to hex
694
+ // Assumes r, g, and b are contained in the set [0, 255]
695
+ // Returns a 3 or 6 character hex
696
+ function rgbToHex(r, g, b, allow3Char) {
697
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
698
+
699
+ // Return a 3 character hex if possible
700
+ 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)) {
701
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
702
+ }
703
+ return hex.join("");
704
+ }
705
+
706
+ // `rgbaToHex`
707
+ // Converts an RGBA color plus alpha transparency to hex
708
+ // Assumes r, g, b are contained in the set [0, 255] and
709
+ // a in [0, 1]. Returns a 4 or 8 character rgba hex
710
+ function rgbaToHex(r, g, b, a, allow4Char) {
711
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
712
+
713
+ // Return a 4 character hex if possible
714
+ 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)) {
715
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
716
+ }
717
+ return hex.join("");
718
+ }
719
+
720
+ // `rgbaToArgbHex`
721
+ // Converts an RGBA color to an ARGB Hex8 string
722
+ // Rarely used, but required for "toFilter()"
723
+ function rgbaToArgbHex(r, g, b, a) {
724
+ var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
725
+ return hex.join("");
726
+ }
727
+
728
+ // `equals`
729
+ // Can be called with any tinycolor input
730
+ tinycolor.equals = function (color1, color2) {
731
+ if (!color1 || !color2) return false;
732
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
733
+ };
734
+ tinycolor.random = function () {
735
+ return tinycolor.fromRatio({
736
+ r: Math.random(),
737
+ g: Math.random(),
738
+ b: Math.random()
739
+ });
740
+ };
741
+
742
+ // Modification Functions
743
+ // ----------------------
744
+ // Thanks to less.js for some of the basics here
745
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
746
+
747
+ function _desaturate(color, amount) {
748
+ amount = amount === 0 ? 0 : amount || 10;
749
+ var hsl = tinycolor(color).toHsl();
750
+ hsl.s -= amount / 100;
751
+ hsl.s = clamp01(hsl.s);
752
+ return tinycolor(hsl);
753
+ }
754
+ function _saturate(color, amount) {
755
+ amount = amount === 0 ? 0 : amount || 10;
756
+ var hsl = tinycolor(color).toHsl();
757
+ hsl.s += amount / 100;
758
+ hsl.s = clamp01(hsl.s);
759
+ return tinycolor(hsl);
760
+ }
761
+ function _greyscale(color) {
762
+ return tinycolor(color).desaturate(100);
763
+ }
764
+ function _lighten(color, amount) {
765
+ amount = amount === 0 ? 0 : amount || 10;
766
+ var hsl = tinycolor(color).toHsl();
767
+ hsl.l += amount / 100;
768
+ hsl.l = clamp01(hsl.l);
769
+ return tinycolor(hsl);
770
+ }
771
+ function _brighten(color, amount) {
772
+ amount = amount === 0 ? 0 : amount || 10;
773
+ var rgb = tinycolor(color).toRgb();
774
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
775
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
776
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
777
+ return tinycolor(rgb);
778
+ }
779
+ function _darken(color, amount) {
780
+ amount = amount === 0 ? 0 : amount || 10;
781
+ var hsl = tinycolor(color).toHsl();
782
+ hsl.l -= amount / 100;
783
+ hsl.l = clamp01(hsl.l);
784
+ return tinycolor(hsl);
785
+ }
786
+
787
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
788
+ // Values outside of this range will be wrapped into this range.
789
+ function _spin(color, amount) {
790
+ var hsl = tinycolor(color).toHsl();
791
+ var hue = (hsl.h + amount) % 360;
792
+ hsl.h = hue < 0 ? 360 + hue : hue;
793
+ return tinycolor(hsl);
794
+ }
795
+
796
+ // Combination Functions
797
+ // ---------------------
798
+ // Thanks to jQuery xColor for some of the ideas behind these
799
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
800
+
801
+ function _complement(color) {
802
+ var hsl = tinycolor(color).toHsl();
803
+ hsl.h = (hsl.h + 180) % 360;
804
+ return tinycolor(hsl);
805
+ }
806
+ function polyad(color, number) {
807
+ if (isNaN(number) || number <= 0) {
808
+ throw new Error("Argument to polyad must be a positive number");
809
+ }
810
+ var hsl = tinycolor(color).toHsl();
811
+ var result = [tinycolor(color)];
812
+ var step = 360 / number;
813
+ for (var i = 1; i < number; i++) {
814
+ result.push(tinycolor({
815
+ h: (hsl.h + i * step) % 360,
816
+ s: hsl.s,
817
+ l: hsl.l
818
+ }));
819
+ }
820
+ return result;
821
+ }
822
+ function _splitcomplement(color) {
823
+ var hsl = tinycolor(color).toHsl();
824
+ var h = hsl.h;
825
+ return [tinycolor(color), tinycolor({
826
+ h: (h + 72) % 360,
827
+ s: hsl.s,
828
+ l: hsl.l
829
+ }), tinycolor({
830
+ h: (h + 216) % 360,
831
+ s: hsl.s,
832
+ l: hsl.l
833
+ })];
834
+ }
835
+ function _analogous(color, results, slices) {
836
+ results = results || 6;
837
+ slices = slices || 30;
838
+ var hsl = tinycolor(color).toHsl();
839
+ var part = 360 / slices;
840
+ var ret = [tinycolor(color)];
841
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
842
+ hsl.h = (hsl.h + part) % 360;
843
+ ret.push(tinycolor(hsl));
844
+ }
845
+ return ret;
846
+ }
847
+ function _monochromatic(color, results) {
848
+ results = results || 6;
849
+ var hsv = tinycolor(color).toHsv();
850
+ var h = hsv.h,
851
+ s = hsv.s,
852
+ v = hsv.v;
853
+ var ret = [];
854
+ var modification = 1 / results;
855
+ while (results--) {
856
+ ret.push(tinycolor({
857
+ h: h,
858
+ s: s,
859
+ v: v
860
+ }));
861
+ v = (v + modification) % 1;
862
+ }
863
+ return ret;
864
+ }
865
+
866
+ // Utility Functions
867
+ // ---------------------
868
+
869
+ tinycolor.mix = function (color1, color2, amount) {
870
+ amount = amount === 0 ? 0 : amount || 50;
871
+ var rgb1 = tinycolor(color1).toRgb();
872
+ var rgb2 = tinycolor(color2).toRgb();
873
+ var p = amount / 100;
874
+ var rgba = {
875
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
876
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
877
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
878
+ a: (rgb2.a - rgb1.a) * p + rgb1.a
879
+ };
880
+ return tinycolor(rgba);
881
+ };
882
+
883
+ // Readability Functions
884
+ // ---------------------
885
+ // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
886
+
887
+ // `contrast`
888
+ // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
889
+ tinycolor.readability = function (color1, color2) {
890
+ var c1 = tinycolor(color1);
891
+ var c2 = tinycolor(color2);
892
+ return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
893
+ };
894
+
895
+ // `isReadable`
896
+ // Ensure that foreground and background color combinations meet WCAG2 guidelines.
897
+ // The third argument is an optional Object.
898
+ // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
899
+ // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
900
+ // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
901
+
902
+ // *Example*
903
+ // tinycolor.isReadable("#000", "#111") => false
904
+ // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
905
+ tinycolor.isReadable = function (color1, color2, wcag2) {
906
+ var readability = tinycolor.readability(color1, color2);
907
+ var wcag2Parms, out;
908
+ out = false;
909
+ wcag2Parms = validateWCAG2Parms(wcag2);
910
+ switch (wcag2Parms.level + wcag2Parms.size) {
911
+ case "AAsmall":
912
+ case "AAAlarge":
913
+ out = readability >= 4.5;
914
+ break;
915
+ case "AAlarge":
916
+ out = readability >= 3;
917
+ break;
918
+ case "AAAsmall":
919
+ out = readability >= 7;
920
+ break;
921
+ }
922
+ return out;
923
+ };
924
+
925
+ // `mostReadable`
926
+ // Given a base color and a list of possible foreground or background
927
+ // colors for that base, returns the most readable color.
928
+ // Optionally returns Black or White if the most readable color is unreadable.
929
+ // *Example*
930
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
931
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
932
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
933
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
934
+ tinycolor.mostReadable = function (baseColor, colorList, args) {
935
+ var bestColor = null;
936
+ var bestScore = 0;
937
+ var readability;
938
+ var includeFallbackColors, level, size;
939
+ args = args || {};
940
+ includeFallbackColors = args.includeFallbackColors;
941
+ level = args.level;
942
+ size = args.size;
943
+ for (var i = 0; i < colorList.length; i++) {
944
+ readability = tinycolor.readability(baseColor, colorList[i]);
945
+ if (readability > bestScore) {
946
+ bestScore = readability;
947
+ bestColor = tinycolor(colorList[i]);
948
+ }
949
+ }
950
+ if (tinycolor.isReadable(baseColor, bestColor, {
951
+ level: level,
952
+ size: size
953
+ }) || !includeFallbackColors) {
954
+ return bestColor;
955
+ } else {
956
+ args.includeFallbackColors = false;
957
+ return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
958
+ }
959
+ };
960
+
961
+ // Big List of Colors
962
+ // ------------------
963
+ // <https://www.w3.org/TR/css-color-4/#named-colors>
964
+ var names = tinycolor.names = {
965
+ aliceblue: "f0f8ff",
966
+ antiquewhite: "faebd7",
967
+ aqua: "0ff",
968
+ aquamarine: "7fffd4",
969
+ azure: "f0ffff",
970
+ beige: "f5f5dc",
971
+ bisque: "ffe4c4",
972
+ black: "000",
973
+ blanchedalmond: "ffebcd",
974
+ blue: "00f",
975
+ blueviolet: "8a2be2",
976
+ brown: "a52a2a",
977
+ burlywood: "deb887",
978
+ burntsienna: "ea7e5d",
979
+ cadetblue: "5f9ea0",
980
+ chartreuse: "7fff00",
981
+ chocolate: "d2691e",
982
+ coral: "ff7f50",
983
+ cornflowerblue: "6495ed",
984
+ cornsilk: "fff8dc",
985
+ crimson: "dc143c",
986
+ cyan: "0ff",
987
+ darkblue: "00008b",
988
+ darkcyan: "008b8b",
989
+ darkgoldenrod: "b8860b",
990
+ darkgray: "a9a9a9",
991
+ darkgreen: "006400",
992
+ darkgrey: "a9a9a9",
993
+ darkkhaki: "bdb76b",
994
+ darkmagenta: "8b008b",
995
+ darkolivegreen: "556b2f",
996
+ darkorange: "ff8c00",
997
+ darkorchid: "9932cc",
998
+ darkred: "8b0000",
999
+ darksalmon: "e9967a",
1000
+ darkseagreen: "8fbc8f",
1001
+ darkslateblue: "483d8b",
1002
+ darkslategray: "2f4f4f",
1003
+ darkslategrey: "2f4f4f",
1004
+ darkturquoise: "00ced1",
1005
+ darkviolet: "9400d3",
1006
+ deeppink: "ff1493",
1007
+ deepskyblue: "00bfff",
1008
+ dimgray: "696969",
1009
+ dimgrey: "696969",
1010
+ dodgerblue: "1e90ff",
1011
+ firebrick: "b22222",
1012
+ floralwhite: "fffaf0",
1013
+ forestgreen: "228b22",
1014
+ fuchsia: "f0f",
1015
+ gainsboro: "dcdcdc",
1016
+ ghostwhite: "f8f8ff",
1017
+ gold: "ffd700",
1018
+ goldenrod: "daa520",
1019
+ gray: "808080",
1020
+ green: "008000",
1021
+ greenyellow: "adff2f",
1022
+ grey: "808080",
1023
+ honeydew: "f0fff0",
1024
+ hotpink: "ff69b4",
1025
+ indianred: "cd5c5c",
1026
+ indigo: "4b0082",
1027
+ ivory: "fffff0",
1028
+ khaki: "f0e68c",
1029
+ lavender: "e6e6fa",
1030
+ lavenderblush: "fff0f5",
1031
+ lawngreen: "7cfc00",
1032
+ lemonchiffon: "fffacd",
1033
+ lightblue: "add8e6",
1034
+ lightcoral: "f08080",
1035
+ lightcyan: "e0ffff",
1036
+ lightgoldenrodyellow: "fafad2",
1037
+ lightgray: "d3d3d3",
1038
+ lightgreen: "90ee90",
1039
+ lightgrey: "d3d3d3",
1040
+ lightpink: "ffb6c1",
1041
+ lightsalmon: "ffa07a",
1042
+ lightseagreen: "20b2aa",
1043
+ lightskyblue: "87cefa",
1044
+ lightslategray: "789",
1045
+ lightslategrey: "789",
1046
+ lightsteelblue: "b0c4de",
1047
+ lightyellow: "ffffe0",
1048
+ lime: "0f0",
1049
+ limegreen: "32cd32",
1050
+ linen: "faf0e6",
1051
+ magenta: "f0f",
1052
+ maroon: "800000",
1053
+ mediumaquamarine: "66cdaa",
1054
+ mediumblue: "0000cd",
1055
+ mediumorchid: "ba55d3",
1056
+ mediumpurple: "9370db",
1057
+ mediumseagreen: "3cb371",
1058
+ mediumslateblue: "7b68ee",
1059
+ mediumspringgreen: "00fa9a",
1060
+ mediumturquoise: "48d1cc",
1061
+ mediumvioletred: "c71585",
1062
+ midnightblue: "191970",
1063
+ mintcream: "f5fffa",
1064
+ mistyrose: "ffe4e1",
1065
+ moccasin: "ffe4b5",
1066
+ navajowhite: "ffdead",
1067
+ navy: "000080",
1068
+ oldlace: "fdf5e6",
1069
+ olive: "808000",
1070
+ olivedrab: "6b8e23",
1071
+ orange: "ffa500",
1072
+ orangered: "ff4500",
1073
+ orchid: "da70d6",
1074
+ palegoldenrod: "eee8aa",
1075
+ palegreen: "98fb98",
1076
+ paleturquoise: "afeeee",
1077
+ palevioletred: "db7093",
1078
+ papayawhip: "ffefd5",
1079
+ peachpuff: "ffdab9",
1080
+ peru: "cd853f",
1081
+ pink: "ffc0cb",
1082
+ plum: "dda0dd",
1083
+ powderblue: "b0e0e6",
1084
+ purple: "800080",
1085
+ rebeccapurple: "663399",
1086
+ red: "f00",
1087
+ rosybrown: "bc8f8f",
1088
+ royalblue: "4169e1",
1089
+ saddlebrown: "8b4513",
1090
+ salmon: "fa8072",
1091
+ sandybrown: "f4a460",
1092
+ seagreen: "2e8b57",
1093
+ seashell: "fff5ee",
1094
+ sienna: "a0522d",
1095
+ silver: "c0c0c0",
1096
+ skyblue: "87ceeb",
1097
+ slateblue: "6a5acd",
1098
+ slategray: "708090",
1099
+ slategrey: "708090",
1100
+ snow: "fffafa",
1101
+ springgreen: "00ff7f",
1102
+ steelblue: "4682b4",
1103
+ tan: "d2b48c",
1104
+ teal: "008080",
1105
+ thistle: "d8bfd8",
1106
+ tomato: "ff6347",
1107
+ turquoise: "40e0d0",
1108
+ violet: "ee82ee",
1109
+ wheat: "f5deb3",
1110
+ white: "fff",
1111
+ whitesmoke: "f5f5f5",
1112
+ yellow: "ff0",
1113
+ yellowgreen: "9acd32"
1114
+ };
1115
+
1116
+ // Make it easy to access colors via `hexNames[hex]`
1117
+ var hexNames = tinycolor.hexNames = flip(names);
1118
+
1119
+ // Utilities
1120
+ // ---------
1121
+
1122
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
1123
+ function flip(o) {
1124
+ var flipped = {};
1125
+ for (var i in o) {
1126
+ if (o.hasOwnProperty(i)) {
1127
+ flipped[o[i]] = i;
1128
+ }
1129
+ }
1130
+ return flipped;
1131
+ }
1132
+
1133
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
1134
+ function boundAlpha(a) {
1135
+ a = parseFloat(a);
1136
+ if (isNaN(a) || a < 0 || a > 1) {
1137
+ a = 1;
1138
+ }
1139
+ return a;
1140
+ }
1141
+
1142
+ // Take input from [0, n] and return it as [0, 1]
1143
+ function bound01(n, max) {
1144
+ if (isOnePointZero(n)) n = "100%";
1145
+ var processPercent = isPercentage(n);
1146
+ n = Math.min(max, Math.max(0, parseFloat(n)));
1147
+
1148
+ // Automatically convert percentage into number
1149
+ if (processPercent) {
1150
+ n = parseInt(n * max, 10) / 100;
1151
+ }
1152
+
1153
+ // Handle floating point rounding errors
1154
+ if (Math.abs(n - max) < 0.000001) {
1155
+ return 1;
1156
+ }
1157
+
1158
+ // Convert into [0, 1] range if it isn't already
1159
+ return n % max / parseFloat(max);
1160
+ }
1161
+
1162
+ // Force a number between 0 and 1
1163
+ function clamp01(val) {
1164
+ return Math.min(1, Math.max(0, val));
1165
+ }
1166
+
1167
+ // Parse a base-16 hex value into a base-10 integer
1168
+ function parseIntFromHex(val) {
1169
+ return parseInt(val, 16);
1170
+ }
1171
+
1172
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
1173
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
1174
+ function isOnePointZero(n) {
1175
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
1176
+ }
1177
+
1178
+ // Check to see if string passed in is a percentage
1179
+ function isPercentage(n) {
1180
+ return typeof n === "string" && n.indexOf("%") != -1;
1181
+ }
1182
+
1183
+ // Force a hex value to have 2 characters
1184
+ function pad2(c) {
1185
+ return c.length == 1 ? "0" + c : "" + c;
1186
+ }
1187
+
1188
+ // Replace a decimal with it's percentage value
1189
+ function convertToPercentage(n) {
1190
+ if (n <= 1) {
1191
+ n = n * 100 + "%";
1192
+ }
1193
+ return n;
1194
+ }
1195
+
1196
+ // Converts a decimal to a hex value
1197
+ function convertDecimalToHex(d) {
1198
+ return Math.round(parseFloat(d) * 255).toString(16);
1199
+ }
1200
+ // Converts a hex value to a decimal
1201
+ function convertHexToDecimal(h) {
1202
+ return parseIntFromHex(h) / 255;
1203
+ }
1204
+ var matchers = function () {
1205
+ // <http://www.w3.org/TR/css3-values/#integers>
1206
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
1207
+
1208
+ // <http://www.w3.org/TR/css3-values/#number-value>
1209
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
1210
+
1211
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
1212
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
1213
+
1214
+ // Actual matching.
1215
+ // Parentheses and commas are optional, but not required.
1216
+ // Whitespace can take the place of commas or opening paren
1217
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1218
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1219
+ return {
1220
+ CSS_UNIT: new RegExp(CSS_UNIT),
1221
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
1222
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
1223
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
1224
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
1225
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
1226
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
1227
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1228
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1229
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1230
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1231
+ };
1232
+ }();
1233
+
1234
+ // `isValidCSSUnit`
1235
+ // Take in a single string / number and check to see if it looks like a CSS unit
1236
+ // (see `matchers` above for definition).
1237
+ function isValidCSSUnit(color) {
1238
+ return !!matchers.CSS_UNIT.exec(color);
1239
+ }
1240
+
1241
+ // `stringInputToObject`
1242
+ // Permissive string parsing. Take in a number of formats, and output an object
1243
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
1244
+ function stringInputToObject(color) {
1245
+ color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
1246
+ var named = false;
1247
+ if (names[color]) {
1248
+ color = names[color];
1249
+ named = true;
1250
+ } else if (color == "transparent") {
1251
+ return {
1252
+ r: 0,
1253
+ g: 0,
1254
+ b: 0,
1255
+ a: 0,
1256
+ format: "name"
1257
+ };
1258
+ }
1259
+
1260
+ // Try to match string input using regular expressions.
1261
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1262
+ // Just return an object and let the conversion functions handle that.
1263
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
1264
+ var match;
1265
+ if (match = matchers.rgb.exec(color)) {
1266
+ return {
1267
+ r: match[1],
1268
+ g: match[2],
1269
+ b: match[3]
1270
+ };
1271
+ }
1272
+ if (match = matchers.rgba.exec(color)) {
1273
+ return {
1274
+ r: match[1],
1275
+ g: match[2],
1276
+ b: match[3],
1277
+ a: match[4]
1278
+ };
1279
+ }
1280
+ if (match = matchers.hsl.exec(color)) {
1281
+ return {
1282
+ h: match[1],
1283
+ s: match[2],
1284
+ l: match[3]
1285
+ };
1286
+ }
1287
+ if (match = matchers.hsla.exec(color)) {
1288
+ return {
1289
+ h: match[1],
1290
+ s: match[2],
1291
+ l: match[3],
1292
+ a: match[4]
1293
+ };
1294
+ }
1295
+ if (match = matchers.hsv.exec(color)) {
1296
+ return {
1297
+ h: match[1],
1298
+ s: match[2],
1299
+ v: match[3]
1300
+ };
1301
+ }
1302
+ if (match = matchers.hsva.exec(color)) {
1303
+ return {
1304
+ h: match[1],
1305
+ s: match[2],
1306
+ v: match[3],
1307
+ a: match[4]
1308
+ };
1309
+ }
1310
+ if (match = matchers.hex8.exec(color)) {
1311
+ return {
1312
+ r: parseIntFromHex(match[1]),
1313
+ g: parseIntFromHex(match[2]),
1314
+ b: parseIntFromHex(match[3]),
1315
+ a: convertHexToDecimal(match[4]),
1316
+ format: named ? "name" : "hex8"
1317
+ };
1318
+ }
1319
+ if (match = matchers.hex6.exec(color)) {
1320
+ return {
1321
+ r: parseIntFromHex(match[1]),
1322
+ g: parseIntFromHex(match[2]),
1323
+ b: parseIntFromHex(match[3]),
1324
+ format: named ? "name" : "hex"
1325
+ };
1326
+ }
1327
+ if (match = matchers.hex4.exec(color)) {
1328
+ return {
1329
+ r: parseIntFromHex(match[1] + "" + match[1]),
1330
+ g: parseIntFromHex(match[2] + "" + match[2]),
1331
+ b: parseIntFromHex(match[3] + "" + match[3]),
1332
+ a: convertHexToDecimal(match[4] + "" + match[4]),
1333
+ format: named ? "name" : "hex8"
1334
+ };
1335
+ }
1336
+ if (match = matchers.hex3.exec(color)) {
1337
+ return {
1338
+ r: parseIntFromHex(match[1] + "" + match[1]),
1339
+ g: parseIntFromHex(match[2] + "" + match[2]),
1340
+ b: parseIntFromHex(match[3] + "" + match[3]),
1341
+ format: named ? "name" : "hex"
1342
+ };
1343
+ }
1344
+ return false;
1345
+ }
1346
+ function validateWCAG2Parms(parms) {
1347
+ // return valid WCAG2 parms for isReadable.
1348
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
1349
+ var level, size;
1350
+ parms = parms || {
1351
+ level: "AA",
1352
+ size: "small"
1353
+ };
1354
+ level = (parms.level || "AA").toUpperCase();
1355
+ size = (parms.size || "small").toLowerCase();
1356
+ if (level !== "AA" && level !== "AAA") {
1357
+ level = "AA";
1358
+ }
1359
+ if (size !== "small" && size !== "large") {
1360
+ size = "small";
1361
+ }
1362
+ return {
1363
+ level: level,
1364
+ size: size
1365
+ };
1366
+ }
1367
+ const ColorListWrap = styled__default.default(ui.Flex)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n gap: 0.25em;\n"])));
1368
+ const ColorBoxContainer = styled__default.default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\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"])));
1369
+ const ColorBox$1 = styled__default.default.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n content: '';\n position: absolute;\n inset: 0;\n z-index: 1;\n"])));
1370
+ const validateColors = colors => colors.reduce((cls, c) => {
1371
+ const color = c.hex ? tinycolor(c.hex) : tinycolor(c);
1372
+ if (color.isValid()) {
1373
+ cls.push({
1374
+ color: c,
1375
+ backgroundColor: color.toRgbString()
1376
+ });
1377
+ }
1378
+ return cls;
1379
+ }, []);
1380
+ const ColorList = _ref2 => {
1381
+ let {
1382
+ colors,
1383
+ onChange
1384
+ } = _ref2;
1385
+ if (!colors) return null;
1386
+ return /* @__PURE__ */jsxRuntime.jsx(ColorListWrap, {
1387
+ wrap: "wrap",
1388
+ children: validateColors(colors).map((_ref3, idx) => {
1389
+ let {
1390
+ color,
1391
+ backgroundColor
1392
+ } = _ref3;
1393
+ return /* @__PURE__ */jsxRuntime.jsx(ColorBoxContainer, {
1394
+ onClick: () => {
1395
+ onChange(color);
1396
+ },
1397
+ children: /* @__PURE__ */jsxRuntime.jsx(ColorBox$1, {
1398
+ style: {
1399
+ background: backgroundColor
1400
+ }
1401
+ })
1402
+ }, "".concat(backgroundColor, "-").concat(idx));
1403
+ })
1404
+ });
1405
+ };
1406
+ const ColorBox = styled__default.default(ui.Box)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n"])));
1407
+ const ReadOnlyContainer = styled__default.default(ui.Flex)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n"])));
190
1408
  const ColorPickerInner = props => {
191
1409
  var _a, _b, _c;
192
1410
  const {
@@ -200,6 +1418,7 @@ const ColorPickerInner = props => {
200
1418
  onChange,
201
1419
  onUnset,
202
1420
  disableAlpha,
1421
+ colorList,
203
1422
  readOnly
204
1423
  } = props;
205
1424
  if (!hsl || !hsv) {
@@ -245,7 +1464,8 @@ const ColorPickerInner = props => {
245
1464
  overflow: "hidden",
246
1465
  style: {
247
1466
  position: "relative",
248
- height: "10px"
1467
+ height: "10px",
1468
+ background: "#fff"
249
1469
  },
250
1470
  children: /* @__PURE__ */jsxRuntime.jsx(common.Alpha, {
251
1471
  rgb,
@@ -260,7 +1480,8 @@ const ColorPickerInner = props => {
260
1480
  overflow: "hidden",
261
1481
  style: {
262
1482
  position: "relative",
263
- minWidth: "4em"
1483
+ minWidth: "4em",
1484
+ background: "#fff"
264
1485
  },
265
1486
  children: [/* @__PURE__ */jsxRuntime.jsx(common.Checkboard, {}), /* @__PURE__ */jsxRuntime.jsx(ColorBox, {
266
1487
  style: {
@@ -318,6 +1539,9 @@ const ColorPickerInner = props => {
318
1539
  })
319
1540
  })]
320
1541
  })]
1542
+ }), colorList && /* @__PURE__ */jsxRuntime.jsx(ColorList, {
1543
+ colors: colorList,
1544
+ onChange
321
1545
  })]
322
1546
  })
323
1547
  })
@@ -347,7 +1571,7 @@ const DEFAULT_COLOR = {
347
1571
  source: "hex"
348
1572
  };
349
1573
  function ColorInput(props) {
350
- var _a;
1574
+ var _a, _b;
351
1575
  const {
352
1576
  onChange,
353
1577
  readOnly
@@ -389,6 +1613,7 @@ function ColorInput(props) {
389
1613
  onChange: handleColorChange,
390
1614
  readOnly: readOnly || typeof type.readOnly === "boolean" && type.readOnly,
391
1615
  disableAlpha: !!((_a = type.options) == null ? void 0 : _a.disableAlpha),
1616
+ colorList: (_b = type.options) == null ? void 0 : _b.colorList,
392
1617
  onUnset: handleUnset
393
1618
  }) : /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
394
1619
  icon: icons.AddIcon,
@@ -440,13 +1665,13 @@ const color = sanity.defineType({
440
1665
  hex: "hex",
441
1666
  hsl: "hsl"
442
1667
  },
443
- prepare(_ref2) {
1668
+ prepare(_ref4) {
444
1669
  let {
445
1670
  title,
446
1671
  hex,
447
1672
  hsl,
448
1673
  alpha
449
- } = _ref2;
1674
+ } = _ref4;
450
1675
  let subtitle = hex || "No color set";
451
1676
  if (hsl) {
452
1677
  subtitle = "H:".concat(round(hsl.h), " S:").concat(round(hsl.s), " L:").concat(round(hsl.l), " A:").concat(round(alpha));