@nasser-sw/fabric 7.0.1-beta3 → 7.0.1-beta4

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.
Files changed (105) hide show
  1. package/0 +0 -0
  2. package/dist/index.js +323 -155
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/index.min.mjs +1 -1
  7. package/dist/index.min.mjs.map +1 -1
  8. package/dist/index.mjs +323 -155
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.node.cjs +323 -155
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.mjs +323 -155
  13. package/dist/index.node.mjs.map +1 -1
  14. package/dist/package.json.min.mjs +1 -1
  15. package/dist/package.json.mjs +1 -1
  16. package/dist/src/shapes/Line.d.ts +31 -86
  17. package/dist/src/shapes/Line.d.ts.map +1 -1
  18. package/dist/src/shapes/Line.min.mjs +1 -1
  19. package/dist/src/shapes/Line.min.mjs.map +1 -1
  20. package/dist/src/shapes/Line.mjs +323 -154
  21. package/dist/src/shapes/Line.mjs.map +1 -1
  22. package/dist-extensions/src/shapes/CustomLine.d.ts +10 -0
  23. package/dist-extensions/src/shapes/CustomLine.d.ts.map +1 -0
  24. package/dist-extensions/src/shapes/Line.d.ts +31 -86
  25. package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
  26. package/fabric-test-editor.html +157 -8
  27. package/fabric-test2.html +513 -0
  28. package/fabric.ts +182 -182
  29. package/package.json +1 -1
  30. package/src/shapes/Line.ts +372 -158
  31. package/debug/konva/CHANGELOG.md +0 -1474
  32. package/debug/konva/LICENSE +0 -22
  33. package/debug/konva/README.md +0 -205
  34. package/debug/konva/gulpfile.mjs +0 -110
  35. package/debug/konva/package.json +0 -139
  36. package/debug/konva/release.sh +0 -65
  37. package/debug/konva/resources/doc-includes/ContainerParams.txt +0 -6
  38. package/debug/konva/resources/doc-includes/NodeParams.txt +0 -20
  39. package/debug/konva/resources/doc-includes/ShapeParams.txt +0 -53
  40. package/debug/konva/resources/jsdoc.conf.json +0 -28
  41. package/debug/konva/rollup.config.mjs +0 -32
  42. package/debug/konva/src/Animation.ts +0 -237
  43. package/debug/konva/src/BezierFunctions.ts +0 -826
  44. package/debug/konva/src/Canvas.ts +0 -193
  45. package/debug/konva/src/Container.ts +0 -649
  46. package/debug/konva/src/Context.ts +0 -1017
  47. package/debug/konva/src/Core.ts +0 -5
  48. package/debug/konva/src/DragAndDrop.ts +0 -173
  49. package/debug/konva/src/Factory.ts +0 -246
  50. package/debug/konva/src/FastLayer.ts +0 -29
  51. package/debug/konva/src/Global.ts +0 -210
  52. package/debug/konva/src/Group.ts +0 -31
  53. package/debug/konva/src/Layer.ts +0 -546
  54. package/debug/konva/src/Node.ts +0 -3477
  55. package/debug/konva/src/PointerEvents.ts +0 -67
  56. package/debug/konva/src/Shape.ts +0 -2081
  57. package/debug/konva/src/Stage.ts +0 -1000
  58. package/debug/konva/src/Tween.ts +0 -811
  59. package/debug/konva/src/Util.ts +0 -1123
  60. package/debug/konva/src/Validators.ts +0 -210
  61. package/debug/konva/src/_CoreInternals.ts +0 -85
  62. package/debug/konva/src/_FullInternals.ts +0 -171
  63. package/debug/konva/src/canvas-backend.ts +0 -36
  64. package/debug/konva/src/filters/Blur.ts +0 -388
  65. package/debug/konva/src/filters/Brighten.ts +0 -48
  66. package/debug/konva/src/filters/Brightness.ts +0 -30
  67. package/debug/konva/src/filters/Contrast.ts +0 -75
  68. package/debug/konva/src/filters/Emboss.ts +0 -207
  69. package/debug/konva/src/filters/Enhance.ts +0 -154
  70. package/debug/konva/src/filters/Grayscale.ts +0 -25
  71. package/debug/konva/src/filters/HSL.ts +0 -108
  72. package/debug/konva/src/filters/HSV.ts +0 -106
  73. package/debug/konva/src/filters/Invert.ts +0 -23
  74. package/debug/konva/src/filters/Kaleidoscope.ts +0 -274
  75. package/debug/konva/src/filters/Mask.ts +0 -220
  76. package/debug/konva/src/filters/Noise.ts +0 -44
  77. package/debug/konva/src/filters/Pixelate.ts +0 -107
  78. package/debug/konva/src/filters/Posterize.ts +0 -46
  79. package/debug/konva/src/filters/RGB.ts +0 -82
  80. package/debug/konva/src/filters/RGBA.ts +0 -103
  81. package/debug/konva/src/filters/Sepia.ts +0 -27
  82. package/debug/konva/src/filters/Solarize.ts +0 -29
  83. package/debug/konva/src/filters/Threshold.ts +0 -44
  84. package/debug/konva/src/index.ts +0 -3
  85. package/debug/konva/src/shapes/Arc.ts +0 -176
  86. package/debug/konva/src/shapes/Arrow.ts +0 -231
  87. package/debug/konva/src/shapes/Circle.ts +0 -76
  88. package/debug/konva/src/shapes/Ellipse.ts +0 -121
  89. package/debug/konva/src/shapes/Image.ts +0 -319
  90. package/debug/konva/src/shapes/Label.ts +0 -386
  91. package/debug/konva/src/shapes/Line.ts +0 -364
  92. package/debug/konva/src/shapes/Path.ts +0 -1013
  93. package/debug/konva/src/shapes/Rect.ts +0 -79
  94. package/debug/konva/src/shapes/RegularPolygon.ts +0 -167
  95. package/debug/konva/src/shapes/Ring.ts +0 -94
  96. package/debug/konva/src/shapes/Sprite.ts +0 -370
  97. package/debug/konva/src/shapes/Star.ts +0 -125
  98. package/debug/konva/src/shapes/Text.ts +0 -1065
  99. package/debug/konva/src/shapes/TextPath.ts +0 -583
  100. package/debug/konva/src/shapes/Transformer.ts +0 -1889
  101. package/debug/konva/src/shapes/Wedge.ts +0 -129
  102. package/debug/konva/src/skia-backend.ts +0 -35
  103. package/debug/konva/src/types.ts +0 -84
  104. package/debug/konva/tsconfig.json +0 -31
  105. package/debug/konva/tsconfig.test.json +0 -7
@@ -410,7 +410,7 @@ class Cache {
410
410
  }
411
411
  const cache = new Cache();
412
412
 
413
- var version = "7.0.1-beta2";
413
+ var version = "7.0.1-beta3";
414
414
 
415
415
  // use this syntax so babel plugin see this import here
416
416
  const VERSION = version;
@@ -17627,33 +17627,29 @@ class PatternBrush extends PencilBrush {
17627
17627
  }
17628
17628
  }
17629
17629
 
17630
- // @TODO this code is terrible and Line should be a special case of polyline.
17631
-
17632
17630
  const coordProps = ['x1', 'x2', 'y1', 'y2'];
17633
- /**
17634
- * A Class to draw a line
17635
- * A bunch of methods will be added to Polyline to handle the line case
17636
- * The line class is very strange to work with, is all special, it hardly aligns
17637
- * to what a developer want everytime there is an angle
17638
- * @deprecated
17639
- */
17640
17631
  class Line extends FabricObject {
17641
- /**
17642
- * Constructor
17643
- * @param {Array} [points] Array of points
17644
- * @param {Object} [options] Options object
17645
- * @return {Line} thisArg
17646
- */
17647
17632
  constructor() {
17648
- let [x1, y1, x2, y2] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0, 0];
17633
+ let [x1, y1, x2, y2] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 100, 0];
17649
17634
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17650
17635
  super();
17651
- Object.assign(this, Line.ownDefaults);
17636
+ _defineProperty(this, "hitStrokeWidth", 'auto');
17637
+ _defineProperty(this, "_updatingEndpoints", false);
17638
+ _defineProperty(this, "_useEndpointCoords", true);
17652
17639
  this.setOptions(options);
17653
17640
  this.x1 = x1;
17654
17641
  this.x2 = x2;
17655
17642
  this.y1 = y1;
17656
17643
  this.y2 = y2;
17644
+ if (options.hitStrokeWidth !== undefined) {
17645
+ this.hitStrokeWidth = options.hitStrokeWidth;
17646
+ }
17647
+ this.hasBorders = false;
17648
+ this.hasControls = true;
17649
+ this.selectable = true;
17650
+ this.hoverCursor = 'move';
17651
+ this.perPixelTargetFind = false;
17652
+ this.strokeLineCap = 'butt';
17657
17653
  this._setWidthHeight();
17658
17654
  const {
17659
17655
  left,
@@ -17661,96 +17657,323 @@ class Line extends FabricObject {
17661
17657
  } = options;
17662
17658
  typeof left === 'number' && this.set(LEFT, left);
17663
17659
  typeof top === 'number' && this.set(TOP, top);
17660
+ this._setupLineControls();
17661
+ }
17662
+ _setupLineControls() {
17663
+ this.controls = {
17664
+ p1: new Control({
17665
+ x: 0,
17666
+ y: 0,
17667
+ cursorStyle: 'move',
17668
+ actionHandler: this._endpointActionHandler.bind(this),
17669
+ positionHandler: this._p1PositionHandler.bind(this),
17670
+ render: this._renderEndpointControl.bind(this),
17671
+ sizeX: 12,
17672
+ sizeY: 12
17673
+ }),
17674
+ p2: new Control({
17675
+ x: 0,
17676
+ y: 0,
17677
+ cursorStyle: 'move',
17678
+ actionHandler: this._endpointActionHandler.bind(this),
17679
+ positionHandler: this._p2PositionHandler.bind(this),
17680
+ render: this._renderEndpointControl.bind(this),
17681
+ sizeX: 12,
17682
+ sizeY: 12
17683
+ })
17684
+ };
17685
+ }
17686
+ _p1PositionHandler() {
17687
+ var _this$canvas;
17688
+ const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17689
+ return new Point(this.x1, this.y1).transform(vpt);
17690
+ }
17691
+ _p2PositionHandler() {
17692
+ var _this$canvas2;
17693
+ const vpt = ((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.viewportTransform) || [1, 0, 0, 1, 0, 0];
17694
+ return new Point(this.x2, this.y2).transform(vpt);
17695
+ }
17696
+ _renderEndpointControl(ctx, left, top) {
17697
+ const size = 12;
17698
+ ctx.save();
17699
+ ctx.fillStyle = '#007bff';
17700
+ ctx.strokeStyle = '#ffffff';
17701
+ ctx.lineWidth = 2;
17702
+ ctx.beginPath();
17703
+ ctx.arc(left, top, size / 2, 0, 2 * Math.PI);
17704
+ ctx.fill();
17705
+ ctx.stroke();
17706
+ ctx.restore();
17707
+ }
17708
+ drawBorders(ctx) {
17709
+ let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17710
+ if (this._useEndpointCoords) {
17711
+ this._drawLineBorders(ctx, styleOverride);
17712
+ return this;
17713
+ }
17714
+ return super.drawBorders(ctx, styleOverride, {});
17715
+ }
17716
+ _drawLineBorders(ctx) {
17717
+ var _this$canvas3;
17718
+ let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17719
+ const vpt = ((_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 ? void 0 : _this$canvas3.viewportTransform) || [1, 0, 0, 1, 0, 0];
17720
+ ctx.save();
17721
+ ctx.setTransform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17722
+ ctx.strokeStyle = styleOverride.borderColor || this.borderColor || 'rgba(100, 200, 200, 0.5)';
17723
+ ctx.lineWidth = (this.strokeWidth || 1) + 5;
17724
+ ctx.lineCap = this.strokeLineCap || 'butt';
17725
+ ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
17726
+ ctx.beginPath();
17727
+ ctx.moveTo(this.x1, this.y1);
17728
+ ctx.lineTo(this.x2, this.y2);
17729
+ ctx.stroke();
17730
+ ctx.restore();
17731
+ }
17732
+ _renderControls(ctx) {
17733
+ let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17734
+ ctx.save();
17735
+ ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
17736
+ this.drawControls(ctx, styleOverride);
17737
+ ctx.restore();
17738
+ }
17739
+ getBoundingRect() {
17740
+ if (this._useEndpointCoords) {
17741
+ const {
17742
+ x1,
17743
+ y1,
17744
+ x2,
17745
+ y2
17746
+ } = this;
17747
+ const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
17748
+ const padding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
17749
+ return {
17750
+ left: Math.min(x1, x2) - padding,
17751
+ top: Math.min(y1, y2) - padding,
17752
+ width: Math.abs(x2 - x1) + padding * 2 || padding * 2,
17753
+ height: Math.abs(y2 - y1) + padding * 2 || padding * 2
17754
+ };
17755
+ }
17756
+ return super.getBoundingRect();
17757
+ }
17758
+ setCoords() {
17759
+ if (this._useEndpointCoords) {
17760
+ const minX = Math.min(this.x1, this.x2);
17761
+ const maxX = Math.max(this.x1, this.x2);
17762
+ const minY = Math.min(this.y1, this.y2);
17763
+ const maxY = Math.max(this.y1, this.y2);
17764
+ const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
17765
+ const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
17766
+ this.left = minX - hitPadding + (maxX - minX + hitPadding * 2) / 2;
17767
+ this.top = minY - hitPadding + (maxY - minY + hitPadding * 2) / 2;
17768
+ this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
17769
+ this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
17770
+ }
17771
+ super.setCoords();
17664
17772
  }
17773
+ getCoords() {
17774
+ if (this._useEndpointCoords) {
17775
+ const deltaX = this.x2 - this.x1;
17776
+ const deltaY = this.y2 - this.y1;
17777
+ const length = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
17778
+ if (length === 0) {
17779
+ return super.getCoords();
17780
+ }
17781
+ const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
17782
+ const halfWidth = Math.max(effectiveStrokeWidth / 2 + 2, 5);
17665
17783
 
17666
- /**
17667
- * @private
17668
- * @param {Object} [options] Options
17669
- */
17670
- _setWidthHeight() {
17671
- const {
17672
- x1,
17673
- y1,
17674
- x2,
17675
- y2
17676
- } = this;
17677
- this.width = Math.abs(x2 - x1);
17678
- this.height = Math.abs(y2 - y1);
17679
- const {
17680
- left,
17681
- top,
17682
- width,
17683
- height
17684
- } = makeBoundingBoxFromPoints([{
17685
- x: x1,
17686
- y: y1
17687
- }, {
17688
- x: x2,
17689
- y: y2
17690
- }]);
17691
- const position = new Point(left + width / 2, top + height / 2);
17692
- this.setPositionByOrigin(position, CENTER, CENTER);
17784
+ // Unit vector perpendicular to line
17785
+ const perpX = -deltaY / length;
17786
+ const perpY = deltaX / length;
17787
+
17788
+ // Four corners of oriented rectangle
17789
+ return [new Point(this.x1 + perpX * halfWidth, this.y1 + perpY * halfWidth), new Point(this.x2 + perpX * halfWidth, this.y2 + perpY * halfWidth), new Point(this.x2 - perpX * halfWidth, this.y2 - perpY * halfWidth), new Point(this.x1 - perpX * halfWidth, this.y1 - perpY * halfWidth)];
17790
+ }
17791
+ return super.getCoords();
17693
17792
  }
17793
+ containsPoint(point) {
17794
+ if (this._useEndpointCoords) {
17795
+ var _this$canvas4;
17796
+ if (((_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 ? void 0 : _this$canvas4.getActiveObject()) === this) {
17797
+ return super.containsPoint(point);
17798
+ }
17799
+ const distance = this._distanceToLineSegment(point.x, point.y);
17800
+ const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth || 1;
17801
+ const tolerance = Math.max(effectiveStrokeWidth / 2 + 2, 5);
17802
+ return distance <= tolerance;
17803
+ }
17804
+ return super.containsPoint(point);
17805
+ }
17806
+ _distanceToLineSegment(px, py) {
17807
+ const x1 = this.x1,
17808
+ y1 = this.y1,
17809
+ x2 = this.x2,
17810
+ y2 = this.y2;
17811
+ const pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
17812
+ if (pd2 === 0) {
17813
+ return Math.sqrt((px - x1) * (px - x1) + (py - y1) * (py - y1));
17814
+ }
17815
+ const u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / pd2;
17816
+ let closestX, closestY;
17817
+ if (u < 0) {
17818
+ closestX = x1;
17819
+ closestY = y1;
17820
+ } else if (u > 1) {
17821
+ closestX = x2;
17822
+ closestY = y2;
17823
+ } else {
17824
+ closestX = x1 + u * (x2 - x1);
17825
+ closestY = y1 + u * (y2 - y1);
17826
+ }
17827
+ return Math.sqrt((px - closestX) * (px - closestX) + (py - closestY) * (py - closestY));
17828
+ }
17829
+ _endpointActionHandler(eventData, transformData, x, y) {
17830
+ var _this$canvas6;
17831
+ const controlKey = transformData.corner;
17832
+ const pointer = new Point(x, y);
17833
+ let newX = pointer.x;
17834
+ let newY = pointer.y;
17835
+ if (eventData.shiftKey) {
17836
+ const otherControl = controlKey === 'p1' ? 'p2' : 'p1';
17837
+ const otherX = this[otherControl === 'p1' ? 'x1' : 'x2'];
17838
+ const otherY = this[otherControl === 'p1' ? 'y1' : 'y2'];
17839
+ const snapped = this._snapToAngle(otherX, otherY, newX, newY);
17840
+ newX = snapped.x;
17841
+ newY = snapped.y;
17842
+ }
17843
+ if (this._useEndpointCoords) {
17844
+ var _this$canvas5;
17845
+ if (controlKey === 'p1') {
17846
+ this.x1 = newX;
17847
+ this.y1 = newY;
17848
+ } else if (controlKey === 'p2') {
17849
+ this.x2 = newX;
17850
+ this.y2 = newY;
17851
+ }
17852
+ this.dirty = true;
17853
+ this.setCoords();
17854
+ (_this$canvas5 = this.canvas) === null || _this$canvas5 === void 0 || _this$canvas5.requestRenderAll();
17855
+ return true;
17856
+ }
17694
17857
 
17695
- /**
17696
- * @private
17697
- * @param {String} key
17698
- * @param {*} value
17699
- */
17858
+ // Fallback for old system
17859
+ this._updatingEndpoints = true;
17860
+ if (controlKey === 'p1') {
17861
+ this.x1 = newX;
17862
+ this.y1 = newY;
17863
+ } else if (controlKey === 'p2') {
17864
+ this.x2 = newX;
17865
+ this.y2 = newY;
17866
+ }
17867
+ this._setWidthHeight();
17868
+ this.dirty = true;
17869
+ this._updatingEndpoints = false;
17870
+ (_this$canvas6 = this.canvas) === null || _this$canvas6 === void 0 || _this$canvas6.requestRenderAll();
17871
+ this.fire('modified', {
17872
+ transform: transformData,
17873
+ target: this,
17874
+ e: eventData
17875
+ });
17876
+ return true;
17877
+ }
17878
+ _snapToAngle(fromX, fromY, toX, toY) {
17879
+ const deltaX = toX - fromX;
17880
+ const deltaY = toY - fromY;
17881
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
17882
+ if (distance === 0) return {
17883
+ x: toX,
17884
+ y: toY
17885
+ };
17886
+ let angle = Math.atan2(deltaY, deltaX) * (180 / Math.PI);
17887
+ const snapIncrement = 15;
17888
+ const snappedAngle = Math.round(angle / snapIncrement) * snapIncrement;
17889
+ const snappedRadians = snappedAngle * (Math.PI / 180);
17890
+ return {
17891
+ x: fromX + Math.cos(snappedRadians) * distance,
17892
+ y: fromY + Math.sin(snappedRadians) * distance
17893
+ };
17894
+ }
17895
+ _setWidthHeight() {
17896
+ let skipReposition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
17897
+ this.width = Math.abs(this.x2 - this.x1) || 1;
17898
+ this.height = Math.abs(this.y2 - this.y1) || 1;
17899
+ if (!skipReposition && !this._updatingEndpoints) {
17900
+ const {
17901
+ left,
17902
+ top,
17903
+ width,
17904
+ height
17905
+ } = makeBoundingBoxFromPoints([{
17906
+ x: this.x1,
17907
+ y: this.y1
17908
+ }, {
17909
+ x: this.x2,
17910
+ y: this.y2
17911
+ }]);
17912
+ this.setPositionByOrigin(new Point(left + width / 2, top + height / 2), CENTER, CENTER);
17913
+ }
17914
+ }
17700
17915
  _set(key, value) {
17916
+ const oldLeft = this.left;
17917
+ const oldTop = this.top;
17701
17918
  super._set(key, value);
17702
17919
  if (coordProps.includes(key)) {
17703
- // this doesn't make sense very much, since setting x1 when top or left
17704
- // are already set, is just going to show a strange result since the
17705
- // line will move way more than the developer expect.
17706
- // in fabric5 it worked only when the line didn't have extra transformations,
17707
- // in fabric6 too. With extra transform they behave bad in different ways.
17708
- // This needs probably a good rework or a tutorial if you have to create a dynamic line
17709
17920
  this._setWidthHeight();
17921
+ this.dirty = true;
17922
+ }
17923
+ if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
17924
+ const deltaX = this.left - oldLeft;
17925
+ const deltaY = this.top - oldTop;
17926
+ if (deltaX !== 0 || deltaY !== 0) {
17927
+ this._updatingEndpoints = true;
17928
+ this.x1 += deltaX;
17929
+ this.y1 += deltaY;
17930
+ this.x2 += deltaX;
17931
+ this.y2 += deltaY;
17932
+ this._updatingEndpoints = false;
17933
+ }
17710
17934
  }
17711
17935
  return this;
17712
17936
  }
17713
-
17714
- /**
17715
- * @private
17716
- * @param {CanvasRenderingContext2D} ctx Context to render on
17717
- */
17937
+ render(ctx) {
17938
+ if (this._useEndpointCoords) {
17939
+ this._renderDirectly(ctx);
17940
+ return;
17941
+ }
17942
+ super.render(ctx);
17943
+ }
17944
+ _renderDirectly(ctx) {
17945
+ var _this$canvas7, _this$stroke;
17946
+ if (!this.visible) return;
17947
+ ctx.save();
17948
+ const vpt = ((_this$canvas7 = this.canvas) === null || _this$canvas7 === void 0 ? void 0 : _this$canvas7.viewportTransform) || [1, 0, 0, 1, 0, 0];
17949
+ ctx.transform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17950
+ ctx.globalAlpha = this.opacity;
17951
+ ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17952
+ ctx.lineWidth = this.strokeWidth;
17953
+ ctx.lineCap = this.strokeLineCap || 'butt';
17954
+ ctx.beginPath();
17955
+ ctx.moveTo(this.x1, this.y1);
17956
+ ctx.lineTo(this.x2, this.y2);
17957
+ ctx.stroke();
17958
+ ctx.restore();
17959
+ }
17718
17960
  _render(ctx) {
17961
+ if (this._useEndpointCoords) return;
17719
17962
  ctx.beginPath();
17720
17963
  const p = this.calcLinePoints();
17721
17964
  ctx.moveTo(p.x1, p.y1);
17722
17965
  ctx.lineTo(p.x2, p.y2);
17723
17966
  ctx.lineWidth = this.strokeWidth;
17724
-
17725
- // TODO: test this
17726
- // make sure setting "fill" changes color of a line
17727
- // (by copying fillStyle to strokeStyle, since line is stroked, not filled)
17728
17967
  const origStrokeStyle = ctx.strokeStyle;
17729
17968
  if (isFiller(this.stroke)) {
17730
17969
  ctx.strokeStyle = this.stroke.toLive(ctx);
17731
- } else {
17732
- var _this$stroke;
17733
- ctx.strokeStyle = (_this$stroke = this.stroke) !== null && _this$stroke !== void 0 ? _this$stroke : ctx.fillStyle;
17734
17970
  }
17735
17971
  this.stroke && this._renderStroke(ctx);
17736
17972
  ctx.strokeStyle = origStrokeStyle;
17737
17973
  }
17738
-
17739
- /**
17740
- * This function is an helper for svg import. it returns the center of the object in the svg
17741
- * untransformed coordinates
17742
- * @private
17743
- * @return {Point} center point from element coordinates
17744
- */
17745
17974
  _findCenterFromElement() {
17746
17975
  return new Point((this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2);
17747
17976
  }
17748
-
17749
- /**
17750
- * Returns object representation of an instance
17751
- * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
17752
- * @return {Object} object representation of an instance
17753
- */
17754
17977
  toObject() {
17755
17978
  let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
17756
17979
  return {
@@ -17758,32 +17981,25 @@ class Line extends FabricObject {
17758
17981
  ...this.calcLinePoints()
17759
17982
  };
17760
17983
  }
17761
-
17762
- /*
17763
- * Calculate object dimensions from its properties
17764
- * @private
17765
- */
17766
17984
  _getNonTransformedDimensions() {
17767
17985
  const dim = super._getNonTransformedDimensions();
17768
- if (this.strokeLineCap === 'butt') {
17769
- if (this.width === 0) {
17770
- dim.y -= this.strokeWidth;
17771
- }
17772
- if (this.height === 0) {
17773
- dim.x -= this.strokeWidth;
17774
- }
17986
+ if (this.strokeLineCap === 'round') {
17987
+ dim.x += this.strokeWidth;
17988
+ dim.y += this.strokeWidth;
17775
17989
  }
17776
17990
  return dim;
17777
17991
  }
17778
-
17779
- /**
17780
- * Recalculates line points given width and height
17781
- * Those points are simply placed around the center,
17782
- * This is not useful outside internal render functions and svg output
17783
- * Is not meant to be for the developer.
17784
- * @private
17785
- */
17786
17992
  calcLinePoints() {
17993
+ if (this._updatingEndpoints) {
17994
+ const centerX = (this.x1 + this.x2) / 2;
17995
+ const centerY = (this.y1 + this.y2) / 2;
17996
+ return {
17997
+ x1: this.x1 - centerX,
17998
+ y1: this.y1 - centerY,
17999
+ x2: this.x2 - centerX,
18000
+ y2: this.y2 - centerY
18001
+ };
18002
+ }
17787
18003
  const {
17788
18004
  x1: _x1,
17789
18005
  x2: _x2,
@@ -17792,27 +18008,15 @@ class Line extends FabricObject {
17792
18008
  width,
17793
18009
  height
17794
18010
  } = this;
17795
- const xMult = _x1 <= _x2 ? -1 : 1,
17796
- yMult = _y1 <= _y2 ? -1 : 1,
17797
- x1 = xMult * width / 2,
17798
- y1 = yMult * height / 2,
17799
- x2 = xMult * -width / 2,
17800
- y2 = yMult * -height / 2;
18011
+ const xMult = _x1 <= _x2 ? -1 : 1;
18012
+ const yMult = _y1 <= _y2 ? -1 : 1;
17801
18013
  return {
17802
- x1,
17803
- x2,
17804
- y1,
17805
- y2
18014
+ x1: xMult * width / 2,
18015
+ y1: yMult * height / 2,
18016
+ x2: xMult * -width / 2,
18017
+ y2: yMult * -height / 2
17806
18018
  };
17807
18019
  }
17808
-
17809
- /* _FROM_SVG_START_ */
17810
-
17811
- /**
17812
- * Returns svg representation of an instance
17813
- * @return {Array} an array of strings with the specific svg representation
17814
- * of the instance
17815
- */
17816
18020
  _toSVG() {
17817
18021
  const {
17818
18022
  x1,
@@ -17822,18 +18026,6 @@ class Line extends FabricObject {
17822
18026
  } = this.calcLinePoints();
17823
18027
  return ['<line ', 'COMMON_PARTS', `x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" />\n`];
17824
18028
  }
17825
-
17826
- /**
17827
- * List of attribute names to account for when parsing SVG element (used by {@link Line.fromElement})
17828
- * @see http://www.w3.org/TR/SVG/shapes.html#LineElement
17829
- */
17830
-
17831
- /**
17832
- * Returns Line instance from an SVG element
17833
- * @param {HTMLElement} element Element to parse
17834
- * @param {Object} [options] Options object
17835
- * @param {Function} [callback] callback function invoked after parsing
17836
- */
17837
18029
  static async fromElement(element, options, cssRules) {
17838
18030
  const {
17839
18031
  x1 = 0,
@@ -17844,14 +18036,6 @@ class Line extends FabricObject {
17844
18036
  } = parseAttributes(element, this.ATTRIBUTE_NAMES, cssRules);
17845
18037
  return new this([x1, y1, x2, y2], parsedAttributes);
17846
18038
  }
17847
-
17848
- /* _FROM_SVG_END_ */
17849
-
17850
- /**
17851
- * Returns Line instance from an object representation
17852
- * @param {Object} object Object to create an instance from
17853
- * @returns {Promise<Line>}
17854
- */
17855
18039
  static fromObject(_ref) {
17856
18040
  let {
17857
18041
  x1,
@@ -17868,22 +18052,6 @@ class Line extends FabricObject {
17868
18052
  });
17869
18053
  }
17870
18054
  }
17871
- /**
17872
- * x value or first line edge
17873
- * @type number
17874
- */
17875
- /**
17876
- * y value or first line edge
17877
- * @type number
17878
- */
17879
- /**
17880
- * x value or second line edge
17881
- * @type number
17882
- */
17883
- /**
17884
- * y value or second line edge
17885
- * @type number
17886
- */
17887
18055
  _defineProperty(Line, "type", 'Line');
17888
18056
  _defineProperty(Line, "cacheProperties", [...cacheProperties, ...coordProps]);
17889
18057
  _defineProperty(Line, "ATTRIBUTE_NAMES", SHARED_ATTRIBUTES.concat(coordProps));