/** * Shadow-DOM-safe `event.target`. * * `event.target` is re-targeted at shadow-root boundaries, so a listener on * a shadow host sees the host as the target rather than the actual * originating node. `composedPath()[0]` returns the true origin. Older * browsers without shadow DOM fall back to `event.target`. */ export function getTarget(event: Event): EventTarget | null { if ("composedPath" in event) { const path = (event as Event).composedPath(); return path[0] ?? (event as Event).target; } return (event as Event).target; }