fabric 5.3.0 → 5.4.0-browser

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,30 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.4.0]
4
+
5
+ - fix() fix an issue with offScreen detection and background/overlay Vpt setting [`#8896`](https://github.com/fabricjs/fabric.js/pull/8896)
6
+ - fix() removal of shadow for uncached text with decoration
7
+ - fix() active selection control drawing order
8
+ - fix() patterns for gradient sometimes hitting 0 size
9
+ - fix() Enliving of text on a path for classes different than plain Text
10
+ - fix() Some old style shifting bugs for text
11
+
12
+ ## [5.2.1]
13
+
14
+ - fix(): add `eraser` to Object state/cache props [`#7720`](https://github.com/fabricjs/fabric.js/pull/7720)
15
+
16
+ ## [5.2.0]
17
+
18
+ - feat(fabric.Object): isType accepts multiple `type` [`#7715`](https://github.com/fabricjs/fabric.js/pull/7715)
19
+ - chore(): Replace deprecated String.prototype.substr() with Array.prototype.slice() [`#7696`](https://github.com/fabricjs/fabric.js/pull/7696)
20
+ - chore(): use Array.isArray instead of ie6+ workarounds [`#7718`](https://github.com/fabricjs/fabric.js/pull/7718)
21
+ - MINOR: feat(fabric.Canvas): add `getTopContext` method to expose the internal contextTop [`#7697`](https://github.com/fabricjs/fabric.js/pull/7697)
22
+ - fix(fabric.Object) Add cacheContext checks before trying to render on cache [`#7694`](https://github.com/fabricjs/fabric.js/pull/7694)
23
+ - tests(): node test suite enhancement [`#7691`](https://github.com/fabricjs/fabric.js/pull/7691)
24
+ - feat(Canvas#getCenter): migrate to `getCenterPoint` [`#7699`](https://github.com/fabricjs/fabric.js/pull/7699)
25
+ - updated package.json [`803ce95`](https://github.com/fabricjs/fabric.js/commit/803ce95878150fba9e4195804bccae9bcfe45c6d)
26
+ - tests(fabric.animation): fix test reliability [`4be0fb9`](https://github.com/fabricjs/fabric.js/commit/4be0fb9903e15db294b89030feb645e5da766740)
27
+
3
28
  ## [5.1.0]
4
29
 
5
30
  - build(deps): bump node-fetch from 2.6.6 to 2.6.7 [`#7684`](https://github.com/fabricjs/fabric.js/pull/7684)
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.3.0' };
3
+ var fabric = fabric || { version: '5.4.0' };
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.3.0' };
4
+ var fabric = fabric || { version: '5.4.0' };
5
5
  if (typeof exports !== 'undefined') {
6
6
  exports.fabric = fabric;
7
7
  }
@@ -9875,10 +9875,15 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
9875
9875
  }
9876
9876
  if (object) {
9877
9877
  ctx.save();
9878
+ var skipOffscreen = this.skipOffscreen;
9879
+ // if the object doesn't move with the viewport,
9880
+ // the offscreen concept does not apply;
9881
+ this.skipOffscreen = needsVpt;
9878
9882
  if (needsVpt) {
9879
9883
  ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
9880
9884
  }
9881
9885
  object.render(ctx);
9886
+ this.skipOffscreen = skipOffscreen;
9882
9887
  ctx.restore();
9883
9888
  }
9884
9889
  },
@@ -13105,8 +13110,8 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
13105
13110
 
13106
13111
  var _this = this;
13107
13112
  this._hoveredTargets.forEach(function(_target){
13108
- _this.fire('mouse:out', { target: target, e: e });
13109
- _target && target.fire('mouseout', { e: e });
13113
+ _this.fire('mouse:out', { target: _target, e: e });
13114
+ _target && _target.fire('mouseout', { e: e });
13110
13115
  });
13111
13116
  this._hoveredTargets = [];
13112
13117
  },
@@ -16018,8 +16023,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
16018
16023
  var dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
16019
16024
  pCanvas = fabric.util.createCanvasElement(), pCtx, retinaScaling = this.canvas.getRetinaScaling(),
16020
16025
  width = dims.x / this.scaleX / retinaScaling, height = dims.y / this.scaleY / retinaScaling;
16021
- pCanvas.width = width;
16022
- pCanvas.height = height;
16026
+ pCanvas.width = Math.ceil(width);
16027
+ pCanvas.height = Math.ceil(height);
16023
16028
  pCtx = pCanvas.getContext('2d');
16024
16029
  pCtx.beginPath(); pCtx.moveTo(0, 0); pCtx.lineTo(width, 0); pCtx.lineTo(width, height);
16025
16030
  pCtx.lineTo(0, height); pCtx.closePath();
@@ -18055,7 +18060,10 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
18055
18060
  drawControls: function(ctx, styleOverride) {
18056
18061
  styleOverride = styleOverride || {};
18057
18062
  ctx.save();
18058
- var retinaScaling = this.canvas.getRetinaScaling(), matrix, p;
18063
+ var retinaScaling = 1, matrix, p;
18064
+ if (this.canvas) {
18065
+ retinaScaling = this.canvas.getRetinaScaling();
18066
+ }
18059
18067
  ctx.setTransform(retinaScaling, 0, 0, retinaScaling, 0, 0);
18060
18068
  ctx.strokeStyle = ctx.fillStyle = styleOverride.cornerColor || this.cornerColor;
18061
18069
  if (!this.transparentCorners) {
@@ -20857,7 +20865,6 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
20857
20865
  _renderControls: function(ctx, styleOverride, childrenOverride) {
20858
20866
  ctx.save();
20859
20867
  ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
20860
- this.callSuper('_renderControls', ctx, styleOverride);
20861
20868
  childrenOverride = childrenOverride || { };
20862
20869
  if (typeof childrenOverride.hasControls === 'undefined') {
20863
20870
  childrenOverride.hasControls = false;
@@ -20866,6 +20873,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
20866
20873
  for (var i = 0, len = this._objects.length; i < len; i++) {
20867
20874
  this._objects[i]._renderControls(ctx, childrenOverride);
20868
20875
  }
20876
+ this.callSuper('_renderControls', ctx, styleOverride);
20869
20877
  ctx.restore();
20870
20878
  },
20871
20879
  });
@@ -27249,6 +27257,11 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
27249
27257
  if (!this[type] && !this.styleHas(type)) {
27250
27258
  return;
27251
27259
  }
27260
+ ctx.save();
27261
+ // if type is overline or linethrough we shouldn't cast shadow
27262
+ if (type === 'overline' || type === 'linethrough') {
27263
+ this._removeShadow(ctx);
27264
+ }
27252
27265
  var heightOfLine, size, _size,
27253
27266
  lineLeftOffset, dy, _dy,
27254
27267
  line, lastDecoration,
@@ -27335,9 +27348,7 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
27335
27348
  );
27336
27349
  topOffset += heightOfLine;
27337
27350
  }
27338
- // if there is text background color no
27339
- // other shadows should be casted
27340
- this._removeShadow(ctx);
27351
+ ctx.restore();
27341
27352
  },
27342
27353
 
27343
27354
  /**
@@ -27771,7 +27782,7 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
27771
27782
  charIndex: selectionStart
27772
27783
  };
27773
27784
  }
27774
- selectionStart -= lines[i].length + this.missingNewlineOffset(i);
27785
+ selectionStart -= lines[i].length + this.missingNewlineOffset(i, skipWrapping);
27775
27786
  }
27776
27787
  return {
27777
27788
  lineIndex: i - 1,
@@ -28433,6 +28444,7 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
28433
28444
  var styles = fabric.util.stylesFromArray(object.styles, object.text);
28434
28445
  //copy object to prevent mutation
28435
28446
  var objCopy = Object.assign({}, object, { styles: styles });
28447
+ delete objCopy.path;
28436
28448
  parseDecoration(objCopy);
28437
28449
  if (objCopy.styles) {
28438
28450
  for (var i in objCopy.styles) {
@@ -28441,7 +28453,17 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
28441
28453
  }
28442
28454
  }
28443
28455
  }
28444
- fabric.Object._fromObject('IText', objCopy, callback, 'text');
28456
+ fabric.Object._fromObject('IText', objCopy, function(textInstance) {
28457
+ if (object.path) {
28458
+ fabric.Object._fromObject('Path', object.path, function(pathInstance) {
28459
+ textInstance.set('path', pathInstance);
28460
+ callback(textInstance);
28461
+ }, 'path');
28462
+ }
28463
+ else {
28464
+ callback(textInstance);
28465
+ }
28466
+ }, 'text');
28445
28467
  };
28446
28468
  })();
28447
28469
 
@@ -29188,8 +29210,9 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
29188
29210
  insertNewlineStyleObject: function(lineIndex, charIndex, qty, copiedStyle) {
29189
29211
  var currentCharStyle,
29190
29212
  newLineStyles = {},
29191
- somethingAdded = false,
29192
- isEndOfLine = this._unwrappedTextLines[lineIndex].length === charIndex;
29213
+ someStyleIsCarryingOver = false,
29214
+ originalLineLength = this._unwrappedTextLines[lineIndex].length,
29215
+ isEndOfLine = originalLineLength === charIndex;
29193
29216
 
29194
29217
  qty || (qty = 1);
29195
29218
  this.shiftLineStyles(lineIndex, qty);
@@ -29201,7 +29224,7 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
29201
29224
  for (var index in this.styles[lineIndex]) {
29202
29225
  var numIndex = parseInt(index, 10);
29203
29226
  if (numIndex >= charIndex) {
29204
- somethingAdded = true;
29227
+ someStyleIsCarryingOver = true;
29205
29228
  newLineStyles[numIndex - charIndex] = this.styles[lineIndex][index];
29206
29229
  // remove lines from the previous line since they're on a new line now
29207
29230
  if (!(isEndOfLine && charIndex === 0)) {
@@ -29210,14 +29233,16 @@ fabric.Image.filters.BaseFilter.fromObject = function(object, callback) {
29210
29233
  }
29211
29234
  }
29212
29235
  var styleCarriedOver = false;
29213
- if (somethingAdded && !isEndOfLine) {
29236
+ if (someStyleIsCarryingOver && !isEndOfLine) {
29214
29237
  // if is end of line, the extra style we copied
29215
29238
  // is probably not something we want
29216
29239
  this.styles[lineIndex + qty] = newLineStyles;
29217
29240
  styleCarriedOver = true;
29218
29241
  }
29219
- if (styleCarriedOver) {
29220
- // skip the last line of since we already prepared it.
29242
+ if (styleCarriedOver || originalLineLength > charIndex) {
29243
+ // skip the last line of since we already prepared it
29244
+ // or contains text without style that we don't want to style
29245
+ // just because it changed lines
29221
29246
  qty--;
29222
29247
  }
29223
29248
  // for the all the lines or all the other lines
@@ -30997,10 +31022,12 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
30997
31022
  /**
30998
31023
  * Detect if a line has a linebreak and so we need to account for it when moving
30999
31024
  * and counting style.
31025
+ * This is important only for splitByGrapheme at the end of wrapping.
31026
+ * If we are not wrapping the offset is always 1
31000
31027
  * @return Number
31001
31028
  */
31002
- missingNewlineOffset: function(lineIndex) {
31003
- if (this.splitByGrapheme) {
31029
+ missingNewlineOffset: function(lineIndex, skipWrapping) {
31030
+ if (this.splitByGrapheme && !skipWrapping) {
31004
31031
  return this.isEndOfWrapping(lineIndex) ? 1 : 0;
31005
31032
  }
31006
31033
  return 1;
@@ -31065,7 +31092,18 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
31065
31092
  var styles = fabric.util.stylesFromArray(object.styles, object.text);
31066
31093
  //copy object to prevent mutation
31067
31094
  var objCopy = Object.assign({}, object, { styles: styles });
31068
- return fabric.Object._fromObject('Textbox', objCopy, callback, 'text');
31095
+ delete objCopy.path;
31096
+ return fabric.Object._fromObject('Textbox', objCopy, function(textInstance) {
31097
+ if (object.path) {
31098
+ fabric.Object._fromObject('Path', object.path, function(pathInstance) {
31099
+ textInstance.set('path', pathInstance);
31100
+ callback(textInstance);
31101
+ }, 'path');
31102
+ }
31103
+ else {
31104
+ callback(textInstance);
31105
+ }
31106
+ }, 'text');
31069
31107
  };
31070
31108
  })(typeof exports !== 'undefined' ? exports : this);
31071
31109