globe.gl 2.26.11 → 2.26.12

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