konva 10.7.1 → 10.8.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/konva.js +133 -33
- package/konva.min.js +4 -4
- package/lib/Global.js +2 -2
- package/lib/Shape.js +10 -6
- package/lib/shapes/Transformer.d.ts +10 -2
- package/lib/shapes/Transformer.js +120 -24
- package/package.json +1 -1
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v10.
|
|
8
|
+
* Konva JavaScript Framework v10.8.0
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date: Mon Oct
|
|
11
|
+
* Date: Mon Oct 12 2026
|
|
12
12
|
*
|
|
13
13
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
14
14
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
: {};
|
|
36
36
|
const Konva$2 = {
|
|
37
37
|
_global: glob,
|
|
38
|
-
version: '10.
|
|
38
|
+
version: '10.8.0',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -8086,12 +8086,16 @@ js: import "konva/skia-backend";
|
|
|
8086
8086
|
const forDrawing = config._forDrawing;
|
|
8087
8087
|
// Painted bounds are measured in the canvas that draws the shape
|
|
8088
8088
|
// (relativeTo): non-scaling strokes and shadows use that canvas's axes.
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
8089
|
+
let fillRect = forDrawing
|
|
8090
|
+
? this._getSelfRectForDrawing()
|
|
8091
|
+
: this.getSelfRect();
|
|
8092
|
+
if (forDrawing && !this.strokeScaleEnabled()) {
|
|
8093
|
+
fillRect = this._transformedRect(fillRect, relativeTo);
|
|
8094
|
+
}
|
|
8095
|
+
else if (fillRect.width < 0 || fillRect.height < 0) {
|
|
8096
|
+
// The identity transform normalizes negative sizes.
|
|
8097
|
+
fillRect = new Transform()._getTransformedRect(fillRect);
|
|
8098
|
+
}
|
|
8095
8099
|
const applyStroke = !config.skipStroke && this.hasStroke();
|
|
8096
8100
|
const strokeWidth = applyStroke
|
|
8097
8101
|
? forDrawing
|
|
@@ -16459,6 +16463,7 @@ js: import "konva/skia-backend";
|
|
|
16459
16463
|
'rotateAnchorOffsetChange',
|
|
16460
16464
|
'rotateAnchorAngleChange',
|
|
16461
16465
|
'rotateEnabledChange',
|
|
16466
|
+
'rotateModeChange',
|
|
16462
16467
|
'enabledAnchorsChange',
|
|
16463
16468
|
'anchorSizeChange',
|
|
16464
16469
|
'borderEnabledChange',
|
|
@@ -16507,10 +16512,37 @@ js: import "konva/skia-backend";
|
|
|
16507
16512
|
'bottom-right': 135,
|
|
16508
16513
|
};
|
|
16509
16514
|
const TOUCH_DEVICE = 'ontouchstart' in Konva$2._global;
|
|
16515
|
+
// invisible zones just outside the corners, the rotate area of rotateMode 'corners'
|
|
16516
|
+
const ROTATE_ZONE_NAMES = [
|
|
16517
|
+
'rotater-top-left',
|
|
16518
|
+
'rotater-top-right',
|
|
16519
|
+
'rotater-bottom-left',
|
|
16520
|
+
'rotater-bottom-right',
|
|
16521
|
+
];
|
|
16522
|
+
function isRotateAnchor(anchorName) {
|
|
16523
|
+
return anchorName.startsWith('rotater');
|
|
16524
|
+
}
|
|
16525
|
+
// with Shift pressed the rotation snaps to this step
|
|
16526
|
+
const SHIFT_ROTATION_STEP = Math.PI / 12;
|
|
16527
|
+
// curved double arrow drawn for the top-right corner, rotated for others
|
|
16528
|
+
function getRotateZoneCursor(deg, fallback) {
|
|
16529
|
+
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24">' +
|
|
16530
|
+
`<g transform="rotate(${deg} 12 12)" stroke-linejoin="round">` +
|
|
16531
|
+
'<path d="M5 8 A11 11 0 0 1 16 19" fill="none" stroke="white" stroke-width="4"/>' +
|
|
16532
|
+
'<path d="M2 8 L6 4.5 L6 11.5 Z M16 22 L12.5 18 L19.5 18 Z" fill="black" stroke="white"/>' +
|
|
16533
|
+
'<path d="M5 8 A11 11 0 0 1 16 19" fill="none" stroke="black" stroke-width="1.5"/>' +
|
|
16534
|
+
'</g></svg>';
|
|
16535
|
+
return `url("data:image/svg+xml,${encodeURIComponent(svg)}") 12 12, ${fallback}`;
|
|
16536
|
+
}
|
|
16510
16537
|
function getCursor(anchorName, rad, rotateCursor) {
|
|
16511
16538
|
if (anchorName === 'rotater') {
|
|
16512
16539
|
return rotateCursor;
|
|
16513
16540
|
}
|
|
16541
|
+
if (isRotateAnchor(anchorName)) {
|
|
16542
|
+
const corner = anchorName.slice('rotater-'.length);
|
|
16543
|
+
const deg = Math.round(Util.radToDeg(rad) + ANGLES[corner] - 45);
|
|
16544
|
+
return getRotateZoneCursor(deg, rotateCursor);
|
|
16545
|
+
}
|
|
16514
16546
|
rad += Util.degToRad(ANGLES[anchorName] || 0);
|
|
16515
16547
|
const angle = ((Util.radToDeg(rad) % 360) + 360) % 360;
|
|
16516
16548
|
if (Util._inRange(angle, 315 + 22.5, 360) || Util._inRange(angle, 0, 22.5)) {
|
|
@@ -16651,6 +16683,7 @@ js: import "konva/skia-backend";
|
|
|
16651
16683
|
* @param {Number} [config.rotateAnchorOffset] Default is 50
|
|
16652
16684
|
* @param {Number} [config.rotateAnchorAngle] Angle of the rotate anchor around the box, in degrees. Default is 0 (top)
|
|
16653
16685
|
* @param {String} [config.rotateAnchorCursor] Default is crosshair
|
|
16686
|
+
* @param {String} [config.rotateMode] How the user rotates: 'handle' (the rotate anchor), 'corners' (invisible zones just outside the corners) or 'both'. Default is 'handle'
|
|
16654
16687
|
* @param {Number} [config.padding] Default is 0
|
|
16655
16688
|
* @param {Boolean} [config.borderEnabled] Should we draw border? Default is true
|
|
16656
16689
|
* @param {String} [config.borderStroke] Border stroke color
|
|
@@ -16662,7 +16695,7 @@ js: import "konva/skia-backend";
|
|
|
16662
16695
|
* @param {Number} [config.anchorStrokeWidth] Anchor stroke size
|
|
16663
16696
|
* @param {Number} [config.anchorSize] Default is 10
|
|
16664
16697
|
* @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true
|
|
16665
|
-
* @param {String} [config.shiftBehavior] How does transformer react on shift key press when we are moving edges? Default is 'default'
|
|
16698
|
+
* @param {String} [config.shiftBehavior] How does transformer react on shift key press when we are moving edges? 'none' also turns off the Shift rotation snap. Default is 'default'
|
|
16666
16699
|
* @param {Boolean} [config.centeredScaling] Should we resize relative to node's center? Default is false
|
|
16667
16700
|
* @param {Array} [config.enabledAnchors] Array of names of enabled handles
|
|
16668
16701
|
* @param {Boolean} [config.flipEnabled] Can we flip/mirror shape on transform?. True by default
|
|
@@ -17063,18 +17096,27 @@ js: import "konva/skia-backend";
|
|
|
17063
17096
|
}
|
|
17064
17097
|
_createElements() {
|
|
17065
17098
|
this._createBack();
|
|
17099
|
+
// below the resize anchors, so a resize anchor wins where they overlap
|
|
17100
|
+
ROTATE_ZONE_NAMES.forEach((name) => {
|
|
17101
|
+
// invisible, but its fill keeps it in the hit graph
|
|
17102
|
+
this._createAnchor(name, '_rotate-zone').setAttrs({
|
|
17103
|
+
fill: 'transparent',
|
|
17104
|
+
strokeEnabled: false,
|
|
17105
|
+
visible: false,
|
|
17106
|
+
});
|
|
17107
|
+
});
|
|
17066
17108
|
ANCHORS_NAMES.forEach((name) => {
|
|
17067
17109
|
this._createAnchor(name);
|
|
17068
17110
|
});
|
|
17069
17111
|
this._createAnchor('rotater');
|
|
17070
17112
|
this._elementsCreated = true;
|
|
17071
17113
|
}
|
|
17072
|
-
_createAnchor(name) {
|
|
17114
|
+
_createAnchor(name, className = '_anchor') {
|
|
17073
17115
|
const anchor = new Rect({
|
|
17074
17116
|
stroke: 'rgb(0, 161, 255)',
|
|
17075
17117
|
fill: 'white',
|
|
17076
17118
|
strokeWidth: 1,
|
|
17077
|
-
name: name + '
|
|
17119
|
+
name: name + ' ' + className,
|
|
17078
17120
|
dragDistance: 0,
|
|
17079
17121
|
// make it draggable,
|
|
17080
17122
|
// so activating the anchor will not start drag&drop of any parent
|
|
@@ -17097,11 +17139,7 @@ js: import "konva/skia-backend";
|
|
|
17097
17139
|
anchor.on('mouseenter', () => {
|
|
17098
17140
|
if (this.isTransforming())
|
|
17099
17141
|
return;
|
|
17100
|
-
|
|
17101
|
-
const rotateCursor = this.rotateAnchorCursor();
|
|
17102
|
-
const cursor = getCursor(name, rad, rotateCursor);
|
|
17103
|
-
anchor.getStage().content &&
|
|
17104
|
-
(anchor.getStage().content.style.cursor = cursor);
|
|
17142
|
+
this._setAnchorCursor(name);
|
|
17105
17143
|
this._cursorChange = true;
|
|
17106
17144
|
});
|
|
17107
17145
|
anchor.on('mouseout', () => {
|
|
@@ -17112,6 +17150,14 @@ js: import "konva/skia-backend";
|
|
|
17112
17150
|
(anchor.getStage().content.style.cursor = '');
|
|
17113
17151
|
});
|
|
17114
17152
|
this.add(anchor);
|
|
17153
|
+
return anchor;
|
|
17154
|
+
}
|
|
17155
|
+
_setAnchorCursor(name, rad = Konva$2.getAngle(this.rotation())) {
|
|
17156
|
+
var _a;
|
|
17157
|
+
const content = (_a = this.getStage()) === null || _a === void 0 ? void 0 : _a.content;
|
|
17158
|
+
if (content) {
|
|
17159
|
+
content.style.cursor = getCursor(name, rad, this.rotateAnchorCursor());
|
|
17160
|
+
}
|
|
17115
17161
|
}
|
|
17116
17162
|
_createBack() {
|
|
17117
17163
|
const back = new Shape({
|
|
@@ -17127,7 +17173,9 @@ js: import "konva/skia-backend";
|
|
|
17127
17173
|
const height = shape.height();
|
|
17128
17174
|
ctx.beginPath();
|
|
17129
17175
|
ctx.rect(-padding, -padding, width + padding * 2, height + padding * 2);
|
|
17130
|
-
if (tr.rotateEnabled() &&
|
|
17176
|
+
if (tr.rotateEnabled() &&
|
|
17177
|
+
tr.rotateLineVisible() &&
|
|
17178
|
+
tr.rotateMode() !== 'corners') {
|
|
17131
17179
|
const line = getRotaterLine(tr, width, height);
|
|
17132
17180
|
ctx.moveTo(line.edgeX, line.edgeY);
|
|
17133
17181
|
ctx.lineTo(line.endX, line.endY);
|
|
@@ -17199,6 +17247,13 @@ js: import "konva/skia-backend";
|
|
|
17199
17247
|
x: pos.x - ap.x,
|
|
17200
17248
|
y: pos.y - ap.y,
|
|
17201
17249
|
};
|
|
17250
|
+
if (isRotateAnchor(this._movingAnchorName)) {
|
|
17251
|
+
const center = getCenter(attrs);
|
|
17252
|
+
this._rotateStart = {
|
|
17253
|
+
pointerAngle: Math.atan2(pos.y - center.y, pos.x - center.x),
|
|
17254
|
+
rotation: attrs.rotation,
|
|
17255
|
+
};
|
|
17256
|
+
}
|
|
17202
17257
|
activeTransformers.add(this);
|
|
17203
17258
|
this._fire('transformstart', { evt: e.evt, target: this.getNode() });
|
|
17204
17259
|
this._nodes.forEach((target) => {
|
|
@@ -17234,19 +17289,33 @@ js: import "konva/skia-backend";
|
|
|
17234
17289
|
if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
|
|
17235
17290
|
return;
|
|
17236
17291
|
}
|
|
17237
|
-
//
|
|
17238
|
-
if (this._movingAnchorName
|
|
17292
|
+
// rotation is working very differently, so do it first
|
|
17293
|
+
if (isRotateAnchor(this._movingAnchorName)) {
|
|
17239
17294
|
const attrs = this._getNodeRect();
|
|
17240
|
-
|
|
17241
|
-
|
|
17242
|
-
//
|
|
17243
|
-
//
|
|
17244
|
-
const
|
|
17245
|
-
|
|
17246
|
-
|
|
17247
|
-
|
|
17248
|
-
const
|
|
17249
|
-
const
|
|
17295
|
+
const center = getCenter(attrs);
|
|
17296
|
+
const start = this._rotateStart;
|
|
17297
|
+
// the grabbed point turns around the center by as much as the box,
|
|
17298
|
+
// so the box follows the pointer wherever it was grabbed
|
|
17299
|
+
const point = {
|
|
17300
|
+
x: newAbs.x + this._anchorDragOffset.x,
|
|
17301
|
+
y: newAbs.y + this._anchorDragOffset.y,
|
|
17302
|
+
};
|
|
17303
|
+
const pointerAngle = Math.atan2(point.y - center.y, point.x - center.x);
|
|
17304
|
+
const newRotation = start.rotation + pointerAngle - start.pointerAngle;
|
|
17305
|
+
let snappedRot;
|
|
17306
|
+
if (e.shiftKey && this.shiftBehavior() !== 'none') {
|
|
17307
|
+
snappedRot =
|
|
17308
|
+
Math.round(newRotation / SHIFT_ROTATION_STEP) * SHIFT_ROTATION_STEP;
|
|
17309
|
+
}
|
|
17310
|
+
else {
|
|
17311
|
+
const tol = Konva$2.getAngle(this.rotationSnapTolerance());
|
|
17312
|
+
snappedRot = getSnap(this.rotationSnaps(), newRotation, tol);
|
|
17313
|
+
}
|
|
17314
|
+
// a corner zone cursor shows the direction of the turned corner,
|
|
17315
|
+
// set before the transform event so its handlers can override it
|
|
17316
|
+
if (this._movingAnchorName !== 'rotater') {
|
|
17317
|
+
this._setAnchorCursor(this._movingAnchorName, snappedRot);
|
|
17318
|
+
}
|
|
17250
17319
|
const diff = snappedRot - attrs.rotation;
|
|
17251
17320
|
const shape = rotateAroundCenter(attrs, diff);
|
|
17252
17321
|
this._fitNodesInto(shape, e);
|
|
@@ -17676,7 +17745,7 @@ js: import "konva/skia-backend";
|
|
|
17676
17745
|
}
|
|
17677
17746
|
const styleFunc = this.anchorStyleFunc();
|
|
17678
17747
|
if (styleFunc) {
|
|
17679
|
-
Object.values(this._anchors).forEach((node) => styleFunc(node));
|
|
17748
|
+
Object.values(this._anchors).forEach((node) => node.hasName('_anchor') && styleFunc(node));
|
|
17680
17749
|
}
|
|
17681
17750
|
(_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
|
|
17682
17751
|
}
|
|
@@ -17700,7 +17769,7 @@ js: import "konva/skia-backend";
|
|
|
17700
17769
|
const resizeEnabled = this.resizeEnabled();
|
|
17701
17770
|
const padding = this.padding();
|
|
17702
17771
|
const anchorSize = this.anchorSize();
|
|
17703
|
-
const anchors = Object.values(this._anchors);
|
|
17772
|
+
const anchors = Object.values(this._anchors).filter((node) => node.hasName('_anchor'));
|
|
17704
17773
|
anchors.forEach((node) => {
|
|
17705
17774
|
node.setAttrs({
|
|
17706
17775
|
width: anchorSize,
|
|
@@ -17765,11 +17834,25 @@ js: import "konva/skia-backend";
|
|
|
17765
17834
|
offsetY: anchorSize / 2 - padding,
|
|
17766
17835
|
visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
|
|
17767
17836
|
});
|
|
17837
|
+
const rotateMode = this.rotateMode();
|
|
17768
17838
|
const rotaterLine = getRotaterLine(this, width, height);
|
|
17769
17839
|
this._anchors['rotater'].setAttrs({
|
|
17770
17840
|
x: rotaterLine.endX,
|
|
17771
17841
|
y: rotaterLine.endY,
|
|
17772
|
-
visible: this.rotateEnabled(),
|
|
17842
|
+
visible: this.rotateEnabled() && rotateMode !== 'corners',
|
|
17843
|
+
});
|
|
17844
|
+
// each zone is a square that touches its corner from the outside
|
|
17845
|
+
const zoneSize = anchorSize * 2;
|
|
17846
|
+
const zonesVisible = this.rotateEnabled() && rotateMode !== 'handle';
|
|
17847
|
+
const near = -padding - zoneSize;
|
|
17848
|
+
ROTATE_ZONE_NAMES.forEach((name) => {
|
|
17849
|
+
this._anchors[name].setAttrs({
|
|
17850
|
+
x: name.includes('left') ? near : width + padding,
|
|
17851
|
+
y: name.includes('top') ? near : height + padding,
|
|
17852
|
+
width: zoneSize,
|
|
17853
|
+
height: zoneSize,
|
|
17854
|
+
visible: zonesVisible,
|
|
17855
|
+
});
|
|
17773
17856
|
});
|
|
17774
17857
|
this._back.setAttrs({
|
|
17775
17858
|
width: width,
|
|
@@ -18008,6 +18091,23 @@ js: import "konva/skia-backend";
|
|
|
18008
18091
|
* transformer.rotateAnchorCursor('grab');
|
|
18009
18092
|
*/
|
|
18010
18093
|
Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
|
|
18094
|
+
/**
|
|
18095
|
+
* get/set how the user rotates the nodes. 'handle' shows the rotate anchor,
|
|
18096
|
+
* 'corners' makes invisible zones just outside the box corners rotate,
|
|
18097
|
+
* 'both' enables both. Hold Shift while rotating to snap to 15 degree steps, unless shiftBehavior is 'none'.
|
|
18098
|
+
* While a corner zone rotates, `getActiveAnchor()` returns its name, such as 'rotater-top-left'.
|
|
18099
|
+
* @name Konva.Transformer#rotateMode
|
|
18100
|
+
* @method
|
|
18101
|
+
* @param {String} mode
|
|
18102
|
+
* @returns {String}
|
|
18103
|
+
* @example
|
|
18104
|
+
* // get
|
|
18105
|
+
* var rotateMode = transformer.rotateMode();
|
|
18106
|
+
*
|
|
18107
|
+
* // set
|
|
18108
|
+
* transformer.rotateMode('corners');
|
|
18109
|
+
*/
|
|
18110
|
+
Factory.addGetterSetter(Transformer, 'rotateMode', 'handle');
|
|
18011
18111
|
/**
|
|
18012
18112
|
* get/set distance for rotation tolerance
|
|
18013
18113
|
* @name Konva.Transformer#rotationSnapTolerance
|