Skip to content

Commit

Permalink
Version 5.2 (#7721)
Browse files Browse the repository at this point in the history
Co-authored-by: Shachar <[email protected]>
Co-authored-by: Andrejs <[email protected]>
Co-authored-by: CommanderRoot <[email protected]>
  • Loading branch information
4 people authored Feb 21, 2022
1 parent a693198 commit b8ee6c7
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/browser-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: Unit tests on Chrome

on:
push:
branches: [ master ]
branches: [ master, 5.x ]
pull_request:
branches: [ master ]
branches: [ master, 5.x ]

jobs:
chrome-tests:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/browser-firefox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: Unit tests on Firefox

on:
push:
branches: [ master ]
branches: [ master, 5.x ]
pull_request:
branches: [ master ]
branches: [ master, 5.x ]

jobs:
firefox-tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Pr quality check

on:
pull_request:
branches: [ master ]
branches: [ master, 5.x ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/node-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Node Unit tests

on:
push:
branches: [ master ]
branches: [ master, 5.x ]
pull_request:
branches: [ master ]
branches: [ master, 5.x ]

jobs:
node-unit-tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
release:
branches:
- master
- v3.x
- 5.x
types: [published]

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/visual-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Node visual unit tests

on:
push:
branches: [ master ]
branches: [ master, 5.x ]
pull_request:
branches: [ master ]
branches: [ master, 5.x ]

jobs:
node-visual-tests:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/visual-test-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: Visual unit tests on Chrome

on:
push:
branches: [ master ]
branches: [ master, 5.x ]
pull_request:
branches: [ master ]
branches: [ master, 5.x ]

jobs:
chrome-visual-tests:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/visual-test-firefox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: Visual unit tests on Firefox

on:
push:
branches: [ master ]
branches: [ master, 5.x ]
pull_request:
branches: [ master ]
branches: [ master, 5.x ]

jobs:
firefox-visual-tests:
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: '5.1.0' };
var fabric = fabric || { version: '5.2.0' };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down
68 changes: 39 additions & 29 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=gestures,accessors,erasing requirejs minifier=uglifyjs` */
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */

var fabric = fabric || { version: '5.1.0' };
var fabric = fabric || { version: '5.2.0' };
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
}
Expand Down Expand Up @@ -1304,7 +1304,7 @@ fabric.CommonMethods = {
* @return {Array} properties Properties names to include
*/
populateWithProperties: function(source, destination, properties) {
if (properties && Object.prototype.toString.call(properties) === '[object Array]') {
if (properties && Array.isArray(properties)) {
for (var i = 0, len = properties.length; i < len; i++) {
if (properties[i] in source) {
destination[properties[i]] = source[properties[i]];
Expand Down Expand Up @@ -4382,8 +4382,7 @@ fabric.warn = console.warn;
}

function normalizeValue(attr, value, parentAttributes, fontSize) {
var isArray = Object.prototype.toString.call(value) === '[object Array]',
parsed;
var isArray = Array.isArray(value), parsed;

if ((attr === 'fill' || attr === 'stroke') && value === 'none') {
value = '';
Expand Down Expand Up @@ -4781,7 +4780,7 @@ fabric.warn = console.warn;
return;
}

var xlink = xlinkAttribute.substr(1),
var xlink = xlinkAttribute.slice(1),
x = el.getAttribute('x') || 0,
y = el.getAttribute('y') || 0,
el2 = elementById(doc, xlink).cloneNode(true),
Expand Down Expand Up @@ -5053,7 +5052,7 @@ fabric.warn = console.warn;
function recursivelyParseGradientsXlink(doc, gradient) {
var gradientsAttrs = ['gradientTransform', 'x1', 'x2', 'y1', 'y2', 'gradientUnits', 'cx', 'cy', 'r', 'fx', 'fy'],
xlinkAttr = 'xlink:href',
xLink = gradient.getAttribute(xlinkAttr).substr(1),
xLink = gradient.getAttribute(xlinkAttr).slice(1),
referencedGradient = elementById(doc, xLink);
if (referencedGradient && referencedGradient.getAttribute(xlinkAttr)) {
recursivelyParseGradientsXlink(doc, referencedGradient);
Expand Down Expand Up @@ -9793,6 +9792,7 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
* Returns coordinates of a center of canvas.
* Returned value is an object with top and left properties
* @return {Object} object with "top" and "left" number values
* @deprecated migrate to `getCenterPoint`
*/
getCenter: function () {
return {
Expand All @@ -9801,13 +9801,21 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
};
},

/**
* Returns coordinates of a center of canvas.
* @return {fabric.Point}
*/
getCenterPoint: function () {
return new fabric.Point(this.width / 2, this.height / 2);
},

/**
* Centers object horizontally in the canvas
* @param {fabric.Object} object Object to center horizontally
* @return {fabric.Canvas} thisArg
*/
centerObjectH: function (object) {
return this._centerObject(object, new fabric.Point(this.getCenter().left, object.getCenterPoint().y));
return this._centerObject(object, new fabric.Point(this.getCenterPoint().x, object.getCenterPoint().y));
},

/**
Expand All @@ -9817,7 +9825,7 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
* @chainable
*/
centerObjectV: function (object) {
return this._centerObject(object, new fabric.Point(object.getCenterPoint().x, this.getCenter().top));
return this._centerObject(object, new fabric.Point(object.getCenterPoint().x, this.getCenterPoint().y));
},

/**
Expand All @@ -9827,9 +9835,8 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
* @chainable
*/
centerObject: function(object) {
var center = this.getCenter();

return this._centerObject(object, new fabric.Point(center.left, center.top));
var center = this.getCenterPoint();
return this._centerObject(object, center);
},

/**
Expand All @@ -9840,7 +9847,6 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
*/
viewportCenterObject: function(object) {
var vpCenter = this.getVpCenter();

return this._centerObject(object, vpCenter);
},

Expand Down Expand Up @@ -9874,9 +9880,9 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
* @chainable
*/
getVpCenter: function() {
var center = this.getCenter(),
var center = this.getCenterPoint(),
iVpt = invertTransform(this.viewportTransform);
return transformPoint({ x: center.left, y: center.top }, iVpt);
return transformPoint(center, iVpt);
},

/**
Expand Down Expand Up @@ -12033,7 +12039,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
_isSelectionKeyPressed: function(e) {
var selectionKeyPressed = false;

if (Object.prototype.toString.call(this.selectionKey) === '[object Array]') {
if (Array.isArray(this.selectionKey)) {
selectionKeyPressed = !!this.selectionKey.find(function(key) { return e[key] === true; });
}
else {
Expand Down Expand Up @@ -12459,6 +12465,14 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
this.contextTop = upperCanvasEl.getContext('2d');
},

/**
* Returns context of top canvas where interactions are drawn
* @returns {CanvasRenderingContext2D}
*/
getTopContext: function () {
return this.contextTop;
},

/**
* @private
*/
Expand Down Expand Up @@ -15236,11 +15250,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
if (object[prop] === prototype[prop]) {
delete object[prop];
}
var isArray = Object.prototype.toString.call(object[prop]) === '[object Array]' &&
Object.prototype.toString.call(prototype[prop]) === '[object Array]';

// basically a check for [] === []
if (isArray && object[prop].length === 0 && prototype[prop].length === 0) {
if (Array.isArray(object[prop]) && Array.isArray(prototype[prop])
&& object[prop].length === 0 && prototype[prop].length === 0) {
delete object[prop];
}
});
Expand Down Expand Up @@ -15416,7 +15428,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati

renderCache: function(options) {
options = options || {};
if (!this._cacheCanvas) {
if (!this._cacheCanvas || !this._cacheContext) {
this._createCacheCanvas();
}
if (this.isCacheDirty()) {
Expand All @@ -15431,6 +15443,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
*/
_removeCacheCanvas: function() {
this._cacheCanvas = null;
this._cacheContext = null;
this.cacheWidth = 0;
this.cacheHeight = 0;
},
Expand Down Expand Up @@ -15589,7 +15602,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
if (this.isNotVisible()) {
return false;
}
if (this._cacheCanvas && !skipCanvas && this._updateCacheCanvas()) {
if (this._cacheCanvas && this._cacheContext && !skipCanvas && this._updateCacheCanvas()) {
// in this case the context is already cleared.
return true;
}
Expand All @@ -15598,7 +15611,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
(this.clipPath && this.clipPath.absolutePositioned) ||
(this.statefullCache && this.hasStateChanged('cacheProperties'))
) {
if (this._cacheCanvas && !skipCanvas) {
if (this._cacheCanvas && this._cacheContext && !skipCanvas) {
var width = this.cacheWidth / this.zoomX;
var height = this.cacheHeight / this.zoomY;
this._cacheContext.clearRect(-width / 2, -height / 2, width, height);
Expand Down Expand Up @@ -16132,7 +16145,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
* @return {Boolean}
*/
isType: function(type) {
return this.type === type;
return arguments.length > 1 ? Array.from(arguments).includes(this.type) : this.type === type;
},

/**
Expand Down Expand Up @@ -18070,7 +18083,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
return fabric.util.animate({
target: this,
startValue: object.left,
endValue: this.getCenter().left,
endValue: this.getCenterPoint().x,
duration: this.FX_DURATION,
onChange: function(value) {
object.set('left', value);
Expand Down Expand Up @@ -18103,7 +18116,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
return fabric.util.animate({
target: this,
startValue: object.top,
endValue: this.getCenter().top,
endValue: this.getCenterPoint().y,
duration: this.FX_DURATION,
onChange: function(value) {
object.set('top', value);
Expand Down Expand Up @@ -19642,7 +19655,6 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
max = fabric.util.array.max,
extend = fabric.util.object.extend,
clone = fabric.util.object.clone,
_toString = Object.prototype.toString,
toFixed = fabric.util.toFixed;

if (fabric.Path) {
Expand Down Expand Up @@ -19696,10 +19708,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
* @param {Object} [options] Options object
*/
_setPath: function (path, options) {
var fromArray = _toString.call(path) === '[object Array]';

this.path = fabric.util.makePathSimpler(
fromArray ? path : fabric.util.parsePath(path)
Array.isArray(path) ? path : fabric.util.parsePath(path)
);

fabric.Polyline.prototype._setPositionDimensions.call(this, options || {});
Expand Down
2 changes: 1 addition & 1 deletion dist/fabric.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ var eventManager = function(target, type, listener, configure, trigger, fromOver
}
return createBatchCommands(events);
} else if (type.indexOf("on") === 0) { // to support things like "onclick" instead of "click"
type = type.substr(2);
type = type.slice(2);
}

// Ensure listener is a function.
Expand Down Expand Up @@ -1368,7 +1368,7 @@ root.gesture = function(conf) {
var dx = touch.move.x - self.x;
var dy = touch.move.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If touch start.distance from centroid is 0, scale should not be updated.
// If touch start.distance from centroid is 0, scale should not be updated.
// This prevents dividing by 0 in cases where start.distance is oddly 0.
if (start.distance !== 0) {
scale += distance / start.distance;
Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"test:coverage": "nyc --silent qunit test/node_test_setup.js test/lib test/unit",
"test:visual:coverage": "nyc --silent --no-clean qunit test/node_test_setup.js test/lib test/visual",
"coverage:report": "nyc report --reporter=lcov --reporter=text",
"test": "qunit test/node_test_setup.js test/lib test/unit",
"test": "qunit --require ./test/node_test_setup.js test/lib test/unit",
"test:visual": "qunit test/node_test_setup.js test/lib test/visual",
"test:visual:single": "qunit test/node_test_setup.js test/lib",
"test:all": "npm run test && npm run test:visual",
Expand All @@ -75,11 +75,12 @@
"devDependencies": {
"auto-changelog": "^2.3.0",
"chalk": "^2.4.1",
"deep-object-diff": "^1.1.7",
"eslint": "4.18.x",
"nyc": "^15.1.0",
"onchange": "^7.1.0",
"pixelmatch": "^4.0.2",
"qunit": "^2.13.0",
"qunit": "^2.17.2",
"testem": "^3.2.0",
"uglify-js": "3.3.x"
},
Expand Down
Loading

0 comments on commit b8ee6c7

Please sign in to comment.