| 4946 | } |
| 4947 | |
| 4948 | function openContextMenu(x, y) { |
| 4949 | if (!contextMenu) return; |
| 4950 | contextMenu.classList.add("open"); |
| 4951 | contextMenu.setAttribute("aria-hidden", "false"); |
| 4952 | const pad = 8; |
| 4953 | const w = contextMenu.offsetWidth || 200; |
| 4954 | const h = contextMenu.offsetHeight || 220; |
| 4955 | const maxX = window.innerWidth - w - pad; |
| 4956 | const maxY = window.innerHeight - h - pad; |
| 4957 | contextMenu.style.left = clamp(x, pad, maxX) + "px"; |
| 4958 | contextMenu.style.top = clamp(y, pad, maxY) + "px"; |
| 4959 | } |
| 4960 | |
| 4961 | function closeContextMenu() { |
| 4962 | if (!contextMenu) return; |