Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo-mod-jslibs-dist.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-13 18:11:28 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-13 18:11:28 +0300
commit02b6116825341c309c1ceef951f4ec3566728397 (patch)
treeab5d3625431db2f3076c3dded6f79b37af8cacf3 /popperjs/package/lib/dom-utils/getDocumentRect.js.flow
parent7c4d83e324c73bb3dc1209ddefef733c5144424e (diff)
Diffstat (limited to 'popperjs/package/lib/dom-utils/getDocumentRect.js.flow')
-rw-r--r--popperjs/package/lib/dom-utils/getDocumentRect.js.flow37
1 files changed, 37 insertions, 0 deletions
diff --git a/popperjs/package/lib/dom-utils/getDocumentRect.js.flow b/popperjs/package/lib/dom-utils/getDocumentRect.js.flow
new file mode 100644
index 0000000..c9f63b0
--- /dev/null
+++ b/popperjs/package/lib/dom-utils/getDocumentRect.js.flow
@@ -0,0 +1,37 @@
+// @flow
+import type { Rect } from '../types';
+import getDocumentElement from './getDocumentElement';
+import getComputedStyle from './getComputedStyle';
+import getWindowScrollBarX from './getWindowScrollBarX';
+import getWindowScroll from './getWindowScroll';
+import { max } from '../utils/math';
+
+// Gets the entire size of the scrollable document area, even extending outside
+// of the `<html>` and `<body>` rect bounds if horizontally scrollable
+export default function getDocumentRect(element: HTMLElement): Rect {
+ const html = getDocumentElement(element);
+ const winScroll = getWindowScroll(element);
+ const body = element.ownerDocument?.body;
+
+ const width = max(
+ html.scrollWidth,
+ html.clientWidth,
+ body ? body.scrollWidth : 0,
+ body ? body.clientWidth : 0
+ );
+ const height = max(
+ html.scrollHeight,
+ html.clientHeight,
+ body ? body.scrollHeight : 0,
+ body ? body.clientHeight : 0
+ );
+
+ let x = -winScroll.scrollLeft + getWindowScrollBarX(element);
+ const y = -winScroll.scrollTop;
+
+ if (getComputedStyle(body || html).direction === 'rtl') {
+ x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
+ }
+
+ return { width, height, x, y };
+}