Download src/utils/viewportTooltip.js from NKessler/Horizon: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/NKessler/Horizon/resolve/main/src/utils/viewportTooltip.js
- Command line
-
hf download hf://NKessler/Horizon/src/utils/viewportTooltip.js
-
curl -L -o viewportTooltip.js https://huggingface.co/NKessler/Horizon/resolve/main/src/utils/viewportTooltip.js
1.06 kB
| /** | |
| * Place a tooltip near (clientX, clientY) without jumping left unless the | |
| * default below-right placement would overflow the viewport. | |
| * | |
| * @param {number} clientX | |
| * @param {number} clientY | |
| * @param {{ estWidth?: number; estHeight?: number; gap?: number; pad?: number }} [opts] | |
| * Pass measured width/height from the tooltip element when possible; defaults | |
| * that are larger than the real box cause early horizontal clamping. | |
| */ | |
| export function viewportTooltipPosition(clientX, clientY, opts = {}) { | |
| const vw = typeof window !== "undefined" ? window.innerWidth : 1200; | |
| const vh = typeof window !== "undefined" ? window.innerHeight : 800; | |
| const W = opts.estWidth ?? 236; | |
| const H = opts.estHeight ?? 92; | |
| const gap = opts.gap ?? 12; | |
| const pad = opts.pad ?? 8; | |
| let left = clientX + gap; | |
| let top = clientY + gap; | |
| if (left + W + pad > vw) { | |
| left = vw - W - pad; | |
| } | |
| if (left < pad) { | |
| left = pad; | |
| } | |
| if (top + H + pad > vh) { | |
| top = vh - H - pad; | |
| } | |
| if (top < pad) { | |
| top = pad; | |
| } | |
| return { left, top }; | |
| } | |