@guardian/interactive-component-library 0.1.0-alpha.21 → 0.1.0-alpha.22

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.
@@ -424,14 +424,15 @@
424
424
  button: button$5,
425
425
  svg: svg$7
426
426
  };
427
- const InfoButton = ({
427
+ const InfoButton = compat.forwardRef(({
428
428
  onClick,
429
429
  styles: styles2
430
- }) => {
430
+ }, ref) => {
431
431
  styles2 = mergeStyles({
432
432
  ...defaultStyles$p
433
433
  }, styles2);
434
434
  return jsxRuntime.jsx("button", {
435
+ ref,
435
436
  class: styles2.button,
436
437
  onClick,
437
438
  children: jsxRuntime.jsx("svg", {
@@ -443,7 +444,7 @@
443
444
  })
444
445
  })
445
446
  });
446
- };
447
+ });
447
448
  const svg$6 = "_svg_1v49v_1";
448
449
  const circle$1 = "_circle_1v49v_5";
449
450
  const pulse = "_pulse_1v49v_9";
@@ -1538,161 +1539,27 @@
1538
1539
  children: show && chart
1539
1540
  });
1540
1541
  };
1541
- const useTooltipTarget = (targetElement, trackPosition) => {
1542
- const [targetRect, setTargetRect] = hooks.useState();
1543
- const [position, setPosition] = hooks.useState(null);
1544
- const [hoverActive, setHoverActive] = hooks.useState(false);
1545
- const onMouseMove = ({
1546
- clientX,
1547
- clientY,
1548
- currentTarget
1549
- }) => {
1550
- const rect = currentTarget.getBoundingClientRect();
1551
- const x = clientX - rect.left;
1552
- const y = clientY - rect.top;
1553
- requestAnimationFrame(() => {
1554
- setTargetRect(rect);
1555
- setPosition({
1556
- x,
1557
- y
1558
- });
1559
- setHoverActive(true);
1560
- });
1561
- };
1562
- const onMouseOut = () => {
1563
- requestAnimationFrame(() => {
1564
- setHoverActive(false);
1565
- });
1566
- };
1567
- hooks.useEffect(() => {
1568
- setTargetRect(targetElement.getBoundingClientRect());
1569
- if (trackPosition) {
1570
- targetElement.addEventListener("mousemove", onMouseMove);
1571
- targetElement.addEventListener("mouseout", onMouseOut);
1572
- }
1573
- return () => {
1574
- if (trackPosition) {
1575
- targetElement.removeEventListener("mousemove", onMouseMove);
1576
- targetElement.removeEventListener("mouseout", onMouseOut);
1577
- }
1578
- };
1579
- }, [targetElement, trackPosition]);
1580
- return {
1581
- targetRect,
1582
- positionInTarget: position,
1583
- hoverActive
1584
- };
1585
- };
1586
- function n(n2) {
1587
- return (r) => {
1588
- n2.forEach((n3) => {
1589
- "function" == typeof n3 ? n3(r) : null != n3 && (n3.current = r);
1590
- });
1591
- };
1592
- }
1593
- var T, c;
1594
- !function(e) {
1595
- e.APPEAR = "appear", e.APPEAR_ACTIVE = "appearActive", e.APPEAR_DONE = "appearDone", e.ENTER = "enter", e.ENTER_ACTIVE = "enterActive", e.ENTER_DONE = "enterDone", e.EXIT = "exit", e.EXIT_ACTIVE = "exitActive", e.EXIT_DONE = "exitDone";
1596
- }(T || (T = {})), function(e) {
1597
- e.ENTER = "onEnter", e.ENTERING = "onEntering", e.ENTERED = "onEntered", e.EXIT = "onExit", e.EXITING = "onExiting", e.EXITED = "onExited";
1598
- }(c || (c = {}));
1599
- const s = { [T.APPEAR]: [c.ENTER, T.APPEAR_ACTIVE], [T.APPEAR_ACTIVE]: [c.ENTERING, T.APPEAR_DONE, true], [T.APPEAR_DONE]: [c.ENTERED], [T.ENTER]: [c.ENTER, T.ENTER_ACTIVE], [T.ENTER_ACTIVE]: [c.ENTERING, T.ENTER_DONE, true], [T.ENTER_DONE]: [c.ENTERED], [T.EXIT]: [c.EXIT, T.EXIT_ACTIVE], [T.EXIT_ACTIVE]: [c.EXITING, T.EXIT_DONE, true], [T.EXIT_DONE]: [c.EXITED] };
1600
- var u = (r) => {
1601
- const { children: c2, in: u2 = false, appear: A = false, enter: N2 = true, exit: l = true, duration: I = 500, alwaysMounted: p2 = false, addEndListener: R2 } = r, P2 = hooks.useRef(), _2 = hooks.useRef();
1602
- let d2 = false;
1603
- const [f, D] = hooks.useState(() => (d2 = true, u2 ? A ? T.APPEAR : T.APPEAR_DONE : T.EXIT_DONE));
1604
- hooks.useEffect(() => {
1605
- var e;
1606
- const { setTimeout: E, clearTimeout: t } = window, [n2, o, i] = s[f];
1607
- return null == (e = r[n2]) || e.call(r, P2.current), o && (i ? R2 ? R2(P2.current, () => D(o)) : _2.current = E(D, I, o) : D(o)), () => {
1608
- t(_2.current);
1609
- };
1610
- }, [f, I]), hooks.useLayoutEffect(() => {
1611
- d2 || D(u2 ? N2 ? T.ENTER : T.ENTER_DONE : l ? T.EXIT : T.EXIT_DONE);
1612
- }, [u2]);
1613
- const X = hooks.useMemo(() => {
1614
- const e = {};
1615
- return Object.values(T).forEach((r2) => {
1616
- e[r2] = f === r2;
1617
- }), e;
1618
- }, [f]);
1619
- if (!p2 && f === T.EXIT_DONE)
1620
- return null;
1621
- const O = c2(X, f);
1622
- return preact.cloneElement(O, { ref: n([P2, O.ref]) });
1623
- };
1624
- function N(e, r) {
1625
- if (null == e)
1626
- return {};
1627
- var E, t, n2 = {}, o = Object.keys(e);
1628
- for (t = 0; t < o.length; t++)
1629
- r.indexOf(E = o[t]) >= 0 || (n2[E] = e[E]);
1630
- return n2;
1542
+ function rectsIntersect(rect1, rect2) {
1543
+ if (rect1.width === 0 || rect1.height === 0 || rect2.width === 0 || rect2.height === 0) {
1544
+ return false;
1545
+ }
1546
+ if (rect1.x + rect1.width <= rect2.x || rect2.x + rect2.width <= rect1.x || rect1.y + rect1.height <= rect2.y || rect2.y + rect2.height <= rect1.y) {
1547
+ return false;
1548
+ }
1549
+ return true;
1631
1550
  }
1632
- const p = ["children", "classNames"], R = { [T.APPEAR]: "-appear", [T.APPEAR_ACTIVE]: "-appear-active", [T.APPEAR_DONE]: "-appear-done", [T.ENTER]: "-enter", [T.ENTER_ACTIVE]: "-enter-active", [T.ENTER_DONE]: "-enter-done", [T.EXIT]: "-exit", [T.EXIT_ACTIVE]: "-exit-active", [T.EXIT_DONE]: "-exit-done" }, P = (...e) => e.filter((e2) => !!e2).join(" "), _ = (e, r) => "string" == typeof r ? `${r}${R[e]}` : r[e];
1633
- var d = (E) => {
1634
- const { children: t, classNames: n2 } = E, o = N(E, p);
1635
- return preact.createElement(u, o, (r, E2) => {
1636
- const { className: o2 } = t.props, i = hooks.useMemo(() => P(o2, ((e, r2) => {
1637
- const E3 = _(e, r2);
1638
- switch (e) {
1639
- case T.APPEAR_ACTIVE:
1640
- return P(_(T.APPEAR, r2), E3);
1641
- case T.ENTER_ACTIVE:
1642
- return P(_(T.ENTER, r2), E3);
1643
- case T.EXIT_ACTIVE:
1644
- return P(_(T.EXIT, r2), E3);
1645
- default:
1646
- return E3;
1647
- }
1648
- })(E2, n2)), [o2, n2, E2]);
1649
- return preact.cloneElement(t, { className: i });
1650
- });
1651
- };
1652
- const transitionContainer$1 = "_transitionContainer_1gzlr_1";
1653
- const modalBox$1 = "_modalBox_1gzlr_13";
1654
- const enter$1 = "_enter_1gzlr_21";
1655
- const exitDone$1 = "_exitDone_1gzlr_22";
1656
- const enterActive$1 = "_enterActive_1gzlr_31";
1657
- const exit$1 = "_exit_1gzlr_22";
1658
- const styles$6 = {
1659
- transitionContainer: transitionContainer$1,
1660
- modalBox: modalBox$1,
1661
- enter: enter$1,
1662
- exitDone: exitDone$1,
1663
- enterActive: enterActive$1,
1664
- exit: exit$1
1665
- };
1666
- function Modal$1({
1667
- visible = false,
1668
- children
1669
- }) {
1670
- return jsxRuntime.jsx(d, {
1671
- in: visible,
1672
- duration: 300,
1673
- classNames: styles$6,
1674
- alwaysMounted: true,
1675
- children: jsxRuntime.jsx("div", {
1676
- class: styles$6.transitionContainer,
1677
- children: jsxRuntime.jsx("div", {
1678
- class: styles$6.modalBox,
1679
- children
1680
- })
1681
- })
1682
- });
1551
+ function pointInsideRect(point, rect) {
1552
+ return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
1683
1553
  }
1684
1554
  const tooltip = "_tooltip_11t5d_1";
1685
1555
  const defaultStyles$b = {
1686
1556
  tooltip
1687
1557
  };
1688
- const TooltipType = {
1689
- float: "float",
1690
- modal: "modal"
1691
- };
1692
1558
  function Tooltip({
1693
1559
  for: targetElement,
1694
- renderIn: refOrSelector,
1695
- type = TooltipType.float,
1560
+ touchRect,
1561
+ positionInTarget,
1562
+ show = true,
1696
1563
  styles: styles2,
1697
1564
  children
1698
1565
  }) {
@@ -1703,29 +1570,19 @@
1703
1570
  y: 0
1704
1571
  });
1705
1572
  const [displayElement, setDisplayElement] = hooks.useState(null);
1706
- const trackPosition = typeof children === "function";
1707
- const {
1708
- targetRect,
1709
- positionInTarget,
1710
- hoverActive
1711
- } = useTooltipTarget(targetElement, trackPosition);
1712
- const tooltipRef = hooks.useRef(null);
1573
+ const tooltipRef = hooks.useRef();
1713
1574
  styles2 = mergeStyles(defaultStyles$b, styles2);
1714
1575
  hooks.useEffect(() => {
1715
- let element = null;
1716
- if (typeof refOrSelector === "string") {
1717
- element = document.querySelector(refOrSelector);
1718
- } else if ("current" in refOrSelector) {
1719
- element = refOrSelector.current;
1720
- } else {
1721
- throw new Error("renderIn prop needs to be a selector or ref (from useRef)");
1722
- }
1723
- setDisplayElement(element);
1724
- }, [refOrSelector]);
1576
+ setDisplayElement(document.querySelector("body"));
1577
+ return () => {
1578
+ setDisplayElement(null);
1579
+ };
1580
+ }, []);
1725
1581
  hooks.useLayoutEffect(() => {
1726
1582
  if (!tooltipRef.current)
1727
1583
  return;
1728
- if (trackPosition && positionInTarget) {
1584
+ const targetRect = targetElement.getBoundingClientRect();
1585
+ if (positionInTarget) {
1729
1586
  const newPosition = tooltipPositionForPoint({
1730
1587
  targetRect,
1731
1588
  positionInTarget,
@@ -1733,35 +1590,32 @@
1733
1590
  displayElement
1734
1591
  });
1735
1592
  setTooltipPosition(newPosition);
1736
- } else if (!trackPosition) {
1593
+ } else if (!positionInTarget) {
1737
1594
  const newPosition = tooltipPositionForRect({
1738
1595
  targetRect,
1596
+ touchRect,
1739
1597
  tooltip: tooltipRef.current,
1740
1598
  displayElement
1741
1599
  });
1742
1600
  setTooltipPosition(newPosition);
1743
1601
  }
1744
- }, [trackPosition, targetRect, positionInTarget, displayElement, tooltipRef]);
1602
+ }, [targetElement, positionInTarget, displayElement, tooltipRef, touchRect]);
1745
1603
  if (!displayElement)
1746
1604
  return;
1747
- const displayTooltip = hoverActive || !trackPosition;
1748
- const fixedStyle = type === TooltipType.modal ? {} : {
1749
- display: displayTooltip ? "block" : "none",
1605
+ const fixedStyle = {
1606
+ display: show ? "block" : "none",
1750
1607
  position: "fixed",
1751
1608
  left: tooltipPosition.x,
1752
1609
  top: tooltipPosition.y,
1753
1610
  zIndex: 100
1754
1611
  };
1755
- const tooltip2 = jsxRuntime.jsxs("div", {
1612
+ const tooltip2 = jsxRuntime.jsx("div", {
1756
1613
  ref: tooltipRef,
1757
1614
  className: styles2.tooltip,
1758
1615
  style: fixedStyle,
1759
- children: [positionInTarget && children(positionInTarget), !trackPosition && children]
1616
+ children
1760
1617
  });
1761
- return compat.createPortal(type === TooltipType.modal ? jsxRuntime.jsx(Modal$1, {
1762
- visible: hoverActive,
1763
- children: tooltip2
1764
- }) : tooltip2, displayElement);
1618
+ return compat.createPortal(tooltip2, displayElement);
1765
1619
  }
1766
1620
  function tooltipPositionForPoint({
1767
1621
  targetRect,
@@ -1782,10 +1636,19 @@
1782
1636
  if (newPosition.y + tooltipHeight > displayElementRect.bottom) {
1783
1637
  newPosition.y -= tooltipHeight;
1784
1638
  }
1639
+ if (newPosition.x <= displayElementRect.left) {
1640
+ newPosition.x = displayElementRect.left + displayElementRect.width / 2 - tooltipWidth / 2;
1641
+ }
1785
1642
  return newPosition;
1786
1643
  }
1787
1644
  function tooltipPositionForRect({
1788
1645
  targetRect,
1646
+ touchRect = {
1647
+ x: 0,
1648
+ y: 0,
1649
+ width: 0,
1650
+ height: 0
1651
+ },
1789
1652
  tooltip: tooltip2,
1790
1653
  displayElement
1791
1654
  }) {
@@ -1795,6 +1658,15 @@
1795
1658
  };
1796
1659
  const tooltipWidth = tooltip2.offsetWidth;
1797
1660
  const tooltipHeight = tooltip2.offsetHeight;
1661
+ const tooltipRect = {
1662
+ ...newPosition,
1663
+ width: tooltipWidth,
1664
+ height: tooltipHeight
1665
+ };
1666
+ if (rectsIntersect(tooltipRect, touchRect)) {
1667
+ newPosition.x = touchRect.x + touchRect.width / 2;
1668
+ newPosition.y = touchRect.y - tooltipHeight;
1669
+ }
1798
1670
  const displayElementRect = displayElement.getBoundingClientRect();
1799
1671
  if (newPosition.x + tooltipWidth > displayElementRect.right) {
1800
1672
  newPosition.x = targetRect.left - tooltipWidth;
@@ -1802,6 +1674,9 @@
1802
1674
  if (newPosition.y - tooltipHeight < displayElementRect.top) {
1803
1675
  newPosition.y = targetRect.bottom;
1804
1676
  }
1677
+ if (newPosition.x <= displayElementRect.left) {
1678
+ newPosition.x = displayElementRect.left + displayElementRect.width / 2 - tooltipWidth / 2;
1679
+ }
1805
1680
  return newPosition;
1806
1681
  }
1807
1682
  const text$1 = "_text_1b8t2_1";
@@ -1865,7 +1740,7 @@
1865
1740
  displayColumn,
1866
1741
  topRow
1867
1742
  };
1868
- const ToplineResult = ({
1743
+ const ToplineResult = compat.forwardRef(({
1869
1744
  name: name2,
1870
1745
  secondaryName,
1871
1746
  mainNumber: mainNumber2,
@@ -1876,8 +1751,9 @@
1876
1751
  abbreviation,
1877
1752
  onMouseOver,
1878
1753
  onInfoPress,
1879
- showInfoButton = false
1880
- }) => {
1754
+ showInfoButton = false,
1755
+ infoButtonRef
1756
+ }, ref) => {
1881
1757
  styles2 = mergeStyles({
1882
1758
  ...defaultStyles$9
1883
1759
  }, styles2);
@@ -1885,6 +1761,7 @@
1885
1761
  return !secondaryName ? jsxRuntime.jsxs("div", {
1886
1762
  class: styles2.toplineResult,
1887
1763
  onMouseOver,
1764
+ ref,
1888
1765
  children: [jsxRuntime.jsxs("div", {
1889
1766
  class: styles2.topRow,
1890
1767
  children: [jsxRuntime.jsx("span", {
@@ -1893,7 +1770,8 @@
1893
1770
  }), " ", showInfoButton && jsxRuntime.jsx("span", {
1894
1771
  class: styles2.infoButton,
1895
1772
  children: jsxRuntime.jsx(InfoButton, {
1896
- onClick: onInfoPress
1773
+ onClick: onInfoPress,
1774
+ ref: infoButtonRef
1897
1775
  })
1898
1776
  })]
1899
1777
  }), jsxRuntime.jsxs("div", {
@@ -1912,6 +1790,7 @@
1912
1790
  }) : jsxRuntime.jsxs("div", {
1913
1791
  class: styles2.toplineResult,
1914
1792
  onMouseOver,
1793
+ ref,
1915
1794
  children: [jsxRuntime.jsxs("div", {
1916
1795
  class: styles2.topRow,
1917
1796
  children: [jsxRuntime.jsx("span", {
@@ -1943,7 +1822,7 @@
1943
1822
  })]
1944
1823
  })]
1945
1824
  });
1946
- };
1825
+ });
1947
1826
  const section = "_section_12aiu_9";
1948
1827
  const borderTop = "_borderTop_12aiu_52";
1949
1828
  const header = "_header_12aiu_56";
@@ -3010,6 +2889,72 @@
3010
2889
  })
3011
2890
  });
3012
2891
  }
2892
+ function n(n2) {
2893
+ return (r) => {
2894
+ n2.forEach((n3) => {
2895
+ "function" == typeof n3 ? n3(r) : null != n3 && (n3.current = r);
2896
+ });
2897
+ };
2898
+ }
2899
+ var T, c;
2900
+ !function(e) {
2901
+ e.APPEAR = "appear", e.APPEAR_ACTIVE = "appearActive", e.APPEAR_DONE = "appearDone", e.ENTER = "enter", e.ENTER_ACTIVE = "enterActive", e.ENTER_DONE = "enterDone", e.EXIT = "exit", e.EXIT_ACTIVE = "exitActive", e.EXIT_DONE = "exitDone";
2902
+ }(T || (T = {})), function(e) {
2903
+ e.ENTER = "onEnter", e.ENTERING = "onEntering", e.ENTERED = "onEntered", e.EXIT = "onExit", e.EXITING = "onExiting", e.EXITED = "onExited";
2904
+ }(c || (c = {}));
2905
+ const s = { [T.APPEAR]: [c.ENTER, T.APPEAR_ACTIVE], [T.APPEAR_ACTIVE]: [c.ENTERING, T.APPEAR_DONE, true], [T.APPEAR_DONE]: [c.ENTERED], [T.ENTER]: [c.ENTER, T.ENTER_ACTIVE], [T.ENTER_ACTIVE]: [c.ENTERING, T.ENTER_DONE, true], [T.ENTER_DONE]: [c.ENTERED], [T.EXIT]: [c.EXIT, T.EXIT_ACTIVE], [T.EXIT_ACTIVE]: [c.EXITING, T.EXIT_DONE, true], [T.EXIT_DONE]: [c.EXITED] };
2906
+ var u = (r) => {
2907
+ const { children: c2, in: u2 = false, appear: A = false, enter: N2 = true, exit: l = true, duration: I = 500, alwaysMounted: p2 = false, addEndListener: R2 } = r, P2 = hooks.useRef(), _2 = hooks.useRef();
2908
+ let d2 = false;
2909
+ const [f, D] = hooks.useState(() => (d2 = true, u2 ? A ? T.APPEAR : T.APPEAR_DONE : T.EXIT_DONE));
2910
+ hooks.useEffect(() => {
2911
+ var e;
2912
+ const { setTimeout: E, clearTimeout: t } = window, [n2, o, i] = s[f];
2913
+ return null == (e = r[n2]) || e.call(r, P2.current), o && (i ? R2 ? R2(P2.current, () => D(o)) : _2.current = E(D, I, o) : D(o)), () => {
2914
+ t(_2.current);
2915
+ };
2916
+ }, [f, I]), hooks.useLayoutEffect(() => {
2917
+ d2 || D(u2 ? N2 ? T.ENTER : T.ENTER_DONE : l ? T.EXIT : T.EXIT_DONE);
2918
+ }, [u2]);
2919
+ const X = hooks.useMemo(() => {
2920
+ const e = {};
2921
+ return Object.values(T).forEach((r2) => {
2922
+ e[r2] = f === r2;
2923
+ }), e;
2924
+ }, [f]);
2925
+ if (!p2 && f === T.EXIT_DONE)
2926
+ return null;
2927
+ const O = c2(X, f);
2928
+ return preact.cloneElement(O, { ref: n([P2, O.ref]) });
2929
+ };
2930
+ function N(e, r) {
2931
+ if (null == e)
2932
+ return {};
2933
+ var E, t, n2 = {}, o = Object.keys(e);
2934
+ for (t = 0; t < o.length; t++)
2935
+ r.indexOf(E = o[t]) >= 0 || (n2[E] = e[E]);
2936
+ return n2;
2937
+ }
2938
+ const p = ["children", "classNames"], R = { [T.APPEAR]: "-appear", [T.APPEAR_ACTIVE]: "-appear-active", [T.APPEAR_DONE]: "-appear-done", [T.ENTER]: "-enter", [T.ENTER_ACTIVE]: "-enter-active", [T.ENTER_DONE]: "-enter-done", [T.EXIT]: "-exit", [T.EXIT_ACTIVE]: "-exit-active", [T.EXIT_DONE]: "-exit-done" }, P = (...e) => e.filter((e2) => !!e2).join(" "), _ = (e, r) => "string" == typeof r ? `${r}${R[e]}` : r[e];
2939
+ var d = (E) => {
2940
+ const { children: t, classNames: n2 } = E, o = N(E, p);
2941
+ return preact.createElement(u, o, (r, E2) => {
2942
+ const { className: o2 } = t.props, i = hooks.useMemo(() => P(o2, ((e, r2) => {
2943
+ const E3 = _(e, r2);
2944
+ switch (e) {
2945
+ case T.APPEAR_ACTIVE:
2946
+ return P(_(T.APPEAR, r2), E3);
2947
+ case T.ENTER_ACTIVE:
2948
+ return P(_(T.ENTER, r2), E3);
2949
+ case T.EXIT_ACTIVE:
2950
+ return P(_(T.EXIT, r2), E3);
2951
+ default:
2952
+ return E3;
2953
+ }
2954
+ })(E2, n2)), [o2, n2, E2]);
2955
+ return preact.cloneElement(t, { className: i });
2956
+ });
2957
+ };
3013
2958
  const transitionContainer = "_transitionContainer_wws3j_1";
3014
2959
  const modalBox = "_modalBox_wws3j_13";
3015
2960
  const enter = "_enter_wws3j_21";
@@ -3438,6 +3383,122 @@
3438
3383
  })]
3439
3384
  });
3440
3385
  }
3386
+ function useTouchOrHover() {
3387
+ const ref = hooks.useRef();
3388
+ const [position, setPosition] = hooks.useState();
3389
+ const [isActive, setIsActive] = hooks.useState(false);
3390
+ const [touchRect, setTouchRect] = hooks.useState();
3391
+ hooks.useEffect(() => {
3392
+ const element = ref.current;
3393
+ let touchCancelled = false;
3394
+ const touchStarted = (event) => {
3395
+ if (event.touches.length > 1)
3396
+ return;
3397
+ touchCancelled = false;
3398
+ const touch = event.touches[0];
3399
+ const {
3400
+ clientX,
3401
+ clientY
3402
+ } = touch;
3403
+ const rect = element.getBoundingClientRect();
3404
+ const point = {
3405
+ x: clientX - rect.left,
3406
+ y: clientY - rect.top
3407
+ };
3408
+ setPosition(point);
3409
+ const touchRect2 = {
3410
+ x: clientX - touch.radiusX,
3411
+ y: clientY - touch.radiusY,
3412
+ width: touch.radiusX * 2,
3413
+ height: touch.radiusY * 2
3414
+ };
3415
+ setTouchRect(touchRect2);
3416
+ setIsActive(true);
3417
+ event.stopPropagation();
3418
+ };
3419
+ const touchMoved = (event) => {
3420
+ if (touchCancelled || event.targetTouches.length !== 1)
3421
+ return;
3422
+ const touch = event.targetTouches[0];
3423
+ const {
3424
+ clientX,
3425
+ clientY
3426
+ } = touch;
3427
+ const rect = element.getBoundingClientRect();
3428
+ const point = {
3429
+ x: clientX - rect.left,
3430
+ y: clientY - rect.top
3431
+ };
3432
+ if (!event.cancelable || !pointInsideRect(point, rect)) {
3433
+ setIsActive(false);
3434
+ touchCancelled = true;
3435
+ } else {
3436
+ setPosition(point);
3437
+ setIsActive(true);
3438
+ }
3439
+ };
3440
+ const touchEnded = (event) => {
3441
+ if (event.cancelable) {
3442
+ event.preventDefault();
3443
+ }
3444
+ setIsActive(false);
3445
+ setPosition(null);
3446
+ };
3447
+ const mouseOver = (event) => {
3448
+ const {
3449
+ clientX,
3450
+ clientY
3451
+ } = event;
3452
+ const rect = element.getBoundingClientRect();
3453
+ const x = clientX - rect.left;
3454
+ const y = clientY - rect.top;
3455
+ setPosition({
3456
+ x,
3457
+ y
3458
+ });
3459
+ setIsActive(true);
3460
+ };
3461
+ const mouseMoved = (event) => {
3462
+ const {
3463
+ clientX,
3464
+ clientY
3465
+ } = event;
3466
+ const rect = element.getBoundingClientRect();
3467
+ const x = clientX - rect.left;
3468
+ const y = clientY - rect.top;
3469
+ setPosition({
3470
+ x,
3471
+ y
3472
+ });
3473
+ };
3474
+ const mouseOut = () => {
3475
+ setIsActive(false);
3476
+ setPosition(null);
3477
+ };
3478
+ element.addEventListener("touchstart", touchStarted);
3479
+ element.addEventListener("touchmove", touchMoved);
3480
+ element.addEventListener("touchend", touchEnded);
3481
+ element.addEventListener("touchcancel", touchEnded);
3482
+ element.addEventListener("mouseover", mouseOver);
3483
+ element.addEventListener("mousemove", mouseMoved);
3484
+ element.addEventListener("mouseout", mouseOut);
3485
+ return () => {
3486
+ element.removeEventListener("touchstart", touchStarted);
3487
+ element.removeEventListener("touchmove", touchMoved);
3488
+ element.removeEventListener("touchend", mouseOut);
3489
+ element.removeEventListener("touchcancel", mouseOut);
3490
+ element.removeEventListener("mouseover", touchStarted);
3491
+ element.removeEventListener("mousemove", mouseMoved);
3492
+ element.removeEventListener("mouseout", mouseOut);
3493
+ };
3494
+ }, []);
3495
+ return {
3496
+ touchOrHoverRef: ref,
3497
+ touchOrHoverIsActive: isActive,
3498
+ touchRect,
3499
+ positionInTarget: position
3500
+ };
3501
+ }
3441
3502
  exports2.AdSlot = AdSlot;
3442
3503
  exports2.ArrowButton = ArrowButton;
3443
3504
  exports2.Button = Button;
@@ -3475,8 +3536,10 @@
3475
3536
  exports2.Table = Table;
3476
3537
  exports2.Ticker = Ticker;
3477
3538
  exports2.Tooltip = Tooltip;
3478
- exports2.TooltipType = TooltipType;
3479
3539
  exports2.ToplineResult = ToplineResult;
3540
+ exports2.useContainerSize = useContainerSize;
3541
+ exports2.useTouchOrHover = useTouchOrHover;
3542
+ exports2.useWindowSize = useWindowSize;
3480
3543
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
3481
3544
  });
3482
3545
  //# sourceMappingURL=interactive-component-library.umd.cjs.map