@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.js CHANGED
@@ -360,7 +360,7 @@
360
360
  }
361
361
  const cache = new Cache();
362
362
 
363
- var version = "7.0.1-beta5";
363
+ var version = "7.0.1-beta6";
364
364
 
365
365
  // use this syntax so babel plugin see this import here
366
366
  const VERSION = version;
@@ -17634,14 +17634,10 @@
17634
17634
  };
17635
17635
  }
17636
17636
  _p1PositionHandler() {
17637
- var _this$canvas;
17638
- const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17639
- return new Point(this.x1, this.y1).transform(vpt);
17637
+ return new Point(this.x1, this.y1).transform(this.getViewportTransform());
17640
17638
  }
17641
17639
  _p2PositionHandler() {
17642
- var _this$canvas2;
17643
- const vpt = ((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.viewportTransform) || [1, 0, 0, 1, 0, 0];
17644
- return new Point(this.x2, this.y2).transform(vpt);
17640
+ return new Point(this.x2, this.y2).transform(this.getViewportTransform());
17645
17641
  }
17646
17642
  _renderEndpointControl(ctx, left, top) {
17647
17643
  const size = 12;
@@ -17664,9 +17660,9 @@
17664
17660
  return super.drawBorders(ctx, styleOverride, {});
17665
17661
  }
17666
17662
  _drawLineBorders(ctx) {
17667
- var _this$canvas3;
17663
+ var _this$canvas;
17668
17664
  let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17669
- const vpt = ((_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 ? void 0 : _this$canvas3.viewportTransform) || [1, 0, 0, 1, 0, 0];
17665
+ const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17670
17666
  ctx.save();
17671
17667
  ctx.setTransform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17672
17668
  ctx.strokeStyle = styleOverride.borderColor || this.borderColor || 'rgba(100, 200, 200, 0.5)';
@@ -17707,16 +17703,18 @@
17707
17703
  }
17708
17704
  setCoords() {
17709
17705
  if (this._useEndpointCoords) {
17710
- // Set the object's center to the geometric center of the line
17711
- const center = this._findCenterFromElement();
17712
- this.left = center.x;
17713
- this.top = center.y;
17714
-
17715
17706
  // Set width and height for hit detection and bounding box
17716
17707
  const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
17717
17708
  const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
17718
17709
  this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
17719
17710
  this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
17711
+
17712
+ // Only update left/top if they haven't been explicitly set (e.g., during loading)
17713
+ if (this.left === 0 && this.top === 0) {
17714
+ const center = this._findCenterFromElement();
17715
+ this.left = center.x;
17716
+ this.top = center.y;
17717
+ }
17720
17718
  }
17721
17719
  super.setCoords();
17722
17720
  }
@@ -17742,8 +17740,8 @@
17742
17740
  }
17743
17741
  containsPoint(point) {
17744
17742
  if (this._useEndpointCoords) {
17745
- var _this$canvas4;
17746
- if (((_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 ? void 0 : _this$canvas4.getActiveObject()) === this) {
17743
+ var _this$canvas2;
17744
+ if (((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.getActiveObject()) === this) {
17747
17745
  return super.containsPoint(point);
17748
17746
  }
17749
17747
  const distance = this._distanceToLineSegment(point.x, point.y);
@@ -17777,7 +17775,7 @@
17777
17775
  return Math.sqrt((px - closestX) * (px - closestX) + (py - closestY) * (py - closestY));
17778
17776
  }
17779
17777
  _endpointActionHandler(eventData, transformData, x, y) {
17780
- var _this$canvas6;
17778
+ var _this$canvas4;
17781
17779
  const controlKey = transformData.corner;
17782
17780
  const pointer = new Point(x, y);
17783
17781
  let newX = pointer.x;
@@ -17791,7 +17789,7 @@
17791
17789
  newY = snapped.y;
17792
17790
  }
17793
17791
  if (this._useEndpointCoords) {
17794
- var _this$canvas5;
17792
+ var _this$canvas3;
17795
17793
  if (controlKey === 'p1') {
17796
17794
  this.x1 = newX;
17797
17795
  this.y1 = newY;
@@ -17801,7 +17799,7 @@
17801
17799
  }
17802
17800
  this.dirty = true;
17803
17801
  this.setCoords();
17804
- (_this$canvas5 = this.canvas) === null || _this$canvas5 === void 0 || _this$canvas5.requestRenderAll();
17802
+ (_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
17805
17803
  return true;
17806
17804
  }
17807
17805
 
@@ -17817,7 +17815,7 @@
17817
17815
  this._setWidthHeight();
17818
17816
  this.dirty = true;
17819
17817
  this._updatingEndpoints = false;
17820
- (_this$canvas6 = this.canvas) === null || _this$canvas6 === void 0 || _this$canvas6.requestRenderAll();
17818
+ (_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 || _this$canvas4.requestRenderAll();
17821
17819
  this.fire('modified', {
17822
17820
  transform: transformData,
17823
17821
  target: this,
@@ -17892,11 +17890,9 @@
17892
17890
  super.render(ctx);
17893
17891
  }
17894
17892
  _renderDirectly(ctx) {
17895
- var _this$canvas7, _this$stroke;
17893
+ var _this$stroke;
17896
17894
  if (!this.visible) return;
17897
17895
  ctx.save();
17898
- const vpt = ((_this$canvas7 = this.canvas) === null || _this$canvas7 === void 0 ? void 0 : _this$canvas7.viewportTransform) || [1, 0, 0, 1, 0, 0];
17899
- ctx.transform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17900
17896
  ctx.globalAlpha = this.opacity;
17901
17897
  ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17902
17898
  ctx.lineWidth = this.strokeWidth;
@@ -17926,6 +17922,15 @@
17926
17922
  }
17927
17923
  toObject() {
17928
17924
  let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
17925
+ if (this._useEndpointCoords) {
17926
+ return {
17927
+ ...super.toObject(propertiesToInclude),
17928
+ x1: this.x1,
17929
+ y1: this.y1,
17930
+ x2: this.x2,
17931
+ y2: this.y2
17932
+ };
17933
+ }
17929
17934
  return {
17930
17935
  ...super.toObject(propertiesToInclude),
17931
17936
  ...this.calcLinePoints()