chromaticity-color-utilities
Advanced tools
Comparing version 0.8.6-alpha to 0.11.0-alpha
@@ -75,2 +75,3 @@ "use strict"; | ||
case 'temperature': | ||
case 'colortemperature': | ||
case 'temp': | ||
@@ -77,0 +78,0 @@ from = new Colors.kelvin(value); |
import { newColorArgs, colorType } from './ColorType'; | ||
export declare class rgbNormalized extends colorType { | ||
protected type: string; | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
gamma?: number; | ||
private r; | ||
private g; | ||
private b; | ||
private a; | ||
private gamma?; | ||
constructor(r: number, g: number, b: number, a?: number, gamma?: number); | ||
protected toStringValues: () => object; | ||
getR: () => number; | ||
getG: () => number; | ||
getB: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
getGamma: () => number | undefined; | ||
gety: () => number | undefined; | ||
getY: () => number | undefined; | ||
protected setAlpha(value: number): boolean; | ||
} | ||
export declare class hex extends colorType { | ||
protected type: string; | ||
hex: string; | ||
private hex; | ||
constructor(hex: string | number); | ||
protected toStringValues: () => object; | ||
getHex: () => string; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -22,10 +32,18 @@ protected tohex(args: newColorArgs): hex; | ||
protected type: string; | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
bitDepth: number; | ||
max: number; | ||
private r; | ||
private g; | ||
private b; | ||
private a; | ||
private bitDepth; | ||
private max; | ||
constructor(r: number, g: number, b: number, a?: number, bitDepth?: number); | ||
protected toStringValues: () => object; | ||
getR: () => number; | ||
getG: () => number; | ||
getB: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
getMax: () => number; | ||
getBitDepth: () => number; | ||
protected setAlpha(value: number): boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -35,10 +53,18 @@ } | ||
protected type: string; | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
bitDepth: number; | ||
max: number; | ||
private r; | ||
private g; | ||
private b; | ||
private a; | ||
private bitDepth; | ||
private max; | ||
constructor(r: number, g: number, b: number, a?: number, bitDepth?: number); | ||
protected toStringValues: () => object; | ||
getR: () => number; | ||
getG: () => number; | ||
getB: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
getMax: () => number; | ||
getBitDepth: () => number; | ||
protected setAlpha(value: number): boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -49,10 +75,18 @@ protected torec709(args: newColorArgs): rec709rgb; | ||
protected type: string; | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
bitDepth: number; | ||
max: number; | ||
private r; | ||
private g; | ||
private b; | ||
private a; | ||
private bitDepth; | ||
private max; | ||
constructor(r: number, g: number, b: number, a?: number, bitDepth?: number); | ||
protected toStringValues: () => object; | ||
getR: () => number; | ||
getG: () => number; | ||
getB: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
getMax: () => number; | ||
getBitDepth: () => number; | ||
protected setAlpha(value: number): boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -63,8 +97,14 @@ protected torec2020(args: newColorArgs): rec2020rgb; | ||
protected type: string; | ||
h: number; | ||
s: number; | ||
v: number; | ||
a: number; | ||
private h; | ||
private s; | ||
private v; | ||
private a; | ||
constructor(h: number, s: number, v: number, a?: number); | ||
protected toStringValues: () => object; | ||
getH: () => number; | ||
getS: () => number; | ||
getV: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
protected setAlpha(value: number): boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -76,8 +116,14 @@ protected tohsv(args: newColorArgs): hsv; | ||
protected type: string; | ||
h: number; | ||
s: number; | ||
l: number; | ||
a: number; | ||
private h; | ||
private s; | ||
private l; | ||
private a; | ||
constructor(h: number, s: number, l: number, a?: number); | ||
protected toStringValues: () => object; | ||
getH: () => number; | ||
getS: () => number; | ||
getL: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
protected setAlpha(value: number): boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -89,8 +135,14 @@ protected tohsv(args: newColorArgs): hsv; | ||
protected type: string; | ||
h: number; | ||
s: number; | ||
i: number; | ||
a: number; | ||
private h; | ||
private s; | ||
private i; | ||
private a; | ||
constructor(h: number, s: number, i: number, a?: number); | ||
protected toStringValues: () => object; | ||
getH: () => number; | ||
getS: () => number; | ||
getI: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
protected setAlpha(value: number): boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -101,11 +153,20 @@ protected tohsi(args: newColorArgs): hsi; | ||
protected type: string; | ||
h: number; | ||
s: number; | ||
p: number; | ||
a: number; | ||
pr: number; | ||
pg: number; | ||
pb: number; | ||
private h; | ||
private s; | ||
private p; | ||
private a; | ||
private pr; | ||
private pg; | ||
private pb; | ||
constructor(h: number, s: number, p: number, a?: number, pb?: number, pr?: number); | ||
protected toStringValues: () => object; | ||
getH: () => number; | ||
getS: () => number; | ||
getP: () => number; | ||
getPb: () => number; | ||
getPr: () => number; | ||
getPg: () => number; | ||
getA: () => number; | ||
getAlpha: () => number; | ||
protected setAlpha(value: number): boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -116,8 +177,12 @@ protected tohsp(args: newColorArgs): hsp; | ||
protected type: string; | ||
c: number; | ||
m: number; | ||
y: number; | ||
k: number; | ||
private c; | ||
private m; | ||
private y; | ||
private k; | ||
constructor(c: number, m: number, y: number, k: number); | ||
protected toStringValues: () => object; | ||
getC: () => number; | ||
getM: () => number; | ||
getY: () => number; | ||
getK: () => number; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -128,6 +193,6 @@ protected tocmyk(args: newColorArgs): cmyk; | ||
protected type: string; | ||
y: number; | ||
i: number; | ||
q: number; | ||
normalized: boolean; | ||
private y; | ||
private i; | ||
private q; | ||
private normalized; | ||
/** | ||
@@ -143,2 +208,7 @@ * YIQ | ||
protected toStringValues: () => object; | ||
getY: () => number; | ||
getI: () => number; | ||
getQ: () => number; | ||
isNormalized: () => boolean; | ||
getNormalized: () => boolean; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -149,7 +219,10 @@ protected toyiq(args: newColorArgs): yiq; | ||
protected type: string; | ||
x: number; | ||
y: number; | ||
z: number; | ||
private x; | ||
private y; | ||
private z; | ||
constructor(x: number, y: number, z: number); | ||
protected toStringValues: () => object; | ||
getX: () => number; | ||
getY: () => number; | ||
getZ: () => number; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -160,7 +233,11 @@ protected toxyz(args: newColorArgs): xyz; | ||
protected type: string; | ||
x: number; | ||
y: number; | ||
yy: number; | ||
private x; | ||
private y; | ||
private yy; | ||
constructor(x: number, y: number, yy: number); | ||
protected torgb(args: newColorArgs): rgb; | ||
getX: () => number; | ||
getY: () => number; | ||
gety: () => never; | ||
getYY: () => number; | ||
protected toStringValues: () => object; | ||
@@ -172,8 +249,8 @@ protected toxyz(args: newColorArgs): xyz; | ||
protected type: string; | ||
l: number; | ||
a: number; | ||
b: number; | ||
private l; | ||
private a; | ||
private b; | ||
/** | ||
* | ||
* @param {number} l 0-100 | ||
* @param {number} l 0-100+ | ||
* @param {number} a unbounded, but typically clamped at -128 and 127 | ||
@@ -184,2 +261,5 @@ * @param {number} b unbounded, but typically clamped at -128 and 127 | ||
protected toStringValues: () => object; | ||
getL: () => number; | ||
getA: () => number; | ||
getB: () => number; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -191,5 +271,5 @@ protected toxyz(args: newColorArgs): xyz; | ||
protected type: string; | ||
l: number; | ||
u: number; | ||
v: number; | ||
private l; | ||
private u; | ||
private v; | ||
/** | ||
@@ -203,2 +283,5 @@ * | ||
protected toStringValues: () => object; | ||
getL: () => number; | ||
getU: () => number; | ||
getV: () => number; | ||
protected torgb(args: newColorArgs): rgb; | ||
@@ -210,8 +293,15 @@ protected toxyz(args: newColorArgs): xyz; | ||
protected type: string; | ||
y: number; | ||
pb: number; | ||
pr: number; | ||
kb: number; | ||
kr: number; | ||
private y; | ||
private pb; | ||
private pr; | ||
private kb; | ||
private kr; | ||
constructor(y: number, pb: number, pr: number, kb: number, kr: number); | ||
getY: () => number; | ||
getPb: () => number; | ||
getPr: () => number; | ||
getPg: () => number; | ||
getKb: () => number; | ||
getKr: () => number; | ||
getKg: () => number; | ||
protected toStringValues: () => object; | ||
@@ -224,12 +314,19 @@ protected torgb(args: newColorArgs): rgb; | ||
protected type: string; | ||
y: number; | ||
cb: number; | ||
cr: number; | ||
yLower: number; | ||
yUpper: number; | ||
cLower: number; | ||
cUpper: number; | ||
private y; | ||
private cb; | ||
private cr; | ||
private yLower; | ||
private yUpper; | ||
private cLower; | ||
private cUpper; | ||
constructor(y: number, cb: number, cr: number, yLower?: number, yUpper?: number, cLower?: number, cUpper?: number); | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
getY: () => number; | ||
getCb: () => number; | ||
getCr: () => number; | ||
getYLower: () => number; | ||
getYUpper: () => number; | ||
getCLower: () => number; | ||
getCUpper: () => number; | ||
protected toypbpr(args: newColorArgs): ypbpr; | ||
@@ -240,4 +337,6 @@ protected toycbcr(args: newColorArgs): ycbcr; | ||
protected type: string; | ||
wavelength: number; | ||
private wavelength; | ||
constructor(wavelength: number); | ||
getWavelength: () => number; | ||
getNm: () => number; | ||
protected toStringValues: () => object; | ||
@@ -248,6 +347,8 @@ protected torgb(args: newColorArgs): rgb; | ||
protected type: string; | ||
k: number; | ||
private k; | ||
constructor(k: number); | ||
getK: () => number; | ||
getKelvin: () => number; | ||
protected toStringValues: () => object; | ||
protected torgb(args: newColorArgs): rgb; | ||
} |
@@ -50,4 +50,22 @@ "use strict"; | ||
a: _this.a, | ||
gamma: _this.gamma | ||
gamma: _this.gamma, | ||
}); }; | ||
_this.getR = function () { | ||
return _this.r; | ||
}; | ||
_this.getG = function () { | ||
return _this.g; | ||
}; | ||
_this.getB = function () { | ||
return _this.b; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.getGamma = function () { | ||
return _this.gamma; | ||
}; | ||
_this.gety = function () { return _this.getGamma(); }; | ||
_this.getY = function () { return _this.getGamma(); }; | ||
_this.valueRangeCheck(r, 0, 1); | ||
@@ -67,2 +85,7 @@ _this.valueRangeCheck(g, 0, 1); | ||
} | ||
rgbNormalized.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, 1); | ||
this.a = value; | ||
return true; | ||
}; | ||
return rgbNormalized; | ||
@@ -77,4 +100,7 @@ }(ColorType_1.colorType)); | ||
_this.toStringValues = function () { return ({ | ||
hex: _this.hex | ||
hex: _this.hex, | ||
}); }; | ||
_this.getHex = function () { | ||
return _this.hex; | ||
}; | ||
if (typeof hex === 'string') { | ||
@@ -125,4 +151,23 @@ if (hex.charAt(0) == '#') { | ||
a: _this.a, | ||
bitDepth: _this.bitDepth | ||
bitDepth: _this.bitDepth, | ||
}); }; | ||
_this.getR = function () { | ||
return _this.r; | ||
}; | ||
_this.getG = function () { | ||
return _this.g; | ||
}; | ||
_this.getB = function () { | ||
return _this.b; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.getMax = function () { | ||
return _this.max; | ||
}; | ||
_this.getBitDepth = function () { | ||
return _this.bitDepth; | ||
}; | ||
_this.valueRangeCheck(bitDepth, 1, false, 'Bit depth must be a positive number greater than 1'); | ||
@@ -144,2 +189,7 @@ var max = Math.pow(2, bitDepth) - 1; | ||
} | ||
rgb.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, this.max); | ||
this.a = value; | ||
return true; | ||
}; | ||
rgb.prototype.torgb = function (args) { | ||
@@ -168,4 +218,23 @@ if (args.round !== false) { | ||
a: _this.a, | ||
bitDepth: _this.bitDepth | ||
bitDepth: _this.bitDepth, | ||
}); }; | ||
_this.getR = function () { | ||
return _this.r; | ||
}; | ||
_this.getG = function () { | ||
return _this.g; | ||
}; | ||
_this.getB = function () { | ||
return _this.b; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.getMax = function () { | ||
return _this.max; | ||
}; | ||
_this.getBitDepth = function () { | ||
return _this.bitDepth; | ||
}; | ||
if (bitDepth != 8 && bitDepth != 10) { | ||
@@ -196,2 +265,7 @@ throw new Error('Invalid bitrate for Rec709, must be 8 or 10'); | ||
} | ||
rec709rgb.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, this.max); | ||
this.a = value; | ||
return true; | ||
}; | ||
rec709rgb.prototype.torgb = function (args) { | ||
@@ -223,4 +297,23 @@ return Convert_1.default.rec709rgb2rgb(this, args.round, args.bitDepth); | ||
a: _this.a, | ||
bitDepth: _this.bitDepth | ||
bitDepth: _this.bitDepth, | ||
}); }; | ||
_this.getR = function () { | ||
return _this.r; | ||
}; | ||
_this.getG = function () { | ||
return _this.g; | ||
}; | ||
_this.getB = function () { | ||
return _this.b; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.getMax = function () { | ||
return _this.max; | ||
}; | ||
_this.getBitDepth = function () { | ||
return _this.bitDepth; | ||
}; | ||
if (bitDepth != 10 && bitDepth != 12) { | ||
@@ -251,2 +344,7 @@ throw new Error('Invalid bitrate for Rec2020, must be 10 or 12'); | ||
} | ||
rec2020rgb.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, this.max); | ||
this.a = value; | ||
return true; | ||
}; | ||
rec2020rgb.prototype.torgb = function (args) { | ||
@@ -277,4 +375,17 @@ return Convert_1.default.rec2020rgb2rgb(this, args.round, args.bitDepth); | ||
v: _this.v, | ||
a: _this.a | ||
a: _this.a, | ||
}); }; | ||
_this.getH = function () { | ||
return _this.h; | ||
}; | ||
_this.getS = function () { | ||
return _this.s; | ||
}; | ||
_this.getV = function () { | ||
return _this.v; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -290,2 +401,7 @@ _this.valueRangeCheck(s, 0, 100); | ||
} | ||
hsv.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, 100); | ||
this.a = value; | ||
return true; | ||
}; | ||
hsv.prototype.torgb = function (args) { | ||
@@ -319,4 +435,17 @@ return Convert_1.default.hsv2rgb(this, args.round, args.bitDepth); | ||
l: _this.l, | ||
a: _this.a | ||
a: _this.a, | ||
}); }; | ||
_this.getH = function () { | ||
return _this.h; | ||
}; | ||
_this.getS = function () { | ||
return _this.s; | ||
}; | ||
_this.getL = function () { | ||
return _this.l; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -332,2 +461,7 @@ _this.valueRangeCheck(s, 0, 100); | ||
} | ||
hsl.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, 100); | ||
this.a = value; | ||
return true; | ||
}; | ||
hsl.prototype.torgb = function (args) { | ||
@@ -361,4 +495,17 @@ return Convert_1.default.hsl2rgb(this, args.round, args.bitDepth); | ||
i: _this.i, | ||
a: _this.a | ||
a: _this.a, | ||
}); }; | ||
_this.getH = function () { | ||
return _this.h; | ||
}; | ||
_this.getS = function () { | ||
return _this.s; | ||
}; | ||
_this.getI = function () { | ||
return _this.i; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -374,2 +521,7 @@ _this.valueRangeCheck(s, 0, 100); | ||
} | ||
hsi.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, 100); | ||
this.a = value; | ||
return true; | ||
}; | ||
hsi.prototype.torgb = function (args) { | ||
@@ -410,4 +562,26 @@ return Convert_1.default.hsi2rgb(this, args.round, args.bitDepth); | ||
pb: _this.pb, | ||
pr: _this.pr | ||
pr: _this.pr, | ||
}); }; | ||
_this.getH = function () { | ||
return _this.h; | ||
}; | ||
_this.getS = function () { | ||
return _this.s; | ||
}; | ||
_this.getP = function () { | ||
return _this.p; | ||
}; | ||
_this.getPb = function () { | ||
return _this.pb; | ||
}; | ||
_this.getPr = function () { | ||
return _this.pr; | ||
}; | ||
_this.getPg = function () { | ||
return 1 - _this.pr - _this.pb; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getAlpha = function () { return _this.getA(); }; | ||
_this.valueRangeCheck(h, 0, 360); | ||
@@ -429,2 +603,7 @@ _this.valueRangeCheck(s, 0, 100); | ||
} | ||
hsp.prototype.setAlpha = function (value) { | ||
this.valueRangeCheck(value, 0, 100); | ||
this.a = value; | ||
return true; | ||
}; | ||
hsp.prototype.torgb = function (args) { | ||
@@ -456,2 +635,14 @@ return Convert_1.default.hsp2rgb(this, args.round, args.bitDepth); | ||
}); }; | ||
_this.getC = function () { | ||
return _this.c; | ||
}; | ||
_this.getM = function () { | ||
return _this.m; | ||
}; | ||
_this.getY = function () { | ||
return _this.y; | ||
}; | ||
_this.getK = function () { | ||
return _this.k; | ||
}; | ||
_this.valueRangeCheck(c, 0, 100, 'CMYK values must be between 0 and 100'); | ||
@@ -502,2 +693,15 @@ _this.valueRangeCheck(m, 0, 100, 'CMYK values must be between 0 and 100'); | ||
}); }; | ||
_this.getY = function () { | ||
return _this.y; | ||
}; | ||
_this.getI = function () { | ||
return _this.i; | ||
}; | ||
_this.getQ = function () { | ||
return _this.q; | ||
}; | ||
_this.isNormalized = function () { | ||
return _this.normalized; | ||
}; | ||
_this.getNormalized = function () { return _this.isNormalized(); }; | ||
if (normalized) { | ||
@@ -543,2 +747,11 @@ _this.valueRangeCheck(y, 0, 255, 'Normalized Y value must be between 0 and 255'); | ||
}); }; | ||
_this.getX = function () { | ||
return _this.x; | ||
}; | ||
_this.getY = function () { | ||
return _this.y; | ||
}; | ||
_this.getZ = function () { | ||
return _this.z; | ||
}; | ||
// this.valueRangeCheck(x, 0, 1, 'XYZ values must be between 0 and 1') | ||
@@ -566,2 +779,14 @@ // this.valueRangeCheck(y, 0, 1, 'XYZ values must be between 0 and 1') | ||
_this.type = 'xyy'; | ||
_this.getX = function () { | ||
return _this.x; | ||
}; | ||
_this.getY = function () { | ||
return _this.y; | ||
}; | ||
_this.gety = function () { | ||
throw new Error('Use getY() and getYY() for the y and Y values of xyY'); | ||
}; | ||
_this.getYY = function () { | ||
return _this.yy; | ||
}; | ||
_this.toStringValues = function () { return ({ | ||
@@ -593,3 +818,3 @@ x: _this.x, | ||
* | ||
* @param {number} l 0-100 | ||
* @param {number} l 0-100+ | ||
* @param {number} a unbounded, but typically clamped at -128 and 127 | ||
@@ -606,3 +831,12 @@ * @param {number} b unbounded, but typically clamped at -128 and 127 | ||
}); }; | ||
_this.valueRangeCheck(l, 0, 100); | ||
_this.getL = function () { | ||
return _this.l; | ||
}; | ||
_this.getA = function () { | ||
return _this.a; | ||
}; | ||
_this.getB = function () { | ||
return _this.b; | ||
}; | ||
_this.valueRangeCheck(l, 0, false); | ||
if (typeof a === 'undefined') | ||
@@ -650,2 +884,11 @@ throw new Error('a undefined'); | ||
}); }; | ||
_this.getL = function () { | ||
return _this.l; | ||
}; | ||
_this.getU = function () { | ||
return _this.u; | ||
}; | ||
_this.getV = function () { | ||
return _this.v; | ||
}; | ||
_this.valueRangeCheck(l, 0, 100); | ||
@@ -685,2 +928,23 @@ // this.valueRangeCheck(u, -100, 100) | ||
_this.type = 'ypbpr'; | ||
_this.getY = function () { | ||
return _this.y; | ||
}; | ||
_this.getPb = function () { | ||
return _this.pb; | ||
}; | ||
_this.getPr = function () { | ||
return _this.pr; | ||
}; | ||
_this.getPg = function () { | ||
return 1 - _this.pr - _this.pb; | ||
}; | ||
_this.getKb = function () { | ||
return _this.kb; | ||
}; | ||
_this.getKr = function () { | ||
return _this.kr; | ||
}; | ||
_this.getKg = function () { | ||
return 1 - _this.kr - _this.kb; | ||
}; | ||
_this.toStringValues = function () { return ({ | ||
@@ -738,2 +1002,23 @@ y: _this.y, | ||
}); }; | ||
_this.getY = function () { | ||
return _this.y; | ||
}; | ||
_this.getCb = function () { | ||
return _this.cb; | ||
}; | ||
_this.getCr = function () { | ||
return _this.cr; | ||
}; | ||
_this.getYLower = function () { | ||
return _this.yLower; | ||
}; | ||
_this.getYUpper = function () { | ||
return _this.yUpper; | ||
}; | ||
_this.getCLower = function () { | ||
return _this.cLower; | ||
}; | ||
_this.getCUpper = function () { | ||
return _this.cUpper; | ||
}; | ||
_this.y = y; | ||
@@ -784,6 +1069,10 @@ _this.cb = cb; | ||
_this.type = 'nm'; | ||
_this.getWavelength = function () { | ||
return _this.wavelength; | ||
}; | ||
_this.getNm = function () { return _this.getWavelength(); }; | ||
_this.toStringValues = function () { return ({ | ||
wavelength: _this.wavelength, | ||
}); }; | ||
_this.valueRangeCheck(wavelength, 200, 800, 'Wavelength (in nm) must fall between 200 and 800'); | ||
_this.valueRangeCheck(wavelength, 360, 820, 'Wavelength (in nm) must fall between 360 and 820'); | ||
_this.wavelength = wavelength; | ||
@@ -803,2 +1092,6 @@ return _this; | ||
_this.type = 'kelvin'; | ||
_this.getK = function () { | ||
return _this.k; | ||
}; | ||
_this.getKelvin = function () { return _this.getK(); }; | ||
_this.toStringValues = function () { return ({ | ||
@@ -805,0 +1098,0 @@ k: _this.k, |
@@ -54,16 +54,2 @@ import * as Colors from './Colors'; | ||
protected type: string; | ||
bitDepth?: number; | ||
normalized?: boolean; | ||
colorSpace?: string; | ||
referenceWhite?: string; | ||
kb?: number; | ||
kr?: number; | ||
pb?: number; | ||
pr?: number; | ||
yLower?: number; | ||
yUpper?: number; | ||
cLower?: number; | ||
cUpper?: number; | ||
gamma?: number; | ||
a?: number; | ||
/** | ||
@@ -77,2 +63,18 @@ * Returns generic simplified object for toString() | ||
/** | ||
* Returns any property of type boolean|number|string, otherwise returns undefined | ||
* Useful for passing values as arguments back and forth | ||
* | ||
* @param {string} propertyName | ||
* @returns {any} | ||
*/ | ||
private get; | ||
/** | ||
* Set alpha | ||
* Extend on color types with an alpha value | ||
* | ||
* @param {number} value | ||
* @returns {boolean} | ||
*/ | ||
protected setAlpha(value: number): boolean; | ||
/** | ||
* Stringify object | ||
@@ -83,3 +85,3 @@ * | ||
*/ | ||
toString(whitespace?: string | number, quotes?: boolean, showType?: boolean): string; | ||
toString(whitespace?: string | number | null, quotes?: boolean, showType?: boolean): string; | ||
to<T extends colorType>(type: string, args?: newColorArgs): T; | ||
@@ -86,0 +88,0 @@ getType(): string; |
@@ -52,2 +52,15 @@ "use strict"; | ||
this.type = 'colorType'; | ||
// private bitDepth?: number | ||
// private normalized?: boolean | ||
// private colorSpace?: string | ||
// private referenceWhite?: string | ||
// private kb?: number | ||
// private kr?: number | ||
// private pb?: number | ||
// private pr?: number | ||
// private yLower?: number | ||
// private yUpper?: number | ||
// private cLower?: number | ||
// private cUpper?: number | ||
// private gamma?: number | ||
/** | ||
@@ -62,2 +75,23 @@ * Returns generic simplified object for toString() | ||
/** | ||
* Returns any property of type boolean|number|string, otherwise returns undefined | ||
* Useful for passing values as arguments back and forth | ||
* | ||
* @param {string} propertyName | ||
* @returns {any} | ||
*/ | ||
colorType.prototype.get = function (propertyName) { | ||
if (['boolean', 'number', 'string'].includes(typeof this[propertyName])) { | ||
return this[propertyName]; | ||
} | ||
return undefined; | ||
}; | ||
/** | ||
* Set alpha | ||
* Extend on color types with an alpha value | ||
* | ||
* @param {number} value | ||
* @returns {boolean} | ||
*/ | ||
colorType.prototype.setAlpha = function (value) { return false; }; | ||
/** | ||
* Stringify object | ||
@@ -73,2 +107,4 @@ * | ||
var type = showType ? this.getType() + (whitespace ? ': ' : ':') : ''; | ||
if (whitespace == null) | ||
whitespace = undefined; | ||
var json = JSON.stringify(this.toStringValues(), null, whitespace); | ||
@@ -164,17 +200,17 @@ if (!quotes) { | ||
round: args.round, | ||
bitDepth: this.bitDepth, | ||
normalize: this.normalized, | ||
colorSpace: this.colorSpace, | ||
referenceWhite: this.referenceWhite, | ||
kb: this.kb, | ||
kr: this.kr, | ||
pb: this.pb, | ||
pr: this.pr, | ||
yLower: this.yLower, | ||
yUpper: this.yUpper, | ||
cLower: this.cLower, | ||
cUpper: this.cUpper, | ||
gamma: this.gamma, | ||
bitDepth: this.get('bitDepth'), | ||
normalize: this.get('normalized'), | ||
colorSpace: this.get('colorSpace'), | ||
referenceWhite: this.get('referenceWhite'), | ||
kb: this.get('kb'), | ||
kr: this.get('kr'), | ||
pb: this.get('pb'), | ||
pr: this.get('pr'), | ||
yLower: this.get('yLower'), | ||
yUpper: this.get('yUpper'), | ||
cLower: this.get('cLower'), | ||
cUpper: this.get('cUpper'), | ||
gamma: this.get('gamma'), | ||
}; | ||
var ogalpha = this.a; | ||
var ogalpha = this.get('a'); | ||
var modified; | ||
@@ -201,3 +237,3 @@ switch (modification) { | ||
tmpColor2 = args.with.torgb({ round: false }); | ||
modified = Modify_1.default.rgbBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
modified = Modify_1.default.rgbBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
@@ -208,3 +244,3 @@ case 'hsv': | ||
tmpColor2 = args.with.tohsv({ round: false }); | ||
modified = Modify_1.default.hsvBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
modified = Modify_1.default.hsvBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
@@ -215,3 +251,3 @@ case 'hsl': | ||
tmpColor2 = args.with.tohsl({ round: false }); | ||
modified = Modify_1.default.hslBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
modified = Modify_1.default.hslBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
@@ -222,3 +258,3 @@ case 'hsi': | ||
tmpColor2 = args.with.tohsi({ round: false }); | ||
modified = Modify_1.default.hsiBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
modified = Modify_1.default.hsiBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
@@ -229,3 +265,3 @@ case 'hsp': | ||
tmpColor2 = args.with.tohsp({ round: false }); | ||
modified = Modify_1.default.hspBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
modified = Modify_1.default.hspBlend(tmpColor1, tmpColor2, args.amount); | ||
break; | ||
@@ -235,4 +271,19 @@ case 'cmyk': | ||
tmpColor2 = args.with.tocmyk({ round: false }); | ||
modified = Modify_1.default.cmykBlend(tmpColor1, tmpColor2, args.amount, args.round); | ||
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: | ||
@@ -255,8 +306,13 @@ throw new Error('Unrecognized blending method: ' + args.method); | ||
case 'rgba': | ||
modified = Modify_1.default.rgbDarken(this.torgb({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.rgbDarken(this.torgb({ round: false }), args.amount); | ||
break; | ||
case 'rgb2': | ||
case 'rgb2a': | ||
case 'rgba2': | ||
modified = Modify_1.default.rgb2Darken(this.torgb({ round: false }), args.amount); | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
case 'lightness': | ||
modified = Modify_1.default.hslDarken(this.tohsl({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hslDarken(this.tohsl({ round: false }), args.amount); | ||
break; | ||
@@ -266,3 +322,3 @@ case 'hsv': | ||
case 'value': | ||
modified = Modify_1.default.hsvDarken(this.tohsv({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsvDarken(this.tohsv({ round: false }), args.amount); | ||
break; | ||
@@ -272,3 +328,3 @@ case 'hsi': | ||
case 'intensity': | ||
modified = Modify_1.default.hsiDarken(this.tohsi({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsiDarken(this.tohsi({ round: false }), args.amount); | ||
break; | ||
@@ -281,12 +337,24 @@ case 'hsp': | ||
case 'perceivedbrightness': | ||
modified = Modify_1.default.hspDarken(this.tohsp({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hspDarken(this.tohsp({ round: false }), args.amount); | ||
break; | ||
case 'cmyk': | ||
modified = Modify_1.default.cmykDarken(this.tocmyk({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.cmykDarken(this.tocmyk({ round: false }), args.amount); | ||
break; | ||
case 'cmyk2': | ||
case 'black': | ||
case 'cmykBlack': | ||
modified = Modify_1.default.cmykBlackDarken(this.tocmyk({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.cmyk2Darken(this.tocmyk({ round: false }), args.amount); | ||
break; | ||
case 'lab': | ||
modified = Modify_1.default.labDarken(this.tolab({ round: false }), args.amount); | ||
break; | ||
case 'lab2': | ||
case 'lstar': | ||
modified = Modify_1.default.lab2Darken(this.tolab({ round: false }), args.amount); | ||
break; | ||
case 'luv': | ||
modified = Modify_1.default.luvDarken(this.toluv({ round: false }), args.amount); | ||
break; | ||
case 'luv2': | ||
modified = Modify_1.default.luv2Darken(this.toluv({ round: false }), args.amount); | ||
break; | ||
default: | ||
@@ -309,8 +377,13 @@ throw new Error('Unrecognized darken method: ' + args.method); | ||
case 'rgba': | ||
modified = Modify_1.default.rgbLighten(this.torgb({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.rgbLighten(this.torgb({ round: false }), args.amount); | ||
break; | ||
case 'rgb2': | ||
case 'rgb2a': | ||
case 'rgba2': | ||
modified = Modify_1.default.rgb2Lighten(this.torgb({ round: false }), args.amount); | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
case 'lightness': | ||
modified = Modify_1.default.hslLighten(this.tohsl({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hslLighten(this.tohsl({ round: false }), args.amount); | ||
break; | ||
@@ -320,3 +393,3 @@ case 'hsv': | ||
case 'value': | ||
modified = Modify_1.default.hsvLighten(this.tohsv({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsvLighten(this.tohsv({ round: false }), args.amount); | ||
break; | ||
@@ -326,3 +399,3 @@ case 'hsi': | ||
case 'intensity': | ||
modified = Modify_1.default.hsiLighten(this.tohsi({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsiLighten(this.tohsi({ round: false }), args.amount); | ||
break; | ||
@@ -335,12 +408,24 @@ case 'hsp': | ||
case 'perceivedbrightness': | ||
modified = Modify_1.default.hspLighten(this.tohsp({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hspLighten(this.tohsp({ round: false }), args.amount); | ||
break; | ||
case 'cmyk': | ||
modified = Modify_1.default.cmykLighten(this.tocmyk({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.cmykLighten(this.tocmyk({ round: false }), args.amount); | ||
break; | ||
case 'cmyk2': | ||
case 'black': | ||
case 'cmykBlack': | ||
modified = Modify_1.default.cmykBlackLighten(this.tocmyk({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.cmyk2Lighten(this.tocmyk({ round: false }), args.amount); | ||
break; | ||
case 'lab': | ||
modified = Modify_1.default.labLighten(this.tolab({ round: false }), args.amount); | ||
break; | ||
case 'lab2': | ||
case 'lstar': | ||
modified = Modify_1.default.lab2Lighten(this.tolab({ round: false }), args.amount); | ||
break; | ||
case 'luv': | ||
modified = Modify_1.default.luvLighten(this.toluv({ round: false }), args.amount); | ||
break; | ||
case 'luv2': | ||
modified = Modify_1.default.luv2Lighten(this.toluv({ round: false }), args.amount); | ||
break; | ||
default: | ||
@@ -364,3 +449,3 @@ throw new Error('Unrecognized lighten method: ' + args.method); | ||
case 'value': | ||
modified = Modify_1.default.hsvDesaturate(this.tohsv({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsvDesaturate(this.tohsv({ round: false }), args.amount); | ||
break; | ||
@@ -370,3 +455,3 @@ case 'hsl': | ||
case 'lightness': | ||
modified = Modify_1.default.hslDesaturate(this.tohsl({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hslDesaturate(this.tohsl({ round: false }), args.amount); | ||
break; | ||
@@ -376,3 +461,3 @@ case 'hsi': | ||
case 'intensity': | ||
modified = Modify_1.default.hsiDesaturate(this.tohsi({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsiDesaturate(this.tohsi({ round: false }), args.amount); | ||
break; | ||
@@ -385,3 +470,3 @@ case 'hsp': | ||
case 'perceivedbrightness': | ||
modified = Modify_1.default.hspDesaturate(this.tohsp({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hspDesaturate(this.tohsp({ round: false }), args.amount); | ||
break; | ||
@@ -406,3 +491,3 @@ default: | ||
case 'value': | ||
modified = Modify_1.default.hsvSaturate(this.tohsv({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsvSaturate(this.tohsv({ round: false }), args.amount); | ||
break; | ||
@@ -412,3 +497,3 @@ case 'hsl': | ||
case 'lightness': | ||
modified = Modify_1.default.hslSaturate(this.tohsl({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hslSaturate(this.tohsl({ round: false }), args.amount); | ||
break; | ||
@@ -418,3 +503,3 @@ case 'hsi': | ||
case 'intensity': | ||
modified = Modify_1.default.hsiSaturate(this.tohsi({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hsiSaturate(this.tohsi({ round: false }), args.amount); | ||
break; | ||
@@ -427,3 +512,3 @@ case 'hsp': | ||
case 'perceivedbrightness': | ||
modified = Modify_1.default.hspSaturate(this.tohsp({ round: false }), args.amount, args.round); | ||
modified = Modify_1.default.hspSaturate(this.tohsp({ round: false }), args.amount); | ||
break; | ||
@@ -439,7 +524,7 @@ default: | ||
if (typeof ogalpha !== 'undefined') | ||
ogModified.a = ogalpha; // otherwise this gets lost on some modifications | ||
ogModified.setAlpha(ogalpha); // otherwise this gets lost on some modifications | ||
return ogModified; | ||
}; | ||
colorType.prototype.scheme = function (type, args) { | ||
var _a, _b, _c; | ||
var _a; | ||
if (typeof args === 'undefined') | ||
@@ -450,18 +535,18 @@ args = {}; | ||
round: args.round, | ||
bitDepth: this.bitDepth, | ||
normalize: this.normalized, | ||
bitDepth: this.get('bitDepth'), | ||
normalize: this.get('normalized'), | ||
// Don't pass the following or the color will shift | ||
// colorSpace: this.colorSpace, | ||
// referenceWhite: this.referenceWhite, | ||
kb: this.kb, | ||
kr: this.kr, | ||
pb: this.pb, | ||
pr: this.pr, | ||
yLower: this.yLower, | ||
yUpper: this.yUpper, | ||
cLower: this.cLower, | ||
cUpper: this.cUpper, | ||
gamma: this.gamma, | ||
// colorSpace: this.get('colorSpace'), | ||
// referenceWhite: this.get('referenceWhite'), | ||
kb: this.get('kb'), | ||
kr: this.get('kr'), | ||
pb: this.get('pb'), | ||
pr: this.get('pr'), | ||
yLower: this.get('yLower'), | ||
yUpper: this.get('yUpper'), | ||
cLower: this.get('cLower'), | ||
cUpper: this.get('cUpper'), | ||
gamma: this.get('gamma'), | ||
}; | ||
var ogalpha = this.a; | ||
var ogalpha = this.get('a'); | ||
var intScheme; | ||
@@ -506,3 +591,3 @@ var distance; | ||
: args.distanceToBlack; | ||
intScheme = Harmony_1.default.shade(this, args.method ? args.method.toLowerCase() : 'hsl', args.colors, distance !== null && distance !== void 0 ? distance : 1, (_a = args.round) !== null && _a !== void 0 ? _a : true); | ||
intScheme = Harmony_1.default.shade(this, args.method ? args.method.toLowerCase() : 'hsl', args.colors, distance !== null && distance !== void 0 ? distance : 1); | ||
break; | ||
@@ -519,3 +604,3 @@ case 'tint': | ||
: args.distanceToWhite; | ||
intScheme = Harmony_1.default.tint(this, args.method ? args.method.toLowerCase() : 'hsl', args.colors, distance !== null && distance !== void 0 ? distance : 1, (_b = args.round) !== null && _b !== void 0 ? _b : true); | ||
intScheme = Harmony_1.default.tint(this, args.method ? args.method.toLowerCase() : 'hsl', args.colors, distance !== null && distance !== void 0 ? distance : 1); | ||
break; | ||
@@ -535,3 +620,3 @@ case 'tintshade': | ||
: args.distanceToWhite; | ||
intScheme = Harmony_1.default.shadetint(this, args.method ? args.method.toLowerCase() : 'hsl', args.colors, (_c = args.round) !== null && _c !== void 0 ? _c : true, distance !== null && distance !== void 0 ? distance : 1, args.distanceToBlack); | ||
intScheme = Harmony_1.default.shadetint(this, args.method ? args.method.toLowerCase() : 'hsl', args.colors, (_a = args.round) !== null && _a !== void 0 ? _a : true, distance !== null && distance !== void 0 ? distance : 1, args.distanceToBlack); | ||
break; | ||
@@ -555,3 +640,3 @@ case 'gradient': | ||
if (typeof ogalpha !== 'undefined') | ||
ogColor.a = ogalpha; // otherwise this gets lost on some modifications | ||
ogColor.setAlpha(ogalpha); // otherwise this gets lost on some modifications | ||
ogScheme.push(ogColor); | ||
@@ -558,0 +643,0 @@ }); |
@@ -379,3 +379,5 @@ import * as Colors from './Colors'; | ||
* Convert a wavelength in nm to RGB | ||
* This is hugely perceptual and approximate | ||
* This is hugely perceptual and approximate. | ||
* Adapted from http://www.physics.sfasu.edu/astro/color/spectra.html, | ||
* but with better visual falloff at edges. | ||
* | ||
@@ -382,0 +384,0 @@ * @param {Colors.nm} nm Wavelength of light in nanometers (positive number) |
@@ -63,3 +63,3 @@ import * as Colors from './Colors'; | ||
*/ | ||
static shade<T extends colorType>(color: T, method: string | undefined, colors: number, distanceToBlack?: number, round?: boolean): T[]; | ||
static shade<T extends colorType>(color: T, method: string | undefined, colors: number, distanceToBlack?: number): T[]; | ||
/** | ||
@@ -75,3 +75,3 @@ * Returns an array of colors of a lighter tint | ||
*/ | ||
static tint<T extends colorType>(color: T, method: string | undefined, colors: number, distanceToWhite?: number, round?: boolean): T[]; | ||
static tint<T extends colorType>(color: T, method: string | undefined, colors: number, distanceToWhite?: number): T[]; | ||
/** | ||
@@ -78,0 +78,0 @@ * Returns an array of colors of darker shades and lighter tints |
@@ -55,4 +55,4 @@ "use strict"; | ||
Harmony.complement = function (hsv) { | ||
var hueComplement = Modify_1.default.hueShift(hsv.h, 180); | ||
return [hsv, new Colors.hsv(hueComplement, hsv.s, hsv.v)]; | ||
var hueComplement = Modify_1.default.hueShift(hsv.getH(), 180); | ||
return [hsv, new Colors.hsv(hueComplement, hsv.getS(), hsv.getV())]; | ||
}; | ||
@@ -68,8 +68,8 @@ /** | ||
if (angle === void 0) { angle = 30; } | ||
var aHue1 = Modify_1.default.hueShift(hsv.h, angle); | ||
var aHue2 = Modify_1.default.hueShift(hsv.h, angle * -1); | ||
var aHue1 = Modify_1.default.hueShift(hsv.getH(), angle); | ||
var aHue2 = Modify_1.default.hueShift(hsv.getH(), angle * -1); | ||
return [ | ||
hsv, | ||
new Colors.hsv(aHue1, hsv.s, hsv.v), | ||
new Colors.hsv(aHue2, hsv.s, hsv.v), | ||
new Colors.hsv(aHue1, hsv.getS(), hsv.getV()), | ||
new Colors.hsv(aHue2, hsv.getS(), hsv.getV()), | ||
]; | ||
@@ -110,10 +110,10 @@ }; | ||
if (angle === void 0) { angle = 45; } | ||
var hue2 = Modify_1.default.hueShift(hsv.h, angle); | ||
var hue3 = Modify_1.default.hueShift(hsv.h, angle + 180); | ||
var hue4 = Modify_1.default.hueShift(hsv.h, 180); | ||
var hue2 = Modify_1.default.hueShift(hsv.getH(), angle); | ||
var hue3 = Modify_1.default.hueShift(hsv.getH(), angle + 180); | ||
var hue4 = Modify_1.default.hueShift(hsv.getH(), 180); | ||
return [ | ||
hsv, | ||
new Colors.hsv(hue2, hsv.s, hsv.v), | ||
new Colors.hsv(hue3, hsv.s, hsv.v), | ||
new Colors.hsv(hue4, hsv.s, hsv.v), | ||
new Colors.hsv(hue2, hsv.getS(), hsv.getV()), | ||
new Colors.hsv(hue3, hsv.getS(), hsv.getV()), | ||
new Colors.hsv(hue4, hsv.getS(), hsv.getV()), | ||
]; | ||
@@ -141,114 +141,32 @@ }; | ||
*/ | ||
Harmony.shade = function (color, method, colors, distanceToBlack, round) { | ||
Harmony.shade = function (color, method, colors, distanceToBlack) { | ||
if (method === void 0) { method = 'hsl'; } | ||
if (distanceToBlack === void 0) { distanceToBlack = 1; } | ||
if (round === void 0) { round = true; } | ||
var scheme = []; | ||
var start, end, separation; | ||
switch (method) { | ||
case 'hsv': | ||
case 'hsva': | ||
var hsv = color.to('hsv', { round: false }); | ||
start = hsv.v; | ||
end = start * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
separation = (start - end) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextV = Math.max(start - separation * i, 0); | ||
scheme.push(new Colors.hsv(hsv.h, hsv.s, nextV, hsv.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
var hsi = color.to('hsi', { round: false }); | ||
start = hsi.i; | ||
end = start * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
separation = (start - end) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextI = Math.max(start - separation * i, 0); | ||
scheme.push(new Colors.hsi(hsi.h, hsi.s, nextI, hsi.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'hsp': | ||
case 'hspa': | ||
var hsp = color.to('hsp', { round: false }); | ||
start = hsp.p; | ||
end = start * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
separation = (start - end) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextP = Math.max(start - separation * i, 0); | ||
scheme.push(new Colors.hsp(hsp.h, hsp.s, nextP, hsp.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
var hsl = color.to('hsl', { round: false }); | ||
start = hsl.l; | ||
end = start * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
separation = (start - end) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextL = Math.max(start - separation * i, 0); | ||
scheme.push(new Colors.hsl(hsl.h, hsl.s, nextL, hsl.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'rgb': | ||
case 'rgba': | ||
var rgb = color.to('rgb', { round: false }); | ||
start = Math.max(rgb.r, rgb.g, rgb.b); | ||
end = start * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
separation = (start - end) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var rNext = Math.max(rgb.r - separation * i, 0); | ||
var gNext = Math.max(rgb.g - separation * i, 0); | ||
var bNext = Math.max(rgb.b - separation * i, 0); | ||
scheme.push(new Colors.rgb(rNext, gNext, bNext, rgb.a).to(color.getType(), { round: round, bitDepth: rgb.bitDepth })); | ||
} | ||
break; | ||
case 'rgb2': | ||
case 'rgba2': | ||
var rgb2 = color.to('rgb', { round: false }); | ||
var rEnd = rgb2.r * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
var gEnd = rgb2.g * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
var bEnd = rgb2.b * (1 - Math.min(Math.max(distanceToBlack, 0), 1)); | ||
var rSep = (rgb2.r - rEnd) / (colors - 1); | ||
var gSep = (rgb2.g - gEnd) / (colors - 1); | ||
var bSep = (rgb2.b - bEnd) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var rNext = Math.max(rgb2.r - rSep * i, 0); | ||
var gNext = Math.max(rgb2.g - gSep * i, 0); | ||
var bNext = Math.max(rgb2.b - bSep * i, 0); | ||
scheme.push(new Colors.rgb(rNext, gNext, bNext, rgb2.a).to(color.getType(), { round: round, bitDepth: rgb2.bitDepth })); | ||
} | ||
break; | ||
case 'cmyk': | ||
var cmyk = color.to('cmyk', { round: false }); | ||
// reverse algorithm, max k is all values = 100 | ||
var cEnd = cmyk.c + (100 - cmyk.c) * Math.min(Math.max(distanceToBlack, 0), 1); | ||
var mEnd = cmyk.m + (100 - cmyk.m) * Math.min(Math.max(distanceToBlack, 0), 1); | ||
var yEnd = cmyk.y + (100 - cmyk.y) * Math.min(Math.max(distanceToBlack, 0), 1); | ||
var kEnd = cmyk.k + (100 - cmyk.k) * Math.min(Math.max(distanceToBlack, 0), 1); | ||
var cSep = (cmyk.c - cEnd) / (colors - 1); | ||
var mSep = (cmyk.m - mEnd) / (colors - 1); | ||
var ySep = (cmyk.y - yEnd) / (colors - 1); | ||
var kSep = (cmyk.k - kEnd) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextC = Math.min(cmyk.c - cSep * i, 100); | ||
var nextM = Math.min(cmyk.m - mSep * i, 100); | ||
var nextY = Math.min(cmyk.y - ySep * i, 100); | ||
var nextK = Math.min(cmyk.k - kSep * i, 100); | ||
scheme.push(new Colors.cmyk(nextC, nextM, nextY, nextK).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
default: | ||
throw new Error('Invalid method for generating color scheme'); | ||
if ([ | ||
'hsv', | ||
'hsva', | ||
'hsi', | ||
'hsia', | ||
'hsp', | ||
'hspa', | ||
'hsl', | ||
'hsla', | ||
'rgb', | ||
'rgb2', | ||
'cmyk', | ||
].includes(method)) { | ||
var type = method.replace(/[0-9]/, '').replace(/a$/, ''); | ||
var start = color.to(type, { round: false }); | ||
for (var n = 0; n < colors; n++) { | ||
scheme.push(start.modify('darken', { | ||
method: method, | ||
amount: (n / (colors - 1)) * distanceToBlack, | ||
round: false, | ||
})); | ||
} | ||
} | ||
else { | ||
throw new Error('Invalid shade scheme method: ' + method); | ||
} | ||
return scheme; | ||
@@ -266,128 +184,32 @@ }; | ||
*/ | ||
Harmony.tint = function (color, method, colors, distanceToWhite, round) { | ||
Harmony.tint = function (color, method, colors, distanceToWhite) { | ||
if (method === void 0) { method = 'hsl'; } | ||
if (distanceToWhite === void 0) { distanceToWhite = 1; } | ||
if (round === void 0) { round = true; } | ||
var scheme = []; | ||
var start, end, separation; | ||
switch (method) { | ||
case 'hsv': | ||
case 'hsva': | ||
var hsv = color.to('hsv', { round: false }); | ||
var startV = hsv.v; | ||
var endV = startV + (100 - startV) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
var separationV = (endV - startV) / (colors - 1); | ||
var startVS = hsv.s; | ||
var endVS = (1 - distanceToWhite) * 100; | ||
var separationVS = (endVS - startVS) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextV = Math.min(startV + separationV * i, 100); | ||
var nextS = Math.min(startVS + separationVS * i, 100); | ||
scheme.push(new Colors.hsv(hsv.h, nextS, nextV).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'hsi': | ||
case 'hsia': | ||
var hsi = color.to('hsi', { round: false }); | ||
start = hsi.i; | ||
end = start + (100 - start) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
separation = (end - start) / (colors - 1); | ||
var endIS = (1 - distanceToWhite) * 100; | ||
var separationIS = (endIS - hsi.s) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextI = Math.min(start + separation * i, 100); | ||
var nextS = Math.min(hsi.s + separationIS * i, 100); | ||
scheme.push(new Colors.hsi(hsi.h, nextS, nextI).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'hsp': | ||
case 'hspa': | ||
var hsp = color.to('hsp', { round: false }); | ||
start = hsp.p; | ||
end = start + (100 - start) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
separation = (end - start) / (colors - 1); | ||
var endPS = (1 - distanceToWhite) * 100; | ||
var separationPS = (endPS - hsp.s) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextP = Math.min(start + separation * i, 100); | ||
var nextS = Math.min(hsp.s + separationPS * i, 100); | ||
scheme.push(new Colors.hsp(hsp.h, nextS, nextP).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'hsl': | ||
case 'hsla': | ||
var hsl = color.to('hsl', { round: false }); | ||
start = hsl.l; | ||
end = start + (100 - start) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
separation = (end - start) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextL = Math.min(start + separation * i, 100); | ||
scheme.push(new Colors.hsl(hsl.h, hsl.s, nextL).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
case 'rgb': | ||
case 'rgba': | ||
var rgb = color.to('rgb', { round: false }); | ||
start = Math.min(rgb.r, rgb.g, rgb.b); | ||
end = | ||
start + (rgb.max - start) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
separation = (end - start) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var rNext = Math.min(rgb.r + separation * i, rgb.max); | ||
var gNext = Math.min(rgb.g + separation * i, rgb.max); | ||
var bNext = Math.min(rgb.b + separation * i, rgb.max); | ||
scheme.push(new Colors.rgb(rNext, gNext, bNext, rgb.a).to(color.getType(), { round: round, bitDepth: rgb.bitDepth })); | ||
} | ||
break; | ||
case 'rgb2': | ||
case 'rgba2': | ||
var rgb2 = color.to('rgb', { round: false }); | ||
var rEnd = rgb2.r + | ||
(rgb2.max - rgb2.r) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
var gEnd = rgb2.g + | ||
(rgb2.max - rgb2.g) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
var bEnd = rgb2.b + | ||
(rgb2.max - rgb2.b) * Math.min(Math.max(distanceToWhite, 0), 1); | ||
var rSep = (rEnd - rgb2.r) / (colors - 1); | ||
var gSep = (gEnd - rgb2.g) / (colors - 1); | ||
var bSep = (bEnd - rgb2.b) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var rNext = Math.min(rgb2.r + rSep * i, rgb2.max); | ||
var gNext = Math.min(rgb2.g + gSep * i, rgb2.max); | ||
var bNext = Math.min(rgb2.b + bSep * i, rgb2.max); | ||
scheme.push(new Colors.rgb(rNext, gNext, bNext, rgb2.a).to(color.getType(), { round: round, bitDepth: rgb2.bitDepth })); | ||
} | ||
break; | ||
case 'cmyk': | ||
var cmyk = color.to('cmyk', { round: false }); | ||
// reverse algorithm, max "white" is all values = 0 | ||
var cEnd = cmyk.c * (1 - Math.min(Math.max(distanceToWhite, 0), 1)); | ||
var mEnd = cmyk.m * (1 - Math.min(Math.max(distanceToWhite, 0), 1)); | ||
var yEnd = cmyk.y * (1 - Math.min(Math.max(distanceToWhite, 0), 1)); | ||
var kEnd = cmyk.k * (1 - Math.min(Math.max(distanceToWhite, 0), 1)); | ||
var cSep = (cmyk.c - cEnd) / (colors - 1); | ||
var mSep = (cmyk.m - mEnd) / (colors - 1); | ||
var ySep = (cmyk.y - yEnd) / (colors - 1); | ||
var kSep = (cmyk.k - kEnd) / (colors - 1); | ||
for (var i = 0; i < colors; i++) { | ||
var nextC = Math.max(cmyk.c - cSep * i, 0); | ||
var nextM = Math.max(cmyk.m - mSep * i, 0); | ||
var nextY = Math.max(cmyk.y - ySep * i, 0); | ||
var nextK = Math.max(cmyk.k - kSep * i, 0); | ||
scheme.push(new Colors.cmyk(nextC, nextM, nextY, nextK).to(color.getType(), { | ||
round: round, | ||
})); | ||
} | ||
break; | ||
default: | ||
throw new Error('Invalid method for generating color scheme'); | ||
if ([ | ||
'hsv', | ||
'hsva', | ||
'hsi', | ||
'hsia', | ||
'hsp', | ||
'hspa', | ||
'hsl', | ||
'hsla', | ||
'rgb', | ||
'rgb2', | ||
'cmyk', | ||
].includes(method)) { | ||
var type = method.replace(/[0-9]/, '').replace(/a$/, ''); | ||
var start = color.to(type, { round: false }); | ||
for (var n = 0; n < colors; n++) { | ||
scheme.push(start.modify('lighten', { | ||
method: method, | ||
amount: (n / (colors - 1)) * distanceToWhite, | ||
round: false, | ||
})); | ||
} | ||
} | ||
else { | ||
throw new Error('Invalid tint scheme method: ' + method); | ||
} | ||
return scheme; | ||
@@ -416,33 +238,16 @@ }; | ||
if (typeof distanceShade === 'undefined') { | ||
if (100 - hsl.l < hsl.l) { | ||
tEnd = hsl.l + (100 - hsl.l) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsl.l) / colors; | ||
sSeparation = tSeparation; | ||
sEnd = hsl.l - sSeparation * colors; | ||
if (100 - hsl.getL() < hsl.getL()) { | ||
distanceShade = (100 - hsl.getL()) / 50 * distance; | ||
} | ||
else { | ||
sEnd = hsl.l * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sSeparation = (hsl.l - sEnd) / colors; | ||
tSeparation = sSeparation; | ||
tEnd = hsl.l + tSeparation * colors; | ||
distanceShade = distance; | ||
distance = hsl.getL() / 50 * distanceShade; | ||
} | ||
} | ||
else { | ||
tEnd = hsl.l + (100 - hsl.l) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsl.l) / colors; | ||
sEnd = hsl.l * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sSeparation = (hsl.l - sEnd) / colors; | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
var nextL = Math.max(sEnd + sSeparation * i, 0); | ||
scheme.push(new Colors.hsl(hsl.h, hsl.s, nextL, hsl.a).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++) { | ||
var nextL = Math.min(hsl.l + tSeparation * i, 100); | ||
scheme.push(new Colors.hsl(hsl.h, hsl.s, nextL, hsl.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
scheme.push(Modify_1.default.hslLighten(hsl, i / colors * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -453,43 +258,17 @@ break; | ||
var hsv = color.to('hsv', { round: false }); | ||
var separationTVS = void 0; | ||
var endTVS = (1 - distance) * 100; | ||
if (typeof distanceShade === 'undefined') { | ||
var distanceFromWhite = 100 - hsv.v + hsv.s; | ||
if (distanceFromWhite < 100) { | ||
// closer to white | ||
tEnd = hsv.v + (100 - hsv.v) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsv.v) / colors; | ||
separationTVS = (endTVS - hsv.s) / colors; | ||
sSeparation = tSeparation - separationTVS; | ||
sEnd = hsv.v - sSeparation * colors; | ||
if (100 - hsv.getV() < hsv.getV()) { | ||
distanceShade = (100 - hsv.getV()) / 50 * distance; | ||
} | ||
else { | ||
// closer to black | ||
sEnd = hsv.v * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sSeparation = (hsv.v - sEnd) / colors; | ||
tEnd = hsv.v + sSeparation * (colors - 1); | ||
separationTVS = (-1 * Math.abs(hsv.s - tEnd)) / colors; | ||
// tint spacing should take saturation into account? | ||
tSeparation = sSeparation + separationTVS; | ||
distanceShade = distance; | ||
distance = hsv.getV() / 50 * distanceShade; | ||
} | ||
} | ||
else { | ||
tEnd = hsv.v + (100 - hsv.v) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsv.v) / colors; | ||
sEnd = hsv.v * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sSeparation = (hsv.v - sEnd) / colors; | ||
separationTVS = (endTVS - hsv.s) / colors; | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
var nextV = Math.min(Math.max(sEnd + sSeparation * i, 0), 100); | ||
scheme.push(new Colors.hsv(hsv.h, hsv.s, nextV, hsv.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
scheme.push(Modify_1.default.hsvDarken(hsv, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
for (var i = 0; i <= colors; i++) { | ||
var nextV = Math.max(Math.min(hsv.v + tSeparation * i, 100), 0); | ||
var nextTVS = Math.min(Math.max(hsv.s + separationTVS * i, 0), 100); | ||
scheme.push(new Colors.hsv(hsv.h, nextTVS, nextV, hsv.a).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 })); | ||
} | ||
@@ -500,43 +279,17 @@ break; | ||
var hsi = color.to('hsi', { round: false }); | ||
var separationTIS = void 0; | ||
var endTIS = (1 - distance) * 100; | ||
if (typeof distanceShade === 'undefined') { | ||
var distanceFromWhite = 100 - hsi.i + hsi.s; | ||
if (distanceFromWhite < 100) { | ||
// closer to white | ||
tEnd = hsi.i + (100 - hsi.i) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsi.i) / colors; | ||
sSeparation = tSeparation; | ||
sEnd = hsi.i - sSeparation * colors; | ||
separationTIS = (endTIS - hsi.s) / colors; | ||
if (100 - hsi.getI() < hsi.getI()) { | ||
distanceShade = (100 - hsi.getI()) / 50 * distance; | ||
} | ||
else { | ||
// closer to black | ||
sEnd = hsi.i * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sSeparation = (hsi.i - sEnd) / colors; | ||
tSeparation = sSeparation; | ||
tEnd = hsi.i + tSeparation * (colors - 1); | ||
separationTIS = (-1 * Math.abs(hsi.s - tEnd)) / colors; | ||
distanceShade = distance; | ||
distance = hsi.getI() / 50 * distanceShade; | ||
} | ||
} | ||
else { | ||
tEnd = hsi.i + (100 - hsi.i) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsi.i) / colors; | ||
sEnd = hsi.i * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sSeparation = (hsi.i - sEnd) / colors; | ||
separationTIS = (endTIS - hsi.s) / colors; | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
var nextI = Math.max(sEnd + sSeparation * i, 0); | ||
scheme.push(new Colors.hsi(hsi.h, hsi.s, nextI, hsi.a).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++) { | ||
var nextI = Math.min(hsi.i + tSeparation * i, 100); | ||
var nextTIS = Math.max(hsi.s + separationTIS * i, 0); | ||
scheme.push(new Colors.hsi(hsi.h, nextTIS, nextI, hsi.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
scheme.push(Modify_1.default.hsiLighten(hsi, i / colors * distance).to(color.getType(), { round: round })); | ||
} | ||
@@ -547,148 +300,59 @@ break; | ||
var hsp = color.to('hsp', { round: false }); | ||
var separationTPS = void 0; | ||
var endTPS = (1 - distance) * 100; | ||
if (typeof distanceShade === 'undefined') { | ||
if (100 - hsp.p < hsp.p) { | ||
// closer to white | ||
tEnd = hsp.p + (100 - hsp.p) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsp.p) / colors; | ||
sSeparation = tSeparation; | ||
sEnd = hsp.p - sSeparation * colors; | ||
separationTPS = (endTPS - hsp.s) / colors; | ||
if (100 - hsp.getP() < hsp.getP()) { | ||
distanceShade = (100 - hsp.getP()) / 50 * distance; | ||
} | ||
else { | ||
// closer to black | ||
sEnd = hsp.p * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sSeparation = (hsp.p - sEnd) / colors; | ||
tSeparation = sSeparation; | ||
tEnd = hsp.p + tSeparation * colors; | ||
separationTPS = (-1 * Math.abs(hsp.s - tEnd)) / colors; | ||
distanceShade = distance; | ||
distance = hsp.getP() / 50 * distanceShade; | ||
} | ||
} | ||
else { | ||
tEnd = hsp.p + (100 - hsp.p) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - hsp.p) / colors; | ||
sEnd = hsp.p * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sSeparation = (hsp.p - sEnd) / colors; | ||
separationTPS = (endTPS - hsp.s) / colors; | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
var nextP = Math.max(sEnd + sSeparation * i, 0); | ||
scheme.push(new Colors.hsp(hsp.h, hsp.s, nextP, hsp.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
scheme.push(Modify_1.default.hspDarken(hsp, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
for (var i = 0; i <= colors; i++) { | ||
var nextP = Math.min(hsp.p + tSeparation * i, 100); | ||
var nextTPS = Math.max(hsp.s + separationTPS * i, 0); | ||
scheme.push(new Colors.hsp(hsp.h, nextTPS, nextP, hsp.a).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 })); | ||
} | ||
break; | ||
case 'rgb': | ||
case 'rgba': | ||
var rgb = color.to('rgb', { round: false }); | ||
var maxVal = Math.max(rgb.r, rgb.g, rgb.b); | ||
var minVal = Math.min(rgb.r, rgb.g, rgb.b); | ||
case 'rgb2': | ||
case 'rgba2': | ||
var rgb2 = color.to('rgb', { round: false }); | ||
if (typeof distanceShade === 'undefined') { | ||
if (rgb.max - minVal < maxVal) { | ||
tEnd = | ||
minVal + (rgb.max - minVal) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - minVal) / colors; | ||
sSeparation = tSeparation; | ||
sEnd = minVal - sSeparation * colors; | ||
var avg = (rgb2.getR() + rgb2.getG() + rgb2.getB()) / 3; | ||
if (rgb2.getMax() - avg < avg) { | ||
distanceShade = (rgb2.getMax() - Math.min(rgb2.getR(), rgb2.getG(), rgb2.getB())) / rgb2.getMax() / 2 * distance; | ||
} | ||
else { | ||
sEnd = maxVal * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sSeparation = (maxVal - sEnd) / colors; | ||
tSeparation = sSeparation; | ||
tEnd = maxVal + tSeparation * colors; | ||
distanceShade = distance; | ||
distance = Math.max(rgb2.getR(), rgb2.getG(), rgb2.getB()) / rgb2.getMax() / 2 * distanceShade; | ||
} | ||
} | ||
else { | ||
tEnd = | ||
minVal + (rgb.max - minVal) * Math.min(Math.max(distance, 0), 1); | ||
tSeparation = (tEnd - minVal) / colors; | ||
sEnd = maxVal * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sSeparation = (maxVal - sEnd) / colors; | ||
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(rgb2.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
var rNext = Math.max(rgb.r - sSeparation * i, 0); | ||
var gNext = Math.max(rgb.g - sSeparation * i, 0); | ||
var bNext = Math.max(rgb.b - sSeparation * i, 0); | ||
scheme.unshift(new Colors.rgb(rNext, gNext, bNext, rgb.a).to(color.getType(), { round: round, bitDepth: rgb.bitDepth })); | ||
scheme.push(Modify_1.default.rgb2Lighten(rgb2, i / colors * distance).to(color.getType(), { round: round })); | ||
} | ||
scheme.push(rgb.to(color.getType(), { round: round })); | ||
for (var i = 1; i <= colors; i++) { | ||
var rNext = Math.min(rgb.r + tSeparation * i, rgb.max); | ||
var gNext = Math.min(rgb.g + tSeparation * i, rgb.max); | ||
var bNext = Math.min(rgb.b + tSeparation * i, rgb.max); | ||
scheme.push(new Colors.rgb(rNext, gNext, bNext, rgb.a).to(color.getType(), { round: round, bitDepth: rgb.bitDepth })); | ||
} | ||
break; | ||
case 'rgb2': | ||
case 'rgba2': | ||
var rgb2 = color.to('rgb', { round: false }); | ||
var tREnd = void 0, tGEnd = void 0, tBEnd = void 0, sREnd = void 0, sGEnd = void 0, sBEnd = void 0, tRSep = void 0, tGSep = void 0, tBSep = void 0, sRSep = void 0, sGSep = void 0, sBSep = void 0; | ||
case 'rgb': | ||
case 'rgba': | ||
var rgb = color.to('rgb', { round: false }); | ||
if (typeof distanceShade === 'undefined') { | ||
var percentDistanceToWhite = (rgb2.max * 3 - rgb2.r - rgb2.g - rgb2.b) / (rgb2.max * 3); | ||
if (percentDistanceToWhite < 0.5) { | ||
tREnd = rgb2.r + (rgb2.max - rgb2.r) * Math.min(Math.max(distance, 0), 1); | ||
tRSep = (tREnd - rgb2.r) / colors; | ||
sREnd = rgb2.r * percentDistanceToWhite; | ||
sRSep = (rgb2.r - sREnd) / colors; | ||
tGEnd = rgb2.g + (rgb2.max - rgb2.g) * Math.min(Math.max(distance, 0), 1); | ||
tGSep = (tGEnd - rgb2.g) / colors; | ||
sGEnd = rgb2.g * percentDistanceToWhite; | ||
sGSep = (rgb2.g - sGEnd) / colors; | ||
tBEnd = rgb2.b + (rgb2.max - rgb2.b) * Math.min(Math.max(distance, 0), 1); | ||
tBSep = (tBEnd - rgb2.b) / colors; | ||
sBEnd = rgb2.b * percentDistanceToWhite; | ||
sBSep = (rgb2.b - sBEnd) / colors; | ||
var avg = (rgb.getR() + rgb.getG() + rgb.getB()) / 3; | ||
if (rgb.getMax() - avg < avg) { | ||
distanceShade = (rgb.getMax() - Math.min(rgb.getR(), rgb.getG(), rgb.getB())) / rgb.getMax() / 2 * distance; | ||
} | ||
else { | ||
sREnd = rgb2.r * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sRSep = (rgb2.r - sREnd) / colors; | ||
tREnd = rgb2.r * (1 + ((rgb2.max - rgb2.r) / rgb2.max)); | ||
tRSep = (tREnd - rgb2.r) / colors; | ||
sGEnd = rgb2.g * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sGSep = (rgb2.g - sGEnd) / colors; | ||
tGEnd = rgb2.g * (1 + ((rgb2.max - rgb2.g) / rgb2.max)); | ||
tGSep = (tGEnd - rgb2.g) / colors; | ||
sBEnd = rgb2.b * (1 - Math.min(Math.max(distance, 0), 1)); | ||
sBSep = (rgb2.b - sBEnd) / colors; | ||
tBEnd = rgb2.b * (1 + ((rgb2.max - rgb2.b) / rgb2.max)); | ||
tBSep = (tBEnd - rgb2.b) / colors; | ||
distanceShade = distance; | ||
distance = Math.max(rgb.getR(), rgb.getG(), rgb.getB()) / rgb.getMax() / 2 * distanceShade; | ||
} | ||
} | ||
else { | ||
tREnd = rgb2.r + (rgb2.max - rgb2.r) * Math.min(Math.max(distance, 0), 1); | ||
tRSep = (tREnd - rgb2.r) / colors; | ||
sREnd = rgb2.r * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sRSep = (rgb2.r - sREnd) / colors; | ||
tGEnd = rgb2.g + (rgb2.max - rgb2.g) * Math.min(Math.max(distance, 0), 1); | ||
tGSep = (tGEnd - rgb2.g) / colors; | ||
sGEnd = rgb2.g * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sGSep = (rgb2.g - sGEnd) / colors; | ||
tBEnd = rgb2.b + (rgb2.max - rgb2.b) * Math.min(Math.max(distance, 0), 1); | ||
tBSep = (tBEnd - rgb2.b) / colors; | ||
sBEnd = rgb2.b * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
sBSep = (rgb2.b - sBEnd) / colors; | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
var rNext = Math.min(Math.max(sREnd + sRSep * i, 0), rgb2.max); | ||
var gNext = Math.min(Math.max(sGEnd + sGSep * i, 0), rgb2.max); | ||
var bNext = Math.min(Math.max(sBEnd + sBSep * i, 0), rgb2.max); | ||
scheme.push(new Colors.rgb(rNext, gNext, bNext, rgb2.a).to(color.getType(), { | ||
round: round, | ||
})); | ||
scheme.push(Modify_1.default.rgbDarken(rgb, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
for (var i = 0; i <= colors; i++) { | ||
var rNext = Math.min(Math.max(rgb2.r + tRSep * i, 0), rgb2.max); | ||
var gNext = Math.min(Math.max(rgb2.g + tGSep * i, 0), rgb2.max); | ||
var bNext = Math.min(Math.max(rgb2.b + tBSep * i, 0), rgb2.max); | ||
scheme.push(new Colors.rgb(rNext, gNext, bNext, rgb2.a).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 })); | ||
} | ||
@@ -698,82 +362,17 @@ break; | ||
var cmyk = color.to('cmyk', { round: false }); | ||
var tCEnd = void 0, tMEnd = void 0, tYEnd = void 0, tKEnd = void 0, sCEnd = void 0, sMEnd = void 0, sYEnd = void 0, sKEnd = void 0, tCSep = void 0, tMSep = void 0, tYSep = void 0, tKSep = void 0, sCSep = void 0, sMSep = void 0, sYSep = void 0, sKSep = void 0; | ||
if (typeof distanceShade === 'undefined') { | ||
var percentDistanceToWhite = (cmyk.c + cmyk.m + cmyk.y + cmyk.k) / 400; | ||
// not sure how to calculate when to go up or down with cmyk, so using rgb | ||
var rgb_1 = cmyk.to('rgb'); | ||
var perceivedDistanceToWhite = (rgb_1.max * 3 - rgb_1.r - rgb_1.g - rgb_1.b) / (rgb_1.max * 3); | ||
if (perceivedDistanceToWhite > 0.5) { | ||
// closer to black | ||
sCEnd = cmyk.c + (100 - cmyk.c) * Math.min(Math.max(distance, 0), 1); | ||
sCSep = (sCEnd - cmyk.c) / colors; | ||
tCEnd = cmyk.c * percentDistanceToWhite; | ||
tCSep = (cmyk.c - tCEnd) / colors; | ||
sMEnd = cmyk.m + (100 - cmyk.m) * Math.min(Math.max(distance, 0), 1); | ||
sMSep = (sMEnd - cmyk.m) / colors; | ||
tMEnd = cmyk.m * percentDistanceToWhite; | ||
tMSep = (cmyk.m - tMEnd) / colors; | ||
sYEnd = cmyk.y + (100 - cmyk.y) * Math.min(Math.max(distance, 0), 1); | ||
sYSep = (sYEnd - cmyk.y) / colors; | ||
tYEnd = cmyk.y * percentDistanceToWhite; | ||
tYSep = (cmyk.y - tYEnd) / colors; | ||
sKEnd = cmyk.k + (100 - cmyk.k) * Math.min(Math.max(distance, 0), 1); | ||
sKSep = (sKEnd - cmyk.k) / colors; | ||
tKEnd = cmyk.k * percentDistanceToWhite; | ||
tKSep = (cmyk.k - tKEnd) / colors; | ||
if (cmyk.getK() < 50) { | ||
distanceShade = cmyk.getK() / 50 * distance; | ||
} | ||
else { | ||
// closer to white | ||
tCEnd = cmyk.c * (1 - Math.min(Math.max(distance, 0), 1)); | ||
tCSep = (cmyk.c - tCEnd) / colors; | ||
sCEnd = cmyk.c * (1 + ((100 - cmyk.c) / 100)); | ||
sCSep = (sCEnd - cmyk.c) / colors; | ||
tMEnd = cmyk.m * (1 - Math.min(Math.max(distance, 0), 1)); | ||
tMSep = (cmyk.m - tMEnd) / colors; | ||
sMEnd = cmyk.m * (1 + ((100 - cmyk.m) / 100)); | ||
sMSep = (sMEnd - cmyk.m) / colors; | ||
tYEnd = cmyk.y * (1 - Math.min(Math.max(distance, 0), 1)); | ||
tYSep = (cmyk.y - tYEnd) / colors; | ||
sYEnd = cmyk.y * (1 + ((100 - cmyk.y) / 100)); | ||
sYSep = (sYEnd - cmyk.y) / colors; | ||
tKEnd = cmyk.k * (1 - Math.min(Math.max(distance, 0), 1)); | ||
tKSep = (cmyk.k - tKEnd) / colors; | ||
sKEnd = cmyk.k * (1 + ((100 - cmyk.k) / 100)); | ||
sKSep = (sKEnd - cmyk.k) / colors; | ||
distanceShade = distance; | ||
distance = (100 - cmyk.getK()) / 50 * distanceShade; | ||
} | ||
} | ||
else { | ||
sCEnd = cmyk.c + (100 - cmyk.c) * Math.min(Math.max(distance, 0), 1); | ||
sCSep = (sCEnd - cmyk.c) / colors; | ||
tCEnd = cmyk.c * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
tCSep = (cmyk.c - tCEnd) / colors; | ||
sMEnd = cmyk.m + (100 - cmyk.m) * Math.min(Math.max(distance, 0), 1); | ||
sMSep = (sMEnd - cmyk.m) / colors; | ||
tMEnd = cmyk.m * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
tMSep = (cmyk.m - tMEnd) / colors; | ||
sYEnd = cmyk.y + (100 - cmyk.y) * Math.min(Math.max(distance, 0), 1); | ||
sYSep = (sYEnd - cmyk.y) / colors; | ||
tYEnd = cmyk.y * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
tYSep = (cmyk.y - tYEnd) / colors; | ||
sKEnd = cmyk.k + (100 - cmyk.k) * Math.min(Math.max(distance, 0), 1); | ||
sKSep = (sKEnd - cmyk.k) / colors; | ||
tKEnd = cmyk.k * (1 - Math.min(Math.max(distanceShade, 0), 1)); | ||
tKSep = (cmyk.k - tKEnd) / colors; | ||
} | ||
for (var i = 0; i < colors; i++) { | ||
var cNext = Math.min(Math.max(sCEnd - sCSep * i, 0), 100); | ||
var mNext = Math.min(Math.max(sMEnd - sMSep * i, 0), 100); | ||
var yNext = Math.min(Math.max(sYEnd - sYSep * i, 0), 100); | ||
var kNext = Math.min(Math.max(sKEnd - sKSep * i, 0), 100); | ||
scheme.push(new Colors.cmyk(cNext, mNext, yNext, kNext).to(color.getType(), { | ||
round: round, | ||
})); | ||
scheme.push(Modify_1.default.cmykDarken(cmyk, (colors - i) / colors * distanceShade).to(color.getType(), { round: round })); | ||
} | ||
for (var i = 0; i <= colors; i++) { | ||
var cNext = Math.min(Math.max(cmyk.c - tCSep * i, 0), 100); | ||
var mNext = Math.min(Math.max(cmyk.m - tMSep * i, 0), 100); | ||
var yNext = Math.min(Math.max(cmyk.y - tYSep * i, 0), 100); | ||
var kNext = Math.min(Math.max(cmyk.k - tKSep * i, 0), 100); | ||
scheme.push(new Colors.cmyk(cNext, mNext, yNext, kNext).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 })); | ||
} | ||
@@ -807,26 +406,32 @@ break; | ||
case 'rgba': | ||
gradient.push(Modify_1.default.rgbBlend(color1.to('rgb', { round: false }), color2.to('rgb', { round: false }), amount, false).to(color1.getType(), { round: round })); | ||
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, false).to(color1.getType(), { round: round })); | ||
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, false).to(color1.getType(), { round: round })); | ||
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, false).to(color1.getType(), { round: round })); | ||
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, false).to(color1.getType(), { round: round })); | ||
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, false).to(color1.getType(), { round: round })); | ||
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, false).to(color1.getType(), { round: round })); | ||
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; | ||
} | ||
@@ -833,0 +438,0 @@ } |
@@ -21,3 +21,3 @@ import * as Colors from './Colors'; | ||
*/ | ||
static rgbBlend(rgb1: Colors.rgb, rgb2: Colors.rgb, amount?: number, round?: boolean): Colors.rgb; | ||
static rgbBlend(rgb1: Colors.rgb, rgb2: Colors.rgb, amount?: number): Colors.rgb; | ||
/** | ||
@@ -32,3 +32,3 @@ * Blend one HSV color with another | ||
*/ | ||
static hsvBlend(hsv1: Colors.hsv, hsv2: Colors.hsv, amount?: number, round?: boolean): Colors.hsv; | ||
static hsvBlend(hsv1: Colors.hsv, hsv2: Colors.hsv, amount?: number): Colors.hsv; | ||
/** | ||
@@ -43,3 +43,3 @@ * Blend one HSL color with another | ||
*/ | ||
static hslBlend(hsl1: Colors.hsl, hsl2: Colors.hsl, amount?: number, round?: boolean): Colors.hsl; | ||
static hslBlend(hsl1: Colors.hsl, hsl2: Colors.hsl, amount?: number): Colors.hsl; | ||
/** | ||
@@ -54,3 +54,3 @@ * Blend one HSI color with another | ||
*/ | ||
static hsiBlend(hsi1: Colors.hsi, hsi2: Colors.hsi, amount?: number, round?: boolean): Colors.hsi; | ||
static hsiBlend(hsi1: Colors.hsi, hsi2: Colors.hsi, amount?: number): Colors.hsi; | ||
/** | ||
@@ -65,3 +65,3 @@ * Blend one HSP color with another | ||
*/ | ||
static hspBlend(hsp1: Colors.hsp, hsp2: Colors.hsp, amount?: number, round?: boolean): Colors.hsp; | ||
static hspBlend(hsp1: Colors.hsp, hsp2: Colors.hsp, amount?: number): Colors.hsp; | ||
/** | ||
@@ -76,3 +76,3 @@ * Blend one CMYK color with another | ||
*/ | ||
static cmykBlend(cmyk1: Colors.cmyk, cmyk2: Colors.cmyk, amount?: number, round?: boolean): Colors.cmyk; | ||
static cmykBlend(cmyk1: Colors.cmyk, cmyk2: Colors.cmyk, amount?: number): Colors.cmyk; | ||
/** | ||
@@ -87,26 +87,38 @@ * Blend one YIQ color with another | ||
*/ | ||
static yiqBlend(c1: Colors.yiq, c2: Colors.yiq, amount?: number, round?: boolean): Colors.yiq; | ||
static rgbDarken(rgb: Colors.rgb, amount?: number, round?: boolean): Colors.rgb; | ||
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; | ||
static hspLighten(hsp: Colors.hsp, amount?: number, round?: boolean): Colors.hsp; | ||
static hslDesaturate(hsl: Colors.hsl, amount?: number, round?: boolean): Colors.hsl; | ||
static hslSaturate(hsl: Colors.hsl, amount?: number, round?: boolean): Colors.hsl; | ||
static hsvDesaturate(hsv: Colors.hsv, amount?: number, round?: boolean): Colors.hsv; | ||
static hsvSaturate(hsv: Colors.hsv, amount?: number, round?: boolean): Colors.hsv; | ||
static hsiDesaturate(hsi: Colors.hsi, amount?: number, round?: boolean): Colors.hsi; | ||
static hsiSaturate(hsi: Colors.hsi, amount?: number, round?: boolean): Colors.hsi; | ||
static hspDesaturate(hsp: Colors.hsp, amount?: number, round?: boolean): Colors.hsp; | ||
static hspSaturate(hsp: Colors.hsp, amount?: number, round?: boolean): Colors.hsp; | ||
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; | ||
static cmyk2Lighten(cmyk: Colors.cmyk, amount?: number): Colors.cmyk; | ||
static hslDarken(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
static hslLighten(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
static hsvDarken(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
static hsvLighten(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
static hsiDarken(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
static hsiLighten(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
static hspDarken(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
static hspLighten(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
static labDarken(lab: Colors.lab, amount?: number): Colors.lab; | ||
static labLighten(lab: Colors.lab, amount?: number): Colors.lab; | ||
static lab2Darken(lab: Colors.lab, amount?: number): Colors.lab; | ||
static lab2Lighten(lab: Colors.lab, amount?: number): Colors.lab; | ||
static luvDarken(luv: Colors.luv, amount?: number): Colors.luv; | ||
static luvLighten(luv: Colors.luv, amount?: number): Colors.luv; | ||
static luv2Darken(luv: Colors.luv, amount?: number): Colors.luv; | ||
static luv2Lighten(luv: Colors.luv, amount?: number): Colors.luv; | ||
static hslDesaturate(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
static hslSaturate(hsl: Colors.hsl, amount?: number): Colors.hsl; | ||
static hsvDesaturate(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
static hsvSaturate(hsv: Colors.hsv, amount?: number): Colors.hsv; | ||
static hsiDesaturate(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
static hsiSaturate(hsi: Colors.hsi, amount?: number): Colors.hsi; | ||
static hspDesaturate(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
static hspSaturate(hsp: Colors.hsp, amount?: number): Colors.hsp; | ||
} | ||
export = Modify; |
@@ -69,16 +69,9 @@ "use strict"; | ||
*/ | ||
Modify.rgbBlend = function (rgb1, rgb2, amount, round) { | ||
Modify.rgbBlend = function (rgb1, rgb2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var r3 = rgb1.r + (rgb2.r - rgb1.r) * amount; | ||
var g3 = rgb1.g + (rgb2.g - rgb1.g) * amount; | ||
var b3 = rgb1.b + (rgb2.b - rgb1.b) * amount; | ||
var a3 = rgb1.a + (rgb2.a - rgb1.a) * amount; | ||
if (round) { | ||
r3 = Math.round(r3); | ||
g3 = Math.round(g3); | ||
b3 = Math.round(b3); | ||
a3 = Math.round(a3); | ||
} | ||
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); | ||
@@ -95,23 +88,16 @@ }; | ||
*/ | ||
Modify.hsvBlend = function (hsv1, hsv2, amount, round) { | ||
Modify.hsvBlend = function (hsv1, hsv2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsv2.h - hsv1.h) > 180) { | ||
hueDiff = 360 - (hsv2.h - hsv1.h) * amount * -1; | ||
if (Math.abs(hsv2.getH() - hsv1.getH()) > 180) { | ||
hueDiff = 360 - (hsv2.getH() - hsv1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsv2.h - hsv1.h) * amount; | ||
hueDiff = (hsv2.getH() - hsv1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsv1.h, hueDiff); | ||
var s3 = hsv1.s + (hsv2.s - hsv1.s) * amount; | ||
var v3 = hsv1.v + (hsv2.v - hsv1.v) * amount; | ||
var a3 = hsv1.a + (hsv2.a - hsv1.a) * amount; | ||
if (round) { | ||
h3 = Math.round(h3); | ||
s3 = Math.round(s3); | ||
v3 = Math.round(v3); | ||
a3 = Math.round(a3); | ||
} | ||
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); | ||
@@ -128,23 +114,16 @@ }; | ||
*/ | ||
Modify.hslBlend = function (hsl1, hsl2, amount, round) { | ||
Modify.hslBlend = function (hsl1, hsl2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsl2.h - hsl1.h) > 180) { | ||
hueDiff = 360 - (hsl2.h - hsl1.h) * amount * -1; | ||
if (Math.abs(hsl2.getH() - hsl1.getH()) > 180) { | ||
hueDiff = 360 - (hsl2.getH() - hsl1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsl2.h - hsl1.h) * amount; | ||
hueDiff = (hsl2.getH() - hsl1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsl1.h, hueDiff); | ||
var s3 = hsl1.s + (hsl2.s - hsl1.s) * amount; | ||
var l3 = hsl1.l + (hsl2.l - hsl1.l) * amount; | ||
var a3 = hsl1.a + (hsl2.a - hsl1.a) * amount; | ||
if (round) { | ||
h3 = Math.round(h3); | ||
s3 = Math.round(s3); | ||
l3 = Math.round(l3); | ||
a3 = Math.round(a3); | ||
} | ||
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); | ||
@@ -161,23 +140,16 @@ }; | ||
*/ | ||
Modify.hsiBlend = function (hsi1, hsi2, amount, round) { | ||
Modify.hsiBlend = function (hsi1, hsi2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsi2.h - hsi1.h) > 180) { | ||
hueDiff = 360 - (hsi2.h - hsi1.h) * amount * -1; | ||
if (Math.abs(hsi2.getH() - hsi1.getH()) > 180) { | ||
hueDiff = 360 - (hsi2.getH() - hsi1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsi2.h - hsi1.h) * amount; | ||
hueDiff = (hsi2.getH() - hsi1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsi1.h, hueDiff); | ||
var s3 = hsi1.s + (hsi2.s - hsi1.s) * amount; | ||
var i3 = hsi1.i + (hsi2.i - hsi1.i) * amount; | ||
var a3 = hsi1.a + (hsi2.a - hsi1.a) * amount; | ||
if (round) { | ||
h3 = Math.round(h3); | ||
s3 = Math.round(s3); | ||
i3 = Math.round(i3); | ||
a3 = Math.round(a3); | ||
} | ||
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); | ||
@@ -194,23 +166,16 @@ }; | ||
*/ | ||
Modify.hspBlend = function (hsp1, hsp2, amount, round) { | ||
Modify.hspBlend = function (hsp1, hsp2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var hueDiff; | ||
if (Math.abs(hsp2.h - hsp1.h) > 180) { | ||
hueDiff = 360 - (hsp2.h - hsp1.h) * amount * -1; | ||
if (Math.abs(hsp2.getH() - hsp1.getH()) > 180) { | ||
hueDiff = 360 - (hsp2.getH() - hsp1.getH()) * amount * -1; | ||
} | ||
else { | ||
hueDiff = (hsp2.h - hsp1.h) * amount; | ||
hueDiff = (hsp2.getH() - hsp1.getH()) * amount; | ||
} | ||
var h3 = this.hueShift(hsp1.h, hueDiff); | ||
var s3 = hsp1.s + (hsp2.s - hsp1.s) * amount; | ||
var p3 = hsp1.p + (hsp2.p - hsp1.p) * amount; | ||
var a3 = hsp1.a + (hsp2.a - hsp1.a) * amount; | ||
if (round) { | ||
h3 = Math.round(h3); | ||
s3 = Math.round(s3); | ||
p3 = Math.round(p3); | ||
a3 = Math.round(a3); | ||
} | ||
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); | ||
@@ -227,16 +192,9 @@ }; | ||
*/ | ||
Modify.cmykBlend = function (cmyk1, cmyk2, amount, round) { | ||
Modify.cmykBlend = function (cmyk1, cmyk2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var c3 = cmyk1.c + (cmyk2.c - cmyk1.c) * amount; | ||
var m3 = cmyk1.m + (cmyk2.m - cmyk1.m) * amount; | ||
var y3 = cmyk1.y + (cmyk2.y - cmyk1.y) * amount; | ||
var k3 = cmyk1.k + (cmyk2.k - cmyk1.k) * amount; | ||
if (round) { | ||
c3 = Math.round(c3); | ||
m3 = Math.round(m3); | ||
y3 = Math.round(y3); | ||
k3 = Math.round(k3); | ||
} | ||
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); | ||
@@ -253,251 +211,252 @@ }; | ||
*/ | ||
Modify.yiqBlend = function (c1, c2, amount, round) { | ||
Modify.yiqBlend = function (c1, c2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
amount = Math.min(Math.max(amount, 0), 1); | ||
var y = c1.y + (c2.y - c1.y) * amount; | ||
var i = c1.i + (c2.i - c1.i) * amount; | ||
var q = c1.q + (c2.q - c1.q) * amount; | ||
if (round) { | ||
y = Math.round(y); | ||
i = Math.round(i); | ||
q = Math.round(q); | ||
} | ||
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.rgbDarken = function (rgb, amount, round) { | ||
Modify.labBlend = function (c1, c2, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
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) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var rd = rgb.r * realAmount; | ||
var gd = rgb.g * realAmount; | ||
var bd = rgb.b * realAmount; | ||
if (round) { | ||
rd = Math.round(rd); | ||
gd = Math.round(gd); | ||
bd = Math.round(bd); | ||
} | ||
return new Colors.rgb(rd, gd, bd, rgb.a); | ||
var rd = rgb.getR() * realAmount; | ||
var gd = rgb.getG() * realAmount; | ||
var bd = rgb.getB() * realAmount; | ||
return new Colors.rgb(rd, gd, bd, rgb.getA()); | ||
}; | ||
Modify.rgbLighten = function (rgb, amount, round) { | ||
Modify.rgbLighten = function (rgb, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
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) { | ||
rl = Math.round(rl); | ||
gl = Math.round(gl); | ||
bl = Math.round(bl); | ||
} | ||
return new Colors.rgb(rl, gl, bl, rgb.a); | ||
var rl = rgb.getR() + (rgb.getMax() - rgb.getR()) * realAmount; | ||
var gl = rgb.getG() + (rgb.getMax() - rgb.getG()) * realAmount; | ||
var bl = rgb.getB() + (rgb.getMax() - rgb.getB()) * realAmount; | ||
return new Colors.rgb(rl, gl, bl, rgb.getA()); | ||
}; | ||
Modify.cmykDarken = function (cmyk, amount, round) { | ||
Modify.rgb2Darken = function (rgb, amount) { | ||
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 + (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); | ||
} | ||
var distanceLeft = Math.max(rgb.getR(), rgb.getG(), rgb.getB()); | ||
var changeValue = distanceLeft * realAmount; | ||
var rd = Math.max(0, rgb.getR() - changeValue); | ||
var gd = Math.max(0, rgb.getG() - changeValue); | ||
var bd = Math.max(0, rgb.getB() - changeValue); | ||
return new Colors.rgb(rd, gd, bd, rgb.getA()); | ||
}; | ||
Modify.rgb2Lighten = function (rgb, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var distanceLeft = rgb.getMax() - Math.min(rgb.getR(), rgb.getG(), rgb.getB()); | ||
var changeValue = distanceLeft * realAmount; | ||
var rl = Math.min(rgb.getR() + changeValue, rgb.getMax()); | ||
var gl = Math.min(rgb.getG() + changeValue, rgb.getMax()); | ||
var bl = Math.min(rgb.getB() + changeValue, rgb.getMax()); | ||
return new Colors.rgb(rl, gl, bl, rgb.getA()); | ||
}; | ||
Modify.cmykDarken = function (cmyk, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var c2 = cmyk.getC() + (100 - cmyk.getC()) * realAmount; | ||
var m2 = cmyk.getM() + (100 - cmyk.getM()) * realAmount; | ||
var y2 = cmyk.getY() + (100 - cmyk.getY()) * realAmount; | ||
var k2 = cmyk.getK() + (100 - cmyk.getK()) * realAmount; | ||
return new Colors.cmyk(c2, m2, y2, k2); | ||
}; | ||
Modify.cmykLighten = function (cmyk, amount, round) { | ||
Modify.cmykLighten = function (cmyk, amount) { | ||
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 * 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); | ||
} | ||
var c2 = cmyk.getC() * realAmount; | ||
var m2 = cmyk.getM() * realAmount; | ||
var y2 = cmyk.getY() * realAmount; | ||
var k2 = cmyk.getK() * realAmount; | ||
return new Colors.cmyk(c2, m2, y2, k2); | ||
}; | ||
Modify.cmykBlackDarken = function (cmyk, amount, round) { | ||
Modify.cmyk2Darken = function (cmyk, amount) { | ||
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); | ||
var k2 = cmyk.getK() + (100 - cmyk.getK()) * realAmount; | ||
return new Colors.cmyk(cmyk.getC(), cmyk.getM(), cmyk.getY(), k2); | ||
}; | ||
Modify.cmykBlackLighten = function (cmyk, amount, round) { | ||
Modify.cmyk2Lighten = function (cmyk, amount) { | ||
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); | ||
var k2 = cmyk.getK() * realAmount; | ||
return new Colors.cmyk(cmyk.getC(), cmyk.getM(), cmyk.getY(), k2); | ||
}; | ||
Modify.hslDarken = function (hsl, amount, round) { | ||
Modify.hslDarken = function (hsl, amount) { | ||
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 = hsl.l * realAmount; | ||
if (round) | ||
vDarker = Math.round(vDarker); | ||
return new Colors.hsl(hsl.h, hsl.s, vDarker, hsl.a); | ||
var vDarker = hsl.getL() * realAmount; | ||
return new Colors.hsl(hsl.getH(), hsl.getS(), vDarker, hsl.getA()); | ||
}; | ||
Modify.hslLighten = function (hsl, amount, round) { | ||
Modify.hslLighten = function (hsl, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var vLighter = hsl.l + (100 - hsl.l) * realAmount; | ||
if (round) | ||
vLighter = Math.round(vLighter); | ||
return new Colors.hsl(hsl.h, hsl.s, vLighter, hsl.a); | ||
var vLighter = hsl.getL() + (100 - hsl.getL()) * realAmount; | ||
return new Colors.hsl(hsl.getH(), hsl.getS(), vLighter, hsl.getA()); | ||
}; | ||
Modify.hsvDarken = function (hsv, amount, round) { | ||
Modify.hsvDarken = function (hsv, amount) { | ||
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); | ||
var vDarker = hsv.getV() * realAmount; | ||
return new Colors.hsv(hsv.getH(), hsv.getS(), vDarker, hsv.getA()); | ||
}; | ||
Modify.hsvLighten = function (hsv, amount, round) { | ||
Modify.hsvLighten = function (hsv, amount) { | ||
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; | ||
var sLighter = (1 - realAmount) * 100; | ||
if (round) { | ||
vLighter = Math.round(vLighter); | ||
sLighter = Math.round(sLighter); | ||
} | ||
return new Colors.hsv(hsv.h, sLighter, vLighter, hsv.a); | ||
var vLighter = hsv.getV() + (100 - hsv.getV()) * realAmount; | ||
var sLighter = hsv.getS() - realAmount * hsv.getS(); | ||
return new Colors.hsv(hsv.getH(), sLighter, vLighter, hsv.getA()); | ||
}; | ||
Modify.hsiDarken = function (hsi, amount, round) { | ||
Modify.hsiDarken = function (hsi, amount) { | ||
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); | ||
var vDarker = hsi.getI() * realAmount; | ||
return new Colors.hsi(hsi.getH(), hsi.getS(), vDarker, hsi.getA()); | ||
}; | ||
Modify.hsiLighten = function (hsi, amount, round) { | ||
Modify.hsiLighten = function (hsi, amount) { | ||
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; | ||
var sLighter = (1 - realAmount) * 100; | ||
if (round) { | ||
vLighter = Math.round(vLighter); | ||
sLighter = Math.round(sLighter); | ||
} | ||
return new Colors.hsi(hsi.h, sLighter, vLighter, hsi.a); | ||
var vLighter = hsi.getI() + (100 - hsi.getI()) * realAmount; | ||
var sLighter = hsi.getS() - realAmount * hsi.getS(); | ||
return new Colors.hsi(hsi.getH(), sLighter, vLighter, hsi.getA()); | ||
}; | ||
Modify.hspDarken = function (hsp, amount, round) { | ||
Modify.hspDarken = function (hsp, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var pDarker = hsp.p * realAmount; | ||
if (round) | ||
pDarker = Math.round(pDarker); | ||
return new Colors.hsp(hsp.h, hsp.s, pDarker, hsp.a, hsp.pb, hsp.pr); | ||
var pDarker = hsp.getP() * realAmount; | ||
return new Colors.hsp(hsp.getH(), hsp.getS(), pDarker, hsp.getA(), hsp.getPb(), hsp.getPr()); | ||
}; | ||
Modify.hspLighten = function (hsp, amount, round) { | ||
Modify.hspLighten = function (hsp, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var pLighter = hsp.p + (100 - hsp.p) * realAmount; | ||
var sLighter = (1 - realAmount) * 100; | ||
if (round) { | ||
pLighter = Math.round(pLighter); | ||
sLighter = Math.round(sLighter); | ||
} | ||
return new Colors.hsp(hsp.h, sLighter, pLighter, hsp.a, hsp.pb, hsp.pr); | ||
var pLighter = hsp.getP() + (100 - hsp.getP()) * realAmount; | ||
var sLighter = hsp.getS() - realAmount * hsp.getS(); | ||
return new Colors.hsp(hsp.getH(), sLighter, pLighter, hsp.getA(), hsp.getPb(), hsp.getPr()); | ||
}; | ||
Modify.hslDesaturate = function (hsl, amount, round) { | ||
Modify.labDarken = function (lab, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsl.s * realAmount; | ||
if (round) | ||
sLess = Math.round(sLess); | ||
return new Colors.hsl(hsl.h, sLess, hsl.l, hsl.a); | ||
var lDarker = lab.getL() * realAmount; | ||
var aDarker = lab.getA() * realAmount; | ||
var bDarker = lab.getB() * realAmount; | ||
return new Colors.lab(lDarker, aDarker, bDarker); | ||
}; | ||
Modify.hslSaturate = function (hsl, amount, round) { | ||
Modify.labLighten = function (lab, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsl.s + (100 - hsl.s) * realAmount; | ||
if (round) | ||
sMore = Math.round(sMore); | ||
return new Colors.hsl(hsl.h, sMore, hsl.l, hsl.a); | ||
var realAmountAB = 1 - Math.min(Math.max(amount, 0), 1); | ||
var lLighter = lab.getL() + (100 - lab.getL()) * realAmount; | ||
var aLighter = lab.getA() * realAmountAB; | ||
var bLighter = lab.getB() * realAmountAB; | ||
return new Colors.lab(lLighter, aLighter, bLighter); | ||
}; | ||
Modify.hsvDesaturate = function (hsv, amount, round) { | ||
Modify.lab2Darken = function (lab, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsv.s * realAmount; | ||
if (round) | ||
sLess = Math.round(sLess); | ||
return new Colors.hsv(hsv.h, sLess, hsv.v, hsv.a); | ||
var lDarker = lab.getL() * realAmount; | ||
return new Colors.lab(lDarker, lab.getA(), lab.getB()); | ||
}; | ||
Modify.hsvSaturate = function (hsv, amount, round) { | ||
Modify.lab2Lighten = function (lab, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsv.s + (100 - hsv.s) * realAmount; | ||
if (round) | ||
sMore = Math.round(sMore); | ||
return new Colors.hsv(hsv.h, sMore, hsv.v, hsv.a); | ||
var lLighter = lab.getL() + (100 - lab.getL()) * realAmount; | ||
return new Colors.lab(lLighter, lab.getA(), lab.getB()); | ||
}; | ||
Modify.hsiDesaturate = function (hsi, amount, round) { | ||
Modify.luvDarken = function (luv, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsi.s * realAmount; | ||
if (round) | ||
sLess = Math.round(sLess); | ||
return new Colors.hsi(hsi.h, sLess, hsi.i, hsi.a); | ||
var lDarker = luv.getL() * realAmount; | ||
var uDarker = luv.getU() * realAmount; | ||
var vDarker = luv.getV() * realAmount; | ||
return new Colors.luv(lDarker, uDarker, vDarker); | ||
}; | ||
Modify.hsiSaturate = function (hsi, amount, round) { | ||
Modify.luvLighten = function (luv, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsi.s + (100 - hsi.s) * realAmount; | ||
if (round) | ||
sMore = Math.round(sMore); | ||
return new Colors.hsi(hsi.h, sMore, hsi.i, hsi.a); | ||
var realAmountAB = 1 - Math.min(Math.max(amount, 0), 1); | ||
var lLighter = luv.getL() + (100 - luv.getL()) * realAmount; | ||
var uLighter = luv.getU() * realAmountAB; | ||
var vLighter = luv.getV() * realAmountAB; | ||
return new Colors.luv(lLighter, uLighter, vLighter); | ||
}; | ||
Modify.hspDesaturate = function (hsp, amount, round) { | ||
// breaks as L* approaches 0 | ||
Modify.luv2Darken = function (luv, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsp.s * realAmount; | ||
if (round) | ||
sLess = Math.round(sLess); | ||
return new Colors.hsp(hsp.h, sLess, hsp.p, hsp.a); | ||
var lDarker = luv.getL() * realAmount; | ||
return new Colors.luv(lDarker, luv.getU(), luv.getV()); | ||
}; | ||
Modify.hspSaturate = function (hsp, amount, round) { | ||
Modify.luv2Lighten = function (luv, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
if (round === void 0) { round = true; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsp.s + (100 - hsp.s) * realAmount; | ||
if (round) | ||
sMore = Math.round(sMore); | ||
return new Colors.hsp(hsp.h, sMore, hsp.p, hsp.a); | ||
var lLighter = luv.getL() + (100 - luv.getL()) * realAmount; | ||
return new Colors.luv(lLighter, luv.getU(), luv.getV()); | ||
}; | ||
Modify.hslDesaturate = function (hsl, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsl.getS() * realAmount; | ||
return new Colors.hsl(hsl.getH(), sLess, hsl.getL(), hsl.getA()); | ||
}; | ||
Modify.hslSaturate = function (hsl, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsl.getS() + (100 - hsl.getS()) * realAmount; | ||
return new Colors.hsl(hsl.getH(), sMore, hsl.getL(), hsl.getA()); | ||
}; | ||
Modify.hsvDesaturate = function (hsv, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsv.getS() * realAmount; | ||
return new Colors.hsv(hsv.getH(), sLess, hsv.getV(), hsv.getA()); | ||
}; | ||
Modify.hsvSaturate = function (hsv, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsv.getS() + (100 - hsv.getS()) * realAmount; | ||
return new Colors.hsv(hsv.getH(), sMore, hsv.getV(), hsv.getA()); | ||
}; | ||
Modify.hsiDesaturate = function (hsi, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsi.getS() * realAmount; | ||
return new Colors.hsi(hsi.getH(), sLess, hsi.getI(), hsi.getA()); | ||
}; | ||
Modify.hsiSaturate = function (hsi, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsi.getS() + (100 - hsi.getS()) * realAmount; | ||
return new Colors.hsi(hsi.getH(), sMore, hsi.getI(), hsi.getA()); | ||
}; | ||
Modify.hspDesaturate = function (hsp, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = 1 - Math.min(Math.max(amount, 0), 1); | ||
var sLess = hsp.getS() * realAmount; | ||
return new Colors.hsp(hsp.getH(), sLess, hsp.getP(), hsp.getA()); | ||
}; | ||
Modify.hspSaturate = function (hsp, amount) { | ||
if (amount === void 0) { amount = 0.5; } | ||
var realAmount = Math.min(Math.max(amount, 0), 1); | ||
var sMore = hsp.getS() + (100 - hsp.getS()) * realAmount; | ||
return new Colors.hsp(hsp.getH(), sMore, hsp.getP(), hsp.getA()); | ||
}; | ||
return Modify; | ||
}()); | ||
module.exports = Modify; |
{ | ||
"name": "chromaticity-color-utilities", | ||
"version": "0.8.6-alpha", | ||
"version": "0.11.0-alpha", | ||
"description": "Color utilities for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -71,4 +71,2 @@ # <img src="https://reiniiriarios.github.io/chromaticity-color-utilities/img/chromaticity-icon-01.png" width="26" height="26"> chromaticity-color-utilities | ||
- YCbCr validates only with a high tolerance. Not sure if floating point issue. | ||
- shadetint(cmyk) seems to be reading distanceToWhite and distanceToBlack incorrectly | ||
- shadetint(cmyk) oversaturates toward black when auto and closest bound is white | ||
@@ -75,0 +73,0 @@ ## Compiling from Source |
Sorry, the diff of this file is too big to display
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
7689
323438
99