Comparing version 3.3.2 to 3.4.0-browser
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */ | ||
var fabric = fabric || { version: '3.3.0' }; | ||
var fabric = fabric || { version: '3.4.0' }; | ||
if (typeof exports !== 'undefined') { | ||
@@ -5,0 +5,0 @@ exports.fabric = fabric; |
157
package.json
{ | ||
"name": "fabric", | ||
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.", | ||
"homepage": "http://fabricjs.com/", | ||
"version": "3.3.2", | ||
"authors": "Juriy Zaytsev <kangax@gmail.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Andrea Bogazzi", | ||
"email": "andreabogazzi79@gmail.com" | ||
} | ||
], | ||
"keywords": [ | ||
"canvas", | ||
"graphic", | ||
"graphics", | ||
"SVG", | ||
"node-canvas", | ||
"parser", | ||
"HTML5", | ||
"object model" | ||
], | ||
"browser": { | ||
"canvas": false, | ||
"fs": false, | ||
"jsdom": false, | ||
"jsdom/lib/jsdom/living/generated/utils": false, | ||
"jsdom/lib/jsdom/utils": false, | ||
"http": false, | ||
"https": false, | ||
"xmldom": false, | ||
"url": false | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fabricjs/fabric.js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fabricjs/fabric.js/issues" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "node build.js modules=ALL requirejs exclude=gestures,accessors", | ||
"build:fast": "node build.js modules=ALL requirejs fast exclude=gestures,accessors", | ||
"build:watch": "onchange 'src/**/**' 'HEADER.js' 'lib/**/**' -- npm run build_export", | ||
"build_with_gestures": "node build.js modules=ALL exclude=accessors", | ||
"build_export": "npm run build:fast && npm run export_dist_to_site", | ||
"test:single": "qunit test/node_test_setup.js test/lib", | ||
"test": "nyc qunit 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", | ||
"lint": "eslint --config .eslintrc.json src", | ||
"lint_tests": "eslint test/unit --config .eslintrc_tests && eslint test/visual --config .eslintrc_tests", | ||
"export_dist_to_site": "cp dist/fabric.js ../fabricjs.com/lib/fabric.js && cp package.json ../fabricjs.com/lib/package.json && cp -r src HEADER.js lib ../fabricjs.com/build/files/", | ||
"export_tests_to_site": "cp test/unit/*.js ../fabricjs.com/test/unit && cp -r test/visual/* ../fabricjs.com/test/visual && cp -r test/fixtures/* ../fabricjs.com/test/fixtures && cp -r test/lib/* ../fabricjs.com/test/lib", | ||
"all": "npm run build && npm run test && npm run test:visual && npm run lint && npm run lint_tests && npm run export_dist_to_site && npm run export_tests_to_site", | ||
"testem": "testem .", | ||
"testem:visual": "testem --file testem-visual.json", | ||
"testem:ci": "testem ci" | ||
}, | ||
"optionalDependencies": { | ||
"canvas": "^2.6.0", | ||
"jsdom": "^15.1.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "4.18.x", | ||
"nyc": "13.3.x", | ||
"onchange": "^3.x.x", | ||
"qunit": "2.9.2", | ||
"testem": "^1.18.4", | ||
"uglify-js": "3.3.x", | ||
"pixelmatch": "^4.0.2", | ||
"chalk": "^2.4.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"main": "./dist/fabric.js", | ||
"dependencies": {} | ||
} | ||
"name": "fabric", | ||
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.", | ||
"homepage": "http://fabricjs.com/", | ||
"version": "3.4.0-browser", | ||
"authors": "Juriy Zaytsev <kangax@gmail.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Andrea Bogazzi", | ||
"email": "andreabogazzi79@gmail.com" | ||
} | ||
], | ||
"keywords": [ | ||
"canvas", | ||
"graphic", | ||
"graphics", | ||
"SVG", | ||
"node-canvas", | ||
"parser", | ||
"HTML5", | ||
"object model" | ||
], | ||
"browser": { | ||
"canvas": false, | ||
"fs": false, | ||
"jsdom": false, | ||
"jsdom/lib/jsdom/living/generated/utils": false, | ||
"jsdom/lib/jsdom/utils": false, | ||
"http": false, | ||
"https": false, | ||
"xmldom": false, | ||
"url": false | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fabricjs/fabric.js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fabricjs/fabric.js/issues" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "node build.js modules=ALL requirejs exclude=gestures,accessors", | ||
"build:fast": "node build.js modules=ALL requirejs fast exclude=gestures,accessors", | ||
"build:watch": "onchange 'src/**/**' 'HEADER.js' 'lib/**/**' -- npm run build_export", | ||
"build_with_gestures": "node build.js modules=ALL exclude=accessors", | ||
"build_export": "npm run build:fast && npm run export_dist_to_site", | ||
"test:single": "qunit test/node_test_setup.js test/lib", | ||
"test": "nyc qunit 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", | ||
"lint": "eslint --config .eslintrc.json src", | ||
"lint_tests": "eslint test/unit --config .eslintrc_tests && eslint test/visual --config .eslintrc_tests", | ||
"export_dist_to_site": "cp dist/fabric.js ../fabricjs.com/lib/fabric.js && cp package.json ../fabricjs.com/lib/package.json && cp -r src HEADER.js lib ../fabricjs.com/build/files/", | ||
"export_tests_to_site": "cp test/unit/*.js ../fabricjs.com/test/unit && cp -r test/visual/* ../fabricjs.com/test/visual && cp -r test/fixtures/* ../fabricjs.com/test/fixtures && cp -r test/lib/* ../fabricjs.com/test/lib", | ||
"all": "npm run build && npm run test && npm run test:visual && npm run lint && npm run lint_tests && npm run export_dist_to_site && npm run export_tests_to_site", | ||
"testem": "testem .", | ||
"testem:visual": "testem --file testem-visual.json", | ||
"testem:ci": "testem ci" | ||
}, | ||
"optionalDependencies": {}, | ||
"devDependencies": { | ||
"eslint": "4.18.x", | ||
"nyc": "13.3.x", | ||
"onchange": "^3.x.x", | ||
"qunit": "2.9.2", | ||
"testem": "^1.18.4", | ||
"uglify-js": "3.3.x", | ||
"pixelmatch": "^4.0.2", | ||
"chalk": "^2.4.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"main": "./dist/fabric.js", | ||
"dependencies": {} | ||
} |
@@ -49,4 +49,4 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOptions) { | ||
var _options; | ||
_this.resolveGradient(obj, 'fill'); | ||
_this.resolveGradient(obj, 'stroke'); | ||
_this.resolveGradient(obj, el, 'fill'); | ||
_this.resolveGradient(obj, el, 'stroke'); | ||
if (obj instanceof fabric.Image && obj._originalElement) { | ||
@@ -73,6 +73,8 @@ _options = obj.parsePreserveAspectRatioAttribute(el); | ||
proto.resolveGradient = function(obj, property) { | ||
proto.resolveGradient = function(obj, el, property) { | ||
var gradientDef = this.extractPropertyDefinition(obj, property, 'gradientDefs'); | ||
if (gradientDef) { | ||
obj.set(property, fabric.Gradient.fromElement(gradientDef, obj)); | ||
var opacityAttr = el.getAttribute(property + '-opacity'); | ||
var gradient = fabric.Gradient.fromElement(gradientDef, obj, opacityAttr, this.options); | ||
obj.set(property, gradient); | ||
} | ||
@@ -79,0 +81,0 @@ }; |
(function() { | ||
/* _FROM_SVG_START_ */ | ||
function getColorStop(el) { | ||
function getColorStop(el, multiplier) { | ||
var style = el.getAttribute('style'), | ||
@@ -44,3 +44,3 @@ offset = el.getAttribute('offset') || 0, | ||
opacity = isNaN(parseFloat(opacity)) ? 1 : parseFloat(opacity); | ||
opacity *= colorAlpha; | ||
opacity *= colorAlpha * multiplier; | ||
@@ -100,4 +100,43 @@ return { | ||
/** | ||
* A transform matrix to apply to the gradient before painting. | ||
* Imported from svg gradients, is not applied with the current transform in the center. | ||
* Before this transform is applied, the origin point is at the top left corner of the object | ||
* plus the addition of offsetY and offsetX. | ||
* @type Array[Number] | ||
* @default null | ||
*/ | ||
gradientTransform: null, | ||
/** | ||
* coordinates units for coords. | ||
* If `pixels`, the number of coords are in the same unit of width / height. | ||
* If set as `percentage` the coords are still a number, but 1 means 100% of width | ||
* for the X and 100% of the height for the y. It can be bigger than 1 and negative. | ||
* @type String pixels || percentage | ||
* @default 'pixels' | ||
*/ | ||
gradientUnits: 'pixels', | ||
/** | ||
* Gradient type | ||
* @type String linear || radial | ||
* @default 'pixels' | ||
*/ | ||
type: 'linear', | ||
/** | ||
* Constructor | ||
* @param {Object} [options] Options object with type, coords, gradientUnits and colorStops | ||
* @param {Object} options Options object with type, coords, gradientUnits and colorStops | ||
* @param {Object} [options.type] gradient type linear or radial | ||
* @param {Object} [options.gradientUnits] gradient units | ||
* @param {Object} [options.offsetX] SVG import compatibility | ||
* @param {Object} [options.offsetY] SVG import compatibility | ||
* @param {Array[Object]} options.colorStops contains the colorstops. | ||
* @param {Object} options.coords contains the coords of the gradient | ||
* @param {Number} [options.coords.x1] X coordiante of the first point for linear or of the focal point for radial | ||
* @param {Number} [options.coords.y1] Y coordiante of the first point for linear or of the focal point for radial | ||
* @param {Number} [options.coords.x2] X coordiante of the second point for linear or of the center point for radial | ||
* @param {Number} [options.coords.y2] Y coordiante of the second point for linear or of the center point for radial | ||
* @param {Number} [options.coords.r1] only for radial gradient, radius of the inner circle | ||
* @param {Number} [options.coords.r2] only for radial gradient, radius of the external circle | ||
* @return {fabric.Gradient} thisArg | ||
@@ -107,8 +146,18 @@ */ | ||
options || (options = { }); | ||
options.coords || (options.coords = { }); | ||
var coords = { }; | ||
var coords, _this = this; | ||
this.id = fabric.Object.__uid++; | ||
this.type = options.type || 'linear'; | ||
// sets everything, then coords and colorstops get sets again | ||
Object.keys(options).forEach(function(option) { | ||
_this[option] = options[option]; | ||
}); | ||
if (this.id) { | ||
this.id += '_' + fabric.Object.__uid++; | ||
} | ||
else { | ||
this.id = fabric.Object.__uid++; | ||
} | ||
coords = { | ||
@@ -125,9 +174,5 @@ x1: options.coords.x1 || 0, | ||
} | ||
this.coords = coords; | ||
this.colorStops = options.colorStops.slice(); | ||
if (options.gradientTransform) { | ||
this.gradientTransform = options.gradientTransform; | ||
} | ||
this.offsetX = options.offsetX || this.offsetX; | ||
this.offsetY = options.offsetY || this.offsetY; | ||
}, | ||
@@ -164,2 +209,3 @@ | ||
offsetY: this.offsetY, | ||
gradientUnits: this.gradientUnits, | ||
gradientTransform: this.gradientTransform ? this.gradientTransform.concat() : this.gradientTransform | ||
@@ -183,4 +229,5 @@ }; | ||
transform = this.gradientTransform ? this.gradientTransform.concat() : fabric.iMatrix.concat(), | ||
offsetX = object.width / 2 - this.offsetX, offsetY = object.height / 2 - this.offsetY, | ||
withViewport = !!options.additionalTransform; | ||
offsetX = -this.offsetX, offsetY = -this.offsetY, | ||
withViewport = !!options.additionalTransform, | ||
gradientUnits = this.gradientUnits === 'pixels' ? 'userSpaceOnUse' : 'objectBoundingBox'; | ||
// colorStops must be sorted ascending | ||
@@ -191,2 +238,10 @@ colorStops.sort(function(a, b) { | ||
if (gradientUnits === 'objectBoundingBox') { | ||
offsetX /= object.width; | ||
offsetY /= object.height; | ||
} | ||
else { | ||
offsetX += object.width / 2; | ||
offsetY += object.height / 2; | ||
} | ||
if (object.type === 'path') { | ||
@@ -197,2 +252,3 @@ offsetX -= object.pathOffset.x; | ||
transform[4] -= offsetX; | ||
@@ -202,3 +258,3 @@ transform[5] -= offsetY; | ||
commonAttributes = 'id="SVGID_' + this.id + | ||
'" gradientUnits="userSpaceOnUse"'; | ||
'" gradientUnits="' + gradientUnits + '"'; | ||
commonAttributes += ' gradientTransform="' + (withViewport ? | ||
@@ -314,2 +370,9 @@ options.additionalTransform + ' ' : '') + fabric.util.matrixToSVG(transform) + '" '; | ||
* @param {fabric.Object} instance | ||
* @param {String} opacityAttr A fill-opacity or stroke-opacity attribute to multiply to each stop's opacity. | ||
* @param {Object} svgOptions an object containing the size of the SVG in order to parse correctly graidents | ||
* that uses gradientUnits as 'userSpaceOnUse' and percentages. | ||
* @param {Object.number} viewBoxWidth width part of the viewBox attribute on svg | ||
* @param {Object.number} viewBoxHeight height part of the viewBox attribute on svg | ||
* @param {Object.number} width width part of the svg tag if viewBox is not specified | ||
* @param {Object.number} height height part of the svg tag if viewBox is not specified | ||
* @return {fabric.Gradient} Gradient instance | ||
@@ -319,3 +382,3 @@ * @see http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement | ||
*/ | ||
fromElement: function(el, instance) { | ||
fromElement: function(el, instance, opacityAttr, svgOptions) { | ||
/** | ||
@@ -354,20 +417,22 @@ * @example: | ||
var multiplier = parseFloat(opacityAttr) / (/%$/.test(opacityAttr) ? 100 : 1); | ||
multiplier = multiplier < 0 ? 0 : multiplier > 1 ? 1 : multiplier; | ||
if (isNaN(multiplier)) { | ||
multiplier = 1; | ||
} | ||
var colorStopEls = el.getElementsByTagName('stop'), | ||
type, | ||
gradientUnits = el.getAttribute('gradientUnits') || 'objectBoundingBox', | ||
gradientTransform = el.getAttribute('gradientTransform'), | ||
gradientUnits = el.getAttribute('gradientUnits') === 'userSpaceOnUse' ? | ||
'pixels' : 'percentage', | ||
gradientTransform = el.getAttribute('gradientTransform') || '', | ||
colorStops = [], | ||
coords, ellipseMatrix, i; | ||
coords, i, offsetX = 0, offsetY = 0, | ||
transformMatrix; | ||
if (el.nodeName === 'linearGradient' || el.nodeName === 'LINEARGRADIENT') { | ||
type = 'linear'; | ||
coords = getLinearCoords(el); | ||
} | ||
else { | ||
type = 'radial'; | ||
} | ||
if (type === 'linear') { | ||
coords = getLinearCoords(el); | ||
} | ||
else if (type === 'radial') { | ||
coords = getRadialCoords(el); | ||
@@ -377,19 +442,25 @@ } | ||
for (i = colorStopEls.length; i--; ) { | ||
colorStops.push(getColorStop(colorStopEls[i])); | ||
colorStops.push(getColorStop(colorStopEls[i], multiplier)); | ||
} | ||
ellipseMatrix = _convertPercentUnitsToValues(instance, coords, gradientUnits); | ||
transformMatrix = fabric.parseTransformAttribute(gradientTransform); | ||
__convertPercentUnitsToValues(instance, coords, svgOptions, gradientUnits); | ||
if (gradientUnits === 'pixels') { | ||
offsetX = -instance.left; | ||
offsetY = -instance.top; | ||
} | ||
var gradient = new fabric.Gradient({ | ||
id: el.getAttribute('id'), | ||
type: type, | ||
coords: coords, | ||
colorStops: colorStops, | ||
offsetX: -instance.left, | ||
offsetY: -instance.top | ||
gradientUnits: gradientUnits, | ||
gradientTransform: transformMatrix, | ||
offsetX: offsetX, | ||
offsetY: offsetY, | ||
}); | ||
if (gradientTransform || ellipseMatrix !== '') { | ||
gradient.gradientTransform = fabric.parseTransformAttribute((gradientTransform || '') + ellipseMatrix); | ||
} | ||
return gradient; | ||
@@ -401,3 +472,5 @@ }, | ||
* Returns {@link fabric.Gradient} instance from its object representation | ||
* this function is uniquely used by Object.setGradient and is deprecated with it. | ||
* @static | ||
* @deprecated since 3.4.0 | ||
* @memberOf fabric.Gradient | ||
@@ -409,3 +482,7 @@ * @param {Object} obj | ||
options || (options = { }); | ||
_convertPercentUnitsToValues(obj, options.coords, 'userSpaceOnUse'); | ||
__convertPercentUnitsToValues(obj, options.coords, options.gradientUnits, { | ||
// those values are to avoid errors. this function is uniquely used by | ||
viewBoxWidth: 100, | ||
viewBoxHeight: 100, | ||
}); | ||
return new fabric.Gradient(options); | ||
@@ -418,44 +495,30 @@ } | ||
*/ | ||
function _convertPercentUnitsToValues(object, options, gradientUnits) { | ||
var propValue, addFactor = 0, multFactor = 1, ellipseMatrix = ''; | ||
for (var prop in options) { | ||
if (options[prop] === 'Infinity') { | ||
options[prop] = 1; | ||
function __convertPercentUnitsToValues(instance, options, svgOptions, gradientUnits) { | ||
var propValue, finalValue; | ||
Object.keys(options).forEach(function(prop) { | ||
propValue = options[prop]; | ||
if (propValue === 'Infinity') { | ||
finalValue = 1; | ||
} | ||
else if (options[prop] === '-Infinity') { | ||
options[prop] = 0; | ||
else if (propValue === '-Infinity') { | ||
finalValue = 0; | ||
} | ||
propValue = parseFloat(options[prop], 10); | ||
if (typeof options[prop] === 'string' && /^(\d+\.\d+)%|(\d+)%$/.test(options[prop])) { | ||
multFactor = 0.01; | ||
} | ||
else { | ||
multFactor = 1; | ||
finalValue = parseFloat(options[prop], 10); | ||
if (typeof propValue === 'string' && /^(\d+\.\d+)%|(\d+)%$/.test(propValue)) { | ||
finalValue *= 0.01; | ||
if (gradientUnits === 'pixels') { | ||
// then we need to fix those percentages here in svg parsing | ||
if (prop === 'x1' || prop === 'x2' || prop === 'r2') { | ||
finalValue *= svgOptions.viewBoxWidth || svgOptions.width; | ||
} | ||
if (prop === 'y1' || prop === 'y2') { | ||
finalValue *= svgOptions.viewBoxHeight || svgOptions.height; | ||
} | ||
} | ||
} | ||
} | ||
if (prop === 'x1' || prop === 'x2' || prop === 'r2') { | ||
multFactor *= gradientUnits === 'objectBoundingBox' ? object.width : 1; | ||
addFactor = gradientUnits === 'objectBoundingBox' ? object.left || 0 : 0; | ||
} | ||
else if (prop === 'y1' || prop === 'y2') { | ||
multFactor *= gradientUnits === 'objectBoundingBox' ? object.height : 1; | ||
addFactor = gradientUnits === 'objectBoundingBox' ? object.top || 0 : 0; | ||
} | ||
options[prop] = propValue * multFactor + addFactor; | ||
} | ||
if (object.type === 'ellipse' && | ||
options.r2 !== null && | ||
gradientUnits === 'objectBoundingBox' && | ||
object.rx !== object.ry) { | ||
var scaleFactor = object.ry / object.rx; | ||
ellipseMatrix = ' scale(1, ' + scaleFactor + ')'; | ||
if (options.y1) { | ||
options.y1 /= scaleFactor; | ||
} | ||
if (options.y2) { | ||
options.y2 /= scaleFactor; | ||
} | ||
} | ||
return ellipseMatrix; | ||
options[prop] = finalValue; | ||
}); | ||
} | ||
})(); |
@@ -481,7 +481,3 @@ (function() { | ||
_calcRotateMatrix: function() { | ||
if (this.angle) { | ||
var theta = degreesToRadians(this.angle), cos = fabric.util.cos(theta), sin = fabric.util.sin(theta); | ||
return [cos, sin, -sin, cos, 0, 0]; | ||
} | ||
return fabric.iMatrix.concat(); | ||
return fabric.util.calcRotateMatrix(this); | ||
}, | ||
@@ -531,2 +527,7 @@ | ||
/** | ||
* calculate transform matrix that represents the current transformations from the | ||
* object's properties, this matrix does not include the group transformation | ||
* @return {Array} transform matrix for the object | ||
*/ | ||
calcOwnMatrix: function() { | ||
@@ -537,32 +538,27 @@ var key = this.transformMatrixKey(true), cache = this.ownMatrixCache || (this.ownMatrixCache = {}); | ||
} | ||
var matrix = this._calcTranslateMatrix(), | ||
rotateMatrix, | ||
dimensionMatrix = this._calcDimensionsTransformMatrix(this.skewX, this.skewY, true); | ||
if (this.angle) { | ||
rotateMatrix = this._calcRotateMatrix(); | ||
matrix = multiplyMatrices(matrix, rotateMatrix); | ||
} | ||
matrix = multiplyMatrices(matrix, dimensionMatrix); | ||
var tMatrix = this._calcTranslateMatrix(); | ||
this.translateX = tMatrix[4]; | ||
this.translateY = tMatrix[5]; | ||
cache.key = key; | ||
cache.value = matrix; | ||
return matrix; | ||
cache.value = fabric.util.composeMatrix(this); | ||
return cache.value; | ||
}, | ||
/* | ||
* Calculate object dimensions from its properties | ||
* @private | ||
* @deprecated since 3.4.0, please use fabric.util._calcDimensionsTransformMatrix | ||
* not including or including flipX, flipY to emulate the flipping boolean | ||
* @return {Object} .x width dimension | ||
* @return {Object} .y height dimension | ||
*/ | ||
_calcDimensionsTransformMatrix: function(skewX, skewY, flipping) { | ||
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; | ||
return fabric.util.calcDimensionsMatrix({ | ||
skewX: skewX, | ||
skewY: skewY, | ||
scaleX: this.scaleX * (flipping && this.flipX ? -1 : 1), | ||
scaleY: this.scaleY * (flipping && this.flipY ? -1 : 1) | ||
}); | ||
}, | ||
/* | ||
@@ -631,8 +627,9 @@ * Calculate object dimensions from its properties | ||
}], | ||
i, transformMatrix = this._calcDimensionsTransformMatrix(skewX, skewY, false), | ||
bbox; | ||
for (i = 0; i < points.length; i++) { | ||
points[i] = fabric.util.transformPoint(points[i], transformMatrix); | ||
} | ||
bbox = fabric.util.makeBoundingBoxFromPoints(points); | ||
transformMatrix = fabric.util.calcDimensionsMatrix({ | ||
scaleX: this.scaleX, | ||
scaleY: this.scaleY, | ||
skewX: this.skewX, | ||
skewY: this.skewY, | ||
}), | ||
bbox = fabric.util.makeBoundingBoxFromPoints(points, transformMatrix); | ||
return this._finalizeDimensions(bbox.width, bbox.height); | ||
@@ -639,0 +636,0 @@ }, |
@@ -198,3 +198,7 @@ (function() { | ||
var p = this._getNonTransformedDimensions(), | ||
matrix = fabric.util.customTransformMatrix(options.scaleX, options.scaleY, options.skewX), | ||
matrix = fabric.util.composeMatrix({ | ||
scaleX: options.scaleX, | ||
scaleY: options.scaleY, | ||
skewX: options.skewX | ||
}), | ||
wh = fabric.util.transformPoint(p, matrix), | ||
@@ -201,0 +205,0 @@ strokeWidth = 1 / this.borderScaleFactor, |
@@ -562,3 +562,2 @@ (function(global) { | ||
} | ||
minX = -parseFloat(viewBoxAttr[1]); | ||
@@ -568,3 +567,6 @@ minY = -parseFloat(viewBoxAttr[2]); | ||
viewBoxHeight = parseFloat(viewBoxAttr[4]); | ||
parsedDim.minX = minX; | ||
parsedDim.minY = minY; | ||
parsedDim.viewBoxWidth = viewBoxWidth; | ||
parsedDim.viewBoxHeight = viewBoxHeight; | ||
if (!missingDimAttr) { | ||
@@ -728,3 +730,3 @@ parsedDim.width = parseUnit(widthAttr); | ||
gradientsAttrs.forEach(function(attr) { | ||
if (!gradient.hasAttribute(attr)) { | ||
if (referencedGradient && !gradient.hasAttribute(attr) && referencedGradient.hasAttribute(attr)) { | ||
gradient.setAttribute(attr, referencedGradient.getAttribute(attr)); | ||
@@ -731,0 +733,0 @@ } |
@@ -7,2 +7,6 @@ (function() { | ||
function defaultEasing(t, b, c, d) { | ||
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; | ||
} | ||
/** | ||
@@ -32,3 +36,3 @@ * Changes value from one to another within certain period of time, invoking callbacks as value is being changed. | ||
onComplete = options.onComplete || noop, | ||
easing = options.easing || function(t, b, c, d) {return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;}, | ||
easing = options.easing || defaultEasing, | ||
startValue = 'startValue' in options ? options.startValue : 0, | ||
@@ -43,6 +47,2 @@ endValue = 'endValue' in options ? options.endValue : 100, | ||
// and pass (current,valuePerc, timePerc) as arguments | ||
if (abort()) { | ||
onComplete(endValue, 1, 1); | ||
return; | ||
} | ||
time = ticktime || +new Date(); | ||
@@ -53,11 +53,17 @@ var currentTime = time > finish ? duration : (time - start), | ||
valuePerc = Math.abs((current - startValue) / byValue); | ||
onChange(current, valuePerc, timePerc); | ||
if (abort()) { | ||
onComplete(endValue, 1, 1); | ||
return; | ||
} | ||
if (time > finish) { | ||
options.onComplete && options.onComplete(); | ||
onChange(endValue, 1, 1); | ||
onComplete(endValue, 1, 1); | ||
return; | ||
} | ||
requestAnimFrame(tick); | ||
else { | ||
onChange(current, valuePerc, timePerc); | ||
requestAnimFrame(tick); | ||
} | ||
})(start); | ||
}); | ||
} | ||
@@ -64,0 +70,0 @@ |
@@ -6,3 +6,2 @@ (function(global) { | ||
pow = Math.pow, | ||
abs = Math.abs, | ||
PiBy180 = Math.PI / 180, | ||
@@ -169,5 +168,11 @@ PiBy2 = Math.PI / 2; | ||
* @param {Array} points 4 points array | ||
* @param {Array} [transform] an array of 6 numbers representing a 2x3 transform matrix | ||
* @return {Object} Object with left, top, width, height properties | ||
*/ | ||
makeBoundingBoxFromPoints: function(points) { | ||
makeBoundingBoxFromPoints: function(points, transform) { | ||
if (transform) { | ||
for (var i = 0; i < points.length; i++) { | ||
points[i] = fabric.util.transformPoint(points[i], transform); | ||
} | ||
} | ||
var xPoints = [points[0].x, points[1].x, points[2].x, points[3].x], | ||
@@ -663,3 +668,3 @@ minX = fabric.util.array.min(xPoints), | ||
/** | ||
* Decomposes standard 2x2 matrix into transform componentes | ||
* Decomposes standard 2x3 matrix into transform components | ||
* @static | ||
@@ -687,6 +692,109 @@ * @memberOf fabric.util | ||
/** | ||
* Returns a transform matrix starting from an object of the same kind of | ||
* the one returned from qrDecompose, useful also if you want to calculate some | ||
* transformations from an object that is not enlived yet | ||
* @static | ||
* @memberOf fabric.util | ||
* @param {Object} options | ||
* @param {Number} [options.angle] angle in degrees | ||
* @return {Array[Number]} transform matrix | ||
*/ | ||
calcRotateMatrix: function(options) { | ||
if (!options.angle) { | ||
return fabric.iMatrix.concat(); | ||
} | ||
var theta = fabric.util.degreesToRadians(options.angle), | ||
cos = fabric.util.cos(theta), | ||
sin = fabric.util.sin(theta); | ||
return [cos, sin, -sin, cos, 0, 0]; | ||
}, | ||
/** | ||
* Returns a transform matrix starting from an object of the same kind of | ||
* the one returned from qrDecompose, useful also if you want to calculate some | ||
* transformations from an object that is not enlived yet. | ||
* is called DimensionsTransformMatrix because those properties are the one that influence | ||
* the size of the resulting box of the object. | ||
* @static | ||
* @memberOf fabric.util | ||
* @param {Object} options | ||
* @param {Number} [options.scaleX] | ||
* @param {Number} [options.scaleY] | ||
* @param {Boolean} [options.flipX] | ||
* @param {Boolean} [options.flipY] | ||
* @param {Number} [options.skewX] | ||
* @param {Number} [options.skewX] | ||
* @return {Array[Number]} transform matrix | ||
*/ | ||
calcDimensionsMatrix: function(options) { | ||
var scaleX = typeof options.scaleX === 'undefined' ? 1 : options.scaleX, | ||
scaleY = typeof options.scaleY === 'undefined' ? 1 : options.scaleY, | ||
scaleMatrix = [ | ||
options.flipX ? -scaleX : scaleX, | ||
0, | ||
0, | ||
options.flipY ? -scaleY : scaleY, | ||
0, | ||
0], | ||
multiply = fabric.util.multiplyTransformMatrices, | ||
degreesToRadians = fabric.util.degreesToRadians; | ||
if (options.skewX) { | ||
scaleMatrix = multiply( | ||
scaleMatrix, | ||
[1, 0, Math.tan(degreesToRadians(options.skewX)), 1], | ||
true); | ||
} | ||
if (options.skewY) { | ||
scaleMatrix = multiply( | ||
scaleMatrix, | ||
[1, Math.tan(degreesToRadians(options.skewY)), 0, 1], | ||
true); | ||
} | ||
return scaleMatrix; | ||
}, | ||
/** | ||
* Returns a transform matrix starting from an object of the same kind of | ||
* the one returned from qrDecompose, useful also if you want to calculate some | ||
* transformations from an object that is not enlived yet | ||
* @static | ||
* @memberOf fabric.util | ||
* @param {Object} options | ||
* @param {Number} [options.angle] | ||
* @param {Number} [options.scaleX] | ||
* @param {Number} [options.scaleY] | ||
* @param {Boolean} [options.flipX] | ||
* @param {Boolean} [options.flipY] | ||
* @param {Number} [options.skewX] | ||
* @param {Number} [options.skewX] | ||
* @param {Number} [options.translateX] | ||
* @param {Number} [options.translateY] | ||
* @return {Array[Number]} transform matrix | ||
*/ | ||
composeMatrix: function(options) { | ||
var matrix = [1, 0, 0, 1, options.translateX || 0, options.translateY || 0], | ||
multiply = fabric.util.multiplyTransformMatrices; | ||
if (options.angle) { | ||
matrix = multiply(matrix, fabric.util.calcRotateMatrix(options)); | ||
} | ||
if (options.scaleX || options.scaleY || options.skewX || options.skewY || options.flipX || options.flipY) { | ||
matrix = multiply(matrix, fabric.util.calcDimensionsMatrix(options)); | ||
} | ||
return matrix; | ||
}, | ||
/** | ||
* Returns a transform matrix that has the same effect of scaleX, scaleY and skewX. | ||
* Is deprecated for composeMatrix. Please do not use it. | ||
* @static | ||
* @deprecated since 3.4.0 | ||
* @memberOf fabric.util | ||
* @param {Number} scaleX | ||
* @param {Number} scaleY | ||
* @param {Number} skewX | ||
* @return {Array[Number]} transform matrix | ||
*/ | ||
customTransformMatrix: function(scaleX, scaleY, skewX) { | ||
var skewMatrixX = [1, 0, abs(Math.tan(skewX * PiBy180)), 1], | ||
scaleMatrix = [abs(scaleX), 0, 0, abs(scaleY)]; | ||
return fabric.util.multiplyTransformMatrices(scaleMatrix, skewMatrixX, true); | ||
return fabric.util.composeMatrix({ scaleX: scaleX, scaleY: scaleY, skewX: skewX }); | ||
}, | ||
@@ -693,0 +801,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2376806
0
56158
2