()
| 103 | } |
| 104 | |
| 105 | export function subscribeFocusOpenGuards(): () => void { |
| 106 | const subscribedSession = session |
| 107 | subscribers += 1 |
| 108 | if (!listening && typeof window !== 'undefined') { |
| 109 | listening = true |
| 110 | window.addEventListener('blur', onWindowBlur) |
| 111 | window.addEventListener('focus', onWindowFocus) |
| 112 | // Only Mac Safari reads this, and only when :focus-visible is wrong. |
| 113 | // Other browsers must not pay for a listener on every key and click. |
| 114 | if (isMacSafari()) { |
| 115 | window.addEventListener('keydown', onKeyDown, true) |
| 116 | window.addEventListener('pointerdown', onPointerDown, true) |
| 117 | modalityListening = true |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return () => { |
| 122 | if (subscribedSession !== session) { |
| 123 | return |
| 124 | } |
| 125 | subscribers -= 1 |
| 126 | if (subscribers <= 0) { |
| 127 | subscribers = 0 |
| 128 | detach() |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | export function isWindowRestoredFocus(target: EventTarget | null): boolean { |
| 134 | if (!(target instanceof Node) || restoredFocusElement === null) { |
no test coverage detected