MCPcopy Create free account
hub / github.com/callstack/agent-device / inferViewportRect

Function inferViewportRect

src/core/scroll-gesture.ts:228–245  ·  view source on GitHub ↗
(nodes: Array<Pick<SnapshotNode, 'type' | 'rect'>>)

Source from the content-addressed store, hash-verified

226}
227
228function inferViewportRect(nodes: Array<Pick<SnapshotNode, 'type' | 'rect'>>): Rect | undefined {
229 const candidate = nodes
230 .filter((node) => isViewportNode(node.type) && isValidRect(node.rect))
231 .map((node) => node.rect)
232 .sort(
233 (left, right) =>
234 (right?.width ?? 0) * (right?.height ?? 0) - (left?.width ?? 0) * (left?.height ?? 0),
235 )[0];
236 if (candidate) return candidate;
237
238 const rects = nodes.map((node) => node.rect).filter(isValidRect);
239 if (rects.length === 0) return undefined;
240
241 const width = Math.max(...rects.map((rect) => rect.x + rect.width));
242 const height = Math.max(...rects.map((rect) => rect.y + rect.height));
243 if (width <= 0 || height <= 0) return undefined;
244 return { x: 0, y: 0, width, height };
245}
246
247function isViewportNode(type: string | undefined): boolean {
248 if (!type) return false;

Callers 1

Calls 2

isViewportNodeFunction · 0.85
isValidRectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…