@sanity/color-input 3.0.2 → 3.1.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,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var _templateObject, _templateObject2;
4
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
5
3
  Object.defineProperty(exports, '__esModule', {
6
4
  value: true
7
5
  });
@@ -185,10 +183,1240 @@ const ColorPickerFields = _ref => {
185
183
  })]
186
184
  });
187
185
  };
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"])));
186
+
187
+ // This file is autogenerated. It's used to publish ESM to npm.
188
+ function _typeof(obj) {
189
+ "@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;
195
+ }, _typeof(obj);
196
+ }
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;
227
+ }
228
+ tinycolor.prototype = {
229
+ isDark: function isDark() {
230
+ return this.getBrightness() < 128;
231
+ },
232
+ isLight: function isLight() {
233
+ return !this.isDark();
234
+ },
235
+ isValid: function isValid() {
236
+ return this._ok;
237
+ },
238
+ getOriginalInput: function getOriginalInput() {
239
+ return this._originalInput;
240
+ },
241
+ getFormat: function getFormat() {
242
+ return this._format;
243
+ },
244
+ getAlpha: function getAlpha() {
245
+ return this._a;
246
+ },
247
+ getBrightness: function getBrightness() {
248
+ //http://www.w3.org/TR/AERT#color-contrast
249
+ var rgb = this.toRgb();
250
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
251
+ },
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;
263
+ },
264
+ setAlpha: function setAlpha(value) {
265
+ this._a = boundAlpha(value);
266
+ this._roundA = Math.round(100 * this._a) / 100;
267
+ return this;
268
+ },
269
+ toHsv: function toHsv() {
270
+ var hsv = rgbToHsv(this._r, this._g, this._b);
271
+ return {
272
+ h: hsv.h * 360,
273
+ s: hsv.s,
274
+ v: hsv.v,
275
+ a: this._a
276
+ };
277
+ },
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);
283
+ return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
284
+ },
285
+ toHsl: function toHsl() {
286
+ var hsl = rgbToHsl(this._r, this._g, this._b);
287
+ return {
288
+ h: hsl.h * 360,
289
+ s: hsl.s,
290
+ l: hsl.l,
291
+ a: this._a
292
+ };
293
+ },
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);
299
+ return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
300
+ },
301
+ toHex: function toHex(allow3Char) {
302
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
303
+ },
304
+ toHexString: function toHexString(allow3Char) {
305
+ return "#" + this.toHex(allow3Char);
306
+ },
307
+ toHex8: function toHex8(allow4Char) {
308
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
309
+ },
310
+ toHex8String: function toHex8String(allow4Char) {
311
+ return "#" + this.toHex8(allow4Char);
312
+ },
313
+ toRgb: function toRgb() {
314
+ return {
315
+ r: Math.round(this._r),
316
+ g: Math.round(this._g),
317
+ b: Math.round(this._b),
318
+ a: this._a
319
+ };
320
+ },
321
+ toRgbString: function toRgbString() {
322
+ 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
+ },
324
+ toPercentageRgb: function toPercentageRgb() {
325
+ return {
326
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
327
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
328
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
329
+ a: this._a
330
+ };
331
+ },
332
+ toPercentageRgbString: function toPercentageRgbString() {
333
+ 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
+ },
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;
343
+ },
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, " : "";
348
+ if (secondColor) {
349
+ var s = tinycolor(secondColor);
350
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
351
+ }
352
+ return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
353
+ },
354
+ toString: function toString(format) {
355
+ var formatSet = !!format;
356
+ 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();
396
+ },
397
+ clone: function clone() {
398
+ return tinycolor(this.toString());
399
+ },
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;
407
+ },
408
+ lighten: function lighten() {
409
+ return this._applyModification(_lighten, arguments);
410
+ },
411
+ brighten: function brighten() {
412
+ return this._applyModification(_brighten, arguments);
413
+ },
414
+ darken: function darken() {
415
+ return this._applyModification(_darken, arguments);
416
+ },
417
+ desaturate: function desaturate() {
418
+ return this._applyModification(_desaturate, arguments);
419
+ },
420
+ saturate: function saturate() {
421
+ return this._applyModification(_saturate, arguments);
422
+ },
423
+ greyscale: function greyscale() {
424
+ return this._applyModification(_greyscale, arguments);
425
+ },
426
+ spin: function spin() {
427
+ return this._applyModification(_spin, arguments);
428
+ },
429
+ _applyCombination: function _applyCombination(fn, args) {
430
+ return fn.apply(null, [this].concat([].slice.call(args)));
431
+ },
432
+ analogous: function analogous() {
433
+ return this._applyCombination(_analogous, arguments);
434
+ },
435
+ complement: function complement() {
436
+ return this._applyCombination(_complement, arguments);
437
+ },
438
+ monochromatic: function monochromatic() {
439
+ return this._applyCombination(_monochromatic, arguments);
440
+ },
441
+ splitcomplement: function splitcomplement() {
442
+ return this._applyCombination(_splitcomplement, arguments);
443
+ },
444
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
445
+ // polyad: function (number) {
446
+ // return this._applyCombination(polyad, [number]);
447
+ // },
448
+ triad: function triad() {
449
+ return this._applyCombination(polyad, [3]);
450
+ },
451
+ tetrad: function tetrad() {
452
+ return this._applyCombination(polyad, [4]);
453
+ }
454
+ };
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") {
460
+ 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;
471
+ }
472
+ return tinycolor(color, opts);
473
+ };
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) {
491
+ var rgb = {
492
+ r: 0,
493
+ g: 0,
494
+ 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,
531
+ r: Math.min(255, Math.max(rgb.r, 0)),
532
+ g: Math.min(255, Math.max(rgb.g, 0)),
533
+ b: Math.min(255, Math.max(rgb.b, 0)),
534
+ a: a
535
+ };
536
+ }
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
+ function rgbToRgb(r, g, b) {
550
+ return {
551
+ r: bound01(r, 255) * 255,
552
+ g: bound01(g, 255) * 255,
553
+ b: bound01(b, 255) * 255
554
+ };
555
+ }
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
+ 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 {
573
+ var d = max - min;
574
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
575
+ switch (max) {
576
+ case r:
577
+ h = (g - b) / d + (g < b ? 6 : 0);
578
+ break;
579
+ case g:
580
+ h = (b - r) / d + 2;
581
+ break;
582
+ case b:
583
+ h = (r - g) / d + 4;
584
+ break;
585
+ }
586
+ h /= 6;
587
+ }
588
+ return {
589
+ h: h,
590
+ s: s,
591
+ l: l
592
+ };
593
+ }
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
+ function hslToRgb(h, s, l) {
600
+ 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;
611
+ }
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);
620
+ }
621
+ return {
622
+ r: r * 255,
623
+ g: g * 255,
624
+ b: b * 255
625
+ };
626
+ }
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
+ 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 {
646
+ switch (max) {
647
+ case r:
648
+ h = (g - b) / d + (g < b ? 6 : 0);
649
+ break;
650
+ case g:
651
+ h = (b - r) / d + 2;
652
+ break;
653
+ case b:
654
+ h = (r - g) / d + 4;
655
+ break;
656
+ }
657
+ h /= 6;
658
+ }
659
+ return {
660
+ h: h,
661
+ s: s,
662
+ v: v
663
+ };
664
+ }
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
+ 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];
683
+ return {
684
+ r: r * 255,
685
+ g: g * 255,
686
+ b: b * 255
687
+ };
688
+ }
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
+ function rgbToHex(r, g, b, allow3Char) {
695
+ 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("");
702
+ }
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
+ function rgbaToHex(r, g, b, a, allow4Char) {
709
+ 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("");
716
+ }
717
+
718
+ // `rgbaToArgbHex`
719
+ // Converts an RGBA color to an ARGB Hex8 string
720
+ // Rarely used, but required for "toFilter()"
721
+ function rgbaToArgbHex(r, g, b, a) {
722
+ var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
723
+ return hex.join("");
724
+ }
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();
731
+ };
732
+ tinycolor.random = function () {
733
+ return tinycolor.fromRatio({
734
+ r: Math.random(),
735
+ g: Math.random(),
736
+ b: Math.random()
737
+ });
738
+ };
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) {
746
+ 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);
751
+ }
752
+ function _saturate(color, amount) {
753
+ 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);
758
+ }
759
+ function _greyscale(color) {
760
+ return tinycolor(color).desaturate(100);
761
+ }
762
+ function _lighten(color, amount) {
763
+ 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);
768
+ }
769
+ function _brighten(color, amount) {
770
+ 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);
776
+ }
777
+ function _darken(color, amount) {
778
+ 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);
783
+ }
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);
792
+ }
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);
803
+ }
804
+ function polyad(color, number) {
805
+ if (isNaN(number) || number <= 0) {
806
+ 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++) {
812
+ result.push(tinycolor({
813
+ h: (hsl.h + i * step) % 360,
814
+ s: hsl.s,
815
+ l: hsl.l
816
+ }));
817
+ }
818
+ return result;
819
+ }
820
+ function _splitcomplement(color) {
821
+ var hsl = tinycolor(color).toHsl();
822
+ var h = hsl.h;
823
+ return [tinycolor(color), tinycolor({
824
+ h: (h + 72) % 360,
825
+ s: hsl.s,
826
+ l: hsl.l
827
+ }), tinycolor({
828
+ h: (h + 216) % 360,
829
+ s: hsl.s,
830
+ l: hsl.l
831
+ })];
832
+ }
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
+ }
843
+ return ret;
844
+ }
845
+ function _monochromatic(color, results) {
846
+ 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--) {
854
+ ret.push(tinycolor({
855
+ h: h,
856
+ s: s,
857
+ v: v
858
+ }));
859
+ v = (v + modification) % 1;
860
+ }
861
+ return ret;
862
+ }
863
+
864
+ // Utility Functions
865
+ // ---------------------
866
+
867
+ tinycolor.mix = function (color1, color2, amount) {
868
+ 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 = {
873
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
874
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
875
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
876
+ a: (rgb2.a - rgb1.a) * p + rgb1.a
877
+ };
878
+ return tinycolor(rgba);
879
+ };
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);
890
+ return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
891
+ };
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) {
909
+ case "AAsmall":
910
+ case "AAAlarge":
911
+ out = readability >= 4.5;
912
+ break;
913
+ case "AAlarge":
914
+ out = readability >= 3;
915
+ break;
916
+ case "AAAsmall":
917
+ out = readability >= 7;
918
+ break;
919
+ }
920
+ return out;
921
+ };
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
+ }
957
+ };
958
+
959
+ // Big List of Colors
960
+ // ------------------
961
+ // <https://www.w3.org/TR/css-color-4/#named-colors>
962
+ var names = tinycolor.names = {
963
+ aliceblue: "f0f8ff",
964
+ antiquewhite: "faebd7",
965
+ aqua: "0ff",
966
+ aquamarine: "7fffd4",
967
+ azure: "f0ffff",
968
+ beige: "f5f5dc",
969
+ bisque: "ffe4c4",
970
+ black: "000",
971
+ blanchedalmond: "ffebcd",
972
+ blue: "00f",
973
+ blueviolet: "8a2be2",
974
+ brown: "a52a2a",
975
+ burlywood: "deb887",
976
+ burntsienna: "ea7e5d",
977
+ cadetblue: "5f9ea0",
978
+ chartreuse: "7fff00",
979
+ chocolate: "d2691e",
980
+ coral: "ff7f50",
981
+ cornflowerblue: "6495ed",
982
+ cornsilk: "fff8dc",
983
+ crimson: "dc143c",
984
+ cyan: "0ff",
985
+ darkblue: "00008b",
986
+ darkcyan: "008b8b",
987
+ darkgoldenrod: "b8860b",
988
+ darkgray: "a9a9a9",
989
+ darkgreen: "006400",
990
+ darkgrey: "a9a9a9",
991
+ darkkhaki: "bdb76b",
992
+ darkmagenta: "8b008b",
993
+ darkolivegreen: "556b2f",
994
+ darkorange: "ff8c00",
995
+ darkorchid: "9932cc",
996
+ darkred: "8b0000",
997
+ darksalmon: "e9967a",
998
+ darkseagreen: "8fbc8f",
999
+ darkslateblue: "483d8b",
1000
+ darkslategray: "2f4f4f",
1001
+ darkslategrey: "2f4f4f",
1002
+ darkturquoise: "00ced1",
1003
+ darkviolet: "9400d3",
1004
+ deeppink: "ff1493",
1005
+ deepskyblue: "00bfff",
1006
+ dimgray: "696969",
1007
+ dimgrey: "696969",
1008
+ dodgerblue: "1e90ff",
1009
+ firebrick: "b22222",
1010
+ floralwhite: "fffaf0",
1011
+ forestgreen: "228b22",
1012
+ fuchsia: "f0f",
1013
+ gainsboro: "dcdcdc",
1014
+ ghostwhite: "f8f8ff",
1015
+ gold: "ffd700",
1016
+ goldenrod: "daa520",
1017
+ gray: "808080",
1018
+ green: "008000",
1019
+ greenyellow: "adff2f",
1020
+ grey: "808080",
1021
+ honeydew: "f0fff0",
1022
+ hotpink: "ff69b4",
1023
+ indianred: "cd5c5c",
1024
+ indigo: "4b0082",
1025
+ ivory: "fffff0",
1026
+ khaki: "f0e68c",
1027
+ lavender: "e6e6fa",
1028
+ lavenderblush: "fff0f5",
1029
+ lawngreen: "7cfc00",
1030
+ lemonchiffon: "fffacd",
1031
+ lightblue: "add8e6",
1032
+ lightcoral: "f08080",
1033
+ lightcyan: "e0ffff",
1034
+ lightgoldenrodyellow: "fafad2",
1035
+ lightgray: "d3d3d3",
1036
+ lightgreen: "90ee90",
1037
+ lightgrey: "d3d3d3",
1038
+ lightpink: "ffb6c1",
1039
+ lightsalmon: "ffa07a",
1040
+ lightseagreen: "20b2aa",
1041
+ lightskyblue: "87cefa",
1042
+ lightslategray: "789",
1043
+ lightslategrey: "789",
1044
+ lightsteelblue: "b0c4de",
1045
+ lightyellow: "ffffe0",
1046
+ lime: "0f0",
1047
+ limegreen: "32cd32",
1048
+ linen: "faf0e6",
1049
+ magenta: "f0f",
1050
+ maroon: "800000",
1051
+ mediumaquamarine: "66cdaa",
1052
+ mediumblue: "0000cd",
1053
+ mediumorchid: "ba55d3",
1054
+ mediumpurple: "9370db",
1055
+ mediumseagreen: "3cb371",
1056
+ mediumslateblue: "7b68ee",
1057
+ mediumspringgreen: "00fa9a",
1058
+ mediumturquoise: "48d1cc",
1059
+ mediumvioletred: "c71585",
1060
+ midnightblue: "191970",
1061
+ mintcream: "f5fffa",
1062
+ mistyrose: "ffe4e1",
1063
+ moccasin: "ffe4b5",
1064
+ navajowhite: "ffdead",
1065
+ navy: "000080",
1066
+ oldlace: "fdf5e6",
1067
+ olive: "808000",
1068
+ olivedrab: "6b8e23",
1069
+ orange: "ffa500",
1070
+ orangered: "ff4500",
1071
+ orchid: "da70d6",
1072
+ palegoldenrod: "eee8aa",
1073
+ palegreen: "98fb98",
1074
+ paleturquoise: "afeeee",
1075
+ palevioletred: "db7093",
1076
+ papayawhip: "ffefd5",
1077
+ peachpuff: "ffdab9",
1078
+ peru: "cd853f",
1079
+ pink: "ffc0cb",
1080
+ plum: "dda0dd",
1081
+ powderblue: "b0e0e6",
1082
+ purple: "800080",
1083
+ rebeccapurple: "663399",
1084
+ red: "f00",
1085
+ rosybrown: "bc8f8f",
1086
+ royalblue: "4169e1",
1087
+ saddlebrown: "8b4513",
1088
+ salmon: "fa8072",
1089
+ sandybrown: "f4a460",
1090
+ seagreen: "2e8b57",
1091
+ seashell: "fff5ee",
1092
+ sienna: "a0522d",
1093
+ silver: "c0c0c0",
1094
+ skyblue: "87ceeb",
1095
+ slateblue: "6a5acd",
1096
+ slategray: "708090",
1097
+ slategrey: "708090",
1098
+ snow: "fffafa",
1099
+ springgreen: "00ff7f",
1100
+ steelblue: "4682b4",
1101
+ tan: "d2b48c",
1102
+ teal: "008080",
1103
+ thistle: "d8bfd8",
1104
+ tomato: "ff6347",
1105
+ turquoise: "40e0d0",
1106
+ violet: "ee82ee",
1107
+ wheat: "f5deb3",
1108
+ white: "fff",
1109
+ whitesmoke: "f5f5f5",
1110
+ yellow: "ff0",
1111
+ 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' }`
1121
+ function flip(o) {
1122
+ var flipped = {};
1123
+ for (var i in o) {
1124
+ if (o.hasOwnProperty(i)) {
1125
+ flipped[o[i]] = i;
1126
+ }
1127
+ }
1128
+ return flipped;
1129
+ }
1130
+
1131
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
1132
+ function boundAlpha(a) {
1133
+ a = parseFloat(a);
1134
+ if (isNaN(a) || a < 0 || a > 1) {
1135
+ a = 1;
1136
+ }
1137
+ return a;
1138
+ }
1139
+
1140
+ // Take input from [0, n] and return it as [0, 1]
1141
+ function bound01(n, max) {
1142
+ if (isOnePointZero(n)) n = "100%";
1143
+ 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);
1158
+ }
1159
+
1160
+ // Force a number between 0 and 1
1161
+ function clamp01(val) {
1162
+ return Math.min(1, Math.max(0, val));
1163
+ }
1164
+
1165
+ // Parse a base-16 hex value into a base-10 integer
1166
+ function parseIntFromHex(val) {
1167
+ return parseInt(val, 16);
1168
+ }
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
+ function isOnePointZero(n) {
1173
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
1174
+ }
1175
+
1176
+ // Check to see if string passed in is a percentage
1177
+ function isPercentage(n) {
1178
+ return typeof n === "string" && n.indexOf("%") != -1;
1179
+ }
1180
+
1181
+ // Force a hex value to have 2 characters
1182
+ function pad2(c) {
1183
+ return c.length == 1 ? "0" + c : "" + c;
1184
+ }
1185
+
1186
+ // Replace a decimal with it's percentage value
1187
+ function convertToPercentage(n) {
1188
+ if (n <= 1) {
1189
+ n = n * 100 + "%";
1190
+ }
1191
+ return n;
1192
+ }
1193
+
1194
+ // Converts a decimal to a hex value
1195
+ function convertDecimalToHex(d) {
1196
+ return Math.round(parseFloat(d) * 255).toString(16);
1197
+ }
1198
+ // Converts a hex value to a decimal
1199
+ function convertHexToDecimal(h) {
1200
+ return parseIntFromHex(h) / 255;
1201
+ }
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*\\)?";
1217
+ return {
1218
+ CSS_UNIT: new RegExp(CSS_UNIT),
1219
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
1220
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
1221
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
1222
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
1223
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
1224
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
1225
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1226
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1227
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1228
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1229
+ };
1230
+ }();
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);
1237
+ }
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") {
1249
+ return {
1250
+ r: 0,
1251
+ g: 0,
1252
+ b: 0,
1253
+ a: 0,
1254
+ format: "name"
1255
+ };
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
+ 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;
1343
+ }
1344
+ function validateWCAG2Parms(parms) {
1345
+ // return valid WCAG2 parms for isReadable.
1346
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
1347
+ var level, size;
1348
+ parms = parms || {
1349
+ level: "AA",
1350
+ 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
1363
+ };
1364
+ }
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 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"])));
190
1418
  const ColorPickerInner = props => {
191
- var _a, _b, _c;
1419
+ var _a2, _b2, _c;
192
1420
  const {
193
1421
  width,
194
1422
  color: {
@@ -200,6 +1428,7 @@ const ColorPickerInner = props => {
200
1428
  onChange,
201
1429
  onUnset,
202
1430
  disableAlpha,
1431
+ colorList,
203
1432
  readOnly
204
1433
  } = props;
205
1434
  if (!hsl || !hsv) {
@@ -245,7 +1474,8 @@ const ColorPickerInner = props => {
245
1474
  overflow: "hidden",
246
1475
  style: {
247
1476
  position: "relative",
248
- height: "10px"
1477
+ height: "10px",
1478
+ background: "#fff"
249
1479
  },
250
1480
  children: /* @__PURE__ */jsxRuntime.jsx(common.Alpha, {
251
1481
  rgb,
@@ -260,7 +1490,8 @@ const ColorPickerInner = props => {
260
1490
  overflow: "hidden",
261
1491
  style: {
262
1492
  position: "relative",
263
- minWidth: "4em"
1493
+ minWidth: "4em",
1494
+ background: "#fff"
264
1495
  },
265
1496
  children: [/* @__PURE__ */jsxRuntime.jsx(common.Checkboard, {}), /* @__PURE__ */jsxRuntime.jsx(ColorBox, {
266
1497
  style: {
@@ -289,7 +1520,7 @@ const ColorPickerInner = props => {
289
1520
  size: 1,
290
1521
  children: [/* @__PURE__ */jsxRuntime.jsx("strong", {
291
1522
  children: "HSL: "
292
- }), " ", Math.round((_a = hsl == null ? void 0 : hsl.h) != null ? _a : 0), " ", Math.round((_b = hsl == null ? void 0 : hsl.s) != null ? _b : 0), "%", " ", Math.round((_c = hsl == null ? void 0 : hsl.l) != null ? _c : 0)]
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), "%", " ", Math.round((_c = hsl == null ? void 0 : hsl.l) != null ? _c : 0)]
293
1524
  })]
294
1525
  })]
295
1526
  })
@@ -318,6 +1549,9 @@ const ColorPickerInner = props => {
318
1549
  })
319
1550
  })]
320
1551
  })]
1552
+ }), colorList && /* @__PURE__ */jsxRuntime.jsx(ColorList, {
1553
+ colors: colorList,
1554
+ onChange
321
1555
  })]
322
1556
  })
323
1557
  })
@@ -347,7 +1581,7 @@ const DEFAULT_COLOR = {
347
1581
  source: "hex"
348
1582
  };
349
1583
  function ColorInput(props) {
350
- var _a;
1584
+ var _a, _b;
351
1585
  const {
352
1586
  onChange,
353
1587
  readOnly
@@ -389,6 +1623,7 @@ function ColorInput(props) {
389
1623
  onChange: handleColorChange,
390
1624
  readOnly: readOnly || typeof type.readOnly === "boolean" && type.readOnly,
391
1625
  disableAlpha: !!((_a = type.options) == null ? void 0 : _a.disableAlpha),
1626
+ colorList: (_b = type.options) == null ? void 0 : _b.colorList,
392
1627
  onUnset: handleUnset
393
1628
  }) : /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
394
1629
  icon: icons.AddIcon,
@@ -440,13 +1675,13 @@ const color = sanity.defineType({
440
1675
  hex: "hex",
441
1676
  hsl: "hsl"
442
1677
  },
443
- prepare(_ref2) {
1678
+ prepare(_ref4) {
444
1679
  let {
445
1680
  title,
446
1681
  hex,
447
1682
  hsl,
448
1683
  alpha
449
- } = _ref2;
1684
+ } = _ref4;
450
1685
  let subtitle = hex || "No color set";
451
1686
  if (hsl) {
452
1687
  subtitle = "H:".concat(round(hsl.h), " S:").concat(round(hsl.s), " L:").concat(round(hsl.l), " A:").concat(round(alpha));