@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.cjs
CHANGED
|
@@ -412,7 +412,7 @@ class Cache {
|
|
|
412
412
|
}
|
|
413
413
|
const cache = new Cache();
|
|
414
414
|
|
|
415
|
-
var version = "7.0.1-
|
|
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;
|
|
@@ -17755,16 +17756,18 @@ class Line extends FabricObject {
|
|
|
17755
17756
|
}
|
|
17756
17757
|
setCoords() {
|
|
17757
17758
|
if (this._useEndpointCoords) {
|
|
17758
|
-
// Set the object's center to the geometric center of the line
|
|
17759
|
-
const center = this._findCenterFromElement();
|
|
17760
|
-
this.left = center.x;
|
|
17761
|
-
this.top = center.y;
|
|
17762
|
-
|
|
17763
17759
|
// Set width and height for hit detection and bounding box
|
|
17764
17760
|
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17765
17761
|
const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
|
|
17766
17762
|
this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
|
|
17767
17763
|
this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
|
|
17764
|
+
|
|
17765
|
+
// Only update left/top if they haven't been explicitly set (e.g., during loading)
|
|
17766
|
+
if (this.left === 0 && this.top === 0) {
|
|
17767
|
+
const center = this._findCenterFromElement();
|
|
17768
|
+
this.left = center.x;
|
|
17769
|
+
this.top = center.y;
|
|
17770
|
+
}
|
|
17768
17771
|
}
|
|
17769
17772
|
super.setCoords();
|
|
17770
17773
|
}
|
|
@@ -17847,6 +17850,14 @@ class Line extends FabricObject {
|
|
|
17847
17850
|
this.x2 = newX;
|
|
17848
17851
|
this.y2 = newY;
|
|
17849
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
|
+
}
|
|
17850
17861
|
this.dirty = true;
|
|
17851
17862
|
this.setCoords();
|
|
17852
17863
|
(_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 || _this$canvas3.requestRenderAll();
|
|
@@ -17917,6 +17928,14 @@ class Line extends FabricObject {
|
|
|
17917
17928
|
if (coordProps.includes(key)) {
|
|
17918
17929
|
this._setWidthHeight();
|
|
17919
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
|
+
}
|
|
17920
17939
|
}
|
|
17921
17940
|
if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
|
|
17922
17941
|
const deltaX = this.left - oldLeft;
|
|
@@ -17927,6 +17946,14 @@ class Line extends FabricObject {
|
|
|
17927
17946
|
this.y1 += deltaY;
|
|
17928
17947
|
this.x2 += deltaX;
|
|
17929
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
|
+
}
|
|
17930
17957
|
this._updatingEndpoints = false;
|
|
17931
17958
|
}
|
|
17932
17959
|
}
|
|
@@ -17940,17 +17967,23 @@ class Line extends FabricObject {
|
|
|
17940
17967
|
super.render(ctx);
|
|
17941
17968
|
}
|
|
17942
17969
|
_renderDirectly(ctx) {
|
|
17943
|
-
var _this$stroke;
|
|
17944
17970
|
if (!this.visible) return;
|
|
17945
17971
|
ctx.save();
|
|
17946
17972
|
ctx.globalAlpha = this.opacity;
|
|
17947
|
-
ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
|
|
17948
17973
|
ctx.lineWidth = this.strokeWidth;
|
|
17949
17974
|
ctx.lineCap = this.strokeLineCap || 'butt';
|
|
17950
17975
|
ctx.beginPath();
|
|
17951
17976
|
ctx.moveTo(this.x1, this.y1);
|
|
17952
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
|
+
}
|
|
17953
17985
|
ctx.stroke();
|
|
17986
|
+
ctx.strokeStyle = origStrokeStyle;
|
|
17954
17987
|
ctx.restore();
|
|
17955
17988
|
}
|
|
17956
17989
|
_render(ctx) {
|
|
@@ -17972,6 +18005,15 @@ class Line extends FabricObject {
|
|
|
17972
18005
|
}
|
|
17973
18006
|
toObject() {
|
|
17974
18007
|
let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
18008
|
+
if (this._useEndpointCoords) {
|
|
18009
|
+
return {
|
|
18010
|
+
...super.toObject(propertiesToInclude),
|
|
18011
|
+
x1: this.x1,
|
|
18012
|
+
y1: this.y1,
|
|
18013
|
+
x2: this.x2,
|
|
18014
|
+
y2: this.y2
|
|
18015
|
+
};
|
|
18016
|
+
}
|
|
17975
18017
|
return {
|
|
17976
18018
|
...super.toObject(propertiesToInclude),
|
|
17977
18019
|
...this.calcLinePoints()
|
|
@@ -18016,7 +18058,15 @@ class Line extends FabricObject {
|
|
|
18016
18058
|
_toSVG() {
|
|
18017
18059
|
if (this._useEndpointCoords) {
|
|
18018
18060
|
// Use absolute coordinates to bypass all Fabric.js transforms
|
|
18019
|
-
|
|
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`];
|
|
18020
18070
|
} else {
|
|
18021
18071
|
// Use standard calcLinePoints for legacy mode
|
|
18022
18072
|
const {
|
|
@@ -18030,9 +18080,26 @@ class Line extends FabricObject {
|
|
|
18030
18080
|
}
|
|
18031
18081
|
toSVG(reviver) {
|
|
18032
18082
|
if (this._useEndpointCoords) {
|
|
18033
|
-
//
|
|
18034
|
-
|
|
18035
|
-
|
|
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;
|
|
18036
18103
|
}
|
|
18037
18104
|
// Use default behavior for legacy mode
|
|
18038
18105
|
return super.toSVG(reviver);
|