@nasser-sw/fabric 7.0.1-beta5 → 7.0.1-beta7

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.
@@ -412,7 +412,7 @@ class Cache {
412
412
  }
413
413
  const cache = new Cache();
414
414
 
415
- var version = "7.0.1-beta5";
415
+ var version = "7.0.1-beta6";
416
416
 
417
417
  // use this syntax so babel plugin see this import here
418
418
  const VERSION = version;
@@ -17686,14 +17686,10 @@ class Line extends FabricObject {
17686
17686
  };
17687
17687
  }
17688
17688
  _p1PositionHandler() {
17689
- var _this$canvas;
17690
- const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17691
- return new Point(this.x1, this.y1).transform(vpt);
17689
+ return new Point(this.x1, this.y1).transform(this.getViewportTransform());
17692
17690
  }
17693
17691
  _p2PositionHandler() {
17694
- var _this$canvas2;
17695
- const vpt = ((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.viewportTransform) || [1, 0, 0, 1, 0, 0];
17696
- return new Point(this.x2, this.y2).transform(vpt);
17692
+ return new Point(this.x2, this.y2).transform(this.getViewportTransform());
17697
17693
  }
17698
17694
  _renderEndpointControl(ctx, left, top) {
17699
17695
  const size = 12;
@@ -17716,9 +17712,9 @@ class Line extends FabricObject {
17716
17712
  return super.drawBorders(ctx, styleOverride, {});
17717
17713
  }
17718
17714
  _drawLineBorders(ctx) {
17719
- var _this$canvas3;
17715
+ var _this$canvas;
17720
17716
  let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17721
- const vpt = ((_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 ? void 0 : _this$canvas3.viewportTransform) || [1, 0, 0, 1, 0, 0];
17717
+ const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17722
17718
  ctx.save();
17723
17719
  ctx.setTransform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17724
17720
  ctx.strokeStyle = styleOverride.borderColor || this.borderColor || 'rgba(100, 200, 200, 0.5)';
@@ -17759,16 +17755,18 @@ class Line extends FabricObject {
17759
17755
  }
17760
17756
  setCoords() {
17761
17757
  if (this._useEndpointCoords) {
17762
- // Set the object's center to the geometric center of the line
17763
- const center = this._findCenterFromElement();
17764
- this.left = center.x;
17765
- this.top = center.y;
17766
-
17767
17758
  // Set width and height for hit detection and bounding box
17768
17759
  const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
17769
17760
  const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
17770
17761
  this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
17771
17762
  this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
17763
+
17764
+ // Only update left/top if they haven't been explicitly set (e.g., during loading)
17765
+ if (this.left === 0 && this.top === 0) {
17766
+ const center = this._findCenterFromElement();
17767
+ this.left = center.x;
17768
+ this.top = center.y;
17769
+ }
17772
17770
  }
17773
17771
  super.setCoords();
17774
17772
  }
@@ -17794,8 +17792,8 @@ class Line extends FabricObject {
17794
17792
  }
17795
17793
  containsPoint(point) {
17796
17794
  if (this._useEndpointCoords) {
17797
- var _this$canvas4;
17798
- if (((_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 ? void 0 : _this$canvas4.getActiveObject()) === this) {
17795
+ var _this$canvas2;
17796
+ if (((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.getActiveObject()) === this) {
17799
17797
  return super.containsPoint(point);
17800
17798
  }
17801
17799
  const distance = this._distanceToLineSegment(point.x, point.y);
@@ -17829,7 +17827,7 @@ class Line extends FabricObject {
17829
17827
  return Math.sqrt((px - closestX) * (px - closestX) + (py - closestY) * (py - closestY));
17830
17828
  }
17831
17829
  _endpointActionHandler(eventData, transformData, x, y) {
17832
- var _this$canvas6;
17830
+ var _this$canvas4;
17833
17831
  const controlKey = transformData.corner;
17834
17832
  const pointer = new Point(x, y);
17835
17833
  let newX = pointer.x;
@@ -17843,7 +17841,7 @@ class Line extends FabricObject {
17843
17841
  newY = snapped.y;
17844
17842
  }
17845
17843
  if (this._useEndpointCoords) {
17846
- var _this$canvas5;
17844
+ var _this$canvas3;
17847
17845
  if (controlKey === 'p1') {
17848
17846
  this.x1 = newX;
17849
17847
  this.y1 = newY;
@@ -17853,7 +17851,7 @@ class Line extends FabricObject {
17853
17851
  }
17854
17852
  this.dirty = true;
17855
17853
  this.setCoords();
17856
- (_this$canvas5 = this.canvas) === null || _this$canvas5 === void 0 || _this$canvas5.requestRenderAll();
17854
+ (_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
17857
17855
  return true;
17858
17856
  }
17859
17857
 
@@ -17869,7 +17867,7 @@ class Line extends FabricObject {
17869
17867
  this._setWidthHeight();
17870
17868
  this.dirty = true;
17871
17869
  this._updatingEndpoints = false;
17872
- (_this$canvas6 = this.canvas) === null || _this$canvas6 === void 0 || _this$canvas6.requestRenderAll();
17870
+ (_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 || _this$canvas4.requestRenderAll();
17873
17871
  this.fire('modified', {
17874
17872
  transform: transformData,
17875
17873
  target: this,
@@ -17944,11 +17942,9 @@ class Line extends FabricObject {
17944
17942
  super.render(ctx);
17945
17943
  }
17946
17944
  _renderDirectly(ctx) {
17947
- var _this$canvas7, _this$stroke;
17945
+ var _this$stroke;
17948
17946
  if (!this.visible) return;
17949
17947
  ctx.save();
17950
- const vpt = ((_this$canvas7 = this.canvas) === null || _this$canvas7 === void 0 ? void 0 : _this$canvas7.viewportTransform) || [1, 0, 0, 1, 0, 0];
17951
- ctx.transform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17952
17948
  ctx.globalAlpha = this.opacity;
17953
17949
  ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17954
17950
  ctx.lineWidth = this.strokeWidth;
@@ -17978,6 +17974,15 @@ class Line extends FabricObject {
17978
17974
  }
17979
17975
  toObject() {
17980
17976
  let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
17977
+ if (this._useEndpointCoords) {
17978
+ return {
17979
+ ...super.toObject(propertiesToInclude),
17980
+ x1: this.x1,
17981
+ y1: this.y1,
17982
+ x2: this.x2,
17983
+ y2: this.y2
17984
+ };
17985
+ }
17981
17986
  return {
17982
17987
  ...super.toObject(propertiesToInclude),
17983
17988
  ...this.calcLinePoints()