@alpinejs/focus
Advanced tools
Comparing version 3.12.3 to 3.13.0
536
dist/cdn.js
(() => { | ||
// node_modules/tabbable/dist/index.esm.js | ||
/*! | ||
* tabbable 5.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*/ | ||
var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"]; | ||
var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]:not(slot)", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"]; | ||
var candidateSelector = /* @__PURE__ */ candidateSelectors.join(","); | ||
var matches = typeof Element === "undefined" ? function() { | ||
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) { | ||
return element.getRootNode(); | ||
} : function(element) { | ||
return element.ownerDocument; | ||
}; | ||
var getCandidates = function getCandidates2(el, includeContainer, filter) { | ||
@@ -19,16 +21,50 @@ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector)); | ||
}; | ||
var isContentEditable = function isContentEditable2(node) { | ||
return node.contentEditable === "true"; | ||
var getCandidatesIteratively = function getCandidatesIteratively2(elements, includeContainer, options) { | ||
var candidates = []; | ||
var elementsToCheck = Array.from(elements); | ||
while (elementsToCheck.length) { | ||
var element = elementsToCheck.shift(); | ||
if (element.tagName === "SLOT") { | ||
var assigned = element.assignedElements(); | ||
var content = assigned.length ? assigned : element.children; | ||
var nestedCandidates = getCandidatesIteratively2(content, true, options); | ||
if (options.flatten) { | ||
candidates.push.apply(candidates, nestedCandidates); | ||
} else { | ||
candidates.push({ | ||
scope: element, | ||
candidates: nestedCandidates | ||
}); | ||
} | ||
} else { | ||
var validCandidate = matches.call(element, candidateSelector); | ||
if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) { | ||
candidates.push(element); | ||
} | ||
var shadowRoot = element.shadowRoot || // check for an undisclosed shadow | ||
typeof options.getShadowRoot === "function" && options.getShadowRoot(element); | ||
var validShadowRoot = !options.shadowRootFilter || options.shadowRootFilter(element); | ||
if (shadowRoot && validShadowRoot) { | ||
var _nestedCandidates = getCandidatesIteratively2(shadowRoot === true ? element.children : shadowRoot.children, true, options); | ||
if (options.flatten) { | ||
candidates.push.apply(candidates, _nestedCandidates); | ||
} else { | ||
candidates.push({ | ||
scope: element, | ||
candidates: _nestedCandidates | ||
}); | ||
} | ||
} else { | ||
elementsToCheck.unshift.apply(elementsToCheck, element.children); | ||
} | ||
} | ||
} | ||
return candidates; | ||
}; | ||
var getTabindex = function getTabindex2(node) { | ||
var tabindexAttr = parseInt(node.getAttribute("tabindex"), 10); | ||
if (!isNaN(tabindexAttr)) { | ||
return tabindexAttr; | ||
var getTabindex = function getTabindex2(node, isScope) { | ||
if (node.tabIndex < 0) { | ||
if ((isScope || /^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || node.isContentEditable) && isNaN(parseInt(node.getAttribute("tabindex"), 10))) { | ||
return 0; | ||
} | ||
} | ||
if (isContentEditable(node)) { | ||
return 0; | ||
} | ||
if ((node.nodeName === "AUDIO" || node.nodeName === "VIDEO" || node.nodeName === "DETAILS") && node.getAttribute("tabindex") === null) { | ||
return 0; | ||
} | ||
return node.tabIndex; | ||
@@ -62,3 +98,3 @@ }; | ||
} | ||
var radioScope = node.form || node.ownerDocument; | ||
var radioScope = node.form || getRootNode(node); | ||
var queryRadios = function queryRadios2(name) { | ||
@@ -87,3 +123,8 @@ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]'); | ||
}; | ||
var isHidden = function isHidden2(node, displayCheck) { | ||
var isZeroArea = function isZeroArea2(node) { | ||
var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height; | ||
return width === 0 && height === 0; | ||
}; | ||
var isHidden = function isHidden2(node, _ref) { | ||
var displayCheck = _ref.displayCheck, getShadowRoot = _ref.getShadowRoot; | ||
if (getComputedStyle(node).visibility === "hidden") { | ||
@@ -97,12 +138,27 @@ return true; | ||
} | ||
var nodeRootHost = getRootNode(node).host; | ||
var nodeIsAttached = (nodeRootHost === null || nodeRootHost === void 0 ? void 0 : nodeRootHost.ownerDocument.contains(nodeRootHost)) || node.ownerDocument.contains(node); | ||
if (!displayCheck || displayCheck === "full") { | ||
while (node) { | ||
if (getComputedStyle(node).display === "none") { | ||
return true; | ||
if (typeof getShadowRoot === "function") { | ||
var originalNode = node; | ||
while (node) { | ||
var parentElement = node.parentElement; | ||
var rootNode = getRootNode(node); | ||
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 = node.parentElement; | ||
node = originalNode; | ||
} | ||
if (nodeIsAttached) { | ||
return !node.getClientRects().length; | ||
} | ||
} else if (displayCheck === "non-zero-area") { | ||
var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height; | ||
return width === 0 && height === 0; | ||
return isZeroArea(node); | ||
} | ||
@@ -112,3 +168,3 @@ return false; | ||
var isDisabledFromFieldset = function isDisabledFromFieldset2(node) { | ||
if (isInput(node) || node.tagName === "SELECT" || node.tagName === "TEXTAREA" || node.tagName === "BUTTON") { | ||
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) { | ||
var parentNode = node.parentElement; | ||
@@ -120,6 +176,3 @@ while (parentNode) { | ||
if (child.tagName === "LEGEND") { | ||
if (child.contains(node)) { | ||
return false; | ||
} | ||
return true; | ||
return matches.call(parentNode, "fieldset[disabled] *") ? true : !child.contains(node); | ||
} | ||
@@ -135,3 +188,4 @@ } | ||
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable2(options, node) { | ||
if (node.disabled || isHiddenInput(node) || isHidden(node, options.displayCheck) || isDetailsWithSummary(node) || isDisabledFromFieldset(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; | ||
@@ -142,3 +196,3 @@ } | ||
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(options, node) { | ||
if (!isNodeMatchingSelectorFocusable(options, node) || isNonTabbableRadio(node) || getTabindex(node) < 0) { | ||
if (isNonTabbableRadio(node) || getTabindex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) { | ||
return false; | ||
@@ -148,11 +202,19 @@ } | ||
}; | ||
var tabbable = function tabbable2(el, options) { | ||
options = options || {}; | ||
var isValidShadowRootTabbable = function isValidShadowRootTabbable2(shadowHostNode) { | ||
var tabIndex = parseInt(shadowHostNode.getAttribute("tabindex"), 10); | ||
if (isNaN(tabIndex) || tabIndex >= 0) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
var sortByOrder = function sortByOrder2(candidates) { | ||
var regularTabbables = []; | ||
var orderedTabbables = []; | ||
var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options)); | ||
candidates.forEach(function(candidate, i) { | ||
var candidateTabindex = getTabindex(candidate); | ||
candidates.forEach(function(item, i) { | ||
var isScope = !!item.scope; | ||
var element = isScope ? item.scope : item; | ||
var candidateTabindex = getTabindex(element, isScope); | ||
var elements = isScope ? sortByOrder2(item.candidates) : element; | ||
if (candidateTabindex === 0) { | ||
regularTabbables.push(candidate); | ||
isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element); | ||
} else { | ||
@@ -162,16 +224,52 @@ orderedTabbables.push({ | ||
tabIndex: candidateTabindex, | ||
node: candidate | ||
item, | ||
isScope, | ||
content: elements | ||
}); | ||
} | ||
}); | ||
var tabbableNodes = orderedTabbables.sort(sortOrderedTabbables).map(function(a) { | ||
return a.node; | ||
}).concat(regularTabbables); | ||
return tabbableNodes; | ||
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(el, options) { | ||
options = options || {}; | ||
var candidates; | ||
if (options.getShadowRoot) { | ||
candidates = getCandidatesIteratively([el], options.includeContainer, { | ||
filter: isNodeMatchingSelectorTabbable.bind(null, options), | ||
flatten: false, | ||
getShadowRoot: options.getShadowRoot, | ||
shadowRootFilter: isValidShadowRootTabbable | ||
}); | ||
} else { | ||
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options)); | ||
} | ||
return sortByOrder(candidates); | ||
}; | ||
var focusable = function focusable2(el, options) { | ||
options = options || {}; | ||
var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options)); | ||
var candidates; | ||
if (options.getShadowRoot) { | ||
candidates = getCandidatesIteratively([el], options.includeContainer, { | ||
filter: isNodeMatchingSelectorFocusable.bind(null, options), | ||
flatten: true, | ||
getShadowRoot: options.getShadowRoot | ||
}); | ||
} else { | ||
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options)); | ||
} | ||
return candidates; | ||
}; | ||
var isTabbable = function isTabbable2(node, options) { | ||
options = options || {}; | ||
if (!node) { | ||
throw new Error("No node provided"); | ||
} | ||
if (matches.call(node, candidateSelector) === false) { | ||
return false; | ||
} | ||
return isNodeMatchingSelectorTabbable(options, node); | ||
}; | ||
var focusableCandidateSelector = /* @__PURE__ */ candidateSelectors.concat("iframe").join(","); | ||
@@ -190,6 +288,2 @@ var isFocusable = function isFocusable2(node, options) { | ||
// node_modules/focus-trap/dist/focus-trap.esm.js | ||
/*! | ||
* focus-trap 6.6.1 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*/ | ||
function ownKeys(object, enumerableOnly) { | ||
@@ -199,8 +293,5 @@ var keys = Object.keys(object); | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
enumerableOnly && (symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
@@ -211,14 +302,8 @@ return keys; | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
@@ -298,4 +383,7 @@ return target; | ||
}; | ||
var getActualTarget = function getActualTarget2(event) { | ||
return event.target.shadowRoot && typeof event.composedPath === "function" ? event.composedPath()[0] : event.target; | ||
}; | ||
var createFocusTrap = function createFocusTrap2(elements, userOptions) { | ||
var doc = document; | ||
var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document; | ||
var config = _objectSpread2({ | ||
@@ -307,3 +395,24 @@ returnFocusOnDeactivate: true, | ||
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 | ||
// firstTabbableNode: HTMLElement|null, | ||
// lastTabbableNode: HTMLElement|null, | ||
// 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: [], | ||
@@ -314,2 +423,4 @@ nodeFocusedBeforeActivation: null, | ||
paused: false, | ||
// timer ID for when delayInitialFocus is true and initial focus in this trap | ||
// has been delayed during activation | ||
delayInitialFocusTimer: void 0 | ||
@@ -321,5 +432,12 @@ }; | ||
}; | ||
var containersContain = function containersContain2(element) { | ||
return state.containers.some(function(container) { | ||
return container.contains(element); | ||
var findContainerIndex = function findContainerIndex2(element) { | ||
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) | ||
tabbableNodes.find(function(node) { | ||
return node === element; | ||
}); | ||
}); | ||
@@ -329,4 +447,16 @@ }; | ||
var optionValue = config[optionName]; | ||
if (typeof optionValue === "function") { | ||
for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
params[_key2 - 1] = arguments[_key2]; | ||
} | ||
optionValue = optionValue.apply(void 0, params); | ||
} | ||
if (optionValue === true) { | ||
optionValue = void 0; | ||
} | ||
if (!optionValue) { | ||
return null; | ||
if (optionValue === void 0 || optionValue === false) { | ||
return optionValue; | ||
} | ||
throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node")); | ||
} | ||
@@ -337,26 +467,20 @@ var node = optionValue; | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` refers to no known node")); | ||
throw new Error("`".concat(optionName, "` as selector refers to no known node")); | ||
} | ||
} | ||
if (typeof optionValue === "function") { | ||
node = optionValue(); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` did not return a node")); | ||
} | ||
} | ||
return node; | ||
}; | ||
var getInitialFocusNode = function getInitialFocusNode2() { | ||
var node; | ||
if (getOption({}, "initialFocus") === false) { | ||
var node = getNodeForOption("initialFocus"); | ||
if (node === false) { | ||
return false; | ||
} | ||
if (getNodeForOption("initialFocus") !== null) { | ||
node = getNodeForOption("initialFocus"); | ||
} else if (containersContain(doc.activeElement)) { | ||
node = doc.activeElement; | ||
} else { | ||
var firstTabbableGroup = state.tabbableGroups[0]; | ||
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; | ||
node = firstTabbableNode || getNodeForOption("fallbackFocus"); | ||
if (node === void 0) { | ||
if (findContainerIndex(doc.activeElement) >= 0) { | ||
node = doc.activeElement; | ||
} else { | ||
var firstTabbableGroup = state.tabbableGroups[0]; | ||
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; | ||
node = firstTabbableNode || getNodeForOption("fallbackFocus"); | ||
} | ||
} | ||
@@ -369,15 +493,41 @@ if (!node) { | ||
var updateTabbableNodes = function updateTabbableNodes2() { | ||
state.tabbableGroups = state.containers.map(function(container) { | ||
var tabbableNodes = tabbable(container); | ||
if (tabbableNodes.length > 0) { | ||
return { | ||
container, | ||
firstTabbableNode: tabbableNodes[0], | ||
lastTabbableNode: tabbableNodes[tabbableNodes.length - 1] | ||
}; | ||
} | ||
return void 0; | ||
}).filter(function(group) { | ||
return !!group; | ||
state.containerGroups = state.containers.map(function(container) { | ||
var tabbableNodes = tabbable(container, config.tabbableOptions); | ||
var focusableNodes = focusable(container, config.tabbableOptions); | ||
return { | ||
container, | ||
tabbableNodes, | ||
focusableNodes, | ||
firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null, | ||
lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null, | ||
/** | ||
* 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) { | ||
var forward = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true; | ||
var nodeIdx = focusableNodes.findIndex(function(n) { | ||
return n === node; | ||
}); | ||
if (nodeIdx < 0) { | ||
return void 0; | ||
} | ||
if (forward) { | ||
return focusableNodes.slice(nodeIdx + 1).find(function(n) { | ||
return isTabbable(n, config.tabbableOptions); | ||
}); | ||
} | ||
return focusableNodes.slice(0, nodeIdx).reverse().find(function(n) { | ||
return isTabbable(n, config.tabbableOptions); | ||
}); | ||
} | ||
}; | ||
}); | ||
state.tabbableGroups = state.containerGroups.filter(function(group) { | ||
return group.tabbableNodes.length > 0; | ||
}); | ||
if (state.tabbableGroups.length <= 0 && !getNodeForOption("fallbackFocus")) { | ||
@@ -407,7 +557,8 @@ throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times"); | ||
var getReturnFocusNode = function getReturnFocusNode2(previousActiveElement) { | ||
var node = getNodeForOption("setReturnFocus"); | ||
return node ? node : previousActiveElement; | ||
var node = getNodeForOption("setReturnFocus", previousActiveElement); | ||
return node ? node : node === false ? false : previousActiveElement; | ||
}; | ||
var checkPointerDown = function checkPointerDown2(e) { | ||
if (containersContain(e.target)) { | ||
var target = getActualTarget(e); | ||
if (findContainerIndex(target) >= 0) { | ||
return; | ||
@@ -417,3 +568,14 @@ } | ||
trap.deactivate({ | ||
returnFocus: config.returnFocusOnDeactivate && !isFocusable(e.target) | ||
// if, on deactivation, we should return focus to the node originally-focused | ||
// when the trap was activated (or the configured `setReturnFocus` node), | ||
// then assume it's also OK to return focus to the outside node that was | ||
// just clicked, causing deactivation, as long as that node is focusable; | ||
// if it isn't focusable, then return focus to the original node focused | ||
// on activation (or the configured `setReturnFocus` node) | ||
// NOTE: by setting `returnFocus: false`, deactivate() will do nothing, | ||
// which will result in the outside click setting focus to the node | ||
// that was clicked, whether it's focusable or not; by setting | ||
// `returnFocus: true`, we'll attempt to re-focus the node originally-focused | ||
// on activation (or the configured `setReturnFocus` node) | ||
returnFocus: config.returnFocusOnDeactivate && !isFocusable(target, config.tabbableOptions) | ||
}); | ||
@@ -428,6 +590,7 @@ return; | ||
var checkFocusIn = function checkFocusIn2(e) { | ||
var targetContained = containersContain(e.target); | ||
if (targetContained || e.target instanceof Document) { | ||
var target = getActualTarget(e); | ||
var targetContained = findContainerIndex(target) >= 0; | ||
if (targetContained || target instanceof Document) { | ||
if (targetContained) { | ||
state.mostRecentlyFocusedNode = e.target; | ||
state.mostRecentlyFocusedNode = target; | ||
} | ||
@@ -440,9 +603,8 @@ } else { | ||
var checkTab = function checkTab2(e) { | ||
var target = getActualTarget(e); | ||
updateTabbableNodes(); | ||
var destinationNode = null; | ||
if (state.tabbableGroups.length > 0) { | ||
var containerIndex = findIndex(state.tabbableGroups, function(_ref) { | ||
var container = _ref.container; | ||
return container.contains(e.target); | ||
}); | ||
var containerIndex = findContainerIndex(target); | ||
var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : void 0; | ||
if (containerIndex < 0) { | ||
@@ -457,5 +619,5 @@ if (e.shiftKey) { | ||
var firstTabbableNode = _ref2.firstTabbableNode; | ||
return e.target === firstTabbableNode; | ||
return target === firstTabbableNode; | ||
}); | ||
if (startOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) { | ||
if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) { | ||
startOfGroupIndex = containerIndex; | ||
@@ -471,5 +633,5 @@ } | ||
var lastTabbableNode = _ref3.lastTabbableNode; | ||
return e.target === lastTabbableNode; | ||
return target === lastTabbableNode; | ||
}); | ||
if (lastOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) { | ||
if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) { | ||
lastOfGroupIndex = containerIndex; | ||
@@ -492,3 +654,3 @@ } | ||
var checkKey = function checkKey2(e) { | ||
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates) !== false) { | ||
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) { | ||
e.preventDefault(); | ||
@@ -504,6 +666,7 @@ trap.deactivate(); | ||
var checkClick = function checkClick2(e) { | ||
if (valueOrHandler(config.clickOutsideDeactivates, e)) { | ||
var target = getActualTarget(e); | ||
if (findContainerIndex(target) >= 0) { | ||
return; | ||
} | ||
if (containersContain(e.target)) { | ||
if (valueOrHandler(config.clickOutsideDeactivates, e)) { | ||
return; | ||
@@ -556,2 +719,8 @@ } | ||
trap = { | ||
get active() { | ||
return state.active; | ||
}, | ||
get paused() { | ||
return state.paused; | ||
}, | ||
activate: function activate(activateOptions) { | ||
@@ -593,2 +762,7 @@ if (state.active) { | ||
} | ||
var options = _objectSpread2({ | ||
onDeactivate: config.onDeactivate, | ||
onPostDeactivate: config.onPostDeactivate, | ||
checkCanReturnFocus: config.checkCanReturnFocus | ||
}, deactivateOptions); | ||
clearTimeout(state.delayInitialFocusTimer); | ||
@@ -600,9 +774,9 @@ state.delayInitialFocusTimer = void 0; | ||
activeFocusTraps.deactivateTrap(trap); | ||
var onDeactivate = getOption(deactivateOptions, "onDeactivate"); | ||
var onPostDeactivate = getOption(deactivateOptions, "onPostDeactivate"); | ||
var checkCanReturnFocus = getOption(deactivateOptions, "checkCanReturnFocus"); | ||
var onDeactivate = getOption(options, "onDeactivate"); | ||
var onPostDeactivate = getOption(options, "onPostDeactivate"); | ||
var checkCanReturnFocus = getOption(options, "checkCanReturnFocus"); | ||
var returnFocus = getOption(options, "returnFocus", "returnFocusOnDeactivate"); | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
} | ||
var returnFocus = getOption(deactivateOptions, "returnFocus", "returnFocusOnDeactivate"); | ||
var finishDeactivation = function finishDeactivation2() { | ||
@@ -704,3 +878,3 @@ delay(function() { | ||
return within; | ||
return focusable(within, {displayCheck: "none"}); | ||
return focusable(within, { displayCheck: "none" }); | ||
}, | ||
@@ -765,3 +939,3 @@ all() { | ||
el2.setAttribute("tabindex", "0"); | ||
el2.focus({preventScroll: this._noscroll}); | ||
el2.focus({ preventScroll: this._noscroll }); | ||
}); | ||
@@ -771,51 +945,57 @@ } | ||
}); | ||
Alpine.directive("trap", Alpine.skipDuringClone((el, {expression, modifiers}, {effect, evaluateLater, cleanup}) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let options = { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el | ||
}; | ||
let autofocusEl = el.querySelector("[autofocus]"); | ||
if (autofocusEl) | ||
options.initialFocus = autofocusEl; | ||
let trap = createFocusTrap(el, options); | ||
let undoInert = () => { | ||
}; | ||
let undoDisableScrolling = () => { | ||
}; | ||
const releaseFocus = () => { | ||
undoInert(); | ||
undoInert = () => { | ||
Alpine.directive("trap", Alpine.skipDuringClone( | ||
(el, { expression, modifiers }, { effect, evaluateLater, cleanup }) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let options = { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
let autofocusEl = el.querySelector("[autofocus]"); | ||
if (autofocusEl) | ||
options.initialFocus = autofocusEl; | ||
let trap = createFocusTrap(el, options); | ||
let undoInert = () => { | ||
}; | ||
trap.deactivate({ | ||
returnFocus: !modifiers.includes("noreturn") | ||
}); | ||
}; | ||
effect(() => evaluator((value) => { | ||
if (oldValue === value) | ||
return; | ||
if (value && !oldValue) { | ||
setTimeout(() => { | ||
if (modifiers.includes("inert")) | ||
undoInert = setInert(el); | ||
if (modifiers.includes("noscroll")) | ||
undoDisableScrolling = disableScrolling(); | ||
trap.activate(); | ||
let undoDisableScrolling = () => { | ||
}; | ||
const releaseFocus = () => { | ||
undoInert(); | ||
undoInert = () => { | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
}; | ||
trap.deactivate({ | ||
returnFocus: !modifiers.includes("noreturn") | ||
}); | ||
} | ||
if (!value && oldValue) { | ||
releaseFocus(); | ||
} | ||
oldValue = !!value; | ||
})); | ||
cleanup(releaseFocus); | ||
}, (el, {expression, modifiers}, {evaluate}) => { | ||
if (modifiers.includes("inert") && evaluate(expression)) | ||
setInert(el); | ||
})); | ||
}; | ||
effect(() => evaluator((value) => { | ||
if (oldValue === value) | ||
return; | ||
if (value && !oldValue) { | ||
setTimeout(() => { | ||
if (modifiers.includes("inert")) | ||
undoInert = setInert(el); | ||
if (modifiers.includes("noscroll")) | ||
undoDisableScrolling = disableScrolling(); | ||
trap.activate(); | ||
}); | ||
} | ||
if (!value && oldValue) { | ||
releaseFocus(); | ||
} | ||
oldValue = !!value; | ||
})); | ||
cleanup(releaseFocus); | ||
}, | ||
// When cloning, we only want to add aria-hidden attributes to the | ||
// DOM and not try to actually trap, as trapping can mess with the | ||
// live DOM and isn't just isolated to the cloned DOM. | ||
(el, { expression, modifiers }, { evaluate }) => { | ||
if (modifiers.includes("inert") && evaluate(expression)) | ||
setInert(el); | ||
} | ||
)); | ||
} | ||
@@ -862,1 +1042,15 @@ function setInert(el) { | ||
})(); | ||
/*! Bundled license information: | ||
tabbable/dist/index.esm.js: | ||
(*! | ||
* tabbable 5.3.3 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.esm.js: | ||
(*! | ||
* focus-trap 6.9.4 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*) | ||
*/ |
@@ -1,9 +0,15 @@ | ||
(()=>{var _=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details"],G=_.join(","),C=typeof Element=="undefined"?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,M=function(e,t,a){var u=Array.prototype.slice.apply(e.querySelectorAll(G));return t&&C.call(e,G)&&u.unshift(e),u=u.filter(a),u},Z=function(e){return e.contentEditable==="true"},q=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return isNaN(t)?Z(e)||(e.nodeName==="AUDIO"||e.nodeName==="VIDEO"||e.nodeName==="DETAILS")&&e.getAttribute("tabindex")===null?0:e.tabIndex:t},$=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},L=function(e){return e.tagName==="INPUT"},ee=function(e){return L(e)&&e.type==="hidden"},te=function(e){var t=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(a){return a.tagName==="SUMMARY"});return t},re=function(e,t){for(var a=0;a<e.length;a++)if(e[a].checked&&e[a].form===t)return e[a]},ae=function(e){if(!e.name)return!0;var t=e.form||e.ownerDocument,a=function(l){return t.querySelectorAll('input[type="radio"][name="'+l+'"]')},u;if(typeof window!="undefined"&&typeof window.CSS!="undefined"&&typeof window.CSS.escape=="function")u=a(window.CSS.escape(e.name));else try{u=a(e.name)}catch(s){return 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",s.message),!1}var r=re(u,e.form);return!r||r===e},ne=function(e){return L(e)&&e.type==="radio"},ie=function(e){return ne(e)&&!ae(e)},ue=function(e,t){if(getComputedStyle(e).visibility==="hidden")return!0;var a=C.call(e,"details>summary:first-of-type"),u=a?e.parentElement:e;if(C.call(u,"details:not([open]) *"))return!0;if(!t||t==="full")for(;e;){if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}else if(t==="non-zero-area"){var r=e.getBoundingClientRect(),s=r.width,l=r.height;return s===0&&l===0}return!1},oe=function(e){if(L(e)||e.tagName==="SELECT"||e.tagName==="TEXTAREA"||e.tagName==="BUTTON")for(var t=e.parentElement;t;){if(t.tagName==="FIELDSET"&&t.disabled){for(var a=0;a<t.children.length;a++){var u=t.children.item(a);if(u.tagName==="LEGEND")return!u.contains(e)}return!0}t=t.parentElement}return!1},R=function(e,t){return!(t.disabled||ee(t)||ue(t,e.displayCheck)||te(t)||oe(t))},se=function(e,t){return!(!R(e,t)||ie(t)||q(t)<0)},W=function(e,t){t=t||{};var a=[],u=[],r=M(e,t.includeContainer,se.bind(null,t));r.forEach(function(l,p){var b=q(l);b===0?a.push(l):u.push({documentOrder:p,tabIndex:b,node:l})});var s=u.sort($).map(function(l){return l.node}).concat(a);return s},B=function(e,t){t=t||{};var a=M(e,t.includeContainer,R.bind(null,t));return a};var ce=_.concat("iframe").join(","),O=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return C.call(e,ce)===!1?!1:R(t,e)};function H(i,e){var t=Object.keys(i);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(i);e&&(a=a.filter(function(u){return Object.getOwnPropertyDescriptor(i,u).enumerable})),t.push.apply(t,a)}return t}function fe(i){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?H(Object(t),!0).forEach(function(a){le(i,a,t[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(t)):H(Object(t)).forEach(function(a){Object.defineProperty(i,a,Object.getOwnPropertyDescriptor(t,a))})}return i}function le(i,e,t){return e in i?Object.defineProperty(i,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):i[e]=t,i}var U=function(){var i=[];return{activateTrap:function(t){if(i.length>0){var a=i[i.length-1];a!==t&&a.pause()}var u=i.indexOf(t);u===-1||i.splice(u,1),i.push(t)},deactivateTrap:function(t){var a=i.indexOf(t);a!==-1&&i.splice(a,1),i.length>0&&i[i.length-1].unpause()}}}(),de=function(e){return e.tagName&&e.tagName.toLowerCase()==="input"&&typeof e.select=="function"},be=function(e){return e.key==="Escape"||e.key==="Esc"||e.keyCode===27},ve=function(e){return e.key==="Tab"||e.keyCode===9},K=function(e){return setTimeout(e,0)},x=function(e,t){var a=-1;return e.every(function(u,r){return t(u)?(a=r,!1):!0}),a},A=function(e){for(var t=arguments.length,a=new Array(t>1?t-1:0),u=1;u<t;u++)a[u-1]=arguments[u];return typeof e=="function"?e.apply(void 0,a):e},V=function(e,t){var a=document,u=fe({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},t),r={containers:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},s,l=function(n,o,c){return n&&n[o]!==void 0?n[o]:u[c||o]},p=function(n){return r.containers.some(function(o){return o.contains(n)})},b=function(n){var o=u[n];if(!o)return null;var c=o;if(typeof o=="string"&&(c=a.querySelector(o),!c))throw new Error("`".concat(n,"` refers to no known node"));if(typeof o=="function"&&(c=o(),!c))throw new Error("`".concat(n,"` did not return a node"));return c},v=function(){var n;if(l({},"initialFocus")===!1)return!1;if(b("initialFocus")!==null)n=b("initialFocus");else if(p(a.activeElement))n=a.activeElement;else{var o=r.tabbableGroups[0],c=o&&o.firstTabbableNode;n=c||b("fallbackFocus")}if(!n)throw new Error("Your focus-trap needs to have at least one focusable element");return n},h=function(){if(r.tabbableGroups=r.containers.map(function(n){var o=W(n);if(o.length>0)return{container:n,firstTabbableNode:o[0],lastTabbableNode:o[o.length-1]}}).filter(function(n){return!!n}),r.tabbableGroups.length<=0&&!b("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},m=function f(n){if(n!==!1&&n!==a.activeElement){if(!n||!n.focus){f(v());return}n.focus({preventScroll:!!u.preventScroll}),r.mostRecentlyFocusedNode=n,de(n)&&n.select()}},S=function(n){var o=b("setReturnFocus");return o||n},g=function(n){if(!p(n.target)){if(A(u.clickOutsideDeactivates,n)){s.deactivate({returnFocus:u.returnFocusOnDeactivate&&!O(n.target)});return}A(u.allowOutsideClick,n)||n.preventDefault()}},w=function(n){var o=p(n.target);o||n.target instanceof Document?o&&(r.mostRecentlyFocusedNode=n.target):(n.stopImmediatePropagation(),m(r.mostRecentlyFocusedNode||v()))},k=function(n){h();var o=null;if(r.tabbableGroups.length>0){var c=x(r.tabbableGroups,function(N){var D=N.container;return D.contains(n.target)});if(c<0)n.shiftKey?o=r.tabbableGroups[r.tabbableGroups.length-1].lastTabbableNode:o=r.tabbableGroups[0].firstTabbableNode;else if(n.shiftKey){var d=x(r.tabbableGroups,function(N){var D=N.firstTabbableNode;return n.target===D});if(d<0&&r.tabbableGroups[c].container===n.target&&(d=c),d>=0){var y=d===0?r.tabbableGroups.length-1:d-1,F=r.tabbableGroups[y];o=F.lastTabbableNode}}else{var T=x(r.tabbableGroups,function(N){var D=N.lastTabbableNode;return n.target===D});if(T<0&&r.tabbableGroups[c].container===n.target&&(T=c),T>=0){var X=T===r.tabbableGroups.length-1?0:T+1,J=r.tabbableGroups[X];o=J.firstTabbableNode}}}else o=b("fallbackFocus");o&&(n.preventDefault(),m(o))},E=function(n){if(be(n)&&A(u.escapeDeactivates)!==!1){n.preventDefault(),s.deactivate();return}if(ve(n)){k(n);return}},I=function(n){A(u.clickOutsideDeactivates,n)||p(n.target)||A(u.allowOutsideClick,n)||(n.preventDefault(),n.stopImmediatePropagation())},P=function(){if(!!r.active)return U.activateTrap(s),r.delayInitialFocusTimer=u.delayInitialFocus?K(function(){m(v())}):m(v()),a.addEventListener("focusin",w,!0),a.addEventListener("mousedown",g,{capture:!0,passive:!1}),a.addEventListener("touchstart",g,{capture:!0,passive:!1}),a.addEventListener("click",I,{capture:!0,passive:!1}),a.addEventListener("keydown",E,{capture:!0,passive:!1}),s},j=function(){if(!!r.active)return a.removeEventListener("focusin",w,!0),a.removeEventListener("mousedown",g,!0),a.removeEventListener("touchstart",g,!0),a.removeEventListener("click",I,!0),a.removeEventListener("keydown",E,!0),s};return s={activate:function(n){if(r.active)return this;var o=l(n,"onActivate"),c=l(n,"onPostActivate"),d=l(n,"checkCanFocusTrap");d||h(),r.active=!0,r.paused=!1,r.nodeFocusedBeforeActivation=a.activeElement,o&&o();var y=function(){d&&h(),P(),c&&c()};return d?(d(r.containers.concat()).then(y,y),this):(y(),this)},deactivate:function(n){if(!r.active)return this;clearTimeout(r.delayInitialFocusTimer),r.delayInitialFocusTimer=void 0,j(),r.active=!1,r.paused=!1,U.deactivateTrap(s);var o=l(n,"onDeactivate"),c=l(n,"onPostDeactivate"),d=l(n,"checkCanReturnFocus");o&&o();var y=l(n,"returnFocus","returnFocusOnDeactivate"),F=function(){K(function(){y&&m(S(r.nodeFocusedBeforeActivation)),c&&c()})};return y&&d?(d(S(r.nodeFocusedBeforeActivation)).then(F,F),this):(F(),this)},pause:function(){return r.paused||!r.active?this:(r.paused=!0,j(),this)},unpause:function(){return!r.paused||!r.active?this:(r.paused=!1,h(),P(),this)},updateContainerElements:function(n){var o=[].concat(n).filter(Boolean);return r.containers=o.map(function(c){return typeof c=="string"?a.querySelector(c):c}),r.active&&h(),this}},s.updateContainerElements(e),s};function z(i){let e,t;window.addEventListener("focusin",()=>{e=t,t=document.activeElement}),i.magic("focus",a=>{let u=a;return{__noscroll:!1,__wrapAround:!1,within(r){return u=r,this},withoutScrolling(){return this.__noscroll=!0,this},noscroll(){return this.__noscroll=!0,this},withWrapAround(){return this.__wrapAround=!0,this},wrap(){return this.withWrapAround()},focusable(r){return O(r)},previouslyFocused(){return e},lastFocused(){return e},focused(){return t},focusables(){return Array.isArray(u)?u:B(u,{displayCheck:"none"})},all(){return this.focusables()},isFirst(r){let s=this.all();return s[0]&&s[0].isSameNode(r)},isLast(r){let s=this.all();return s.length&&s.slice(-1)[0].isSameNode(r)},getFirst(){return this.all()[0]},getLast(){return this.all().slice(-1)[0]},getNext(){let r=this.all(),s=document.activeElement;if(r.indexOf(s)!==-1)return this.__wrapAround&&r.indexOf(s)===r.length-1?r[0]:r[r.indexOf(s)+1]},getPrevious(){let r=this.all(),s=document.activeElement;if(r.indexOf(s)!==-1)return this.__wrapAround&&r.indexOf(s)===0?r.slice(-1)[0]:r[r.indexOf(s)-1]},first(){this.focus(this.getFirst())},last(){this.focus(this.getLast())},next(){this.focus(this.getNext())},previous(){this.focus(this.getPrevious())},prev(){return this.previous()},focus(r){!r||setTimeout(()=>{r.hasAttribute("tabindex")||r.setAttribute("tabindex","0"),r.focus({preventScroll:this._noscroll})})}}}),i.directive("trap",i.skipDuringClone((a,{expression:u,modifiers:r},{effect:s,evaluateLater:l,cleanup:p})=>{let b=l(u),v=!1,h={escapeDeactivates:!1,allowOutsideClick:!0,fallbackFocus:()=>a},m=a.querySelector("[autofocus]");m&&(h.initialFocus=m);let S=V(a,h),g=()=>{},w=()=>{},k=()=>{g(),g=()=>{},w(),w=()=>{},S.deactivate({returnFocus:!r.includes("noreturn")})};s(()=>b(E=>{v!==E&&(E&&!v&&setTimeout(()=>{r.includes("inert")&&(g=Y(a)),r.includes("noscroll")&&(w=pe()),S.activate()}),!E&&v&&k(),v=!!E)})),p(k)},(a,{expression:u,modifiers:r},{evaluate:s})=>{r.includes("inert")&&s(u)&&Y(a)}))}function Y(i){let e=[];return Q(i,t=>{let a=t.hasAttribute("aria-hidden");t.setAttribute("aria-hidden","true"),e.push(()=>a||t.removeAttribute("aria-hidden"))}),()=>{for(;e.length;)e.pop()()}}function Q(i,e){i.isSameNode(document.body)||!i.parentNode||Array.from(i.parentNode.children).forEach(t=>{t.isSameNode(i)?Q(i.parentNode,e):e(t)})}function pe(){let i=document.documentElement.style.overflow,e=document.documentElement.style.paddingRight,t=window.innerWidth-document.documentElement.clientWidth;return document.documentElement.style.overflow="hidden",document.documentElement.style.paddingRight=`${t}px`,()=>{document.documentElement.style.overflow=i,document.documentElement.style.paddingRight=e}}document.addEventListener("alpine:init",()=>{window.Alpine.plugin(z)});})(); | ||
/*! | ||
* focus-trap 6.6.1 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
(()=>{var K=["input","select","textarea","a[href]","button","[tabindex]:not(slot)","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details"],I=K.join(","),V=typeof Element>"u",N=V?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,G=!V&&Element.prototype.getRootNode?function(i){return i.getRootNode()}:function(i){return i.ownerDocument},_=function(e,t,a){var n=Array.prototype.slice.apply(e.querySelectorAll(I));return t&&N.call(e,I)&&n.unshift(e),n=n.filter(a),n},$=function i(e,t,a){for(var n=[],r=Array.from(e);r.length;){var s=r.shift();if(s.tagName==="SLOT"){var l=s.assignedElements(),m=l.length?l:s.children,h=i(m,!0,a);a.flatten?n.push.apply(n,h):n.push({scope:s,candidates:h})}else{var v=N.call(s,I);v&&a.filter(s)&&(t||!e.includes(s))&&n.push(s);var p=s.shadowRoot||typeof a.getShadowRoot=="function"&&a.getShadowRoot(s),y=!a.shadowRootFilter||a.shadowRootFilter(s);if(p&&y){var T=i(p===!0?s.children:p.children,!0,a);a.flatten?n.push.apply(n,T):n.push({scope:s,candidates:T})}else r.unshift.apply(r,s.children)}}return n},Y=function(e,t){return e.tabIndex<0&&(t||/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||e.isContentEditable)&&isNaN(parseInt(e.getAttribute("tabindex"),10))?0:e.tabIndex},se=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},Z=function(e){return e.tagName==="INPUT"},ce=function(e){return Z(e)&&e.type==="hidden"},le=function(e){var t=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(a){return a.tagName==="SUMMARY"});return t},fe=function(e,t){for(var a=0;a<e.length;a++)if(e[a].checked&&e[a].form===t)return e[a]},de=function(e){if(!e.name)return!0;var t=e.form||G(e),a=function(l){return t.querySelectorAll('input[type="radio"][name="'+l+'"]')},n;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")n=a(window.CSS.escape(e.name));else try{n=a(e.name)}catch(s){return 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",s.message),!1}var r=fe(n,e.form);return!r||r===e},be=function(e){return Z(e)&&e.type==="radio"},ve=function(e){return be(e)&&!de(e)},W=function(e){var t=e.getBoundingClientRect(),a=t.width,n=t.height;return a===0&&n===0},he=function(e,t){var a=t.displayCheck,n=t.getShadowRoot;if(getComputedStyle(e).visibility==="hidden")return!0;var r=N.call(e,"details>summary:first-of-type"),s=r?e.parentElement:e;if(N.call(s,"details:not([open]) *"))return!0;var l=G(e).host,m=l?.ownerDocument.contains(l)||e.ownerDocument.contains(e);if(!a||a==="full"){if(typeof n=="function"){for(var h=e;e;){var v=e.parentElement,p=G(e);if(v&&!v.shadowRoot&&n(v)===!0)return W(e);e.assignedSlot?e=e.assignedSlot:!v&&p!==e.ownerDocument?e=p.host:e=v}e=h}if(m)return!e.getClientRects().length}else if(a==="non-zero-area")return W(e);return!1},pe=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if(t.tagName==="FIELDSET"&&t.disabled){for(var a=0;a<t.children.length;a++){var n=t.children.item(a);if(n.tagName==="LEGEND")return N.call(t,"fieldset[disabled] *")?!0:!n.contains(e)}return!0}t=t.parentElement}return!1},x=function(e,t){return!(t.disabled||ce(t)||he(t,e)||le(t)||pe(t))},M=function(e,t){return!(ve(t)||Y(t)<0||!x(e,t))},ge=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},me=function i(e){var t=[],a=[];return e.forEach(function(n,r){var s=!!n.scope,l=s?n.scope:n,m=Y(l,s),h=s?i(n.candidates):l;m===0?s?t.push.apply(t,h):t.push(l):a.push({documentOrder:r,tabIndex:m,item:n,isScope:s,content:h})}),a.sort(se).reduce(function(n,r){return r.isScope?n.push.apply(n,r.content):n.push(r.content),n},[]).concat(t)},z=function(e,t){t=t||{};var a;return t.getShadowRoot?a=$([e],t.includeContainer,{filter:M.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:ge}):a=_(e,t.includeContainer,M.bind(null,t)),me(a)},L=function(e,t){t=t||{};var a;return t.getShadowRoot?a=$([e],t.includeContainer,{filter:x.bind(null,t),flatten:!0,getShadowRoot:t.getShadowRoot}):a=_(e,t.includeContainer,x.bind(null,t)),a},A=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return N.call(e,I)===!1?!1:M(t,e)},ye=K.concat("iframe").join(","),D=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return N.call(e,ye)===!1?!1:x(t,e)};function Q(i,e){var t=Object.keys(i);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(i);e&&(a=a.filter(function(n){return Object.getOwnPropertyDescriptor(i,n).enumerable})),t.push.apply(t,a)}return t}function X(i){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Q(Object(t),!0).forEach(function(a){we(i,a,t[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(t)):Q(Object(t)).forEach(function(a){Object.defineProperty(i,a,Object.getOwnPropertyDescriptor(t,a))})}return i}function we(i,e,t){return e in i?Object.defineProperty(i,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):i[e]=t,i}var J=function(){var i=[];return{activateTrap:function(t){if(i.length>0){var a=i[i.length-1];a!==t&&a.pause()}var n=i.indexOf(t);n===-1||i.splice(n,1),i.push(t)},deactivateTrap:function(t){var a=i.indexOf(t);a!==-1&&i.splice(a,1),i.length>0&&i[i.length-1].unpause()}}}(),Te=function(e){return e.tagName&&e.tagName.toLowerCase()==="input"&&typeof e.select=="function"},Fe=function(e){return e.key==="Escape"||e.key==="Esc"||e.keyCode===27},Se=function(e){return e.key==="Tab"||e.keyCode===9},ee=function(e){return setTimeout(e,0)},te=function(e,t){var a=-1;return e.every(function(n,r){return t(n)?(a=r,!1):!0}),a},O=function(e){for(var t=arguments.length,a=new Array(t>1?t-1:0),n=1;n<t;n++)a[n-1]=arguments[n];return typeof e=="function"?e.apply(void 0,a):e},P=function(e){return e.target.shadowRoot&&typeof e.composedPath=="function"?e.composedPath()[0]:e.target},re=function(e,t){var a=t?.document||document,n=X({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0},t),r={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},s,l=function(o,u,c){return o&&o[u]!==void 0?o[u]:n[c||u]},m=function(o){return r.containerGroups.findIndex(function(u){var c=u.container,b=u.tabbableNodes;return c.contains(o)||b.find(function(f){return f===o})})},h=function(o){var u=n[o];if(typeof u=="function"){for(var c=arguments.length,b=new Array(c>1?c-1:0),f=1;f<c;f++)b[f-1]=arguments[f];u=u.apply(void 0,b)}if(u===!0&&(u=void 0),!u){if(u===void 0||u===!1)return u;throw new Error("`".concat(o,"` was specified but was not a node, or did not return a node"))}var g=u;if(typeof u=="string"&&(g=a.querySelector(u),!g))throw new Error("`".concat(o,"` as selector refers to no known node"));return g},v=function(){var o=h("initialFocus");if(o===!1)return!1;if(o===void 0)if(m(a.activeElement)>=0)o=a.activeElement;else{var u=r.tabbableGroups[0],c=u&&u.firstTabbableNode;o=c||h("fallbackFocus")}if(!o)throw new Error("Your focus-trap needs to have at least one focusable element");return o},p=function(){if(r.containerGroups=r.containers.map(function(o){var u=z(o,n.tabbableOptions),c=L(o,n.tabbableOptions);return{container:o,tabbableNodes:u,focusableNodes:c,firstTabbableNode:u.length>0?u[0]:null,lastTabbableNode:u.length>0?u[u.length-1]:null,nextTabbableNode:function(f){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,w=c.findIndex(function(S){return S===f});if(!(w<0))return g?c.slice(w+1).find(function(S){return A(S,n.tabbableOptions)}):c.slice(0,w).reverse().find(function(S){return A(S,n.tabbableOptions)})}}}),r.tabbableGroups=r.containerGroups.filter(function(o){return o.tabbableNodes.length>0}),r.tabbableGroups.length<=0&&!h("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},y=function d(o){if(o!==!1&&o!==a.activeElement){if(!o||!o.focus){d(v());return}o.focus({preventScroll:!!n.preventScroll}),r.mostRecentlyFocusedNode=o,Te(o)&&o.select()}},T=function(o){var u=h("setReturnFocus",o);return u||(u===!1?!1:o)},F=function(o){var u=P(o);if(!(m(u)>=0)){if(O(n.clickOutsideDeactivates,o)){s.deactivate({returnFocus:n.returnFocusOnDeactivate&&!D(u,n.tabbableOptions)});return}O(n.allowOutsideClick,o)||o.preventDefault()}},R=function(o){var u=P(o),c=m(u)>=0;c||u instanceof Document?c&&(r.mostRecentlyFocusedNode=u):(o.stopImmediatePropagation(),y(r.mostRecentlyFocusedNode||v()))},k=function(o){var u=P(o);p();var c=null;if(r.tabbableGroups.length>0){var b=m(u),f=b>=0?r.containerGroups[b]:void 0;if(b<0)o.shiftKey?c=r.tabbableGroups[r.tabbableGroups.length-1].lastTabbableNode:c=r.tabbableGroups[0].firstTabbableNode;else if(o.shiftKey){var g=te(r.tabbableGroups,function(j){var B=j.firstTabbableNode;return u===B});if(g<0&&(f.container===u||D(u,n.tabbableOptions)&&!A(u,n.tabbableOptions)&&!f.nextTabbableNode(u,!1))&&(g=b),g>=0){var w=g===0?r.tabbableGroups.length-1:g-1,S=r.tabbableGroups[w];c=S.lastTabbableNode}}else{var C=te(r.tabbableGroups,function(j){var B=j.lastTabbableNode;return u===B});if(C<0&&(f.container===u||D(u,n.tabbableOptions)&&!A(u,n.tabbableOptions)&&!f.nextTabbableNode(u))&&(C=b),C>=0){var oe=C===r.tabbableGroups.length-1?0:C+1,ue=r.tabbableGroups[oe];c=ue.firstTabbableNode}}}else c=h("fallbackFocus");c&&(o.preventDefault(),y(c))},E=function(o){if(Fe(o)&&O(n.escapeDeactivates,o)!==!1){o.preventDefault(),s.deactivate();return}if(Se(o)){k(o);return}},q=function(o){var u=P(o);m(u)>=0||O(n.clickOutsideDeactivates,o)||O(n.allowOutsideClick,o)||(o.preventDefault(),o.stopImmediatePropagation())},H=function(){if(r.active)return J.activateTrap(s),r.delayInitialFocusTimer=n.delayInitialFocus?ee(function(){y(v())}):y(v()),a.addEventListener("focusin",R,!0),a.addEventListener("mousedown",F,{capture:!0,passive:!1}),a.addEventListener("touchstart",F,{capture:!0,passive:!1}),a.addEventListener("click",q,{capture:!0,passive:!1}),a.addEventListener("keydown",E,{capture:!0,passive:!1}),s},U=function(){if(r.active)return a.removeEventListener("focusin",R,!0),a.removeEventListener("mousedown",F,!0),a.removeEventListener("touchstart",F,!0),a.removeEventListener("click",q,!0),a.removeEventListener("keydown",E,!0),s};return s={get active(){return r.active},get paused(){return r.paused},activate:function(o){if(r.active)return this;var u=l(o,"onActivate"),c=l(o,"onPostActivate"),b=l(o,"checkCanFocusTrap");b||p(),r.active=!0,r.paused=!1,r.nodeFocusedBeforeActivation=a.activeElement,u&&u();var f=function(){b&&p(),H(),c&&c()};return b?(b(r.containers.concat()).then(f,f),this):(f(),this)},deactivate:function(o){if(!r.active)return this;var u=X({onDeactivate:n.onDeactivate,onPostDeactivate:n.onPostDeactivate,checkCanReturnFocus:n.checkCanReturnFocus},o);clearTimeout(r.delayInitialFocusTimer),r.delayInitialFocusTimer=void 0,U(),r.active=!1,r.paused=!1,J.deactivateTrap(s);var c=l(u,"onDeactivate"),b=l(u,"onPostDeactivate"),f=l(u,"checkCanReturnFocus"),g=l(u,"returnFocus","returnFocusOnDeactivate");c&&c();var w=function(){ee(function(){g&&y(T(r.nodeFocusedBeforeActivation)),b&&b()})};return g&&f?(f(T(r.nodeFocusedBeforeActivation)).then(w,w),this):(w(),this)},pause:function(){return r.paused||!r.active?this:(r.paused=!0,U(),this)},unpause:function(){return!r.paused||!r.active?this:(r.paused=!1,p(),H(),this)},updateContainerElements:function(o){var u=[].concat(o).filter(Boolean);return r.containers=u.map(function(c){return typeof c=="string"?a.querySelector(c):c}),r.active&&p(),this}},s.updateContainerElements(e),s};function ne(i){let e,t;window.addEventListener("focusin",()=>{e=t,t=document.activeElement}),i.magic("focus",a=>{let n=a;return{__noscroll:!1,__wrapAround:!1,within(r){return n=r,this},withoutScrolling(){return this.__noscroll=!0,this},noscroll(){return this.__noscroll=!0,this},withWrapAround(){return this.__wrapAround=!0,this},wrap(){return this.withWrapAround()},focusable(r){return D(r)},previouslyFocused(){return e},lastFocused(){return e},focused(){return t},focusables(){return Array.isArray(n)?n:L(n,{displayCheck:"none"})},all(){return this.focusables()},isFirst(r){let s=this.all();return s[0]&&s[0].isSameNode(r)},isLast(r){let s=this.all();return s.length&&s.slice(-1)[0].isSameNode(r)},getFirst(){return this.all()[0]},getLast(){return this.all().slice(-1)[0]},getNext(){let r=this.all(),s=document.activeElement;if(r.indexOf(s)!==-1)return this.__wrapAround&&r.indexOf(s)===r.length-1?r[0]:r[r.indexOf(s)+1]},getPrevious(){let r=this.all(),s=document.activeElement;if(r.indexOf(s)!==-1)return this.__wrapAround&&r.indexOf(s)===0?r.slice(-1)[0]:r[r.indexOf(s)-1]},first(){this.focus(this.getFirst())},last(){this.focus(this.getLast())},next(){this.focus(this.getNext())},previous(){this.focus(this.getPrevious())},prev(){return this.previous()},focus(r){r&&setTimeout(()=>{r.hasAttribute("tabindex")||r.setAttribute("tabindex","0"),r.focus({preventScroll:this._noscroll})})}}}),i.directive("trap",i.skipDuringClone((a,{expression:n,modifiers:r},{effect:s,evaluateLater:l,cleanup:m})=>{let h=l(n),v=!1,p={escapeDeactivates:!1,allowOutsideClick:!0,fallbackFocus:()=>a},y=a.querySelector("[autofocus]");y&&(p.initialFocus=y);let T=re(a,p),F=()=>{},R=()=>{},k=()=>{F(),F=()=>{},R(),R=()=>{},T.deactivate({returnFocus:!r.includes("noreturn")})};s(()=>h(E=>{v!==E&&(E&&!v&&setTimeout(()=>{r.includes("inert")&&(F=ae(a)),r.includes("noscroll")&&(R=Ee()),T.activate()}),!E&&v&&k(),v=!!E)})),m(k)},(a,{expression:n,modifiers:r},{evaluate:s})=>{r.includes("inert")&&s(n)&&ae(a)}))}function ae(i){let e=[];return ie(i,t=>{let a=t.hasAttribute("aria-hidden");t.setAttribute("aria-hidden","true"),e.push(()=>a||t.removeAttribute("aria-hidden"))}),()=>{for(;e.length;)e.pop()()}}function ie(i,e){i.isSameNode(document.body)||!i.parentNode||Array.from(i.parentNode.children).forEach(t=>{t.isSameNode(i)?ie(i.parentNode,e):e(t)})}function Ee(){let i=document.documentElement.style.overflow,e=document.documentElement.style.paddingRight,t=window.innerWidth-document.documentElement.clientWidth;return document.documentElement.style.overflow="hidden",document.documentElement.style.paddingRight=`${t}px`,()=>{document.documentElement.style.overflow=i,document.documentElement.style.paddingRight=e}}document.addEventListener("alpine:init",()=>{window.Alpine.plugin(ne)});})(); | ||
/*! Bundled license information: | ||
tabbable/dist/index.esm.js: | ||
(*! | ||
* tabbable 5.3.3 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.esm.js: | ||
(*! | ||
* focus-trap 6.9.4 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*) | ||
*/ | ||
/*! | ||
* tabbable 5.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*/ |
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true}); | ||
var __commonJS = (callback, module2) => () => { | ||
if (!module2) { | ||
module2 = {exports: {}}; | ||
callback(module2.exports, module2); | ||
} | ||
return module2.exports; | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, {get: all[name], enumerable: true}); | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __exportStar = (target, module2, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable}); | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
return to; | ||
}; | ||
var __toModule = (module2) => { | ||
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2); | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// node_modules/tabbable/dist/index.js | ||
var require_dist = __commonJS((exports2) => { | ||
/*! | ||
* tabbable 5.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*/ | ||
"use strict"; | ||
Object.defineProperty(exports2, "__esModule", {value: true}); | ||
var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"]; | ||
var candidateSelector = /* @__PURE__ */ candidateSelectors.join(","); | ||
var matches = typeof Element === "undefined" ? function() { | ||
} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; | ||
var getCandidates = function getCandidates2(el, includeContainer, filter) { | ||
var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector)); | ||
if (includeContainer && matches.call(el, candidateSelector)) { | ||
candidates.unshift(el); | ||
} | ||
candidates = candidates.filter(filter); | ||
return candidates; | ||
}; | ||
var isContentEditable = function isContentEditable2(node) { | ||
return node.contentEditable === "true"; | ||
}; | ||
var getTabindex = function getTabindex2(node) { | ||
var tabindexAttr = parseInt(node.getAttribute("tabindex"), 10); | ||
if (!isNaN(tabindexAttr)) { | ||
return tabindexAttr; | ||
} | ||
if (isContentEditable(node)) { | ||
return 0; | ||
} | ||
if ((node.nodeName === "AUDIO" || node.nodeName === "VIDEO" || node.nodeName === "DETAILS") && node.getAttribute("tabindex") === null) { | ||
return 0; | ||
} | ||
return node.tabIndex; | ||
}; | ||
var sortOrderedTabbables = function sortOrderedTabbables2(a, b) { | ||
return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex; | ||
}; | ||
var isInput = function isInput2(node) { | ||
return node.tagName === "INPUT"; | ||
}; | ||
var isHiddenInput = function isHiddenInput2(node) { | ||
return isInput(node) && node.type === "hidden"; | ||
}; | ||
var isDetailsWithSummary = function isDetailsWithSummary2(node) { | ||
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 require_dist = __commonJS({ | ||
"node_modules/tabbable/dist/index.js"(exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]:not(slot)", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"]; | ||
var candidateSelector = /* @__PURE__ */ 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) { | ||
return element.getRootNode(); | ||
} : function(element) { | ||
return element.ownerDocument; | ||
}; | ||
var getCandidates = function getCandidates2(el, includeContainer, filter) { | ||
var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector)); | ||
if (includeContainer && matches.call(el, candidateSelector)) { | ||
candidates.unshift(el); | ||
} | ||
} | ||
}; | ||
var isTabbableRadio = function isTabbableRadio2(node) { | ||
if (!node.name) { | ||
return true; | ||
} | ||
var radioScope = node.form || node.ownerDocument; | ||
var queryRadios = function queryRadios2(name) { | ||
return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]'); | ||
candidates = candidates.filter(filter); | ||
return candidates; | ||
}; | ||
var radioSet; | ||
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) { | ||
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 getCandidatesIteratively = function getCandidatesIteratively2(elements, includeContainer, options) { | ||
var candidates = []; | ||
var elementsToCheck = Array.from(elements); | ||
while (elementsToCheck.length) { | ||
var element = elementsToCheck.shift(); | ||
if (element.tagName === "SLOT") { | ||
var assigned = element.assignedElements(); | ||
var content = assigned.length ? assigned : element.children; | ||
var nestedCandidates = getCandidatesIteratively2(content, true, options); | ||
if (options.flatten) { | ||
candidates.push.apply(candidates, nestedCandidates); | ||
} else { | ||
candidates.push({ | ||
scope: element, | ||
candidates: nestedCandidates | ||
}); | ||
} | ||
} else { | ||
var validCandidate = matches.call(element, candidateSelector); | ||
if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) { | ||
candidates.push(element); | ||
} | ||
var shadowRoot = element.shadowRoot || // check for an undisclosed shadow | ||
typeof options.getShadowRoot === "function" && options.getShadowRoot(element); | ||
var validShadowRoot = !options.shadowRootFilter || options.shadowRootFilter(element); | ||
if (shadowRoot && validShadowRoot) { | ||
var _nestedCandidates = getCandidatesIteratively2(shadowRoot === true ? element.children : shadowRoot.children, true, options); | ||
if (options.flatten) { | ||
candidates.push.apply(candidates, _nestedCandidates); | ||
} else { | ||
candidates.push({ | ||
scope: element, | ||
candidates: _nestedCandidates | ||
}); | ||
} | ||
} else { | ||
elementsToCheck.unshift.apply(elementsToCheck, element.children); | ||
} | ||
} | ||
} | ||
} | ||
var checked = getCheckedRadio(radioSet, node.form); | ||
return !checked || checked === node; | ||
}; | ||
var isRadio = function isRadio2(node) { | ||
return isInput(node) && node.type === "radio"; | ||
}; | ||
var isNonTabbableRadio = function isNonTabbableRadio2(node) { | ||
return isRadio(node) && !isTabbableRadio(node); | ||
}; | ||
var isHidden = function isHidden2(node, displayCheck) { | ||
if (getComputedStyle(node).visibility === "hidden") { | ||
return true; | ||
} | ||
var isDirectSummary = matches.call(node, "details>summary:first-of-type"); | ||
var nodeUnderDetails = isDirectSummary ? node.parentElement : node; | ||
if (matches.call(nodeUnderDetails, "details:not([open]) *")) { | ||
return true; | ||
} | ||
if (!displayCheck || displayCheck === "full") { | ||
while (node) { | ||
if (getComputedStyle(node).display === "none") { | ||
return true; | ||
return candidates; | ||
}; | ||
var getTabindex = function getTabindex2(node, isScope) { | ||
if (node.tabIndex < 0) { | ||
if ((isScope || /^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || node.isContentEditable) && isNaN(parseInt(node.getAttribute("tabindex"), 10))) { | ||
return 0; | ||
} | ||
node = node.parentElement; | ||
} | ||
} else if (displayCheck === "non-zero-area") { | ||
var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height; | ||
return width === 0 && height === 0; | ||
} | ||
return false; | ||
}; | ||
var isDisabledFromFieldset = function isDisabledFromFieldset2(node) { | ||
if (isInput(node) || node.tagName === "SELECT" || node.tagName === "TEXTAREA" || node.tagName === "BUTTON") { | ||
var parentNode = node.parentElement; | ||
while (parentNode) { | ||
if (parentNode.tagName === "FIELDSET" && parentNode.disabled) { | ||
for (var i = 0; i < parentNode.children.length; i++) { | ||
var child = parentNode.children.item(i); | ||
if (child.tagName === "LEGEND") { | ||
if (child.contains(node)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
return true; | ||
return node.tabIndex; | ||
}; | ||
var sortOrderedTabbables = function sortOrderedTabbables2(a, b) { | ||
return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex; | ||
}; | ||
var isInput = function isInput2(node) { | ||
return node.tagName === "INPUT"; | ||
}; | ||
var isHiddenInput = function isHiddenInput2(node) { | ||
return isInput(node) && node.type === "hidden"; | ||
}; | ||
var isDetailsWithSummary = function isDetailsWithSummary2(node) { | ||
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]; | ||
} | ||
parentNode = parentNode.parentElement; | ||
} | ||
} | ||
return false; | ||
}; | ||
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable2(options, node) { | ||
if (node.disabled || isHiddenInput(node) || isHidden(node, options.displayCheck) || isDetailsWithSummary(node) || isDisabledFromFieldset(node)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(options, node) { | ||
if (!isNodeMatchingSelectorFocusable(options, node) || isNonTabbableRadio(node) || getTabindex(node) < 0) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
var tabbable = function tabbable2(el, options) { | ||
options = options || {}; | ||
var regularTabbables = []; | ||
var orderedTabbables = []; | ||
var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options)); | ||
candidates.forEach(function(candidate, i) { | ||
var candidateTabindex = getTabindex(candidate); | ||
if (candidateTabindex === 0) { | ||
regularTabbables.push(candidate); | ||
}; | ||
var isTabbableRadio = function isTabbableRadio2(node) { | ||
if (!node.name) { | ||
return true; | ||
} | ||
var radioScope = node.form || getRootNode(node); | ||
var queryRadios = function queryRadios2(name) { | ||
return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]'); | ||
}; | ||
var radioSet; | ||
if (typeof window !== "undefined" && typeof window.CSS !== "undefined" && typeof window.CSS.escape === "function") { | ||
radioSet = queryRadios(window.CSS.escape(node.name)); | ||
} else { | ||
orderedTabbables.push({ | ||
documentOrder: i, | ||
tabIndex: candidateTabindex, | ||
node: candidate | ||
}); | ||
try { | ||
radioSet = queryRadios(node.name); | ||
} catch (err) { | ||
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 tabbableNodes = orderedTabbables.sort(sortOrderedTabbables).map(function(a) { | ||
return a.node; | ||
}).concat(regularTabbables); | ||
return tabbableNodes; | ||
}; | ||
var focusable2 = function focusable3(el, options) { | ||
options = options || {}; | ||
var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options)); | ||
return candidates; | ||
}; | ||
var isTabbable = function isTabbable2(node, options) { | ||
options = options || {}; | ||
if (!node) { | ||
throw new Error("No node provided"); | ||
} | ||
if (matches.call(node, candidateSelector) === false) { | ||
return false; | ||
} | ||
return isNodeMatchingSelectorTabbable(options, node); | ||
}; | ||
var focusableCandidateSelector = /* @__PURE__ */ candidateSelectors.concat("iframe").join(","); | ||
var isFocusable2 = function isFocusable3(node, options) { | ||
options = options || {}; | ||
if (!node) { | ||
throw new Error("No node provided"); | ||
} | ||
if (matches.call(node, focusableCandidateSelector) === false) { | ||
return false; | ||
} | ||
return isNodeMatchingSelectorFocusable(options, node); | ||
}; | ||
exports2.focusable = focusable2; | ||
exports2.isFocusable = isFocusable2; | ||
exports2.isTabbable = isTabbable; | ||
exports2.tabbable = tabbable; | ||
}); | ||
// node_modules/focus-trap/dist/focus-trap.js | ||
var require_focus_trap = __commonJS((exports2) => { | ||
/*! | ||
* focus-trap 6.6.1 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*/ | ||
"use strict"; | ||
Object.defineProperty(exports2, "__esModule", {value: true}); | ||
var tabbable = require_dist(); | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
var checked = getCheckedRadio(radioSet, node.form); | ||
return !checked || checked === node; | ||
}; | ||
var isRadio = function isRadio2(node) { | ||
return isInput(node) && node.type === "radio"; | ||
}; | ||
var isNonTabbableRadio = function isNonTabbableRadio2(node) { | ||
return isRadio(node) && !isTabbableRadio(node); | ||
}; | ||
var isZeroArea = function isZeroArea2(node) { | ||
var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height; | ||
return width === 0 && height === 0; | ||
}; | ||
var isHidden = function isHidden2(node, _ref) { | ||
var displayCheck = _ref.displayCheck, getShadowRoot = _ref.getShadowRoot; | ||
if (getComputedStyle(node).visibility === "hidden") { | ||
return true; | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
var isDirectSummary = matches.call(node, "details>summary:first-of-type"); | ||
var nodeUnderDetails = isDirectSummary ? node.parentElement : node; | ||
if (matches.call(nodeUnderDetails, "details:not([open]) *")) { | ||
return true; | ||
} | ||
} | ||
return target; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
var activeFocusTraps = function() { | ||
var trapQueue = []; | ||
return { | ||
activateTrap: function activateTrap(trap) { | ||
if (trapQueue.length > 0) { | ||
var activeTrap = trapQueue[trapQueue.length - 1]; | ||
if (activeTrap !== trap) { | ||
activeTrap.pause(); | ||
var nodeRootHost = getRootNode(node).host; | ||
var nodeIsAttached = (nodeRootHost === null || nodeRootHost === void 0 ? void 0 : nodeRootHost.ownerDocument.contains(nodeRootHost)) || node.ownerDocument.contains(node); | ||
if (!displayCheck || displayCheck === "full") { | ||
if (typeof getShadowRoot === "function") { | ||
var originalNode = node; | ||
while (node) { | ||
var parentElement = node.parentElement; | ||
var rootNode = getRootNode(node); | ||
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; | ||
} | ||
var trapIndex = trapQueue.indexOf(trap); | ||
if (trapIndex === -1) { | ||
trapQueue.push(trap); | ||
} else { | ||
trapQueue.splice(trapIndex, 1); | ||
trapQueue.push(trap); | ||
if (nodeIsAttached) { | ||
return !node.getClientRects().length; | ||
} | ||
}, | ||
deactivateTrap: function deactivateTrap(trap) { | ||
var trapIndex = trapQueue.indexOf(trap); | ||
if (trapIndex !== -1) { | ||
trapQueue.splice(trapIndex, 1); | ||
} 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) { | ||
if (parentNode.tagName === "FIELDSET" && parentNode.disabled) { | ||
for (var i = 0; i < parentNode.children.length; i++) { | ||
var child = parentNode.children.item(i); | ||
if (child.tagName === "LEGEND") { | ||
return matches.call(parentNode, "fieldset[disabled] *") ? true : !child.contains(node); | ||
} | ||
} | ||
return true; | ||
} | ||
parentNode = parentNode.parentElement; | ||
} | ||
if (trapQueue.length > 0) { | ||
trapQueue[trapQueue.length - 1].unpause(); | ||
} | ||
} | ||
return false; | ||
}; | ||
}(); | ||
var isSelectableInput = function isSelectableInput2(node) { | ||
return node.tagName && node.tagName.toLowerCase() === "input" && typeof node.select === "function"; | ||
}; | ||
var isEscapeEvent = function isEscapeEvent2(e) { | ||
return e.key === "Escape" || e.key === "Esc" || e.keyCode === 27; | ||
}; | ||
var isTabEvent = function isTabEvent2(e) { | ||
return e.key === "Tab" || e.keyCode === 9; | ||
}; | ||
var delay = function delay2(fn) { | ||
return setTimeout(fn, 0); | ||
}; | ||
var findIndex = function findIndex2(arr, fn) { | ||
var idx = -1; | ||
arr.every(function(value, i) { | ||
if (fn(value)) { | ||
idx = i; | ||
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; | ||
}); | ||
return idx; | ||
}; | ||
var valueOrHandler = function valueOrHandler2(value) { | ||
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
params[_key - 1] = arguments[_key]; | ||
} | ||
return typeof value === "function" ? value.apply(void 0, params) : value; | ||
}; | ||
var createFocusTrap2 = function createFocusTrap3(elements, userOptions) { | ||
var doc = document; | ||
var config = _objectSpread2({ | ||
returnFocusOnDeactivate: true, | ||
escapeDeactivates: true, | ||
delayInitialFocus: true | ||
}, userOptions); | ||
var state = { | ||
containers: [], | ||
tabbableGroups: [], | ||
nodeFocusedBeforeActivation: null, | ||
mostRecentlyFocusedNode: null, | ||
active: false, | ||
paused: false, | ||
delayInitialFocusTimer: void 0 | ||
}; | ||
var trap; | ||
var getOption = function getOption2(configOverrideOptions, optionName, configOptionName) { | ||
return configOverrideOptions && configOverrideOptions[optionName] !== void 0 ? configOverrideOptions[optionName] : config[configOptionName || optionName]; | ||
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(options, node) { | ||
if (isNonTabbableRadio(node) || getTabindex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
var containersContain = function containersContain2(element) { | ||
return state.containers.some(function(container) { | ||
return container.contains(element); | ||
var isValidShadowRootTabbable = function isValidShadowRootTabbable2(shadowHostNode) { | ||
var tabIndex = parseInt(shadowHostNode.getAttribute("tabindex"), 10); | ||
if (isNaN(tabIndex) || tabIndex >= 0) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
var sortByOrder = function sortByOrder2(candidates) { | ||
var regularTabbables = []; | ||
var orderedTabbables = []; | ||
candidates.forEach(function(item, i) { | ||
var isScope = !!item.scope; | ||
var element = isScope ? item.scope : item; | ||
var candidateTabindex = getTabindex(element, isScope); | ||
var elements = isScope ? sortByOrder2(item.candidates) : element; | ||
if (candidateTabindex === 0) { | ||
isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element); | ||
} else { | ||
orderedTabbables.push({ | ||
documentOrder: i, | ||
tabIndex: candidateTabindex, | ||
item, | ||
isScope, | ||
content: elements | ||
}); | ||
} | ||
}); | ||
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 getNodeForOption = function getNodeForOption2(optionName) { | ||
var optionValue = config[optionName]; | ||
if (!optionValue) { | ||
return null; | ||
var tabbable = function tabbable2(el, options) { | ||
options = options || {}; | ||
var candidates; | ||
if (options.getShadowRoot) { | ||
candidates = getCandidatesIteratively([el], options.includeContainer, { | ||
filter: isNodeMatchingSelectorTabbable.bind(null, options), | ||
flatten: false, | ||
getShadowRoot: options.getShadowRoot, | ||
shadowRootFilter: isValidShadowRootTabbable | ||
}); | ||
} else { | ||
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options)); | ||
} | ||
var node = optionValue; | ||
if (typeof optionValue === "string") { | ||
node = doc.querySelector(optionValue); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` refers to no known node")); | ||
} | ||
} | ||
if (typeof optionValue === "function") { | ||
node = optionValue(); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` did not return a node")); | ||
} | ||
} | ||
return node; | ||
return sortByOrder(candidates); | ||
}; | ||
var getInitialFocusNode = function getInitialFocusNode2() { | ||
var node; | ||
if (getOption({}, "initialFocus") === false) { | ||
return false; | ||
} | ||
if (getNodeForOption("initialFocus") !== null) { | ||
node = getNodeForOption("initialFocus"); | ||
} else if (containersContain(doc.activeElement)) { | ||
node = doc.activeElement; | ||
var focusable2 = function focusable3(el, options) { | ||
options = options || {}; | ||
var candidates; | ||
if (options.getShadowRoot) { | ||
candidates = getCandidatesIteratively([el], options.includeContainer, { | ||
filter: isNodeMatchingSelectorFocusable.bind(null, options), | ||
flatten: true, | ||
getShadowRoot: options.getShadowRoot | ||
}); | ||
} else { | ||
var firstTabbableGroup = state.tabbableGroups[0]; | ||
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; | ||
node = firstTabbableNode || getNodeForOption("fallbackFocus"); | ||
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options)); | ||
} | ||
return candidates; | ||
}; | ||
var isTabbable = function isTabbable2(node, options) { | ||
options = options || {}; | ||
if (!node) { | ||
throw new Error("Your focus-trap needs to have at least one focusable element"); | ||
throw new Error("No node provided"); | ||
} | ||
return node; | ||
}; | ||
var updateTabbableNodes = function updateTabbableNodes2() { | ||
state.tabbableGroups = state.containers.map(function(container) { | ||
var tabbableNodes = tabbable.tabbable(container); | ||
if (tabbableNodes.length > 0) { | ||
return { | ||
container, | ||
firstTabbableNode: tabbableNodes[0], | ||
lastTabbableNode: tabbableNodes[tabbableNodes.length - 1] | ||
}; | ||
} | ||
return void 0; | ||
}).filter(function(group) { | ||
return !!group; | ||
}); | ||
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"); | ||
if (matches.call(node, candidateSelector) === false) { | ||
return false; | ||
} | ||
return isNodeMatchingSelectorTabbable(options, node); | ||
}; | ||
var tryFocus = function tryFocus2(node) { | ||
if (node === false) { | ||
return; | ||
var focusableCandidateSelector = /* @__PURE__ */ candidateSelectors.concat("iframe").join(","); | ||
var isFocusable2 = function isFocusable3(node, options) { | ||
options = options || {}; | ||
if (!node) { | ||
throw new Error("No node provided"); | ||
} | ||
if (node === doc.activeElement) { | ||
return; | ||
if (matches.call(node, focusableCandidateSelector) === false) { | ||
return false; | ||
} | ||
if (!node || !node.focus) { | ||
tryFocus2(getInitialFocusNode()); | ||
return; | ||
} | ||
node.focus({ | ||
preventScroll: !!config.preventScroll | ||
}); | ||
state.mostRecentlyFocusedNode = node; | ||
if (isSelectableInput(node)) { | ||
node.select(); | ||
} | ||
return isNodeMatchingSelectorFocusable(options, node); | ||
}; | ||
var getReturnFocusNode = function getReturnFocusNode2(previousActiveElement) { | ||
var node = getNodeForOption("setReturnFocus"); | ||
return node ? node : previousActiveElement; | ||
}; | ||
var checkPointerDown = function checkPointerDown2(e) { | ||
if (containersContain(e.target)) { | ||
return; | ||
exports.focusable = focusable2; | ||
exports.isFocusable = isFocusable2; | ||
exports.isTabbable = isTabbable; | ||
exports.tabbable = tabbable; | ||
} | ||
}); | ||
// node_modules/focus-trap/dist/focus-trap.js | ||
var require_focus_trap = __commonJS({ | ||
"node_modules/focus-trap/dist/focus-trap.js"(exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tabbable = require_dist(); | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
if (valueOrHandler(config.clickOutsideDeactivates, e)) { | ||
trap.deactivate({ | ||
returnFocus: config.returnFocusOnDeactivate && !tabbable.isFocusable(e.target) | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
return; | ||
} | ||
if (valueOrHandler(config.allowOutsideClick, e)) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
}; | ||
var checkFocusIn = function checkFocusIn2(e) { | ||
var targetContained = containersContain(e.target); | ||
if (targetContained || e.target instanceof Document) { | ||
if (targetContained) { | ||
state.mostRecentlyFocusedNode = e.target; | ||
} | ||
return target; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
e.stopImmediatePropagation(); | ||
tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode()); | ||
obj[key] = value; | ||
} | ||
}; | ||
var checkTab = function checkTab2(e) { | ||
updateTabbableNodes(); | ||
var destinationNode = null; | ||
if (state.tabbableGroups.length > 0) { | ||
var containerIndex = findIndex(state.tabbableGroups, function(_ref) { | ||
var container = _ref.container; | ||
return container.contains(e.target); | ||
}); | ||
if (containerIndex < 0) { | ||
if (e.shiftKey) { | ||
destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode; | ||
return obj; | ||
} | ||
var activeFocusTraps = function() { | ||
var trapQueue = []; | ||
return { | ||
activateTrap: function activateTrap(trap) { | ||
if (trapQueue.length > 0) { | ||
var activeTrap = trapQueue[trapQueue.length - 1]; | ||
if (activeTrap !== trap) { | ||
activeTrap.pause(); | ||
} | ||
} | ||
var trapIndex = trapQueue.indexOf(trap); | ||
if (trapIndex === -1) { | ||
trapQueue.push(trap); | ||
} else { | ||
destinationNode = state.tabbableGroups[0].firstTabbableNode; | ||
trapQueue.splice(trapIndex, 1); | ||
trapQueue.push(trap); | ||
} | ||
} else if (e.shiftKey) { | ||
var startOfGroupIndex = findIndex(state.tabbableGroups, function(_ref2) { | ||
var firstTabbableNode = _ref2.firstTabbableNode; | ||
return e.target === firstTabbableNode; | ||
}); | ||
if (startOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) { | ||
startOfGroupIndex = containerIndex; | ||
}, | ||
deactivateTrap: function deactivateTrap(trap) { | ||
var trapIndex = trapQueue.indexOf(trap); | ||
if (trapIndex !== -1) { | ||
trapQueue.splice(trapIndex, 1); | ||
} | ||
if (startOfGroupIndex >= 0) { | ||
var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1; | ||
var destinationGroup = state.tabbableGroups[destinationGroupIndex]; | ||
destinationNode = destinationGroup.lastTabbableNode; | ||
if (trapQueue.length > 0) { | ||
trapQueue[trapQueue.length - 1].unpause(); | ||
} | ||
} else { | ||
var lastOfGroupIndex = findIndex(state.tabbableGroups, function(_ref3) { | ||
var lastTabbableNode = _ref3.lastTabbableNode; | ||
return e.target === lastTabbableNode; | ||
}); | ||
if (lastOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) { | ||
lastOfGroupIndex = containerIndex; | ||
} | ||
if (lastOfGroupIndex >= 0) { | ||
var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1; | ||
var _destinationGroup = state.tabbableGroups[_destinationGroupIndex]; | ||
destinationNode = _destinationGroup.firstTabbableNode; | ||
} | ||
} | ||
} else { | ||
destinationNode = getNodeForOption("fallbackFocus"); | ||
} | ||
if (destinationNode) { | ||
e.preventDefault(); | ||
tryFocus(destinationNode); | ||
} | ||
}; | ||
}(); | ||
var isSelectableInput = function isSelectableInput2(node) { | ||
return node.tagName && node.tagName.toLowerCase() === "input" && typeof node.select === "function"; | ||
}; | ||
var checkKey = function checkKey2(e) { | ||
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates) !== false) { | ||
e.preventDefault(); | ||
trap.deactivate(); | ||
return; | ||
} | ||
if (isTabEvent(e)) { | ||
checkTab(e); | ||
return; | ||
} | ||
var isEscapeEvent = function isEscapeEvent2(e) { | ||
return e.key === "Escape" || e.key === "Esc" || e.keyCode === 27; | ||
}; | ||
var checkClick = function checkClick2(e) { | ||
if (valueOrHandler(config.clickOutsideDeactivates, e)) { | ||
return; | ||
} | ||
if (containersContain(e.target)) { | ||
return; | ||
} | ||
if (valueOrHandler(config.allowOutsideClick, e)) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
e.stopImmediatePropagation(); | ||
var isTabEvent = function isTabEvent2(e) { | ||
return e.key === "Tab" || e.keyCode === 9; | ||
}; | ||
var addListeners = function addListeners2() { | ||
if (!state.active) { | ||
return; | ||
} | ||
activeFocusTraps.activateTrap(trap); | ||
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function() { | ||
tryFocus(getInitialFocusNode()); | ||
}) : tryFocus(getInitialFocusNode()); | ||
doc.addEventListener("focusin", checkFocusIn, true); | ||
doc.addEventListener("mousedown", checkPointerDown, { | ||
capture: true, | ||
passive: false | ||
var delay = function delay2(fn) { | ||
return setTimeout(fn, 0); | ||
}; | ||
var findIndex = function findIndex2(arr, fn) { | ||
var idx = -1; | ||
arr.every(function(value, i) { | ||
if (fn(value)) { | ||
idx = i; | ||
return false; | ||
} | ||
return true; | ||
}); | ||
doc.addEventListener("touchstart", checkPointerDown, { | ||
capture: true, | ||
passive: false | ||
}); | ||
doc.addEventListener("click", checkClick, { | ||
capture: true, | ||
passive: false | ||
}); | ||
doc.addEventListener("keydown", checkKey, { | ||
capture: true, | ||
passive: false | ||
}); | ||
return trap; | ||
return idx; | ||
}; | ||
var removeListeners = function removeListeners2() { | ||
if (!state.active) { | ||
return; | ||
var valueOrHandler = function valueOrHandler2(value) { | ||
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
params[_key - 1] = arguments[_key]; | ||
} | ||
doc.removeEventListener("focusin", checkFocusIn, true); | ||
doc.removeEventListener("mousedown", checkPointerDown, true); | ||
doc.removeEventListener("touchstart", checkPointerDown, true); | ||
doc.removeEventListener("click", checkClick, true); | ||
doc.removeEventListener("keydown", checkKey, true); | ||
return trap; | ||
return typeof value === "function" ? value.apply(void 0, params) : value; | ||
}; | ||
trap = { | ||
activate: function activate(activateOptions) { | ||
if (state.active) { | ||
return this; | ||
var getActualTarget = function getActualTarget2(event) { | ||
return event.target.shadowRoot && typeof event.composedPath === "function" ? event.composedPath()[0] : event.target; | ||
}; | ||
var createFocusTrap2 = function createFocusTrap3(elements, userOptions) { | ||
var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document; | ||
var config = _objectSpread2({ | ||
returnFocusOnDeactivate: true, | ||
escapeDeactivates: true, | ||
delayInitialFocus: true | ||
}, 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 | ||
// firstTabbableNode: HTMLElement|null, | ||
// lastTabbableNode: HTMLElement|null, | ||
// 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: [], | ||
nodeFocusedBeforeActivation: null, | ||
mostRecentlyFocusedNode: null, | ||
active: false, | ||
paused: false, | ||
// timer ID for when delayInitialFocus is true and initial focus in this trap | ||
// has been delayed during activation | ||
delayInitialFocusTimer: void 0 | ||
}; | ||
var trap; | ||
var getOption = function getOption2(configOverrideOptions, optionName, configOptionName) { | ||
return configOverrideOptions && configOverrideOptions[optionName] !== void 0 ? configOverrideOptions[optionName] : config[configOptionName || optionName]; | ||
}; | ||
var findContainerIndex = function findContainerIndex2(element) { | ||
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) | ||
tabbableNodes.find(function(node) { | ||
return node === element; | ||
}); | ||
}); | ||
}; | ||
var getNodeForOption = function getNodeForOption2(optionName) { | ||
var optionValue = config[optionName]; | ||
if (typeof optionValue === "function") { | ||
for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
params[_key2 - 1] = arguments[_key2]; | ||
} | ||
optionValue = optionValue.apply(void 0, params); | ||
} | ||
var onActivate = getOption(activateOptions, "onActivate"); | ||
var onPostActivate = getOption(activateOptions, "onPostActivate"); | ||
var checkCanFocusTrap = getOption(activateOptions, "checkCanFocusTrap"); | ||
if (!checkCanFocusTrap) { | ||
updateTabbableNodes(); | ||
if (optionValue === true) { | ||
optionValue = void 0; | ||
} | ||
state.active = true; | ||
state.paused = false; | ||
state.nodeFocusedBeforeActivation = doc.activeElement; | ||
if (onActivate) { | ||
onActivate(); | ||
if (!optionValue) { | ||
if (optionValue === void 0 || optionValue === false) { | ||
return optionValue; | ||
} | ||
throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node")); | ||
} | ||
var finishActivation = function finishActivation2() { | ||
if (checkCanFocusTrap) { | ||
updateTabbableNodes(); | ||
var node = optionValue; | ||
if (typeof optionValue === "string") { | ||
node = doc.querySelector(optionValue); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` as selector refers to no known node")); | ||
} | ||
addListeners(); | ||
if (onPostActivate) { | ||
onPostActivate(); | ||
} | ||
return node; | ||
}; | ||
var getInitialFocusNode = function getInitialFocusNode2() { | ||
var node = getNodeForOption("initialFocus"); | ||
if (node === false) { | ||
return false; | ||
} | ||
if (node === void 0) { | ||
if (findContainerIndex(doc.activeElement) >= 0) { | ||
node = doc.activeElement; | ||
} else { | ||
var firstTabbableGroup = state.tabbableGroups[0]; | ||
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; | ||
node = firstTabbableNode || getNodeForOption("fallbackFocus"); | ||
} | ||
}; | ||
if (checkCanFocusTrap) { | ||
checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation); | ||
return this; | ||
} | ||
finishActivation(); | ||
return this; | ||
}, | ||
deactivate: function deactivate(deactivateOptions) { | ||
if (!node) { | ||
throw new Error("Your focus-trap needs to have at least one focusable element"); | ||
} | ||
return node; | ||
}; | ||
var updateTabbableNodes = function updateTabbableNodes2() { | ||
state.containerGroups = state.containers.map(function(container) { | ||
var tabbableNodes = tabbable.tabbable(container, config.tabbableOptions); | ||
var focusableNodes = tabbable.focusable(container, config.tabbableOptions); | ||
return { | ||
container, | ||
tabbableNodes, | ||
focusableNodes, | ||
firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null, | ||
lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null, | ||
/** | ||
* 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) { | ||
var forward = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true; | ||
var nodeIdx = focusableNodes.findIndex(function(n) { | ||
return n === node; | ||
}); | ||
if (nodeIdx < 0) { | ||
return void 0; | ||
} | ||
if (forward) { | ||
return focusableNodes.slice(nodeIdx + 1).find(function(n) { | ||
return tabbable.isTabbable(n, config.tabbableOptions); | ||
}); | ||
} | ||
return focusableNodes.slice(0, nodeIdx).reverse().find(function(n) { | ||
return tabbable.isTabbable(n, config.tabbableOptions); | ||
}); | ||
} | ||
}; | ||
}); | ||
state.tabbableGroups = state.containerGroups.filter(function(group) { | ||
return group.tabbableNodes.length > 0; | ||
}); | ||
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"); | ||
} | ||
}; | ||
var tryFocus = function tryFocus2(node) { | ||
if (node === false) { | ||
return; | ||
} | ||
if (node === doc.activeElement) { | ||
return; | ||
} | ||
if (!node || !node.focus) { | ||
tryFocus2(getInitialFocusNode()); | ||
return; | ||
} | ||
node.focus({ | ||
preventScroll: !!config.preventScroll | ||
}); | ||
state.mostRecentlyFocusedNode = node; | ||
if (isSelectableInput(node)) { | ||
node.select(); | ||
} | ||
}; | ||
var getReturnFocusNode = function getReturnFocusNode2(previousActiveElement) { | ||
var node = getNodeForOption("setReturnFocus", previousActiveElement); | ||
return node ? node : node === false ? false : previousActiveElement; | ||
}; | ||
var checkPointerDown = function checkPointerDown2(e) { | ||
var target = getActualTarget(e); | ||
if (findContainerIndex(target) >= 0) { | ||
return; | ||
} | ||
if (valueOrHandler(config.clickOutsideDeactivates, e)) { | ||
trap.deactivate({ | ||
// if, on deactivation, we should return focus to the node originally-focused | ||
// when the trap was activated (or the configured `setReturnFocus` node), | ||
// then assume it's also OK to return focus to the outside node that was | ||
// just clicked, causing deactivation, as long as that node is focusable; | ||
// if it isn't focusable, then return focus to the original node focused | ||
// on activation (or the configured `setReturnFocus` node) | ||
// NOTE: by setting `returnFocus: false`, deactivate() will do nothing, | ||
// which will result in the outside click setting focus to the node | ||
// that was clicked, whether it's focusable or not; by setting | ||
// `returnFocus: true`, we'll attempt to re-focus the node originally-focused | ||
// on activation (or the configured `setReturnFocus` node) | ||
returnFocus: config.returnFocusOnDeactivate && !tabbable.isFocusable(target, config.tabbableOptions) | ||
}); | ||
return; | ||
} | ||
if (valueOrHandler(config.allowOutsideClick, e)) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
}; | ||
var checkFocusIn = function checkFocusIn2(e) { | ||
var target = getActualTarget(e); | ||
var targetContained = findContainerIndex(target) >= 0; | ||
if (targetContained || target instanceof Document) { | ||
if (targetContained) { | ||
state.mostRecentlyFocusedNode = target; | ||
} | ||
} else { | ||
e.stopImmediatePropagation(); | ||
tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode()); | ||
} | ||
}; | ||
var checkTab = function checkTab2(e) { | ||
var target = getActualTarget(e); | ||
updateTabbableNodes(); | ||
var destinationNode = null; | ||
if (state.tabbableGroups.length > 0) { | ||
var containerIndex = findContainerIndex(target); | ||
var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : void 0; | ||
if (containerIndex < 0) { | ||
if (e.shiftKey) { | ||
destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode; | ||
} else { | ||
destinationNode = state.tabbableGroups[0].firstTabbableNode; | ||
} | ||
} else if (e.shiftKey) { | ||
var startOfGroupIndex = findIndex(state.tabbableGroups, function(_ref2) { | ||
var firstTabbableNode = _ref2.firstTabbableNode; | ||
return target === firstTabbableNode; | ||
}); | ||
if (startOfGroupIndex < 0 && (containerGroup.container === target || tabbable.isFocusable(target, config.tabbableOptions) && !tabbable.isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) { | ||
startOfGroupIndex = containerIndex; | ||
} | ||
if (startOfGroupIndex >= 0) { | ||
var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1; | ||
var destinationGroup = state.tabbableGroups[destinationGroupIndex]; | ||
destinationNode = destinationGroup.lastTabbableNode; | ||
} | ||
} else { | ||
var lastOfGroupIndex = findIndex(state.tabbableGroups, function(_ref3) { | ||
var lastTabbableNode = _ref3.lastTabbableNode; | ||
return target === lastTabbableNode; | ||
}); | ||
if (lastOfGroupIndex < 0 && (containerGroup.container === target || tabbable.isFocusable(target, config.tabbableOptions) && !tabbable.isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) { | ||
lastOfGroupIndex = containerIndex; | ||
} | ||
if (lastOfGroupIndex >= 0) { | ||
var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1; | ||
var _destinationGroup = state.tabbableGroups[_destinationGroupIndex]; | ||
destinationNode = _destinationGroup.firstTabbableNode; | ||
} | ||
} | ||
} else { | ||
destinationNode = getNodeForOption("fallbackFocus"); | ||
} | ||
if (destinationNode) { | ||
e.preventDefault(); | ||
tryFocus(destinationNode); | ||
} | ||
}; | ||
var checkKey = function checkKey2(e) { | ||
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) { | ||
e.preventDefault(); | ||
trap.deactivate(); | ||
return; | ||
} | ||
if (isTabEvent(e)) { | ||
checkTab(e); | ||
return; | ||
} | ||
}; | ||
var checkClick = function checkClick2(e) { | ||
var target = getActualTarget(e); | ||
if (findContainerIndex(target) >= 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 this; | ||
return; | ||
} | ||
clearTimeout(state.delayInitialFocusTimer); | ||
state.delayInitialFocusTimer = void 0; | ||
removeListeners(); | ||
state.active = false; | ||
state.paused = false; | ||
activeFocusTraps.deactivateTrap(trap); | ||
var onDeactivate = getOption(deactivateOptions, "onDeactivate"); | ||
var onPostDeactivate = getOption(deactivateOptions, "onPostDeactivate"); | ||
var checkCanReturnFocus = getOption(deactivateOptions, "checkCanReturnFocus"); | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
activeFocusTraps.activateTrap(trap); | ||
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function() { | ||
tryFocus(getInitialFocusNode()); | ||
}) : tryFocus(getInitialFocusNode()); | ||
doc.addEventListener("focusin", checkFocusIn, true); | ||
doc.addEventListener("mousedown", checkPointerDown, { | ||
capture: true, | ||
passive: false | ||
}); | ||
doc.addEventListener("touchstart", checkPointerDown, { | ||
capture: true, | ||
passive: false | ||
}); | ||
doc.addEventListener("click", checkClick, { | ||
capture: true, | ||
passive: false | ||
}); | ||
doc.addEventListener("keydown", checkKey, { | ||
capture: true, | ||
passive: false | ||
}); | ||
return trap; | ||
}; | ||
var removeListeners = function removeListeners2() { | ||
if (!state.active) { | ||
return; | ||
} | ||
var returnFocus = getOption(deactivateOptions, "returnFocus", "returnFocusOnDeactivate"); | ||
var finishDeactivation = function finishDeactivation2() { | ||
delay(function() { | ||
if (returnFocus) { | ||
tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)); | ||
doc.removeEventListener("focusin", checkFocusIn, true); | ||
doc.removeEventListener("mousedown", checkPointerDown, true); | ||
doc.removeEventListener("touchstart", checkPointerDown, true); | ||
doc.removeEventListener("click", checkClick, true); | ||
doc.removeEventListener("keydown", checkKey, true); | ||
return trap; | ||
}; | ||
trap = { | ||
get active() { | ||
return state.active; | ||
}, | ||
get paused() { | ||
return state.paused; | ||
}, | ||
activate: function activate(activateOptions) { | ||
if (state.active) { | ||
return this; | ||
} | ||
var onActivate = getOption(activateOptions, "onActivate"); | ||
var onPostActivate = getOption(activateOptions, "onPostActivate"); | ||
var checkCanFocusTrap = getOption(activateOptions, "checkCanFocusTrap"); | ||
if (!checkCanFocusTrap) { | ||
updateTabbableNodes(); | ||
} | ||
state.active = true; | ||
state.paused = false; | ||
state.nodeFocusedBeforeActivation = doc.activeElement; | ||
if (onActivate) { | ||
onActivate(); | ||
} | ||
var finishActivation = function finishActivation2() { | ||
if (checkCanFocusTrap) { | ||
updateTabbableNodes(); | ||
} | ||
if (onPostDeactivate) { | ||
onPostDeactivate(); | ||
addListeners(); | ||
if (onPostActivate) { | ||
onPostActivate(); | ||
} | ||
}); | ||
}; | ||
if (returnFocus && checkCanReturnFocus) { | ||
checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation); | ||
}; | ||
if (checkCanFocusTrap) { | ||
checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation); | ||
return this; | ||
} | ||
finishActivation(); | ||
return this; | ||
} | ||
finishDeactivation(); | ||
return this; | ||
}, | ||
pause: function pause() { | ||
if (state.paused || !state.active) { | ||
}, | ||
deactivate: function deactivate(deactivateOptions) { | ||
if (!state.active) { | ||
return this; | ||
} | ||
var options = _objectSpread2({ | ||
onDeactivate: config.onDeactivate, | ||
onPostDeactivate: config.onPostDeactivate, | ||
checkCanReturnFocus: config.checkCanReturnFocus | ||
}, deactivateOptions); | ||
clearTimeout(state.delayInitialFocusTimer); | ||
state.delayInitialFocusTimer = void 0; | ||
removeListeners(); | ||
state.active = false; | ||
state.paused = false; | ||
activeFocusTraps.deactivateTrap(trap); | ||
var onDeactivate = getOption(options, "onDeactivate"); | ||
var onPostDeactivate = getOption(options, "onPostDeactivate"); | ||
var checkCanReturnFocus = getOption(options, "checkCanReturnFocus"); | ||
var returnFocus = getOption(options, "returnFocus", "returnFocusOnDeactivate"); | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
} | ||
var finishDeactivation = function finishDeactivation2() { | ||
delay(function() { | ||
if (returnFocus) { | ||
tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)); | ||
} | ||
if (onPostDeactivate) { | ||
onPostDeactivate(); | ||
} | ||
}); | ||
}; | ||
if (returnFocus && checkCanReturnFocus) { | ||
checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation); | ||
return this; | ||
} | ||
finishDeactivation(); | ||
return this; | ||
} | ||
state.paused = true; | ||
removeListeners(); | ||
return this; | ||
}, | ||
unpause: function unpause() { | ||
if (!state.paused || !state.active) { | ||
}, | ||
pause: function pause() { | ||
if (state.paused || !state.active) { | ||
return this; | ||
} | ||
state.paused = true; | ||
removeListeners(); | ||
return this; | ||
} | ||
state.paused = false; | ||
updateTabbableNodes(); | ||
addListeners(); | ||
return this; | ||
}, | ||
updateContainerElements: function updateContainerElements(containerElements) { | ||
var elementsAsArray = [].concat(containerElements).filter(Boolean); | ||
state.containers = elementsAsArray.map(function(element) { | ||
return typeof element === "string" ? doc.querySelector(element) : element; | ||
}); | ||
if (state.active) { | ||
}, | ||
unpause: function unpause() { | ||
if (!state.paused || !state.active) { | ||
return this; | ||
} | ||
state.paused = false; | ||
updateTabbableNodes(); | ||
addListeners(); | ||
return this; | ||
}, | ||
updateContainerElements: function updateContainerElements(containerElements) { | ||
var elementsAsArray = [].concat(containerElements).filter(Boolean); | ||
state.containers = elementsAsArray.map(function(element) { | ||
return typeof element === "string" ? doc.querySelector(element) : element; | ||
}); | ||
if (state.active) { | ||
updateTabbableNodes(); | ||
} | ||
return this; | ||
} | ||
return this; | ||
} | ||
}; | ||
trap.updateContainerElements(elements); | ||
return trap; | ||
}; | ||
trap.updateContainerElements(elements); | ||
return trap; | ||
}; | ||
exports2.createFocusTrap = createFocusTrap2; | ||
exports.createFocusTrap = createFocusTrap2; | ||
} | ||
}); | ||
// packages/focus/builds/module.js | ||
__markAsModule(exports); | ||
__export(exports, { | ||
var module_exports = {}; | ||
__export(module_exports, { | ||
default: () => module_default | ||
}); | ||
module.exports = __toCommonJS(module_exports); | ||
// packages/focus/src/index.js | ||
var import_focus_trap = __toModule(require_focus_trap()); | ||
var import_tabbable = __toModule(require_dist()); | ||
var import_focus_trap = __toESM(require_focus_trap()); | ||
var import_tabbable = __toESM(require_dist()); | ||
function src_default(Alpine) { | ||
@@ -734,3 +904,3 @@ let lastFocused; | ||
return within; | ||
return (0, import_tabbable.focusable)(within, {displayCheck: "none"}); | ||
return (0, import_tabbable.focusable)(within, { displayCheck: "none" }); | ||
}, | ||
@@ -795,3 +965,3 @@ all() { | ||
el2.setAttribute("tabindex", "0"); | ||
el2.focus({preventScroll: this._noscroll}); | ||
el2.focus({ preventScroll: this._noscroll }); | ||
}); | ||
@@ -801,51 +971,57 @@ } | ||
}); | ||
Alpine.directive("trap", Alpine.skipDuringClone((el, {expression, modifiers}, {effect, evaluateLater, cleanup}) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let options = { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el | ||
}; | ||
let autofocusEl = el.querySelector("[autofocus]"); | ||
if (autofocusEl) | ||
options.initialFocus = autofocusEl; | ||
let trap = (0, import_focus_trap.createFocusTrap)(el, options); | ||
let undoInert = () => { | ||
}; | ||
let undoDisableScrolling = () => { | ||
}; | ||
const releaseFocus = () => { | ||
undoInert(); | ||
undoInert = () => { | ||
Alpine.directive("trap", Alpine.skipDuringClone( | ||
(el, { expression, modifiers }, { effect, evaluateLater, cleanup }) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let options = { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
let autofocusEl = el.querySelector("[autofocus]"); | ||
if (autofocusEl) | ||
options.initialFocus = autofocusEl; | ||
let trap = (0, import_focus_trap.createFocusTrap)(el, options); | ||
let undoInert = () => { | ||
}; | ||
trap.deactivate({ | ||
returnFocus: !modifiers.includes("noreturn") | ||
}); | ||
}; | ||
effect(() => evaluator((value) => { | ||
if (oldValue === value) | ||
return; | ||
if (value && !oldValue) { | ||
setTimeout(() => { | ||
if (modifiers.includes("inert")) | ||
undoInert = setInert(el); | ||
if (modifiers.includes("noscroll")) | ||
undoDisableScrolling = disableScrolling(); | ||
trap.activate(); | ||
let undoDisableScrolling = () => { | ||
}; | ||
const releaseFocus = () => { | ||
undoInert(); | ||
undoInert = () => { | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
}; | ||
trap.deactivate({ | ||
returnFocus: !modifiers.includes("noreturn") | ||
}); | ||
} | ||
if (!value && oldValue) { | ||
releaseFocus(); | ||
} | ||
oldValue = !!value; | ||
})); | ||
cleanup(releaseFocus); | ||
}, (el, {expression, modifiers}, {evaluate}) => { | ||
if (modifiers.includes("inert") && evaluate(expression)) | ||
setInert(el); | ||
})); | ||
}; | ||
effect(() => evaluator((value) => { | ||
if (oldValue === value) | ||
return; | ||
if (value && !oldValue) { | ||
setTimeout(() => { | ||
if (modifiers.includes("inert")) | ||
undoInert = setInert(el); | ||
if (modifiers.includes("noscroll")) | ||
undoDisableScrolling = disableScrolling(); | ||
trap.activate(); | ||
}); | ||
} | ||
if (!value && oldValue) { | ||
releaseFocus(); | ||
} | ||
oldValue = !!value; | ||
})); | ||
cleanup(releaseFocus); | ||
}, | ||
// When cloning, we only want to add aria-hidden attributes to the | ||
// DOM and not try to actually trap, as trapping can mess with the | ||
// live DOM and isn't just isolated to the cloned DOM. | ||
(el, { expression, modifiers }, { evaluate }) => { | ||
if (modifiers.includes("inert") && evaluate(expression)) | ||
setInert(el); | ||
} | ||
)); | ||
} | ||
@@ -889,1 +1065,17 @@ function setInert(el) { | ||
var module_default = src_default; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = {}); | ||
/*! Bundled license information: | ||
tabbable/dist/index.js: | ||
(*! | ||
* tabbable 5.3.3 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.js: | ||
(*! | ||
* focus-trap 6.9.4 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*) | ||
*/ |
// node_modules/tabbable/dist/index.esm.js | ||
/*! | ||
* tabbable 5.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*/ | ||
var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"]; | ||
var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]:not(slot)", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"]; | ||
var candidateSelector = /* @__PURE__ */ candidateSelectors.join(","); | ||
var matches = typeof Element === "undefined" ? function() { | ||
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) { | ||
return element.getRootNode(); | ||
} : function(element) { | ||
return element.ownerDocument; | ||
}; | ||
var getCandidates = function getCandidates2(el, includeContainer, filter) { | ||
@@ -18,16 +20,50 @@ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector)); | ||
}; | ||
var isContentEditable = function isContentEditable2(node) { | ||
return node.contentEditable === "true"; | ||
var getCandidatesIteratively = function getCandidatesIteratively2(elements, includeContainer, options) { | ||
var candidates = []; | ||
var elementsToCheck = Array.from(elements); | ||
while (elementsToCheck.length) { | ||
var element = elementsToCheck.shift(); | ||
if (element.tagName === "SLOT") { | ||
var assigned = element.assignedElements(); | ||
var content = assigned.length ? assigned : element.children; | ||
var nestedCandidates = getCandidatesIteratively2(content, true, options); | ||
if (options.flatten) { | ||
candidates.push.apply(candidates, nestedCandidates); | ||
} else { | ||
candidates.push({ | ||
scope: element, | ||
candidates: nestedCandidates | ||
}); | ||
} | ||
} else { | ||
var validCandidate = matches.call(element, candidateSelector); | ||
if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) { | ||
candidates.push(element); | ||
} | ||
var shadowRoot = element.shadowRoot || // check for an undisclosed shadow | ||
typeof options.getShadowRoot === "function" && options.getShadowRoot(element); | ||
var validShadowRoot = !options.shadowRootFilter || options.shadowRootFilter(element); | ||
if (shadowRoot && validShadowRoot) { | ||
var _nestedCandidates = getCandidatesIteratively2(shadowRoot === true ? element.children : shadowRoot.children, true, options); | ||
if (options.flatten) { | ||
candidates.push.apply(candidates, _nestedCandidates); | ||
} else { | ||
candidates.push({ | ||
scope: element, | ||
candidates: _nestedCandidates | ||
}); | ||
} | ||
} else { | ||
elementsToCheck.unshift.apply(elementsToCheck, element.children); | ||
} | ||
} | ||
} | ||
return candidates; | ||
}; | ||
var getTabindex = function getTabindex2(node) { | ||
var tabindexAttr = parseInt(node.getAttribute("tabindex"), 10); | ||
if (!isNaN(tabindexAttr)) { | ||
return tabindexAttr; | ||
var getTabindex = function getTabindex2(node, isScope) { | ||
if (node.tabIndex < 0) { | ||
if ((isScope || /^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || node.isContentEditable) && isNaN(parseInt(node.getAttribute("tabindex"), 10))) { | ||
return 0; | ||
} | ||
} | ||
if (isContentEditable(node)) { | ||
return 0; | ||
} | ||
if ((node.nodeName === "AUDIO" || node.nodeName === "VIDEO" || node.nodeName === "DETAILS") && node.getAttribute("tabindex") === null) { | ||
return 0; | ||
} | ||
return node.tabIndex; | ||
@@ -61,3 +97,3 @@ }; | ||
} | ||
var radioScope = node.form || node.ownerDocument; | ||
var radioScope = node.form || getRootNode(node); | ||
var queryRadios = function queryRadios2(name) { | ||
@@ -86,3 +122,8 @@ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]'); | ||
}; | ||
var isHidden = function isHidden2(node, displayCheck) { | ||
var isZeroArea = function isZeroArea2(node) { | ||
var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height; | ||
return width === 0 && height === 0; | ||
}; | ||
var isHidden = function isHidden2(node, _ref) { | ||
var displayCheck = _ref.displayCheck, getShadowRoot = _ref.getShadowRoot; | ||
if (getComputedStyle(node).visibility === "hidden") { | ||
@@ -96,12 +137,27 @@ return true; | ||
} | ||
var nodeRootHost = getRootNode(node).host; | ||
var nodeIsAttached = (nodeRootHost === null || nodeRootHost === void 0 ? void 0 : nodeRootHost.ownerDocument.contains(nodeRootHost)) || node.ownerDocument.contains(node); | ||
if (!displayCheck || displayCheck === "full") { | ||
while (node) { | ||
if (getComputedStyle(node).display === "none") { | ||
return true; | ||
if (typeof getShadowRoot === "function") { | ||
var originalNode = node; | ||
while (node) { | ||
var parentElement = node.parentElement; | ||
var rootNode = getRootNode(node); | ||
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 = node.parentElement; | ||
node = originalNode; | ||
} | ||
if (nodeIsAttached) { | ||
return !node.getClientRects().length; | ||
} | ||
} else if (displayCheck === "non-zero-area") { | ||
var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height; | ||
return width === 0 && height === 0; | ||
return isZeroArea(node); | ||
} | ||
@@ -111,3 +167,3 @@ return false; | ||
var isDisabledFromFieldset = function isDisabledFromFieldset2(node) { | ||
if (isInput(node) || node.tagName === "SELECT" || node.tagName === "TEXTAREA" || node.tagName === "BUTTON") { | ||
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) { | ||
var parentNode = node.parentElement; | ||
@@ -119,6 +175,3 @@ while (parentNode) { | ||
if (child.tagName === "LEGEND") { | ||
if (child.contains(node)) { | ||
return false; | ||
} | ||
return true; | ||
return matches.call(parentNode, "fieldset[disabled] *") ? true : !child.contains(node); | ||
} | ||
@@ -134,3 +187,4 @@ } | ||
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable2(options, node) { | ||
if (node.disabled || isHiddenInput(node) || isHidden(node, options.displayCheck) || isDetailsWithSummary(node) || isDisabledFromFieldset(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; | ||
@@ -141,3 +195,3 @@ } | ||
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(options, node) { | ||
if (!isNodeMatchingSelectorFocusable(options, node) || isNonTabbableRadio(node) || getTabindex(node) < 0) { | ||
if (isNonTabbableRadio(node) || getTabindex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) { | ||
return false; | ||
@@ -147,11 +201,19 @@ } | ||
}; | ||
var tabbable = function tabbable2(el, options) { | ||
options = options || {}; | ||
var isValidShadowRootTabbable = function isValidShadowRootTabbable2(shadowHostNode) { | ||
var tabIndex = parseInt(shadowHostNode.getAttribute("tabindex"), 10); | ||
if (isNaN(tabIndex) || tabIndex >= 0) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
var sortByOrder = function sortByOrder2(candidates) { | ||
var regularTabbables = []; | ||
var orderedTabbables = []; | ||
var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options)); | ||
candidates.forEach(function(candidate, i) { | ||
var candidateTabindex = getTabindex(candidate); | ||
candidates.forEach(function(item, i) { | ||
var isScope = !!item.scope; | ||
var element = isScope ? item.scope : item; | ||
var candidateTabindex = getTabindex(element, isScope); | ||
var elements = isScope ? sortByOrder2(item.candidates) : element; | ||
if (candidateTabindex === 0) { | ||
regularTabbables.push(candidate); | ||
isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element); | ||
} else { | ||
@@ -161,16 +223,52 @@ orderedTabbables.push({ | ||
tabIndex: candidateTabindex, | ||
node: candidate | ||
item, | ||
isScope, | ||
content: elements | ||
}); | ||
} | ||
}); | ||
var tabbableNodes = orderedTabbables.sort(sortOrderedTabbables).map(function(a) { | ||
return a.node; | ||
}).concat(regularTabbables); | ||
return tabbableNodes; | ||
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(el, options) { | ||
options = options || {}; | ||
var candidates; | ||
if (options.getShadowRoot) { | ||
candidates = getCandidatesIteratively([el], options.includeContainer, { | ||
filter: isNodeMatchingSelectorTabbable.bind(null, options), | ||
flatten: false, | ||
getShadowRoot: options.getShadowRoot, | ||
shadowRootFilter: isValidShadowRootTabbable | ||
}); | ||
} else { | ||
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options)); | ||
} | ||
return sortByOrder(candidates); | ||
}; | ||
var focusable = function focusable2(el, options) { | ||
options = options || {}; | ||
var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options)); | ||
var candidates; | ||
if (options.getShadowRoot) { | ||
candidates = getCandidatesIteratively([el], options.includeContainer, { | ||
filter: isNodeMatchingSelectorFocusable.bind(null, options), | ||
flatten: true, | ||
getShadowRoot: options.getShadowRoot | ||
}); | ||
} else { | ||
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options)); | ||
} | ||
return candidates; | ||
}; | ||
var isTabbable = function isTabbable2(node, options) { | ||
options = options || {}; | ||
if (!node) { | ||
throw new Error("No node provided"); | ||
} | ||
if (matches.call(node, candidateSelector) === false) { | ||
return false; | ||
} | ||
return isNodeMatchingSelectorTabbable(options, node); | ||
}; | ||
var focusableCandidateSelector = /* @__PURE__ */ candidateSelectors.concat("iframe").join(","); | ||
@@ -189,6 +287,2 @@ var isFocusable = function isFocusable2(node, options) { | ||
// node_modules/focus-trap/dist/focus-trap.esm.js | ||
/*! | ||
* focus-trap 6.6.1 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*/ | ||
function ownKeys(object, enumerableOnly) { | ||
@@ -198,8 +292,5 @@ var keys = Object.keys(object); | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
enumerableOnly && (symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
@@ -210,14 +301,8 @@ return keys; | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
@@ -297,4 +382,7 @@ return target; | ||
}; | ||
var getActualTarget = function getActualTarget2(event) { | ||
return event.target.shadowRoot && typeof event.composedPath === "function" ? event.composedPath()[0] : event.target; | ||
}; | ||
var createFocusTrap = function createFocusTrap2(elements, userOptions) { | ||
var doc = document; | ||
var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document; | ||
var config = _objectSpread2({ | ||
@@ -306,3 +394,24 @@ returnFocusOnDeactivate: true, | ||
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 | ||
// firstTabbableNode: HTMLElement|null, | ||
// lastTabbableNode: HTMLElement|null, | ||
// 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: [], | ||
@@ -313,2 +422,4 @@ nodeFocusedBeforeActivation: null, | ||
paused: false, | ||
// timer ID for when delayInitialFocus is true and initial focus in this trap | ||
// has been delayed during activation | ||
delayInitialFocusTimer: void 0 | ||
@@ -320,5 +431,12 @@ }; | ||
}; | ||
var containersContain = function containersContain2(element) { | ||
return state.containers.some(function(container) { | ||
return container.contains(element); | ||
var findContainerIndex = function findContainerIndex2(element) { | ||
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) | ||
tabbableNodes.find(function(node) { | ||
return node === element; | ||
}); | ||
}); | ||
@@ -328,4 +446,16 @@ }; | ||
var optionValue = config[optionName]; | ||
if (typeof optionValue === "function") { | ||
for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
params[_key2 - 1] = arguments[_key2]; | ||
} | ||
optionValue = optionValue.apply(void 0, params); | ||
} | ||
if (optionValue === true) { | ||
optionValue = void 0; | ||
} | ||
if (!optionValue) { | ||
return null; | ||
if (optionValue === void 0 || optionValue === false) { | ||
return optionValue; | ||
} | ||
throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node")); | ||
} | ||
@@ -336,26 +466,20 @@ var node = optionValue; | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` refers to no known node")); | ||
throw new Error("`".concat(optionName, "` as selector refers to no known node")); | ||
} | ||
} | ||
if (typeof optionValue === "function") { | ||
node = optionValue(); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` did not return a node")); | ||
} | ||
} | ||
return node; | ||
}; | ||
var getInitialFocusNode = function getInitialFocusNode2() { | ||
var node; | ||
if (getOption({}, "initialFocus") === false) { | ||
var node = getNodeForOption("initialFocus"); | ||
if (node === false) { | ||
return false; | ||
} | ||
if (getNodeForOption("initialFocus") !== null) { | ||
node = getNodeForOption("initialFocus"); | ||
} else if (containersContain(doc.activeElement)) { | ||
node = doc.activeElement; | ||
} else { | ||
var firstTabbableGroup = state.tabbableGroups[0]; | ||
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; | ||
node = firstTabbableNode || getNodeForOption("fallbackFocus"); | ||
if (node === void 0) { | ||
if (findContainerIndex(doc.activeElement) >= 0) { | ||
node = doc.activeElement; | ||
} else { | ||
var firstTabbableGroup = state.tabbableGroups[0]; | ||
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; | ||
node = firstTabbableNode || getNodeForOption("fallbackFocus"); | ||
} | ||
} | ||
@@ -368,15 +492,41 @@ if (!node) { | ||
var updateTabbableNodes = function updateTabbableNodes2() { | ||
state.tabbableGroups = state.containers.map(function(container) { | ||
var tabbableNodes = tabbable(container); | ||
if (tabbableNodes.length > 0) { | ||
return { | ||
container, | ||
firstTabbableNode: tabbableNodes[0], | ||
lastTabbableNode: tabbableNodes[tabbableNodes.length - 1] | ||
}; | ||
} | ||
return void 0; | ||
}).filter(function(group) { | ||
return !!group; | ||
state.containerGroups = state.containers.map(function(container) { | ||
var tabbableNodes = tabbable(container, config.tabbableOptions); | ||
var focusableNodes = focusable(container, config.tabbableOptions); | ||
return { | ||
container, | ||
tabbableNodes, | ||
focusableNodes, | ||
firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null, | ||
lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null, | ||
/** | ||
* 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) { | ||
var forward = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true; | ||
var nodeIdx = focusableNodes.findIndex(function(n) { | ||
return n === node; | ||
}); | ||
if (nodeIdx < 0) { | ||
return void 0; | ||
} | ||
if (forward) { | ||
return focusableNodes.slice(nodeIdx + 1).find(function(n) { | ||
return isTabbable(n, config.tabbableOptions); | ||
}); | ||
} | ||
return focusableNodes.slice(0, nodeIdx).reverse().find(function(n) { | ||
return isTabbable(n, config.tabbableOptions); | ||
}); | ||
} | ||
}; | ||
}); | ||
state.tabbableGroups = state.containerGroups.filter(function(group) { | ||
return group.tabbableNodes.length > 0; | ||
}); | ||
if (state.tabbableGroups.length <= 0 && !getNodeForOption("fallbackFocus")) { | ||
@@ -406,7 +556,8 @@ throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times"); | ||
var getReturnFocusNode = function getReturnFocusNode2(previousActiveElement) { | ||
var node = getNodeForOption("setReturnFocus"); | ||
return node ? node : previousActiveElement; | ||
var node = getNodeForOption("setReturnFocus", previousActiveElement); | ||
return node ? node : node === false ? false : previousActiveElement; | ||
}; | ||
var checkPointerDown = function checkPointerDown2(e) { | ||
if (containersContain(e.target)) { | ||
var target = getActualTarget(e); | ||
if (findContainerIndex(target) >= 0) { | ||
return; | ||
@@ -416,3 +567,14 @@ } | ||
trap.deactivate({ | ||
returnFocus: config.returnFocusOnDeactivate && !isFocusable(e.target) | ||
// if, on deactivation, we should return focus to the node originally-focused | ||
// when the trap was activated (or the configured `setReturnFocus` node), | ||
// then assume it's also OK to return focus to the outside node that was | ||
// just clicked, causing deactivation, as long as that node is focusable; | ||
// if it isn't focusable, then return focus to the original node focused | ||
// on activation (or the configured `setReturnFocus` node) | ||
// NOTE: by setting `returnFocus: false`, deactivate() will do nothing, | ||
// which will result in the outside click setting focus to the node | ||
// that was clicked, whether it's focusable or not; by setting | ||
// `returnFocus: true`, we'll attempt to re-focus the node originally-focused | ||
// on activation (or the configured `setReturnFocus` node) | ||
returnFocus: config.returnFocusOnDeactivate && !isFocusable(target, config.tabbableOptions) | ||
}); | ||
@@ -427,6 +589,7 @@ return; | ||
var checkFocusIn = function checkFocusIn2(e) { | ||
var targetContained = containersContain(e.target); | ||
if (targetContained || e.target instanceof Document) { | ||
var target = getActualTarget(e); | ||
var targetContained = findContainerIndex(target) >= 0; | ||
if (targetContained || target instanceof Document) { | ||
if (targetContained) { | ||
state.mostRecentlyFocusedNode = e.target; | ||
state.mostRecentlyFocusedNode = target; | ||
} | ||
@@ -439,9 +602,8 @@ } else { | ||
var checkTab = function checkTab2(e) { | ||
var target = getActualTarget(e); | ||
updateTabbableNodes(); | ||
var destinationNode = null; | ||
if (state.tabbableGroups.length > 0) { | ||
var containerIndex = findIndex(state.tabbableGroups, function(_ref) { | ||
var container = _ref.container; | ||
return container.contains(e.target); | ||
}); | ||
var containerIndex = findContainerIndex(target); | ||
var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : void 0; | ||
if (containerIndex < 0) { | ||
@@ -456,5 +618,5 @@ if (e.shiftKey) { | ||
var firstTabbableNode = _ref2.firstTabbableNode; | ||
return e.target === firstTabbableNode; | ||
return target === firstTabbableNode; | ||
}); | ||
if (startOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) { | ||
if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) { | ||
startOfGroupIndex = containerIndex; | ||
@@ -470,5 +632,5 @@ } | ||
var lastTabbableNode = _ref3.lastTabbableNode; | ||
return e.target === lastTabbableNode; | ||
return target === lastTabbableNode; | ||
}); | ||
if (lastOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e.target) { | ||
if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) { | ||
lastOfGroupIndex = containerIndex; | ||
@@ -491,3 +653,3 @@ } | ||
var checkKey = function checkKey2(e) { | ||
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates) !== false) { | ||
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) { | ||
e.preventDefault(); | ||
@@ -503,6 +665,7 @@ trap.deactivate(); | ||
var checkClick = function checkClick2(e) { | ||
if (valueOrHandler(config.clickOutsideDeactivates, e)) { | ||
var target = getActualTarget(e); | ||
if (findContainerIndex(target) >= 0) { | ||
return; | ||
} | ||
if (containersContain(e.target)) { | ||
if (valueOrHandler(config.clickOutsideDeactivates, e)) { | ||
return; | ||
@@ -555,2 +718,8 @@ } | ||
trap = { | ||
get active() { | ||
return state.active; | ||
}, | ||
get paused() { | ||
return state.paused; | ||
}, | ||
activate: function activate(activateOptions) { | ||
@@ -592,2 +761,7 @@ if (state.active) { | ||
} | ||
var options = _objectSpread2({ | ||
onDeactivate: config.onDeactivate, | ||
onPostDeactivate: config.onPostDeactivate, | ||
checkCanReturnFocus: config.checkCanReturnFocus | ||
}, deactivateOptions); | ||
clearTimeout(state.delayInitialFocusTimer); | ||
@@ -599,9 +773,9 @@ state.delayInitialFocusTimer = void 0; | ||
activeFocusTraps.deactivateTrap(trap); | ||
var onDeactivate = getOption(deactivateOptions, "onDeactivate"); | ||
var onPostDeactivate = getOption(deactivateOptions, "onPostDeactivate"); | ||
var checkCanReturnFocus = getOption(deactivateOptions, "checkCanReturnFocus"); | ||
var onDeactivate = getOption(options, "onDeactivate"); | ||
var onPostDeactivate = getOption(options, "onPostDeactivate"); | ||
var checkCanReturnFocus = getOption(options, "checkCanReturnFocus"); | ||
var returnFocus = getOption(options, "returnFocus", "returnFocusOnDeactivate"); | ||
if (onDeactivate) { | ||
onDeactivate(); | ||
} | ||
var returnFocus = getOption(deactivateOptions, "returnFocus", "returnFocusOnDeactivate"); | ||
var finishDeactivation = function finishDeactivation2() { | ||
@@ -703,3 +877,3 @@ delay(function() { | ||
return within; | ||
return focusable(within, {displayCheck: "none"}); | ||
return focusable(within, { displayCheck: "none" }); | ||
}, | ||
@@ -764,3 +938,3 @@ all() { | ||
el2.setAttribute("tabindex", "0"); | ||
el2.focus({preventScroll: this._noscroll}); | ||
el2.focus({ preventScroll: this._noscroll }); | ||
}); | ||
@@ -770,51 +944,57 @@ } | ||
}); | ||
Alpine.directive("trap", Alpine.skipDuringClone((el, {expression, modifiers}, {effect, evaluateLater, cleanup}) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let options = { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el | ||
}; | ||
let autofocusEl = el.querySelector("[autofocus]"); | ||
if (autofocusEl) | ||
options.initialFocus = autofocusEl; | ||
let trap = createFocusTrap(el, options); | ||
let undoInert = () => { | ||
}; | ||
let undoDisableScrolling = () => { | ||
}; | ||
const releaseFocus = () => { | ||
undoInert(); | ||
undoInert = () => { | ||
Alpine.directive("trap", Alpine.skipDuringClone( | ||
(el, { expression, modifiers }, { effect, evaluateLater, cleanup }) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let options = { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
let autofocusEl = el.querySelector("[autofocus]"); | ||
if (autofocusEl) | ||
options.initialFocus = autofocusEl; | ||
let trap = createFocusTrap(el, options); | ||
let undoInert = () => { | ||
}; | ||
trap.deactivate({ | ||
returnFocus: !modifiers.includes("noreturn") | ||
}); | ||
}; | ||
effect(() => evaluator((value) => { | ||
if (oldValue === value) | ||
return; | ||
if (value && !oldValue) { | ||
setTimeout(() => { | ||
if (modifiers.includes("inert")) | ||
undoInert = setInert(el); | ||
if (modifiers.includes("noscroll")) | ||
undoDisableScrolling = disableScrolling(); | ||
trap.activate(); | ||
let undoDisableScrolling = () => { | ||
}; | ||
const releaseFocus = () => { | ||
undoInert(); | ||
undoInert = () => { | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
}; | ||
trap.deactivate({ | ||
returnFocus: !modifiers.includes("noreturn") | ||
}); | ||
} | ||
if (!value && oldValue) { | ||
releaseFocus(); | ||
} | ||
oldValue = !!value; | ||
})); | ||
cleanup(releaseFocus); | ||
}, (el, {expression, modifiers}, {evaluate}) => { | ||
if (modifiers.includes("inert") && evaluate(expression)) | ||
setInert(el); | ||
})); | ||
}; | ||
effect(() => evaluator((value) => { | ||
if (oldValue === value) | ||
return; | ||
if (value && !oldValue) { | ||
setTimeout(() => { | ||
if (modifiers.includes("inert")) | ||
undoInert = setInert(el); | ||
if (modifiers.includes("noscroll")) | ||
undoDisableScrolling = disableScrolling(); | ||
trap.activate(); | ||
}); | ||
} | ||
if (!value && oldValue) { | ||
releaseFocus(); | ||
} | ||
oldValue = !!value; | ||
})); | ||
cleanup(releaseFocus); | ||
}, | ||
// When cloning, we only want to add aria-hidden attributes to the | ||
// DOM and not try to actually trap, as trapping can mess with the | ||
// live DOM and isn't just isolated to the cloned DOM. | ||
(el, { expression, modifiers }, { evaluate }) => { | ||
if (modifiers.includes("inert") && evaluate(expression)) | ||
setInert(el); | ||
} | ||
)); | ||
} | ||
@@ -861,1 +1041,15 @@ function setInert(el) { | ||
}; | ||
/*! Bundled license information: | ||
tabbable/dist/index.esm.js: | ||
(*! | ||
* tabbable 5.3.3 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.esm.js: | ||
(*! | ||
* focus-trap 6.9.4 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*) | ||
*/ |
{ | ||
"name": "@alpinejs/focus", | ||
"version": "3.12.3", | ||
"version": "3.13.0", | ||
"description": "Manage focus within a page", | ||
@@ -17,4 +17,5 @@ "homepage": "https://alpinejs.dev/plugins/focus", | ||
"dependencies": { | ||
"focus-trap": "^6.6.1" | ||
"focus-trap": "^6.9.4", | ||
"tabbable": "^5.3.3" | ||
} | ||
} |
139132
3338
2
+ Addedtabbable@^5.3.3
Updatedfocus-trap@^6.9.4