konva 8.4.2 → 9.0.0
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/README.md +1 -9
- package/konva.js +17669 -16968
- package/konva.min.js +3 -3
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +11 -7
- package/lib/BezierFunctions.d.ts +6 -0
- package/lib/BezierFunctions.js +791 -0
- package/lib/Canvas.d.ts +2 -1
- package/lib/Canvas.js +26 -18
- package/lib/Container.d.ts +4 -4
- package/lib/Container.js +16 -12
- package/lib/Context.d.ts +16 -13
- package/lib/Context.js +27 -19
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +7 -3
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +25 -22
- package/lib/Factory.js +27 -24
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +10 -6
- package/lib/Global.js +16 -12
- package/lib/Group.d.ts +3 -3
- package/lib/Group.js +10 -6
- package/lib/Layer.d.ts +9 -9
- package/lib/Layer.js +37 -33
- package/lib/Node.d.ts +8 -8
- package/lib/Node.js +95 -90
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +15 -7
- package/lib/Shape.d.ts +6 -4
- package/lib/Shape.js +90 -86
- package/lib/Stage.d.ts +7 -7
- package/lib/Stage.js +51 -47
- package/lib/Tween.d.ts +2 -2
- package/lib/Tween.js +26 -22
- package/lib/Util.d.ts +2 -2
- package/lib/Util.js +29 -25
- package/lib/Validators.js +58 -44
- package/lib/_CoreInternals.d.ts +29 -29
- package/lib/_CoreInternals.js +36 -33
- package/lib/_FullInternals.d.ts +67 -67
- package/lib/_FullInternals.js +78 -75
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +9 -5
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +9 -5
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +9 -5
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +14 -10
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +9 -5
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +5 -1
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +11 -7
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +11 -7
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +5 -1
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +13 -9
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +9 -5
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +9 -5
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +11 -7
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +9 -5
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +11 -7
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +12 -8
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +5 -1
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +5 -1
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +9 -5
- package/lib/index-node.d.ts +1 -1
- package/lib/index-node.js +7 -5
- package/lib/index-types.d.ts +124 -124
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -2
- package/lib/shapes/Arc.d.ts +6 -5
- package/lib/shapes/Arc.js +17 -13
- package/lib/shapes/Arrow.d.ts +5 -4
- package/lib/shapes/Arrow.js +17 -13
- package/lib/shapes/Circle.d.ts +6 -5
- package/lib/shapes/Circle.js +11 -7
- package/lib/shapes/Ellipse.d.ts +6 -5
- package/lib/shapes/Ellipse.js +13 -9
- package/lib/shapes/Image.d.ts +5 -5
- package/lib/shapes/Image.js +21 -17
- package/lib/shapes/Label.d.ts +8 -7
- package/lib/shapes/Label.js +18 -13
- package/lib/shapes/Line.d.ts +3 -3
- package/lib/shapes/Line.js +14 -10
- package/lib/shapes/Path.d.ts +6 -3
- package/lib/shapes/Path.js +44 -43
- package/lib/shapes/Rect.d.ts +3 -3
- package/lib/shapes/Rect.js +13 -9
- package/lib/shapes/RegularPolygon.d.ts +6 -5
- package/lib/shapes/RegularPolygon.js +12 -8
- package/lib/shapes/Ring.d.ts +6 -5
- package/lib/shapes/Ring.js +12 -8
- package/lib/shapes/Sprite.d.ts +7 -6
- package/lib/shapes/Sprite.js +19 -15
- package/lib/shapes/Star.d.ts +6 -5
- package/lib/shapes/Star.js +13 -9
- package/lib/shapes/Text.d.ts +8 -7
- package/lib/shapes/Text.js +31 -26
- package/lib/shapes/TextPath.d.ts +12 -7
- package/lib/shapes/TextPath.js +82 -188
- package/lib/shapes/Transformer.d.ts +10 -10
- package/lib/shapes/Transformer.js +92 -81
- package/lib/shapes/Wedge.d.ts +6 -5
- package/lib/shapes/Wedge.js +16 -12
- package/lib/types.d.ts +6 -0
- package/lib/types.js +5 -2
- package/package.json +13 -42
- package/cmj/Animation.d.ts +0 -24
- package/cmj/Animation.js +0 -145
- package/cmj/Canvas.d.ts +0 -32
- package/cmj/Canvas.js +0 -114
- package/cmj/Container.d.ts +0 -47
- package/cmj/Container.js +0 -325
- package/cmj/Context.d.ts +0 -84
- package/cmj/Context.js +0 -538
- package/cmj/Core.d.ts +0 -3
- package/cmj/Core.js +0 -7
- package/cmj/DragAndDrop.d.ts +0 -17
- package/cmj/DragAndDrop.js +0 -111
- package/cmj/Factory.d.ts +0 -11
- package/cmj/Factory.js +0 -125
- package/cmj/FastLayer.d.ts +0 -4
- package/cmj/FastLayer.js +0 -16
- package/cmj/Global.d.ts +0 -34
- package/cmj/Global.js +0 -61
- package/cmj/Group.d.ts +0 -8
- package/cmj/Group.js +0 -17
- package/cmj/Layer.d.ts +0 -61
- package/cmj/Layer.js +0 -309
- package/cmj/Node.d.ts +0 -328
- package/cmj/Node.js +0 -1420
- package/cmj/PointerEvents.d.ts +0 -11
- package/cmj/PointerEvents.js +0 -45
- package/cmj/Shape.d.ts +0 -184
- package/cmj/Shape.js +0 -521
- package/cmj/Stage.d.ts +0 -85
- package/cmj/Stage.js +0 -692
- package/cmj/Tween.d.ts +0 -86
- package/cmj/Tween.js +0 -520
- package/cmj/Util.d.ts +0 -91
- package/cmj/Util.js +0 -801
- package/cmj/Validators.d.ts +0 -11
- package/cmj/Validators.js +0 -192
- package/cmj/_CoreInternals.d.ts +0 -152
- package/cmj/_CoreInternals.js +0 -37
- package/cmj/_FullInternals.d.ts +0 -196
- package/cmj/_FullInternals.js +0 -81
- package/cmj/filters/Blur.d.ts +0 -2
- package/cmj/filters/Blur.js +0 -701
- package/cmj/filters/Brighten.d.ts +0 -2
- package/cmj/filters/Brighten.js +0 -16
- package/cmj/filters/Contrast.d.ts +0 -2
- package/cmj/filters/Contrast.js +0 -38
- package/cmj/filters/Emboss.d.ts +0 -2
- package/cmj/filters/Emboss.js +0 -106
- package/cmj/filters/Enhance.d.ts +0 -2
- package/cmj/filters/Enhance.js +0 -87
- package/cmj/filters/Grayscale.d.ts +0 -2
- package/cmj/filters/Grayscale.js +0 -13
- package/cmj/filters/HSL.d.ts +0 -2
- package/cmj/filters/HSL.js +0 -28
- package/cmj/filters/HSV.d.ts +0 -2
- package/cmj/filters/HSV.js +0 -28
- package/cmj/filters/Invert.d.ts +0 -2
- package/cmj/filters/Invert.js +0 -12
- package/cmj/filters/Kaleidoscope.d.ts +0 -2
- package/cmj/filters/Kaleidoscope.js +0 -137
- package/cmj/filters/Mask.d.ts +0 -2
- package/cmj/filters/Mask.js +0 -144
- package/cmj/filters/Noise.d.ts +0 -2
- package/cmj/filters/Noise.js +0 -16
- package/cmj/filters/Pixelate.d.ts +0 -2
- package/cmj/filters/Pixelate.js +0 -64
- package/cmj/filters/Posterize.d.ts +0 -2
- package/cmj/filters/Posterize.js +0 -14
- package/cmj/filters/RGB.d.ts +0 -2
- package/cmj/filters/RGB.js +0 -43
- package/cmj/filters/RGBA.d.ts +0 -2
- package/cmj/filters/RGBA.js +0 -53
- package/cmj/filters/Sepia.d.ts +0 -2
- package/cmj/filters/Sepia.js +0 -15
- package/cmj/filters/Solarize.d.ts +0 -2
- package/cmj/filters/Solarize.js +0 -29
- package/cmj/filters/Threshold.d.ts +0 -2
- package/cmj/filters/Threshold.js +0 -14
- package/cmj/index-node.d.ts +0 -2
- package/cmj/index-node.js +0 -21
- package/cmj/index-types.d.ts +0 -181
- package/cmj/index.d.ts +0 -2
- package/cmj/index.js +0 -4
- package/cmj/package.json +0 -6
- package/cmj/shapes/Arc.d.ts +0 -25
- package/cmj/shapes/Arc.js +0 -59
- package/cmj/shapes/Arrow.d.ts +0 -25
- package/cmj/shapes/Arrow.js +0 -103
- package/cmj/shapes/Circle.d.ts +0 -13
- package/cmj/shapes/Circle.js +0 -37
- package/cmj/shapes/Ellipse.d.ts +0 -16
- package/cmj/shapes/Ellipse.js +0 -41
- package/cmj/shapes/Image.d.ts +0 -25
- package/cmj/shapes/Image.js +0 -117
- package/cmj/shapes/Label.d.ts +0 -35
- package/cmj/shapes/Label.js +0 -178
- package/cmj/shapes/Line.d.ts +0 -28
- package/cmj/shapes/Line.js +0 -159
- package/cmj/shapes/Path.d.ts +0 -37
- package/cmj/shapes/Path.js +0 -631
- package/cmj/shapes/Rect.d.ts +0 -10
- package/cmj/shapes/Rect.js +0 -26
- package/cmj/shapes/RegularPolygon.d.ts +0 -22
- package/cmj/shapes/RegularPolygon.js +0 -69
- package/cmj/shapes/Ring.d.ts +0 -15
- package/cmj/shapes/Ring.js +0 -37
- package/cmj/shapes/Sprite.d.ts +0 -30
- package/cmj/shapes/Sprite.js +0 -112
- package/cmj/shapes/Star.d.ts +0 -17
- package/cmj/shapes/Star.js +0 -42
- package/cmj/shapes/Text.d.ts +0 -62
- package/cmj/shapes/Text.js +0 -373
- package/cmj/shapes/TextPath.d.ts +0 -55
- package/cmj/shapes/TextPath.js +0 -351
- package/cmj/shapes/Transformer.d.ts +0 -116
- package/cmj/shapes/Transformer.js +0 -964
- package/cmj/shapes/Wedge.d.ts +0 -17
- package/cmj/shapes/Wedge.js +0 -42
- package/cmj/types.d.ts +0 -50
- package/cmj/types.js +0 -25
|
@@ -1,964 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Transformer = void 0;
|
|
4
|
-
const Util_1 = require("../Util");
|
|
5
|
-
const Factory_1 = require("../Factory");
|
|
6
|
-
const Node_1 = require("../Node");
|
|
7
|
-
const Shape_1 = require("../Shape");
|
|
8
|
-
const Rect_1 = require("./Rect");
|
|
9
|
-
const Group_1 = require("../Group");
|
|
10
|
-
const Global_1 = require("../Global");
|
|
11
|
-
const Validators_1 = require("../Validators");
|
|
12
|
-
const Global_2 = require("../Global");
|
|
13
|
-
var EVENTS_NAME = 'tr-konva';
|
|
14
|
-
var ATTR_CHANGE_LIST = [
|
|
15
|
-
'resizeEnabledChange',
|
|
16
|
-
'rotateAnchorOffsetChange',
|
|
17
|
-
'rotateEnabledChange',
|
|
18
|
-
'enabledAnchorsChange',
|
|
19
|
-
'anchorSizeChange',
|
|
20
|
-
'borderEnabledChange',
|
|
21
|
-
'borderStrokeChange',
|
|
22
|
-
'borderStrokeWidthChange',
|
|
23
|
-
'borderDashChange',
|
|
24
|
-
'anchorStrokeChange',
|
|
25
|
-
'anchorStrokeWidthChange',
|
|
26
|
-
'anchorFillChange',
|
|
27
|
-
'anchorCornerRadiusChange',
|
|
28
|
-
'ignoreStrokeChange',
|
|
29
|
-
]
|
|
30
|
-
.map((e) => e + `.${EVENTS_NAME}`)
|
|
31
|
-
.join(' ');
|
|
32
|
-
var NODES_RECT = 'nodesRect';
|
|
33
|
-
var TRANSFORM_CHANGE_STR = [
|
|
34
|
-
'widthChange',
|
|
35
|
-
'heightChange',
|
|
36
|
-
'scaleXChange',
|
|
37
|
-
'scaleYChange',
|
|
38
|
-
'skewXChange',
|
|
39
|
-
'skewYChange',
|
|
40
|
-
'rotationChange',
|
|
41
|
-
'offsetXChange',
|
|
42
|
-
'offsetYChange',
|
|
43
|
-
'transformsEnabledChange',
|
|
44
|
-
'strokeWidthChange',
|
|
45
|
-
];
|
|
46
|
-
var ANGLES = {
|
|
47
|
-
'top-left': -45,
|
|
48
|
-
'top-center': 0,
|
|
49
|
-
'top-right': 45,
|
|
50
|
-
'middle-right': -90,
|
|
51
|
-
'middle-left': 90,
|
|
52
|
-
'bottom-left': -135,
|
|
53
|
-
'bottom-center': 180,
|
|
54
|
-
'bottom-right': 135,
|
|
55
|
-
};
|
|
56
|
-
const TOUCH_DEVICE = 'ontouchstart' in Global_1.Konva._global;
|
|
57
|
-
function getCursor(anchorName, rad) {
|
|
58
|
-
if (anchorName === 'rotater') {
|
|
59
|
-
return 'crosshair';
|
|
60
|
-
}
|
|
61
|
-
rad += Util_1.Util.degToRad(ANGLES[anchorName] || 0);
|
|
62
|
-
var angle = ((Util_1.Util.radToDeg(rad) % 360) + 360) % 360;
|
|
63
|
-
if (Util_1.Util._inRange(angle, 315 + 22.5, 360) || Util_1.Util._inRange(angle, 0, 22.5)) {
|
|
64
|
-
return 'ns-resize';
|
|
65
|
-
}
|
|
66
|
-
else if (Util_1.Util._inRange(angle, 45 - 22.5, 45 + 22.5)) {
|
|
67
|
-
return 'nesw-resize';
|
|
68
|
-
}
|
|
69
|
-
else if (Util_1.Util._inRange(angle, 90 - 22.5, 90 + 22.5)) {
|
|
70
|
-
return 'ew-resize';
|
|
71
|
-
}
|
|
72
|
-
else if (Util_1.Util._inRange(angle, 135 - 22.5, 135 + 22.5)) {
|
|
73
|
-
return 'nwse-resize';
|
|
74
|
-
}
|
|
75
|
-
else if (Util_1.Util._inRange(angle, 180 - 22.5, 180 + 22.5)) {
|
|
76
|
-
return 'ns-resize';
|
|
77
|
-
}
|
|
78
|
-
else if (Util_1.Util._inRange(angle, 225 - 22.5, 225 + 22.5)) {
|
|
79
|
-
return 'nesw-resize';
|
|
80
|
-
}
|
|
81
|
-
else if (Util_1.Util._inRange(angle, 270 - 22.5, 270 + 22.5)) {
|
|
82
|
-
return 'ew-resize';
|
|
83
|
-
}
|
|
84
|
-
else if (Util_1.Util._inRange(angle, 315 - 22.5, 315 + 22.5)) {
|
|
85
|
-
return 'nwse-resize';
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
Util_1.Util.error('Transformer has unknown angle for cursor detection: ' + angle);
|
|
89
|
-
return 'pointer';
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
var ANCHORS_NAMES = [
|
|
93
|
-
'top-left',
|
|
94
|
-
'top-center',
|
|
95
|
-
'top-right',
|
|
96
|
-
'middle-right',
|
|
97
|
-
'middle-left',
|
|
98
|
-
'bottom-left',
|
|
99
|
-
'bottom-center',
|
|
100
|
-
'bottom-right',
|
|
101
|
-
];
|
|
102
|
-
var MAX_SAFE_INTEGER = 100000000;
|
|
103
|
-
function getCenter(shape) {
|
|
104
|
-
return {
|
|
105
|
-
x: shape.x +
|
|
106
|
-
(shape.width / 2) * Math.cos(shape.rotation) +
|
|
107
|
-
(shape.height / 2) * Math.sin(-shape.rotation),
|
|
108
|
-
y: shape.y +
|
|
109
|
-
(shape.height / 2) * Math.cos(shape.rotation) +
|
|
110
|
-
(shape.width / 2) * Math.sin(shape.rotation),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function rotateAroundPoint(shape, angleRad, point) {
|
|
114
|
-
const x = point.x +
|
|
115
|
-
(shape.x - point.x) * Math.cos(angleRad) -
|
|
116
|
-
(shape.y - point.y) * Math.sin(angleRad);
|
|
117
|
-
const y = point.y +
|
|
118
|
-
(shape.x - point.x) * Math.sin(angleRad) +
|
|
119
|
-
(shape.y - point.y) * Math.cos(angleRad);
|
|
120
|
-
return Object.assign(Object.assign({}, shape), { rotation: shape.rotation + angleRad, x,
|
|
121
|
-
y });
|
|
122
|
-
}
|
|
123
|
-
function rotateAroundCenter(shape, deltaRad) {
|
|
124
|
-
const center = getCenter(shape);
|
|
125
|
-
return rotateAroundPoint(shape, deltaRad, center);
|
|
126
|
-
}
|
|
127
|
-
function getSnap(snaps, newRotationRad, tol) {
|
|
128
|
-
let snapped = newRotationRad;
|
|
129
|
-
for (let i = 0; i < snaps.length; i++) {
|
|
130
|
-
const angle = Global_1.Konva.getAngle(snaps[i]);
|
|
131
|
-
const absDiff = Math.abs(angle - newRotationRad) % (Math.PI * 2);
|
|
132
|
-
const dif = Math.min(absDiff, Math.PI * 2 - absDiff);
|
|
133
|
-
if (dif < tol) {
|
|
134
|
-
snapped = angle;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return snapped;
|
|
138
|
-
}
|
|
139
|
-
class Transformer extends Group_1.Group {
|
|
140
|
-
constructor(config) {
|
|
141
|
-
super(config);
|
|
142
|
-
this._transforming = false;
|
|
143
|
-
this._createElements();
|
|
144
|
-
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
145
|
-
this._handleMouseUp = this._handleMouseUp.bind(this);
|
|
146
|
-
this.update = this.update.bind(this);
|
|
147
|
-
this.on(ATTR_CHANGE_LIST, this.update);
|
|
148
|
-
if (this.getNode()) {
|
|
149
|
-
this.update();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
attachTo(node) {
|
|
153
|
-
this.setNode(node);
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
156
|
-
setNode(node) {
|
|
157
|
-
Util_1.Util.warn('tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead.');
|
|
158
|
-
return this.setNodes([node]);
|
|
159
|
-
}
|
|
160
|
-
getNode() {
|
|
161
|
-
return this._nodes && this._nodes[0];
|
|
162
|
-
}
|
|
163
|
-
_getEventNamespace() {
|
|
164
|
-
return EVENTS_NAME + this._id;
|
|
165
|
-
}
|
|
166
|
-
setNodes(nodes = []) {
|
|
167
|
-
if (this._nodes && this._nodes.length) {
|
|
168
|
-
this.detach();
|
|
169
|
-
}
|
|
170
|
-
this._nodes = nodes;
|
|
171
|
-
if (nodes.length === 1 && this.useSingleNodeRotation()) {
|
|
172
|
-
this.rotation(nodes[0].getAbsoluteRotation());
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
this.rotation(0);
|
|
176
|
-
}
|
|
177
|
-
this._nodes.forEach((node) => {
|
|
178
|
-
const onChange = () => {
|
|
179
|
-
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
180
|
-
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
181
|
-
}
|
|
182
|
-
this._resetTransformCache();
|
|
183
|
-
if (!this._transforming && !this.isDragging()) {
|
|
184
|
-
this.update();
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const additionalEvents = node._attrsAffectingSize
|
|
188
|
-
.map((prop) => prop + 'Change.' + this._getEventNamespace())
|
|
189
|
-
.join(' ');
|
|
190
|
-
node.on(additionalEvents, onChange);
|
|
191
|
-
node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
|
|
192
|
-
node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
|
|
193
|
-
this._proxyDrag(node);
|
|
194
|
-
});
|
|
195
|
-
this._resetTransformCache();
|
|
196
|
-
var elementsCreated = !!this.findOne('.top-left');
|
|
197
|
-
if (elementsCreated) {
|
|
198
|
-
this.update();
|
|
199
|
-
}
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
_proxyDrag(node) {
|
|
203
|
-
let lastPos;
|
|
204
|
-
node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
|
|
205
|
-
lastPos = node.getAbsolutePosition();
|
|
206
|
-
if (!this.isDragging() && node !== this.findOne('.back')) {
|
|
207
|
-
this.startDrag(e, false);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
|
|
211
|
-
if (!lastPos) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const abs = node.getAbsolutePosition();
|
|
215
|
-
const dx = abs.x - lastPos.x;
|
|
216
|
-
const dy = abs.y - lastPos.y;
|
|
217
|
-
this.nodes().forEach((otherNode) => {
|
|
218
|
-
if (otherNode === node) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
if (otherNode.isDragging()) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
const otherAbs = otherNode.getAbsolutePosition();
|
|
225
|
-
otherNode.setAbsolutePosition({
|
|
226
|
-
x: otherAbs.x + dx,
|
|
227
|
-
y: otherAbs.y + dy,
|
|
228
|
-
});
|
|
229
|
-
otherNode.startDrag(e);
|
|
230
|
-
});
|
|
231
|
-
lastPos = null;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
getNodes() {
|
|
235
|
-
return this._nodes || [];
|
|
236
|
-
}
|
|
237
|
-
getActiveAnchor() {
|
|
238
|
-
return this._movingAnchorName;
|
|
239
|
-
}
|
|
240
|
-
detach() {
|
|
241
|
-
if (this._nodes) {
|
|
242
|
-
this._nodes.forEach((node) => {
|
|
243
|
-
node.off('.' + this._getEventNamespace());
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
this._nodes = [];
|
|
247
|
-
this._resetTransformCache();
|
|
248
|
-
}
|
|
249
|
-
_resetTransformCache() {
|
|
250
|
-
this._clearCache(NODES_RECT);
|
|
251
|
-
this._clearCache('transform');
|
|
252
|
-
this._clearSelfAndDescendantCache('absoluteTransform');
|
|
253
|
-
}
|
|
254
|
-
_getNodeRect() {
|
|
255
|
-
return this._getCache(NODES_RECT, this.__getNodeRect);
|
|
256
|
-
}
|
|
257
|
-
__getNodeShape(node, rot = this.rotation(), relative) {
|
|
258
|
-
var rect = node.getClientRect({
|
|
259
|
-
skipTransform: true,
|
|
260
|
-
skipShadow: true,
|
|
261
|
-
skipStroke: this.ignoreStroke(),
|
|
262
|
-
});
|
|
263
|
-
var absScale = node.getAbsoluteScale(relative);
|
|
264
|
-
var absPos = node.getAbsolutePosition(relative);
|
|
265
|
-
var dx = rect.x * absScale.x - node.offsetX() * absScale.x;
|
|
266
|
-
var dy = rect.y * absScale.y - node.offsetY() * absScale.y;
|
|
267
|
-
const rotation = (Global_1.Konva.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) %
|
|
268
|
-
(Math.PI * 2);
|
|
269
|
-
const box = {
|
|
270
|
-
x: absPos.x + dx * Math.cos(rotation) + dy * Math.sin(-rotation),
|
|
271
|
-
y: absPos.y + dy * Math.cos(rotation) + dx * Math.sin(rotation),
|
|
272
|
-
width: rect.width * absScale.x,
|
|
273
|
-
height: rect.height * absScale.y,
|
|
274
|
-
rotation: rotation,
|
|
275
|
-
};
|
|
276
|
-
return rotateAroundPoint(box, -Global_1.Konva.getAngle(rot), {
|
|
277
|
-
x: 0,
|
|
278
|
-
y: 0,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
__getNodeRect() {
|
|
282
|
-
var node = this.getNode();
|
|
283
|
-
if (!node) {
|
|
284
|
-
return {
|
|
285
|
-
x: -MAX_SAFE_INTEGER,
|
|
286
|
-
y: -MAX_SAFE_INTEGER,
|
|
287
|
-
width: 0,
|
|
288
|
-
height: 0,
|
|
289
|
-
rotation: 0,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
const totalPoints = [];
|
|
293
|
-
this.nodes().map((node) => {
|
|
294
|
-
const box = node.getClientRect({
|
|
295
|
-
skipTransform: true,
|
|
296
|
-
skipShadow: true,
|
|
297
|
-
skipStroke: this.ignoreStroke(),
|
|
298
|
-
});
|
|
299
|
-
var points = [
|
|
300
|
-
{ x: box.x, y: box.y },
|
|
301
|
-
{ x: box.x + box.width, y: box.y },
|
|
302
|
-
{ x: box.x + box.width, y: box.y + box.height },
|
|
303
|
-
{ x: box.x, y: box.y + box.height },
|
|
304
|
-
];
|
|
305
|
-
var trans = node.getAbsoluteTransform();
|
|
306
|
-
points.forEach(function (point) {
|
|
307
|
-
var transformed = trans.point(point);
|
|
308
|
-
totalPoints.push(transformed);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
const tr = new Util_1.Transform();
|
|
312
|
-
tr.rotate(-Global_1.Konva.getAngle(this.rotation()));
|
|
313
|
-
var minX, minY, maxX, maxY;
|
|
314
|
-
totalPoints.forEach(function (point) {
|
|
315
|
-
var transformed = tr.point(point);
|
|
316
|
-
if (minX === undefined) {
|
|
317
|
-
minX = maxX = transformed.x;
|
|
318
|
-
minY = maxY = transformed.y;
|
|
319
|
-
}
|
|
320
|
-
minX = Math.min(minX, transformed.x);
|
|
321
|
-
minY = Math.min(minY, transformed.y);
|
|
322
|
-
maxX = Math.max(maxX, transformed.x);
|
|
323
|
-
maxY = Math.max(maxY, transformed.y);
|
|
324
|
-
});
|
|
325
|
-
tr.invert();
|
|
326
|
-
const p = tr.point({ x: minX, y: minY });
|
|
327
|
-
return {
|
|
328
|
-
x: p.x,
|
|
329
|
-
y: p.y,
|
|
330
|
-
width: maxX - minX,
|
|
331
|
-
height: maxY - minY,
|
|
332
|
-
rotation: Global_1.Konva.getAngle(this.rotation()),
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
getX() {
|
|
336
|
-
return this._getNodeRect().x;
|
|
337
|
-
}
|
|
338
|
-
getY() {
|
|
339
|
-
return this._getNodeRect().y;
|
|
340
|
-
}
|
|
341
|
-
getWidth() {
|
|
342
|
-
return this._getNodeRect().width;
|
|
343
|
-
}
|
|
344
|
-
getHeight() {
|
|
345
|
-
return this._getNodeRect().height;
|
|
346
|
-
}
|
|
347
|
-
_createElements() {
|
|
348
|
-
this._createBack();
|
|
349
|
-
ANCHORS_NAMES.forEach(function (name) {
|
|
350
|
-
this._createAnchor(name);
|
|
351
|
-
}.bind(this));
|
|
352
|
-
this._createAnchor('rotater');
|
|
353
|
-
}
|
|
354
|
-
_createAnchor(name) {
|
|
355
|
-
var anchor = new Rect_1.Rect({
|
|
356
|
-
stroke: 'rgb(0, 161, 255)',
|
|
357
|
-
fill: 'white',
|
|
358
|
-
strokeWidth: 1,
|
|
359
|
-
name: name + ' _anchor',
|
|
360
|
-
dragDistance: 0,
|
|
361
|
-
draggable: true,
|
|
362
|
-
hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto',
|
|
363
|
-
});
|
|
364
|
-
var self = this;
|
|
365
|
-
anchor.on('mousedown touchstart', function (e) {
|
|
366
|
-
self._handleMouseDown(e);
|
|
367
|
-
});
|
|
368
|
-
anchor.on('dragstart', (e) => {
|
|
369
|
-
anchor.stopDrag();
|
|
370
|
-
e.cancelBubble = true;
|
|
371
|
-
});
|
|
372
|
-
anchor.on('dragend', (e) => {
|
|
373
|
-
e.cancelBubble = true;
|
|
374
|
-
});
|
|
375
|
-
anchor.on('mouseenter', () => {
|
|
376
|
-
var rad = Global_1.Konva.getAngle(this.rotation());
|
|
377
|
-
var cursor = getCursor(name, rad);
|
|
378
|
-
anchor.getStage().content &&
|
|
379
|
-
(anchor.getStage().content.style.cursor = cursor);
|
|
380
|
-
this._cursorChange = true;
|
|
381
|
-
});
|
|
382
|
-
anchor.on('mouseout', () => {
|
|
383
|
-
anchor.getStage().content &&
|
|
384
|
-
(anchor.getStage().content.style.cursor = '');
|
|
385
|
-
this._cursorChange = false;
|
|
386
|
-
});
|
|
387
|
-
this.add(anchor);
|
|
388
|
-
}
|
|
389
|
-
_createBack() {
|
|
390
|
-
var back = new Shape_1.Shape({
|
|
391
|
-
name: 'back',
|
|
392
|
-
width: 0,
|
|
393
|
-
height: 0,
|
|
394
|
-
draggable: true,
|
|
395
|
-
sceneFunc(ctx) {
|
|
396
|
-
var tr = this.getParent();
|
|
397
|
-
var padding = tr.padding();
|
|
398
|
-
ctx.beginPath();
|
|
399
|
-
ctx.rect(-padding, -padding, this.width() + padding * 2, this.height() + padding * 2);
|
|
400
|
-
ctx.moveTo(this.width() / 2, -padding);
|
|
401
|
-
if (tr.rotateEnabled()) {
|
|
402
|
-
ctx.lineTo(this.width() / 2, -tr.rotateAnchorOffset() * Util_1.Util._sign(this.height()) - padding);
|
|
403
|
-
}
|
|
404
|
-
ctx.fillStrokeShape(this);
|
|
405
|
-
},
|
|
406
|
-
hitFunc: (ctx, shape) => {
|
|
407
|
-
if (!this.shouldOverdrawWholeArea()) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
var padding = this.padding();
|
|
411
|
-
ctx.beginPath();
|
|
412
|
-
ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
|
|
413
|
-
ctx.fillStrokeShape(shape);
|
|
414
|
-
},
|
|
415
|
-
});
|
|
416
|
-
this.add(back);
|
|
417
|
-
this._proxyDrag(back);
|
|
418
|
-
back.on('dragstart', (e) => {
|
|
419
|
-
e.cancelBubble = true;
|
|
420
|
-
});
|
|
421
|
-
back.on('dragmove', (e) => {
|
|
422
|
-
e.cancelBubble = true;
|
|
423
|
-
});
|
|
424
|
-
back.on('dragend', (e) => {
|
|
425
|
-
e.cancelBubble = true;
|
|
426
|
-
});
|
|
427
|
-
this.on('dragmove', (e) => {
|
|
428
|
-
this.update();
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
_handleMouseDown(e) {
|
|
432
|
-
this._movingAnchorName = e.target.name().split(' ')[0];
|
|
433
|
-
var attrs = this._getNodeRect();
|
|
434
|
-
var width = attrs.width;
|
|
435
|
-
var height = attrs.height;
|
|
436
|
-
var hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
|
|
437
|
-
this.sin = Math.abs(height / hypotenuse);
|
|
438
|
-
this.cos = Math.abs(width / hypotenuse);
|
|
439
|
-
if (typeof window !== 'undefined') {
|
|
440
|
-
window.addEventListener('mousemove', this._handleMouseMove);
|
|
441
|
-
window.addEventListener('touchmove', this._handleMouseMove);
|
|
442
|
-
window.addEventListener('mouseup', this._handleMouseUp, true);
|
|
443
|
-
window.addEventListener('touchend', this._handleMouseUp, true);
|
|
444
|
-
}
|
|
445
|
-
this._transforming = true;
|
|
446
|
-
var ap = e.target.getAbsolutePosition();
|
|
447
|
-
var pos = e.target.getStage().getPointerPosition();
|
|
448
|
-
this._anchorDragOffset = {
|
|
449
|
-
x: pos.x - ap.x,
|
|
450
|
-
y: pos.y - ap.y,
|
|
451
|
-
};
|
|
452
|
-
this._fire('transformstart', { evt: e.evt, target: this.getNode() });
|
|
453
|
-
this._nodes.forEach((target) => {
|
|
454
|
-
target._fire('transformstart', { evt: e.evt, target });
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
_handleMouseMove(e) {
|
|
458
|
-
var x, y, newHypotenuse;
|
|
459
|
-
var anchorNode = this.findOne('.' + this._movingAnchorName);
|
|
460
|
-
var stage = anchorNode.getStage();
|
|
461
|
-
stage.setPointersPositions(e);
|
|
462
|
-
const pp = stage.getPointerPosition();
|
|
463
|
-
let newNodePos = {
|
|
464
|
-
x: pp.x - this._anchorDragOffset.x,
|
|
465
|
-
y: pp.y - this._anchorDragOffset.y,
|
|
466
|
-
};
|
|
467
|
-
const oldAbs = anchorNode.getAbsolutePosition();
|
|
468
|
-
if (this.anchorDragBoundFunc()) {
|
|
469
|
-
newNodePos = this.anchorDragBoundFunc()(oldAbs, newNodePos, e);
|
|
470
|
-
}
|
|
471
|
-
anchorNode.setAbsolutePosition(newNodePos);
|
|
472
|
-
const newAbs = anchorNode.getAbsolutePosition();
|
|
473
|
-
if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (this._movingAnchorName === 'rotater') {
|
|
477
|
-
var attrs = this._getNodeRect();
|
|
478
|
-
x = anchorNode.x() - attrs.width / 2;
|
|
479
|
-
y = -anchorNode.y() + attrs.height / 2;
|
|
480
|
-
let delta = Math.atan2(-y, x) + Math.PI / 2;
|
|
481
|
-
if (attrs.height < 0) {
|
|
482
|
-
delta -= Math.PI;
|
|
483
|
-
}
|
|
484
|
-
var oldRotation = Global_1.Konva.getAngle(this.rotation());
|
|
485
|
-
const newRotation = oldRotation + delta;
|
|
486
|
-
const tol = Global_1.Konva.getAngle(this.rotationSnapTolerance());
|
|
487
|
-
const snappedRot = getSnap(this.rotationSnaps(), newRotation, tol);
|
|
488
|
-
const diff = snappedRot - attrs.rotation;
|
|
489
|
-
const shape = rotateAroundCenter(attrs, diff);
|
|
490
|
-
this._fitNodesInto(shape, e);
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
var keepProportion = this.keepRatio() || e.shiftKey;
|
|
494
|
-
var centeredScaling = this.centeredScaling() || e.altKey;
|
|
495
|
-
if (this._movingAnchorName === 'top-left') {
|
|
496
|
-
if (keepProportion) {
|
|
497
|
-
var comparePoint = centeredScaling
|
|
498
|
-
? {
|
|
499
|
-
x: this.width() / 2,
|
|
500
|
-
y: this.height() / 2,
|
|
501
|
-
}
|
|
502
|
-
: {
|
|
503
|
-
x: this.findOne('.bottom-right').x(),
|
|
504
|
-
y: this.findOne('.bottom-right').y(),
|
|
505
|
-
};
|
|
506
|
-
newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
|
|
507
|
-
Math.pow(comparePoint.y - anchorNode.y(), 2));
|
|
508
|
-
var reverseX = this.findOne('.top-left').x() > comparePoint.x ? -1 : 1;
|
|
509
|
-
var reverseY = this.findOne('.top-left').y() > comparePoint.y ? -1 : 1;
|
|
510
|
-
x = newHypotenuse * this.cos * reverseX;
|
|
511
|
-
y = newHypotenuse * this.sin * reverseY;
|
|
512
|
-
this.findOne('.top-left').x(comparePoint.x - x);
|
|
513
|
-
this.findOne('.top-left').y(comparePoint.y - y);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
else if (this._movingAnchorName === 'top-center') {
|
|
517
|
-
this.findOne('.top-left').y(anchorNode.y());
|
|
518
|
-
}
|
|
519
|
-
else if (this._movingAnchorName === 'top-right') {
|
|
520
|
-
if (keepProportion) {
|
|
521
|
-
var comparePoint = centeredScaling
|
|
522
|
-
? {
|
|
523
|
-
x: this.width() / 2,
|
|
524
|
-
y: this.height() / 2,
|
|
525
|
-
}
|
|
526
|
-
: {
|
|
527
|
-
x: this.findOne('.bottom-left').x(),
|
|
528
|
-
y: this.findOne('.bottom-left').y(),
|
|
529
|
-
};
|
|
530
|
-
newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
|
|
531
|
-
Math.pow(comparePoint.y - anchorNode.y(), 2));
|
|
532
|
-
var reverseX = this.findOne('.top-right').x() < comparePoint.x ? -1 : 1;
|
|
533
|
-
var reverseY = this.findOne('.top-right').y() > comparePoint.y ? -1 : 1;
|
|
534
|
-
x = newHypotenuse * this.cos * reverseX;
|
|
535
|
-
y = newHypotenuse * this.sin * reverseY;
|
|
536
|
-
this.findOne('.top-right').x(comparePoint.x + x);
|
|
537
|
-
this.findOne('.top-right').y(comparePoint.y - y);
|
|
538
|
-
}
|
|
539
|
-
var pos = anchorNode.position();
|
|
540
|
-
this.findOne('.top-left').y(pos.y);
|
|
541
|
-
this.findOne('.bottom-right').x(pos.x);
|
|
542
|
-
}
|
|
543
|
-
else if (this._movingAnchorName === 'middle-left') {
|
|
544
|
-
this.findOne('.top-left').x(anchorNode.x());
|
|
545
|
-
}
|
|
546
|
-
else if (this._movingAnchorName === 'middle-right') {
|
|
547
|
-
this.findOne('.bottom-right').x(anchorNode.x());
|
|
548
|
-
}
|
|
549
|
-
else if (this._movingAnchorName === 'bottom-left') {
|
|
550
|
-
if (keepProportion) {
|
|
551
|
-
var comparePoint = centeredScaling
|
|
552
|
-
? {
|
|
553
|
-
x: this.width() / 2,
|
|
554
|
-
y: this.height() / 2,
|
|
555
|
-
}
|
|
556
|
-
: {
|
|
557
|
-
x: this.findOne('.top-right').x(),
|
|
558
|
-
y: this.findOne('.top-right').y(),
|
|
559
|
-
};
|
|
560
|
-
newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
|
|
561
|
-
Math.pow(anchorNode.y() - comparePoint.y, 2));
|
|
562
|
-
var reverseX = comparePoint.x < anchorNode.x() ? -1 : 1;
|
|
563
|
-
var reverseY = anchorNode.y() < comparePoint.y ? -1 : 1;
|
|
564
|
-
x = newHypotenuse * this.cos * reverseX;
|
|
565
|
-
y = newHypotenuse * this.sin * reverseY;
|
|
566
|
-
anchorNode.x(comparePoint.x - x);
|
|
567
|
-
anchorNode.y(comparePoint.y + y);
|
|
568
|
-
}
|
|
569
|
-
pos = anchorNode.position();
|
|
570
|
-
this.findOne('.top-left').x(pos.x);
|
|
571
|
-
this.findOne('.bottom-right').y(pos.y);
|
|
572
|
-
}
|
|
573
|
-
else if (this._movingAnchorName === 'bottom-center') {
|
|
574
|
-
this.findOne('.bottom-right').y(anchorNode.y());
|
|
575
|
-
}
|
|
576
|
-
else if (this._movingAnchorName === 'bottom-right') {
|
|
577
|
-
if (keepProportion) {
|
|
578
|
-
var comparePoint = centeredScaling
|
|
579
|
-
? {
|
|
580
|
-
x: this.width() / 2,
|
|
581
|
-
y: this.height() / 2,
|
|
582
|
-
}
|
|
583
|
-
: {
|
|
584
|
-
x: this.findOne('.top-left').x(),
|
|
585
|
-
y: this.findOne('.top-left').y(),
|
|
586
|
-
};
|
|
587
|
-
newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
|
|
588
|
-
Math.pow(anchorNode.y() - comparePoint.y, 2));
|
|
589
|
-
var reverseX = this.findOne('.bottom-right').x() < comparePoint.x ? -1 : 1;
|
|
590
|
-
var reverseY = this.findOne('.bottom-right').y() < comparePoint.y ? -1 : 1;
|
|
591
|
-
x = newHypotenuse * this.cos * reverseX;
|
|
592
|
-
y = newHypotenuse * this.sin * reverseY;
|
|
593
|
-
this.findOne('.bottom-right').x(comparePoint.x + x);
|
|
594
|
-
this.findOne('.bottom-right').y(comparePoint.y + y);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
console.error(new Error('Wrong position argument of selection resizer: ' +
|
|
599
|
-
this._movingAnchorName));
|
|
600
|
-
}
|
|
601
|
-
var centeredScaling = this.centeredScaling() || e.altKey;
|
|
602
|
-
if (centeredScaling) {
|
|
603
|
-
var topLeft = this.findOne('.top-left');
|
|
604
|
-
var bottomRight = this.findOne('.bottom-right');
|
|
605
|
-
var topOffsetX = topLeft.x();
|
|
606
|
-
var topOffsetY = topLeft.y();
|
|
607
|
-
var bottomOffsetX = this.getWidth() - bottomRight.x();
|
|
608
|
-
var bottomOffsetY = this.getHeight() - bottomRight.y();
|
|
609
|
-
bottomRight.move({
|
|
610
|
-
x: -topOffsetX,
|
|
611
|
-
y: -topOffsetY,
|
|
612
|
-
});
|
|
613
|
-
topLeft.move({
|
|
614
|
-
x: bottomOffsetX,
|
|
615
|
-
y: bottomOffsetY,
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
var absPos = this.findOne('.top-left').getAbsolutePosition();
|
|
619
|
-
x = absPos.x;
|
|
620
|
-
y = absPos.y;
|
|
621
|
-
var width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
|
|
622
|
-
var height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
|
|
623
|
-
this._fitNodesInto({
|
|
624
|
-
x: x,
|
|
625
|
-
y: y,
|
|
626
|
-
width: width,
|
|
627
|
-
height: height,
|
|
628
|
-
rotation: Global_1.Konva.getAngle(this.rotation()),
|
|
629
|
-
}, e);
|
|
630
|
-
}
|
|
631
|
-
_handleMouseUp(e) {
|
|
632
|
-
this._removeEvents(e);
|
|
633
|
-
}
|
|
634
|
-
getAbsoluteTransform() {
|
|
635
|
-
return this.getTransform();
|
|
636
|
-
}
|
|
637
|
-
_removeEvents(e) {
|
|
638
|
-
if (this._transforming) {
|
|
639
|
-
this._transforming = false;
|
|
640
|
-
if (typeof window !== 'undefined') {
|
|
641
|
-
window.removeEventListener('mousemove', this._handleMouseMove);
|
|
642
|
-
window.removeEventListener('touchmove', this._handleMouseMove);
|
|
643
|
-
window.removeEventListener('mouseup', this._handleMouseUp, true);
|
|
644
|
-
window.removeEventListener('touchend', this._handleMouseUp, true);
|
|
645
|
-
}
|
|
646
|
-
var node = this.getNode();
|
|
647
|
-
this._fire('transformend', { evt: e, target: node });
|
|
648
|
-
if (node) {
|
|
649
|
-
this._nodes.forEach((target) => {
|
|
650
|
-
target._fire('transformend', { evt: e, target });
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
this._movingAnchorName = null;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
_fitNodesInto(newAttrs, evt) {
|
|
657
|
-
var oldAttrs = this._getNodeRect();
|
|
658
|
-
const minSize = 1;
|
|
659
|
-
if (Util_1.Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
|
|
660
|
-
this.update();
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
if (Util_1.Util._inRange(newAttrs.height, -this.padding() * 2 - minSize, minSize)) {
|
|
664
|
-
this.update();
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
const allowNegativeScale = this.flipEnabled();
|
|
668
|
-
var t = new Util_1.Transform();
|
|
669
|
-
t.rotate(Global_1.Konva.getAngle(this.rotation()));
|
|
670
|
-
if (this._movingAnchorName &&
|
|
671
|
-
newAttrs.width < 0 &&
|
|
672
|
-
this._movingAnchorName.indexOf('left') >= 0) {
|
|
673
|
-
const offset = t.point({
|
|
674
|
-
x: -this.padding() * 2,
|
|
675
|
-
y: 0,
|
|
676
|
-
});
|
|
677
|
-
newAttrs.x += offset.x;
|
|
678
|
-
newAttrs.y += offset.y;
|
|
679
|
-
newAttrs.width += this.padding() * 2;
|
|
680
|
-
this._movingAnchorName = this._movingAnchorName.replace('left', 'right');
|
|
681
|
-
this._anchorDragOffset.x -= offset.x;
|
|
682
|
-
this._anchorDragOffset.y -= offset.y;
|
|
683
|
-
if (!allowNegativeScale) {
|
|
684
|
-
this.update();
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
else if (this._movingAnchorName &&
|
|
689
|
-
newAttrs.width < 0 &&
|
|
690
|
-
this._movingAnchorName.indexOf('right') >= 0) {
|
|
691
|
-
const offset = t.point({
|
|
692
|
-
x: this.padding() * 2,
|
|
693
|
-
y: 0,
|
|
694
|
-
});
|
|
695
|
-
this._movingAnchorName = this._movingAnchorName.replace('right', 'left');
|
|
696
|
-
this._anchorDragOffset.x -= offset.x;
|
|
697
|
-
this._anchorDragOffset.y -= offset.y;
|
|
698
|
-
newAttrs.width += this.padding() * 2;
|
|
699
|
-
if (!allowNegativeScale) {
|
|
700
|
-
this.update();
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
if (this._movingAnchorName &&
|
|
705
|
-
newAttrs.height < 0 &&
|
|
706
|
-
this._movingAnchorName.indexOf('top') >= 0) {
|
|
707
|
-
const offset = t.point({
|
|
708
|
-
x: 0,
|
|
709
|
-
y: -this.padding() * 2,
|
|
710
|
-
});
|
|
711
|
-
newAttrs.x += offset.x;
|
|
712
|
-
newAttrs.y += offset.y;
|
|
713
|
-
this._movingAnchorName = this._movingAnchorName.replace('top', 'bottom');
|
|
714
|
-
this._anchorDragOffset.x -= offset.x;
|
|
715
|
-
this._anchorDragOffset.y -= offset.y;
|
|
716
|
-
newAttrs.height += this.padding() * 2;
|
|
717
|
-
if (!allowNegativeScale) {
|
|
718
|
-
this.update();
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
else if (this._movingAnchorName &&
|
|
723
|
-
newAttrs.height < 0 &&
|
|
724
|
-
this._movingAnchorName.indexOf('bottom') >= 0) {
|
|
725
|
-
const offset = t.point({
|
|
726
|
-
x: 0,
|
|
727
|
-
y: this.padding() * 2,
|
|
728
|
-
});
|
|
729
|
-
this._movingAnchorName = this._movingAnchorName.replace('bottom', 'top');
|
|
730
|
-
this._anchorDragOffset.x -= offset.x;
|
|
731
|
-
this._anchorDragOffset.y -= offset.y;
|
|
732
|
-
newAttrs.height += this.padding() * 2;
|
|
733
|
-
if (!allowNegativeScale) {
|
|
734
|
-
this.update();
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
if (this.boundBoxFunc()) {
|
|
739
|
-
const bounded = this.boundBoxFunc()(oldAttrs, newAttrs);
|
|
740
|
-
if (bounded) {
|
|
741
|
-
newAttrs = bounded;
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
Util_1.Util.warn('boundBoxFunc returned falsy. You should return new bound rect from it!');
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
const baseSize = 10000000;
|
|
748
|
-
const oldTr = new Util_1.Transform();
|
|
749
|
-
oldTr.translate(oldAttrs.x, oldAttrs.y);
|
|
750
|
-
oldTr.rotate(oldAttrs.rotation);
|
|
751
|
-
oldTr.scale(oldAttrs.width / baseSize, oldAttrs.height / baseSize);
|
|
752
|
-
const newTr = new Util_1.Transform();
|
|
753
|
-
newTr.translate(newAttrs.x, newAttrs.y);
|
|
754
|
-
newTr.rotate(newAttrs.rotation);
|
|
755
|
-
newTr.scale(newAttrs.width / baseSize, newAttrs.height / baseSize);
|
|
756
|
-
const delta = newTr.multiply(oldTr.invert());
|
|
757
|
-
this._nodes.forEach((node) => {
|
|
758
|
-
var _a;
|
|
759
|
-
const parentTransform = node.getParent().getAbsoluteTransform();
|
|
760
|
-
const localTransform = node.getTransform().copy();
|
|
761
|
-
localTransform.translate(node.offsetX(), node.offsetY());
|
|
762
|
-
const newLocalTransform = new Util_1.Transform();
|
|
763
|
-
newLocalTransform
|
|
764
|
-
.multiply(parentTransform.copy().invert())
|
|
765
|
-
.multiply(delta)
|
|
766
|
-
.multiply(parentTransform)
|
|
767
|
-
.multiply(localTransform);
|
|
768
|
-
const attrs = newLocalTransform.decompose();
|
|
769
|
-
node.setAttrs(attrs);
|
|
770
|
-
this._fire('transform', { evt: evt, target: node });
|
|
771
|
-
node._fire('transform', { evt: evt, target: node });
|
|
772
|
-
(_a = node.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
|
|
773
|
-
});
|
|
774
|
-
this.rotation(Util_1.Util._getRotation(newAttrs.rotation));
|
|
775
|
-
this._resetTransformCache();
|
|
776
|
-
this.update();
|
|
777
|
-
this.getLayer().batchDraw();
|
|
778
|
-
}
|
|
779
|
-
forceUpdate() {
|
|
780
|
-
this._resetTransformCache();
|
|
781
|
-
this.update();
|
|
782
|
-
}
|
|
783
|
-
_batchChangeChild(selector, attrs) {
|
|
784
|
-
const anchor = this.findOne(selector);
|
|
785
|
-
anchor.setAttrs(attrs);
|
|
786
|
-
}
|
|
787
|
-
update() {
|
|
788
|
-
var _a;
|
|
789
|
-
var attrs = this._getNodeRect();
|
|
790
|
-
this.rotation(Util_1.Util._getRotation(attrs.rotation));
|
|
791
|
-
var width = attrs.width;
|
|
792
|
-
var height = attrs.height;
|
|
793
|
-
var enabledAnchors = this.enabledAnchors();
|
|
794
|
-
var resizeEnabled = this.resizeEnabled();
|
|
795
|
-
var padding = this.padding();
|
|
796
|
-
var anchorSize = this.anchorSize();
|
|
797
|
-
this.find('._anchor').forEach((node) => {
|
|
798
|
-
node.setAttrs({
|
|
799
|
-
width: anchorSize,
|
|
800
|
-
height: anchorSize,
|
|
801
|
-
offsetX: anchorSize / 2,
|
|
802
|
-
offsetY: anchorSize / 2,
|
|
803
|
-
stroke: this.anchorStroke(),
|
|
804
|
-
strokeWidth: this.anchorStrokeWidth(),
|
|
805
|
-
fill: this.anchorFill(),
|
|
806
|
-
cornerRadius: this.anchorCornerRadius(),
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
this._batchChangeChild('.top-left', {
|
|
810
|
-
x: 0,
|
|
811
|
-
y: 0,
|
|
812
|
-
offsetX: anchorSize / 2 + padding,
|
|
813
|
-
offsetY: anchorSize / 2 + padding,
|
|
814
|
-
visible: resizeEnabled && enabledAnchors.indexOf('top-left') >= 0,
|
|
815
|
-
});
|
|
816
|
-
this._batchChangeChild('.top-center', {
|
|
817
|
-
x: width / 2,
|
|
818
|
-
y: 0,
|
|
819
|
-
offsetY: anchorSize / 2 + padding,
|
|
820
|
-
visible: resizeEnabled && enabledAnchors.indexOf('top-center') >= 0,
|
|
821
|
-
});
|
|
822
|
-
this._batchChangeChild('.top-right', {
|
|
823
|
-
x: width,
|
|
824
|
-
y: 0,
|
|
825
|
-
offsetX: anchorSize / 2 - padding,
|
|
826
|
-
offsetY: anchorSize / 2 + padding,
|
|
827
|
-
visible: resizeEnabled && enabledAnchors.indexOf('top-right') >= 0,
|
|
828
|
-
});
|
|
829
|
-
this._batchChangeChild('.middle-left', {
|
|
830
|
-
x: 0,
|
|
831
|
-
y: height / 2,
|
|
832
|
-
offsetX: anchorSize / 2 + padding,
|
|
833
|
-
visible: resizeEnabled && enabledAnchors.indexOf('middle-left') >= 0,
|
|
834
|
-
});
|
|
835
|
-
this._batchChangeChild('.middle-right', {
|
|
836
|
-
x: width,
|
|
837
|
-
y: height / 2,
|
|
838
|
-
offsetX: anchorSize / 2 - padding,
|
|
839
|
-
visible: resizeEnabled && enabledAnchors.indexOf('middle-right') >= 0,
|
|
840
|
-
});
|
|
841
|
-
this._batchChangeChild('.bottom-left', {
|
|
842
|
-
x: 0,
|
|
843
|
-
y: height,
|
|
844
|
-
offsetX: anchorSize / 2 + padding,
|
|
845
|
-
offsetY: anchorSize / 2 - padding,
|
|
846
|
-
visible: resizeEnabled && enabledAnchors.indexOf('bottom-left') >= 0,
|
|
847
|
-
});
|
|
848
|
-
this._batchChangeChild('.bottom-center', {
|
|
849
|
-
x: width / 2,
|
|
850
|
-
y: height,
|
|
851
|
-
offsetY: anchorSize / 2 - padding,
|
|
852
|
-
visible: resizeEnabled && enabledAnchors.indexOf('bottom-center') >= 0,
|
|
853
|
-
});
|
|
854
|
-
this._batchChangeChild('.bottom-right', {
|
|
855
|
-
x: width,
|
|
856
|
-
y: height,
|
|
857
|
-
offsetX: anchorSize / 2 - padding,
|
|
858
|
-
offsetY: anchorSize / 2 - padding,
|
|
859
|
-
visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
|
|
860
|
-
});
|
|
861
|
-
this._batchChangeChild('.rotater', {
|
|
862
|
-
x: width / 2,
|
|
863
|
-
y: -this.rotateAnchorOffset() * Util_1.Util._sign(height) - padding,
|
|
864
|
-
visible: this.rotateEnabled(),
|
|
865
|
-
});
|
|
866
|
-
this._batchChangeChild('.back', {
|
|
867
|
-
width: width,
|
|
868
|
-
height: height,
|
|
869
|
-
visible: this.borderEnabled(),
|
|
870
|
-
stroke: this.borderStroke(),
|
|
871
|
-
strokeWidth: this.borderStrokeWidth(),
|
|
872
|
-
dash: this.borderDash(),
|
|
873
|
-
x: 0,
|
|
874
|
-
y: 0,
|
|
875
|
-
});
|
|
876
|
-
(_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
|
|
877
|
-
}
|
|
878
|
-
isTransforming() {
|
|
879
|
-
return this._transforming;
|
|
880
|
-
}
|
|
881
|
-
stopTransform() {
|
|
882
|
-
if (this._transforming) {
|
|
883
|
-
this._removeEvents();
|
|
884
|
-
var anchorNode = this.findOne('.' + this._movingAnchorName);
|
|
885
|
-
if (anchorNode) {
|
|
886
|
-
anchorNode.stopDrag();
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
destroy() {
|
|
891
|
-
if (this.getStage() && this._cursorChange) {
|
|
892
|
-
this.getStage().content && (this.getStage().content.style.cursor = '');
|
|
893
|
-
}
|
|
894
|
-
Group_1.Group.prototype.destroy.call(this);
|
|
895
|
-
this.detach();
|
|
896
|
-
this._removeEvents();
|
|
897
|
-
return this;
|
|
898
|
-
}
|
|
899
|
-
toObject() {
|
|
900
|
-
return Node_1.Node.prototype.toObject.call(this);
|
|
901
|
-
}
|
|
902
|
-
clone(obj) {
|
|
903
|
-
var node = Node_1.Node.prototype.clone.call(this, obj);
|
|
904
|
-
return node;
|
|
905
|
-
}
|
|
906
|
-
getClientRect() {
|
|
907
|
-
if (this.nodes().length > 0) {
|
|
908
|
-
return super.getClientRect();
|
|
909
|
-
}
|
|
910
|
-
else {
|
|
911
|
-
return { x: 0, y: 0, width: 0, height: 0 };
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
exports.Transformer = Transformer;
|
|
916
|
-
function validateAnchors(val) {
|
|
917
|
-
if (!(val instanceof Array)) {
|
|
918
|
-
Util_1.Util.warn('enabledAnchors value should be an array');
|
|
919
|
-
}
|
|
920
|
-
if (val instanceof Array) {
|
|
921
|
-
val.forEach(function (name) {
|
|
922
|
-
if (ANCHORS_NAMES.indexOf(name) === -1) {
|
|
923
|
-
Util_1.Util.warn('Unknown anchor name: ' +
|
|
924
|
-
name +
|
|
925
|
-
'. Available names are: ' +
|
|
926
|
-
ANCHORS_NAMES.join(', '));
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
return val || [];
|
|
931
|
-
}
|
|
932
|
-
Transformer.prototype.className = 'Transformer';
|
|
933
|
-
(0, Global_2._registerNode)(Transformer);
|
|
934
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'enabledAnchors', ANCHORS_NAMES, validateAnchors);
|
|
935
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'flipEnabled', true, (0, Validators_1.getBooleanValidator)());
|
|
936
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'resizeEnabled', true);
|
|
937
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'anchorSize', 10, (0, Validators_1.getNumberValidator)());
|
|
938
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'rotateEnabled', true);
|
|
939
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
|
|
940
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, (0, Validators_1.getNumberValidator)());
|
|
941
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, (0, Validators_1.getNumberValidator)());
|
|
942
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'borderEnabled', true);
|
|
943
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'anchorStroke', 'rgb(0, 161, 255)');
|
|
944
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'anchorStrokeWidth', 1, (0, Validators_1.getNumberValidator)());
|
|
945
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'anchorFill', 'white');
|
|
946
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'anchorCornerRadius', 0, (0, Validators_1.getNumberValidator)());
|
|
947
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'borderStroke', 'rgb(0, 161, 255)');
|
|
948
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'borderStrokeWidth', 1, (0, Validators_1.getNumberValidator)());
|
|
949
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'borderDash');
|
|
950
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'keepRatio', true);
|
|
951
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'centeredScaling', false);
|
|
952
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'ignoreStroke', false);
|
|
953
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'padding', 0, (0, Validators_1.getNumberValidator)());
|
|
954
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'node');
|
|
955
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'nodes');
|
|
956
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'boundBoxFunc');
|
|
957
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
|
|
958
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
|
|
959
|
-
Factory_1.Factory.addGetterSetter(Transformer, 'useSingleNodeRotation', true);
|
|
960
|
-
Factory_1.Factory.backCompat(Transformer, {
|
|
961
|
-
lineEnabled: 'borderEnabled',
|
|
962
|
-
rotateHandlerOffset: 'rotateAnchorOffset',
|
|
963
|
-
enabledHandlers: 'enabledAnchors',
|
|
964
|
-
});
|