index.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. var $iVrL9$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
  2. var $iVrL9$react = require("react");
  3. var $iVrL9$radixuiprimitive = require("@radix-ui/primitive");
  4. var $iVrL9$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
  5. var $iVrL9$radixuireactcontext = require("@radix-ui/react-context");
  6. var $iVrL9$radixuireactdismissablelayer = require("@radix-ui/react-dismissable-layer");
  7. var $iVrL9$radixuireactid = require("@radix-ui/react-id");
  8. var $iVrL9$radixuireactpopper = require("@radix-ui/react-popper");
  9. var $iVrL9$radixuireactportal = require("@radix-ui/react-portal");
  10. var $iVrL9$radixuireactpresence = require("@radix-ui/react-presence");
  11. var $iVrL9$radixuireactprimitive = require("@radix-ui/react-primitive");
  12. var $iVrL9$radixuireactslot = require("@radix-ui/react-slot");
  13. var $iVrL9$radixuireactusecontrollablestate = require("@radix-ui/react-use-controllable-state");
  14. var $iVrL9$radixuireactvisuallyhidden = require("@radix-ui/react-visually-hidden");
  15. function $parcel$export(e, n, v, s) {
  16. Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
  17. }
  18. function $parcel$interopDefault(a) {
  19. return a && a.__esModule ? a.default : a;
  20. }
  21. $parcel$export(module.exports, "createTooltipScope", () => $c34afbc43c90cc6f$export$1c540a2224f0d865);
  22. $parcel$export(module.exports, "TooltipProvider", () => $c34afbc43c90cc6f$export$f78649fb9ca566b8);
  23. $parcel$export(module.exports, "Tooltip", () => $c34afbc43c90cc6f$export$28c660c63b792dea);
  24. $parcel$export(module.exports, "TooltipTrigger", () => $c34afbc43c90cc6f$export$8c610744efcf8a1d);
  25. $parcel$export(module.exports, "TooltipPortal", () => $c34afbc43c90cc6f$export$7b36b8f925ab7497);
  26. $parcel$export(module.exports, "TooltipContent", () => $c34afbc43c90cc6f$export$e9003e2be37ec060);
  27. $parcel$export(module.exports, "TooltipArrow", () => $c34afbc43c90cc6f$export$c27ee0ad710f7559);
  28. $parcel$export(module.exports, "Provider", () => $c34afbc43c90cc6f$export$2881499e37b75b9a);
  29. $parcel$export(module.exports, "Root", () => $c34afbc43c90cc6f$export$be92b6f5f03c0fe9);
  30. $parcel$export(module.exports, "Trigger", () => $c34afbc43c90cc6f$export$41fb9f06171c75f4);
  31. $parcel$export(module.exports, "Portal", () => $c34afbc43c90cc6f$export$602eac185826482c);
  32. $parcel$export(module.exports, "Content", () => $c34afbc43c90cc6f$export$7c6e2c02157bb7d2);
  33. $parcel$export(module.exports, "Arrow", () => $c34afbc43c90cc6f$export$21b07c8f274aebd5);
  34. const [$c34afbc43c90cc6f$var$createTooltipContext, $c34afbc43c90cc6f$export$1c540a2224f0d865] = $iVrL9$radixuireactcontext.createContextScope('Tooltip', [
  35. $iVrL9$radixuireactpopper.createPopperScope
  36. ]);
  37. const $c34afbc43c90cc6f$var$usePopperScope = $iVrL9$radixuireactpopper.createPopperScope();
  38. /* -------------------------------------------------------------------------------------------------
  39. * TooltipProvider
  40. * -----------------------------------------------------------------------------------------------*/ const $c34afbc43c90cc6f$var$PROVIDER_NAME = 'TooltipProvider';
  41. const $c34afbc43c90cc6f$var$DEFAULT_DELAY_DURATION = 700;
  42. const $c34afbc43c90cc6f$var$TOOLTIP_OPEN = 'tooltip.open';
  43. const [$c34afbc43c90cc6f$var$TooltipProviderContextProvider, $c34afbc43c90cc6f$var$useTooltipProviderContext] = $c34afbc43c90cc6f$var$createTooltipContext($c34afbc43c90cc6f$var$PROVIDER_NAME);
  44. const $c34afbc43c90cc6f$export$f78649fb9ca566b8 = (props)=>{
  45. const { __scopeTooltip: __scopeTooltip , delayDuration: delayDuration = $c34afbc43c90cc6f$var$DEFAULT_DELAY_DURATION , skipDelayDuration: skipDelayDuration = 300 , disableHoverableContent: disableHoverableContent = false , children: children } = props;
  46. const [isOpenDelayed, setIsOpenDelayed] = $iVrL9$react.useState(true);
  47. const isPointerInTransitRef = $iVrL9$react.useRef(false);
  48. const skipDelayTimerRef = $iVrL9$react.useRef(0);
  49. $iVrL9$react.useEffect(()=>{
  50. const skipDelayTimer = skipDelayTimerRef.current;
  51. return ()=>window.clearTimeout(skipDelayTimer)
  52. ;
  53. }, []);
  54. return /*#__PURE__*/ $iVrL9$react.createElement($c34afbc43c90cc6f$var$TooltipProviderContextProvider, {
  55. scope: __scopeTooltip,
  56. isOpenDelayed: isOpenDelayed,
  57. delayDuration: delayDuration,
  58. onOpen: $iVrL9$react.useCallback(()=>{
  59. window.clearTimeout(skipDelayTimerRef.current);
  60. setIsOpenDelayed(false);
  61. }, []),
  62. onClose: $iVrL9$react.useCallback(()=>{
  63. window.clearTimeout(skipDelayTimerRef.current);
  64. skipDelayTimerRef.current = window.setTimeout(()=>setIsOpenDelayed(true)
  65. , skipDelayDuration);
  66. }, [
  67. skipDelayDuration
  68. ]),
  69. isPointerInTransitRef: isPointerInTransitRef,
  70. onPointerInTransitChange: $iVrL9$react.useCallback((inTransit)=>{
  71. isPointerInTransitRef.current = inTransit;
  72. }, []),
  73. disableHoverableContent: disableHoverableContent
  74. }, children);
  75. };
  76. /*#__PURE__*/ Object.assign($c34afbc43c90cc6f$export$f78649fb9ca566b8, {
  77. displayName: $c34afbc43c90cc6f$var$PROVIDER_NAME
  78. });
  79. /* -------------------------------------------------------------------------------------------------
  80. * Tooltip
  81. * -----------------------------------------------------------------------------------------------*/ const $c34afbc43c90cc6f$var$TOOLTIP_NAME = 'Tooltip';
  82. const [$c34afbc43c90cc6f$var$TooltipContextProvider, $c34afbc43c90cc6f$var$useTooltipContext] = $c34afbc43c90cc6f$var$createTooltipContext($c34afbc43c90cc6f$var$TOOLTIP_NAME);
  83. const $c34afbc43c90cc6f$export$28c660c63b792dea = (props)=>{
  84. const { __scopeTooltip: __scopeTooltip , children: children , open: openProp , defaultOpen: defaultOpen = false , onOpenChange: onOpenChange , disableHoverableContent: disableHoverableContentProp , delayDuration: delayDurationProp } = props;
  85. const providerContext = $c34afbc43c90cc6f$var$useTooltipProviderContext($c34afbc43c90cc6f$var$TOOLTIP_NAME, props.__scopeTooltip);
  86. const popperScope = $c34afbc43c90cc6f$var$usePopperScope(__scopeTooltip);
  87. const [trigger, setTrigger] = $iVrL9$react.useState(null);
  88. const contentId = $iVrL9$radixuireactid.useId();
  89. const openTimerRef = $iVrL9$react.useRef(0);
  90. const disableHoverableContent = disableHoverableContentProp !== null && disableHoverableContentProp !== void 0 ? disableHoverableContentProp : providerContext.disableHoverableContent;
  91. const delayDuration = delayDurationProp !== null && delayDurationProp !== void 0 ? delayDurationProp : providerContext.delayDuration;
  92. const wasOpenDelayedRef = $iVrL9$react.useRef(false);
  93. const [open1 = false, setOpen] = $iVrL9$radixuireactusecontrollablestate.useControllableState({
  94. prop: openProp,
  95. defaultProp: defaultOpen,
  96. onChange: (open)=>{
  97. if (open) {
  98. providerContext.onOpen(); // as `onChange` is called within a lifecycle method we
  99. // avoid dispatching via `dispatchDiscreteCustomEvent`.
  100. document.dispatchEvent(new CustomEvent($c34afbc43c90cc6f$var$TOOLTIP_OPEN));
  101. } else providerContext.onClose();
  102. onOpenChange === null || onOpenChange === void 0 || onOpenChange(open);
  103. }
  104. });
  105. const stateAttribute = $iVrL9$react.useMemo(()=>{
  106. return open1 ? wasOpenDelayedRef.current ? 'delayed-open' : 'instant-open' : 'closed';
  107. }, [
  108. open1
  109. ]);
  110. const handleOpen = $iVrL9$react.useCallback(()=>{
  111. window.clearTimeout(openTimerRef.current);
  112. wasOpenDelayedRef.current = false;
  113. setOpen(true);
  114. }, [
  115. setOpen
  116. ]);
  117. const handleClose = $iVrL9$react.useCallback(()=>{
  118. window.clearTimeout(openTimerRef.current);
  119. setOpen(false);
  120. }, [
  121. setOpen
  122. ]);
  123. const handleDelayedOpen = $iVrL9$react.useCallback(()=>{
  124. window.clearTimeout(openTimerRef.current);
  125. openTimerRef.current = window.setTimeout(()=>{
  126. wasOpenDelayedRef.current = true;
  127. setOpen(true);
  128. }, delayDuration);
  129. }, [
  130. delayDuration,
  131. setOpen
  132. ]);
  133. $iVrL9$react.useEffect(()=>{
  134. return ()=>window.clearTimeout(openTimerRef.current)
  135. ;
  136. }, []);
  137. return /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactpopper.Root, popperScope, /*#__PURE__*/ $iVrL9$react.createElement($c34afbc43c90cc6f$var$TooltipContextProvider, {
  138. scope: __scopeTooltip,
  139. contentId: contentId,
  140. open: open1,
  141. stateAttribute: stateAttribute,
  142. trigger: trigger,
  143. onTriggerChange: setTrigger,
  144. onTriggerEnter: $iVrL9$react.useCallback(()=>{
  145. if (providerContext.isOpenDelayed) handleDelayedOpen();
  146. else handleOpen();
  147. }, [
  148. providerContext.isOpenDelayed,
  149. handleDelayedOpen,
  150. handleOpen
  151. ]),
  152. onTriggerLeave: $iVrL9$react.useCallback(()=>{
  153. if (disableHoverableContent) handleClose();
  154. else // Clear the timer in case the pointer leaves the trigger before the tooltip is opened.
  155. window.clearTimeout(openTimerRef.current);
  156. }, [
  157. handleClose,
  158. disableHoverableContent
  159. ]),
  160. onOpen: handleOpen,
  161. onClose: handleClose,
  162. disableHoverableContent: disableHoverableContent
  163. }, children));
  164. };
  165. /*#__PURE__*/ Object.assign($c34afbc43c90cc6f$export$28c660c63b792dea, {
  166. displayName: $c34afbc43c90cc6f$var$TOOLTIP_NAME
  167. });
  168. /* -------------------------------------------------------------------------------------------------
  169. * TooltipTrigger
  170. * -----------------------------------------------------------------------------------------------*/ const $c34afbc43c90cc6f$var$TRIGGER_NAME = 'TooltipTrigger';
  171. const $c34afbc43c90cc6f$export$8c610744efcf8a1d = /*#__PURE__*/ $iVrL9$react.forwardRef((props, forwardedRef)=>{
  172. const { __scopeTooltip: __scopeTooltip , ...triggerProps } = props;
  173. const context = $c34afbc43c90cc6f$var$useTooltipContext($c34afbc43c90cc6f$var$TRIGGER_NAME, __scopeTooltip);
  174. const providerContext = $c34afbc43c90cc6f$var$useTooltipProviderContext($c34afbc43c90cc6f$var$TRIGGER_NAME, __scopeTooltip);
  175. const popperScope = $c34afbc43c90cc6f$var$usePopperScope(__scopeTooltip);
  176. const ref = $iVrL9$react.useRef(null);
  177. const composedRefs = $iVrL9$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref, context.onTriggerChange);
  178. const isPointerDownRef = $iVrL9$react.useRef(false);
  179. const hasPointerMoveOpenedRef = $iVrL9$react.useRef(false);
  180. const handlePointerUp = $iVrL9$react.useCallback(()=>isPointerDownRef.current = false
  181. , []);
  182. $iVrL9$react.useEffect(()=>{
  183. return ()=>document.removeEventListener('pointerup', handlePointerUp)
  184. ;
  185. }, [
  186. handlePointerUp
  187. ]);
  188. return /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactpopper.Anchor, ($parcel$interopDefault($iVrL9$babelruntimehelpersextends))({
  189. asChild: true
  190. }, popperScope), /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($iVrL9$babelruntimehelpersextends))({
  191. // We purposefully avoid adding `type=button` here because tooltip triggers are also
  192. // commonly anchors and the anchor `type` attribute signifies MIME type.
  193. "aria-describedby": context.open ? context.contentId : undefined,
  194. "data-state": context.stateAttribute
  195. }, triggerProps, {
  196. ref: composedRefs,
  197. onPointerMove: $iVrL9$radixuiprimitive.composeEventHandlers(props.onPointerMove, (event)=>{
  198. if (event.pointerType === 'touch') return;
  199. if (!hasPointerMoveOpenedRef.current && !providerContext.isPointerInTransitRef.current) {
  200. context.onTriggerEnter();
  201. hasPointerMoveOpenedRef.current = true;
  202. }
  203. }),
  204. onPointerLeave: $iVrL9$radixuiprimitive.composeEventHandlers(props.onPointerLeave, ()=>{
  205. context.onTriggerLeave();
  206. hasPointerMoveOpenedRef.current = false;
  207. }),
  208. onPointerDown: $iVrL9$radixuiprimitive.composeEventHandlers(props.onPointerDown, ()=>{
  209. isPointerDownRef.current = true;
  210. document.addEventListener('pointerup', handlePointerUp, {
  211. once: true
  212. });
  213. }),
  214. onFocus: $iVrL9$radixuiprimitive.composeEventHandlers(props.onFocus, ()=>{
  215. if (!isPointerDownRef.current) context.onOpen();
  216. }),
  217. onBlur: $iVrL9$radixuiprimitive.composeEventHandlers(props.onBlur, context.onClose),
  218. onClick: $iVrL9$radixuiprimitive.composeEventHandlers(props.onClick, context.onClose)
  219. })));
  220. });
  221. /*#__PURE__*/ Object.assign($c34afbc43c90cc6f$export$8c610744efcf8a1d, {
  222. displayName: $c34afbc43c90cc6f$var$TRIGGER_NAME
  223. });
  224. /* -------------------------------------------------------------------------------------------------
  225. * TooltipPortal
  226. * -----------------------------------------------------------------------------------------------*/ const $c34afbc43c90cc6f$var$PORTAL_NAME = 'TooltipPortal';
  227. const [$c34afbc43c90cc6f$var$PortalProvider, $c34afbc43c90cc6f$var$usePortalContext] = $c34afbc43c90cc6f$var$createTooltipContext($c34afbc43c90cc6f$var$PORTAL_NAME, {
  228. forceMount: undefined
  229. });
  230. const $c34afbc43c90cc6f$export$7b36b8f925ab7497 = (props)=>{
  231. const { __scopeTooltip: __scopeTooltip , forceMount: forceMount , children: children , container: container } = props;
  232. const context = $c34afbc43c90cc6f$var$useTooltipContext($c34afbc43c90cc6f$var$PORTAL_NAME, __scopeTooltip);
  233. return /*#__PURE__*/ $iVrL9$react.createElement($c34afbc43c90cc6f$var$PortalProvider, {
  234. scope: __scopeTooltip,
  235. forceMount: forceMount
  236. }, /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactpresence.Presence, {
  237. present: forceMount || context.open
  238. }, /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactportal.Portal, {
  239. asChild: true,
  240. container: container
  241. }, children)));
  242. };
  243. /*#__PURE__*/ Object.assign($c34afbc43c90cc6f$export$7b36b8f925ab7497, {
  244. displayName: $c34afbc43c90cc6f$var$PORTAL_NAME
  245. });
  246. /* -------------------------------------------------------------------------------------------------
  247. * TooltipContent
  248. * -----------------------------------------------------------------------------------------------*/ const $c34afbc43c90cc6f$var$CONTENT_NAME = 'TooltipContent';
  249. const $c34afbc43c90cc6f$export$e9003e2be37ec060 = /*#__PURE__*/ $iVrL9$react.forwardRef((props, forwardedRef)=>{
  250. const portalContext = $c34afbc43c90cc6f$var$usePortalContext($c34afbc43c90cc6f$var$CONTENT_NAME, props.__scopeTooltip);
  251. const { forceMount: forceMount = portalContext.forceMount , side: side = 'top' , ...contentProps } = props;
  252. const context = $c34afbc43c90cc6f$var$useTooltipContext($c34afbc43c90cc6f$var$CONTENT_NAME, props.__scopeTooltip);
  253. return /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactpresence.Presence, {
  254. present: forceMount || context.open
  255. }, context.disableHoverableContent ? /*#__PURE__*/ $iVrL9$react.createElement($c34afbc43c90cc6f$var$TooltipContentImpl, ($parcel$interopDefault($iVrL9$babelruntimehelpersextends))({
  256. side: side
  257. }, contentProps, {
  258. ref: forwardedRef
  259. })) : /*#__PURE__*/ $iVrL9$react.createElement($c34afbc43c90cc6f$var$TooltipContentHoverable, ($parcel$interopDefault($iVrL9$babelruntimehelpersextends))({
  260. side: side
  261. }, contentProps, {
  262. ref: forwardedRef
  263. })));
  264. });
  265. const $c34afbc43c90cc6f$var$TooltipContentHoverable = /*#__PURE__*/ $iVrL9$react.forwardRef((props, forwardedRef)=>{
  266. const context = $c34afbc43c90cc6f$var$useTooltipContext($c34afbc43c90cc6f$var$CONTENT_NAME, props.__scopeTooltip);
  267. const providerContext = $c34afbc43c90cc6f$var$useTooltipProviderContext($c34afbc43c90cc6f$var$CONTENT_NAME, props.__scopeTooltip);
  268. const ref = $iVrL9$react.useRef(null);
  269. const composedRefs = $iVrL9$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
  270. const [pointerGraceArea, setPointerGraceArea] = $iVrL9$react.useState(null);
  271. const { trigger: trigger , onClose: onClose } = context;
  272. const content = ref.current;
  273. const { onPointerInTransitChange: onPointerInTransitChange } = providerContext;
  274. const handleRemoveGraceArea = $iVrL9$react.useCallback(()=>{
  275. setPointerGraceArea(null);
  276. onPointerInTransitChange(false);
  277. }, [
  278. onPointerInTransitChange
  279. ]);
  280. const handleCreateGraceArea = $iVrL9$react.useCallback((event, hoverTarget)=>{
  281. const currentTarget = event.currentTarget;
  282. const exitPoint = {
  283. x: event.clientX,
  284. y: event.clientY
  285. };
  286. const exitSide = $c34afbc43c90cc6f$var$getExitSideFromRect(exitPoint, currentTarget.getBoundingClientRect());
  287. const paddedExitPoints = $c34afbc43c90cc6f$var$getPaddedExitPoints(exitPoint, exitSide);
  288. const hoverTargetPoints = $c34afbc43c90cc6f$var$getPointsFromRect(hoverTarget.getBoundingClientRect());
  289. const graceArea = $c34afbc43c90cc6f$var$getHull([
  290. ...paddedExitPoints,
  291. ...hoverTargetPoints
  292. ]);
  293. setPointerGraceArea(graceArea);
  294. onPointerInTransitChange(true);
  295. }, [
  296. onPointerInTransitChange
  297. ]);
  298. $iVrL9$react.useEffect(()=>{
  299. return ()=>handleRemoveGraceArea()
  300. ;
  301. }, [
  302. handleRemoveGraceArea
  303. ]);
  304. $iVrL9$react.useEffect(()=>{
  305. if (trigger && content) {
  306. const handleTriggerLeave = (event)=>handleCreateGraceArea(event, content)
  307. ;
  308. const handleContentLeave = (event)=>handleCreateGraceArea(event, trigger)
  309. ;
  310. trigger.addEventListener('pointerleave', handleTriggerLeave);
  311. content.addEventListener('pointerleave', handleContentLeave);
  312. return ()=>{
  313. trigger.removeEventListener('pointerleave', handleTriggerLeave);
  314. content.removeEventListener('pointerleave', handleContentLeave);
  315. };
  316. }
  317. }, [
  318. trigger,
  319. content,
  320. handleCreateGraceArea,
  321. handleRemoveGraceArea
  322. ]);
  323. $iVrL9$react.useEffect(()=>{
  324. if (pointerGraceArea) {
  325. const handleTrackPointerGrace = (event)=>{
  326. const target = event.target;
  327. const pointerPosition = {
  328. x: event.clientX,
  329. y: event.clientY
  330. };
  331. const hasEnteredTarget = (trigger === null || trigger === void 0 ? void 0 : trigger.contains(target)) || (content === null || content === void 0 ? void 0 : content.contains(target));
  332. const isPointerOutsideGraceArea = !$c34afbc43c90cc6f$var$isPointInPolygon(pointerPosition, pointerGraceArea);
  333. if (hasEnteredTarget) handleRemoveGraceArea();
  334. else if (isPointerOutsideGraceArea) {
  335. handleRemoveGraceArea();
  336. onClose();
  337. }
  338. };
  339. document.addEventListener('pointermove', handleTrackPointerGrace);
  340. return ()=>document.removeEventListener('pointermove', handleTrackPointerGrace)
  341. ;
  342. }
  343. }, [
  344. trigger,
  345. content,
  346. pointerGraceArea,
  347. onClose,
  348. handleRemoveGraceArea
  349. ]);
  350. return /*#__PURE__*/ $iVrL9$react.createElement($c34afbc43c90cc6f$var$TooltipContentImpl, ($parcel$interopDefault($iVrL9$babelruntimehelpersextends))({}, props, {
  351. ref: composedRefs
  352. }));
  353. });
  354. const [$c34afbc43c90cc6f$var$VisuallyHiddenContentContextProvider, $c34afbc43c90cc6f$var$useVisuallyHiddenContentContext] = $c34afbc43c90cc6f$var$createTooltipContext($c34afbc43c90cc6f$var$TOOLTIP_NAME, {
  355. isInside: false
  356. });
  357. const $c34afbc43c90cc6f$var$TooltipContentImpl = /*#__PURE__*/ $iVrL9$react.forwardRef((props, forwardedRef)=>{
  358. const { __scopeTooltip: __scopeTooltip , children: children , 'aria-label': ariaLabel , onEscapeKeyDown: onEscapeKeyDown , onPointerDownOutside: onPointerDownOutside , ...contentProps } = props;
  359. const context = $c34afbc43c90cc6f$var$useTooltipContext($c34afbc43c90cc6f$var$CONTENT_NAME, __scopeTooltip);
  360. const popperScope = $c34afbc43c90cc6f$var$usePopperScope(__scopeTooltip);
  361. const { onClose: onClose } = context; // Close this tooltip if another one opens
  362. $iVrL9$react.useEffect(()=>{
  363. document.addEventListener($c34afbc43c90cc6f$var$TOOLTIP_OPEN, onClose);
  364. return ()=>document.removeEventListener($c34afbc43c90cc6f$var$TOOLTIP_OPEN, onClose)
  365. ;
  366. }, [
  367. onClose
  368. ]); // Close the tooltip if the trigger is scrolled
  369. $iVrL9$react.useEffect(()=>{
  370. if (context.trigger) {
  371. const handleScroll = (event)=>{
  372. const target = event.target;
  373. if (target !== null && target !== void 0 && target.contains(context.trigger)) onClose();
  374. };
  375. window.addEventListener('scroll', handleScroll, {
  376. capture: true
  377. });
  378. return ()=>window.removeEventListener('scroll', handleScroll, {
  379. capture: true
  380. })
  381. ;
  382. }
  383. }, [
  384. context.trigger,
  385. onClose
  386. ]);
  387. return /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactdismissablelayer.DismissableLayer, {
  388. asChild: true,
  389. disableOutsidePointerEvents: false,
  390. onEscapeKeyDown: onEscapeKeyDown,
  391. onPointerDownOutside: onPointerDownOutside,
  392. onFocusOutside: (event)=>event.preventDefault()
  393. ,
  394. onDismiss: onClose
  395. }, /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactpopper.Content, ($parcel$interopDefault($iVrL9$babelruntimehelpersextends))({
  396. "data-state": context.stateAttribute
  397. }, popperScope, contentProps, {
  398. ref: forwardedRef,
  399. style: {
  400. ...contentProps.style,
  401. '--radix-tooltip-content-transform-origin': 'var(--radix-popper-transform-origin)',
  402. '--radix-tooltip-content-available-width': 'var(--radix-popper-available-width)',
  403. '--radix-tooltip-content-available-height': 'var(--radix-popper-available-height)',
  404. '--radix-tooltip-trigger-width': 'var(--radix-popper-anchor-width)',
  405. '--radix-tooltip-trigger-height': 'var(--radix-popper-anchor-height)'
  406. }
  407. }), /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactslot.Slottable, null, children), /*#__PURE__*/ $iVrL9$react.createElement($c34afbc43c90cc6f$var$VisuallyHiddenContentContextProvider, {
  408. scope: __scopeTooltip,
  409. isInside: true
  410. }, /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactvisuallyhidden.Root, {
  411. id: context.contentId,
  412. role: "tooltip"
  413. }, ariaLabel || children))));
  414. });
  415. /*#__PURE__*/ Object.assign($c34afbc43c90cc6f$export$e9003e2be37ec060, {
  416. displayName: $c34afbc43c90cc6f$var$CONTENT_NAME
  417. });
  418. /* -------------------------------------------------------------------------------------------------
  419. * TooltipArrow
  420. * -----------------------------------------------------------------------------------------------*/ const $c34afbc43c90cc6f$var$ARROW_NAME = 'TooltipArrow';
  421. const $c34afbc43c90cc6f$export$c27ee0ad710f7559 = /*#__PURE__*/ $iVrL9$react.forwardRef((props, forwardedRef)=>{
  422. const { __scopeTooltip: __scopeTooltip , ...arrowProps } = props;
  423. const popperScope = $c34afbc43c90cc6f$var$usePopperScope(__scopeTooltip);
  424. const visuallyHiddenContentContext = $c34afbc43c90cc6f$var$useVisuallyHiddenContentContext($c34afbc43c90cc6f$var$ARROW_NAME, __scopeTooltip); // if the arrow is inside the `VisuallyHidden`, we don't want to render it all to
  425. // prevent issues in positioning the arrow due to the duplicate
  426. return visuallyHiddenContentContext.isInside ? null : /*#__PURE__*/ $iVrL9$react.createElement($iVrL9$radixuireactpopper.Arrow, ($parcel$interopDefault($iVrL9$babelruntimehelpersextends))({}, popperScope, arrowProps, {
  427. ref: forwardedRef
  428. }));
  429. });
  430. /*#__PURE__*/ Object.assign($c34afbc43c90cc6f$export$c27ee0ad710f7559, {
  431. displayName: $c34afbc43c90cc6f$var$ARROW_NAME
  432. });
  433. /* -----------------------------------------------------------------------------------------------*/ function $c34afbc43c90cc6f$var$getExitSideFromRect(point, rect) {
  434. const top = Math.abs(rect.top - point.y);
  435. const bottom = Math.abs(rect.bottom - point.y);
  436. const right = Math.abs(rect.right - point.x);
  437. const left = Math.abs(rect.left - point.x);
  438. switch(Math.min(top, bottom, right, left)){
  439. case left:
  440. return 'left';
  441. case right:
  442. return 'right';
  443. case top:
  444. return 'top';
  445. case bottom:
  446. return 'bottom';
  447. default:
  448. throw new Error('unreachable');
  449. }
  450. }
  451. function $c34afbc43c90cc6f$var$getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
  452. const paddedExitPoints = [];
  453. switch(exitSide){
  454. case 'top':
  455. paddedExitPoints.push({
  456. x: exitPoint.x - padding,
  457. y: exitPoint.y + padding
  458. }, {
  459. x: exitPoint.x + padding,
  460. y: exitPoint.y + padding
  461. });
  462. break;
  463. case 'bottom':
  464. paddedExitPoints.push({
  465. x: exitPoint.x - padding,
  466. y: exitPoint.y - padding
  467. }, {
  468. x: exitPoint.x + padding,
  469. y: exitPoint.y - padding
  470. });
  471. break;
  472. case 'left':
  473. paddedExitPoints.push({
  474. x: exitPoint.x + padding,
  475. y: exitPoint.y - padding
  476. }, {
  477. x: exitPoint.x + padding,
  478. y: exitPoint.y + padding
  479. });
  480. break;
  481. case 'right':
  482. paddedExitPoints.push({
  483. x: exitPoint.x - padding,
  484. y: exitPoint.y - padding
  485. }, {
  486. x: exitPoint.x - padding,
  487. y: exitPoint.y + padding
  488. });
  489. break;
  490. }
  491. return paddedExitPoints;
  492. }
  493. function $c34afbc43c90cc6f$var$getPointsFromRect(rect) {
  494. const { top: top , right: right , bottom: bottom , left: left } = rect;
  495. return [
  496. {
  497. x: left,
  498. y: top
  499. },
  500. {
  501. x: right,
  502. y: top
  503. },
  504. {
  505. x: right,
  506. y: bottom
  507. },
  508. {
  509. x: left,
  510. y: bottom
  511. }
  512. ];
  513. } // Determine if a point is inside of a polygon.
  514. // Based on https://github.com/substack/point-in-polygon
  515. function $c34afbc43c90cc6f$var$isPointInPolygon(point, polygon) {
  516. const { x: x , y: y } = point;
  517. let inside = false;
  518. for(let i = 0, j = polygon.length - 1; i < polygon.length; j = i++){
  519. const xi = polygon[i].x;
  520. const yi = polygon[i].y;
  521. const xj = polygon[j].x;
  522. const yj = polygon[j].y; // prettier-ignore
  523. const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
  524. if (intersect) inside = !inside;
  525. }
  526. return inside;
  527. } // Returns a new array of points representing the convex hull of the given set of points.
  528. // https://www.nayuki.io/page/convex-hull-algorithm
  529. function $c34afbc43c90cc6f$var$getHull(points) {
  530. const newPoints = points.slice();
  531. newPoints.sort((a, b)=>{
  532. if (a.x < b.x) return -1;
  533. else if (a.x > b.x) return 1;
  534. else if (a.y < b.y) return -1;
  535. else if (a.y > b.y) return 1;
  536. else return 0;
  537. });
  538. return $c34afbc43c90cc6f$var$getHullPresorted(newPoints);
  539. } // Returns the convex hull, assuming that each points[i] <= points[i + 1]. Runs in O(n) time.
  540. function $c34afbc43c90cc6f$var$getHullPresorted(points) {
  541. if (points.length <= 1) return points.slice();
  542. const upperHull = [];
  543. for(let i = 0; i < points.length; i++){
  544. const p = points[i];
  545. while(upperHull.length >= 2){
  546. const q = upperHull[upperHull.length - 1];
  547. const r = upperHull[upperHull.length - 2];
  548. if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) upperHull.pop();
  549. else break;
  550. }
  551. upperHull.push(p);
  552. }
  553. upperHull.pop();
  554. const lowerHull = [];
  555. for(let i1 = points.length - 1; i1 >= 0; i1--){
  556. const p = points[i1];
  557. while(lowerHull.length >= 2){
  558. const q = lowerHull[lowerHull.length - 1];
  559. const r = lowerHull[lowerHull.length - 2];
  560. if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) lowerHull.pop();
  561. else break;
  562. }
  563. lowerHull.push(p);
  564. }
  565. lowerHull.pop();
  566. if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y) return upperHull;
  567. else return upperHull.concat(lowerHull);
  568. }
  569. const $c34afbc43c90cc6f$export$2881499e37b75b9a = $c34afbc43c90cc6f$export$f78649fb9ca566b8;
  570. const $c34afbc43c90cc6f$export$be92b6f5f03c0fe9 = $c34afbc43c90cc6f$export$28c660c63b792dea;
  571. const $c34afbc43c90cc6f$export$41fb9f06171c75f4 = $c34afbc43c90cc6f$export$8c610744efcf8a1d;
  572. const $c34afbc43c90cc6f$export$602eac185826482c = $c34afbc43c90cc6f$export$7b36b8f925ab7497;
  573. const $c34afbc43c90cc6f$export$7c6e2c02157bb7d2 = $c34afbc43c90cc6f$export$e9003e2be37ec060;
  574. const $c34afbc43c90cc6f$export$21b07c8f274aebd5 = $c34afbc43c90cc6f$export$c27ee0ad710f7559;
  575. //# sourceMappingURL=index.js.map