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/package.json CHANGED
@@ -1,92 +1,89 @@
1
1
  {
2
- "name": "fabric",
3
- "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
4
- "homepage": "http://fabricjs.com/",
5
- "version": "5.3.0",
6
- "author": "Juriy Zaytsev <kangax@gmail.com>",
7
- "contributors": [
8
- {
9
- "name": "Andrea Bogazzi",
10
- "email": "andreabogazzi79@gmail.com"
11
- },
12
- {
13
- "name": "Steve Eberhardt",
14
- "email": "melchiar2@gmail.com"
15
- }
16
- ],
17
- "keywords": [
18
- "canvas",
19
- "graphic",
20
- "graphics",
21
- "SVG",
22
- "node-canvas",
23
- "parser",
24
- "HTML5",
25
- "object model"
26
- ],
27
- "browser": {
28
- "canvas": false,
29
- "fs": false,
30
- "jsdom": false,
31
- "jsdom/lib/jsdom/living/generated/utils": false,
32
- "jsdom/lib/jsdom/utils": false,
33
- "http": false,
34
- "https": false,
35
- "xmldom": false,
36
- "url": false
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "https://github.com/fabricjs/fabric.js"
41
- },
42
- "bugs": {
43
- "url": "https://github.com/fabricjs/fabric.js/issues"
44
- },
45
- "license": "MIT",
46
- "scripts": {
47
- "changelog": "auto-changelog -o change-output.md --unreleased-only",
48
- "build": "node build.js modules=ALL requirejs exclude=gestures,accessors,erasing",
49
- "build:fast": "node build.js modules=ALL requirejs fast exclude=gestures,accessors,erasing",
50
- "build:watch": "onchange 'src/**/**' 'HEADER.js' 'lib/**/**' -- npm run build_export",
51
- "link:watch": "onchange 'src/**/**' 'HEADER.js' 'lib/**/**' -- npm link",
52
- "build_with_gestures": "node build.js modules=ALL exclude=accessors",
53
- "build_export": "npm run build:fast && npm run export_dist_to_site",
54
- "test:single": "qunit test/node_test_setup.js test/lib",
55
- "test:coverage": "nyc --silent qunit test/node_test_setup.js test/lib test/unit",
56
- "test:visual:coverage": "nyc --silent --no-clean qunit test/node_test_setup.js test/lib test/visual",
57
- "coverage:report": "nyc report --reporter=lcov --reporter=text",
58
- "test": "qunit --require ./test/node_test_setup.js test/lib test/unit",
59
- "test:visual": "qunit test/node_test_setup.js test/lib test/visual",
60
- "test:visual:single": "qunit test/node_test_setup.js test/lib",
61
- "test:all": "npm run test && npm run test:visual",
62
- "lint": "eslint --config .eslintrc.json src",
63
- "lint_tests": "eslint test/unit --config .eslintrc_tests && eslint test/visual --config .eslintrc_tests",
64
- "export_gesture_to_site": "cp dist/fabric.js ../fabricjs.com/lib/fabric_with_gestures.js",
65
- "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/",
66
- "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",
67
- "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",
68
- "testem": "testem .",
69
- "testem:ci": "testem ci"
70
- },
71
- "optionalDependencies": {
72
- "canvas": "^2.8.0",
73
- "jsdom": "^19.0.0"
74
- },
75
- "devDependencies": {
76
- "auto-changelog": "^2.3.0",
77
- "chalk": "^2.4.1",
78
- "deep-object-diff": "^1.1.7",
79
- "eslint": "4.18.x",
80
- "nyc": "^15.1.0",
81
- "onchange": "^7.1.0",
82
- "pixelmatch": "^4.0.2",
83
- "qunit": "^2.17.2",
84
- "testem": "^3.2.0",
85
- "uglify-js": "3.3.x"
86
- },
87
- "engines": {
88
- "node": ">=14.0.0"
89
- },
90
- "main": "./dist/fabric.js",
91
- "dependencies": {}
92
- }
2
+ "name": "fabric",
3
+ "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
4
+ "homepage": "http://fabricjs.com/",
5
+ "version": "5.4.0-browser",
6
+ "author": "Juriy Zaytsev <kangax@gmail.com>",
7
+ "contributors": [
8
+ {
9
+ "name": "Andrea Bogazzi",
10
+ "email": "andreabogazzi79@gmail.com"
11
+ },
12
+ {
13
+ "name": "Steve Eberhardt",
14
+ "email": "melchiar2@gmail.com"
15
+ }
16
+ ],
17
+ "keywords": [
18
+ "canvas",
19
+ "graphic",
20
+ "graphics",
21
+ "SVG",
22
+ "node-canvas",
23
+ "parser",
24
+ "HTML5",
25
+ "object model"
26
+ ],
27
+ "browser": {
28
+ "canvas": false,
29
+ "fs": false,
30
+ "jsdom": false,
31
+ "jsdom/lib/jsdom/living/generated/utils": false,
32
+ "jsdom/lib/jsdom/utils": false,
33
+ "http": false,
34
+ "https": false,
35
+ "xmldom": false,
36
+ "url": false
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/fabricjs/fabric.js"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/fabricjs/fabric.js/issues"
44
+ },
45
+ "license": "MIT",
46
+ "scripts": {
47
+ "changelog": "auto-changelog -o change-output.md --unreleased-only",
48
+ "build": "node build.js modules=ALL requirejs exclude=gestures,accessors,erasing",
49
+ "build:fast": "node build.js modules=ALL requirejs fast exclude=gestures,accessors,erasing",
50
+ "build:watch": "onchange 'src/**/**' 'HEADER.js' 'lib/**/**' -- npm run build_export",
51
+ "link:watch": "onchange 'src/**/**' 'HEADER.js' 'lib/**/**' -- npm link",
52
+ "build_with_gestures": "node build.js modules=ALL exclude=accessors",
53
+ "build_export": "npm run build:fast && npm run export_dist_to_site",
54
+ "test:single": "qunit test/node_test_setup.js test/lib",
55
+ "test:coverage": "nyc --silent qunit test/node_test_setup.js test/lib test/unit",
56
+ "test:visual:coverage": "nyc --silent --no-clean qunit test/node_test_setup.js test/lib test/visual",
57
+ "coverage:report": "nyc report --reporter=lcov --reporter=text",
58
+ "test": "qunit --require ./test/node_test_setup.js test/lib test/unit",
59
+ "test:visual": "qunit test/node_test_setup.js test/lib test/visual",
60
+ "test:visual:single": "qunit test/node_test_setup.js test/lib",
61
+ "test:all": "npm run test && npm run test:visual",
62
+ "lint": "eslint --config .eslintrc.json src",
63
+ "lint_tests": "eslint test/unit --config .eslintrc_tests && eslint test/visual --config .eslintrc_tests",
64
+ "export_gesture_to_site": "cp dist/fabric.js ../fabricjs.com/lib/fabric_with_gestures.js",
65
+ "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/",
66
+ "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",
67
+ "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",
68
+ "testem": "testem .",
69
+ "testem:ci": "testem ci"
70
+ },
71
+ "optionalDependencies": {},
72
+ "devDependencies": {
73
+ "auto-changelog": "^2.3.0",
74
+ "chalk": "^2.4.1",
75
+ "deep-object-diff": "^1.1.7",
76
+ "eslint": "4.18.x",
77
+ "nyc": "^15.1.0",
78
+ "onchange": "^7.1.0",
79
+ "pixelmatch": "^4.0.2",
80
+ "qunit": "^2.17.2",
81
+ "testem": "^3.2.0",
82
+ "uglify-js": "3.3.x"
83
+ },
84
+ "engines": {
85
+ "node": ">=14.0.0"
86
+ },
87
+ "main": "./dist/fabric.js",
88
+ "dependencies": {}
89
+ }
@@ -148,8 +148,8 @@
148
148
 
149
149
  var _this = this;
150
150
  this._hoveredTargets.forEach(function(_target){
151
- _this.fire('mouse:out', { target: target, e: e });
152
- _target && target.fire('mouseout', { e: e });
151
+ _this.fire('mouse:out', { target: _target, e: e });
152
+ _target && _target.fire('mouseout', { e: e });
153
153
  });
154
154
  this._hoveredTargets = [];
155
155
  },
@@ -740,8 +740,9 @@
740
740
  insertNewlineStyleObject: function(lineIndex, charIndex, qty, copiedStyle) {
741
741
  var currentCharStyle,
742
742
  newLineStyles = {},
743
- somethingAdded = false,
744
- isEndOfLine = this._unwrappedTextLines[lineIndex].length === charIndex;
743
+ someStyleIsCarryingOver = false,
744
+ originalLineLength = this._unwrappedTextLines[lineIndex].length,
745
+ isEndOfLine = originalLineLength === charIndex;
745
746
 
746
747
  qty || (qty = 1);
747
748
  this.shiftLineStyles(lineIndex, qty);
@@ -753,7 +754,7 @@
753
754
  for (var index in this.styles[lineIndex]) {
754
755
  var numIndex = parseInt(index, 10);
755
756
  if (numIndex >= charIndex) {
756
- somethingAdded = true;
757
+ someStyleIsCarryingOver = true;
757
758
  newLineStyles[numIndex - charIndex] = this.styles[lineIndex][index];
758
759
  // remove lines from the previous line since they're on a new line now
759
760
  if (!(isEndOfLine && charIndex === 0)) {
@@ -762,14 +763,16 @@
762
763
  }
763
764
  }
764
765
  var styleCarriedOver = false;
765
- if (somethingAdded && !isEndOfLine) {
766
+ if (someStyleIsCarryingOver && !isEndOfLine) {
766
767
  // if is end of line, the extra style we copied
767
768
  // is probably not something we want
768
769
  this.styles[lineIndex + qty] = newLineStyles;
769
770
  styleCarriedOver = true;
770
771
  }
771
- if (styleCarriedOver) {
772
- // skip the last line of since we already prepared it.
772
+ if (styleCarriedOver || originalLineLength > charIndex) {
773
+ // skip the last line of since we already prepared it
774
+ // or contains text without style that we don't want to style
775
+ // just because it changed lines
773
776
  qty--;
774
777
  }
775
778
  // for the all the lines or all the other lines
@@ -211,7 +211,10 @@
211
211
  drawControls: function(ctx, styleOverride) {
212
212
  styleOverride = styleOverride || {};
213
213
  ctx.save();
214
- var retinaScaling = this.canvas.getRetinaScaling(), matrix, p;
214
+ var retinaScaling = 1, matrix, p;
215
+ if (this.canvas) {
216
+ retinaScaling = this.canvas.getRetinaScaling();
217
+ }
215
218
  ctx.setTransform(retinaScaling, 0, 0, retinaScaling, 0, 0);
216
219
  ctx.strokeStyle = ctx.fillStyle = styleOverride.cornerColor || this.cornerColor;
217
220
  if (!this.transparentCorners) {
@@ -177,7 +177,7 @@
177
177
  charIndex: selectionStart
178
178
  };
179
179
  }
180
- selectionStart -= lines[i].length + this.missingNewlineOffset(i);
180
+ selectionStart -= lines[i].length + this.missingNewlineOffset(i, skipWrapping);
181
181
  }
182
182
  return {
183
183
  lineIndex: i - 1,
@@ -125,7 +125,6 @@
125
125
  _renderControls: function(ctx, styleOverride, childrenOverride) {
126
126
  ctx.save();
127
127
  ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
128
- this.callSuper('_renderControls', ctx, styleOverride);
129
128
  childrenOverride = childrenOverride || { };
130
129
  if (typeof childrenOverride.hasControls === 'undefined') {
131
130
  childrenOverride.hasControls = false;
@@ -134,6 +133,7 @@
134
133
  for (var i = 0, len = this._objects.length; i < len; i++) {
135
134
  this._objects[i]._renderControls(ctx, childrenOverride);
136
135
  }
136
+ this.callSuper('_renderControls', ctx, styleOverride);
137
137
  ctx.restore();
138
138
  },
139
139
  });
@@ -513,6 +513,7 @@
513
513
  var styles = fabric.util.stylesFromArray(object.styles, object.text);
514
514
  //copy object to prevent mutation
515
515
  var objCopy = Object.assign({}, object, { styles: styles });
516
+ delete objCopy.path;
516
517
  parseDecoration(objCopy);
517
518
  if (objCopy.styles) {
518
519
  for (var i in objCopy.styles) {
@@ -521,6 +522,16 @@
521
522
  }
522
523
  }
523
524
  }
524
- fabric.Object._fromObject('IText', objCopy, callback, 'text');
525
+ fabric.Object._fromObject('IText', objCopy, function(textInstance) {
526
+ if (object.path) {
527
+ fabric.Object._fromObject('Path', object.path, function(pathInstance) {
528
+ textInstance.set('path', pathInstance);
529
+ callback(textInstance);
530
+ }, 'path');
531
+ }
532
+ else {
533
+ callback(textInstance);
534
+ }
535
+ }, 'text');
525
536
  };
526
537
  })();
@@ -1577,8 +1577,8 @@
1577
1577
  var dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
1578
1578
  pCanvas = fabric.util.createCanvasElement(), pCtx, retinaScaling = this.canvas.getRetinaScaling(),
1579
1579
  width = dims.x / this.scaleX / retinaScaling, height = dims.y / this.scaleY / retinaScaling;
1580
- pCanvas.width = width;
1581
- pCanvas.height = height;
1580
+ pCanvas.width = Math.ceil(width);
1581
+ pCanvas.height = Math.ceil(height);
1582
1582
  pCtx = pCanvas.getContext('2d');
1583
1583
  pCtx.beginPath(); pCtx.moveTo(0, 0); pCtx.lineTo(width, 0); pCtx.lineTo(width, height);
1584
1584
  pCtx.lineTo(0, height); pCtx.closePath();
@@ -1353,6 +1353,11 @@
1353
1353
  if (!this[type] && !this.styleHas(type)) {
1354
1354
  return;
1355
1355
  }
1356
+ ctx.save();
1357
+ // if type is overline or linethrough we shouldn't cast shadow
1358
+ if (type === 'overline' || type === 'linethrough') {
1359
+ this._removeShadow(ctx);
1360
+ }
1356
1361
  var heightOfLine, size, _size,
1357
1362
  lineLeftOffset, dy, _dy,
1358
1363
  line, lastDecoration,
@@ -1439,9 +1444,7 @@
1439
1444
  );
1440
1445
  topOffset += heightOfLine;
1441
1446
  }
1442
- // if there is text background color no
1443
- // other shadows should be casted
1444
- this._removeShadow(ctx);
1447
+ ctx.restore();
1445
1448
  },
1446
1449
 
1447
1450
  /**
@@ -388,10 +388,12 @@
388
388
  /**
389
389
  * Detect if a line has a linebreak and so we need to account for it when moving
390
390
  * and counting style.
391
+ * This is important only for splitByGrapheme at the end of wrapping.
392
+ * If we are not wrapping the offset is always 1
391
393
  * @return Number
392
394
  */
393
- missingNewlineOffset: function(lineIndex) {
394
- if (this.splitByGrapheme) {
395
+ missingNewlineOffset: function(lineIndex, skipWrapping) {
396
+ if (this.splitByGrapheme && !skipWrapping) {
395
397
  return this.isEndOfWrapping(lineIndex) ? 1 : 0;
396
398
  }
397
399
  return 1;
@@ -456,6 +458,17 @@
456
458
  var styles = fabric.util.stylesFromArray(object.styles, object.text);
457
459
  //copy object to prevent mutation
458
460
  var objCopy = Object.assign({}, object, { styles: styles });
459
- return fabric.Object._fromObject('Textbox', objCopy, callback, 'text');
461
+ delete objCopy.path;
462
+ return fabric.Object._fromObject('Textbox', objCopy, function(textInstance) {
463
+ if (object.path) {
464
+ fabric.Object._fromObject('Path', object.path, function(pathInstance) {
465
+ textInstance.set('path', pathInstance);
466
+ callback(textInstance);
467
+ }, 'path');
468
+ }
469
+ else {
470
+ callback(textInstance);
471
+ }
472
+ }, 'text');
460
473
  };
461
474
  })(typeof exports !== 'undefined' ? exports : this);
@@ -999,10 +999,15 @@
999
999
  }
1000
1000
  if (object) {
1001
1001
  ctx.save();
1002
+ var skipOffscreen = this.skipOffscreen;
1003
+ // if the object doesn't move with the viewport,
1004
+ // the offscreen concept does not apply;
1005
+ this.skipOffscreen = needsVpt;
1002
1006
  if (needsVpt) {
1003
1007
  ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
1004
1008
  }
1005
1009
  object.render(ctx);
1010
+ this.skipOffscreen = skipOffscreen;
1006
1011
  ctx.restore();
1007
1012
  }
1008
1013
  },