1 | import { isHTMLElement } from "./instanceOf.js";
|
2 | import { round } from "../utils/math.js";
|
3 | export default function getBoundingClientRect(element, includeScale) {
|
4 | if (includeScale === void 0) {
|
5 | includeScale = false;
|
6 | }
|
7 |
|
8 | var rect = element.getBoundingClientRect();
|
9 | var scaleX = 1;
|
10 | var scaleY = 1;
|
11 |
|
12 | if (isHTMLElement(element) && includeScale) {
|
13 | var offsetHeight = element.offsetHeight;
|
14 | var offsetWidth = element.offsetWidth;
|
15 |
|
16 |
|
17 | if (offsetWidth > 0) {
|
18 | scaleX = round(rect.width) / offsetWidth || 1;
|
19 | }
|
20 |
|
21 | if (offsetHeight > 0) {
|
22 | scaleY = round(rect.height) / offsetHeight || 1;
|
23 | }
|
24 | }
|
25 |
|
26 | return {
|
27 | width: rect.width / scaleX,
|
28 | height: rect.height / scaleY,
|
29 | top: rect.top / scaleY,
|
30 | right: rect.right / scaleX,
|
31 | bottom: rect.bottom / scaleY,
|
32 | left: rect.left / scaleX,
|
33 | x: rect.left / scaleX,
|
34 | y: rect.top / scaleY
|
35 | };
|
36 | } |
\ | No newline at end of file |