From 46d0657041f69a59cb4c9d64d1ea92dc2fa54d98 Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Mon, 28 Dec 2020 16:43:30 -0500 Subject: [PATCH 1/8] Update tinycolor.js --- tinycolor.js | 752 +++++++++++++++++++++++++++------------------------ 1 file changed, 398 insertions(+), 354 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 9ce79d84..ce4fb9a3 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -2,356 +2,390 @@ // https://github.com/bgrins/TinyColor // Brian Grinstead, MIT License -(function(Math) { +(function (Math) { + var trimLeft = /^\s+/, + trimRight = /\s+$/, + tinyCounter = 0, + mathRound = Math.round, + mathMin = Math.min, + mathMax = Math.max, + mathRandom = Math.random; + + class TinyColor { + constructor(color, opts) { + this.color = (color) ? color : ''; + this.opts = opts || {}; + + var rgb = inputToRGB(color); + this.originalInput = color, + this.red = rgb.r, + this.green = rgb.g, + this.blue = rgb.b, + this.alpha = rgb.a, + this.roundAlpha = mathRound(100 * this.alpha) / 100, + this.format = opts.format || rgb.format; + this.gradientType = opts.gradientType; + + // Don't let the range of [0,255] come back in [0,1]. + // Potentially lose a little bit of precision here, but will fix issues where + // .5 gets interpreted as half of the total, instead of half of 1 + // If it was supposed to be 128, this was already taken care of by `inputToRgb` + + if (this.red < 1) + this.red = mathRound(this.red); + if (this.green < 1) + this.green = mathRound(this.green); + if (this.blue < 1) + this.blue = mathRound(this.blue); + + this.ok = rgb.ok; + this.tinyColorId = tinyCounter++; + } -var trimLeft = /^\s+/, - trimRight = /\s+$/, - tinyCounter = 0, - mathRound = Math.round, - mathMin = Math.min, - mathMax = Math.max, - mathRandom = Math.random; + isDark() { + return this.getBrightness() < 128; + } + isLight() { + return !this.isDark(); + } -function tinycolor (color, opts) { + isValid() { + return this.ok; + } + getOriginalInput() { + return this.originalInput; + } + getFormat() { + return this.format; + } + getAlpha() { + return this.alpha; + } + getBrightness() { + //http://www.w3.org/TR/AERT#color-contrast + var rgb = this.toRgb(); + return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; + } - color = (color) ? color : ''; - opts = opts || { }; + getLuminance() { + //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef + var rgb = this.toRgb(), + RsRGB = rgb.r / 255, + GsRGB = rgb.g / 255, + BsRGB = rgb.b / 255, + R = (RsRGB <= 0.03928) ? RsRGB / 12.92 : Math.pow(((RsRGB + 0.055) / 1.055), 2.4), + G = (GsRGB <= 0.03928) ? GsRGB / 12.92 : Math.pow(((GsRGB + 0.055) / 1.055), 2.4), + B = (BsRGB <= 0.03928) ? BsRGB / 12.92 : Math.pow(((BsRGB + 0.055) / 1.055), 2.4); + return (0.2126 * R) + (0.7152 * G) + (0.0722 * B); + } - // If input is already a tinycolor, return itself - if (color instanceof tinycolor) { - return color; - } - // If we are called as a function, call using new instead - if (!(this instanceof tinycolor)) { - return new tinycolor(color, opts); - } + setAlpha(value) { + this.alpha = boundAlpha(value); + this.roundAlpha = mathRound(100 * this.alpha) / 100; + return this; + } - var rgb = inputToRGB(color); - this._originalInput = color, - this._r = rgb.r, - this._g = rgb.g, - this._b = rgb.b, - this._a = rgb.a, - this._roundA = mathRound(100*this._a) / 100, - this._format = opts.format || rgb.format; - this._gradientType = opts.gradientType; - - // Don't let the range of [0,255] come back in [0,1]. - // Potentially lose a little bit of precision here, but will fix issues where - // .5 gets interpreted as half of the total, instead of half of 1 - // If it was supposed to be 128, this was already taken care of by `inputToRgb` - if (this._r < 1) { this._r = mathRound(this._r); } - if (this._g < 1) { this._g = mathRound(this._g); } - if (this._b < 1) { this._b = mathRound(this._b); } - - this._ok = rgb.ok; - this._tc_id = tinyCounter++; -} + toHsv() { + var hsv = rgbToHsv(this.red, this.green, this.blue); + return { + h: hsv.h * 360, + s: hsv.s, + v: hsv.v, + a: this.alpha + }; + } + toHsvString() { + var hsv = rgbToHsv(this.red, this.green, this.blue), + h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100); + return (this.alpha == 1) ? + "hsv(" + h + ", " + s + "%, " + v + "%)" : + "hsva(" + h + ", " + s + "%, " + v + "%, " + this.roundAlpha + ")"; + } -tinycolor.prototype = { - isDark: function() { - return this.getBrightness() < 128; - }, - isLight: function() { - return !this.isDark(); - }, - isValid: function() { - return this._ok; - }, - getOriginalInput: function() { - return this._originalInput; - }, - getFormat: function() { - return this._format; - }, - getAlpha: function() { - return this._a; - }, - getBrightness: function() { - //http://www.w3.org/TR/AERT#color-contrast - var rgb = this.toRgb(); - return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; - }, - getLuminance: function() { - //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef - var rgb = this.toRgb(); - var RsRGB, GsRGB, BsRGB, R, G, B; - RsRGB = rgb.r/255; - GsRGB = rgb.g/255; - BsRGB = rgb.b/255; - - if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);} - if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);} - if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);} - return (0.2126 * R) + (0.7152 * G) + (0.0722 * B); - }, - setAlpha: function(value) { - this._a = boundAlpha(value); - this._roundA = mathRound(100*this._a) / 100; - return this; - }, - toHsv: function() { - var hsv = rgbToHsv(this._r, this._g, this._b); - return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a }; - }, - toHsvString: function() { - var hsv = rgbToHsv(this._r, this._g, this._b); - var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100); - return (this._a == 1) ? - "hsv(" + h + ", " + s + "%, " + v + "%)" : - "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")"; - }, - toHsl: function() { - var hsl = rgbToHsl(this._r, this._g, this._b); - return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a }; - }, - toHslString: function() { - var hsl = rgbToHsl(this._r, this._g, this._b); - var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100); - return (this._a == 1) ? - "hsl(" + h + ", " + s + "%, " + l + "%)" : - "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")"; - }, - toHex: function(allow3Char) { - return rgbToHex(this._r, this._g, this._b, allow3Char); - }, - toHexString: function(allow3Char) { - return '#' + this.toHex(allow3Char); - }, - toHex8: function(allow4Char) { - return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char); - }, - toHex8String: function(allow4Char) { - return '#' + this.toHex8(allow4Char); - }, - toRgb: function() { - return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a }; - }, - toRgbString: function() { - return (this._a == 1) ? - "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" : - "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")"; - }, - toPercentageRgb: function() { - 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 }; - }, - toPercentageRgbString: function() { - return (this._a == 1) ? - "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" : - "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")"; - }, - toName: function() { - if (this._a === 0) { - return "transparent"; + toHsl() { + var hsl = rgbToHsl(this.red, this.green, this.blue); + return { + h: hsl.h * 360, + s: hsl.s, + l: hsl.l, + a: this.alpha + }; + } + toHslString() { + var hsl = rgbToHsl(this.red, this.green, this.blue), + h = mathRound(hsl.h * 360), + s = mathRound(hsl.s * 100), + l = mathRound(hsl.l * 100); + return (this.alpha == 1) ? + "hsl(" + h + ", " + s + "%, " + l + "%)" : + "hsla(" + h + ", " + s + "%, " + l + "%, " + this.roundAlpha + ")"; } - if (this._a < 1) { - return false; + toHex(allow3Char) { + return rgbToHex(this.red, this.green, this.blue, allow3Char); + } + toHexString(allow3Char) { + return '#' + this.toHex(allow3Char); } - return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false; - }, - toFilter: function(secondColor) { - var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a); - var secondHex8String = hex8String; - var gradientType = this._gradientType ? "GradientType = 1, " : ""; + toHex8(allow4Char) { + return rgbaToHex(this.red, this.green, this.blue, this.alpha, allow4Char); + } + toHex8String(allow4Char) { + return '#' + this.toHex8(allow4Char); + } - if (secondColor) { - var s = tinycolor(secondColor); - secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a); + toRgb() { + return { + r: mathRound(this.red), + g: mathRound(this.green), + b: mathRound(this.blue), + a: this.alpha + }; + } + toRgbString() { + return (this.alpha == 1) ? + "rgb(" + mathRound(this.red) + ", " + mathRound(this.green) + ", " + mathRound(this.blue) + ")" : + "rgba(" + mathRound(this.red) + ", " + mathRound(this.green) + ", " + mathRound(this.blue) + ", " + this.roundAlpha + ")"; } + toCmyk() { + return rgbToCmyk(this.red, this.green, this.blue); + } + toCmykString() { + var cmyk = rgbToCmyk(this.red, this.green, this.blue); + return "cmyk(" + mathRound(cmyk.c * 100) + "," + mathRound(cmyk.m * 100) + "," + mathRound(cmyk.y * 100) + "," + mathRound(cmyk.k * 100) + ")"; + } + toPercentageRgb() { + return { + r: mathRound(bound01(this.red, 255) * 100) + "%", + g: mathRound(bound01(this.green, 255) * 100) + "%", + b: mathRound(bound01(this.blue, 255) * 100) + "%", + a: this.alpha + }; + } + toPercentageRgbString() { + return (this.alpha == 1) ? + "rgb(" + mathRound(bound01(this.red, 255) * 100) + "%, " + mathRound(bound01(this.green, 255) * 100) + "%, " + mathRound(bound01(this.blue, 255) * 100) + "%)" : + "rgba(" + mathRound(bound01(this.red, 255) * 100) + "%, " + mathRound(bound01(this.green, 255) * 100) + "%, " + mathRound(bound01(this.blue, 255) * 100) + "%, " + this.roundAlpha + ")"; + } + toName() { + if (this.alpha === 0) + return "transparent"; + + if (this.alpha < 1) + return false; - return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")"; - }, - toString: function(format) { - var formatSet = !!format; - format = format || this._format; - - var formattedString = false; - var hasAlpha = this._a < 1 && this._a >= 0; - var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name"); - - if (needsAlphaFormat) { - // Special case for "transparent", all other non-alpha formats - // will return rgba when there is transparency. - if (format === "name" && this._a === 0) { - return this.toName(); + return hexNames[rgbToHex(this.red, this.green, this.blue, true)] || false; + } + toFilter(secondColor) { + var hex8String = '#' + rgbaToArgbHex(this.red, this.green, this.blue, this.alpha), + secondHex8String = hex8String, + gradientType = this.gradientType ? "GradientType = 1, " : ""; + + if (secondColor) { + var s = tinycolor(secondColor); + secondHex8String = '#' + rgbaToArgbHex(s.red, s.green, s.blue, s.alpha); } - return this.toRgbString(); + + return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")"; } - if (format === "rgb") { - formattedString = this.toRgbString(); + toString(format) { + var formatSet = !!format; + format = format || this.format; + + var formattedString = false, + hasAlpha = this.alpha < 1 && this.alpha >= 0, + needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name"); + + if (needsAlphaFormat) { + // Special case for "transparent", all other non-alpha formats + // will return rgba when there is transparency. + + if (format === "name" && this.alpha === 0) return this.toName(); + return this.toRgbString(); + } + if (format === "rgb") + formattedString = this.toRgbString(); + + if (format === "prgb") + formattedString = this.toPercentageRgbString(); + + if (format === "hex" || format === "hex6") + formattedString = this.toHexString(); + + if (format === "hex3") + formattedString = this.toHexString(true); + + if (format === "hex4") + formattedString = this.toHex8String(true); + + if (format === "hex8") + formattedString = this.toHex8String(); + + if (format === "name") + formattedString = this.toName(); + + if (format === "hsl") + formattedString = this.toHslString(); + + if (format === "hsv") + formattedString = this.toHsvString(); + + return formattedString || this.toHexString(); } - if (format === "prgb") { - formattedString = this.toPercentageRgbString(); + + clone() { + return new TinyColor(this.toString()); } - if (format === "hex" || format === "hex6") { - formattedString = this.toHexString(); + + applyModification(fn, args) { + var color = fn.apply(null, [this].concat([].slice.call(args))); + this.red = color.red; + this.green = color.green; + this.blue = color.blue; + this.setAlpha(color.alpha); + return this; + } + + lighten() { + return this.applyModification(lighten, arguments); } - if (format === "hex3") { - formattedString = this.toHexString(true); + brighten() { + return this.applyModification(brighten, arguments); } - if (format === "hex4") { - formattedString = this.toHex8String(true); + + darken() { + return this.applyModification(darken, arguments); } - if (format === "hex8") { - formattedString = this.toHex8String(); + + desaturate() { + return this.applyModification(desaturate, arguments); } - if (format === "name") { - formattedString = this.toName(); + saturate() { + return this.applyModification(saturate, arguments); } - if (format === "hsl") { - formattedString = this.toHslString(); + + greyscale() { + return this.applyModification(greyscale, arguments); } - if (format === "hsv") { - formattedString = this.toHsvString(); + spin() { + return this.applyModification(spin, arguments); } - return formattedString || this.toHexString(); - }, - clone: function() { - return tinycolor(this.toString()); - }, - - _applyModification: function(fn, args) { - var color = fn.apply(null, [this].concat([].slice.call(args))); - this._r = color._r; - this._g = color._g; - this._b = color._b; - this.setAlpha(color._a); - return this; - }, - lighten: function() { - return this._applyModification(lighten, arguments); - }, - brighten: function() { - return this._applyModification(brighten, arguments); - }, - darken: function() { - return this._applyModification(darken, arguments); - }, - desaturate: function() { - return this._applyModification(desaturate, arguments); - }, - saturate: function() { - return this._applyModification(saturate, arguments); - }, - greyscale: function() { - return this._applyModification(greyscale, arguments); - }, - spin: function() { - return this._applyModification(spin, arguments); - }, - - _applyCombination: function(fn, args) { - return fn.apply(null, [this].concat([].slice.call(args))); - }, - analogous: function() { - return this._applyCombination(analogous, arguments); - }, - complement: function() { - return this._applyCombination(complement, arguments); - }, - monochromatic: function() { - return this._applyCombination(monochromatic, arguments); - }, - splitcomplement: function() { - return this._applyCombination(splitcomplement, arguments); - }, - triad: function() { - return this._applyCombination(triad, arguments); - }, - tetrad: function() { - return this._applyCombination(tetrad, arguments); - } -}; + _applyCombination(fn, args) { + return fn.apply(null, [this].concat([].slice.call(args))); + } -// If input is an object, force 1 into "1.0" to handle ratios properly -// String input requires "1.0" as input, so 1 will be treated as 1 -tinycolor.fromRatio = function(color, opts) { - if (typeof color == "object") { - var newColor = {}; - for (var i in color) { - if (color.hasOwnProperty(i)) { - if (i === "a") { - newColor[i] = color[i]; - } - else { - newColor[i] = convertToPercentage(color[i]); - } - } + analogous() { + return this._applyCombination(analogous, arguments); } - color = newColor; - } - return tinycolor(color, opts); -}; + complement() { + return this._applyCombination(complement, arguments); + } -// Given a string or object, convert that input to RGB -// Possible string inputs: -// -// "red" -// "#f00" or "f00" -// "#ff0000" or "ff0000" -// "#ff000000" or "ff000000" -// "rgb 255 0 0" or "rgb (255, 0, 0)" -// "rgb 1.0 0 0" or "rgb (1, 0, 0)" -// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1" -// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1" -// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%" -// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1" -// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" -// -function inputToRGB(color) { - - var rgb = { r: 0, g: 0, b: 0 }; - var a = 1; - var s = null; - var v = null; - var l = null; - var ok = false; - var format = false; - - if (typeof color == "string") { - color = stringInputToObject(color); - } + monochromatic() { + return this._applyCombination(monochromatic, arguments); + } - if (typeof color == "object") { - if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) { - rgb = rgbToRgb(color.r, color.g, color.b); - ok = true; - format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb"; + splitcomplement() { + return this._applyCombination(splitcomplement, arguments); } - else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) { - s = convertToPercentage(color.s); - v = convertToPercentage(color.v); - rgb = hsvToRgb(color.h, s, v); - ok = true; - format = "hsv"; + + triad() { + return this._applyCombination(triad, arguments); } - else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) { - s = convertToPercentage(color.s); - l = convertToPercentage(color.l); - rgb = hslToRgb(color.h, s, l); - ok = true; - format = "hsl"; + + tetrad() { + return this._applyCombination(tetrad, arguments); } - if (color.hasOwnProperty("a")) { - a = color.a; + // If input is an object, force 1 into "1.0" to handle ratios properly + // String input requires "1.0" as input, so 1 will be treated as 1 + fromRatio(color, opts) { + if (typeof color == "object") { + var newColor = {}; + for (var i in color) { + if (color.hasOwnProperty(i)) { + if (i === "a") + newColor[i] = color[i]; + else + newColor[i] = convertToPercentage(color[i]); + } + } + color = newColor; + } + return new TinyColor(color, opts); + }; + + // Given a string or object, convert that input to RGB + // Possible string inputs: + // + // "red" + // "#f00" or "f00" + // "#ff0000" or "ff0000" + // "#ff000000" or "ff000000" + // "rgb 255 0 0" or "rgb (255, 0, 0)" + // "rgb 1.0 0 0" or "rgb (1, 0, 0)" + // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1" + // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1" + // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%" + // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1" + // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" + // + inputToRGB(color) { + + var rgb = { + r: 0, + g: 0, + b: 0 } - } + a = 1, + s = null, + v = null, + l = null, + ok = false, + format = false; + + if (typeof color == "string") + color = stringInputToObject(color); + + if (typeof color == "object") { + if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) { + rgb = rgbToRgb(color.r, color.g, color.b); + ok = true; + format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb"; + } + else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) { + s = convertToPercentage(color.s); + v = convertToPercentage(color.v); + rgb = hsvToRgb(color.h, s, v); + ok = true; + format = "hsv"; + } + else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) { + s = convertToPercentage(color.s); + l = convertToPercentage(color.l); + rgb = hslToRgb(color.h, s, l); + ok = true; + format = "hsl"; + } - a = boundAlpha(a); + if (color.hasOwnProperty("a")) + a = color.a; + } - return { - ok: ok, - format: color.format || format, - r: mathMin(255, mathMax(rgb.r, 0)), - g: mathMin(255, mathMax(rgb.g, 0)), - b: mathMin(255, mathMax(rgb.b, 0)), - a: a - }; + a = boundAlpha(a); + + return { + ok: ok, + format: color.format || format, + r: mathMin(255, mathMax(rgb.r, 0)), + g: mathMin(255, mathMax(rgb.g, 0)), + b: mathMin(255, mathMax(rgb.b, 0)), + a: a + }; + } } @@ -366,7 +400,7 @@ function inputToRGB(color) { // // *Assumes:* r, g, b in [0, 255] or [0, 1] // *Returns:* { r, g, b } in [0, 255] -function rgbToRgb(r, g, b){ +function rgbToRgb(r, g, b) { return { r: bound01(r, 255) * 255, g: bound01(g, 255) * 255, @@ -387,13 +421,13 @@ function rgbToHsl(r, g, b) { var max = mathMax(r, g, b), min = mathMin(r, g, b); var h, s, l = (max + min) / 2; - if(max == min) { + if (max == min) { h = s = 0; // achromatic } else { var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - switch(max) { + switch (max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; @@ -417,23 +451,23 @@ function hslToRgb(h, s, l) { l = bound01(l, 100); function hue2rgb(p, q, t) { - if(t < 0) t += 1; - if(t > 1) t -= 1; - if(t < 1/6) return p + (q - p) * 6 * t; - if(t < 1/2) return q; - if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; + if (t < 0) t += 1; + if (t > 1) t -= 1; + if (t < 1 / 6) return p + (q - p) * 6 * t; + if (t < 1 / 2) return q; + if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; return p; } - if(s === 0) { + if (s === 0) { r = g = b = l; // achromatic } else { var q = l < 0.5 ? l * (1 + s) : l + s - l * s; var p = 2 * l - q; - r = hue2rgb(p, q, h + 1/3); + r = hue2rgb(p, q, h + 1 / 3); g = hue2rgb(p, q, h); - b = hue2rgb(p, q, h - 1/3); + b = hue2rgb(p, q, h - 1 / 3); } return { r: r * 255, g: g * 255, b: b * 255 }; @@ -455,11 +489,11 @@ function rgbToHsv(r, g, b) { var d = max - min; s = max === 0 ? 0 : d / max; - if(max == min) { + if (max == min) { h = 0; // achromatic } else { - switch(max) { + switch (max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; @@ -473,7 +507,7 @@ function rgbToHsv(r, g, b) { // Converts an HSV color value to RGB. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100] // *Returns:* { r, g, b } in the set [0, 255] - function hsvToRgb(h, s, v) { +function hsvToRgb(h, s, v) { h = bound01(h, 360) * 6; s = bound01(s, 100); @@ -548,6 +582,16 @@ function rgbaToArgbHex(r, g, b, a) { return hex.join(""); } +// `rgbToCmyk` +// Converts RGB color to CMYK +function rgbToCmyk(r, g, b) { + var R = r / 255, + G = g / 255, + B = b / 255, + K = 1 - Math.max(R, G, B); + return { c: (1 - R - K) / (1 - K), m: (1 - B - K) / (1 - K), y: (1 - G - K) / (1 - K), k: K }; +} + // `equals` // Can be called with any tinycolor input tinycolor.equals = function (color1, color2) { @@ -555,7 +599,7 @@ tinycolor.equals = function (color1, color2) { return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString(); }; -tinycolor.random = function() { +tinycolor.random = function () { return tinycolor.fromRatio({ r: mathRandom(), g: mathRandom(), @@ -589,7 +633,7 @@ function greyscale(color) { return tinycolor(color).desaturate(100); } -function lighten (color, amount) { +function lighten(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); var hsl = tinycolor(color).toHsl(); hsl.l += amount / 100; @@ -606,7 +650,7 @@ function brighten(color, amount) { return tinycolor(rgb); } -function darken (color, amount) { +function darken(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); var hsl = tinycolor(color).toHsl(); hsl.l -= amount / 100; @@ -660,8 +704,8 @@ function splitcomplement(color) { var h = hsl.h; return [ tinycolor(color), - tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}), - tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l}) + tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }), + tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }) ]; } @@ -673,7 +717,7 @@ function analogous(color, results, slices) { var part = 360 / slices; var ret = [tinycolor(color)]; - for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) { + for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results;) { hsl.h = (hsl.h + part) % 360; ret.push(tinycolor(hsl)); } @@ -688,7 +732,7 @@ function monochromatic(color, results) { var modification = 1 / results; while (results--) { - ret.push(tinycolor({ h: h, s: s, v: v})); + ret.push(tinycolor({ h: h, s: s, v: v })); v = (v + modification) % 1; } @@ -698,7 +742,7 @@ function monochromatic(color, results) { // Utility Functions // --------------------- -tinycolor.mix = function(color1, color2, amount) { +tinycolor.mix = function (color1, color2, amount) { amount = (amount === 0) ? 0 : (amount || 50); var rgb1 = tinycolor(color1).toRgb(); @@ -723,10 +767,10 @@ tinycolor.mix = function(color1, color2, amount) { // `contrast` // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2) -tinycolor.readability = function(color1, color2) { +tinycolor.readability = function (color1, color2) { var c1 = tinycolor(color1); var c2 = tinycolor(color2); - return (Math.max(c1.getLuminance(),c2.getLuminance())+0.05) / (Math.min(c1.getLuminance(),c2.getLuminance())+0.05); + return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05); }; // `isReadable` @@ -739,7 +783,7 @@ tinycolor.readability = function(color1, color2) { // *Example* // tinycolor.isReadable("#000", "#111") => false // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false -tinycolor.isReadable = function(color1, color2, wcag2) { +tinycolor.isReadable = function (color1, color2, wcag2) { var readability = tinycolor.readability(color1, color2); var wcag2Parms, out; @@ -771,17 +815,17 @@ tinycolor.isReadable = function(color1, color2, wcag2) { // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff" // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3" // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff" -tinycolor.mostReadable = function(baseColor, colorList, args) { +tinycolor.mostReadable = function (baseColor, colorList, args) { var bestColor = null; var bestScore = 0; var readability; - var includeFallbackColors, level, size ; + var includeFallbackColors, level, size; args = args || {}; - includeFallbackColors = args.includeFallbackColors ; + includeFallbackColors = args.includeFallbackColors; level = args.level; size = args.size; - for (var i= 0; i < colorList.length ; i++) { + for (var i = 0; i < colorList.length; i++) { readability = tinycolor.readability(baseColor, colorList[i]); if (readability > bestScore) { bestScore = readability; @@ -789,12 +833,12 @@ tinycolor.mostReadable = function(baseColor, colorList, args) { } } - if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) { + if (tinycolor.isReadable(baseColor, bestColor, { "level": level, "size": size }) || !includeFallbackColors) { return bestColor; } else { - args.includeFallbackColors=false; - return tinycolor.mostReadable(baseColor,["#fff", "#000"],args); + args.includeFallbackColors = false; + return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args); } }; @@ -963,7 +1007,7 @@ var hexNames = tinycolor.hexNames = flip(names); // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }` function flip(o) { - var flipped = { }; + var flipped = {}; for (var i in o) { if (o.hasOwnProperty(i)) { flipped[o[i]] = i; @@ -1048,7 +1092,7 @@ function convertHexToDecimal(h) { return (parseIntFromHex(h) / 255); } -var matchers = (function() { +var matchers = (function () { // var CSS_INTEGER = "[-\\+]?\\d+%?"; @@ -1092,7 +1136,7 @@ function isValidCSSUnit(color) { // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}` function stringInputToObject(color) { - color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase(); + color = color.replace(trimLeft, '').replace(trimRight, '').toLowerCase(); var named = false; if (names[color]) { color = names[color]; @@ -1167,7 +1211,7 @@ function validateWCAG2Parms(parms) { // return valid WCAG2 parms for isReadable. // If input parms are invalid, return {"level":"AA", "size":"small"} var level, size; - parms = parms || {"level":"AA", "size":"small"}; + parms = parms || { "level": "AA", "size": "small" }; level = (parms.level || "AA").toUpperCase(); size = (parms.size || "small").toLowerCase(); if (level !== "AA" && level !== "AAA") { @@ -1176,20 +1220,20 @@ function validateWCAG2Parms(parms) { if (size !== "small" && size !== "large") { size = "small"; } - return {"level":level, "size":size}; + return { "level": level, "size": size }; } // Node: Export function if (typeof module !== "undefined" && module.exports) { - module.exports = tinycolor; + module.exports = TinyColor; } // AMD/requirejs: Define the module -else if (typeof define === 'function' && define.amd) { - define(function () {return tinycolor;}); +else if (typeof define === 'class' && define.amd) { + define(function () { return TinyColor; }); } // Browser: Expose to window else { window.tinycolor = tinycolor; } -})(Math); +}) (Math); From cc68c41f28c82a3ea57a67508527f9398f987d9f Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Mon, 28 Dec 2020 18:23:29 -0500 Subject: [PATCH 2/8] Update tinycolor.js --- tinycolor.js | 96 ++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index ce4fb9a3..e1224a9a 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -2,14 +2,9 @@ // https://github.com/bgrins/TinyColor // Brian Grinstead, MIT License -(function (Math) { var trimLeft = /^\s+/, trimRight = /\s+$/, - tinyCounter = 0, - mathRound = Math.round, - mathMin = Math.min, - mathMax = Math.max, - mathRandom = Math.random; + tinyCounter = 0 class TinyColor { constructor(color, opts) { @@ -22,7 +17,7 @@ this.green = rgb.g, this.blue = rgb.b, this.alpha = rgb.a, - this.roundAlpha = mathRound(100 * this.alpha) / 100, + this.roundAlpha = Math.round(100 * this.alpha) / 100, this.format = opts.format || rgb.format; this.gradientType = opts.gradientType; @@ -32,11 +27,11 @@ // If it was supposed to be 128, this was already taken care of by `inputToRgb` if (this.red < 1) - this.red = mathRound(this.red); + this.red = Math.round(this.red); if (this.green < 1) - this.green = mathRound(this.green); + this.green = Math.round(this.green); if (this.blue < 1) - this.blue = mathRound(this.blue); + this.blue = Math.round(this.blue); this.ok = rgb.ok; this.tinyColorId = tinyCounter++; @@ -81,7 +76,7 @@ setAlpha(value) { this.alpha = boundAlpha(value); - this.roundAlpha = mathRound(100 * this.alpha) / 100; + this.roundAlpha = Math.round(100 * this.alpha) / 100; return this; } @@ -96,7 +91,7 @@ } toHsvString() { var hsv = rgbToHsv(this.red, this.green, this.blue), - h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100); + h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100); return (this.alpha == 1) ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this.roundAlpha + ")"; @@ -113,9 +108,9 @@ } toHslString() { var hsl = rgbToHsl(this.red, this.green, this.blue), - h = mathRound(hsl.h * 360), - s = mathRound(hsl.s * 100), - l = mathRound(hsl.l * 100); + h = Math.round(hsl.h * 360), + s = Math.round(hsl.s * 100), + l = Math.round(hsl.l * 100); return (this.alpha == 1) ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this.roundAlpha + ")"; @@ -137,36 +132,36 @@ toRgb() { return { - r: mathRound(this.red), - g: mathRound(this.green), - b: mathRound(this.blue), + r: Math.round(this.red), + g: Math.round(this.green), + b: Math.round(this.blue), a: this.alpha }; } toRgbString() { return (this.alpha == 1) ? - "rgb(" + mathRound(this.red) + ", " + mathRound(this.green) + ", " + mathRound(this.blue) + ")" : - "rgba(" + mathRound(this.red) + ", " + mathRound(this.green) + ", " + mathRound(this.blue) + ", " + this.roundAlpha + ")"; + "rgb(" + Math.round(this.red) + ", " + Math.round(this.green) + ", " + Math.round(this.blue) + ")" : + "rgba(" + Math.round(this.red) + ", " + Math.round(this.green) + ", " + Math.round(this.blue) + ", " + this.roundAlpha + ")"; } toCmyk() { return rgbToCmyk(this.red, this.green, this.blue); } toCmykString() { var cmyk = rgbToCmyk(this.red, this.green, this.blue); - return "cmyk(" + mathRound(cmyk.c * 100) + "," + mathRound(cmyk.m * 100) + "," + mathRound(cmyk.y * 100) + "," + mathRound(cmyk.k * 100) + ")"; + return "cmyk(" + Math.round(cmyk.c * 100) + "," + Math.round(cmyk.m * 100) + "," + Math.round(cmyk.y * 100) + "," + Math.round(cmyk.k * 100) + ")"; } toPercentageRgb() { return { - r: mathRound(bound01(this.red, 255) * 100) + "%", - g: mathRound(bound01(this.green, 255) * 100) + "%", - b: mathRound(bound01(this.blue, 255) * 100) + "%", + r: Math.round(bound01(this.red, 255) * 100) + "%", + g: Math.round(bound01(this.green, 255) * 100) + "%", + b: Math.round(bound01(this.blue, 255) * 100) + "%", a: this.alpha }; } toPercentageRgbString() { return (this.alpha == 1) ? - "rgb(" + mathRound(bound01(this.red, 255) * 100) + "%, " + mathRound(bound01(this.green, 255) * 100) + "%, " + mathRound(bound01(this.blue, 255) * 100) + "%)" : - "rgba(" + mathRound(bound01(this.red, 255) * 100) + "%, " + mathRound(bound01(this.green, 255) * 100) + "%, " + mathRound(bound01(this.blue, 255) * 100) + "%, " + this.roundAlpha + ")"; + "rgb(" + Math.round(bound01(this.red, 255) * 100) + "%, " + Math.round(bound01(this.green, 255) * 100) + "%, " + Math.round(bound01(this.blue, 255) * 100) + "%)" : + "rgba(" + Math.round(bound01(this.red, 255) * 100) + "%, " + Math.round(bound01(this.green, 255) * 100) + "%, " + Math.round(bound01(this.blue, 255) * 100) + "%, " + this.roundAlpha + ")"; } toName() { if (this.alpha === 0) @@ -380,9 +375,9 @@ return { ok: ok, format: color.format || format, - r: mathMin(255, mathMax(rgb.r, 0)), - g: mathMin(255, mathMax(rgb.g, 0)), - b: mathMin(255, mathMax(rgb.b, 0)), + r: Math.min(255, Math.max(rgb.r, 0)), + g: Math.min(255, Math.max(rgb.g, 0)), + b: Math.min(255, Math.max(rgb.b, 0)), a: a }; } @@ -418,7 +413,7 @@ function rgbToHsl(r, g, b) { g = bound01(g, 255); b = bound01(b, 255); - var max = mathMax(r, g, b), min = mathMin(r, g, b); + var max = Math.max(r, g, b), min = Math.min(r, g, b); var h, s, l = (max + min) / 2; if (max == min) { @@ -483,7 +478,7 @@ function rgbToHsv(r, g, b) { g = bound01(g, 255); b = bound01(b, 255); - var max = mathMax(r, g, b), min = mathMin(r, g, b); + var max = Math.max(r, g, b), min = Math.min(r, g, b); var h, s, v = max; var d = max - min; @@ -533,9 +528,9 @@ function hsvToRgb(h, s, v) { function rgbToHex(r, g, b, allow3Char) { var hex = [ - pad2(mathRound(r).toString(16)), - pad2(mathRound(g).toString(16)), - pad2(mathRound(b).toString(16)) + pad2(Math.round(r).toString(16)), + pad2(Math.round(g).toString(16)), + pad2(Math.round(b).toString(16)) ]; // Return a 3 character hex if possible @@ -553,9 +548,9 @@ function rgbToHex(r, g, b, allow3Char) { function rgbaToHex(r, g, b, a, allow4Char) { var hex = [ - pad2(mathRound(r).toString(16)), - pad2(mathRound(g).toString(16)), - pad2(mathRound(b).toString(16)), + pad2(Math.round(r).toString(16)), + pad2(Math.round(g).toString(16)), + pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a)) ]; @@ -574,9 +569,9 @@ function rgbaToArgbHex(r, g, b, a) { var hex = [ pad2(convertDecimalToHex(a)), - pad2(mathRound(r).toString(16)), - pad2(mathRound(g).toString(16)), - pad2(mathRound(b).toString(16)) + pad2(Math.round(r).toString(16)), + pad2(Math.round(g).toString(16)), + pad2(Math.round(b).toString(16)) ]; return hex.join(""); @@ -601,9 +596,9 @@ tinycolor.equals = function (color1, color2) { tinycolor.random = function () { return tinycolor.fromRatio({ - r: mathRandom(), - g: mathRandom(), - b: mathRandom() + r: Math.random(), + g: Math.random(), + b: Math.random() }); }; @@ -644,9 +639,9 @@ function lighten(color, amount) { function brighten(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); var rgb = tinycolor(color).toRgb(); - rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100)))); - rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100)))); - rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100)))); + rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * - (amount / 100)))); + rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * - (amount / 100)))); + rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * - (amount / 100)))); return tinycolor(rgb); } @@ -1032,7 +1027,7 @@ function bound01(n, max) { if (isOnePointZero(n)) { n = "100%"; } var processPercent = isPercentage(n); - n = mathMin(max, mathMax(0, parseFloat(n))); + n = Math.min(max, Math.max(0, parseFloat(n))); // Automatically convert percentage into number if (processPercent) { @@ -1050,7 +1045,7 @@ function bound01(n, max) { // Force a number between 0 and 1 function clamp01(val) { - return mathMin(1, mathMax(0, val)); + return Math.min(1, Math.max(0, val)); } // Parse a base-16 hex value into a base-10 integer @@ -1230,10 +1225,7 @@ if (typeof module !== "undefined" && module.exports) { // AMD/requirejs: Define the module else if (typeof define === 'class' && define.amd) { define(function () { return TinyColor; }); -} -// Browser: Expose to window +} // Browser: Expose to window else { window.tinycolor = tinycolor; } - -}) (Math); From e837a55771a3ff6e5f10c70e7772b87ff3aefa59 Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Thu, 31 Dec 2020 00:52:35 -0500 Subject: [PATCH 3/8] Update tinycolor.js --- tinycolor.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index e1224a9a..973b19cd 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -4,22 +4,21 @@ var trimLeft = /^\s+/, trimRight = /\s+$/, - tinyCounter = 0 - - class TinyColor { - constructor(color, opts) { - this.color = (color) ? color : ''; - this.opts = opts || {}; - - var rgb = inputToRGB(color); - this.originalInput = color, - this.red = rgb.r, - this.green = rgb.g, - this.blue = rgb.b, - this.alpha = rgb.a, - this.roundAlpha = Math.round(100 * this.alpha) / 100, - this.format = opts.format || rgb.format; - this.gradientType = opts.gradientType; + tinyCounter = 0; +class TinyColor { + constructor(color, opts) { + this.color = (color) ? color : ''; + this.opts = opts || {}; + + var rgb = inputToRGB(color); + this.originalInput = color; + this.red = rgb.r; + this.green = rgb.g; + this.blue = rgb.b; + this.alpha = rgb.a; + this.roundAlpha = Math.round(100 * this.alpha) / 100; + this.format = opts.format || rgb.format; + this.gradientType = opts.gradientType; // Don't let the range of [0,255] come back in [0,1]. // Potentially lose a little bit of precision here, but will fix issues where From 093c0d65e7407090c333098258aab0c6213892a8 Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Thu, 31 Dec 2020 01:16:30 -0500 Subject: [PATCH 4/8] Update tinycolor.js --- tinycolor.js | 623 ++++++++++++++++++++++++++------------------------- 1 file changed, 316 insertions(+), 307 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 973b19cd..68c9c6b0 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -34,6 +34,163 @@ class TinyColor { this.ok = rgb.ok; this.tinyColorId = tinyCounter++; + + // Big List of Colors + // ------------------ + // + + // Make it easy to access colors via `hexNames[hex]` + this.names = { + aliceblue: "f0f8ff", + antiquewhite: "faebd7", + aqua: "0ff", + aquamarine: "7fffd4", + azure: "f0ffff", + beige: "f5f5dc", + bisque: "ffe4c4", + black: "000", + blanchedalmond: "ffebcd", + blue: "00f", + blueviolet: "8a2be2", + brown: "a52a2a", + burlywood: "deb887", + burntsienna: "ea7e5d", + cadetblue: "5f9ea0", + chartreuse: "7fff00", + chocolate: "d2691e", + coral: "ff7f50", + cornflowerblue: "6495ed", + cornsilk: "fff8dc", + crimson: "dc143c", + cyan: "0ff", + darkblue: "00008b", + darkcyan: "008b8b", + darkgoldenrod: "b8860b", + darkgray: "a9a9a9", + darkgreen: "006400", + darkgrey: "a9a9a9", + darkkhaki: "bdb76b", + darkmagenta: "8b008b", + darkolivegreen: "556b2f", + darkorange: "ff8c00", + darkorchid: "9932cc", + darkred: "8b0000", + darksalmon: "e9967a", + darkseagreen: "8fbc8f", + darkslateblue: "483d8b", + darkslategray: "2f4f4f", + darkslategrey: "2f4f4f", + darkturquoise: "00ced1", + darkviolet: "9400d3", + deeppink: "ff1493", + deepskyblue: "00bfff", + dimgray: "696969", + dimgrey: "696969", + dodgerblue: "1e90ff", + firebrick: "b22222", + floralwhite: "fffaf0", + forestgreen: "228b22", + fuchsia: "f0f", + gainsboro: "dcdcdc", + ghostwhite: "f8f8ff", + gold: "ffd700", + goldenrod: "daa520", + gray: "808080", + green: "008000", + greenyellow: "adff2f", + grey: "808080", + honeydew: "f0fff0", + hotpink: "ff69b4", + indianred: "cd5c5c", + indigo: "4b0082", + ivory: "fffff0", + khaki: "f0e68c", + lavender: "e6e6fa", + lavenderblush: "fff0f5", + lawngreen: "7cfc00", + lemonchiffon: "fffacd", + lightblue: "add8e6", + lightcoral: "f08080", + lightcyan: "e0ffff", + lightgoldenrodyellow: "fafad2", + lightgray: "d3d3d3", + lightgreen: "90ee90", + lightgrey: "d3d3d3", + lightpink: "ffb6c1", + lightsalmon: "ffa07a", + lightseagreen: "20b2aa", + lightskyblue: "87cefa", + lightslategray: "789", + lightslategrey: "789", + lightsteelblue: "b0c4de", + lightyellow: "ffffe0", + lime: "0f0", + limegreen: "32cd32", + linen: "faf0e6", + magenta: "f0f", + maroon: "800000", + mediumaquamarine: "66cdaa", + mediumblue: "0000cd", + mediumorchid: "ba55d3", + mediumpurple: "9370db", + mediumseagreen: "3cb371", + mediumslateblue: "7b68ee", + mediumspringgreen: "00fa9a", + mediumturquoise: "48d1cc", + mediumvioletred: "c71585", + midnightblue: "191970", + mintcream: "f5fffa", + mistyrose: "ffe4e1", + moccasin: "ffe4b5", + navajowhite: "ffdead", + navy: "000080", + oldlace: "fdf5e6", + olive: "808000", + olivedrab: "6b8e23", + orange: "ffa500", + orangered: "ff4500", + orchid: "da70d6", + palegoldenrod: "eee8aa", + palegreen: "98fb98", + paleturquoise: "afeeee", + palevioletred: "db7093", + papayawhip: "ffefd5", + peachpuff: "ffdab9", + peru: "cd853f", + pink: "ffc0cb", + plum: "dda0dd", + powderblue: "b0e0e6", + purple: "800080", + rebeccapurple: "663399", + red: "f00", + rosybrown: "bc8f8f", + royalblue: "4169e1", + saddlebrown: "8b4513", + salmon: "fa8072", + sandybrown: "f4a460", + seagreen: "2e8b57", + seashell: "fff5ee", + sienna: "a0522d", + silver: "c0c0c0", + skyblue: "87ceeb", + slateblue: "6a5acd", + slategray: "708090", + slategrey: "708090", + snow: "fffafa", + springgreen: "00ff7f", + steelblue: "4682b4", + tan: "d2b48c", + teal: "008080", + thistle: "d8bfd8", + tomato: "ff6347", + turquoise: "40e0d0", + violet: "ee82ee", + wheat: "f5deb3", + white: "fff", + whitesmoke: "f5f5f5", + yellow: "ff0", + yellowgreen: "9acd32" + }; } isDark() { @@ -177,7 +334,7 @@ class TinyColor { gradientType = this.gradientType ? "GradientType = 1, " : ""; if (secondColor) { - var s = tinycolor(secondColor); + var s = TinyColor(secondColor); secondHex8String = '#' + rgbaToArgbHex(s.red, s.green, s.blue, s.alpha); } @@ -380,7 +537,126 @@ class TinyColor { a: a }; } -} + + random() { + return this.fromRatio({ + r: Math.random(), + g: Math.random(), + b: Math.random() + }); + }; + // `equals` + // Can be called with any tinycolor input + equals(color1, color2) { + if (!color1 || !color2) { return false; } + let c1 = new TinyColor(color1), + c2 = new TinyColor(color2) + return c1.toRgbString() == c2.toRgbString(); + }; + + // Readability Functions + // --------------------- + // false + // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false + isReadable (color1, color2, wcag2) { + var readability = this.readability(color1, color2); + var wcag2Parms, out; + + out = false; + + wcag2Parms = validateWCAG2Parms(wcag2); + switch (wcag2Parms.level + wcag2Parms.size) { + case "AAsmall": + case "AAAlarge": + out = readability >= 4.5; + break; + case "AAlarge": + out = readability >= 3; + break; + case "AAAsmall": + out = readability >= 7; + break; + } + return out; + + }; + + // `mostReadable` + // Given a base color and a list of possible foreground or background + // colors for that base, returns the most readable color. + // Optionally returns Black or White if the most readable color is unreadable. + // *Example* + // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255" + // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff" + // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3" + // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff" + mostReadable (baseColor, colorList, args) { + var bestColor = null; + var bestScore = 0; + var readability; + var includeFallbackColors, level, size; + args = args || {}; + includeFallbackColors = args.includeFallbackColors; + level = args.level; + size = args.size; + + for (var i = 0; i < colorList.length; i++) { + readability = this.readability(baseColor, colorList[i]); + if (readability > bestScore) { + bestScore = readability; + bestColor = this.colorList[i]; + } + } + + if (this.isReadable(baseColor, bestColor, { "level": level, "size": size }) || !includeFallbackColors) { + return bestColor; + } + else { + args.includeFallbackColors = false; + return this.mostReadable(baseColor, ["#fff", "#000"], args); + } + }; + +// Utility Functions +// --------------------- + +tinycolor.mix = function (color1, color2, amount) { + amount = (amount === 0) ? 0 : (amount || 50); + + var c1 = new TinyColor(color1), + rgb1 = c1.toRgb(); + var c2 = new TinyColor(color2), + rgb2 = c2.toRgb(); + + var p = amount / 100; + + var rgba = { + r: ((rgb2.r - rgb1.r) * p) + rgb1.r, + g: ((rgb2.g - rgb1.g) * p) + rgb1.g, + b: ((rgb2.b - rgb1.b) * p) + rgb1.b, + a: ((rgb2.a - rgb1.a) * p) + rgb1.a + }; + + return new TinyColor(rgba); +}; + // Conversion Functions @@ -586,22 +862,6 @@ function rgbToCmyk(r, g, b) { return { c: (1 - R - K) / (1 - K), m: (1 - B - K) / (1 - K), y: (1 - G - K) / (1 - K), k: K }; } -// `equals` -// Can be called with any tinycolor input -tinycolor.equals = function (color1, color2) { - if (!color1 || !color2) { return false; } - return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString(); -}; - -tinycolor.random = function () { - return tinycolor.fromRatio({ - r: Math.random(), - g: Math.random(), - b: Math.random() - }); -}; - - // Modification Functions // ---------------------- // Thanks to less.js for some of the basics here @@ -609,56 +869,63 @@ tinycolor.random = function () { function desaturate(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var hsl = tinycolor(color).toHsl(); + var c = new TinyColor(color), + hsl = c.toHsl(); hsl.s -= amount / 100; hsl.s = clamp01(hsl.s); - return tinycolor(hsl); + return new TinyColor(hsl); } function saturate(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var hsl = tinycolor(color).toHsl(); + var c = new TinyColor(color), + hsl = c.toHsl(); hsl.s += amount / 100; hsl.s = clamp01(hsl.s); - return tinycolor(hsl); + return new TinyColor(hsl); } function greyscale(color) { - return tinycolor(color).desaturate(100); + var c = new TinyColor(color); + return c.desaturate(100); } function lighten(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var hsl = tinycolor(color).toHsl(); + var c = new TinyColor(color), + hsl = c.toHsl(); hsl.l += amount / 100; hsl.l = clamp01(hsl.l); - return tinycolor(hsl); + return new TinyColor(hsl); } function brighten(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var rgb = tinycolor(color).toRgb(); + var c = new TinyColor(color), + rgb = c.toRgb(); rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * - (amount / 100)))); rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * - (amount / 100)))); rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * - (amount / 100)))); - return tinycolor(rgb); + return new TinyColor(rgb); } function darken(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var hsl = tinycolor(color).toHsl(); + var c = new TinyColor(color), + hsl = c.toHsl(); hsl.l -= amount / 100; hsl.l = clamp01(hsl.l); - return tinycolor(hsl); + return new TinyColor(hsl); } // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. // Values outside of this range will be wrapped into this range. function spin(color, amount) { - var hsl = tinycolor(color).toHsl(); + var c = new TinyColor(color), + hsl = c.toHsl(); var hue = (hsl.h + amount) % 360; hsl.h = hue < 0 ? 360 + hue : hue; - return tinycolor(hsl); + return new TinyColor(hsl); } // Combination Functions @@ -667,24 +934,27 @@ function spin(color, amount) { // function complement(color) { - var hsl = tinycolor(color).toHsl(); + var c = new TinyColor(color), + hsl = c.toHsl(); hsl.h = (hsl.h + 180) % 360; - return tinycolor(hsl); + return new TinyColor(hsl); } function triad(color) { - var hsl = tinycolor(color).toHsl(); - var h = hsl.h; + var c = new TinyColor(color), + hsl = c.toHsl(), + h = hsl.h; return [ - tinycolor(color), - tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }), - tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l }) + new TinyColor(color);, + new TinyColor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }), + new TinyColor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l }) ]; } function tetrad(color) { - var hsl = tinycolor(color).toHsl(); - var h = hsl.h; + var c = new TinyColor(color), + hsl = c.toHsl(), + h = hsl.h; return [ tinycolor(color), tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }), @@ -694,8 +964,9 @@ function tetrad(color) { } function splitcomplement(color) { - var hsl = tinycolor(color).toHsl(); - var h = hsl.h; + var c = new TinyColor(color), + hsl = c.toHsl(), + h = hsl.h; return [ tinycolor(color), tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }), @@ -720,281 +991,19 @@ function analogous(color, results, slices) { function monochromatic(color, results) { results = results || 6; - var hsv = tinycolor(color).toHsv(); + var hsv = new TinyColor(color).toHsv(); var h = hsv.h, s = hsv.s, v = hsv.v; var ret = []; var modification = 1 / results; while (results--) { - ret.push(tinycolor({ h: h, s: s, v: v })); + ret.push(TinyColor({ h: h, s: s, v: v })); v = (v + modification) % 1; } return ret; } -// Utility Functions -// --------------------- - -tinycolor.mix = function (color1, color2, amount) { - amount = (amount === 0) ? 0 : (amount || 50); - - var rgb1 = tinycolor(color1).toRgb(); - var rgb2 = tinycolor(color2).toRgb(); - - var p = amount / 100; - - var rgba = { - r: ((rgb2.r - rgb1.r) * p) + rgb1.r, - g: ((rgb2.g - rgb1.g) * p) + rgb1.g, - b: ((rgb2.b - rgb1.b) * p) + rgb1.b, - a: ((rgb2.a - rgb1.a) * p) + rgb1.a - }; - - return tinycolor(rgba); -}; - - -// Readability Functions -// --------------------- -// false -// tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false -tinycolor.isReadable = function (color1, color2, wcag2) { - var readability = tinycolor.readability(color1, color2); - var wcag2Parms, out; - - out = false; - - wcag2Parms = validateWCAG2Parms(wcag2); - switch (wcag2Parms.level + wcag2Parms.size) { - case "AAsmall": - case "AAAlarge": - out = readability >= 4.5; - break; - case "AAlarge": - out = readability >= 3; - break; - case "AAAsmall": - out = readability >= 7; - break; - } - return out; - -}; - -// `mostReadable` -// Given a base color and a list of possible foreground or background -// colors for that base, returns the most readable color. -// Optionally returns Black or White if the most readable color is unreadable. -// *Example* -// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255" -// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff" -// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3" -// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff" -tinycolor.mostReadable = function (baseColor, colorList, args) { - var bestColor = null; - var bestScore = 0; - var readability; - var includeFallbackColors, level, size; - args = args || {}; - includeFallbackColors = args.includeFallbackColors; - level = args.level; - size = args.size; - - for (var i = 0; i < colorList.length; i++) { - readability = tinycolor.readability(baseColor, colorList[i]); - if (readability > bestScore) { - bestScore = readability; - bestColor = tinycolor(colorList[i]); - } - } - - if (tinycolor.isReadable(baseColor, bestColor, { "level": level, "size": size }) || !includeFallbackColors) { - return bestColor; - } - else { - args.includeFallbackColors = false; - return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args); - } -}; - - -// Big List of Colors -// ------------------ -// -var names = tinycolor.names = { - aliceblue: "f0f8ff", - antiquewhite: "faebd7", - aqua: "0ff", - aquamarine: "7fffd4", - azure: "f0ffff", - beige: "f5f5dc", - bisque: "ffe4c4", - black: "000", - blanchedalmond: "ffebcd", - blue: "00f", - blueviolet: "8a2be2", - brown: "a52a2a", - burlywood: "deb887", - burntsienna: "ea7e5d", - cadetblue: "5f9ea0", - chartreuse: "7fff00", - chocolate: "d2691e", - coral: "ff7f50", - cornflowerblue: "6495ed", - cornsilk: "fff8dc", - crimson: "dc143c", - cyan: "0ff", - darkblue: "00008b", - darkcyan: "008b8b", - darkgoldenrod: "b8860b", - darkgray: "a9a9a9", - darkgreen: "006400", - darkgrey: "a9a9a9", - darkkhaki: "bdb76b", - darkmagenta: "8b008b", - darkolivegreen: "556b2f", - darkorange: "ff8c00", - darkorchid: "9932cc", - darkred: "8b0000", - darksalmon: "e9967a", - darkseagreen: "8fbc8f", - darkslateblue: "483d8b", - darkslategray: "2f4f4f", - darkslategrey: "2f4f4f", - darkturquoise: "00ced1", - darkviolet: "9400d3", - deeppink: "ff1493", - deepskyblue: "00bfff", - dimgray: "696969", - dimgrey: "696969", - dodgerblue: "1e90ff", - firebrick: "b22222", - floralwhite: "fffaf0", - forestgreen: "228b22", - fuchsia: "f0f", - gainsboro: "dcdcdc", - ghostwhite: "f8f8ff", - gold: "ffd700", - goldenrod: "daa520", - gray: "808080", - green: "008000", - greenyellow: "adff2f", - grey: "808080", - honeydew: "f0fff0", - hotpink: "ff69b4", - indianred: "cd5c5c", - indigo: "4b0082", - ivory: "fffff0", - khaki: "f0e68c", - lavender: "e6e6fa", - lavenderblush: "fff0f5", - lawngreen: "7cfc00", - lemonchiffon: "fffacd", - lightblue: "add8e6", - lightcoral: "f08080", - lightcyan: "e0ffff", - lightgoldenrodyellow: "fafad2", - lightgray: "d3d3d3", - lightgreen: "90ee90", - lightgrey: "d3d3d3", - lightpink: "ffb6c1", - lightsalmon: "ffa07a", - lightseagreen: "20b2aa", - lightskyblue: "87cefa", - lightslategray: "789", - lightslategrey: "789", - lightsteelblue: "b0c4de", - lightyellow: "ffffe0", - lime: "0f0", - limegreen: "32cd32", - linen: "faf0e6", - magenta: "f0f", - maroon: "800000", - mediumaquamarine: "66cdaa", - mediumblue: "0000cd", - mediumorchid: "ba55d3", - mediumpurple: "9370db", - mediumseagreen: "3cb371", - mediumslateblue: "7b68ee", - mediumspringgreen: "00fa9a", - mediumturquoise: "48d1cc", - mediumvioletred: "c71585", - midnightblue: "191970", - mintcream: "f5fffa", - mistyrose: "ffe4e1", - moccasin: "ffe4b5", - navajowhite: "ffdead", - navy: "000080", - oldlace: "fdf5e6", - olive: "808000", - olivedrab: "6b8e23", - orange: "ffa500", - orangered: "ff4500", - orchid: "da70d6", - palegoldenrod: "eee8aa", - palegreen: "98fb98", - paleturquoise: "afeeee", - palevioletred: "db7093", - papayawhip: "ffefd5", - peachpuff: "ffdab9", - peru: "cd853f", - pink: "ffc0cb", - plum: "dda0dd", - powderblue: "b0e0e6", - purple: "800080", - rebeccapurple: "663399", - red: "f00", - rosybrown: "bc8f8f", - royalblue: "4169e1", - saddlebrown: "8b4513", - salmon: "fa8072", - sandybrown: "f4a460", - seagreen: "2e8b57", - seashell: "fff5ee", - sienna: "a0522d", - silver: "c0c0c0", - skyblue: "87ceeb", - slateblue: "6a5acd", - slategray: "708090", - slategrey: "708090", - snow: "fffafa", - springgreen: "00ff7f", - steelblue: "4682b4", - tan: "d2b48c", - teal: "008080", - thistle: "d8bfd8", - tomato: "ff6347", - turquoise: "40e0d0", - violet: "ee82ee", - wheat: "f5deb3", - white: "fff", - whitesmoke: "f5f5f5", - yellow: "ff0", - yellowgreen: "9acd32" -}; - -// Make it easy to access colors via `hexNames[hex]` -var hexNames = tinycolor.hexNames = flip(names); - // Utilities // --------- @@ -1226,5 +1235,5 @@ else if (typeof define === 'class' && define.amd) { define(function () { return TinyColor; }); } // Browser: Expose to window else { - window.tinycolor = tinycolor; + window.tinycolor = TinyColor; } From 6b81d8aca35d0cd5d318006f9f05f8299aa70f31 Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Thu, 31 Dec 2020 01:24:08 -0500 Subject: [PATCH 5/8] Update tinycolor.js --- tinycolor.js | 1367 +++++++++++++++++++++++++------------------------- 1 file changed, 670 insertions(+), 697 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 68c9c6b0..629a6950 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -2,661 +2,364 @@ // https://github.com/bgrins/TinyColor // Brian Grinstead, MIT License - var trimLeft = /^\s+/, - trimRight = /\s+$/, - tinyCounter = 0; -class TinyColor { - constructor(color, opts) { - this.color = (color) ? color : ''; - this.opts = opts || {}; - - var rgb = inputToRGB(color); - this.originalInput = color; - this.red = rgb.r; - this.green = rgb.g; - this.blue = rgb.b; - this.alpha = rgb.a; - this.roundAlpha = Math.round(100 * this.alpha) / 100; - this.format = opts.format || rgb.format; - this.gradientType = opts.gradientType; - - // Don't let the range of [0,255] come back in [0,1]. - // Potentially lose a little bit of precision here, but will fix issues where - // .5 gets interpreted as half of the total, instead of half of 1 - // If it was supposed to be 128, this was already taken care of by `inputToRgb` - - if (this.red < 1) - this.red = Math.round(this.red); - if (this.green < 1) - this.green = Math.round(this.green); - if (this.blue < 1) - this.blue = Math.round(this.blue); - - this.ok = rgb.ok; - this.tinyColorId = tinyCounter++; - - // Big List of Colors - // ------------------ - // - - // Make it easy to access colors via `hexNames[hex]` - this.names = { - aliceblue: "f0f8ff", - antiquewhite: "faebd7", - aqua: "0ff", - aquamarine: "7fffd4", - azure: "f0ffff", - beige: "f5f5dc", - bisque: "ffe4c4", - black: "000", - blanchedalmond: "ffebcd", - blue: "00f", - blueviolet: "8a2be2", - brown: "a52a2a", - burlywood: "deb887", - burntsienna: "ea7e5d", - cadetblue: "5f9ea0", - chartreuse: "7fff00", - chocolate: "d2691e", - coral: "ff7f50", - cornflowerblue: "6495ed", - cornsilk: "fff8dc", - crimson: "dc143c", - cyan: "0ff", - darkblue: "00008b", - darkcyan: "008b8b", - darkgoldenrod: "b8860b", - darkgray: "a9a9a9", - darkgreen: "006400", - darkgrey: "a9a9a9", - darkkhaki: "bdb76b", - darkmagenta: "8b008b", - darkolivegreen: "556b2f", - darkorange: "ff8c00", - darkorchid: "9932cc", - darkred: "8b0000", - darksalmon: "e9967a", - darkseagreen: "8fbc8f", - darkslateblue: "483d8b", - darkslategray: "2f4f4f", - darkslategrey: "2f4f4f", - darkturquoise: "00ced1", - darkviolet: "9400d3", - deeppink: "ff1493", - deepskyblue: "00bfff", - dimgray: "696969", - dimgrey: "696969", - dodgerblue: "1e90ff", - firebrick: "b22222", - floralwhite: "fffaf0", - forestgreen: "228b22", - fuchsia: "f0f", - gainsboro: "dcdcdc", - ghostwhite: "f8f8ff", - gold: "ffd700", - goldenrod: "daa520", - gray: "808080", - green: "008000", - greenyellow: "adff2f", - grey: "808080", - honeydew: "f0fff0", - hotpink: "ff69b4", - indianred: "cd5c5c", - indigo: "4b0082", - ivory: "fffff0", - khaki: "f0e68c", - lavender: "e6e6fa", - lavenderblush: "fff0f5", - lawngreen: "7cfc00", - lemonchiffon: "fffacd", - lightblue: "add8e6", - lightcoral: "f08080", - lightcyan: "e0ffff", - lightgoldenrodyellow: "fafad2", - lightgray: "d3d3d3", - lightgreen: "90ee90", - lightgrey: "d3d3d3", - lightpink: "ffb6c1", - lightsalmon: "ffa07a", - lightseagreen: "20b2aa", - lightskyblue: "87cefa", - lightslategray: "789", - lightslategrey: "789", - lightsteelblue: "b0c4de", - lightyellow: "ffffe0", - lime: "0f0", - limegreen: "32cd32", - linen: "faf0e6", - magenta: "f0f", - maroon: "800000", - mediumaquamarine: "66cdaa", - mediumblue: "0000cd", - mediumorchid: "ba55d3", - mediumpurple: "9370db", - mediumseagreen: "3cb371", - mediumslateblue: "7b68ee", - mediumspringgreen: "00fa9a", - mediumturquoise: "48d1cc", - mediumvioletred: "c71585", - midnightblue: "191970", - mintcream: "f5fffa", - mistyrose: "ffe4e1", - moccasin: "ffe4b5", - navajowhite: "ffdead", - navy: "000080", - oldlace: "fdf5e6", - olive: "808000", - olivedrab: "6b8e23", - orange: "ffa500", - orangered: "ff4500", - orchid: "da70d6", - palegoldenrod: "eee8aa", - palegreen: "98fb98", - paleturquoise: "afeeee", - palevioletred: "db7093", - papayawhip: "ffefd5", - peachpuff: "ffdab9", - peru: "cd853f", - pink: "ffc0cb", - plum: "dda0dd", - powderblue: "b0e0e6", - purple: "800080", - rebeccapurple: "663399", - red: "f00", - rosybrown: "bc8f8f", - royalblue: "4169e1", - saddlebrown: "8b4513", - salmon: "fa8072", - sandybrown: "f4a460", - seagreen: "2e8b57", - seashell: "fff5ee", - sienna: "a0522d", - silver: "c0c0c0", - skyblue: "87ceeb", - slateblue: "6a5acd", - slategray: "708090", - slategrey: "708090", - snow: "fffafa", - springgreen: "00ff7f", - steelblue: "4682b4", - tan: "d2b48c", - teal: "008080", - thistle: "d8bfd8", - tomato: "ff6347", - turquoise: "40e0d0", - violet: "ee82ee", - wheat: "f5deb3", - white: "fff", - whitesmoke: "f5f5f5", - yellow: "ff0", - yellowgreen: "9acd32" - }; - } +(function(Math) { - isDark() { - return this.getBrightness() < 128; - } - isLight() { - return !this.isDark(); - } +var trimLeft = /^\s+/, + trimRight = /\s+$/, + tinyCounter = 0, + mathRound = Math.round, + mathMin = Math.min, + mathMax = Math.max, + mathRandom = Math.random; - isValid() { - return this.ok; - } - getOriginalInput() { - return this.originalInput; - } - getFormat() { - return this.format; - } - getAlpha() { - return this.alpha; - } - getBrightness() { - //http://www.w3.org/TR/AERT#color-contrast - var rgb = this.toRgb(); - return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; - } +function tinycolor (color, opts) { - getLuminance() { - //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef - var rgb = this.toRgb(), - RsRGB = rgb.r / 255, - GsRGB = rgb.g / 255, - BsRGB = rgb.b / 255, - R = (RsRGB <= 0.03928) ? RsRGB / 12.92 : Math.pow(((RsRGB + 0.055) / 1.055), 2.4), - G = (GsRGB <= 0.03928) ? GsRGB / 12.92 : Math.pow(((GsRGB + 0.055) / 1.055), 2.4), - B = (BsRGB <= 0.03928) ? BsRGB / 12.92 : Math.pow(((BsRGB + 0.055) / 1.055), 2.4); - return (0.2126 * R) + (0.7152 * G) + (0.0722 * B); - } + color = (color) ? color : ''; + opts = opts || { }; - setAlpha(value) { - this.alpha = boundAlpha(value); - this.roundAlpha = Math.round(100 * this.alpha) / 100; - return this; - } + // If input is already a tinycolor, return itself + if (color instanceof tinycolor) { + return color; + } + // If we are called as a function, call using new instead + if (!(this instanceof tinycolor)) { + return new tinycolor(color, opts); + } - toHsv() { - var hsv = rgbToHsv(this.red, this.green, this.blue); - return { - h: hsv.h * 360, - s: hsv.s, - v: hsv.v, - a: this.alpha - }; - } - toHsvString() { - var hsv = rgbToHsv(this.red, this.green, this.blue), - h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100); - return (this.alpha == 1) ? - "hsv(" + h + ", " + s + "%, " + v + "%)" : - "hsva(" + h + ", " + s + "%, " + v + "%, " + this.roundAlpha + ")"; - } + var rgb = inputToRGB(color); + this._originalInput = color, + this._r = rgb.r, + this._g = rgb.g, + this._b = rgb.b, + this._a = rgb.a, + this._roundA = mathRound(100*this._a) / 100, + this._format = opts.format || rgb.format; + this._gradientType = opts.gradientType; + + // Don't let the range of [0,255] come back in [0,1]. + // Potentially lose a little bit of precision here, but will fix issues where + // .5 gets interpreted as half of the total, instead of half of 1 + // If it was supposed to be 128, this was already taken care of by `inputToRgb` + if (this._r < 1) { this._r = mathRound(this._r); } + if (this._g < 1) { this._g = mathRound(this._g); } + if (this._b < 1) { this._b = mathRound(this._b); } + + this._ok = rgb.ok; + this._tc_id = tinyCounter++; +} - toHsl() { - var hsl = rgbToHsl(this.red, this.green, this.blue); - return { - h: hsl.h * 360, - s: hsl.s, - l: hsl.l, - a: this.alpha - }; - } - toHslString() { - var hsl = rgbToHsl(this.red, this.green, this.blue), - h = Math.round(hsl.h * 360), - s = Math.round(hsl.s * 100), - l = Math.round(hsl.l * 100); - return (this.alpha == 1) ? - "hsl(" + h + ", " + s + "%, " + l + "%)" : - "hsla(" + h + ", " + s + "%, " + l + "%, " + this.roundAlpha + ")"; +tinycolor.prototype = { + isDark: function() { + return this.getBrightness() < 128; + }, + isLight: function() { + return !this.isDark(); + }, + isValid: function() { + return this._ok; + }, + getOriginalInput: function() { + return this._originalInput; + }, + getFormat: function() { + return this._format; + }, + getAlpha: function() { + return this._a; + }, + getBrightness: function() { + //http://www.w3.org/TR/AERT#color-contrast + var rgb = this.toRgb(); + return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; + }, + getLuminance: function() { + //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef + var rgb = this.toRgb(); + var RsRGB, GsRGB, BsRGB, R, G, B; + RsRGB = rgb.r/255; + GsRGB = rgb.g/255; + BsRGB = rgb.b/255; + + if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);} + if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);} + if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);} + return (0.2126 * R) + (0.7152 * G) + (0.0722 * B); + }, + setAlpha: function(value) { + this._a = boundAlpha(value); + this._roundA = mathRound(100*this._a) / 100; + return this; + }, + toHsv: function() { + var hsv = rgbToHsv(this._r, this._g, this._b); + return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a }; + }, + toHsvString: function() { + var hsv = rgbToHsv(this._r, this._g, this._b); + var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100); + return (this._a == 1) ? + "hsv(" + h + ", " + s + "%, " + v + "%)" : + "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")"; + }, + toHsl: function() { + var hsl = rgbToHsl(this._r, this._g, this._b); + return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a }; + }, + toHslString: function() { + var hsl = rgbToHsl(this._r, this._g, this._b); + var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100); + return (this._a == 1) ? + "hsl(" + h + ", " + s + "%, " + l + "%)" : + "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")"; + }, + toHex: function(allow3Char) { + return rgbToHex(this._r, this._g, this._b, allow3Char); + }, + toHexString: function(allow3Char) { + return '#' + this.toHex(allow3Char); + }, + toHex8: function(allow4Char) { + return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char); + }, + toHex8String: function(allow4Char) { + return '#' + this.toHex8(allow4Char); + }, + toRgb: function() { + return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a }; + }, + toRgbString: function() { + return (this._a == 1) ? + "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" : + "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")"; + }, + toPercentageRgb: function() { + 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 }; + }, + toPercentageRgbString: function() { + return (this._a == 1) ? + "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" : + "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")"; + }, + toCmyk: function() { + return rgbToCmyk(this.red, this.green, this.blue); + }, + toCmykString: function() { + var cmyk = rgbToCmyk(this.red, this.green, this.blue); + return "cmyk(" + Math.round(cmyk.c * 100) + "," + Math.round(cmyk.m * 100) + "," + Math.round(cmyk.y * 100) + "," + Math.round(cmyk.k * 100) + ")"; + }, + toName: function() { + if (this._a === 0) { + return "transparent"; } - toHex(allow3Char) { - return rgbToHex(this.red, this.green, this.blue, allow3Char); - } - toHexString(allow3Char) { - return '#' + this.toHex(allow3Char); + if (this._a < 1) { + return false; } - toHex8(allow4Char) { - return rgbaToHex(this.red, this.green, this.blue, this.alpha, allow4Char); - } - toHex8String(allow4Char) { - return '#' + this.toHex8(allow4Char); - } + return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false; + }, + toFilter: function(secondColor) { + var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a); + var secondHex8String = hex8String; + var gradientType = this._gradientType ? "GradientType = 1, " : ""; - toRgb() { - return { - r: Math.round(this.red), - g: Math.round(this.green), - b: Math.round(this.blue), - a: this.alpha - }; - } - toRgbString() { - return (this.alpha == 1) ? - "rgb(" + Math.round(this.red) + ", " + Math.round(this.green) + ", " + Math.round(this.blue) + ")" : - "rgba(" + Math.round(this.red) + ", " + Math.round(this.green) + ", " + Math.round(this.blue) + ", " + this.roundAlpha + ")"; + if (secondColor) { + var s = tinycolor(secondColor); + secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a); } - toCmyk() { - return rgbToCmyk(this.red, this.green, this.blue); - } - toCmykString() { - var cmyk = rgbToCmyk(this.red, this.green, this.blue); - return "cmyk(" + Math.round(cmyk.c * 100) + "," + Math.round(cmyk.m * 100) + "," + Math.round(cmyk.y * 100) + "," + Math.round(cmyk.k * 100) + ")"; - } - toPercentageRgb() { - return { - r: Math.round(bound01(this.red, 255) * 100) + "%", - g: Math.round(bound01(this.green, 255) * 100) + "%", - b: Math.round(bound01(this.blue, 255) * 100) + "%", - a: this.alpha - }; - } - toPercentageRgbString() { - return (this.alpha == 1) ? - "rgb(" + Math.round(bound01(this.red, 255) * 100) + "%, " + Math.round(bound01(this.green, 255) * 100) + "%, " + Math.round(bound01(this.blue, 255) * 100) + "%)" : - "rgba(" + Math.round(bound01(this.red, 255) * 100) + "%, " + Math.round(bound01(this.green, 255) * 100) + "%, " + Math.round(bound01(this.blue, 255) * 100) + "%, " + this.roundAlpha + ")"; - } - toName() { - if (this.alpha === 0) - return "transparent"; - - if (this.alpha < 1) - return false; - return hexNames[rgbToHex(this.red, this.green, this.blue, true)] || false; - } - toFilter(secondColor) { - var hex8String = '#' + rgbaToArgbHex(this.red, this.green, this.blue, this.alpha), - secondHex8String = hex8String, - gradientType = this.gradientType ? "GradientType = 1, " : ""; - - if (secondColor) { - var s = TinyColor(secondColor); - secondHex8String = '#' + rgbaToArgbHex(s.red, s.green, s.blue, s.alpha); + return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")"; + }, + toString: function(format) { + var formatSet = !!format; + format = format || this._format; + + var formattedString = false; + var hasAlpha = this._a < 1 && this._a >= 0; + var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name"); + + if (needsAlphaFormat) { + // Special case for "transparent", all other non-alpha formats + // will return rgba when there is transparency. + if (format === "name" && this._a === 0) { + return this.toName(); } - - return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")"; + return this.toRgbString(); } - toString(format) { - var formatSet = !!format; - format = format || this.format; - - var formattedString = false, - hasAlpha = this.alpha < 1 && this.alpha >= 0, - needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name"); - - if (needsAlphaFormat) { - // Special case for "transparent", all other non-alpha formats - // will return rgba when there is transparency. - - if (format === "name" && this.alpha === 0) return this.toName(); - return this.toRgbString(); - } - if (format === "rgb") - formattedString = this.toRgbString(); - - if (format === "prgb") - formattedString = this.toPercentageRgbString(); - - if (format === "hex" || format === "hex6") - formattedString = this.toHexString(); - - if (format === "hex3") - formattedString = this.toHexString(true); - - if (format === "hex4") - formattedString = this.toHex8String(true); - - if (format === "hex8") - formattedString = this.toHex8String(); - - if (format === "name") - formattedString = this.toName(); - - if (format === "hsl") - formattedString = this.toHslString(); - - if (format === "hsv") - formattedString = this.toHsvString(); - - return formattedString || this.toHexString(); - } - - clone() { - return new TinyColor(this.toString()); - } - - applyModification(fn, args) { - var color = fn.apply(null, [this].concat([].slice.call(args))); - this.red = color.red; - this.green = color.green; - this.blue = color.blue; - this.setAlpha(color.alpha); - return this; + if (format === "rgb") { + formattedString = this.toRgbString(); } - - lighten() { - return this.applyModification(lighten, arguments); + if (format === "prgb") { + formattedString = this.toPercentageRgbString(); } - brighten() { - return this.applyModification(brighten, arguments); + if (format === "hex" || format === "hex6") { + formattedString = this.toHexString(); } - - darken() { - return this.applyModification(darken, arguments); + if (format === "hex3") { + formattedString = this.toHexString(true); } - - desaturate() { - return this.applyModification(desaturate, arguments); + if (format === "hex4") { + formattedString = this.toHex8String(true); } - saturate() { - return this.applyModification(saturate, arguments); - } - - greyscale() { - return this.applyModification(greyscale, arguments); + if (format === "hex8") { + formattedString = this.toHex8String(); } - spin() { - return this.applyModification(spin, arguments); + if (format === "name") { + formattedString = this.toName(); } - - _applyCombination(fn, args) { - return fn.apply(null, [this].concat([].slice.call(args))); - } - - analogous() { - return this._applyCombination(analogous, arguments); - } - - complement() { - return this._applyCombination(complement, arguments); - } - - monochromatic() { - return this._applyCombination(monochromatic, arguments); - } - - splitcomplement() { - return this._applyCombination(splitcomplement, arguments); + if (format === "hsl") { + formattedString = this.toHslString(); } - - triad() { - return this._applyCombination(triad, arguments); + if (format === "hsv") { + formattedString = this.toHsvString(); } - tetrad() { - return this._applyCombination(tetrad, arguments); - } + return formattedString || this.toHexString(); + }, + clone: function() { + return tinycolor(this.toString()); + }, + + _applyModification: function(fn, args) { + var color = fn.apply(null, [this].concat([].slice.call(args))); + this._r = color._r; + this._g = color._g; + this._b = color._b; + this.setAlpha(color._a); + return this; + }, + lighten: function() { + return this._applyModification(lighten, arguments); + }, + brighten: function() { + return this._applyModification(brighten, arguments); + }, + darken: function() { + return this._applyModification(darken, arguments); + }, + desaturate: function() { + return this._applyModification(desaturate, arguments); + }, + saturate: function() { + return this._applyModification(saturate, arguments); + }, + greyscale: function() { + return this._applyModification(greyscale, arguments); + }, + spin: function() { + return this._applyModification(spin, arguments); + }, + + _applyCombination: function(fn, args) { + return fn.apply(null, [this].concat([].slice.call(args))); + }, + analogous: function() { + return this._applyCombination(analogous, arguments); + }, + complement: function() { + return this._applyCombination(complement, arguments); + }, + monochromatic: function() { + return this._applyCombination(monochromatic, arguments); + }, + splitcomplement: function() { + return this._applyCombination(splitcomplement, arguments); + }, + triad: function() { + return this._applyCombination(triad, arguments); + }, + tetrad: function() { + return this._applyCombination(tetrad, arguments); + } +}; - // If input is an object, force 1 into "1.0" to handle ratios properly - // String input requires "1.0" as input, so 1 will be treated as 1 - fromRatio(color, opts) { - if (typeof color == "object") { - var newColor = {}; - for (var i in color) { - if (color.hasOwnProperty(i)) { - if (i === "a") - newColor[i] = color[i]; - else - newColor[i] = convertToPercentage(color[i]); - } +// If input is an object, force 1 into "1.0" to handle ratios properly +// String input requires "1.0" as input, so 1 will be treated as 1 +tinycolor.fromRatio = function(color, opts) { + if (typeof color == "object") { + var newColor = {}; + for (var i in color) { + if (color.hasOwnProperty(i)) { + if (i === "a") { + newColor[i] = color[i]; + } + else { + newColor[i] = convertToPercentage(color[i]); } - color = newColor; - } - return new TinyColor(color, opts); - }; - - // Given a string or object, convert that input to RGB - // Possible string inputs: - // - // "red" - // "#f00" or "f00" - // "#ff0000" or "ff0000" - // "#ff000000" or "ff000000" - // "rgb 255 0 0" or "rgb (255, 0, 0)" - // "rgb 1.0 0 0" or "rgb (1, 0, 0)" - // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1" - // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1" - // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%" - // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1" - // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" - // - inputToRGB(color) { - - var rgb = { - r: 0, - g: 0, - b: 0 - } - a = 1, - s = null, - v = null, - l = null, - ok = false, - format = false; - - if (typeof color == "string") - color = stringInputToObject(color); - - if (typeof color == "object") { - if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) { - rgb = rgbToRgb(color.r, color.g, color.b); - ok = true; - format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb"; - } - else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) { - s = convertToPercentage(color.s); - v = convertToPercentage(color.v); - rgb = hsvToRgb(color.h, s, v); - ok = true; - format = "hsv"; - } - else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) { - s = convertToPercentage(color.s); - l = convertToPercentage(color.l); - rgb = hslToRgb(color.h, s, l); - ok = true; - format = "hsl"; } - - if (color.hasOwnProperty("a")) - a = color.a; } + color = newColor; + } - a = boundAlpha(a); + return tinycolor(color, opts); +}; - return { - ok: ok, - format: color.format || format, - r: Math.min(255, Math.max(rgb.r, 0)), - g: Math.min(255, Math.max(rgb.g, 0)), - b: Math.min(255, Math.max(rgb.b, 0)), - a: a - }; +// Given a string or object, convert that input to RGB +// Possible string inputs: +// +// "red" +// "#f00" or "f00" +// "#ff0000" or "ff0000" +// "#ff000000" or "ff000000" +// "rgb 255 0 0" or "rgb (255, 0, 0)" +// "rgb 1.0 0 0" or "rgb (1, 0, 0)" +// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1" +// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1" +// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%" +// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1" +// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" +// +function inputToRGB(color) { + + var rgb = { r: 0, g: 0, b: 0 }; + var a = 1; + var s = null; + var v = null; + var l = null; + var ok = false; + var format = false; + + if (typeof color == "string") { + color = stringInputToObject(color); } - - random() { - return this.fromRatio({ - r: Math.random(), - g: Math.random(), - b: Math.random() - }); - }; - // `equals` - // Can be called with any tinycolor input - equals(color1, color2) { - if (!color1 || !color2) { return false; } - let c1 = new TinyColor(color1), - c2 = new TinyColor(color2) - return c1.toRgbString() == c2.toRgbString(); - }; - - // Readability Functions - // --------------------- - // false - // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false - isReadable (color1, color2, wcag2) { - var readability = this.readability(color1, color2); - var wcag2Parms, out; - - out = false; - - wcag2Parms = validateWCAG2Parms(wcag2); - switch (wcag2Parms.level + wcag2Parms.size) { - case "AAsmall": - case "AAAlarge": - out = readability >= 4.5; - break; - case "AAlarge": - out = readability >= 3; - break; - case "AAAsmall": - out = readability >= 7; - break; - } - return out; - - }; - // `mostReadable` - // Given a base color and a list of possible foreground or background - // colors for that base, returns the most readable color. - // Optionally returns Black or White if the most readable color is unreadable. - // *Example* - // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255" - // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff" - // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3" - // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff" - mostReadable (baseColor, colorList, args) { - var bestColor = null; - var bestScore = 0; - var readability; - var includeFallbackColors, level, size; - args = args || {}; - includeFallbackColors = args.includeFallbackColors; - level = args.level; - size = args.size; - - for (var i = 0; i < colorList.length; i++) { - readability = this.readability(baseColor, colorList[i]); - if (readability > bestScore) { - bestScore = readability; - bestColor = this.colorList[i]; - } + if (typeof color == "object") { + if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) { + rgb = rgbToRgb(color.r, color.g, color.b); + ok = true; + format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb"; } - - if (this.isReadable(baseColor, bestColor, { "level": level, "size": size }) || !includeFallbackColors) { - return bestColor; + else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) { + s = convertToPercentage(color.s); + v = convertToPercentage(color.v); + rgb = hsvToRgb(color.h, s, v); + ok = true; + format = "hsv"; } - else { - args.includeFallbackColors = false; - return this.mostReadable(baseColor, ["#fff", "#000"], args); + else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) { + s = convertToPercentage(color.s); + l = convertToPercentage(color.l); + rgb = hslToRgb(color.h, s, l); + ok = true; + format = "hsl"; } - }; - -// Utility Functions -// --------------------- - -tinycolor.mix = function (color1, color2, amount) { - amount = (amount === 0) ? 0 : (amount || 50); - var c1 = new TinyColor(color1), - rgb1 = c1.toRgb(); - var c2 = new TinyColor(color2), - rgb2 = c2.toRgb(); + if (color.hasOwnProperty("a")) { + a = color.a; + } + } - var p = amount / 100; + a = boundAlpha(a); - var rgba = { - r: ((rgb2.r - rgb1.r) * p) + rgb1.r, - g: ((rgb2.g - rgb1.g) * p) + rgb1.g, - b: ((rgb2.b - rgb1.b) * p) + rgb1.b, - a: ((rgb2.a - rgb1.a) * p) + rgb1.a + return { + ok: ok, + format: color.format || format, + r: mathMin(255, mathMax(rgb.r, 0)), + g: mathMin(255, mathMax(rgb.g, 0)), + b: mathMin(255, mathMax(rgb.b, 0)), + a: a }; - - return new TinyColor(rgba); -}; - +} // Conversion Functions @@ -670,7 +373,7 @@ tinycolor.mix = function (color1, color2, amount) { // // *Assumes:* r, g, b in [0, 255] or [0, 1] // *Returns:* { r, g, b } in [0, 255] -function rgbToRgb(r, g, b) { +function rgbToRgb(r, g, b){ return { r: bound01(r, 255) * 255, g: bound01(g, 255) * 255, @@ -688,16 +391,16 @@ function rgbToHsl(r, g, b) { g = bound01(g, 255); b = bound01(b, 255); - var max = Math.max(r, g, b), min = Math.min(r, g, b); + var max = mathMax(r, g, b), min = mathMin(r, g, b); var h, s, l = (max + min) / 2; - if (max == min) { + if(max == min) { h = s = 0; // achromatic } else { var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - switch (max) { + switch(max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; @@ -721,23 +424,23 @@ function hslToRgb(h, s, l) { l = bound01(l, 100); function hue2rgb(p, q, t) { - if (t < 0) t += 1; - if (t > 1) t -= 1; - if (t < 1 / 6) return p + (q - p) * 6 * t; - if (t < 1 / 2) return q; - if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; + if(t < 0) t += 1; + if(t > 1) t -= 1; + if(t < 1/6) return p + (q - p) * 6 * t; + if(t < 1/2) return q; + if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; return p; } - if (s === 0) { + if(s === 0) { r = g = b = l; // achromatic } else { var q = l < 0.5 ? l * (1 + s) : l + s - l * s; var p = 2 * l - q; - r = hue2rgb(p, q, h + 1 / 3); + r = hue2rgb(p, q, h + 1/3); g = hue2rgb(p, q, h); - b = hue2rgb(p, q, h - 1 / 3); + b = hue2rgb(p, q, h - 1/3); } return { r: r * 255, g: g * 255, b: b * 255 }; @@ -753,17 +456,17 @@ function rgbToHsv(r, g, b) { g = bound01(g, 255); b = bound01(b, 255); - var max = Math.max(r, g, b), min = Math.min(r, g, b); + var max = mathMax(r, g, b), min = mathMin(r, g, b); var h, s, v = max; var d = max - min; s = max === 0 ? 0 : d / max; - if (max == min) { + if(max == min) { h = 0; // achromatic } else { - switch (max) { + switch(max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; @@ -777,7 +480,7 @@ function rgbToHsv(r, g, b) { // Converts an HSV color value to RGB. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100] // *Returns:* { r, g, b } in the set [0, 255] -function hsvToRgb(h, s, v) { + function hsvToRgb(h, s, v) { h = bound01(h, 360) * 6; s = bound01(s, 100); @@ -803,9 +506,9 @@ function hsvToRgb(h, s, v) { function rgbToHex(r, g, b, allow3Char) { var hex = [ - pad2(Math.round(r).toString(16)), - pad2(Math.round(g).toString(16)), - pad2(Math.round(b).toString(16)) + pad2(mathRound(r).toString(16)), + pad2(mathRound(g).toString(16)), + pad2(mathRound(b).toString(16)) ]; // Return a 3 character hex if possible @@ -823,9 +526,9 @@ function rgbToHex(r, g, b, allow3Char) { function rgbaToHex(r, g, b, a, allow4Char) { var hex = [ - pad2(Math.round(r).toString(16)), - pad2(Math.round(g).toString(16)), - pad2(Math.round(b).toString(16)), + pad2(mathRound(r).toString(16)), + pad2(mathRound(g).toString(16)), + pad2(mathRound(b).toString(16)), pad2(convertDecimalToHex(a)) ]; @@ -844,9 +547,9 @@ function rgbaToArgbHex(r, g, b, a) { var hex = [ pad2(convertDecimalToHex(a)), - pad2(Math.round(r).toString(16)), - pad2(Math.round(g).toString(16)), - pad2(Math.round(b).toString(16)) + pad2(mathRound(r).toString(16)), + pad2(mathRound(g).toString(16)), + pad2(mathRound(b).toString(16)) ]; return hex.join(""); @@ -862,6 +565,22 @@ function rgbToCmyk(r, g, b) { return { c: (1 - R - K) / (1 - K), m: (1 - B - K) / (1 - K), y: (1 - G - K) / (1 - K), k: K }; } +// `equals` +// Can be called with any tinycolor input +tinycolor.equals = function (color1, color2) { + if (!color1 || !color2) { return false; } + return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString(); +}; + +tinycolor.random = function() { + return tinycolor.fromRatio({ + r: mathRandom(), + g: mathRandom(), + b: mathRandom() + }); +}; + + // Modification Functions // ---------------------- // Thanks to less.js for some of the basics here @@ -869,63 +588,56 @@ function rgbToCmyk(r, g, b) { function desaturate(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var c = new TinyColor(color), - hsl = c.toHsl(); + var hsl = tinycolor(color).toHsl(); hsl.s -= amount / 100; hsl.s = clamp01(hsl.s); - return new TinyColor(hsl); + return tinycolor(hsl); } function saturate(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var c = new TinyColor(color), - hsl = c.toHsl(); + var hsl = tinycolor(color).toHsl(); hsl.s += amount / 100; hsl.s = clamp01(hsl.s); - return new TinyColor(hsl); + return tinycolor(hsl); } function greyscale(color) { - var c = new TinyColor(color); - return c.desaturate(100); + return tinycolor(color).desaturate(100); } -function lighten(color, amount) { +function lighten (color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var c = new TinyColor(color), - hsl = c.toHsl(); + var hsl = tinycolor(color).toHsl(); hsl.l += amount / 100; hsl.l = clamp01(hsl.l); - return new TinyColor(hsl); + return tinycolor(hsl); } function brighten(color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var c = new TinyColor(color), - rgb = c.toRgb(); - rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * - (amount / 100)))); - rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * - (amount / 100)))); - rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * - (amount / 100)))); - return new TinyColor(rgb); + var rgb = tinycolor(color).toRgb(); + rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100)))); + rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100)))); + rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100)))); + return tinycolor(rgb); } -function darken(color, amount) { +function darken (color, amount) { amount = (amount === 0) ? 0 : (amount || 10); - var c = new TinyColor(color), - hsl = c.toHsl(); + var hsl = tinycolor(color).toHsl(); hsl.l -= amount / 100; hsl.l = clamp01(hsl.l); - return new TinyColor(hsl); + return tinycolor(hsl); } // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. // Values outside of this range will be wrapped into this range. function spin(color, amount) { - var c = new TinyColor(color), - hsl = c.toHsl(); + var hsl = tinycolor(color).toHsl(); var hue = (hsl.h + amount) % 360; hsl.h = hue < 0 ? 360 + hue : hue; - return new TinyColor(hsl); + return tinycolor(hsl); } // Combination Functions @@ -934,27 +646,24 @@ function spin(color, amount) { // function complement(color) { - var c = new TinyColor(color), - hsl = c.toHsl(); + var hsl = tinycolor(color).toHsl(); hsl.h = (hsl.h + 180) % 360; - return new TinyColor(hsl); + return tinycolor(hsl); } function triad(color) { - var c = new TinyColor(color), - hsl = c.toHsl(), - h = hsl.h; + var hsl = tinycolor(color).toHsl(); + var h = hsl.h; return [ - new TinyColor(color);, - new TinyColor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }), - new TinyColor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l }) + tinycolor(color), + tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }), + tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l }) ]; } function tetrad(color) { - var c = new TinyColor(color), - hsl = c.toHsl(), - h = hsl.h; + var hsl = tinycolor(color).toHsl(); + var h = hsl.h; return [ tinycolor(color), tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }), @@ -964,13 +673,12 @@ function tetrad(color) { } function splitcomplement(color) { - var c = new TinyColor(color), - hsl = c.toHsl(), - h = hsl.h; + var hsl = tinycolor(color).toHsl(); + var h = hsl.h; return [ tinycolor(color), - tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }), - tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }) + tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}), + tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l}) ]; } @@ -982,7 +690,7 @@ function analogous(color, results, slices) { var part = 360 / slices; var ret = [tinycolor(color)]; - for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results;) { + for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) { hsl.h = (hsl.h + part) % 360; ret.push(tinycolor(hsl)); } @@ -991,26 +699,288 @@ function analogous(color, results, slices) { function monochromatic(color, results) { results = results || 6; - var hsv = new TinyColor(color).toHsv(); + var hsv = tinycolor(color).toHsv(); var h = hsv.h, s = hsv.s, v = hsv.v; var ret = []; var modification = 1 / results; while (results--) { - ret.push(TinyColor({ h: h, s: s, v: v })); + ret.push(tinycolor({ h: h, s: s, v: v})); v = (v + modification) % 1; } return ret; } +// Utility Functions +// --------------------- + +tinycolor.mix = function(color1, color2, amount) { + amount = (amount === 0) ? 0 : (amount || 50); + + var rgb1 = tinycolor(color1).toRgb(); + var rgb2 = tinycolor(color2).toRgb(); + + var p = amount / 100; + + var rgba = { + r: ((rgb2.r - rgb1.r) * p) + rgb1.r, + g: ((rgb2.g - rgb1.g) * p) + rgb1.g, + b: ((rgb2.b - rgb1.b) * p) + rgb1.b, + a: ((rgb2.a - rgb1.a) * p) + rgb1.a + }; + + return tinycolor(rgba); +}; + + +// Readability Functions +// --------------------- +// false +// tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false +tinycolor.isReadable = function(color1, color2, wcag2) { + var readability = tinycolor.readability(color1, color2); + var wcag2Parms, out; + + out = false; + + wcag2Parms = validateWCAG2Parms(wcag2); + switch (wcag2Parms.level + wcag2Parms.size) { + case "AAsmall": + case "AAAlarge": + out = readability >= 4.5; + break; + case "AAlarge": + out = readability >= 3; + break; + case "AAAsmall": + out = readability >= 7; + break; + } + return out; + +}; + +// `mostReadable` +// Given a base color and a list of possible foreground or background +// colors for that base, returns the most readable color. +// Optionally returns Black or White if the most readable color is unreadable. +// *Example* +// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255" +// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff" +// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3" +// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff" +tinycolor.mostReadable = function(baseColor, colorList, args) { + var bestColor = null; + var bestScore = 0; + var readability; + var includeFallbackColors, level, size ; + args = args || {}; + includeFallbackColors = args.includeFallbackColors ; + level = args.level; + size = args.size; + + for (var i= 0; i < colorList.length ; i++) { + readability = tinycolor.readability(baseColor, colorList[i]); + if (readability > bestScore) { + bestScore = readability; + bestColor = tinycolor(colorList[i]); + } + } + + if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) { + return bestColor; + } + else { + args.includeFallbackColors=false; + return tinycolor.mostReadable(baseColor,["#fff", "#000"],args); + } +}; + + +// Big List of Colors +// ------------------ +// +var names = tinycolor.names = { + aliceblue: "f0f8ff", + antiquewhite: "faebd7", + aqua: "0ff", + aquamarine: "7fffd4", + azure: "f0ffff", + beige: "f5f5dc", + bisque: "ffe4c4", + black: "000", + blanchedalmond: "ffebcd", + blue: "00f", + blueviolet: "8a2be2", + brown: "a52a2a", + burlywood: "deb887", + burntsienna: "ea7e5d", + cadetblue: "5f9ea0", + chartreuse: "7fff00", + chocolate: "d2691e", + coral: "ff7f50", + cornflowerblue: "6495ed", + cornsilk: "fff8dc", + crimson: "dc143c", + cyan: "0ff", + darkblue: "00008b", + darkcyan: "008b8b", + darkgoldenrod: "b8860b", + darkgray: "a9a9a9", + darkgreen: "006400", + darkgrey: "a9a9a9", + darkkhaki: "bdb76b", + darkmagenta: "8b008b", + darkolivegreen: "556b2f", + darkorange: "ff8c00", + darkorchid: "9932cc", + darkred: "8b0000", + darksalmon: "e9967a", + darkseagreen: "8fbc8f", + darkslateblue: "483d8b", + darkslategray: "2f4f4f", + darkslategrey: "2f4f4f", + darkturquoise: "00ced1", + darkviolet: "9400d3", + deeppink: "ff1493", + deepskyblue: "00bfff", + dimgray: "696969", + dimgrey: "696969", + dodgerblue: "1e90ff", + firebrick: "b22222", + floralwhite: "fffaf0", + forestgreen: "228b22", + fuchsia: "f0f", + gainsboro: "dcdcdc", + ghostwhite: "f8f8ff", + gold: "ffd700", + goldenrod: "daa520", + gray: "808080", + green: "008000", + greenyellow: "adff2f", + grey: "808080", + honeydew: "f0fff0", + hotpink: "ff69b4", + indianred: "cd5c5c", + indigo: "4b0082", + ivory: "fffff0", + khaki: "f0e68c", + lavender: "e6e6fa", + lavenderblush: "fff0f5", + lawngreen: "7cfc00", + lemonchiffon: "fffacd", + lightblue: "add8e6", + lightcoral: "f08080", + lightcyan: "e0ffff", + lightgoldenrodyellow: "fafad2", + lightgray: "d3d3d3", + lightgreen: "90ee90", + lightgrey: "d3d3d3", + lightpink: "ffb6c1", + lightsalmon: "ffa07a", + lightseagreen: "20b2aa", + lightskyblue: "87cefa", + lightslategray: "789", + lightslategrey: "789", + lightsteelblue: "b0c4de", + lightyellow: "ffffe0", + lime: "0f0", + limegreen: "32cd32", + linen: "faf0e6", + magenta: "f0f", + maroon: "800000", + mediumaquamarine: "66cdaa", + mediumblue: "0000cd", + mediumorchid: "ba55d3", + mediumpurple: "9370db", + mediumseagreen: "3cb371", + mediumslateblue: "7b68ee", + mediumspringgreen: "00fa9a", + mediumturquoise: "48d1cc", + mediumvioletred: "c71585", + midnightblue: "191970", + mintcream: "f5fffa", + mistyrose: "ffe4e1", + moccasin: "ffe4b5", + navajowhite: "ffdead", + navy: "000080", + oldlace: "fdf5e6", + olive: "808000", + olivedrab: "6b8e23", + orange: "ffa500", + orangered: "ff4500", + orchid: "da70d6", + palegoldenrod: "eee8aa", + palegreen: "98fb98", + paleturquoise: "afeeee", + palevioletred: "db7093", + papayawhip: "ffefd5", + peachpuff: "ffdab9", + peru: "cd853f", + pink: "ffc0cb", + plum: "dda0dd", + powderblue: "b0e0e6", + purple: "800080", + rebeccapurple: "663399", + red: "f00", + rosybrown: "bc8f8f", + royalblue: "4169e1", + saddlebrown: "8b4513", + salmon: "fa8072", + sandybrown: "f4a460", + seagreen: "2e8b57", + seashell: "fff5ee", + sienna: "a0522d", + silver: "c0c0c0", + skyblue: "87ceeb", + slateblue: "6a5acd", + slategray: "708090", + slategrey: "708090", + snow: "fffafa", + springgreen: "00ff7f", + steelblue: "4682b4", + tan: "d2b48c", + teal: "008080", + thistle: "d8bfd8", + tomato: "ff6347", + turquoise: "40e0d0", + violet: "ee82ee", + wheat: "f5deb3", + white: "fff", + whitesmoke: "f5f5f5", + yellow: "ff0", + yellowgreen: "9acd32" +}; + +// Make it easy to access colors via `hexNames[hex]` +var hexNames = tinycolor.hexNames = flip(names); + // Utilities // --------- // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }` function flip(o) { - var flipped = {}; + var flipped = { }; for (var i in o) { if (o.hasOwnProperty(i)) { flipped[o[i]] = i; @@ -1035,7 +1005,7 @@ function bound01(n, max) { if (isOnePointZero(n)) { n = "100%"; } var processPercent = isPercentage(n); - n = Math.min(max, Math.max(0, parseFloat(n))); + n = mathMin(max, mathMax(0, parseFloat(n))); // Automatically convert percentage into number if (processPercent) { @@ -1053,7 +1023,7 @@ function bound01(n, max) { // Force a number between 0 and 1 function clamp01(val) { - return Math.min(1, Math.max(0, val)); + return mathMin(1, mathMax(0, val)); } // Parse a base-16 hex value into a base-10 integer @@ -1095,7 +1065,7 @@ function convertHexToDecimal(h) { return (parseIntFromHex(h) / 255); } -var matchers = (function () { +var matchers = (function() { // var CSS_INTEGER = "[-\\+]?\\d+%?"; @@ -1139,7 +1109,7 @@ function isValidCSSUnit(color) { // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}` function stringInputToObject(color) { - color = color.replace(trimLeft, '').replace(trimRight, '').toLowerCase(); + color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase(); var named = false; if (names[color]) { color = names[color]; @@ -1214,7 +1184,7 @@ function validateWCAG2Parms(parms) { // return valid WCAG2 parms for isReadable. // If input parms are invalid, return {"level":"AA", "size":"small"} var level, size; - parms = parms || { "level": "AA", "size": "small" }; + parms = parms || {"level":"AA", "size":"small"}; level = (parms.level || "AA").toUpperCase(); size = (parms.size || "small").toLowerCase(); if (level !== "AA" && level !== "AAA") { @@ -1223,17 +1193,20 @@ function validateWCAG2Parms(parms) { if (size !== "small" && size !== "large") { size = "small"; } - return { "level": level, "size": size }; + return {"level":level, "size":size}; } // Node: Export function if (typeof module !== "undefined" && module.exports) { - module.exports = TinyColor; + module.exports = tinycolor; } // AMD/requirejs: Define the module -else if (typeof define === 'class' && define.amd) { - define(function () { return TinyColor; }); -} // Browser: Expose to window +else if (typeof define === 'function' && define.amd) { + define(function () {return tinycolor;}); +} +// Browser: Expose to window else { - window.tinycolor = TinyColor; + window.tinycolor = tinycolor; } + +})(Math); From 37572c56651e9d7c30f7e7c6dbd44583e0e294ec Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Sun, 10 Jan 2021 05:20:35 -0500 Subject: [PATCH 6/8] Update tinycolor.js --- tinycolor.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 629a6950..9e5fe304 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -557,12 +557,17 @@ function rgbaToArgbHex(r, g, b, a) { // `rgbToCmyk` // Converts RGB color to CMYK -function rgbToCmyk(r, g, b) { - var R = r / 255, - G = g / 255, - B = b / 255, - K = 1 - Math.max(R, G, B); - return { c: (1 - R - K) / (1 - K), m: (1 - B - K) / (1 - K), y: (1 - G - K) / (1 - K), k: K }; +function rgbToCMYK(r, g, b) { + var R = r/255, + G = g/255, + B = b/255, + K = 1-Math.max(R, G, B); + return { + C: (1-R-K) / (1-K), + M: (1-B-K) / (1-K), + Y: (1-G-K) / (1-K), + K: K + }; } // `equals` From 48310bcdfabe0f9c350407d249d9d0da042fee67 Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Sun, 10 Jan 2021 05:24:29 -0500 Subject: [PATCH 7/8] Update tinycolor.js --- tinycolor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinycolor.js b/tinycolor.js index 9e5fe304..e4cf3175 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -557,7 +557,7 @@ function rgbaToArgbHex(r, g, b, a) { // `rgbToCmyk` // Converts RGB color to CMYK -function rgbToCMYK(r, g, b) { +function rgbToCmyk(r, g, b) { var R = r/255, G = g/255, B = b/255, From 673e19e2ab35be5c4f496cb74a116686d01b081a Mon Sep 17 00:00:00 2001 From: Jay Rizuri <65318393+JayRizuri@users.noreply.github.com> Date: Sun, 10 Jan 2021 05:27:48 -0500 Subject: [PATCH 8/8] Update tinycolor.js --- tinycolor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index e4cf3175..d3c2ea41 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -141,10 +141,10 @@ tinycolor.prototype = { "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")"; }, toCmyk: function() { - return rgbToCmyk(this.red, this.green, this.blue); + return rgbToCmyk(this._r, this._g, this._b); }, toCmykString: function() { - var cmyk = rgbToCmyk(this.red, this.green, this.blue); + var cmyk = rgbToCmyk(this._r, this._g, this._b); return "cmyk(" + Math.round(cmyk.c * 100) + "," + Math.round(cmyk.m * 100) + "," + Math.round(cmyk.y * 100) + "," + Math.round(cmyk.k * 100) + ")"; }, toName: function() {