Files
bentopdf/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js

1694 lines
54 KiB
JavaScript
Raw Normal View History

import {
notNullish,
toArray,
tryOnScopeDispose,
2026-03-20 21:48:48 +05:30
unrefElement,
} from './chunk-BRNHR3LR.js';
import { computed, shallowRef, toValue, watch } from './chunk-H6MPEGKE.js';
// node_modules/tabbable/dist/index.esm.js
2026-03-20 21:48:48 +05:30
var candidateSelectors = [
'input:not([inert]):not([inert] *)',
'select:not([inert]):not([inert] *)',
'textarea:not([inert]):not([inert] *)',
'a[href]:not([inert]):not([inert] *)',
'button:not([inert]):not([inert] *)',
'[tabindex]:not(slot):not([inert]):not([inert] *)',
'audio[controls]:not([inert]):not([inert] *)',
'video[controls]:not([inert]):not([inert] *)',
'[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)',
'details>summary:first-of-type:not([inert]):not([inert] *)',
'details:not([inert]):not([inert] *)',
];
var candidateSelector = candidateSelectors.join(',');
var NoElement = typeof Element === 'undefined';
var matches = NoElement
? function () {}
: Element.prototype.matches ||
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
var getRootNode =
!NoElement && Element.prototype.getRootNode
? function (element) {
var _element$getRootNode;
return element === null || element === void 0
? void 0
: (_element$getRootNode = element.getRootNode) === null ||
_element$getRootNode === void 0
? void 0
: _element$getRootNode.call(element);
}
: function (element) {
return element === null || element === void 0
? void 0
: element.ownerDocument;
};
var _isInert = function isInert(node, lookUp) {
var _node$getAttribute;
if (lookUp === void 0) {
lookUp = true;
}
2026-03-20 21:48:48 +05:30
var inertAtt =
node === null || node === void 0
? void 0
: (_node$getAttribute = node.getAttribute) === null ||
_node$getAttribute === void 0
? void 0
: _node$getAttribute.call(node, 'inert');
var inert = inertAtt === '' || inertAtt === 'true';
var result =
inert ||
(lookUp &&
node && // closest does not exist on shadow roots, so we fall back to a manual
// lookup upward, in case it is not defined.
(typeof node.closest === 'function'
? node.closest('[inert]')
: _isInert(node.parentNode)));
return result;
};
var isContentEditable = function isContentEditable2(node) {
var _node$getAttribute2;
2026-03-20 21:48:48 +05:30
var attValue =
node === null || node === void 0
? void 0
: (_node$getAttribute2 = node.getAttribute) === null ||
_node$getAttribute2 === void 0
? void 0
: _node$getAttribute2.call(node, 'contenteditable');
return attValue === '' || attValue === 'true';
};
var getCandidates = function getCandidates2(el, includeContainer, filter) {
if (_isInert(el)) {
return [];
}
2026-03-20 21:48:48 +05:30
var candidates = Array.prototype.slice.apply(
el.querySelectorAll(candidateSelector)
);
if (includeContainer && matches.call(el, candidateSelector)) {
candidates.unshift(el);
}
candidates = candidates.filter(filter);
return candidates;
};
2026-03-20 21:48:48 +05:30
var _getCandidatesIteratively = function getCandidatesIteratively(
elements,
includeContainer,
options
) {
var candidates = [];
var elementsToCheck = Array.from(elements);
while (elementsToCheck.length) {
var element = elementsToCheck.shift();
if (_isInert(element, false)) {
continue;
}
2026-03-20 21:48:48 +05:30
if (element.tagName === 'SLOT') {
var assigned = element.assignedElements();
var content = assigned.length ? assigned : element.children;
var nestedCandidates = _getCandidatesIteratively(content, true, options);
if (options.flatten) {
candidates.push.apply(candidates, nestedCandidates);
} else {
candidates.push({
scopeParent: element,
2026-03-20 21:48:48 +05:30
candidates: nestedCandidates,
});
}
} else {
var validCandidate = matches.call(element, candidateSelector);
2026-03-20 21:48:48 +05:30
if (
validCandidate &&
options.filter(element) &&
(includeContainer || !elements.includes(element))
) {
candidates.push(element);
}
2026-03-20 21:48:48 +05:30
var shadowRoot =
element.shadowRoot || // check for an undisclosed shadow
(typeof options.getShadowRoot === 'function' &&
options.getShadowRoot(element));
var validShadowRoot =
!_isInert(shadowRoot, false) &&
(!options.shadowRootFilter || options.shadowRootFilter(element));
if (shadowRoot && validShadowRoot) {
2026-03-20 21:48:48 +05:30
var _nestedCandidates = _getCandidatesIteratively(
shadowRoot === true ? element.children : shadowRoot.children,
true,
options
);
if (options.flatten) {
candidates.push.apply(candidates, _nestedCandidates);
} else {
candidates.push({
scopeParent: element,
2026-03-20 21:48:48 +05:30
candidates: _nestedCandidates,
});
}
} else {
elementsToCheck.unshift.apply(elementsToCheck, element.children);
}
}
}
return candidates;
};
var hasTabIndex = function hasTabIndex2(node) {
2026-03-20 21:48:48 +05:30
return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
};
var getTabIndex = function getTabIndex2(node) {
if (!node) {
2026-03-20 21:48:48 +05:30
throw new Error('No node provided');
}
if (node.tabIndex < 0) {
2026-03-20 21:48:48 +05:30
if (
(/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) ||
isContentEditable(node)) &&
!hasTabIndex(node)
) {
return 0;
}
}
return node.tabIndex;
};
var getSortOrderTabIndex = function getSortOrderTabIndex2(node, isScope) {
var tabIndex = getTabIndex(node);
if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
return 0;
}
return tabIndex;
};
var sortOrderedTabbables = function sortOrderedTabbables2(a, b) {
2026-03-20 21:48:48 +05:30
return a.tabIndex === b.tabIndex
? a.documentOrder - b.documentOrder
: a.tabIndex - b.tabIndex;
};
var isInput = function isInput2(node) {
2026-03-20 21:48:48 +05:30
return node.tagName === 'INPUT';
};
var isHiddenInput = function isHiddenInput2(node) {
2026-03-20 21:48:48 +05:30
return isInput(node) && node.type === 'hidden';
};
var isDetailsWithSummary = function isDetailsWithSummary2(node) {
2026-03-20 21:48:48 +05:30
var r =
node.tagName === 'DETAILS' &&
Array.prototype.slice.apply(node.children).some(function (child) {
return child.tagName === 'SUMMARY';
});
return r;
};
var getCheckedRadio = function getCheckedRadio2(nodes, form) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].checked && nodes[i].form === form) {
return nodes[i];
}
}
};
var isTabbableRadio = function isTabbableRadio2(node) {
if (!node.name) {
return true;
}
var radioScope = node.form || getRootNode(node);
var queryRadios = function queryRadios2(name) {
2026-03-20 21:48:48 +05:30
return radioScope.querySelectorAll(
'input[type="radio"][name="' + name + '"]'
);
};
var radioSet;
2026-03-20 21:48:48 +05:30
if (
typeof window !== 'undefined' &&
typeof window.CSS !== 'undefined' &&
typeof window.CSS.escape === 'function'
) {
radioSet = queryRadios(window.CSS.escape(node.name));
} else {
try {
radioSet = queryRadios(node.name);
} catch (err) {
2026-03-20 21:48:48 +05:30
console.error(
'Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s',
err.message
);
return false;
}
}
var checked = getCheckedRadio(radioSet, node.form);
return !checked || checked === node;
};
var isRadio = function isRadio2(node) {
2026-03-20 21:48:48 +05:30
return isInput(node) && node.type === 'radio';
};
var isNonTabbableRadio = function isNonTabbableRadio2(node) {
return isRadio(node) && !isTabbableRadio(node);
};
var isNodeAttached = function isNodeAttached2(node) {
var _nodeRoot;
var nodeRoot = node && getRootNode(node);
2026-03-20 21:48:48 +05:30
var nodeRootHost =
(_nodeRoot = nodeRoot) === null || _nodeRoot === void 0
? void 0
: _nodeRoot.host;
var attached = false;
if (nodeRoot && nodeRoot !== node) {
var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
2026-03-20 21:48:48 +05:30
attached = !!(
((_nodeRootHost = nodeRootHost) !== null &&
_nodeRootHost !== void 0 &&
(_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null &&
_nodeRootHost$ownerDo !== void 0 &&
_nodeRootHost$ownerDo.contains(nodeRootHost)) ||
(node !== null &&
node !== void 0 &&
(_node$ownerDocument = node.ownerDocument) !== null &&
_node$ownerDocument !== void 0 &&
_node$ownerDocument.contains(node))
);
while (!attached && nodeRootHost) {
var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
nodeRoot = getRootNode(nodeRootHost);
2026-03-20 21:48:48 +05:30
nodeRootHost =
(_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0
? void 0
: _nodeRoot2.host;
attached = !!(
(_nodeRootHost2 = nodeRootHost) !== null &&
_nodeRootHost2 !== void 0 &&
(_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null &&
_nodeRootHost2$ownerD !== void 0 &&
_nodeRootHost2$ownerD.contains(nodeRootHost)
);
}
}
return attached;
};
var isZeroArea = function isZeroArea2(node) {
2026-03-20 21:48:48 +05:30
var _node$getBoundingClie = node.getBoundingClientRect(),
width = _node$getBoundingClie.width,
height = _node$getBoundingClie.height;
return width === 0 && height === 0;
};
var isHidden = function isHidden2(node, _ref) {
2026-03-20 21:48:48 +05:30
var displayCheck = _ref.displayCheck,
getShadowRoot = _ref.getShadowRoot;
if (displayCheck === 'full-native') {
if ('checkVisibility' in node) {
var visible = node.checkVisibility({
// Checking opacity might be desirable for some use cases, but natively,
// opacity zero elements _are_ focusable and tabbable.
checkOpacity: false,
opacityProperty: false,
contentVisibilityAuto: true,
visibilityProperty: true,
// This is an alias for `visibilityProperty`. Contemporary browsers
// support both. However, this alias has wider browser support (Chrome
// >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
// we include it anyway.
2026-03-20 21:48:48 +05:30
checkVisibilityCSS: true,
});
return !visible;
}
}
2026-03-20 21:48:48 +05:30
if (getComputedStyle(node).visibility === 'hidden') {
return true;
}
2026-03-20 21:48:48 +05:30
var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
2026-03-20 21:48:48 +05:30
if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
return true;
}
2026-03-20 21:48:48 +05:30
if (
!displayCheck ||
displayCheck === 'full' || // full-native can run this branch when it falls through in case
// Element#checkVisibility is unsupported
displayCheck === 'full-native' ||
displayCheck === 'legacy-full'
) {
if (typeof getShadowRoot === 'function') {
var originalNode = node;
while (node) {
var parentElement = node.parentElement;
var rootNode = getRootNode(node);
2026-03-20 21:48:48 +05:30
if (
parentElement &&
!parentElement.shadowRoot &&
getShadowRoot(parentElement) === true
) {
return isZeroArea(node);
} else if (node.assignedSlot) {
node = node.assignedSlot;
} else if (!parentElement && rootNode !== node.ownerDocument) {
node = rootNode.host;
} else {
node = parentElement;
}
}
node = originalNode;
}
if (isNodeAttached(node)) {
return !node.getClientRects().length;
}
2026-03-20 21:48:48 +05:30
if (displayCheck !== 'legacy-full') {
return true;
}
2026-03-20 21:48:48 +05:30
} else if (displayCheck === 'non-zero-area') {
return isZeroArea(node);
}
return false;
};
var isDisabledFromFieldset = function isDisabledFromFieldset2(node) {
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
var parentNode = node.parentElement;
while (parentNode) {
2026-03-20 21:48:48 +05:30
if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
for (var i = 0; i < parentNode.children.length; i++) {
var child = parentNode.children.item(i);
2026-03-20 21:48:48 +05:30
if (child.tagName === 'LEGEND') {
return matches.call(parentNode, 'fieldset[disabled] *')
? true
: !child.contains(node);
}
}
return true;
}
parentNode = parentNode.parentElement;
}
}
return false;
};
2026-03-20 21:48:48 +05:30
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable2(
options,
node
) {
if (
node.disabled ||
isHiddenInput(node) ||
isHidden(node, options) || // For a details element with a summary, the summary element gets the focus
isDetailsWithSummary(node) ||
isDisabledFromFieldset(node)
) {
return false;
}
return true;
};
2026-03-20 21:48:48 +05:30
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(
options,
node
) {
if (
isNonTabbableRadio(node) ||
getTabIndex(node) < 0 ||
!isNodeMatchingSelectorFocusable(options, node)
) {
return false;
}
return true;
};
var isShadowRootTabbable = function isShadowRootTabbable2(shadowHostNode) {
2026-03-20 21:48:48 +05:30
var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
if (isNaN(tabIndex) || tabIndex >= 0) {
return true;
}
return false;
};
var _sortByOrder = function sortByOrder(candidates) {
var regularTabbables = [];
var orderedTabbables = [];
2026-03-20 21:48:48 +05:30
candidates.forEach(function (item, i) {
var isScope = !!item.scopeParent;
var element = isScope ? item.scopeParent : item;
var candidateTabindex = getSortOrderTabIndex(element, isScope);
var elements = isScope ? _sortByOrder(item.candidates) : element;
if (candidateTabindex === 0) {
2026-03-20 21:48:48 +05:30
isScope
? regularTabbables.push.apply(regularTabbables, elements)
: regularTabbables.push(element);
} else {
orderedTabbables.push({
documentOrder: i,
tabIndex: candidateTabindex,
item,
isScope,
2026-03-20 21:48:48 +05:30
content: elements,
});
}
});
2026-03-20 21:48:48 +05:30
return orderedTabbables
.sort(sortOrderedTabbables)
.reduce(function (acc, sortable) {
sortable.isScope
? acc.push.apply(acc, sortable.content)
: acc.push(sortable.content);
return acc;
}, [])
.concat(regularTabbables);
};
var tabbable = function tabbable2(container, options) {
options = options || {};
var candidates;
if (options.getShadowRoot) {
2026-03-20 21:48:48 +05:30
candidates = _getCandidatesIteratively(
[container],
options.includeContainer,
{
filter: isNodeMatchingSelectorTabbable.bind(null, options),
flatten: false,
getShadowRoot: options.getShadowRoot,
shadowRootFilter: isShadowRootTabbable,
}
);
} else {
2026-03-20 21:48:48 +05:30
candidates = getCandidates(
container,
options.includeContainer,
isNodeMatchingSelectorTabbable.bind(null, options)
);
}
return _sortByOrder(candidates);
};
var focusable = function focusable2(container, options) {
options = options || {};
var candidates;
if (options.getShadowRoot) {
2026-03-20 21:48:48 +05:30
candidates = _getCandidatesIteratively(
[container],
options.includeContainer,
{
filter: isNodeMatchingSelectorFocusable.bind(null, options),
flatten: true,
getShadowRoot: options.getShadowRoot,
}
);
} else {
2026-03-20 21:48:48 +05:30
candidates = getCandidates(
container,
options.includeContainer,
isNodeMatchingSelectorFocusable.bind(null, options)
);
}
return candidates;
};
var isTabbable = function isTabbable2(node, options) {
options = options || {};
if (!node) {
2026-03-20 21:48:48 +05:30
throw new Error('No node provided');
}
if (matches.call(node, candidateSelector) === false) {
return false;
}
return isNodeMatchingSelectorTabbable(options, node);
};
2026-03-20 21:48:48 +05:30
var focusableCandidateSelector = candidateSelectors
.concat('iframe:not([inert]):not([inert] *)')
.join(',');
var isFocusable = function isFocusable2(node, options) {
options = options || {};
if (!node) {
2026-03-20 21:48:48 +05:30
throw new Error('No node provided');
}
if (matches.call(node, focusableCandidateSelector) === false) {
return false;
}
return isNodeMatchingSelectorFocusable(options, node);
};
// node_modules/focus-trap/dist/focus-trap.esm.js
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return _arrayLikeToArray(r);
}
function _createForOfIteratorHelper(r, e) {
2026-03-20 21:48:48 +05:30
var t =
('undefined' != typeof Symbol && r[Symbol.iterator]) || r['@@iterator'];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
t && (r = t);
2026-03-20 21:48:48 +05:30
var n = 0,
F = function () {};
return {
s: F,
2026-03-20 21:48:48 +05:30
n: function () {
return n >= r.length
? {
done: true,
}
: {
done: false,
value: r[n++],
};
},
2026-03-20 21:48:48 +05:30
e: function (r2) {
throw r2;
},
2026-03-20 21:48:48 +05:30
f: F,
};
}
2026-03-20 21:48:48 +05:30
throw new TypeError(
'Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
);
}
2026-03-20 21:48:48 +05:30
var o,
a = true,
u = false;
return {
2026-03-20 21:48:48 +05:30
s: function () {
t = t.call(r);
},
2026-03-20 21:48:48 +05:30
n: function () {
var r2 = t.next();
2026-03-20 21:48:48 +05:30
return ((a = r2.done), r2);
},
2026-03-20 21:48:48 +05:30
e: function (r2) {
((u = true), (o = r2));
},
2026-03-20 21:48:48 +05:30
f: function () {
try {
a || null == t.return || t.return();
} finally {
if (u) throw o;
}
2026-03-20 21:48:48 +05:30
},
};
}
function _defineProperty(e, r, t) {
2026-03-20 21:48:48 +05:30
return (
(r = _toPropertyKey(r)) in e
? Object.defineProperty(e, r, {
value: t,
enumerable: true,
configurable: true,
writable: true,
})
: (e[r] = t),
e
);
}
function _iterableToArray(r) {
2026-03-20 21:48:48 +05:30
if (
('undefined' != typeof Symbol && null != r[Symbol.iterator]) ||
null != r['@@iterator']
)
return Array.from(r);
}
function _nonIterableSpread() {
2026-03-20 21:48:48 +05:30
throw new TypeError(
'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
);
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
2026-03-20 21:48:48 +05:30
(r &&
(o = o.filter(function (r2) {
return Object.getOwnPropertyDescriptor(e, r2).enumerable;
})),
t.push.apply(t, o));
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
2026-03-20 21:48:48 +05:30
r % 2
? ownKeys(Object(t), true).forEach(function (r2) {
_defineProperty(e, r2, t[r2]);
})
: Object.getOwnPropertyDescriptors
? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t))
: ownKeys(Object(t)).forEach(function (r2) {
Object.defineProperty(
e,
r2,
Object.getOwnPropertyDescriptor(t, r2)
);
});
}
return e;
}
function _toConsumableArray(r) {
2026-03-20 21:48:48 +05:30
return (
_arrayWithoutHoles(r) ||
_iterableToArray(r) ||
_unsupportedIterableToArray(r) ||
_nonIterableSpread()
);
}
function _toPrimitive(t, r) {
2026-03-20 21:48:48 +05:30
if ('object' != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r);
2026-03-20 21:48:48 +05:30
if ('object' != typeof i) return i;
throw new TypeError('@@toPrimitive must return a primitive value.');
}
2026-03-20 21:48:48 +05:30
return ('string' === r ? String : Number)(t);
}
function _toPropertyKey(t) {
2026-03-20 21:48:48 +05:30
var i = _toPrimitive(t, 'string');
return 'symbol' == typeof i ? i : i + '';
}
function _unsupportedIterableToArray(r, a) {
if (r) {
2026-03-20 21:48:48 +05:30
if ('string' == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
2026-03-20 21:48:48 +05:30
return (
'Object' === t && r.constructor && (t = r.constructor.name),
'Map' === t || 'Set' === t
? Array.from(r)
: 'Arguments' === t ||
/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)
? _arrayLikeToArray(r, a)
: void 0
);
}
}
var activeFocusTraps = {
// Returns the trap from the top of the stack.
getActiveTrap: function getActiveTrap(trapStack) {
2026-03-20 21:48:48 +05:30
if (
(trapStack === null || trapStack === void 0 ? void 0 : trapStack.length) >
0
) {
return trapStack[trapStack.length - 1];
}
return null;
},
// Pauses the currently active trap, then adds a new trap to the stack.
activateTrap: function activateTrap(trapStack, trap) {
var activeTrap = activeFocusTraps.getActiveTrap(trapStack);
if (trap !== activeTrap) {
activeFocusTraps.pauseTrap(trapStack);
}
var trapIndex = trapStack.indexOf(trap);
if (trapIndex === -1) {
trapStack.push(trap);
} else {
trapStack.splice(trapIndex, 1);
trapStack.push(trap);
}
},
// Removes the trap from the top of the stack, then unpauses the next trap down.
deactivateTrap: function deactivateTrap(trapStack, trap) {
var trapIndex = trapStack.indexOf(trap);
if (trapIndex !== -1) {
trapStack.splice(trapIndex, 1);
}
activeFocusTraps.unpauseTrap(trapStack);
},
// Pauses the trap at the top of the stack.
pauseTrap: function pauseTrap(trapStack) {
var activeTrap = activeFocusTraps.getActiveTrap(trapStack);
2026-03-20 21:48:48 +05:30
activeTrap === null ||
activeTrap === void 0 ||
activeTrap._setPausedState(true);
},
// Unpauses the trap at the top of the stack.
unpauseTrap: function unpauseTrap(trapStack) {
var activeTrap = activeFocusTraps.getActiveTrap(trapStack);
if (activeTrap && !activeTrap._isManuallyPaused()) {
activeTrap._setPausedState(false);
}
2026-03-20 21:48:48 +05:30
},
};
var isSelectableInput = function isSelectableInput2(node) {
2026-03-20 21:48:48 +05:30
return (
node.tagName &&
node.tagName.toLowerCase() === 'input' &&
typeof node.select === 'function'
);
};
var isEscapeEvent = function isEscapeEvent2(e) {
2026-03-20 21:48:48 +05:30
return (
(e === null || e === void 0 ? void 0 : e.key) === 'Escape' ||
(e === null || e === void 0 ? void 0 : e.key) === 'Esc' ||
(e === null || e === void 0 ? void 0 : e.keyCode) === 27
);
};
var isTabEvent = function isTabEvent2(e) {
2026-03-20 21:48:48 +05:30
return (
(e === null || e === void 0 ? void 0 : e.key) === 'Tab' ||
(e === null || e === void 0 ? void 0 : e.keyCode) === 9
);
};
var isKeyForward = function isKeyForward2(e) {
return isTabEvent(e) && !e.shiftKey;
};
var isKeyBackward = function isKeyBackward2(e) {
return isTabEvent(e) && e.shiftKey;
};
var delay = function delay2(fn) {
return setTimeout(fn, 0);
};
var valueOrHandler = function valueOrHandler2(value) {
2026-03-20 21:48:48 +05:30
for (
var _len = arguments.length,
params = new Array(_len > 1 ? _len - 1 : 0),
_key = 1;
_key < _len;
_key++
) {
params[_key - 1] = arguments[_key];
}
2026-03-20 21:48:48 +05:30
return typeof value === 'function' ? value.apply(void 0, params) : value;
};
var getActualTarget = function getActualTarget2(event) {
2026-03-20 21:48:48 +05:30
return event.target.shadowRoot && typeof event.composedPath === 'function'
? event.composedPath()[0]
: event.target;
};
var internalTrapStack = [];
var createFocusTrap = function createFocusTrap2(elements, userOptions) {
2026-03-20 21:48:48 +05:30
var doc =
(userOptions === null || userOptions === void 0
? void 0
: userOptions.document) || document;
var trapStack =
(userOptions === null || userOptions === void 0
? void 0
: userOptions.trapStack) || internalTrapStack;
var config = _objectSpread2(
{
returnFocusOnDeactivate: true,
escapeDeactivates: true,
delayInitialFocus: true,
isolateSubtrees: false,
isKeyForward,
isKeyBackward,
},
userOptions
);
var state = {
// containers given to createFocusTrap()
/** @type {Array<HTMLElement>} */
containers: [],
// list of objects identifying tabbable nodes in `containers` in the trap
// NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
// is active, but the trap should never get to a state where there isn't at least one group
// with at least one tabbable node in it (that would lead to an error condition that would
// result in an error being thrown)
/** @type {Array<{
* container: HTMLElement,
* tabbableNodes: Array<HTMLElement>, // empty if none
* focusableNodes: Array<HTMLElement>, // empty if none
* posTabIndexesFound: boolean,
* firstTabbableNode: HTMLElement|undefined,
* lastTabbableNode: HTMLElement|undefined,
* firstDomTabbableNode: HTMLElement|undefined,
* lastDomTabbableNode: HTMLElement|undefined,
* nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
* }>}
*/
containerGroups: [],
// same order/length as `containers` list
// references to objects in `containerGroups`, but only those that actually have
// tabbable nodes in them
// NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
// the same length
tabbableGroups: [],
// references to nodes that are siblings to the ancestors of this trap's containers.
/** @type {Set<HTMLElement>} */
adjacentElements: /* @__PURE__ */ new Set(),
// references to nodes that were inert before the trap was activated.
/** @type {Set<HTMLElement>} */
alreadyInert: /* @__PURE__ */ new Set(),
nodeFocusedBeforeActivation: null,
mostRecentlyFocusedNode: null,
active: false,
paused: false,
manuallyPaused: false,
// timer ID for when delayInitialFocus is true and initial focus in this trap
// has been delayed during activation
delayInitialFocusTimer: void 0,
// the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any
2026-03-20 21:48:48 +05:30
recentNavEvent: void 0,
};
var trap;
2026-03-20 21:48:48 +05:30
var getOption = function getOption2(
configOverrideOptions,
optionName,
configOptionName
) {
return configOverrideOptions && configOverrideOptions[optionName] !== void 0
? configOverrideOptions[optionName]
: config[configOptionName || optionName];
};
var findContainerIndex = function findContainerIndex2(element, event) {
2026-03-20 21:48:48 +05:30
var composedPath =
typeof (event === null || event === void 0
? void 0
: event.composedPath) === 'function'
? event.composedPath()
: void 0;
return state.containerGroups.findIndex(function (_ref) {
var container = _ref.container,
tabbableNodes = _ref.tabbableNodes;
return (
container.contains(element) || // fall back to explicit tabbable search which will take into consideration any
// web components if the `tabbableOptions.getShadowRoot` option was used for
// the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
// look inside web components even if open)
(composedPath === null || composedPath === void 0
? void 0
: composedPath.includes(container)) ||
tabbableNodes.find(function (node) {
return node === element;
})
);
});
};
var getNodeForOption = function getNodeForOption2(optionName) {
2026-03-20 21:48:48 +05:30
var _ref2 =
arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {},
_ref2$hasFallback = _ref2.hasFallback,
hasFallback = _ref2$hasFallback === void 0 ? false : _ref2$hasFallback,
_ref2$params = _ref2.params,
params = _ref2$params === void 0 ? [] : _ref2$params;
var optionValue = config[optionName];
2026-03-20 21:48:48 +05:30
if (typeof optionValue === 'function') {
optionValue = optionValue.apply(void 0, _toConsumableArray(params));
}
if (optionValue === true) {
optionValue = void 0;
}
if (!optionValue) {
if (optionValue === void 0 || optionValue === false) {
return optionValue;
}
2026-03-20 21:48:48 +05:30
throw new Error(
'`'.concat(
optionName,
'` was specified but was not a node, or did not return a node'
)
);
}
var node = optionValue;
2026-03-20 21:48:48 +05:30
if (typeof optionValue === 'string') {
try {
node = doc.querySelector(optionValue);
} catch (err) {
2026-03-20 21:48:48 +05:30
throw new Error(
'`'
.concat(optionName, '` appears to be an invalid selector; error="')
.concat(err.message, '"')
);
}
if (!node) {
if (!hasFallback) {
2026-03-20 21:48:48 +05:30
throw new Error(
'`'.concat(optionName, '` as selector refers to no known node')
);
}
}
}
return node;
};
var getInitialFocusNode = function getInitialFocusNode2() {
2026-03-20 21:48:48 +05:30
var node = getNodeForOption('initialFocus', {
hasFallback: true,
});
if (node === false) {
return false;
}
2026-03-20 21:48:48 +05:30
if (
node === void 0 ||
(node && !isFocusable(node, config.tabbableOptions))
) {
if (findContainerIndex(doc.activeElement) >= 0) {
node = doc.activeElement;
} else {
var firstTabbableGroup = state.tabbableGroups[0];
2026-03-20 21:48:48 +05:30
var firstTabbableNode =
firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
node = firstTabbableNode || getNodeForOption('fallbackFocus');
}
} else if (node === null) {
2026-03-20 21:48:48 +05:30
node = getNodeForOption('fallbackFocus');
}
if (!node) {
2026-03-20 21:48:48 +05:30
throw new Error(
'Your focus-trap needs to have at least one focusable element'
);
}
return node;
};
var updateTabbableNodes = function updateTabbableNodes2() {
2026-03-20 21:48:48 +05:30
state.containerGroups = state.containers.map(function (container) {
var tabbableNodes = tabbable(container, config.tabbableOptions);
var focusableNodes = focusable(container, config.tabbableOptions);
2026-03-20 21:48:48 +05:30
var firstTabbableNode =
tabbableNodes.length > 0 ? tabbableNodes[0] : void 0;
var lastTabbableNode =
tabbableNodes.length > 0
? tabbableNodes[tabbableNodes.length - 1]
: void 0;
var firstDomTabbableNode = focusableNodes.find(function (node) {
return isTabbable(node);
});
2026-03-20 21:48:48 +05:30
var lastDomTabbableNode = focusableNodes
.slice()
.reverse()
.find(function (node) {
return isTabbable(node);
});
var posTabIndexesFound = !!tabbableNodes.find(function (node) {
return getTabIndex(node) > 0;
});
return {
container,
tabbableNodes,
focusableNodes,
/** True if at least one node with positive `tabindex` was found in this container. */
posTabIndexesFound,
/** First tabbable node in container, __tabindex__ order; `undefined` if none. */
firstTabbableNode,
/** Last tabbable node in container, __tabindex__ order; `undefined` if none. */
lastTabbableNode,
// NOTE: DOM order is NOT NECESSARILY "document position" order, but figuring that out
// would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
// because that API doesn't work with Shadow DOM as well as it should (@see
// https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,
// to address an edge case related to positive tabindex support, this seems like a much easier,
// "close enough most of the time" alternative for positive tabindexes which should generally
// be avoided anyway...
/** First tabbable node in container, __DOM__ order; `undefined` if none. */
firstDomTabbableNode,
/** Last tabbable node in container, __DOM__ order; `undefined` if none. */
lastDomTabbableNode,
/**
* Finds the __tabbable__ node that follows the given node in the specified direction,
* in this container, if any.
* @param {HTMLElement} node
* @param {boolean} [forward] True if going in forward tab order; false if going
* in reverse.
* @returns {HTMLElement|undefined} The next tabbable node, if any.
*/
nextTabbableNode: function nextTabbableNode(node) {
2026-03-20 21:48:48 +05:30
var forward =
arguments.length > 1 && arguments[1] !== void 0
? arguments[1]
: true;
var nodeIdx = tabbableNodes.indexOf(node);
if (nodeIdx < 0) {
if (forward) {
2026-03-20 21:48:48 +05:30
return focusableNodes
.slice(focusableNodes.indexOf(node) + 1)
.find(function (el) {
return isTabbable(el);
});
}
return focusableNodes
.slice(0, focusableNodes.indexOf(node))
.reverse()
.find(function (el) {
return isTabbable(el);
});
}
return tabbableNodes[nodeIdx + (forward ? 1 : -1)];
2026-03-20 21:48:48 +05:30
},
};
});
2026-03-20 21:48:48 +05:30
state.tabbableGroups = state.containerGroups.filter(function (group) {
return group.tabbableNodes.length > 0;
});
2026-03-20 21:48:48 +05:30
if (
state.tabbableGroups.length <= 0 &&
!getNodeForOption('fallbackFocus')
) {
throw new Error(
'Your focus-trap must have at least one container with at least one tabbable node in it at all times'
);
}
2026-03-20 21:48:48 +05:30
if (
state.containerGroups.find(function (g) {
return g.posTabIndexesFound;
}) &&
state.containerGroups.length > 1
) {
throw new Error(
"At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps."
);
}
};
var _getActiveElement = function getActiveElement(el) {
var activeElement = el.activeElement;
if (!activeElement) {
return;
}
2026-03-20 21:48:48 +05:30
if (
activeElement.shadowRoot &&
activeElement.shadowRoot.activeElement !== null
) {
return _getActiveElement(activeElement.shadowRoot);
}
return activeElement;
};
var _tryFocus = function tryFocus(node) {
if (node === false) {
return;
}
if (node === _getActiveElement(document)) {
return;
}
if (!node || !node.focus) {
_tryFocus(getInitialFocusNode());
return;
}
node.focus({
2026-03-20 21:48:48 +05:30
preventScroll: !!config.preventScroll,
});
state.mostRecentlyFocusedNode = node;
if (isSelectableInput(node)) {
node.select();
}
};
var getReturnFocusNode = function getReturnFocusNode2(previousActiveElement) {
2026-03-20 21:48:48 +05:30
var node = getNodeForOption('setReturnFocus', {
params: [previousActiveElement],
});
return node ? node : node === false ? false : previousActiveElement;
};
var findNextNavNode = function findNextNavNode2(_ref3) {
2026-03-20 21:48:48 +05:30
var target = _ref3.target,
event = _ref3.event,
_ref3$isBackward = _ref3.isBackward,
isBackward = _ref3$isBackward === void 0 ? false : _ref3$isBackward;
target = target || getActualTarget(event);
updateTabbableNodes();
var destinationNode = null;
if (state.tabbableGroups.length > 0) {
var containerIndex = findContainerIndex(target, event);
2026-03-20 21:48:48 +05:30
var containerGroup =
containerIndex >= 0 ? state.containerGroups[containerIndex] : void 0;
if (containerIndex < 0) {
if (isBackward) {
2026-03-20 21:48:48 +05:30
destinationNode =
state.tabbableGroups[state.tabbableGroups.length - 1]
.lastTabbableNode;
} else {
destinationNode = state.tabbableGroups[0].firstTabbableNode;
}
} else if (isBackward) {
2026-03-20 21:48:48 +05:30
var startOfGroupIndex = state.tabbableGroups.findIndex(
function (_ref4) {
var firstTabbableNode = _ref4.firstTabbableNode;
return target === firstTabbableNode;
}
);
if (
startOfGroupIndex < 0 &&
(containerGroup.container === target ||
(isFocusable(target, config.tabbableOptions) &&
!isTabbable(target, config.tabbableOptions) &&
!containerGroup.nextTabbableNode(target, false)))
) {
startOfGroupIndex = containerIndex;
}
if (startOfGroupIndex >= 0) {
2026-03-20 21:48:48 +05:30
var destinationGroupIndex =
startOfGroupIndex === 0
? state.tabbableGroups.length - 1
: startOfGroupIndex - 1;
var destinationGroup = state.tabbableGroups[destinationGroupIndex];
2026-03-20 21:48:48 +05:30
destinationNode =
getTabIndex(target) >= 0
? destinationGroup.lastTabbableNode
: destinationGroup.lastDomTabbableNode;
} else if (!isTabEvent(event)) {
destinationNode = containerGroup.nextTabbableNode(target, false);
}
} else {
2026-03-20 21:48:48 +05:30
var lastOfGroupIndex = state.tabbableGroups.findIndex(function (_ref5) {
var lastTabbableNode = _ref5.lastTabbableNode;
return target === lastTabbableNode;
});
2026-03-20 21:48:48 +05:30
if (
lastOfGroupIndex < 0 &&
(containerGroup.container === target ||
(isFocusable(target, config.tabbableOptions) &&
!isTabbable(target, config.tabbableOptions) &&
!containerGroup.nextTabbableNode(target)))
) {
lastOfGroupIndex = containerIndex;
}
if (lastOfGroupIndex >= 0) {
2026-03-20 21:48:48 +05:30
var _destinationGroupIndex =
lastOfGroupIndex === state.tabbableGroups.length - 1
? 0
: lastOfGroupIndex + 1;
var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
2026-03-20 21:48:48 +05:30
destinationNode =
getTabIndex(target) >= 0
? _destinationGroup.firstTabbableNode
: _destinationGroup.firstDomTabbableNode;
} else if (!isTabEvent(event)) {
destinationNode = containerGroup.nextTabbableNode(target);
}
}
} else {
2026-03-20 21:48:48 +05:30
destinationNode = getNodeForOption('fallbackFocus');
}
return destinationNode;
};
var checkPointerDown = function checkPointerDown2(e) {
var target = getActualTarget(e);
if (findContainerIndex(target, e) >= 0) {
return;
}
if (valueOrHandler(config.clickOutsideDeactivates, e)) {
trap.deactivate({
// NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
// which will result in the outside click setting focus to the node
// that was clicked (and if not focusable, to "nothing"); by setting
// `returnFocus: true`, we'll attempt to re-focus the node originally-focused
// on activation (or the configured `setReturnFocus` node), whether the
// outside click was on a focusable node or not
2026-03-20 21:48:48 +05:30
returnFocus: config.returnFocusOnDeactivate,
});
return;
}
if (valueOrHandler(config.allowOutsideClick, e)) {
return;
}
e.preventDefault();
};
var checkFocusIn = function checkFocusIn2(event) {
var target = getActualTarget(event);
var targetContained = findContainerIndex(target, event) >= 0;
if (targetContained || target instanceof Document) {
if (targetContained) {
state.mostRecentlyFocusedNode = target;
}
} else {
event.stopImmediatePropagation();
var nextNode;
var navAcrossContainers = true;
if (state.mostRecentlyFocusedNode) {
if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {
2026-03-20 21:48:48 +05:30
var mruContainerIdx = findContainerIndex(
state.mostRecentlyFocusedNode
);
var tabbableNodes =
state.containerGroups[mruContainerIdx].tabbableNodes;
if (tabbableNodes.length > 0) {
2026-03-20 21:48:48 +05:30
var mruTabIdx = tabbableNodes.findIndex(function (node) {
return node === state.mostRecentlyFocusedNode;
});
if (mruTabIdx >= 0) {
if (config.isKeyForward(state.recentNavEvent)) {
if (mruTabIdx + 1 < tabbableNodes.length) {
nextNode = tabbableNodes[mruTabIdx + 1];
navAcrossContainers = false;
}
} else {
if (mruTabIdx - 1 >= 0) {
nextNode = tabbableNodes[mruTabIdx - 1];
navAcrossContainers = false;
}
}
}
}
} else {
2026-03-20 21:48:48 +05:30
if (
!state.containerGroups.some(function (g) {
return g.tabbableNodes.some(function (n) {
return getTabIndex(n) > 0;
});
})
) {
navAcrossContainers = false;
}
}
} else {
navAcrossContainers = false;
}
if (navAcrossContainers) {
nextNode = findNextNavNode({
// move FROM the MRU node, not event-related node (which will be the node that is
// outside the trap causing the focus escape we're trying to fix)
target: state.mostRecentlyFocusedNode,
2026-03-20 21:48:48 +05:30
isBackward: config.isKeyBackward(state.recentNavEvent),
});
}
if (nextNode) {
_tryFocus(nextNode);
} else {
_tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
}
}
state.recentNavEvent = void 0;
};
var checkKeyNav = function checkKeyNav2(event) {
2026-03-20 21:48:48 +05:30
var isBackward =
arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
state.recentNavEvent = event;
var destinationNode = findNextNavNode({
event,
2026-03-20 21:48:48 +05:30
isBackward,
});
if (destinationNode) {
if (isTabEvent(event)) {
event.preventDefault();
}
_tryFocus(destinationNode);
}
};
var checkTabKey = function checkTabKey2(event) {
if (config.isKeyForward(event) || config.isKeyBackward(event)) {
checkKeyNav(event, config.isKeyBackward(event));
}
};
var checkEscapeKey = function checkEscapeKey2(event) {
2026-03-20 21:48:48 +05:30
if (
isEscapeEvent(event) &&
valueOrHandler(config.escapeDeactivates, event) !== false
) {
event.preventDefault();
trap.deactivate();
}
};
var checkClick = function checkClick2(e) {
var target = getActualTarget(e);
if (findContainerIndex(target, e) >= 0) {
return;
}
if (valueOrHandler(config.clickOutsideDeactivates, e)) {
return;
}
if (valueOrHandler(config.allowOutsideClick, e)) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
};
var addListeners = function addListeners2() {
if (!state.active) {
return;
}
activeFocusTraps.activateTrap(trapStack, trap);
2026-03-20 21:48:48 +05:30
state.delayInitialFocusTimer = config.delayInitialFocus
? delay(function () {
_tryFocus(getInitialFocusNode());
})
: _tryFocus(getInitialFocusNode());
doc.addEventListener('focusin', checkFocusIn, true);
doc.addEventListener('mousedown', checkPointerDown, {
capture: true,
2026-03-20 21:48:48 +05:30
passive: false,
});
2026-03-20 21:48:48 +05:30
doc.addEventListener('touchstart', checkPointerDown, {
capture: true,
2026-03-20 21:48:48 +05:30
passive: false,
});
2026-03-20 21:48:48 +05:30
doc.addEventListener('click', checkClick, {
capture: true,
2026-03-20 21:48:48 +05:30
passive: false,
});
2026-03-20 21:48:48 +05:30
doc.addEventListener('keydown', checkTabKey, {
capture: true,
2026-03-20 21:48:48 +05:30
passive: false,
});
2026-03-20 21:48:48 +05:30
doc.addEventListener('keydown', checkEscapeKey);
return trap;
};
var collectAdjacentElements = function collectAdjacentElements2(containers) {
if (state.active && !state.paused) {
trap._setSubtreeIsolation(false);
}
state.adjacentElements.clear();
state.alreadyInert.clear();
var containerAncestors = /* @__PURE__ */ new Set();
var adjacentElements = /* @__PURE__ */ new Set();
2026-03-20 21:48:48 +05:30
var _iterator = _createForOfIteratorHelper(containers),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
var container = _step.value;
containerAncestors.add(container);
2026-03-20 21:48:48 +05:30
var insideShadowRoot =
typeof ShadowRoot !== 'undefined' &&
container.getRootNode() instanceof ShadowRoot;
var current = container;
while (current) {
containerAncestors.add(current);
var parent = current.parentElement;
var siblings = [];
if (parent) {
siblings = parent.children;
} else if (!parent && insideShadowRoot) {
siblings = current.getRootNode().children;
parent = current.getRootNode().host;
2026-03-20 21:48:48 +05:30
insideShadowRoot =
typeof ShadowRoot !== 'undefined' &&
parent.getRootNode() instanceof ShadowRoot;
}
2026-03-20 21:48:48 +05:30
var _iterator2 = _createForOfIteratorHelper(siblings),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
var child = _step2.value;
adjacentElements.add(child);
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
current = parent;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
2026-03-20 21:48:48 +05:30
containerAncestors.forEach(function (el) {
adjacentElements['delete'](el);
});
state.adjacentElements = adjacentElements;
};
var removeListeners = function removeListeners2() {
if (!state.active) {
return;
}
2026-03-20 21:48:48 +05:30
doc.removeEventListener('focusin', checkFocusIn, true);
doc.removeEventListener('mousedown', checkPointerDown, true);
doc.removeEventListener('touchstart', checkPointerDown, true);
doc.removeEventListener('click', checkClick, true);
doc.removeEventListener('keydown', checkTabKey, true);
doc.removeEventListener('keydown', checkEscapeKey);
return trap;
};
var checkDomRemoval = function checkDomRemoval2(mutations) {
2026-03-20 21:48:48 +05:30
var isFocusedNodeRemoved = mutations.some(function (mutation) {
var removedNodes = Array.from(mutation.removedNodes);
2026-03-20 21:48:48 +05:30
return removedNodes.some(function (node) {
return node === state.mostRecentlyFocusedNode;
});
});
if (isFocusedNodeRemoved) {
_tryFocus(getInitialFocusNode());
}
};
2026-03-20 21:48:48 +05:30
var mutationObserver =
typeof window !== 'undefined' && 'MutationObserver' in window
? new MutationObserver(checkDomRemoval)
: void 0;
var updateObservedNodes = function updateObservedNodes2() {
if (!mutationObserver) {
return;
}
mutationObserver.disconnect();
if (state.active && !state.paused) {
2026-03-20 21:48:48 +05:30
state.containers.map(function (container) {
mutationObserver.observe(container, {
subtree: true,
2026-03-20 21:48:48 +05:30
childList: true,
});
});
}
};
trap = {
get active() {
return state.active;
},
get paused() {
return state.paused;
},
activate: function activate(activateOptions) {
if (state.active) {
return this;
}
2026-03-20 21:48:48 +05:30
var onActivate = getOption(activateOptions, 'onActivate');
var onPostActivate = getOption(activateOptions, 'onPostActivate');
var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
var preexistingTrap = activeFocusTraps.getActiveTrap(trapStack);
var revertState = false;
if (preexistingTrap && !preexistingTrap.paused) {
preexistingTrap._setSubtreeIsolation(false);
revertState = true;
}
try {
if (!checkCanFocusTrap) {
updateTabbableNodes();
}
state.active = true;
state.paused = false;
state.nodeFocusedBeforeActivation = _getActiveElement(doc);
onActivate === null || onActivate === void 0 || onActivate();
var finishActivation = function finishActivation2() {
if (checkCanFocusTrap) {
updateTabbableNodes();
}
addListeners();
updateObservedNodes();
if (config.isolateSubtrees) {
trap._setSubtreeIsolation(true);
}
2026-03-20 21:48:48 +05:30
onPostActivate === null ||
onPostActivate === void 0 ||
onPostActivate();
};
if (checkCanFocusTrap) {
2026-03-20 21:48:48 +05:30
checkCanFocusTrap(state.containers.concat()).then(
finishActivation,
finishActivation
);
return this;
}
finishActivation();
} catch (error) {
2026-03-20 21:48:48 +05:30
if (
preexistingTrap === activeFocusTraps.getActiveTrap(trapStack) &&
revertState
) {
preexistingTrap._setSubtreeIsolation(true);
}
throw error;
}
return this;
},
deactivate: function deactivate(deactivateOptions) {
if (!state.active) {
return this;
}
2026-03-20 21:48:48 +05:30
var options = _objectSpread2(
{
onDeactivate: config.onDeactivate,
onPostDeactivate: config.onPostDeactivate,
checkCanReturnFocus: config.checkCanReturnFocus,
},
deactivateOptions
);
clearTimeout(state.delayInitialFocusTimer);
state.delayInitialFocusTimer = void 0;
if (!state.paused) {
trap._setSubtreeIsolation(false);
}
state.alreadyInert.clear();
removeListeners();
state.active = false;
state.paused = false;
updateObservedNodes();
activeFocusTraps.deactivateTrap(trapStack, trap);
2026-03-20 21:48:48 +05:30
var onDeactivate = getOption(options, 'onDeactivate');
var onPostDeactivate = getOption(options, 'onPostDeactivate');
var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
var returnFocus = getOption(
options,
'returnFocus',
'returnFocusOnDeactivate'
);
onDeactivate === null || onDeactivate === void 0 || onDeactivate();
var finishDeactivation = function finishDeactivation2() {
2026-03-20 21:48:48 +05:30
delay(function () {
if (returnFocus) {
_tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
}
2026-03-20 21:48:48 +05:30
onPostDeactivate === null ||
onPostDeactivate === void 0 ||
onPostDeactivate();
});
};
if (returnFocus && checkCanReturnFocus) {
2026-03-20 21:48:48 +05:30
checkCanReturnFocus(
getReturnFocusNode(state.nodeFocusedBeforeActivation)
).then(finishDeactivation, finishDeactivation);
return this;
}
finishDeactivation();
return this;
},
pause: function pause(pauseOptions) {
if (!state.active) {
return this;
}
state.manuallyPaused = true;
return this._setPausedState(true, pauseOptions);
},
unpause: function unpause(unpauseOptions) {
if (!state.active) {
return this;
}
state.manuallyPaused = false;
if (trapStack[trapStack.length - 1] !== this) {
return this;
}
return this._setPausedState(false, unpauseOptions);
},
2026-03-20 21:48:48 +05:30
updateContainerElements: function updateContainerElements(
containerElements
) {
var elementsAsArray = [].concat(containerElements).filter(Boolean);
2026-03-20 21:48:48 +05:30
state.containers = elementsAsArray.map(function (element) {
return typeof element === 'string'
? doc.querySelector(element)
: element;
});
if (config.isolateSubtrees) {
collectAdjacentElements(state.containers);
}
if (state.active) {
updateTabbableNodes();
if (config.isolateSubtrees && !state.paused) {
trap._setSubtreeIsolation(true);
}
}
updateObservedNodes();
return this;
2026-03-20 21:48:48 +05:30
},
};
Object.defineProperties(trap, {
_isManuallyPaused: {
value: function value() {
return state.manuallyPaused;
2026-03-20 21:48:48 +05:30
},
},
_setPausedState: {
value: function value(paused, options) {
if (state.paused === paused) {
return this;
}
state.paused = paused;
if (paused) {
2026-03-20 21:48:48 +05:30
var onPause = getOption(options, 'onPause');
var onPostPause = getOption(options, 'onPostPause');
onPause === null || onPause === void 0 || onPause();
removeListeners();
updateObservedNodes();
trap._setSubtreeIsolation(false);
onPostPause === null || onPostPause === void 0 || onPostPause();
} else {
2026-03-20 21:48:48 +05:30
var onUnpause = getOption(options, 'onUnpause');
var onPostUnpause = getOption(options, 'onPostUnpause');
onUnpause === null || onUnpause === void 0 || onUnpause();
trap._setSubtreeIsolation(true);
updateTabbableNodes();
addListeners();
updateObservedNodes();
onPostUnpause === null || onPostUnpause === void 0 || onPostUnpause();
}
return this;
2026-03-20 21:48:48 +05:30
},
},
_setSubtreeIsolation: {
value: function value(isEnabled) {
if (config.isolateSubtrees) {
2026-03-20 21:48:48 +05:30
state.adjacentElements.forEach(function (el) {
if (isEnabled) {
2026-03-20 21:48:48 +05:30
var isInitiallyInert = el.inert || el.hasAttribute('inert');
if (isInitiallyInert) {
state.alreadyInert.add(el);
}
el.inert = true;
} else {
2026-03-20 21:48:48 +05:30
if (state.alreadyInert.has(el));
else {
el.inert = false;
}
}
});
}
2026-03-20 21:48:48 +05:30
},
},
});
trap.updateContainerElements(elements);
return trap;
};
// node_modules/@vueuse/integrations/useFocusTrap.mjs
function useFocusTrap(target, options = {}) {
let trap;
const { immediate, ...focusTrapOptions } = options;
const hasFocus = shallowRef(false);
const isPaused = shallowRef(false);
const activate = (opts) => trap && trap.activate(opts);
const deactivate = (opts) => trap && trap.deactivate(opts);
const pause = () => {
if (trap) {
trap.pause();
isPaused.value = true;
}
};
const unpause = () => {
if (trap) {
trap.unpause();
isPaused.value = false;
}
};
const targets = computed(() => {
const _targets = toValue(target);
2026-03-20 21:48:48 +05:30
return toArray(_targets)
.map((el) => {
const _el = toValue(el);
return typeof _el === 'string' ? _el : unrefElement(_el);
})
.filter(notNullish);
});
watch(
targets,
(els) => {
2026-03-20 21:48:48 +05:30
if (!els.length) return;
trap = createFocusTrap(els, {
...focusTrapOptions,
onActivate() {
hasFocus.value = true;
2026-03-20 21:48:48 +05:30
if (options.onActivate) options.onActivate();
},
onDeactivate() {
hasFocus.value = false;
2026-03-20 21:48:48 +05:30
if (options.onDeactivate) options.onDeactivate();
},
});
2026-03-20 21:48:48 +05:30
if (immediate) activate();
},
2026-03-20 21:48:48 +05:30
{ flush: 'post' }
);
tryOnScopeDispose(() => deactivate());
return {
hasFocus,
isPaused,
activate,
deactivate,
pause,
2026-03-20 21:48:48 +05:30
unpause,
};
}
2026-03-20 21:48:48 +05:30
export { useFocusTrap };
/*! Bundled license information:
tabbable/dist/index.esm.js:
(*!
2026-03-20 21:48:48 +05:30
* tabbable 6.4.0
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*)
focus-trap/dist/focus-trap.esm.js:
(*!
2026-03-20 21:48:48 +05:30
* focus-trap 7.7.1
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*)
*/
//# sourceMappingURL=vitepress___@vueuse_integrations_useFocusTrap.js.map