Fixed eslint issues

This commit is contained in:
Tomas Korcak 2015-08-14 22:53:46 +02:00
parent 2a8011df34
commit c85f591f93
3 changed files with 35 additions and 38 deletions

View File

@ -21,7 +21,7 @@ class Color {
this.__state = interpret.apply(this, arguments); this.__state = interpret.apply(this, arguments);
if (this.__state === false) { if (this.__state === false) {
throw 'Failed to interpret color arguments'; throw new Error('Failed to interpret color arguments');
} }
this.__state.a = this.__state.a || 1; this.__state.a = this.__state.a || 1;
@ -42,12 +42,12 @@ Color.recalculateRGB = function(color, component, componentHexIndex) {
} else if (color.__state.space === 'HSV') { } else if (color.__state.space === 'HSV') {
common.extend(color.__state, math.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v)); common.extend(color.__state, math.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v));
} else { } else {
throw 'Corrupted color state'; throw new Error('Corrupted color state');
} }
}; };
Color.recalculateHSV = function(color) { Color.recalculateHSV = function(color) {
var result = math.rgb_to_hsv(color.r, color.g, color.b); const result = math.rgb_to_hsv(color.r, color.g, color.b);
common.extend(color.__state, common.extend(color.__state,
{ {
@ -74,17 +74,17 @@ defineHSVComponent(Color.prototype, 's');
defineHSVComponent(Color.prototype, 'v'); defineHSVComponent(Color.prototype, 'v');
Object.defineProperty(Color.prototype, 'a', { Object.defineProperty(Color.prototype, 'a', {
get: function () { get: function() {
return this.__state.a; return this.__state.a;
}, },
set: function (v) { set: function(v) {
this.__state.a = v; this.__state.a = v;
} }
}); });
Object.defineProperty(Color.prototype, 'hex', { Object.defineProperty(Color.prototype, 'hex', {
get: function () { get: function() {
if (!this.__state.space !== 'HEX') { if (!this.__state.space !== 'HEX') {
this.__state.hex = math.rgb_to_hex(this.r, this.g, this.b); this.__state.hex = math.rgb_to_hex(this.r, this.g, this.b);
} }
@ -92,7 +92,7 @@ Object.defineProperty(Color.prototype, 'hex', {
return this.__state.hex; return this.__state.hex;
}, },
set: function (v) { set: function(v) {
this.__state.space = 'HEX'; this.__state.space = 'HEX';
this.__state.hex = v; this.__state.hex = v;
} }
@ -100,7 +100,7 @@ Object.defineProperty(Color.prototype, 'hex', {
function defineRGBComponent(target, component, componentHexIndex) { function defineRGBComponent(target, component, componentHexIndex) {
Object.defineProperty(target, component, { Object.defineProperty(target, component, {
get: function () { get: function() {
if (this.__state.space === 'RGB') { if (this.__state.space === 'RGB') {
return this.__state[component]; return this.__state[component];
} }
@ -110,7 +110,7 @@ function defineRGBComponent(target, component, componentHexIndex) {
return this.__state[component]; return this.__state[component];
}, },
set: function (v) { set: function(v) {
if (this.__state.space !== 'RGB') { if (this.__state.space !== 'RGB') {
Color.recalculateRGB(this, component, componentHexIndex); Color.recalculateRGB(this, component, componentHexIndex);
this.__state.space = 'RGB'; this.__state.space = 'RGB';
@ -123,7 +123,7 @@ function defineRGBComponent(target, component, componentHexIndex) {
function defineHSVComponent(target, component) { function defineHSVComponent(target, component) {
Object.defineProperty(target, component, { Object.defineProperty(target, component, {
get: function () { get: function() {
if (this.__state.space === 'HSV') { if (this.__state.space === 'HSV') {
return this.__state[component]; return this.__state[component];
} }
@ -131,10 +131,9 @@ function defineHSVComponent(target, component) {
Color.recalculateHSV(this); Color.recalculateHSV(this);
return this.__state[component]; return this.__state[component];
}, },
set: function (v) { set: function(v) {
if (this.__state.space !== 'HSV') { if (this.__state.space !== 'HSV') {
Color.recalculateHSV(this); Color.recalculateHSV(this);
this.__state.space = 'HSV'; this.__state.space = 'HSV';

View File

@ -11,19 +11,18 @@
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
var tmpComponent; let tmpComponent;
var ColorMath = { const ColorMath = {
hsv_to_rgb: function(h, s, v) {
const hi = Math.floor(h / 60) % 6;
hsv_to_rgb: function (h, s, v) { const f = h / 60 - Math.floor(h / 60);
const p = v * (1.0 - s);
const q = v * (1.0 - (f * s));
const t = v * (1.0 - ((1.0 - f) * s));
var hi = Math.floor(h / 60) % 6; const c = [
var f = h / 60 - Math.floor(h / 60);
var p = v * (1.0 - s);
var q = v * (1.0 - (f * s));
var t = v * (1.0 - ((1.0 - f) * s));
var c = [
[v, t, p], [v, t, p],
[q, v, p], [q, v, p],
[p, v, t], [p, v, t],
@ -37,17 +36,16 @@ var ColorMath = {
g: c[1] * 255, g: c[1] * 255,
b: c[2] * 255 b: c[2] * 255
}; };
}, },
rgb_to_hsv: function (r, g, b) { rgb_to_hsv: function(r, g, b) {
const min = Math.min(r, g, b);
const max = Math.max(r, g, b);
const delta = max - min;
let h;
let s;
var min = Math.min(r, g, b), if (max !== 0) {
max = Math.max(r, g, b),
delta = max - min,
h, s;
if (max != 0) {
s = delta / max; s = delta / max;
} else { } else {
return { return {
@ -57,9 +55,9 @@ var ColorMath = {
}; };
} }
if (r == max) { if (r === max) {
h = (g - b) / delta; h = (g - b) / delta;
} else if (g == max) { } else if (g === max) {
h = 2 + (b - r) / delta; h = 2 + (b - r) / delta;
} else { } else {
h = 4 + (r - g) / delta; h = 4 + (r - g) / delta;
@ -76,20 +74,20 @@ var ColorMath = {
}; };
}, },
rgb_to_hex: function (r, g, b) { rgb_to_hex: function(r, g, b) {
var hex = this.hex_with_component(0, 2, r); let hex = this.hex_with_component(0, 2, r);
hex = this.hex_with_component(hex, 1, g); hex = this.hex_with_component(hex, 1, g);
hex = this.hex_with_component(hex, 0, b); hex = this.hex_with_component(hex, 0, b);
return hex; return hex;
}, },
component_from_hex: function (hex, componentIndex) { component_from_hex: function(hex, componentIndex) {
return (hex >> (componentIndex * 8)) & 0xFF; return (hex >> (componentIndex * 8)) & 0xFF;
}, },
hex_with_component: function (hex, componentIndex, value) { hex_with_component: function(hex, componentIndex, value) {
return value << (tmpComponent = componentIndex * 8) | (hex & ~(0xFF << tmpComponent)); return value << (tmpComponent = componentIndex * 8) | (hex & ~(0xFF << tmpComponent));
} }
} };
export default ColorMath; export default ColorMath;

View File

@ -23,4 +23,4 @@ export default function(color) {
} }
return 'rgba(' + Math.round(color.r) + ',' + Math.round(color.g) + ',' + Math.round(color.b) + ',' + color.a + ')'; return 'rgba(' + Math.round(color.r) + ',' + Math.round(color.g) + ',' + Math.round(color.b) + ',' + color.a + ')';
}; }