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

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.
@@ -410,7 +410,7 @@ class Cache {
410
410
  }
411
411
  const cache = new Cache();
412
412
 
413
- var version = "7.0.1-beta3";
413
+ var version = "7.0.1-beta5";
414
414
 
415
415
  // use this syntax so babel plugin see this import here
416
416
  const VERSION = version;
@@ -17684,14 +17684,10 @@ class Line extends FabricObject {
17684
17684
  };
17685
17685
  }
17686
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);
17687
+ return new Point(this.x1, this.y1).transform(this.getViewportTransform());
17690
17688
  }
17691
17689
  _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);
17690
+ return new Point(this.x2, this.y2).transform(this.getViewportTransform());
17695
17691
  }
17696
17692
  _renderEndpointControl(ctx, left, top) {
17697
17693
  const size = 12;
@@ -17714,9 +17710,9 @@ class Line extends FabricObject {
17714
17710
  return super.drawBorders(ctx, styleOverride, {});
17715
17711
  }
17716
17712
  _drawLineBorders(ctx) {
17717
- var _this$canvas3;
17713
+ var _this$canvas;
17718
17714
  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];
17715
+ const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
17720
17716
  ctx.save();
17721
17717
  ctx.setTransform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
17722
17718
  ctx.strokeStyle = styleOverride.borderColor || this.borderColor || 'rgba(100, 200, 200, 0.5)';
@@ -17757,14 +17753,14 @@ class Line extends FabricObject {
17757
17753
  }
17758
17754
  setCoords() {
17759
17755
  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);
17756
+ // Set the object's center to the geometric center of the line
17757
+ const center = this._findCenterFromElement();
17758
+ this.left = center.x;
17759
+ this.top = center.y;
17760
+
17761
+ // Set width and height for hit detection and bounding box
17764
17762
  const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
17765
17763
  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
17764
  this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
17769
17765
  this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
17770
17766
  }
@@ -17792,8 +17788,8 @@ class Line extends FabricObject {
17792
17788
  }
17793
17789
  containsPoint(point) {
17794
17790
  if (this._useEndpointCoords) {
17795
- var _this$canvas4;
17796
- if (((_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 ? void 0 : _this$canvas4.getActiveObject()) === this) {
17791
+ var _this$canvas2;
17792
+ if (((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.getActiveObject()) === this) {
17797
17793
  return super.containsPoint(point);
17798
17794
  }
17799
17795
  const distance = this._distanceToLineSegment(point.x, point.y);
@@ -17827,7 +17823,7 @@ class Line extends FabricObject {
17827
17823
  return Math.sqrt((px - closestX) * (px - closestX) + (py - closestY) * (py - closestY));
17828
17824
  }
17829
17825
  _endpointActionHandler(eventData, transformData, x, y) {
17830
- var _this$canvas6;
17826
+ var _this$canvas4;
17831
17827
  const controlKey = transformData.corner;
17832
17828
  const pointer = new Point(x, y);
17833
17829
  let newX = pointer.x;
@@ -17841,7 +17837,7 @@ class Line extends FabricObject {
17841
17837
  newY = snapped.y;
17842
17838
  }
17843
17839
  if (this._useEndpointCoords) {
17844
- var _this$canvas5;
17840
+ var _this$canvas3;
17845
17841
  if (controlKey === 'p1') {
17846
17842
  this.x1 = newX;
17847
17843
  this.y1 = newY;
@@ -17851,7 +17847,7 @@ class Line extends FabricObject {
17851
17847
  }
17852
17848
  this.dirty = true;
17853
17849
  this.setCoords();
17854
- (_this$canvas5 = this.canvas) === null || _this$canvas5 === void 0 || _this$canvas5.requestRenderAll();
17850
+ (_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
17855
17851
  return true;
17856
17852
  }
17857
17853
 
@@ -17867,7 +17863,7 @@ class Line extends FabricObject {
17867
17863
  this._setWidthHeight();
17868
17864
  this.dirty = true;
17869
17865
  this._updatingEndpoints = false;
17870
- (_this$canvas6 = this.canvas) === null || _this$canvas6 === void 0 || _this$canvas6.requestRenderAll();
17866
+ (_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 || _this$canvas4.requestRenderAll();
17871
17867
  this.fire('modified', {
17872
17868
  transform: transformData,
17873
17869
  target: this,
@@ -17942,11 +17938,9 @@ class Line extends FabricObject {
17942
17938
  super.render(ctx);
17943
17939
  }
17944
17940
  _renderDirectly(ctx) {
17945
- var _this$canvas7, _this$stroke;
17941
+ var _this$stroke;
17946
17942
  if (!this.visible) return;
17947
17943
  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
17944
  ctx.globalAlpha = this.opacity;
17951
17945
  ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17952
17946
  ctx.lineWidth = this.strokeWidth;
@@ -18018,13 +18012,28 @@ class Line extends FabricObject {
18018
18012
  };
18019
18013
  }
18020
18014
  _toSVG() {
18021
- const {
18022
- x1,
18023
- x2,
18024
- y1,
18025
- y2
18026
- } = this.calcLinePoints();
18027
- return ['<line ', 'COMMON_PARTS', `x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" />\n`];
18015
+ if (this._useEndpointCoords) {
18016
+ // Use absolute coordinates to bypass all Fabric.js transforms
18017
+ return [`<line stroke="${this.stroke}" stroke-width="${this.strokeWidth}" stroke-linecap="${this.strokeLineCap}" `, `x1="${this.x1}" y1="${this.y1}" x2="${this.x2}" y2="${this.y2}" />\n`];
18018
+ } else {
18019
+ // Use standard calcLinePoints for legacy mode
18020
+ const {
18021
+ x1,
18022
+ x2,
18023
+ y1,
18024
+ y2
18025
+ } = this.calcLinePoints();
18026
+ return ['<line ', 'COMMON_PARTS', `x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" />\n`];
18027
+ }
18028
+ }
18029
+ toSVG(reviver) {
18030
+ if (this._useEndpointCoords) {
18031
+ // Override toSVG to prevent Fabric.js from adding transform wrapper
18032
+ const markup = this._toSVG().join('');
18033
+ return reviver ? reviver(markup) : markup;
18034
+ }
18035
+ // Use default behavior for legacy mode
18036
+ return super.toSVG(reviver);
18028
18037
  }
18029
18038
  static async fromElement(element, options, cssRules) {
18030
18039
  const {