futuro 0.6.2 → 0.6.3

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.
@@ -0,0 +1,1195 @@
1
+ // TinyColor v1.4.1
2
+ // https://github.com/bgrins/TinyColor
3
+ // Brian Grinstead, MIT License
4
+
5
+ (function(Math) {
6
+
7
+ var trimLeft = /^\s+/,
8
+ trimRight = /\s+$/,
9
+ tinyCounter = 0,
10
+ mathRound = Math.round,
11
+ mathMin = Math.min,
12
+ mathMax = Math.max,
13
+ mathRandom = Math.random;
14
+
15
+ function tinycolor (color, opts) {
16
+
17
+ color = (color) ? color : '';
18
+ opts = opts || { };
19
+
20
+ // If input is already a tinycolor, return itself
21
+ if (color instanceof tinycolor) {
22
+ return color;
23
+ }
24
+ // If we are called as a function, call using new instead
25
+ if (!(this instanceof tinycolor)) {
26
+ return new tinycolor(color, opts);
27
+ }
28
+
29
+ var rgb = inputToRGB(color);
30
+ this._originalInput = color,
31
+ this._r = rgb.r,
32
+ this._g = rgb.g,
33
+ this._b = rgb.b,
34
+ this._a = rgb.a,
35
+ this._roundA = mathRound(100*this._a) / 100,
36
+ this._format = opts.format || rgb.format;
37
+ this._gradientType = opts.gradientType;
38
+
39
+ // Don't let the range of [0,255] come back in [0,1].
40
+ // Potentially lose a little bit of precision here, but will fix issues where
41
+ // .5 gets interpreted as half of the total, instead of half of 1
42
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
43
+ if (this._r < 1) { this._r = mathRound(this._r); }
44
+ if (this._g < 1) { this._g = mathRound(this._g); }
45
+ if (this._b < 1) { this._b = mathRound(this._b); }
46
+
47
+ this._ok = rgb.ok;
48
+ this._tc_id = tinyCounter++;
49
+ }
50
+
51
+ tinycolor.prototype = {
52
+ isDark: function() {
53
+ return this.getBrightness() < 128;
54
+ },
55
+ isLight: function() {
56
+ return !this.isDark();
57
+ },
58
+ isValid: function() {
59
+ return this._ok;
60
+ },
61
+ getOriginalInput: function() {
62
+ return this._originalInput;
63
+ },
64
+ getFormat: function() {
65
+ return this._format;
66
+ },
67
+ getAlpha: function() {
68
+ return this._a;
69
+ },
70
+ getBrightness: function() {
71
+ //http://www.w3.org/TR/AERT#color-contrast
72
+ var rgb = this.toRgb();
73
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
74
+ },
75
+ getLuminance: function() {
76
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
77
+ var rgb = this.toRgb();
78
+ var RsRGB, GsRGB, BsRGB, R, G, B;
79
+ RsRGB = rgb.r/255;
80
+ GsRGB = rgb.g/255;
81
+ BsRGB = rgb.b/255;
82
+
83
+ if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
84
+ if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
85
+ if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
86
+ return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
87
+ },
88
+ setAlpha: function(value) {
89
+ this._a = boundAlpha(value);
90
+ this._roundA = mathRound(100*this._a) / 100;
91
+ return this;
92
+ },
93
+ toHsv: function() {
94
+ var hsv = rgbToHsv(this._r, this._g, this._b);
95
+ return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
96
+ },
97
+ toHsvString: function() {
98
+ var hsv = rgbToHsv(this._r, this._g, this._b);
99
+ var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
100
+ return (this._a == 1) ?
101
+ "hsv(" + h + ", " + s + "%, " + v + "%)" :
102
+ "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
103
+ },
104
+ toHsl: function() {
105
+ var hsl = rgbToHsl(this._r, this._g, this._b);
106
+ return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
107
+ },
108
+ toHslString: function() {
109
+ var hsl = rgbToHsl(this._r, this._g, this._b);
110
+ var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
111
+ return (this._a == 1) ?
112
+ "hsl(" + h + ", " + s + "%, " + l + "%)" :
113
+ "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
114
+ },
115
+ toHex: function(allow3Char) {
116
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
117
+ },
118
+ toHexString: function(allow3Char) {
119
+ return '#' + this.toHex(allow3Char);
120
+ },
121
+ toHex8: function(allow4Char) {
122
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
123
+ },
124
+ toHex8String: function(allow4Char) {
125
+ return '#' + this.toHex8(allow4Char);
126
+ },
127
+ toRgb: function() {
128
+ return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
129
+ },
130
+ toRgbString: function() {
131
+ return (this._a == 1) ?
132
+ "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
133
+ "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
134
+ },
135
+ toPercentageRgb: function() {
136
+ 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 };
137
+ },
138
+ toPercentageRgbString: function() {
139
+ return (this._a == 1) ?
140
+ "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
141
+ "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
142
+ },
143
+ toName: function() {
144
+ if (this._a === 0) {
145
+ return "transparent";
146
+ }
147
+
148
+ if (this._a < 1) {
149
+ return false;
150
+ }
151
+
152
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
153
+ },
154
+ toFilter: function(secondColor) {
155
+ var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
156
+ var secondHex8String = hex8String;
157
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
158
+
159
+ if (secondColor) {
160
+ var s = tinycolor(secondColor);
161
+ secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
162
+ }
163
+
164
+ return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
165
+ },
166
+ toString: function(format) {
167
+ var formatSet = !!format;
168
+ format = format || this._format;
169
+
170
+ var formattedString = false;
171
+ var hasAlpha = this._a < 1 && this._a >= 0;
172
+ var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
173
+
174
+ if (needsAlphaFormat) {
175
+ // Special case for "transparent", all other non-alpha formats
176
+ // will return rgba when there is transparency.
177
+ if (format === "name" && this._a === 0) {
178
+ return this.toName();
179
+ }
180
+ return this.toRgbString();
181
+ }
182
+ if (format === "rgb") {
183
+ formattedString = this.toRgbString();
184
+ }
185
+ if (format === "prgb") {
186
+ formattedString = this.toPercentageRgbString();
187
+ }
188
+ if (format === "hex" || format === "hex6") {
189
+ formattedString = this.toHexString();
190
+ }
191
+ if (format === "hex3") {
192
+ formattedString = this.toHexString(true);
193
+ }
194
+ if (format === "hex4") {
195
+ formattedString = this.toHex8String(true);
196
+ }
197
+ if (format === "hex8") {
198
+ formattedString = this.toHex8String();
199
+ }
200
+ if (format === "name") {
201
+ formattedString = this.toName();
202
+ }
203
+ if (format === "hsl") {
204
+ formattedString = this.toHslString();
205
+ }
206
+ if (format === "hsv") {
207
+ formattedString = this.toHsvString();
208
+ }
209
+
210
+ return formattedString || this.toHexString();
211
+ },
212
+ clone: function() {
213
+ return tinycolor(this.toString());
214
+ },
215
+
216
+ _applyModification: function(fn, args) {
217
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
218
+ this._r = color._r;
219
+ this._g = color._g;
220
+ this._b = color._b;
221
+ this.setAlpha(color._a);
222
+ return this;
223
+ },
224
+ lighten: function() {
225
+ return this._applyModification(lighten, arguments);
226
+ },
227
+ brighten: function() {
228
+ return this._applyModification(brighten, arguments);
229
+ },
230
+ darken: function() {
231
+ return this._applyModification(darken, arguments);
232
+ },
233
+ desaturate: function() {
234
+ return this._applyModification(desaturate, arguments);
235
+ },
236
+ saturate: function() {
237
+ return this._applyModification(saturate, arguments);
238
+ },
239
+ greyscale: function() {
240
+ return this._applyModification(greyscale, arguments);
241
+ },
242
+ spin: function() {
243
+ return this._applyModification(spin, arguments);
244
+ },
245
+
246
+ _applyCombination: function(fn, args) {
247
+ return fn.apply(null, [this].concat([].slice.call(args)));
248
+ },
249
+ analogous: function() {
250
+ return this._applyCombination(analogous, arguments);
251
+ },
252
+ complement: function() {
253
+ return this._applyCombination(complement, arguments);
254
+ },
255
+ monochromatic: function() {
256
+ return this._applyCombination(monochromatic, arguments);
257
+ },
258
+ splitcomplement: function() {
259
+ return this._applyCombination(splitcomplement, arguments);
260
+ },
261
+ triad: function() {
262
+ return this._applyCombination(triad, arguments);
263
+ },
264
+ tetrad: function() {
265
+ return this._applyCombination(tetrad, arguments);
266
+ }
267
+ };
268
+
269
+ // If input is an object, force 1 into "1.0" to handle ratios properly
270
+ // String input requires "1.0" as input, so 1 will be treated as 1
271
+ tinycolor.fromRatio = function(color, opts) {
272
+ if (typeof color == "object") {
273
+ var newColor = {};
274
+ for (var i in color) {
275
+ if (color.hasOwnProperty(i)) {
276
+ if (i === "a") {
277
+ newColor[i] = color[i];
278
+ }
279
+ else {
280
+ newColor[i] = convertToPercentage(color[i]);
281
+ }
282
+ }
283
+ }
284
+ color = newColor;
285
+ }
286
+
287
+ return tinycolor(color, opts);
288
+ };
289
+
290
+ // Given a string or object, convert that input to RGB
291
+ // Possible string inputs:
292
+ //
293
+ // "red"
294
+ // "#f00" or "f00"
295
+ // "#ff0000" or "ff0000"
296
+ // "#ff000000" or "ff000000"
297
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
298
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
299
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
300
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
301
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
302
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
303
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
304
+ //
305
+ function inputToRGB(color) {
306
+
307
+ var rgb = { r: 0, g: 0, b: 0 };
308
+ var a = 1;
309
+ var s = null;
310
+ var v = null;
311
+ var l = null;
312
+ var ok = false;
313
+ var format = false;
314
+
315
+ if (typeof color == "string") {
316
+ color = stringInputToObject(color);
317
+ }
318
+
319
+ if (typeof color == "object") {
320
+ if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
321
+ rgb = rgbToRgb(color.r, color.g, color.b);
322
+ ok = true;
323
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
324
+ }
325
+ else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
326
+ s = convertToPercentage(color.s);
327
+ v = convertToPercentage(color.v);
328
+ rgb = hsvToRgb(color.h, s, v);
329
+ ok = true;
330
+ format = "hsv";
331
+ }
332
+ else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
333
+ s = convertToPercentage(color.s);
334
+ l = convertToPercentage(color.l);
335
+ rgb = hslToRgb(color.h, s, l);
336
+ ok = true;
337
+ format = "hsl";
338
+ }
339
+
340
+ if (color.hasOwnProperty("a")) {
341
+ a = color.a;
342
+ }
343
+ }
344
+
345
+ a = boundAlpha(a);
346
+
347
+ return {
348
+ ok: ok,
349
+ format: color.format || format,
350
+ r: mathMin(255, mathMax(rgb.r, 0)),
351
+ g: mathMin(255, mathMax(rgb.g, 0)),
352
+ b: mathMin(255, mathMax(rgb.b, 0)),
353
+ a: a
354
+ };
355
+ }
356
+
357
+
358
+ // Conversion Functions
359
+ // --------------------
360
+
361
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
362
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
363
+
364
+ // `rgbToRgb`
365
+ // Handle bounds / percentage checking to conform to CSS color spec
366
+ // <http://www.w3.org/TR/css3-color/>
367
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
368
+ // *Returns:* { r, g, b } in [0, 255]
369
+ function rgbToRgb(r, g, b){
370
+ return {
371
+ r: bound01(r, 255) * 255,
372
+ g: bound01(g, 255) * 255,
373
+ b: bound01(b, 255) * 255
374
+ };
375
+ }
376
+
377
+ // `rgbToHsl`
378
+ // Converts an RGB color value to HSL.
379
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
380
+ // *Returns:* { h, s, l } in [0,1]
381
+ function rgbToHsl(r, g, b) {
382
+
383
+ r = bound01(r, 255);
384
+ g = bound01(g, 255);
385
+ b = bound01(b, 255);
386
+
387
+ var max = mathMax(r, g, b), min = mathMin(r, g, b);
388
+ var h, s, l = (max + min) / 2;
389
+
390
+ if(max == min) {
391
+ h = s = 0; // achromatic
392
+ }
393
+ else {
394
+ var d = max - min;
395
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
396
+ switch(max) {
397
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
398
+ case g: h = (b - r) / d + 2; break;
399
+ case b: h = (r - g) / d + 4; break;
400
+ }
401
+
402
+ h /= 6;
403
+ }
404
+
405
+ return { h: h, s: s, l: l };
406
+ }
407
+
408
+ // `hslToRgb`
409
+ // Converts an HSL color value to RGB.
410
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
411
+ // *Returns:* { r, g, b } in the set [0, 255]
412
+ function hslToRgb(h, s, l) {
413
+ var r, g, b;
414
+
415
+ h = bound01(h, 360);
416
+ s = bound01(s, 100);
417
+ l = bound01(l, 100);
418
+
419
+ function hue2rgb(p, q, t) {
420
+ if(t < 0) t += 1;
421
+ if(t > 1) t -= 1;
422
+ if(t < 1/6) return p + (q - p) * 6 * t;
423
+ if(t < 1/2) return q;
424
+ if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
425
+ return p;
426
+ }
427
+
428
+ if(s === 0) {
429
+ r = g = b = l; // achromatic
430
+ }
431
+ else {
432
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
433
+ var p = 2 * l - q;
434
+ r = hue2rgb(p, q, h + 1/3);
435
+ g = hue2rgb(p, q, h);
436
+ b = hue2rgb(p, q, h - 1/3);
437
+ }
438
+
439
+ return { r: r * 255, g: g * 255, b: b * 255 };
440
+ }
441
+
442
+ // `rgbToHsv`
443
+ // Converts an RGB color value to HSV
444
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
445
+ // *Returns:* { h, s, v } in [0,1]
446
+ function rgbToHsv(r, g, b) {
447
+
448
+ r = bound01(r, 255);
449
+ g = bound01(g, 255);
450
+ b = bound01(b, 255);
451
+
452
+ var max = mathMax(r, g, b), min = mathMin(r, g, b);
453
+ var h, s, v = max;
454
+
455
+ var d = max - min;
456
+ s = max === 0 ? 0 : d / max;
457
+
458
+ if(max == min) {
459
+ h = 0; // achromatic
460
+ }
461
+ else {
462
+ switch(max) {
463
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
464
+ case g: h = (b - r) / d + 2; break;
465
+ case b: h = (r - g) / d + 4; break;
466
+ }
467
+ h /= 6;
468
+ }
469
+ return { h: h, s: s, v: v };
470
+ }
471
+
472
+ // `hsvToRgb`
473
+ // Converts an HSV color value to RGB.
474
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
475
+ // *Returns:* { r, g, b } in the set [0, 255]
476
+ function hsvToRgb(h, s, v) {
477
+
478
+ h = bound01(h, 360) * 6;
479
+ s = bound01(s, 100);
480
+ v = bound01(v, 100);
481
+
482
+ var i = Math.floor(h),
483
+ f = h - i,
484
+ p = v * (1 - s),
485
+ q = v * (1 - f * s),
486
+ t = v * (1 - (1 - f) * s),
487
+ mod = i % 6,
488
+ r = [v, q, p, p, t, v][mod],
489
+ g = [t, v, v, q, p, p][mod],
490
+ b = [p, p, t, v, v, q][mod];
491
+
492
+ return { r: r * 255, g: g * 255, b: b * 255 };
493
+ }
494
+
495
+ // `rgbToHex`
496
+ // Converts an RGB color to hex
497
+ // Assumes r, g, and b are contained in the set [0, 255]
498
+ // Returns a 3 or 6 character hex
499
+ function rgbToHex(r, g, b, allow3Char) {
500
+
501
+ var hex = [
502
+ pad2(mathRound(r).toString(16)),
503
+ pad2(mathRound(g).toString(16)),
504
+ pad2(mathRound(b).toString(16))
505
+ ];
506
+
507
+ // Return a 3 character hex if possible
508
+ 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)) {
509
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
510
+ }
511
+
512
+ return hex.join("");
513
+ }
514
+
515
+ // `rgbaToHex`
516
+ // Converts an RGBA color plus alpha transparency to hex
517
+ // Assumes r, g, b are contained in the set [0, 255] and
518
+ // a in [0, 1]. Returns a 4 or 8 character rgba hex
519
+ function rgbaToHex(r, g, b, a, allow4Char) {
520
+
521
+ var hex = [
522
+ pad2(mathRound(r).toString(16)),
523
+ pad2(mathRound(g).toString(16)),
524
+ pad2(mathRound(b).toString(16)),
525
+ pad2(convertDecimalToHex(a))
526
+ ];
527
+
528
+ // Return a 4 character hex if possible
529
+ 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)) {
530
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
531
+ }
532
+
533
+ return hex.join("");
534
+ }
535
+
536
+ // `rgbaToArgbHex`
537
+ // Converts an RGBA color to an ARGB Hex8 string
538
+ // Rarely used, but required for "toFilter()"
539
+ function rgbaToArgbHex(r, g, b, a) {
540
+
541
+ var hex = [
542
+ pad2(convertDecimalToHex(a)),
543
+ pad2(mathRound(r).toString(16)),
544
+ pad2(mathRound(g).toString(16)),
545
+ pad2(mathRound(b).toString(16))
546
+ ];
547
+
548
+ return hex.join("");
549
+ }
550
+
551
+ // `equals`
552
+ // Can be called with any tinycolor input
553
+ tinycolor.equals = function (color1, color2) {
554
+ if (!color1 || !color2) { return false; }
555
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
556
+ };
557
+
558
+ tinycolor.random = function() {
559
+ return tinycolor.fromRatio({
560
+ r: mathRandom(),
561
+ g: mathRandom(),
562
+ b: mathRandom()
563
+ });
564
+ };
565
+
566
+
567
+ // Modification Functions
568
+ // ----------------------
569
+ // Thanks to less.js for some of the basics here
570
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
571
+
572
+ function desaturate(color, amount) {
573
+ amount = (amount === 0) ? 0 : (amount || 10);
574
+ var hsl = tinycolor(color).toHsl();
575
+ hsl.s -= amount / 100;
576
+ hsl.s = clamp01(hsl.s);
577
+ return tinycolor(hsl);
578
+ }
579
+
580
+ function saturate(color, amount) {
581
+ amount = (amount === 0) ? 0 : (amount || 10);
582
+ var hsl = tinycolor(color).toHsl();
583
+ hsl.s += amount / 100;
584
+ hsl.s = clamp01(hsl.s);
585
+ return tinycolor(hsl);
586
+ }
587
+
588
+ function greyscale(color) {
589
+ return tinycolor(color).desaturate(100);
590
+ }
591
+
592
+ function lighten (color, amount) {
593
+ amount = (amount === 0) ? 0 : (amount || 10);
594
+ var hsl = tinycolor(color).toHsl();
595
+ hsl.l += amount / 100;
596
+ hsl.l = clamp01(hsl.l);
597
+ return tinycolor(hsl);
598
+ }
599
+
600
+ function brighten(color, amount) {
601
+ amount = (amount === 0) ? 0 : (amount || 10);
602
+ var rgb = tinycolor(color).toRgb();
603
+ rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
604
+ rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
605
+ rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
606
+ return tinycolor(rgb);
607
+ }
608
+
609
+ function darken (color, amount) {
610
+ amount = (amount === 0) ? 0 : (amount || 10);
611
+ var hsl = tinycolor(color).toHsl();
612
+ hsl.l -= amount / 100;
613
+ hsl.l = clamp01(hsl.l);
614
+ return tinycolor(hsl);
615
+ }
616
+
617
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
618
+ // Values outside of this range will be wrapped into this range.
619
+ function spin(color, amount) {
620
+ var hsl = tinycolor(color).toHsl();
621
+ var hue = (hsl.h + amount) % 360;
622
+ hsl.h = hue < 0 ? 360 + hue : hue;
623
+ return tinycolor(hsl);
624
+ }
625
+
626
+ // Combination Functions
627
+ // ---------------------
628
+ // Thanks to jQuery xColor for some of the ideas behind these
629
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
630
+
631
+ function complement(color) {
632
+ var hsl = tinycolor(color).toHsl();
633
+ hsl.h = (hsl.h + 180) % 360;
634
+ return tinycolor(hsl);
635
+ }
636
+
637
+ function triad(color) {
638
+ var hsl = tinycolor(color).toHsl();
639
+ var h = hsl.h;
640
+ return [
641
+ tinycolor(color),
642
+ tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
643
+ tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
644
+ ];
645
+ }
646
+
647
+ function tetrad(color) {
648
+ var hsl = tinycolor(color).toHsl();
649
+ var h = hsl.h;
650
+ return [
651
+ tinycolor(color),
652
+ tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
653
+ tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
654
+ tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
655
+ ];
656
+ }
657
+
658
+ function splitcomplement(color) {
659
+ var hsl = tinycolor(color).toHsl();
660
+ var h = hsl.h;
661
+ return [
662
+ tinycolor(color),
663
+ tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
664
+ tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
665
+ ];
666
+ }
667
+
668
+ function analogous(color, results, slices) {
669
+ results = results || 6;
670
+ slices = slices || 30;
671
+
672
+ var hsl = tinycolor(color).toHsl();
673
+ var part = 360 / slices;
674
+ var ret = [tinycolor(color)];
675
+
676
+ for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
677
+ hsl.h = (hsl.h + part) % 360;
678
+ ret.push(tinycolor(hsl));
679
+ }
680
+ return ret;
681
+ }
682
+
683
+ function monochromatic(color, results) {
684
+ results = results || 6;
685
+ var hsv = tinycolor(color).toHsv();
686
+ var h = hsv.h, s = hsv.s, v = hsv.v;
687
+ var ret = [];
688
+ var modification = 1 / results;
689
+
690
+ while (results--) {
691
+ ret.push(tinycolor({ h: h, s: s, v: v}));
692
+ v = (v + modification) % 1;
693
+ }
694
+
695
+ return ret;
696
+ }
697
+
698
+ // Utility Functions
699
+ // ---------------------
700
+
701
+ tinycolor.mix = function(color1, color2, amount) {
702
+ amount = (amount === 0) ? 0 : (amount || 50);
703
+
704
+ var rgb1 = tinycolor(color1).toRgb();
705
+ var rgb2 = tinycolor(color2).toRgb();
706
+
707
+ var p = amount / 100;
708
+
709
+ var rgba = {
710
+ r: ((rgb2.r - rgb1.r) * p) + rgb1.r,
711
+ g: ((rgb2.g - rgb1.g) * p) + rgb1.g,
712
+ b: ((rgb2.b - rgb1.b) * p) + rgb1.b,
713
+ a: ((rgb2.a - rgb1.a) * p) + rgb1.a
714
+ };
715
+
716
+ return tinycolor(rgba);
717
+ };
718
+
719
+
720
+ // Readability Functions
721
+ // ---------------------
722
+ // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
723
+
724
+ // `contrast`
725
+ // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
726
+ tinycolor.readability = function(color1, color2) {
727
+ var c1 = tinycolor(color1);
728
+ var c2 = tinycolor(color2);
729
+ return (Math.max(c1.getLuminance(),c2.getLuminance())+0.05) / (Math.min(c1.getLuminance(),c2.getLuminance())+0.05);
730
+ };
731
+
732
+ // `isReadable`
733
+ // Ensure that foreground and background color combinations meet WCAG2 guidelines.
734
+ // The third argument is an optional Object.
735
+ // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
736
+ // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
737
+ // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
738
+
739
+ // *Example*
740
+ // tinycolor.isReadable("#000", "#111") => false
741
+ // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
742
+ tinycolor.isReadable = function(color1, color2, wcag2) {
743
+ var readability = tinycolor.readability(color1, color2);
744
+ var wcag2Parms, out;
745
+
746
+ out = false;
747
+
748
+ wcag2Parms = validateWCAG2Parms(wcag2);
749
+ switch (wcag2Parms.level + wcag2Parms.size) {
750
+ case "AAsmall":
751
+ case "AAAlarge":
752
+ out = readability >= 4.5;
753
+ break;
754
+ case "AAlarge":
755
+ out = readability >= 3;
756
+ break;
757
+ case "AAAsmall":
758
+ out = readability >= 7;
759
+ break;
760
+ }
761
+ return out;
762
+
763
+ };
764
+
765
+ // `mostReadable`
766
+ // Given a base color and a list of possible foreground or background
767
+ // colors for that base, returns the most readable color.
768
+ // Optionally returns Black or White if the most readable color is unreadable.
769
+ // *Example*
770
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
771
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
772
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
773
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
774
+ tinycolor.mostReadable = function(baseColor, colorList, args) {
775
+ var bestColor = null;
776
+ var bestScore = 0;
777
+ var readability;
778
+ var includeFallbackColors, level, size ;
779
+ args = args || {};
780
+ includeFallbackColors = args.includeFallbackColors ;
781
+ level = args.level;
782
+ size = args.size;
783
+
784
+ for (var i= 0; i < colorList.length ; i++) {
785
+ readability = tinycolor.readability(baseColor, colorList[i]);
786
+ if (readability > bestScore) {
787
+ bestScore = readability;
788
+ bestColor = tinycolor(colorList[i]);
789
+ }
790
+ }
791
+
792
+ if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) {
793
+ return bestColor;
794
+ }
795
+ else {
796
+ args.includeFallbackColors=false;
797
+ return tinycolor.mostReadable(baseColor,["#fff", "#000"],args);
798
+ }
799
+ };
800
+
801
+
802
+ // Big List of Colors
803
+ // ------------------
804
+ // <http://www.w3.org/TR/css3-color/#svg-color>
805
+ var names = tinycolor.names = {
806
+ aliceblue: "f0f8ff",
807
+ antiquewhite: "faebd7",
808
+ aqua: "0ff",
809
+ aquamarine: "7fffd4",
810
+ azure: "f0ffff",
811
+ beige: "f5f5dc",
812
+ bisque: "ffe4c4",
813
+ black: "000",
814
+ blanchedalmond: "ffebcd",
815
+ blue: "00f",
816
+ blueviolet: "8a2be2",
817
+ brown: "a52a2a",
818
+ burlywood: "deb887",
819
+ burntsienna: "ea7e5d",
820
+ cadetblue: "5f9ea0",
821
+ chartreuse: "7fff00",
822
+ chocolate: "d2691e",
823
+ coral: "ff7f50",
824
+ cornflowerblue: "6495ed",
825
+ cornsilk: "fff8dc",
826
+ crimson: "dc143c",
827
+ cyan: "0ff",
828
+ darkblue: "00008b",
829
+ darkcyan: "008b8b",
830
+ darkgoldenrod: "b8860b",
831
+ darkgray: "a9a9a9",
832
+ darkgreen: "006400",
833
+ darkgrey: "a9a9a9",
834
+ darkkhaki: "bdb76b",
835
+ darkmagenta: "8b008b",
836
+ darkolivegreen: "556b2f",
837
+ darkorange: "ff8c00",
838
+ darkorchid: "9932cc",
839
+ darkred: "8b0000",
840
+ darksalmon: "e9967a",
841
+ darkseagreen: "8fbc8f",
842
+ darkslateblue: "483d8b",
843
+ darkslategray: "2f4f4f",
844
+ darkslategrey: "2f4f4f",
845
+ darkturquoise: "00ced1",
846
+ darkviolet: "9400d3",
847
+ deeppink: "ff1493",
848
+ deepskyblue: "00bfff",
849
+ dimgray: "696969",
850
+ dimgrey: "696969",
851
+ dodgerblue: "1e90ff",
852
+ firebrick: "b22222",
853
+ floralwhite: "fffaf0",
854
+ forestgreen: "228b22",
855
+ fuchsia: "f0f",
856
+ gainsboro: "dcdcdc",
857
+ ghostwhite: "f8f8ff",
858
+ gold: "ffd700",
859
+ goldenrod: "daa520",
860
+ gray: "808080",
861
+ green: "008000",
862
+ greenyellow: "adff2f",
863
+ grey: "808080",
864
+ honeydew: "f0fff0",
865
+ hotpink: "ff69b4",
866
+ indianred: "cd5c5c",
867
+ indigo: "4b0082",
868
+ ivory: "fffff0",
869
+ khaki: "f0e68c",
870
+ lavender: "e6e6fa",
871
+ lavenderblush: "fff0f5",
872
+ lawngreen: "7cfc00",
873
+ lemonchiffon: "fffacd",
874
+ lightblue: "add8e6",
875
+ lightcoral: "f08080",
876
+ lightcyan: "e0ffff",
877
+ lightgoldenrodyellow: "fafad2",
878
+ lightgray: "d3d3d3",
879
+ lightgreen: "90ee90",
880
+ lightgrey: "d3d3d3",
881
+ lightpink: "ffb6c1",
882
+ lightsalmon: "ffa07a",
883
+ lightseagreen: "20b2aa",
884
+ lightskyblue: "87cefa",
885
+ lightslategray: "789",
886
+ lightslategrey: "789",
887
+ lightsteelblue: "b0c4de",
888
+ lightyellow: "ffffe0",
889
+ lime: "0f0",
890
+ limegreen: "32cd32",
891
+ linen: "faf0e6",
892
+ magenta: "f0f",
893
+ maroon: "800000",
894
+ mediumaquamarine: "66cdaa",
895
+ mediumblue: "0000cd",
896
+ mediumorchid: "ba55d3",
897
+ mediumpurple: "9370db",
898
+ mediumseagreen: "3cb371",
899
+ mediumslateblue: "7b68ee",
900
+ mediumspringgreen: "00fa9a",
901
+ mediumturquoise: "48d1cc",
902
+ mediumvioletred: "c71585",
903
+ midnightblue: "191970",
904
+ mintcream: "f5fffa",
905
+ mistyrose: "ffe4e1",
906
+ moccasin: "ffe4b5",
907
+ navajowhite: "ffdead",
908
+ navy: "000080",
909
+ oldlace: "fdf5e6",
910
+ olive: "808000",
911
+ olivedrab: "6b8e23",
912
+ orange: "ffa500",
913
+ orangered: "ff4500",
914
+ orchid: "da70d6",
915
+ palegoldenrod: "eee8aa",
916
+ palegreen: "98fb98",
917
+ paleturquoise: "afeeee",
918
+ palevioletred: "db7093",
919
+ papayawhip: "ffefd5",
920
+ peachpuff: "ffdab9",
921
+ peru: "cd853f",
922
+ pink: "ffc0cb",
923
+ plum: "dda0dd",
924
+ powderblue: "b0e0e6",
925
+ purple: "800080",
926
+ rebeccapurple: "663399",
927
+ red: "f00",
928
+ rosybrown: "bc8f8f",
929
+ royalblue: "4169e1",
930
+ saddlebrown: "8b4513",
931
+ salmon: "fa8072",
932
+ sandybrown: "f4a460",
933
+ seagreen: "2e8b57",
934
+ seashell: "fff5ee",
935
+ sienna: "a0522d",
936
+ silver: "c0c0c0",
937
+ skyblue: "87ceeb",
938
+ slateblue: "6a5acd",
939
+ slategray: "708090",
940
+ slategrey: "708090",
941
+ snow: "fffafa",
942
+ springgreen: "00ff7f",
943
+ steelblue: "4682b4",
944
+ tan: "d2b48c",
945
+ teal: "008080",
946
+ thistle: "d8bfd8",
947
+ tomato: "ff6347",
948
+ turquoise: "40e0d0",
949
+ violet: "ee82ee",
950
+ wheat: "f5deb3",
951
+ white: "fff",
952
+ whitesmoke: "f5f5f5",
953
+ yellow: "ff0",
954
+ yellowgreen: "9acd32"
955
+ };
956
+
957
+ // Make it easy to access colors via `hexNames[hex]`
958
+ var hexNames = tinycolor.hexNames = flip(names);
959
+
960
+
961
+ // Utilities
962
+ // ---------
963
+
964
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
965
+ function flip(o) {
966
+ var flipped = { };
967
+ for (var i in o) {
968
+ if (o.hasOwnProperty(i)) {
969
+ flipped[o[i]] = i;
970
+ }
971
+ }
972
+ return flipped;
973
+ }
974
+
975
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
976
+ function boundAlpha(a) {
977
+ a = parseFloat(a);
978
+
979
+ if (isNaN(a) || a < 0 || a > 1) {
980
+ a = 1;
981
+ }
982
+
983
+ return a;
984
+ }
985
+
986
+ // Take input from [0, n] and return it as [0, 1]
987
+ function bound01(n, max) {
988
+ if (isOnePointZero(n)) { n = "100%"; }
989
+
990
+ var processPercent = isPercentage(n);
991
+ n = mathMin(max, mathMax(0, parseFloat(n)));
992
+
993
+ // Automatically convert percentage into number
994
+ if (processPercent) {
995
+ n = parseInt(n * max, 10) / 100;
996
+ }
997
+
998
+ // Handle floating point rounding errors
999
+ if ((Math.abs(n - max) < 0.000001)) {
1000
+ return 1;
1001
+ }
1002
+
1003
+ // Convert into [0, 1] range if it isn't already
1004
+ return (n % max) / parseFloat(max);
1005
+ }
1006
+
1007
+ // Force a number between 0 and 1
1008
+ function clamp01(val) {
1009
+ return mathMin(1, mathMax(0, val));
1010
+ }
1011
+
1012
+ // Parse a base-16 hex value into a base-10 integer
1013
+ function parseIntFromHex(val) {
1014
+ return parseInt(val, 16);
1015
+ }
1016
+
1017
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
1018
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
1019
+ function isOnePointZero(n) {
1020
+ return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
1021
+ }
1022
+
1023
+ // Check to see if string passed in is a percentage
1024
+ function isPercentage(n) {
1025
+ return typeof n === "string" && n.indexOf('%') != -1;
1026
+ }
1027
+
1028
+ // Force a hex value to have 2 characters
1029
+ function pad2(c) {
1030
+ return c.length == 1 ? '0' + c : '' + c;
1031
+ }
1032
+
1033
+ // Replace a decimal with it's percentage value
1034
+ function convertToPercentage(n) {
1035
+ if (n <= 1) {
1036
+ n = (n * 100) + "%";
1037
+ }
1038
+
1039
+ return n;
1040
+ }
1041
+
1042
+ // Converts a decimal to a hex value
1043
+ function convertDecimalToHex(d) {
1044
+ return Math.round(parseFloat(d) * 255).toString(16);
1045
+ }
1046
+ // Converts a hex value to a decimal
1047
+ function convertHexToDecimal(h) {
1048
+ return (parseIntFromHex(h) / 255);
1049
+ }
1050
+
1051
+ var matchers = (function() {
1052
+
1053
+ // <http://www.w3.org/TR/css3-values/#integers>
1054
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
1055
+
1056
+ // <http://www.w3.org/TR/css3-values/#number-value>
1057
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
1058
+
1059
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
1060
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
1061
+
1062
+ // Actual matching.
1063
+ // Parentheses and commas are optional, but not required.
1064
+ // Whitespace can take the place of commas or opening paren
1065
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1066
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1067
+
1068
+ return {
1069
+ CSS_UNIT: new RegExp(CSS_UNIT),
1070
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
1071
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
1072
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
1073
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
1074
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
1075
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
1076
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1077
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1078
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1079
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1080
+ };
1081
+ })();
1082
+
1083
+ // `isValidCSSUnit`
1084
+ // Take in a single string / number and check to see if it looks like a CSS unit
1085
+ // (see `matchers` above for definition).
1086
+ function isValidCSSUnit(color) {
1087
+ return !!matchers.CSS_UNIT.exec(color);
1088
+ }
1089
+
1090
+ // `stringInputToObject`
1091
+ // Permissive string parsing. Take in a number of formats, and output an object
1092
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
1093
+ function stringInputToObject(color) {
1094
+
1095
+ color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
1096
+ var named = false;
1097
+ if (names[color]) {
1098
+ color = names[color];
1099
+ named = true;
1100
+ }
1101
+ else if (color == 'transparent') {
1102
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
1103
+ }
1104
+
1105
+ // Try to match string input using regular expressions.
1106
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1107
+ // Just return an object and let the conversion functions handle that.
1108
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
1109
+ var match;
1110
+ if ((match = matchers.rgb.exec(color))) {
1111
+ return { r: match[1], g: match[2], b: match[3] };
1112
+ }
1113
+ if ((match = matchers.rgba.exec(color))) {
1114
+ return { r: match[1], g: match[2], b: match[3], a: match[4] };
1115
+ }
1116
+ if ((match = matchers.hsl.exec(color))) {
1117
+ return { h: match[1], s: match[2], l: match[3] };
1118
+ }
1119
+ if ((match = matchers.hsla.exec(color))) {
1120
+ return { h: match[1], s: match[2], l: match[3], a: match[4] };
1121
+ }
1122
+ if ((match = matchers.hsv.exec(color))) {
1123
+ return { h: match[1], s: match[2], v: match[3] };
1124
+ }
1125
+ if ((match = matchers.hsva.exec(color))) {
1126
+ return { h: match[1], s: match[2], v: match[3], a: match[4] };
1127
+ }
1128
+ if ((match = matchers.hex8.exec(color))) {
1129
+ return {
1130
+ r: parseIntFromHex(match[1]),
1131
+ g: parseIntFromHex(match[2]),
1132
+ b: parseIntFromHex(match[3]),
1133
+ a: convertHexToDecimal(match[4]),
1134
+ format: named ? "name" : "hex8"
1135
+ };
1136
+ }
1137
+ if ((match = matchers.hex6.exec(color))) {
1138
+ return {
1139
+ r: parseIntFromHex(match[1]),
1140
+ g: parseIntFromHex(match[2]),
1141
+ b: parseIntFromHex(match[3]),
1142
+ format: named ? "name" : "hex"
1143
+ };
1144
+ }
1145
+ if ((match = matchers.hex4.exec(color))) {
1146
+ return {
1147
+ r: parseIntFromHex(match[1] + '' + match[1]),
1148
+ g: parseIntFromHex(match[2] + '' + match[2]),
1149
+ b: parseIntFromHex(match[3] + '' + match[3]),
1150
+ a: convertHexToDecimal(match[4] + '' + match[4]),
1151
+ format: named ? "name" : "hex8"
1152
+ };
1153
+ }
1154
+ if ((match = matchers.hex3.exec(color))) {
1155
+ return {
1156
+ r: parseIntFromHex(match[1] + '' + match[1]),
1157
+ g: parseIntFromHex(match[2] + '' + match[2]),
1158
+ b: parseIntFromHex(match[3] + '' + match[3]),
1159
+ format: named ? "name" : "hex"
1160
+ };
1161
+ }
1162
+
1163
+ return false;
1164
+ }
1165
+
1166
+ function validateWCAG2Parms(parms) {
1167
+ // return valid WCAG2 parms for isReadable.
1168
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
1169
+ var level, size;
1170
+ parms = parms || {"level":"AA", "size":"small"};
1171
+ level = (parms.level || "AA").toUpperCase();
1172
+ size = (parms.size || "small").toLowerCase();
1173
+ if (level !== "AA" && level !== "AAA") {
1174
+ level = "AA";
1175
+ }
1176
+ if (size !== "small" && size !== "large") {
1177
+ size = "small";
1178
+ }
1179
+ return {"level":level, "size":size};
1180
+ }
1181
+
1182
+ // Node: Export function
1183
+ if (typeof module !== "undefined" && module.exports) {
1184
+ module.exports = tinycolor;
1185
+ }
1186
+ // AMD/requirejs: Define the module
1187
+ else if (typeof define === 'function' && define.amd) {
1188
+ define(function () {return tinycolor;});
1189
+ }
1190
+ // Browser: Expose to window
1191
+ else {
1192
+ window.tinycolor = tinycolor;
1193
+ }
1194
+
1195
+ })(Math);