diff --git a/components/style/color/tiny-color.js b/components/style/color/tiny-color.js index 297ffa798e62..1ffd9fa9f7d2 100644 --- a/components/style/color/tiny-color.js +++ b/components/style/color/tiny-color.js @@ -108,171 +108,9 @@ tinycolor.prototype = { 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); - }, toLessColor: function(less) { return less.color([this._r, this._g, this._b], this._a); }, - 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'; - } - - if (this._a < 1) { - return false; - } - - 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, ' : ''; - - if (secondColor) { - var s = tinycolor(secondColor); - secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a); - } - - 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 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: function() { return tinycolor(this.toString()); },