@xpert-ai/chatkit-web-component 0.5.1 → 0.5.2

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.
@@ -1427,6 +1427,7 @@ class PetOverlay {
1427
1427
  this.lastDragPosition = null;
1428
1428
  this.lastDragClientX = null;
1429
1429
  this.dragAnimation = null;
1430
+ this.activePointerId = null;
1430
1431
  this.isDragging = false;
1431
1432
  this.isHovering = false;
1432
1433
  this.movedDuringDrag = false;
@@ -1558,7 +1559,7 @@ class PetOverlay {
1558
1559
  };
1559
1560
  this.handlePointerDown = (event) => {
1560
1561
  var _a2, _b2;
1561
- if (event.button !== 0 || event.ctrlKey) {
1562
+ if (event.button !== 0 || event.ctrlKey || this.isDragging) {
1562
1563
  return;
1563
1564
  }
1564
1565
  this.closeContextMenu();
@@ -1584,12 +1585,17 @@ class PetOverlay {
1584
1585
  this.movedDuringDrag = false;
1585
1586
  this.dragPosition = nextPosition;
1586
1587
  this.isDragging = true;
1588
+ this.activePointerId = event.pointerId;
1587
1589
  this.clearRestingDelayTimer();
1588
1590
  this.isHovering = true;
1591
+ this.captureActivePointer();
1589
1592
  this.installDragListeners();
1590
1593
  this.rescheduleAnimation();
1591
1594
  };
1592
1595
  this.handlePointerMove = (event) => {
1596
+ if (!this.isActiveDragPointer(event)) {
1597
+ return;
1598
+ }
1593
1599
  const nextPosition = this.getNextDragPosition(event);
1594
1600
  const last = this.lastDragPosition;
1595
1601
  if (last && (Math.abs(last.x - nextPosition.x) > DRAG_DIRECTION_THRESHOLD_PX || Math.abs(last.y - nextPosition.y) > DRAG_DIRECTION_THRESHOLD_PX)) {
@@ -1609,20 +1615,18 @@ class PetOverlay {
1609
1615
  this.render();
1610
1616
  };
1611
1617
  this.handlePointerUp = (event) => {
1618
+ if (!this.isActiveDragPointer(event)) {
1619
+ return;
1620
+ }
1612
1621
  const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
1613
- this.isDragging = false;
1614
- this.dragPosition = null;
1615
- this.dragAnimation = null;
1616
- this.lastDragClientX = null;
1617
- this.removeDragListeners();
1618
- this.persistPosition(finalPosition);
1619
- if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
1620
- this.isHovering = true;
1621
- this.rescheduleAnimation();
1622
- } else {
1623
- this.enterRestingAfterDelay();
1624
- this.rescheduleAnimation();
1622
+ this.finishDrag(finalPosition, event);
1623
+ };
1624
+ this.handleLostPointerCapture = (event) => {
1625
+ if (!this.isActiveDragPointer(event)) {
1626
+ return;
1625
1627
  }
1628
+ const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
1629
+ this.finishDrag(finalPosition, event);
1626
1630
  };
1627
1631
  this.handleClick = () => {
1628
1632
  var _a2;
@@ -1826,6 +1830,7 @@ class PetOverlay {
1826
1830
  pet.addEventListener("pointerenter", this.handlePointerEnter);
1827
1831
  pet.addEventListener("pointerleave", this.handlePointerLeave);
1828
1832
  pet.addEventListener("pointerdown", this.handlePointerDown);
1833
+ pet.addEventListener("lostpointercapture", this.handleLostPointerCapture);
1829
1834
  pet.addEventListener("contextmenu", this.handleContextMenu);
1830
1835
  pet.addEventListener("click", this.handleClick);
1831
1836
  overlay.append(style, pet);
@@ -1835,6 +1840,7 @@ class PetOverlay {
1835
1840
  }
1836
1841
  removeOverlay() {
1837
1842
  var _a2;
1843
+ this.cancelActiveDrag();
1838
1844
  this.clearRestingDelayTimer();
1839
1845
  this.clearTimers();
1840
1846
  this.closeContextMenu();
@@ -1851,6 +1857,10 @@ class PetOverlay {
1851
1857
  "pointerdown",
1852
1858
  this.handlePointerDown
1853
1859
  );
1860
+ this.petElement.removeEventListener(
1861
+ "lostpointercapture",
1862
+ this.handleLostPointerCapture
1863
+ );
1854
1864
  this.petElement.removeEventListener(
1855
1865
  "contextmenu",
1856
1866
  this.handleContextMenu
@@ -2568,6 +2578,34 @@ class PetOverlay {
2568
2578
  this.render();
2569
2579
  }
2570
2580
  }
2581
+ captureActivePointer() {
2582
+ const pointerId = this.activePointerId;
2583
+ const pet = this.petElement;
2584
+ if (pointerId === null || typeof (pet == null ? void 0 : pet.setPointerCapture) !== "function") {
2585
+ return;
2586
+ }
2587
+ try {
2588
+ pet.setPointerCapture(pointerId);
2589
+ } catch {
2590
+ }
2591
+ }
2592
+ releaseActivePointer() {
2593
+ const pointerId = this.activePointerId;
2594
+ const pet = this.petElement;
2595
+ this.activePointerId = null;
2596
+ if (pointerId === null || typeof (pet == null ? void 0 : pet.hasPointerCapture) !== "function" || typeof pet.releasePointerCapture !== "function") {
2597
+ return;
2598
+ }
2599
+ try {
2600
+ if (pet.hasPointerCapture(pointerId)) {
2601
+ pet.releasePointerCapture(pointerId);
2602
+ }
2603
+ } catch {
2604
+ }
2605
+ }
2606
+ isActiveDragPointer(event) {
2607
+ return this.isDragging && event.pointerId === this.activePointerId;
2608
+ }
2571
2609
  getNextDragPosition(event) {
2572
2610
  if (!this.options) {
2573
2611
  return { x: 0, y: 0 };
@@ -2582,12 +2620,35 @@ class PetOverlay {
2582
2620
  normalizeBoundsPadding(this.options.position.boundsPadding)
2583
2621
  );
2584
2622
  }
2623
+ finishDrag(finalPosition, event) {
2624
+ this.isDragging = false;
2625
+ this.dragPosition = null;
2626
+ this.dragAnimation = null;
2627
+ this.lastDragClientX = null;
2628
+ this.removeDragListeners();
2629
+ this.releaseActivePointer();
2630
+ this.persistPosition(finalPosition);
2631
+ if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
2632
+ this.isHovering = true;
2633
+ this.rescheduleAnimation();
2634
+ } else {
2635
+ this.enterRestingAfterDelay();
2636
+ this.rescheduleAnimation();
2637
+ }
2638
+ }
2639
+ cancelActiveDrag() {
2640
+ this.isDragging = false;
2641
+ this.dragPosition = null;
2642
+ this.dragAnimation = null;
2643
+ this.lastDragPosition = null;
2644
+ this.lastDragClientX = null;
2645
+ this.removeDragListeners();
2646
+ this.releaseActivePointer();
2647
+ }
2585
2648
  installDragListeners() {
2586
2649
  window.addEventListener("pointermove", this.handlePointerMove);
2587
- window.addEventListener("pointerup", this.handlePointerUp, { once: true });
2588
- window.addEventListener("pointercancel", this.handlePointerUp, {
2589
- once: true
2590
- });
2650
+ window.addEventListener("pointerup", this.handlePointerUp);
2651
+ window.addEventListener("pointercancel", this.handlePointerUp);
2591
2652
  }
2592
2653
  removeDragListeners() {
2593
2654
  window.removeEventListener("pointermove", this.handlePointerMove);