konva 10.4.0 → 10.6.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.
Files changed (63) hide show
  1. package/README.md +4 -4
  2. package/konva.js +3432 -3746
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +2 -2
  6. package/lib/BezierFunctions.d.ts +1 -1
  7. package/lib/BezierFunctions.js +76 -116
  8. package/lib/Canvas.d.ts +1 -1
  9. package/lib/Canvas.js +8 -5
  10. package/lib/Container.js +9 -6
  11. package/lib/Context.d.ts +4 -5
  12. package/lib/Context.js +77 -72
  13. package/lib/DragAndDrop.d.ts +5 -3
  14. package/lib/DragAndDrop.js +65 -29
  15. package/lib/Factory.d.ts +3 -2
  16. package/lib/Factory.js +10 -9
  17. package/lib/Global.d.ts +0 -6
  18. package/lib/Global.js +2 -8
  19. package/lib/Layer.js +9 -6
  20. package/lib/Node.d.ts +33 -15
  21. package/lib/Node.js +179 -135
  22. package/lib/PointerEvents.d.ts +1 -2
  23. package/lib/PointerEvents.js +20 -18
  24. package/lib/Shape.d.ts +2 -2
  25. package/lib/Shape.js +51 -7
  26. package/lib/Stage.d.ts +23 -14
  27. package/lib/Stage.js +221 -93
  28. package/lib/Tween.js +59 -66
  29. package/lib/Util.d.ts +3 -2
  30. package/lib/Util.js +43 -16
  31. package/lib/_CoreInternals.d.ts +25 -11
  32. package/lib/_FullInternals.d.ts +25 -11
  33. package/lib/filters/Blur.js +16 -12
  34. package/lib/filters/Brighten.d.ts +1 -0
  35. package/lib/filters/Brighten.js +1 -0
  36. package/lib/filters/Brightness.d.ts +2 -1
  37. package/lib/filters/Brightness.js +4 -4
  38. package/lib/filters/Emboss.js +16 -58
  39. package/lib/filters/Kaleidoscope.js +8 -15
  40. package/lib/filters/Mask.js +8 -8
  41. package/lib/filters/Pixelate.js +16 -29
  42. package/lib/filters/Threshold.d.ts +1 -1
  43. package/lib/filters/Threshold.js +1 -1
  44. package/lib/shapes/Arc.js +5 -3
  45. package/lib/shapes/Arrow.d.ts +2 -6
  46. package/lib/shapes/Arrow.js +68 -46
  47. package/lib/shapes/Image.js +16 -19
  48. package/lib/shapes/Label.d.ts +2 -3
  49. package/lib/shapes/Label.js +7 -21
  50. package/lib/shapes/Line.d.ts +1 -1
  51. package/lib/shapes/Line.js +1 -1
  52. package/lib/shapes/Path.d.ts +27 -2
  53. package/lib/shapes/Path.js +148 -142
  54. package/lib/shapes/RegularPolygon.js +1 -1
  55. package/lib/shapes/Sprite.js +2 -6
  56. package/lib/shapes/Text.d.ts +12 -4
  57. package/lib/shapes/Text.js +96 -54
  58. package/lib/shapes/TextPath.d.ts +4 -3
  59. package/lib/shapes/TextPath.js +40 -26
  60. package/lib/shapes/Transformer.d.ts +16 -1
  61. package/lib/shapes/Transformer.js +209 -130
  62. package/lib/types.d.ts +2 -2
  63. package/package.json +4 -3
package/lib/Stage.js CHANGED
@@ -65,17 +65,8 @@ const EVENTS_MAP = {
65
65
  pointerdblclick: 'pointerdblclick',
66
66
  },
67
67
  };
68
- const getEventType = (type) => {
69
- if (type.indexOf('pointer') >= 0) {
70
- return 'pointer';
71
- }
72
- if (type.indexOf('touch') >= 0) {
73
- return 'touch';
74
- }
75
- return 'mouse';
76
- };
77
68
  const getEventsMap = (eventType) => {
78
- const type = getEventType(eventType);
69
+ const type = Util._getEventType(eventType);
79
70
  if (type === 'pointer') {
80
71
  return Konva.pointerEventsEnabled && EVENTS_MAP.pointer;
81
72
  }
@@ -133,6 +124,8 @@ export class Stage extends Container {
133
124
  super(checkNoClip(config));
134
125
  this._pointerPositions = [];
135
126
  this._changedPointerPositions = [];
127
+ this._pointerStates = new Map();
128
+ this._lastClicks = {};
136
129
  this._buildDOM();
137
130
  this._bindContentEvents();
138
131
  stages.push(this);
@@ -231,17 +224,12 @@ export class Stage extends Container {
231
224
  return Container.prototype.clone.call(this, obj);
232
225
  }
233
226
  destroy() {
227
+ var _a;
234
228
  super.destroy();
235
- // a pending double-click timer is what closes the global double-click
236
- // window, so close the window when the timer goes
237
- ['mouse', 'touch', 'pointer'].forEach((type) => {
238
- clearTimeout(this['_' + type + 'DblTimeout']);
239
- Konva['_' + type + 'InDblClickWindow'] = false;
240
- });
229
+ this._pointerStates.clear();
230
+ this._lastClicks = {};
241
231
  const content = this.content;
242
- if (content && Util._isInDocument(content)) {
243
- this.container().removeChild(content);
244
- }
232
+ (_a = content === null || content === void 0 ? void 0 : content.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(content);
245
233
  const index = stages.indexOf(this);
246
234
  if (index > -1) {
247
235
  stages.splice(index, 1);
@@ -410,10 +398,13 @@ export class Stage extends Container {
410
398
  }
411
399
  EVENTS.forEach(([event, methodName]) => {
412
400
  this.content.addEventListener(event, (evt) => {
413
- this[methodName](evt);
401
+ this._batchEvents(() => this[methodName](evt));
414
402
  }, { passive: false });
415
403
  });
416
404
  }
405
+ _batchEvents(callback) {
406
+ Util._batchEvents(this.eventBatchFunc(), callback);
407
+ }
417
408
  _pointerenter(evt) {
418
409
  this.setPointersPositions(evt);
419
410
  const events = getEventsMap(evt.type);
@@ -436,31 +427,57 @@ export class Stage extends Container {
436
427
  });
437
428
  }
438
429
  }
439
- _getTargetShape(evenType) {
440
- let shape = this[evenType + 'targetShape'];
441
- if (shape && !shape.getStage()) {
442
- shape = null;
430
+ _pointerEventsEnabled() {
431
+ if (Konva.hitOnDragEnabled)
432
+ return true;
433
+ for (const { node, dragStatus } of DD._dragElements.values()) {
434
+ if (dragStatus === 'dragging' && node.getStage() === this)
435
+ return false;
436
+ }
437
+ return !this.getLayers().some((layer) => { var _a; return (_a = Konva['Transformer']) === null || _a === void 0 ? void 0 : _a._isLayerTransforming(layer); });
438
+ }
439
+ _cancelClick(pointerId, eventType) {
440
+ const types = eventType ? [eventType] : ['mouse', 'touch', 'pointer'];
441
+ for (const type of types) {
442
+ const state = this._pointerStates.get(`${type}:${pointerId}`);
443
+ if (!state)
444
+ continue;
445
+ state.clickStartShape = undefined;
446
+ if (state.relatedPointer)
447
+ state.relatedPointer.clickStartShape = undefined;
443
448
  }
444
- return shape;
445
449
  }
446
450
  _pointerleave(evt) {
451
+ var _a, _b;
447
452
  const events = getEventsMap(evt.type);
448
- const eventType = getEventType(evt.type);
453
+ const eventType = Util._getEventType(evt.type);
449
454
  if (!events) {
450
455
  return;
451
456
  }
452
457
  this.setPointersPositions(evt);
453
- const targetShape = this._getTargetShape(eventType);
454
- const eventsEnabled = !(Konva.isDragging() || Konva.isTransforming()) || Konva.hitOnDragEnabled;
458
+ const pointerId = (_a = this._changedPointerPositions[0]) === null || _a === void 0 ? void 0 : _a.id;
459
+ const key = `${eventType}:${pointerId}`;
460
+ const state = this._pointerStates.get(key);
461
+ const targetShape = ((_b = state === null || state === void 0 ? void 0 : state.targetShape) === null || _b === void 0 ? void 0 : _b.getStage()) === this ? state.targetShape : undefined;
462
+ // A released touch will not return to deliver a deferred hover exit.
463
+ const eventsEnabled = this._pointerEventsEnabled() ||
464
+ (evt.pointerType === 'touch' && !(state === null || state === void 0 ? void 0 : state.downPosition));
465
+ if (eventsEnabled) {
466
+ if ((state === null || state === void 0 ? void 0 : state.clickStartShape) !== undefined) {
467
+ state.targetShape = undefined;
468
+ }
469
+ else {
470
+ this._pointerStates.delete(key);
471
+ }
472
+ }
455
473
  if (targetShape && eventsEnabled) {
456
- targetShape._fireAndBubble(events.pointerout, { evt: evt });
457
- targetShape._fireAndBubble(events.pointerleave, { evt: evt });
474
+ targetShape._fireAndBubble(events.pointerout, { evt, pointerId });
475
+ targetShape._fireAndBubble(events.pointerleave, { evt, pointerId });
458
476
  this._fire(events.pointerleave, {
459
477
  evt: evt,
460
478
  target: this,
461
479
  currentTarget: this,
462
480
  });
463
- this[eventType + 'targetShape'] = null;
464
481
  }
465
482
  else if (eventsEnabled) {
466
483
  this._fire(events.pointerleave, {
@@ -476,30 +493,79 @@ export class Stage extends Container {
476
493
  }
477
494
  this.pointerPos = null;
478
495
  this._pointerPositions = [];
496
+ this._changedPointerPositions = [];
497
+ this._pointerEventType = undefined;
479
498
  }
480
499
  _pointerdown(evt) {
481
500
  const events = getEventsMap(evt.type);
482
- const eventType = getEventType(evt.type);
501
+ const eventType = Util._getEventType(evt.type);
483
502
  if (!events) {
484
503
  return;
485
504
  }
486
505
  this.setPointersPositions(evt);
487
506
  let triggeredOnShape = false;
488
507
  this._changedPointerPositions.forEach((pos) => {
508
+ var _a;
489
509
  const shape = this.getIntersection(pos);
490
- DD.justDragged = false;
491
- // probably we are staring a click
492
- Konva['_' + eventType + 'ListenClick'] = true;
510
+ const key = `${eventType}:${pos.id}`;
511
+ const state = {
512
+ targetShape: (_a = this._pointerStates.get(key)) === null || _a === void 0 ? void 0 : _a.targetShape,
513
+ clickStartShape: shape && shape.isListening() ? shape : null,
514
+ lastClick: this._lastClicks[eventType],
515
+ downPosition: pos,
516
+ pointerType: evt.pointerType,
517
+ };
518
+ // A native pointerdown precedes its compatibility mouse/touch event.
519
+ // Keep that association for the press: IDs can differ, and mouse
520
+ // coordinates can be rounded by the browser.
521
+ this._pointerStates.delete(key);
522
+ if (eventType !== 'pointer') {
523
+ for (const [pointerKey, pointer] of [
524
+ ...this._pointerStates,
525
+ ].reverse()) {
526
+ if (!pointerKey.startsWith('pointer:') ||
527
+ !pointer.downPosition ||
528
+ (eventType === 'touch' && pointer.relatedPointer))
529
+ continue;
530
+ const matches = eventType === 'mouse'
531
+ ? pointer.pointerType !== 'touch'
532
+ : pointer.pointerType === 'touch' &&
533
+ pointer.downPosition.x === pos.x &&
534
+ pointer.downPosition.y === pos.y;
535
+ if (matches) {
536
+ state.relatedPointer = pointer;
537
+ pointer.relatedPointer = state;
538
+ if (pointer.clickStartShape === undefined)
539
+ state.clickStartShape = undefined;
540
+ break;
541
+ }
542
+ }
543
+ }
544
+ this._pointerStates.set(key, state);
545
+ for (const elem of DD._dragElements.values()) {
546
+ if (elem.dragStatus === 'dragging' &&
547
+ (elem.pointerId === undefined ||
548
+ (elem.pointerEventType === eventType &&
549
+ elem.pointerId === pos.id) ||
550
+ (elem.pointerEventType === 'mouse' &&
551
+ eventType === 'pointer' &&
552
+ state.pointerType !== 'touch')) &&
553
+ elem.node.getStage() === this) {
554
+ // Drag movement uses the compatibility mouse/touch pointer.
555
+ if (elem.pointerId === undefined && eventType !== 'pointer') {
556
+ elem.pointerId = pos.id;
557
+ elem.pointerEventType = eventType;
558
+ }
559
+ this._cancelClick(pos.id, eventType);
560
+ }
561
+ }
493
562
  // no shape detected? do nothing
494
563
  if (!shape || !shape.isListening()) {
495
- this[eventType + 'ClickStartShape'] = undefined;
496
564
  return;
497
565
  }
498
566
  if (Konva.capturePointerEventsEnabled) {
499
567
  shape.setPointerCapture(pos.id);
500
568
  }
501
- // save where we started the click
502
- this[eventType + 'ClickStartShape'] = shape;
503
569
  shape._fireAndBubble(events.pointerdown, {
504
570
  evt: evt,
505
571
  pointerId: pos.id,
@@ -517,13 +583,13 @@ export class Stage extends Container {
517
583
  evt: evt,
518
584
  target: this,
519
585
  currentTarget: this,
520
- pointerId: this._pointerPositions[0].id,
586
+ pointerId: this._changedPointerPositions[0].id,
521
587
  });
522
588
  }
523
589
  }
524
590
  _pointermove(evt) {
525
591
  const events = getEventsMap(evt.type);
526
- const eventType = getEventType(evt.type);
592
+ const eventType = Util._getEventType(evt.type);
527
593
  if (!events) {
528
594
  return;
529
595
  }
@@ -531,44 +597,54 @@ export class Stage extends Container {
531
597
  // native mouse wheel scrolling during drag on desktop
532
598
  const isTouchPointer = evt.type.indexOf('touch') >= 0 ||
533
599
  evt.pointerType === 'touch';
534
- if (Konva.isDragging() &&
535
- DD.node.preventDefault() &&
536
- evt.cancelable &&
537
- isTouchPointer) {
538
- evt.preventDefault();
600
+ if (evt.cancelable && isTouchPointer) {
601
+ for (const { node, dragStatus } of DD._dragElements.values()) {
602
+ if (dragStatus === 'dragging' &&
603
+ node.getStage() === this &&
604
+ node.preventDefault()) {
605
+ evt.preventDefault();
606
+ break;
607
+ }
608
+ }
539
609
  }
540
610
  this.setPointersPositions(evt);
541
- const eventsEnabled = !(Konva.isDragging() || Konva.isTransforming()) || Konva.hitOnDragEnabled;
611
+ const eventsEnabled = this._pointerEventsEnabled();
542
612
  if (!eventsEnabled) {
543
613
  return;
544
614
  }
545
615
  const processedShapesIds = {};
546
616
  let triggeredOnShape = false;
547
- const targetShape = this._getTargetShape(eventType);
548
617
  this._changedPointerPositions.forEach((pos) => {
618
+ var _a;
619
+ const key = `${eventType}:${pos.id}`;
620
+ let state = this._pointerStates.get(key);
621
+ if (!state) {
622
+ state = {};
623
+ this._pointerStates.set(key, state);
624
+ }
549
625
  const shape = (PointerEvents.getCapturedShape(pos.id) ||
550
626
  this.getIntersection(pos));
627
+ const targetShape = state.targetShape === shape || ((_a = state.targetShape) === null || _a === void 0 ? void 0 : _a.getStage()) === this
628
+ ? state.targetShape
629
+ : undefined;
551
630
  const pointerId = pos.id;
552
631
  const event = { evt: evt, pointerId };
553
632
  const differentTarget = targetShape !== shape;
633
+ state.targetShape = shape && shape.isListening() ? shape : undefined;
554
634
  if (differentTarget && targetShape) {
555
635
  targetShape._fireAndBubble(events.pointerout, { ...event }, shape);
556
636
  targetShape._fireAndBubble(events.pointerleave, { ...event }, shape);
557
637
  }
558
- if (shape) {
559
- if (processedShapesIds[shape._id]) {
560
- return;
561
- }
562
- processedShapesIds[shape._id] = true;
563
- }
564
638
  if (shape && shape.isListening()) {
565
639
  triggeredOnShape = true;
566
640
  if (differentTarget) {
567
641
  shape._fireAndBubble(events.pointerover, { ...event }, targetShape);
568
642
  shape._fireAndBubble(events.pointerenter, { ...event }, targetShape);
569
- this[eventType + 'targetShape'] = shape;
570
643
  }
571
- shape._fireAndBubble(events.pointermove, { ...event });
644
+ if (!processedShapesIds[shape._id]) {
645
+ processedShapesIds[shape._id] = true;
646
+ shape._fireAndBubble(events.pointermove, { ...event });
647
+ }
572
648
  }
573
649
  else {
574
650
  if (targetShape) {
@@ -578,7 +654,6 @@ export class Stage extends Container {
578
654
  currentTarget: this,
579
655
  pointerId,
580
656
  });
581
- this[eventType + 'targetShape'] = null;
582
657
  }
583
658
  }
584
659
  });
@@ -593,61 +668,61 @@ export class Stage extends Container {
593
668
  }
594
669
  _pointerup(evt) {
595
670
  const events = getEventsMap(evt.type);
596
- const eventType = getEventType(evt.type);
671
+ const eventType = Util._getEventType(evt.type);
597
672
  if (!events) {
598
673
  return;
599
674
  }
600
675
  this.setPointersPositions(evt);
601
- // the mouse/touch families get their "listen click" flags reset by
602
- // DD._endDragBefore, but native "pointerup" fires before the
603
- // "mouseup"/"touchend" that ends the drag, so for the pointer family the
604
- // flags are still set — check the live drag state as well, otherwise
605
- // "pointerclick" fires after a drag while "click" does not (issue #1756)
606
- const wasDragged = DD.justDragged || (eventType === 'pointer' && Konva.isDragging());
607
- const listenClick = Konva['_' + eventType + 'ListenClick'] && !wasDragged;
608
- const clickStartShape = this[eventType + 'ClickStartShape'];
609
- const clickEndShape = this[eventType + 'ClickEndShape'];
610
676
  const processedShapesIds = {};
611
677
  let skipPointerUpTrigger = false;
612
678
  this._changedPointerPositions.forEach((pos) => {
679
+ var _a;
680
+ const key = `${eventType}:${pos.id}`;
681
+ const state = this._pointerStates.get(key);
682
+ const listenClick = (state === null || state === void 0 ? void 0 : state.clickStartShape) !== undefined;
683
+ const clickStartShape = state === null || state === void 0 ? void 0 : state.clickStartShape;
684
+ if ((state === null || state === void 0 ? void 0 : state.targetShape) && eventType !== 'touch') {
685
+ this._pointerStates.set(key, { targetShape: state.targetShape });
686
+ }
687
+ else {
688
+ this._pointerStates.delete(key);
689
+ }
613
690
  const shape = (PointerEvents.getCapturedShape(pos.id) ||
614
691
  this.getIntersection(pos));
692
+ const alreadyReleased = shape && processedShapesIds[shape._id];
615
693
  if (shape) {
616
694
  shape.releaseCapture(pos.id);
617
- if (processedShapesIds[shape._id]) {
618
- return;
619
- }
620
695
  processedShapesIds[shape._id] = true;
621
696
  }
622
697
  const pointerId = pos.id;
623
698
  const event = { evt: evt, pointerId };
624
- let fireDblClick = false;
625
- if (Konva['_' + eventType + 'InDblClickWindow']) {
626
- fireDblClick = true;
627
- clearTimeout(this['_' + eventType + 'DblTimeout']);
699
+ const clickTarget = shape && shape.isListening() ? shape : null;
700
+ const lastClick = this._lastClicks[eventType];
701
+ const canClick = listenClick && (!clickTarget || clickStartShape === clickTarget);
702
+ const fireDblClick = canClick &&
703
+ lastClick &&
704
+ (state === null || state === void 0 ? void 0 : state.lastClick) === lastClick &&
705
+ lastClick.shape === clickTarget &&
706
+ Date.now() - lastClick.time < Konva.dblClickWindow;
707
+ if (canClick) {
708
+ this._lastClicks[eventType] = fireDblClick
709
+ ? undefined
710
+ : { shape: clickTarget, time: Date.now() };
628
711
  }
629
- else if (!wasDragged) {
630
- // don't set inDblClickWindow after dragging
631
- Konva['_' + eventType + 'InDblClickWindow'] = true;
632
- clearTimeout(this['_' + eventType + 'DblTimeout']);
633
- }
634
- this['_' + eventType + 'DblTimeout'] = setTimeout(function () {
635
- Konva['_' + eventType + 'InDblClickWindow'] = false;
636
- }, Konva.dblClickWindow);
637
712
  if (shape && shape.isListening()) {
638
713
  skipPointerUpTrigger = true;
639
- this[eventType + 'ClickEndShape'] = shape;
640
- shape._fireAndBubble(events.pointerup, { ...event });
714
+ if (!alreadyReleased) {
715
+ shape._fireAndBubble(events.pointerup, { ...event });
716
+ }
641
717
  // detect if click or double click occurred
642
718
  if (listenClick && clickStartShape === shape) {
643
719
  shape._fireAndBubble(events.pointerclick, { ...event });
644
- if (fireDblClick && clickEndShape && clickEndShape === shape) {
720
+ if (fireDblClick) {
645
721
  shape._fireAndBubble(events.pointerdblclick, { ...event });
646
722
  }
647
723
  }
648
724
  }
649
725
  else {
650
- this[eventType + 'ClickEndShape'] = null;
651
726
  if (!skipPointerUpTrigger) {
652
727
  this._fire(events.pointerup, {
653
728
  evt: evt,
@@ -674,6 +749,10 @@ export class Stage extends Container {
674
749
  });
675
750
  }
676
751
  }
752
+ if (eventType === 'touch' && ((_a = state === null || state === void 0 ? void 0 : state.targetShape) === null || _a === void 0 ? void 0 : _a.getStage()) === this) {
753
+ state.targetShape._fireAndBubble(events.pointerout, { ...event });
754
+ state.targetShape._fireAndBubble(events.pointerleave, { ...event });
755
+ }
677
756
  });
678
757
  if (!skipPointerUpTrigger) {
679
758
  this._fire(events.pointerup, {
@@ -683,7 +762,6 @@ export class Stage extends Container {
683
762
  pointerId: this._changedPointerPositions[0].id,
684
763
  });
685
764
  }
686
- Konva['_' + eventType + 'ListenClick'] = false;
687
765
  // always call preventDefault for desktop events because some browsers
688
766
  // try to drag and drop the canvas element
689
767
  // do not call this function on mobile because it prevent "click" event on all parent containers
@@ -722,15 +800,46 @@ export class Stage extends Container {
722
800
  }
723
801
  _pointercancel(evt) {
724
802
  this.setPointersPositions(evt);
725
- const shape = PointerEvents.getCapturedShape(evt.pointerId) ||
726
- this.getIntersection(this.getPointerPosition());
727
- if (shape) {
728
- shape._fireAndBubble(POINTERUP, PointerEvents.createEvent(evt));
729
- }
730
- PointerEvents.releaseCapture(evt.pointerId);
803
+ const events = getEventsMap(evt.type);
804
+ this._changedPointerPositions.forEach((pos) => {
805
+ var _a;
806
+ const eventType = Util._getEventType(evt.type);
807
+ const key = `${eventType}:${pos.id}`;
808
+ this._cancelClick(pos.id, eventType);
809
+ const targetShape = (_a = this._pointerStates.get(key)) === null || _a === void 0 ? void 0 : _a.targetShape;
810
+ if (targetShape && eventType !== 'touch') {
811
+ this._pointerStates.set(key, { targetShape });
812
+ }
813
+ else {
814
+ this._pointerStates.delete(key);
815
+ }
816
+ const shape = PointerEvents.getCapturedShape(pos.id) || this.getIntersection(pos);
817
+ const event = { evt, pointerId: pos.id };
818
+ if (shape) {
819
+ if (events)
820
+ shape._fireAndBubble(events.pointercancel, { ...event });
821
+ // Keep the historical pointerup notification for cancellation listeners.
822
+ shape._fireAndBubble(POINTERUP, { ...event });
823
+ }
824
+ else if (events) {
825
+ this._fire(events.pointercancel, {
826
+ ...event,
827
+ target: this,
828
+ currentTarget: this,
829
+ });
830
+ }
831
+ PointerEvents.releaseCapture(pos.id);
832
+ if (events && eventType === 'touch' && (targetShape === null || targetShape === void 0 ? void 0 : targetShape.getStage()) === this) {
833
+ targetShape._fireAndBubble(events.pointerout, { ...event });
834
+ targetShape._fireAndBubble(events.pointerleave, { ...event });
835
+ }
836
+ });
731
837
  }
732
838
  _lostpointercapture(evt) {
733
- PointerEvents.releaseCapture(evt.pointerId);
839
+ const captured = PointerEvents.getCapturedShape(evt.pointerId, this);
840
+ if (captured) {
841
+ PointerEvents.releaseCapture(evt.pointerId);
842
+ }
734
843
  }
735
844
  /**
736
845
  * manually register pointers positions (mouse/touch) in the stage.
@@ -752,6 +861,7 @@ export class Stage extends Container {
752
861
  evt = evt ? evt : window.event;
753
862
  // touch events
754
863
  if (evt.touches !== undefined) {
864
+ this._pointerEventType = 'touch';
755
865
  // touchlist has not support for map method
756
866
  // so we have to iterate
757
867
  this._pointerPositions = [];
@@ -773,6 +883,8 @@ export class Stage extends Container {
773
883
  }
774
884
  else {
775
885
  // mouse events
886
+ this._pointerEventType =
887
+ evt.pointerId === undefined ? 'mouse' : 'pointer';
776
888
  x = (evt.clientX - contentPosition.left) / contentPosition.scaleX;
777
889
  y = (evt.clientY - contentPosition.top) / contentPosition.scaleY;
778
890
  this.pointerPos = {
@@ -887,3 +999,19 @@ _registerNode(Stage);
887
999
  * stage.container(popout.document.body);
888
1000
  */
889
1001
  Factory.addGetterSetter(Stage, 'container');
1002
+ /**
1003
+ * Get/set the callback used by framework integrations to batch native input.
1004
+ * The callback must invoke its argument exactly once, synchronously. Existing
1005
+ * node events keep their order and cancellation behavior. Direct node.fire()
1006
+ * and programmatic mutations do not create a batch.
1007
+ * Missing calls warn; duplicate or late calls warn and are ignored. Exceptions
1008
+ * propagate and skipped input is not replayed, so an invalid callback can
1009
+ * prevent input processing and drag cleanup.
1010
+ * Each native Konva listener creates its own scope; a DOM event may invoke
1011
+ * several listeners. Batching does not reorder or merge those listeners.
1012
+ * @method
1013
+ * @name Konva.Stage#eventBatchFunc
1014
+ * @example
1015
+ * stage.eventBatchFunc((run) => frameworkBatch(run));
1016
+ */
1017
+ Factory.addGetterSetter(Stage, 'eventBatchFunc');