@primer/behaviors 0.0.0-20251222042738 → 0.0.0-20251222200353
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/anchored-position.js +23 -35
- package/dist/esm/anchored-position.mjs +23 -35
- package/package.json +1 -1
|
@@ -12,9 +12,9 @@ const alternateAlignments = {
|
|
|
12
12
|
center: ['end', 'start'],
|
|
13
13
|
};
|
|
14
14
|
function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
|
|
15
|
-
const
|
|
16
|
-
const clippingRect = getClippingRect(
|
|
17
|
-
const parentElementStyle =
|
|
15
|
+
const parentElement = getPositionedParent(floatingElement);
|
|
16
|
+
const clippingRect = getClippingRect(parentElement);
|
|
17
|
+
const parentElementStyle = getComputedStyle(parentElement);
|
|
18
18
|
const parentElementRect = parentElement.getBoundingClientRect();
|
|
19
19
|
const [borderTop, borderLeft] = [parentElementStyle.borderTopWidth, parentElementStyle.borderLeftWidth].map(v => parseInt(v, 10) || 0);
|
|
20
20
|
const relativeRect = {
|
|
@@ -23,43 +23,19 @@ function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
|
|
|
23
23
|
};
|
|
24
24
|
return pureCalculateAnchoredPosition(clippingRect, relativeRect, floatingElement.getBoundingClientRect(), anchorElement instanceof Element ? anchorElement.getBoundingClientRect() : anchorElement, getDefaultSettings(settings));
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
if (isOnTopLayer(element))
|
|
28
|
-
return
|
|
29
|
-
positionedParent: document.body,
|
|
30
|
-
clippingNode: document.body,
|
|
31
|
-
positionedParentStyle: null,
|
|
32
|
-
clippingNodeStyle: null,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
let positionedParent = null;
|
|
36
|
-
let clippingNode = null;
|
|
37
|
-
let positionedParentStyle = null;
|
|
38
|
-
let clippingNodeStyle = null;
|
|
26
|
+
function getPositionedParent(element) {
|
|
27
|
+
if (isOnTopLayer(element))
|
|
28
|
+
return document.body;
|
|
39
29
|
let parentNode = element.parentNode;
|
|
40
30
|
while (parentNode !== null && parentNode !== document.body) {
|
|
41
31
|
if (parentNode instanceof HTMLElement) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
positionedParent = parentNode;
|
|
45
|
-
positionedParentStyle = style;
|
|
46
|
-
}
|
|
47
|
-
if (!clippingNode && style.overflow !== 'visible') {
|
|
48
|
-
clippingNode = parentNode;
|
|
49
|
-
clippingNodeStyle = style;
|
|
50
|
-
}
|
|
51
|
-
if (positionedParent && clippingNode) {
|
|
52
|
-
break;
|
|
32
|
+
if (getComputedStyle(parentNode).position !== 'static') {
|
|
33
|
+
return parentNode;
|
|
53
34
|
}
|
|
54
35
|
}
|
|
55
36
|
parentNode = parentNode.parentNode;
|
|
56
37
|
}
|
|
57
|
-
return
|
|
58
|
-
positionedParent: positionedParent !== null && positionedParent !== void 0 ? positionedParent : document.body,
|
|
59
|
-
clippingNode: clippingNode !== null && clippingNode !== void 0 ? clippingNode : document.body,
|
|
60
|
-
positionedParentStyle,
|
|
61
|
-
clippingNodeStyle,
|
|
62
|
-
};
|
|
38
|
+
return document.body;
|
|
63
39
|
}
|
|
64
40
|
function isOnTopLayer(element) {
|
|
65
41
|
var _a;
|
|
@@ -76,9 +52,21 @@ function isOnTopLayer(element) {
|
|
|
76
52
|
}
|
|
77
53
|
return false;
|
|
78
54
|
}
|
|
79
|
-
function getClippingRect(
|
|
55
|
+
function getClippingRect(element) {
|
|
56
|
+
let clippingNode = document.body;
|
|
57
|
+
let parentNode = element;
|
|
58
|
+
while (parentNode !== null && parentNode !== document.body) {
|
|
59
|
+
if (parentNode instanceof HTMLElement) {
|
|
60
|
+
const overflow = getComputedStyle(parentNode).overflow;
|
|
61
|
+
if (overflow !== 'visible') {
|
|
62
|
+
clippingNode = parentNode;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
parentNode = parentNode.parentNode;
|
|
67
|
+
}
|
|
80
68
|
const elemRect = clippingNode.getBoundingClientRect();
|
|
81
|
-
const elemStyle =
|
|
69
|
+
const elemStyle = getComputedStyle(clippingNode);
|
|
82
70
|
const borderTop = parseInt(elemStyle.borderTopWidth, 10) || 0;
|
|
83
71
|
const borderLeft = parseInt(elemStyle.borderLeftWidth, 10) || 0;
|
|
84
72
|
const borderRight = parseInt(elemStyle.borderRightWidth, 10) || 0;
|
|
@@ -10,9 +10,9 @@ const alternateAlignments = {
|
|
|
10
10
|
center: ['end', 'start'],
|
|
11
11
|
};
|
|
12
12
|
function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
|
|
13
|
-
const
|
|
14
|
-
const clippingRect = getClippingRect(
|
|
15
|
-
const parentElementStyle =
|
|
13
|
+
const parentElement = getPositionedParent(floatingElement);
|
|
14
|
+
const clippingRect = getClippingRect(parentElement);
|
|
15
|
+
const parentElementStyle = getComputedStyle(parentElement);
|
|
16
16
|
const parentElementRect = parentElement.getBoundingClientRect();
|
|
17
17
|
const [borderTop, borderLeft] = [parentElementStyle.borderTopWidth, parentElementStyle.borderLeftWidth].map(v => parseInt(v, 10) || 0);
|
|
18
18
|
const relativeRect = {
|
|
@@ -21,43 +21,19 @@ function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
|
|
|
21
21
|
};
|
|
22
22
|
return pureCalculateAnchoredPosition(clippingRect, relativeRect, floatingElement.getBoundingClientRect(), anchorElement instanceof Element ? anchorElement.getBoundingClientRect() : anchorElement, getDefaultSettings(settings));
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
if (isOnTopLayer(element))
|
|
26
|
-
return
|
|
27
|
-
positionedParent: document.body,
|
|
28
|
-
clippingNode: document.body,
|
|
29
|
-
positionedParentStyle: null,
|
|
30
|
-
clippingNodeStyle: null,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
let positionedParent = null;
|
|
34
|
-
let clippingNode = null;
|
|
35
|
-
let positionedParentStyle = null;
|
|
36
|
-
let clippingNodeStyle = null;
|
|
24
|
+
function getPositionedParent(element) {
|
|
25
|
+
if (isOnTopLayer(element))
|
|
26
|
+
return document.body;
|
|
37
27
|
let parentNode = element.parentNode;
|
|
38
28
|
while (parentNode !== null && parentNode !== document.body) {
|
|
39
29
|
if (parentNode instanceof HTMLElement) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
positionedParent = parentNode;
|
|
43
|
-
positionedParentStyle = style;
|
|
44
|
-
}
|
|
45
|
-
if (!clippingNode && style.overflow !== 'visible') {
|
|
46
|
-
clippingNode = parentNode;
|
|
47
|
-
clippingNodeStyle = style;
|
|
48
|
-
}
|
|
49
|
-
if (positionedParent && clippingNode) {
|
|
50
|
-
break;
|
|
30
|
+
if (getComputedStyle(parentNode).position !== 'static') {
|
|
31
|
+
return parentNode;
|
|
51
32
|
}
|
|
52
33
|
}
|
|
53
34
|
parentNode = parentNode.parentNode;
|
|
54
35
|
}
|
|
55
|
-
return
|
|
56
|
-
positionedParent: positionedParent !== null && positionedParent !== void 0 ? positionedParent : document.body,
|
|
57
|
-
clippingNode: clippingNode !== null && clippingNode !== void 0 ? clippingNode : document.body,
|
|
58
|
-
positionedParentStyle,
|
|
59
|
-
clippingNodeStyle,
|
|
60
|
-
};
|
|
36
|
+
return document.body;
|
|
61
37
|
}
|
|
62
38
|
function isOnTopLayer(element) {
|
|
63
39
|
var _a;
|
|
@@ -74,9 +50,21 @@ function isOnTopLayer(element) {
|
|
|
74
50
|
}
|
|
75
51
|
return false;
|
|
76
52
|
}
|
|
77
|
-
function getClippingRect(
|
|
53
|
+
function getClippingRect(element) {
|
|
54
|
+
let clippingNode = document.body;
|
|
55
|
+
let parentNode = element;
|
|
56
|
+
while (parentNode !== null && parentNode !== document.body) {
|
|
57
|
+
if (parentNode instanceof HTMLElement) {
|
|
58
|
+
const overflow = getComputedStyle(parentNode).overflow;
|
|
59
|
+
if (overflow !== 'visible') {
|
|
60
|
+
clippingNode = parentNode;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
parentNode = parentNode.parentNode;
|
|
65
|
+
}
|
|
78
66
|
const elemRect = clippingNode.getBoundingClientRect();
|
|
79
|
-
const elemStyle =
|
|
67
|
+
const elemStyle = getComputedStyle(clippingNode);
|
|
80
68
|
const borderTop = parseInt(elemStyle.borderTopWidth, 10) || 0;
|
|
81
69
|
const borderLeft = parseInt(elemStyle.borderLeftWidth, 10) || 0;
|
|
82
70
|
const borderRight = parseInt(elemStyle.borderRightWidth, 10) || 0;
|