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

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-beta6";
413
+ var version = "7.0.1-beta7";
414
414
 
415
415
  // use this syntax so babel plugin see this import here
416
416
  const VERSION = version;
@@ -17636,6 +17636,7 @@ class Line extends FabricObject {
17636
17636
  _defineProperty(this, "hitStrokeWidth", 'auto');
17637
17637
  _defineProperty(this, "_updatingEndpoints", false);
17638
17638
  _defineProperty(this, "_useEndpointCoords", true);
17639
+ _defineProperty(this, "_exportingSVG", false);
17639
17640
  this.setOptions(options);
17640
17641
  this.x1 = x1;
17641
17642
  this.x2 = x2;
@@ -17847,6 +17848,14 @@ class Line extends FabricObject {
17847
17848
  this.x2 = newX;
17848
17849
  this.y2 = newY;
17849
17850
  }
17851
+
17852
+ // Update gradient coordinates if stroke is a gradient (but not during SVG export)
17853
+ if (this.stroke instanceof Gradient && !this._exportingSVG) {
17854
+ this.stroke.coords.x1 = this.x1;
17855
+ this.stroke.coords.y1 = this.y1;
17856
+ this.stroke.coords.x2 = this.x2;
17857
+ this.stroke.coords.y2 = this.y2;
17858
+ }
17850
17859
  this.dirty = true;
17851
17860
  this.setCoords();
17852
17861
  (_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
@@ -17917,6 +17926,14 @@ class Line extends FabricObject {
17917
17926
  if (coordProps.includes(key)) {
17918
17927
  this._setWidthHeight();
17919
17928
  this.dirty = true;
17929
+
17930
+ // Update gradient coordinates if stroke is a gradient (but not during SVG export)
17931
+ if (this.stroke instanceof Gradient && !this._exportingSVG) {
17932
+ this.stroke.coords.x1 = this.x1;
17933
+ this.stroke.coords.y1 = this.y1;
17934
+ this.stroke.coords.x2 = this.x2;
17935
+ this.stroke.coords.y2 = this.y2;
17936
+ }
17920
17937
  }
17921
17938
  if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
17922
17939
  const deltaX = this.left - oldLeft;
@@ -17927,6 +17944,14 @@ class Line extends FabricObject {
17927
17944
  this.y1 += deltaY;
17928
17945
  this.x2 += deltaX;
17929
17946
  this.y2 += deltaY;
17947
+
17948
+ // Update gradient coordinates if stroke is a gradient
17949
+ if (this.stroke instanceof Gradient) {
17950
+ this.stroke.coords.x1 = this.x1;
17951
+ this.stroke.coords.y1 = this.y1;
17952
+ this.stroke.coords.x2 = this.x2;
17953
+ this.stroke.coords.y2 = this.y2;
17954
+ }
17930
17955
  this._updatingEndpoints = false;
17931
17956
  }
17932
17957
  }
@@ -17940,17 +17965,23 @@ class Line extends FabricObject {
17940
17965
  super.render(ctx);
17941
17966
  }
17942
17967
  _renderDirectly(ctx) {
17943
- var _this$stroke;
17944
17968
  if (!this.visible) return;
17945
17969
  ctx.save();
17946
17970
  ctx.globalAlpha = this.opacity;
17947
- ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17948
17971
  ctx.lineWidth = this.strokeWidth;
17949
17972
  ctx.lineCap = this.strokeLineCap || 'butt';
17950
17973
  ctx.beginPath();
17951
17974
  ctx.moveTo(this.x1, this.y1);
17952
17975
  ctx.lineTo(this.x2, this.y2);
17976
+ const origStrokeStyle = ctx.strokeStyle;
17977
+ if (isFiller(this.stroke)) {
17978
+ ctx.strokeStyle = this.stroke.toLive(ctx);
17979
+ } else {
17980
+ var _this$stroke;
17981
+ ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17982
+ }
17953
17983
  ctx.stroke();
17984
+ ctx.strokeStyle = origStrokeStyle;
17954
17985
  ctx.restore();
17955
17986
  }
17956
17987
  _render(ctx) {
@@ -18025,7 +18056,15 @@ class Line extends FabricObject {
18025
18056
  _toSVG() {
18026
18057
  if (this._useEndpointCoords) {
18027
18058
  // Use absolute coordinates to bypass all Fabric.js transforms
18028
- 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`];
18059
+ // Handle gradients manually for proper SVG export
18060
+ let strokeAttr = '';
18061
+ if (this.stroke instanceof Gradient) {
18062
+ // Let Fabric.js handle gradient definition, but we'll use the reference
18063
+ strokeAttr = `stroke="url(#${this.stroke.id})"`;
18064
+ } else {
18065
+ strokeAttr = `stroke="${this.stroke || 'none'}"`;
18066
+ }
18067
+ return [`<line ${strokeAttr} stroke-width="${this.strokeWidth}" stroke-linecap="${this.strokeLineCap}" `, `stroke-dasharray="${this.strokeDashArray ? this.strokeDashArray.join(' ') : 'none'}" `, `stroke-dashoffset="${this.strokeDashOffset}" stroke-linejoin="${this.strokeLineJoin}" `, `stroke-miterlimit="${this.strokeMiterLimit}" fill="${this.fill || 'none'}" `, `fill-rule="${this.fillRule}" opacity="${this.opacity}" `, `x1="${this.x1}" y1="${this.y1}" x2="${this.x2}" y2="${this.y2}" />\n`];
18029
18068
  } else {
18030
18069
  // Use standard calcLinePoints for legacy mode
18031
18070
  const {
@@ -18039,9 +18078,26 @@ class Line extends FabricObject {
18039
18078
  }
18040
18079
  toSVG(reviver) {
18041
18080
  if (this._useEndpointCoords) {
18042
- // Override toSVG to prevent Fabric.js from adding transform wrapper
18043
- const markup = this._toSVG().join('');
18044
- return reviver ? reviver(markup) : markup;
18081
+ // For endpoint coords, we need to bypass transforms but still allow gradients
18082
+ // Let's temporarily disable transforms during SVG generation
18083
+ const originalLeft = this.left;
18084
+ const originalTop = this.top;
18085
+
18086
+ // Set position to center of line for gradient calculation
18087
+ this.left = (this.x1 + this.x2) / 2;
18088
+ this.top = (this.y1 + this.y2) / 2;
18089
+
18090
+ // Get the SVG with standard system (for gradient handling)
18091
+ const standardSVG = super.toSVG(reviver);
18092
+
18093
+ // Restore original position
18094
+ this.left = originalLeft;
18095
+ this.top = originalTop;
18096
+
18097
+ // Extract gradient definition and clean up the line element
18098
+ // Remove the transform wrapper and update coordinates
18099
+ const cleanSVG = standardSVG.replace(/<g transform="[^"]*"[^>]*>/g, '').replace(/<\/g>/g, '').replace(/x1="[^"]*"/g, `x1="${this.x1}"`).replace(/y1="[^"]*"/g, `y1="${this.y1}"`).replace(/x2="[^"]*"/g, `x2="${this.x2}"`).replace(/y2="[^"]*"/g, `y2="${this.y2}"`);
18100
+ return cleanSVG;
18045
18101
  }
18046
18102
  // Use default behavior for legacy mode
18047
18103
  return super.toSVG(reviver);