@@ -563,7 +563,9 @@ function startAnnotation( |
563 | 563 | const host = document.createElement("div"); |
564 | 564 | host.setAttribute(OVERLAY_ATTRIBUTE, ""); |
565 | 565 | host.setAttribute("dir", "ltr"); |
566 | | - host.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY};pointer-events:none`; |
| 566 | + host.popover = "manual"; |
| 567 | + // Resets the UA popover box (fit-content size, auto margin, border, padding, Canvas background). |
| 568 | + host.style.cssText = `position:fixed;inset:0;width:auto;height:auto;margin:0;border:0;padding:0;overflow:visible;background:transparent;color:inherit;z-index:${Z_INDEX_OVERLAY};pointer-events:none`; |
567 | 569 | applyAnnotationTheme(host, annotationTheme); |
568 | 570 | const shadowRoot = host.attachShadow({ mode: "closed" }); |
569 | 571 | const themeStyle = document.createElement("style"); |
@@ -577,7 +579,7 @@ function startAnnotation( |
577 | 579 | root.style.cssText = "pointer-events:none"; |
578 | 580 | const cursorStyle = document.createElement("style"); |
579 | 581 | cursorStyle.setAttribute(OVERLAY_ATTRIBUTE, ""); |
580 | | - cursorStyle.textContent = `html[data-t3code-annotation-tool] body, html[data-t3code-annotation-tool] body * { cursor: crosshair !important; } [${OVERLAY_ATTRIBUTE}], [${OVERLAY_ATTRIBUTE}] * { cursor: default !important; } [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-inner-spin-button, [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-outer-spin-button { appearance:none; margin:0; }`; |
| 582 | + cursorStyle.textContent = `[${OVERLAY_ATTRIBUTE}]::backdrop { display:none !important; } html[data-t3code-annotation-tool] body, html[data-t3code-annotation-tool] body * { cursor: crosshair !important; } [${OVERLAY_ATTRIBUTE}], [${OVERLAY_ATTRIBUTE}] * { cursor: default !important; } [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-inner-spin-button, [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-outer-spin-button { appearance:none; margin:0; }`; |
581 | 583 | document.documentElement.appendChild(cursorStyle); |
582 | 584 | shadowRoot.appendChild(root); |
583 | 585 |
|
@@ -1600,6 +1602,38 @@ function startAnnotation( |
1600 | 1602 | event.stopPropagation(); |
1601 | 1603 | }; |
1602 | 1604 |
|
| 1605 | + // Page popovers and modal dialogs sit in the top layer above any z-index, and a modal makes |
| 1606 | + // everything outside it inert, so the overlay is shown last and lives inside the topmost modal. |
| 1607 | + // Modals in the order they opened, since DOM order does not say which one blocks the rest. |
| 1608 | + const openedModals: Element[] = []; |
| 1609 | + const raiseOverlay = (): void => { |
| 1610 | + const focused = shadowRoot.activeElement; |
| 1611 | + const parent = |
| 1612 | + document.activeElement?.closest("dialog:modal") ?? |
| 1613 | + openedModals.findLast((dialog) => dialog.matches(":modal")) ?? |
| 1614 | + Array.from(document.querySelectorAll("dialog:modal")).at(-1) ?? |
| 1615 | + document.documentElement; |
| 1616 | + if (host.parentElement !== parent) parent.appendChild(host); |
| 1617 | + if (host.matches(":popover-open")) host.hidePopover(); |
| 1618 | + host.showPopover(); |
| 1619 | + if (focused instanceof HTMLElement && !focused.matches(":focus")) |
| 1620 | + focused.focus({ preventScroll: true }); |
| 1621 | + }; |
| 1622 | + const onPageToggle = (event: Event): void => { |
| 1623 | + const target = event.target; |
| 1624 | + if (target === host) return; |
| 1625 | + if (target instanceof HTMLDialogElement) { |
| 1626 | + const index = openedModals.indexOf(target); |
| 1627 | + if (index !== -1) openedModals.splice(index, 1); |
| 1628 | + if (target.matches(":modal")) openedModals.push(target); |
| 1629 | + } |
| 1630 | + raiseOverlay(); |
| 1631 | + }; |
| 1632 | + // Removing an open dialog hides the overlay inside it without a toggle event. |
| 1633 | + const detachObserver = new MutationObserver(() => { |
| 1634 | + if (!host.isConnected || !host.matches(":popover-open")) raiseOverlay(); |
| 1635 | + }); |
| 1636 | + |
1603 | 1637 | const onPointerOut = (event: PointerEvent): void => { |
1604 | 1638 | if (event.relatedTarget === null) clearHoverOutline(); |
1605 | 1639 | }; |
@@ -1644,6 +1678,8 @@ function startAnnotation( |
1644 | 1678 | dragHandle.removeEventListener("pointerup", onEditorPointerUp); |
1645 | 1679 | dragHandle.removeEventListener("pointercancel", onEditorPointerUp); |
1646 | 1680 | for (const type of PAGE_ISOLATED_EVENTS) host.removeEventListener(type, stopAtOverlay); |
| 1681 | + window.removeEventListener("toggle", onPageToggle, true); |
| 1682 | + detachObserver.disconnect(); |
1647 | 1683 | document.documentElement.removeEventListener("focusout", onFocusOutToOverlay); |
1648 | 1684 | if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame); |
1649 | 1685 | ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel); |
@@ -1813,7 +1849,9 @@ function startAnnotation( |
1813 | 1849 | document.documentElement.appendChild(inputLayer); |
1814 | 1850 | inputLayer.focus({ preventScroll: true }); |
1815 | 1851 | } |
1816 | | - document.documentElement.appendChild(host); |
| 1852 | + raiseOverlay(); |
| 1853 | + window.addEventListener("toggle", onPageToggle, true); |
| 1854 | + detachObserver.observe(document.documentElement, { childList: true, subtree: true }); |
1817 | 1855 | rootResizeObserver.observe(document.documentElement); |
1818 | 1856 | refreshToolButtons(); |
1819 | 1857 | updateStatus(); |
|