@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.js CHANGED
@@ -360,7 +360,7 @@
360
360
  }
361
361
  const cache = new Cache();
362
362
 
363
- var version = "7.0.1-beta6";
363
+ var version = "7.0.1-beta7";
364
364
 
365
365
  // use this syntax so babel plugin see this import here
366
366
  const VERSION = version;
@@ -17586,6 +17586,7 @@
17586
17586
  _defineProperty(this, "hitStrokeWidth", 'auto');
17587
17587
  _defineProperty(this, "_updatingEndpoints", false);
17588
17588
  _defineProperty(this, "_useEndpointCoords", true);
17589
+ _defineProperty(this, "_exportingSVG", false);
17589
17590
  this.setOptions(options);
17590
17591
  this.x1 = x1;
17591
17592
  this.x2 = x2;
@@ -17797,6 +17798,14 @@
17797
17798
  this.x2 = newX;
17798
17799
  this.y2 = newY;
17799
17800
  }
17801
+
17802
+ // Update gradient coordinates if stroke is a gradient (but not during SVG export)
17803
+ if (this.stroke instanceof Gradient && !this._exportingSVG) {
17804
+ this.stroke.coords.x1 = this.x1;
17805
+ this.stroke.coords.y1 = this.y1;
17806
+ this.stroke.coords.x2 = this.x2;
17807
+ this.stroke.coords.y2 = this.y2;
17808
+ }
17800
17809
  this.dirty = true;
17801
17810
  this.setCoords();
17802
17811
  (_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
@@ -17867,6 +17876,14 @@
17867
17876
  if (coordProps.includes(key)) {
17868
17877
  this._setWidthHeight();
17869
17878
  this.dirty = true;
17879
+
17880
+ // Update gradient coordinates if stroke is a gradient (but not during SVG export)
17881
+ if (this.stroke instanceof Gradient && !this._exportingSVG) {
17882
+ this.stroke.coords.x1 = this.x1;
17883
+ this.stroke.coords.y1 = this.y1;
17884
+ this.stroke.coords.x2 = this.x2;
17885
+ this.stroke.coords.y2 = this.y2;
17886
+ }
17870
17887
  }
17871
17888
  if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
17872
17889
  const deltaX = this.left - oldLeft;
@@ -17877,6 +17894,14 @@
17877
17894
  this.y1 += deltaY;
17878
17895
  this.x2 += deltaX;
17879
17896
  this.y2 += deltaY;
17897
+
17898
+ // Update gradient coordinates if stroke is a gradient
17899
+ if (this.stroke instanceof Gradient) {
17900
+ this.stroke.coords.x1 = this.x1;
17901
+ this.stroke.coords.y1 = this.y1;
17902
+ this.stroke.coords.x2 = this.x2;
17903
+ this.stroke.coords.y2 = this.y2;
17904
+ }
17880
17905
  this._updatingEndpoints = false;
17881
17906
  }
17882
17907
  }
@@ -17890,17 +17915,23 @@
17890
17915
  super.render(ctx);
17891
17916
  }
17892
17917
  _renderDirectly(ctx) {
17893
- var _this$stroke;
17894
17918
  if (!this.visible) return;
17895
17919
  ctx.save();
17896
17920
  ctx.globalAlpha = this.opacity;
17897
- ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17898
17921
  ctx.lineWidth = this.strokeWidth;
17899
17922
  ctx.lineCap = this.strokeLineCap || 'butt';
17900
17923
  ctx.beginPath();
17901
17924
  ctx.moveTo(this.x1, this.y1);
17902
17925
  ctx.lineTo(this.x2, this.y2);
17926
+ const origStrokeStyle = ctx.strokeStyle;
17927
+ if (isFiller(this.stroke)) {
17928
+ ctx.strokeStyle = this.stroke.toLive(ctx);
17929
+ } else {
17930
+ var _this$stroke;
17931
+ ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
17932
+ }
17903
17933
  ctx.stroke();
17934
+ ctx.strokeStyle = origStrokeStyle;
17904
17935
  ctx.restore();
17905
17936
  }
17906
17937
  _render(ctx) {
@@ -17975,7 +18006,15 @@
17975
18006
  _toSVG() {
17976
18007
  if (this._useEndpointCoords) {
17977
18008
  // Use absolute coordinates to bypass all Fabric.js transforms
17978
- 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`];
18009
+ // Handle gradients manually for proper SVG export
18010
+ let strokeAttr = '';
18011
+ if (this.stroke instanceof Gradient) {
18012
+ // Let Fabric.js handle gradient definition, but we'll use the reference
18013
+ strokeAttr = `stroke="url(#${this.stroke.id})"`;
18014
+ } else {
18015
+ strokeAttr = `stroke="${this.stroke || 'none'}"`;
18016
+ }
18017
+ 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`];
17979
18018
  } else {
17980
18019
  // Use standard calcLinePoints for legacy mode
17981
18020
  const {
@@ -17989,9 +18028,26 @@
17989
18028
  }
17990
18029
  toSVG(reviver) {
17991
18030
  if (this._useEndpointCoords) {
17992
- // Override toSVG to prevent Fabric.js from adding transform wrapper
17993
- const markup = this._toSVG().join('');
17994
- return reviver ? reviver(markup) : markup;
18031
+ // For endpoint coords, we need to bypass transforms but still allow gradients
18032
+ // Let's temporarily disable transforms during SVG generation
18033
+ const originalLeft = this.left;
18034
+ const originalTop = this.top;
18035
+
18036
+ // Set position to center of line for gradient calculation
18037
+ this.left = (this.x1 + this.x2) / 2;
18038
+ this.top = (this.y1 + this.y2) / 2;
18039
+
18040
+ // Get the SVG with standard system (for gradient handling)
18041
+ const standardSVG = super.toSVG(reviver);
18042
+
18043
+ // Restore original position
18044
+ this.left = originalLeft;
18045
+ this.top = originalTop;
18046
+
18047
+ // Extract gradient definition and clean up the line element
18048
+ // Remove the transform wrapper and update coordinates
18049
+ 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}"`);
18050
+ return cleanSVG;
17995
18051
  }
17996
18052
  // Use default behavior for legacy mode
17997
18053
  return super.toSVG(reviver);