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