@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.
package/dist/index.mjs CHANGED
@@ -354,7 +354,7 @@ class Cache {
354
354
  }
355
355
  const cache = new Cache();
356
356
 
357
- var version = "7.0.1-beta5";
357
+ var version = "7.0.1-beta6";
358
358
 
359
359
  // use this syntax so babel plugin see this import here
360
360
  const VERSION = version;
@@ -17628,14 +17628,10 @@ class Line extends FabricObject {
17628
17628
  };
17629
17629
  }
17630
17630
  _p1PositionHandler() {
17631
- var _this$canvas;
17632
- const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17633
- return new Point(this.x1, this.y1).transform(vpt);
17631
+ return new Point(this.x1, this.y1).transform(this.getViewportTransform());
17634
17632
  }
17635
17633
  _p2PositionHandler() {
17636
- var _this$canvas2;
17637
- const vpt = ((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.viewportTransform) || [1, 0, 0, 1, 0, 0];
17638
- return new Point(this.x2, this.y2).transform(vpt);
17634
+ return new Point(this.x2, this.y2).transform(this.getViewportTransform());
17639
17635
  }
17640
17636
  _renderEndpointControl(ctx, left, top) {
17641
17637
  const size = 12;
@@ -17658,9 +17654,9 @@ class Line extends FabricObject {
17658
17654
  return super.drawBorders(ctx, styleOverride, {});
17659
17655
  }
17660
17656
  _drawLineBorders(ctx) {
17661
- var _this$canvas3;
17657
+ var _this$canvas;
17662
17658
  let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17663
- const vpt = ((_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 ? void 0 : _this$canvas3.viewportTransform) || [1, 0, 0, 1, 0, 0];
17659
+ const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17664
17660
  ctx.save();
17665
17661
  ctx.setTransform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17666
17662
  ctx.strokeStyle = styleOverride.borderColor || this.borderColor || 'rgba(100, 200, 200, 0.5)';
@@ -17701,16 +17697,18 @@ class Line extends FabricObject {
17701
17697
  }
17702
17698
  setCoords() {
17703
17699
  if (this._useEndpointCoords) {
17704
- // Set the object's center to the geometric center of the line
17705
- const center = this._findCenterFromElement();
17706
- this.left = center.x;
17707
- this.top = center.y;
17708
-
17709
17700
  // Set width and height for hit detection and bounding box
17710
17701
  const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
17711
17702
  const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
17712
17703
  this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
17713
17704
  this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
17705
+
17706
+ // Only update left/top if they haven't been explicitly set (e.g., during loading)
17707
+ if (this.left === 0 && this.top === 0) {
17708
+ const center = this._findCenterFromElement();
17709
+ this.left = center.x;
17710
+ this.top = center.y;
17711
+ }
17714
17712
  }
17715
17713
  super.setCoords();
17716
17714
  }
@@ -17736,8 +17734,8 @@ class Line extends FabricObject {
17736
17734
  }
17737
17735
  containsPoint(point) {
17738
17736
  if (this._useEndpointCoords) {
17739
- var _this$canvas4;
17740
- if (((_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 ? void 0 : _this$canvas4.getActiveObject()) === this) {
17737
+ var _this$canvas2;
17738
+ if (((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.getActiveObject()) === this) {
17741
17739
  return super.containsPoint(point);
17742
17740
  }
17743
17741
  const distance = this._distanceToLineSegment(point.x, point.y);
@@ -17771,7 +17769,7 @@ class Line extends FabricObject {
17771
17769
  return Math.sqrt((px - closestX) * (px - closestX) + (py - closestY) * (py - closestY));
17772
17770
  }
17773
17771
  _endpointActionHandler(eventData, transformData, x, y) {
17774
- var _this$canvas6;
17772
+ var _this$canvas4;
17775
17773
  const controlKey = transformData.corner;
17776
17774
  const pointer = new Point(x, y);
17777
17775
  let newX = pointer.x;
@@ -17785,7 +17783,7 @@ class Line extends FabricObject {
17785
17783
  newY = snapped.y;
17786
17784
  }
17787
17785
  if (this._useEndpointCoords) {
17788
- var _this$canvas5;
17786
+ var _this$canvas3;
17789
17787
  if (controlKey === 'p1') {
17790
17788
  this.x1 = newX;
17791
17789
  this.y1 = newY;
@@ -17795,7 +17793,7 @@ class Line extends FabricObject {
17795
17793
  }
17796
17794
  this.dirty = true;
17797
17795
  this.setCoords();
17798
- (_this$canvas5 = this.canvas) === null || _this$canvas5 === void 0 || _this$canvas5.requestRenderAll();
17796
+ (_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
17799
17797
  return true;
17800
17798
  }
17801
17799
 
@@ -17811,7 +17809,7 @@ class Line extends FabricObject {
17811
17809
  this._setWidthHeight();
17812
17810
  this.dirty = true;
17813
17811
  this._updatingEndpoints = false;
17814
- (_this$canvas6 = this.canvas) === null || _this$canvas6 === void 0 || _this$canvas6.requestRenderAll();
17812
+ (_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 || _this$canvas4.requestRenderAll();
17815
17813
  this.fire('modified', {
17816
17814
  transform: transformData,
17817
17815
  target: this,
@@ -17886,11 +17884,9 @@ class Line extends FabricObject {
17886
17884
  super.render(ctx);
17887
17885
  }
17888
17886
  _renderDirectly(ctx) {
17889
- var _this$canvas7, _this$stroke;
17887
+ var _this$stroke;
17890
17888
  if (!this.visible) return;
17891
17889
  ctx.save();
17892
- const vpt = ((_this$canvas7 = this.canvas) === null || _this$canvas7 === void 0 ? void 0 : _this$canvas7.viewportTransform) || [1, 0, 0, 1, 0, 0];
17893
- ctx.transform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17894
17890
  ctx.globalAlpha = this.opacity;
17895
17891
  ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17896
17892
  ctx.lineWidth = this.strokeWidth;
@@ -17920,6 +17916,15 @@ class Line extends FabricObject {
17920
17916
  }
17921
17917
  toObject() {
17922
17918
  let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
17919
+ if (this._useEndpointCoords) {
17920
+ return {
17921
+ ...super.toObject(propertiesToInclude),
17922
+ x1: this.x1,
17923
+ y1: this.y1,
17924
+ x2: this.x2,
17925
+ y2: this.y2
17926
+ };
17927
+ }
17923
17928
  return {
17924
17929
  ...super.toObject(propertiesToInclude),
17925
17930
  ...this.calcLinePoints()