index.mjs 28 KB

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