konva 10.1.0 → 10.2.1
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 +143 -87
- package/konva.min.js +4 -4
- package/lib/DragAndDrop.d.ts +1 -0
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +3 -2
- package/lib/Node.js +19 -9
- package/lib/Shape.js +5 -5
- package/lib/_CoreInternals.d.ts +1 -0
- package/lib/_FullInternals.d.ts +1 -0
- package/lib/shapes/TextPath.js +7 -2
- package/lib/shapes/Transformer.d.ts +2 -0
- package/lib/shapes/Transformer.js +59 -6
- package/package.json +1 -1
package/lib/DragAndDrop.d.ts
CHANGED
package/lib/Global.js
CHANGED
|
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
|
|
|
13
13
|
: {};
|
|
14
14
|
export const Konva = {
|
|
15
15
|
_global: glob,
|
|
16
|
-
version: '10.1
|
|
16
|
+
version: '10.2.1',
|
|
17
17
|
isBrowser: detectBrowser(),
|
|
18
18
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
19
19
|
dblClickWindow: 400,
|
package/lib/Node.d.ts
CHANGED
|
@@ -124,12 +124,13 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
124
124
|
_drawCachedSceneCanvas(context: Context): void;
|
|
125
125
|
_drawCachedHitCanvas(context: Context): void;
|
|
126
126
|
_getCachedSceneCanvas(): Canvas;
|
|
127
|
-
on<K extends keyof NodeEventMap>(evtStr: K, handler: KonvaEventListener<this, NodeEventMap[K]>):
|
|
127
|
+
on<K extends keyof NodeEventMap>(evtStr: K, handler: KonvaEventListener<this, NodeEventMap[K]>): this;
|
|
128
|
+
on<K extends keyof NodeEventMap>(evtStr: K, selector: string, handler: KonvaEventListener<Node, NodeEventMap[K]>): this;
|
|
128
129
|
off(evtStr?: string, callback?: Function): this;
|
|
129
130
|
dispatchEvent(evt: any): this;
|
|
130
131
|
addEventListener(type: string, handler: (e: Event) => void): this;
|
|
131
132
|
removeEventListener(type: string): this;
|
|
132
|
-
_delegate(event: string, selector: string, handler: (e: Event) => void):
|
|
133
|
+
_delegate(event: string, selector: string, handler: (e: Event) => void): this;
|
|
133
134
|
remove(): this;
|
|
134
135
|
_clearCaches(): void;
|
|
135
136
|
_remove(): void;
|
package/lib/Node.js
CHANGED
|
@@ -351,12 +351,15 @@ export class Node {
|
|
|
351
351
|
this._filterUpToDate = true;
|
|
352
352
|
return filterCanvas;
|
|
353
353
|
}
|
|
354
|
-
on(
|
|
354
|
+
on(...args) {
|
|
355
|
+
const evtStr = args[0];
|
|
356
|
+
const selectorOrHandler = args[1];
|
|
357
|
+
const handler = args[2];
|
|
355
358
|
if (this._cache) {
|
|
356
359
|
this._cache.delete(ALL_LISTENERS);
|
|
357
360
|
}
|
|
358
|
-
if (
|
|
359
|
-
return this._delegate.apply(this,
|
|
361
|
+
if (args.length === 3) {
|
|
362
|
+
return this._delegate.apply(this, args);
|
|
360
363
|
}
|
|
361
364
|
const events = evtStr.split(SPACE);
|
|
362
365
|
for (let n = 0; n < events.length; n++) {
|
|
@@ -367,7 +370,7 @@ export class Node {
|
|
|
367
370
|
if (!this.eventListeners[baseEvent]) {
|
|
368
371
|
this.eventListeners[baseEvent] = [];
|
|
369
372
|
}
|
|
370
|
-
this.eventListeners[baseEvent].push({ name, handler });
|
|
373
|
+
this.eventListeners[baseEvent].push({ name, handler: selectorOrHandler });
|
|
371
374
|
}
|
|
372
375
|
return this;
|
|
373
376
|
}
|
|
@@ -426,12 +429,18 @@ export class Node {
|
|
|
426
429
|
handler.call(targets[i], evt);
|
|
427
430
|
}
|
|
428
431
|
});
|
|
432
|
+
return this;
|
|
429
433
|
}
|
|
430
434
|
remove() {
|
|
431
435
|
if (this.isDragging()) {
|
|
432
436
|
this.stopDrag();
|
|
433
437
|
}
|
|
434
438
|
DD._dragElements.delete(this._id);
|
|
439
|
+
DD._dragElements.forEach((elem, key) => {
|
|
440
|
+
if (this.isAncestorOf(elem.node)) {
|
|
441
|
+
DD._dragElements.delete(key);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
435
444
|
this._remove();
|
|
436
445
|
return this;
|
|
437
446
|
}
|
|
@@ -1327,6 +1336,7 @@ export class Node {
|
|
|
1327
1336
|
},
|
|
1328
1337
|
dragStatus: 'ready',
|
|
1329
1338
|
pointerId,
|
|
1339
|
+
startEvent: evt,
|
|
1330
1340
|
});
|
|
1331
1341
|
}
|
|
1332
1342
|
startDrag(evt, bubbleEvent = true) {
|
|
@@ -1338,7 +1348,7 @@ export class Node {
|
|
|
1338
1348
|
this.fire('dragstart', {
|
|
1339
1349
|
type: 'dragstart',
|
|
1340
1350
|
target: this,
|
|
1341
|
-
evt: evt && evt.evt,
|
|
1351
|
+
evt: (elem.startEvent && elem.startEvent.evt) || (evt && evt.evt),
|
|
1342
1352
|
}, bubbleEvent);
|
|
1343
1353
|
}
|
|
1344
1354
|
_setDragPosition(evt, elem) {
|
|
@@ -1476,7 +1486,7 @@ Node.protoListenerMap = new Map();
|
|
|
1476
1486
|
Node.prototype.nodeType = 'Node';
|
|
1477
1487
|
Node.prototype._attrsAffectingSize = [];
|
|
1478
1488
|
Node.prototype.eventListeners = {};
|
|
1479
|
-
Node.prototype.on
|
|
1489
|
+
Node.prototype.on(TRANSFORM_CHANGE_STR, function () {
|
|
1480
1490
|
if (this._batchingTransformChange) {
|
|
1481
1491
|
this._needClearTransformCache = true;
|
|
1482
1492
|
return;
|
|
@@ -1484,13 +1494,13 @@ Node.prototype.on.call(Node.prototype, TRANSFORM_CHANGE_STR, function () {
|
|
|
1484
1494
|
this._clearCache(TRANSFORM);
|
|
1485
1495
|
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
1486
1496
|
});
|
|
1487
|
-
Node.prototype.on
|
|
1497
|
+
Node.prototype.on('visibleChange.konva', function () {
|
|
1488
1498
|
this._clearSelfAndDescendantCache(VISIBLE);
|
|
1489
1499
|
});
|
|
1490
|
-
Node.prototype.on
|
|
1500
|
+
Node.prototype.on('listeningChange.konva', function () {
|
|
1491
1501
|
this._clearSelfAndDescendantCache(LISTENING);
|
|
1492
1502
|
});
|
|
1493
|
-
Node.prototype.on
|
|
1503
|
+
Node.prototype.on('opacityChange.konva', function () {
|
|
1494
1504
|
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
1495
1505
|
});
|
|
1496
1506
|
const addGetterSetter = Factory.addGetterSetter;
|
package/lib/Shape.js
CHANGED
|
@@ -465,11 +465,11 @@ Shape.prototype._centroid = false;
|
|
|
465
465
|
Shape.prototype.nodeType = 'Shape';
|
|
466
466
|
_registerNode(Shape);
|
|
467
467
|
Shape.prototype.eventListeners = {};
|
|
468
|
-
Shape.prototype.on
|
|
469
|
-
Shape.prototype.on
|
|
470
|
-
Shape.prototype.on
|
|
471
|
-
Shape.prototype.on
|
|
472
|
-
Shape.prototype.on
|
|
468
|
+
Shape.prototype.on('shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearHasShadowCache);
|
|
469
|
+
Shape.prototype.on('shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearGetShadowRGBACache);
|
|
470
|
+
Shape.prototype.on('fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva', _clearFillPatternCache);
|
|
471
|
+
Shape.prototype.on('fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva', _clearLinearGradientCache);
|
|
472
|
+
Shape.prototype.on('fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva', _clearRadialGradientCache);
|
|
473
473
|
Factory.addGetterSetter(Shape, 'stroke', undefined, getStringOrGradientValidator());
|
|
474
474
|
Factory.addGetterSetter(Shape, 'strokeWidth', 2, getNumberValidator());
|
|
475
475
|
Factory.addGetterSetter(Shape, 'fillAfterStrokeEnabled', false);
|
package/lib/_CoreInternals.d.ts
CHANGED
|
@@ -164,6 +164,7 @@ export declare const Konva: {
|
|
|
164
164
|
startPointerPos: import("./types.ts").Vector2d;
|
|
165
165
|
offset: import("./types.ts").Vector2d;
|
|
166
166
|
pointerId?: number;
|
|
167
|
+
startEvent?: any;
|
|
167
168
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
168
169
|
}>;
|
|
169
170
|
_drag(evt: any): void;
|
package/lib/_FullInternals.d.ts
CHANGED
|
@@ -170,6 +170,7 @@ export declare const Konva: {
|
|
|
170
170
|
startPointerPos: import("./types.ts").Vector2d;
|
|
171
171
|
offset: import("./types.ts").Vector2d;
|
|
172
172
|
pointerId?: number;
|
|
173
|
+
startEvent?: any;
|
|
173
174
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
174
175
|
}>;
|
|
175
176
|
_drag(evt: any): void;
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -146,7 +146,7 @@ export class TextPath extends Shape {
|
|
|
146
146
|
});
|
|
147
147
|
width += chars[i].width;
|
|
148
148
|
}
|
|
149
|
-
const { height } = this._getTextSize(this.attrs.text);
|
|
149
|
+
const { width: fullTextWidth, height } = this._getTextSize(this.attrs.text);
|
|
150
150
|
this.textWidth = width;
|
|
151
151
|
this.textHeight = height;
|
|
152
152
|
this.glyphInfo = [];
|
|
@@ -156,6 +156,7 @@ export class TextPath extends Shape {
|
|
|
156
156
|
const letterSpacing = this.letterSpacing();
|
|
157
157
|
const align = this.align();
|
|
158
158
|
const kerningFunc = this.kerningFunc();
|
|
159
|
+
const kerningAdjustment = Math.max(0, width - fullTextWidth);
|
|
159
160
|
const textWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
|
|
160
161
|
let offset = 0;
|
|
161
162
|
if (align === 'center') {
|
|
@@ -175,7 +176,11 @@ export class TextPath extends Shape {
|
|
|
175
176
|
const numberOfSpaces = this.text().split(' ').length - 1;
|
|
176
177
|
glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
|
|
177
178
|
}
|
|
178
|
-
const
|
|
179
|
+
const charEndLength = offsetToGlyph + glyphWidth;
|
|
180
|
+
const charEndPoint = this._getPointAtLength(charEndLength > this.pathLength &&
|
|
181
|
+
charEndLength - this.pathLength <= kerningAdjustment
|
|
182
|
+
? this.pathLength
|
|
183
|
+
: charEndLength);
|
|
179
184
|
if (!charEndPoint) {
|
|
180
185
|
return;
|
|
181
186
|
}
|
|
@@ -15,6 +15,7 @@ export interface TransformerConfig extends ContainerConfig {
|
|
|
15
15
|
rotationSnaps?: Array<number>;
|
|
16
16
|
rotationSnapTolerance?: number;
|
|
17
17
|
rotateAnchorOffset?: number;
|
|
18
|
+
rotateAnchorAngle?: number;
|
|
18
19
|
rotateAnchorCursor?: string;
|
|
19
20
|
borderEnabled?: boolean;
|
|
20
21
|
borderStroke?: string;
|
|
@@ -106,6 +107,7 @@ export declare class Transformer extends Group {
|
|
|
106
107
|
rotateEnabled: GetSet<boolean, this>;
|
|
107
108
|
rotateLineVisible: GetSet<boolean, this>;
|
|
108
109
|
rotateAnchorOffset: GetSet<number, this>;
|
|
110
|
+
rotateAnchorAngle: GetSet<number, this>;
|
|
109
111
|
rotationSnapTolerance: GetSet<number, this>;
|
|
110
112
|
rotateAnchorCursor: GetSet<string, this>;
|
|
111
113
|
padding: GetSet<number, this>;
|
|
@@ -11,6 +11,7 @@ const EVENTS_NAME = 'tr-konva';
|
|
|
11
11
|
const ATTR_CHANGE_LIST = [
|
|
12
12
|
'resizeEnabledChange',
|
|
13
13
|
'rotateAnchorOffsetChange',
|
|
14
|
+
'rotateAnchorAngleChange',
|
|
14
15
|
'rotateEnabledChange',
|
|
15
16
|
'enabledAnchorsChange',
|
|
16
17
|
'anchorSizeChange',
|
|
@@ -409,11 +410,38 @@ export class Transformer extends Group {
|
|
|
409
410
|
sceneFunc(ctx, shape) {
|
|
410
411
|
const tr = shape.getParent();
|
|
411
412
|
const padding = tr.padding();
|
|
413
|
+
const width = shape.width();
|
|
414
|
+
const height = shape.height();
|
|
412
415
|
ctx.beginPath();
|
|
413
|
-
ctx.rect(-padding, -padding,
|
|
414
|
-
ctx.moveTo(shape.width() / 2, -padding);
|
|
416
|
+
ctx.rect(-padding, -padding, width + padding * 2, height + padding * 2);
|
|
415
417
|
if (tr.rotateEnabled() && tr.rotateLineVisible()) {
|
|
416
|
-
|
|
418
|
+
const rotateAnchorAngle = tr.rotateAnchorAngle();
|
|
419
|
+
const rotateAnchorOffset = tr.rotateAnchorOffset();
|
|
420
|
+
const rad = Util.degToRad(rotateAnchorAngle);
|
|
421
|
+
const dirX = Math.sin(rad);
|
|
422
|
+
const dirY = -Math.cos(rad);
|
|
423
|
+
const cx = width / 2;
|
|
424
|
+
const cy = height / 2;
|
|
425
|
+
let t = Infinity;
|
|
426
|
+
if (dirY < 0) {
|
|
427
|
+
t = Math.min(t, -cy / dirY);
|
|
428
|
+
}
|
|
429
|
+
else if (dirY > 0) {
|
|
430
|
+
t = Math.min(t, (height - cy) / dirY);
|
|
431
|
+
}
|
|
432
|
+
if (dirX < 0) {
|
|
433
|
+
t = Math.min(t, -cx / dirX);
|
|
434
|
+
}
|
|
435
|
+
else if (dirX > 0) {
|
|
436
|
+
t = Math.min(t, (width - cx) / dirX);
|
|
437
|
+
}
|
|
438
|
+
const edgeX = cx + dirX * t;
|
|
439
|
+
const edgeY = cy + dirY * t;
|
|
440
|
+
const sign = Util._sign(height);
|
|
441
|
+
const endX = edgeX + dirX * rotateAnchorOffset * sign;
|
|
442
|
+
const endY = edgeY + dirY * rotateAnchorOffset * sign;
|
|
443
|
+
ctx.moveTo(edgeX, edgeY);
|
|
444
|
+
ctx.lineTo(endX, endY);
|
|
417
445
|
}
|
|
418
446
|
ctx.fillStrokeShape(shape);
|
|
419
447
|
},
|
|
@@ -495,7 +523,8 @@ export class Transformer extends Group {
|
|
|
495
523
|
const attrs = this._getNodeRect();
|
|
496
524
|
x = anchorNode.x() - attrs.width / 2;
|
|
497
525
|
y = -anchorNode.y() + attrs.height / 2;
|
|
498
|
-
|
|
526
|
+
const rotateAnchorAngleRad = Konva.getAngle(this.rotateAnchorAngle());
|
|
527
|
+
let delta = Math.atan2(-y, x) + Math.PI / 2 - rotateAnchorAngleRad;
|
|
499
528
|
if (attrs.height < 0) {
|
|
500
529
|
delta -= Math.PI;
|
|
501
530
|
}
|
|
@@ -890,9 +919,32 @@ export class Transformer extends Group {
|
|
|
890
919
|
offsetY: anchorSize / 2 - padding,
|
|
891
920
|
visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
|
|
892
921
|
});
|
|
922
|
+
const rotateAnchorAngle = this.rotateAnchorAngle();
|
|
923
|
+
const rotateAnchorOffset = this.rotateAnchorOffset();
|
|
924
|
+
const rad = Util.degToRad(rotateAnchorAngle);
|
|
925
|
+
const dirX = Math.sin(rad);
|
|
926
|
+
const dirY = -Math.cos(rad);
|
|
927
|
+
const cx = width / 2;
|
|
928
|
+
const cy = height / 2;
|
|
929
|
+
let t = Infinity;
|
|
930
|
+
if (dirY < 0) {
|
|
931
|
+
t = Math.min(t, -cy / dirY);
|
|
932
|
+
}
|
|
933
|
+
else if (dirY > 0) {
|
|
934
|
+
t = Math.min(t, (height - cy) / dirY);
|
|
935
|
+
}
|
|
936
|
+
if (dirX < 0) {
|
|
937
|
+
t = Math.min(t, -cx / dirX);
|
|
938
|
+
}
|
|
939
|
+
else if (dirX > 0) {
|
|
940
|
+
t = Math.min(t, (width - cx) / dirX);
|
|
941
|
+
}
|
|
942
|
+
const edgeX = cx + dirX * t;
|
|
943
|
+
const edgeY = cy + dirY * t;
|
|
944
|
+
const sign = Util._sign(height);
|
|
893
945
|
this._batchChangeChild('.rotater', {
|
|
894
|
-
x:
|
|
895
|
-
y:
|
|
946
|
+
x: edgeX + dirX * rotateAnchorOffset * sign,
|
|
947
|
+
y: edgeY + dirY * rotateAnchorOffset * sign - padding * dirY,
|
|
896
948
|
visible: this.rotateEnabled(),
|
|
897
949
|
});
|
|
898
950
|
this._batchChangeChild('.back', {
|
|
@@ -980,6 +1032,7 @@ Factory.addGetterSetter(Transformer, 'rotateEnabled', true);
|
|
|
980
1032
|
Factory.addGetterSetter(Transformer, 'rotateLineVisible', true);
|
|
981
1033
|
Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
|
|
982
1034
|
Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, getNumberValidator());
|
|
1035
|
+
Factory.addGetterSetter(Transformer, 'rotateAnchorAngle', 0, getNumberValidator());
|
|
983
1036
|
Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
|
|
984
1037
|
Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, getNumberValidator());
|
|
985
1038
|
Factory.addGetterSetter(Transformer, 'borderEnabled', true);
|