@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.
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-beta6";
357
+ var version = "7.0.1-beta7";
358
358
 
359
359
  // use this syntax so babel plugin see this import here
360
360
  const VERSION = version;
@@ -17580,6 +17580,7 @@ class Line extends FabricObject {
17580
17580
  _defineProperty(this, "hitStrokeWidth", 'auto');
17581
17581
  _defineProperty(this, "_updatingEndpoints", false);
17582
17582
  _defineProperty(this, "_useEndpointCoords", true);
17583
+ _defineProperty(this, "_exportingSVG", false);
17583
17584
  this.setOptions(options);
17584
17585
  this.x1 = x1;
17585
17586
  this.x2 = x2;
@@ -17791,6 +17792,14 @@ class Line extends FabricObject {
17791
17792
  this.x2 = newX;
17792
17793
  this.y2 = newY;
17793
17794
  }
17795
+
17796
+ // Update gradient coordinates if stroke is a gradient (but not during SVG export)
17797
+ if (this.stroke instanceof Gradient && !this._exportingSVG) {
17798
+ this.stroke.coords.x1 = this.x1;
17799
+ this.stroke.coords.y1 = this.y1;
17800
+ this.stroke.coords.x2 = this.x2;
17801
+ this.stroke.coords.y2 = this.y2;
17802
+ }
17794
17803
  this.dirty = true;
17795
17804
  this.setCoords();
17796
17805
  (_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
@@ -17861,6 +17870,14 @@ class Line extends FabricObject {
17861
17870
  if (coordProps.includes(key)) {
17862
17871
  this._setWidthHeight();
17863
17872
  this.dirty = true;
17873
+
17874
+ // Update gradient coordinates if stroke is a gradient (but not during SVG export)
17875
+ if (this.stroke instanceof Gradient && !this._exportingSVG) {
17876
+ this.stroke.coords.x1 = this.x1;
17877
+ this.stroke.coords.y1 = this.y1;
17878
+ this.stroke.coords.x2 = this.x2;
17879
+ this.stroke.coords.y2 = this.y2;
17880
+ }
17864
17881
  }
17865
17882
  if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
17866
17883
  const deltaX = this.left - oldLeft;
@@ -17871,6 +17888,14 @@ class Line extends FabricObject {
17871
17888
  this.y1 += deltaY;
17872
17889
  this.x2 += deltaX;
17873
17890
  this.y2 += deltaY;
17891
+
17892
+ // Update gradient coordinates if stroke is a gradient
17893
+ if (this.stroke instanceof Gradient) {
17894
+ this.stroke.coords.x1 = this.x1;
17895
+ this.stroke.coords.y1 = this.y1;
17896
+ this.stroke.coords.x2 = this.x2;
17897
+ this.stroke.coords.y2 = this.y2;
17898
+ }
17874
17899
  this._updatingEndpoints = false;
17875
17900
  }
17876
17901
  }
@@ -17884,17 +17909,23 @@ class Line extends FabricObject {
17884
17909
  super.render(ctx);
17885
17910
  }
17886
17911
  _renderDirectly(ctx) {
17887
- var _this$stroke;
17888
17912
  if (!this.visible) return;
17889
17913
  ctx.save();
17890
17914
  ctx.globalAlpha = this.opacity;
17891
- ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17892
17915
  ctx.lineWidth = this.strokeWidth;
17893
17916
  ctx.lineCap = this.strokeLineCap || 'butt';
17894
17917
  ctx.beginPath();
17895
17918
  ctx.moveTo(this.x1, this.y1);
17896
17919
  ctx.lineTo(this.x2, this.y2);
17920
+ const origStrokeStyle = ctx.strokeStyle;
17921
+ if (isFiller(this.stroke)) {
17922
+ ctx.strokeStyle = this.stroke.toLive(ctx);
17923
+ } else {
17924
+ var _this$stroke;
17925
+ ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17926
+ }
17897
17927
  ctx.stroke();
17928
+ ctx.strokeStyle = origStrokeStyle;
17898
17929
  ctx.restore();
17899
17930
  }
17900
17931
  _render(ctx) {
@@ -17969,7 +18000,15 @@ class Line extends FabricObject {
17969
18000
  _toSVG() {
17970
18001
  if (this._useEndpointCoords) {
17971
18002
  // Use absolute coordinates to bypass all Fabric.js transforms
17972
- 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`];
18003
+ // Handle gradients manually for proper SVG export
18004
+ let strokeAttr = '';
18005
+ if (this.stroke instanceof Gradient) {
18006
+ // Let Fabric.js handle gradient definition, but we'll use the reference
18007
+ strokeAttr = `stroke="url(#${this.stroke.id})"`;
18008
+ } else {
18009
+ strokeAttr = `stroke="${this.stroke || 'none'}"`;
18010
+ }
18011
+ 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`];
17973
18012
  } else {
17974
18013
  // Use standard calcLinePoints for legacy mode
17975
18014
  const {
@@ -17983,9 +18022,26 @@ class Line extends FabricObject {
17983
18022
  }
17984
18023
  toSVG(reviver) {
17985
18024
  if (this._useEndpointCoords) {
17986
- // Override toSVG to prevent Fabric.js from adding transform wrapper
17987
- const markup = this._toSVG().join('');
17988
- return reviver ? reviver(markup) : markup;
18025
+ // For endpoint coords, we need to bypass transforms but still allow gradients
18026
+ // Let's temporarily disable transforms during SVG generation
18027
+ const originalLeft = this.left;
18028
+ const originalTop = this.top;
18029
+
18030
+ // Set position to center of line for gradient calculation
18031
+ this.left = (this.x1 + this.x2) / 2;
18032
+ this.top = (this.y1 + this.y2) / 2;
18033
+
18034
+ // Get the SVG with standard system (for gradient handling)
18035
+ const standardSVG = super.toSVG(reviver);
18036
+
18037
+ // Restore original position
18038
+ this.left = originalLeft;
18039
+ this.top = originalTop;
18040
+
18041
+ // Extract gradient definition and clean up the line element
18042
+ // Remove the transform wrapper and update coordinates
18043
+ 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}"`);
18044
+ return cleanSVG;
17989
18045
  }
17990
18046
  // Use default behavior for legacy mode
17991
18047
  return super.toSVG(reviver);