Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chromaticity-color-utilities

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chromaticity-color-utilities - npm Package Compare versions

Comparing version 0.2.1-alpha to 0.2.4-alpha

32

dist/Colors.d.ts
import { newColorArgs, colorType } from './ColorType';
export declare class hex extends colorType {
hex: string;
constructor(hex: string | number);
protected torgb(args: newColorArgs): rgb;
protected tohex(args: newColorArgs): hex;
}
export declare class rgbNormalized extends colorType {

@@ -16,2 +10,8 @@ r: number;

}
export declare class hex extends colorType {
hex: string;
constructor(hex: string | number);
protected torgb(args: newColorArgs): rgb;
protected tohex(args: newColorArgs): hex;
}
export declare class rgb extends colorType {

@@ -124,5 +124,3 @@ r: number;

z: number;
colorSpace: string;
referenceWhite: string;
constructor(x: number, y: number, z: number, colorSpace?: string, referenceWhite?: string);
constructor(x: number, y: number, z: number);
protected torgb(args: newColorArgs): rgb;

@@ -135,5 +133,3 @@ protected toxyz(args: newColorArgs): xyz;

yy: number;
colorSpace: string;
referenceWhite: string;
constructor(x: number, y: number, yy: number, colorSpace?: string, referenceWhite?: string);
constructor(x: number, y: number, yy: number);
protected torgb(args: newColorArgs): rgb;

@@ -147,4 +143,2 @@ protected toxyz(args: newColorArgs): xyz;

b: number;
colorSpace: string;
referenceWhite: string;
/**

@@ -155,6 +149,4 @@ *

* @param {number} b unbounded, but typically clamped at -128 and 127
* @param {string} colorSpace
* @param {string} referenceWhite
*/
constructor(l: number, a: number, b: number, colorSpace?: string, referenceWhite?: string);
constructor(l: number, a: number, b: number);
protected torgb(args: newColorArgs): rgb;

@@ -168,4 +160,2 @@ protected toxyz(args: newColorArgs): xyz;

v: number;
colorSpace: string;
referenceWhite: string;
/**

@@ -176,6 +166,4 @@ *

* @param {number} v -100-100
* @param {string} colorSpace
* @param {string} referenceWhite
*/
constructor(l: number, u: number, v: number, colorSpace?: string, referenceWhite?: string);
constructor(l: number, u: number, v: number);
protected torgb(args: newColorArgs): rgb;

@@ -182,0 +170,0 @@ protected toxyz(args: newColorArgs): xyz;

@@ -36,5 +36,27 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.kelvin = exports.nm = exports.ycbcr = exports.ypbpr = exports.luv = exports.lab = exports.xyy = exports.xyz = exports.yiq = exports.cmyk = exports.hsp = exports.hsi = exports.hsl = exports.hsv = exports.rec2020rgb = exports.rec709rgb = exports.rgb = exports.rgbNormalized = exports.hex = void 0;
exports.kelvin = exports.nm = exports.ycbcr = exports.ypbpr = exports.luv = exports.lab = exports.xyy = exports.xyz = exports.yiq = exports.cmyk = exports.hsp = exports.hsi = exports.hsl = exports.hsv = exports.rec2020rgb = exports.rec709rgb = exports.rgb = exports.hex = exports.rgbNormalized = void 0;
var Convert_1 = __importDefault(require("./Convert"));
var ColorType_1 = require("./ColorType");
var rgbNormalized = /** @class */ (function (_super) {
__extends(rgbNormalized, _super);
function rgbNormalized(r, g, b, a, gamma) {
if (a === void 0) { a = 1; }
var _this = _super.call(this) || this;
_this.valueRangeCheck(r, 0, 1);
_this.valueRangeCheck(g, 0, 1);
_this.valueRangeCheck(b, 0, 1);
_this.valueRangeCheck(a, 0, 1);
_this.r = r;
_this.g = g;
_this.b = b;
_this.a = a;
if (typeof gamma !== 'undefined') {
_this.valueRangeCheck(gamma, 0, false);
_this.gamma = gamma;
}
return _this;
}
return rgbNormalized;
}(ColorType_1.colorType));
exports.rgbNormalized = rgbNormalized;
var hex = /** @class */ (function (_super) {

@@ -73,24 +95,2 @@ __extends(hex, _super);

exports.hex = hex;
var rgbNormalized = /** @class */ (function (_super) {
__extends(rgbNormalized, _super);
function rgbNormalized(r, g, b, a, gamma) {
if (a === void 0) { a = 1; }
var _this = _super.call(this) || this;
_this.valueRangeCheck(r, 0, 1);
_this.valueRangeCheck(g, 0, 1);
_this.valueRangeCheck(b, 0, 1);
_this.valueRangeCheck(a, 0, 1);
_this.r = r;
_this.g = g;
_this.b = b;
_this.a = a;
if (typeof gamma !== 'undefined') {
_this.valueRangeCheck(gamma, 0, false);
_this.gamma = gamma;
}
return _this;
}
return rgbNormalized;
}(ColorType_1.colorType));
exports.rgbNormalized = rgbNormalized;
var rgb = /** @class */ (function (_super) {

@@ -427,5 +427,3 @@ __extends(rgb, _super);

__extends(xyz, _super);
function xyz(x, y, z, colorSpace, referenceWhite) {
if (colorSpace === void 0) { colorSpace = 'srgb'; }
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
function xyz(x, y, z) {
var _this = _super.call(this) || this;

@@ -438,9 +436,6 @@ _this.valueRangeCheck(x, 0, 1, 'XYZ values must be between 0 and 1');

_this.z = z;
// error handling of the following two properties handled in conversion
_this.colorSpace = colorSpace;
_this.referenceWhite = referenceWhite;
return _this;
}
xyz.prototype.torgb = function (args) {
return Convert_1.default.xyz2rgb(this, args.round, args.bitDepth);
return Convert_1.default.xyz2rgb(this, args.colorSpace, args.referenceWhite, args.round, args.bitDepth);
};

@@ -455,5 +450,3 @@ xyz.prototype.toxyz = function (args) {

__extends(xyy, _super);
function xyy(x, y, yy, colorSpace, referenceWhite) {
if (colorSpace === void 0) { colorSpace = 'srgb'; }
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
function xyy(x, y, yy) {
var _this = _super.call(this) || this;

@@ -463,8 +456,6 @@ _this.x = x;

_this.yy = yy;
_this.colorSpace = colorSpace;
_this.referenceWhite = referenceWhite;
return _this;
}
xyy.prototype.torgb = function (args) {
return Convert_1.default.xyz2rgb(this.toxyz(args), args.round, args.bitDepth);
return Convert_1.default.xyz2rgb(this.toxyz(args), args.colorSpace, args.referenceWhite, args.round, args.bitDepth);
};

@@ -487,8 +478,4 @@ xyy.prototype.toxyz = function (args) {

* @param {number} b unbounded, but typically clamped at -128 and 127
* @param {string} colorSpace
* @param {string} referenceWhite
*/
function lab(l, a, b, colorSpace, referenceWhite) {
if (colorSpace === void 0) { colorSpace = 'srgb'; }
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
function lab(l, a, b) {
var _this = _super.call(this) || this;

@@ -499,11 +486,9 @@ _this.valueRangeCheck(l, 0, 100);

_this.b = b;
_this.colorSpace = colorSpace;
_this.referenceWhite = referenceWhite;
return _this;
}
lab.prototype.torgb = function (args) {
return Convert_1.default.xyz2rgb(this.toxyz(args), args.round, args.bitDepth);
return Convert_1.default.xyz2rgb(this.toxyz(args), args.colorSpace, args.referenceWhite, args.round, args.bitDepth);
};
lab.prototype.toxyz = function (args) {
return Convert_1.default.lab2xyz(this);
return Convert_1.default.lab2xyz(this, args.referenceWhite);
};

@@ -528,8 +513,4 @@ lab.prototype.tolab = function (args) {

* @param {number} v -100-100
* @param {string} colorSpace
* @param {string} referenceWhite
*/
function luv(l, u, v, colorSpace, referenceWhite) {
if (colorSpace === void 0) { colorSpace = 'srgb'; }
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
function luv(l, u, v) {
var _this = _super.call(this) || this;

@@ -542,11 +523,9 @@ _this.valueRangeCheck(l, 0, 100);

_this.v = v;
_this.colorSpace = colorSpace;
_this.referenceWhite = referenceWhite;
return _this;
}
luv.prototype.torgb = function (args) {
return Convert_1.default.xyz2rgb(this.toxyz(args), args.round, args.bitDepth);
return Convert_1.default.xyz2rgb(this.toxyz(args), args.colorSpace, args.referenceWhite, args.round, args.bitDepth);
};
luv.prototype.toxyz = function (args) {
return Convert_1.default.luv2xyz(this);
return Convert_1.default.luv2xyz(this, args.referenceWhite);
};

@@ -553,0 +532,0 @@ luv.prototype.toluv = function (args) {

@@ -196,5 +196,6 @@ import * as Colors from './Colors';

*/
static xyz2rgb(xyz: Colors.xyz, round?: boolean, bitDepth?: number): Colors.rgb;
static xyz2rgb(xyz: Colors.xyz, colorSpace?: string, referenceWhite?: string, round?: boolean, bitDepth?: number): Colors.rgb;
/**
* Convert XYZ to xyY
* If X = Z = Y = 0, set x and y to chromaticity coordinates of reference white
*

@@ -204,3 +205,3 @@ * @param {Colors.xyz} xyz

*/
static xyz2xyy(xyz: Colors.xyz): Colors.xyy;
static xyz2xyy(xyz: Colors.xyz, referenceWhite?: string): Colors.xyy;
/**

@@ -217,5 +218,7 @@ * Convert xyY to XYZ

* @param {Colors.xyz} xyz
* @param {string} referenceWhite
* @param {boolean} [round=true]
* @return {Colors.lab}
*/
static xyz2lab(xyz: Colors.xyz): Colors.lab;
static xyz2lab(xyz: Colors.xyz, referenceWhite?: string, round?: boolean): Colors.lab;
/**

@@ -227,3 +230,3 @@ * Convert Lab to XYZ

*/
static lab2xyz(lab: Colors.lab): Colors.xyz;
static lab2xyz(lab: Colors.lab, referenceWhite?: string): Colors.xyz;
/**

@@ -237,3 +240,3 @@ * Convert XYZ to Luv

*/
static xyz2luv(xyz: Colors.xyz): Colors.luv;
static xyz2luv(xyz: Colors.xyz, referenceWhite?: string, round?: boolean): Colors.luv;
/**

@@ -246,3 +249,3 @@ * Convert Luv to XYZ

*/
static luv2xyz(luv: Colors.luv): Colors.xyz;
static luv2xyz(luv: Colors.luv, referenceWhite?: string): Colors.xyz;
/**

@@ -249,0 +252,0 @@ * Convert RGB to Rec709 RGB

@@ -860,30 +860,9 @@ "use strict";

var b = rgb.b / rgb.max;
// make lowercase, include common nomenclature differences, ignore spaces, etc
colorSpace = colorSpace.toLowerCase().replace(/[^a-z0-9]/, '');
var space = Util_1.default.validColorSpace(colorSpace);
referenceWhite = referenceWhite.toLowerCase();
var conform = {
'adobe': 'adobergb1998',
'adobergb': 'adobergb1998',
'ntsc': 'ntscrgb',
'palsecam': 'palsecamrgb',
'pal': 'palsecamrgb',
'palrgb': 'palsecamrgb',
'secam': 'palsecamrgb',
'secamrgb': 'palsecamrgb',
'prophoto': 'prophotorgb',
'smpte': 'smptecrgb',
'smptec': 'smptecrgb',
'widegamut': 'widegamutrgb',
'ecirgbv2': 'ecirgb',
'ektaspace': 'ektaspaceps5'
};
if (typeof conform[colorSpace] == 'string') {
colorSpace = conform[colorSpace];
}
if (typeof Reference_1.colorSpaces[colorSpace] == 'undefined' ||
typeof Reference_1.colorSpaces[colorSpace]['rgb2xyz'] == 'undefined' ||
typeof Reference_1.colorSpaces[colorSpace]['rgb2xyz'][referenceWhite] == 'undefined') {
if (typeof space['rgb2xyz'] == 'undefined' ||
typeof space['rgb2xyz'][referenceWhite] == 'undefined') {
throw new Error('Transformation matrix unavailable for this color space and reference white');
}
var m = Reference_1.colorSpaces[colorSpace]['rgb2xyz'][referenceWhite];
var m = space['rgb2xyz'][referenceWhite];
if (colorSpace == 'srgb') {

@@ -903,8 +882,9 @@ // sRGB

// Gamma
if (typeof Reference_1.colorSpaces[colorSpace]['gamma'] == 'undefined') {
if (typeof space['gamma'] == 'undefined') {
throw new Error('Gamma not defined for this color space');
}
r = Math.pow(r, Reference_1.colorSpaces[colorSpace]['gamma']);
g = Math.pow(g, Reference_1.colorSpaces[colorSpace]['gamma']);
b = Math.pow(b, Reference_1.colorSpaces[colorSpace]['gamma']);
var gamma = space['gamma'];
r = Math.pow(r, gamma);
g = Math.pow(g, gamma);
b = Math.pow(b, gamma);
}

@@ -917,3 +897,6 @@ // [X] [R]

var z = m[2][0] * r + m[2][1] * g + m[2][2] * b;
return new Colors.xyz(x, y, z, colorSpace, referenceWhite);
x = Math.min(Math.max(x, 0), 1);
y = Math.min(Math.max(y, 0), 1);
z = Math.min(Math.max(z, 0), 1);
return new Colors.xyz(x, y, z);
};

@@ -929,11 +912,14 @@ /**

*/
Convert.xyz2rgb = function (xyz, round, bitDepth) {
Convert.xyz2rgb = function (xyz, colorSpace, referenceWhite, round, bitDepth) {
if (colorSpace === void 0) { colorSpace = 'srgb'; }
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
if (round === void 0) { round = true; }
if (bitDepth === void 0) { bitDepth = 8; }
if (typeof Reference_1.colorSpaces[xyz.colorSpace] == 'undefined' ||
typeof Reference_1.colorSpaces[xyz.colorSpace]['xyz2rgb'] == 'undefined' ||
typeof Reference_1.colorSpaces[xyz.colorSpace]['xyz2rgb'][xyz.referenceWhite] == 'undefined') {
var space = Util_1.default.validColorSpace(colorSpace);
referenceWhite = referenceWhite.toLowerCase();
if (typeof space['rgb2xyz'] == 'undefined' ||
typeof space['rgb2xyz'][referenceWhite] == 'undefined') {
throw new Error('Transformation matrix unavailable for this color space and reference white');
}
var m = Reference_1.colorSpaces[xyz.colorSpace]['xyz2rgb'][xyz.referenceWhite];
var m = space['rgb2xyz'][referenceWhite];
// [R] [X]

@@ -979,2 +965,3 @@ // [G] = [M]*[Y] where [M] is [RGB to XYZ matrix]^-1

* Convert XYZ to xyY
* If X = Z = Y = 0, set x and y to chromaticity coordinates of reference white
*

@@ -984,3 +971,5 @@ * @param {Colors.xyz} xyz

*/
Convert.xyz2xyy = function (xyz) {
Convert.xyz2xyy = function (xyz, referenceWhite) {
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
var w = Util_1.default.validReferenceWhite(referenceWhite);
var cx;

@@ -990,4 +979,4 @@ var cy;

if (!sum) {
cx = 0;
cy = 0;
cx = w.x;
cy = w.y;
}

@@ -998,3 +987,3 @@ else {

}
return new Colors.xyy(cx, cy, xyz.y, xyz.colorSpace, xyz.referenceWhite);
return new Colors.xyy(cx, cy, xyz.y);
};

@@ -1017,3 +1006,3 @@ /**

}
return new Colors.xyz(cx, xyy.y, cz, xyy.colorSpace, xyy.referenceWhite);
return new Colors.xyz(cx, xyy.y, cz);
};

@@ -1025,9 +1014,13 @@ /////////// Lab ///////////

* @param {Colors.xyz} xyz
* @param {string} referenceWhite
* @param {boolean} [round=true]
* @return {Colors.lab}
*/
Convert.xyz2lab = function (xyz) {
var w = Util_1.default.validReferenceWhite(xyz.referenceWhite);
var xr = xyz.x / w[0];
var yr = xyz.y / w[1];
var zr = xyz.z / w[2];
Convert.xyz2lab = function (xyz, referenceWhite, round) {
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
if (round === void 0) { round = true; }
var w = Util_1.default.validReferenceWhite(referenceWhite);
var xr = xyz.x / w.x;
var yr = xyz.y / w.y;
var zr = xyz.z / w.z;
var fx = xyz.x > Reference_1.cieE ? Math.pow(xr, 1 / 3) : (Reference_1.cieK * xr + 16) / 116;

@@ -1039,3 +1032,8 @@ var fy = xyz.y > Reference_1.cieE ? Math.pow(yr, 1 / 3) : (Reference_1.cieK * yr + 16) / 116;

var b = 200 * (fy - fz);
return new Colors.lab(l, a, b, xyz.colorSpace, xyz.referenceWhite);
if (round) {
l = Math.round(l);
a = Math.round(a);
b = Math.round(b);
}
return new Colors.lab(l, a, b);
};

@@ -1048,4 +1046,5 @@ /**

*/
Convert.lab2xyz = function (lab) {
var w = Util_1.default.validReferenceWhite(lab.referenceWhite);
Convert.lab2xyz = function (lab, referenceWhite) {
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
var w = Util_1.default.validReferenceWhite(referenceWhite);
var fy = (lab.l + 16) / 116;

@@ -1057,6 +1056,6 @@ var fx = lab.a / 500 + fy;

var zr = Math.pow(fz, 3) > Reference_1.cieE ? Math.pow(fz, 3) : (116 * fz - 16) / Reference_1.cieK;
var x = xr * w[0];
var y = yr * w[1];
var z = zr * w[2];
return new Colors.xyz(x, y, z, lab.colorSpace, lab.referenceWhite);
var x = xr * w.x;
var y = yr * w.y;
var z = zr * w.z;
return new Colors.xyz(x, y, z);
};

@@ -1072,5 +1071,7 @@ /////////// Luv ///////////

*/
Convert.xyz2luv = function (xyz) {
var w = Util_1.default.validReferenceWhite(xyz.referenceWhite);
var yr = xyz.y / w[1];
Convert.xyz2luv = function (xyz, referenceWhite, round) {
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
if (round === void 0) { round = true; }
var w = Util_1.default.validReferenceWhite(referenceWhite);
var yr = xyz.y / w.y;
var div = xyz.x + 15 * xyz.y + 3 * xyz.z;

@@ -1086,8 +1087,13 @@ var up, vp;

}
var upr = (4 * w[0]) / (w[0] + 15 * w[1] + 3 * w[2]);
var vpr = (9 * w[1]) / (w[0] + 15 * w[1] + 3 * w[2]);
var upr = (4 * w.x) / (w.x + 15 * w.y + 3 * w.z);
var vpr = (9 * w.y) / (w.x + 15 * w.y + 3 * w.z);
var l = yr > Reference_1.cieE ? 116 * Math.pow(yr, 1 / 3) - 16 : Reference_1.cieK * yr;
var u = 13 * l * (up - upr);
var v = 13 * l * (vp - vpr);
return new Colors.luv(l, u, v, xyz.colorSpace, xyz.referenceWhite);
if (round) {
l = Math.round(l);
u = Math.round(u);
v = Math.round(v);
}
return new Colors.luv(l, u, v);
};

@@ -1101,6 +1107,7 @@ /**

*/
Convert.luv2xyz = function (luv) {
var w = Util_1.default.validReferenceWhite(luv.referenceWhite);
var u0 = (4 * w[0]) / (w[0] + 15 * w[1] + 3 * w[2]);
var v0 = (9 * w[0]) / (w[0] + 15 * w[1] + 3 * w[2]);
Convert.luv2xyz = function (luv, referenceWhite) {
if (referenceWhite === void 0) { referenceWhite = 'd65'; }
var w = Util_1.default.validReferenceWhite(referenceWhite);
var u0 = (4 * w.x) / (w.x + 15 * w.y + 3 * w.z);
var v0 = (9 * w.y) / (w.x + 15 * w.y + 3 * w.z);
var y = luv.l > Reference_1.cieK * Reference_1.cieE ? Math.pow((luv.l + 16) / 116, 3) : luv.l / Reference_1.cieK;

@@ -1113,3 +1120,3 @@ var a = 1 / 3 * (((52 * luv.l) / (luv.u + 13 * luv.l * u0)) - 1);

var z = x * a + b;
return new Colors.xyz(x, y, z, luv.colorSpace, luv.referenceWhite);
return new Colors.xyz(x, y, z);
};

@@ -1116,0 +1123,0 @@ /////////// YCbCr and STANDARDS ///////////

@@ -121,9 +121,9 @@ "use strict";

case 'xyz':
return new Colors.xyz(value[0], value[1], value[2], args.colorSpace, args.referenceWhite);
return new Colors.xyz(value[0], value[1], value[2]);
case 'xyy':
return new Colors.xyy(value[0], value[1], value[2], args.colorSpace, args.referenceWhite);
return new Colors.xyy(value[0], value[1], value[2]);
case 'lab':
return new Colors.lab(value[0], value[1], value[2], args.colorSpace, args.referenceWhite);
return new Colors.lab(value[0], value[1], value[2]);
case 'luv':
return new Colors.luv(value[0], value[1], value[2], args.colorSpace, args.referenceWhite);
return new Colors.luv(value[0], value[1], value[2]);
case 'ypbpr':

@@ -130,0 +130,0 @@ if (typeof args.kb == 'undefined' || typeof args.kr == 'undefined') {

@@ -19,2 +19,7 @@ /**

export declare const cieK: number;
export interface referenceWhite {
x: number;
y: number;
z: number;
}
export declare const stdIlluminants: {

@@ -21,0 +26,0 @@ a: {

@@ -0,1 +1,2 @@

import { referenceWhite } from './Reference';
declare class Util {

@@ -77,3 +78,4 @@ /**

*/
static validReferenceWhite(referenceWhite: string | number[]): number[];
static validReferenceWhite(referenceWhite: string | referenceWhite): referenceWhite;
static validColorSpace(colorSpace: string): object;
/**

@@ -80,0 +82,0 @@ * Floating point modulo function

@@ -183,7 +183,6 @@ "use strict";

referenceWhite = referenceWhite.toLowerCase();
if (typeof Reference_1.stdIlluminants[referenceWhite] == 'undefined' ||
typeof Reference_1.stdIlluminants[referenceWhite]['vector'] == 'undefined') {
throw new Error('Invalid reference white, vector not found');
if (typeof Reference_1.stdIlluminants[referenceWhite] == 'undefined') {
throw new Error('Invalid reference white');
}
w = Reference_1.stdIlluminants[referenceWhite]['vector'];
w = Reference_1.stdIlluminants[referenceWhite]['chrom']['2d'];
}

@@ -193,4 +192,37 @@ else {

}
return w;
var z = 1 - w['x'] - w['y'];
return {
x: w['x'],
y: w['y'],
z: z
};
};
Util.validColorSpace = function (colorSpace) {
// make lowercase, include common nomenclature differences, ignore spaces, etc
colorSpace = colorSpace.toLowerCase().replace(/[^a-z0-9]/, '');
var conform = {
'adobe': 'adobergb1998',
'adobergb': 'adobergb1998',
'ntsc': 'ntscrgb',
'palsecam': 'palsecamrgb',
'pal': 'palsecamrgb',
'palrgb': 'palsecamrgb',
'secam': 'palsecamrgb',
'secamrgb': 'palsecamrgb',
'prophoto': 'prophotorgb',
'smpte': 'smptecrgb',
'smptec': 'smptecrgb',
'widegamut': 'widegamutrgb',
'ecirgbv2': 'ecirgb',
'ektaspace': 'ektaspaceps5'
};
if (typeof conform[colorSpace] == 'string') {
colorSpace = conform[colorSpace];
}
if (typeof Reference_1.colorSpaces[colorSpace] == 'undefined') {
throw new Error('Unable to parse given color space');
}
var space = Reference_1.colorSpaces[colorSpace];
return space;
};
/**

@@ -197,0 +229,0 @@ * Floating point modulo function

{
"name": "chromaticity-color-utilities",
"version": "0.2.1-alpha",
"version": "0.2.4-alpha",
"description": "Color utilities for Node.js",

@@ -5,0 +5,0 @@ "main": "dist/main.js",

@@ -403,13 +403,10 @@ # chromaticity-color-utilities

Available Color Spaces and Stardard Illuminants below.
When converting to most color types, you must supply color space and standard illuminant reference white. Available Color Spaces and Stardard Illuminants below.
```ts
Color.from('xyz', [x, y, z], {
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
})
Color.from('xyz', [x, y, z])
.to('xyz',{
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
colorSpace: string, // optional, default = 'srgb' -- ignored if converting from xyy, lab, luv
referenceWhite: string // optional, default = 'd65' -- ignored if converting from xyy
})

@@ -421,3 +418,4 @@

let color4 = Color.from('xyz', [0.7589799, 0.3743439, 0.7643198], {
let color4 = color1.to('rgb')
let color5 = color1.to('rgb', {
colorSpace: 'adobergb',

@@ -432,13 +430,10 @@ referenceWhite: 'd50'

Available Color Spaces and Stardard Illuminants below.
When converting to most color types, you must supply color space and standard illuminant reference white. Available Color Spaces and Stardard Illuminants below.
```ts
Color.from('xyy', [x, y, Y], {
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
})
Color.from('xyy', [x, y, Y])
.to('xyy',{
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
colorSpace: string, // optional, defaults to 'srgb' -- ignored if converting from xyz
referenceWhite: string // optional, defaults to 'd65'
})

@@ -449,11 +444,2 @@

let color3 = color2.to('xyy')
let color4 = Color.from('xyz', [
0.39995913879719036,
0.1972677588141419,
0.3743439
], {
colorSpace: 'adobergb',
referenceWhite: 'd50'
})
```

@@ -469,28 +455,19 @@

Available Color Spaces and Stardard Illuminants below.
When converting to most color types, you must supply color space and standard illuminant reference white. Available Color Spaces and Stardard Illuminants below.
```ts
Color.from('lab', [l, a, b], {
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
})
Color.from('lab', [l, a, b])
.to('lab',{
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
colorSpace: string, // optional, defaults to 'srgb' -- ignored if converting from xyz, luv
referenceWhite: string, // optional, defaults to 'd65'
round: boolean // optional, defaults to true
})
// e.g.
let color1 = Color.from('lab',[
60.32421212836874,
98.23431188800397,
-60.82489220885006
])
let color1 = Color.from('lab',[95, 142, -88])
let color3 = color2.to('lab')
let color4 = Color.from('lab', [
67.60166164169028,
101.30709261827131,
-5.488771094285516
], {
let color4 = color1.to('rgb')
let color5 = color1.to('rgb', {
colorSpace: 'adobergb',

@@ -503,30 +480,21 @@ referenceWhite: 'd50'

Derived from XYZ. L\* is identical to L\* in L\*a\*b\*
Derived from XYZ. L\*, luma, is identical to L\* in L\*a\*b\*
Available Color Spaces and Stardard Illuminants below.
When converting to most color types, you must supply color space and standard illuminant reference white. Available Color Spaces and Stardard Illuminants below.
```ts
Color.from('luv', [l, u, v], {
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
})
Color.from('luv', [l, u, v])
.to('luv',{
colorSpace: string, // optional, default = 'srgb'
referenceWhite: string // optional, default = 'd65'
colorSpace: string, // optional, default = 'srgb' -- ignored if converting from xyz, lab
referenceWhite: string, // optional, default = 'd65'
round: boolean // optional, defaults to true
})
// e.g.
let color1 = Color.from('luv',[
60.32421212836874,
84.07139572483507,
-108.68333851910185
])
let color1 = Color.from('luv',[95, 132, -170])
let color3 = color2.to('luv')
let color4 = Color.from('luv', [
67.60166164169028,
124.0201282170453,
-87.3117870588082
], {
let color4 = color1.to('rgb')
let color5 = color1.to('rgb', {
colorSpace: 'adobergb',

@@ -1549,6 +1517,18 @@ referenceWhite: 'd50'

If X = Y = Z = 0, x and y are set to the chromaticity coordinates of the reference white.
<!--
\begin{align*}
x &= \frac{X}{X + Y + Z} \\
y &= \frac{Y}{X + Y + Z} \\
x &=
\begin{cases}
W_X & \text{ if } X = Y = Z = 0 \\
\frac{X}{X + Y + Z} & \text{ otherwise }
\end{cases}
\\
y &=
\begin{cases}
W_Y & \text{ if } X = Y = Z = 0 \\
\frac{Y}{X + Y + Z} & \text{ otherwise }
\end{cases}
\\
Y &= Y

@@ -1756,3 +1736,3 @@ \end{align*}

Where v is a tensor of XYZ color matching vectors for wavelengths in 5nm increments from 380nm to 780nm and T is the given temperature in Kelvin. Trapezoid integration is used to sum the the XYZ values from a black body spectrum generated from the tensor v based on temperature. <sup>[[9]](#references)</sup>
Where v is a tensor of XYZ color matching vectors for wavelengths in 5nm increments from 380nm to 780nm and T is the given temperature in Kelvin. Trapezoid integration is used to sum the XYZ values from a black body spectrum generated from the tensor v based on temperature. <sup>[[9]](#references)</sup>

@@ -1860,2 +1840,3 @@ In other words, a black body emission spectrum is generated for a given temperature, from which a summation of each XYZ set of values in the spectrum, normalized, gives an average XYZ, the mish-mash of wavelengths that we perceive as a single color. Then that XYZ color is simply converted to RGB.

* Integrate my references better. :)
* Turn readme into a documentation mini-site, it's too loooooooong

@@ -1862,0 +1843,0 @@ ## References

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc