konva 10.2.0 → 10.2.3
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 +64 -80
- package/konva.min.js +3 -3
- package/lib/DragAndDrop.d.ts +1 -0
- package/lib/DragAndDrop.js +3 -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 +9 -0
- package/package.json +1 -1
package/lib/DragAndDrop.d.ts
CHANGED
package/lib/DragAndDrop.js
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.2.
|
|
16
|
+
version: '10.2.3',
|
|
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
|
}
|
|
@@ -46,6 +46,7 @@ export declare class Transformer extends Group {
|
|
|
46
46
|
sin: number;
|
|
47
47
|
cos: number;
|
|
48
48
|
_cursorChange: boolean;
|
|
49
|
+
_elementsCreated: boolean;
|
|
49
50
|
static isTransforming: () => boolean;
|
|
50
51
|
constructor(config?: TransformerConfig);
|
|
51
52
|
attachTo(node: Node): this;
|
|
@@ -92,6 +93,7 @@ export declare class Transformer extends Group {
|
|
|
92
93
|
isTransforming(): boolean;
|
|
93
94
|
stopTransform(): void;
|
|
94
95
|
destroy(): this;
|
|
96
|
+
add(...children: any[]): this;
|
|
95
97
|
toObject(): {
|
|
96
98
|
attrs: any;
|
|
97
99
|
className: string;
|
|
@@ -146,6 +146,7 @@ export class Transformer extends Group {
|
|
|
146
146
|
super(config);
|
|
147
147
|
this._movingAnchorName = null;
|
|
148
148
|
this._transforming = false;
|
|
149
|
+
this._elementsCreated = false;
|
|
149
150
|
this._createElements();
|
|
150
151
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
151
152
|
this._handleMouseUp = this._handleMouseUp.bind(this);
|
|
@@ -365,6 +366,7 @@ export class Transformer extends Group {
|
|
|
365
366
|
this._createAnchor(name);
|
|
366
367
|
});
|
|
367
368
|
this._createAnchor('rotater');
|
|
369
|
+
this._elementsCreated = true;
|
|
368
370
|
}
|
|
369
371
|
_createAnchor(name) {
|
|
370
372
|
const anchor = new Rect({
|
|
@@ -987,6 +989,13 @@ export class Transformer extends Group {
|
|
|
987
989
|
this._removeEvents();
|
|
988
990
|
return this;
|
|
989
991
|
}
|
|
992
|
+
add(...children) {
|
|
993
|
+
if (this._elementsCreated) {
|
|
994
|
+
Util.error('You cannot add external nodes to the Transformer. Use tr.nodes([node]) instead.');
|
|
995
|
+
return this;
|
|
996
|
+
}
|
|
997
|
+
return super.add(...children);
|
|
998
|
+
}
|
|
990
999
|
toObject() {
|
|
991
1000
|
return Node.prototype.toObject.call(this);
|
|
992
1001
|
}
|