@primer/components 0.0.0-2021116153548 → 0.0.0-202111616587

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.
Files changed (63) hide show
  1. package/dist/browser.esm.js +2 -2
  2. package/dist/browser.esm.js.map +1 -1
  3. package/dist/browser.umd.js +2 -2
  4. package/dist/browser.umd.js.map +1 -1
  5. package/lib/ActionList/Item.js +3 -3
  6. package/lib/ActionList/List.js +2 -2
  7. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
  8. package/lib/Autocomplete/AutocompleteMenu.js +10 -5
  9. package/lib/Dialog/ConfirmationDialog.js +2 -2
  10. package/lib/Dialog/Dialog.js +2 -2
  11. package/lib/FilteredActionList/FilteredActionList.js +10 -3
  12. package/lib/Overlay.d.ts +1 -1
  13. package/lib/TextInputWithTokens.js +4 -4
  14. package/lib/hooks/useAnchoredPosition.d.ts +1 -1
  15. package/lib/hooks/useAnchoredPosition.js +2 -2
  16. package/lib/hooks/useFocusTrap.js +2 -2
  17. package/lib/hooks/useFocusZone.d.ts +1 -1
  18. package/lib/hooks/useFocusZone.js +2 -2
  19. package/lib/hooks/useOpenAndCloseFocus.js +2 -2
  20. package/lib-esm/ActionList/Item.js +1 -1
  21. package/lib-esm/ActionList/List.js +1 -1
  22. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
  23. package/lib-esm/Autocomplete/AutocompleteMenu.js +9 -4
  24. package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
  25. package/lib-esm/Dialog/Dialog.js +1 -1
  26. package/lib-esm/FilteredActionList/FilteredActionList.js +9 -3
  27. package/lib-esm/Overlay.d.ts +1 -1
  28. package/lib-esm/TextInputWithTokens.js +2 -2
  29. package/lib-esm/hooks/useAnchoredPosition.d.ts +1 -1
  30. package/lib-esm/hooks/useAnchoredPosition.js +1 -1
  31. package/lib-esm/hooks/useFocusTrap.js +1 -1
  32. package/lib-esm/hooks/useFocusZone.d.ts +1 -1
  33. package/lib-esm/hooks/useFocusZone.js +1 -1
  34. package/lib-esm/hooks/useOpenAndCloseFocus.js +1 -1
  35. package/package.json +2 -5
  36. package/lib/behaviors/anchoredPosition.d.ts +0 -89
  37. package/lib/behaviors/anchoredPosition.js +0 -316
  38. package/lib/behaviors/focusTrap.d.ts +0 -12
  39. package/lib/behaviors/focusTrap.js +0 -179
  40. package/lib/behaviors/focusZone.d.ts +0 -137
  41. package/lib/behaviors/focusZone.js +0 -578
  42. package/lib/behaviors/scrollIntoViewingArea.d.ts +0 -1
  43. package/lib/behaviors/scrollIntoViewingArea.js +0 -39
  44. package/lib/utils/iterateFocusableElements.d.ts +0 -42
  45. package/lib/utils/iterateFocusableElements.js +0 -113
  46. package/lib/utils/uniqueId.d.ts +0 -1
  47. package/lib/utils/uniqueId.js +0 -12
  48. package/lib/utils/userAgent.d.ts +0 -1
  49. package/lib/utils/userAgent.js +0 -15
  50. package/lib-esm/behaviors/anchoredPosition.d.ts +0 -89
  51. package/lib-esm/behaviors/anchoredPosition.js +0 -309
  52. package/lib-esm/behaviors/focusTrap.d.ts +0 -12
  53. package/lib-esm/behaviors/focusTrap.js +0 -170
  54. package/lib-esm/behaviors/focusZone.d.ts +0 -137
  55. package/lib-esm/behaviors/focusZone.js +0 -560
  56. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +0 -1
  57. package/lib-esm/behaviors/scrollIntoViewingArea.js +0 -30
  58. package/lib-esm/utils/iterateFocusableElements.d.ts +0 -42
  59. package/lib-esm/utils/iterateFocusableElements.js +0 -102
  60. package/lib-esm/utils/uniqueId.d.ts +0 -1
  61. package/lib-esm/utils/uniqueId.js +0 -5
  62. package/lib-esm/utils/userAgent.d.ts +0 -1
  63. package/lib-esm/utils/userAgent.js +0 -8
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.iterateFocusableElements = iterateFocusableElements;
7
- exports.isFocusable = isFocusable;
8
- exports.isTabbable = isTabbable;
9
-
10
- /**
11
- * Options to the focusable elements iterator
12
- */
13
-
14
- /**
15
- * Returns an iterator over all of the focusable elements within `container`.
16
- * Note: If `container` is itself focusable it will be included in the results.
17
- * @param container The container over which to find focusable elements.
18
- * @param reverse If true, iterate backwards through focusable elements.
19
- */
20
- function* iterateFocusableElements(container, options = {}) {
21
- var _options$strict, _options$onlyTabbable;
22
-
23
- const strict = (_options$strict = options.strict) !== null && _options$strict !== void 0 ? _options$strict : false;
24
- const acceptFn = ((_options$onlyTabbable = options.onlyTabbable) !== null && _options$onlyTabbable !== void 0 ? _options$onlyTabbable : false) ? isTabbable : isFocusable;
25
- const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
26
- acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
27
- });
28
- let nextNode = null; // Allow the container to participate
29
-
30
- if (!options.reverse && acceptFn(container, strict)) {
31
- yield container;
32
- } // If iterating in reverse, continue traversing down into the last child until we reach
33
- // a leaf DOM node
34
-
35
-
36
- if (options.reverse) {
37
- let lastChild = walker.lastChild();
38
-
39
- while (lastChild) {
40
- nextNode = lastChild;
41
- lastChild = walker.lastChild();
42
- }
43
- } else {
44
- nextNode = walker.firstChild();
45
- }
46
-
47
- while (nextNode instanceof HTMLElement) {
48
- yield nextNode;
49
- nextNode = options.reverse ? walker.previousNode() : walker.nextNode();
50
- } // Allow the container to participate (in reverse)
51
-
52
-
53
- if (options.reverse && acceptFn(container, strict)) {
54
- yield container;
55
- }
56
-
57
- return undefined;
58
- }
59
- /**
60
- * Determines whether the given element is focusable. If `strict` is true, we may
61
- * perform additional checks that require a reflow (less performant).
62
- * @param elem
63
- * @param strict
64
- */
65
-
66
-
67
- function isFocusable(elem, strict = false) {
68
- // Certain conditions cause an element to never be focusable, even if they have tabindex="0"
69
- const disabledAttrInert = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(elem.tagName) && elem.disabled;
70
- const hiddenInert = elem.hidden;
71
- const hiddenInputInert = elem instanceof HTMLInputElement && elem.type === 'hidden';
72
-
73
- if (disabledAttrInert || hiddenInert || hiddenInputInert) {
74
- return false;
75
- } // Each of the conditions checked below require a reflow, thus are gated by the `strict`
76
- // argument. If any are true, the element is not focusable, even if tabindex is set.
77
-
78
-
79
- if (strict) {
80
- const sizeInert = elem.offsetWidth === 0 || elem.offsetHeight === 0;
81
- const visibilityInert = ['hidden', 'collapse'].includes(getComputedStyle(elem).visibility);
82
- const clientRectsInert = elem.getClientRects().length === 0;
83
-
84
- if (sizeInert || visibilityInert || clientRectsInert) {
85
- return false;
86
- }
87
- } // Any element with `tabindex` explicitly set can be focusable, even if it's set to "-1"
88
-
89
-
90
- if (elem.getAttribute('tabindex') != null) {
91
- return true;
92
- } // One last way `elem.tabIndex` can be wrong.
93
-
94
-
95
- if (elem instanceof HTMLAnchorElement && elem.getAttribute('href') == null) {
96
- return false;
97
- }
98
-
99
- return elem.tabIndex !== -1;
100
- }
101
- /**
102
- * Determines whether the given element is tabbable. If `strict` is true, we may
103
- * perform additional checks that require a reflow (less performant). This check
104
- * ensures that the element is focusable and that its tabindex is not explicitly
105
- * set to "-1" (which makes it focusable, but removes it from the tab order).
106
- * @param elem
107
- * @param strict
108
- */
109
-
110
-
111
- function isTabbable(elem, strict = false) {
112
- return isFocusable(elem, strict) && elem.getAttribute('tabindex') !== '-1';
113
- }
@@ -1 +0,0 @@
1
- export declare function uniqueId(): string;
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.uniqueId = uniqueId;
7
- // Note: uniqueId may be unsafe in SSR contexts if it is used create DOM IDs or otherwise cause a hydration warning. Use useSSRSafeId instead.
8
- let idSeed = 10000;
9
-
10
- function uniqueId() {
11
- return `__primer_id_${idSeed++}`;
12
- }
@@ -1 +0,0 @@
1
- export declare function isMacOS(): boolean;
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isMacOS = isMacOS;
7
- let isMac = undefined;
8
-
9
- function isMacOS() {
10
- if (isMac === undefined) {
11
- isMac = /^mac/i.test(window.navigator.platform);
12
- }
13
-
14
- return isMac;
15
- }
@@ -1,89 +0,0 @@
1
- export declare type AnchorAlignment = 'start' | 'center' | 'end';
2
- export declare type AnchorSide = 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right' | 'inside-center' | 'outside-top' | 'outside-bottom' | 'outside-left' | 'outside-right';
3
- /**
4
- * Settings that customize how a floating element is positioned
5
- * with respect to an anchor element.
6
- */
7
- export interface PositionSettings {
8
- /**
9
- * Sets the side of the anchor element that the floating element should be
10
- * pinned to. This side is given by a string starting with either "inside" or
11
- * "outside", followed by a hyphen, followed by either "top", "right", "bottom",
12
- * or "left". Additionally, "inside-center" is an allowed value.
13
- *
14
- * The first part of this string, "inside" or "outside", determines whether the
15
- * floating element should be attempted to be placed "inside" the anchor element
16
- * or "outside" of it. Using "inside" is useful for making it appear that the
17
- * anchor _contains_ the floating element, and it can be used for implementing a
18
- * dialog that is centered on the screen. The "outside" value is more common and
19
- * can be used for tooltips, popovers, menus, etc.
20
- *
21
- * The second part of this string determines the _edge_ on the anchor element that
22
- * the floating element will be anchored to. If side is "inside-center", then
23
- * the floating element will be centered in the X-direction (while align is used
24
- * to position it in the Y-direction).
25
- * Note: "outside-center" is _not_ a valid value for this property.
26
- */
27
- side: AnchorSide;
28
- /**
29
- * Determines how the floating element should align with the anchor element. If
30
- * set to "start", the floating element's first edge (top or left) will align
31
- * with the anchor element's first edge. If set to "center", the floating
32
- * element will be centered along the axis of the anchor edge. If set to "end",
33
- * the floating element's last edge will align with the anchor element's last edge.
34
- */
35
- align: AnchorAlignment;
36
- /**
37
- * The number of pixels between the anchor edge and the floating element.
38
- *
39
- * Positive values move the floating element farther from the anchor element
40
- * (for outside positioning) or further inside the anchor element (for inside
41
- * positioning). Negative values have the opposite effect.
42
- */
43
- anchorOffset: number;
44
- /**
45
- * An additional offset, in pixels, to move the floating element from
46
- * the aligning edge.
47
- *
48
- * Positive values move the floating element in the direction of center-
49
- * alignment. Negative values move the floating element away from center-
50
- * alignment. When align is "center", positive offsets move the floating
51
- * element right (top or bottom anchor side) or down (left or right
52
- * anchor side).
53
- */
54
- alignmentOffset: number;
55
- /**
56
- * If false, when the above settings result in rendering the floating element
57
- * wholly or partially outside of the bounds of the containing element, attempt
58
- * to adjust the settings to prevent this. Only applies to "outside" positioning.
59
- *
60
- * First, attempt to flip to the opposite edge of the anchor if the floating
61
- * element is getting clipped in that direction. If flipping results in a
62
- * similar clipping, try moving to the adjacent sides.
63
- *
64
- * Once we find a side that does not clip the overlay in its own dimension,
65
- * check the rest of the sides to see if we need to adjust the alignment offset
66
- * to fit in other dimensions.
67
- *
68
- * If we try all four sides and get clipped each time, settle for overflowing
69
- * and use the "bottom" side, since the ability to scroll is most likely in
70
- * this direction.
71
- */
72
- allowOutOfBounds: boolean;
73
- }
74
- export interface AnchorPosition {
75
- top: number;
76
- left: number;
77
- anchorSide: AnchorSide;
78
- }
79
- /**
80
- * Given a floating element and an anchor element, return coordinates for the top-left
81
- * of the floating element in order to absolutely position it such that it appears
82
- * near the anchor element.
83
- *
84
- * @param floatingElement Element intended to be positioned near or within an anchor
85
- * @param anchorElement The element to serve as the position anchor
86
- * @param settings Settings to determine the rules for positioning the floating element
87
- * @returns {top: number, left: number} coordinates for the floating element
88
- */
89
- export declare function getAnchoredPosition(floatingElement: Element, anchorElement: Element | DOMRect, settings?: Partial<PositionSettings>): AnchorPosition;
@@ -1,309 +0,0 @@
1
- // When prettier supports template literal types...
2
- // export type AnchorSide = `${'inside' | 'outside'}-${'top' | 'bottom' | 'right' | 'left'}` | 'inside-center'
3
-
4
- /**
5
- * Settings that customize how a floating element is positioned
6
- * with respect to an anchor element.
7
- */
8
- // For each outside anchor position, list the order of alternate positions to try in
9
- // the event that the original position overflows. See comment on `allowOutOfBounds`
10
- // for a more detailed description.
11
- const alternateOrders = {
12
- 'outside-top': ['outside-bottom', 'outside-right', 'outside-left', 'outside-bottom'],
13
- 'outside-bottom': ['outside-top', 'outside-right', 'outside-left', 'outside-bottom'],
14
- 'outside-left': ['outside-right', 'outside-bottom', 'outside-top', 'outside-bottom'],
15
- 'outside-right': ['outside-left', 'outside-bottom', 'outside-top', 'outside-bottom']
16
- };
17
-
18
- /**
19
- * Given a floating element and an anchor element, return coordinates for the top-left
20
- * of the floating element in order to absolutely position it such that it appears
21
- * near the anchor element.
22
- *
23
- * @param floatingElement Element intended to be positioned near or within an anchor
24
- * @param anchorElement The element to serve as the position anchor
25
- * @param settings Settings to determine the rules for positioning the floating element
26
- * @returns {top: number, left: number} coordinates for the floating element
27
- */
28
- export function getAnchoredPosition(floatingElement, anchorElement, settings = {}) {
29
- const parentElement = getPositionedParent(floatingElement);
30
- const clippingRect = getClippingRect(parentElement);
31
- const parentElementStyle = getComputedStyle(parentElement);
32
- const parentElementRect = parentElement.getBoundingClientRect();
33
- const [borderTop, borderLeft] = [parentElementStyle.borderTopWidth, parentElementStyle.borderLeftWidth].map(v => parseInt(v, 10) || 0);
34
- const relativeRect = {
35
- top: parentElementRect.top + borderTop,
36
- left: parentElementRect.left + borderLeft
37
- };
38
- return pureCalculateAnchoredPosition(clippingRect, relativeRect, floatingElement.getBoundingClientRect(), anchorElement instanceof Element ? anchorElement.getBoundingClientRect() : anchorElement, getDefaultSettings(settings));
39
- }
40
- /**
41
- * Returns the nearest proper HTMLElement parent of `element` whose
42
- * position is not "static", or document.body, whichever is closer
43
- */
44
-
45
- function getPositionedParent(element) {
46
- let parentNode = element.parentNode;
47
-
48
- while (parentNode !== null) {
49
- if (parentNode instanceof HTMLElement && getComputedStyle(parentNode).position !== 'static') {
50
- return parentNode;
51
- }
52
-
53
- parentNode = parentNode.parentNode;
54
- }
55
-
56
- return document.body;
57
- }
58
- /**
59
- * Returns the rectangle (relative to the window) that will clip the given element
60
- * if it is rendered outside of its bounds.
61
- * @param element
62
- * @returns
63
- */
64
-
65
-
66
- function getClippingRect(element) {
67
- let parentNode = element;
68
-
69
- while (parentNode !== null) {
70
- if (parentNode === document.body) {
71
- break;
72
- }
73
-
74
- const parentNodeStyle = getComputedStyle(parentNode);
75
-
76
- if (parentNodeStyle.overflow !== 'visible') {
77
- break;
78
- }
79
-
80
- parentNode = parentNode.parentNode;
81
- }
82
-
83
- const clippingNode = parentNode === document.body || !(parentNode instanceof HTMLElement) ? document.body : parentNode;
84
- const elemRect = clippingNode.getBoundingClientRect();
85
- const elemStyle = getComputedStyle(clippingNode);
86
- const [borderTop, borderLeft, borderRight, borderBottom] = [elemStyle.borderTopWidth, elemStyle.borderLeftWidth, elemStyle.borderRightWidth, elemStyle.borderBottomWidth].map(v => parseInt(v, 10) || 0);
87
- return {
88
- top: elemRect.top + borderTop,
89
- left: elemRect.left + borderLeft,
90
- width: elemRect.width - borderRight - borderLeft,
91
- // If the clipping node is document.body, it can expand to the full height of the window
92
- height: Math.max(elemRect.height - borderTop - borderBottom, clippingNode === document.body ? window.innerHeight : -Infinity)
93
- };
94
- } // Default settings to position a floating element
95
-
96
-
97
- const positionDefaults = {
98
- side: 'outside-bottom',
99
- align: 'start',
100
- // note: the following default is not applied if side === "inside-center"
101
- anchorOffset: 4,
102
- // note: the following default is only applied if side starts with "inside"
103
- // and align is not center
104
- alignmentOffset: 4,
105
- allowOutOfBounds: false
106
- };
107
- /**
108
- * Compute a full PositionSettings object from the given partial PositionSettings object
109
- * by filling in with defaults where applicable.
110
- * @param settings Partial settings - any omissions will be defaulted
111
- */
112
-
113
- function getDefaultSettings(settings = {}) {
114
- var _settings$side, _settings$align, _settings$anchorOffse, _settings$alignmentOf, _settings$allowOutOfB;
115
-
116
- const side = (_settings$side = settings.side) !== null && _settings$side !== void 0 ? _settings$side : positionDefaults.side;
117
- const align = (_settings$align = settings.align) !== null && _settings$align !== void 0 ? _settings$align : positionDefaults.align;
118
- return {
119
- side,
120
- align,
121
- // offsets always default to 0 if their respective side/alignment is centered
122
- anchorOffset: (_settings$anchorOffse = settings.anchorOffset) !== null && _settings$anchorOffse !== void 0 ? _settings$anchorOffse : side === 'inside-center' ? 0 : positionDefaults.anchorOffset,
123
- alignmentOffset: (_settings$alignmentOf = settings.alignmentOffset) !== null && _settings$alignmentOf !== void 0 ? _settings$alignmentOf : align !== 'center' && side.startsWith('inside') ? positionDefaults.alignmentOffset : 0,
124
- allowOutOfBounds: (_settings$allowOutOfB = settings.allowOutOfBounds) !== null && _settings$allowOutOfB !== void 0 ? _settings$allowOutOfB : positionDefaults.allowOutOfBounds
125
- };
126
- }
127
- /**
128
- * Note: This is a pure function with no dependency on DOM APIs.
129
- * @see getAnchoredPosition
130
- * @see getDefaultSettings
131
- * @param viewportRect BoxPosition for the rectangle that will clip the floating element if it is
132
- * rendered outside of the boundsof the rectangle.
133
- * @param relativePosition Position for the closest positioned proper parent of the floating element
134
- * @param floatingRect WidthAndHeight for the floating element
135
- * @param anchorRect BoxPosition for the anchor element
136
- * @param PositionSettings to customize the calculated position for the floating element.
137
- */
138
-
139
-
140
- function pureCalculateAnchoredPosition(viewportRect, relativePosition, floatingRect, anchorRect, {
141
- side,
142
- align,
143
- allowOutOfBounds,
144
- anchorOffset,
145
- alignmentOffset
146
- }) {
147
- // Compute the relative viewport rect, to bring it into the same coordinate space as `pos`
148
- const relativeViewportRect = {
149
- top: viewportRect.top - relativePosition.top,
150
- left: viewportRect.left - relativePosition.left,
151
- width: viewportRect.width,
152
- height: viewportRect.height
153
- };
154
- let pos = calculatePosition(floatingRect, anchorRect, side, align, anchorOffset, alignmentOffset);
155
- let anchorSide = side;
156
- pos.top -= relativePosition.top;
157
- pos.left -= relativePosition.left; // Handle screen overflow
158
-
159
- if (!allowOutOfBounds) {
160
- const alternateOrder = alternateOrders[side];
161
- let positionAttempt = 0;
162
-
163
- if (alternateOrder) {
164
- let prevSide = side; // Try all the alternate sides until one does not overflow
165
-
166
- while (positionAttempt < alternateOrder.length && shouldRecalculatePosition(prevSide, pos, relativeViewportRect, floatingRect)) {
167
- const nextSide = alternateOrder[positionAttempt++];
168
- prevSide = nextSide; // If we have cut off in the same dimension as the "side" option, try flipping to the opposite side.
169
-
170
- pos = calculatePosition(floatingRect, anchorRect, nextSide, align, anchorOffset, alignmentOffset);
171
- pos.top -= relativePosition.top;
172
- pos.left -= relativePosition.left;
173
- anchorSide = nextSide;
174
- }
175
- } // At this point we've flipped the position if applicable. Now just nudge until it's on-screen.
176
-
177
-
178
- if (pos.top < relativeViewportRect.top) {
179
- pos.top = relativeViewportRect.top;
180
- }
181
-
182
- if (pos.left < relativeViewportRect.left) {
183
- pos.left = relativeViewportRect.left;
184
- }
185
-
186
- if (pos.left + floatingRect.width > viewportRect.width + relativeViewportRect.left) {
187
- pos.left = viewportRect.width + relativeViewportRect.left - floatingRect.width;
188
- } // If we have exhausted all possible positions and none of them worked, we
189
- // say that overflowing the bottom of the screen is acceptable since it is
190
- // likely to be able to scroll.
191
-
192
-
193
- if (alternateOrder && positionAttempt < alternateOrder.length) {
194
- if (pos.top + floatingRect.height > viewportRect.height + relativeViewportRect.top) {
195
- pos.top = viewportRect.height + relativeViewportRect.top - floatingRect.height;
196
- }
197
- }
198
- }
199
-
200
- return { ...pos,
201
- anchorSide
202
- };
203
- }
204
- /**
205
- * Given a floating element and an anchor element, return coordinates for the
206
- * top-left of the floating element in order to absolutely position it such
207
- * that it appears near the anchor element.
208
- *
209
- * @param elementDimensions Dimensions of the floating element
210
- * @param anchorPosition Position of the anchor element
211
- * @param side Side of the anchor to position the floating element
212
- * @param align How to align the floating element with the anchor element
213
- * @param anchorOffset Absolute pixel offset for anchor positioning
214
- * @param alignmentOffset Absolute pixel offset for alignment
215
- * @returns {top: number, left: number} coordinates for the floating element
216
- */
217
-
218
-
219
- function calculatePosition(elementDimensions, anchorPosition, side, align, anchorOffset, alignmentOffset) {
220
- const anchorRight = anchorPosition.left + anchorPosition.width;
221
- const anchorBottom = anchorPosition.top + anchorPosition.height;
222
- let top = -1;
223
- let left = -1;
224
-
225
- if (side === 'outside-top') {
226
- top = anchorPosition.top - anchorOffset - elementDimensions.height;
227
- } else if (side === 'outside-bottom') {
228
- top = anchorBottom + anchorOffset;
229
- } else if (side === 'outside-left') {
230
- left = anchorPosition.left - anchorOffset - elementDimensions.width;
231
- } else if (side === 'outside-right') {
232
- left = anchorRight + anchorOffset;
233
- }
234
-
235
- if (side === 'outside-top' || side === 'outside-bottom') {
236
- if (align === 'start') {
237
- left = anchorPosition.left + alignmentOffset;
238
- } else if (align === 'center') {
239
- left = anchorPosition.left - (elementDimensions.width - anchorPosition.width) / 2 + alignmentOffset;
240
- } else {
241
- // end
242
- left = anchorRight - elementDimensions.width - alignmentOffset;
243
- }
244
- }
245
-
246
- if (side === 'outside-left' || side === 'outside-right') {
247
- if (align === 'start') {
248
- top = anchorPosition.top + alignmentOffset;
249
- } else if (align === 'center') {
250
- top = anchorPosition.top - (elementDimensions.height - anchorPosition.height) / 2 + alignmentOffset;
251
- } else {
252
- // end
253
- top = anchorBottom - elementDimensions.height - alignmentOffset;
254
- }
255
- }
256
-
257
- if (side === 'inside-top') {
258
- top = anchorPosition.top + anchorOffset;
259
- } else if (side === 'inside-bottom') {
260
- top = anchorBottom - anchorOffset - elementDimensions.height;
261
- } else if (side === 'inside-left') {
262
- left = anchorPosition.left + anchorOffset;
263
- } else if (side === 'inside-right') {
264
- left = anchorRight - anchorOffset - elementDimensions.width;
265
- } else if (side === 'inside-center') {
266
- left = (anchorRight + anchorPosition.left) / 2 - elementDimensions.width / 2 + anchorOffset;
267
- }
268
-
269
- if (side === 'inside-top' || side === 'inside-bottom') {
270
- if (align === 'start') {
271
- left = anchorPosition.left + alignmentOffset;
272
- } else if (align === 'center') {
273
- left = anchorPosition.left - (elementDimensions.width - anchorPosition.width) / 2 + alignmentOffset;
274
- } else {
275
- // end
276
- left = anchorRight - elementDimensions.width - alignmentOffset;
277
- }
278
- } else if (side === 'inside-left' || side === 'inside-right' || side === 'inside-center') {
279
- if (align === 'start') {
280
- top = anchorPosition.top + alignmentOffset;
281
- } else if (align === 'center') {
282
- top = anchorPosition.top - (elementDimensions.height - anchorPosition.height) / 2 + alignmentOffset;
283
- } else {
284
- // end
285
- top = anchorBottom - elementDimensions.height - alignmentOffset;
286
- }
287
- }
288
-
289
- return {
290
- top,
291
- left
292
- };
293
- }
294
- /**
295
- * Determines if there is an overflow
296
- * @param side
297
- * @param currentPos
298
- * @param containerDimensions
299
- * @param elementDimensions
300
- */
301
-
302
-
303
- function shouldRecalculatePosition(side, currentPos, containerDimensions, elementDimensions) {
304
- if (side === 'outside-top' || side === 'outside-bottom') {
305
- return currentPos.top < containerDimensions.top || currentPos.top + elementDimensions.height > containerDimensions.height + containerDimensions.top;
306
- } else {
307
- return currentPos.left < containerDimensions.left || currentPos.left + elementDimensions.width > containerDimensions.width + containerDimensions.left;
308
- }
309
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Traps focus within the given container.
3
- * @param container The container in which to trap focus
4
- * @returns AbortController - call `.abort()` to disable the focus trap
5
- */
6
- export declare function focusTrap(container: HTMLElement, initialFocus?: HTMLElement): AbortController;
7
- /**
8
- * Traps focus within the given container.
9
- * @param container The container in which to trap focus
10
- * @param abortSignal An AbortSignal to control the focus trap.
11
- */
12
- export declare function focusTrap(container: HTMLElement, initialFocus: HTMLElement | undefined, abortSignal: AbortSignal): void;