@alpinejs/focus
Advanced tools
Comparing version 3.11.1 to 3.12.0
142
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"]; | ||
@@ -129,3 +125,4 @@ var candidateSelector = /* @__PURE__ */ candidateSelectors.join(","); | ||
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.displayCheck) || // For a details element with a summary, the summary element gets the focus | ||
isDetailsWithSummary(node) || isDisabledFromFieldset(node)) { | ||
return false; | ||
@@ -181,6 +178,2 @@ } | ||
// 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) { | ||
@@ -295,3 +288,11 @@ var keys = Object.keys(object); | ||
var state = { | ||
// @type {Array<HTMLElement>} | ||
containers: [], | ||
// list of objects identifying the first and last tabbable nodes in all containers/groups 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, firstTabbableNode: HTMLElement|null, lastTabbableNode: HTMLElement|null }>} | ||
tabbableGroups: [], | ||
@@ -302,2 +303,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 | ||
@@ -400,2 +403,13 @@ }; | ||
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 && !isFocusable(e.target) | ||
@@ -678,3 +692,3 @@ }); | ||
return within; | ||
return focusable(within, {displayCheck: "none"}); | ||
return focusable(within, { displayCheck: "none" }); | ||
}, | ||
@@ -739,3 +753,3 @@ all() { | ||
el2.setAttribute("tabindex", "0"); | ||
el2.focus({preventScroll: this._noscroll}); | ||
el2.focus({ preventScroll: this._noscroll }); | ||
}); | ||
@@ -745,48 +759,54 @@ } | ||
}); | ||
Alpine.directive("trap", Alpine.skipDuringClone((el, {expression, modifiers}, {effect, evaluateLater, cleanup}) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let trap = createFocusTrap(el, { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el, | ||
initialFocus: el.querySelector("[autofocus]") | ||
}); | ||
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 trap = createFocusTrap(el, { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el, | ||
initialFocus: el.querySelector("[autofocus]") | ||
}); | ||
let undoInert = () => { | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
let undoDisableScrolling = () => { | ||
}; | ||
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(); | ||
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); | ||
} | ||
)); | ||
} | ||
@@ -833,1 +853,15 @@ function setInert(el) { | ||
})(); | ||
/*! Bundled license information: | ||
tabbable/dist/index.esm.js: | ||
(*! | ||
* tabbable 5.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.esm.js: | ||
(*! | ||
* focus-trap 6.6.1 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*) | ||
*/ |
@@ -1,9 +0,15 @@ | ||
(()=>{var j=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details"],_=j.join(","),A=typeof Element=="undefined"?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,G=function(e,t,a){var u=Array.prototype.slice.apply(e.querySelectorAll(_));return t&&A.call(e,_)&&u.unshift(e),u=u.filter(a),u},Z=function(e){return e.contentEditable==="true"},M=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},C=function(e){return e.tagName==="INPUT"},ee=function(e){return C(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 C(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=A.call(e,"details>summary:first-of-type"),u=a?e.parentElement:e;if(A.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(C(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},O=function(e,t){return!(t.disabled||ee(t)||ue(t,e.displayCheck)||te(t)||oe(t))},se=function(e,t){return!(!O(e,t)||ie(t)||M(t)<0)},q=function(e,t){t=t||{};var a=[],u=[],r=G(e,t.includeContainer,se.bind(null,t));r.forEach(function(l,h){var b=M(l);b===0?a.push(l):u.push({documentOrder:h,tabIndex:b,node:l})});var s=u.sort($).map(function(l){return l.node}).concat(a);return s},W=function(e,t){t=t||{};var a=G(e,t.includeContainer,O.bind(null,t));return a};var ce=j.concat("iframe").join(","),k=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return A.call(e,ce)===!1?!1:O(t,e)};function B(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?B(Object(t),!0).forEach(function(a){le(i,a,t[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(t)):B(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 H=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},U=function(e){return setTimeout(e,0)},L=function(e,t){var a=-1;return e.every(function(u,r){return t(u)?(a=r,!1):!0}),a},D=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},K=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]},h=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(h(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},m=function(){if(r.tabbableGroups=r.containers.map(function(n){var o=q(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")},p=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()}},E=function(n){var o=b("setReturnFocus");return o||n},y=function(n){if(!h(n.target)){if(D(u.clickOutsideDeactivates,n)){s.deactivate({returnFocus:u.returnFocusOnDeactivate&&!k(n.target)});return}D(u.allowOutsideClick,n)||n.preventDefault()}},w=function(n){var o=h(n.target);o||n.target instanceof Document?o&&(r.mostRecentlyFocusedNode=n.target):(n.stopImmediatePropagation(),p(r.mostRecentlyFocusedNode||v()))},Q=function(n){m();var o=null;if(r.tabbableGroups.length>0){var c=L(r.tabbableGroups,function(S){var N=S.container;return N.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=L(r.tabbableGroups,function(S){var N=S.firstTabbableNode;return n.target===N});if(d<0&&r.tabbableGroups[c].container===n.target&&(d=c),d>=0){var g=d===0?r.tabbableGroups.length-1:d-1,F=r.tabbableGroups[g];o=F.lastTabbableNode}}else{var T=L(r.tabbableGroups,function(S){var N=S.lastTabbableNode;return n.target===N});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(),p(o))},R=function(n){if(be(n)&&D(u.escapeDeactivates)!==!1){n.preventDefault(),s.deactivate();return}if(ve(n)){Q(n);return}},x=function(n){D(u.clickOutsideDeactivates,n)||h(n.target)||D(u.allowOutsideClick,n)||(n.preventDefault(),n.stopImmediatePropagation())},I=function(){if(!!r.active)return H.activateTrap(s),r.delayInitialFocusTimer=u.delayInitialFocus?U(function(){p(v())}):p(v()),a.addEventListener("focusin",w,!0),a.addEventListener("mousedown",y,{capture:!0,passive:!1}),a.addEventListener("touchstart",y,{capture:!0,passive:!1}),a.addEventListener("click",x,{capture:!0,passive:!1}),a.addEventListener("keydown",R,{capture:!0,passive:!1}),s},P=function(){if(!!r.active)return a.removeEventListener("focusin",w,!0),a.removeEventListener("mousedown",y,!0),a.removeEventListener("touchstart",y,!0),a.removeEventListener("click",x,!0),a.removeEventListener("keydown",R,!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||m(),r.active=!0,r.paused=!1,r.nodeFocusedBeforeActivation=a.activeElement,o&&o();var g=function(){d&&m(),I(),c&&c()};return d?(d(r.containers.concat()).then(g,g),this):(g(),this)},deactivate:function(n){if(!r.active)return this;clearTimeout(r.delayInitialFocusTimer),r.delayInitialFocusTimer=void 0,P(),r.active=!1,r.paused=!1,H.deactivateTrap(s);var o=l(n,"onDeactivate"),c=l(n,"onPostDeactivate"),d=l(n,"checkCanReturnFocus");o&&o();var g=l(n,"returnFocus","returnFocusOnDeactivate"),F=function(){U(function(){g&&p(E(r.nodeFocusedBeforeActivation)),c&&c()})};return g&&d?(d(E(r.nodeFocusedBeforeActivation)).then(F,F),this):(F(),this)},pause:function(){return r.paused||!r.active?this:(r.paused=!0,P(),this)},unpause:function(){return!r.paused||!r.active?this:(r.paused=!1,m(),I(),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&&m(),this}},s.updateContainerElements(e),s};function Y(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 k(r)},previouslyFocused(){return e},lastFocused(){return e},focused(){return t},focusables(){return Array.isArray(u)?u:W(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:h})=>{let b=l(u),v=!1,m=K(a,{escapeDeactivates:!1,allowOutsideClick:!0,fallbackFocus:()=>a,initialFocus:a.querySelector("[autofocus]")}),p=()=>{},E=()=>{},y=()=>{p(),p=()=>{},E(),E=()=>{},m.deactivate({returnFocus:!r.includes("noreturn")})};s(()=>b(w=>{v!==w&&(w&&!v&&setTimeout(()=>{r.includes("inert")&&(p=V(a)),r.includes("noscroll")&&(E=pe()),m.activate()}),!w&&v&&y(),v=!!w)})),h(y)},(a,{expression:u,modifiers:r},{evaluate:s})=>{r.includes("inert")&&s(u)&&V(a)}))}function V(i){let e=[];return z(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 z(i,e){i.isSameNode(document.body)||!i.parentNode||Array.from(i.parentNode.children).forEach(t=>{t.isSameNode(i)?z(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(Y)});})(); | ||
/*! | ||
* focus-trap 6.6.1 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
(()=>{var j=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details"],_=j.join(","),A=typeof Element>"u"?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,G=function(e,t,a){var u=Array.prototype.slice.apply(e.querySelectorAll(_));return t&&A.call(e,_)&&u.unshift(e),u=u.filter(a),u},Z=function(e){return e.contentEditable==="true"},M=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},C=function(e){return e.tagName==="INPUT"},ee=function(e){return C(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<"u"&&typeof window.CSS<"u"&&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 C(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=A.call(e,"details>summary:first-of-type"),u=a?e.parentElement:e;if(A.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(C(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},O=function(e,t){return!(t.disabled||ee(t)||ue(t,e.displayCheck)||te(t)||oe(t))},se=function(e,t){return!(!O(e,t)||ie(t)||M(t)<0)},q=function(e,t){t=t||{};var a=[],u=[],r=G(e,t.includeContainer,se.bind(null,t));r.forEach(function(l,h){var b=M(l);b===0?a.push(l):u.push({documentOrder:h,tabIndex:b,node:l})});var s=u.sort($).map(function(l){return l.node}).concat(a);return s},W=function(e,t){t=t||{};var a=G(e,t.includeContainer,O.bind(null,t));return a};var ce=j.concat("iframe").join(","),k=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return A.call(e,ce)===!1?!1:O(t,e)};function B(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 le(i){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?B(Object(t),!0).forEach(function(a){fe(i,a,t[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(t)):B(Object(t)).forEach(function(a){Object.defineProperty(i,a,Object.getOwnPropertyDescriptor(t,a))})}return i}function fe(i,e,t){return e in i?Object.defineProperty(i,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):i[e]=t,i}var H=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},U=function(e){return setTimeout(e,0)},L=function(e,t){var a=-1;return e.every(function(u,r){return t(u)?(a=r,!1):!0}),a},D=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},K=function(e,t){var a=document,u=le({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]},h=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(h(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},m=function(){if(r.tabbableGroups=r.containers.map(function(n){var o=q(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")},p=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()}},E=function(n){var o=b("setReturnFocus");return o||n},y=function(n){if(!h(n.target)){if(D(u.clickOutsideDeactivates,n)){s.deactivate({returnFocus:u.returnFocusOnDeactivate&&!k(n.target)});return}D(u.allowOutsideClick,n)||n.preventDefault()}},w=function(n){var o=h(n.target);o||n.target instanceof Document?o&&(r.mostRecentlyFocusedNode=n.target):(n.stopImmediatePropagation(),p(r.mostRecentlyFocusedNode||v()))},Q=function(n){m();var o=null;if(r.tabbableGroups.length>0){var c=L(r.tabbableGroups,function(S){var N=S.container;return N.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=L(r.tabbableGroups,function(S){var N=S.firstTabbableNode;return n.target===N});if(d<0&&r.tabbableGroups[c].container===n.target&&(d=c),d>=0){var g=d===0?r.tabbableGroups.length-1:d-1,F=r.tabbableGroups[g];o=F.lastTabbableNode}}else{var T=L(r.tabbableGroups,function(S){var N=S.lastTabbableNode;return n.target===N});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(),p(o))},R=function(n){if(be(n)&&D(u.escapeDeactivates)!==!1){n.preventDefault(),s.deactivate();return}if(ve(n)){Q(n);return}},I=function(n){D(u.clickOutsideDeactivates,n)||h(n.target)||D(u.allowOutsideClick,n)||(n.preventDefault(),n.stopImmediatePropagation())},x=function(){if(r.active)return H.activateTrap(s),r.delayInitialFocusTimer=u.delayInitialFocus?U(function(){p(v())}):p(v()),a.addEventListener("focusin",w,!0),a.addEventListener("mousedown",y,{capture:!0,passive:!1}),a.addEventListener("touchstart",y,{capture:!0,passive:!1}),a.addEventListener("click",I,{capture:!0,passive:!1}),a.addEventListener("keydown",R,{capture:!0,passive:!1}),s},P=function(){if(r.active)return a.removeEventListener("focusin",w,!0),a.removeEventListener("mousedown",y,!0),a.removeEventListener("touchstart",y,!0),a.removeEventListener("click",I,!0),a.removeEventListener("keydown",R,!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||m(),r.active=!0,r.paused=!1,r.nodeFocusedBeforeActivation=a.activeElement,o&&o();var g=function(){d&&m(),x(),c&&c()};return d?(d(r.containers.concat()).then(g,g),this):(g(),this)},deactivate:function(n){if(!r.active)return this;clearTimeout(r.delayInitialFocusTimer),r.delayInitialFocusTimer=void 0,P(),r.active=!1,r.paused=!1,H.deactivateTrap(s);var o=l(n,"onDeactivate"),c=l(n,"onPostDeactivate"),d=l(n,"checkCanReturnFocus");o&&o();var g=l(n,"returnFocus","returnFocusOnDeactivate"),F=function(){U(function(){g&&p(E(r.nodeFocusedBeforeActivation)),c&&c()})};return g&&d?(d(E(r.nodeFocusedBeforeActivation)).then(F,F),this):(F(),this)},pause:function(){return r.paused||!r.active?this:(r.paused=!0,P(),this)},unpause:function(){return!r.paused||!r.active?this:(r.paused=!1,m(),x(),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&&m(),this}},s.updateContainerElements(e),s};function Y(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 k(r)},previouslyFocused(){return e},lastFocused(){return e},focused(){return t},focusables(){return Array.isArray(u)?u:W(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:h})=>{let b=l(u),v=!1,m=K(a,{escapeDeactivates:!1,allowOutsideClick:!0,fallbackFocus:()=>a,initialFocus:a.querySelector("[autofocus]")}),p=()=>{},E=()=>{},y=()=>{p(),p=()=>{},E(),E=()=>{},m.deactivate({returnFocus:!r.includes("noreturn")})};s(()=>b(w=>{v!==w&&(w&&!v&&setTimeout(()=>{r.includes("inert")&&(p=V(a)),r.includes("noscroll")&&(E=pe()),m.activate()}),!w&&v&&y(),v=!!w)})),h(y)},(a,{expression:u,modifiers:r},{evaluate:s})=>{r.includes("inert")&&s(u)&&V(a)}))}function V(i){let e=[];return z(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 z(i,e){i.isSameNode(document.body)||!i.parentNode||Array.from(i.parentNode.children).forEach(t=>{t.isSameNode(i)?z(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(Y)});})(); | ||
/*! Bundled license information: | ||
tabbable/dist/index.esm.js: | ||
(*! | ||
* tabbable 5.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.esm.js: | ||
(*! | ||
* focus-trap 6.6.1 | ||
* @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]", "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); | ||
} | ||
} | ||
}; | ||
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 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; | ||
} | ||
} | ||
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; | ||
} | ||
node = node.parentElement; | ||
if (isContentEditable(node)) { | ||
return 0; | ||
} | ||
} 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; | ||
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]; | ||
} | ||
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); | ||
} else { | ||
orderedTabbables.push({ | ||
documentOrder: i, | ||
tabIndex: candidateTabindex, | ||
node: candidate | ||
}); | ||
}; | ||
var isTabbableRadio = function isTabbableRadio2(node) { | ||
if (!node.name) { | ||
return true; | ||
} | ||
}); | ||
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; | ||
}); | ||
} | ||
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)); | ||
var radioScope = node.form || node.ownerDocument; | ||
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 { | ||
ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
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(); | ||
} | ||
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 trapIndex = trapQueue.indexOf(trap); | ||
if (trapIndex === -1) { | ||
trapQueue.push(trap); | ||
} else { | ||
trapQueue.splice(trapIndex, 1); | ||
trapQueue.push(trap); | ||
} | ||
}, | ||
deactivateTrap: function deactivateTrap(trap) { | ||
var trapIndex = trapQueue.indexOf(trap); | ||
if (trapIndex !== -1) { | ||
trapQueue.splice(trapIndex, 1); | ||
} | ||
if (trapQueue.length > 0) { | ||
trapQueue[trapQueue.length - 1].unpause(); | ||
} | ||
} | ||
var checked = getCheckedRadio(radioSet, node.form); | ||
return !checked || checked === node; | ||
}; | ||
}(); | ||
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; | ||
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 isRadio = function isRadio2(node) { | ||
return isInput(node) && node.type === "radio"; | ||
}; | ||
var trap; | ||
var getOption = function getOption2(configOverrideOptions, optionName, configOptionName) { | ||
return configOverrideOptions && configOverrideOptions[optionName] !== void 0 ? configOverrideOptions[optionName] : config[configOptionName || optionName]; | ||
var isNonTabbableRadio = function isNonTabbableRadio2(node) { | ||
return isRadio(node) && !isTabbableRadio(node); | ||
}; | ||
var containersContain = function containersContain2(element) { | ||
return state.containers.some(function(container) { | ||
return container.contains(element); | ||
}); | ||
}; | ||
var getNodeForOption = function getNodeForOption2(optionName) { | ||
var optionValue = config[optionName]; | ||
if (!optionValue) { | ||
return null; | ||
var isHidden = function isHidden2(node, displayCheck) { | ||
if (getComputedStyle(node).visibility === "hidden") { | ||
return true; | ||
} | ||
var node = optionValue; | ||
if (typeof optionValue === "string") { | ||
node = doc.querySelector(optionValue); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` refers to no known node")); | ||
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; | ||
} | ||
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; | ||
} | ||
if (typeof optionValue === "function") { | ||
node = optionValue(); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` did not return a node")); | ||
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; | ||
} | ||
parentNode = parentNode.parentElement; | ||
} | ||
} | ||
return node; | ||
return false; | ||
}; | ||
var getInitialFocusNode = function getInitialFocusNode2() { | ||
var node; | ||
if (getOption({}, "initialFocus") === false) { | ||
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable2(options, node) { | ||
if (node.disabled || isHiddenInput(node) || isHidden(node, options.displayCheck) || // For a details element with a summary, the summary element gets the focus | ||
isDetailsWithSummary(node) || isDisabledFromFieldset(node)) { | ||
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"); | ||
return true; | ||
}; | ||
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(options, node) { | ||
if (!isNodeMatchingSelectorFocusable(options, node) || isNonTabbableRadio(node) || getTabindex(node) < 0) { | ||
return false; | ||
} | ||
if (!node) { | ||
throw new Error("Your focus-trap needs to have at least one focusable element"); | ||
} | ||
return node; | ||
return true; | ||
}; | ||
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] | ||
}; | ||
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); | ||
} else { | ||
orderedTabbables.push({ | ||
documentOrder: i, | ||
tabIndex: candidateTabindex, | ||
node: candidate | ||
}); | ||
} | ||
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"); | ||
} | ||
var tabbableNodes = orderedTabbables.sort(sortOrderedTabbables).map(function(a) { | ||
return a.node; | ||
}).concat(regularTabbables); | ||
return tabbableNodes; | ||
}; | ||
var tryFocus = function tryFocus2(node) { | ||
if (node === false) { | ||
return; | ||
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 (node === doc.activeElement) { | ||
return; | ||
if (matches.call(node, candidateSelector) === false) { | ||
return false; | ||
} | ||
if (!node || !node.focus) { | ||
tryFocus2(getInitialFocusNode()); | ||
return; | ||
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"); | ||
} | ||
node.focus({ | ||
preventScroll: !!config.preventScroll | ||
}); | ||
state.mostRecentlyFocusedNode = node; | ||
if (isSelectableInput(node)) { | ||
node.select(); | ||
if (matches.call(node, focusableCandidateSelector) === false) { | ||
return false; | ||
} | ||
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); | ||
if (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 = 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)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
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; | ||
} | ||
} 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 createFocusTrap2 = function createFocusTrap3(elements, userOptions) { | ||
var doc = document; | ||
var config = _objectSpread2({ | ||
returnFocusOnDeactivate: true, | ||
escapeDeactivates: true, | ||
delayInitialFocus: true | ||
}, userOptions); | ||
var state = { | ||
// @type {Array<HTMLElement>} | ||
containers: [], | ||
// list of objects identifying the first and last tabbable nodes in all containers/groups 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, firstTabbableNode: HTMLElement|null, lastTabbableNode: HTMLElement|null }>} | ||
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 containersContain = function containersContain2(element) { | ||
return state.containers.some(function(container) { | ||
return container.contains(element); | ||
}); | ||
}; | ||
var getNodeForOption = function getNodeForOption2(optionName) { | ||
var optionValue = config[optionName]; | ||
if (!optionValue) { | ||
return null; | ||
} | ||
var onActivate = getOption(activateOptions, "onActivate"); | ||
var onPostActivate = getOption(activateOptions, "onPostActivate"); | ||
var checkCanFocusTrap = getOption(activateOptions, "checkCanFocusTrap"); | ||
if (!checkCanFocusTrap) { | ||
updateTabbableNodes(); | ||
var node = optionValue; | ||
if (typeof optionValue === "string") { | ||
node = doc.querySelector(optionValue); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` refers to no known node")); | ||
} | ||
} | ||
state.active = true; | ||
state.paused = false; | ||
state.nodeFocusedBeforeActivation = doc.activeElement; | ||
if (onActivate) { | ||
onActivate(); | ||
if (typeof optionValue === "function") { | ||
node = optionValue(); | ||
if (!node) { | ||
throw new Error("`".concat(optionName, "` did not return a node")); | ||
} | ||
} | ||
var finishActivation = function finishActivation2() { | ||
if (checkCanFocusTrap) { | ||
updateTabbableNodes(); | ||
return node; | ||
}; | ||
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; | ||
} else { | ||
var firstTabbableGroup = state.tabbableGroups[0]; | ||
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; | ||
node = firstTabbableNode || getNodeForOption("fallbackFocus"); | ||
} | ||
if (!node) { | ||
throw new Error("Your focus-trap needs to have at least one focusable element"); | ||
} | ||
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] | ||
}; | ||
} | ||
addListeners(); | ||
if (onPostActivate) { | ||
onPostActivate(); | ||
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"); | ||
} | ||
}; | ||
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"); | ||
return node ? node : previousActiveElement; | ||
}; | ||
var checkPointerDown = function checkPointerDown2(e) { | ||
if (containersContain(e.target)) { | ||
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(e.target) | ||
}); | ||
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; | ||
} | ||
}; | ||
if (checkCanFocusTrap) { | ||
checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation); | ||
return this; | ||
} else { | ||
e.stopImmediatePropagation(); | ||
tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode()); | ||
} | ||
finishActivation(); | ||
return this; | ||
}, | ||
deactivate: function deactivate(deactivateOptions) { | ||
}; | ||
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; | ||
} else { | ||
destinationNode = state.tabbableGroups[0].firstTabbableNode; | ||
} | ||
} 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; | ||
} | ||
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 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 checkKey = function checkKey2(e) { | ||
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates) !== false) { | ||
e.preventDefault(); | ||
trap.deactivate(); | ||
return; | ||
} | ||
if (isTabEvent(e)) { | ||
checkTab(e); | ||
return; | ||
} | ||
}; | ||
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 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 = { | ||
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; | ||
} | ||
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(); | ||
} | ||
var returnFocus = getOption(deactivateOptions, "returnFocus", "returnFocusOnDeactivate"); | ||
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 +754,3 @@ let lastFocused; | ||
return within; | ||
return (0, import_tabbable.focusable)(within, {displayCheck: "none"}); | ||
return (0, import_tabbable.focusable)(within, { displayCheck: "none" }); | ||
}, | ||
@@ -795,3 +815,3 @@ all() { | ||
el2.setAttribute("tabindex", "0"); | ||
el2.focus({preventScroll: this._noscroll}); | ||
el2.focus({ preventScroll: this._noscroll }); | ||
}); | ||
@@ -801,48 +821,54 @@ } | ||
}); | ||
Alpine.directive("trap", Alpine.skipDuringClone((el, {expression, modifiers}, {effect, evaluateLater, cleanup}) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let trap = (0, import_focus_trap.createFocusTrap)(el, { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el, | ||
initialFocus: el.querySelector("[autofocus]") | ||
}); | ||
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 trap = (0, import_focus_trap.createFocusTrap)(el, { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el, | ||
initialFocus: el.querySelector("[autofocus]") | ||
}); | ||
let undoInert = () => { | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
let undoDisableScrolling = () => { | ||
}; | ||
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(); | ||
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); | ||
} | ||
)); | ||
} | ||
@@ -886,1 +912,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.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.js: | ||
(*! | ||
* focus-trap 6.6.1 | ||
* @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"]; | ||
@@ -128,3 +124,4 @@ var candidateSelector = /* @__PURE__ */ candidateSelectors.join(","); | ||
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.displayCheck) || // For a details element with a summary, the summary element gets the focus | ||
isDetailsWithSummary(node) || isDisabledFromFieldset(node)) { | ||
return false; | ||
@@ -180,6 +177,2 @@ } | ||
// 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) { | ||
@@ -294,3 +287,11 @@ var keys = Object.keys(object); | ||
var state = { | ||
// @type {Array<HTMLElement>} | ||
containers: [], | ||
// list of objects identifying the first and last tabbable nodes in all containers/groups 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, firstTabbableNode: HTMLElement|null, lastTabbableNode: HTMLElement|null }>} | ||
tabbableGroups: [], | ||
@@ -301,2 +302,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 | ||
@@ -399,2 +402,13 @@ }; | ||
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 && !isFocusable(e.target) | ||
@@ -677,3 +691,3 @@ }); | ||
return within; | ||
return focusable(within, {displayCheck: "none"}); | ||
return focusable(within, { displayCheck: "none" }); | ||
}, | ||
@@ -738,3 +752,3 @@ all() { | ||
el2.setAttribute("tabindex", "0"); | ||
el2.focus({preventScroll: this._noscroll}); | ||
el2.focus({ preventScroll: this._noscroll }); | ||
}); | ||
@@ -744,48 +758,54 @@ } | ||
}); | ||
Alpine.directive("trap", Alpine.skipDuringClone((el, {expression, modifiers}, {effect, evaluateLater, cleanup}) => { | ||
let evaluator = evaluateLater(expression); | ||
let oldValue = false; | ||
let trap = createFocusTrap(el, { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el, | ||
initialFocus: el.querySelector("[autofocus]") | ||
}); | ||
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 trap = createFocusTrap(el, { | ||
escapeDeactivates: false, | ||
allowOutsideClick: true, | ||
fallbackFocus: () => el, | ||
initialFocus: el.querySelector("[autofocus]") | ||
}); | ||
let undoInert = () => { | ||
}; | ||
undoDisableScrolling(); | ||
undoDisableScrolling = () => { | ||
let undoDisableScrolling = () => { | ||
}; | ||
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(); | ||
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); | ||
} | ||
)); | ||
} | ||
@@ -832,1 +852,15 @@ function setInert(el) { | ||
}; | ||
/*! Bundled license information: | ||
tabbable/dist/index.esm.js: | ||
(*! | ||
* tabbable 5.2.1 | ||
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE | ||
*) | ||
focus-trap/dist/focus-trap.esm.js: | ||
(*! | ||
* focus-trap 6.6.1 | ||
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE | ||
*) | ||
*/ |
{ | ||
"name": "@alpinejs/focus", | ||
"version": "3.11.1", | ||
"version": "3.12.0", | ||
"description": "Manage focus within a page", | ||
@@ -5,0 +5,0 @@ "homepage": "https://alpinejs.dev/plugins/focus", |
112574
2847