@nasser-sw/fabric 7.0.1-beta3 → 7.0.1-beta5
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/0 +0 -0
- package/dist/index.js +345 -162
- 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 +345 -162
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +345 -162
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +345 -162
- 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 +32 -86
- 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 +345 -161
- package/dist/src/shapes/Line.mjs.map +1 -1
- package/dist-extensions/src/shapes/CustomLine.d.ts +10 -0
- package/dist-extensions/src/shapes/CustomLine.d.ts.map +1 -0
- package/dist-extensions/src/shapes/Line.d.ts +32 -86
- package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
- package/fabric-test-editor.html +157 -8
- package/fabric-test2.html +513 -0
- package/fabric.ts +182 -182
- package/package.json +1 -1
- package/src/shapes/Line.ts +397 -164
- package/debug/konva/CHANGELOG.md +0 -1474
- package/debug/konva/LICENSE +0 -22
- package/debug/konva/README.md +0 -205
- package/debug/konva/gulpfile.mjs +0 -110
- package/debug/konva/package.json +0 -139
- package/debug/konva/release.sh +0 -65
- package/debug/konva/resources/doc-includes/ContainerParams.txt +0 -6
- package/debug/konva/resources/doc-includes/NodeParams.txt +0 -20
- package/debug/konva/resources/doc-includes/ShapeParams.txt +0 -53
- package/debug/konva/resources/jsdoc.conf.json +0 -28
- package/debug/konva/rollup.config.mjs +0 -32
- package/debug/konva/src/Animation.ts +0 -237
- package/debug/konva/src/BezierFunctions.ts +0 -826
- package/debug/konva/src/Canvas.ts +0 -193
- package/debug/konva/src/Container.ts +0 -649
- package/debug/konva/src/Context.ts +0 -1017
- package/debug/konva/src/Core.ts +0 -5
- package/debug/konva/src/DragAndDrop.ts +0 -173
- package/debug/konva/src/Factory.ts +0 -246
- package/debug/konva/src/FastLayer.ts +0 -29
- package/debug/konva/src/Global.ts +0 -210
- package/debug/konva/src/Group.ts +0 -31
- package/debug/konva/src/Layer.ts +0 -546
- package/debug/konva/src/Node.ts +0 -3477
- package/debug/konva/src/PointerEvents.ts +0 -67
- package/debug/konva/src/Shape.ts +0 -2081
- package/debug/konva/src/Stage.ts +0 -1000
- package/debug/konva/src/Tween.ts +0 -811
- package/debug/konva/src/Util.ts +0 -1123
- package/debug/konva/src/Validators.ts +0 -210
- package/debug/konva/src/_CoreInternals.ts +0 -85
- package/debug/konva/src/_FullInternals.ts +0 -171
- package/debug/konva/src/canvas-backend.ts +0 -36
- package/debug/konva/src/filters/Blur.ts +0 -388
- package/debug/konva/src/filters/Brighten.ts +0 -48
- package/debug/konva/src/filters/Brightness.ts +0 -30
- package/debug/konva/src/filters/Contrast.ts +0 -75
- package/debug/konva/src/filters/Emboss.ts +0 -207
- package/debug/konva/src/filters/Enhance.ts +0 -154
- package/debug/konva/src/filters/Grayscale.ts +0 -25
- package/debug/konva/src/filters/HSL.ts +0 -108
- package/debug/konva/src/filters/HSV.ts +0 -106
- package/debug/konva/src/filters/Invert.ts +0 -23
- package/debug/konva/src/filters/Kaleidoscope.ts +0 -274
- package/debug/konva/src/filters/Mask.ts +0 -220
- package/debug/konva/src/filters/Noise.ts +0 -44
- package/debug/konva/src/filters/Pixelate.ts +0 -107
- package/debug/konva/src/filters/Posterize.ts +0 -46
- package/debug/konva/src/filters/RGB.ts +0 -82
- package/debug/konva/src/filters/RGBA.ts +0 -103
- package/debug/konva/src/filters/Sepia.ts +0 -27
- package/debug/konva/src/filters/Solarize.ts +0 -29
- package/debug/konva/src/filters/Threshold.ts +0 -44
- package/debug/konva/src/index.ts +0 -3
- package/debug/konva/src/shapes/Arc.ts +0 -176
- package/debug/konva/src/shapes/Arrow.ts +0 -231
- package/debug/konva/src/shapes/Circle.ts +0 -76
- package/debug/konva/src/shapes/Ellipse.ts +0 -121
- package/debug/konva/src/shapes/Image.ts +0 -319
- package/debug/konva/src/shapes/Label.ts +0 -386
- package/debug/konva/src/shapes/Line.ts +0 -364
- package/debug/konva/src/shapes/Path.ts +0 -1013
- package/debug/konva/src/shapes/Rect.ts +0 -79
- package/debug/konva/src/shapes/RegularPolygon.ts +0 -167
- package/debug/konva/src/shapes/Ring.ts +0 -94
- package/debug/konva/src/shapes/Sprite.ts +0 -370
- package/debug/konva/src/shapes/Star.ts +0 -125
- package/debug/konva/src/shapes/Text.ts +0 -1065
- package/debug/konva/src/shapes/TextPath.ts +0 -583
- package/debug/konva/src/shapes/Transformer.ts +0 -1889
- package/debug/konva/src/shapes/Wedge.ts +0 -129
- package/debug/konva/src/skia-backend.ts +0 -35
- package/debug/konva/src/types.ts +0 -84
- package/debug/konva/tsconfig.json +0 -31
- package/debug/konva/tsconfig.test.json +0 -7
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-beta5";
|
|
414
414
|
|
|
415
415
|
// use this syntax so babel plugin see this import here
|
|
416
416
|
const VERSION = version;
|
|
@@ -17627,33 +17627,29 @@ class PatternBrush extends PencilBrush {
|
|
|
17627
17627
|
}
|
|
17628
17628
|
}
|
|
17629
17629
|
|
|
17630
|
-
// @TODO this code is terrible and Line should be a special case of polyline.
|
|
17631
|
-
|
|
17632
17630
|
const coordProps = ['x1', 'x2', 'y1', 'y2'];
|
|
17633
|
-
/**
|
|
17634
|
-
* A Class to draw a line
|
|
17635
|
-
* A bunch of methods will be added to Polyline to handle the line case
|
|
17636
|
-
* The line class is very strange to work with, is all special, it hardly aligns
|
|
17637
|
-
* to what a developer want everytime there is an angle
|
|
17638
|
-
* @deprecated
|
|
17639
|
-
*/
|
|
17640
17631
|
class Line extends FabricObject {
|
|
17641
|
-
/**
|
|
17642
|
-
* Constructor
|
|
17643
|
-
* @param {Array} [points] Array of points
|
|
17644
|
-
* @param {Object} [options] Options object
|
|
17645
|
-
* @return {Line} thisArg
|
|
17646
|
-
*/
|
|
17647
17632
|
constructor() {
|
|
17648
|
-
let [x1, y1, x2, y2] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0,
|
|
17633
|
+
let [x1, y1, x2, y2] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 100, 0];
|
|
17649
17634
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17650
17635
|
super();
|
|
17651
|
-
|
|
17636
|
+
_defineProperty(this, "hitStrokeWidth", 'auto');
|
|
17637
|
+
_defineProperty(this, "_updatingEndpoints", false);
|
|
17638
|
+
_defineProperty(this, "_useEndpointCoords", true);
|
|
17652
17639
|
this.setOptions(options);
|
|
17653
17640
|
this.x1 = x1;
|
|
17654
17641
|
this.x2 = x2;
|
|
17655
17642
|
this.y1 = y1;
|
|
17656
17643
|
this.y2 = y2;
|
|
17644
|
+
if (options.hitStrokeWidth !== undefined) {
|
|
17645
|
+
this.hitStrokeWidth = options.hitStrokeWidth;
|
|
17646
|
+
}
|
|
17647
|
+
this.hasBorders = false;
|
|
17648
|
+
this.hasControls = true;
|
|
17649
|
+
this.selectable = true;
|
|
17650
|
+
this.hoverCursor = 'move';
|
|
17651
|
+
this.perPixelTargetFind = false;
|
|
17652
|
+
this.strokeLineCap = 'butt';
|
|
17657
17653
|
this._setWidthHeight();
|
|
17658
17654
|
const {
|
|
17659
17655
|
left,
|
|
@@ -17661,96 +17657,323 @@ class Line extends FabricObject {
|
|
|
17661
17657
|
} = options;
|
|
17662
17658
|
typeof left === 'number' && this.set(LEFT, left);
|
|
17663
17659
|
typeof top === 'number' && this.set(TOP, top);
|
|
17660
|
+
this._setupLineControls();
|
|
17661
|
+
}
|
|
17662
|
+
_setupLineControls() {
|
|
17663
|
+
this.controls = {
|
|
17664
|
+
p1: new Control({
|
|
17665
|
+
x: 0,
|
|
17666
|
+
y: 0,
|
|
17667
|
+
cursorStyle: 'move',
|
|
17668
|
+
actionHandler: this._endpointActionHandler.bind(this),
|
|
17669
|
+
positionHandler: this._p1PositionHandler.bind(this),
|
|
17670
|
+
render: this._renderEndpointControl.bind(this),
|
|
17671
|
+
sizeX: 12,
|
|
17672
|
+
sizeY: 12
|
|
17673
|
+
}),
|
|
17674
|
+
p2: new Control({
|
|
17675
|
+
x: 0,
|
|
17676
|
+
y: 0,
|
|
17677
|
+
cursorStyle: 'move',
|
|
17678
|
+
actionHandler: this._endpointActionHandler.bind(this),
|
|
17679
|
+
positionHandler: this._p2PositionHandler.bind(this),
|
|
17680
|
+
render: this._renderEndpointControl.bind(this),
|
|
17681
|
+
sizeX: 12,
|
|
17682
|
+
sizeY: 12
|
|
17683
|
+
})
|
|
17684
|
+
};
|
|
17685
|
+
}
|
|
17686
|
+
_p1PositionHandler() {
|
|
17687
|
+
var _this$canvas;
|
|
17688
|
+
const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17689
|
+
return new Point(this.x1, this.y1).transform(vpt);
|
|
17690
|
+
}
|
|
17691
|
+
_p2PositionHandler() {
|
|
17692
|
+
var _this$canvas2;
|
|
17693
|
+
const vpt = ((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17694
|
+
return new Point(this.x2, this.y2).transform(vpt);
|
|
17695
|
+
}
|
|
17696
|
+
_renderEndpointControl(ctx, left, top) {
|
|
17697
|
+
const size = 12;
|
|
17698
|
+
ctx.save();
|
|
17699
|
+
ctx.fillStyle = '#007bff';
|
|
17700
|
+
ctx.strokeStyle = '#ffffff';
|
|
17701
|
+
ctx.lineWidth = 2;
|
|
17702
|
+
ctx.beginPath();
|
|
17703
|
+
ctx.arc(left, top, size / 2, 0, 2 * Math.PI);
|
|
17704
|
+
ctx.fill();
|
|
17705
|
+
ctx.stroke();
|
|
17706
|
+
ctx.restore();
|
|
17707
|
+
}
|
|
17708
|
+
drawBorders(ctx) {
|
|
17709
|
+
let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17710
|
+
if (this._useEndpointCoords) {
|
|
17711
|
+
this._drawLineBorders(ctx, styleOverride);
|
|
17712
|
+
return this;
|
|
17713
|
+
}
|
|
17714
|
+
return super.drawBorders(ctx, styleOverride, {});
|
|
17715
|
+
}
|
|
17716
|
+
_drawLineBorders(ctx) {
|
|
17717
|
+
var _this$canvas3;
|
|
17718
|
+
let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17719
|
+
const vpt = ((_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 ? void 0 : _this$canvas3.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17720
|
+
ctx.save();
|
|
17721
|
+
ctx.setTransform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
|
|
17722
|
+
ctx.strokeStyle = styleOverride.borderColor || this.borderColor || 'rgba(100, 200, 200, 0.5)';
|
|
17723
|
+
ctx.lineWidth = (this.strokeWidth || 1) + 5;
|
|
17724
|
+
ctx.lineCap = this.strokeLineCap || 'butt';
|
|
17725
|
+
ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
|
|
17726
|
+
ctx.beginPath();
|
|
17727
|
+
ctx.moveTo(this.x1, this.y1);
|
|
17728
|
+
ctx.lineTo(this.x2, this.y2);
|
|
17729
|
+
ctx.stroke();
|
|
17730
|
+
ctx.restore();
|
|
17731
|
+
}
|
|
17732
|
+
_renderControls(ctx) {
|
|
17733
|
+
let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17734
|
+
ctx.save();
|
|
17735
|
+
ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
|
|
17736
|
+
this.drawControls(ctx, styleOverride);
|
|
17737
|
+
ctx.restore();
|
|
17738
|
+
}
|
|
17739
|
+
getBoundingRect() {
|
|
17740
|
+
if (this._useEndpointCoords) {
|
|
17741
|
+
const {
|
|
17742
|
+
x1,
|
|
17743
|
+
y1,
|
|
17744
|
+
x2,
|
|
17745
|
+
y2
|
|
17746
|
+
} = this;
|
|
17747
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17748
|
+
const padding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
|
|
17749
|
+
return {
|
|
17750
|
+
left: Math.min(x1, x2) - padding,
|
|
17751
|
+
top: Math.min(y1, y2) - padding,
|
|
17752
|
+
width: Math.abs(x2 - x1) + padding * 2 || padding * 2,
|
|
17753
|
+
height: Math.abs(y2 - y1) + padding * 2 || padding * 2
|
|
17754
|
+
};
|
|
17755
|
+
}
|
|
17756
|
+
return super.getBoundingRect();
|
|
17664
17757
|
}
|
|
17758
|
+
setCoords() {
|
|
17759
|
+
if (this._useEndpointCoords) {
|
|
17760
|
+
// Set the object's center to the geometric center of the line
|
|
17761
|
+
const center = this._findCenterFromElement();
|
|
17762
|
+
this.left = center.x;
|
|
17763
|
+
this.top = center.y;
|
|
17764
|
+
|
|
17765
|
+
// Set width and height for hit detection and bounding box
|
|
17766
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17767
|
+
const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
|
|
17768
|
+
this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
|
|
17769
|
+
this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
|
|
17770
|
+
}
|
|
17771
|
+
super.setCoords();
|
|
17772
|
+
}
|
|
17773
|
+
getCoords() {
|
|
17774
|
+
if (this._useEndpointCoords) {
|
|
17775
|
+
const deltaX = this.x2 - this.x1;
|
|
17776
|
+
const deltaY = this.y2 - this.y1;
|
|
17777
|
+
const length = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
17778
|
+
if (length === 0) {
|
|
17779
|
+
return super.getCoords();
|
|
17780
|
+
}
|
|
17781
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17782
|
+
const halfWidth = Math.max(effectiveStrokeWidth / 2 + 2, 5);
|
|
17665
17783
|
|
|
17666
|
-
|
|
17667
|
-
|
|
17668
|
-
|
|
17669
|
-
|
|
17670
|
-
|
|
17671
|
-
|
|
17672
|
-
|
|
17673
|
-
|
|
17674
|
-
x2,
|
|
17675
|
-
y2
|
|
17676
|
-
} = this;
|
|
17677
|
-
this.width = Math.abs(x2 - x1);
|
|
17678
|
-
this.height = Math.abs(y2 - y1);
|
|
17679
|
-
const {
|
|
17680
|
-
left,
|
|
17681
|
-
top,
|
|
17682
|
-
width,
|
|
17683
|
-
height
|
|
17684
|
-
} = makeBoundingBoxFromPoints([{
|
|
17685
|
-
x: x1,
|
|
17686
|
-
y: y1
|
|
17687
|
-
}, {
|
|
17688
|
-
x: x2,
|
|
17689
|
-
y: y2
|
|
17690
|
-
}]);
|
|
17691
|
-
const position = new Point(left + width / 2, top + height / 2);
|
|
17692
|
-
this.setPositionByOrigin(position, CENTER, CENTER);
|
|
17784
|
+
// Unit vector perpendicular to line
|
|
17785
|
+
const perpX = -deltaY / length;
|
|
17786
|
+
const perpY = deltaX / length;
|
|
17787
|
+
|
|
17788
|
+
// Four corners of oriented rectangle
|
|
17789
|
+
return [new Point(this.x1 + perpX * halfWidth, this.y1 + perpY * halfWidth), new Point(this.x2 + perpX * halfWidth, this.y2 + perpY * halfWidth), new Point(this.x2 - perpX * halfWidth, this.y2 - perpY * halfWidth), new Point(this.x1 - perpX * halfWidth, this.y1 - perpY * halfWidth)];
|
|
17790
|
+
}
|
|
17791
|
+
return super.getCoords();
|
|
17693
17792
|
}
|
|
17793
|
+
containsPoint(point) {
|
|
17794
|
+
if (this._useEndpointCoords) {
|
|
17795
|
+
var _this$canvas4;
|
|
17796
|
+
if (((_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 ? void 0 : _this$canvas4.getActiveObject()) === this) {
|
|
17797
|
+
return super.containsPoint(point);
|
|
17798
|
+
}
|
|
17799
|
+
const distance = this._distanceToLineSegment(point.x, point.y);
|
|
17800
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth || 1;
|
|
17801
|
+
const tolerance = Math.max(effectiveStrokeWidth / 2 + 2, 5);
|
|
17802
|
+
return distance <= tolerance;
|
|
17803
|
+
}
|
|
17804
|
+
return super.containsPoint(point);
|
|
17805
|
+
}
|
|
17806
|
+
_distanceToLineSegment(px, py) {
|
|
17807
|
+
const x1 = this.x1,
|
|
17808
|
+
y1 = this.y1,
|
|
17809
|
+
x2 = this.x2,
|
|
17810
|
+
y2 = this.y2;
|
|
17811
|
+
const pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
|
|
17812
|
+
if (pd2 === 0) {
|
|
17813
|
+
return Math.sqrt((px - x1) * (px - x1) + (py - y1) * (py - y1));
|
|
17814
|
+
}
|
|
17815
|
+
const u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / pd2;
|
|
17816
|
+
let closestX, closestY;
|
|
17817
|
+
if (u < 0) {
|
|
17818
|
+
closestX = x1;
|
|
17819
|
+
closestY = y1;
|
|
17820
|
+
} else if (u > 1) {
|
|
17821
|
+
closestX = x2;
|
|
17822
|
+
closestY = y2;
|
|
17823
|
+
} else {
|
|
17824
|
+
closestX = x1 + u * (x2 - x1);
|
|
17825
|
+
closestY = y1 + u * (y2 - y1);
|
|
17826
|
+
}
|
|
17827
|
+
return Math.sqrt((px - closestX) * (px - closestX) + (py - closestY) * (py - closestY));
|
|
17828
|
+
}
|
|
17829
|
+
_endpointActionHandler(eventData, transformData, x, y) {
|
|
17830
|
+
var _this$canvas6;
|
|
17831
|
+
const controlKey = transformData.corner;
|
|
17832
|
+
const pointer = new Point(x, y);
|
|
17833
|
+
let newX = pointer.x;
|
|
17834
|
+
let newY = pointer.y;
|
|
17835
|
+
if (eventData.shiftKey) {
|
|
17836
|
+
const otherControl = controlKey === 'p1' ? 'p2' : 'p1';
|
|
17837
|
+
const otherX = this[otherControl === 'p1' ? 'x1' : 'x2'];
|
|
17838
|
+
const otherY = this[otherControl === 'p1' ? 'y1' : 'y2'];
|
|
17839
|
+
const snapped = this._snapToAngle(otherX, otherY, newX, newY);
|
|
17840
|
+
newX = snapped.x;
|
|
17841
|
+
newY = snapped.y;
|
|
17842
|
+
}
|
|
17843
|
+
if (this._useEndpointCoords) {
|
|
17844
|
+
var _this$canvas5;
|
|
17845
|
+
if (controlKey === 'p1') {
|
|
17846
|
+
this.x1 = newX;
|
|
17847
|
+
this.y1 = newY;
|
|
17848
|
+
} else if (controlKey === 'p2') {
|
|
17849
|
+
this.x2 = newX;
|
|
17850
|
+
this.y2 = newY;
|
|
17851
|
+
}
|
|
17852
|
+
this.dirty = true;
|
|
17853
|
+
this.setCoords();
|
|
17854
|
+
(_this$canvas5 = this.canvas) === null || _this$canvas5 === void 0 || _this$canvas5.requestRenderAll();
|
|
17855
|
+
return true;
|
|
17856
|
+
}
|
|
17694
17857
|
|
|
17695
|
-
|
|
17696
|
-
|
|
17697
|
-
|
|
17698
|
-
|
|
17699
|
-
|
|
17858
|
+
// Fallback for old system
|
|
17859
|
+
this._updatingEndpoints = true;
|
|
17860
|
+
if (controlKey === 'p1') {
|
|
17861
|
+
this.x1 = newX;
|
|
17862
|
+
this.y1 = newY;
|
|
17863
|
+
} else if (controlKey === 'p2') {
|
|
17864
|
+
this.x2 = newX;
|
|
17865
|
+
this.y2 = newY;
|
|
17866
|
+
}
|
|
17867
|
+
this._setWidthHeight();
|
|
17868
|
+
this.dirty = true;
|
|
17869
|
+
this._updatingEndpoints = false;
|
|
17870
|
+
(_this$canvas6 = this.canvas) === null || _this$canvas6 === void 0 || _this$canvas6.requestRenderAll();
|
|
17871
|
+
this.fire('modified', {
|
|
17872
|
+
transform: transformData,
|
|
17873
|
+
target: this,
|
|
17874
|
+
e: eventData
|
|
17875
|
+
});
|
|
17876
|
+
return true;
|
|
17877
|
+
}
|
|
17878
|
+
_snapToAngle(fromX, fromY, toX, toY) {
|
|
17879
|
+
const deltaX = toX - fromX;
|
|
17880
|
+
const deltaY = toY - fromY;
|
|
17881
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
17882
|
+
if (distance === 0) return {
|
|
17883
|
+
x: toX,
|
|
17884
|
+
y: toY
|
|
17885
|
+
};
|
|
17886
|
+
let angle = Math.atan2(deltaY, deltaX) * (180 / Math.PI);
|
|
17887
|
+
const snapIncrement = 15;
|
|
17888
|
+
const snappedAngle = Math.round(angle / snapIncrement) * snapIncrement;
|
|
17889
|
+
const snappedRadians = snappedAngle * (Math.PI / 180);
|
|
17890
|
+
return {
|
|
17891
|
+
x: fromX + Math.cos(snappedRadians) * distance,
|
|
17892
|
+
y: fromY + Math.sin(snappedRadians) * distance
|
|
17893
|
+
};
|
|
17894
|
+
}
|
|
17895
|
+
_setWidthHeight() {
|
|
17896
|
+
let skipReposition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
17897
|
+
this.width = Math.abs(this.x2 - this.x1) || 1;
|
|
17898
|
+
this.height = Math.abs(this.y2 - this.y1) || 1;
|
|
17899
|
+
if (!skipReposition && !this._updatingEndpoints) {
|
|
17900
|
+
const {
|
|
17901
|
+
left,
|
|
17902
|
+
top,
|
|
17903
|
+
width,
|
|
17904
|
+
height
|
|
17905
|
+
} = makeBoundingBoxFromPoints([{
|
|
17906
|
+
x: this.x1,
|
|
17907
|
+
y: this.y1
|
|
17908
|
+
}, {
|
|
17909
|
+
x: this.x2,
|
|
17910
|
+
y: this.y2
|
|
17911
|
+
}]);
|
|
17912
|
+
this.setPositionByOrigin(new Point(left + width / 2, top + height / 2), CENTER, CENTER);
|
|
17913
|
+
}
|
|
17914
|
+
}
|
|
17700
17915
|
_set(key, value) {
|
|
17916
|
+
const oldLeft = this.left;
|
|
17917
|
+
const oldTop = this.top;
|
|
17701
17918
|
super._set(key, value);
|
|
17702
17919
|
if (coordProps.includes(key)) {
|
|
17703
|
-
// this doesn't make sense very much, since setting x1 when top or left
|
|
17704
|
-
// are already set, is just going to show a strange result since the
|
|
17705
|
-
// line will move way more than the developer expect.
|
|
17706
|
-
// in fabric5 it worked only when the line didn't have extra transformations,
|
|
17707
|
-
// in fabric6 too. With extra transform they behave bad in different ways.
|
|
17708
|
-
// This needs probably a good rework or a tutorial if you have to create a dynamic line
|
|
17709
17920
|
this._setWidthHeight();
|
|
17921
|
+
this.dirty = true;
|
|
17922
|
+
}
|
|
17923
|
+
if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
|
|
17924
|
+
const deltaX = this.left - oldLeft;
|
|
17925
|
+
const deltaY = this.top - oldTop;
|
|
17926
|
+
if (deltaX !== 0 || deltaY !== 0) {
|
|
17927
|
+
this._updatingEndpoints = true;
|
|
17928
|
+
this.x1 += deltaX;
|
|
17929
|
+
this.y1 += deltaY;
|
|
17930
|
+
this.x2 += deltaX;
|
|
17931
|
+
this.y2 += deltaY;
|
|
17932
|
+
this._updatingEndpoints = false;
|
|
17933
|
+
}
|
|
17710
17934
|
}
|
|
17711
17935
|
return this;
|
|
17712
17936
|
}
|
|
17713
|
-
|
|
17714
|
-
|
|
17715
|
-
|
|
17716
|
-
|
|
17717
|
-
|
|
17937
|
+
render(ctx) {
|
|
17938
|
+
if (this._useEndpointCoords) {
|
|
17939
|
+
this._renderDirectly(ctx);
|
|
17940
|
+
return;
|
|
17941
|
+
}
|
|
17942
|
+
super.render(ctx);
|
|
17943
|
+
}
|
|
17944
|
+
_renderDirectly(ctx) {
|
|
17945
|
+
var _this$canvas7, _this$stroke;
|
|
17946
|
+
if (!this.visible) return;
|
|
17947
|
+
ctx.save();
|
|
17948
|
+
const vpt = ((_this$canvas7 = this.canvas) === null || _this$canvas7 === void 0 ? void 0 : _this$canvas7.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17949
|
+
ctx.transform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
|
|
17950
|
+
ctx.globalAlpha = this.opacity;
|
|
17951
|
+
ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
|
|
17952
|
+
ctx.lineWidth = this.strokeWidth;
|
|
17953
|
+
ctx.lineCap = this.strokeLineCap || 'butt';
|
|
17954
|
+
ctx.beginPath();
|
|
17955
|
+
ctx.moveTo(this.x1, this.y1);
|
|
17956
|
+
ctx.lineTo(this.x2, this.y2);
|
|
17957
|
+
ctx.stroke();
|
|
17958
|
+
ctx.restore();
|
|
17959
|
+
}
|
|
17718
17960
|
_render(ctx) {
|
|
17961
|
+
if (this._useEndpointCoords) return;
|
|
17719
17962
|
ctx.beginPath();
|
|
17720
17963
|
const p = this.calcLinePoints();
|
|
17721
17964
|
ctx.moveTo(p.x1, p.y1);
|
|
17722
17965
|
ctx.lineTo(p.x2, p.y2);
|
|
17723
17966
|
ctx.lineWidth = this.strokeWidth;
|
|
17724
|
-
|
|
17725
|
-
// TODO: test this
|
|
17726
|
-
// make sure setting "fill" changes color of a line
|
|
17727
|
-
// (by copying fillStyle to strokeStyle, since line is stroked, not filled)
|
|
17728
17967
|
const origStrokeStyle = ctx.strokeStyle;
|
|
17729
17968
|
if (isFiller(this.stroke)) {
|
|
17730
17969
|
ctx.strokeStyle = this.stroke.toLive(ctx);
|
|
17731
|
-
} else {
|
|
17732
|
-
var _this$stroke;
|
|
17733
|
-
ctx.strokeStyle = (_this$stroke = this.stroke) !== null && _this$stroke !== void 0 ? _this$stroke : ctx.fillStyle;
|
|
17734
17970
|
}
|
|
17735
17971
|
this.stroke && this._renderStroke(ctx);
|
|
17736
17972
|
ctx.strokeStyle = origStrokeStyle;
|
|
17737
17973
|
}
|
|
17738
|
-
|
|
17739
|
-
/**
|
|
17740
|
-
* This function is an helper for svg import. it returns the center of the object in the svg
|
|
17741
|
-
* untransformed coordinates
|
|
17742
|
-
* @private
|
|
17743
|
-
* @return {Point} center point from element coordinates
|
|
17744
|
-
*/
|
|
17745
17974
|
_findCenterFromElement() {
|
|
17746
17975
|
return new Point((this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2);
|
|
17747
17976
|
}
|
|
17748
|
-
|
|
17749
|
-
/**
|
|
17750
|
-
* Returns object representation of an instance
|
|
17751
|
-
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
17752
|
-
* @return {Object} object representation of an instance
|
|
17753
|
-
*/
|
|
17754
17977
|
toObject() {
|
|
17755
17978
|
let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
17756
17979
|
return {
|
|
@@ -17758,32 +17981,25 @@ class Line extends FabricObject {
|
|
|
17758
17981
|
...this.calcLinePoints()
|
|
17759
17982
|
};
|
|
17760
17983
|
}
|
|
17761
|
-
|
|
17762
|
-
/*
|
|
17763
|
-
* Calculate object dimensions from its properties
|
|
17764
|
-
* @private
|
|
17765
|
-
*/
|
|
17766
17984
|
_getNonTransformedDimensions() {
|
|
17767
17985
|
const dim = super._getNonTransformedDimensions();
|
|
17768
|
-
if (this.strokeLineCap === '
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
}
|
|
17772
|
-
if (this.height === 0) {
|
|
17773
|
-
dim.x -= this.strokeWidth;
|
|
17774
|
-
}
|
|
17986
|
+
if (this.strokeLineCap === 'round') {
|
|
17987
|
+
dim.x += this.strokeWidth;
|
|
17988
|
+
dim.y += this.strokeWidth;
|
|
17775
17989
|
}
|
|
17776
17990
|
return dim;
|
|
17777
17991
|
}
|
|
17778
|
-
|
|
17779
|
-
/**
|
|
17780
|
-
* Recalculates line points given width and height
|
|
17781
|
-
* Those points are simply placed around the center,
|
|
17782
|
-
* This is not useful outside internal render functions and svg output
|
|
17783
|
-
* Is not meant to be for the developer.
|
|
17784
|
-
* @private
|
|
17785
|
-
*/
|
|
17786
17992
|
calcLinePoints() {
|
|
17993
|
+
if (this._updatingEndpoints) {
|
|
17994
|
+
const centerX = (this.x1 + this.x2) / 2;
|
|
17995
|
+
const centerY = (this.y1 + this.y2) / 2;
|
|
17996
|
+
return {
|
|
17997
|
+
x1: this.x1 - centerX,
|
|
17998
|
+
y1: this.y1 - centerY,
|
|
17999
|
+
x2: this.x2 - centerX,
|
|
18000
|
+
y2: this.y2 - centerY
|
|
18001
|
+
};
|
|
18002
|
+
}
|
|
17787
18003
|
const {
|
|
17788
18004
|
x1: _x1,
|
|
17789
18005
|
x2: _x2,
|
|
@@ -17792,48 +18008,39 @@ class Line extends FabricObject {
|
|
|
17792
18008
|
width,
|
|
17793
18009
|
height
|
|
17794
18010
|
} = this;
|
|
17795
|
-
const xMult = _x1 <= _x2 ? -1 : 1
|
|
17796
|
-
|
|
17797
|
-
x1 = xMult * width / 2,
|
|
17798
|
-
y1 = yMult * height / 2,
|
|
17799
|
-
x2 = xMult * -width / 2,
|
|
17800
|
-
y2 = yMult * -height / 2;
|
|
18011
|
+
const xMult = _x1 <= _x2 ? -1 : 1;
|
|
18012
|
+
const yMult = _y1 <= _y2 ? -1 : 1;
|
|
17801
18013
|
return {
|
|
17802
|
-
x1,
|
|
17803
|
-
|
|
17804
|
-
|
|
17805
|
-
y2
|
|
18014
|
+
x1: xMult * width / 2,
|
|
18015
|
+
y1: yMult * height / 2,
|
|
18016
|
+
x2: xMult * -width / 2,
|
|
18017
|
+
y2: yMult * -height / 2
|
|
17806
18018
|
};
|
|
17807
18019
|
}
|
|
17808
|
-
|
|
17809
|
-
/* _FROM_SVG_START_ */
|
|
17810
|
-
|
|
17811
|
-
/**
|
|
17812
|
-
* Returns svg representation of an instance
|
|
17813
|
-
* @return {Array} an array of strings with the specific svg representation
|
|
17814
|
-
* of the instance
|
|
17815
|
-
*/
|
|
17816
18020
|
_toSVG() {
|
|
17817
|
-
|
|
17818
|
-
|
|
17819
|
-
x2
|
|
17820
|
-
|
|
17821
|
-
|
|
17822
|
-
|
|
17823
|
-
|
|
18021
|
+
if (this._useEndpointCoords) {
|
|
18022
|
+
// Use absolute coordinates to bypass all Fabric.js transforms
|
|
18023
|
+
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`];
|
|
18024
|
+
} else {
|
|
18025
|
+
// Use standard calcLinePoints for legacy mode
|
|
18026
|
+
const {
|
|
18027
|
+
x1,
|
|
18028
|
+
x2,
|
|
18029
|
+
y1,
|
|
18030
|
+
y2
|
|
18031
|
+
} = this.calcLinePoints();
|
|
18032
|
+
return ['<line ', 'COMMON_PARTS', `x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" />\n`];
|
|
18033
|
+
}
|
|
18034
|
+
}
|
|
18035
|
+
toSVG(reviver) {
|
|
18036
|
+
if (this._useEndpointCoords) {
|
|
18037
|
+
// Override toSVG to prevent Fabric.js from adding transform wrapper
|
|
18038
|
+
const markup = this._toSVG().join('');
|
|
18039
|
+
return reviver ? reviver(markup) : markup;
|
|
18040
|
+
}
|
|
18041
|
+
// Use default behavior for legacy mode
|
|
18042
|
+
return super.toSVG(reviver);
|
|
17824
18043
|
}
|
|
17825
|
-
|
|
17826
|
-
/**
|
|
17827
|
-
* List of attribute names to account for when parsing SVG element (used by {@link Line.fromElement})
|
|
17828
|
-
* @see http://www.w3.org/TR/SVG/shapes.html#LineElement
|
|
17829
|
-
*/
|
|
17830
|
-
|
|
17831
|
-
/**
|
|
17832
|
-
* Returns Line instance from an SVG element
|
|
17833
|
-
* @param {HTMLElement} element Element to parse
|
|
17834
|
-
* @param {Object} [options] Options object
|
|
17835
|
-
* @param {Function} [callback] callback function invoked after parsing
|
|
17836
|
-
*/
|
|
17837
18044
|
static async fromElement(element, options, cssRules) {
|
|
17838
18045
|
const {
|
|
17839
18046
|
x1 = 0,
|
|
@@ -17844,14 +18051,6 @@ class Line extends FabricObject {
|
|
|
17844
18051
|
} = parseAttributes(element, this.ATTRIBUTE_NAMES, cssRules);
|
|
17845
18052
|
return new this([x1, y1, x2, y2], parsedAttributes);
|
|
17846
18053
|
}
|
|
17847
|
-
|
|
17848
|
-
/* _FROM_SVG_END_ */
|
|
17849
|
-
|
|
17850
|
-
/**
|
|
17851
|
-
* Returns Line instance from an object representation
|
|
17852
|
-
* @param {Object} object Object to create an instance from
|
|
17853
|
-
* @returns {Promise<Line>}
|
|
17854
|
-
*/
|
|
17855
18054
|
static fromObject(_ref) {
|
|
17856
18055
|
let {
|
|
17857
18056
|
x1,
|
|
@@ -17868,22 +18067,6 @@ class Line extends FabricObject {
|
|
|
17868
18067
|
});
|
|
17869
18068
|
}
|
|
17870
18069
|
}
|
|
17871
|
-
/**
|
|
17872
|
-
* x value or first line edge
|
|
17873
|
-
* @type number
|
|
17874
|
-
*/
|
|
17875
|
-
/**
|
|
17876
|
-
* y value or first line edge
|
|
17877
|
-
* @type number
|
|
17878
|
-
*/
|
|
17879
|
-
/**
|
|
17880
|
-
* x value or second line edge
|
|
17881
|
-
* @type number
|
|
17882
|
-
*/
|
|
17883
|
-
/**
|
|
17884
|
-
* y value or second line edge
|
|
17885
|
-
* @type number
|
|
17886
|
-
*/
|
|
17887
18070
|
_defineProperty(Line, "type", 'Line');
|
|
17888
18071
|
_defineProperty(Line, "cacheProperties", [...cacheProperties, ...coordProps]);
|
|
17889
18072
|
_defineProperty(Line, "ATTRIBUTE_NAMES", SHARED_ATTRIBUTES.concat(coordProps));
|