@daeinc/color
Advanced tools
Comparing version 0.2.0 to 0.2.1
/** | ||
* convert normalized grayscale value to RGB | ||
* @param val grayscale value 0..1 | ||
* @returns RGB color array[3] in 0..255 | ||
*/ | ||
export declare function hsv2rgb(val: number): number[]; | ||
/** | ||
* convert normalized HSB color to RGB | ||
@@ -3,0 +9,0 @@ * @param arr [h, s, v] or [h, s, v, a] |
@@ -8,3 +8,3 @@ "use strict"; | ||
* convert normalized HSB color to RGB | ||
* @param hOrArr normalized hue 0..1 (wrapped) | ||
* @param hOrValOrArr normalized hue 0..1 (wrapped) | ||
* @param s normalized saturation 0..1 (clamped) | ||
@@ -15,21 +15,27 @@ * @param v normalized brightness 0..1 (clamped) | ||
*/ | ||
function hsv2rgb(hOrArr, s, v, a) { | ||
function hsv2rgb(hOrValOrArr, s, v, a) { | ||
if (s !== undefined && v !== undefined && a !== undefined) { | ||
// (h, s, v, a) | ||
return [...hsvrgb(hOrArr * 360, s, v), a]; | ||
return [...hsvrgb(hOrValOrArr * 360, s, v), a]; | ||
} | ||
else if (s !== undefined && v !== undefined) { | ||
// (h, s, v) | ||
return [...hsvrgb(hOrArr * 360, s, v)]; | ||
return [...hsvrgb(hOrValOrArr * 360, s, v)]; | ||
} | ||
else if (s === undefined) { | ||
hOrArr[0] *= 360; | ||
if (hOrArr.length === 3) { | ||
// ([h, s, v]) | ||
return [...hsvrgb(...hOrArr)]; | ||
if (Array.isArray(hOrValOrArr)) { | ||
hOrValOrArr[0] *= 360; | ||
if (hOrValOrArr.length === 3) { | ||
// ([h, s, v]) | ||
return [...hsvrgb(...hOrValOrArr)]; | ||
} | ||
else if (hOrValOrArr.length === 4) { | ||
// ([h, s, v, a]) | ||
// hsvrgb's 4th argument is NOT alpha but out array | ||
return [...hsvrgb(...hOrValOrArr.slice(0, 3)), hOrValOrArr[3]]; | ||
} | ||
} | ||
else if (hOrArr.length === 4) { | ||
// ([h, s, v, a]) | ||
// hsvrgb's 4th argument is NOT alpha but out array | ||
return [...hsvrgb(...hOrArr.slice(0, 3)), hOrArr[3]]; | ||
else { | ||
// a single argument | ||
return [...hsvrgb(0, 0, hOrValOrArr)]; | ||
} | ||
@@ -36,0 +42,0 @@ } |
{ | ||
"name": "@daeinc/color", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Color utilities", | ||
@@ -23,2 +23,3 @@ "types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"color-functions": "^3.0.1", | ||
"color-normalize": "^1.5.2", | ||
@@ -25,0 +26,0 @@ "hsv-rgb": "^1.0.0", |
# @daeinc/color | ||
Color utilities. Mostly wrapper functions on existing packages. | ||
Color utilities. Mostly wrapper functions on existing packages for convenience. | ||
`npm i @daeinc/color` | ||
## To dos | ||
- back to back conversion does not return the original value. ex. `hsv2rgb(rgb2hsv(128, 127, 108))` | ||
- not equal: `expect(hex2rgb("#80808080")[3]).toBeCloseTo(0.5);` | ||
- add `rgb2hsl` and `hsl2rgb` | ||
- try | ||
- [`color-functions`](https://github.com/pqx/color-functions) | ||
- [`color-normalize`](https://github.com/colorjs/color-normalize) | ||
@@ -11,0 +14,0 @@ ## License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12813
175
17
5