Comparing version 1.0.2 to 2.0.0
255
husl.js
@@ -1,10 +0,7 @@ | ||
// Generated by CoffeeScript 1.3.1 | ||
// Generated by CoffeeScript 1.3.3 | ||
(function() { | ||
var conv, dotProduct, f, f_inv, fromLinear, huslToRgb, lab_e, lab_k, m, m_inv, maxChroma, refU, refV, refX, refY, refZ, rgbPrepare, rgbToHusl, root, round, stylus, toLinear; | ||
var conv, dotProduct, f, f_inv, fromLinear, lab_e, lab_k, m, m_inv, maxChroma, maxChromaD, refU, refV, refX, refY, refZ, rgbPrepare, root, round, stylus, toLinear, _hradExtremum, _maxChroma, _maxChroma2; | ||
maxChroma = function(L, H, debug) { | ||
var C, bottom, cosH, hrad, lbottom, list, m1, m2, m3, rbottom, result, row, sinH, sub1, sub2, t, top, _i, _j, _len, _len1, _ref; | ||
if (debug == null) { | ||
debug = false; | ||
} | ||
_maxChroma = function(L, H) { | ||
var cosH, hrad, sinH, sub1, sub2; | ||
hrad = H / 360 * 2 * Math.PI; | ||
@@ -15,7 +12,5 @@ sinH = Math.sin(hrad); | ||
sub2 = sub1 > 0.008856 ? sub1 : L / 903.3; | ||
result = Infinity; | ||
list = []; | ||
for (_i = 0, _len = m.length; _i < _len; _i++) { | ||
row = m[_i]; | ||
m1 = row[0], m2 = row[1], m3 = row[2]; | ||
return function(channel) { | ||
var bottom, lbottom, m1, m2, m3, rbottom, top, _ref; | ||
_ref = m[channel], m1 = _ref[0], m2 = _ref[1], m3 = _ref[2]; | ||
top = (0.99915 * m1 + 1.05122 * m2 + 1.14460 * m3) * sub2; | ||
@@ -25,24 +20,98 @@ rbottom = 0.86330 * m3 - 0.17266 * m2; | ||
bottom = (rbottom * sinH + lbottom * cosH) * sub2; | ||
_ref = [0, 1]; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
t = _ref[_j]; | ||
C = L * (top - 1.05122 * t) / (bottom + 0.17266 * sinH * t); | ||
return function(limit) { | ||
return L * (top - 1.05122 * limit) / (bottom + 0.17266 * sinH * limit); | ||
}; | ||
}; | ||
}; | ||
_maxChroma2 = function(L) { | ||
var sub1, sub2; | ||
sub1 = Math.pow(L + 16, 3) / 1560896; | ||
sub2 = sub1 > 0.008856 ? sub1 : L / 903.3; | ||
return function(channel) { | ||
var lbottom, m1, m2, m3, rbottom, top, _ref; | ||
_ref = m[channel], m1 = _ref[0], m2 = _ref[1], m3 = _ref[2]; | ||
top = (0.99915 * m1 + 1.05122 * m2 + 1.14460 * m3) * sub2; | ||
rbottom = 0.86330 * m3 - 0.17266 * m2; | ||
lbottom = 0.12949 * m3 - 0.38848 * m1; | ||
return function(limit, hrad) { | ||
var bottom, cosH, sinH; | ||
sinH = Math.sin(hrad); | ||
cosH = Math.cos(hrad); | ||
bottom = (rbottom * sinH + lbottom * cosH) * sub2; | ||
return L * (top - 1.05122 * limit) / (bottom + 0.17266 * sinH * limit); | ||
}; | ||
}; | ||
}; | ||
_hradExtremum = function(L) { | ||
var lhs, rhs, sub; | ||
lhs = (Math.pow(L, 3) + 48 * Math.pow(L, 2) + 768 * L + 4096) / 1560896; | ||
rhs = 1107 / 125000; | ||
sub = lhs > rhs ? lhs : 10 * L / 9033; | ||
return function(channel, limit) { | ||
var bottom, hrad, m1, m2, m3, top, _ref; | ||
_ref = m[channel], m1 = _ref[0], m2 = _ref[1], m3 = _ref[2]; | ||
top = -3015466475 * m3 * sub + 603093295 * m2 * sub - 603093295 * limit; | ||
bottom = 1356959916 * m1 * sub - 452319972 * m3 * sub; | ||
hrad = Math.atan2(top, bottom); | ||
if (limit === 0) { | ||
hrad += Math.PI; | ||
} | ||
return hrad; | ||
}; | ||
}; | ||
maxChroma = function(L, H) { | ||
var C, channel, limit, mc1, mc2, result, _i, _j, _len, _len1, _ref, _ref1; | ||
result = Infinity; | ||
mc1 = _maxChroma(L, H); | ||
_ref = ['R', 'G', 'B']; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
channel = _ref[_i]; | ||
mc2 = mc1(channel); | ||
_ref1 = [0, 1]; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
limit = _ref1[_j]; | ||
C = mc2(limit); | ||
if ((0 < C && C < result)) { | ||
result = C; | ||
} | ||
if (debug) { | ||
list.push(C); | ||
} | ||
} | ||
} | ||
if (debug) { | ||
return list; | ||
} | ||
return result; | ||
}; | ||
m = [[3.2406, -1.5372, -0.4986], [-0.9689, 1.8758, 0.0415], [0.0557, -0.2040, 1.0570]]; | ||
maxChromaD = function(L) { | ||
var C, channel, he1, hrad, limit, mc1, mc2, minima_C, _i, _j, _len, _len1, _ref, _ref1; | ||
minima_C = []; | ||
mc1 = _maxChroma2(L); | ||
he1 = _hradExtremum(L); | ||
_ref = ['R', 'G', 'B']; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
channel = _ref[_i]; | ||
mc2 = mc1(channel); | ||
_ref1 = [0, 1]; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
limit = _ref1[_j]; | ||
hrad = he1(channel, limit); | ||
C = mc2(limit, hrad); | ||
minima_C.push(C); | ||
} | ||
} | ||
return Math.min.apply(Math, minima_C); | ||
}; | ||
m_inv = [[0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722], [0.0193, 0.1192, 0.9505]]; | ||
m = { | ||
R: [3.2406, -1.5372, -0.4986], | ||
G: [-0.9689, 1.8758, 0.0415], | ||
B: [0.0557, -0.2040, 1.0570] | ||
}; | ||
m_inv = { | ||
X: [0.4124, 0.3576, 0.1805], | ||
Y: [0.2126, 0.7152, 0.0722], | ||
Z: [0.0193, 0.1192, 0.9505] | ||
}; | ||
dotProduct = function(a, b) { | ||
@@ -124,5 +193,11 @@ var i, ret, _i, _ref; | ||
ch = tuple[_i]; | ||
if (ch < 0 || ch > 1) { | ||
throw new Error("Illegal rgb value"); | ||
if (ch < -0.0001 || ch > 1.0001) { | ||
throw new Error("Illegal rgb value: " + ch); | ||
} | ||
if (ch < 0) { | ||
ch = 0; | ||
} | ||
if (ch > 1) { | ||
ch = 1; | ||
} | ||
} | ||
@@ -142,2 +217,3 @@ _results = []; | ||
'husl': {}, | ||
'huslp': {}, | ||
'rgb': {}, | ||
@@ -149,5 +225,5 @@ 'hex': {} | ||
var B, G, R; | ||
R = fromLinear(dotProduct(m[0], tuple)); | ||
G = fromLinear(dotProduct(m[1], tuple)); | ||
B = fromLinear(dotProduct(m[2], tuple)); | ||
R = fromLinear(dotProduct(m.R, tuple)); | ||
G = fromLinear(dotProduct(m.G, tuple)); | ||
B = fromLinear(dotProduct(m.B, tuple)); | ||
return [R, G, B]; | ||
@@ -160,5 +236,5 @@ }; | ||
rgbl = [toLinear(R), toLinear(G), toLinear(B)]; | ||
X = dotProduct(m_inv[0], rgbl); | ||
Y = dotProduct(m_inv[1], rgbl); | ||
Z = dotProduct(m_inv[2], rgbl); | ||
X = dotProduct(m_inv.X, rgbl); | ||
Y = dotProduct(m_inv.Y, rgbl); | ||
Z = dotProduct(m_inv.Z, rgbl); | ||
return [X, Y, Z]; | ||
@@ -220,2 +296,8 @@ }; | ||
H = tuple[0], S = tuple[1], L = tuple[2]; | ||
if (L > 99.9999999) { | ||
return [100, 0, H]; | ||
} | ||
if (L < 0.00000001) { | ||
return [0, 0, H]; | ||
} | ||
max = maxChroma(L, H); | ||
@@ -229,2 +311,8 @@ C = max / 100 * S; | ||
L = tuple[0], C = tuple[1], H = tuple[2]; | ||
if (L > 99.9999999) { | ||
return [H, 0, 100]; | ||
} | ||
if (L < 0.00000001) { | ||
return [H, 0, 0]; | ||
} | ||
max = maxChroma(L, H); | ||
@@ -235,2 +323,30 @@ S = C / max * 100; | ||
conv.huslp.lch = function(tuple) { | ||
var C, H, L, S, max; | ||
H = tuple[0], S = tuple[1], L = tuple[2]; | ||
if (L > 99.9999999) { | ||
return [100, 0, H]; | ||
} | ||
if (L < 0.00000001) { | ||
return [0, 0, H]; | ||
} | ||
max = maxChromaD(L); | ||
C = max / 100 * S; | ||
return [L, C, H]; | ||
}; | ||
conv.lch.huslp = function(tuple) { | ||
var C, H, L, S, max; | ||
L = tuple[0], C = tuple[1], H = tuple[2]; | ||
if (L > 99.9999999) { | ||
return [H, 0, 100]; | ||
} | ||
if (L < 0.00000001) { | ||
return [H, 0, 0]; | ||
} | ||
max = maxChromaD(L); | ||
S = C / max * 100; | ||
return [H, S, L]; | ||
}; | ||
conv.rgb.hex = function(tuple) { | ||
@@ -264,10 +380,26 @@ var ch, hex, _i, _len; | ||
huslToRgb = function(tuple) { | ||
return conv.xyz.rgb(conv.luv.xyz(conv.lch.luv(conv.husl.lch(tuple)))); | ||
conv.lch.rgb = function(tuple) { | ||
return conv.xyz.rgb(conv.luv.xyz(conv.lch.luv(tuple))); | ||
}; | ||
rgbToHusl = function(tuple) { | ||
return conv.lch.husl(conv.luv.lch(conv.xyz.luv(conv.rgb.xyz(tuple)))); | ||
conv.rgb.lch = function(tuple) { | ||
return conv.luv.lch(conv.xyz.luv(conv.rgb.xyz(tuple))); | ||
}; | ||
conv.husl.rgb = function(tuple) { | ||
return conv.lch.rgb(conv.husl.lch(tuple)); | ||
}; | ||
conv.rgb.husl = function(tuple) { | ||
return conv.lch.husl(conv.rgb.lch(tuple)); | ||
}; | ||
conv.huslp.rgb = function(tuple) { | ||
return conv.lch.rgb(conv.huslp.lch(tuple)); | ||
}; | ||
conv.rgb.huslp = function(tuple) { | ||
return conv.lch.huslp(conv.rgb.lch(tuple)); | ||
}; | ||
root = {}; | ||
@@ -279,7 +411,12 @@ | ||
return function(style) { | ||
return style.define('husl', function(H, S, L, A) { | ||
style.define('husl', function(H, S, L, A) { | ||
var B, G, R, _ref; | ||
_ref = rgbPrepare(huslToRgb([H.val, S.val, L.val])), R = _ref[0], G = _ref[1], B = _ref[2]; | ||
_ref = rgbPrepare(conv.husl.rgb([H.val, S.val, L.val])), R = _ref[0], G = _ref[1], B = _ref[2]; | ||
return new stylus.nodes.RGBA(R, G, B, (A != null ? A.val : 1)); | ||
}); | ||
return style.define('huslp', function(H, S, L, A) { | ||
var B, G, R, _ref; | ||
_ref = rgbPrepare(conv.huslp.rgb([H.val, S.val, L.val])), R = _ref[0], G = _ref[1], B = _ref[2]; | ||
return new stylus.nodes.RGBA(R, G, B, (A != null ? A.val : 1)); | ||
}); | ||
}; | ||
@@ -289,22 +426,36 @@ }; | ||
root.husl = function(H, S, L, noHex) { | ||
var rgb; | ||
if (noHex == null) { | ||
noHex = false; | ||
} | ||
rgb = huslToRgb([H, S, L]); | ||
if (noHex) { | ||
return rgb; | ||
} | ||
return conv.rgb.hex(rgb); | ||
root.fromRGB = function(R, G, B) { | ||
return conv.rgb.husl([R, G, B]); | ||
}; | ||
root.rgb = function(R, G, B) { | ||
return rgbToHusl([R, G, B]); | ||
root.fromHex = function(hex) { | ||
return conv.rgb.husl(conv.hex.rgb(hex)); | ||
}; | ||
root.hex = function(hex) { | ||
return rgbToHusl(conv.hex.rgb(hex)); | ||
root.toRGB = function(H, S, L) { | ||
return conv.husl.rgb([H, S, L]); | ||
}; | ||
root.toHex = function(H, S, L) { | ||
return conv.rgb.hex(conv.husl.rgb([H, S, L])); | ||
}; | ||
root.p = {}; | ||
root.p.toRGB = function(H, S, L) { | ||
return conv.xyz.rgb(conv.luv.xyz(conv.lch.luv(conv.huslp.lch([H, S, L])))); | ||
}; | ||
root.p.toHex = function(H, S, L) { | ||
return conv.rgb.hex(conv.xyz.rgb(conv.luv.xyz(conv.lch.luv(conv.huslp.lch([H, S, L]))))); | ||
}; | ||
root.p.fromRGB = function(R, G, B) { | ||
return conv.lch.huslp(conv.luv.lch(conv.xyz.luv(conv.rgb.xyz([R, G, B])))); | ||
}; | ||
root.p.fromHex = function(hex) { | ||
return conv.lch.huslp(conv.luv.lch(conv.xyz.luv(conv.rgb.xyz(conv.hex.rgb(hex))))); | ||
}; | ||
root._conv = conv; | ||
@@ -311,0 +462,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["color", "color space", "CIE", "RGB", "stylus", "HUSL", "HSL"], | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"author": "Alexei Boronine <alexei.boronine@gmail.com>", | ||
@@ -14,3 +14,16 @@ "main": "husl.js", | ||
}, | ||
"homepage": "http://boronine.github.com/husl/" | ||
"homepage": "http://boronine.github.com/husl/", | ||
"devDependencies": { | ||
"coffee-script": "*", | ||
"colorspaces": "*", | ||
"onecolor": "*", | ||
"png": "*", | ||
"stylus": "*", | ||
"eco": "*", | ||
"mocha": "*", | ||
"imagediff": "*" | ||
}, | ||
"scripts": { | ||
"test": "mocha --compilers coffee:coffee-script" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
0
26
14842
8
3
406
1