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