Socket
Socket
Sign inDemoInstall

tinycolor2

Package Overview
Dependencies
0
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.17 to 0.9.18

.travis.yml

2

component.json
{
"name": "tinycolor",
"version": "0.9.17",
"version": "0.9.18",
"main": ["./tinycolor.js"],

@@ -5,0 +5,0 @@ "dependencies": {

{
"version": "0.9.17",
"version": "0.9.18",
"name": "tinycolor2",

@@ -4,0 +4,0 @@ "description": "Fast Color Parsing and Manipulation",

@@ -5,73 +5,73 @@ # TinyColor

### Features
Fast, small color manipulation and conversion for JavaScript. TinyColor is allows many forms of input, while providing color conversions and other color utility functions. It has no dependancies.
* Color Types Supported
* Hex, 8-digit (ARGB) Hex
[![Build Status](https://travis-ci.org/bgrins/TinyColor.png?branch=master)](https://travis-ci.org/bgrins/TinyColor)
```js
tinycolor("#000");
tinycolor("000");
tinycolor("#f0f0f6");
tinycolor("f0f0f6");
tinycolor("#88f0f0f6");
tinycolor("88f0f0f6");
```
## Supported Color Types
* RGB, RGBA
### Hex, 8-digit (ARGB) Hex
```js
tinycolor("rgb (255, 0, 0)");
tinycolor("rgb 255 0 0");
tinycolor("rgba (255, 0, 0, .5)");
tinycolor({ r: 255, g: 0, b: 0 });
```
tinycolor("#000");
tinycolor("000");
tinycolor("#f0f0f6");
tinycolor("f0f0f6");
tinycolor("#88f0f0f6");
tinycolor("88f0f0f6");
* HSL, HSLA
### RGB, RGBA
```js
tinycolor("hsl(0, 100%, 50%)");
tinycolor("hsla(0, 100%, 50%, .5)");
tinycolor("hsl(0, 100%, 50%)");
tinycolor("hsl 0 1.0 0.5");
tinycolor({ h: 0, s: 1, l: .5 });
```
tinycolor("rgb (255, 0, 0)");
tinycolor("rgb 255 0 0");
tinycolor("rgba (255, 0, 0, .5)");
tinycolor({ r: 255, g: 0, b: 0 });
tinycolor.fromRatio({ r: 1, g: 0, b: 0 });
tinycolor.fromRatio({ r: .5, g: .5, b: .5 });
* HSV, HSVA
### HSL, HSLA
```js
tinycolor("hsv(0, 100%, 100%)");
tinycolor("hsva(0, 100%, 100%, .5)");
tinycolor("hsv (0 100% 100%)");
tinycolor("hsv 0 1 1");
tinycolor({ h: 0, s: 100, v: 100 });
```
tinycolor("hsl(0, 100%, 50%)");
tinycolor("hsla(0, 100%, 50%, .5)");
tinycolor("hsl(0, 100%, 50%)");
tinycolor("hsl 0 1.0 0.5");
tinycolor({ h: 0, s: 1, l: .5 });
* Named
### HSV, HSVA
```js
tinycolor("RED");
tinycolor("blanchedalmond");
tinycolor("darkblue");
```
tinycolor("hsv(0, 100%, 100%)");
tinycolor("hsva(0, 100%, 100%, .5)");
tinycolor("hsv (0 100% 100%)");
tinycolor("hsv 0 1 1");
tinycolor({ h: 0, s: 100, v: 100 });
### Usage
### Named
```js
var t = tinycolor("red");
tinycolor("RED");
tinycolor("blanchedalmond");
tinycolor("darkblue");
t.toHex() // "ff0000"
t.toHexString() // "#ff0000"
t.toHex8() // "ffff0000"
t.toHex8String() // "#ffff0000"
t.toRgb() // {"r":255,"g":0,"b":0} or {"r":255,"g":0,"b":0,"a":0.5}
t.toRgbString() // "rgb(255, 0, 0)" or "rgba(255, 0, 0, 0.5)"
t.toPercentageRgb() // {"r":100,"g":0,"b":0} or {"r":100,"g":0,"b":0,"a":0.5}
t.toPercentageRgbString() // "rgb(100%, 0%, 0%)" or "rgba(100%, 0%, 0%, 0.5)"
t.toHsv() // {"h":0,"s":1,"v":1}
t.toHsvString() // "hsv(0, 100%, 100%)"
t.toHsl() // {"h":0,"s":1,"l":0.5}
t.toHslString() // "hsl(0, 100%, 50%)"
t.toName() // "red"
```
## Using in a browser
<script type='text/javascript' src='tinycolor.js'></script>
<script type='text/javascript'>
var t = tinycolor("red");
t.toHex() // "ff0000"
t.toHexString() // "#ff0000"
t.toHex8() // "ffff0000"
t.toHex8String() // "#ffff0000"
t.toRgb() // {"r":255,"g":0,"b":0} or {"r":255,"g":0,"b":0,"a":0.5}
t.toRgbString() // "rgb(255, 0, 0)" or "rgba(255, 0, 0, 0.5)"
t.toPercentageRgb() // {"r":100,"g":0,"b":0} or {"r":100,"g":0,"b":0,"a":0.5}
t.toPercentageRgbString() // "rgb(100%, 0%, 0%)" or "rgba(100%, 0%, 0%, 0.5)"
t.toHsv() // {"h":0,"s":1,"v":1}
t.toHsvString() // "hsv(0, 100%, 100%)"
t.toHsl() // {"h":0,"s":1,"l":0.5}
t.toHslString() // "hsl(0, 100%, 50%)"
t.toName() // "red"
t.toString(/* format */) // "red"
t.toFilter()
</script>
## Using in node
`tinycolor` may also be included as a [node](http://nodejs.org/) module like so:

@@ -93,3 +93,7 @@

HSL and HSV both require either 0%-100% or 0-1. RGB requires either 0-255 or 0%-100%. If you call tinycolor.fromRatio, any input can also accept 0-1
HSL and HSV both require either 0%-100% or 0-1.
RGB input requires either 0-255 or 0%-100%.
If you call `tinycolor.fromRatio`, RGB input can also accept 0-1
Here are some examples of string input:

@@ -124,3 +128,2 @@

{ r: 255, g: 0, b: 0, a: .5 }
{ r: 1, g: 0, b: 0 }
{ h: 0, s: 100, l: 50 }

@@ -127,0 +130,0 @@ { h: 0, s: 100, v: 100 }

test("TinyColor initialization", function() {
ok ( typeof tinycolor != "undefined", "tinycolor is initialized on the page" );
ok ( typeof tinycolor("red") == "object", "tinycolor is able to be instantiated." );
equal ( tinycolor("red", { format: "hex" }).toString(), "#ff0000", "tinycolor options are being parsed" );
equal ( tinycolor.fromRatio({r: 1, g: 0, b: 0 }, { format: "hex" }).toString(), "#ff0000", "tinycolor options are being parsed" );
ok (typeof tinycolor != "undefined", "tinycolor is initialized on the page");
ok (typeof tinycolor("red") == "object", "tinycolor is able to be instantiated.");
var r = tinycolor("red");
ok (tinycolor(r) === r, "when given a tinycolor instance, tinycolor() returns it.");
ok (new tinycolor(r) === r, "when given a tinycolor instance, new tinycolor() returns it.");
equal (tinycolor("red", { format: "hex" }).toString(), "#ff0000", "tinycolor options are being parsed");
equal (tinycolor.fromRatio({r: 1, g: 0, b: 0 }, { format: "hex" }).toString(), "#ff0000", "tinycolor options are being parsed");
});

@@ -12,18 +14,18 @@

var conversions = [
{"hex":"#FFFFFF","hex8":"#FFFFFFFF","rgb":{"r":"100.0%","g":"100.0%","b":"100.0%"},"hsv":{"h":"0","s":"0.000","v":"1.000"},"hsl":{"h":"0","s":"0.000","l":"1.000"}},
{"hex":"#808080","hex8":"#FF808080","rgb":{"r":"050.0%","g":"050.0%","b":"050.0%"},"hsv":{"h":"0","s":"0.000","v":"0.500"},"hsl":{"h":"0","s":"0.000","l":"0.500"}},
{"hex":"#000000","hex8":"#FF000000","rgb":{"r":"000.0%","g":"000.0%","b":"000.0%"},"hsv":{"h":"0","s":"0.000","v":"0.000"},"hsl":{"h":"0","s":"0.000","l":"0.000"}},
{"hex":"#FF0000","hex8":"#FFFF0000","rgb":{"r":"100.0%","g":"000.0%","b":"000.0%"},"hsv":{"h":"0.0","s":"1.000","v":"1.000"},"hsl":{"h":"0.0","s":"1.000","l":"0.500"}},
{"hex":"#BFBF00","hex8":"#FFBFBF00","rgb":{"r":"075.0%","g":"075.0%","b":"000.0%"},"hsv":{"h":"60.0","s":"1.000","v":"0.750"},"hsl":{"h":"60.0","s":"1.000","l":"0.375"}},
{"hex":"#008000","hex8":"#FF008000","rgb":{"r":"000.0%","g":"050.0%","b":"000.0%"},"hsv":{"h":"120.0","s":"1.000","v":"0.500"},"hsl":{"h":"120.0","s":"1.000","l":"0.250"}},
{"hex":"#80FFFF","hex8":"#FF80FFFF","rgb":{"r":"050.0%","g":"100.0%","b":"100.0%"},"hsv":{"h":"180.0","s":"0.500","v":"1.000"},"hsl":{"h":"180.0","s":"1.000","l":"0.750"}},
{"hex":"#8080FF","hex8":"#FF8080FF","rgb":{"r":"050.0%","g":"050.0%","b":"100.0%"},"hsv":{"h":"240.0","s":"0.500","v":"1.000"},"hsl":{"h":"240.0","s":"1.000","l":"0.750"}},
{"hex":"#BF40BF","hex8":"#FFBF40BF","rgb":{"r":"075.0%","g":"025.0%","b":"075.0%"},"hsv":{"h":"300.0","s":"0.667","v":"0.750"},"hsl":{"h":"300.0","s":"0.500","l":"0.500"}},
{"hex":"#A0A424","hex8":"#FFA0A424","rgb":{"r":"062.8%","g":"064.3%","b":"014.2%"},"hsv":{"h":"61.8","s":"0.779","v":"0.643"},"hsl":{"h":"61.8","s":"0.638","l":"0.393"}},
{"hex":"#1EAC41","hex8":"#FF1EAC41","rgb":{"r":"011.6%","g":"067.5%","b":"025.5%"},"hsv":{"h":"134.9","s":"0.828","v":"0.675"},"hsl":{"h":"134.9","s":"0.707","l":"0.396"}},
{"hex":"#B430E5","hex8":"#FFB430E5","rgb":{"r":"070.4%","g":"018.7%","b":"089.7%"},"hsv":{"h":"283.7","s":"0.792","v":"0.897"},"hsl":{"h":"283.7","s":"0.775","l":"0.542"}},
{"hex":"#FEF888","hex8":"#FFFEF888","rgb":{"r":"099.8%","g":"097.4%","b":"053.2%"},"hsv":{"h":"56.9","s":"0.467","v":"0.998"},"hsl":{"h":"56.9","s":"0.991","l":"0.765"}},
{"hex":"#19CB97","hex8":"#FF19CB97","rgb":{"r":"009.9%","g":"079.5%","b":"059.1%"},"hsv":{"h":"162.4","s":"0.875","v":"0.795"},"hsl":{"h":"162.4","s":"0.779","l":"0.447"}},
{"hex":"#362698","hex8":"#FF362698","rgb":{"r":"021.1%","g":"014.9%","b":"059.7%"},"hsv":{"h":"248.3","s":"0.750","v":"0.597"},"hsl":{"h":"248.3","s":"0.601","l":"0.373"}},
{"hex":"#7E7EB8","hex8":"#FF7E7EB8","rgb":{"r":"049.5%","g":"049.3%","b":"072.1%"},"hsv":{"h":"240.5","s":"0.316","v":"0.721"},"hsl":{"h":"240.5","s":"0.290","l":"0.607"}}
{"hex":"#FFFFFF","hex8":"#FFFFFFFF","rgb":{"r":"100.0%","g":"100.0%","b":"100.0%"},"hsv":{"h":"0","s":"0.000","v":"1.000"},"hsl":{"h":"0","s":"0.000","l":"1.000"}},
{"hex":"#808080","hex8":"#FF808080","rgb":{"r":"050.0%","g":"050.0%","b":"050.0%"},"hsv":{"h":"0","s":"0.000","v":"0.500"},"hsl":{"h":"0","s":"0.000","l":"0.500"}},
{"hex":"#000000","hex8":"#FF000000","rgb":{"r":"000.0%","g":"000.0%","b":"000.0%"},"hsv":{"h":"0","s":"0.000","v":"0.000"},"hsl":{"h":"0","s":"0.000","l":"0.000"}},
{"hex":"#FF0000","hex8":"#FFFF0000","rgb":{"r":"100.0%","g":"000.0%","b":"000.0%"},"hsv":{"h":"0.0","s":"1.000","v":"1.000"},"hsl":{"h":"0.0","s":"1.000","l":"0.500"}},
{"hex":"#BFBF00","hex8":"#FFBFBF00","rgb":{"r":"075.0%","g":"075.0%","b":"000.0%"},"hsv":{"h":"60.0","s":"1.000","v":"0.750"},"hsl":{"h":"60.0","s":"1.000","l":"0.375"}},
{"hex":"#008000","hex8":"#FF008000","rgb":{"r":"000.0%","g":"050.0%","b":"000.0%"},"hsv":{"h":"120.0","s":"1.000","v":"0.500"},"hsl":{"h":"120.0","s":"1.000","l":"0.250"}},
{"hex":"#80FFFF","hex8":"#FF80FFFF","rgb":{"r":"050.0%","g":"100.0%","b":"100.0%"},"hsv":{"h":"180.0","s":"0.500","v":"1.000"},"hsl":{"h":"180.0","s":"1.000","l":"0.750"}},
{"hex":"#8080FF","hex8":"#FF8080FF","rgb":{"r":"050.0%","g":"050.0%","b":"100.0%"},"hsv":{"h":"240.0","s":"0.500","v":"1.000"},"hsl":{"h":"240.0","s":"1.000","l":"0.750"}},
{"hex":"#BF40BF","hex8":"#FFBF40BF","rgb":{"r":"075.0%","g":"025.0%","b":"075.0%"},"hsv":{"h":"300.0","s":"0.667","v":"0.750"},"hsl":{"h":"300.0","s":"0.500","l":"0.500"}},
{"hex":"#A0A424","hex8":"#FFA0A424","rgb":{"r":"062.8%","g":"064.3%","b":"014.2%"},"hsv":{"h":"61.8","s":"0.779","v":"0.643"},"hsl":{"h":"61.8","s":"0.638","l":"0.393"}},
{"hex":"#1EAC41","hex8":"#FF1EAC41","rgb":{"r":"011.6%","g":"067.5%","b":"025.5%"},"hsv":{"h":"134.9","s":"0.828","v":"0.675"},"hsl":{"h":"134.9","s":"0.707","l":"0.396"}},
{"hex":"#B430E5","hex8":"#FFB430E5","rgb":{"r":"070.4%","g":"018.7%","b":"089.7%"},"hsv":{"h":"283.7","s":"0.792","v":"0.897"},"hsl":{"h":"283.7","s":"0.775","l":"0.542"}},
{"hex":"#FEF888","hex8":"#FFFEF888","rgb":{"r":"099.8%","g":"097.4%","b":"053.2%"},"hsv":{"h":"56.9","s":"0.467","v":"0.998"},"hsl":{"h":"56.9","s":"0.991","l":"0.765"}},
{"hex":"#19CB97","hex8":"#FF19CB97","rgb":{"r":"009.9%","g":"079.5%","b":"059.1%"},"hsv":{"h":"162.4","s":"0.875","v":"0.795"},"hsl":{"h":"162.4","s":"0.779","l":"0.447"}},
{"hex":"#362698","hex8":"#FF362698","rgb":{"r":"021.1%","g":"014.9%","b":"059.7%"},"hsv":{"h":"248.3","s":"0.750","v":"0.597"},"hsl":{"h":"248.3","s":"0.601","l":"0.373"}},
{"hex":"#7E7EB8","hex8":"#FF7E7EB8","rgb":{"r":"049.5%","g":"049.3%","b":"072.1%"},"hsv":{"h":"240.5","s":"0.316","v":"0.721"},"hsl":{"h":"240.5","s":"0.290","l":"0.607"}}
];

@@ -35,24 +37,24 @@

test("Color Equality", function() {
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
ok (true,
"Testing " + c.hex + ": " + tiny.toRgbString() + " " + tiny.toPercentageRgbString() + " " + tiny.toHsvString() + " " + tiny.toHslString() + " " + tiny.toHexString() +
"Original: " + JSON.stringify(c.rgb) + " " + JSON.stringify(c.hsv) + " " + JSON.stringify(c.hsl)
);
ok (tinycolor.equals(c.rgb, c.hex), "RGB equals hex " + c.hex);
ok (tinycolor.equals(c.rgb, c.hex8), "RGB equals hex " + c.hex);
ok (tinycolor.equals(c.rgb, c.hsl), "RGB equals HSL " + c.hex);
ok (tinycolor.equals(c.rgb, c.hsv), "RGB equals HSV " + c.hex);
ok (tinycolor.equals(c.rgb, c.rgb), "RGB equals RGB " + c.hex);
ok (true,
"Testing " + c.hex + ": " + tiny.toRgbString() + " " + tiny.toPercentageRgbString() + " " + tiny.toHsvString() + " " + tiny.toHslString() + " " + tiny.toHexString() +
"Original: " + JSON.stringify(c.rgb) + " " + JSON.stringify(c.hsv) + " " + JSON.stringify(c.hsl)
);
ok (tinycolor.equals(c.rgb, c.hex), "RGB equals hex " + c.hex);
ok (tinycolor.equals(c.rgb, c.hex8), "RGB equals hex " + c.hex);
ok (tinycolor.equals(c.rgb, c.hsl), "RGB equals HSL " + c.hex);
ok (tinycolor.equals(c.rgb, c.hsv), "RGB equals HSV " + c.hex);
ok (tinycolor.equals(c.rgb, c.rgb), "RGB equals RGB " + c.hex);
ok (tinycolor.equals(c.hex, c.hex), "hex equals hex " + c.hex);
ok (tinycolor.equals(c.hex, c.hex8), "hex equals hex8 " + c.hex);
ok (tinycolor.equals(c.hex, c.hsl), "hex equals HSL " + c.hex);
ok (tinycolor.equals(c.hex, c.hsv), "hex equals HSV " + c.hex);
ok (tinycolor.equals(c.hex, c.hex), "hex equals hex " + c.hex);
ok (tinycolor.equals(c.hex, c.hex8), "hex equals hex8 " + c.hex);
ok (tinycolor.equals(c.hex, c.hsl), "hex equals HSL " + c.hex);
ok (tinycolor.equals(c.hex, c.hsv), "hex equals HSV " + c.hex);
ok (tinycolor.equals(c.hsl, c.hsv), "HSL equals HSV " + c.hex);
ok (tinycolor.equals(c.hsl, c.hsv), "HSL equals HSV " + c.hex);
}
}
});

@@ -62,11 +64,14 @@

test("With Ratio", function() {
equal (tinycolor.fromRatio({r: 1, g: 1, b: 1}).toHexString(), "#ffffff", "white");
equal ( tinycolor.fromRatio({r: 1, g: 0, b: 0, a: .5 }).toRgbString(), "rgba(255, 0, 0, 0.5)", "alpha works when ratio is parsed" );
equal ( tinycolor.fromRatio({r: 1, g: 0, b: 0, a: 1 }).toRgbString(), "rgb(255, 0, 0)", "alpha = 1 works when ratio is parsed" );
equal ( tinycolor.fromRatio({r: 1, g: 0, b: 0, a: 10 }).toRgbString(), "rgb(255, 0, 0)", "alpha > 1 works when ratio is parsed" );
equal ( tinycolor.fromRatio({r: 1, g: 0, b: 0, a: -1 }).toRgbString(), "rgb(255, 0, 0)", "alpha < 1 works when ratio is parsed" );
equal (tinycolor.fromRatio({r: 1, g: 1, b: 1}).toHexString(), "#ffffff", "white");
equal (tinycolor.fromRatio({r: 1, g: 0, b: 0, a: .5 }).toRgbString(), "rgba(255, 0, 0, 0.5)", "alpha works when ratio is parsed");
equal (tinycolor.fromRatio({r: 1, g: 0, b: 0, a: 1 }).toRgbString(), "rgb(255, 0, 0)", "alpha = 1 works when ratio is parsed");
equal (tinycolor.fromRatio({r: 1, g: 0, b: 0, a: 10 }).toRgbString(), "rgb(255, 0, 0)", "alpha > 1 works when ratio is parsed");
equal (tinycolor.fromRatio({r: 1, g: 0, b: 0, a: -1 }).toRgbString(), "rgb(255, 0, 0)", "alpha < 1 works when ratio is parsed");
});
test("Without Ratio", function() {
equal (tinycolor({r: 1, g: 1, b: 1}).toHexString(), "#010101", "010101");
equal (tinycolor({r: 1, g: 1, b: 1}).toHexString(), "#010101", "010101");
equal (tinycolor({r: .1, g: .1, b: .1}).toHexString(), "#000000", "000000");
equal (tinycolor("rgb .1 .1 .1").toHexString(), "#000000", "000000");
});

@@ -78,23 +83,23 @@

equal (tinycolor("rgb 255 0 0").toHexString(), "#ff0000", "spaced input");
equal (tinycolor("rgb(255, 0, 0)").toHexString(), "#ff0000", "parenthesized input");
equal (tinycolor("rgb (255, 0, 0)").toHexString(), "#ff0000", "parenthesized spaced input");
equal (tinycolor({ r: 255, g: 0, b: 0 }).toHexString(), "#ff0000", "object input");
deepEqual (tinycolor({ r: 255, g: 0, b: 0 }).toRgb(), { r: 255, g: 0, b: 0, a: 1 }, "object input and compare");
equal (tinycolor("rgb 255 0 0").toHexString(), "#ff0000", "spaced input");
equal (tinycolor("rgb(255, 0, 0)").toHexString(), "#ff0000", "parenthesized input");
equal (tinycolor("rgb (255, 0, 0)").toHexString(), "#ff0000", "parenthesized spaced input");
equal (tinycolor({ r: 255, g: 0, b: 0 }).toHexString(), "#ff0000", "object input");
deepEqual (tinycolor({ r: 255, g: 0, b: 0 }).toRgb(), { r: 255, g: 0, b: 0, a: 1 }, "object input and compare");
ok (tinycolor.equals({r:200, g: 100, b: 0 }, "rgb(200, 100, 0)"));
ok (tinycolor.equals({r:200, g: 100, b: 0 }, "rgb 200 100 0"));
ok (tinycolor.equals({r:200, g: 100, b: 0 }, "rgb 200 100 0"));
ok (tinycolor.equals({r:200, g: 100, b: 0, a: .4 }, "rgba 200 100 0 .4"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgba 200 100 0 1"));
ok (tinycolor.equals({r:200, g: 100, b: 0 }, "rgb(200, 100, 0)"));
ok (tinycolor.equals({r:200, g: 100, b: 0 }, "rgb 200 100 0"));
ok (tinycolor.equals({r:200, g: 100, b: 0 }, "rgb 200 100 0"));
ok (tinycolor.equals({r:200, g: 100, b: 0, a: .4 }, "rgba 200 100 0 .4"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgba 200 100 0 1"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgb(200, 100, 0)"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgb 200 100 0"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgb 200 100 0"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgb(200, 100, 0)"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgb 200 100 0"));
ok (!tinycolor.equals({r:199, g: 100, b: 0 }, "rgb 200 100 0"));
ok (tinycolor.equals(tinycolor({r:200, g: 100, b: 0 }), "rgb(200, 100, 0)"));
ok (tinycolor.equals(tinycolor({r:200, g: 100, b: 0 }), "rgb 200 100 0"));
ok (tinycolor.equals(tinycolor({r:200, g: 100, b: 0 }), "rgb 200 100 0"));
ok (tinycolor.equals(tinycolor({r:200, g: 100, b: 0 }), "rgb(200, 100, 0)"));
ok (tinycolor.equals(tinycolor({r:200, g: 100, b: 0 }), "rgb 200 100 0"));
ok (tinycolor.equals(tinycolor({r:200, g: 100, b: 0 }), "rgb 200 100 0"));

@@ -105,23 +110,23 @@ });

equal (tinycolor("rgb 100% 0% 0%").toHexString(), "#ff0000", "spaced input");
equal (tinycolor("rgb(100%, 0%, 0%)").toHexString(), "#ff0000", "parenthesized input");
equal (tinycolor("rgb (100%, 0%, 0%)").toHexString(), "#ff0000", "parenthesized spaced input");
equal (tinycolor({ r: "100%", g: "0%", b: "0%" }).toHexString(), "#ff0000", "object input");
deepEqual (tinycolor({ r: "100%", g: "0%", b: "0%" }).toRgb(), { r: 255, g: 0, b: 0, a: 1 }, "object input and compare");
equal (tinycolor("rgb 100% 0% 0%").toHexString(), "#ff0000", "spaced input");
equal (tinycolor("rgb(100%, 0%, 0%)").toHexString(), "#ff0000", "parenthesized input");
equal (tinycolor("rgb (100%, 0%, 0%)").toHexString(), "#ff0000", "parenthesized spaced input");
equal (tinycolor({ r: "100%", g: "0%", b: "0%" }).toHexString(), "#ff0000", "object input");
deepEqual (tinycolor({ r: "100%", g: "0%", b: "0%" }).toRgb(), { r: 255, g: 0, b: 0, a: 1 }, "object input and compare");
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%" }, "rgb(90%, 45%, 0%)"));
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%", a: .4 }, "rgba 90% 45% 0% .4"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgba 90% 45% 0% 1"));
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%" }, "rgb(90%, 45%, 0%)"));
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (tinycolor.equals({r:"90%", g: "45%", b: "0%", a: .4 }, "rgba 90% 45% 0% .4"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgba 90% 45% 0% 1"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgb(90%, 45%, 0%)"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgb(90%, 45%, 0%)"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (!tinycolor.equals({r:"89%", g: "45%", b: "0%" }, "rgb 90% 45% 0%"));
ok (tinycolor.equals(tinycolor({r:"90%", g: "45%", b: "0%" }), "rgb(90%, 45%, 0%)"));
ok (tinycolor.equals(tinycolor({r:"90%", g: "45%", b: "0%" }), "rgb 90% 45% 0%"));
ok (tinycolor.equals(tinycolor({r:"90%", g: "45%", b: "0%" }), "rgb 90% 45% 0%"));
ok (tinycolor.equals(tinycolor({r:"90%", g: "45%", b: "0%" }), "rgb(90%, 45%, 0%)"));
ok (tinycolor.equals(tinycolor({r:"90%", g: "45%", b: "0%" }), "rgb 90% 45% 0%"));
ok (tinycolor.equals(tinycolor({r:"90%", g: "45%", b: "0%" }), "rgb 90% 45% 0%"));

@@ -131,9 +136,9 @@ });

test("HSL parsing", function() {
equal( tinycolor({ h: 251, s: 100, l: .38 }).toHexString(), "#2400c2", "to hex" );
equal( tinycolor({ h: 251, s: 100, l: .38 }).toRgbString(), "rgb(36, 0, 194)", "to rgb" );
equal( tinycolor({ h: 251, s: 100, l: .38 }).toHslString(), "hsl(251, 100%, 38%)", "to hsl" );
equal( tinycolor("hsl(251, 100, 38)").toHexString(), "#2400c2", "to hex" );
equal( tinycolor("hsl(251, 100%, 38%)").toRgbString(), "rgb(36, 0, 194)", "to rgb" );
equal( tinycolor("hsl(251, 100%, 38%)").toHslString(), "hsl(251, 100%, 38%)", "to hsl" );
equal( tinycolor("hsl 100 20 10").toHslString(), "hsl(100, 20%, 10%)", "problematic hsl");
equal (tinycolor({ h: 251, s: 100, l: .38 }).toHexString(), "#2400c2", "to hex");
equal (tinycolor({ h: 251, s: 100, l: .38 }).toRgbString(), "rgb(36, 0, 194)", "to rgb");
equal (tinycolor({ h: 251, s: 100, l: .38 }).toHslString(), "hsl(251, 100%, 38%)", "to hsl");
equal (tinycolor("hsl(251, 100, 38)").toHexString(), "#2400c2", "to hex");
equal (tinycolor("hsl(251, 100%, 38%)").toRgbString(), "rgb(36, 0, 194)", "to rgb");
equal (tinycolor("hsl(251, 100%, 38%)").toHslString(), "hsl(251, 100%, 38%)", "to hsl");
equal (tinycolor("hsl 100 20 10").toHslString(), "hsl(100, 20%, 10%)", "problematic hsl");
});

@@ -144,10 +149,10 @@

equal (tinycolor("rgb 255 0 0").toHexString(), "#ff0000");
equal (tinycolor("rgb 255 0 0").toHexString(true), "#f00");
equal (tinycolor("rgba 255 0 0 0.5").toHex8String(), "#80ff0000");
equal (tinycolor("rgb 255 0 0").toHexString(), "#ff0000");
equal (tinycolor("rgb 255 0 0").toHexString(true), "#f00");
equal (tinycolor("rgba 255 0 0 0.5").toHex8String(), "#80ff0000");
equal (tinycolor("rgb 255 0 0").toHex(), "ff0000");
equal (tinycolor("rgb 255 0 0").toHex(true), "f00");
equal (tinycolor("rgba 255 0 0 0.5").toHex8(), "80ff0000");
equal (tinycolor("rgb 255 0 0").toHex(), "ff0000");
equal (tinycolor("rgb 255 0 0").toHex(true), "f00");
equal (tinycolor("rgba 255 0 0 0.5").toHex8(), "80ff0000");

@@ -158,4 +163,4 @@ });

equal( tinycolor("hsv 251.1 0.887 .918").toHsvString(), "hsv(251, 89%, 92%)");
equal( tinycolor("hsv 251.1 0.887 0.918").toHsvString(), "hsv(251, 89%, 92%)");
equal (tinycolor("hsv 251.1 0.887 .918").toHsvString(), "hsv(251, 89%, 92%)");
equal (tinycolor("hsv 251.1 0.887 0.918").toHsvString(), "hsv(251, 89%, 92%)");

@@ -166,3 +171,3 @@ });

equal( tinycolor("this is not a color").toHexString(), "#000000");
equal (tinycolor("this is not a color").toHexString(), "#000000");

@@ -172,146 +177,146 @@ });

test("Named colors", function() {
equal (tinycolor("aliceblue").toHex(), "f0f8ff");
equal (tinycolor("antiquewhite").toHex(), "faebd7");
equal (tinycolor("aqua").toHex(), "00ffff");
equal (tinycolor("aquamarine").toHex(), "7fffd4");
equal (tinycolor("azure").toHex(), "f0ffff");
equal (tinycolor("beige").toHex(), "f5f5dc");
equal (tinycolor("bisque").toHex(), "ffe4c4");
equal (tinycolor("black").toHex(), "000000");
equal (tinycolor("blanchedalmond").toHex(), "ffebcd");
equal (tinycolor("blue").toHex(), "0000ff");
equal (tinycolor("blueviolet").toHex(), "8a2be2");
equal (tinycolor("brown").toHex(), "a52a2a");
equal (tinycolor("burlywood").toHex(), "deb887");
equal (tinycolor("cadetblue").toHex(), "5f9ea0");
equal (tinycolor("chartreuse").toHex(), "7fff00");
equal (tinycolor("chocolate").toHex(), "d2691e");
equal (tinycolor("coral").toHex(), "ff7f50");
equal (tinycolor("cornflowerblue").toHex(), "6495ed");
equal (tinycolor("cornsilk").toHex(), "fff8dc");
equal (tinycolor("crimson").toHex(), "dc143c");
equal (tinycolor("cyan").toHex(), "00ffff");
equal (tinycolor("darkblue").toHex(), "00008b");
equal (tinycolor("darkcyan").toHex(), "008b8b");
equal (tinycolor("darkgoldenrod").toHex(), "b8860b");
equal (tinycolor("darkgray").toHex(), "a9a9a9");
equal (tinycolor("darkgreen").toHex(), "006400");
equal (tinycolor("darkkhaki").toHex(), "bdb76b");
equal (tinycolor("darkmagenta").toHex(), "8b008b");
equal (tinycolor("darkolivegreen").toHex(), "556b2f");
equal (tinycolor("darkorange").toHex(), "ff8c00");
equal (tinycolor("darkorchid").toHex(), "9932cc");
equal (tinycolor("darkred").toHex(), "8b0000");
equal (tinycolor("darksalmon").toHex(), "e9967a");
equal (tinycolor("darkseagreen").toHex(), "8fbc8f");
equal (tinycolor("darkslateblue").toHex(), "483d8b");
equal (tinycolor("darkslategray").toHex(), "2f4f4f");
equal (tinycolor("darkturquoise").toHex(), "00ced1");
equal (tinycolor("darkviolet").toHex(), "9400d3");
equal (tinycolor("deeppink").toHex(), "ff1493");
equal (tinycolor("deepskyblue").toHex(), "00bfff");
equal (tinycolor("dimgray").toHex(), "696969");
equal (tinycolor("dodgerblue").toHex(), "1e90ff");
equal (tinycolor("firebrick").toHex(), "b22222");
equal (tinycolor("floralwhite").toHex(), "fffaf0");
equal (tinycolor("forestgreen").toHex(), "228b22");
equal (tinycolor("fuchsia").toHex(), "ff00ff");
equal (tinycolor("gainsboro").toHex(), "dcdcdc");
equal (tinycolor("ghostwhite").toHex(), "f8f8ff");
equal (tinycolor("gold").toHex(), "ffd700");
equal (tinycolor("goldenrod").toHex(), "daa520");
equal (tinycolor("gray").toHex(), "808080");
equal (tinycolor("grey").toHex(), "808080");
equal (tinycolor("green").toHex(), "008000");
equal (tinycolor("greenyellow").toHex(), "adff2f");
equal (tinycolor("honeydew").toHex(), "f0fff0");
equal (tinycolor("hotpink").toHex(), "ff69b4");
equal (tinycolor("indianred ").toHex(), "cd5c5c");
equal (tinycolor("indigo ").toHex(), "4b0082");
equal (tinycolor("ivory").toHex(), "fffff0");
equal (tinycolor("khaki").toHex(), "f0e68c");
equal (tinycolor("lavender").toHex(), "e6e6fa");
equal (tinycolor("lavenderblush").toHex(), "fff0f5");
equal (tinycolor("lawngreen").toHex(), "7cfc00");
equal (tinycolor("lemonchiffon").toHex(), "fffacd");
equal (tinycolor("lightblue").toHex(), "add8e6");
equal (tinycolor("lightcoral").toHex(), "f08080");
equal (tinycolor("lightcyan").toHex(), "e0ffff");
equal (tinycolor("lightgoldenrodyellow").toHex(), "fafad2");
equal (tinycolor("lightgrey").toHex(), "d3d3d3");
equal (tinycolor("lightgreen").toHex(), "90ee90");
equal (tinycolor("lightpink").toHex(), "ffb6c1");
equal (tinycolor("lightsalmon").toHex(), "ffa07a");
equal (tinycolor("lightseagreen").toHex(), "20b2aa");
equal (tinycolor("lightskyblue").toHex(), "87cefa");
equal (tinycolor("lightslategray").toHex(), "778899");
equal (tinycolor("lightsteelblue").toHex(), "b0c4de");
equal (tinycolor("lightyellow").toHex(), "ffffe0");
equal (tinycolor("lime").toHex(), "00ff00");
equal (tinycolor("limegreen").toHex(), "32cd32");
equal (tinycolor("linen").toHex(), "faf0e6");
equal (tinycolor("magenta").toHex(), "ff00ff");
equal (tinycolor("maroon").toHex(), "800000");
equal (tinycolor("mediumaquamarine").toHex(), "66cdaa");
equal (tinycolor("mediumblue").toHex(), "0000cd");
equal (tinycolor("mediumorchid").toHex(), "ba55d3");
equal (tinycolor("mediumpurple").toHex(), "9370db");
equal (tinycolor("mediumseagreen").toHex(), "3cb371");
equal (tinycolor("mediumslateblue").toHex(), "7b68ee");
equal (tinycolor("mediumspringgreen").toHex(), "00fa9a");
equal (tinycolor("mediumturquoise").toHex(), "48d1cc");
equal (tinycolor("mediumvioletred").toHex(), "c71585");
equal (tinycolor("midnightblue").toHex(), "191970");
equal (tinycolor("mintcream").toHex(), "f5fffa");
equal (tinycolor("mistyrose").toHex(), "ffe4e1");
equal (tinycolor("moccasin").toHex(), "ffe4b5");
equal (tinycolor("navajowhite").toHex(), "ffdead");
equal (tinycolor("navy").toHex(), "000080");
equal (tinycolor("oldlace").toHex(), "fdf5e6");
equal (tinycolor("olive").toHex(), "808000");
equal (tinycolor("olivedrab").toHex(), "6b8e23");
equal (tinycolor("orange").toHex(), "ffa500");
equal (tinycolor("orangered").toHex(), "ff4500");
equal (tinycolor("orchid").toHex(), "da70d6");
equal (tinycolor("palegoldenrod").toHex(), "eee8aa");
equal (tinycolor("palegreen").toHex(), "98fb98");
equal (tinycolor("paleturquoise").toHex(), "afeeee");
equal (tinycolor("palevioletred").toHex(), "db7093");
equal (tinycolor("papayawhip").toHex(), "ffefd5");
equal (tinycolor("peachpuff").toHex(), "ffdab9");
equal (tinycolor("peru").toHex(), "cd853f");
equal (tinycolor("pink").toHex(), "ffc0cb");
equal (tinycolor("plum").toHex(), "dda0dd");
equal (tinycolor("powderblue").toHex(), "b0e0e6");
equal (tinycolor("purple").toHex(), "800080");
equal (tinycolor("red").toHex(), "ff0000");
equal (tinycolor("rosybrown").toHex(), "bc8f8f");
equal (tinycolor("royalblue").toHex(), "4169e1");
equal (tinycolor("saddlebrown").toHex(), "8b4513");
equal (tinycolor("salmon").toHex(), "fa8072");
equal (tinycolor("sandybrown").toHex(), "f4a460");
equal (tinycolor("seagreen").toHex(), "2e8b57");
equal (tinycolor("seashell").toHex(), "fff5ee");
equal (tinycolor("sienna").toHex(), "a0522d");
equal (tinycolor("silver").toHex(), "c0c0c0");
equal (tinycolor("skyblue").toHex(), "87ceeb");
equal (tinycolor("slateblue").toHex(), "6a5acd");
equal (tinycolor("slategray").toHex(), "708090");
equal (tinycolor("snow").toHex(), "fffafa");
equal (tinycolor("springgreen").toHex(), "00ff7f");
equal (tinycolor("steelblue").toHex(), "4682b4");
equal (tinycolor("tan").toHex(), "d2b48c");
equal (tinycolor("teal").toHex(), "008080");
equal (tinycolor("thistle").toHex(), "d8bfd8");
equal (tinycolor("tomato").toHex(), "ff6347");
equal (tinycolor("turquoise").toHex(), "40e0d0");
equal (tinycolor("violet").toHex(), "ee82ee");
equal (tinycolor("wheat").toHex(), "f5deb3");
equal (tinycolor("white").toHex(), "ffffff");
equal (tinycolor("whitesmoke").toHex(), "f5f5f5");
equal (tinycolor("yellow").toHex(), "ffff00");
equal (tinycolor("yellowgreen").toHex(), "9acd32");
equal (tinycolor("aliceblue").toHex(), "f0f8ff");
equal (tinycolor("antiquewhite").toHex(), "faebd7");
equal (tinycolor("aqua").toHex(), "00ffff");
equal (tinycolor("aquamarine").toHex(), "7fffd4");
equal (tinycolor("azure").toHex(), "f0ffff");
equal (tinycolor("beige").toHex(), "f5f5dc");
equal (tinycolor("bisque").toHex(), "ffe4c4");
equal (tinycolor("black").toHex(), "000000");
equal (tinycolor("blanchedalmond").toHex(), "ffebcd");
equal (tinycolor("blue").toHex(), "0000ff");
equal (tinycolor("blueviolet").toHex(), "8a2be2");
equal (tinycolor("brown").toHex(), "a52a2a");
equal (tinycolor("burlywood").toHex(), "deb887");
equal (tinycolor("cadetblue").toHex(), "5f9ea0");
equal (tinycolor("chartreuse").toHex(), "7fff00");
equal (tinycolor("chocolate").toHex(), "d2691e");
equal (tinycolor("coral").toHex(), "ff7f50");
equal (tinycolor("cornflowerblue").toHex(), "6495ed");
equal (tinycolor("cornsilk").toHex(), "fff8dc");
equal (tinycolor("crimson").toHex(), "dc143c");
equal (tinycolor("cyan").toHex(), "00ffff");
equal (tinycolor("darkblue").toHex(), "00008b");
equal (tinycolor("darkcyan").toHex(), "008b8b");
equal (tinycolor("darkgoldenrod").toHex(), "b8860b");
equal (tinycolor("darkgray").toHex(), "a9a9a9");
equal (tinycolor("darkgreen").toHex(), "006400");
equal (tinycolor("darkkhaki").toHex(), "bdb76b");
equal (tinycolor("darkmagenta").toHex(), "8b008b");
equal (tinycolor("darkolivegreen").toHex(), "556b2f");
equal (tinycolor("darkorange").toHex(), "ff8c00");
equal (tinycolor("darkorchid").toHex(), "9932cc");
equal (tinycolor("darkred").toHex(), "8b0000");
equal (tinycolor("darksalmon").toHex(), "e9967a");
equal (tinycolor("darkseagreen").toHex(), "8fbc8f");
equal (tinycolor("darkslateblue").toHex(), "483d8b");
equal (tinycolor("darkslategray").toHex(), "2f4f4f");
equal (tinycolor("darkturquoise").toHex(), "00ced1");
equal (tinycolor("darkviolet").toHex(), "9400d3");
equal (tinycolor("deeppink").toHex(), "ff1493");
equal (tinycolor("deepskyblue").toHex(), "00bfff");
equal (tinycolor("dimgray").toHex(), "696969");
equal (tinycolor("dodgerblue").toHex(), "1e90ff");
equal (tinycolor("firebrick").toHex(), "b22222");
equal (tinycolor("floralwhite").toHex(), "fffaf0");
equal (tinycolor("forestgreen").toHex(), "228b22");
equal (tinycolor("fuchsia").toHex(), "ff00ff");
equal (tinycolor("gainsboro").toHex(), "dcdcdc");
equal (tinycolor("ghostwhite").toHex(), "f8f8ff");
equal (tinycolor("gold").toHex(), "ffd700");
equal (tinycolor("goldenrod").toHex(), "daa520");
equal (tinycolor("gray").toHex(), "808080");
equal (tinycolor("grey").toHex(), "808080");
equal (tinycolor("green").toHex(), "008000");
equal (tinycolor("greenyellow").toHex(), "adff2f");
equal (tinycolor("honeydew").toHex(), "f0fff0");
equal (tinycolor("hotpink").toHex(), "ff69b4");
equal (tinycolor("indianred ").toHex(), "cd5c5c");
equal (tinycolor("indigo ").toHex(), "4b0082");
equal (tinycolor("ivory").toHex(), "fffff0");
equal (tinycolor("khaki").toHex(), "f0e68c");
equal (tinycolor("lavender").toHex(), "e6e6fa");
equal (tinycolor("lavenderblush").toHex(), "fff0f5");
equal (tinycolor("lawngreen").toHex(), "7cfc00");
equal (tinycolor("lemonchiffon").toHex(), "fffacd");
equal (tinycolor("lightblue").toHex(), "add8e6");
equal (tinycolor("lightcoral").toHex(), "f08080");
equal (tinycolor("lightcyan").toHex(), "e0ffff");
equal (tinycolor("lightgoldenrodyellow").toHex(), "fafad2");
equal (tinycolor("lightgrey").toHex(), "d3d3d3");
equal (tinycolor("lightgreen").toHex(), "90ee90");
equal (tinycolor("lightpink").toHex(), "ffb6c1");
equal (tinycolor("lightsalmon").toHex(), "ffa07a");
equal (tinycolor("lightseagreen").toHex(), "20b2aa");
equal (tinycolor("lightskyblue").toHex(), "87cefa");
equal (tinycolor("lightslategray").toHex(), "778899");
equal (tinycolor("lightsteelblue").toHex(), "b0c4de");
equal (tinycolor("lightyellow").toHex(), "ffffe0");
equal (tinycolor("lime").toHex(), "00ff00");
equal (tinycolor("limegreen").toHex(), "32cd32");
equal (tinycolor("linen").toHex(), "faf0e6");
equal (tinycolor("magenta").toHex(), "ff00ff");
equal (tinycolor("maroon").toHex(), "800000");
equal (tinycolor("mediumaquamarine").toHex(), "66cdaa");
equal (tinycolor("mediumblue").toHex(), "0000cd");
equal (tinycolor("mediumorchid").toHex(), "ba55d3");
equal (tinycolor("mediumpurple").toHex(), "9370db");
equal (tinycolor("mediumseagreen").toHex(), "3cb371");
equal (tinycolor("mediumslateblue").toHex(), "7b68ee");
equal (tinycolor("mediumspringgreen").toHex(), "00fa9a");
equal (tinycolor("mediumturquoise").toHex(), "48d1cc");
equal (tinycolor("mediumvioletred").toHex(), "c71585");
equal (tinycolor("midnightblue").toHex(), "191970");
equal (tinycolor("mintcream").toHex(), "f5fffa");
equal (tinycolor("mistyrose").toHex(), "ffe4e1");
equal (tinycolor("moccasin").toHex(), "ffe4b5");
equal (tinycolor("navajowhite").toHex(), "ffdead");
equal (tinycolor("navy").toHex(), "000080");
equal (tinycolor("oldlace").toHex(), "fdf5e6");
equal (tinycolor("olive").toHex(), "808000");
equal (tinycolor("olivedrab").toHex(), "6b8e23");
equal (tinycolor("orange").toHex(), "ffa500");
equal (tinycolor("orangered").toHex(), "ff4500");
equal (tinycolor("orchid").toHex(), "da70d6");
equal (tinycolor("palegoldenrod").toHex(), "eee8aa");
equal (tinycolor("palegreen").toHex(), "98fb98");
equal (tinycolor("paleturquoise").toHex(), "afeeee");
equal (tinycolor("palevioletred").toHex(), "db7093");
equal (tinycolor("papayawhip").toHex(), "ffefd5");
equal (tinycolor("peachpuff").toHex(), "ffdab9");
equal (tinycolor("peru").toHex(), "cd853f");
equal (tinycolor("pink").toHex(), "ffc0cb");
equal (tinycolor("plum").toHex(), "dda0dd");
equal (tinycolor("powderblue").toHex(), "b0e0e6");
equal (tinycolor("purple").toHex(), "800080");
equal (tinycolor("red").toHex(), "ff0000");
equal (tinycolor("rosybrown").toHex(), "bc8f8f");
equal (tinycolor("royalblue").toHex(), "4169e1");
equal (tinycolor("saddlebrown").toHex(), "8b4513");
equal (tinycolor("salmon").toHex(), "fa8072");
equal (tinycolor("sandybrown").toHex(), "f4a460");
equal (tinycolor("seagreen").toHex(), "2e8b57");
equal (tinycolor("seashell").toHex(), "fff5ee");
equal (tinycolor("sienna").toHex(), "a0522d");
equal (tinycolor("silver").toHex(), "c0c0c0");
equal (tinycolor("skyblue").toHex(), "87ceeb");
equal (tinycolor("slateblue").toHex(), "6a5acd");
equal (tinycolor("slategray").toHex(), "708090");
equal (tinycolor("snow").toHex(), "fffafa");
equal (tinycolor("springgreen").toHex(), "00ff7f");
equal (tinycolor("steelblue").toHex(), "4682b4");
equal (tinycolor("tan").toHex(), "d2b48c");
equal (tinycolor("teal").toHex(), "008080");
equal (tinycolor("thistle").toHex(), "d8bfd8");
equal (tinycolor("tomato").toHex(), "ff6347");
equal (tinycolor("turquoise").toHex(), "40e0d0");
equal (tinycolor("violet").toHex(), "ee82ee");
equal (tinycolor("wheat").toHex(), "f5deb3");
equal (tinycolor("white").toHex(), "ffffff");
equal (tinycolor("whitesmoke").toHex(), "f5f5f5");
equal (tinycolor("yellow").toHex(), "ffff00");
equal (tinycolor("yellowgreen").toHex(), "9acd32");
equal (tinycolor("#f00").toName(), "red");
equal (tinycolor("#fa0a0a").toName(), false);
equal (tinycolor("#f00").toName(), "red");
equal (tinycolor("#fa0a0a").toName(), false);
});

@@ -321,51 +326,60 @@

test("Invalid alpha should normalize to 1", function() {
equal(tinycolor({r:255,g:20,b:10,a: -1}).toRgbString(), "rgb(255, 20, 10)", "Negative value");
equal(tinycolor({r:255,g:20,b:10,a: -0}).toRgbString(), "rgba(255, 20, 10, 0)", "Negative 0");
equal(tinycolor({r:255,g:20,b:10,a: 0}).toRgbString(), "rgba(255, 20, 10, 0)", "0");
equal(tinycolor({r:255,g:20,b:10,a: .5}).toRgbString(), "rgba(255, 20, 10, 0.5)", ".5");
equal(tinycolor({r:255,g:20,b:10,a: 1}).toRgbString(), "rgb(255, 20, 10)", "1");
equal(tinycolor({r:255,g:20,b:10,a: 100}).toRgbString(), "rgb(255, 20, 10)", "Greater than 1");
equal(tinycolor({r:255,g:20,b:10,a: "asdfasd"}).toRgbString(), "rgb(255, 20, 10)", "Non Numeric");
equal (tinycolor({r:255,g:20,b:10,a: -1}).toRgbString(), "rgb(255, 20, 10)", "Negative value");
equal (tinycolor({r:255,g:20,b:10,a: -0}).toRgbString(), "rgba(255, 20, 10, 0)", "Negative 0");
equal (tinycolor({r:255,g:20,b:10,a: 0}).toRgbString(), "rgba(255, 20, 10, 0)", "0");
equal (tinycolor({r:255,g:20,b:10,a: .5}).toRgbString(), "rgba(255, 20, 10, 0.5)", ".5");
equal (tinycolor({r:255,g:20,b:10,a: 1}).toRgbString(), "rgb(255, 20, 10)", "1");
equal (tinycolor({r:255,g:20,b:10,a: 100}).toRgbString(), "rgb(255, 20, 10)", "Greater than 1");
equal (tinycolor({r:255,g:20,b:10,a: "asdfasd"}).toRgbString(), "rgb(255, 20, 10)", "Non Numeric");
equal(tinycolor("#fff").toRgbString(), "rgb(255, 255, 255)", "Hex should be 1");
equal(tinycolor("rgba 255 0 0 100").toRgbString(), "rgb(255, 0, 0)", "Greater than 1 in string parsing");
equal (tinycolor("#fff").toRgbString(), "rgb(255, 255, 255)", "Hex should be 1");
equal (tinycolor("rgba 255 0 0 100").toRgbString(), "rgb(255, 0, 0)", "Greater than 1 in string parsing");
});
var redNamed = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: .5}, {format: "name"});
var transparentNamed = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: 0 }, {format: "name"});
var redHex = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: .5}, {format: "hex"});
test("toString() with alpha set", function() {
var redNamed = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: .5}, {format: "name"});
var transparentNamed = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: 0 }, {format: "name"});
var redHex = tinycolor.fromRatio({ r: 255, g: 0, b: 0, a: .5}, {format: "hex"});
equal(redNamed.toString(), "rgba(255, 0, 0, 0.5)", "Names should default to rgba if alpha is < 1");
equal(redHex.toString(), "rgba(255, 0, 0, 0.5)", "Hex should default to rgba if alpha is < 1");
equal (redNamed.toString(), "rgba(255, 0, 0, 0.5)", "Names should default to rgba if alpha is < 1");
equal (redHex.toString(), "rgba(255, 0, 0, 0.5)", "Hex should default to rgba if alpha is < 1");
equal(redNamed.toString("hex"), "#ff0000", "Names should not be returned as rgba if format is specified");
equal(redNamed.toString("hex6"), "#ff0000", "Names should not be returned as rgba if format is specified");
equal(redNamed.toString("hex3"), "#f00", "Names should not be returned as rgba if format is specified");
equal(redNamed.toString("name"), "red", "Names should not be returned as rgba if format is specified");
equal (redNamed.toString("hex"), "#ff0000", "Names should not be returned as rgba if format is specified");
equal (redNamed.toString("hex6"), "#ff0000", "Names should not be returned as rgba if format is specified");
equal (redNamed.toString("hex3"), "#f00", "Names should not be returned as rgba if format is specified");
equal (redNamed.toString("name"), "#ff0000", "Semi transparent names should return hex in toString() if name format is specified");
equal(redHex.toString(), "rgba(255, 0, 0, 0.5)", "Hex should default to rgba if alpha is < 1");
equal(transparentNamed.toString(), "transparent", "Named color should equal transparent if alpha == 0");
equal (redNamed.toName(), false, "Semi transparent names should be false in toName()");
var hexSetter = tinycolor("rgba(255, 0, 0, 1)");
equal(hexSetter.alpha, 1, "Alpha should start as 1");
hexSetter.setAlpha(.9);
equal(hexSetter.getAlpha(), .9, "setAlpha should change alpha value");
hexSetter.setAlpha(.5);
equal(hexSetter.getAlpha(), .5, "setAlpha should change alpha value");
hexSetter.setAlpha(0);
equal(hexSetter.getAlpha(), 0, "setAlpha should change alpha value");
hexSetter.setAlpha(-1);
equal(hexSetter.getAlpha(), 1, "setAlpha with value < 0 should be bound to 1");
hexSetter.setAlpha(2);
equal(hexSetter.getAlpha(), 1, "setAlpha with value > 1 should be bound to 1");
hexSetter.setAlpha();
equal(hexSetter.getAlpha(), 1, "setAlpha with invalid value should be bound to 1");
hexSetter.setAlpha(null);
equal(hexSetter.getAlpha(), 1, "setAlpha with invalid value should be bound to 1");
hexSetter.setAlpha("test");
equal(hexSetter.getAlpha(), 1, "setAlpha with invalid value should be bound to 1");
equal (redHex.toString(), "rgba(255, 0, 0, 0.5)", "Hex should default to rgba if alpha is < 1");
equal (transparentNamed.toString(), "transparent", "Named color should equal transparent if alpha == 0");
});
test("setting alpha", function() {
var hexSetter = tinycolor("rgba(255, 0, 0, 1)");
equal (hexSetter.getAlpha(), 1, "Alpha should start as 1");
hexSetter.setAlpha(.9);
equal (hexSetter.getAlpha(), .9, "setAlpha should change alpha value");
hexSetter.setAlpha(.5);
equal (hexSetter.getAlpha(), .5, "setAlpha should change alpha value");
hexSetter.setAlpha(0);
equal (hexSetter.getAlpha(), 0, "setAlpha should change alpha value");
hexSetter.setAlpha(-1);
equal (hexSetter.getAlpha(), 1, "setAlpha with value < 0 should be bound to 1");
hexSetter.setAlpha(2);
equal (hexSetter.getAlpha(), 1, "setAlpha with value > 1 should be bound to 1");
hexSetter.setAlpha();
equal (hexSetter.getAlpha(), 1, "setAlpha with invalid value should be bound to 1");
hexSetter.setAlpha(null);
equal (hexSetter.getAlpha(), 1, "setAlpha with invalid value should be bound to 1");
hexSetter.setAlpha("test");
equal (hexSetter.getAlpha(), 1, "setAlpha with invalid value should be bound to 1");
});
test("Alpha = 0 should act differently on toName()", function() {
equal(tinycolor({r:255,g:20,b:10,a: 0}).toName(), "transparent", "0");
equal(tinycolor("transparent").toString(), "transparent", "toString when passed");
equal(tinycolor("transparent").toHex(), "000000", "toHex");
equal (tinycolor({r:255,g:20,b:10,a: 0}).toName(), "transparent", "0");
equal (tinycolor("transparent").toString(), "transparent", "toString when passed");
equal (tinycolor("transparent").toHex(), "000000", "toHex");
});

@@ -375,50 +389,89 @@

test("HSL Object", function() {
var random = tinycolor.random();
equal (random.toHexString(), tinycolor(random.toHsl()).toHexString(), "HSL Object");
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
equal (tiny.toHexString(), tinycolor(tiny.toHsl()).toHexString(), "HSL Object");
}
});
/*
test("HSL String", function() {
var random = tinycolor.random();
equal (random.toHexString(), tinycolor(random.toHslString()).toHexString(), random.toHexString());
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
var input = tiny.toRgb();
var output = tinycolor(tiny.toHslString()).toRgb();
var maxDiff = 2;
equal (Math.abs(input.r - output.r) <= maxDiff, true, "toHslString red value difference <= " + maxDiff);
equal (Math.abs(input.g - output.g) <= maxDiff, true, "toHslString green value difference <= " + maxDiff);
equal (Math.abs(input.b - output.b) <= maxDiff, true, "toHslString blue value difference <= " + maxDiff);
}
});
test("HSV String", function() {
var random = tinycolor.random();
equal (random.toHexString(), tinycolor(random.toHsvString()).toHexString(), random.toHsvString());
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
var input = tiny.toRgb();
var output = tinycolor(tiny.toHsvString()).toRgb();
var maxDiff = 2;
equal (Math.abs(input.r - output.r) <= maxDiff, true, "toHsvString red value difference <= " + maxDiff);
equal (Math.abs(input.g - output.g) <= maxDiff, true, "toHsvString green value difference <= " + maxDiff);
equal (Math.abs(input.b - output.b) <= maxDiff, true, "toHsvString blue value difference <= " + maxDiff);
}
});
*/
test("HSV Object", function() {
var random = tinycolor.random();
equal (random.toHexString(), tinycolor(random.toHsv()).toHexString(), "HSV Object");
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
equal (tiny.toHexString(), tinycolor(tiny.toHsv()).toHexString(), "HSV Object");
}
});
test("RGB Object", function() {
var random = tinycolor.random();
equal (random.toHexString(), tinycolor(random.toRgb()).toHexString(), "RGB Object");
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
equal (tiny.toHexString(), tinycolor(tiny.toRgb()).toHexString(), "RGB Object");
}
});
test("RGB String", function() {
var random = tinycolor.random();
equal (random.toHexString(), tinycolor(random.toRgbString()).toHexString(), "RGB String");
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
equal (tiny.toHexString(), tinycolor(tiny.toRgbString()).toHexString(), "RGB String");
}
});
test("PRGB Object", function() {
var random = tinycolor.random();
var input = random.toRgb();
var output = tinycolor(random.toPercentageRgb()).toRgb();
var maxDiff = 2;
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
var input = tiny.toRgb();
var output = tinycolor(tiny.toPercentageRgb()).toRgb();
var maxDiff = 2;
equal(Math.abs(input.r - output.r) <= maxDiff, true, "Red value difference <= " + maxDiff);
equal(Math.abs(input.g - output.g) <= maxDiff, true, "Green value difference <= " + maxDiff);
equal(Math.abs(input.b - output.b) <= maxDiff, true, "Blue value difference <= " + maxDiff);
equal (Math.abs(input.r - output.r) <= maxDiff, true, "Red value difference <= " + maxDiff);
equal (Math.abs(input.g - output.g) <= maxDiff, true, "Green value difference <= " + maxDiff);
equal (Math.abs(input.b - output.b) <= maxDiff, true, "Blue value difference <= " + maxDiff);
}
});
test("PRGB String", function() {
var random = tinycolor.random();
var input = random.toRgb();
var output = tinycolor(random.toPercentageRgbString()).toRgb();
var maxDiff = 2;
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
var input = tiny.toRgb();
var output = tinycolor(tiny.toPercentageRgbString()).toRgb();
var maxDiff = 2;
equal(Math.abs(input.r - output.r) <= maxDiff, true, "Red value difference <= " + maxDiff);
equal(Math.abs(input.g - output.g) <= maxDiff, true, "Green value difference <= " + maxDiff);
equal(Math.abs(input.b - output.b) <= maxDiff, true, "Blue value difference <= " + maxDiff);
equal (Math.abs(input.r - output.r) <= maxDiff, true, "Red value difference <= " + maxDiff);
equal (Math.abs(input.g - output.g) <= maxDiff, true, "Green value difference <= " + maxDiff);
equal (Math.abs(input.b - output.b) <= maxDiff, true, "Blue value difference <= " + maxDiff);
}
});
test("Object", function() {
var random = tinycolor.random();
equal (random.toHexString(), tinycolor(random).toHexString(), "Object");
for (var i = 0; i < conversions.length; i++) {
var c = conversions[i];
var tiny = tinycolor(c.hex);
equal (tiny.toHexString(), tinycolor(tiny).toHexString(), "Object");
}
});

@@ -430,11 +483,11 @@

test("Color equality", function() {
ok (tinycolor.equals("#ff0000", "#ff0000"), "Same hex");
ok (tinycolor.equals("#ff0000", "rgb(255, 0, 0)"), "Same alphas");
ok (!tinycolor.equals("#ff0000", "rgba(255, 0, 0, .1)"), "Different alphas");
ok (tinycolor.equals("ff0000", "#ff0000"), "Same hex");
ok (tinycolor.equals("#f00", "#ff0000"), "Same hex");
ok (tinycolor.equals("f00", "#ff0000"), "Same hex");
equal (tinycolor("010101").toHexString(), "#010101");
ok (!tinycolor.equals("#ff0000", "#00ff00"), "Different hex");
ok (tinycolor.equals("#ff8000", "rgb(100%, 50%, 0%)"), "Percentage bounds checking");
ok (tinycolor.equals("#ff0000", "#ff0000"), "Same hex");
ok (tinycolor.equals("#ff0000", "rgb(255, 0, 0)"), "Same alphas");
ok (!tinycolor.equals("#ff0000", "rgba(255, 0, 0, .1)"), "Different alphas");
ok (tinycolor.equals("ff0000", "#ff0000"), "Same hex");
ok (tinycolor.equals("#f00", "#ff0000"), "Same hex");
ok (tinycolor.equals("f00", "#ff0000"), "Same hex");
equal (tinycolor("010101").toHexString(), "#010101");
ok (!tinycolor.equals("#ff0000", "#00ff00"), "Different hex");
ok (tinycolor.equals("#ff8000", "rgb(100%, 50%, 0%)"), "Percentage bounds checking");
});

@@ -451,10 +504,10 @@

equal (tinycolor("red").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffff0000,endColorstr=#ffff0000)");
equal (tinycolor("red").toFilter("blue"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffff0000,endColorstr=#ff0000ff)");
equal (tinycolor("red").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffff0000,endColorstr=#ffff0000)");
equal (tinycolor("red").toFilter("blue"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffff0000,endColorstr=#ff0000ff)");
equal(tinycolor("transparent").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00000000,endColorstr=#00000000)");
equal(tinycolor("transparent").toFilter("red"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00000000,endColorstr=#ffff0000)");
equal (tinycolor("transparent").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00000000,endColorstr=#00000000)");
equal (tinycolor("transparent").toFilter("red"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00000000,endColorstr=#ffff0000)");
equal (tinycolor("#ddf0f0f0").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ddf0f0f0,endColorstr=#ddf0f0f0)");
equal (tinycolor("rgba(0, 0, 255, .5").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#800000ff,endColorstr=#800000ff)");
equal (tinycolor("#ddf0f0f0").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ddf0f0f0,endColorstr=#ddf0f0f0)");
equal (tinycolor("rgba(0, 0, 255, .5").toFilter(), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#800000ff,endColorstr=#800000ff)");
});

@@ -473,18 +526,18 @@

test("Combinations", function () {
for (var i = 0; i <= 100; i++) {
equal(tinycolor.desaturate("red", i).toHex(), DESATURATIONS[i], "Desaturation " + i + " works");
}
for (var i = 0; i <= 100; i++) {
equal(tinycolor.saturate("red", i).toHex(), SATURATIONS[i], "Saturation " + i + " works");
}
for (var i = 0; i <= 100; i++) {
equal(tinycolor.lighten("red", i).toHex(), LIGHTENS[i], "Lighten " + i + " works");
}
for (var i = 0; i <= 100; i++) {
equal(tinycolor.darken("red", i).toHex(), DARKENS[i], "Darken " + i + " works");
}
for (var i = 0; i <= 100; i++) {
equal (tinycolor.desaturate("red", i).toHex(), DESATURATIONS[i], "Desaturation " + i + " works");
}
for (var i = 0; i <= 100; i++) {
equal (tinycolor.saturate("red", i).toHex(), SATURATIONS[i], "Saturation " + i + " works");
}
for (var i = 0; i <= 100; i++) {
equal (tinycolor.lighten("red", i).toHex(), LIGHTENS[i], "Lighten " + i + " works");
}
for (var i = 0; i <= 100; i++) {
equal (tinycolor.darken("red", i).toHex(), DARKENS[i], "Darken " + i + " works");
}
equal(tinycolor.greyscale("red").toHex(), "808080", "Greyscale works")
equal(tinycolor.complement("red").toHex(), "00ffff", "Complement works");
equal (tinycolor.greyscale("red").toHex(), "808080", "Greyscale works")
equal (tinycolor.complement("red").toHex(), "00ffff", "Complement works");
});

@@ -496,11 +549,11 @@

$.get("allhex.txt", function(d) {
var hex = d.split('\n');
for (var i = 0, l = hex.length; i < l; i++) {
ok(tinycolor(hex[i]).toHex(), hex[i]);
}
console.log(hex.length);
start();
});
$.get("allhex.txt", function(d) {
var hex = d.split('\n');
for (var i = 0, l = hex.length; i < l; i++) {
ok (tinycolor(hex[i]).toHex(), hex[i]);
}
console.log(hex.length);
start();
});
});
*/

@@ -1,2 +0,2 @@

// TinyColor v0.9.17
// TinyColor v0.9.18
// https://github.com/bgrins/TinyColor

@@ -16,3 +16,3 @@ // 2013-08-10, Brian Grinstead, MIT License

function tinycolor (color, opts) {
var tinycolor = function tinycolor (color, opts) {

@@ -23,13 +23,18 @@ color = (color) ? color : '';

// If input is already a tinycolor, return itself
if (typeof color == "object" && color.hasOwnProperty("_tc_id")) {
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);
}
var rgb = inputToRGB(color);
var r = rgb.r,
g = rgb.g,
b = rgb.b,
a = rgb.a,
roundA = mathRound(100*a) / 100,
format = opts.format || rgb.format;
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;

@@ -40,129 +45,131 @@ // Don't let the range of [0,255] come back in [0,1].

// If it was supposed to be 128, this was already taken care of by `inputToRgb`
if (r < 1) { r = mathRound(r); }
if (g < 1) { g = mathRound(g); }
if (b < 1) { b = mathRound(b); }
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); }
return {
ok: rgb.ok,
format: format,
_tc_id: tinyCounter++,
alpha: a,
getAlpha: function() {
return a;
},
setAlpha: function(value) {
a = boundAlpha(value);
roundA = mathRound(100*a) / 100;
},
toHsv: function() {
var hsv = rgbToHsv(r, g, b);
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: a };
},
toHsvString: function() {
var hsv = rgbToHsv(r, g, b);
var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
return (a == 1) ?
"hsv(" + h + ", " + s + "%, " + v + "%)" :
"hsva(" + h + ", " + s + "%, " + v + "%, "+ roundA + ")";
},
toHsl: function() {
var hsl = rgbToHsl(r, g, b);
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: a };
},
toHslString: function() {
var hsl = rgbToHsl(r, g, b);
var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
return (a == 1) ?
"hsl(" + h + ", " + s + "%, " + l + "%)" :
"hsla(" + h + ", " + s + "%, " + l + "%, "+ roundA + ")";
},
toHex: function(allow3Char) {
return rgbToHex(r, g, b, allow3Char);
},
toHexString: function(allow3Char) {
return '#' + this.toHex(allow3Char);
},
toHex8: function() {
return rgbaToHex(r, g, b, a);
},
toHex8String: function() {
return '#' + this.toHex8();
},
toRgb: function() {
return { r: mathRound(r), g: mathRound(g), b: mathRound(b), a: a };
},
toRgbString: function() {
return (a == 1) ?
"rgb(" + mathRound(r) + ", " + mathRound(g) + ", " + mathRound(b) + ")" :
"rgba(" + mathRound(r) + ", " + mathRound(g) + ", " + mathRound(b) + ", " + roundA + ")";
},
toPercentageRgb: function() {
return { r: mathRound(bound01(r, 255) * 100) + "%", g: mathRound(bound01(g, 255) * 100) + "%", b: mathRound(bound01(b, 255) * 100) + "%", a: a };
},
toPercentageRgbString: function() {
return (a == 1) ?
"rgb(" + mathRound(bound01(r, 255) * 100) + "%, " + mathRound(bound01(g, 255) * 100) + "%, " + mathRound(bound01(b, 255) * 100) + "%)" :
"rgba(" + mathRound(bound01(r, 255) * 100) + "%, " + mathRound(bound01(g, 255) * 100) + "%, " + mathRound(bound01(b, 255) * 100) + "%, " + roundA + ")";
},
toName: function() {
if (a === 0) {
return "transparent";
}
this._ok = rgb.ok;
this._tc_id = tinyCounter++;
};
return hexNames[rgbToHex(r, g, b, true)] || false;
},
toFilter: function(secondColor) {
var hex8String = '#' + rgbaToHex(r, g, b, a);
var secondHex8String = hex8String;
var gradientType = opts && opts.gradientType ? "GradientType = 1, " : "";
tinycolor.prototype = {
getAlpha: function() {
return this._a;
},
setAlpha: function(value) {
this._a = boundAlpha(value);
this._roundA = mathRound(100*this._a) / 100;
},
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() {
return rgbaToHex(this._r, this._g, this._b, this._a);
},
toHex8String: function() {
return '#' + this.toHex8();
},
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 (secondColor) {
var s = tinycolor(secondColor);
secondHex8String = s.toHex8String();
}
if (this._a < 1) {
return false;
}
return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
},
toString: function(format) {
var formatSet = !!format;
format = format || this.format;
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
},
toFilter: function(secondColor) {
var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a);
var secondHex8String = hex8String;
var gradientType = this._gradientType ? "GradientType = 1, " : "";
var formattedString = false;
var hasAlphaAndFormatNotSet = !formatSet && a < 1 && a > 0;
var formatWithAlpha = hasAlphaAndFormatNotSet && (format === "hex" || format === "hex6" || format === "hex3" || format === "name");
if (secondColor) {
var s = tinycolor(secondColor);
secondHex8String = s.toHex8String();
}
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 === "hex8") {
formattedString = this.toHex8String();
}
if (format === "name") {
formattedString = this.toName();
}
if (format === "hsl") {
formattedString = this.toHslString();
}
if (format === "hsv") {
formattedString = this.toHsvString();
}
return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
},
toString: function(format) {
var formatSet = !!format;
format = format || this._format;
if (formatWithAlpha) {
return this.toRgbString();
}
var formattedString = false;
var hasAlphaAndFormatNotSet = !formatSet && this._a < 1 && this._a > 0;
var formatWithAlpha = hasAlphaAndFormatNotSet && (format === "hex" || format === "hex6" || format === "hex3" || format === "name");
return formattedString || this.toHexString();
if (formatWithAlpha) {
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 === "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 input is an object, force 1 into "1.0" to handle ratios properly

@@ -958,3 +965,3 @@ // String input requires "1.0" as input, so 1 will be treated as 1

// AMD/requirejs: Define the module
else if (typeof define !== "undefined") {
else if (typeof define === 'function' && define.amd) {
define(function () {return tinycolor;});

@@ -961,0 +968,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc