MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / getPageElementAtPoint

Function getPageElementAtPoint

packages/overlay/src/interaction.ts:157–178  ·  view source on GitHub ↗
(clientX: number, clientY: number)

Source from the content-addressed store, hash-verified

155 * Uses elementsFromPoint to skip the interaction layer, shadow DOM host, and placeholder elements.
156 */
157export function getPageElementAtPoint(clientX: number, clientY: number): HTMLElement | null {
158 // Check cache first — avoids expensive elementsFromPoint on small mouse movements
159 const cached = getCachedElement(clientX, clientY);
160 if (cached !== undefined) return cached;
161
162 const elements = document.elementsFromPoint(clientX, clientY);
163 let result: HTMLElement | null = null;
164
165 for (const el of elements) {
166 if (!(el instanceof HTMLElement)) continue;
167 if (el.closest("#react-rewrite-root")) continue;
168 if (el.hasAttribute("data-react-rewrite-interaction")) continue;
169 if (el.hasAttribute("data-react-rewrite-placeholder")) continue;
170 if (el === document.body || el === document.documentElement) continue;
171 if (isFullPageElement(el)) continue;
172 result = el;
173 break;
174 }
175
176 setCachedElement(clientX, clientY, result);
177 return result;
178}
179
180export function destroyInteraction(): void {
181 document.removeEventListener("scroll", clearElementCache, true);

Callers 4

resolveClickTargetFunction · 0.85
resolveComponentAtPointFunction · 0.85
onMouseDownFunction · 0.85

Calls 3

getCachedElementFunction · 0.85
isFullPageElementFunction · 0.85
setCachedElementFunction · 0.85

Tested by

no test coverage detected