Version 1.7.16 #4081

Merged
merged 2 commits into from Jul 8, 2017
View
@@ -1,3 +1,10 @@
+**Version 1.7.16**
+
+- Improvement: Add information to onChange and onComplete animation function [#4068](https://github.com/kangax/fabric.js/pull/4068)
+- Improvement: avoid multiplying identity matrices in calcTransformMatrix function
+- Fix: ativeGroup did not destroy correctly if a toObject was happening
+- Improvement: Pass the event to object:modified when available. [#4061](https://github.com/kangax/fabric.js/pull/4061)
+
**Version 1.7.15**
- Improvement: Made iText keymap public. [#4053](https://github.com/kangax/fabric.js/pull/4053)
View
@@ -1,6 +1,6 @@
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
-var fabric = fabric || { version: "1.7.15" };
+var fabric = fabric || { version: "1.7.16" };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
View
@@ -25,7 +25,7 @@ Remove the template from below and provide thoughtful commentary *and code sampl
<!-- BUG TEMPLATE -->
## Version
-1.7.14
+1.7.16
## Test Case
http://jsfiddle.net/fabricjs/Da7SP/
View
@@ -274,6 +274,7 @@ Get help in Fabric's IRC channel — irc://irc.freenode.net/#fabric.js
- [Maxim "hakunin" Chernyak](http://twitter.com/hakunin) for ideas, and help with various parts of the library throughout its life
- [Sergey Nisnevich](http://nisnya.com) for help with geometry logic
- [Stefan Kienzle](https://twitter.com/kienzle_s) for help with bugs, features, documentation, github issues
+- [Shutterstock](http://www.shutterstock.com) for the resources used and the time spent using and improving the library.
- [And all the other GitHub contributors](https://github.com/kangax/fabric.js/graphs/contributors)
### MIT License
View
@@ -1,7 +1,7 @@
/* build: `node build.js modules=ALL exclude=json,gestures minifier=uglifyjs` */
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
-var fabric = fabric || { version: "1.7.15" };
+var fabric = fabric || { version: "1.7.16" };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
@@ -2736,6 +2736,10 @@ if (typeof console !== 'undefined') {
(function() {
+ function noop() {
+ return false;
+ }
+
/**
* Changes value from one to another within certain period of time, invoking callbacks as value is being changed.
* @memberOf fabric.util
@@ -2756,8 +2760,9 @@ if (typeof console !== 'undefined') {
var start = timestamp || +new Date(),
duration = options.duration || 500,
finish = start + duration, time,
- onChange = options.onChange || function() { },
- abort = options.abort || function() { return false; },
+ onChange = options.onChange || noop,
+ abort = options.abort || noop,
+ onComplete = options.onComplete || noop,
easing = options.easing || function(t, b, c, d) {return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;},
startValue = 'startValue' in options ? options.startValue : 0,
endValue = 'endValue' in options ? options.endValue : 100,
@@ -2766,13 +2771,16 @@ if (typeof console !== 'undefined') {
options.onStart && options.onStart();
(function tick(ticktime) {
- time = ticktime || +new Date();
- var currentTime = time > finish ? duration : (time - start);
if (abort()) {
- options.onComplete && options.onComplete();
+ onComplete(endValue, 1, 1);
return;
}
- onChange(easing(currentTime, startValue, byValue, duration));
+ time = ticktime || +new Date();
+ var currentTime = time > finish ? duration : (time - start),
+ timePerc = currentTime / duration,
+ current = easing(currentTime, startValue, byValue, duration),
+ valuePerc = Math.abs((current - startValue) / byValue);
+ onChange(current, valuePerc, timePerc);
if (time > finish) {
options.onComplete && options.onComplete();
return;
@@ -10253,10 +10261,10 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
* @returns the original values of instance which were changed
*/
_realizeGroupTransformOnObject: function(instance) {
- var layoutProps = ['angle', 'flipX', 'flipY', 'height', 'left', 'scaleX', 'scaleY', 'top', 'width'];
if (instance.group && instance.group === this.getActiveGroup()) {
//Copy all the positionally relevant properties across now
- var originalValues = {};
+ var originalValues = {},
+ layoutProps = ['angle', 'flipX', 'flipY', 'left', 'scaleX', 'scaleY', 'skewX', 'skewY', 'top'];
layoutProps.forEach(function(prop) {
originalValues[prop] = instance[prop];
});
@@ -10663,7 +10671,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
isClick = (!groupSelector || (groupSelector.left === 0 && groupSelector.top === 0));
if (transform) {
- this._finalizeCurrentTransform();
+ this._finalizeCurrentTransform(e);
searchTarget = !transform.actionPerformed;
}
@@ -10718,8 +10726,9 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
/**
* @private
+ * @param {Event} e send the mouse event that generate the finalize down, so it can be used in the event
*/
- _finalizeCurrentTransform: function() {
+ _finalizeCurrentTransform: function(e) {
var transform = this._currentTransform,
target = transform.target;
@@ -10732,8 +10741,8 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
this._restoreOriginXY(target);
if (transform.actionPerformed || (this.stateful && target.hasStateChanged())) {
- this.fire('object:modified', { target: target });
- target.fire('modified');
+ this.fire('object:modified', { target: target, e: e });
+ target.fire('modified', { e: e });
}
},
@@ -14394,23 +14403,37 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
calcTransformMatrix: function(skipGroup) {
var center = this.getCenterPoint(),
translateMatrix = [1, 0, 0, 1, center.x, center.y],
- rotateMatrix = this._calcRotateMatrix(),
+ rotateMatrix,
dimensionMatrix = this._calcDimensionsTransformMatrix(this.skewX, this.skewY, true),
- matrix = this.group && !skipGroup ? this.group.calcTransformMatrix() : fabric.iMatrix.concat();
- matrix = multiplyMatrices(matrix, translateMatrix);
- matrix = multiplyMatrices(matrix, rotateMatrix);
+ matrix;
+ if (this.group && !skipGroup) {
+ matrix = multiplyMatrices(this.group.calcTransformMatrix(), translateMatrix);
+ }
+ else {
+ matrix = translateMatrix;
+ }
+ if (this.angle) {
+ rotateMatrix = this._calcRotateMatrix();
+ matrix = multiplyMatrices(matrix, rotateMatrix);
+ }
matrix = multiplyMatrices(matrix, dimensionMatrix);
return matrix;
},
_calcDimensionsTransformMatrix: function(skewX, skewY, flipping) {
- var skewMatrixX = [1, 0, Math.tan(degreesToRadians(skewX)), 1],
- skewMatrixY = [1, Math.tan(degreesToRadians(skewY)), 0, 1],
+ var skewMatrix,
scaleX = this.scaleX * (flipping && this.flipX ? -1 : 1),
scaleY = this.scaleY * (flipping && this.flipY ? -1 : 1),
- scaleMatrix = [scaleX, 0, 0, scaleY],
- m = multiplyMatrices(scaleMatrix, skewMatrixX, true);
- return multiplyMatrices(m, skewMatrixY, true);
+ scaleMatrix = [scaleX, 0, 0, scaleY, 0, 0];
+ if (skewX) {
+ skewMatrix = [1, 0, Math.tan(degreesToRadians(skewX)), 1];
+ scaleMatrix = multiplyMatrices(scaleMatrix, skewMatrix, true);
+ }
+ if (skewY) {
+ skewMatrix = [1, Math.tan(degreesToRadians(skewY)), 0, 1];
+ scaleMatrix = multiplyMatrices(scaleMatrix, skewMatrix, true);
+ }
+ return scaleMatrix;
},
/*
@@ -15414,7 +15437,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
abort: options.abort && function() {
return options.abort.call(_this);
},
- onChange: function(value) {
+ onChange: function(value, valueProgress, timeProgress) {
if (propPair) {
_this[propPair[0]][propPair[1]] = value;
}
@@ -15424,15 +15447,15 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
if (skipCallbacks) {
return;
}
- options.onChange && options.onChange();
+ options.onChange && options.onChange(value, valueProgress, timeProgress);
},
- onComplete: function() {
+ onComplete: function(value, valueProgress, timeProgress) {
if (skipCallbacks) {
return;
}
_this.setCoords();
- options.onComplete && options.onComplete();
+ options.onComplete && options.onComplete(value, valueProgress, timeProgress);
}
});
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
Binary file not shown.
View
@@ -1,5 +1,5 @@
var fabric = fabric || {
- version: "1.7.15"
+ version: "1.7.16"
};
if (typeof exports !== "undefined") {
@@ -1471,23 +1471,24 @@ if (typeof console !== "undefined") {
}
(function() {
+ function noop() {
+ return false;
+ }
function animate(options) {
requestAnimFrame(function(timestamp) {
options || (options = {});
- var start = timestamp || +new Date(), duration = options.duration || 500, finish = start + duration, time, onChange = options.onChange || function() {}, abort = options.abort || function() {
- return false;
- }, easing = options.easing || function(t, b, c, d) {
+ var start = timestamp || +new Date(), duration = options.duration || 500, finish = start + duration, time, onChange = options.onChange || noop, abort = options.abort || noop, onComplete = options.onComplete || noop, easing = options.easing || function(t, b, c, d) {
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
}, startValue = "startValue" in options ? options.startValue : 0, endValue = "endValue" in options ? options.endValue : 100, byValue = options.byValue || endValue - startValue;
options.onStart && options.onStart();
(function tick(ticktime) {
- time = ticktime || +new Date();
- var currentTime = time > finish ? duration : time - start;
if (abort()) {
- options.onComplete && options.onComplete();
+ onComplete(endValue, 1, 1);
return;
}
- onChange(easing(currentTime, startValue, byValue, duration));
+ time = ticktime || +new Date();
+ var currentTime = time > finish ? duration : time - start, timePerc = currentTime / duration, current = easing(currentTime, startValue, byValue, duration), valuePerc = Math.abs((current - startValue) / byValue);
+ onChange(current, valuePerc, timePerc);
if (time > finish) {
options.onComplete && options.onComplete();
return;
@@ -5185,9 +5186,8 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
return object;
},
_realizeGroupTransformOnObject: function(instance) {
- var layoutProps = [ "angle", "flipX", "flipY", "height", "left", "scaleX", "scaleY", "top", "width" ];
if (instance.group && instance.group === this.getActiveGroup()) {
- var originalValues = {};
+ var originalValues = {}, layoutProps = [ "angle", "flipX", "flipY", "left", "scaleX", "scaleY", "skewX", "skewY", "top" ];
layoutProps.forEach(function(prop) {
originalValues[prop] = instance[prop];
});
@@ -5417,7 +5417,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
}
var searchTarget = true, transform = this._currentTransform, groupSelector = this._groupSelector, isClick = !groupSelector || groupSelector.left === 0 && groupSelector.top === 0;
if (transform) {
- this._finalizeCurrentTransform();
+ this._finalizeCurrentTransform(e);
searchTarget = !transform.actionPerformed;
}
target = searchTarget ? this.findTarget(e, true) : transform.target;
@@ -5450,7 +5450,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
targets[i].fire("mouse" + eventType, options);
}
},
- _finalizeCurrentTransform: function() {
+ _finalizeCurrentTransform: function(e) {
var transform = this._currentTransform, target = transform.target;
if (target._scaling) {
target._scaling = false;
@@ -5459,9 +5459,12 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
this._restoreOriginXY(target);
if (transform.actionPerformed || this.stateful && target.hasStateChanged()) {
this.fire("object:modified", {
- target: target
+ target: target,
+ e: e
+ });
+ target.fire("modified", {
+ e: e
});
- target.fire("modified");
}
},
_restoreOriginXY: function(target) {
@@ -6965,15 +6968,30 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
return fabric.iMatrix.concat();
},
calcTransformMatrix: function(skipGroup) {
- var center = this.getCenterPoint(), translateMatrix = [ 1, 0, 0, 1, center.x, center.y ], rotateMatrix = this._calcRotateMatrix(), dimensionMatrix = this._calcDimensionsTransformMatrix(this.skewX, this.skewY, true), matrix = this.group && !skipGroup ? this.group.calcTransformMatrix() : fabric.iMatrix.concat();
- matrix = multiplyMatrices(matrix, translateMatrix);
- matrix = multiplyMatrices(matrix, rotateMatrix);
+ var center = this.getCenterPoint(), translateMatrix = [ 1, 0, 0, 1, center.x, center.y ], rotateMatrix, dimensionMatrix = this._calcDimensionsTransformMatrix(this.skewX, this.skewY, true), matrix;
+ if (this.group && !skipGroup) {
+ matrix = multiplyMatrices(this.group.calcTransformMatrix(), translateMatrix);
+ } else {
+ matrix = translateMatrix;
+ }
+ if (this.angle) {
+ rotateMatrix = this._calcRotateMatrix();
+ matrix = multiplyMatrices(matrix, rotateMatrix);
+ }
matrix = multiplyMatrices(matrix, dimensionMatrix);
return matrix;
},
_calcDimensionsTransformMatrix: function(skewX, skewY, flipping) {
- var skewMatrixX = [ 1, 0, Math.tan(degreesToRadians(skewX)), 1 ], skewMatrixY = [ 1, Math.tan(degreesToRadians(skewY)), 0, 1 ], scaleX = this.scaleX * (flipping && this.flipX ? -1 : 1), scaleY = this.scaleY * (flipping && this.flipY ? -1 : 1), scaleMatrix = [ scaleX, 0, 0, scaleY ], m = multiplyMatrices(scaleMatrix, skewMatrixX, true);
- return multiplyMatrices(m, skewMatrixY, true);
+ var skewMatrix, scaleX = this.scaleX * (flipping && this.flipX ? -1 : 1), scaleY = this.scaleY * (flipping && this.flipY ? -1 : 1), scaleMatrix = [ scaleX, 0, 0, scaleY, 0, 0 ];
+ if (skewX) {
+ skewMatrix = [ 1, 0, Math.tan(degreesToRadians(skewX)), 1 ];
+ scaleMatrix = multiplyMatrices(scaleMatrix, skewMatrix, true);
+ }
+ if (skewY) {
+ skewMatrix = [ 1, Math.tan(degreesToRadians(skewY)), 0, 1 ];
+ scaleMatrix = multiplyMatrices(scaleMatrix, skewMatrix, true);
+ }
+ return scaleMatrix;
},
_getNonTransformedDimensions: function() {
var strokeWidth = this.strokeWidth, w = this.width + strokeWidth, h = this.height + strokeWidth;
@@ -7477,7 +7495,7 @@ fabric.util.object.extend(fabric.Object.prototype, {
abort: options.abort && function() {
return options.abort.call(_this);
},
- onChange: function(value) {
+ onChange: function(value, valueProgress, timeProgress) {
if (propPair) {
_this[propPair[0]][propPair[1]] = value;
} else {
@@ -7486,14 +7504,14 @@ fabric.util.object.extend(fabric.Object.prototype, {
if (skipCallbacks) {
return;
}
- options.onChange && options.onChange();
+ options.onChange && options.onChange(value, valueProgress, timeProgress);
},
- onComplete: function() {
+ onComplete: function(value, valueProgress, timeProgress) {
if (skipCallbacks) {
return;
}
_this.setCoords();
- options.onComplete && options.onComplete();
+ options.onComplete && options.onComplete(value, valueProgress, timeProgress);
}
});
}
View
@@ -2,7 +2,7 @@
"name": "fabric",
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
"homepage": "http://fabricjs.com/",
- "version": "1.7.15",
+ "version": "1.7.16",
"author": "Juriy Zaytsev <kangax@gmail.com>",
"contributors": [
{
@@ -201,7 +201,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
abort: options.abort && function() {
return options.abort.call(_this);
},
- onChange: function(value) {
+ onChange: function(value, valueProgress, timeProgress) {
if (propPair) {
_this[propPair[0]][propPair[1]] = value;
}
@@ -211,15 +211,15 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
if (skipCallbacks) {
return;
}
- options.onChange && options.onChange();
+ options.onChange && options.onChange(value, valueProgress, timeProgress);
},
- onComplete: function() {
+ onComplete: function(value, valueProgress, timeProgress) {
if (skipCallbacks) {
return;
}
_this.setCoords();
- options.onComplete && options.onComplete();
+ options.onComplete && options.onComplete(value, valueProgress, timeProgress);
}
});
}
Oops, something went wrong.