@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/0
ADDED
|
File without changes
|
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-
|
|
363
|
+
var version = "7.0.1-beta5";
|
|
364
364
|
|
|
365
365
|
// use this syntax so babel plugin see this import here
|
|
366
366
|
const VERSION = version;
|
|
@@ -17577,33 +17577,29 @@
|
|
|
17577
17577
|
}
|
|
17578
17578
|
}
|
|
17579
17579
|
|
|
17580
|
-
// @TODO this code is terrible and Line should be a special case of polyline.
|
|
17581
|
-
|
|
17582
17580
|
const coordProps = ['x1', 'x2', 'y1', 'y2'];
|
|
17583
|
-
/**
|
|
17584
|
-
* A Class to draw a line
|
|
17585
|
-
* A bunch of methods will be added to Polyline to handle the line case
|
|
17586
|
-
* The line class is very strange to work with, is all special, it hardly aligns
|
|
17587
|
-
* to what a developer want everytime there is an angle
|
|
17588
|
-
* @deprecated
|
|
17589
|
-
*/
|
|
17590
17581
|
class Line extends FabricObject {
|
|
17591
|
-
/**
|
|
17592
|
-
* Constructor
|
|
17593
|
-
* @param {Array} [points] Array of points
|
|
17594
|
-
* @param {Object} [options] Options object
|
|
17595
|
-
* @return {Line} thisArg
|
|
17596
|
-
*/
|
|
17597
17582
|
constructor() {
|
|
17598
|
-
let [x1, y1, x2, y2] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0,
|
|
17583
|
+
let [x1, y1, x2, y2] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 100, 0];
|
|
17599
17584
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17600
17585
|
super();
|
|
17601
|
-
|
|
17586
|
+
_defineProperty(this, "hitStrokeWidth", 'auto');
|
|
17587
|
+
_defineProperty(this, "_updatingEndpoints", false);
|
|
17588
|
+
_defineProperty(this, "_useEndpointCoords", true);
|
|
17602
17589
|
this.setOptions(options);
|
|
17603
17590
|
this.x1 = x1;
|
|
17604
17591
|
this.x2 = x2;
|
|
17605
17592
|
this.y1 = y1;
|
|
17606
17593
|
this.y2 = y2;
|
|
17594
|
+
if (options.hitStrokeWidth !== undefined) {
|
|
17595
|
+
this.hitStrokeWidth = options.hitStrokeWidth;
|
|
17596
|
+
}
|
|
17597
|
+
this.hasBorders = false;
|
|
17598
|
+
this.hasControls = true;
|
|
17599
|
+
this.selectable = true;
|
|
17600
|
+
this.hoverCursor = 'move';
|
|
17601
|
+
this.perPixelTargetFind = false;
|
|
17602
|
+
this.strokeLineCap = 'butt';
|
|
17607
17603
|
this._setWidthHeight();
|
|
17608
17604
|
const {
|
|
17609
17605
|
left,
|
|
@@ -17611,96 +17607,323 @@
|
|
|
17611
17607
|
} = options;
|
|
17612
17608
|
typeof left === 'number' && this.set(LEFT, left);
|
|
17613
17609
|
typeof top === 'number' && this.set(TOP, top);
|
|
17610
|
+
this._setupLineControls();
|
|
17611
|
+
}
|
|
17612
|
+
_setupLineControls() {
|
|
17613
|
+
this.controls = {
|
|
17614
|
+
p1: new Control({
|
|
17615
|
+
x: 0,
|
|
17616
|
+
y: 0,
|
|
17617
|
+
cursorStyle: 'move',
|
|
17618
|
+
actionHandler: this._endpointActionHandler.bind(this),
|
|
17619
|
+
positionHandler: this._p1PositionHandler.bind(this),
|
|
17620
|
+
render: this._renderEndpointControl.bind(this),
|
|
17621
|
+
sizeX: 12,
|
|
17622
|
+
sizeY: 12
|
|
17623
|
+
}),
|
|
17624
|
+
p2: new Control({
|
|
17625
|
+
x: 0,
|
|
17626
|
+
y: 0,
|
|
17627
|
+
cursorStyle: 'move',
|
|
17628
|
+
actionHandler: this._endpointActionHandler.bind(this),
|
|
17629
|
+
positionHandler: this._p2PositionHandler.bind(this),
|
|
17630
|
+
render: this._renderEndpointControl.bind(this),
|
|
17631
|
+
sizeX: 12,
|
|
17632
|
+
sizeY: 12
|
|
17633
|
+
})
|
|
17634
|
+
};
|
|
17635
|
+
}
|
|
17636
|
+
_p1PositionHandler() {
|
|
17637
|
+
var _this$canvas;
|
|
17638
|
+
const vpt = ((_this$canvas = this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17639
|
+
return new Point(this.x1, this.y1).transform(vpt);
|
|
17640
|
+
}
|
|
17641
|
+
_p2PositionHandler() {
|
|
17642
|
+
var _this$canvas2;
|
|
17643
|
+
const vpt = ((_this$canvas2 = this.canvas) === null || _this$canvas2 === void 0 ? void 0 : _this$canvas2.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17644
|
+
return new Point(this.x2, this.y2).transform(vpt);
|
|
17645
|
+
}
|
|
17646
|
+
_renderEndpointControl(ctx, left, top) {
|
|
17647
|
+
const size = 12;
|
|
17648
|
+
ctx.save();
|
|
17649
|
+
ctx.fillStyle = '#007bff';
|
|
17650
|
+
ctx.strokeStyle = '#ffffff';
|
|
17651
|
+
ctx.lineWidth = 2;
|
|
17652
|
+
ctx.beginPath();
|
|
17653
|
+
ctx.arc(left, top, size / 2, 0, 2 * Math.PI);
|
|
17654
|
+
ctx.fill();
|
|
17655
|
+
ctx.stroke();
|
|
17656
|
+
ctx.restore();
|
|
17657
|
+
}
|
|
17658
|
+
drawBorders(ctx) {
|
|
17659
|
+
let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17660
|
+
if (this._useEndpointCoords) {
|
|
17661
|
+
this._drawLineBorders(ctx, styleOverride);
|
|
17662
|
+
return this;
|
|
17663
|
+
}
|
|
17664
|
+
return super.drawBorders(ctx, styleOverride, {});
|
|
17665
|
+
}
|
|
17666
|
+
_drawLineBorders(ctx) {
|
|
17667
|
+
var _this$canvas3;
|
|
17668
|
+
let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17669
|
+
const vpt = ((_this$canvas3 = this.canvas) === null || _this$canvas3 === void 0 ? void 0 : _this$canvas3.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17670
|
+
ctx.save();
|
|
17671
|
+
ctx.setTransform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
|
|
17672
|
+
ctx.strokeStyle = styleOverride.borderColor || this.borderColor || 'rgba(100, 200, 200, 0.5)';
|
|
17673
|
+
ctx.lineWidth = (this.strokeWidth || 1) + 5;
|
|
17674
|
+
ctx.lineCap = this.strokeLineCap || 'butt';
|
|
17675
|
+
ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
|
|
17676
|
+
ctx.beginPath();
|
|
17677
|
+
ctx.moveTo(this.x1, this.y1);
|
|
17678
|
+
ctx.lineTo(this.x2, this.y2);
|
|
17679
|
+
ctx.stroke();
|
|
17680
|
+
ctx.restore();
|
|
17681
|
+
}
|
|
17682
|
+
_renderControls(ctx) {
|
|
17683
|
+
let styleOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17684
|
+
ctx.save();
|
|
17685
|
+
ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
|
|
17686
|
+
this.drawControls(ctx, styleOverride);
|
|
17687
|
+
ctx.restore();
|
|
17688
|
+
}
|
|
17689
|
+
getBoundingRect() {
|
|
17690
|
+
if (this._useEndpointCoords) {
|
|
17691
|
+
const {
|
|
17692
|
+
x1,
|
|
17693
|
+
y1,
|
|
17694
|
+
x2,
|
|
17695
|
+
y2
|
|
17696
|
+
} = this;
|
|
17697
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17698
|
+
const padding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
|
|
17699
|
+
return {
|
|
17700
|
+
left: Math.min(x1, x2) - padding,
|
|
17701
|
+
top: Math.min(y1, y2) - padding,
|
|
17702
|
+
width: Math.abs(x2 - x1) + padding * 2 || padding * 2,
|
|
17703
|
+
height: Math.abs(y2 - y1) + padding * 2 || padding * 2
|
|
17704
|
+
};
|
|
17705
|
+
}
|
|
17706
|
+
return super.getBoundingRect();
|
|
17614
17707
|
}
|
|
17708
|
+
setCoords() {
|
|
17709
|
+
if (this._useEndpointCoords) {
|
|
17710
|
+
// Set the object's center to the geometric center of the line
|
|
17711
|
+
const center = this._findCenterFromElement();
|
|
17712
|
+
this.left = center.x;
|
|
17713
|
+
this.top = center.y;
|
|
17714
|
+
|
|
17715
|
+
// Set width and height for hit detection and bounding box
|
|
17716
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17717
|
+
const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
|
|
17718
|
+
this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
|
|
17719
|
+
this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
|
|
17720
|
+
}
|
|
17721
|
+
super.setCoords();
|
|
17722
|
+
}
|
|
17723
|
+
getCoords() {
|
|
17724
|
+
if (this._useEndpointCoords) {
|
|
17725
|
+
const deltaX = this.x2 - this.x1;
|
|
17726
|
+
const deltaY = this.y2 - this.y1;
|
|
17727
|
+
const length = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
17728
|
+
if (length === 0) {
|
|
17729
|
+
return super.getCoords();
|
|
17730
|
+
}
|
|
17731
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth;
|
|
17732
|
+
const halfWidth = Math.max(effectiveStrokeWidth / 2 + 2, 5);
|
|
17615
17733
|
|
|
17616
|
-
|
|
17617
|
-
|
|
17618
|
-
|
|
17619
|
-
|
|
17620
|
-
|
|
17621
|
-
|
|
17622
|
-
|
|
17623
|
-
|
|
17624
|
-
x2,
|
|
17625
|
-
y2
|
|
17626
|
-
} = this;
|
|
17627
|
-
this.width = Math.abs(x2 - x1);
|
|
17628
|
-
this.height = Math.abs(y2 - y1);
|
|
17629
|
-
const {
|
|
17630
|
-
left,
|
|
17631
|
-
top,
|
|
17632
|
-
width,
|
|
17633
|
-
height
|
|
17634
|
-
} = makeBoundingBoxFromPoints([{
|
|
17635
|
-
x: x1,
|
|
17636
|
-
y: y1
|
|
17637
|
-
}, {
|
|
17638
|
-
x: x2,
|
|
17639
|
-
y: y2
|
|
17640
|
-
}]);
|
|
17641
|
-
const position = new Point(left + width / 2, top + height / 2);
|
|
17642
|
-
this.setPositionByOrigin(position, CENTER, CENTER);
|
|
17734
|
+
// Unit vector perpendicular to line
|
|
17735
|
+
const perpX = -deltaY / length;
|
|
17736
|
+
const perpY = deltaX / length;
|
|
17737
|
+
|
|
17738
|
+
// Four corners of oriented rectangle
|
|
17739
|
+
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)];
|
|
17740
|
+
}
|
|
17741
|
+
return super.getCoords();
|
|
17643
17742
|
}
|
|
17743
|
+
containsPoint(point) {
|
|
17744
|
+
if (this._useEndpointCoords) {
|
|
17745
|
+
var _this$canvas4;
|
|
17746
|
+
if (((_this$canvas4 = this.canvas) === null || _this$canvas4 === void 0 ? void 0 : _this$canvas4.getActiveObject()) === this) {
|
|
17747
|
+
return super.containsPoint(point);
|
|
17748
|
+
}
|
|
17749
|
+
const distance = this._distanceToLineSegment(point.x, point.y);
|
|
17750
|
+
const effectiveStrokeWidth = this.hitStrokeWidth === 'auto' ? this.strokeWidth : this.hitStrokeWidth || 1;
|
|
17751
|
+
const tolerance = Math.max(effectiveStrokeWidth / 2 + 2, 5);
|
|
17752
|
+
return distance <= tolerance;
|
|
17753
|
+
}
|
|
17754
|
+
return super.containsPoint(point);
|
|
17755
|
+
}
|
|
17756
|
+
_distanceToLineSegment(px, py) {
|
|
17757
|
+
const x1 = this.x1,
|
|
17758
|
+
y1 = this.y1,
|
|
17759
|
+
x2 = this.x2,
|
|
17760
|
+
y2 = this.y2;
|
|
17761
|
+
const pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
|
|
17762
|
+
if (pd2 === 0) {
|
|
17763
|
+
return Math.sqrt((px - x1) * (px - x1) + (py - y1) * (py - y1));
|
|
17764
|
+
}
|
|
17765
|
+
const u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / pd2;
|
|
17766
|
+
let closestX, closestY;
|
|
17767
|
+
if (u < 0) {
|
|
17768
|
+
closestX = x1;
|
|
17769
|
+
closestY = y1;
|
|
17770
|
+
} else if (u > 1) {
|
|
17771
|
+
closestX = x2;
|
|
17772
|
+
closestY = y2;
|
|
17773
|
+
} else {
|
|
17774
|
+
closestX = x1 + u * (x2 - x1);
|
|
17775
|
+
closestY = y1 + u * (y2 - y1);
|
|
17776
|
+
}
|
|
17777
|
+
return Math.sqrt((px - closestX) * (px - closestX) + (py - closestY) * (py - closestY));
|
|
17778
|
+
}
|
|
17779
|
+
_endpointActionHandler(eventData, transformData, x, y) {
|
|
17780
|
+
var _this$canvas6;
|
|
17781
|
+
const controlKey = transformData.corner;
|
|
17782
|
+
const pointer = new Point(x, y);
|
|
17783
|
+
let newX = pointer.x;
|
|
17784
|
+
let newY = pointer.y;
|
|
17785
|
+
if (eventData.shiftKey) {
|
|
17786
|
+
const otherControl = controlKey === 'p1' ? 'p2' : 'p1';
|
|
17787
|
+
const otherX = this[otherControl === 'p1' ? 'x1' : 'x2'];
|
|
17788
|
+
const otherY = this[otherControl === 'p1' ? 'y1' : 'y2'];
|
|
17789
|
+
const snapped = this._snapToAngle(otherX, otherY, newX, newY);
|
|
17790
|
+
newX = snapped.x;
|
|
17791
|
+
newY = snapped.y;
|
|
17792
|
+
}
|
|
17793
|
+
if (this._useEndpointCoords) {
|
|
17794
|
+
var _this$canvas5;
|
|
17795
|
+
if (controlKey === 'p1') {
|
|
17796
|
+
this.x1 = newX;
|
|
17797
|
+
this.y1 = newY;
|
|
17798
|
+
} else if (controlKey === 'p2') {
|
|
17799
|
+
this.x2 = newX;
|
|
17800
|
+
this.y2 = newY;
|
|
17801
|
+
}
|
|
17802
|
+
this.dirty = true;
|
|
17803
|
+
this.setCoords();
|
|
17804
|
+
(_this$canvas5 = this.canvas) === null || _this$canvas5 === void 0 || _this$canvas5.requestRenderAll();
|
|
17805
|
+
return true;
|
|
17806
|
+
}
|
|
17644
17807
|
|
|
17645
|
-
|
|
17646
|
-
|
|
17647
|
-
|
|
17648
|
-
|
|
17649
|
-
|
|
17808
|
+
// Fallback for old system
|
|
17809
|
+
this._updatingEndpoints = true;
|
|
17810
|
+
if (controlKey === 'p1') {
|
|
17811
|
+
this.x1 = newX;
|
|
17812
|
+
this.y1 = newY;
|
|
17813
|
+
} else if (controlKey === 'p2') {
|
|
17814
|
+
this.x2 = newX;
|
|
17815
|
+
this.y2 = newY;
|
|
17816
|
+
}
|
|
17817
|
+
this._setWidthHeight();
|
|
17818
|
+
this.dirty = true;
|
|
17819
|
+
this._updatingEndpoints = false;
|
|
17820
|
+
(_this$canvas6 = this.canvas) === null || _this$canvas6 === void 0 || _this$canvas6.requestRenderAll();
|
|
17821
|
+
this.fire('modified', {
|
|
17822
|
+
transform: transformData,
|
|
17823
|
+
target: this,
|
|
17824
|
+
e: eventData
|
|
17825
|
+
});
|
|
17826
|
+
return true;
|
|
17827
|
+
}
|
|
17828
|
+
_snapToAngle(fromX, fromY, toX, toY) {
|
|
17829
|
+
const deltaX = toX - fromX;
|
|
17830
|
+
const deltaY = toY - fromY;
|
|
17831
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
17832
|
+
if (distance === 0) return {
|
|
17833
|
+
x: toX,
|
|
17834
|
+
y: toY
|
|
17835
|
+
};
|
|
17836
|
+
let angle = Math.atan2(deltaY, deltaX) * (180 / Math.PI);
|
|
17837
|
+
const snapIncrement = 15;
|
|
17838
|
+
const snappedAngle = Math.round(angle / snapIncrement) * snapIncrement;
|
|
17839
|
+
const snappedRadians = snappedAngle * (Math.PI / 180);
|
|
17840
|
+
return {
|
|
17841
|
+
x: fromX + Math.cos(snappedRadians) * distance,
|
|
17842
|
+
y: fromY + Math.sin(snappedRadians) * distance
|
|
17843
|
+
};
|
|
17844
|
+
}
|
|
17845
|
+
_setWidthHeight() {
|
|
17846
|
+
let skipReposition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
17847
|
+
this.width = Math.abs(this.x2 - this.x1) || 1;
|
|
17848
|
+
this.height = Math.abs(this.y2 - this.y1) || 1;
|
|
17849
|
+
if (!skipReposition && !this._updatingEndpoints) {
|
|
17850
|
+
const {
|
|
17851
|
+
left,
|
|
17852
|
+
top,
|
|
17853
|
+
width,
|
|
17854
|
+
height
|
|
17855
|
+
} = makeBoundingBoxFromPoints([{
|
|
17856
|
+
x: this.x1,
|
|
17857
|
+
y: this.y1
|
|
17858
|
+
}, {
|
|
17859
|
+
x: this.x2,
|
|
17860
|
+
y: this.y2
|
|
17861
|
+
}]);
|
|
17862
|
+
this.setPositionByOrigin(new Point(left + width / 2, top + height / 2), CENTER, CENTER);
|
|
17863
|
+
}
|
|
17864
|
+
}
|
|
17650
17865
|
_set(key, value) {
|
|
17866
|
+
const oldLeft = this.left;
|
|
17867
|
+
const oldTop = this.top;
|
|
17651
17868
|
super._set(key, value);
|
|
17652
17869
|
if (coordProps.includes(key)) {
|
|
17653
|
-
// this doesn't make sense very much, since setting x1 when top or left
|
|
17654
|
-
// are already set, is just going to show a strange result since the
|
|
17655
|
-
// line will move way more than the developer expect.
|
|
17656
|
-
// in fabric5 it worked only when the line didn't have extra transformations,
|
|
17657
|
-
// in fabric6 too. With extra transform they behave bad in different ways.
|
|
17658
|
-
// This needs probably a good rework or a tutorial if you have to create a dynamic line
|
|
17659
17870
|
this._setWidthHeight();
|
|
17871
|
+
this.dirty = true;
|
|
17872
|
+
}
|
|
17873
|
+
if ((key === 'left' || key === 'top') && this.canvas && !this._updatingEndpoints) {
|
|
17874
|
+
const deltaX = this.left - oldLeft;
|
|
17875
|
+
const deltaY = this.top - oldTop;
|
|
17876
|
+
if (deltaX !== 0 || deltaY !== 0) {
|
|
17877
|
+
this._updatingEndpoints = true;
|
|
17878
|
+
this.x1 += deltaX;
|
|
17879
|
+
this.y1 += deltaY;
|
|
17880
|
+
this.x2 += deltaX;
|
|
17881
|
+
this.y2 += deltaY;
|
|
17882
|
+
this._updatingEndpoints = false;
|
|
17883
|
+
}
|
|
17660
17884
|
}
|
|
17661
17885
|
return this;
|
|
17662
17886
|
}
|
|
17663
|
-
|
|
17664
|
-
|
|
17665
|
-
|
|
17666
|
-
|
|
17667
|
-
|
|
17887
|
+
render(ctx) {
|
|
17888
|
+
if (this._useEndpointCoords) {
|
|
17889
|
+
this._renderDirectly(ctx);
|
|
17890
|
+
return;
|
|
17891
|
+
}
|
|
17892
|
+
super.render(ctx);
|
|
17893
|
+
}
|
|
17894
|
+
_renderDirectly(ctx) {
|
|
17895
|
+
var _this$canvas7, _this$stroke;
|
|
17896
|
+
if (!this.visible) return;
|
|
17897
|
+
ctx.save();
|
|
17898
|
+
const vpt = ((_this$canvas7 = this.canvas) === null || _this$canvas7 === void 0 ? void 0 : _this$canvas7.viewportTransform) || [1, 0, 0, 1, 0, 0];
|
|
17899
|
+
ctx.transform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
|
|
17900
|
+
ctx.globalAlpha = this.opacity;
|
|
17901
|
+
ctx.strokeStyle = ((_this$stroke = this.stroke) === null || _this$stroke === void 0 ? void 0 : _this$stroke.toString()) || '#000';
|
|
17902
|
+
ctx.lineWidth = this.strokeWidth;
|
|
17903
|
+
ctx.lineCap = this.strokeLineCap || 'butt';
|
|
17904
|
+
ctx.beginPath();
|
|
17905
|
+
ctx.moveTo(this.x1, this.y1);
|
|
17906
|
+
ctx.lineTo(this.x2, this.y2);
|
|
17907
|
+
ctx.stroke();
|
|
17908
|
+
ctx.restore();
|
|
17909
|
+
}
|
|
17668
17910
|
_render(ctx) {
|
|
17911
|
+
if (this._useEndpointCoords) return;
|
|
17669
17912
|
ctx.beginPath();
|
|
17670
17913
|
const p = this.calcLinePoints();
|
|
17671
17914
|
ctx.moveTo(p.x1, p.y1);
|
|
17672
17915
|
ctx.lineTo(p.x2, p.y2);
|
|
17673
17916
|
ctx.lineWidth = this.strokeWidth;
|
|
17674
|
-
|
|
17675
|
-
// TODO: test this
|
|
17676
|
-
// make sure setting "fill" changes color of a line
|
|
17677
|
-
// (by copying fillStyle to strokeStyle, since line is stroked, not filled)
|
|
17678
17917
|
const origStrokeStyle = ctx.strokeStyle;
|
|
17679
17918
|
if (isFiller(this.stroke)) {
|
|
17680
17919
|
ctx.strokeStyle = this.stroke.toLive(ctx);
|
|
17681
|
-
} else {
|
|
17682
|
-
var _this$stroke;
|
|
17683
|
-
ctx.strokeStyle = (_this$stroke = this.stroke) !== null && _this$stroke !== void 0 ? _this$stroke : ctx.fillStyle;
|
|
17684
17920
|
}
|
|
17685
17921
|
this.stroke && this._renderStroke(ctx);
|
|
17686
17922
|
ctx.strokeStyle = origStrokeStyle;
|
|
17687
17923
|
}
|
|
17688
|
-
|
|
17689
|
-
/**
|
|
17690
|
-
* This function is an helper for svg import. it returns the center of the object in the svg
|
|
17691
|
-
* untransformed coordinates
|
|
17692
|
-
* @private
|
|
17693
|
-
* @return {Point} center point from element coordinates
|
|
17694
|
-
*/
|
|
17695
17924
|
_findCenterFromElement() {
|
|
17696
17925
|
return new Point((this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2);
|
|
17697
17926
|
}
|
|
17698
|
-
|
|
17699
|
-
/**
|
|
17700
|
-
* Returns object representation of an instance
|
|
17701
|
-
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
17702
|
-
* @return {Object} object representation of an instance
|
|
17703
|
-
*/
|
|
17704
17927
|
toObject() {
|
|
17705
17928
|
let propertiesToInclude = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
17706
17929
|
return {
|
|
@@ -17708,32 +17931,25 @@
|
|
|
17708
17931
|
...this.calcLinePoints()
|
|
17709
17932
|
};
|
|
17710
17933
|
}
|
|
17711
|
-
|
|
17712
|
-
/*
|
|
17713
|
-
* Calculate object dimensions from its properties
|
|
17714
|
-
* @private
|
|
17715
|
-
*/
|
|
17716
17934
|
_getNonTransformedDimensions() {
|
|
17717
17935
|
const dim = super._getNonTransformedDimensions();
|
|
17718
|
-
if (this.strokeLineCap === '
|
|
17719
|
-
|
|
17720
|
-
|
|
17721
|
-
}
|
|
17722
|
-
if (this.height === 0) {
|
|
17723
|
-
dim.x -= this.strokeWidth;
|
|
17724
|
-
}
|
|
17936
|
+
if (this.strokeLineCap === 'round') {
|
|
17937
|
+
dim.x += this.strokeWidth;
|
|
17938
|
+
dim.y += this.strokeWidth;
|
|
17725
17939
|
}
|
|
17726
17940
|
return dim;
|
|
17727
17941
|
}
|
|
17728
|
-
|
|
17729
|
-
/**
|
|
17730
|
-
* Recalculates line points given width and height
|
|
17731
|
-
* Those points are simply placed around the center,
|
|
17732
|
-
* This is not useful outside internal render functions and svg output
|
|
17733
|
-
* Is not meant to be for the developer.
|
|
17734
|
-
* @private
|
|
17735
|
-
*/
|
|
17736
17942
|
calcLinePoints() {
|
|
17943
|
+
if (this._updatingEndpoints) {
|
|
17944
|
+
const centerX = (this.x1 + this.x2) / 2;
|
|
17945
|
+
const centerY = (this.y1 + this.y2) / 2;
|
|
17946
|
+
return {
|
|
17947
|
+
x1: this.x1 - centerX,
|
|
17948
|
+
y1: this.y1 - centerY,
|
|
17949
|
+
x2: this.x2 - centerX,
|
|
17950
|
+
y2: this.y2 - centerY
|
|
17951
|
+
};
|
|
17952
|
+
}
|
|
17737
17953
|
const {
|
|
17738
17954
|
x1: _x1,
|
|
17739
17955
|
x2: _x2,
|
|
@@ -17742,48 +17958,39 @@
|
|
|
17742
17958
|
width,
|
|
17743
17959
|
height
|
|
17744
17960
|
} = this;
|
|
17745
|
-
const xMult = _x1 <= _x2 ? -1 : 1
|
|
17746
|
-
|
|
17747
|
-
x1 = xMult * width / 2,
|
|
17748
|
-
y1 = yMult * height / 2,
|
|
17749
|
-
x2 = xMult * -width / 2,
|
|
17750
|
-
y2 = yMult * -height / 2;
|
|
17961
|
+
const xMult = _x1 <= _x2 ? -1 : 1;
|
|
17962
|
+
const yMult = _y1 <= _y2 ? -1 : 1;
|
|
17751
17963
|
return {
|
|
17752
|
-
x1,
|
|
17753
|
-
|
|
17754
|
-
|
|
17755
|
-
y2
|
|
17964
|
+
x1: xMult * width / 2,
|
|
17965
|
+
y1: yMult * height / 2,
|
|
17966
|
+
x2: xMult * -width / 2,
|
|
17967
|
+
y2: yMult * -height / 2
|
|
17756
17968
|
};
|
|
17757
17969
|
}
|
|
17758
|
-
|
|
17759
|
-
/* _FROM_SVG_START_ */
|
|
17760
|
-
|
|
17761
|
-
/**
|
|
17762
|
-
* Returns svg representation of an instance
|
|
17763
|
-
* @return {Array} an array of strings with the specific svg representation
|
|
17764
|
-
* of the instance
|
|
17765
|
-
*/
|
|
17766
17970
|
_toSVG() {
|
|
17767
|
-
|
|
17768
|
-
|
|
17769
|
-
x2
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17971
|
+
if (this._useEndpointCoords) {
|
|
17972
|
+
// Use absolute coordinates to bypass all Fabric.js transforms
|
|
17973
|
+
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`];
|
|
17974
|
+
} else {
|
|
17975
|
+
// Use standard calcLinePoints for legacy mode
|
|
17976
|
+
const {
|
|
17977
|
+
x1,
|
|
17978
|
+
x2,
|
|
17979
|
+
y1,
|
|
17980
|
+
y2
|
|
17981
|
+
} = this.calcLinePoints();
|
|
17982
|
+
return ['<line ', 'COMMON_PARTS', `x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" />\n`];
|
|
17983
|
+
}
|
|
17984
|
+
}
|
|
17985
|
+
toSVG(reviver) {
|
|
17986
|
+
if (this._useEndpointCoords) {
|
|
17987
|
+
// Override toSVG to prevent Fabric.js from adding transform wrapper
|
|
17988
|
+
const markup = this._toSVG().join('');
|
|
17989
|
+
return reviver ? reviver(markup) : markup;
|
|
17990
|
+
}
|
|
17991
|
+
// Use default behavior for legacy mode
|
|
17992
|
+
return super.toSVG(reviver);
|
|
17774
17993
|
}
|
|
17775
|
-
|
|
17776
|
-
/**
|
|
17777
|
-
* List of attribute names to account for when parsing SVG element (used by {@link Line.fromElement})
|
|
17778
|
-
* @see http://www.w3.org/TR/SVG/shapes.html#LineElement
|
|
17779
|
-
*/
|
|
17780
|
-
|
|
17781
|
-
/**
|
|
17782
|
-
* Returns Line instance from an SVG element
|
|
17783
|
-
* @param {HTMLElement} element Element to parse
|
|
17784
|
-
* @param {Object} [options] Options object
|
|
17785
|
-
* @param {Function} [callback] callback function invoked after parsing
|
|
17786
|
-
*/
|
|
17787
17994
|
static async fromElement(element, options, cssRules) {
|
|
17788
17995
|
const {
|
|
17789
17996
|
x1 = 0,
|
|
@@ -17794,14 +18001,6 @@
|
|
|
17794
18001
|
} = parseAttributes(element, this.ATTRIBUTE_NAMES, cssRules);
|
|
17795
18002
|
return new this([x1, y1, x2, y2], parsedAttributes);
|
|
17796
18003
|
}
|
|
17797
|
-
|
|
17798
|
-
/* _FROM_SVG_END_ */
|
|
17799
|
-
|
|
17800
|
-
/**
|
|
17801
|
-
* Returns Line instance from an object representation
|
|
17802
|
-
* @param {Object} object Object to create an instance from
|
|
17803
|
-
* @returns {Promise<Line>}
|
|
17804
|
-
*/
|
|
17805
18004
|
static fromObject(_ref) {
|
|
17806
18005
|
let {
|
|
17807
18006
|
x1,
|
|
@@ -17818,22 +18017,6 @@
|
|
|
17818
18017
|
});
|
|
17819
18018
|
}
|
|
17820
18019
|
}
|
|
17821
|
-
/**
|
|
17822
|
-
* x value or first line edge
|
|
17823
|
-
* @type number
|
|
17824
|
-
*/
|
|
17825
|
-
/**
|
|
17826
|
-
* y value or first line edge
|
|
17827
|
-
* @type number
|
|
17828
|
-
*/
|
|
17829
|
-
/**
|
|
17830
|
-
* x value or second line edge
|
|
17831
|
-
* @type number
|
|
17832
|
-
*/
|
|
17833
|
-
/**
|
|
17834
|
-
* y value or second line edge
|
|
17835
|
-
* @type number
|
|
17836
|
-
*/
|
|
17837
18020
|
_defineProperty(Line, "type", 'Line');
|
|
17838
18021
|
_defineProperty(Line, "cacheProperties", [...cacheProperties, ...coordProps]);
|
|
17839
18022
|
_defineProperty(Line, "ATTRIBUTE_NAMES", SHARED_ATTRIBUTES.concat(coordProps));
|