Browse files

add gruntfile, fix jshint errors

  • Loading branch information...
1 parent 73f7554 commit 3b1604421111c0c9aaa83169b3c3f5360675c941 @bgrins committed Nov 28, 2012
Showing with 103 additions and 79 deletions.
  1. +1 −1 LICENSE
  2. +1 −1 component.json
  3. +46 −43 docs/tinycolor.html
  4. +22 −0 grunt.js
  5. +1 −1 package.json
  6. +21 −22 tinycolor-min.js
  7. +11 −11 tinycolor.js
View
2 LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2011, Brian Grinstead, http://briangrinstead.com
+Copyright (c) 2012, Brian Grinstead, http://briangrinstead.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
2 component.json
@@ -1,6 +1,6 @@
{
"name": "tinycolor",
- "version": "0.9.11",
+ "version": "0.9.12",
"main": ["./tinycolor.js"],
"dependencies": {
View
89 docs/tinycolor.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>tinycolor.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> tinycolor.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>TinyColor.js - <a href="https://github.com/bgrins/TinyColor">https://github.com/bgrins/TinyColor</a> - 2012 Brian Grinstead - v0.9.11</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">root</span><span class="p">)</span> <span class="p">{</span>
+<!DOCTYPE html> <html> <head> <title>tinycolor.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> tinycolor.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>TinyColor.js - <a href="https://github.com/bgrins/TinyColor">https://github.com/bgrins/TinyColor</a> - 2012 Brian Grinstead - v0.9.12</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">root</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">trimLeft</span> <span class="o">=</span> <span class="sr">/^[\s,#]+/</span><span class="p">,</span>
<span class="nx">trimRight</span> <span class="o">=</span> <span class="sr">/\s+$/</span><span class="p">,</span>
@@ -7,9 +7,11 @@
<span class="nx">mathRound</span> <span class="o">=</span> <span class="nx">math</span><span class="p">.</span><span class="nx">round</span><span class="p">,</span>
<span class="nx">mathMin</span> <span class="o">=</span> <span class="nx">math</span><span class="p">.</span><span class="nx">min</span><span class="p">,</span>
<span class="nx">mathMax</span> <span class="o">=</span> <span class="nx">math</span><span class="p">.</span><span class="nx">max</span><span class="p">,</span>
- <span class="nx">mathRandom</span> <span class="o">=</span> <span class="nx">math</span><span class="p">.</span><span class="nx">random</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>parseFloat redeclaration caused errors in Node</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">tinycolor</span> <span class="p">(</span><span class="nx">color</span><span class="p">,</span> <span class="nx">opts</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">mathRandom</span> <span class="o">=</span> <span class="nx">math</span><span class="p">.</span><span class="nx">random</span><span class="p">;</span>
- <span class="nx">color</span> <span class="o">=</span> <span class="p">(</span><span class="nx">color</span><span class="p">)</span> <span class="o">?</span> <span class="nx">color</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>If input is already a tinycolor, return itself</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">color</span> <span class="o">==</span> <span class="s2">&quot;object&quot;</span> <span class="o">&amp;&amp;</span> <span class="nx">color</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="s2">&quot;_tc_id&quot;</span><span class="p">))</span> <span class="p">{</span>
+<span class="kd">function</span> <span class="nx">tinycolor</span> <span class="p">(</span><span class="nx">color</span><span class="p">,</span> <span class="nx">opts</span><span class="p">)</span> <span class="p">{</span>
+
+ <span class="nx">color</span> <span class="o">=</span> <span class="p">(</span><span class="nx">color</span><span class="p">)</span> <span class="o">?</span> <span class="nx">color</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>If input is already a tinycolor, return itself</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">color</span> <span class="o">==</span> <span class="s2">&quot;object&quot;</span> <span class="o">&amp;&amp;</span> <span class="nx">color</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="s2">&quot;_tc_id&quot;</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">color</span><span class="p">;</span>
<span class="p">}</span>
@@ -19,7 +21,7 @@
<span class="nx">b</span> <span class="o">=</span> <span class="nx">rgb</span><span class="p">.</span><span class="nx">b</span><span class="p">,</span>
<span class="nx">a</span> <span class="o">=</span> <span class="nx">rgb</span><span class="p">.</span><span class="nx">a</span><span class="p">,</span>
<span class="nx">roundA</span> <span class="o">=</span> <span class="nx">mathRound</span><span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="nx">a</span><span class="p">)</span> <span class="o">/</span> <span class="mi">100</span><span class="p">,</span>
- <span class="nx">format</span> <span class="o">=</span> <span class="nx">rgb</span><span class="p">.</span><span class="nx">format</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Don't let the range of [0,255] come back in [0,1].
+ <span class="nx">format</span> <span class="o">=</span> <span class="nx">rgb</span><span class="p">.</span><span class="nx">format</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>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 <code>inputToRgb</code></p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">r</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span> <span class="nx">r</span> <span class="o">=</span> <span class="nx">mathRound</span><span class="p">(</span><span class="nx">r</span><span class="p">);</span> <span class="p">}</span>
@@ -79,8 +81,10 @@
<span class="k">return</span> <span class="nx">hexNames</span><span class="p">[</span><span class="nx">rgbToHex</span><span class="p">(</span><span class="nx">r</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">b</span><span class="p">)]</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">},</span>
<span class="nx">toFilter</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
- <span class="kd">var</span> <span class="nx">hex</span> <span class="o">=</span> <span class="nx">secondHex</span> <span class="o">=</span> <span class="nx">rgbToHex</span><span class="p">(</span><span class="nx">r</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">b</span><span class="p">);</span>
- <span class="kd">var</span> <span class="nx">alphaHex</span> <span class="o">=</span> <span class="nx">secondAlphaHex</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">round</span><span class="p">(</span><span class="nb">parseFloat</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="o">*</span> <span class="mi">255</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">hex</span> <span class="o">=</span> <span class="nx">rgbToHex</span><span class="p">(</span><span class="nx">r</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">b</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">secondHex</span> <span class="o">=</span> <span class="nx">hex</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">alphaHex</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">round</span><span class="p">(</span><span class="nb">parseFloat</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="o">*</span> <span class="mi">255</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">secondAlphaHex</span> <span class="o">=</span> <span class="nx">alphaHex</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">gradientType</span> <span class="o">=</span> <span class="nx">opts</span> <span class="o">&amp;&amp;</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">gradientType</span> <span class="o">?</span> <span class="s2">&quot;GradientType = 1, &quot;</span> <span class="o">:</span> <span class="s2">&quot;&quot;</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">secondColor</span><span class="p">)</span> <span class="p">{</span>
@@ -116,7 +120,7 @@
<span class="k">return</span> <span class="nx">formattedString</span> <span class="o">||</span> <span class="k">this</span><span class="p">.</span><span class="nx">toHexString</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">};</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>If input is an object, force 1 into "1.0" to handle ratios properly
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>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</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">tinycolor</span><span class="p">.</span><span class="nx">fromRatio</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">color</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">color</span> <span class="o">==</span> <span class="s2">&quot;object&quot;</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">newColor</span> <span class="o">=</span> <span class="p">{};</span>
@@ -127,7 +131,7 @@
<span class="p">}</span>
<span class="k">return</span> <span class="nx">tinycolor</span><span class="p">(</span><span class="nx">color</span><span class="p">);</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Given a string or object, convert that input to RGB
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Given a string or object, convert that input to RGB
Possible string inputs:</p>
<pre><code>"red"
@@ -167,7 +171,7 @@
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">color</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="s2">&quot;h&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">color</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="s2">&quot;s&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">color</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="s2">&quot;l&quot;</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">color</span><span class="p">.</span><span class="nx">s</span> <span class="o">=</span> <span class="nx">convertToPercentage</span><span class="p">(</span><span class="nx">color</span><span class="p">.</span><span class="nx">s</span><span class="p">);</span>
<span class="nx">color</span><span class="p">.</span><span class="nx">l</span> <span class="o">=</span> <span class="nx">convertToPercentage</span><span class="p">(</span><span class="nx">color</span><span class="p">.</span><span class="nx">l</span><span class="p">);</span>
- <span class="kd">var</span> <span class="nx">rgb</span> <span class="o">=</span> <span class="nx">hslToRgb</span><span class="p">(</span><span class="nx">color</span><span class="p">.</span><span class="nx">h</span><span class="p">,</span> <span class="nx">color</span><span class="p">.</span><span class="nx">s</span><span class="p">,</span> <span class="nx">color</span><span class="p">.</span><span class="nx">l</span><span class="p">);</span>
+ <span class="nx">rgb</span> <span class="o">=</span> <span class="nx">hslToRgb</span><span class="p">(</span><span class="nx">color</span><span class="p">.</span><span class="nx">h</span><span class="p">,</span> <span class="nx">color</span><span class="p">.</span><span class="nx">s</span><span class="p">,</span> <span class="nx">color</span><span class="p">.</span><span class="nx">l</span><span class="p">);</span>
<span class="nx">ok</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">format</span> <span class="o">=</span> <span class="s2">&quot;hsl&quot;</span><span class="p">;</span>
<span class="p">}</span>
@@ -177,7 +181,7 @@
<span class="p">}</span>
<span class="p">}</span>
- <span class="nx">a</span> <span class="o">=</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Handle invalid alpha characters by setting to 1</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="o">||</span> <span class="nx">a</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">a</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">a</span> <span class="o">=</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Handle invalid alpha characters by setting to 1</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="o">||</span> <span class="nx">a</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="o">||</span> <span class="nx">a</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">a</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
@@ -189,8 +193,8 @@
<span class="nx">b</span><span class="o">:</span> <span class="nx">mathMin</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="nx">mathMax</span><span class="p">(</span><span class="nx">rgb</span><span class="p">.</span><span class="nx">b</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span>
<span class="nx">a</span><span class="o">:</span> <span class="nx">a</span>
<span class="p">};</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h2>Conversion Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p><code>rgbToHsl</code>, <code>rgbToHsv</code>, <code>hslToRgb</code>, <code>hsvToRgb</code> modified from:
-<a href="http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript">http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript</a></p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p><code>rgbToRgb</code>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h2>Conversion Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p><code>rgbToHsl</code>, <code>rgbToHsv</code>, <code>hslToRgb</code>, <code>hsvToRgb</code> modified from:
+<a href="http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript">http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript</a></p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p><code>rgbToRgb</code>
Handle bounds / percentage checking to conform to CSS color spec
<a href="http://www.w3.org/TR/css3-color/">http://www.w3.org/TR/css3-color/</a>
<em>Assumes:</em> r, g, b in [0, 255] or [0, 1]
@@ -200,7 +204,7 @@
<span class="nx">g</span><span class="o">:</span> <span class="nx">bound01</span><span class="p">(</span><span class="nx">g</span><span class="p">,</span> <span class="mi">255</span><span class="p">)</span> <span class="o">*</span> <span class="mi">255</span><span class="p">,</span>
<span class="nx">b</span><span class="o">:</span> <span class="nx">bound01</span><span class="p">(</span><span class="nx">b</span><span class="p">,</span> <span class="mi">255</span><span class="p">)</span> <span class="o">*</span> <span class="mi">255</span>
<span class="p">};</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p><code>rgbToHsl</code>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p><code>rgbToHsl</code>
Converts an RGB color value to HSL.
<em>Assumes:</em> r, g, and b are contained in [0, 255] or [0, 1]
<em>Returns:</em> { h, s, l } in [0,1]</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">rgbToHsl</span><span class="p">(</span><span class="nx">r</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span>
@@ -228,7 +232,7 @@
<span class="p">}</span>
<span class="k">return</span> <span class="p">{</span> <span class="nx">h</span><span class="o">:</span> <span class="nx">h</span><span class="p">,</span> <span class="nx">s</span><span class="o">:</span> <span class="nx">s</span><span class="p">,</span> <span class="nx">l</span><span class="o">:</span> <span class="nx">l</span> <span class="p">};</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p><code>hslToRgb</code>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p><code>hslToRgb</code>
Converts an HSL color value to RGB.
<em>Assumes:</em> h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
<em>Returns:</em> { r, g, b } in the set [0, 255]</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">hslToRgb</span><span class="p">(</span><span class="nx">h</span><span class="p">,</span> <span class="nx">s</span><span class="p">,</span> <span class="nx">l</span><span class="p">)</span> <span class="p">{</span>
@@ -247,7 +251,7 @@
<span class="k">return</span> <span class="nx">p</span><span class="p">;</span>
<span class="p">}</span>
- <span class="k">if</span><span class="p">(</span><span class="nx">s</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span><span class="p">(</span><span class="nx">s</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">r</span> <span class="o">=</span> <span class="nx">g</span> <span class="o">=</span> <span class="nx">b</span> <span class="o">=</span> <span class="nx">l</span><span class="p">;</span> <span class="c1">// achromatic</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span>
@@ -259,7 +263,7 @@
<span class="p">}</span>
<span class="k">return</span> <span class="p">{</span> <span class="nx">r</span><span class="o">:</span> <span class="nx">r</span> <span class="o">*</span> <span class="mi">255</span><span class="p">,</span> <span class="nx">g</span><span class="o">:</span> <span class="nx">g</span> <span class="o">*</span> <span class="mi">255</span><span class="p">,</span> <span class="nx">b</span><span class="o">:</span> <span class="nx">b</span> <span class="o">*</span> <span class="mi">255</span> <span class="p">};</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p><code>rgbToHsv</code>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p><code>rgbToHsv</code>
Converts an RGB color value to HSV
<em>Assumes:</em> r, g, and b are contained in the set [0, 255] or [0, 1]
<em>Returns:</em> { h, s, v } in [0,1]</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">rgbToHsv</span><span class="p">(</span><span class="nx">r</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span>
@@ -272,7 +276,7 @@
<span class="kd">var</span> <span class="nx">h</span><span class="p">,</span> <span class="nx">s</span><span class="p">,</span> <span class="nx">v</span> <span class="o">=</span> <span class="nx">max</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">d</span> <span class="o">=</span> <span class="nx">max</span> <span class="o">-</span> <span class="nx">min</span><span class="p">;</span>
- <span class="nx">s</span> <span class="o">=</span> <span class="nx">max</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="nx">d</span> <span class="o">/</span> <span class="nx">max</span><span class="p">;</span>
+ <span class="nx">s</span> <span class="o">=</span> <span class="nx">max</span> <span class="o">===</span> <span class="mi">0</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="nx">d</span> <span class="o">/</span> <span class="nx">max</span><span class="p">;</span>
<span class="k">if</span><span class="p">(</span><span class="nx">max</span> <span class="o">==</span> <span class="nx">min</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">h</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="c1">// achromatic</span>
@@ -286,11 +290,10 @@
<span class="nx">h</span> <span class="o">/=</span> <span class="mi">6</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="p">{</span> <span class="nx">h</span><span class="o">:</span> <span class="nx">h</span><span class="p">,</span> <span class="nx">s</span><span class="o">:</span> <span class="nx">s</span><span class="p">,</span> <span class="nx">v</span><span class="o">:</span> <span class="nx">v</span> <span class="p">};</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p><code>hsvToRgb</code>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p><code>hsvToRgb</code>
Converts an HSV color value to RGB.
<em>Assumes:</em> h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
<em>Returns:</em> { r, g, b } in the set [0, 255]</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">hsvToRgb</span><span class="p">(</span><span class="nx">h</span><span class="p">,</span> <span class="nx">s</span><span class="p">,</span> <span class="nx">v</span><span class="p">)</span> <span class="p">{</span>
- <span class="kd">var</span> <span class="nx">r</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">b</span><span class="p">;</span>
<span class="nx">h</span> <span class="o">=</span> <span class="nx">bound01</span><span class="p">(</span><span class="nx">h</span><span class="p">,</span> <span class="mi">360</span><span class="p">)</span> <span class="o">*</span> <span class="mi">6</span><span class="p">;</span>
<span class="nx">s</span> <span class="o">=</span> <span class="nx">bound01</span><span class="p">(</span><span class="nx">s</span><span class="p">,</span> <span class="mi">100</span><span class="p">);</span>
@@ -307,20 +310,20 @@
<span class="nx">b</span> <span class="o">=</span> <span class="p">[</span><span class="nx">p</span><span class="p">,</span> <span class="nx">p</span><span class="p">,</span> <span class="nx">t</span><span class="p">,</span> <span class="nx">v</span><span class="p">,</span> <span class="nx">v</span><span class="p">,</span> <span class="nx">q</span><span class="p">][</span><span class="nx">mod</span><span class="p">];</span>
<span class="k">return</span> <span class="p">{</span> <span class="nx">r</span><span class="o">:</span> <span class="nx">r</span> <span class="o">*</span> <span class="mi">255</span><span class="p">,</span> <span class="nx">g</span><span class="o">:</span> <span class="nx">g</span> <span class="o">*</span> <span class="mi">255</span><span class="p">,</span> <span class="nx">b</span><span class="o">:</span> <span class="nx">b</span> <span class="o">*</span> <span class="mi">255</span> <span class="p">};</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p><code>rgbToHex</code>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p><code>rgbToHex</code>
Converts an RGB color to hex
Assumes r, g, and b are contained in the set [0, 255]
Returns a 3 or 6 character hex</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">rgbToHex</span><span class="p">(</span><span class="nx">r</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">hex</span> <span class="o">=</span> <span class="p">[</span>
<span class="nx">pad2</span><span class="p">(</span><span class="nx">mathRound</span><span class="p">(</span><span class="nx">r</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">)),</span>
<span class="nx">pad2</span><span class="p">(</span><span class="nx">mathRound</span><span class="p">(</span><span class="nx">g</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">)),</span>
<span class="nx">pad2</span><span class="p">(</span><span class="nx">mathRound</span><span class="p">(</span><span class="nx">b</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">))</span>
- <span class="p">];</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Return a 3 character hex if possible</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">hex</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="p">{</span>
+ <span class="p">];</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Return a 3 character hex if possible</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">hex</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="nx">hex</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">hex</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">);</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p><code>equals</code>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p><code>equals</code>
Can be called with any tinycolor input</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">tinycolor</span><span class="p">.</span><span class="nx">equals</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">color1</span><span class="p">,</span> <span class="nx">color2</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">color1</span> <span class="o">||</span> <span class="o">!</span><span class="nx">color2</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span> <span class="p">}</span>
<span class="k">return</span> <span class="nx">tinycolor</span><span class="p">(</span><span class="nx">color1</span><span class="p">).</span><span class="nx">toRgbString</span><span class="p">()</span> <span class="o">==</span> <span class="nx">tinycolor</span><span class="p">(</span><span class="nx">color2</span><span class="p">).</span><span class="nx">toRgbString</span><span class="p">();</span>
@@ -331,7 +334,7 @@
<span class="nx">g</span><span class="o">:</span> <span class="nx">mathRandom</span><span class="p">(),</span>
<span class="nx">b</span><span class="o">:</span> <span class="nx">mathRandom</span><span class="p">()</span>
<span class="p">});</span>
-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <h2>Modification Functions</h2>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <h2>Modification Functions</h2>
<p>Thanks to less.js for some of the basics here
<a href="https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js">https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js</a></p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">tinycolor</span><span class="p">.</span><span class="nx">desaturate</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">color</span><span class="p">,</span> <span class="nx">amount</span><span class="p">)</span> <span class="p">{</span>
@@ -365,7 +368,7 @@
<span class="kd">var</span> <span class="nx">hsl</span> <span class="o">=</span> <span class="nx">tinycolor</span><span class="p">(</span><span class="nx">color</span><span class="p">).</span><span class="nx">toHsl</span><span class="p">();</span>
<span class="nx">hsl</span><span class="p">.</span><span class="nx">h</span> <span class="o">=</span> <span class="p">(</span><span class="nx">hsl</span><span class="p">.</span><span class="nx">h</span> <span class="o">+</span> <span class="mi">180</span><span class="p">)</span> <span class="o">%</span> <span class="mi">360</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">tinycolor</span><span class="p">(</span><span class="nx">hsl</span><span class="p">);</span>
-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <h2>Combination Functions</h2>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <h2>Combination Functions</h2>
<p>Thanks to jQuery xColor for some of the ideas behind these
<a href="https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js">https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js</a></p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">tinycolor</span><span class="p">.</span><span class="nx">triad</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">color</span><span class="p">)</span> <span class="p">{</span>
@@ -401,7 +404,7 @@
<span class="nx">slices</span> <span class="o">=</span> <span class="nx">slices</span> <span class="o">||</span> <span class="mi">30</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">hsl</span> <span class="o">=</span> <span class="nx">tinycolor</span><span class="p">(</span><span class="nx">color</span><span class="p">).</span><span class="nx">toHsl</span><span class="p">();</span>
- <span class="kd">var</span> <span class="nx">part</span> <span class="o">=</span> <span class="mi">360</span> <span class="o">/</span> <span class="nx">slices</span>
+ <span class="kd">var</span> <span class="nx">part</span> <span class="o">=</span> <span class="mi">360</span> <span class="o">/</span> <span class="nx">slices</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="p">[</span><span class="nx">tinycolor</span><span class="p">(</span><span class="nx">color</span><span class="p">)];</span>
<span class="k">for</span> <span class="p">(</span><span class="nx">hsl</span><span class="p">.</span><span class="nx">h</span> <span class="o">=</span> <span class="p">((</span><span class="nx">hsl</span><span class="p">.</span><span class="nx">h</span> <span class="o">-</span> <span class="p">(</span><span class="nx">part</span> <span class="o">*</span> <span class="nx">results</span> <span class="o">&gt;&gt;</span> <span class="mi">1</span><span class="p">))</span> <span class="o">+</span> <span class="mi">720</span><span class="p">)</span> <span class="o">%</span> <span class="mi">360</span><span class="p">;</span> <span class="o">--</span><span class="nx">results</span><span class="p">;</span> <span class="p">)</span> <span class="p">{</span>
@@ -431,7 +434,7 @@
<span class="p">(</span><span class="nx">b</span><span class="p">.</span><span class="nx">g</span> <span class="o">-</span> <span class="nx">a</span><span class="p">.</span><span class="nx">g</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="nx">b</span><span class="p">.</span><span class="nx">g</span> <span class="o">-</span> <span class="nx">a</span><span class="p">.</span><span class="nx">g</span><span class="p">)</span> <span class="o">+</span>
<span class="p">(</span><span class="nx">b</span><span class="p">.</span><span class="nx">b</span> <span class="o">-</span> <span class="nx">a</span><span class="p">.</span><span class="nx">b</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="nx">b</span><span class="p">.</span><span class="nx">b</span> <span class="o">-</span> <span class="nx">a</span><span class="p">.</span><span class="nx">b</span><span class="p">)</span>
<span class="p">)</span> <span class="o">&gt;</span> <span class="mh">0x28A4</span><span class="p">;</span>
-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <h2>Big List of Colors</h2>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <h2>Big List of Colors</h2>
<p><a href="http://www.w3.org/TR/css3-color/#svg-color">http://www.w3.org/TR/css3-color/#svg-color</a></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">names</span> <span class="o">=</span> <span class="nx">tinycolor</span><span class="p">.</span><span class="nx">names</span> <span class="o">=</span> <span class="p">{</span>
<span class="nx">aliceblue</span><span class="o">:</span> <span class="s2">&quot;f0f8ff&quot;</span><span class="p">,</span>
@@ -582,43 +585,43 @@
<span class="nx">whitesmoke</span><span class="o">:</span> <span class="s2">&quot;f5f5f5&quot;</span><span class="p">,</span>
<span class="nx">yellow</span><span class="o">:</span> <span class="s2">&quot;ff0&quot;</span><span class="p">,</span>
<span class="nx">yellowgreen</span><span class="o">:</span> <span class="s2">&quot;9acd32&quot;</span>
-<span class="p">};</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Make it easy to access colors via <code>hexNames[hex]</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">hexNames</span> <span class="o">=</span> <span class="nx">tinycolor</span><span class="p">.</span><span class="nx">hexNames</span> <span class="o">=</span> <span class="nx">flip</span><span class="p">(</span><span class="nx">names</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <h2>Utilities</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p><code>{ 'name1': 'val1' }</code> becomes <code>{ 'val1': 'name1' }</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">flip</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">};</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Make it easy to access colors via <code>hexNames[hex]</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">hexNames</span> <span class="o">=</span> <span class="nx">tinycolor</span><span class="p">.</span><span class="nx">hexNames</span> <span class="o">=</span> <span class="nx">flip</span><span class="p">(</span><span class="nx">names</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <h2>Utilities</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p><code>{ 'name1': 'val1' }</code> becomes <code>{ 'val1': 'name1' }</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">flip</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">flipped</span> <span class="o">=</span> <span class="p">{</span> <span class="p">};</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">i</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">flipped</span><span class="p">[</span><span class="nx">o</span><span class="p">[</span><span class="nx">i</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">flipped</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>Take input from [0, n] and return it as [0, 1]</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">bound01</span><span class="p">(</span><span class="nx">n</span><span class="p">,</span> <span class="nx">max</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Take input from [0, n] and return it as [0, 1]</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">bound01</span><span class="p">(</span><span class="nx">n</span><span class="p">,</span> <span class="nx">max</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">isOnePointZero</span><span class="p">(</span><span class="nx">n</span><span class="p">))</span> <span class="p">{</span> <span class="nx">n</span> <span class="o">=</span> <span class="s2">&quot;100%&quot;</span><span class="p">;</span> <span class="p">}</span>
<span class="kd">var</span> <span class="nx">processPercent</span> <span class="o">=</span> <span class="nx">isPercentage</span><span class="p">(</span><span class="nx">n</span><span class="p">);</span>
- <span class="nx">n</span> <span class="o">=</span> <span class="nx">mathMin</span><span class="p">(</span><span class="nx">max</span><span class="p">,</span> <span class="nx">mathMax</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">n</span><span class="p">)));</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Automatically convert percentage into number</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">processPercent</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">n</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">n</span> <span class="o">*</span> <span class="nx">max</span><span class="p">)</span> <span class="o">/</span> <span class="mi">100</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Handle floating point rounding errors</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">((</span><span class="nx">math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span><span class="nx">n</span> <span class="o">-</span> <span class="nx">max</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">0.000001</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">n</span> <span class="o">=</span> <span class="nx">mathMin</span><span class="p">(</span><span class="nx">max</span><span class="p">,</span> <span class="nx">mathMax</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">n</span><span class="p">)));</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>Automatically convert percentage into number</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">processPercent</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">n</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">n</span> <span class="o">*</span> <span class="nx">max</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <span class="o">/</span> <span class="mi">100</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Handle floating point rounding errors</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">((</span><span class="nx">math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span><span class="nx">n</span> <span class="o">-</span> <span class="nx">max</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">0.000001</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Convert into [0, 1] range if it isn't already</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="p">(</span><span class="nx">n</span> <span class="o">%</span> <span class="nx">max</span><span class="p">)</span> <span class="o">/</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">max</span><span class="p">);</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Force a number between 0 and 1</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">clamp01</span><span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Convert into [0, 1] range if it isn't already</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="p">(</span><span class="nx">n</span> <span class="o">%</span> <span class="nx">max</span><span class="p">)</span> <span class="o">/</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">max</span><span class="p">);</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Force a number between 0 and 1</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">clamp01</span><span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">mathMin</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nx">mathMax</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">val</span><span class="p">));</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Parse an integer into hex</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">parseHex</span><span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Parse an integer into hex</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">parseHex</span><span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">val</span><span class="p">,</span> <span class="mi">16</span><span class="p">);</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
<a href="http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0">http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0</a></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">isOnePointZero</span><span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">typeof</span> <span class="nx">n</span> <span class="o">==</span> <span class="s2">&quot;string&quot;</span> <span class="o">&amp;&amp;</span> <span class="nx">n</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span> <span class="o">&amp;&amp;</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="o">===</span> <span class="mi">1</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Check to see if string passed in is a percentage</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">isPercentage</span><span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Check to see if string passed in is a percentage</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">isPercentage</span><span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">typeof</span> <span class="nx">n</span> <span class="o">===</span> <span class="s2">&quot;string&quot;</span> <span class="o">&amp;&amp;</span> <span class="nx">n</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39;%&#39;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>Force a hex value to have 2 characters</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">pad2</span><span class="p">(</span><span class="nx">c</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Force a hex value to have 2 characters</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">pad2</span><span class="p">(</span><span class="nx">c</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">c</span><span class="p">.</span><span class="nx">length</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">?</span> <span class="s1">&#39;0&#39;</span> <span class="o">+</span> <span class="nx">c</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span> <span class="o">+</span> <span class="nx">c</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div> <p>Replace a decimal with it's percentage value</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">convertToPercentage</span><span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>Replace a decimal with it's percentage value</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">convertToPercentage</span><span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">n</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">n</span> <span class="o">=</span> <span class="p">(</span><span class="nx">n</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;%&quot;</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">n</span><span class="p">;</span>
<span class="p">}</span>
-<span class="kd">var</span> <span class="nx">matchers</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p><a href="http://www.w3.org/TR/css3-values/#integers">http://www.w3.org/TR/css3-values/#integers</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">CSS_INTEGER</span> <span class="o">=</span> <span class="s2">&quot;[-\\+]?\\d+%?&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <p><a href="http://www.w3.org/TR/css3-values/#number-value">http://www.w3.org/TR/css3-values/#number-value</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">CSS_NUMBER</span> <span class="o">=</span> <span class="s2">&quot;[-\\+]?\\d*\\.\\d+%?&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-36">&#182;</a> </div> <p>Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">CSS_UNIT</span> <span class="o">=</span> <span class="s2">&quot;(?:&quot;</span> <span class="o">+</span> <span class="nx">CSS_NUMBER</span> <span class="o">+</span> <span class="s2">&quot;)|(?:&quot;</span> <span class="o">+</span> <span class="nx">CSS_INTEGER</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-37">&#182;</a> </div> <p>Actual matching.
+<span class="kd">var</span> <span class="nx">matchers</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div> <p><a href="http://www.w3.org/TR/css3-values/#integers">http://www.w3.org/TR/css3-values/#integers</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">CSS_INTEGER</span> <span class="o">=</span> <span class="s2">&quot;[-\\+]?\\d+%?&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p><a href="http://www.w3.org/TR/css3-values/#number-value">http://www.w3.org/TR/css3-values/#number-value</a></p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">CSS_NUMBER</span> <span class="o">=</span> <span class="s2">&quot;[-\\+]?\\d*\\.\\d+%?&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <p>Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">CSS_UNIT</span> <span class="o">=</span> <span class="s2">&quot;(?:&quot;</span> <span class="o">+</span> <span class="nx">CSS_NUMBER</span> <span class="o">+</span> <span class="s2">&quot;)|(?:&quot;</span> <span class="o">+</span> <span class="nx">CSS_INTEGER</span> <span class="o">+</span> <span class="s2">&quot;)&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-36">&#182;</a> </div> <p>Actual matching.
Parentheses and commas are optional, but not required.
Whitespace can take the place of commas or opening paren</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">PERMISSIVE_MATCH3</span> <span class="o">=</span> <span class="s2">&quot;[\\s|\\(]+(&quot;</span> <span class="o">+</span> <span class="nx">CSS_UNIT</span> <span class="o">+</span> <span class="s2">&quot;)[,|\\s]+(&quot;</span> <span class="o">+</span> <span class="nx">CSS_UNIT</span> <span class="o">+</span> <span class="s2">&quot;)[,|\\s]+(&quot;</span> <span class="o">+</span> <span class="nx">CSS_UNIT</span> <span class="o">+</span> <span class="s2">&quot;)\\s*\\)?&quot;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">PERMISSIVE_MATCH4</span> <span class="o">=</span> <span class="s2">&quot;[\\s|\\(]+(&quot;</span> <span class="o">+</span> <span class="nx">CSS_UNIT</span> <span class="o">+</span> <span class="s2">&quot;)[,|\\s]+(&quot;</span> <span class="o">+</span> <span class="nx">CSS_UNIT</span> <span class="o">+</span> <span class="s2">&quot;)[,|\\s]+(&quot;</span> <span class="o">+</span> <span class="nx">CSS_UNIT</span> <span class="o">+</span> <span class="s2">&quot;)[,|\\s]+(&quot;</span> <span class="o">+</span> <span class="nx">CSS_UNIT</span> <span class="o">+</span> <span class="s2">&quot;)\\s*\\)?&quot;</span><span class="p">;</span>
@@ -632,7 +635,7 @@
<span class="nx">hex3</span><span class="o">:</span> <span class="sr">/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/</span><span class="p">,</span>
<span class="nx">hex6</span><span class="o">:</span> <span class="sr">/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/</span>
<span class="p">};</span>
-<span class="p">})();</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">&#182;</a> </div> <p><code>stringInputToObject</code>
+<span class="p">})();</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-37">&#182;</a> </div> <p><code>stringInputToObject</code>
Permissive string parsing. Take in a number of formats, and output an object
based on detected format. Returns <code>{ r, g, b }</code> or <code>{ h, s, l }</code> or <code>{ h, s, v}</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">stringInputToObject</span><span class="p">(</span><span class="nx">color</span><span class="p">)</span> <span class="p">{</span>
@@ -644,7 +647,7 @@
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">color</span> <span class="o">==</span> <span class="s1">&#39;transparent&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">{</span> <span class="nx">r</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">g</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">b</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">a</span><span class="o">:</span> <span class="mi">0</span> <span class="p">};</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-39">&#182;</a> </div> <p>Try to match string input using regular expressions.
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">&#182;</a> </div> <p>Try to match string input using regular expressions.
Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
Just return an object and let the conversion functions handle that.
This way the result will be the same whether the tinycolor is initialized with string or object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">match</span><span class="p">;</span>
@@ -681,9 +684,9 @@
<span class="p">}</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Node: Export function</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">module</span> <span class="o">!==</span> <span class="s2">&quot;undefined&quot;</span> <span class="o">&amp;&amp;</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-39">&#182;</a> </div> <p>Node: Export function</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">module</span> <span class="o">!==</span> <span class="s2">&quot;undefined&quot;</span> <span class="o">&amp;&amp;</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">tinycolor</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>Browser: Expose to window</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">else</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Browser: Expose to window</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">else</span> <span class="p">{</span>
<span class="nx">root</span><span class="p">.</span><span class="nx">tinycolor</span> <span class="o">=</span> <span class="nx">tinycolor</span><span class="p">;</span>
<span class="p">}</span>
View
22 grunt.js
@@ -0,0 +1,22 @@
+
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+ lint: {
+ all: ['tinycolor.js']
+ },
+
+ jshint: {
+ options: {
+ browser: true,
+ sub: true
+ },
+ globals: {
+ jQuery: true
+ }
+ }
+ });
+
+ grunt.registerTask('default', 'lint');
+
+};
View
2 package.json
@@ -1,5 +1,5 @@
{
- "version": "0.9.11",
+ "version": "0.9.12",
"name" : "tinycolor2",
"description" : "Fast Color Parsing and Manipulation",
"url" : "http://bgrins.github.com/TinyColor",
View
43 tinycolor-min.js
@@ -1,22 +1,21 @@
-// TinyColor.js - <https://github.com/bgrins/TinyColor> - 2012 Brian Grinstead - v0.9.11
-(function(C){var t,u,v,w,x,y,z;function d(a,c){a=a?a:"";if("object"==typeof a&&a.hasOwnProperty("_tc_id"))return a;var b=D(a),h=b.r,j=b.g,g=b.b,f=b.a,k=e(100*f)/100,E=b.format;1>h&&(h=e(h));1>j&&(j=e(j));1>g&&(g=e(g));return{ok:b.ok,format:E,_tc_id:F++,alpha:f,toHsv:function(){var a=A(h,j,g);return{h:360*a.h,s:a.s,v:a.v,a:f}},toHsvString:function(){var a=A(h,j,g),b=e(360*a.h),c=e(100*a.s),a=e(100*a.v);return 1==f?"hsv("+b+", "+c+"%, "+a+"%)":"hsva("+b+", "+c+"%, "+a+"%, "+k+")"},toHsl:function(){var a=
-B(h,j,g);return{h:360*a.h,s:a.s,l:a.l,a:f}},toHslString:function(){var a=B(h,j,g),b=e(360*a.h),c=e(100*a.s),a=e(100*a.l);return 1==f?"hsl("+b+", "+c+"%, "+a+"%)":"hsla("+b+", "+c+"%, "+a+"%, "+k+")"},toHex:function(){return q(h,j,g)},toHexString:function(){return"#"+q(h,j,g)},toRgb:function(){return{r:e(h),g:e(j),b:e(g),a:f}},toRgbString:function(){return 1==f?"rgb("+e(h)+", "+e(j)+", "+e(g)+")":"rgba("+e(h)+", "+e(j)+", "+e(g)+", "+k+")"},toPercentageRgb:function(){return{r:e(100*i(h,255))+"%",g:e(100*
-i(j,255))+"%",b:e(100*i(g,255))+"%",a:f}},toPercentageRgbString:function(){return 1==f?"rgb("+e(100*i(h,255))+"%, "+e(100*i(j,255))+"%, "+e(100*i(g,255))+"%)":"rgba("+e(100*i(h,255))+"%, "+e(100*i(j,255))+"%, "+e(100*i(g,255))+"%, "+k+")"},toName:function(){return G[q(h,j,g)]||!1},toFilter:function(){var a=secondHex=q(h,j,g),b=secondAlphaHex=Math.round(255*parseFloat(f)).toString(16),e=c&&c.gradientType?"GradientType = 1, ":"";if(secondColor){var i=d(secondColor);secondHex=i.toHex();secondAlphaHex=
-Math.round(255*parseFloat(i.alpha)).toString(16)}return"progid:DXImageTransform.Microsoft.gradient("+e+"startColorstr=#"+o(b)+a+",endColorstr=#"+o(secondAlphaHex)+secondHex+")"},toString:function(a){var a=a||this.format,b=!1;"rgb"===a&&(b=this.toRgbString());"prgb"===a&&(b=this.toPercentageRgbString());"hex"===a&&(b=this.toHexString());"name"===a&&(b=this.toName());"hsl"===a&&(b=this.toHslString());"hsv"===a&&(b=this.toHsvString());return b||this.toHexString()}}}function D(a){var c={r:255,g:255,b:255},
-b=1,h=!1,d=!1;if("string"==typeof a)a:{var a=a.replace(H,"").replace(I,"").toLowerCase(),g=!1;if(r[a])a=r[a],g=!0;else if("transparent"==a){a={r:0,g:0,b:0,a:0};break a}var f,a=(f=t.exec(a))?{r:f[1],g:f[2],b:f[3]}:(f=u.exec(a))?{r:f[1],g:f[2],b:f[3],a:f[4]}:(f=v.exec(a))?{h:f[1],s:f[2],l:f[3]}:(f=w.exec(a))?{h:f[1],s:f[2],l:f[3],a:f[4]}:(f=x.exec(a))?{h:f[1],s:f[2],v:f[3]}:(f=y.exec(a))?{r:parseInt(f[1],16),g:parseInt(f[2],16),b:parseInt(f[3],16),format:g?"name":"hex"}:(f=z.exec(a))?{r:parseInt(f[1]+
-""+f[1],16),g:parseInt(f[2]+""+f[2],16),b:parseInt(f[3]+""+f[3],16),format:g?"name":"hex"}:!1}if("object"==typeof a){if(a.hasOwnProperty("r")&&a.hasOwnProperty("g")&&a.hasOwnProperty("b"))c={r:255*i(a.r,255),g:255*i(a.g,255),b:255*i(a.b,255)},h=!0,d="%"===(""+a.r).substr(-1)?"prgb":"rgb";else if(a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("v")){a.s=p(a.s);a.v=p(a.v);var d=a.h,g=a.s,c=a.v,d=6*i(d,360),g=i(g,100),c=i(c,100),h=n.floor(d),e=d-h,d=c*(1-g);f=c*(1-e*g);g=c*(1-(1-e)*g);
-h%=6;c={r:255*[c,f,d,d,g,c][h],g:255*[g,c,c,f,d,d][h],b:255*[d,d,g,c,c,f][h]};h=!0;d="hsv"}else a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("l")&&(a.s=p(a.s),a.l=p(a.l),c=J(a.h,a.s,a.l),h=!0,d="hsl");a.hasOwnProperty("a")&&(b=a.a)}b=parseFloat(b);if(isNaN(b)||0>b||1<b)b=1;return{ok:h,format:a.format||d,r:l(255,m(c.r,0)),g:l(255,m(c.g,0)),b:l(255,m(c.b,0)),a:b}}function B(a,c,b){var a=i(a,255),c=i(c,255),b=i(b,255),d=m(a,c,b),e=l(a,c,b),g,f=(d+e)/2;if(d==e)g=e=0;else{var k=d-e,e=
-0.5<f?k/(2-d-e):k/(d+e);switch(d){case a:g=(c-b)/k+(c<b?6:0);break;case c:g=(b-a)/k+2;break;case b:g=(a-c)/k+4}g/=6}return{h:g,s:e,l:f}}function J(a,c,b){function d(a,b,c){0>c&&(c+=1);1<c&&(c-=1);return c<1/6?a+6*(b-a)*c:0.5>c?b:c<2/3?a+6*(b-a)*(2/3-c):a}a=i(a,360);c=i(c,100);b=i(b,100);if(0==c)b=c=a=b;else var e=0.5>b?b*(1+c):b+c-b*c,g=2*b-e,b=d(g,e,a+1/3),c=d(g,e,a),a=d(g,e,a-1/3);return{r:255*b,g:255*c,b:255*a}}function A(a,c,b){var a=i(a,255),c=i(c,255),b=i(b,255),d=m(a,c,b),e=l(a,c,b),g,f=d-
-e;if(d==e)g=0;else{switch(d){case a:g=(c-b)/f+(c<b?6:0);break;case c:g=(b-a)/f+2;break;case b:g=(a-c)/f+4}g/=6}return{h:g,s:0==d?0:f/d,v:d}}function q(a,c,b){a=[o(e(a).toString(16)),o(e(c).toString(16)),o(e(b).toString(16))];return a[0][0]==a[0][1]&&a[1][0]==a[1][1]&&a[2][0]==a[2][1]?a[0][0]+a[1][0]+a[2][0]:a.join("")}function i(a,c){"string"==typeof a&&-1!=a.indexOf(".")&&1===parseFloat(a)&&(a="100%");var b="string"===typeof a&&-1!=a.indexOf("%"),a=l(c,m(0,parseFloat(a)));b&&(a=parseInt(a*c)/100);
-return 1.0E-6>n.abs(a-c)?1:a%c/parseFloat(c)}function o(a){return 1==a.length?"0"+a:""+a}function p(a){1>=a&&(a=100*a+"%");return a}var H=/^[\s,#]+/,I=/\s+$/,F=0,n=Math,e=n.round,l=n.min,m=n.max,s=n.random;d.fromRatio=function(a){if("object"==typeof a){var c={},b;for(b in a)c[b]=p(a[b]);a=c}return d(a)};d.equals=function(a,c){return!a||!c?!1:d(a).toRgbString()==d(c).toRgbString()};d.random=function(){return d.fromRatio({r:s(),g:s(),b:s()})};d.desaturate=function(a,c){var b=d(a).toHsl();b.s-=(c||10)/
-100;b.s=l(1,m(0,b.s));return d(b)};d.saturate=function(a,c){var b=d(a).toHsl();b.s+=(c||10)/100;b.s=l(1,m(0,b.s));return d(b)};d.greyscale=function(a){return d.desaturate(a,100)};d.lighten=function(a,c){var b=d(a).toHsl();b.l+=(c||10)/100;b.l=l(1,m(0,b.l));return d(b)};d.darken=function(a,c){var b=d(a).toHsl();b.l-=(c||10)/100;b.l=l(1,m(0,b.l));return d(b)};d.complement=function(a){a=d(a).toHsl();a.h=(a.h+180)%360;return d(a)};d.triad=function(a){var c=d(a).toHsl(),b=c.h;return[d(a),d({h:(b+120)%
-360,s:c.s,l:c.l}),d({h:(b+240)%360,s:c.s,l:c.l})]};d.tetrad=function(a){var c=d(a).toHsl(),b=c.h;return[d(a),d({h:(b+90)%360,s:c.s,l:c.l}),d({h:(b+180)%360,s:c.s,l:c.l}),d({h:(b+270)%360,s:c.s,l:c.l})]};d.splitcomplement=function(a){var c=d(a).toHsl(),b=c.h;return[d(a),d({h:(b+72)%360,s:c.s,l:c.l}),d({h:(b+216)%360,s:c.s,l:c.l})]};d.analogous=function(a,c,b){var c=c||6,b=b||30,e=d(a).toHsl(),b=360/b,a=[d(a)];for(e.h=(e.h-(b*c>>1)+720)%360;--c;)e.h=(e.h+b)%360,a.push(d(e));return a};d.monochromatic=
-function(a,c){for(var c=c||6,b=d(a).toHsv(),e=b.h,i=b.s,b=b.v,g=[],f=1/c;c--;)g.push(d({h:e,s:i,v:b})),b=(b+f)%1;return g};d.readable=function(a,c){var b=d(a).toRgb(),e=d(c).toRgb();return 10404<(e.r-b.r)*(e.r-b.r)+(e.g-b.g)*(e.g-b.g)+(e.b-b.b)*(e.b-b.b)};var r=d.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",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"},G=d.hexNames=
-function(a){var c={},b;for(b in a)a.hasOwnProperty(b)&&(c[a[b]]=b);return c}(r);t=RegExp("rgb[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");u=RegExp("rgba[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");v=RegExp("hsl[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");
-w=RegExp("hsla[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");x=RegExp("hsv[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");z=/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;y=/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;
-"undefined"!==typeof module&&module.exports?module.exports=d:C.tinycolor=d})(this);
+// TinyColor.js - <https://github.com/bgrins/TinyColor> - 2012 Brian Grinstead - v0.9.12
+(function(C){var t,u,v,w,x,y,z;function d(a,c){a=a?a:"";if("object"==typeof a&&a.hasOwnProperty("_tc_id"))return a;var b=D(a),i=b.r,j=b.g,g=b.b,f=b.a,k=e(100*f)/100,E=b.format;1>i&&(i=e(i));1>j&&(j=e(j));1>g&&(g=e(g));return{ok:b.ok,format:E,_tc_id:F++,alpha:f,toHsv:function(){var a=A(i,j,g);return{h:360*a.h,s:a.s,v:a.v,a:f}},toHsvString:function(){var a=A(i,j,g),b=e(360*a.h),c=e(100*a.s),a=e(100*a.v);return 1==f?"hsv("+b+", "+c+"%, "+a+"%)":"hsva("+b+", "+c+"%, "+a+"%, "+k+")"},toHsl:function(){var a=
+B(i,j,g);return{h:360*a.h,s:a.s,l:a.l,a:f}},toHslString:function(){var a=B(i,j,g),b=e(360*a.h),c=e(100*a.s),a=e(100*a.l);return 1==f?"hsl("+b+", "+c+"%, "+a+"%)":"hsla("+b+", "+c+"%, "+a+"%, "+k+")"},toHex:function(){return q(i,j,g)},toHexString:function(){return"#"+q(i,j,g)},toRgb:function(){return{r:e(i),g:e(j),b:e(g),a:f}},toRgbString:function(){return 1==f?"rgb("+e(i)+", "+e(j)+", "+e(g)+")":"rgba("+e(i)+", "+e(j)+", "+e(g)+", "+k+")"},toPercentageRgb:function(){return{r:e(100*h(i,255))+"%",g:e(100*
+h(j,255))+"%",b:e(100*h(g,255))+"%",a:f}},toPercentageRgbString:function(){return 1==f?"rgb("+e(100*h(i,255))+"%, "+e(100*h(j,255))+"%, "+e(100*h(g,255))+"%)":"rgba("+e(100*h(i,255))+"%, "+e(100*h(j,255))+"%, "+e(100*h(g,255))+"%, "+k+")"},toName:function(){return G[q(i,j,g)]||!1},toFilter:function(){var a=q(i,j,g),b=a,e=Math.round(255*parseFloat(f)).toString(16),h=e,k=c&&c.gradientType?"GradientType = 1, ":"";secondColor&&(h=d(secondColor),b=h.toHex(),h=Math.round(255*parseFloat(h.alpha)).toString(16));
+return"progid:DXImageTransform.Microsoft.gradient("+k+"startColorstr=#"+o(e)+a+",endColorstr=#"+o(h)+b+")"},toString:function(a){var a=a||this.format,b=!1;"rgb"===a&&(b=this.toRgbString());"prgb"===a&&(b=this.toPercentageRgbString());"hex"===a&&(b=this.toHexString());"name"===a&&(b=this.toName());"hsl"===a&&(b=this.toHslString());"hsv"===a&&(b=this.toHsvString());return b||this.toHexString()}}}function D(a){var c={r:255,g:255,b:255},b=1,i=!1,d=!1;if("string"==typeof a)a:{var a=a.replace(H,"").replace(I,
+"").toLowerCase(),g=!1;if(r[a])a=r[a],g=!0;else if("transparent"==a){a={r:0,g:0,b:0,a:0};break a}var f,a=(f=t.exec(a))?{r:f[1],g:f[2],b:f[3]}:(f=u.exec(a))?{r:f[1],g:f[2],b:f[3],a:f[4]}:(f=v.exec(a))?{h:f[1],s:f[2],l:f[3]}:(f=w.exec(a))?{h:f[1],s:f[2],l:f[3],a:f[4]}:(f=x.exec(a))?{h:f[1],s:f[2],v:f[3]}:(f=y.exec(a))?{r:parseInt(f[1],16),g:parseInt(f[2],16),b:parseInt(f[3],16),format:g?"name":"hex"}:(f=z.exec(a))?{r:parseInt(f[1]+""+f[1],16),g:parseInt(f[2]+""+f[2],16),b:parseInt(f[3]+""+f[3],16),
+format:g?"name":"hex"}:!1}if("object"==typeof a){if(a.hasOwnProperty("r")&&a.hasOwnProperty("g")&&a.hasOwnProperty("b"))c={r:255*h(a.r,255),g:255*h(a.g,255),b:255*h(a.b,255)},i=!0,d="%"===(""+a.r).substr(-1)?"prgb":"rgb";else if(a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("v")){a.s=p(a.s);a.v=p(a.v);var d=a.h,g=a.s,c=a.v,d=6*h(d,360),g=h(g,100),c=h(c,100),i=n.floor(d),e=d-i,d=c*(1-g);f=c*(1-e*g);g=c*(1-(1-e)*g);i%=6;c={r:255*[c,f,d,d,g,c][i],g:255*[g,c,c,f,d,d][i],b:255*[d,d,g,
+c,c,f][i]};i=!0;d="hsv"}else a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("l")&&(a.s=p(a.s),a.l=p(a.l),c=J(a.h,a.s,a.l),i=!0,d="hsl");a.hasOwnProperty("a")&&(b=a.a)}b=parseFloat(b);if(isNaN(b)||0>b||1<b)b=1;return{ok:i,format:a.format||d,r:l(255,m(c.r,0)),g:l(255,m(c.g,0)),b:l(255,m(c.b,0)),a:b}}function B(a,c,b){var a=h(a,255),c=h(c,255),b=h(b,255),d=m(a,c,b),e=l(a,c,b),g,f=(d+e)/2;if(d==e)g=e=0;else{var k=d-e,e=0.5<f?k/(2-d-e):k/(d+e);switch(d){case a:g=(c-b)/k+(c<b?6:0);break;
+case c:g=(b-a)/k+2;break;case b:g=(a-c)/k+4}g/=6}return{h:g,s:e,l:f}}function J(a,c,b){function d(a,b,c){0>c&&(c+=1);1<c&&(c-=1);return c<1/6?a+6*(b-a)*c:0.5>c?b:c<2/3?a+6*(b-a)*(2/3-c):a}a=h(a,360);c=h(c,100);b=h(b,100);if(0===c)b=c=a=b;else var e=0.5>b?b*(1+c):b+c-b*c,g=2*b-e,b=d(g,e,a+1/3),c=d(g,e,a),a=d(g,e,a-1/3);return{r:255*b,g:255*c,b:255*a}}function A(a,c,b){var a=h(a,255),c=h(c,255),b=h(b,255),d=m(a,c,b),e=l(a,c,b),g,f=d-e;if(d==e)g=0;else{switch(d){case a:g=(c-b)/f+(c<b?6:0);break;case c:g=
+(b-a)/f+2;break;case b:g=(a-c)/f+4}g/=6}return{h:g,s:0===d?0:f/d,v:d}}function q(a,c,b){a=[o(e(a).toString(16)),o(e(c).toString(16)),o(e(b).toString(16))];return a[0][0]==a[0][1]&&a[1][0]==a[1][1]&&a[2][0]==a[2][1]?a[0][0]+a[1][0]+a[2][0]:a.join("")}function h(a,c){"string"==typeof a&&-1!=a.indexOf(".")&&1===parseFloat(a)&&(a="100%");var b="string"===typeof a&&-1!=a.indexOf("%"),a=l(c,m(0,parseFloat(a)));b&&(a=parseInt(a*c,10)/100);return 1.0E-6>n.abs(a-c)?1:a%c/parseFloat(c)}function o(a){return 1==
+a.length?"0"+a:""+a}function p(a){1>=a&&(a=100*a+"%");return a}var H=/^[\s,#]+/,I=/\s+$/,F=0,n=Math,e=n.round,l=n.min,m=n.max,s=n.random;d.fromRatio=function(a){if("object"==typeof a){var c={},b;for(b in a)c[b]=p(a[b]);a=c}return d(a)};d.equals=function(a,c){return!a||!c?!1:d(a).toRgbString()==d(c).toRgbString()};d.random=function(){return d.fromRatio({r:s(),g:s(),b:s()})};d.desaturate=function(a,c){var b=d(a).toHsl();b.s-=(c||10)/100;b.s=l(1,m(0,b.s));return d(b)};d.saturate=function(a,c){var b=
+d(a).toHsl();b.s+=(c||10)/100;b.s=l(1,m(0,b.s));return d(b)};d.greyscale=function(a){return d.desaturate(a,100)};d.lighten=function(a,c){var b=d(a).toHsl();b.l+=(c||10)/100;b.l=l(1,m(0,b.l));return d(b)};d.darken=function(a,c){var b=d(a).toHsl();b.l-=(c||10)/100;b.l=l(1,m(0,b.l));return d(b)};d.complement=function(a){a=d(a).toHsl();a.h=(a.h+180)%360;return d(a)};d.triad=function(a){var c=d(a).toHsl(),b=c.h;return[d(a),d({h:(b+120)%360,s:c.s,l:c.l}),d({h:(b+240)%360,s:c.s,l:c.l})]};d.tetrad=function(a){var c=
+d(a).toHsl(),b=c.h;return[d(a),d({h:(b+90)%360,s:c.s,l:c.l}),d({h:(b+180)%360,s:c.s,l:c.l}),d({h:(b+270)%360,s:c.s,l:c.l})]};d.splitcomplement=function(a){var c=d(a).toHsl(),b=c.h;return[d(a),d({h:(b+72)%360,s:c.s,l:c.l}),d({h:(b+216)%360,s:c.s,l:c.l})]};d.analogous=function(a,c,b){var c=c||6,b=b||30,e=d(a).toHsl(),b=360/b,a=[d(a)];for(e.h=(e.h-(b*c>>1)+720)%360;--c;)e.h=(e.h+b)%360,a.push(d(e));return a};d.monochromatic=function(a,c){for(var c=c||6,b=d(a).toHsv(),e=b.h,h=b.s,b=b.v,g=[],f=1/c;c--;)g.push(d({h:e,
+s:h,v:b})),b=(b+f)%1;return g};d.readable=function(a,c){var b=d(a).toRgb(),e=d(c).toRgb();return 10404<(e.r-b.r)*(e.r-b.r)+(e.g-b.g)*(e.g-b.g)+(e.b-b.b)*(e.b-b.b)};var r=d.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",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"},G=d.hexNames=function(a){var c={},b;for(b in a)a.hasOwnProperty(b)&&(c[a[b]]=b);return c}(r);t=RegExp("rgb[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");
+u=RegExp("rgba[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");v=RegExp("hsl[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");w=RegExp("hsla[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");
+x=RegExp("hsv[\\s|\\(]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))[,|\\s]+((?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?))\\s*\\)?");z=/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;y=/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;"undefined"!==typeof module&&module.exports?module.exports=d:C.tinycolor=d})(this);
View
22 tinycolor.js
@@ -1,4 +1,4 @@
-// TinyColor.js - <https://github.com/bgrins/TinyColor> - 2012 Brian Grinstead - v0.9.11
+// TinyColor.js - <https://github.com/bgrins/TinyColor> - 2012 Brian Grinstead - v0.9.12
(function(root) {
@@ -10,7 +10,6 @@ var trimLeft = /^[\s,#]+/,
mathMin = math.min,
mathMax = math.max,
mathRandom = math.random;
- // parseFloat redeclaration caused errors in Node
function tinycolor (color, opts) {
@@ -90,8 +89,10 @@ function tinycolor (color, opts) {
return hexNames[rgbToHex(r, g, b)] || false;
},
toFilter: function() {
- var hex = secondHex = rgbToHex(r, g, b);
- var alphaHex = secondAlphaHex = Math.round(parseFloat(a) * 255).toString(16);
+ var hex = rgbToHex(r, g, b);
+ var secondHex = hex;
+ var alphaHex = Math.round(parseFloat(a) * 255).toString(16);
+ var secondAlphaHex = alphaHex;
var gradientType = opts && opts.gradientType ? "GradientType = 1, " : "";
if (secondColor) {
@@ -141,7 +142,7 @@ tinycolor.fromRatio = function(color) {
}
return tinycolor(color);
-}
+};
// Given a string or object, convert that input to RGB
// Possible string inputs:
@@ -184,7 +185,7 @@ function inputToRGB(color) {
else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("l")) {
color.s = convertToPercentage(color.s);
color.l = convertToPercentage(color.l);
- var rgb = hslToRgb(color.h, color.s, color.l);
+ rgb = hslToRgb(color.h, color.s, color.l);
ok = true;
format = "hsl";
}
@@ -283,7 +284,7 @@ function hslToRgb(h, s, l) {
return p;
}
- if(s == 0) {
+ if(s === 0) {
r = g = b = l; // achromatic
}
else {
@@ -311,7 +312,7 @@ function rgbToHsv(r, g, b) {
var h, s, v = max;
var d = max - min;
- s = max == 0 ? 0 : d / max;
+ s = max === 0 ? 0 : d / max;
if(max == min) {
h = 0; // achromatic
@@ -332,7 +333,6 @@ function rgbToHsv(r, g, b) {
// *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) {
- var r, g, b;
h = bound01(h, 360) * 6;
s = bound01(s, 100);
@@ -463,7 +463,7 @@ tinycolor.analogous = function(color, results, slices) {
slices = slices || 30;
var hsl = tinycolor(color).toHsl();
- var part = 360 / slices
+ var part = 360 / slices;
var ret = [tinycolor(color)];
for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
@@ -676,7 +676,7 @@ function bound01(n, max) {
// Automatically convert percentage into number
if (processPercent) {
- n = parseInt(n * max) / 100;
+ n = parseInt(n * max, 10) / 100;
}
// Handle floating point rounding errors

0 comments on commit 3b16044

Please sign in to comment.