@huin-core/react-tooltip 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +100 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +579 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +547 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +3 -2
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../src/index.ts", "../src/Tooltip.tsx", "../src/TooltipProvider.tsx", "../src/TooltipPortal.tsx", "../src/TooltipContent.tsx", "../src/TooltipTrigger.tsx", "../src/TooltipArrow.tsx"],
|
4
|
+
"sourcesContent": ["\"use client\";\nexport { Tooltip, Root } from \"./Tooltip\";\nexport { TooltipPortal } from \"./TooltipPortal\";\nexport { TooltipContent } from \"./TooltipContent\";\nexport { TooltipProvider } from \"./TooltipProvider\";\nexport { TooltipTrigger } from \"./TooltipTrigger\";\nexport { TooltipArrow } from \"./TooltipArrow\";\n\nexport type { TooltipProps } from \"./Tooltip\";\nexport type { TooltipPortalProps } from \"./TooltipPortal\";\nexport type { TooltipContentProps } from \"./TooltipContent\";\nexport type { TooltipProviderProps } from \"./TooltipProvider\";\nexport type { TooltipTriggerProps } from \"./TooltipTrigger\";\nexport type { TooltipArrowProps } from \"./TooltipArrow\";\n", "import * as React from \"react\";\nimport { createContextScope } from \"@huin-core/react-context\";\nimport { useId } from \"@huin-core/react-id\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { createPopperScope } from \"@huin-core/react-popper\";\nimport { useControllableState } from \"@huin-core/react-use-controllable-state\";\nimport type { Scope } from \"@huin-core/react-context\";\nimport { TooltipTriggerElement } from \"./TooltipTrigger\";\nimport { useTooltipProviderContext } from \"./TooltipProvider\";\n\nexport type ScopedProps<P = {}> = P & { __scopeTooltip?: Scope };\nexport const [createTooltipContext, createTooltipScope] = createContextScope(\n \"Tooltip\",\n [createPopperScope]\n);\nexport const usePopperScope = createPopperScope();\nexport const TOOLTIP_OPEN = \"tooltip.open\";\n\n/* -------------------------------------------------------------------------------------------------\n * Tooltip\n * -----------------------------------------------------------------------------------------------*/\n\nexport const TOOLTIP_NAME = \"Tooltip\";\n\ntype TooltipContextValue = {\n contentId: string;\n open: boolean;\n stateAttribute: \"closed\" | \"delayed-open\" | \"instant-open\";\n trigger: TooltipTriggerElement | null;\n onTriggerChange(trigger: TooltipTriggerElement | null): void;\n onTriggerEnter(): void;\n onTriggerLeave(): void;\n onOpen(): void;\n onClose(): void;\n disableHoverableContent: boolean;\n};\n\nexport const [TooltipContextProvider, useTooltipContext] =\n createTooltipContext<TooltipContextValue>(TOOLTIP_NAME);\n\ninterface TooltipProps {\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /**\n * The duration from when the pointer enters the trigger until the tooltip gets opened. This will\n * override the prop with the same name passed to Provider.\n * @defaultValue 700\n */\n delayDuration?: number;\n /**\n * When `true`, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.\n * @defaultValue false\n */\n disableHoverableContent?: boolean;\n}\n\nconst Tooltip: React.FC<TooltipProps> = (props: ScopedProps<TooltipProps>) => {\n const {\n __scopeTooltip,\n children,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n disableHoverableContent: disableHoverableContentProp,\n delayDuration: delayDurationProp,\n } = props;\n const providerContext = useTooltipProviderContext(\n TOOLTIP_NAME,\n props.__scopeTooltip\n );\n const popperScope = usePopperScope(__scopeTooltip);\n const [trigger, setTrigger] = React.useState<HTMLButtonElement | null>(null);\n const contentId = useId();\n const openTimerRef = React.useRef(0);\n const disableHoverableContent =\n disableHoverableContentProp ?? providerContext.disableHoverableContent;\n const delayDuration = delayDurationProp ?? providerContext.delayDuration;\n const wasOpenDelayedRef = React.useRef(false);\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: (open) => {\n if (open) {\n providerContext.onOpen();\n\n // as `onChange` is called within a lifecycle method we\n // avoid dispatching via `dispatchDiscreteCustomEvent`.\n document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN));\n } else {\n providerContext.onClose();\n }\n onOpenChange?.(open);\n },\n });\n const stateAttribute = React.useMemo(() => {\n return open\n ? wasOpenDelayedRef.current\n ? \"delayed-open\"\n : \"instant-open\"\n : \"closed\";\n }, [open]);\n\n const handleOpen = React.useCallback(() => {\n window.clearTimeout(openTimerRef.current);\n wasOpenDelayedRef.current = false;\n setOpen(true);\n }, [setOpen]);\n\n const handleClose = React.useCallback(() => {\n window.clearTimeout(openTimerRef.current);\n setOpen(false);\n }, [setOpen]);\n\n const handleDelayedOpen = React.useCallback(() => {\n window.clearTimeout(openTimerRef.current);\n openTimerRef.current = window.setTimeout(() => {\n wasOpenDelayedRef.current = true;\n setOpen(true);\n }, delayDuration);\n }, [delayDuration, setOpen]);\n\n React.useEffect(() => {\n return () => window.clearTimeout(openTimerRef.current);\n }, []);\n\n return (\n <PopperPrimitive.Root {...popperScope}>\n <TooltipContextProvider\n scope={__scopeTooltip}\n contentId={contentId}\n open={open}\n stateAttribute={stateAttribute}\n trigger={trigger}\n onTriggerChange={setTrigger}\n onTriggerEnter={React.useCallback(() => {\n if (providerContext.isOpenDelayed) handleDelayedOpen();\n else handleOpen();\n }, [providerContext.isOpenDelayed, handleDelayedOpen, handleOpen])}\n onTriggerLeave={React.useCallback(() => {\n if (disableHoverableContent) {\n handleClose();\n } else {\n // Clear the timer in case the pointer leaves the trigger before the tooltip is opened.\n window.clearTimeout(openTimerRef.current);\n }\n }, [handleClose, disableHoverableContent])}\n onOpen={handleOpen}\n onClose={handleClose}\n disableHoverableContent={disableHoverableContent}\n >\n {children}\n </TooltipContextProvider>\n </PopperPrimitive.Root>\n );\n};\n\nTooltip.displayName = TOOLTIP_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Tooltip;\n\nexport { Tooltip, Root };\nexport type { TooltipProps };\n", "import React from \"react\";\nimport { createTooltipContext, ScopedProps } from \"./Tooltip\";\n\nconst PROVIDER_NAME = \"TooltipProvider\";\nconst DEFAULT_DELAY_DURATION = 700;\n\ntype TooltipProviderContextValue = {\n isOpenDelayed: boolean;\n delayDuration: number;\n onOpen(): void;\n onClose(): void;\n onPointerInTransitChange(inTransit: boolean): void;\n isPointerInTransitRef: React.MutableRefObject<boolean>;\n disableHoverableContent: boolean;\n};\n\nexport const [TooltipProviderContextProvider, useTooltipProviderContext] =\n createTooltipContext<TooltipProviderContextValue>(PROVIDER_NAME);\n\ninterface TooltipProviderProps {\n children: React.ReactNode;\n /**\n * The duration from when the pointer enters the trigger until the tooltip gets opened.\n * @defaultValue 700\n */\n delayDuration?: number;\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * @defaultValue 300\n */\n skipDelayDuration?: number;\n /**\n * When `true`, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.\n * @defaultValue false\n */\n disableHoverableContent?: boolean;\n}\n\nconst TooltipProvider: React.FC<TooltipProviderProps> = (\n props: ScopedProps<TooltipProviderProps>\n) => {\n const {\n __scopeTooltip,\n delayDuration = DEFAULT_DELAY_DURATION,\n skipDelayDuration = 300,\n disableHoverableContent = false,\n children,\n } = props;\n const [isOpenDelayed, setIsOpenDelayed] = React.useState(true);\n const isPointerInTransitRef = React.useRef(false);\n const skipDelayTimerRef = React.useRef(0);\n\n React.useEffect(() => {\n const skipDelayTimer = skipDelayTimerRef.current;\n return () => window.clearTimeout(skipDelayTimer);\n }, []);\n\n return (\n <TooltipProviderContextProvider\n scope={__scopeTooltip}\n isOpenDelayed={isOpenDelayed}\n delayDuration={delayDuration}\n onOpen={React.useCallback(() => {\n window.clearTimeout(skipDelayTimerRef.current);\n setIsOpenDelayed(false);\n }, [])}\n onClose={React.useCallback(() => {\n window.clearTimeout(skipDelayTimerRef.current);\n skipDelayTimerRef.current = window.setTimeout(\n () => setIsOpenDelayed(true),\n skipDelayDuration\n );\n }, [skipDelayDuration])}\n isPointerInTransitRef={isPointerInTransitRef}\n onPointerInTransitChange={React.useCallback((inTransit: boolean) => {\n isPointerInTransitRef.current = inTransit;\n }, [])}\n disableHoverableContent={disableHoverableContent}\n >\n {children}\n </TooltipProviderContextProvider>\n );\n};\n\nTooltipProvider.displayName = PROVIDER_NAME;\n\n\n\nexport { TooltipProvider };\nexport type { TooltipProviderProps };\n", "import { Presence } from \"@huin-core/react-presence\";\nimport { createTooltipContext, ScopedProps, useTooltipContext } from \"./Tooltip\";\nimport { Portal as PortalPrimitive } from \"@huin-core/react-portal\";\n\nconst PORTAL_NAME = \"TooltipPortal\";\n\ntype PortalContextValue = { forceMount?: true };\nexport const [PortalProvider, usePortalContext] =\n createTooltipContext<PortalContextValue>(PORTAL_NAME, {\n forceMount: undefined,\n });\n\ntype PortalProps = React.ComponentPropsWithoutRef<typeof PortalPrimitive>;\ninterface TooltipPortalProps {\n children?: React.ReactNode;\n /**\n * Specify a container element to portal the content into.\n */\n container?: PortalProps[\"container\"];\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst TooltipPortal: React.FC<TooltipPortalProps> = (\n props: ScopedProps<TooltipPortalProps>\n) => {\n const { __scopeTooltip, forceMount, children, container } = props;\n const context = useTooltipContext(PORTAL_NAME, __scopeTooltip);\n return (\n <PortalProvider scope={__scopeTooltip} forceMount={forceMount}>\n <Presence present={forceMount || context.open}>\n <PortalPrimitive asChild container={container}>\n {children}\n </PortalPrimitive>\n </Presence>\n </PortalProvider>\n );\n};\n\nTooltipPortal.displayName = PORTAL_NAME;\n\n\nexport { TooltipPortal };\nexport type { TooltipPortalProps };\n", "import React from \"react\";\nimport {\n createTooltipContext,\n ScopedProps,\n TOOLTIP_NAME,\n TOOLTIP_OPEN,\n usePopperScope,\n useTooltipContext,\n} from \"./Tooltip\";\nimport { usePortalContext } from \"./TooltipPortal\";\nimport { Presence } from \"@huin-core/react-presence\";\nimport { useTooltipProviderContext } from \"./TooltipProvider\";\nimport { useComposedRefs } from \"@huin-core/react-compose-refs\";\nimport { Slottable } from \"@huin-core/react-slot\";\nimport * as VisuallyHiddenPrimitive from \"@huin-core/react-visually-hidden\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { DismissableLayer } from \"@huin-core/react-dismissable-layer\";\n\nconst CONTENT_NAME = \"TooltipContent\";\n\ntype TooltipContentElement = TooltipContentImplElement;\ninterface TooltipContentProps extends TooltipContentImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst TooltipContent = React.forwardRef<\n TooltipContentElement,\n TooltipContentProps\n>((props: ScopedProps<TooltipContentProps>, forwardedRef) => {\n const portalContext = usePortalContext(CONTENT_NAME, props.__scopeTooltip);\n const { forceMount = portalContext.forceMount, side = 'top', ...contentProps } = props;\n const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);\n\n return (\n <Presence present={forceMount || context.open}>\n {context.disableHoverableContent ? (\n <TooltipContentImpl side={side} {...contentProps} ref={forwardedRef} />\n ) : (\n <TooltipContentHoverable side={side} {...contentProps} ref={forwardedRef} />\n )}\n </Presence>\n );\n});\n\ntype Point = { x: number; y: number };\ntype Polygon = Point[];\n\ntype TooltipContentHoverableElement = TooltipContentImplElement;\ninterface TooltipContentHoverableProps extends TooltipContentImplProps {}\n\nconst TooltipContentHoverable = React.forwardRef<\n TooltipContentHoverableElement,\n TooltipContentHoverableProps\n>((props: ScopedProps<TooltipContentHoverableProps>, forwardedRef) => {\n const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);\n const providerContext = useTooltipProviderContext(\n CONTENT_NAME,\n props.__scopeTooltip\n );\n const ref = React.useRef<TooltipContentHoverableElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const [pointerGraceArea, setPointerGraceArea] =\n React.useState<Polygon | null>(null);\n\n const { trigger, onClose } = context;\n const content = ref.current;\n\n const { onPointerInTransitChange } = providerContext;\n\n const handleRemoveGraceArea = React.useCallback(() => {\n setPointerGraceArea(null);\n onPointerInTransitChange(false);\n }, [onPointerInTransitChange]);\n\n const handleCreateGraceArea = React.useCallback(\n (event: PointerEvent, hoverTarget: HTMLElement) => {\n const currentTarget = event.currentTarget as HTMLElement;\n const exitPoint = { x: event.clientX, y: event.clientY };\n const exitSide = getExitSideFromRect(\n exitPoint,\n currentTarget.getBoundingClientRect()\n );\n const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);\n const hoverTargetPoints = getPointsFromRect(\n hoverTarget.getBoundingClientRect()\n );\n const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);\n setPointerGraceArea(graceArea);\n onPointerInTransitChange(true);\n },\n [onPointerInTransitChange]\n );\n\n React.useEffect(() => {\n return () => handleRemoveGraceArea();\n }, [handleRemoveGraceArea]);\n\n React.useEffect(() => {\n if (trigger && content) {\n const handleTriggerLeave = (event: PointerEvent) =>\n handleCreateGraceArea(event, content);\n const handleContentLeave = (event: PointerEvent) =>\n handleCreateGraceArea(event, trigger);\n\n trigger.addEventListener(\"pointerleave\", handleTriggerLeave);\n content.addEventListener(\"pointerleave\", handleContentLeave);\n return () => {\n trigger.removeEventListener(\"pointerleave\", handleTriggerLeave);\n content.removeEventListener(\"pointerleave\", handleContentLeave);\n };\n }\n }, [trigger, content, handleCreateGraceArea, handleRemoveGraceArea]);\n\n React.useEffect(() => {\n if (pointerGraceArea) {\n const handleTrackPointerGrace = (event: PointerEvent) => {\n const target = event.target as HTMLElement;\n const pointerPosition = { x: event.clientX, y: event.clientY };\n const hasEnteredTarget =\n trigger?.contains(target) || content?.contains(target);\n const isPointerOutsideGraceArea = !isPointInPolygon(\n pointerPosition,\n pointerGraceArea\n );\n\n if (hasEnteredTarget) {\n handleRemoveGraceArea();\n } else if (isPointerOutsideGraceArea) {\n handleRemoveGraceArea();\n onClose();\n }\n };\n document.addEventListener(\"pointermove\", handleTrackPointerGrace);\n return () =>\n document.removeEventListener(\"pointermove\", handleTrackPointerGrace);\n }\n }, [trigger, content, pointerGraceArea, onClose, handleRemoveGraceArea]);\n\n return <TooltipContentImpl {...props} ref={composedRefs} />;\n});\n\nexport const [\n VisuallyHiddenContentContextProvider,\n useVisuallyHiddenContentContext,\n] = createTooltipContext(TOOLTIP_NAME, { isInside: false });\n\ntype TooltipContentImplElement = React.ElementRef<\n typeof PopperPrimitive.Content\n>;\ntype DismissableLayerProps = React.ComponentPropsWithoutRef<\n typeof DismissableLayer\n>;\ntype PopperContentProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Content\n>;\ninterface TooltipContentImplProps extends Omit<PopperContentProps, \"onPlaced\"> {\n /**\n * A more descriptive label for accessibility purpose\n */\n \"aria-label\"?: string;\n\n /**\n * Event handler called when the escape key is down.\n * Can be prevented.\n */\n onEscapeKeyDown?: DismissableLayerProps[\"onEscapeKeyDown\"];\n /**\n * Event handler called when the a `pointerdown` event happens outside of the `Tooltip`.\n * Can be prevented.\n */\n onPointerDownOutside?: DismissableLayerProps[\"onPointerDownOutside\"];\n}\n\nconst TooltipContentImpl = React.forwardRef<\n TooltipContentImplElement,\n TooltipContentImplProps\n>((props: ScopedProps<TooltipContentImplProps>, forwardedRef) => {\n const {\n __scopeTooltip,\n children,\n \"aria-label\": ariaLabel,\n onEscapeKeyDown,\n onPointerDownOutside,\n ...contentProps\n } = props;\n const context = useTooltipContext(CONTENT_NAME, __scopeTooltip);\n const popperScope = usePopperScope(__scopeTooltip);\n const { onClose } = context;\n\n // Close this tooltip if another one opens\n React.useEffect(() => {\n document.addEventListener(TOOLTIP_OPEN, onClose);\n return () => document.removeEventListener(TOOLTIP_OPEN, onClose);\n }, [onClose]);\n\n // Close the tooltip if the trigger is scrolled\n React.useEffect(() => {\n if (context.trigger) {\n const handleScroll = (event: Event) => {\n const target = event.target as HTMLElement;\n if (target?.contains(context.trigger)) onClose();\n };\n window.addEventListener(\"scroll\", handleScroll, { capture: true });\n return () =>\n window.removeEventListener(\"scroll\", handleScroll, { capture: true });\n }\n }, [context.trigger, onClose]);\n\n return (\n <DismissableLayer\n asChild\n disableOutsidePointerEvents={false}\n onEscapeKeyDown={onEscapeKeyDown}\n onPointerDownOutside={onPointerDownOutside}\n onFocusOutside={(event) => event.preventDefault()}\n onDismiss={onClose}\n >\n <PopperPrimitive.Content\n data-state={context.stateAttribute}\n {...popperScope}\n {...contentProps}\n ref={forwardedRef}\n style={{\n ...contentProps.style,\n // re-namespace exposed content custom properties\n ...{\n \"--huin-core-tooltip-content-transform-origin\":\n \"var(--huin-core-popper-transform-origin)\",\n \"--huin-core-tooltip-content-available-width\":\n \"var(--huin-core-popper-available-width)\",\n \"--huin-core-tooltip-content-available-height\":\n \"var(--huin-core-popper-available-height)\",\n \"--huin-core-tooltip-trigger-width\": \"var(--huin-core-popper-anchor-width)\",\n \"--huin-core-tooltip-trigger-height\":\n \"var(--huin-core-popper-anchor-height)\",\n },\n }}\n >\n <Slottable>{children}</Slottable>\n <VisuallyHiddenContentContextProvider\n scope={__scopeTooltip}\n isInside={true}\n >\n <VisuallyHiddenPrimitive.Root id={context.contentId} role=\"tooltip\">\n {ariaLabel || children}\n </VisuallyHiddenPrimitive.Root>\n </VisuallyHiddenContentContextProvider>\n </PopperPrimitive.Content>\n </DismissableLayer>\n );\n});\n\nTooltipContent.displayName = CONTENT_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype Side = NonNullable<TooltipContentProps[\"side\"]>;\n\nfunction getExitSideFromRect(point: Point, rect: DOMRect): Side {\n const top = Math.abs(rect.top - point.y);\n const bottom = Math.abs(rect.bottom - point.y);\n const right = Math.abs(rect.right - point.x);\n const left = Math.abs(rect.left - point.x);\n\n switch (Math.min(top, bottom, right, left)) {\n case left:\n return \"left\";\n case right:\n return \"right\";\n case top:\n return \"top\";\n case bottom:\n return \"bottom\";\n default:\n throw new Error(\"unreachable\");\n }\n}\n\nfunction getPaddedExitPoints(exitPoint: Point, exitSide: Side, padding = 5) {\n const paddedExitPoints: Point[] = [];\n switch (exitSide) {\n case \"top\":\n paddedExitPoints.push(\n { x: exitPoint.x - padding, y: exitPoint.y + padding },\n { x: exitPoint.x + padding, y: exitPoint.y + padding }\n );\n break;\n case \"bottom\":\n paddedExitPoints.push(\n { x: exitPoint.x - padding, y: exitPoint.y - padding },\n { x: exitPoint.x + padding, y: exitPoint.y - padding }\n );\n break;\n case \"left\":\n paddedExitPoints.push(\n { x: exitPoint.x + padding, y: exitPoint.y - padding },\n { x: exitPoint.x + padding, y: exitPoint.y + padding }\n );\n break;\n case \"right\":\n paddedExitPoints.push(\n { x: exitPoint.x - padding, y: exitPoint.y - padding },\n { x: exitPoint.x - padding, y: exitPoint.y + padding }\n );\n break;\n }\n return paddedExitPoints;\n}\n\nfunction getPointsFromRect(rect: DOMRect) {\n const { top, right, bottom, left } = rect;\n return [\n { x: left, y: top },\n { x: right, y: top },\n { x: right, y: bottom },\n { x: left, y: bottom },\n ];\n}\n\n// Determine if a point is inside of a polygon.\n// Based on https://github.com/substack/point-in-polygon\nfunction isPointInPolygon(point: Point, polygon: Polygon) {\n const { x, y } = point;\n let inside = false;\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x;\n const yi = polygon[i].y;\n const xj = polygon[j].x;\n const yj = polygon[j].y;\n\n // prettier-ignore\n const intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);\n if (intersect) inside = !inside;\n }\n\n return inside;\n}\n\n// Returns a new array of points representing the convex hull of the given set of points.\n// https://www.nayuki.io/page/convex-hull-algorithm\nfunction getHull<P extends Point>(points: Readonly<Array<P>>): Array<P> {\n const newPoints: Array<P> = points.slice();\n newPoints.sort((a: Point, b: Point) => {\n if (a.x < b.x) return -1;\n else if (a.x > b.x) return +1;\n else if (a.y < b.y) return -1;\n else if (a.y > b.y) return +1;\n else return 0;\n });\n return getHullPresorted(newPoints);\n}\n\n// Returns the convex hull, assuming that each points[i] <= points[i + 1]. Runs in O(n) time.\nfunction getHullPresorted<P extends Point>(\n points: Readonly<Array<P>>\n): Array<P> {\n if (points.length <= 1) return points.slice();\n\n const upperHull: Array<P> = [];\n for (let i = 0; i < points.length; i++) {\n const p = points[i];\n while (upperHull.length >= 2) {\n const q = upperHull[upperHull.length - 1];\n const r = upperHull[upperHull.length - 2];\n if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))\n upperHull.pop();\n else break;\n }\n upperHull.push(p);\n }\n upperHull.pop();\n\n const lowerHull: Array<P> = [];\n for (let i = points.length - 1; i >= 0; i--) {\n const p = points[i];\n while (lowerHull.length >= 2) {\n const q = lowerHull[lowerHull.length - 1];\n const r = lowerHull[lowerHull.length - 2];\n if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))\n lowerHull.pop();\n else break;\n }\n lowerHull.push(p);\n }\n lowerHull.pop();\n\n if (\n upperHull.length === 1 &&\n lowerHull.length === 1 &&\n upperHull[0].x === lowerHull[0].x &&\n upperHull[0].y === lowerHull[0].y\n ) {\n return upperHull;\n } else {\n return upperHull.concat(lowerHull);\n }\n}\n\nexport { TooltipContent };\nexport type { TooltipContentProps };\n", "import React from \"react\";\nimport { Primitive } from \"@huin-core/react-primitive\";\nimport * as PopperPrimitive from \"@huin-core/react-popper\";\nimport { ScopedProps, usePopperScope, useTooltipContext } from \"./Tooltip\";\nimport { useTooltipProviderContext } from \"./TooltipProvider\";\nimport { useComposedRefs } from \"@huin-core/react-compose-refs\";\nimport { composeEventHandlers } from \"@huin-core/primitive\";\n\nconst TRIGGER_NAME = \"TooltipTrigger\";\n\nexport type TooltipTriggerElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = React.ComponentPropsWithoutRef<\n typeof Primitive.button\n>;\ninterface TooltipTriggerProps extends PrimitiveButtonProps {}\n\nconst TooltipTrigger = React.forwardRef<\n TooltipTriggerElement,\n TooltipTriggerProps\n>((props: ScopedProps<TooltipTriggerProps>, forwardedRef) => {\n const { __scopeTooltip, ...triggerProps } = props;\n const context = useTooltipContext(TRIGGER_NAME, __scopeTooltip);\n const providerContext = useTooltipProviderContext(\n TRIGGER_NAME,\n __scopeTooltip\n );\n const popperScope = usePopperScope(__scopeTooltip);\n const ref = React.useRef<TooltipTriggerElement>(null);\n const composedRefs = useComposedRefs(\n forwardedRef,\n ref,\n context.onTriggerChange\n );\n const isPointerDownRef = React.useRef(false);\n const hasPointerMoveOpenedRef = React.useRef(false);\n const handlePointerUp = React.useCallback(\n () => (isPointerDownRef.current = false),\n []\n );\n\n React.useEffect(() => {\n return () => document.removeEventListener(\"pointerup\", handlePointerUp);\n }, [handlePointerUp]);\n\n return (\n <PopperPrimitive.Anchor asChild {...popperScope}>\n <Primitive.button\n // We purposefully avoid adding `type=button` here because tooltip triggers are also\n // commonly anchors and the anchor `type` attribute signifies MIME type.\n aria-describedby={context.open ? context.contentId : undefined}\n data-state={context.stateAttribute}\n {...triggerProps}\n ref={composedRefs}\n onPointerMove={composeEventHandlers(props.onPointerMove, (event) => {\n if (event.pointerType === \"touch\") return;\n if (\n !hasPointerMoveOpenedRef.current &&\n !providerContext.isPointerInTransitRef.current\n ) {\n context.onTriggerEnter();\n hasPointerMoveOpenedRef.current = true;\n }\n })}\n onPointerLeave={composeEventHandlers(props.onPointerLeave, () => {\n context.onTriggerLeave();\n hasPointerMoveOpenedRef.current = false;\n })}\n onPointerDown={composeEventHandlers(props.onPointerDown, () => {\n isPointerDownRef.current = true;\n document.addEventListener(\"pointerup\", handlePointerUp, {\n once: true,\n });\n })}\n onFocus={composeEventHandlers(props.onFocus, () => {\n if (!isPointerDownRef.current) context.onOpen();\n })}\n onBlur={composeEventHandlers(props.onBlur, context.onClose)}\n onClick={composeEventHandlers(props.onClick, context.onClose)}\n />\n </PopperPrimitive.Anchor>\n );\n});\n\nTooltipTrigger.displayName = TRIGGER_NAME;\n\nexport { TooltipTrigger };\nexport type { TooltipTriggerProps };\n", "import * as PopperPrimitive from \"@huin-core/react-popper\";\nimport React from \"react\";\nimport { ScopedProps, usePopperScope } from \"./Tooltip\";\nimport { useVisuallyHiddenContentContext } from \"./TooltipContent\";\n\nconst ARROW_NAME = \"TooltipArrow\";\n\ntype TooltipArrowElement = React.ElementRef<typeof PopperPrimitive.Arrow>;\ntype PopperArrowProps = React.ComponentPropsWithoutRef<\n typeof PopperPrimitive.Arrow\n>;\ninterface TooltipArrowProps extends PopperArrowProps {}\n\nconst TooltipArrow = React.forwardRef<TooltipArrowElement, TooltipArrowProps>(\n (props: ScopedProps<TooltipArrowProps>, forwardedRef) => {\n const { __scopeTooltip, ...arrowProps } = props;\n const popperScope = usePopperScope(__scopeTooltip);\n const visuallyHiddenContentContext = useVisuallyHiddenContentContext(\n ARROW_NAME,\n __scopeTooltip\n );\n // if the arrow is inside the `VisuallyHidden`, we don't want to render it all to\n // prevent issues in positioning the arrow due to the duplicate\n return visuallyHiddenContentContext.isInside ? null : (\n <PopperPrimitive.Arrow\n {...popperScope}\n {...arrowProps}\n ref={forwardedRef}\n />\n );\n }\n);\n\nTooltipArrow.displayName = ARROW_NAME;\n\nexport { TooltipArrow };\nexport type { TooltipArrowProps };\n"],
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,cAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAC,SAAuB;AACvB,2BAAmC;AACnC,sBAAsB;AACtB,sBAAiC;AACjC,0BAAkC;AAClC,0CAAqC;;;ACLrC,mBAAkB;AA0Dd;AAvDJ,IAAM,gBAAgB;AACtB,IAAM,yBAAyB;AAYxB,IAAM,CAAC,gCAAgC,yBAAyB,IACrE,qBAAkD,aAAa;AAqBjE,IAAM,kBAAkD,CACtD,UACG;AACH,QAAM;AAAA,IACJ;AAAA,IACA,gBAAgB;AAAA,IAChB,oBAAoB;AAAA,IACpB,0BAA0B;AAAA,IAC1B;AAAA,EACF,IAAI;AACJ,QAAM,CAAC,eAAe,gBAAgB,IAAI,aAAAC,QAAM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AACF;AAEA,aAAa,cAAc;",
|
6
|
+
"names": ["Root", "React", "React", "import_jsx_runtime", "open", "Root", "import_jsx_runtime", "PortalPrimitive", "import_react", "import_react_presence", "PopperPrimitive", "import_jsx_runtime", "React", "import_react", "PopperPrimitive", "import_react_compose_refs", "import_jsx_runtime", "React", "PopperPrimitive", "import_react", "import_jsx_runtime", "React"]
|
7
|
+
}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,547 @@
|
|
1
|
+
"use client";
|
2
|
+
|
3
|
+
// packages/react/tooltip/src/Tooltip.tsx
|
4
|
+
import * as React2 from "react";
|
5
|
+
import { createContextScope } from "@huin-core/react-context";
|
6
|
+
import { useId } from "@huin-core/react-id";
|
7
|
+
import * as PopperPrimitive from "@huin-core/react-popper";
|
8
|
+
import { createPopperScope } from "@huin-core/react-popper";
|
9
|
+
import { useControllableState } from "@huin-core/react-use-controllable-state";
|
10
|
+
|
11
|
+
// packages/react/tooltip/src/TooltipProvider.tsx
|
12
|
+
import React from "react";
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
14
|
+
var PROVIDER_NAME = "TooltipProvider";
|
15
|
+
var DEFAULT_DELAY_DURATION = 700;
|
16
|
+
var [TooltipProviderContextProvider, useTooltipProviderContext] = createTooltipContext(PROVIDER_NAME);
|
17
|
+
var TooltipProvider = (props) => {
|
18
|
+
const {
|
19
|
+
__scopeTooltip,
|
20
|
+
delayDuration = DEFAULT_DELAY_DURATION,
|
21
|
+
skipDelayDuration = 300,
|
22
|
+
disableHoverableContent = false,
|
23
|
+
children
|
24
|
+
} = props;
|
25
|
+
const [isOpenDelayed, setIsOpenDelayed] = React.useState(true);
|
26
|
+
const isPointerInTransitRef = React.useRef(false);
|
27
|
+
const skipDelayTimerRef = React.useRef(0);
|
28
|
+
React.useEffect(() => {
|
29
|
+
const skipDelayTimer = skipDelayTimerRef.current;
|
30
|
+
return () => window.clearTimeout(skipDelayTimer);
|
31
|
+
}, []);
|
32
|
+
return /* @__PURE__ */ jsx(
|
33
|
+
TooltipProviderContextProvider,
|
34
|
+
{
|
35
|
+
scope: __scopeTooltip,
|
36
|
+
isOpenDelayed,
|
37
|
+
delayDuration,
|
38
|
+
onOpen: React.useCallback(() => {
|
39
|
+
window.clearTimeout(skipDelayTimerRef.current);
|
40
|
+
setIsOpenDelayed(false);
|
41
|
+
}, []),
|
42
|
+
onClose: React.useCallback(() => {
|
43
|
+
window.clearTimeout(skipDelayTimerRef.current);
|
44
|
+
skipDelayTimerRef.current = window.setTimeout(
|
45
|
+
() => setIsOpenDelayed(true),
|
46
|
+
skipDelayDuration
|
47
|
+
);
|
48
|
+
}, [skipDelayDuration]),
|
49
|
+
isPointerInTransitRef,
|
50
|
+
onPointerInTransitChange: React.useCallback((inTransit) => {
|
51
|
+
isPointerInTransitRef.current = inTransit;
|
52
|
+
}, []),
|
53
|
+
disableHoverableContent,
|
54
|
+
children
|
55
|
+
}
|
56
|
+
);
|
57
|
+
};
|
58
|
+
TooltipProvider.displayName = PROVIDER_NAME;
|
59
|
+
|
60
|
+
// packages/react/tooltip/src/Tooltip.tsx
|
61
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
62
|
+
var [createTooltipContext, createTooltipScope] = createContextScope(
|
63
|
+
"Tooltip",
|
64
|
+
[createPopperScope]
|
65
|
+
);
|
66
|
+
var usePopperScope = createPopperScope();
|
67
|
+
var TOOLTIP_OPEN = "tooltip.open";
|
68
|
+
var TOOLTIP_NAME = "Tooltip";
|
69
|
+
var [TooltipContextProvider, useTooltipContext] = createTooltipContext(TOOLTIP_NAME);
|
70
|
+
var Tooltip = (props) => {
|
71
|
+
const {
|
72
|
+
__scopeTooltip,
|
73
|
+
children,
|
74
|
+
open: openProp,
|
75
|
+
defaultOpen = false,
|
76
|
+
onOpenChange,
|
77
|
+
disableHoverableContent: disableHoverableContentProp,
|
78
|
+
delayDuration: delayDurationProp
|
79
|
+
} = props;
|
80
|
+
const providerContext = useTooltipProviderContext(
|
81
|
+
TOOLTIP_NAME,
|
82
|
+
props.__scopeTooltip
|
83
|
+
);
|
84
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
85
|
+
const [trigger, setTrigger] = React2.useState(null);
|
86
|
+
const contentId = useId();
|
87
|
+
const openTimerRef = React2.useRef(0);
|
88
|
+
const disableHoverableContent = disableHoverableContentProp ?? providerContext.disableHoverableContent;
|
89
|
+
const delayDuration = delayDurationProp ?? providerContext.delayDuration;
|
90
|
+
const wasOpenDelayedRef = React2.useRef(false);
|
91
|
+
const [open = false, setOpen] = useControllableState({
|
92
|
+
prop: openProp,
|
93
|
+
defaultProp: defaultOpen,
|
94
|
+
onChange: (open2) => {
|
95
|
+
if (open2) {
|
96
|
+
providerContext.onOpen();
|
97
|
+
document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN));
|
98
|
+
} else {
|
99
|
+
providerContext.onClose();
|
100
|
+
}
|
101
|
+
onOpenChange?.(open2);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
const stateAttribute = React2.useMemo(() => {
|
105
|
+
return open ? wasOpenDelayedRef.current ? "delayed-open" : "instant-open" : "closed";
|
106
|
+
}, [open]);
|
107
|
+
const handleOpen = React2.useCallback(() => {
|
108
|
+
window.clearTimeout(openTimerRef.current);
|
109
|
+
wasOpenDelayedRef.current = false;
|
110
|
+
setOpen(true);
|
111
|
+
}, [setOpen]);
|
112
|
+
const handleClose = React2.useCallback(() => {
|
113
|
+
window.clearTimeout(openTimerRef.current);
|
114
|
+
setOpen(false);
|
115
|
+
}, [setOpen]);
|
116
|
+
const handleDelayedOpen = React2.useCallback(() => {
|
117
|
+
window.clearTimeout(openTimerRef.current);
|
118
|
+
openTimerRef.current = window.setTimeout(() => {
|
119
|
+
wasOpenDelayedRef.current = true;
|
120
|
+
setOpen(true);
|
121
|
+
}, delayDuration);
|
122
|
+
}, [delayDuration, setOpen]);
|
123
|
+
React2.useEffect(() => {
|
124
|
+
return () => window.clearTimeout(openTimerRef.current);
|
125
|
+
}, []);
|
126
|
+
return /* @__PURE__ */ jsx2(PopperPrimitive.Root, { ...popperScope, children: /* @__PURE__ */ jsx2(
|
127
|
+
TooltipContextProvider,
|
128
|
+
{
|
129
|
+
scope: __scopeTooltip,
|
130
|
+
contentId,
|
131
|
+
open,
|
132
|
+
stateAttribute,
|
133
|
+
trigger,
|
134
|
+
onTriggerChange: setTrigger,
|
135
|
+
onTriggerEnter: React2.useCallback(() => {
|
136
|
+
if (providerContext.isOpenDelayed) handleDelayedOpen();
|
137
|
+
else handleOpen();
|
138
|
+
}, [providerContext.isOpenDelayed, handleDelayedOpen, handleOpen]),
|
139
|
+
onTriggerLeave: React2.useCallback(() => {
|
140
|
+
if (disableHoverableContent) {
|
141
|
+
handleClose();
|
142
|
+
} else {
|
143
|
+
window.clearTimeout(openTimerRef.current);
|
144
|
+
}
|
145
|
+
}, [handleClose, disableHoverableContent]),
|
146
|
+
onOpen: handleOpen,
|
147
|
+
onClose: handleClose,
|
148
|
+
disableHoverableContent,
|
149
|
+
children
|
150
|
+
}
|
151
|
+
) });
|
152
|
+
};
|
153
|
+
Tooltip.displayName = TOOLTIP_NAME;
|
154
|
+
var Root2 = Tooltip;
|
155
|
+
|
156
|
+
// packages/react/tooltip/src/TooltipPortal.tsx
|
157
|
+
import { Presence } from "@huin-core/react-presence";
|
158
|
+
import { Portal as PortalPrimitive } from "@huin-core/react-portal";
|
159
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
160
|
+
var PORTAL_NAME = "TooltipPortal";
|
161
|
+
var [PortalProvider, usePortalContext] = createTooltipContext(PORTAL_NAME, {
|
162
|
+
forceMount: void 0
|
163
|
+
});
|
164
|
+
var TooltipPortal = (props) => {
|
165
|
+
const { __scopeTooltip, forceMount, children, container } = props;
|
166
|
+
const context = useTooltipContext(PORTAL_NAME, __scopeTooltip);
|
167
|
+
return /* @__PURE__ */ jsx3(PortalProvider, { scope: __scopeTooltip, forceMount, children: /* @__PURE__ */ jsx3(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx3(PortalPrimitive, { asChild: true, container, children }) }) });
|
168
|
+
};
|
169
|
+
TooltipPortal.displayName = PORTAL_NAME;
|
170
|
+
|
171
|
+
// packages/react/tooltip/src/TooltipContent.tsx
|
172
|
+
import React3 from "react";
|
173
|
+
import { Presence as Presence2 } from "@huin-core/react-presence";
|
174
|
+
import { useComposedRefs } from "@huin-core/react-compose-refs";
|
175
|
+
import { Slottable } from "@huin-core/react-slot";
|
176
|
+
import * as VisuallyHiddenPrimitive from "@huin-core/react-visually-hidden";
|
177
|
+
import * as PopperPrimitive2 from "@huin-core/react-popper";
|
178
|
+
import { DismissableLayer } from "@huin-core/react-dismissable-layer";
|
179
|
+
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
180
|
+
var CONTENT_NAME = "TooltipContent";
|
181
|
+
var TooltipContent = React3.forwardRef((props, forwardedRef) => {
|
182
|
+
const portalContext = usePortalContext(CONTENT_NAME, props.__scopeTooltip);
|
183
|
+
const { forceMount = portalContext.forceMount, side = "top", ...contentProps } = props;
|
184
|
+
const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);
|
185
|
+
return /* @__PURE__ */ jsx4(Presence2, { present: forceMount || context.open, children: context.disableHoverableContent ? /* @__PURE__ */ jsx4(TooltipContentImpl, { side, ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx4(TooltipContentHoverable, { side, ...contentProps, ref: forwardedRef }) });
|
186
|
+
});
|
187
|
+
var TooltipContentHoverable = React3.forwardRef((props, forwardedRef) => {
|
188
|
+
const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);
|
189
|
+
const providerContext = useTooltipProviderContext(
|
190
|
+
CONTENT_NAME,
|
191
|
+
props.__scopeTooltip
|
192
|
+
);
|
193
|
+
const ref = React3.useRef(null);
|
194
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
195
|
+
const [pointerGraceArea, setPointerGraceArea] = React3.useState(null);
|
196
|
+
const { trigger, onClose } = context;
|
197
|
+
const content = ref.current;
|
198
|
+
const { onPointerInTransitChange } = providerContext;
|
199
|
+
const handleRemoveGraceArea = React3.useCallback(() => {
|
200
|
+
setPointerGraceArea(null);
|
201
|
+
onPointerInTransitChange(false);
|
202
|
+
}, [onPointerInTransitChange]);
|
203
|
+
const handleCreateGraceArea = React3.useCallback(
|
204
|
+
(event, hoverTarget) => {
|
205
|
+
const currentTarget = event.currentTarget;
|
206
|
+
const exitPoint = { x: event.clientX, y: event.clientY };
|
207
|
+
const exitSide = getExitSideFromRect(
|
208
|
+
exitPoint,
|
209
|
+
currentTarget.getBoundingClientRect()
|
210
|
+
);
|
211
|
+
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
|
212
|
+
const hoverTargetPoints = getPointsFromRect(
|
213
|
+
hoverTarget.getBoundingClientRect()
|
214
|
+
);
|
215
|
+
const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
|
216
|
+
setPointerGraceArea(graceArea);
|
217
|
+
onPointerInTransitChange(true);
|
218
|
+
},
|
219
|
+
[onPointerInTransitChange]
|
220
|
+
);
|
221
|
+
React3.useEffect(() => {
|
222
|
+
return () => handleRemoveGraceArea();
|
223
|
+
}, [handleRemoveGraceArea]);
|
224
|
+
React3.useEffect(() => {
|
225
|
+
if (trigger && content) {
|
226
|
+
const handleTriggerLeave = (event) => handleCreateGraceArea(event, content);
|
227
|
+
const handleContentLeave = (event) => handleCreateGraceArea(event, trigger);
|
228
|
+
trigger.addEventListener("pointerleave", handleTriggerLeave);
|
229
|
+
content.addEventListener("pointerleave", handleContentLeave);
|
230
|
+
return () => {
|
231
|
+
trigger.removeEventListener("pointerleave", handleTriggerLeave);
|
232
|
+
content.removeEventListener("pointerleave", handleContentLeave);
|
233
|
+
};
|
234
|
+
}
|
235
|
+
}, [trigger, content, handleCreateGraceArea, handleRemoveGraceArea]);
|
236
|
+
React3.useEffect(() => {
|
237
|
+
if (pointerGraceArea) {
|
238
|
+
const handleTrackPointerGrace = (event) => {
|
239
|
+
const target = event.target;
|
240
|
+
const pointerPosition = { x: event.clientX, y: event.clientY };
|
241
|
+
const hasEnteredTarget = trigger?.contains(target) || content?.contains(target);
|
242
|
+
const isPointerOutsideGraceArea = !isPointInPolygon(
|
243
|
+
pointerPosition,
|
244
|
+
pointerGraceArea
|
245
|
+
);
|
246
|
+
if (hasEnteredTarget) {
|
247
|
+
handleRemoveGraceArea();
|
248
|
+
} else if (isPointerOutsideGraceArea) {
|
249
|
+
handleRemoveGraceArea();
|
250
|
+
onClose();
|
251
|
+
}
|
252
|
+
};
|
253
|
+
document.addEventListener("pointermove", handleTrackPointerGrace);
|
254
|
+
return () => document.removeEventListener("pointermove", handleTrackPointerGrace);
|
255
|
+
}
|
256
|
+
}, [trigger, content, pointerGraceArea, onClose, handleRemoveGraceArea]);
|
257
|
+
return /* @__PURE__ */ jsx4(TooltipContentImpl, { ...props, ref: composedRefs });
|
258
|
+
});
|
259
|
+
var [
|
260
|
+
VisuallyHiddenContentContextProvider,
|
261
|
+
useVisuallyHiddenContentContext
|
262
|
+
] = createTooltipContext(TOOLTIP_NAME, { isInside: false });
|
263
|
+
var TooltipContentImpl = React3.forwardRef((props, forwardedRef) => {
|
264
|
+
const {
|
265
|
+
__scopeTooltip,
|
266
|
+
children,
|
267
|
+
"aria-label": ariaLabel,
|
268
|
+
onEscapeKeyDown,
|
269
|
+
onPointerDownOutside,
|
270
|
+
...contentProps
|
271
|
+
} = props;
|
272
|
+
const context = useTooltipContext(CONTENT_NAME, __scopeTooltip);
|
273
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
274
|
+
const { onClose } = context;
|
275
|
+
React3.useEffect(() => {
|
276
|
+
document.addEventListener(TOOLTIP_OPEN, onClose);
|
277
|
+
return () => document.removeEventListener(TOOLTIP_OPEN, onClose);
|
278
|
+
}, [onClose]);
|
279
|
+
React3.useEffect(() => {
|
280
|
+
if (context.trigger) {
|
281
|
+
const handleScroll = (event) => {
|
282
|
+
const target = event.target;
|
283
|
+
if (target?.contains(context.trigger)) onClose();
|
284
|
+
};
|
285
|
+
window.addEventListener("scroll", handleScroll, { capture: true });
|
286
|
+
return () => window.removeEventListener("scroll", handleScroll, { capture: true });
|
287
|
+
}
|
288
|
+
}, [context.trigger, onClose]);
|
289
|
+
return /* @__PURE__ */ jsx4(
|
290
|
+
DismissableLayer,
|
291
|
+
{
|
292
|
+
asChild: true,
|
293
|
+
disableOutsidePointerEvents: false,
|
294
|
+
onEscapeKeyDown,
|
295
|
+
onPointerDownOutside,
|
296
|
+
onFocusOutside: (event) => event.preventDefault(),
|
297
|
+
onDismiss: onClose,
|
298
|
+
children: /* @__PURE__ */ jsxs(
|
299
|
+
PopperPrimitive2.Content,
|
300
|
+
{
|
301
|
+
"data-state": context.stateAttribute,
|
302
|
+
...popperScope,
|
303
|
+
...contentProps,
|
304
|
+
ref: forwardedRef,
|
305
|
+
style: {
|
306
|
+
...contentProps.style,
|
307
|
+
// re-namespace exposed content custom properties
|
308
|
+
...{
|
309
|
+
"--huin-core-tooltip-content-transform-origin": "var(--huin-core-popper-transform-origin)",
|
310
|
+
"--huin-core-tooltip-content-available-width": "var(--huin-core-popper-available-width)",
|
311
|
+
"--huin-core-tooltip-content-available-height": "var(--huin-core-popper-available-height)",
|
312
|
+
"--huin-core-tooltip-trigger-width": "var(--huin-core-popper-anchor-width)",
|
313
|
+
"--huin-core-tooltip-trigger-height": "var(--huin-core-popper-anchor-height)"
|
314
|
+
}
|
315
|
+
},
|
316
|
+
children: [
|
317
|
+
/* @__PURE__ */ jsx4(Slottable, { children }),
|
318
|
+
/* @__PURE__ */ jsx4(
|
319
|
+
VisuallyHiddenContentContextProvider,
|
320
|
+
{
|
321
|
+
scope: __scopeTooltip,
|
322
|
+
isInside: true,
|
323
|
+
children: /* @__PURE__ */ jsx4(VisuallyHiddenPrimitive.Root, { id: context.contentId, role: "tooltip", children: ariaLabel || children })
|
324
|
+
}
|
325
|
+
)
|
326
|
+
]
|
327
|
+
}
|
328
|
+
)
|
329
|
+
}
|
330
|
+
);
|
331
|
+
});
|
332
|
+
TooltipContent.displayName = CONTENT_NAME;
|
333
|
+
function getExitSideFromRect(point, rect) {
|
334
|
+
const top = Math.abs(rect.top - point.y);
|
335
|
+
const bottom = Math.abs(rect.bottom - point.y);
|
336
|
+
const right = Math.abs(rect.right - point.x);
|
337
|
+
const left = Math.abs(rect.left - point.x);
|
338
|
+
switch (Math.min(top, bottom, right, left)) {
|
339
|
+
case left:
|
340
|
+
return "left";
|
341
|
+
case right:
|
342
|
+
return "right";
|
343
|
+
case top:
|
344
|
+
return "top";
|
345
|
+
case bottom:
|
346
|
+
return "bottom";
|
347
|
+
default:
|
348
|
+
throw new Error("unreachable");
|
349
|
+
}
|
350
|
+
}
|
351
|
+
function getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
|
352
|
+
const paddedExitPoints = [];
|
353
|
+
switch (exitSide) {
|
354
|
+
case "top":
|
355
|
+
paddedExitPoints.push(
|
356
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding },
|
357
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
358
|
+
);
|
359
|
+
break;
|
360
|
+
case "bottom":
|
361
|
+
paddedExitPoints.push(
|
362
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
363
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding }
|
364
|
+
);
|
365
|
+
break;
|
366
|
+
case "left":
|
367
|
+
paddedExitPoints.push(
|
368
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding },
|
369
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
370
|
+
);
|
371
|
+
break;
|
372
|
+
case "right":
|
373
|
+
paddedExitPoints.push(
|
374
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
375
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding }
|
376
|
+
);
|
377
|
+
break;
|
378
|
+
}
|
379
|
+
return paddedExitPoints;
|
380
|
+
}
|
381
|
+
function getPointsFromRect(rect) {
|
382
|
+
const { top, right, bottom, left } = rect;
|
383
|
+
return [
|
384
|
+
{ x: left, y: top },
|
385
|
+
{ x: right, y: top },
|
386
|
+
{ x: right, y: bottom },
|
387
|
+
{ x: left, y: bottom }
|
388
|
+
];
|
389
|
+
}
|
390
|
+
function isPointInPolygon(point, polygon) {
|
391
|
+
const { x, y } = point;
|
392
|
+
let inside = false;
|
393
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
394
|
+
const xi = polygon[i].x;
|
395
|
+
const yi = polygon[i].y;
|
396
|
+
const xj = polygon[j].x;
|
397
|
+
const yj = polygon[j].y;
|
398
|
+
const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
|
399
|
+
if (intersect) inside = !inside;
|
400
|
+
}
|
401
|
+
return inside;
|
402
|
+
}
|
403
|
+
function getHull(points) {
|
404
|
+
const newPoints = points.slice();
|
405
|
+
newPoints.sort((a, b) => {
|
406
|
+
if (a.x < b.x) return -1;
|
407
|
+
else if (a.x > b.x) return 1;
|
408
|
+
else if (a.y < b.y) return -1;
|
409
|
+
else if (a.y > b.y) return 1;
|
410
|
+
else return 0;
|
411
|
+
});
|
412
|
+
return getHullPresorted(newPoints);
|
413
|
+
}
|
414
|
+
function getHullPresorted(points) {
|
415
|
+
if (points.length <= 1) return points.slice();
|
416
|
+
const upperHull = [];
|
417
|
+
for (let i = 0; i < points.length; i++) {
|
418
|
+
const p = points[i];
|
419
|
+
while (upperHull.length >= 2) {
|
420
|
+
const q = upperHull[upperHull.length - 1];
|
421
|
+
const r = upperHull[upperHull.length - 2];
|
422
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
423
|
+
upperHull.pop();
|
424
|
+
else break;
|
425
|
+
}
|
426
|
+
upperHull.push(p);
|
427
|
+
}
|
428
|
+
upperHull.pop();
|
429
|
+
const lowerHull = [];
|
430
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
431
|
+
const p = points[i];
|
432
|
+
while (lowerHull.length >= 2) {
|
433
|
+
const q = lowerHull[lowerHull.length - 1];
|
434
|
+
const r = lowerHull[lowerHull.length - 2];
|
435
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
436
|
+
lowerHull.pop();
|
437
|
+
else break;
|
438
|
+
}
|
439
|
+
lowerHull.push(p);
|
440
|
+
}
|
441
|
+
lowerHull.pop();
|
442
|
+
if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y) {
|
443
|
+
return upperHull;
|
444
|
+
} else {
|
445
|
+
return upperHull.concat(lowerHull);
|
446
|
+
}
|
447
|
+
}
|
448
|
+
|
449
|
+
// packages/react/tooltip/src/TooltipTrigger.tsx
|
450
|
+
import React4 from "react";
|
451
|
+
import { Primitive } from "@huin-core/react-primitive";
|
452
|
+
import * as PopperPrimitive3 from "@huin-core/react-popper";
|
453
|
+
import { useComposedRefs as useComposedRefs2 } from "@huin-core/react-compose-refs";
|
454
|
+
import { composeEventHandlers } from "@huin-core/primitive";
|
455
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
456
|
+
var TRIGGER_NAME = "TooltipTrigger";
|
457
|
+
var TooltipTrigger = React4.forwardRef((props, forwardedRef) => {
|
458
|
+
const { __scopeTooltip, ...triggerProps } = props;
|
459
|
+
const context = useTooltipContext(TRIGGER_NAME, __scopeTooltip);
|
460
|
+
const providerContext = useTooltipProviderContext(
|
461
|
+
TRIGGER_NAME,
|
462
|
+
__scopeTooltip
|
463
|
+
);
|
464
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
465
|
+
const ref = React4.useRef(null);
|
466
|
+
const composedRefs = useComposedRefs2(
|
467
|
+
forwardedRef,
|
468
|
+
ref,
|
469
|
+
context.onTriggerChange
|
470
|
+
);
|
471
|
+
const isPointerDownRef = React4.useRef(false);
|
472
|
+
const hasPointerMoveOpenedRef = React4.useRef(false);
|
473
|
+
const handlePointerUp = React4.useCallback(
|
474
|
+
() => isPointerDownRef.current = false,
|
475
|
+
[]
|
476
|
+
);
|
477
|
+
React4.useEffect(() => {
|
478
|
+
return () => document.removeEventListener("pointerup", handlePointerUp);
|
479
|
+
}, [handlePointerUp]);
|
480
|
+
return /* @__PURE__ */ jsx5(PopperPrimitive3.Anchor, { asChild: true, ...popperScope, children: /* @__PURE__ */ jsx5(
|
481
|
+
Primitive.button,
|
482
|
+
{
|
483
|
+
"aria-describedby": context.open ? context.contentId : void 0,
|
484
|
+
"data-state": context.stateAttribute,
|
485
|
+
...triggerProps,
|
486
|
+
ref: composedRefs,
|
487
|
+
onPointerMove: composeEventHandlers(props.onPointerMove, (event) => {
|
488
|
+
if (event.pointerType === "touch") return;
|
489
|
+
if (!hasPointerMoveOpenedRef.current && !providerContext.isPointerInTransitRef.current) {
|
490
|
+
context.onTriggerEnter();
|
491
|
+
hasPointerMoveOpenedRef.current = true;
|
492
|
+
}
|
493
|
+
}),
|
494
|
+
onPointerLeave: composeEventHandlers(props.onPointerLeave, () => {
|
495
|
+
context.onTriggerLeave();
|
496
|
+
hasPointerMoveOpenedRef.current = false;
|
497
|
+
}),
|
498
|
+
onPointerDown: composeEventHandlers(props.onPointerDown, () => {
|
499
|
+
isPointerDownRef.current = true;
|
500
|
+
document.addEventListener("pointerup", handlePointerUp, {
|
501
|
+
once: true
|
502
|
+
});
|
503
|
+
}),
|
504
|
+
onFocus: composeEventHandlers(props.onFocus, () => {
|
505
|
+
if (!isPointerDownRef.current) context.onOpen();
|
506
|
+
}),
|
507
|
+
onBlur: composeEventHandlers(props.onBlur, context.onClose),
|
508
|
+
onClick: composeEventHandlers(props.onClick, context.onClose)
|
509
|
+
}
|
510
|
+
) });
|
511
|
+
});
|
512
|
+
TooltipTrigger.displayName = TRIGGER_NAME;
|
513
|
+
|
514
|
+
// packages/react/tooltip/src/TooltipArrow.tsx
|
515
|
+
import * as PopperPrimitive4 from "@huin-core/react-popper";
|
516
|
+
import React5 from "react";
|
517
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
518
|
+
var ARROW_NAME = "TooltipArrow";
|
519
|
+
var TooltipArrow = React5.forwardRef(
|
520
|
+
(props, forwardedRef) => {
|
521
|
+
const { __scopeTooltip, ...arrowProps } = props;
|
522
|
+
const popperScope = usePopperScope(__scopeTooltip);
|
523
|
+
const visuallyHiddenContentContext = useVisuallyHiddenContentContext(
|
524
|
+
ARROW_NAME,
|
525
|
+
__scopeTooltip
|
526
|
+
);
|
527
|
+
return visuallyHiddenContentContext.isInside ? null : /* @__PURE__ */ jsx6(
|
528
|
+
PopperPrimitive4.Arrow,
|
529
|
+
{
|
530
|
+
...popperScope,
|
531
|
+
...arrowProps,
|
532
|
+
ref: forwardedRef
|
533
|
+
}
|
534
|
+
);
|
535
|
+
}
|
536
|
+
);
|
537
|
+
TooltipArrow.displayName = ARROW_NAME;
|
538
|
+
export {
|
539
|
+
Root2 as Root,
|
540
|
+
Tooltip,
|
541
|
+
TooltipArrow,
|
542
|
+
TooltipContent,
|
543
|
+
TooltipPortal,
|
544
|
+
TooltipProvider,
|
545
|
+
TooltipTrigger
|
546
|
+
};
|
547
|
+
//# sourceMappingURL=index.mjs.map
|