konva 10.3.0 → 10.3.2
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 +33 -43
- package/konva.js +1158 -681
- package/konva.min.js +4 -4
- package/lib/BezierFunctions.d.ts +2 -0
- package/lib/BezierFunctions.js +46 -0
- package/lib/Canvas.d.ts +1 -0
- package/lib/Canvas.js +6 -0
- package/lib/Container.js +22 -8
- package/lib/Context.js +6 -0
- package/lib/DragAndDrop.d.ts +13 -10
- package/lib/DragAndDrop.js +18 -13
- package/lib/Factory.d.ts +1 -1
- package/lib/Global.js +1 -1
- package/lib/Layer.d.ts +1 -0
- package/lib/Layer.js +15 -4
- package/lib/Node.d.ts +6 -2
- package/lib/Node.js +51 -18
- package/lib/PointerEvents.js +12 -2
- package/lib/Shape.js +6 -5
- package/lib/Stage.d.ts +2 -0
- package/lib/Stage.js +34 -19
- package/lib/Tween.js +10 -4
- package/lib/Util.d.ts +1 -7
- package/lib/Util.js +135 -135
- package/lib/_CoreInternals.d.ts +4 -9
- package/lib/_FullInternals.d.ts +4 -9
- package/lib/shapes/Arc.js +11 -0
- package/lib/shapes/Line.d.ts +2 -0
- package/lib/shapes/Line.js +39 -59
- package/lib/shapes/Path.js +10 -6
- package/lib/shapes/Text.d.ts +2 -0
- package/lib/shapes/Text.js +21 -4
- package/lib/shapes/Transformer.d.ts +5 -1
- package/lib/shapes/Transformer.js +80 -37
- package/package.json +13 -1
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface LineConfig extends ShapeConfig {
|
|
|
10
10
|
}
|
|
11
11
|
export declare class Line<Config extends LineConfig = LineConfig> extends Shape<Config> {
|
|
12
12
|
constructor(config?: Config);
|
|
13
|
+
_hasTension(): boolean;
|
|
14
|
+
_eachTensionSegment(onQuadratic: (x0: number, y0: number, cpx: number, cpy: number, x: number, y: number) => void, onCubic: (x0: number, y0: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) => void): void;
|
|
13
15
|
_sceneFunc(context: Context): void;
|
|
14
16
|
getTensionPoints(): any;
|
|
15
17
|
_getTensionPoints(): number[];
|
package/lib/shapes/Line.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { getCubicExtremaPoints, getQuadraticExtremaPoints, } from "../BezierFunctions.js";
|
|
1
2
|
import { Factory } from "../Factory.js";
|
|
2
3
|
import { _registerNode } from "../Global.js";
|
|
3
4
|
import { Shape } from "../Shape.js";
|
|
4
5
|
import { getNumberArrayValidator, getNumberValidator } from "../Validators.js";
|
|
5
6
|
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
6
|
-
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)),
|
|
7
|
+
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), dSum = d01 + d12;
|
|
8
|
+
if (dSum === 0) {
|
|
9
|
+
return [x1, y1, x1, y1];
|
|
10
|
+
}
|
|
11
|
+
const fa = (t * d01) / dSum, fb = (t * d12) / dSum, p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
|
|
7
12
|
return [p1x, p1y, p2x, p2y];
|
|
8
13
|
}
|
|
9
14
|
function expandPoints(p, tension) {
|
|
@@ -23,33 +28,11 @@ function expandPoints(p, tension) {
|
|
|
23
28
|
return allPoints;
|
|
24
29
|
}
|
|
25
30
|
function getBezierExtremaPoints(points) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
[points[1], points[3], points[5], points[7]
|
|
29
|
-
];
|
|
30
|
-
const extremaTs = [];
|
|
31
|
-
for (const axis of axisPoints) {
|
|
32
|
-
const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
|
|
33
|
-
if (a !== 0) {
|
|
34
|
-
const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
|
|
35
|
-
const c = -3 * axis[0] + 3 * axis[1];
|
|
36
|
-
const discriminant = b * b - 4 * a * c;
|
|
37
|
-
if (discriminant >= 0) {
|
|
38
|
-
const d = Math.sqrt(discriminant);
|
|
39
|
-
extremaTs.push((-b + d) / (2 * a));
|
|
40
|
-
extremaTs.push((-b - d) / (2 * a));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
31
|
+
const extrema = [];
|
|
32
|
+
for (let n = 0; n + 7 < points.length; n += 6) {
|
|
33
|
+
extrema.push(points[n + 6], points[n + 7], ...getCubicExtremaPoints(points[n], points[n + 1], points[n + 2], points[n + 3], points[n + 4], points[n + 5], points[n + 6], points[n + 7]));
|
|
43
34
|
}
|
|
44
|
-
return
|
|
45
|
-
.filter((t) => t > 0 && t < 1)
|
|
46
|
-
.flatMap((t) => axisPoints.map((axis) => {
|
|
47
|
-
const mt = 1 - t;
|
|
48
|
-
return (mt * mt * mt * axis[0] +
|
|
49
|
-
3 * mt * mt * t * axis[1] +
|
|
50
|
-
3 * mt * t * t * axis[2] +
|
|
51
|
-
t * t * t * axis[3]);
|
|
52
|
-
}));
|
|
35
|
+
return extrema;
|
|
53
36
|
}
|
|
54
37
|
export class Line extends Shape {
|
|
55
38
|
constructor(config) {
|
|
@@ -58,27 +41,37 @@ export class Line extends Shape {
|
|
|
58
41
|
this._clearCache('tensionPoints');
|
|
59
42
|
});
|
|
60
43
|
}
|
|
44
|
+
_hasTension() {
|
|
45
|
+
return this.tension() !== 0 && this.points().length > 4;
|
|
46
|
+
}
|
|
47
|
+
_eachTensionSegment(onQuadratic, onCubic) {
|
|
48
|
+
const points = this.points(), length = points.length, closed = this.closed(), tp = this.getTensionPoints(), len = tp.length;
|
|
49
|
+
let x0 = points[0], y0 = points[1], n = closed ? 0 : 4;
|
|
50
|
+
if (!closed) {
|
|
51
|
+
onQuadratic(x0, y0, tp[0], tp[1], tp[2], tp[3]);
|
|
52
|
+
x0 = tp[2];
|
|
53
|
+
y0 = tp[3];
|
|
54
|
+
}
|
|
55
|
+
while (n < len - 2) {
|
|
56
|
+
const cp1x = tp[n++], cp1y = tp[n++], cp2x = tp[n++], cp2y = tp[n++], x = tp[n++], y = tp[n++];
|
|
57
|
+
onCubic(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y);
|
|
58
|
+
x0 = x;
|
|
59
|
+
y0 = y;
|
|
60
|
+
}
|
|
61
|
+
if (!closed) {
|
|
62
|
+
onQuadratic(x0, y0, tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
61
65
|
_sceneFunc(context) {
|
|
62
|
-
const points = this.points(), length = points.length,
|
|
66
|
+
const points = this.points(), length = points.length, closed = this.closed(), bezier = this.bezier();
|
|
63
67
|
if (!length) {
|
|
64
68
|
return;
|
|
65
69
|
}
|
|
66
70
|
let n = 0;
|
|
67
71
|
context.beginPath();
|
|
68
72
|
context.moveTo(points[0], points[1]);
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
const len = tp.length;
|
|
72
|
-
n = closed ? 0 : 4;
|
|
73
|
-
if (!closed) {
|
|
74
|
-
context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]);
|
|
75
|
-
}
|
|
76
|
-
while (n < len - 2) {
|
|
77
|
-
context.bezierCurveTo(tp[n++], tp[n++], tp[n++], tp[n++], tp[n++], tp[n++]);
|
|
78
|
-
}
|
|
79
|
-
if (!closed) {
|
|
80
|
-
context.quadraticCurveTo(tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
|
81
|
-
}
|
|
73
|
+
if (this._hasTension()) {
|
|
74
|
+
this._eachTensionSegment((_x0, _y0, cpx, cpy, x, y) => context.quadraticCurveTo(cpx, cpy, x, y), (_x0, _y0, cp1x, cp1y, cp2x, cp2y, x, y) => context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y));
|
|
82
75
|
}
|
|
83
76
|
else if (bezier) {
|
|
84
77
|
n = 2;
|
|
@@ -143,26 +136,13 @@ export class Line extends Shape {
|
|
|
143
136
|
height: 0,
|
|
144
137
|
};
|
|
145
138
|
}
|
|
146
|
-
if (this.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
...this._getTensionPoints(),
|
|
151
|
-
points[points.length - 2],
|
|
152
|
-
points[points.length - 1],
|
|
153
|
-
];
|
|
139
|
+
if (this._hasTension()) {
|
|
140
|
+
const bounds = [points[0], points[1]];
|
|
141
|
+
this._eachTensionSegment((x0, y0, cpx, cpy, x, y) => bounds.push(x, y, ...getQuadraticExtremaPoints(x0, y0, cpx, cpy, x, y)), (x0, y0, cp1x, cp1y, cp2x, cp2y, x, y) => bounds.push(x, y, ...getCubicExtremaPoints(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y)));
|
|
142
|
+
points = bounds;
|
|
154
143
|
}
|
|
155
144
|
else if (this.bezier()) {
|
|
156
|
-
points = [
|
|
157
|
-
points[0],
|
|
158
|
-
points[1],
|
|
159
|
-
...getBezierExtremaPoints(this.points()),
|
|
160
|
-
points[points.length - 2],
|
|
161
|
-
points[points.length - 1],
|
|
162
|
-
];
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
points = this.points();
|
|
145
|
+
points = [points[0], points[1], ...getBezierExtremaPoints(points)];
|
|
166
146
|
}
|
|
167
147
|
let minX = points[0];
|
|
168
148
|
let maxX = points[0];
|
package/lib/shapes/Path.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Factory } from "../Factory.js";
|
|
2
2
|
import { _registerNode } from "../Global.js";
|
|
3
3
|
import { Shape } from "../Shape.js";
|
|
4
|
-
import { getCubicArcLength, getQuadraticArcLength, t2length, } from "../BezierFunctions.js";
|
|
4
|
+
import { getCubicArcLength, getCubicExtremaPoints, getQuadraticArcLength, getQuadraticExtremaPoints, t2length, } from "../BezierFunctions.js";
|
|
5
5
|
export class Path extends Shape {
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super(config);
|
|
@@ -87,10 +87,10 @@ export class Path extends Shape {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
else if (data.command === 'C') {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
points.push(data.start.x, data.start.y, data.points[4], data.points[5], ...getCubicExtremaPoints(data.start.x, data.start.y, data.points[0], data.points[1], data.points[2], data.points[3], data.points[4], data.points[5]));
|
|
91
|
+
}
|
|
92
|
+
else if (data.command === 'Q') {
|
|
93
|
+
points.push(data.start.x, data.start.y, data.points[2], data.points[3], ...getQuadraticExtremaPoints(data.start.x, data.start.y, data.points[0], data.points[1], data.points[2], data.points[3]));
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
96
96
|
points = points.concat(data.points);
|
|
@@ -146,7 +146,11 @@ export class Path extends Shape {
|
|
|
146
146
|
++i;
|
|
147
147
|
}
|
|
148
148
|
if (i === ii) {
|
|
149
|
-
|
|
149
|
+
let j = i - 1;
|
|
150
|
+
while (j > 0 && dataArray[j].points.length < 2) {
|
|
151
|
+
j--;
|
|
152
|
+
}
|
|
153
|
+
points = dataArray[j].points.slice(-2);
|
|
150
154
|
return {
|
|
151
155
|
x: points[0],
|
|
152
156
|
y: points[1],
|
package/lib/shapes/Text.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export declare class Text extends Shape<TextConfig> {
|
|
|
40
40
|
_partialText: string;
|
|
41
41
|
_partialTextX: number;
|
|
42
42
|
_partialTextY: number;
|
|
43
|
+
_partialFillStyle?: string | CanvasGradient | CanvasPattern;
|
|
44
|
+
_partialStrokeStyle?: string | CanvasGradient | CanvasPattern;
|
|
43
45
|
textWidth: number;
|
|
44
46
|
textHeight: number;
|
|
45
47
|
constructor(config?: TextConfig);
|
package/lib/shapes/Text.js
CHANGED
|
@@ -101,10 +101,16 @@ function getDummyContext() {
|
|
|
101
101
|
return dummyContext;
|
|
102
102
|
}
|
|
103
103
|
function _fillFunc(context) {
|
|
104
|
+
if (this._partialFillStyle) {
|
|
105
|
+
context.setAttr('fillStyle', this._partialFillStyle);
|
|
106
|
+
}
|
|
104
107
|
context.fillText(this._partialText, this._partialTextX, this._partialTextY);
|
|
105
108
|
}
|
|
106
109
|
function _strokeFunc(context) {
|
|
107
110
|
context.setAttr('miterLimit', 2);
|
|
111
|
+
if (this._partialStrokeStyle) {
|
|
112
|
+
context.setAttr('strokeStyle', this._partialStrokeStyle);
|
|
113
|
+
}
|
|
108
114
|
context.strokeText(this._partialText, this._partialTextX, this._partialTextY);
|
|
109
115
|
}
|
|
110
116
|
function checkDefaultFill(config) {
|
|
@@ -156,6 +162,8 @@ export class Text extends Shape {
|
|
|
156
162
|
alignY = this.getHeight() - textArrLen * lineHeightPx - padding * 2;
|
|
157
163
|
}
|
|
158
164
|
context.translate(padding, alignY + padding);
|
|
165
|
+
const fillStyleBefore = charRenderFunc ? context.fillStyle : undefined;
|
|
166
|
+
const strokeStyleBefore = charRenderFunc ? context.strokeStyle : undefined;
|
|
159
167
|
for (n = 0; n < textArrLen; n++) {
|
|
160
168
|
let lineTranslateX = 0;
|
|
161
169
|
let lineTranslateY = 0;
|
|
@@ -213,9 +221,19 @@ export class Text extends Shape {
|
|
|
213
221
|
width: this.measureSize(letter).width,
|
|
214
222
|
context,
|
|
215
223
|
});
|
|
224
|
+
const fillStyleAfter = context.fillStyle;
|
|
225
|
+
if (fillStyleAfter !== fillStyleBefore) {
|
|
226
|
+
this._partialFillStyle = fillStyleAfter;
|
|
227
|
+
}
|
|
228
|
+
const strokeStyleAfter = context.strokeStyle;
|
|
229
|
+
if (strokeStyleAfter !== strokeStyleBefore) {
|
|
230
|
+
this._partialStrokeStyle = strokeStyleAfter;
|
|
231
|
+
}
|
|
216
232
|
}
|
|
217
233
|
context.fillStrokeShape(this);
|
|
218
234
|
if (charRenderFunc) {
|
|
235
|
+
this._partialFillStyle = undefined;
|
|
236
|
+
this._partialStrokeStyle = undefined;
|
|
219
237
|
context.restore();
|
|
220
238
|
}
|
|
221
239
|
lineTranslateX += this.measureSize(letter).width + letterSpacing;
|
|
@@ -347,9 +365,10 @@ export class Text extends Shape {
|
|
|
347
365
|
let lineWidth = this._getTextWidth(line);
|
|
348
366
|
if (fixedWidth && lineWidth > maxWidth) {
|
|
349
367
|
while (line.length > 0) {
|
|
350
|
-
|
|
368
|
+
const lineArray = stringToArray(line);
|
|
369
|
+
let low = 0, high = lineArray.length, match = '', matchWidth = 0;
|
|
351
370
|
while (low < high) {
|
|
352
|
-
const mid = (low + high) >>> 1,
|
|
371
|
+
const mid = (low + high) >>> 1, substr = lineArray.slice(0, mid + 1).join(''), substrWidth = this._getTextWidth(substr);
|
|
353
372
|
const shouldConsiderEllipsis = shouldAddEllipsis &&
|
|
354
373
|
fixedHeight &&
|
|
355
374
|
currentHeightPx + lineHeightPx > maxHeightPx;
|
|
@@ -367,7 +386,6 @@ export class Text extends Shape {
|
|
|
367
386
|
}
|
|
368
387
|
if (match) {
|
|
369
388
|
if (wrapAtWord) {
|
|
370
|
-
const lineArray = stringToArray(line);
|
|
371
389
|
const matchArray = stringToArray(match);
|
|
372
390
|
const nextChar = lineArray[matchArray.length];
|
|
373
391
|
const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
|
|
@@ -395,7 +413,6 @@ export class Text extends Shape {
|
|
|
395
413
|
this._tryToAddEllipsisToLastLine();
|
|
396
414
|
break;
|
|
397
415
|
}
|
|
398
|
-
const lineArray = stringToArray(line);
|
|
399
416
|
line = lineArray.slice(low).join('').trimLeft();
|
|
400
417
|
if (line.length > 0) {
|
|
401
418
|
lineWidth = this._getTextWidth(line);
|
|
@@ -42,11 +42,13 @@ export declare class Transformer extends Group {
|
|
|
42
42
|
_nodes: Array<Node>;
|
|
43
43
|
_movingAnchorName: string | null;
|
|
44
44
|
_transforming: boolean;
|
|
45
|
+
_transformWindow: Window | null;
|
|
45
46
|
_anchorDragOffset: Vector2d;
|
|
46
47
|
sin: number;
|
|
47
48
|
cos: number;
|
|
48
49
|
_cursorChange: boolean;
|
|
49
50
|
_elementsCreated: boolean;
|
|
51
|
+
_updateScheduled: boolean;
|
|
50
52
|
static isTransforming: () => boolean;
|
|
51
53
|
constructor(config?: TransformerConfig);
|
|
52
54
|
attachTo(node: Node): this;
|
|
@@ -86,7 +88,9 @@ export declare class Transformer extends Group {
|
|
|
86
88
|
_handleMouseUp(e: any): void;
|
|
87
89
|
getAbsoluteTransform(): Transform;
|
|
88
90
|
_removeEvents(e?: any): void;
|
|
89
|
-
_fitNodesInto(newAttrs: any, evt?: any): void;
|
|
91
|
+
_fitNodesInto(newAttrs: any, evt?: any, anchorProjected?: boolean): void;
|
|
92
|
+
_doFitNodesInto(newAttrs: any, evt?: any, anchorProjected?: boolean): void;
|
|
93
|
+
_scheduleUpdate(): void;
|
|
90
94
|
forceUpdate(): void;
|
|
91
95
|
_batchChangeChild(selector: string, attrs: any): void;
|
|
92
96
|
update(): void;
|
|
@@ -146,7 +146,9 @@ export class Transformer extends Group {
|
|
|
146
146
|
super(config);
|
|
147
147
|
this._movingAnchorName = null;
|
|
148
148
|
this._transforming = false;
|
|
149
|
+
this._transformWindow = null;
|
|
149
150
|
this._elementsCreated = false;
|
|
151
|
+
this._updateScheduled = false;
|
|
150
152
|
this._createElements();
|
|
151
153
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
152
154
|
this._handleMouseUp = this._handleMouseUp.bind(this);
|
|
@@ -190,12 +192,14 @@ export class Transformer extends Group {
|
|
|
190
192
|
}
|
|
191
193
|
this._nodes.forEach((node) => {
|
|
192
194
|
const onChange = () => {
|
|
195
|
+
if (this._transforming)
|
|
196
|
+
return;
|
|
193
197
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
194
198
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
195
199
|
}
|
|
196
200
|
this._resetTransformCache();
|
|
197
|
-
if (!this.
|
|
198
|
-
this.
|
|
201
|
+
if (!this.isDragging()) {
|
|
202
|
+
this._scheduleUpdate();
|
|
199
203
|
}
|
|
200
204
|
};
|
|
201
205
|
if (node._attrsAffectingSize.length) {
|
|
@@ -473,6 +477,7 @@ export class Transformer extends Group {
|
|
|
473
477
|
});
|
|
474
478
|
}
|
|
475
479
|
_handleMouseDown(e) {
|
|
480
|
+
var _a;
|
|
476
481
|
if (this._transforming) {
|
|
477
482
|
return;
|
|
478
483
|
}
|
|
@@ -483,11 +488,13 @@ export class Transformer extends Group {
|
|
|
483
488
|
const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
|
|
484
489
|
this.sin = Math.abs(height / hypotenuse);
|
|
485
490
|
this.cos = Math.abs(width / hypotenuse);
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
+
const win = (_a = this.getStage()) === null || _a === void 0 ? void 0 : _a._getOwnerWindow();
|
|
492
|
+
this._transformWindow = win || null;
|
|
493
|
+
if (win) {
|
|
494
|
+
win.addEventListener('mousemove', this._handleMouseMove);
|
|
495
|
+
win.addEventListener('touchmove', this._handleMouseMove);
|
|
496
|
+
win.addEventListener('mouseup', this._handleMouseUp, true);
|
|
497
|
+
win.addEventListener('touchend', this._handleMouseUp, true);
|
|
491
498
|
}
|
|
492
499
|
this._transforming = true;
|
|
493
500
|
const ap = e.target.getAbsolutePosition();
|
|
@@ -551,8 +558,10 @@ export class Transformer extends Group {
|
|
|
551
558
|
keepProportion = this.keepRatio() || e.shiftKey;
|
|
552
559
|
}
|
|
553
560
|
let centeredScaling = this.centeredScaling() || e.altKey;
|
|
561
|
+
let anchorProjected = false;
|
|
554
562
|
if (this._movingAnchorName === 'top-left') {
|
|
555
563
|
if (keepProportion) {
|
|
564
|
+
anchorProjected = true;
|
|
556
565
|
const comparePoint = centeredScaling
|
|
557
566
|
? {
|
|
558
567
|
x: this.width() / 2,
|
|
@@ -577,6 +586,7 @@ export class Transformer extends Group {
|
|
|
577
586
|
}
|
|
578
587
|
else if (this._movingAnchorName === 'top-right') {
|
|
579
588
|
if (keepProportion) {
|
|
589
|
+
anchorProjected = true;
|
|
580
590
|
const comparePoint = centeredScaling
|
|
581
591
|
? {
|
|
582
592
|
x: this.width() / 2,
|
|
@@ -607,6 +617,7 @@ export class Transformer extends Group {
|
|
|
607
617
|
}
|
|
608
618
|
else if (this._movingAnchorName === 'bottom-left') {
|
|
609
619
|
if (keepProportion) {
|
|
620
|
+
anchorProjected = true;
|
|
610
621
|
const comparePoint = centeredScaling
|
|
611
622
|
? {
|
|
612
623
|
x: this.width() / 2,
|
|
@@ -634,6 +645,7 @@ export class Transformer extends Group {
|
|
|
634
645
|
}
|
|
635
646
|
else if (this._movingAnchorName === 'bottom-right') {
|
|
636
647
|
if (keepProportion) {
|
|
648
|
+
anchorProjected = true;
|
|
637
649
|
const comparePoint = centeredScaling
|
|
638
650
|
? {
|
|
639
651
|
x: this.width() / 2,
|
|
@@ -685,7 +697,7 @@ export class Transformer extends Group {
|
|
|
685
697
|
width: width,
|
|
686
698
|
height: height,
|
|
687
699
|
rotation: Konva.getAngle(this.rotation()),
|
|
688
|
-
}, e);
|
|
700
|
+
}, e, anchorProjected);
|
|
689
701
|
}
|
|
690
702
|
_handleMouseUp(e) {
|
|
691
703
|
this._removeEvents(e);
|
|
@@ -697,11 +709,13 @@ export class Transformer extends Group {
|
|
|
697
709
|
var _a;
|
|
698
710
|
if (this._transforming) {
|
|
699
711
|
this._transforming = false;
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
712
|
+
const win = this._transformWindow;
|
|
713
|
+
this._transformWindow = null;
|
|
714
|
+
if (win) {
|
|
715
|
+
win.removeEventListener('mousemove', this._handleMouseMove);
|
|
716
|
+
win.removeEventListener('touchmove', this._handleMouseMove);
|
|
717
|
+
win.removeEventListener('mouseup', this._handleMouseUp, true);
|
|
718
|
+
win.removeEventListener('touchend', this._handleMouseUp, true);
|
|
705
719
|
}
|
|
706
720
|
const node = this.getNode();
|
|
707
721
|
activeTransformersCount--;
|
|
@@ -717,7 +731,17 @@ export class Transformer extends Group {
|
|
|
717
731
|
this._movingAnchorName = null;
|
|
718
732
|
}
|
|
719
733
|
}
|
|
720
|
-
_fitNodesInto(newAttrs, evt) {
|
|
734
|
+
_fitNodesInto(newAttrs, evt, anchorProjected = false) {
|
|
735
|
+
const prevAutoDraw = Konva.autoDrawEnabled;
|
|
736
|
+
Konva.autoDrawEnabled = false;
|
|
737
|
+
try {
|
|
738
|
+
return this._doFitNodesInto(newAttrs, evt, anchorProjected);
|
|
739
|
+
}
|
|
740
|
+
finally {
|
|
741
|
+
Konva.autoDrawEnabled = prevAutoDraw;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
_doFitNodesInto(newAttrs, evt, anchorProjected = false) {
|
|
721
745
|
const oldAttrs = this._getNodeRect();
|
|
722
746
|
const minSize = 1;
|
|
723
747
|
if (Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
|
|
@@ -730,57 +754,52 @@ export class Transformer extends Group {
|
|
|
730
754
|
}
|
|
731
755
|
const t = new Transform();
|
|
732
756
|
t.rotate(Konva.getAngle(this.rotation()));
|
|
757
|
+
const flipPadding = anchorProjected ? 0 : this.padding() * 2;
|
|
758
|
+
let widthFlip = null;
|
|
759
|
+
let heightFlip = null;
|
|
733
760
|
if (this._movingAnchorName &&
|
|
734
761
|
newAttrs.width < 0 &&
|
|
735
762
|
this._movingAnchorName.indexOf('left') >= 0) {
|
|
736
763
|
const offset = t.point({
|
|
737
|
-
x: -
|
|
764
|
+
x: -flipPadding,
|
|
738
765
|
y: 0,
|
|
739
766
|
});
|
|
740
767
|
newAttrs.x += offset.x;
|
|
741
768
|
newAttrs.y += offset.y;
|
|
742
|
-
newAttrs.width +=
|
|
743
|
-
|
|
744
|
-
this._anchorDragOffset.x -= offset.x;
|
|
745
|
-
this._anchorDragOffset.y -= offset.y;
|
|
769
|
+
newAttrs.width += flipPadding;
|
|
770
|
+
widthFlip = { axis: 'width', from: 'left', to: 'right', offset };
|
|
746
771
|
}
|
|
747
772
|
else if (this._movingAnchorName &&
|
|
748
773
|
newAttrs.width < 0 &&
|
|
749
774
|
this._movingAnchorName.indexOf('right') >= 0) {
|
|
750
775
|
const offset = t.point({
|
|
751
|
-
x:
|
|
776
|
+
x: flipPadding,
|
|
752
777
|
y: 0,
|
|
753
778
|
});
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
this._anchorDragOffset.y -= offset.y;
|
|
757
|
-
newAttrs.width += this.padding() * 2;
|
|
779
|
+
newAttrs.width += flipPadding;
|
|
780
|
+
widthFlip = { axis: 'width', from: 'right', to: 'left', offset };
|
|
758
781
|
}
|
|
759
782
|
if (this._movingAnchorName &&
|
|
760
783
|
newAttrs.height < 0 &&
|
|
761
784
|
this._movingAnchorName.indexOf('top') >= 0) {
|
|
762
785
|
const offset = t.point({
|
|
763
786
|
x: 0,
|
|
764
|
-
y: -
|
|
787
|
+
y: -flipPadding,
|
|
765
788
|
});
|
|
766
789
|
newAttrs.x += offset.x;
|
|
767
790
|
newAttrs.y += offset.y;
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
this._anchorDragOffset.y -= offset.y;
|
|
771
|
-
newAttrs.height += this.padding() * 2;
|
|
791
|
+
newAttrs.height += flipPadding;
|
|
792
|
+
heightFlip = { axis: 'height', from: 'top', to: 'bottom', offset };
|
|
772
793
|
}
|
|
773
794
|
else if (this._movingAnchorName &&
|
|
774
795
|
newAttrs.height < 0 &&
|
|
775
796
|
this._movingAnchorName.indexOf('bottom') >= 0) {
|
|
776
797
|
const offset = t.point({
|
|
777
798
|
x: 0,
|
|
778
|
-
y:
|
|
799
|
+
y: flipPadding,
|
|
779
800
|
});
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
this._anchorDragOffset.y -= offset.y;
|
|
783
|
-
newAttrs.height += this.padding() * 2;
|
|
801
|
+
newAttrs.height += flipPadding;
|
|
802
|
+
heightFlip = { axis: 'height', from: 'bottom', to: 'top', offset };
|
|
784
803
|
}
|
|
785
804
|
if (this.boundBoxFunc()) {
|
|
786
805
|
const bounded = this.boundBoxFunc()(oldAttrs, newAttrs);
|
|
@@ -791,6 +810,13 @@ export class Transformer extends Group {
|
|
|
791
810
|
Util.warn('boundBoxFunc returned falsy. You should return new bound rect from it!');
|
|
792
811
|
}
|
|
793
812
|
}
|
|
813
|
+
for (const flip of [widthFlip, heightFlip]) {
|
|
814
|
+
if (flip && newAttrs[flip.axis] < 0 && this._movingAnchorName) {
|
|
815
|
+
this._movingAnchorName = this._movingAnchorName.replace(flip.from, flip.to);
|
|
816
|
+
this._anchorDragOffset.x -= flip.offset.x;
|
|
817
|
+
this._anchorDragOffset.y -= flip.offset.y;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
794
820
|
const baseSize = 10000000;
|
|
795
821
|
const oldTr = new Transform();
|
|
796
822
|
oldTr.translate(oldAttrs.x, oldAttrs.y);
|
|
@@ -811,8 +837,8 @@ export class Transformer extends Group {
|
|
|
811
837
|
newTr.scale(newScaleX, newScaleY);
|
|
812
838
|
}
|
|
813
839
|
const delta = newTr.multiply(oldTr.invert());
|
|
840
|
+
const layersToDraw = new Set();
|
|
814
841
|
this._nodes.forEach((node) => {
|
|
815
|
-
var _a;
|
|
816
842
|
if (!node.getStage()) {
|
|
817
843
|
return;
|
|
818
844
|
}
|
|
@@ -827,7 +853,10 @@ export class Transformer extends Group {
|
|
|
827
853
|
.multiply(localTransform);
|
|
828
854
|
const attrs = newLocalTransform.decompose();
|
|
829
855
|
node.setAttrs(attrs);
|
|
830
|
-
|
|
856
|
+
const layer = node.getLayer();
|
|
857
|
+
if (layer) {
|
|
858
|
+
layersToDraw.add(layer);
|
|
859
|
+
}
|
|
831
860
|
});
|
|
832
861
|
this.rotation(Util._getRotation(newAttrs.rotation));
|
|
833
862
|
this._nodes.forEach((node) => {
|
|
@@ -836,7 +865,21 @@ export class Transformer extends Group {
|
|
|
836
865
|
});
|
|
837
866
|
this._resetTransformCache();
|
|
838
867
|
this.update();
|
|
839
|
-
this.getLayer()
|
|
868
|
+
layersToDraw.add(this.getLayer());
|
|
869
|
+
layersToDraw.forEach((layer) => layer && layer.batchDraw());
|
|
870
|
+
}
|
|
871
|
+
_scheduleUpdate() {
|
|
872
|
+
if (this._updateScheduled)
|
|
873
|
+
return;
|
|
874
|
+
this._updateScheduled = true;
|
|
875
|
+
Node._runAfterAbsTransformCascade(() => {
|
|
876
|
+
var _a;
|
|
877
|
+
this._updateScheduled = false;
|
|
878
|
+
if (!((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) || this._transforming || this.isDragging()) {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
this.update();
|
|
882
|
+
});
|
|
840
883
|
}
|
|
841
884
|
forceUpdate() {
|
|
842
885
|
this._resetTransformCache();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "konva",
|
|
3
|
-
"version": "10.3.
|
|
3
|
+
"version": "10.3.2",
|
|
4
4
|
"description": "HTML5 2d canvas library.",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"type": "module",
|
|
@@ -117,6 +117,18 @@
|
|
|
117
117
|
"tsx": "^4.21.0",
|
|
118
118
|
"typescript": "^5.9.3"
|
|
119
119
|
},
|
|
120
|
+
"peerDependencies": {
|
|
121
|
+
"canvas": "^3.0.0",
|
|
122
|
+
"skia-canvas": "^3.0.0"
|
|
123
|
+
},
|
|
124
|
+
"peerDependenciesMeta": {
|
|
125
|
+
"canvas": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
128
|
+
"skia-canvas": {
|
|
129
|
+
"optional": true
|
|
130
|
+
}
|
|
131
|
+
},
|
|
120
132
|
"keywords": [
|
|
121
133
|
"canvas",
|
|
122
134
|
"animations",
|