konva 10.2.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.
@@ -9,6 +9,7 @@ export declare const DD: {
9
9
  startPointerPos: Vector2d;
10
10
  offset: Vector2d;
11
11
  pointerId?: number;
12
+ startEvent?: any;
12
13
  dragStatus: "ready" | "dragging" | "stopped";
13
14
  }>;
14
15
  _drag(evt: any): void;
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.0',
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]>): void | this;
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): 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(evtStr, handler) {
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 (arguments.length === 3) {
359
- return this._delegate.apply(this, arguments);
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.call(Node.prototype, TRANSFORM_CHANGE_STR, function () {
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.call(Node.prototype, 'visibleChange.konva', function () {
1497
+ Node.prototype.on('visibleChange.konva', function () {
1488
1498
  this._clearSelfAndDescendantCache(VISIBLE);
1489
1499
  });
1490
- Node.prototype.on.call(Node.prototype, 'listeningChange.konva', function () {
1500
+ Node.prototype.on('listeningChange.konva', function () {
1491
1501
  this._clearSelfAndDescendantCache(LISTENING);
1492
1502
  });
1493
- Node.prototype.on.call(Node.prototype, 'opacityChange.konva', function () {
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.call(Shape.prototype, 'shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearHasShadowCache);
469
- Shape.prototype.on.call(Shape.prototype, 'shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearGetShadowRGBACache);
470
- Shape.prototype.on.call(Shape.prototype, '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.call(Shape.prototype, 'fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva', _clearLinearGradientCache);
472
- Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva', _clearRadialGradientCache);
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);
@@ -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;
@@ -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;
@@ -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 charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "10.2.0",
3
+ "version": "10.2.1",
4
4
  "description": "HTML5 2d canvas library.",
5
5
  "author": "Anton Lavrenov",
6
6
  "type": "module",