chromaticity-color-utilities
Advanced tools
Comparing version 0.12.1-alpha to 0.13.0-alpha
@@ -1044,3 +1044,3 @@ "use strict"; | ||
}); }; | ||
_this.valueRangeCheck(wavelength, 360, 820, 'Wavelength (in nm) must fall between 360 and 820'); | ||
_this.valueRangeCheck(wavelength, 380, 800, 'Wavelength (in nm) must fall between 380 and 800'); | ||
_this.wavelength = wavelength; | ||
@@ -1047,0 +1047,0 @@ return _this; |
@@ -47,2 +47,3 @@ "use strict"; | ||
var Modify_1 = __importDefault(require("./Modify")); | ||
var Blend_1 = __importDefault(require("./Blend")); | ||
var Harmony_1 = __importDefault(require("./Harmony")); | ||
@@ -94,3 +95,5 @@ var Colors = __importStar(require("./Colors")); | ||
*/ | ||
colorType.prototype.setAlpha = function (value) { return false; }; | ||
colorType.prototype.setAlpha = function (value) { | ||
return false; | ||
}; | ||
/** | ||
@@ -228,58 +231,107 @@ * Stringify object | ||
} | ||
args.method = args.method.toLowerCase().replace(' ', ''); | ||
var tmpColor1 = void 0, tmpColor2 = void 0; | ||
switch (args.method) { | ||
case 'rgb': | ||
case 'rgba': | ||
case 'hex': | ||
tmpColor1 = this.torgb({ round: false }); | ||
tmpColor2 = args.with.torgb({ round: false }); | ||
modified = Modify_1.default.rgbBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'hsv': | ||
case 'hsva': | ||
tmpColor1 = this.tohsv({ round: false }); | ||
tmpColor2 = args.with.tohsv({ round: false }); | ||
modified = Modify_1.default.hsvBlend(tmpColor1, tmpColor2, args.amount); | ||
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); | ||
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); | ||
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); | ||
break; | ||
case 'cmyk': | ||
tmpColor1 = this.tocmyk({ round: false }); | ||
tmpColor2 = args.with.tocmyk({ round: false }); | ||
modified = Modify_1.default.cmykBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'yiq': | ||
tmpColor1 = this.toyiq({ round: false }); | ||
tmpColor2 = args.with.toyiq({ round: false }); | ||
modified = Modify_1.default.yiqBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'lab': | ||
tmpColor1 = this.tolab({ round: false }); | ||
tmpColor2 = args.with.tolab({ round: false }); | ||
modified = Modify_1.default.labBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'luv': | ||
tmpColor1 = this.toluv({ round: false }); | ||
tmpColor2 = args.with.toluv({ round: false }); | ||
modified = Modify_1.default.luvBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
default: | ||
throw new Error('Unrecognized blending method: ' + args.method); | ||
if ([ | ||
'multiply', | ||
'screen', | ||
'overlay', | ||
'softlight', | ||
'colordodge', | ||
'colorburn', | ||
'vividlight', | ||
'lineardodge', | ||
'linearburn', | ||
'linearlight', | ||
'divide', | ||
'addition', | ||
'subtraction', | ||
'difference', | ||
].includes(args.method)) { | ||
tmpColor1 = this.torgb({ round: false }); | ||
tmpColor2 = args.with.torgb({ round: false }); | ||
modified = Blend_1.default.rgbBlendMode(tmpColor1, tmpColor2, args.amount, args.method); | ||
} | ||
else { | ||
switch (args.method) { | ||
case 'rgb': | ||
case 'rgba': | ||
case 'hex': | ||
tmpColor1 = this.torgb({ round: false }); | ||
tmpColor2 = args.with.torgb({ round: false }); | ||
modified = Blend_1.default.rgbBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'hue': | ||
tmpColor1 = this.tohsv({ round: false }); | ||
tmpColor2 = args.with.tohsv({ round: false }); | ||
modified = Blend_1.default.hueBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'hsv': | ||
case 'hsva': | ||
tmpColor1 = this.tohsv({ round: false }); | ||
tmpColor2 = args.with.tohsv({ round: false }); | ||
modified = Blend_1.default.hsvBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'value': | ||
tmpColor1 = this.tohsv({ round: false }); | ||
tmpColor2 = args.with.tohsv({ round: false }); | ||
modified = Blend_1.default.valueBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
tmpColor1 = this.tohsl({ round: false }); | ||
tmpColor2 = args.with.tohsl({ round: false }); | ||
modified = Blend_1.default.hslBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'lightness': | ||
tmpColor1 = this.tohsl({ round: false }); | ||
tmpColor2 = args.with.tohsl({ round: false }); | ||
modified = Blend_1.default.lightnessBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
tmpColor1 = this.tohsi({ round: false }); | ||
tmpColor2 = args.with.tohsi({ round: false }); | ||
modified = Blend_1.default.hsiBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'intensity': | ||
tmpColor1 = this.tohsi({ round: false }); | ||
tmpColor2 = args.with.tohsi({ round: false }); | ||
modified = Blend_1.default.intensityBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'hsp': | ||
case 'hspa': | ||
tmpColor1 = this.tohsp({ round: false }); | ||
tmpColor2 = args.with.tohsp({ round: false }); | ||
modified = Blend_1.default.hspBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'perceived': | ||
case 'perceivedbrightness': | ||
tmpColor1 = this.tohsp({ round: false }); | ||
tmpColor2 = args.with.tohsp({ round: false }); | ||
modified = Blend_1.default.perceivedBrightnessBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'cmyk': | ||
tmpColor1 = this.tocmyk({ round: false }); | ||
tmpColor2 = args.with.tocmyk({ round: false }); | ||
modified = Blend_1.default.cmykBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'yiq': | ||
tmpColor1 = this.toyiq({ round: false }); | ||
tmpColor2 = args.with.toyiq({ round: false }); | ||
modified = Blend_1.default.yiqBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'lab': | ||
tmpColor1 = this.tolab({ round: false }); | ||
tmpColor2 = args.with.tolab({ round: false }); | ||
modified = Blend_1.default.labBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
case 'luv': | ||
tmpColor1 = this.toluv({ round: false }); | ||
tmpColor2 = args.with.toluv({ round: false }); | ||
modified = Blend_1.default.luvBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
default: | ||
throw new Error('Unrecognized blending method: ' + args.method); | ||
} | ||
} | ||
break; | ||
@@ -620,3 +672,3 @@ case 'darken': | ||
args = { | ||
method: 'hex' | ||
method: 'hex', | ||
}; | ||
@@ -642,3 +694,5 @@ } | ||
// precision of alpha is ~1/256, or ~0.004 at best | ||
var rgbaAlpha = (rgba.getA() / rgba.getMax()).toPrecision(4).replace(/\.?0+$/, ''); | ||
var rgbaAlpha = (rgba.getA() / rgba.getMax()) | ||
.toPrecision(4) | ||
.replace(/\.?0+$/, ''); | ||
colorString = "rgba(".concat(rgba.getR(), ", ").concat(rgba.getG(), ", ").concat(rgba.getB(), ", ").concat(rgbaAlpha, ")"); | ||
@@ -653,3 +707,5 @@ break; | ||
// precision of alpha is ~1/256, or ~0.004 at best | ||
var hslaAlpha = (hsla.getA() / 100).toPrecision(4).replace(/\.?0+$/, ''); | ||
var hslaAlpha = (hsla.getA() / 100) | ||
.toPrecision(4) | ||
.replace(/\.?0+$/, ''); | ||
colorString = "hsla(".concat(hsla.getH(), ", ").concat(hsla.getS(), "%, ").concat(hsla.getL(), "%, ").concat(hslaAlpha, ")"); | ||
@@ -656,0 +712,0 @@ break; |
@@ -44,2 +44,3 @@ "use strict"; | ||
var Modify_1 = __importDefault(require("./Modify")); | ||
var Blend_1 = __importDefault(require("./Blend")); | ||
var Colors = __importStar(require("./Colors")); | ||
@@ -238,15 +239,15 @@ var Harmony = /** @class */ (function () { | ||
if (100 - hsl.getL() < hsl.getL()) { | ||
distanceShade = (100 - hsl.getL()) / 50 * distance; | ||
distanceShade = ((100 - hsl.getL()) / 50) * distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = hsl.getL() / 50 * distanceShade; | ||
distance = (hsl.getL() / 50) * distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.hslDarken(hsl, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hslDarken(hsl, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(hsl.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.hslLighten(hsl, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hslLighten(hsl, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -259,15 +260,15 @@ break; | ||
if (100 - hsv.getV() < hsv.getV()) { | ||
distanceShade = (100 - hsv.getV()) / 50 * distance; | ||
distanceShade = ((100 - hsv.getV()) / 50) * distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = hsv.getV() / 50 * distanceShade; | ||
distance = (hsv.getV() / 50) * distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.hsvDarken(hsv, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hsvDarken(hsv, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(hsv.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.hsvLighten(hsv, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hsvLighten(hsv, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -280,15 +281,15 @@ break; | ||
if (100 - hsi.getI() < hsi.getI()) { | ||
distanceShade = (100 - hsi.getI()) / 50 * distance; | ||
distanceShade = ((100 - hsi.getI()) / 50) * distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = hsi.getI() / 50 * distanceShade; | ||
distance = (hsi.getI() / 50) * distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.hsiDarken(hsi, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hsiDarken(hsi, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(hsi.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.hsiLighten(hsi, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hsiLighten(hsi, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -301,15 +302,15 @@ break; | ||
if (100 - hsp.getP() < hsp.getP()) { | ||
distanceShade = (100 - hsp.getP()) / 50 * distance; | ||
distanceShade = ((100 - hsp.getP()) / 50) * distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = hsp.getP() / 50 * distanceShade; | ||
distance = (hsp.getP() / 50) * distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.hspDarken(hsp, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hspDarken(hsp, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(hsp.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.hspLighten(hsp, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.hspLighten(hsp, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -323,15 +324,24 @@ break; | ||
if (rgb2.getMax() - avg < avg) { | ||
distanceShade = (rgb2.getMax() - Math.min(rgb2.getR(), rgb2.getG(), rgb2.getB())) / rgb2.getMax() / 2 * distance; | ||
distanceShade = | ||
((rgb2.getMax() - | ||
Math.min(rgb2.getR(), rgb2.getG(), rgb2.getB())) / | ||
rgb2.getMax() / | ||
2) * | ||
distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = Math.max(rgb2.getR(), rgb2.getG(), rgb2.getB()) / rgb2.getMax() / 2 * distanceShade; | ||
distance = | ||
(Math.max(rgb2.getR(), rgb2.getG(), rgb2.getB()) / | ||
rgb2.getMax() / | ||
2) * | ||
distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.rgb2Darken(rgb2, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.rgb2Darken(rgb2, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(rgb2.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.rgb2Lighten(rgb2, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.rgb2Lighten(rgb2, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -345,15 +355,23 @@ break; | ||
if (rgb.getMax() - avg < avg) { | ||
distanceShade = (rgb.getMax() - Math.min(rgb.getR(), rgb.getG(), rgb.getB())) / rgb.getMax() / 2 * distance; | ||
distanceShade = | ||
((rgb.getMax() - Math.min(rgb.getR(), rgb.getG(), rgb.getB())) / | ||
rgb.getMax() / | ||
2) * | ||
distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = Math.max(rgb.getR(), rgb.getG(), rgb.getB()) / rgb.getMax() / 2 * distanceShade; | ||
distance = | ||
(Math.max(rgb.getR(), rgb.getG(), rgb.getB()) / | ||
rgb.getMax() / | ||
2) * | ||
distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.rgbDarken(rgb, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.rgbDarken(rgb, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(rgb.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.rgbLighten(rgb, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.rgbLighten(rgb, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -365,15 +383,15 @@ break; | ||
if (cmyk.getK() < 50) { | ||
distanceShade = cmyk.getK() / 50 * distance; | ||
distanceShade = (cmyk.getK() / 50) * distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = (100 - cmyk.getK()) / 50 * distanceShade; | ||
distance = ((100 - cmyk.getK()) / 50) * distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.cmykDarken(cmyk, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.cmykDarken(cmyk, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(cmyk.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.cmykLighten(cmyk, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.cmykLighten(cmyk, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -385,15 +403,15 @@ break; | ||
if (lab.getL() < 50) { | ||
distanceShade = lab.getL() / 50 * distance; | ||
distanceShade = (lab.getL() / 50) * distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = (100 - lab.getL()) / 50 * distanceShade; | ||
distance = ((100 - lab.getL()) / 50) * distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.labDarken(lab, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.labDarken(lab, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(lab.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.labLighten(lab, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.labLighten(lab, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -405,15 +423,15 @@ break; | ||
if (luv.getL() < 50) { | ||
distanceShade = luv.getL() / 50 * distance; | ||
distanceShade = (luv.getL() / 50) * distance; | ||
} | ||
else { | ||
distanceShade = distance; | ||
distance = (100 - luv.getL()) / 50 * distanceShade; | ||
distance = ((100 - luv.getL()) / 50) * distanceShade; | ||
} | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
scheme.push(Modify_1.default.luvDarken(luv, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.luvDarken(luv, ((colors - i) / colors) * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(luv.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
scheme.push(Modify_1.default.luvLighten(luv, i / colors * distance).to(color.getType(), { round: round })); | ||
scheme.push(Modify_1.default.luvLighten(luv, (i / colors) * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -439,3 +457,26 @@ break; | ||
} | ||
var inBetweenColors = colors - 2; | ||
type = type.toLowerCase(); | ||
var reachesColor2 = ![ | ||
'multiply', | ||
'screen', | ||
'overlay', | ||
'softlight', | ||
'colorburn', | ||
'colordodge', | ||
'vividlight', | ||
'linearburn', | ||
'lineardodge', | ||
'linearlight', | ||
'divide', | ||
'addition', | ||
'subtraction', | ||
'difference', | ||
'hue', | ||
'value', | ||
'lightness', | ||
'intensity', | ||
'perceivedbrightness', | ||
'perceived', | ||
].includes(type); | ||
var inBetweenColors = reachesColor2 ? colors - 2 : colors - 1; | ||
var gradient = []; | ||
@@ -445,38 +486,77 @@ gradient.push(color1); | ||
var amount = (i + 1) / (inBetweenColors + 1); | ||
switch (type) { | ||
case 'rgb': | ||
case 'rgba': | ||
gradient.push(Modify_1.default.rgbBlend(color1.to('rgb', { round: false }), color2.to('rgb', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsv': | ||
case 'hsva': | ||
gradient.push(Modify_1.default.hsvBlend(color1.to('hsv', { round: false }), color2.to('hsv', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
gradient.push(Modify_1.default.hslBlend(color1.to('hsl', { round: false }), color2.to('hsl', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
gradient.push(Modify_1.default.hsiBlend(color1.to('hsi', { round: false }), color2.to('hsi', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsp': | ||
case 'hspa': | ||
gradient.push(Modify_1.default.hspBlend(color1.to('hsp', { round: false }), color2.to('hsp', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'cmyk': | ||
gradient.push(Modify_1.default.cmykBlend(color1.to('cmyk', { round: false }), color2.to('cmyk', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'yiq': | ||
gradient.push(Modify_1.default.yiqBlend(color1.to('yiq', { round: false }), color2.to('yiq', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'lab': | ||
gradient.push(Modify_1.default.labBlend(color1.to('lab', { round: false }), color2.to('lab', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'luv': | ||
gradient.push(Modify_1.default.luvBlend(color1.to('luv', { round: false }), color2.to('luv', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
if ([ | ||
'multiply', | ||
'screen', | ||
'overlay', | ||
'softlight', | ||
'colordodge', | ||
'colorburn', | ||
'vividlight', | ||
'lineardodge', | ||
'linearburn', | ||
'linearlight', | ||
'divide', | ||
'addition', | ||
'subtraction', | ||
'difference', | ||
].includes(type)) { | ||
gradient.push(Blend_1.default.rgbBlendMode(color1.to('rgb', { round: false }), color2.to('rgb', { round: false }), amount, type).to(color1.getType(), { round: round })); | ||
} | ||
else { | ||
switch (type) { | ||
case 'rgb': | ||
case 'rgba': | ||
gradient.push(Blend_1.default.rgbBlend(color1.to('rgb', { round: false }), color2.to('rgb', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hue': | ||
gradient.push(Blend_1.default.hueBlend(color1.to('hsv', { round: false }), color2.to('hsv', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsv': | ||
case 'hsva': | ||
gradient.push(Blend_1.default.hsvBlend(color1.to('hsv', { round: false }), color2.to('hsv', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'value': | ||
gradient.push(Blend_1.default.valueBlend(color1.to('hsv', { round: false }), color2.to('hsv', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
gradient.push(Blend_1.default.hslBlend(color1.to('hsl', { round: false }), color2.to('hsl', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'lightness': | ||
gradient.push(Blend_1.default.lightnessBlend(color1.to('hsl', { round: false }), color2.to('hsl', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
gradient.push(Blend_1.default.hsiBlend(color1.to('hsi', { round: false }), color2.to('hsi', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'intensity': | ||
gradient.push(Blend_1.default.intensityBlend(color1.to('hsi', { round: false }), color2.to('hsi', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'hsp': | ||
case 'hspa': | ||
gradient.push(Blend_1.default.hspBlend(color1.to('hsp', { round: false }), color2.to('hsp', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'perceivedbrightness': | ||
case 'perceived': | ||
gradient.push(Blend_1.default.perceivedBrightnessBlend(color1.to('hsp', { round: false }), color2.to('hsp', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'cmyk': | ||
gradient.push(Blend_1.default.cmykBlend(color1.to('cmyk', { round: false }), color2.to('cmyk', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'yiq': | ||
gradient.push(Blend_1.default.yiqBlend(color1.to('yiq', { round: false }), color2.to('yiq', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'lab': | ||
gradient.push(Blend_1.default.labBlend(color1.to('lab', { round: false }), color2.to('lab', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
case 'luv': | ||
gradient.push(Blend_1.default.luvBlend(color1.to('luv', { round: false }), color2.to('luv', { round: false }), amount).to(color1.getType(), { round: round })); | ||
break; | ||
default: | ||
throw new Error('Unrecognized gradient method'); | ||
} | ||
} | ||
} | ||
gradient.push(color2); | ||
if (reachesColor2) | ||
gradient.push(color2); | ||
return gradient; | ||
@@ -483,0 +563,0 @@ }; |
@@ -13,106 +13,259 @@ import * as Colors from './Colors'; | ||
/** | ||
* Blend one RGB color with another | ||
* Darken RGB color by amount | ||
* | ||
* @param {Colors.rgb} rgb1 | ||
* @param {Colors.rgb} rgb2 | ||
* @param {number} amount amount to blend, 0-1 | ||
* @param {boolean} [round=true] | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
static rgbBlend(rgb1: Colors.rgb, rgb2: Colors.rgb, amount?: number): Colors.rgb; | ||
static rgbDarken(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
/** | ||
* Blend one HSV color with another | ||
* Lighten RGB color by amount | ||
* | ||
* @param {Colors.hsv} hsv1 | ||
* @param {Colors.hsv} hsv2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsv} | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
static hsvBlend(hsv1: Colors.hsv, hsv2: Colors.hsv, amount?: number): Colors.hsv; | ||
static rgbLighten(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
/** | ||
* Blend one HSL color with another | ||
* Darken RGB color by amount (alt method) | ||
* | ||
* @param {Colors.hsl} hsl1 | ||
* @param {Colors.hsl} hsl2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsl} | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
static hslBlend(hsl1: Colors.hsl, hsl2: Colors.hsl, amount?: number): Colors.hsl; | ||
static rgb2Darken(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
/** | ||
* Blend one HSI color with another | ||
* Lighten RGB color by amount (alt method) | ||
* | ||
* @param {Colors.hsi} hsi1 | ||
* @param {Colors.hsi} hsi2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsi} | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
static hsiBlend(hsi1: Colors.hsi, hsi2: Colors.hsi, amount?: number): Colors.hsi; | ||
static rgb2Lighten(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
/** | ||
* Blend one HSP color with another | ||
* Darken CMYK color by amount | ||
* | ||
* @param {Colors.hsp} hsp1 | ||
* @param {Colors.hsp} hsp2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsp} | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
static hspBlend(hsp1: Colors.hsp, hsp2: Colors.hsp, amount?: number): Colors.hsp; | ||
static cmykDarken(cmyk: Colors.cmyk, amount?: number): Colors.cmyk; | ||
/** | ||
* Blend one CMYK color with another | ||
* Lighten CMYK color by amount | ||
* | ||
* @param {Colors.cmyk} cmyk1 | ||
* @param {Colors.cmyk} cmyk2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
static cmykBlend(cmyk1: Colors.cmyk, cmyk2: Colors.cmyk, amount?: number): Colors.cmyk; | ||
static cmykLighten(cmyk: Colors.cmyk, amount?: number): Colors.cmyk; | ||
/** | ||
* Blend one YIQ color with another | ||
* Darken CMYK color by amount (alt method) | ||
* | ||
* @param {Colors.yiq} c1 | ||
* @param {Colors.yiq} c2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.yiq} | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
static yiqBlend(c1: Colors.yiq, c2: Colors.yiq, amount?: number): Colors.yiq; | ||
static labBlend(c1: Colors.lab, c2: Colors.lab, amount?: number): Colors.lab; | ||
static luvBlend(c1: Colors.luv, c2: Colors.luv, amount?: number): Colors.luv; | ||
static rgbDarken(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
static rgbLighten(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
static rgb2Darken(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
static rgb2Lighten(rgb: Colors.rgb, amount?: number): Colors.rgb; | ||
static cmykDarken(cmyk: Colors.cmyk, amount?: number): Colors.cmyk; | ||
static cmykLighten(cmyk: Colors.cmyk, amount?: number): Colors.cmyk; | ||
static cmyk2Darken(cmyk: Colors.cmyk, amount?: number): Colors.cmyk; | ||
/** | ||
* Lighten CMYK color by amount (alt method) | ||
* | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
static cmyk2Lighten(cmyk: Colors.cmyk, amount?: number): Colors.cmyk; | ||
/** | ||
* Darken HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
static hslDarken(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
/** | ||
* Lighten HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
static hslLighten(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
/** | ||
* Darken HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
static hsvDarken(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
/** | ||
* Lighten HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
static hsvLighten(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
/** | ||
* Darken HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
static hsiDarken(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
/** | ||
* Lighten HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
static hsiLighten(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
/** | ||
* Darken HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
static hspDarken(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
/** | ||
* Lighten HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
static hspLighten(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
/** | ||
* Darken Lab color by amount | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
static labDarken(lab: Colors.lab, amount?: number): Colors.lab; | ||
/** | ||
* Lighten Lab color by amount | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
static labLighten(lab: Colors.lab, amount?: number): Colors.lab; | ||
/** | ||
* Darken Lab color by amount (alt method) | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
static lab2Darken(lab: Colors.lab, amount?: number): Colors.lab; | ||
/** | ||
* Lighten Lab color by amount (alt method) | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
static lab2Lighten(lab: Colors.lab, amount?: number): Colors.lab; | ||
/** | ||
* Darken Luv color by amount | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
static luvDarken(luv: Colors.luv, amount?: number): Colors.luv; | ||
/** | ||
* Lighten Luv color by amount | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
static luvLighten(luv: Colors.luv, amount?: number): Colors.luv; | ||
/** | ||
* Darken Luv color by amount (alt method) | ||
* Breaks as L* approaches 0 | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
static luv2Darken(luv: Colors.luv, amount?: number): Colors.luv; | ||
/** | ||
* Lighten Luv color by amount (alt method) | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
static luv2Lighten(luv: Colors.luv, amount?: number): Colors.luv; | ||
/** | ||
* Desaturate HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
static hslDesaturate(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
/** | ||
* Saturate HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
static hslSaturate(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
/** | ||
* Desaturate HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
static hsvDesaturate(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
/** | ||
* Saturate HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
static hsvSaturate(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
/** | ||
* Desaturate HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
static hsiDesaturate(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
/** | ||
* Saturate HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
static hsiSaturate(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
/** | ||
* Desaturate HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
static hspDesaturate(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
/** | ||
* Saturate HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
static hspSaturate(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
} | ||
export = Modify; |
@@ -61,170 +61,8 @@ "use strict"; | ||
/** | ||
* Blend one RGB color with another | ||
* Darken RGB color by amount | ||
* | ||
* @param {Colors.rgb} rgb1 | ||
* @param {Colors.rgb} rgb2 | ||
* @param {number} amount amount to blend, 0-1 | ||
* @param {boolean} [round=true] | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
Modify.rgbBlend = function (rgb1, rgb2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var r3 = rgb1.getR() + (rgb2.getR() - rgb1.getR()) * amount; | ||
var g3 = rgb1.getG() + (rgb2.getG() - rgb1.getG()) * amount; | ||
var b3 = rgb1.getB() + (rgb2.getB() - rgb1.getB()) * amount; | ||
var a3 = rgb1.getA() + (rgb2.getA() - rgb1.getA()) * amount; | ||
return new Colors.rgb(r3, g3, b3, a3); | ||
}; | ||
/** | ||
* Blend one HSV color with another | ||
* | ||
* @param {Colors.hsv} hsv1 | ||
* @param {Colors.hsv} hsv2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsv} | ||
*/ | ||
Modify.hsvBlend = function (hsv1, hsv2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsv2.getH() - hsv1.getH()) > 180) { | ||
hueDiff = 360 - (hsv2.getH() - hsv1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsv2.getH() - hsv1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsv1.getH(), hueDiff); | ||
var s3 = hsv1.getS() + (hsv2.getS() - hsv1.getS()) * amount; | ||
var v3 = hsv1.getV() + (hsv2.getV() - hsv1.getV()) * amount; | ||
var a3 = hsv1.getA() + (hsv2.getA() - hsv1.getA()) * amount; | ||
return new Colors.hsv(h3, s3, v3, a3); | ||
}; | ||
/** | ||
* Blend one HSL color with another | ||
* | ||
* @param {Colors.hsl} hsl1 | ||
* @param {Colors.hsl} hsl2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsl} | ||
*/ | ||
Modify.hslBlend = function (hsl1, hsl2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsl2.getH() - hsl1.getH()) > 180) { | ||
hueDiff = 360 - (hsl2.getH() - hsl1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsl2.getH() - hsl1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsl1.getH(), hueDiff); | ||
var s3 = hsl1.getS() + (hsl2.getS() - hsl1.getS()) * amount; | ||
var l3 = hsl1.getL() + (hsl2.getL() - hsl1.getL()) * amount; | ||
var a3 = hsl1.getA() + (hsl2.getA() - hsl1.getA()) * amount; | ||
return new Colors.hsl(h3, s3, l3, a3); | ||
}; | ||
/** | ||
* Blend one HSI color with another | ||
* | ||
* @param {Colors.hsi} hsi1 | ||
* @param {Colors.hsi} hsi2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsi} | ||
*/ | ||
Modify.hsiBlend = function (hsi1, hsi2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsi2.getH() - hsi1.getH()) > 180) { | ||
hueDiff = 360 - (hsi2.getH() - hsi1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsi2.getH() - hsi1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsi1.getH(), hueDiff); | ||
var s3 = hsi1.getS() + (hsi2.getS() - hsi1.getS()) * amount; | ||
var i3 = hsi1.getI() + (hsi2.getI() - hsi1.getI()) * amount; | ||
var a3 = hsi1.getA() + (hsi2.getA() - hsi1.getA()) * amount; | ||
return new Colors.hsi(h3, s3, i3, a3); | ||
}; | ||
/** | ||
* Blend one HSP color with another | ||
* | ||
* @param {Colors.hsp} hsp1 | ||
* @param {Colors.hsp} hsp2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.hsp} | ||
*/ | ||
Modify.hspBlend = function (hsp1, hsp2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsp2.getH() - hsp1.getH()) > 180) { | ||
hueDiff = 360 - (hsp2.getH() - hsp1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsp2.getH() - hsp1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsp1.getH(), hueDiff); | ||
var s3 = hsp1.getS() + (hsp2.getS() - hsp1.getS()) * amount; | ||
var p3 = hsp1.getP() + (hsp2.getP() - hsp1.getP()) * amount; | ||
var a3 = hsp1.getA() + (hsp2.getA() - hsp1.getA()) * amount; | ||
return new Colors.hsp(h3, s3, p3, a3); | ||
}; | ||
/** | ||
* Blend one CMYK color with another | ||
* | ||
* @param {Colors.cmyk} cmyk1 | ||
* @param {Colors.cmyk} cmyk2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.cmyk} | ||
*/ | ||
Modify.cmykBlend = function (cmyk1, cmyk2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var c3 = cmyk1.getC() + (cmyk2.getC() - cmyk1.getC()) * amount; | ||
var m3 = cmyk1.getM() + (cmyk2.getM() - cmyk1.getM()) * amount; | ||
var y3 = cmyk1.getY() + (cmyk2.getY() - cmyk1.getY()) * amount; | ||
var k3 = cmyk1.getK() + (cmyk2.getK() - cmyk1.getK()) * amount; | ||
return new Colors.cmyk(c3, m3, y3, k3); | ||
}; | ||
/** | ||
* Blend one YIQ color with another | ||
* | ||
* @param {Colors.yiq} c1 | ||
* @param {Colors.yiq} c2 | ||
* @param {number} amount amount to blend (0-1) | ||
* @param {boolean} [round=true] | ||
* @return {Colors.yiq} | ||
*/ | ||
Modify.yiqBlend = function (c1, c2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var y = c1.getY() + (c2.getY() - c1.getY()) * amount; | ||
var i = c1.getI() + (c2.getI() - c1.getI()) * amount; | ||
var q = c1.getQ() + (c2.getQ() - c1.getQ()) * amount; | ||
return new Colors.yiq(y, i, q); | ||
}; | ||
Modify.labBlend = function (c1, c2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var l = c1.getL() + (c2.getL() - c1.getL()) * amount; | ||
var a = c1.getA() + (c2.getA() - c1.getA()) * amount; | ||
var b = c1.getB() + (c2.getB() - c1.getB()) * amount; | ||
return new Colors.lab(l, a, b); | ||
}; | ||
Modify.luvBlend = function (c1, c2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var l = c1.getL() + (c2.getL() - c1.getL()) * amount; | ||
var u = c1.getU() + (c2.getU() - c1.getU()) * amount; | ||
var v = c1.getV() + (c2.getV() - c1.getV()) * amount; | ||
return new Colors.luv(l, u, v); | ||
}; | ||
Modify.rgbDarken = function (rgb, amount) { | ||
@@ -238,2 +76,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten RGB color by amount | ||
* | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
Modify.rgbLighten = function (rgb, amount) { | ||
@@ -247,2 +92,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken RGB color by amount (alt method) | ||
* | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
Modify.rgb2Darken = function (rgb, amount) { | ||
@@ -258,2 +110,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten RGB color by amount (alt method) | ||
* | ||
* @param {Colors.rgb} rgb | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.rgb} | ||
*/ | ||
Modify.rgb2Lighten = function (rgb, amount) { | ||
@@ -269,2 +128,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken CMYK color by amount | ||
* | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
Modify.cmykDarken = function (cmyk, amount) { | ||
@@ -279,2 +145,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten CMYK color by amount | ||
* | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
Modify.cmykLighten = function (cmyk, amount) { | ||
@@ -289,2 +162,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken CMYK color by amount (alt method) | ||
* | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
Modify.cmyk2Darken = function (cmyk, amount) { | ||
@@ -296,2 +176,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten CMYK color by amount (alt method) | ||
* | ||
* @param {Colors.cmyk} cmyk | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.cmyk} | ||
*/ | ||
Modify.cmyk2Lighten = function (cmyk, amount) { | ||
@@ -303,2 +190,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
Modify.hslDarken = function (hsl, amount) { | ||
@@ -310,2 +204,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
Modify.hslLighten = function (hsl, amount) { | ||
@@ -317,2 +218,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
Modify.hsvDarken = function (hsv, amount) { | ||
@@ -324,2 +232,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
Modify.hsvLighten = function (hsv, amount) { | ||
@@ -332,2 +247,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
Modify.hsiDarken = function (hsi, amount) { | ||
@@ -339,2 +261,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
Modify.hsiLighten = function (hsi, amount) { | ||
@@ -347,2 +276,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
Modify.hspDarken = function (hsp, amount) { | ||
@@ -354,2 +290,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
Modify.hspLighten = function (hsp, amount) { | ||
@@ -362,2 +305,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken Lab color by amount | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
Modify.labDarken = function (lab, amount) { | ||
@@ -371,2 +321,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten Lab color by amount | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
Modify.labLighten = function (lab, amount) { | ||
@@ -381,2 +338,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken Lab color by amount (alt method) | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
Modify.lab2Darken = function (lab, amount) { | ||
@@ -388,2 +352,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten Lab color by amount (alt method) | ||
* | ||
* @param {Colors.lab} lab | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.lab} | ||
*/ | ||
Modify.lab2Lighten = function (lab, amount) { | ||
@@ -395,2 +366,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Darken Luv color by amount | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
Modify.luvDarken = function (luv, amount) { | ||
@@ -404,2 +382,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten Luv color by amount | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
Modify.luvLighten = function (luv, amount) { | ||
@@ -414,3 +399,10 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
// breaks as L* approaches 0 | ||
/** | ||
* Darken Luv color by amount (alt method) | ||
* Breaks as L* approaches 0 | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to darken, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
Modify.luv2Darken = function (luv, amount) { | ||
@@ -422,2 +414,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Lighten Luv color by amount (alt method) | ||
* | ||
* @param {Colors.luv} luv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.luv} | ||
*/ | ||
Modify.luv2Lighten = function (luv, amount) { | ||
@@ -429,2 +428,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Desaturate HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
Modify.hslDesaturate = function (hsl, amount) { | ||
@@ -436,2 +442,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Saturate HSL color by amount | ||
* | ||
* @param {Colors.hsl} hsl | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsl} | ||
*/ | ||
Modify.hslSaturate = function (hsl, amount) { | ||
@@ -443,2 +456,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Desaturate HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
Modify.hsvDesaturate = function (hsv, amount) { | ||
@@ -450,2 +470,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Saturate HSV color by amount | ||
* | ||
* @param {Colors.hsv} hsv | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsv} | ||
*/ | ||
Modify.hsvSaturate = function (hsv, amount) { | ||
@@ -457,2 +484,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Desaturate HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
Modify.hsiDesaturate = function (hsi, amount) { | ||
@@ -464,2 +498,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Saturate HSI color by amount | ||
* | ||
* @param {Colors.hsi} hsi | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsi} | ||
*/ | ||
Modify.hsiSaturate = function (hsi, amount) { | ||
@@ -471,2 +512,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Desaturate HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
Modify.hspDesaturate = function (hsp, amount) { | ||
@@ -478,2 +526,9 @@ if (amount === void 0) { amount = 0.5; } | ||
}; | ||
/** | ||
* Saturate HSP color by amount | ||
* | ||
* @param {Colors.hsp} hsp | ||
* @param {number} [amount=0.5] amount to lighten, 0-1 | ||
* @return {Colors.hsp} | ||
*/ | ||
Modify.hspSaturate = function (hsp, amount) { | ||
@@ -480,0 +535,0 @@ if (amount === void 0) { amount = 0.5; } |
@@ -79,2 +79,9 @@ import { referenceWhite } from './Reference'; | ||
static validReferenceWhite(referenceWhite: string | referenceWhite): referenceWhite; | ||
/** | ||
* Validates color space from string and returns object with relevant data, | ||
* including name, gamma, xyz2rgb conversion matrices... | ||
* | ||
* @param {string} colorSpace | ||
* @returns {object} | ||
*/ | ||
static validColorSpace(colorSpace: string): object; | ||
@@ -81,0 +88,0 @@ /** |
@@ -189,3 +189,4 @@ "use strict"; | ||
if (typeof Reference_1.stdIlluminants[referenceWhite] == 'undefined' || | ||
typeof Reference_1.stdIlluminants[referenceWhite]['vector'] == 'undefined') { | ||
typeof Reference_1.stdIlluminants[referenceWhite]['vector'] == | ||
'undefined') { | ||
throw new Error('Invalid reference white'); | ||
@@ -205,2 +206,9 @@ } | ||
}; | ||
/** | ||
* Validates color space from string and returns object with relevant data, | ||
* including name, gamma, xyz2rgb conversion matrices... | ||
* | ||
* @param {string} colorSpace | ||
* @returns {object} | ||
*/ | ||
Util.validColorSpace = function (colorSpace) { | ||
@@ -243,3 +251,3 @@ // make lowercase, include common nomenclature differences, ignore spaces, etc | ||
Util.fmod = function (x, y) { | ||
return Number((x - (Math.floor(x / y) * y)).toPrecision(8)); | ||
return Number((x - Math.floor(x / y) * y).toPrecision(8)); | ||
}; | ||
@@ -246,0 +254,0 @@ return Util; |
{ | ||
"name": "chromaticity-color-utilities", | ||
"version": "0.12.1-alpha", | ||
"version": "0.13.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
357892
24
8660