Skip to content

Commit

Permalink
Version 1.7.16 (#4081)
Browse files Browse the repository at this point in the history
* change animation (#4068)
* change animation
* added params to object.animate
* upgrade v1716
  • Loading branch information
asturur authored Jul 8, 2017
1 parent be16e5f commit 3d022bc
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 71 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion HEADER.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 49 additions & 26 deletions dist/fabric.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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];
});
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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 });
}
},

Expand Down Expand Up @@ -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;
},

/*
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
});
}
Expand Down
18 changes: 9 additions & 9 deletions dist/fabric.min.js

Large diffs are not rendered by default.

Binary file modified dist/fabric.min.js.gz
Binary file not shown.
64 changes: 41 additions & 23 deletions dist/fabric.require.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fabric = fabric || {
version: "1.7.15"
version: "1.7.16"
};

if (typeof exports !== "undefined") {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
"contributors": [
{
Expand Down
8 changes: 4 additions & 4 deletions src/mixins/animation.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
});
}
Expand Down
Loading

0 comments on commit 3d022bc

Please sign in to comment.