MCPcopy
hub / github.com/microsoft/SandDance / hslConvert

Function hslConvert

docs/app/js/sanddance-app.js:2455–2470  ·  view source on GitHub ↗
(o)

Source from the content-addressed store, hash-verified

2453 return new Hsl(h, s, l, a);
2454}
2455function hslConvert(o) {
2456 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2457 if (!(o instanceof Color)) o = color(o);
2458 if (!o) return new Hsl;
2459 if (o instanceof Hsl) return o;
2460 o = o.rgb();
2461 var r = o.r / 255, g = o.g / 255, b = o.b / 255, min = Math.min(r, g, b), max = Math.max(r, g, b), h = NaN, s = max - min, l = (max + min) / 2;
2462 if (s) {
2463 if (r === max) h = (g - b) / s + (g < b) * 6;
2464 else if (g === max) h = (b - r) / s + 2;
2465 else h = (r - g) / s + 4;
2466 s /= l < 0.5 ? max + min : 2 - max - min;
2467 h *= 60;
2468 } else s = l > 0 && l < 1 ? 0 : h;
2469 return new Hsl(h, s, l, o.opacity);
2470}
2471function hsl(h, s, l, opacity) {
2472 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2473}

Callers 2

color_formatHslFunction · 0.70
hslFunction · 0.70

Calls 3

colorFunction · 0.70
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected