react-globe.gl 2.22.9 → 2.22.10

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.
@@ -1,4 +1,4 @@
1
- // Version 2.22.9 react-globe.gl - https://github.com/vasturiano/react-globe.gl
1
+ // Version 2.22.10 react-globe.gl - https://github.com/vasturiano/react-globe.gl
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
4
4
  typeof define === 'function' && define.amd ? define(['react'], factory) :
@@ -42318,20 +42318,20 @@
42318
42318
 
42319
42319
  var _bfg = /*#__PURE__*/Object.freeze({
42320
42320
  __proto__: null,
42321
+ computeMikkTSpaceTangents: computeMikkTSpaceTangents,
42322
+ computeMorphedAttributes: computeMorphedAttributes,
42323
+ computeTangents: computeTangents,
42321
42324
  deepCloneAttribute: deepCloneAttribute,
42322
42325
  deinterleaveAttribute: deinterleaveAttribute,
42323
42326
  deinterleaveGeometry: deinterleaveGeometry,
42324
- computeTangents: computeTangents,
42325
- computeMikkTSpaceTangents: computeMikkTSpaceTangents,
42326
- mergeBufferGeometries: mergeBufferGeometries,
42327
- mergeBufferAttributes: mergeBufferAttributes,
42328
- interleaveAttributes: interleaveAttributes,
42329
42327
  estimateBytesUsed: estimateBytesUsed,
42330
- mergeVertices: mergeVertices,
42331
- toTrianglesDrawMode: toTrianglesDrawMode,
42332
- computeMorphedAttributes: computeMorphedAttributes,
42328
+ interleaveAttributes: interleaveAttributes,
42329
+ mergeBufferAttributes: mergeBufferAttributes,
42330
+ mergeBufferGeometries: mergeBufferGeometries,
42333
42331
  mergeGroups: mergeGroups,
42334
- toCreasedNormals: toCreasedNormals
42332
+ mergeVertices: mergeVertices,
42333
+ toCreasedNormals: toCreasedNormals,
42334
+ toTrianglesDrawMode: toTrianglesDrawMode
42335
42335
  });
42336
42336
 
42337
42337
  var index$1 = (function (p) {
@@ -42344,1207 +42344,1282 @@
42344
42344
  };
42345
42345
  }); // constant
42346
42346
 
42347
- var tinycolorExports = {};
42348
- var tinycolor = {
42349
- get exports(){ return tinycolorExports; },
42350
- set exports(v){ tinycolorExports = v; },
42347
+ // This file is autogenerated. It's used to publish ESM to npm.
42348
+ // https://github.com/bgrins/TinyColor
42349
+ // Brian Grinstead, MIT License
42350
+
42351
+ const trimLeft = /^\s+/;
42352
+ const trimRight = /\s+$/;
42353
+
42354
+ function tinycolor(color, opts) {
42355
+ color = color ? color : "";
42356
+ opts = opts || {};
42357
+
42358
+ // If input is already a tinycolor, return itself
42359
+ if (color instanceof tinycolor) {
42360
+ return color;
42361
+ }
42362
+ // If we are called as a function, call using new instead
42363
+ if (!(this instanceof tinycolor)) {
42364
+ return new tinycolor(color, opts);
42365
+ }
42366
+
42367
+ var rgb = inputToRGB(color);
42368
+ (this._originalInput = color),
42369
+ (this._r = rgb.r),
42370
+ (this._g = rgb.g),
42371
+ (this._b = rgb.b),
42372
+ (this._a = rgb.a),
42373
+ (this._roundA = Math.round(100 * this._a) / 100),
42374
+ (this._format = opts.format || rgb.format);
42375
+ this._gradientType = opts.gradientType;
42376
+
42377
+ // Don't let the range of [0,255] come back in [0,1].
42378
+ // Potentially lose a little bit of precision here, but will fix issues where
42379
+ // .5 gets interpreted as half of the total, instead of half of 1
42380
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
42381
+ if (this._r < 1) this._r = Math.round(this._r);
42382
+ if (this._g < 1) this._g = Math.round(this._g);
42383
+ if (this._b < 1) this._b = Math.round(this._b);
42384
+
42385
+ this._ok = rgb.ok;
42386
+ }
42387
+
42388
+ tinycolor.prototype = {
42389
+ isDark: function () {
42390
+ return this.getBrightness() < 128;
42391
+ },
42392
+ isLight: function () {
42393
+ return !this.isDark();
42394
+ },
42395
+ isValid: function () {
42396
+ return this._ok;
42397
+ },
42398
+ getOriginalInput: function () {
42399
+ return this._originalInput;
42400
+ },
42401
+ getFormat: function () {
42402
+ return this._format;
42403
+ },
42404
+ getAlpha: function () {
42405
+ return this._a;
42406
+ },
42407
+ getBrightness: function () {
42408
+ //http://www.w3.org/TR/AERT#color-contrast
42409
+ var rgb = this.toRgb();
42410
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
42411
+ },
42412
+ getLuminance: function () {
42413
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
42414
+ var rgb = this.toRgb();
42415
+ var RsRGB, GsRGB, BsRGB, R, G, B;
42416
+ RsRGB = rgb.r / 255;
42417
+ GsRGB = rgb.g / 255;
42418
+ BsRGB = rgb.b / 255;
42419
+
42420
+ if (RsRGB <= 0.03928) R = RsRGB / 12.92;
42421
+ else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
42422
+ if (GsRGB <= 0.03928) G = GsRGB / 12.92;
42423
+ else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
42424
+ if (BsRGB <= 0.03928) B = BsRGB / 12.92;
42425
+ else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
42426
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
42427
+ },
42428
+ setAlpha: function (value) {
42429
+ this._a = boundAlpha(value);
42430
+ this._roundA = Math.round(100 * this._a) / 100;
42431
+ return this;
42432
+ },
42433
+ toHsv: function () {
42434
+ var hsv = rgbToHsv(this._r, this._g, this._b);
42435
+ return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
42436
+ },
42437
+ toHsvString: function () {
42438
+ var hsv = rgbToHsv(this._r, this._g, this._b);
42439
+ var h = Math.round(hsv.h * 360),
42440
+ s = Math.round(hsv.s * 100),
42441
+ v = Math.round(hsv.v * 100);
42442
+ return this._a == 1
42443
+ ? "hsv(" + h + ", " + s + "%, " + v + "%)"
42444
+ : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
42445
+ },
42446
+ toHsl: function () {
42447
+ var hsl = rgbToHsl(this._r, this._g, this._b);
42448
+ return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
42449
+ },
42450
+ toHslString: function () {
42451
+ var hsl = rgbToHsl(this._r, this._g, this._b);
42452
+ var h = Math.round(hsl.h * 360),
42453
+ s = Math.round(hsl.s * 100),
42454
+ l = Math.round(hsl.l * 100);
42455
+ return this._a == 1
42456
+ ? "hsl(" + h + ", " + s + "%, " + l + "%)"
42457
+ : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
42458
+ },
42459
+ toHex: function (allow3Char) {
42460
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
42461
+ },
42462
+ toHexString: function (allow3Char) {
42463
+ return "#" + this.toHex(allow3Char);
42464
+ },
42465
+ toHex8: function (allow4Char) {
42466
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
42467
+ },
42468
+ toHex8String: function (allow4Char) {
42469
+ return "#" + this.toHex8(allow4Char);
42470
+ },
42471
+ toRgb: function () {
42472
+ return {
42473
+ r: Math.round(this._r),
42474
+ g: Math.round(this._g),
42475
+ b: Math.round(this._b),
42476
+ a: this._a,
42477
+ };
42478
+ },
42479
+ toRgbString: function () {
42480
+ return this._a == 1
42481
+ ? "rgb(" +
42482
+ Math.round(this._r) +
42483
+ ", " +
42484
+ Math.round(this._g) +
42485
+ ", " +
42486
+ Math.round(this._b) +
42487
+ ")"
42488
+ : "rgba(" +
42489
+ Math.round(this._r) +
42490
+ ", " +
42491
+ Math.round(this._g) +
42492
+ ", " +
42493
+ Math.round(this._b) +
42494
+ ", " +
42495
+ this._roundA +
42496
+ ")";
42497
+ },
42498
+ toPercentageRgb: function () {
42499
+ return {
42500
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
42501
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
42502
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
42503
+ a: this._a,
42504
+ };
42505
+ },
42506
+ toPercentageRgbString: function () {
42507
+ return this._a == 1
42508
+ ? "rgb(" +
42509
+ Math.round(bound01(this._r, 255) * 100) +
42510
+ "%, " +
42511
+ Math.round(bound01(this._g, 255) * 100) +
42512
+ "%, " +
42513
+ Math.round(bound01(this._b, 255) * 100) +
42514
+ "%)"
42515
+ : "rgba(" +
42516
+ Math.round(bound01(this._r, 255) * 100) +
42517
+ "%, " +
42518
+ Math.round(bound01(this._g, 255) * 100) +
42519
+ "%, " +
42520
+ Math.round(bound01(this._b, 255) * 100) +
42521
+ "%, " +
42522
+ this._roundA +
42523
+ ")";
42524
+ },
42525
+ toName: function () {
42526
+ if (this._a === 0) {
42527
+ return "transparent";
42528
+ }
42529
+
42530
+ if (this._a < 1) {
42531
+ return false;
42532
+ }
42533
+
42534
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
42535
+ },
42536
+ toFilter: function (secondColor) {
42537
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
42538
+ var secondHex8String = hex8String;
42539
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
42540
+
42541
+ if (secondColor) {
42542
+ var s = tinycolor(secondColor);
42543
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
42544
+ }
42545
+
42546
+ return (
42547
+ "progid:DXImageTransform.Microsoft.gradient(" +
42548
+ gradientType +
42549
+ "startColorstr=" +
42550
+ hex8String +
42551
+ ",endColorstr=" +
42552
+ secondHex8String +
42553
+ ")"
42554
+ );
42555
+ },
42556
+ toString: function (format) {
42557
+ var formatSet = !!format;
42558
+ format = format || this._format;
42559
+
42560
+ var formattedString = false;
42561
+ var hasAlpha = this._a < 1 && this._a >= 0;
42562
+ var needsAlphaFormat =
42563
+ !formatSet &&
42564
+ hasAlpha &&
42565
+ (format === "hex" ||
42566
+ format === "hex6" ||
42567
+ format === "hex3" ||
42568
+ format === "hex4" ||
42569
+ format === "hex8" ||
42570
+ format === "name");
42571
+
42572
+ if (needsAlphaFormat) {
42573
+ // Special case for "transparent", all other non-alpha formats
42574
+ // will return rgba when there is transparency.
42575
+ if (format === "name" && this._a === 0) {
42576
+ return this.toName();
42577
+ }
42578
+ return this.toRgbString();
42579
+ }
42580
+ if (format === "rgb") {
42581
+ formattedString = this.toRgbString();
42582
+ }
42583
+ if (format === "prgb") {
42584
+ formattedString = this.toPercentageRgbString();
42585
+ }
42586
+ if (format === "hex" || format === "hex6") {
42587
+ formattedString = this.toHexString();
42588
+ }
42589
+ if (format === "hex3") {
42590
+ formattedString = this.toHexString(true);
42591
+ }
42592
+ if (format === "hex4") {
42593
+ formattedString = this.toHex8String(true);
42594
+ }
42595
+ if (format === "hex8") {
42596
+ formattedString = this.toHex8String();
42597
+ }
42598
+ if (format === "name") {
42599
+ formattedString = this.toName();
42600
+ }
42601
+ if (format === "hsl") {
42602
+ formattedString = this.toHslString();
42603
+ }
42604
+ if (format === "hsv") {
42605
+ formattedString = this.toHsvString();
42606
+ }
42607
+
42608
+ return formattedString || this.toHexString();
42609
+ },
42610
+ clone: function () {
42611
+ return tinycolor(this.toString());
42612
+ },
42613
+
42614
+ _applyModification: function (fn, args) {
42615
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
42616
+ this._r = color._r;
42617
+ this._g = color._g;
42618
+ this._b = color._b;
42619
+ this.setAlpha(color._a);
42620
+ return this;
42621
+ },
42622
+ lighten: function () {
42623
+ return this._applyModification(lighten, arguments);
42624
+ },
42625
+ brighten: function () {
42626
+ return this._applyModification(brighten, arguments);
42627
+ },
42628
+ darken: function () {
42629
+ return this._applyModification(darken, arguments);
42630
+ },
42631
+ desaturate: function () {
42632
+ return this._applyModification(desaturate, arguments);
42633
+ },
42634
+ saturate: function () {
42635
+ return this._applyModification(saturate, arguments);
42636
+ },
42637
+ greyscale: function () {
42638
+ return this._applyModification(greyscale, arguments);
42639
+ },
42640
+ spin: function () {
42641
+ return this._applyModification(spin, arguments);
42642
+ },
42643
+
42644
+ _applyCombination: function (fn, args) {
42645
+ return fn.apply(null, [this].concat([].slice.call(args)));
42646
+ },
42647
+ analogous: function () {
42648
+ return this._applyCombination(analogous, arguments);
42649
+ },
42650
+ complement: function () {
42651
+ return this._applyCombination(complement, arguments);
42652
+ },
42653
+ monochromatic: function () {
42654
+ return this._applyCombination(monochromatic, arguments);
42655
+ },
42656
+ splitcomplement: function () {
42657
+ return this._applyCombination(splitcomplement, arguments);
42658
+ },
42659
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
42660
+ // polyad: function (number) {
42661
+ // return this._applyCombination(polyad, [number]);
42662
+ // },
42663
+ triad: function () {
42664
+ return this._applyCombination(polyad, [3]);
42665
+ },
42666
+ tetrad: function () {
42667
+ return this._applyCombination(polyad, [4]);
42668
+ },
42351
42669
  };
42352
42670
 
42353
- (function (module) {
42354
- // TinyColor v1.4.2
42355
- // https://github.com/bgrins/TinyColor
42356
- // Brian Grinstead, MIT License
42357
-
42358
- (function(Math) {
42359
-
42360
- var trimLeft = /^\s+/,
42361
- trimRight = /\s+$/,
42362
- tinyCounter = 0,
42363
- mathRound = Math.round,
42364
- mathMin = Math.min,
42365
- mathMax = Math.max,
42366
- mathRandom = Math.random;
42367
-
42368
- function tinycolor (color, opts) {
42369
-
42370
- color = (color) ? color : '';
42371
- opts = opts || { };
42372
-
42373
- // If input is already a tinycolor, return itself
42374
- if (color instanceof tinycolor) {
42375
- return color;
42376
- }
42377
- // If we are called as a function, call using new instead
42378
- if (!(this instanceof tinycolor)) {
42379
- return new tinycolor(color, opts);
42380
- }
42381
-
42382
- var rgb = inputToRGB(color);
42383
- this._originalInput = color,
42384
- this._r = rgb.r,
42385
- this._g = rgb.g,
42386
- this._b = rgb.b,
42387
- this._a = rgb.a,
42388
- this._roundA = mathRound(100*this._a) / 100,
42389
- this._format = opts.format || rgb.format;
42390
- this._gradientType = opts.gradientType;
42391
-
42392
- // Don't let the range of [0,255] come back in [0,1].
42393
- // Potentially lose a little bit of precision here, but will fix issues where
42394
- // .5 gets interpreted as half of the total, instead of half of 1
42395
- // If it was supposed to be 128, this was already taken care of by `inputToRgb`
42396
- if (this._r < 1) { this._r = mathRound(this._r); }
42397
- if (this._g < 1) { this._g = mathRound(this._g); }
42398
- if (this._b < 1) { this._b = mathRound(this._b); }
42399
-
42400
- this._ok = rgb.ok;
42401
- this._tc_id = tinyCounter++;
42402
- }
42403
-
42404
- tinycolor.prototype = {
42405
- isDark: function() {
42406
- return this.getBrightness() < 128;
42407
- },
42408
- isLight: function() {
42409
- return !this.isDark();
42410
- },
42411
- isValid: function() {
42412
- return this._ok;
42413
- },
42414
- getOriginalInput: function() {
42415
- return this._originalInput;
42416
- },
42417
- getFormat: function() {
42418
- return this._format;
42419
- },
42420
- getAlpha: function() {
42421
- return this._a;
42422
- },
42423
- getBrightness: function() {
42424
- //http://www.w3.org/TR/AERT#color-contrast
42425
- var rgb = this.toRgb();
42426
- return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
42427
- },
42428
- getLuminance: function() {
42429
- //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
42430
- var rgb = this.toRgb();
42431
- var RsRGB, GsRGB, BsRGB, R, G, B;
42432
- RsRGB = rgb.r/255;
42433
- GsRGB = rgb.g/255;
42434
- BsRGB = rgb.b/255;
42435
-
42436
- if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
42437
- if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
42438
- if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
42439
- return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
42440
- },
42441
- setAlpha: function(value) {
42442
- this._a = boundAlpha(value);
42443
- this._roundA = mathRound(100*this._a) / 100;
42444
- return this;
42445
- },
42446
- toHsv: function() {
42447
- var hsv = rgbToHsv(this._r, this._g, this._b);
42448
- return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
42449
- },
42450
- toHsvString: function() {
42451
- var hsv = rgbToHsv(this._r, this._g, this._b);
42452
- var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
42453
- return (this._a == 1) ?
42454
- "hsv(" + h + ", " + s + "%, " + v + "%)" :
42455
- "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
42456
- },
42457
- toHsl: function() {
42458
- var hsl = rgbToHsl(this._r, this._g, this._b);
42459
- return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
42460
- },
42461
- toHslString: function() {
42462
- var hsl = rgbToHsl(this._r, this._g, this._b);
42463
- var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
42464
- return (this._a == 1) ?
42465
- "hsl(" + h + ", " + s + "%, " + l + "%)" :
42466
- "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
42467
- },
42468
- toHex: function(allow3Char) {
42469
- return rgbToHex(this._r, this._g, this._b, allow3Char);
42470
- },
42471
- toHexString: function(allow3Char) {
42472
- return '#' + this.toHex(allow3Char);
42473
- },
42474
- toHex8: function(allow4Char) {
42475
- return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
42476
- },
42477
- toHex8String: function(allow4Char) {
42478
- return '#' + this.toHex8(allow4Char);
42479
- },
42480
- toRgb: function() {
42481
- return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
42482
- },
42483
- toRgbString: function() {
42484
- return (this._a == 1) ?
42485
- "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
42486
- "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
42487
- },
42488
- toPercentageRgb: function() {
42489
- return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
42490
- },
42491
- toPercentageRgbString: function() {
42492
- return (this._a == 1) ?
42493
- "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
42494
- "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
42495
- },
42496
- toName: function() {
42497
- if (this._a === 0) {
42498
- return "transparent";
42499
- }
42500
-
42501
- if (this._a < 1) {
42502
- return false;
42503
- }
42504
-
42505
- return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
42506
- },
42507
- toFilter: function(secondColor) {
42508
- var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
42509
- var secondHex8String = hex8String;
42510
- var gradientType = this._gradientType ? "GradientType = 1, " : "";
42511
-
42512
- if (secondColor) {
42513
- var s = tinycolor(secondColor);
42514
- secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
42515
- }
42516
-
42517
- return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
42518
- },
42519
- toString: function(format) {
42520
- var formatSet = !!format;
42521
- format = format || this._format;
42522
-
42523
- var formattedString = false;
42524
- var hasAlpha = this._a < 1 && this._a >= 0;
42525
- var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
42526
-
42527
- if (needsAlphaFormat) {
42528
- // Special case for "transparent", all other non-alpha formats
42529
- // will return rgba when there is transparency.
42530
- if (format === "name" && this._a === 0) {
42531
- return this.toName();
42532
- }
42533
- return this.toRgbString();
42534
- }
42535
- if (format === "rgb") {
42536
- formattedString = this.toRgbString();
42537
- }
42538
- if (format === "prgb") {
42539
- formattedString = this.toPercentageRgbString();
42540
- }
42541
- if (format === "hex" || format === "hex6") {
42542
- formattedString = this.toHexString();
42543
- }
42544
- if (format === "hex3") {
42545
- formattedString = this.toHexString(true);
42546
- }
42547
- if (format === "hex4") {
42548
- formattedString = this.toHex8String(true);
42549
- }
42550
- if (format === "hex8") {
42551
- formattedString = this.toHex8String();
42552
- }
42553
- if (format === "name") {
42554
- formattedString = this.toName();
42555
- }
42556
- if (format === "hsl") {
42557
- formattedString = this.toHslString();
42558
- }
42559
- if (format === "hsv") {
42560
- formattedString = this.toHsvString();
42561
- }
42562
-
42563
- return formattedString || this.toHexString();
42564
- },
42565
- clone: function() {
42566
- return tinycolor(this.toString());
42567
- },
42568
-
42569
- _applyModification: function(fn, args) {
42570
- var color = fn.apply(null, [this].concat([].slice.call(args)));
42571
- this._r = color._r;
42572
- this._g = color._g;
42573
- this._b = color._b;
42574
- this.setAlpha(color._a);
42575
- return this;
42576
- },
42577
- lighten: function() {
42578
- return this._applyModification(lighten, arguments);
42579
- },
42580
- brighten: function() {
42581
- return this._applyModification(brighten, arguments);
42582
- },
42583
- darken: function() {
42584
- return this._applyModification(darken, arguments);
42585
- },
42586
- desaturate: function() {
42587
- return this._applyModification(desaturate, arguments);
42588
- },
42589
- saturate: function() {
42590
- return this._applyModification(saturate, arguments);
42591
- },
42592
- greyscale: function() {
42593
- return this._applyModification(greyscale, arguments);
42594
- },
42595
- spin: function() {
42596
- return this._applyModification(spin, arguments);
42597
- },
42598
-
42599
- _applyCombination: function(fn, args) {
42600
- return fn.apply(null, [this].concat([].slice.call(args)));
42601
- },
42602
- analogous: function() {
42603
- return this._applyCombination(analogous, arguments);
42604
- },
42605
- complement: function() {
42606
- return this._applyCombination(complement, arguments);
42607
- },
42608
- monochromatic: function() {
42609
- return this._applyCombination(monochromatic, arguments);
42610
- },
42611
- splitcomplement: function() {
42612
- return this._applyCombination(splitcomplement, arguments);
42613
- },
42614
- triad: function() {
42615
- return this._applyCombination(triad, arguments);
42616
- },
42617
- tetrad: function() {
42618
- return this._applyCombination(tetrad, arguments);
42619
- }
42620
- };
42671
+ // If input is an object, force 1 into "1.0" to handle ratios properly
42672
+ // String input requires "1.0" as input, so 1 will be treated as 1
42673
+ tinycolor.fromRatio = function (color, opts) {
42674
+ if (typeof color == "object") {
42675
+ var newColor = {};
42676
+ for (var i in color) {
42677
+ if (color.hasOwnProperty(i)) {
42678
+ if (i === "a") {
42679
+ newColor[i] = color[i];
42680
+ } else {
42681
+ newColor[i] = convertToPercentage(color[i]);
42682
+ }
42683
+ }
42684
+ }
42685
+ color = newColor;
42686
+ }
42621
42687
 
42622
- // If input is an object, force 1 into "1.0" to handle ratios properly
42623
- // String input requires "1.0" as input, so 1 will be treated as 1
42624
- tinycolor.fromRatio = function(color, opts) {
42625
- if (typeof color == "object") {
42626
- var newColor = {};
42627
- for (var i in color) {
42628
- if (color.hasOwnProperty(i)) {
42629
- if (i === "a") {
42630
- newColor[i] = color[i];
42631
- }
42632
- else {
42633
- newColor[i] = convertToPercentage(color[i]);
42634
- }
42635
- }
42636
- }
42637
- color = newColor;
42638
- }
42639
-
42640
- return tinycolor(color, opts);
42641
- };
42688
+ return tinycolor(color, opts);
42689
+ };
42642
42690
 
42643
- // Given a string or object, convert that input to RGB
42644
- // Possible string inputs:
42645
- //
42646
- // "red"
42647
- // "#f00" or "f00"
42648
- // "#ff0000" or "ff0000"
42649
- // "#ff000000" or "ff000000"
42650
- // "rgb 255 0 0" or "rgb (255, 0, 0)"
42651
- // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
42652
- // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
42653
- // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
42654
- // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
42655
- // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
42656
- // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
42657
- //
42658
- function inputToRGB(color) {
42659
-
42660
- var rgb = { r: 0, g: 0, b: 0 };
42661
- var a = 1;
42662
- var s = null;
42663
- var v = null;
42664
- var l = null;
42665
- var ok = false;
42666
- var format = false;
42667
-
42668
- if (typeof color == "string") {
42669
- color = stringInputToObject(color);
42670
- }
42671
-
42672
- if (typeof color == "object") {
42673
- if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
42674
- rgb = rgbToRgb(color.r, color.g, color.b);
42675
- ok = true;
42676
- format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
42677
- }
42678
- else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
42679
- s = convertToPercentage(color.s);
42680
- v = convertToPercentage(color.v);
42681
- rgb = hsvToRgb(color.h, s, v);
42682
- ok = true;
42683
- format = "hsv";
42684
- }
42685
- else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
42686
- s = convertToPercentage(color.s);
42687
- l = convertToPercentage(color.l);
42688
- rgb = hslToRgb(color.h, s, l);
42689
- ok = true;
42690
- format = "hsl";
42691
- }
42692
-
42693
- if (color.hasOwnProperty("a")) {
42694
- a = color.a;
42695
- }
42696
- }
42697
-
42698
- a = boundAlpha(a);
42699
-
42700
- return {
42701
- ok: ok,
42702
- format: color.format || format,
42703
- r: mathMin(255, mathMax(rgb.r, 0)),
42704
- g: mathMin(255, mathMax(rgb.g, 0)),
42705
- b: mathMin(255, mathMax(rgb.b, 0)),
42706
- a: a
42707
- };
42708
- }
42709
-
42710
-
42711
- // Conversion Functions
42712
- // --------------------
42713
-
42714
- // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
42715
- // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
42716
-
42717
- // `rgbToRgb`
42718
- // Handle bounds / percentage checking to conform to CSS color spec
42719
- // <http://www.w3.org/TR/css3-color/>
42720
- // *Assumes:* r, g, b in [0, 255] or [0, 1]
42721
- // *Returns:* { r, g, b } in [0, 255]
42722
- function rgbToRgb(r, g, b){
42723
- return {
42724
- r: bound01(r, 255) * 255,
42725
- g: bound01(g, 255) * 255,
42726
- b: bound01(b, 255) * 255
42727
- };
42728
- }
42729
-
42730
- // `rgbToHsl`
42731
- // Converts an RGB color value to HSL.
42732
- // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
42733
- // *Returns:* { h, s, l } in [0,1]
42734
- function rgbToHsl(r, g, b) {
42735
-
42736
- r = bound01(r, 255);
42737
- g = bound01(g, 255);
42738
- b = bound01(b, 255);
42739
-
42740
- var max = mathMax(r, g, b), min = mathMin(r, g, b);
42741
- var h, s, l = (max + min) / 2;
42742
-
42743
- if(max == min) {
42744
- h = s = 0; // achromatic
42745
- }
42746
- else {
42747
- var d = max - min;
42748
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
42749
- switch(max) {
42750
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
42751
- case g: h = (b - r) / d + 2; break;
42752
- case b: h = (r - g) / d + 4; break;
42753
- }
42754
-
42755
- h /= 6;
42756
- }
42757
-
42758
- return { h: h, s: s, l: l };
42759
- }
42760
-
42761
- // `hslToRgb`
42762
- // Converts an HSL color value to RGB.
42763
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
42764
- // *Returns:* { r, g, b } in the set [0, 255]
42765
- function hslToRgb(h, s, l) {
42766
- var r, g, b;
42767
-
42768
- h = bound01(h, 360);
42769
- s = bound01(s, 100);
42770
- l = bound01(l, 100);
42771
-
42772
- function hue2rgb(p, q, t) {
42773
- if(t < 0) t += 1;
42774
- if(t > 1) t -= 1;
42775
- if(t < 1/6) return p + (q - p) * 6 * t;
42776
- if(t < 1/2) return q;
42777
- if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
42778
- return p;
42779
- }
42780
-
42781
- if(s === 0) {
42782
- r = g = b = l; // achromatic
42783
- }
42784
- else {
42785
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
42786
- var p = 2 * l - q;
42787
- r = hue2rgb(p, q, h + 1/3);
42788
- g = hue2rgb(p, q, h);
42789
- b = hue2rgb(p, q, h - 1/3);
42790
- }
42791
-
42792
- return { r: r * 255, g: g * 255, b: b * 255 };
42793
- }
42794
-
42795
- // `rgbToHsv`
42796
- // Converts an RGB color value to HSV
42797
- // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
42798
- // *Returns:* { h, s, v } in [0,1]
42799
- function rgbToHsv(r, g, b) {
42800
-
42801
- r = bound01(r, 255);
42802
- g = bound01(g, 255);
42803
- b = bound01(b, 255);
42804
-
42805
- var max = mathMax(r, g, b), min = mathMin(r, g, b);
42806
- var h, s, v = max;
42807
-
42808
- var d = max - min;
42809
- s = max === 0 ? 0 : d / max;
42810
-
42811
- if(max == min) {
42812
- h = 0; // achromatic
42813
- }
42814
- else {
42815
- switch(max) {
42816
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
42817
- case g: h = (b - r) / d + 2; break;
42818
- case b: h = (r - g) / d + 4; break;
42819
- }
42820
- h /= 6;
42821
- }
42822
- return { h: h, s: s, v: v };
42823
- }
42824
-
42825
- // `hsvToRgb`
42826
- // Converts an HSV color value to RGB.
42827
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
42828
- // *Returns:* { r, g, b } in the set [0, 255]
42829
- function hsvToRgb(h, s, v) {
42830
-
42831
- h = bound01(h, 360) * 6;
42832
- s = bound01(s, 100);
42833
- v = bound01(v, 100);
42834
-
42835
- var i = Math.floor(h),
42836
- f = h - i,
42837
- p = v * (1 - s),
42838
- q = v * (1 - f * s),
42839
- t = v * (1 - (1 - f) * s),
42840
- mod = i % 6,
42841
- r = [v, q, p, p, t, v][mod],
42842
- g = [t, v, v, q, p, p][mod],
42843
- b = [p, p, t, v, v, q][mod];
42844
-
42845
- return { r: r * 255, g: g * 255, b: b * 255 };
42846
- }
42847
-
42848
- // `rgbToHex`
42849
- // Converts an RGB color to hex
42850
- // Assumes r, g, and b are contained in the set [0, 255]
42851
- // Returns a 3 or 6 character hex
42852
- function rgbToHex(r, g, b, allow3Char) {
42853
-
42854
- var hex = [
42855
- pad2(mathRound(r).toString(16)),
42856
- pad2(mathRound(g).toString(16)),
42857
- pad2(mathRound(b).toString(16))
42858
- ];
42859
-
42860
- // Return a 3 character hex if possible
42861
- 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)) {
42862
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
42863
- }
42864
-
42865
- return hex.join("");
42866
- }
42867
-
42868
- // `rgbaToHex`
42869
- // Converts an RGBA color plus alpha transparency to hex
42870
- // Assumes r, g, b are contained in the set [0, 255] and
42871
- // a in [0, 1]. Returns a 4 or 8 character rgba hex
42872
- function rgbaToHex(r, g, b, a, allow4Char) {
42873
-
42874
- var hex = [
42875
- pad2(mathRound(r).toString(16)),
42876
- pad2(mathRound(g).toString(16)),
42877
- pad2(mathRound(b).toString(16)),
42878
- pad2(convertDecimalToHex(a))
42879
- ];
42880
-
42881
- // Return a 4 character hex if possible
42882
- 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)) {
42883
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
42884
- }
42885
-
42886
- return hex.join("");
42887
- }
42888
-
42889
- // `rgbaToArgbHex`
42890
- // Converts an RGBA color to an ARGB Hex8 string
42891
- // Rarely used, but required for "toFilter()"
42892
- function rgbaToArgbHex(r, g, b, a) {
42893
-
42894
- var hex = [
42895
- pad2(convertDecimalToHex(a)),
42896
- pad2(mathRound(r).toString(16)),
42897
- pad2(mathRound(g).toString(16)),
42898
- pad2(mathRound(b).toString(16))
42899
- ];
42900
-
42901
- return hex.join("");
42902
- }
42903
-
42904
- // `equals`
42905
- // Can be called with any tinycolor input
42906
- tinycolor.equals = function (color1, color2) {
42907
- if (!color1 || !color2) { return false; }
42908
- return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
42909
- };
42691
+ // Given a string or object, convert that input to RGB
42692
+ // Possible string inputs:
42693
+ //
42694
+ // "red"
42695
+ // "#f00" or "f00"
42696
+ // "#ff0000" or "ff0000"
42697
+ // "#ff000000" or "ff000000"
42698
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
42699
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
42700
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
42701
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
42702
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
42703
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
42704
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
42705
+ //
42706
+ function inputToRGB(color) {
42707
+ var rgb = { r: 0, g: 0, b: 0 };
42708
+ var a = 1;
42709
+ var s = null;
42710
+ var v = null;
42711
+ var l = null;
42712
+ var ok = false;
42713
+ var format = false;
42714
+
42715
+ if (typeof color == "string") {
42716
+ color = stringInputToObject(color);
42717
+ }
42910
42718
 
42911
- tinycolor.random = function() {
42912
- return tinycolor.fromRatio({
42913
- r: mathRandom(),
42914
- g: mathRandom(),
42915
- b: mathRandom()
42916
- });
42917
- };
42719
+ if (typeof color == "object") {
42720
+ if (
42721
+ isValidCSSUnit(color.r) &&
42722
+ isValidCSSUnit(color.g) &&
42723
+ isValidCSSUnit(color.b)
42724
+ ) {
42725
+ rgb = rgbToRgb(color.r, color.g, color.b);
42726
+ ok = true;
42727
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
42728
+ } else if (
42729
+ isValidCSSUnit(color.h) &&
42730
+ isValidCSSUnit(color.s) &&
42731
+ isValidCSSUnit(color.v)
42732
+ ) {
42733
+ s = convertToPercentage(color.s);
42734
+ v = convertToPercentage(color.v);
42735
+ rgb = hsvToRgb(color.h, s, v);
42736
+ ok = true;
42737
+ format = "hsv";
42738
+ } else if (
42739
+ isValidCSSUnit(color.h) &&
42740
+ isValidCSSUnit(color.s) &&
42741
+ isValidCSSUnit(color.l)
42742
+ ) {
42743
+ s = convertToPercentage(color.s);
42744
+ l = convertToPercentage(color.l);
42745
+ rgb = hslToRgb$1(color.h, s, l);
42746
+ ok = true;
42747
+ format = "hsl";
42748
+ }
42749
+
42750
+ if (color.hasOwnProperty("a")) {
42751
+ a = color.a;
42752
+ }
42753
+ }
42918
42754
 
42755
+ a = boundAlpha(a);
42919
42756
 
42920
- // Modification Functions
42921
- // ----------------------
42922
- // Thanks to less.js for some of the basics here
42923
- // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
42757
+ return {
42758
+ ok: ok,
42759
+ format: color.format || format,
42760
+ r: Math.min(255, Math.max(rgb.r, 0)),
42761
+ g: Math.min(255, Math.max(rgb.g, 0)),
42762
+ b: Math.min(255, Math.max(rgb.b, 0)),
42763
+ a: a,
42764
+ };
42765
+ }
42924
42766
 
42925
- function desaturate(color, amount) {
42926
- amount = (amount === 0) ? 0 : (amount || 10);
42927
- var hsl = tinycolor(color).toHsl();
42928
- hsl.s -= amount / 100;
42929
- hsl.s = clamp01(hsl.s);
42930
- return tinycolor(hsl);
42931
- }
42767
+ // Conversion Functions
42768
+ // --------------------
42932
42769
 
42933
- function saturate(color, amount) {
42934
- amount = (amount === 0) ? 0 : (amount || 10);
42935
- var hsl = tinycolor(color).toHsl();
42936
- hsl.s += amount / 100;
42937
- hsl.s = clamp01(hsl.s);
42938
- return tinycolor(hsl);
42939
- }
42770
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
42771
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
42940
42772
 
42941
- function greyscale(color) {
42942
- return tinycolor(color).desaturate(100);
42943
- }
42773
+ // `rgbToRgb`
42774
+ // Handle bounds / percentage checking to conform to CSS color spec
42775
+ // <http://www.w3.org/TR/css3-color/>
42776
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
42777
+ // *Returns:* { r, g, b } in [0, 255]
42778
+ function rgbToRgb(r, g, b) {
42779
+ return {
42780
+ r: bound01(r, 255) * 255,
42781
+ g: bound01(g, 255) * 255,
42782
+ b: bound01(b, 255) * 255,
42783
+ };
42784
+ }
42944
42785
 
42945
- function lighten (color, amount) {
42946
- amount = (amount === 0) ? 0 : (amount || 10);
42947
- var hsl = tinycolor(color).toHsl();
42948
- hsl.l += amount / 100;
42949
- hsl.l = clamp01(hsl.l);
42950
- return tinycolor(hsl);
42951
- }
42786
+ // `rgbToHsl`
42787
+ // Converts an RGB color value to HSL.
42788
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
42789
+ // *Returns:* { h, s, l } in [0,1]
42790
+ function rgbToHsl(r, g, b) {
42791
+ r = bound01(r, 255);
42792
+ g = bound01(g, 255);
42793
+ b = bound01(b, 255);
42952
42794
 
42953
- function brighten(color, amount) {
42954
- amount = (amount === 0) ? 0 : (amount || 10);
42955
- var rgb = tinycolor(color).toRgb();
42956
- rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
42957
- rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
42958
- rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
42959
- return tinycolor(rgb);
42960
- }
42795
+ var max = Math.max(r, g, b),
42796
+ min = Math.min(r, g, b);
42797
+ var h,
42798
+ s,
42799
+ l = (max + min) / 2;
42961
42800
 
42962
- function darken (color, amount) {
42963
- amount = (amount === 0) ? 0 : (amount || 10);
42964
- var hsl = tinycolor(color).toHsl();
42965
- hsl.l -= amount / 100;
42966
- hsl.l = clamp01(hsl.l);
42967
- return tinycolor(hsl);
42968
- }
42801
+ if (max == min) {
42802
+ h = s = 0; // achromatic
42803
+ } else {
42804
+ var d = max - min;
42805
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
42806
+ switch (max) {
42807
+ case r:
42808
+ h = (g - b) / d + (g < b ? 6 : 0);
42809
+ break;
42810
+ case g:
42811
+ h = (b - r) / d + 2;
42812
+ break;
42813
+ case b:
42814
+ h = (r - g) / d + 4;
42815
+ break;
42816
+ }
42969
42817
 
42970
- // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
42971
- // Values outside of this range will be wrapped into this range.
42972
- function spin(color, amount) {
42973
- var hsl = tinycolor(color).toHsl();
42974
- var hue = (hsl.h + amount) % 360;
42975
- hsl.h = hue < 0 ? 360 + hue : hue;
42976
- return tinycolor(hsl);
42977
- }
42818
+ h /= 6;
42819
+ }
42978
42820
 
42979
- // Combination Functions
42980
- // ---------------------
42981
- // Thanks to jQuery xColor for some of the ideas behind these
42982
- // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
42821
+ return { h: h, s: s, l: l };
42822
+ }
42983
42823
 
42984
- function complement(color) {
42985
- var hsl = tinycolor(color).toHsl();
42986
- hsl.h = (hsl.h + 180) % 360;
42987
- return tinycolor(hsl);
42988
- }
42824
+ // `hslToRgb`
42825
+ // Converts an HSL color value to RGB.
42826
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
42827
+ // *Returns:* { r, g, b } in the set [0, 255]
42828
+ function hslToRgb$1(h, s, l) {
42829
+ var r, g, b;
42989
42830
 
42990
- function triad(color) {
42991
- var hsl = tinycolor(color).toHsl();
42992
- var h = hsl.h;
42993
- return [
42994
- tinycolor(color),
42995
- tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
42996
- tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
42997
- ];
42998
- }
42831
+ h = bound01(h, 360);
42832
+ s = bound01(s, 100);
42833
+ l = bound01(l, 100);
42999
42834
 
43000
- function tetrad(color) {
43001
- var hsl = tinycolor(color).toHsl();
43002
- var h = hsl.h;
43003
- return [
43004
- tinycolor(color),
43005
- tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
43006
- tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
43007
- tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
43008
- ];
43009
- }
42835
+ function hue2rgb(p, q, t) {
42836
+ if (t < 0) t += 1;
42837
+ if (t > 1) t -= 1;
42838
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
42839
+ if (t < 1 / 2) return q;
42840
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
42841
+ return p;
42842
+ }
43010
42843
 
43011
- function splitcomplement(color) {
43012
- var hsl = tinycolor(color).toHsl();
43013
- var h = hsl.h;
43014
- return [
43015
- tinycolor(color),
43016
- tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
43017
- tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
43018
- ];
43019
- }
42844
+ if (s === 0) {
42845
+ r = g = b = l; // achromatic
42846
+ } else {
42847
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
42848
+ var p = 2 * l - q;
42849
+ r = hue2rgb(p, q, h + 1 / 3);
42850
+ g = hue2rgb(p, q, h);
42851
+ b = hue2rgb(p, q, h - 1 / 3);
42852
+ }
43020
42853
 
43021
- function analogous(color, results, slices) {
43022
- results = results || 6;
43023
- slices = slices || 30;
42854
+ return { r: r * 255, g: g * 255, b: b * 255 };
42855
+ }
43024
42856
 
43025
- var hsl = tinycolor(color).toHsl();
43026
- var part = 360 / slices;
43027
- var ret = [tinycolor(color)];
42857
+ // `rgbToHsv`
42858
+ // Converts an RGB color value to HSV
42859
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
42860
+ // *Returns:* { h, s, v } in [0,1]
42861
+ function rgbToHsv(r, g, b) {
42862
+ r = bound01(r, 255);
42863
+ g = bound01(g, 255);
42864
+ b = bound01(b, 255);
43028
42865
 
43029
- for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
43030
- hsl.h = (hsl.h + part) % 360;
43031
- ret.push(tinycolor(hsl));
43032
- }
43033
- return ret;
43034
- }
42866
+ var max = Math.max(r, g, b),
42867
+ min = Math.min(r, g, b);
42868
+ var h,
42869
+ s,
42870
+ v = max;
43035
42871
 
43036
- function monochromatic(color, results) {
43037
- results = results || 6;
43038
- var hsv = tinycolor(color).toHsv();
43039
- var h = hsv.h, s = hsv.s, v = hsv.v;
43040
- var ret = [];
43041
- var modification = 1 / results;
42872
+ var d = max - min;
42873
+ s = max === 0 ? 0 : d / max;
43042
42874
 
43043
- while (results--) {
43044
- ret.push(tinycolor({ h: h, s: s, v: v}));
43045
- v = (v + modification) % 1;
43046
- }
42875
+ if (max == min) {
42876
+ h = 0; // achromatic
42877
+ } else {
42878
+ switch (max) {
42879
+ case r:
42880
+ h = (g - b) / d + (g < b ? 6 : 0);
42881
+ break;
42882
+ case g:
42883
+ h = (b - r) / d + 2;
42884
+ break;
42885
+ case b:
42886
+ h = (r - g) / d + 4;
42887
+ break;
42888
+ }
42889
+ h /= 6;
42890
+ }
42891
+ return { h: h, s: s, v: v };
42892
+ }
42893
+
42894
+ // `hsvToRgb`
42895
+ // Converts an HSV color value to RGB.
42896
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
42897
+ // *Returns:* { r, g, b } in the set [0, 255]
42898
+ function hsvToRgb(h, s, v) {
42899
+ h = bound01(h, 360) * 6;
42900
+ s = bound01(s, 100);
42901
+ v = bound01(v, 100);
42902
+
42903
+ var i = Math.floor(h),
42904
+ f = h - i,
42905
+ p = v * (1 - s),
42906
+ q = v * (1 - f * s),
42907
+ t = v * (1 - (1 - f) * s),
42908
+ mod = i % 6,
42909
+ r = [v, q, p, p, t, v][mod],
42910
+ g = [t, v, v, q, p, p][mod],
42911
+ b = [p, p, t, v, v, q][mod];
42912
+
42913
+ return { r: r * 255, g: g * 255, b: b * 255 };
42914
+ }
42915
+
42916
+ // `rgbToHex`
42917
+ // Converts an RGB color to hex
42918
+ // Assumes r, g, and b are contained in the set [0, 255]
42919
+ // Returns a 3 or 6 character hex
42920
+ function rgbToHex(r, g, b, allow3Char) {
42921
+ var hex = [
42922
+ pad2(Math.round(r).toString(16)),
42923
+ pad2(Math.round(g).toString(16)),
42924
+ pad2(Math.round(b).toString(16)),
42925
+ ];
43047
42926
 
43048
- return ret;
43049
- }
42927
+ // Return a 3 character hex if possible
42928
+ if (
42929
+ allow3Char &&
42930
+ hex[0].charAt(0) == hex[0].charAt(1) &&
42931
+ hex[1].charAt(0) == hex[1].charAt(1) &&
42932
+ hex[2].charAt(0) == hex[2].charAt(1)
42933
+ ) {
42934
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
42935
+ }
43050
42936
 
43051
- // Utility Functions
43052
- // ---------------------
43053
-
43054
- tinycolor.mix = function(color1, color2, amount) {
43055
- amount = (amount === 0) ? 0 : (amount || 50);
42937
+ return hex.join("");
42938
+ }
43056
42939
 
43057
- var rgb1 = tinycolor(color1).toRgb();
43058
- var rgb2 = tinycolor(color2).toRgb();
42940
+ // `rgbaToHex`
42941
+ // Converts an RGBA color plus alpha transparency to hex
42942
+ // Assumes r, g, b are contained in the set [0, 255] and
42943
+ // a in [0, 1]. Returns a 4 or 8 character rgba hex
42944
+ function rgbaToHex(r, g, b, a, allow4Char) {
42945
+ var hex = [
42946
+ pad2(Math.round(r).toString(16)),
42947
+ pad2(Math.round(g).toString(16)),
42948
+ pad2(Math.round(b).toString(16)),
42949
+ pad2(convertDecimalToHex(a)),
42950
+ ];
43059
42951
 
43060
- var p = amount / 100;
42952
+ // Return a 4 character hex if possible
42953
+ if (
42954
+ allow4Char &&
42955
+ hex[0].charAt(0) == hex[0].charAt(1) &&
42956
+ hex[1].charAt(0) == hex[1].charAt(1) &&
42957
+ hex[2].charAt(0) == hex[2].charAt(1) &&
42958
+ hex[3].charAt(0) == hex[3].charAt(1)
42959
+ ) {
42960
+ return (
42961
+ hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0)
42962
+ );
42963
+ }
43061
42964
 
43062
- var rgba = {
43063
- r: ((rgb2.r - rgb1.r) * p) + rgb1.r,
43064
- g: ((rgb2.g - rgb1.g) * p) + rgb1.g,
43065
- b: ((rgb2.b - rgb1.b) * p) + rgb1.b,
43066
- a: ((rgb2.a - rgb1.a) * p) + rgb1.a
43067
- };
42965
+ return hex.join("");
42966
+ }
43068
42967
 
43069
- return tinycolor(rgba);
43070
- };
42968
+ // `rgbaToArgbHex`
42969
+ // Converts an RGBA color to an ARGB Hex8 string
42970
+ // Rarely used, but required for "toFilter()"
42971
+ function rgbaToArgbHex(r, g, b, a) {
42972
+ var hex = [
42973
+ pad2(convertDecimalToHex(a)),
42974
+ pad2(Math.round(r).toString(16)),
42975
+ pad2(Math.round(g).toString(16)),
42976
+ pad2(Math.round(b).toString(16)),
42977
+ ];
43071
42978
 
42979
+ return hex.join("");
42980
+ }
43072
42981
 
43073
- // Readability Functions
43074
- // ---------------------
43075
- // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
42982
+ // `equals`
42983
+ // Can be called with any tinycolor input
42984
+ tinycolor.equals = function (color1, color2) {
42985
+ if (!color1 || !color2) return false;
42986
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
42987
+ };
43076
42988
 
43077
- // `contrast`
43078
- // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
43079
- tinycolor.readability = function(color1, color2) {
43080
- var c1 = tinycolor(color1);
43081
- var c2 = tinycolor(color2);
43082
- return (Math.max(c1.getLuminance(),c2.getLuminance())+0.05) / (Math.min(c1.getLuminance(),c2.getLuminance())+0.05);
43083
- };
42989
+ tinycolor.random = function () {
42990
+ return tinycolor.fromRatio({
42991
+ r: Math.random(),
42992
+ g: Math.random(),
42993
+ b: Math.random(),
42994
+ });
42995
+ };
43084
42996
 
43085
- // `isReadable`
43086
- // Ensure that foreground and background color combinations meet WCAG2 guidelines.
43087
- // The third argument is an optional Object.
43088
- // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
43089
- // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
43090
- // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
43091
-
43092
- // *Example*
43093
- // tinycolor.isReadable("#000", "#111") => false
43094
- // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
43095
- tinycolor.isReadable = function(color1, color2, wcag2) {
43096
- var readability = tinycolor.readability(color1, color2);
43097
- var wcag2Parms, out;
43098
-
43099
- out = false;
43100
-
43101
- wcag2Parms = validateWCAG2Parms(wcag2);
43102
- switch (wcag2Parms.level + wcag2Parms.size) {
43103
- case "AAsmall":
43104
- case "AAAlarge":
43105
- out = readability >= 4.5;
43106
- break;
43107
- case "AAlarge":
43108
- out = readability >= 3;
43109
- break;
43110
- case "AAAsmall":
43111
- out = readability >= 7;
43112
- break;
43113
- }
43114
- return out;
42997
+ // Modification Functions
42998
+ // ----------------------
42999
+ // Thanks to less.js for some of the basics here
43000
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
43115
43001
 
43116
- };
43002
+ function desaturate(color, amount) {
43003
+ amount = amount === 0 ? 0 : amount || 10;
43004
+ var hsl = tinycolor(color).toHsl();
43005
+ hsl.s -= amount / 100;
43006
+ hsl.s = clamp01(hsl.s);
43007
+ return tinycolor(hsl);
43008
+ }
43117
43009
 
43118
- // `mostReadable`
43119
- // Given a base color and a list of possible foreground or background
43120
- // colors for that base, returns the most readable color.
43121
- // Optionally returns Black or White if the most readable color is unreadable.
43122
- // *Example*
43123
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
43124
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
43125
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
43126
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
43127
- tinycolor.mostReadable = function(baseColor, colorList, args) {
43128
- var bestColor = null;
43129
- var bestScore = 0;
43130
- var readability;
43131
- var includeFallbackColors, level, size ;
43132
- args = args || {};
43133
- includeFallbackColors = args.includeFallbackColors ;
43134
- level = args.level;
43135
- size = args.size;
43136
-
43137
- for (var i= 0; i < colorList.length ; i++) {
43138
- readability = tinycolor.readability(baseColor, colorList[i]);
43139
- if (readability > bestScore) {
43140
- bestScore = readability;
43141
- bestColor = tinycolor(colorList[i]);
43142
- }
43143
- }
43144
-
43145
- if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) {
43146
- return bestColor;
43147
- }
43148
- else {
43149
- args.includeFallbackColors=false;
43150
- return tinycolor.mostReadable(baseColor,["#fff", "#000"],args);
43151
- }
43152
- };
43010
+ function saturate(color, amount) {
43011
+ amount = amount === 0 ? 0 : amount || 10;
43012
+ var hsl = tinycolor(color).toHsl();
43013
+ hsl.s += amount / 100;
43014
+ hsl.s = clamp01(hsl.s);
43015
+ return tinycolor(hsl);
43016
+ }
43153
43017
 
43018
+ function greyscale(color) {
43019
+ return tinycolor(color).desaturate(100);
43020
+ }
43154
43021
 
43155
- // Big List of Colors
43156
- // ------------------
43157
- // <http://www.w3.org/TR/css3-color/#svg-color>
43158
- var names = tinycolor.names = {
43159
- aliceblue: "f0f8ff",
43160
- antiquewhite: "faebd7",
43161
- aqua: "0ff",
43162
- aquamarine: "7fffd4",
43163
- azure: "f0ffff",
43164
- beige: "f5f5dc",
43165
- bisque: "ffe4c4",
43166
- black: "000",
43167
- blanchedalmond: "ffebcd",
43168
- blue: "00f",
43169
- blueviolet: "8a2be2",
43170
- brown: "a52a2a",
43171
- burlywood: "deb887",
43172
- burntsienna: "ea7e5d",
43173
- cadetblue: "5f9ea0",
43174
- chartreuse: "7fff00",
43175
- chocolate: "d2691e",
43176
- coral: "ff7f50",
43177
- cornflowerblue: "6495ed",
43178
- cornsilk: "fff8dc",
43179
- crimson: "dc143c",
43180
- cyan: "0ff",
43181
- darkblue: "00008b",
43182
- darkcyan: "008b8b",
43183
- darkgoldenrod: "b8860b",
43184
- darkgray: "a9a9a9",
43185
- darkgreen: "006400",
43186
- darkgrey: "a9a9a9",
43187
- darkkhaki: "bdb76b",
43188
- darkmagenta: "8b008b",
43189
- darkolivegreen: "556b2f",
43190
- darkorange: "ff8c00",
43191
- darkorchid: "9932cc",
43192
- darkred: "8b0000",
43193
- darksalmon: "e9967a",
43194
- darkseagreen: "8fbc8f",
43195
- darkslateblue: "483d8b",
43196
- darkslategray: "2f4f4f",
43197
- darkslategrey: "2f4f4f",
43198
- darkturquoise: "00ced1",
43199
- darkviolet: "9400d3",
43200
- deeppink: "ff1493",
43201
- deepskyblue: "00bfff",
43202
- dimgray: "696969",
43203
- dimgrey: "696969",
43204
- dodgerblue: "1e90ff",
43205
- firebrick: "b22222",
43206
- floralwhite: "fffaf0",
43207
- forestgreen: "228b22",
43208
- fuchsia: "f0f",
43209
- gainsboro: "dcdcdc",
43210
- ghostwhite: "f8f8ff",
43211
- gold: "ffd700",
43212
- goldenrod: "daa520",
43213
- gray: "808080",
43214
- green: "008000",
43215
- greenyellow: "adff2f",
43216
- grey: "808080",
43217
- honeydew: "f0fff0",
43218
- hotpink: "ff69b4",
43219
- indianred: "cd5c5c",
43220
- indigo: "4b0082",
43221
- ivory: "fffff0",
43222
- khaki: "f0e68c",
43223
- lavender: "e6e6fa",
43224
- lavenderblush: "fff0f5",
43225
- lawngreen: "7cfc00",
43226
- lemonchiffon: "fffacd",
43227
- lightblue: "add8e6",
43228
- lightcoral: "f08080",
43229
- lightcyan: "e0ffff",
43230
- lightgoldenrodyellow: "fafad2",
43231
- lightgray: "d3d3d3",
43232
- lightgreen: "90ee90",
43233
- lightgrey: "d3d3d3",
43234
- lightpink: "ffb6c1",
43235
- lightsalmon: "ffa07a",
43236
- lightseagreen: "20b2aa",
43237
- lightskyblue: "87cefa",
43238
- lightslategray: "789",
43239
- lightslategrey: "789",
43240
- lightsteelblue: "b0c4de",
43241
- lightyellow: "ffffe0",
43242
- lime: "0f0",
43243
- limegreen: "32cd32",
43244
- linen: "faf0e6",
43245
- magenta: "f0f",
43246
- maroon: "800000",
43247
- mediumaquamarine: "66cdaa",
43248
- mediumblue: "0000cd",
43249
- mediumorchid: "ba55d3",
43250
- mediumpurple: "9370db",
43251
- mediumseagreen: "3cb371",
43252
- mediumslateblue: "7b68ee",
43253
- mediumspringgreen: "00fa9a",
43254
- mediumturquoise: "48d1cc",
43255
- mediumvioletred: "c71585",
43256
- midnightblue: "191970",
43257
- mintcream: "f5fffa",
43258
- mistyrose: "ffe4e1",
43259
- moccasin: "ffe4b5",
43260
- navajowhite: "ffdead",
43261
- navy: "000080",
43262
- oldlace: "fdf5e6",
43263
- olive: "808000",
43264
- olivedrab: "6b8e23",
43265
- orange: "ffa500",
43266
- orangered: "ff4500",
43267
- orchid: "da70d6",
43268
- palegoldenrod: "eee8aa",
43269
- palegreen: "98fb98",
43270
- paleturquoise: "afeeee",
43271
- palevioletred: "db7093",
43272
- papayawhip: "ffefd5",
43273
- peachpuff: "ffdab9",
43274
- peru: "cd853f",
43275
- pink: "ffc0cb",
43276
- plum: "dda0dd",
43277
- powderblue: "b0e0e6",
43278
- purple: "800080",
43279
- rebeccapurple: "663399",
43280
- red: "f00",
43281
- rosybrown: "bc8f8f",
43282
- royalblue: "4169e1",
43283
- saddlebrown: "8b4513",
43284
- salmon: "fa8072",
43285
- sandybrown: "f4a460",
43286
- seagreen: "2e8b57",
43287
- seashell: "fff5ee",
43288
- sienna: "a0522d",
43289
- silver: "c0c0c0",
43290
- skyblue: "87ceeb",
43291
- slateblue: "6a5acd",
43292
- slategray: "708090",
43293
- slategrey: "708090",
43294
- snow: "fffafa",
43295
- springgreen: "00ff7f",
43296
- steelblue: "4682b4",
43297
- tan: "d2b48c",
43298
- teal: "008080",
43299
- thistle: "d8bfd8",
43300
- tomato: "ff6347",
43301
- turquoise: "40e0d0",
43302
- violet: "ee82ee",
43303
- wheat: "f5deb3",
43304
- white: "fff",
43305
- whitesmoke: "f5f5f5",
43306
- yellow: "ff0",
43307
- yellowgreen: "9acd32"
43308
- };
43022
+ function lighten(color, amount) {
43023
+ amount = amount === 0 ? 0 : amount || 10;
43024
+ var hsl = tinycolor(color).toHsl();
43025
+ hsl.l += amount / 100;
43026
+ hsl.l = clamp01(hsl.l);
43027
+ return tinycolor(hsl);
43028
+ }
43309
43029
 
43310
- // Make it easy to access colors via `hexNames[hex]`
43311
- var hexNames = tinycolor.hexNames = flip(names);
43030
+ function brighten(color, amount) {
43031
+ amount = amount === 0 ? 0 : amount || 10;
43032
+ var rgb = tinycolor(color).toRgb();
43033
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
43034
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
43035
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
43036
+ return tinycolor(rgb);
43037
+ }
43312
43038
 
43039
+ function darken(color, amount) {
43040
+ amount = amount === 0 ? 0 : amount || 10;
43041
+ var hsl = tinycolor(color).toHsl();
43042
+ hsl.l -= amount / 100;
43043
+ hsl.l = clamp01(hsl.l);
43044
+ return tinycolor(hsl);
43045
+ }
43313
43046
 
43314
- // Utilities
43315
- // ---------
43047
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
43048
+ // Values outside of this range will be wrapped into this range.
43049
+ function spin(color, amount) {
43050
+ var hsl = tinycolor(color).toHsl();
43051
+ var hue = (hsl.h + amount) % 360;
43052
+ hsl.h = hue < 0 ? 360 + hue : hue;
43053
+ return tinycolor(hsl);
43054
+ }
43316
43055
 
43317
- // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
43318
- function flip(o) {
43319
- var flipped = { };
43320
- for (var i in o) {
43321
- if (o.hasOwnProperty(i)) {
43322
- flipped[o[i]] = i;
43323
- }
43324
- }
43325
- return flipped;
43326
- }
43056
+ // Combination Functions
43057
+ // ---------------------
43058
+ // Thanks to jQuery xColor for some of the ideas behind these
43059
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
43327
43060
 
43328
- // Return a valid alpha value [0,1] with all invalid values being set to 1
43329
- function boundAlpha(a) {
43330
- a = parseFloat(a);
43061
+ function complement(color) {
43062
+ var hsl = tinycolor(color).toHsl();
43063
+ hsl.h = (hsl.h + 180) % 360;
43064
+ return tinycolor(hsl);
43065
+ }
43331
43066
 
43332
- if (isNaN(a) || a < 0 || a > 1) {
43333
- a = 1;
43334
- }
43067
+ function polyad(color, number) {
43068
+ if (isNaN(number) || number <= 0) {
43069
+ throw new Error("Argument to polyad must be a positive number");
43070
+ }
43071
+ var hsl = tinycolor(color).toHsl();
43072
+ var result = [tinycolor(color)];
43073
+ var step = 360 / number;
43074
+ for (var i = 1; i < number; i++) {
43075
+ result.push(tinycolor({ h: (hsl.h + i * step) % 360, s: hsl.s, l: hsl.l }));
43076
+ }
43335
43077
 
43336
- return a;
43337
- }
43078
+ return result;
43079
+ }
43338
43080
 
43339
- // Take input from [0, n] and return it as [0, 1]
43340
- function bound01(n, max) {
43341
- if (isOnePointZero(n)) { n = "100%"; }
43081
+ function splitcomplement(color) {
43082
+ var hsl = tinycolor(color).toHsl();
43083
+ var h = hsl.h;
43084
+ return [
43085
+ tinycolor(color),
43086
+ tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }),
43087
+ tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }),
43088
+ ];
43089
+ }
43342
43090
 
43343
- var processPercent = isPercentage(n);
43344
- n = mathMin(max, mathMax(0, parseFloat(n)));
43091
+ function analogous(color, results, slices) {
43092
+ results = results || 6;
43093
+ slices = slices || 30;
43345
43094
 
43346
- // Automatically convert percentage into number
43347
- if (processPercent) {
43348
- n = parseInt(n * max, 10) / 100;
43349
- }
43095
+ var hsl = tinycolor(color).toHsl();
43096
+ var part = 360 / slices;
43097
+ var ret = [tinycolor(color)];
43350
43098
 
43351
- // Handle floating point rounding errors
43352
- if ((Math.abs(n - max) < 0.000001)) {
43353
- return 1;
43354
- }
43099
+ for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results; ) {
43100
+ hsl.h = (hsl.h + part) % 360;
43101
+ ret.push(tinycolor(hsl));
43102
+ }
43103
+ return ret;
43104
+ }
43355
43105
 
43356
- // Convert into [0, 1] range if it isn't already
43357
- return (n % max) / parseFloat(max);
43358
- }
43106
+ function monochromatic(color, results) {
43107
+ results = results || 6;
43108
+ var hsv = tinycolor(color).toHsv();
43109
+ var h = hsv.h,
43110
+ s = hsv.s,
43111
+ v = hsv.v;
43112
+ var ret = [];
43113
+ var modification = 1 / results;
43359
43114
 
43360
- // Force a number between 0 and 1
43361
- function clamp01(val) {
43362
- return mathMin(1, mathMax(0, val));
43363
- }
43115
+ while (results--) {
43116
+ ret.push(tinycolor({ h: h, s: s, v: v }));
43117
+ v = (v + modification) % 1;
43118
+ }
43364
43119
 
43365
- // Parse a base-16 hex value into a base-10 integer
43366
- function parseIntFromHex(val) {
43367
- return parseInt(val, 16);
43368
- }
43120
+ return ret;
43121
+ }
43369
43122
 
43370
- // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
43371
- // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
43372
- function isOnePointZero(n) {
43373
- return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
43374
- }
43123
+ // Utility Functions
43124
+ // ---------------------
43375
43125
 
43376
- // Check to see if string passed in is a percentage
43377
- function isPercentage(n) {
43378
- return typeof n === "string" && n.indexOf('%') != -1;
43379
- }
43380
-
43381
- // Force a hex value to have 2 characters
43382
- function pad2(c) {
43383
- return c.length == 1 ? '0' + c : '' + c;
43384
- }
43385
-
43386
- // Replace a decimal with it's percentage value
43387
- function convertToPercentage(n) {
43388
- if (n <= 1) {
43389
- n = (n * 100) + "%";
43390
- }
43391
-
43392
- return n;
43393
- }
43394
-
43395
- // Converts a decimal to a hex value
43396
- function convertDecimalToHex(d) {
43397
- return Math.round(parseFloat(d) * 255).toString(16);
43398
- }
43399
- // Converts a hex value to a decimal
43400
- function convertHexToDecimal(h) {
43401
- return (parseIntFromHex(h) / 255);
43402
- }
43403
-
43404
- var matchers = (function() {
43405
-
43406
- // <http://www.w3.org/TR/css3-values/#integers>
43407
- var CSS_INTEGER = "[-\\+]?\\d+%?";
43408
-
43409
- // <http://www.w3.org/TR/css3-values/#number-value>
43410
- var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
43411
-
43412
- // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
43413
- var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
43414
-
43415
- // Actual matching.
43416
- // Parentheses and commas are optional, but not required.
43417
- // Whitespace can take the place of commas or opening paren
43418
- var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
43419
- var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
43420
-
43421
- return {
43422
- CSS_UNIT: new RegExp(CSS_UNIT),
43423
- rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
43424
- rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
43425
- hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
43426
- hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
43427
- hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
43428
- hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
43429
- hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
43430
- hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
43431
- hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
43432
- hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
43433
- };
43434
- })();
43435
-
43436
- // `isValidCSSUnit`
43437
- // Take in a single string / number and check to see if it looks like a CSS unit
43438
- // (see `matchers` above for definition).
43439
- function isValidCSSUnit(color) {
43440
- return !!matchers.CSS_UNIT.exec(color);
43441
- }
43442
-
43443
- // `stringInputToObject`
43444
- // Permissive string parsing. Take in a number of formats, and output an object
43445
- // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
43446
- function stringInputToObject(color) {
43447
-
43448
- color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
43449
- var named = false;
43450
- if (names[color]) {
43451
- color = names[color];
43452
- named = true;
43453
- }
43454
- else if (color == 'transparent') {
43455
- return { r: 0, g: 0, b: 0, a: 0, format: "name" };
43456
- }
43457
-
43458
- // Try to match string input using regular expressions.
43459
- // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
43460
- // Just return an object and let the conversion functions handle that.
43461
- // This way the result will be the same whether the tinycolor is initialized with string or object.
43462
- var match;
43463
- if ((match = matchers.rgb.exec(color))) {
43464
- return { r: match[1], g: match[2], b: match[3] };
43465
- }
43466
- if ((match = matchers.rgba.exec(color))) {
43467
- return { r: match[1], g: match[2], b: match[3], a: match[4] };
43468
- }
43469
- if ((match = matchers.hsl.exec(color))) {
43470
- return { h: match[1], s: match[2], l: match[3] };
43471
- }
43472
- if ((match = matchers.hsla.exec(color))) {
43473
- return { h: match[1], s: match[2], l: match[3], a: match[4] };
43474
- }
43475
- if ((match = matchers.hsv.exec(color))) {
43476
- return { h: match[1], s: match[2], v: match[3] };
43477
- }
43478
- if ((match = matchers.hsva.exec(color))) {
43479
- return { h: match[1], s: match[2], v: match[3], a: match[4] };
43480
- }
43481
- if ((match = matchers.hex8.exec(color))) {
43482
- return {
43483
- r: parseIntFromHex(match[1]),
43484
- g: parseIntFromHex(match[2]),
43485
- b: parseIntFromHex(match[3]),
43486
- a: convertHexToDecimal(match[4]),
43487
- format: named ? "name" : "hex8"
43488
- };
43489
- }
43490
- if ((match = matchers.hex6.exec(color))) {
43491
- return {
43492
- r: parseIntFromHex(match[1]),
43493
- g: parseIntFromHex(match[2]),
43494
- b: parseIntFromHex(match[3]),
43495
- format: named ? "name" : "hex"
43496
- };
43497
- }
43498
- if ((match = matchers.hex4.exec(color))) {
43499
- return {
43500
- r: parseIntFromHex(match[1] + '' + match[1]),
43501
- g: parseIntFromHex(match[2] + '' + match[2]),
43502
- b: parseIntFromHex(match[3] + '' + match[3]),
43503
- a: convertHexToDecimal(match[4] + '' + match[4]),
43504
- format: named ? "name" : "hex8"
43505
- };
43506
- }
43507
- if ((match = matchers.hex3.exec(color))) {
43508
- return {
43509
- r: parseIntFromHex(match[1] + '' + match[1]),
43510
- g: parseIntFromHex(match[2] + '' + match[2]),
43511
- b: parseIntFromHex(match[3] + '' + match[3]),
43512
- format: named ? "name" : "hex"
43513
- };
43514
- }
43515
-
43516
- return false;
43517
- }
43518
-
43519
- function validateWCAG2Parms(parms) {
43520
- // return valid WCAG2 parms for isReadable.
43521
- // If input parms are invalid, return {"level":"AA", "size":"small"}
43522
- var level, size;
43523
- parms = parms || {"level":"AA", "size":"small"};
43524
- level = (parms.level || "AA").toUpperCase();
43525
- size = (parms.size || "small").toLowerCase();
43526
- if (level !== "AA" && level !== "AAA") {
43527
- level = "AA";
43528
- }
43529
- if (size !== "small" && size !== "large") {
43530
- size = "small";
43531
- }
43532
- return {"level":level, "size":size};
43533
- }
43534
-
43535
- // Node: Export function
43536
- if (module.exports) {
43537
- module.exports = tinycolor;
43538
- }
43539
- // AMD/requirejs: Define the module
43540
- else {
43541
- window.tinycolor = tinycolor;
43542
- }
43543
-
43544
- })(Math);
43545
- } (tinycolor));
43546
-
43547
- var tinyColor = tinycolorExports;
43126
+ tinycolor.mix = function (color1, color2, amount) {
43127
+ amount = amount === 0 ? 0 : amount || 50;
43128
+
43129
+ var rgb1 = tinycolor(color1).toRgb();
43130
+ var rgb2 = tinycolor(color2).toRgb();
43131
+
43132
+ var p = amount / 100;
43133
+
43134
+ var rgba = {
43135
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
43136
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
43137
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
43138
+ a: (rgb2.a - rgb1.a) * p + rgb1.a,
43139
+ };
43140
+
43141
+ return tinycolor(rgba);
43142
+ };
43143
+
43144
+ // Readability Functions
43145
+ // ---------------------
43146
+ // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
43147
+
43148
+ // `contrast`
43149
+ // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
43150
+ tinycolor.readability = function (color1, color2) {
43151
+ var c1 = tinycolor(color1);
43152
+ var c2 = tinycolor(color2);
43153
+ return (
43154
+ (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) /
43155
+ (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05)
43156
+ );
43157
+ };
43158
+
43159
+ // `isReadable`
43160
+ // Ensure that foreground and background color combinations meet WCAG2 guidelines.
43161
+ // The third argument is an optional Object.
43162
+ // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
43163
+ // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
43164
+ // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
43165
+
43166
+ // *Example*
43167
+ // tinycolor.isReadable("#000", "#111") => false
43168
+ // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
43169
+ tinycolor.isReadable = function (color1, color2, wcag2) {
43170
+ var readability = tinycolor.readability(color1, color2);
43171
+ var wcag2Parms, out;
43172
+
43173
+ out = false;
43174
+
43175
+ wcag2Parms = validateWCAG2Parms(wcag2);
43176
+ switch (wcag2Parms.level + wcag2Parms.size) {
43177
+ case "AAsmall":
43178
+ case "AAAlarge":
43179
+ out = readability >= 4.5;
43180
+ break;
43181
+ case "AAlarge":
43182
+ out = readability >= 3;
43183
+ break;
43184
+ case "AAAsmall":
43185
+ out = readability >= 7;
43186
+ break;
43187
+ }
43188
+ return out;
43189
+ };
43190
+
43191
+ // `mostReadable`
43192
+ // Given a base color and a list of possible foreground or background
43193
+ // colors for that base, returns the most readable color.
43194
+ // Optionally returns Black or White if the most readable color is unreadable.
43195
+ // *Example*
43196
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
43197
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
43198
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
43199
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
43200
+ tinycolor.mostReadable = function (baseColor, colorList, args) {
43201
+ var bestColor = null;
43202
+ var bestScore = 0;
43203
+ var readability;
43204
+ var includeFallbackColors, level, size;
43205
+ args = args || {};
43206
+ includeFallbackColors = args.includeFallbackColors;
43207
+ level = args.level;
43208
+ size = args.size;
43209
+
43210
+ for (var i = 0; i < colorList.length; i++) {
43211
+ readability = tinycolor.readability(baseColor, colorList[i]);
43212
+ if (readability > bestScore) {
43213
+ bestScore = readability;
43214
+ bestColor = tinycolor(colorList[i]);
43215
+ }
43216
+ }
43217
+
43218
+ if (
43219
+ tinycolor.isReadable(baseColor, bestColor, {
43220
+ level: level,
43221
+ size: size,
43222
+ }) ||
43223
+ !includeFallbackColors
43224
+ ) {
43225
+ return bestColor;
43226
+ } else {
43227
+ args.includeFallbackColors = false;
43228
+ return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
43229
+ }
43230
+ };
43231
+
43232
+ // Big List of Colors
43233
+ // ------------------
43234
+ // <https://www.w3.org/TR/css-color-4/#named-colors>
43235
+ var names = (tinycolor.names = {
43236
+ aliceblue: "f0f8ff",
43237
+ antiquewhite: "faebd7",
43238
+ aqua: "0ff",
43239
+ aquamarine: "7fffd4",
43240
+ azure: "f0ffff",
43241
+ beige: "f5f5dc",
43242
+ bisque: "ffe4c4",
43243
+ black: "000",
43244
+ blanchedalmond: "ffebcd",
43245
+ blue: "00f",
43246
+ blueviolet: "8a2be2",
43247
+ brown: "a52a2a",
43248
+ burlywood: "deb887",
43249
+ burntsienna: "ea7e5d",
43250
+ cadetblue: "5f9ea0",
43251
+ chartreuse: "7fff00",
43252
+ chocolate: "d2691e",
43253
+ coral: "ff7f50",
43254
+ cornflowerblue: "6495ed",
43255
+ cornsilk: "fff8dc",
43256
+ crimson: "dc143c",
43257
+ cyan: "0ff",
43258
+ darkblue: "00008b",
43259
+ darkcyan: "008b8b",
43260
+ darkgoldenrod: "b8860b",
43261
+ darkgray: "a9a9a9",
43262
+ darkgreen: "006400",
43263
+ darkgrey: "a9a9a9",
43264
+ darkkhaki: "bdb76b",
43265
+ darkmagenta: "8b008b",
43266
+ darkolivegreen: "556b2f",
43267
+ darkorange: "ff8c00",
43268
+ darkorchid: "9932cc",
43269
+ darkred: "8b0000",
43270
+ darksalmon: "e9967a",
43271
+ darkseagreen: "8fbc8f",
43272
+ darkslateblue: "483d8b",
43273
+ darkslategray: "2f4f4f",
43274
+ darkslategrey: "2f4f4f",
43275
+ darkturquoise: "00ced1",
43276
+ darkviolet: "9400d3",
43277
+ deeppink: "ff1493",
43278
+ deepskyblue: "00bfff",
43279
+ dimgray: "696969",
43280
+ dimgrey: "696969",
43281
+ dodgerblue: "1e90ff",
43282
+ firebrick: "b22222",
43283
+ floralwhite: "fffaf0",
43284
+ forestgreen: "228b22",
43285
+ fuchsia: "f0f",
43286
+ gainsboro: "dcdcdc",
43287
+ ghostwhite: "f8f8ff",
43288
+ gold: "ffd700",
43289
+ goldenrod: "daa520",
43290
+ gray: "808080",
43291
+ green: "008000",
43292
+ greenyellow: "adff2f",
43293
+ grey: "808080",
43294
+ honeydew: "f0fff0",
43295
+ hotpink: "ff69b4",
43296
+ indianred: "cd5c5c",
43297
+ indigo: "4b0082",
43298
+ ivory: "fffff0",
43299
+ khaki: "f0e68c",
43300
+ lavender: "e6e6fa",
43301
+ lavenderblush: "fff0f5",
43302
+ lawngreen: "7cfc00",
43303
+ lemonchiffon: "fffacd",
43304
+ lightblue: "add8e6",
43305
+ lightcoral: "f08080",
43306
+ lightcyan: "e0ffff",
43307
+ lightgoldenrodyellow: "fafad2",
43308
+ lightgray: "d3d3d3",
43309
+ lightgreen: "90ee90",
43310
+ lightgrey: "d3d3d3",
43311
+ lightpink: "ffb6c1",
43312
+ lightsalmon: "ffa07a",
43313
+ lightseagreen: "20b2aa",
43314
+ lightskyblue: "87cefa",
43315
+ lightslategray: "789",
43316
+ lightslategrey: "789",
43317
+ lightsteelblue: "b0c4de",
43318
+ lightyellow: "ffffe0",
43319
+ lime: "0f0",
43320
+ limegreen: "32cd32",
43321
+ linen: "faf0e6",
43322
+ magenta: "f0f",
43323
+ maroon: "800000",
43324
+ mediumaquamarine: "66cdaa",
43325
+ mediumblue: "0000cd",
43326
+ mediumorchid: "ba55d3",
43327
+ mediumpurple: "9370db",
43328
+ mediumseagreen: "3cb371",
43329
+ mediumslateblue: "7b68ee",
43330
+ mediumspringgreen: "00fa9a",
43331
+ mediumturquoise: "48d1cc",
43332
+ mediumvioletred: "c71585",
43333
+ midnightblue: "191970",
43334
+ mintcream: "f5fffa",
43335
+ mistyrose: "ffe4e1",
43336
+ moccasin: "ffe4b5",
43337
+ navajowhite: "ffdead",
43338
+ navy: "000080",
43339
+ oldlace: "fdf5e6",
43340
+ olive: "808000",
43341
+ olivedrab: "6b8e23",
43342
+ orange: "ffa500",
43343
+ orangered: "ff4500",
43344
+ orchid: "da70d6",
43345
+ palegoldenrod: "eee8aa",
43346
+ palegreen: "98fb98",
43347
+ paleturquoise: "afeeee",
43348
+ palevioletred: "db7093",
43349
+ papayawhip: "ffefd5",
43350
+ peachpuff: "ffdab9",
43351
+ peru: "cd853f",
43352
+ pink: "ffc0cb",
43353
+ plum: "dda0dd",
43354
+ powderblue: "b0e0e6",
43355
+ purple: "800080",
43356
+ rebeccapurple: "663399",
43357
+ red: "f00",
43358
+ rosybrown: "bc8f8f",
43359
+ royalblue: "4169e1",
43360
+ saddlebrown: "8b4513",
43361
+ salmon: "fa8072",
43362
+ sandybrown: "f4a460",
43363
+ seagreen: "2e8b57",
43364
+ seashell: "fff5ee",
43365
+ sienna: "a0522d",
43366
+ silver: "c0c0c0",
43367
+ skyblue: "87ceeb",
43368
+ slateblue: "6a5acd",
43369
+ slategray: "708090",
43370
+ slategrey: "708090",
43371
+ snow: "fffafa",
43372
+ springgreen: "00ff7f",
43373
+ steelblue: "4682b4",
43374
+ tan: "d2b48c",
43375
+ teal: "008080",
43376
+ thistle: "d8bfd8",
43377
+ tomato: "ff6347",
43378
+ turquoise: "40e0d0",
43379
+ violet: "ee82ee",
43380
+ wheat: "f5deb3",
43381
+ white: "fff",
43382
+ whitesmoke: "f5f5f5",
43383
+ yellow: "ff0",
43384
+ yellowgreen: "9acd32",
43385
+ });
43386
+
43387
+ // Make it easy to access colors via `hexNames[hex]`
43388
+ var hexNames = (tinycolor.hexNames = flip(names));
43389
+
43390
+ // Utilities
43391
+ // ---------
43392
+
43393
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
43394
+ function flip(o) {
43395
+ var flipped = {};
43396
+ for (var i in o) {
43397
+ if (o.hasOwnProperty(i)) {
43398
+ flipped[o[i]] = i;
43399
+ }
43400
+ }
43401
+ return flipped;
43402
+ }
43403
+
43404
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
43405
+ function boundAlpha(a) {
43406
+ a = parseFloat(a);
43407
+
43408
+ if (isNaN(a) || a < 0 || a > 1) {
43409
+ a = 1;
43410
+ }
43411
+
43412
+ return a;
43413
+ }
43414
+
43415
+ // Take input from [0, n] and return it as [0, 1]
43416
+ function bound01(n, max) {
43417
+ if (isOnePointZero(n)) n = "100%";
43418
+
43419
+ var processPercent = isPercentage(n);
43420
+ n = Math.min(max, Math.max(0, parseFloat(n)));
43421
+
43422
+ // Automatically convert percentage into number
43423
+ if (processPercent) {
43424
+ n = parseInt(n * max, 10) / 100;
43425
+ }
43426
+
43427
+ // Handle floating point rounding errors
43428
+ if (Math.abs(n - max) < 0.000001) {
43429
+ return 1;
43430
+ }
43431
+
43432
+ // Convert into [0, 1] range if it isn't already
43433
+ return (n % max) / parseFloat(max);
43434
+ }
43435
+
43436
+ // Force a number between 0 and 1
43437
+ function clamp01(val) {
43438
+ return Math.min(1, Math.max(0, val));
43439
+ }
43440
+
43441
+ // Parse a base-16 hex value into a base-10 integer
43442
+ function parseIntFromHex(val) {
43443
+ return parseInt(val, 16);
43444
+ }
43445
+
43446
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
43447
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
43448
+ function isOnePointZero(n) {
43449
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
43450
+ }
43451
+
43452
+ // Check to see if string passed in is a percentage
43453
+ function isPercentage(n) {
43454
+ return typeof n === "string" && n.indexOf("%") != -1;
43455
+ }
43456
+
43457
+ // Force a hex value to have 2 characters
43458
+ function pad2(c) {
43459
+ return c.length == 1 ? "0" + c : "" + c;
43460
+ }
43461
+
43462
+ // Replace a decimal with it's percentage value
43463
+ function convertToPercentage(n) {
43464
+ if (n <= 1) {
43465
+ n = n * 100 + "%";
43466
+ }
43467
+
43468
+ return n;
43469
+ }
43470
+
43471
+ // Converts a decimal to a hex value
43472
+ function convertDecimalToHex(d) {
43473
+ return Math.round(parseFloat(d) * 255).toString(16);
43474
+ }
43475
+ // Converts a hex value to a decimal
43476
+ function convertHexToDecimal(h) {
43477
+ return parseIntFromHex(h) / 255;
43478
+ }
43479
+
43480
+ var matchers = (function () {
43481
+ // <http://www.w3.org/TR/css3-values/#integers>
43482
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
43483
+
43484
+ // <http://www.w3.org/TR/css3-values/#number-value>
43485
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
43486
+
43487
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
43488
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
43489
+
43490
+ // Actual matching.
43491
+ // Parentheses and commas are optional, but not required.
43492
+ // Whitespace can take the place of commas or opening paren
43493
+ var PERMISSIVE_MATCH3 =
43494
+ "[\\s|\\(]+(" +
43495
+ CSS_UNIT +
43496
+ ")[,|\\s]+(" +
43497
+ CSS_UNIT +
43498
+ ")[,|\\s]+(" +
43499
+ CSS_UNIT +
43500
+ ")\\s*\\)?";
43501
+ var PERMISSIVE_MATCH4 =
43502
+ "[\\s|\\(]+(" +
43503
+ CSS_UNIT +
43504
+ ")[,|\\s]+(" +
43505
+ CSS_UNIT +
43506
+ ")[,|\\s]+(" +
43507
+ CSS_UNIT +
43508
+ ")[,|\\s]+(" +
43509
+ CSS_UNIT +
43510
+ ")\\s*\\)?";
43511
+
43512
+ return {
43513
+ CSS_UNIT: new RegExp(CSS_UNIT),
43514
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
43515
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
43516
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
43517
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
43518
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
43519
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
43520
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
43521
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
43522
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
43523
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
43524
+ };
43525
+ })();
43526
+
43527
+ // `isValidCSSUnit`
43528
+ // Take in a single string / number and check to see if it looks like a CSS unit
43529
+ // (see `matchers` above for definition).
43530
+ function isValidCSSUnit(color) {
43531
+ return !!matchers.CSS_UNIT.exec(color);
43532
+ }
43533
+
43534
+ // `stringInputToObject`
43535
+ // Permissive string parsing. Take in a number of formats, and output an object
43536
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
43537
+ function stringInputToObject(color) {
43538
+ color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
43539
+ var named = false;
43540
+ if (names[color]) {
43541
+ color = names[color];
43542
+ named = true;
43543
+ } else if (color == "transparent") {
43544
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
43545
+ }
43546
+
43547
+ // Try to match string input using regular expressions.
43548
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
43549
+ // Just return an object and let the conversion functions handle that.
43550
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
43551
+ var match;
43552
+ if ((match = matchers.rgb.exec(color))) {
43553
+ return { r: match[1], g: match[2], b: match[3] };
43554
+ }
43555
+ if ((match = matchers.rgba.exec(color))) {
43556
+ return { r: match[1], g: match[2], b: match[3], a: match[4] };
43557
+ }
43558
+ if ((match = matchers.hsl.exec(color))) {
43559
+ return { h: match[1], s: match[2], l: match[3] };
43560
+ }
43561
+ if ((match = matchers.hsla.exec(color))) {
43562
+ return { h: match[1], s: match[2], l: match[3], a: match[4] };
43563
+ }
43564
+ if ((match = matchers.hsv.exec(color))) {
43565
+ return { h: match[1], s: match[2], v: match[3] };
43566
+ }
43567
+ if ((match = matchers.hsva.exec(color))) {
43568
+ return { h: match[1], s: match[2], v: match[3], a: match[4] };
43569
+ }
43570
+ if ((match = matchers.hex8.exec(color))) {
43571
+ return {
43572
+ r: parseIntFromHex(match[1]),
43573
+ g: parseIntFromHex(match[2]),
43574
+ b: parseIntFromHex(match[3]),
43575
+ a: convertHexToDecimal(match[4]),
43576
+ format: named ? "name" : "hex8",
43577
+ };
43578
+ }
43579
+ if ((match = matchers.hex6.exec(color))) {
43580
+ return {
43581
+ r: parseIntFromHex(match[1]),
43582
+ g: parseIntFromHex(match[2]),
43583
+ b: parseIntFromHex(match[3]),
43584
+ format: named ? "name" : "hex",
43585
+ };
43586
+ }
43587
+ if ((match = matchers.hex4.exec(color))) {
43588
+ return {
43589
+ r: parseIntFromHex(match[1] + "" + match[1]),
43590
+ g: parseIntFromHex(match[2] + "" + match[2]),
43591
+ b: parseIntFromHex(match[3] + "" + match[3]),
43592
+ a: convertHexToDecimal(match[4] + "" + match[4]),
43593
+ format: named ? "name" : "hex8",
43594
+ };
43595
+ }
43596
+ if ((match = matchers.hex3.exec(color))) {
43597
+ return {
43598
+ r: parseIntFromHex(match[1] + "" + match[1]),
43599
+ g: parseIntFromHex(match[2] + "" + match[2]),
43600
+ b: parseIntFromHex(match[3] + "" + match[3]),
43601
+ format: named ? "name" : "hex",
43602
+ };
43603
+ }
43604
+
43605
+ return false;
43606
+ }
43607
+
43608
+ function validateWCAG2Parms(parms) {
43609
+ // return valid WCAG2 parms for isReadable.
43610
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
43611
+ var level, size;
43612
+ parms = parms || { level: "AA", size: "small" };
43613
+ level = (parms.level || "AA").toUpperCase();
43614
+ size = (parms.size || "small").toLowerCase();
43615
+ if (level !== "AA" && level !== "AAA") {
43616
+ level = "AA";
43617
+ }
43618
+ if (size !== "small" && size !== "large") {
43619
+ size = "small";
43620
+ }
43621
+ return { level: level, size: size };
43622
+ }
43548
43623
 
43549
43624
  function _objectWithoutPropertiesLoose$3(source, excluded) {
43550
43625
  if (source == null) return {};
@@ -63834,14 +63909,14 @@
63834
63909
  });
63835
63910
 
63836
63911
  var colorStr2Hex = function colorStr2Hex(str) {
63837
- return isNaN(str) ? parseInt(tinyColor(str).toHex(), 16) : str;
63912
+ return isNaN(str) ? parseInt(tinycolor(str).toHex(), 16) : str;
63838
63913
  };
63839
63914
  var colorAlpha = function colorAlpha(str) {
63840
- return isNaN(str) ? tinyColor(str).getAlpha() : 1;
63915
+ return isNaN(str) ? tinycolor(str).getAlpha() : 1;
63841
63916
  };
63842
63917
  var color2ShaderArr = function color2ShaderArr(str) {
63843
63918
  var includeAlpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
63844
- var rgba = tinyColor(str).toRgb();
63919
+ var rgba = tinycolor(str).toRgb();
63845
63920
  var rgbArr = ['r', 'g', 'b'].map(function (d) {
63846
63921
  return rgba[d] / 255;
63847
63922
  });
@@ -64606,6 +64681,7 @@
64606
64681
  });
64607
64682
  });
64608
64683
  var topCurvatureResolution = state.hexTopCurvatureResolution;
64684
+ obj.geometry && obj.geometry.dispose();
64609
64685
  obj.geometry = new ConicPolygonBufferGeometry([geoJson], 0, GLOBE_RADIUS, false, true, true, topCurvatureResolution);
64610
64686
  var targetD = {
64611
64687
  alt: +altitudeAccessor(d)
@@ -64792,14 +64868,20 @@
64792
64868
  strokeObj.visible = addStroke;
64793
64869
 
64794
64870
  // regenerate geometries if needed
64795
- !objMatch(conicObj.geometry.parameters || {}, {
64871
+ if (!objMatch(conicObj.geometry.parameters || {}, {
64796
64872
  polygonGeoJson: coords,
64797
64873
  curvatureResolution: capCurvatureResolution
64798
- }) && (conicObj.geometry = new ConicPolygonBufferGeometry(coords, 0, GLOBE_RADIUS, false, true, true, capCurvatureResolution));
64799
- addStroke && (!strokeObj.geometry.parameters || strokeObj.geometry.parameters.geoJson.coordinates !== coords || strokeObj.geometry.parameters.resolution !== capCurvatureResolution) && (strokeObj.geometry = new GeoJsonGeometry({
64800
- type: 'Polygon',
64801
- coordinates: coords
64802
- }, GLOBE_RADIUS, capCurvatureResolution));
64874
+ })) {
64875
+ conicObj.geometry && conicObj.geometry.dispose();
64876
+ conicObj.geometry = new ConicPolygonBufferGeometry(coords, 0, GLOBE_RADIUS, false, true, true, capCurvatureResolution);
64877
+ }
64878
+ if (addStroke && (!strokeObj.geometry.parameters || strokeObj.geometry.parameters.geoJson.coordinates !== coords || strokeObj.geometry.parameters.resolution !== capCurvatureResolution)) {
64879
+ strokeObj.geometry && strokeObj.geometry.dispose();
64880
+ strokeObj.geometry = new GeoJsonGeometry({
64881
+ type: 'Polygon',
64882
+ coordinates: coords
64883
+ }, GLOBE_RADIUS, capCurvatureResolution);
64884
+ }
64803
64885
 
64804
64886
  // replace side/cap materials if defined
64805
64887
  conicObj.material[0] = sideMaterial || obj.__defaultSideMaterial;
@@ -65726,6 +65808,7 @@
65726
65808
 
65727
65809
  // create text geometry
65728
65810
  var textHeight = +sizeAccessor(d) * pxPerDeg;
65811
+ textObj.geometry && textObj.geometry.dispose();
65729
65812
  textObj.geometry = new THREE$5.TextGeometry(textAccessor(d), {
65730
65813
  font: state.font,
65731
65814
  size: textHeight,