UNPKG

react-dev-inspector

Version:

dev-tool for inspect react components and jump to local IDE for component code.

57 lines (51 loc) 2.05 kB
/** * mirror from https://github.com/facebook/react/blob/v16.13.1/packages/react-devtools-shared/src/backend/views/Highlighter/Overlay.js * * remove all process for iframe, because iframe only need to think in chrome extension app, * which will deal multiple levels of nesting iframe. */ export interface Rect { bottom: number; height: number; left: number; right: number; top: number; width: number; } export interface BoxSizing { borderTop: number; borderBottom: number; borderLeft: number; borderRight: number; paddingTop: number; paddingBottom: number; paddingLeft: number; paddingRight: number; marginTop: number; marginBottom: number; marginLeft: number; marginRight: number; } // Calculate a boundingClientRect for a node relative to boundaryWindow, // taking into account any offsets caused by intermediate iframes. export function getNestedBoundingClientRect(node: HTMLElement, boundaryWindow: Window | HTMLElement): Rect export function getNestedBoundingClientRect(node: HTMLElement): Rect { return node.getBoundingClientRect() } export function getElementDimensions(domElement: Element) { const calculatedStyle = window.getComputedStyle(domElement) return { borderLeft: Number.parseInt(calculatedStyle.borderLeftWidth, 10), borderRight: Number.parseInt(calculatedStyle.borderRightWidth, 10), borderTop: Number.parseInt(calculatedStyle.borderTopWidth, 10), borderBottom: Number.parseInt(calculatedStyle.borderBottomWidth, 10), marginLeft: Number.parseInt(calculatedStyle.marginLeft, 10), marginRight: Number.parseInt(calculatedStyle.marginRight, 10), marginTop: Number.parseInt(calculatedStyle.marginTop, 10), marginBottom: Number.parseInt(calculatedStyle.marginBottom, 10), paddingLeft: Number.parseInt(calculatedStyle.paddingLeft, 10), paddingRight: Number.parseInt(calculatedStyle.paddingRight, 10), paddingTop: Number.parseInt(calculatedStyle.paddingTop, 10), paddingBottom: Number.parseInt(calculatedStyle.paddingBottom, 10), } }