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