From 059058fbac867a270ceef34970f5ac04f58ec913 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Sun, 25 Nov 2018 13:04:42 +0100 Subject: fix Morphable so that it works with color spaces. It prefers the `to` space over the `from` space - _d is initialized to 0 so toArray does not give you undefined - fix tests --- src/types/Color.js | 4 ++-- src/types/Morphable.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/types/Color.js b/src/types/Color.js index 8a44de1..3975aef 100644 --- a/src/types/Color.js +++ b/src/types/Color.js @@ -60,14 +60,14 @@ export default class Color { } init (a = 0, b = 0, c = 0, d = 0, space = 'rgb') { - // If the user gave us an array, make the color from it if (typeof a === 'number') { // Allow for the case that we don't need d... space = typeof d === 'string' ? d : space - d = typeof d === 'string' ? undefined : d + d = typeof d === 'string' ? 0 : d // Assign the values straight to the color Object.assign(this, { _a: a, _b: b, _c: c, _d: d, space }) + // If the user gave us an array, make the color from it } else if (a instanceof Array) { this.space = b || 'rgb' Object.assign(this, { _a: a[0], _b: a[1], _c: a[2], _d: a[3] }) diff --git a/src/types/Morphable.js b/src/types/Morphable.js index 240215b..e7af8c1 100644 --- a/src/types/Morphable.js +++ b/src/types/Morphable.js @@ -80,7 +80,14 @@ export default class Morphable { } } - var result = (new this._type(value)).toArray() + var result = (new this._type(value)) + if (this._type === Color) { + result = this._to ? result[this._to[4]]() + : this._from ? result[this._from[4]]() + : result + } + result = result.toArray() + this._morphObj = this._morphObj || new this._type() this._context = this._context || Array.apply(null, Array(result.length)).map(Object) -- cgit v1.2.3