fabric 5.0.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.1.0]
4
+
5
+ - build(deps): bump node-fetch from 2.6.6 to 2.6.7 [`#7684`](https://github.com/fabricjs/fabric.js/pull/7684)
6
+ - build(deps): bump follow-redirects from 1.14.6 to 1.14.8 [`#7683`](https://github.com/fabricjs/fabric.js/pull/7683)
7
+ - build(deps): bump simple-get from 3.1.0 to 3.1.1 [`#7682`](https://github.com/fabricjs/fabric.js/pull/7682)
8
+ - build(deps): bump engine.io from 6.1.0 to 6.1.2 [`#7681`](https://github.com/fabricjs/fabric.js/pull/7681)
9
+ - fix(test): Remove expect assertion [`#7678`](https://github.com/fabricjs/fabric.js/pull/7678)
10
+ - docs(blendimage_filter.class.js) corrected mode options [`#7672`](https://github.com/fabricjs/fabric.js/pull/7672)
11
+ - chore(): Update bug_report.md [`#7659`](https://github.com/fabricjs/fabric.js/pull/7659)
12
+ - fix(util.animation): remove extra animation cancel [`#7631`](https://github.com/fabricjs/fabric.js/pull/7631)
13
+ - feat(animation): Support a list of animation values for animating matrices changes [`#7633`](https://github.com/fabricjs/fabric.js/pull/7633)
14
+ - ci(tests): windows and linux paths resolutions [`#7635`](https://github.com/fabricjs/fabric.js/pull/7635)
3
15
 
4
16
  ## [5.0.0]
5
17
 
package/HEADER.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
2
2
 
3
- var fabric = fabric || { version: '5.0.0' };
3
+ var fabric = fabric || { version: '5.2.1' };
4
4
  if (typeof exports !== 'undefined') {
5
5
  exports.fabric = fabric;
6
6
  }
package/dist/fabric.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* build: `node build.js modules=ALL exclude=gestures,accessors,erasing requirejs minifier=uglifyjs` */
2
2
  /*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
3
3
 
4
- var fabric = fabric || { version: '5.0.0' };
4
+ var fabric = fabric || { version: '5.2.1' };
5
5
  if (typeof exports !== 'undefined') {
6
6
  exports.fabric = fabric;
7
7
  }
@@ -1304,7 +1304,7 @@ fabric.CommonMethods = {
1304
1304
  * @return {Array} properties Properties names to include
1305
1305
  */
1306
1306
  populateWithProperties: function(source, destination, properties) {
1307
- if (properties && Object.prototype.toString.call(properties) === '[object Array]') {
1307
+ if (properties && Array.isArray(properties)) {
1308
1308
  for (var i = 0, len = properties.length; i < len; i++) {
1309
1309
  if (properties[i] in source) {
1310
1310
  destination[properties[i]] = source[properties[i]];
@@ -3577,19 +3577,34 @@ fabric.warn = console.warn;
3577
3577
 
3578
3578
  /**
3579
3579
  * @typedef {Object} AnimationOptions
3580
- * @property {Function} [options.onChange] Callback; invoked on every value change
3581
- * @property {Function} [options.onComplete] Callback; invoked when value change is completed
3582
- * @property {Number} [options.startValue=0] Starting value
3583
- * @property {Number} [options.endValue=100] Ending value
3584
- * @property {Number} [options.byValue=100] Value to modify the property by
3585
- * @property {Function} [options.easing] Easing function
3586
- * @property {Number} [options.duration=500] Duration of change (in ms)
3587
- * @property {Function} [options.abort] Additional function with logic. If returns true, animation aborts.
3580
+ * Animation of a value or list of values.
3581
+ * When using lists, think of something like this:
3582
+ * fabric.util.animate({
3583
+ * startValue: [1, 2, 3],
3584
+ * endValue: [2, 4, 6],
3585
+ * onChange: function([a, b, c]) {
3586
+ * canvas.zoomToPoint({x: b, y: c}, a)
3587
+ * canvas.renderAll()
3588
+ * }
3589
+ * });
3590
+ * @example
3591
+ * @property {Function} [onChange] Callback; invoked on every value change
3592
+ * @property {Function} [onComplete] Callback; invoked when value change is completed
3593
+ * @example
3594
+ * // Note: startValue, endValue, and byValue must match the type
3595
+ * var animationOptions = { startValue: 0, endValue: 1, byValue: 0.25 }
3596
+ * var animationOptions = { startValue: [0, 1], endValue: [1, 2], byValue: [0.25, 0.25] }
3597
+ * @property {number | number[]} [startValue=0] Starting value
3598
+ * @property {number | number[]} [endValue=100] Ending value
3599
+ * @property {number | number[]} [byValue=100] Value to modify the property by
3600
+ * @property {Function} [easing] Easing function
3601
+ * @property {Number} [duration=500] Duration of change (in ms)
3602
+ * @property {Function} [abort] Additional function with logic. If returns true, animation aborts.
3588
3603
  *
3589
3604
  * @typedef {() => void} CancelFunction
3590
3605
  *
3591
3606
  * @typedef {Object} AnimationCurrentState
3592
- * @property {number} currentValue value in range [`startValue`, `endValue`]
3607
+ * @property {number | number[]} currentValue value in range [`startValue`, `endValue`]
3593
3608
  * @property {number} completionRate value in range [0, 1]
3594
3609
  * @property {number} durationRate value in range [0, 1]
3595
3610
  *
@@ -3694,6 +3709,10 @@ fabric.warn = console.warn;
3694
3709
  * Changes value from one to another within certain period of time, invoking callbacks as value is being changed.
3695
3710
  * @memberOf fabric.util
3696
3711
  * @param {AnimationOptions} [options] Animation options
3712
+ * @example
3713
+ * // Note: startValue, endValue, and byValue must match the type
3714
+ * fabric.util.animate({ startValue: 0, endValue: 1, byValue: 0.25 })
3715
+ * fabric.util.animate({ startValue: [0, 1], endValue: [1, 2], byValue: [0.25, 0.25] })
3697
3716
  * @returns {CancelFunction} cancel function
3698
3717
  */
3699
3718
  function animate(options) {
@@ -3724,9 +3743,12 @@ fabric.warn = console.warn;
3724
3743
  abort = options.abort || noop,
3725
3744
  onComplete = options.onComplete || noop,
3726
3745
  easing = options.easing || defaultEasing,
3746
+ isMany = 'startValue' in options ? options.startValue.length > 0 : false,
3727
3747
  startValue = 'startValue' in options ? options.startValue : 0,
3728
3748
  endValue = 'endValue' in options ? options.endValue : 100,
3729
- byValue = options.byValue || endValue - startValue;
3749
+ byValue = options.byValue || (isMany ? startValue.map(function(value, i) {
3750
+ return endValue[i] - startValue[i];
3751
+ }) : endValue - startValue);
3730
3752
 
3731
3753
  options.onStart && options.onStart();
3732
3754
 
@@ -3734,10 +3756,13 @@ fabric.warn = console.warn;
3734
3756
  time = ticktime || +new Date();
3735
3757
  var currentTime = time > finish ? duration : (time - start),
3736
3758
  timePerc = currentTime / duration,
3737
- current = easing(currentTime, startValue, byValue, duration),
3738
- valuePerc = Math.abs((current - startValue) / byValue);
3759
+ current = isMany ? startValue.map(function(_value, i) {
3760
+ return easing(currentTime, startValue[i], byValue[i], duration);
3761
+ }) : easing(currentTime, startValue, byValue, duration),
3762
+ valuePerc = isMany ? Math.abs((current[0] - startValue[0]) / byValue[0])
3763
+ : Math.abs((current - startValue) / byValue);
3739
3764
  // update context
3740
- context.currentValue = current;
3765
+ context.currentValue = isMany ? current.slice() : current;
3741
3766
  context.completionRate = valuePerc;
3742
3767
  context.durationRate = timePerc;
3743
3768
  if (cancel) {
@@ -3749,11 +3774,11 @@ fabric.warn = console.warn;
3749
3774
  }
3750
3775
  if (time > finish) {
3751
3776
  // update context
3752
- context.currentValue = endValue;
3777
+ context.currentValue = isMany ? endValue.slice() : endValue;
3753
3778
  context.completionRate = 1;
3754
3779
  context.durationRate = 1;
3755
3780
  // execute callbacks
3756
- onChange(endValue, 1, 1);
3781
+ onChange(isMany ? endValue.slice() : endValue, 1, 1);
3757
3782
  onComplete(endValue, 1, 1);
3758
3783
  removeFromRegistry();
3759
3784
  return;
@@ -4357,8 +4382,7 @@ fabric.warn = console.warn;
4357
4382
  }
4358
4383
 
4359
4384
  function normalizeValue(attr, value, parentAttributes, fontSize) {
4360
- var isArray = Object.prototype.toString.call(value) === '[object Array]',
4361
- parsed;
4385
+ var isArray = Array.isArray(value), parsed;
4362
4386
 
4363
4387
  if ((attr === 'fill' || attr === 'stroke') && value === 'none') {
4364
4388
  value = '';
@@ -4756,7 +4780,7 @@ fabric.warn = console.warn;
4756
4780
  return;
4757
4781
  }
4758
4782
 
4759
- var xlink = xlinkAttribute.substr(1),
4783
+ var xlink = xlinkAttribute.slice(1),
4760
4784
  x = el.getAttribute('x') || 0,
4761
4785
  y = el.getAttribute('y') || 0,
4762
4786
  el2 = elementById(doc, xlink).cloneNode(true),
@@ -5028,7 +5052,7 @@ fabric.warn = console.warn;
5028
5052
  function recursivelyParseGradientsXlink(doc, gradient) {
5029
5053
  var gradientsAttrs = ['gradientTransform', 'x1', 'x2', 'y1', 'y2', 'gradientUnits', 'cx', 'cy', 'r', 'fx', 'fy'],
5030
5054
  xlinkAttr = 'xlink:href',
5031
- xLink = gradient.getAttribute(xlinkAttr).substr(1),
5055
+ xLink = gradient.getAttribute(xlinkAttr).slice(1),
5032
5056
  referencedGradient = elementById(doc, xLink);
5033
5057
  if (referencedGradient && referencedGradient.getAttribute(xlinkAttr)) {
5034
5058
  recursivelyParseGradientsXlink(doc, referencedGradient);
@@ -9768,6 +9792,7 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
9768
9792
  * Returns coordinates of a center of canvas.
9769
9793
  * Returned value is an object with top and left properties
9770
9794
  * @return {Object} object with "top" and "left" number values
9795
+ * @deprecated migrate to `getCenterPoint`
9771
9796
  */
9772
9797
  getCenter: function () {
9773
9798
  return {
@@ -9776,13 +9801,21 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
9776
9801
  };
9777
9802
  },
9778
9803
 
9804
+ /**
9805
+ * Returns coordinates of a center of canvas.
9806
+ * @return {fabric.Point}
9807
+ */
9808
+ getCenterPoint: function () {
9809
+ return new fabric.Point(this.width / 2, this.height / 2);
9810
+ },
9811
+
9779
9812
  /**
9780
9813
  * Centers object horizontally in the canvas
9781
9814
  * @param {fabric.Object} object Object to center horizontally
9782
9815
  * @return {fabric.Canvas} thisArg
9783
9816
  */
9784
9817
  centerObjectH: function (object) {
9785
- return this._centerObject(object, new fabric.Point(this.getCenter().left, object.getCenterPoint().y));
9818
+ return this._centerObject(object, new fabric.Point(this.getCenterPoint().x, object.getCenterPoint().y));
9786
9819
  },
9787
9820
 
9788
9821
  /**
@@ -9792,7 +9825,7 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
9792
9825
  * @chainable
9793
9826
  */
9794
9827
  centerObjectV: function (object) {
9795
- return this._centerObject(object, new fabric.Point(object.getCenterPoint().x, this.getCenter().top));
9828
+ return this._centerObject(object, new fabric.Point(object.getCenterPoint().x, this.getCenterPoint().y));
9796
9829
  },
9797
9830
 
9798
9831
  /**
@@ -9802,9 +9835,8 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
9802
9835
  * @chainable
9803
9836
  */
9804
9837
  centerObject: function(object) {
9805
- var center = this.getCenter();
9806
-
9807
- return this._centerObject(object, new fabric.Point(center.left, center.top));
9838
+ var center = this.getCenterPoint();
9839
+ return this._centerObject(object, center);
9808
9840
  },
9809
9841
 
9810
9842
  /**
@@ -9815,7 +9847,6 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
9815
9847
  */
9816
9848
  viewportCenterObject: function(object) {
9817
9849
  var vpCenter = this.getVpCenter();
9818
-
9819
9850
  return this._centerObject(object, vpCenter);
9820
9851
  },
9821
9852
 
@@ -9849,9 +9880,9 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
9849
9880
  * @chainable
9850
9881
  */
9851
9882
  getVpCenter: function() {
9852
- var center = this.getCenter(),
9883
+ var center = this.getCenterPoint(),
9853
9884
  iVpt = invertTransform(this.viewportTransform);
9854
- return transformPoint({ x: center.left, y: center.top }, iVpt);
9885
+ return transformPoint(center, iVpt);
9855
9886
  },
9856
9887
 
9857
9888
  /**
@@ -10503,10 +10534,6 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
10503
10534
  }
10504
10535
  this.forEachObject(function(object) {
10505
10536
  object.dispose && object.dispose();
10506
- // animation module is still optional
10507
- if (fabric.runningAnimations) {
10508
- fabric.runningAnimations.cancelByTarget(object);
10509
- }
10510
10537
  });
10511
10538
  this._objects = [];
10512
10539
  if (this.backgroundImage && this.backgroundImage.dispose) {
@@ -12012,7 +12039,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
12012
12039
  _isSelectionKeyPressed: function(e) {
12013
12040
  var selectionKeyPressed = false;
12014
12041
 
12015
- if (Object.prototype.toString.call(this.selectionKey) === '[object Array]') {
12042
+ if (Array.isArray(this.selectionKey)) {
12016
12043
  selectionKeyPressed = !!this.selectionKey.find(function(key) { return e[key] === true; });
12017
12044
  }
12018
12045
  else {
@@ -12438,6 +12465,14 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
12438
12465
  this.contextTop = upperCanvasEl.getContext('2d');
12439
12466
  },
12440
12467
 
12468
+ /**
12469
+ * Returns context of top canvas where interactions are drawn
12470
+ * @returns {CanvasRenderingContext2D}
12471
+ */
12472
+ getTopContext: function () {
12473
+ return this.contextTop;
12474
+ },
12475
+
12441
12476
  /**
12442
12477
  * @private
12443
12478
  */
@@ -15215,11 +15250,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
15215
15250
  if (object[prop] === prototype[prop]) {
15216
15251
  delete object[prop];
15217
15252
  }
15218
- var isArray = Object.prototype.toString.call(object[prop]) === '[object Array]' &&
15219
- Object.prototype.toString.call(prototype[prop]) === '[object Array]';
15220
-
15221
15253
  // basically a check for [] === []
15222
- if (isArray && object[prop].length === 0 && prototype[prop].length === 0) {
15254
+ if (Array.isArray(object[prop]) && Array.isArray(prototype[prop])
15255
+ && object[prop].length === 0 && prototype[prop].length === 0) {
15223
15256
  delete object[prop];
15224
15257
  }
15225
15258
  });
@@ -15395,7 +15428,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
15395
15428
 
15396
15429
  renderCache: function(options) {
15397
15430
  options = options || {};
15398
- if (!this._cacheCanvas) {
15431
+ if (!this._cacheCanvas || !this._cacheContext) {
15399
15432
  this._createCacheCanvas();
15400
15433
  }
15401
15434
  if (this.isCacheDirty()) {
@@ -15410,6 +15443,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
15410
15443
  */
15411
15444
  _removeCacheCanvas: function() {
15412
15445
  this._cacheCanvas = null;
15446
+ this._cacheContext = null;
15413
15447
  this.cacheWidth = 0;
15414
15448
  this.cacheHeight = 0;
15415
15449
  },
@@ -15568,7 +15602,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
15568
15602
  if (this.isNotVisible()) {
15569
15603
  return false;
15570
15604
  }
15571
- if (this._cacheCanvas && !skipCanvas && this._updateCacheCanvas()) {
15605
+ if (this._cacheCanvas && this._cacheContext && !skipCanvas && this._updateCacheCanvas()) {
15572
15606
  // in this case the context is already cleared.
15573
15607
  return true;
15574
15608
  }
@@ -15577,7 +15611,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
15577
15611
  (this.clipPath && this.clipPath.absolutePositioned) ||
15578
15612
  (this.statefullCache && this.hasStateChanged('cacheProperties'))
15579
15613
  ) {
15580
- if (this._cacheCanvas && !skipCanvas) {
15614
+ if (this._cacheCanvas && this._cacheContext && !skipCanvas) {
15581
15615
  var width = this.cacheWidth / this.zoomX;
15582
15616
  var height = this.cacheHeight / this.zoomY;
15583
15617
  this._cacheContext.clearRect(-width / 2, -height / 2, width, height);
@@ -16111,7 +16145,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
16111
16145
  * @return {Boolean}
16112
16146
  */
16113
16147
  isType: function(type) {
16114
- return this.type === type;
16148
+ return arguments.length > 1 ? Array.from(arguments).includes(this.type) : this.type === type;
16115
16149
  },
16116
16150
 
16117
16151
  /**
@@ -16253,6 +16287,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
16253
16287
 
16254
16288
  /**
16255
16289
  * cancel instance's running animations
16290
+ * override if necessary to dispose artifacts such as `clipPath`
16256
16291
  */
16257
16292
  dispose: function () {
16258
16293
  if (fabric.runningAnimations) {
@@ -18048,7 +18083,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
18048
18083
  return fabric.util.animate({
18049
18084
  target: this,
18050
18085
  startValue: object.left,
18051
- endValue: this.getCenter().left,
18086
+ endValue: this.getCenterPoint().x,
18052
18087
  duration: this.FX_DURATION,
18053
18088
  onChange: function(value) {
18054
18089
  object.set('left', value);
@@ -18081,7 +18116,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
18081
18116
  return fabric.util.animate({
18082
18117
  target: this,
18083
18118
  startValue: object.top,
18084
- endValue: this.getCenter().top,
18119
+ endValue: this.getCenterPoint().y,
18085
18120
  duration: this.FX_DURATION,
18086
18121
  onChange: function(value) {
18087
18122
  object.set('top', value);
@@ -19620,7 +19655,6 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19620
19655
  max = fabric.util.array.max,
19621
19656
  extend = fabric.util.object.extend,
19622
19657
  clone = fabric.util.object.clone,
19623
- _toString = Object.prototype.toString,
19624
19658
  toFixed = fabric.util.toFixed;
19625
19659
 
19626
19660
  if (fabric.Path) {
@@ -19674,10 +19708,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
19674
19708
  * @param {Object} [options] Options object
19675
19709
  */
19676
19710
  _setPath: function (path, options) {
19677
- var fromArray = _toString.call(path) === '[object Array]';
19678
-
19679
19711
  this.path = fabric.util.makePathSimpler(
19680
- fromArray ? path : fabric.util.parsePath(path)
19712
+ Array.isArray(path) ? path : fabric.util.parsePath(path)
19681
19713
  );
19682
19714
 
19683
19715
  fabric.Polyline.prototype._setPositionDimensions.call(this, options || {});
@@ -22481,8 +22513,10 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
22481
22513
  mainParameter: 'matrix',
22482
22514
 
22483
22515
  /**
22484
- * Lock the colormatrix on the color part, skipping alpha, manly for non webgl scenario
22516
+ * Lock the colormatrix on the color part, skipping alpha, mainly for non webgl scenario
22485
22517
  * to save some calculation
22518
+ * @type Boolean
22519
+ * @default true
22486
22520
  */
22487
22521
  colorsOnly: true,
22488
22522
 
@@ -23881,17 +23915,23 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
23881
23915
  /**
23882
23916
  * Color to make the blend operation with. default to a reddish color since black or white
23883
23917
  * gives always strong result.
23918
+ * @type String
23919
+ * @default
23884
23920
  **/
23885
23921
  color: '#F95C63',
23886
23922
 
23887
23923
  /**
23888
23924
  * Blend mode for the filter: one of multiply, add, diff, screen, subtract,
23889
23925
  * darken, lighten, overlay, exclusion, tint.
23926
+ * @type String
23927
+ * @default
23890
23928
  **/
23891
23929
  mode: 'multiply',
23892
23930
 
23893
23931
  /**
23894
23932
  * alpha value. represent the strength of the blend color operation.
23933
+ * @type Number
23934
+ * @default
23895
23935
  **/
23896
23936
  alpha: 1,
23897
23937
 
@@ -24132,8 +24172,9 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
24132
24172
  image: null,
24133
24173
 
24134
24174
  /**
24135
- * Blend mode for the filter: one of multiply, add, diff, screen, subtract,
24136
- * darken, lighten, overlay, exclusion, tint.
24175
+ * Blend mode for the filter (one of "multiply", "mask")
24176
+ * @type String
24177
+ * @default
24137
24178
  **/
24138
24179
  mode: 'multiply',
24139
24180
 
@@ -25269,6 +25310,8 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
25269
25310
  * blur value, in percentage of image dimensions.
25270
25311
  * specific to keep the image blur constant at different resolutions
25271
25312
  * range between 0 and 1.
25313
+ * @type Number
25314
+ * @default
25272
25315
  */
25273
25316
  blur: 0,
25274
25317