summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/svg.js17
-rw-r--r--spec/spec/morphing.js2
-rw-r--r--src/types/Color.js4
-rw-r--r--src/types/Morphable.js9
4 files changed, 22 insertions, 10 deletions
diff --git a/dist/svg.js b/dist/svg.js
index 2b7a05e..bb7841f 100644
--- a/dist/svg.js
+++ b/dist/svg.js
@@ -6,7 +6,7 @@
* @copyright Wout Fierens <wout@mick-wout.com>
* @license MIT
*
-* BUILT: Mon Nov 26 2018 00:15:11 GMT+1300 (New Zealand Daylight Time)
+* BUILT: Sun Nov 25 2018 13:00:14 GMT+0100 (GMT+01:00)
*/;
var SVG = (function () {
'use strict';
@@ -1091,11 +1091,10 @@ var SVG = (function () {
var d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
var space = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '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; // Assign the values straight to the color
+ d = typeof d === 'string' ? 0 : d; // Assign the values straight to the color
Object.assign(this, {
_a: a,
@@ -1103,7 +1102,7 @@ var SVG = (function () {
_c: c,
_d: d,
space: 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, {
@@ -1195,7 +1194,7 @@ var SVG = (function () {
this.opacity = _opacity;
}
/*
- */
+ */
}, {
key: "brightness",
@@ -4914,7 +4913,13 @@ var SVG = (function () {
}
}
- 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);
return result;
diff --git a/spec/spec/morphing.js b/spec/spec/morphing.js
index 7fc0c06..50d0ccb 100644
--- a/spec/spec/morphing.js
+++ b/spec/spec/morphing.js
@@ -44,7 +44,7 @@ describe('Morphing', function () {
expect(morpher instanceof SVG.Morphable).toBe(true)
expect(morpher.type()).toBe(SVG.Color)
expect(morpher.at(0.5) instanceof SVG.Color).toBe(true)
- expect(morpher.at(0.5).toHex()).toBe('#808080')
+ expect(morpher.at(0.5).hex()).toBe('#808080')
})
it(`Creates a morphable out of an SVG.Box`, function () {
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)