chromaticity-color-utilities
Advanced tools
Comparing version 0.7.3-alpha to 0.8.0-alpha
@@ -10,3 +10,3 @@ import { newColorArgs, colorType } from './ColorType'; | ||
constructor(r: number, g: number, b: number, a?: number, gamma?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
} | ||
@@ -17,3 +17,3 @@ export declare class hex extends colorType { | ||
constructor(hex: string | number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -31,3 +31,3 @@ protected tohex(args: newColorArgs): hex; | ||
constructor(r: number, g: number, b: number, a?: number, bitDepth?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -44,3 +44,3 @@ } | ||
constructor(r: number, g: number, b: number, a?: number, bitDepth?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -58,3 +58,3 @@ protected torec709(args: newColorArgs): rec709rgb; | ||
constructor(r: number, g: number, b: number, a?: number, bitDepth?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -70,3 +70,3 @@ protected torec2020(args: newColorArgs): rec2020rgb; | ||
constructor(h: number, s: number, v: number, a?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -83,3 +83,3 @@ protected tohsv(args: newColorArgs): hsv; | ||
constructor(h: number, s: number, l: number, a?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -96,3 +96,3 @@ protected tohsv(args: newColorArgs): hsv; | ||
constructor(h: number, s: number, i: number, a?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -111,3 +111,3 @@ protected tohsi(args: newColorArgs): hsi; | ||
constructor(h: number, s: number, p: number, a?: number, pb?: number, pr?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -123,3 +123,3 @@ protected tohsp(args: newColorArgs): hsp; | ||
constructor(c: number, m: number, y: number, k: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -143,3 +143,3 @@ protected tocmyk(args: newColorArgs): cmyk; | ||
constructor(y: number, i: number, q: number, normalized?: boolean); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -154,3 +154,3 @@ protected toyiq(args: newColorArgs): yiq; | ||
constructor(x: number, y: number, z: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -166,3 +166,3 @@ protected toxyz(args: newColorArgs): xyz; | ||
protected torgb(args: newColorArgs): rgb; | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected toxyz(args: newColorArgs): xyz; | ||
@@ -183,3 +183,3 @@ protected toxyy(args: newColorArgs): xyy; | ||
constructor(l: number, a: number, b: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -201,3 +201,3 @@ protected toxyz(args: newColorArgs): xyz; | ||
constructor(l: number, u: number, v: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -215,3 +215,3 @@ protected toxyz(args: newColorArgs): xyz; | ||
constructor(y: number, pb: number, pr: number, kb: number, kr: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -231,3 +231,3 @@ protected toypbpr(args: newColorArgs): ypbpr; | ||
constructor(y: number, cb: number, cr: number, yLower?: number, yUpper?: number, cLower?: number, cUpper?: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -241,3 +241,3 @@ protected toypbpr(args: newColorArgs): ypbpr; | ||
constructor(wavelength: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -249,4 +249,4 @@ } | ||
constructor(k: number); | ||
toString(): string; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
} |
@@ -45,2 +45,9 @@ "use strict"; | ||
_this.type = 'rgbNormalized'; | ||
_this.toStringValues = function () { return ({ | ||
r: _this.r, | ||
g: _this.g, | ||
b: _this.b, | ||
a: _this.a, | ||
gamma: _this.gamma | ||
}); }; | ||
_this.valueRangeCheck(r, 0, 1); | ||
@@ -60,5 +67,2 @@ _this.valueRangeCheck(g, 0, 1); | ||
} | ||
rgbNormalized.prototype.toString = function () { | ||
return "rgbNormalized: { r: ".concat(this.r, ", g: ").concat(this.g, ", b: ").concat(this.b, ", a: ").concat(this.a, ", gamma: ").concat(this.gamma, " }"); | ||
}; | ||
return rgbNormalized; | ||
@@ -72,2 +76,5 @@ }(ColorType_1.colorType)); | ||
_this.type = 'hex'; | ||
_this.toStringValues = function () { return ({ | ||
hex: _this.hex | ||
}); }; | ||
if (typeof hex === 'string') { | ||
@@ -98,5 +105,2 @@ if (hex.charAt(0) == '#') { | ||
} | ||
hex.prototype.toString = function () { | ||
return "hex: { hex: ".concat(this.hex, " }"); | ||
}; | ||
hex.prototype.torgb = function (args) { | ||
@@ -117,2 +121,9 @@ return Convert_1.default.hex2rgb(this, args.bitDepth); | ||
_this.type = 'rgb'; | ||
_this.toStringValues = function () { return ({ | ||
r: _this.r, | ||
g: _this.g, | ||
b: _this.b, | ||
a: _this.a, | ||
bitDepth: _this.bitDepth | ||
}); }; | ||
_this.valueRangeCheck(bitDepth, 1, false, 'Bit depth must be a positive number greater than 1'); | ||
@@ -134,5 +145,2 @@ var max = Math.pow(2, bitDepth) - 1; | ||
} | ||
rgb.prototype.toString = function () { | ||
return "rgb: { r: ".concat(this.r, ", g: ").concat(this.g, ", b: ").concat(this.b, ", a: ").concat(this.a, ", bitDepth: ").concat(this.bitDepth, " }"); | ||
}; | ||
rgb.prototype.torgb = function (args) { | ||
@@ -156,2 +164,9 @@ if (args.round !== false) { | ||
_this.type = 'rec709rgb'; | ||
_this.toStringValues = function () { return ({ | ||
r: _this.r, | ||
g: _this.g, | ||
b: _this.b, | ||
a: _this.a, | ||
bitDepth: _this.bitDepth | ||
}); }; | ||
if (bitDepth != 8 && bitDepth != 10) { | ||
@@ -182,5 +197,2 @@ throw new Error('Invalid bitrate for Rec709, must be 8 or 10'); | ||
} | ||
rec709rgb.prototype.toString = function () { | ||
return "rec709rgb: { r: ".concat(this.r, ", g: ").concat(this.g, ", b: ").concat(this.b, ", a: ").concat(this.a, ", bitDepth: ").concat(this.bitDepth, " }"); | ||
}; | ||
rec709rgb.prototype.torgb = function (args) { | ||
@@ -207,2 +219,9 @@ return Convert_1.default.rec709rgb2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'rec2020rgb'; | ||
_this.toStringValues = function () { return ({ | ||
r: _this.r, | ||
g: _this.g, | ||
b: _this.b, | ||
a: _this.a, | ||
bitDepth: _this.bitDepth | ||
}); }; | ||
if (bitDepth != 10 && bitDepth != 12) { | ||
@@ -233,5 +252,2 @@ throw new Error('Invalid bitrate for Rec2020, must be 10 or 12'); | ||
} | ||
rec2020rgb.prototype.toString = function () { | ||
return "rec2020rgb: { r: ".concat(this.r, ", g: ").concat(this.g, ", b: ").concat(this.b, ", a: ").concat(this.a, ", bitDepth: ").concat(this.bitDepth, " }"); | ||
}; | ||
rec2020rgb.prototype.torgb = function (args) { | ||
@@ -258,2 +274,8 @@ return Convert_1.default.rec2020rgb2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'hsv'; | ||
_this.toStringValues = function () { return ({ | ||
h: _this.h, | ||
s: _this.s, | ||
v: _this.v, | ||
a: _this.a | ||
}); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -269,5 +291,2 @@ _this.valueRangeCheck(s, 0, 100); | ||
} | ||
hsv.prototype.toString = function () { | ||
return "hsv: { h: ".concat(this.h, ", s: ").concat(this.s, ", v: ").concat(this.v, ", a: ").concat(this.a, " }"); | ||
}; | ||
hsv.prototype.torgb = function (args) { | ||
@@ -297,2 +316,8 @@ return Convert_1.default.hsv2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'hsl'; | ||
_this.toStringValues = function () { return ({ | ||
h: _this.h, | ||
s: _this.s, | ||
l: _this.l, | ||
a: _this.a | ||
}); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -308,5 +333,2 @@ _this.valueRangeCheck(s, 0, 100); | ||
} | ||
hsl.prototype.toString = function () { | ||
return "hsl: { h: ".concat(this.h, ", s: ").concat(this.s, ", l: ").concat(this.l, ", a: ").concat(this.a, " }"); | ||
}; | ||
hsl.prototype.torgb = function (args) { | ||
@@ -336,2 +358,8 @@ return Convert_1.default.hsl2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'hsi'; | ||
_this.toStringValues = function () { return ({ | ||
h: _this.h, | ||
s: _this.s, | ||
i: _this.i, | ||
a: _this.a | ||
}); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -347,5 +375,2 @@ _this.valueRangeCheck(s, 0, 100); | ||
} | ||
hsi.prototype.toString = function () { | ||
return "hsi: { h: ".concat(this.h, ", s: ").concat(this.s, ", i: ").concat(this.i, ", a: ").concat(this.a, " }"); | ||
}; | ||
hsi.prototype.torgb = function (args) { | ||
@@ -380,2 +405,10 @@ return Convert_1.default.hsi2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'hsp'; | ||
_this.toStringValues = function () { return ({ | ||
h: _this.h, | ||
s: _this.s, | ||
p: _this.p, | ||
a: _this.a, | ||
pb: _this.pb, | ||
pr: _this.pr | ||
}); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -393,9 +426,6 @@ _this.valueRangeCheck(s, 0, 100); | ||
_this.pr = pr; | ||
_this.pb = pb; | ||
_this.pg = 1 - pr - pb; | ||
_this.pb = pb; | ||
return _this; | ||
} | ||
hsp.prototype.toString = function () { | ||
return "hsp: { h: ".concat(this.h, ", s: ").concat(this.s, ", p: ").concat(this.p, ", a: ").concat(this.a, ", pr: ").concat(this.pr, ", pg: ").concat(this.pg, ", pb: ").concat(this.pb, " }"); | ||
}; | ||
hsp.prototype.torgb = function (args) { | ||
@@ -421,2 +451,8 @@ return Convert_1.default.hsp2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'cmyk'; | ||
_this.toStringValues = function () { return ({ | ||
c: _this.c, | ||
m: _this.m, | ||
y: _this.y, | ||
k: _this.k, | ||
}); }; | ||
_this.valueRangeCheck(c, 0, 100, 'CMYK values must be between 0 and 100'); | ||
@@ -432,5 +468,2 @@ _this.valueRangeCheck(m, 0, 100, 'CMYK values must be between 0 and 100'); | ||
} | ||
cmyk.prototype.toString = function () { | ||
return "cmyk: { c: ".concat(this.c, ", m: ").concat(this.m, ", y: ").concat(this.y, ", k: ").concat(this.k, " }"); | ||
}; | ||
cmyk.prototype.torgb = function (args) { | ||
@@ -465,2 +498,8 @@ return Convert_1.default.cmyk2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'yiq'; | ||
_this.toStringValues = function () { return ({ | ||
y: _this.y, | ||
i: _this.i, | ||
q: _this.q, | ||
normalized: _this.normalized, | ||
}); }; | ||
if (normalized) { | ||
@@ -482,5 +521,2 @@ _this.valueRangeCheck(y, 0, 255, 'Normalized Y value must be between 0 and 255'); | ||
} | ||
yiq.prototype.toString = function () { | ||
return "yiq: { y: ".concat(this.y, ", i: ").concat(this.i, ", q: ").concat(this.q, ", normalized: ").concat(this.normalized, " }"); | ||
}; | ||
yiq.prototype.torgb = function (args) { | ||
@@ -505,2 +541,7 @@ return Convert_1.default.yiq2rgb(this, args.round, args.bitDepth); | ||
_this.type = 'xyz'; | ||
_this.toStringValues = function () { return ({ | ||
x: _this.x, | ||
y: _this.y, | ||
z: _this.z, | ||
}); }; | ||
// this.valueRangeCheck(x, 0, 1, 'XYZ values must be between 0 and 1') | ||
@@ -514,5 +555,2 @@ // this.valueRangeCheck(y, 0, 1, 'XYZ values must be between 0 and 1') | ||
} | ||
xyz.prototype.toString = function () { | ||
return "xyz: { x: ".concat(this.x, ", y: ").concat(this.y, ", z: ").concat(this.z, " }"); | ||
}; | ||
xyz.prototype.torgb = function (args) { | ||
@@ -532,2 +570,7 @@ return Convert_1.default.xyz2rgb(this, args.colorSpace, args.referenceWhite, args.round, args.bitDepth); | ||
_this.type = 'xyy'; | ||
_this.toStringValues = function () { return ({ | ||
x: _this.x, | ||
y: _this.y, | ||
yy: _this.yy, | ||
}); }; | ||
_this.x = x; | ||
@@ -541,5 +584,2 @@ _this.y = y; | ||
}; | ||
xyy.prototype.toString = function () { | ||
return "xyy: { x: ".concat(this.x, ", y: ").concat(this.y, ", yy: ").concat(this.yy, " }"); | ||
}; | ||
xyy.prototype.toxyz = function (args) { | ||
@@ -565,2 +605,7 @@ return Convert_1.default.xyy2xyz(this); | ||
_this.type = 'lab'; | ||
_this.toStringValues = function () { return ({ | ||
l: _this.l, | ||
a: _this.a, | ||
b: _this.b, | ||
}); }; | ||
_this.valueRangeCheck(l, 0, 100); | ||
@@ -576,5 +621,2 @@ if (typeof a === 'undefined') | ||
} | ||
lab.prototype.toString = function () { | ||
return "lab: { l: ".concat(this.l, ", a: ").concat(this.a, ", b: ").concat(this.b, " }"); | ||
}; | ||
lab.prototype.torgb = function (args) { | ||
@@ -608,2 +650,7 @@ return Convert_1.default.xyz2rgb(this.toxyz(args), args.colorSpace, args.referenceWhite, args.round, args.bitDepth); | ||
_this.type = 'luv'; | ||
_this.toStringValues = function () { return ({ | ||
l: _this.l, | ||
u: _this.u, | ||
v: _this.v, | ||
}); }; | ||
_this.valueRangeCheck(l, 0, 100); | ||
@@ -621,5 +668,2 @@ // this.valueRangeCheck(u, -100, 100) | ||
} | ||
luv.prototype.toString = function () { | ||
return "luv: { l: ".concat(this.l, ", u: ").concat(this.u, ", v: ").concat(this.v, " }"); | ||
}; | ||
luv.prototype.torgb = function (args) { | ||
@@ -647,2 +691,9 @@ return Convert_1.default.xyz2rgb(this.toxyz(args), args.colorSpace, args.referenceWhite, args.round, args.bitDepth); | ||
_this.type = 'ypbpr'; | ||
_this.toStringValues = function () { return ({ | ||
y: _this.y, | ||
pb: _this.pb, | ||
pr: _this.pr, | ||
kb: _this.kb, | ||
kr: _this.kr, | ||
}); }; | ||
_this.valueRangeCheck(y, 0, 1); | ||
@@ -658,5 +709,2 @@ _this.valueRangeCheck(pb, -0.5, 0.5); | ||
} | ||
ypbpr.prototype.toString = function () { | ||
return "ypbpr: { y: ".concat(this.y, ", pb: ").concat(this.pb, ", pr: ").concat(this.pr, ", kb: ").concat(this.kb, ", kr: ").concat(this.kr, " }"); | ||
}; | ||
ypbpr.prototype.torgb = function (args) { | ||
@@ -688,2 +736,11 @@ if (typeof args.kb === 'undefined' || typeof args.kr === 'undefined') { | ||
_this.type = 'ycbcr'; | ||
_this.toStringValues = function () { return ({ | ||
y: _this.y, | ||
cb: _this.cb, | ||
cr: _this.cr, | ||
yLower: _this.yLower, | ||
yUpper: _this.yUpper, | ||
cLower: _this.cLower, | ||
cUpper: _this.cUpper, | ||
}); }; | ||
_this.y = y; | ||
@@ -706,5 +763,2 @@ _this.cb = cb; | ||
} | ||
ycbcr.prototype.toString = function () { | ||
return "ycbcr: { y: ".concat(this.y, ", cb: ").concat(this.cb, ", cr: ").concat(this.cr, ", yLower: ").concat(this.yLower, ", yUpper: ").concat(this.yUpper, ", cLower: ").concat(this.cLower, ", cUpper: ").concat(this.cUpper, " }"); | ||
}; | ||
ycbcr.prototype.torgb = function (args) { | ||
@@ -738,2 +792,5 @@ if (typeof args.kb === 'undefined' || typeof args.kr === 'undefined') { | ||
_this.type = 'nm'; | ||
_this.toStringValues = function () { return ({ | ||
wavelength: _this.wavelength, | ||
}); }; | ||
_this.valueRangeCheck(wavelength, 200, 800, 'Wavelength (in nm) must fall between 200 and 800'); | ||
@@ -743,5 +800,2 @@ _this.wavelength = wavelength; | ||
} | ||
nm.prototype.toString = function () { | ||
return "nm: { wavelength: ".concat(this.wavelength, " }"); | ||
}; | ||
nm.prototype.torgb = function (args) { | ||
@@ -758,2 +812,5 @@ return Convert_1.default.nm2rgb(this, args.gamma, args.round, args.bitDepth); | ||
_this.type = 'kelvin'; | ||
_this.toStringValues = function () { return ({ | ||
k: _this.k, | ||
}); }; | ||
_this.valueRangeCheck(k, 1000, 40000, 'Temperature must fall between 1000 and 40000'); | ||
@@ -763,5 +820,2 @@ _this.k = k; | ||
} | ||
kelvin.prototype.toString = function () { | ||
return "kelvin: { k: ".concat(this.k, " }"); | ||
}; | ||
kelvin.prototype.torgb = function (args) { | ||
@@ -768,0 +822,0 @@ return Convert_1.default.kelvin2rgb(this, args.round, args.bitDepth); |
@@ -68,2 +68,16 @@ import * as Colors from './Colors'; | ||
a?: number; | ||
/** | ||
* Returns generic simplified object for toString() | ||
* Overwrite with each subclass | ||
* | ||
* @returns {object} | ||
*/ | ||
protected toStringValues: () => object; | ||
/** | ||
* Stringify object | ||
* | ||
* @param {string} whitespace equiv to third JSON.stringify parameter | ||
* @returns {string} | ||
*/ | ||
toString(whitespace?: string, quotes?: boolean): string; | ||
to<T extends colorType>(type: string, args?: newColorArgs): T; | ||
@@ -70,0 +84,0 @@ getType(): string; |
@@ -52,3 +52,25 @@ "use strict"; | ||
this.type = 'colorType'; | ||
/** | ||
* Returns generic simplified object for toString() | ||
* Overwrite with each subclass | ||
* | ||
* @returns {object} | ||
*/ | ||
this.toStringValues = function () { return ({}); }; | ||
} | ||
/** | ||
* Stringify object | ||
* | ||
* @param {string} whitespace equiv to third JSON.stringify parameter | ||
* @returns {string} | ||
*/ | ||
colorType.prototype.toString = function (whitespace, quotes) { | ||
if (quotes === void 0) { quotes = true; } | ||
var colon = whitespace ? ': ' : ':'; // only have a space if the string is whitespaced | ||
var json = JSON.stringify(this.toStringValues(), null, whitespace); | ||
if (!quotes) { | ||
json = json.replace(/"([^"]+)":/g, '$1:'); | ||
} | ||
return this.getType() + colon + json; | ||
}; | ||
colorType.prototype.to = function (type, args) { | ||
@@ -122,3 +144,3 @@ args = this.setArgs(args); | ||
throw new Error('Unable to find conversion path from ' + | ||
this.constructor.name + | ||
this.getType() + | ||
' to ' + | ||
@@ -136,3 +158,3 @@ type); | ||
args = {}; | ||
var og = this.constructor['name']; | ||
var og = this.getType(); | ||
var ogargs = { | ||
@@ -162,3 +184,8 @@ round: args.round, | ||
if (typeof args.method === 'undefined') { | ||
args.method = 'rgb'; | ||
if (['rgb', 'hsl', 'hsi', 'hsv', 'hsp', 'cmyk'].includes(og)) { | ||
args.method = og; | ||
} | ||
else { | ||
args.method = 'rgb'; | ||
} | ||
} | ||
@@ -180,2 +207,25 @@ var tmpColor1 = void 0, tmpColor2 = void 0; | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
tmpColor1 = this.tohsl({ round: false }); | ||
tmpColor2 = args.with.tohsl({ round: false }); | ||
modified = Modify_1.default.hslBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
tmpColor1 = this.tohsi({ round: false }); | ||
tmpColor2 = args.with.tohsi({ round: false }); | ||
modified = Modify_1.default.hsiBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
break; | ||
case 'hsp': | ||
case 'hspa': | ||
tmpColor1 = this.tohsp({ round: false }); | ||
tmpColor2 = args.with.tohsp({ round: false }); | ||
modified = Modify_1.default.hspBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
break; | ||
case 'cmyk': | ||
tmpColor1 = this.tocmyk({ round: false }); | ||
tmpColor2 = args.with.tocmyk({ round: false }); | ||
modified = Modify_1.default.cmykBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
break; | ||
default: | ||
@@ -188,3 +238,8 @@ throw new Error('Unrecognized blending method'); | ||
if (typeof args.method === 'undefined') { | ||
args.method = 'hsl'; | ||
if (['rgb', 'hsl', 'hsi', 'hsv', 'hsp', 'cmyk'].includes(og)) { | ||
args.method = og; | ||
} | ||
else { | ||
args.method = 'hsl'; | ||
} | ||
} | ||
@@ -201,2 +256,12 @@ switch (args.method) { | ||
break; | ||
case 'hsv': | ||
case 'hsva': | ||
case 'value': | ||
modified = Modify_1.default.hsvDarken(this.tohsv({ round: false }), args.amount, args.round); | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
case 'intensity': | ||
modified = Modify_1.default.hsiDarken(this.tohsi({ round: false }), args.amount, args.round); | ||
break; | ||
case 'hsp': | ||
@@ -210,2 +275,10 @@ case 'hspa': | ||
break; | ||
case 'cmyk': | ||
modified = Modify_1.default.cmykDarken(this.tocmyk({ round: false }), args.amount, args.round); | ||
break; | ||
case 'cmyk2': | ||
case 'black': | ||
case 'cmykBlack': | ||
modified = Modify_1.default.cmykBlackDarken(this.tocmyk({ round: false }), args.amount, args.round); | ||
break; | ||
default: | ||
@@ -218,3 +291,8 @@ throw new Error('Unrecognized darken method'); | ||
if (typeof args.method === 'undefined') { | ||
args.method = 'hsl'; | ||
if (['rgb', 'hsl', 'hsi', 'hsv', 'hsp', 'cmyk'].includes(og)) { | ||
args.method = og; | ||
} | ||
else { | ||
args.method = 'hsl'; | ||
} | ||
} | ||
@@ -231,2 +309,12 @@ switch (args.method) { | ||
break; | ||
case 'hsv': | ||
case 'hsva': | ||
case 'value': | ||
modified = Modify_1.default.hsvLighten(this.tohsv({ round: false }), args.amount, args.round); | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
case 'intensity': | ||
modified = Modify_1.default.hsiLighten(this.tohsi({ round: false }), args.amount, args.round); | ||
break; | ||
case 'hsp': | ||
@@ -240,2 +328,10 @@ case 'hspa': | ||
break; | ||
case 'cmyk': | ||
modified = Modify_1.default.cmykLighten(this.tocmyk({ round: false }), args.amount, args.round); | ||
break; | ||
case 'cmyk2': | ||
case 'black': | ||
case 'cmykBlack': | ||
modified = Modify_1.default.cmykBlackLighten(this.tocmyk({ round: false }), args.amount, args.round); | ||
break; | ||
default: | ||
@@ -297,3 +393,3 @@ throw new Error('Unrecognized lighten method'); | ||
args = {}; | ||
var og = this.constructor['name']; | ||
var og = this.getType(); | ||
var ogargs = { | ||
@@ -300,0 +396,0 @@ round: args.round, |
@@ -84,4 +84,12 @@ import * as Colors from './Colors'; | ||
static rgbLighten(rgb: Colors.rgb, amount?: number, round?: boolean): Colors.rgb; | ||
static cmykDarken(cmyk: Colors.cmyk, amount?: number, round?: boolean): Colors.cmyk; | ||
static cmykLighten(cmyk: Colors.cmyk, amount?: number, round?: boolean): Colors.cmyk; | ||
static cmykBlackDarken(cmyk: Colors.cmyk, amount?: number, round?: boolean): Colors.cmyk; | ||
static cmykBlackLighten(cmyk: Colors.cmyk, amount?: number, round?: boolean): Colors.cmyk; | ||
static hslDarken(hsl: Colors.hsl, amount?: number, round?: boolean): Colors.hsl; | ||
static hslLighten(hsl: Colors.hsl, amount?: number, round?: boolean): Colors.hsl; | ||
static hsvDarken(hsv: Colors.hsv, amount?: number, round?: boolean): Colors.hsv; | ||
static hsvLighten(hsv: Colors.hsv, amount?: number, round?: boolean): Colors.hsv; | ||
static hsiDarken(hsi: Colors.hsi, amount?: number, round?: boolean): Colors.hsi; | ||
static hsiLighten(hsi: Colors.hsi, amount?: number, round?: boolean): Colors.hsi; | ||
static hspDarken(hsp: Colors.hsp, amount?: number, round?: boolean): Colors.hsp; | ||
@@ -88,0 +96,0 @@ static hspLighten(hsp: Colors.hsp, amount?: number, round?: boolean): Colors.hsp; |
@@ -278,6 +278,6 @@ "use strict"; | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var rl = rgb.r + (100 - rgb.r) * realAmount; | ||
var gl = rgb.g + (100 - rgb.g) * realAmount; | ||
var bl = rgb.b + (100 - rgb.b) * realAmount; | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var rl = rgb.r + (rgb.max - rgb.r) * realAmount; | ||
var gl = rgb.g + (rgb.max - rgb.g) * realAmount; | ||
var bl = rgb.b + (rgb.max - rgb.b) * realAmount; | ||
if (round) { | ||
@@ -290,2 +290,54 @@ rl = Math.round(rl); | ||
}; | ||
Modify.cmykDarken = function (cmyk, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var c2 = cmyk.c + (100 - cmyk.c) * realAmount; | ||
var m2 = cmyk.m + (100 - cmyk.m) * realAmount; | ||
var y2 = cmyk.y + (100 - cmyk.y) * realAmount; | ||
var k2 = cmyk.k + (100 - cmyk.k) * realAmount; | ||
if (round) { | ||
c2 = Math.round(c2); | ||
m2 = Math.round(m2); | ||
y2 = Math.round(y2); | ||
k2 = Math.round(k2); | ||
} | ||
return new Colors.cmyk(c2, m2, y2, k2); | ||
}; | ||
Modify.cmykLighten = function (cmyk, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var c2 = cmyk.c * realAmount; | ||
var m2 = cmyk.m * realAmount; | ||
var y2 = cmyk.y * realAmount; | ||
var k2 = cmyk.k * realAmount; | ||
if (round) { | ||
c2 = Math.round(c2); | ||
m2 = Math.round(m2); | ||
y2 = Math.round(y2); | ||
k2 = Math.round(k2); | ||
} | ||
return new Colors.cmyk(c2, m2, y2, k2); | ||
}; | ||
Modify.cmykBlackDarken = function (cmyk, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var k2 = cmyk.k + (100 - cmyk.k) * realAmount; | ||
if (round) { | ||
k2 = Math.round(k2); | ||
} | ||
return new Colors.cmyk(cmyk.c, cmyk.m, cmyk.y, k2); | ||
}; | ||
Modify.cmykBlackLighten = function (cmyk, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var k2 = cmyk.k * realAmount; | ||
if (round) { | ||
k2 = Math.round(k2); | ||
} | ||
return new Colors.cmyk(cmyk.c, cmyk.m, cmyk.y, k2); | ||
}; | ||
Modify.hslDarken = function (hsl, amount, round) { | ||
@@ -309,2 +361,38 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
Modify.hsvDarken = function (hsv, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var vDarker = hsv.v * realAmount; | ||
if (round) | ||
vDarker = Math.round(vDarker); | ||
return new Colors.hsv(hsv.h, hsv.s, vDarker, hsv.a); | ||
}; | ||
Modify.hsvLighten = function (hsv, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var vLighter = hsv.v + (100 - hsv.v) * realAmount; | ||
if (round) | ||
vLighter = Math.round(vLighter); | ||
return new Colors.hsv(hsv.h, hsv.s, vLighter, hsv.a); | ||
}; | ||
Modify.hsiDarken = function (hsi, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var vDarker = hsi.i * realAmount; | ||
if (round) | ||
vDarker = Math.round(vDarker); | ||
return new Colors.hsi(hsi.h, hsi.s, vDarker, hsi.a); | ||
}; | ||
Modify.hsiLighten = function (hsi, amount, round) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var vLighter = hsi.i + (100 - hsi.i) * realAmount; | ||
if (round) | ||
vLighter = Math.round(vLighter); | ||
return new Colors.hsi(hsi.h, hsi.s, vLighter, hsi.a); | ||
}; | ||
Modify.hspDarken = function (hsp, amount, round) { | ||
@@ -311,0 +399,0 @@ if (amount === void 0) { amount = 0.5; } |
{ | ||
"name": "chromaticity-color-utilities", | ||
"version": "0.7.3-alpha", | ||
"version": "0.8.0-alpha", | ||
"description": "Color utilities for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
326534
7520
38