chromaticity-color-utilities
Advanced tools
Comparing version 0.2.6-alpha to 0.2.7-alpha
@@ -81,3 +81,3 @@ "use strict"; | ||
else { | ||
_this.hex = hex.toString(16).slice(1); | ||
_this.hex = hex.toString(16); | ||
} | ||
@@ -87,3 +87,3 @@ return _this; | ||
hex.prototype.torgb = function (args) { | ||
return Convert_1.default.hex2rgb(this); | ||
return Convert_1.default.hex2rgb(this, args.bitDepth); | ||
}; | ||
@@ -90,0 +90,0 @@ hex.prototype.tohex = function (args) { |
@@ -102,2 +102,3 @@ "use strict"; | ||
colorType.prototype.modify = function (modification, args) { | ||
modification = modification.toLowerCase(); | ||
if (typeof args == 'undefined') | ||
@@ -460,6 +461,6 @@ args = {}; | ||
} | ||
if (lowerLimit && upperLimit && lowerLimit >= upperLimit) { | ||
if (lowerLimit !== false && upperLimit !== false && lowerLimit >= upperLimit) { | ||
throw new Error('Invalid range (lower limit must exceed upper limit)'); | ||
} | ||
if ((lowerLimit && value < lowerLimit) || (upperLimit && value > upperLimit)) { | ||
if ((lowerLimit !== false && value < lowerLimit) || (upperLimit !== false && value > upperLimit)) { | ||
throw new Error(typeof msg !== 'undefined' ? msg : 'Color value out of range'); | ||
@@ -466,0 +467,0 @@ } |
@@ -429,3 +429,3 @@ "use strict"; | ||
b *= max; | ||
var a = Util_1.default.scaleValueRange(hsl.a, 0, 100, 0, max); | ||
var a = Util_1.default.scaleValueRange(hsl.a, 0, 100, 0, max, round); | ||
if (round) { | ||
@@ -480,3 +480,3 @@ r = Math.round(r); | ||
var z = 1 - Math.abs(Util_1.default.fmod(h, 2) - 1); | ||
var chroma = (2 * i * s) / (1 + z); | ||
var chroma = (3 * i * s) / (1 + z); | ||
var x = chroma * z; | ||
@@ -528,3 +528,3 @@ var huef = Math.floor(h); | ||
b *= max; | ||
var a = Util_1.default.scaleValueRange(hsi.a, 0, 100, 0, max); | ||
var a = Util_1.default.scaleValueRange(hsi.a, 0, 100, 0, max, round); | ||
if (round) { | ||
@@ -602,3 +602,3 @@ r = Math.round(r); | ||
pb *= 100; | ||
var a = rgb.a / maxVal * 100; | ||
var a = Util_1.default.scaleValueRange(rgb.a, 0, maxVal, 0, 100, round); | ||
if (round) { | ||
@@ -709,3 +709,3 @@ h = Math.round(h); | ||
b *= max; | ||
var a = hsp.a / 100 * max; | ||
var a = Util_1.default.scaleValueRange(hsp.a, 0, 100, 0, max, round); | ||
if (round) { | ||
@@ -838,6 +838,12 @@ r = Math.round(r); | ||
} | ||
var r = y + 0.956 * i + 0.621 * q; | ||
var g = y + -0.272 * i + -0.647 * q; | ||
var b = y + -1.106 * i + 1.703 * q; | ||
r = Math.min(Math.max(r, 0), 1); | ||
g = Math.min(Math.max(g, 0), 1); | ||
b = Math.min(Math.max(b, 0), 1); | ||
var max = (Math.pow(2, bitDepth)) - 1; | ||
var r = (y + 0.956 * i + 0.621 * q) * max; | ||
var g = (y + -0.272 * i + -0.647 * q) * max; | ||
var b = (y + -1.106 * i + 1.703 * q) * max; | ||
r *= max; | ||
g *= max; | ||
b *= max; | ||
if (round) { | ||
@@ -922,7 +928,7 @@ r = Math.round(r); | ||
referenceWhite = referenceWhite.toLowerCase(); | ||
if (typeof space['rgb2xyz'] == 'undefined' || | ||
typeof space['rgb2xyz'][referenceWhite] == 'undefined') { | ||
if (typeof space['xyz2rgb'] == 'undefined' || | ||
typeof space['xyz2rgb'][referenceWhite] == 'undefined') { | ||
throw new Error('Transformation matrix unavailable for this color space and reference white'); | ||
} | ||
var m = space['rgb2xyz'][referenceWhite]; | ||
var m = space['xyz2rgb'][referenceWhite]; | ||
// [R] [X] | ||
@@ -932,4 +938,4 @@ // [G] = [M]*[Y] where [M] is [RGB to XYZ matrix]^-1 | ||
var r = m[0][0] * xyz.x + m[0][1] * xyz.y + m[0][2] * xyz.z; | ||
var g = m[1][1] * xyz.x + m[1][1] * xyz.y + m[1][2] * xyz.z; | ||
var b = m[2][1] * xyz.x + m[2][1] * xyz.y + m[2][2] * xyz.z; | ||
var g = m[1][0] * xyz.x + m[1][1] * xyz.y + m[1][2] * xyz.z; | ||
var b = m[2][0] * xyz.x + m[2][1] * xyz.y + m[2][2] * xyz.z; | ||
if (colorSpace == 'srgb') { | ||
@@ -936,0 +942,0 @@ // sRGB |
@@ -41,2 +41,3 @@ "use strict"; | ||
Color.prototype.from = function (type, value, args) { | ||
type = type.toLowerCase().replace(/[^a-z0-9]/, ''); | ||
if (typeof args === 'undefined') | ||
@@ -43,0 +44,0 @@ args = {}; |
@@ -722,3 +722,3 @@ "use strict"; | ||
[3.2404542, -1.5371385, -0.4985314], | ||
[-0.969266, 1.8760108, 0.041556], | ||
[-0.9692660, 1.8760108, 0.0415560], | ||
[0.0556434, -0.2040259, 1.0572252], | ||
@@ -728,3 +728,3 @@ ], | ||
[3.1338561, -1.6168667, -0.4906146], | ||
[-0.9787684, 1.9161415, 0.033454], | ||
[-0.9787684, 1.9161415, 0.0334540], | ||
[0.0719453, -0.2289914, 1.4052427], | ||
@@ -731,0 +731,0 @@ ], |
{ | ||
"name": "chromaticity-color-utilities", | ||
"version": "0.2.6-alpha", | ||
"version": "0.2.7-alpha", | ||
"description": "Color utilities for Node.js", | ||
"main": "dist/main.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
@@ -51,2 +51,4 @@ "dependencies": {}, | ||
"@types/node": "^14.14.37", | ||
"chai": "^4.3.4", | ||
"mocha": "^8.3.2", | ||
"nodemon": "^2.0.7", | ||
@@ -53,0 +55,0 @@ "ts-node": "^9.1.1", |
@@ -11,2 +11,6 @@ # <img src="https://reiniiriarios.github.io/chromaticity-color-utilities/assets/images/chromaticity-icon-01.png" width="26" height="26"> chromaticity-color-utilities | ||
## Status | ||
Approaching complete-ish stage... Most conversion tests pass. Issues with XYZ. Writing tests for schemes, mods. | ||
## Documentation | ||
@@ -13,0 +17,0 @@ |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
267405
23
6346
1
101
7