@nasser-sw/fabric 7.0.1-beta6 → 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 +79 -12
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +79 -12
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +79 -12
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +79 -12
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/shapes/Line.d.ts +1 -0
- package/dist/src/shapes/Line.d.ts.map +1 -1
- package/dist/src/shapes/Line.min.mjs +1 -1
- package/dist/src/shapes/Line.min.mjs.map +1 -1
- package/dist/src/shapes/Line.mjs +79 -11
- package/dist/src/shapes/Line.mjs.map +1 -1
- package/dist-extensions/src/shapes/Line.d.ts +1 -0
- package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
- package/fabric-test2.html +134 -0
- package/package.json +1 -1
- package/src/shapes/Line.ts +147 -50
package/dist/index.node.mjs
CHANGED
|
@@ -410,7 +410,7 @@ class Cache {
|
|
|
410
410
|
}
|
|
411
411
|
const cache = new Cache();
|
|
412
412
|
|
|
413
|
-
var version = "7.0.1-
|
|
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;
|
|
@@ -17753,16 +17754,18 @@ class Line extends FabricObject {
|
|
|
17753
17754
|
}
|
|
17754
17755
|
setCoords() {
|
|
17755
17756
|
if (this._useEndpointCoords) {
|
|
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
17757
|
// Set width and height for hit detection and bounding box
|
|
17762
17758
|
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17763
17759
|
const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
|
|
17764
17760
|
this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
|
|
17765
17761
|
this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
|
|
17762
|
+
|
|
17763
|
+
// Only update left/top if they haven't been explicitly set (e.g., during loading)
|
|
17764
|
+
if (this.left === 0 && this.top === 0) {
|
|
17765
|
+
const center = this._findCenterFromElement();
|
|
17766
|
+
this.left = center.x;
|
|
17767
|
+
this.top = center.y;
|
|
17768
|
+
}
|
|
17766
17769
|
}
|
|
17767
17770
|
super.setCoords();
|
|
17768
17771
|
}
|
|
@@ -17845,6 +17848,14 @@ class Line extends FabricObject {
|
|
|
17845
17848
|
this.x2 = newX;
|
|
17846
17849
|
this.y2 = newY;
|
|
17847
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
|
+
}
|
|
17848
17859
|
this.dirty = true;
|
|
17849
17860
|
this.setCoords();
|
|
17850
17861
|
(_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
|
|
@@ -17915,6 +17926,14 @@ class Line extends FabricObject {
|
|
|
17915
17926
|
if (coordProps.includes(key)) {
|
|
17916
17927
|
this._setWidthHeight();
|
|
17917
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
|
+
}
|
|
17918
17937
|
}
|
|
17919
17938
|
if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
|
|
17920
17939
|
const deltaX = this.left - oldLeft;
|
|
@@ -17925,6 +17944,14 @@ class Line extends FabricObject {
|
|
|
17925
17944
|
this.y1 += deltaY;
|
|
17926
17945
|
this.x2 += deltaX;
|
|
17927
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
|
+
}
|
|
17928
17955
|
this._updatingEndpoints = false;
|
|
17929
17956
|
}
|
|
17930
17957
|
}
|
|
@@ -17938,17 +17965,23 @@ class Line extends FabricObject {
|
|
|
17938
17965
|
super.render(ctx);
|
|
17939
17966
|
}
|
|
17940
17967
|
_renderDirectly(ctx) {
|
|
17941
|
-
var _this$stroke;
|
|
17942
17968
|
if (!this.visible) return;
|
|
17943
17969
|
ctx.save();
|
|
17944
17970
|
ctx.globalAlpha = this.opacity;
|
|
17945
|
-
ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
|
|
17946
17971
|
ctx.lineWidth = this.strokeWidth;
|
|
17947
17972
|
ctx.lineCap = this.strokeLineCap || 'butt';
|
|
17948
17973
|
ctx.beginPath();
|
|
17949
17974
|
ctx.moveTo(this.x1, this.y1);
|
|
17950
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
|
+
}
|
|
17951
17983
|
ctx.stroke();
|
|
17984
|
+
ctx.strokeStyle = origStrokeStyle;
|
|
17952
17985
|
ctx.restore();
|
|
17953
17986
|
}
|
|
17954
17987
|
_render(ctx) {
|
|
@@ -17970,6 +18003,15 @@ class Line extends FabricObject {
|
|
|
17970
18003
|
}
|
|
17971
18004
|
toObject() {
|
|
17972
18005
|
let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
18006
|
+
if (this._useEndpointCoords) {
|
|
18007
|
+
return {
|
|
18008
|
+
...super.toObject(propertiesToInclude),
|
|
18009
|
+
x1: this.x1,
|
|
18010
|
+
y1: this.y1,
|
|
18011
|
+
x2: this.x2,
|
|
18012
|
+
y2: this.y2
|
|
18013
|
+
};
|
|
18014
|
+
}
|
|
17973
18015
|
return {
|
|
17974
18016
|
...super.toObject(propertiesToInclude),
|
|
17975
18017
|
...this.calcLinePoints()
|
|
@@ -18014,7 +18056,15 @@ class Line extends FabricObject {
|
|
|
18014
18056
|
_toSVG() {
|
|
18015
18057
|
if (this._useEndpointCoords) {
|
|
18016
18058
|
// Use absolute coordinates to bypass all Fabric.js transforms
|
|
18017
|
-
|
|
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`];
|
|
18018
18068
|
} else {
|
|
18019
18069
|
// Use standard calcLinePoints for legacy mode
|
|
18020
18070
|
const {
|
|
@@ -18028,9 +18078,26 @@ class Line extends FabricObject {
|
|
|
18028
18078
|
}
|
|
18029
18079
|
toSVG(reviver) {
|
|
18030
18080
|
if (this._useEndpointCoords) {
|
|
18031
|
-
//
|
|
18032
|
-
|
|
18033
|
-
|
|
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;
|
|
18034
18101
|
}
|
|
18035
18102
|
// Use default behavior for legacy mode
|
|
18036
18103
|
return super.toSVG(reviver);
|