source: imaps-frontend/node_modules/@popperjs/core/lib/dom-utils/getBoundingClientRect.js.flow

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.5 KB
Line 
1// @flow
2import type { ClientRectObject, VirtualElement } from '../types';
3import { isElement, isHTMLElement } from './instanceOf';
4import { round } from '../utils/math';
5import getWindow from './getWindow';
6import isLayoutViewport from './isLayoutViewport';
7
8export default function getBoundingClientRect(
9 element: Element | VirtualElement,
10 includeScale: boolean = false,
11 isFixedStrategy: boolean = false
12): ClientRectObject {
13 const clientRect = element.getBoundingClientRect();
14 let scaleX = 1;
15 let scaleY = 1;
16
17 if (includeScale && isHTMLElement(element)) {
18 scaleX =
19 (element: HTMLElement).offsetWidth > 0
20 ? round(clientRect.width) / (element: HTMLElement).offsetWidth || 1
21 : 1;
22 scaleY =
23 (element: HTMLElement).offsetHeight > 0
24 ? round(clientRect.height) / (element: HTMLElement).offsetHeight || 1
25 : 1;
26 }
27
28 const { visualViewport } = isElement(element) ? getWindow(element) : window;
29 const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
30
31 const x =
32 (clientRect.left +
33 (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) /
34 scaleX;
35 const y =
36 (clientRect.top +
37 (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) /
38 scaleY;
39 const width = clientRect.width / scaleX;
40 const height = clientRect.height / scaleY;
41
42 return {
43 width,
44 height,
45 top: y,
46 right: x + width,
47 bottom: y + height,
48 left: x,
49 x,
50 y,
51 };
52}
Note: See TracBrowser for help on using the repository browser.