diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-25 13:04:42 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-25 13:04:42 +0100 |
commit | 059058fbac867a270ceef34970f5ac04f58ec913 (patch) | |
tree | 9606dc5d7ba661890dfacd7e8cf5f879d638fc15 /src/types | |
parent | 0a357dd3063bcb18ccf7de446f206e8598bea9a1 (diff) | |
download | svg.js-059058fbac867a270ceef34970f5ac04f58ec913.tar.gz svg.js-059058fbac867a270ceef34970f5ac04f58ec913.zip |
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
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/Color.js | 4 | ||||
-rw-r--r-- | src/types/Morphable.js | 9 |
2 files changed, 10 insertions, 3 deletions
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) |