Skip to content

Commit

Permalink
Merge branch 'test-pr-transform' into ts-proto
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Jun 12, 2022
2 parents 22002ca + 0b6da98 commit 656bc9d
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 52 deletions.
6 changes: 2 additions & 4 deletions src/controls.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@

function fireEvent(eventName, options) {
var target = options.transform.target,
canvas = target.canvas,
canvasOptions = fabric.util.object.clone(options);
canvasOptions.target = target;
canvas && canvas.fire('object:' + eventName, canvasOptions);
canvas = target.canvas;
canvas && canvas.fire('object:' + eventName, Object.assign({}, options, { target: target }));
target.fire(eventName, options);
}

Expand Down
4 changes: 1 addition & 3 deletions src/filters/blendimage_filter.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ export class BlendImage extends fabric.Image.filters.BaseFilter {
*/
fabric.Image.filters.BlendImage.fromObject = function(object) {
return fabric.Image.fromObject(object.image).then(function(image) {
var options = fabric.util.object.clone(object);
options.image = image;
return new fabric.Image.filters.BlendImage(options);
return new fabric.Image.filters.BlendImage(Object.assign({}, object, { image: image }));
});
};

8 changes: 3 additions & 5 deletions src/gradient.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@
}
/* _FROM_SVG_END_ */

var clone = fabric.util.object.clone;

/**
* Gradient class
* @class fabric.Gradient
Expand Down Expand Up @@ -219,8 +217,8 @@ export class Gradient {
* @return {String} SVG representation of an gradient (linear/radial)
*/
toSVG(object, options) {
var coords = clone(this.coords, true), i, len, options = options || {},
markup, commonAttributes, colorStops = clone(this.colorStops, true),
var coords = this.coords, i, len, options = options || {},
markup, commonAttributes, colorStops = this.colorStops,
needsSwap = coords.r1 > coords.r2,
transform = this.gradientTransform ? this.gradientTransform.concat() : fabric.iMatrix.concat(),
offsetX = -this.offsetX, offsetY = -this.offsetY,
Expand Down Expand Up @@ -321,7 +319,7 @@ export class Gradient {
* @return {CanvasGradient}
*/
toLive(ctx) {
var gradient, coords = fabric.util.object.clone(this.coords), i, len;
var gradient, coords = this.coords, i, len;

if (!this.type) {
return;
Expand Down
7 changes: 1 addition & 6 deletions src/mixins/animation.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,7 @@ export function ObjectAnimationMixinGenerator(Klass) {

to = to.toString();

if (!options) {
options = { };
}
else {
options = fabric.util.object.clone(options);
}
options = Object.assign({}, options);

if (~property.indexOf('.')) {
propPair = property.split('.');
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/canvas_serialization.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function StaticCanvasSerializationMixinGenerator(Klass) {
// serialize if it wasn't already
var serialized = (typeof json === 'string')
? JSON.parse(json)
: fabric.util.object.clone(json);
: Object.assign({}, json);

var _this = this,
renderOnAddRemove = this.renderOnAddRemove;
Expand Down
17 changes: 7 additions & 10 deletions src/mixins/itext_behavior.mixin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//@ts-nocheck


var clone = fabric.util.object.clone;


export function ITextBehaviorMixinGenerator(Klass) {
return class ITextBehaviorMixin extends Klass {
Expand Down Expand Up @@ -716,7 +713,7 @@ export function ITextBehaviorMixinGenerator(Klass) {
shiftLineStyles(lineIndex, offset) {
// shift all line styles by offset upward or downward
// do not clone deep. we need new array, not new style objects
var clonedStyles = clone(this.styles);
var clonedStyles = Object.assign({}, this.styles);
for (var line in this.styles) {
var numericLine = parseInt(line, 10);
if (numericLine > lineIndex) {
Expand Down Expand Up @@ -785,10 +782,10 @@ export function ITextBehaviorMixinGenerator(Klass) {
// we clone current char style onto the next (otherwise empty) line
while (qty > 0) {
if (copiedStyle && copiedStyle[qty - 1]) {
this.styles[lineIndex + qty] = { 0: clone(copiedStyle[qty - 1]) };
this.styles[lineIndex + qty] = { 0: Object.assign({}, copiedStyle[qty - 1]) };
}
else if (currentCharStyle) {
this.styles[lineIndex + qty] = { 0: clone(currentCharStyle) };
this.styles[lineIndex + qty] = { 0: Object.assign({}, currentCharStyle) };
}
else {
delete this.styles[lineIndex + qty];
Expand All @@ -809,8 +806,8 @@ export function ITextBehaviorMixinGenerator(Klass) {
if (!this.styles) {
this.styles = {};
}
var currentLineStyles = this.styles[lineIndex],
currentLineStylesCloned = currentLineStyles ? clone(currentLineStyles) : {};
var currentLineStyles = this.styles[lineIndex],
currentLineStylesCloned = currentLineStyles ? Object.assign({}, currentLineStyles) : {};

quantity || (quantity = 1);
// shift all char styles by quantity forward
Expand All @@ -834,7 +831,7 @@ export function ITextBehaviorMixinGenerator(Klass) {
if (!this.styles[lineIndex]) {
this.styles[lineIndex] = {};
}
this.styles[lineIndex][charIndex + quantity] = clone(copiedStyle[quantity]);
this.styles[lineIndex][charIndex + quantity] = Object.assign({}, copiedStyle[quantity]);
}
return;
}
Expand All @@ -843,7 +840,7 @@ export function ITextBehaviorMixinGenerator(Klass) {
}
var newStyle = currentLineStyles[charIndex ? charIndex - 1 : 1];
while (newStyle && quantity--) {
this.styles[lineIndex][charIndex + quantity] = clone(newStyle);
this.styles[lineIndex][charIndex + quantity] = Object.assign({}, newStyle);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mixins/itext_key_behavior.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function ITextKeyBehaviorMixinGenerator(Klass) {
* your prototype.
* the map change will affect all Instances unless you need for only some text Instances
* in that case you have to clone this object and assign your Instance.
* this.keysMap = fabric.util.object.clone(this.keysMap);
* this.keysMap = Object.assign({}, this.keysMap);
* The function must be in fabric.Itext.prototype.myFunction And will receive event as args[0]
*/
keysMap = {
Expand Down
16 changes: 7 additions & 9 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/

var fabric = global.fabric || (global.fabric = { }),
extend = fabric.util.object.extend,
clone = fabric.util.object.clone,
toFixed = fabric.util.toFixed,
parseUnit = fabric.util.parseUnit,
multiplyTransformMatrices = fabric.util.multiplyTransformMatrices,
Expand Down Expand Up @@ -742,7 +740,7 @@
delete fabric.cssRules[svgUid];
delete fabric.clipPaths[svgUid];
}
}, clone(options), reviver, parsingOptions);
}, Object.assign({}, options), reviver, parsingOptions);
};

function recursivelyParseGradientsXlink(doc, gradient) {
Expand Down Expand Up @@ -773,7 +771,7 @@
fabric.reNum +
'(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|' + fabric.reNum + '))?\\s+(.*)');

extend(fabric, {
fabric.util.object.extend(fabric, {
/**
* Parses a short font declaration, building adding its properties to a style object
* @static
Expand Down Expand Up @@ -876,11 +874,11 @@
}, { });
// add values parsed from style, which take precedence over attributes
// (see: http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes)
var cssAttrs = extend(
var cssAttrs = Object.assign(
getGlobalStylesForElement(element, svgUid),
fabric.parseStyleAttribute(element)
);
ownAttributes = extend(
ownAttributes = Object.assign(
ownAttributes,
cssAttrs
);
Expand All @@ -902,7 +900,7 @@
if (normalizedStyle && normalizedStyle.font) {
fabric.parseFontDeclaration(normalizedStyle.font, normalizedStyle);
}
var mergedAttrs = extend(parentAttributes, normalizedStyle);
var mergedAttrs = Object.assign(parentAttributes, normalizedStyle);
return fabric.svgValidParentsRegEx.test(element.nodeName) ? mergedAttrs : _setStrokeFillOpacity(mergedAttrs);
},

Expand Down Expand Up @@ -1026,10 +1024,10 @@
return;
}
if (allRules[_rule]) {
fabric.util.object.extend(allRules[_rule], ruleObj);
Object.assign(allRules[_rule], ruleObj);
}
else {
allRules[_rule] = fabric.util.object.clone(ruleObj);
allRules[_rule] = Object.assign({}, ruleObj);
}
});
});
Expand Down
5 changes: 2 additions & 3 deletions src/shapes/group.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
transformPoint = fabric.util.transformPoint,
applyTransformToObject = fabric.util.applyTransformToObject,
degreesToRadians = fabric.util.degreesToRadians,
clone = fabric.util.object.clone,
extend = fabric.util.object.extend;
clone = fabric.util.object.clone;



Expand Down Expand Up @@ -182,7 +181,7 @@ export class Group extends fabric.Collection {
* @private
*/
__objectMonitor(opt) {
this._applyLayoutStrategy(extend(clone(opt), {
this._applyLayoutStrategy(Object.assign({}, opt, {
type: 'object_modified'
}));
this._set('dirty', true);
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/image.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ export class Image extends fabric.Object {
* @returns {Promise<fabric.Image>}
*/
fabric.Image.fromObject = function(_object) {
var object = fabric.util.object.clone(_object),
var object = Object.assign({}, _object),
filters = object.filters,
resizeFilter = object.resizeFilter;
// the generic enliving will fail on filters for now
Expand Down
5 changes: 2 additions & 3 deletions src/shapes/rect.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

'use strict';

var fabric = global.fabric || (global.fabric = { }),
extend = fabric.util.object.extend;
var fabric = global.fabric || (global.fabric = { });



Expand Down Expand Up @@ -165,7 +164,7 @@ export class Rect extends fabric.Object {
parsedAttributes.top = parsedAttributes.top || 0;
parsedAttributes.height = parsedAttributes.height || 0;
parsedAttributes.width = parsedAttributes.width || 0;
var rect = new fabric.Rect(extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes));
var rect = new fabric.Rect(Object.assign({}, options, parsedAttributes));
rect.visible = rect.visible && rect.width > 0 && rect.height > 0;
callback(rect);
};
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/text.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ export class Text extends fabric.Object {

var parsedAttributes = fabric.parseAttributes(element, fabric.Text.ATTRIBUTE_NAMES),
parsedAnchor = parsedAttributes.textAnchor || 'left';
options = fabric.util.object.extend((options ? clone(options) : { }), parsedAttributes);
options = Object.assign({}, options, parsedAttributes);

options.top = options.top || 0;
options.left = options.left || 0;
Expand Down
5 changes: 1 addition & 4 deletions src/util/animate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
(function () {

var extend = fabric.util.object.extend,
clone = fabric.util.object.clone;

/**
*
* @typedef {Object} AnimationOptions
Expand Down Expand Up @@ -157,7 +154,7 @@
return index > -1 && fabric.runningAnimations.splice(index, 1)[0];
};

context = extend(clone(options), {
context = Object.assign({}, options, {
cancel: function () {
cancel = true;
return removeFromRegistry();
Expand Down
2 changes: 1 addition & 1 deletion src/util/animate_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
originalOnChange = options.onChange;
options = options || {};

return fabric.util.animate(fabric.util.object.extend(options, {
return fabric.util.animate(Object.assign(options, {
duration: duration || 500,
startValue: startColor,
endValue: endColor,
Expand Down

0 comments on commit 656bc9d

Please sign in to comment.