@alpinejs/focus
Version:
Manage focus within a page
19 lines (16 loc) • 26.1 kB
JavaScript
(()=>{var fe=["input:not([inert]):not([inert] *)","select:not([inert]):not([inert] *)","textarea:not([inert]):not([inert] *)","a[href]:not([inert]):not([inert] *)","button:not([inert]):not([inert] *)","[tabindex]:not(slot):not([inert]):not([inert] *)","audio[controls]:not([inert]):not([inert] *)","video[controls]:not([inert]):not([inert] *)",'[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)',"details>summary:first-of-type:not([inert]):not([inert] *)","details:not([inert]):not([inert] *)"],J=fe.join(","),de=typeof Element>"u",M=de?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,Q=!de&&Element.prototype.getRootNode?function(a){var e;return a==null||(e=a.getRootNode)===null||e===void 0?void 0:e.call(a)}:function(a){return a?.ownerDocument},ee=function(e,t){var n;t===void 0&&(t=!0);var l=e==null||(n=e.getAttribute)===null||n===void 0?void 0:n.call(e,"inert"),u=l===""||l==="true",r=u||t&&e&&(typeof e.closest=="function"?e.closest("[inert]"):ee(e.parentNode));return r},Oe=function(e){var t,n=e==null||(t=e.getAttribute)===null||t===void 0?void 0:t.call(e,"contenteditable");return n===""||n==="true"},ve=function(e,t,n){if(ee(e))return[];var l=Array.prototype.slice.apply(e.querySelectorAll(J));return t&&M.call(e,J)&&l.unshift(e),l=l.filter(n),l},te=function(e,t,n){for(var l=[],u=Array.from(e);u.length;){var r=u.shift();if(!ee(r,!1))if(r.tagName==="SLOT"){var f=r.assignedElements(),d=f.length?f:r.children,h=te(d,!0,n);n.flatten?l.push.apply(l,h):l.push({scopeParent:r,candidates:h})}else{var S=M.call(r,J);S&&n.filter(r)&&(t||!e.includes(r))&&l.push(r);var w=r.shadowRoot||typeof n.getShadowRoot=="function"&&n.getShadowRoot(r),k=!ee(w,!1)&&(!n.shadowRootFilter||n.shadowRootFilter(r));if(w&&k){var E=te(w===!0?r.children:w.children,!0,n);n.flatten?l.push.apply(l,E):l.push({scopeParent:r,candidates:E})}else u.unshift.apply(u,r.children)}}return l},be=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},L=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||Oe(e))&&!be(e)?0:e.tabIndex},Re=function(e,t){var n=L(e);return n<0&&t&&!be(e)?0:n},Pe=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},he=function(e){return e.tagName==="INPUT"},De=function(e){return he(e)&&e.type==="hidden"},Ce=function(e){var t=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(n){return n.tagName==="SUMMARY"});return t},xe=function(e,t){for(var n=0;n<e.length;n++)if(e[n].checked&&e[n].form===t)return e[n]},je=function(e){if(!e.name)return!0;var t=e.form||Q(e),n=function(f){return t.querySelectorAll('input[type="radio"][name="'+f+'"]')},l;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")l=n(window.CSS.escape(e.name));else try{l=n(e.name)}catch(r){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",r.message),!1}var u=xe(l,e.form);return!u||u===e},_e=function(e){return he(e)&&e.type==="radio"},Le=function(e){return _e(e)&&!je(e)},Be=function(e){var t,n=e&&Q(e),l=(t=n)===null||t===void 0?void 0:t.host,u=!1;if(n&&n!==e){var r,f,d;for(u=!!((r=l)!==null&&r!==void 0&&(f=r.ownerDocument)!==null&&f!==void 0&&f.contains(l)||e!=null&&(d=e.ownerDocument)!==null&&d!==void 0&&d.contains(e));!u&&l;){var h,S,w;n=Q(l),l=(h=n)===null||h===void 0?void 0:h.host,u=!!((S=l)!==null&&S!==void 0&&(w=S.ownerDocument)!==null&&w!==void 0&&w.contains(l))}}return u},ce=function(e){var t=e.getBoundingClientRect(),n=t.width,l=t.height;return n===0&&l===0},Ge=function(e,t){var n=t.displayCheck,l=t.getShadowRoot;if(n==="full-native"&&"checkVisibility"in e){var u=e.checkVisibility({checkOpacity:!1,opacityProperty:!1,contentVisibilityAuto:!0,visibilityProperty:!0,checkVisibilityCSS:!0});return!u}if(getComputedStyle(e).visibility==="hidden")return!0;var r=M.call(e,"details>summary:first-of-type"),f=r?e.parentElement:e;if(M.call(f,"details:not([open]) *"))return!0;if(!n||n==="full"||n==="full-native"||n==="legacy-full"){if(typeof l=="function"){for(var d=e;e;){var h=e.parentElement,S=Q(e);if(h&&!h.shadowRoot&&l(h)===!0)return ce(e);e.assignedSlot?e=e.assignedSlot:!h&&S!==e.ownerDocument?e=S.host:e=h}e=d}if(Be(e))return!e.getClientRects().length;if(n!=="legacy-full")return!0}else if(n==="non-zero-area")return ce(e);return!1},Ke=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if(t.tagName==="FIELDSET"&&t.disabled){for(var n=0;n<t.children.length;n++){var l=t.children.item(n);if(l.tagName==="LEGEND")return M.call(t,"fieldset[disabled] *")?!0:!l.contains(e)}return!0}t=t.parentElement}return!1},re=function(e,t){return!(t.disabled||De(t)||Ge(t,e)||Ce(t)||Ke(t))},le=function(e,t){return!(Le(t)||L(t)<0||!re(e,t))},Me=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},pe=function(e){var t=[],n=[];return e.forEach(function(l,u){var r=!!l.scopeParent,f=r?l.scopeParent:l,d=Re(f,r),h=r?pe(l.candidates):f;d===0?r?t.push.apply(t,h):t.push(f):n.push({documentOrder:u,tabIndex:d,item:l,isScope:r,content:h})}),n.sort(Pe).reduce(function(l,u){return u.isScope?l.push.apply(l,u.content):l.push(u.content),l},[]).concat(t)},ye=function(e,t){t=t||{};var n;return t.getShadowRoot?n=te([e],t.includeContainer,{filter:le.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:Me}):n=ve(e,t.includeContainer,le.bind(null,t)),pe(n)},ae=function(e,t){t=t||{};var n;return t.getShadowRoot?n=te([e],t.includeContainer,{filter:re.bind(null,t),flatten:!0,getShadowRoot:t.getShadowRoot}):n=ve(e,t.includeContainer,re.bind(null,t)),n},V=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return M.call(e,J)===!1?!1:le(t,e)},Ve=fe.concat("iframe:not([inert]):not([inert] *)").join(","),q=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return M.call(e,Ve)===!1?!1:re(t,e)};function se(a,e){(e==null||e>a.length)&&(e=a.length);for(var t=0,n=Array(e);t<e;t++)n[t]=a[t];return n}function We(a){if(Array.isArray(a))return se(a)}function me(a,e,t,n,l,u,r){try{var f=a[u](r),d=f.value}catch(h){return void t(h)}f.done?e(d):Promise.resolve(d).then(n,l)}function ge(a){return function(){var e=this,t=arguments;return new Promise(function(n,l){var u=a.apply(e,t);function r(d){me(u,n,l,r,f,"next",d)}function f(d){me(u,n,l,r,f,"throw",d)}r(void 0)})}}function we(a,e){var t=typeof Symbol<"u"&&a[Symbol.iterator]||a["@@iterator"];if(!t){if(Array.isArray(a)||(t=Ee(a))||e){t&&(a=t);var n=0,l=function(){};return{s:l,n:function(){return n>=a.length?{done:!0}:{done:!1,value:a[n++]}},e:function(d){throw d},f:l}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var u,r=!0,f=!1;return{s:function(){t=t.call(a)},n:function(){var d=t.next();return r=d.done,d},e:function(d){f=!0,u=d},f:function(){try{r||t.return==null||t.return()}finally{if(f)throw u}}}}function qe(a,e,t){return(e=$e(e))in a?Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):a[e]=t,a}function Ue(a){if(typeof Symbol<"u"&&a[Symbol.iterator]!=null||a["@@iterator"]!=null)return Array.from(a)}function Ye(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Se(a,e){var t=Object.keys(a);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);e&&(n=n.filter(function(l){return Object.getOwnPropertyDescriptor(a,l).enumerable})),t.push.apply(t,n)}return t}function Te(a){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Se(Object(t),!0).forEach(function(n){qe(a,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(t)):Se(Object(t)).forEach(function(n){Object.defineProperty(a,n,Object.getOwnPropertyDescriptor(t,n))})}return a}function H(){var a,e,t=typeof Symbol=="function"?Symbol:{},n=t.iterator||"@@iterator",l=t.toStringTag||"@@toStringTag";function u(E,F,B,D){var W=F&&F.prototype instanceof f?F:f,U=Object.create(W.prototype);return P(U,"_invoke",function(ie,$,z){var C,T,I,G=0,X=z||[],x=!1,A={p:0,n:0,v:a,a:y,f:y.bind(a,4),d:function(i,o){return C=i,T=0,I=a,A.n=o,r}};function y(i,o){for(T=i,I=o,e=0;!x&&G&&!s&&e<X.length;e++){var s,c=X[e],b=A.p,p=c[2];i>3?(s=p===o)&&(I=c[(T=c[4])?5:(T=3,3)],c[4]=c[5]=a):c[0]<=b&&((s=i<2&&b<c[1])?(T=0,A.v=o,A.n=c[1]):b<p&&(s=i<3||c[0]>o||o>p)&&(c[4]=i,c[5]=o,A.n=p,T=0))}if(s||i>1)return r;throw x=!0,o}return function(i,o,s){if(G>1)throw TypeError("Generator is already running");for(x&&o===1&&y(o,s),T=o,I=s;(e=T<2?a:I)||!x;){C||(T?T<3?(T>1&&(A.n=-1),y(T,I)):A.n=I:A.v=I);try{if(G=2,C){if(T||(i="next"),e=C[i]){if(!(e=e.call(C,I)))throw TypeError("iterator result is not an object");if(!e.done)return e;I=e.value,T<2&&(T=0)}else T===1&&(e=C.return)&&e.call(C),T<2&&(I=TypeError("The iterator does not provide a '"+i+"' method"),T=1);C=a}else if((e=(x=A.n<0)?I:ie.call($,A))!==r)break}catch(c){C=a,T=1,I=c}finally{G=1}}return{value:e,done:x}}}(E,B,D),!0),U}var r={};function f(){}function d(){}function h(){}e=Object.getPrototypeOf;var S=[][n]?e(e([][n]())):(P(e={},n,function(){return this}),e),w=h.prototype=f.prototype=Object.create(S);function k(E){return Object.setPrototypeOf?Object.setPrototypeOf(E,h):(E.__proto__=h,P(E,l,"GeneratorFunction")),E.prototype=Object.create(w),E}return d.prototype=h,P(w,"constructor",h),P(h,"constructor",d),d.displayName="GeneratorFunction",P(h,l,"GeneratorFunction"),P(w),P(w,l,"Generator"),P(w,n,function(){return this}),P(w,"toString",function(){return"[object Generator]"}),(H=function(){return{w:u,m:k}})()}function P(a,e,t,n){var l=Object.defineProperty;try{l({},"",{})}catch{l=0}P=function(u,r,f,d){function h(S,w){P(u,S,function(k){return this._invoke(S,w,k)})}r?l?l(u,r,{value:f,enumerable:!d,configurable:!d,writable:!d}):u[r]=f:(h("next",0),h("throw",1),h("return",2))},P(a,e,t,n)}function He(a){return We(a)||Ue(a)||Ee(a)||Ye()}function Ze(a,e){if(typeof a!="object"||!a)return a;var t=a[Symbol.toPrimitive];if(t!==void 0){var n=t.call(a,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(a)}function $e(a){var e=Ze(a,"string");return typeof e=="symbol"?e:e+""}function Ee(a,e){if(a){if(typeof a=="string")return se(a,e);var t={}.toString.call(a).slice(8,-1);return t==="Object"&&a.constructor&&(t=a.constructor.name),t==="Map"||t==="Set"?Array.from(a):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?se(a,e):void 0}}var j={getActiveTrap:function(e){return e?.length>0?e[e.length-1]:null},activateTrap:function(e,t){var n=j.getActiveTrap(e);t!==n&&j.pauseTrap(e);var l=e.indexOf(t);l===-1||e.splice(l,1),e.push(t)},deactivateTrap:function(e,t){var n=e.indexOf(t);n!==-1&&e.splice(n,1),j.unpauseTrap(e)},pauseTrap:function(e){var t=j.getActiveTrap(e);t?._setPausedState(!0)},unpauseTrap:function(e){var t=j.getActiveTrap(e);t&&!t._isManuallyPaused()&&t._setPausedState(!1)}},ze=function(e){return e.tagName&&e.tagName.toLowerCase()==="input"&&typeof e.select=="function"},Xe=function(e){return e?.key==="Escape"||e?.key==="Esc"||e?.keyCode===27},Z=function(e){return e?.key==="Tab"||e?.keyCode===9},Je=function(e){return Z(e)&&!e.shiftKey},Qe=function(e){return Z(e)&&e.shiftKey},Ne=function(e){return setTimeout(e,0)},Y=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),l=1;l<t;l++)n[l-1]=arguments[l];return typeof e=="function"?e.apply(void 0,n):e},ne=function(e){return e.target.shadowRoot&&typeof e.composedPath=="function"?e.composedPath()[0]:e.target},et=[],Fe=function(e,t){var n=t?.document||document,l=t?.trapStack||et,u=Te({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isolateSubtrees:!1,isKeyForward:Je,isKeyBackward:Qe},t),r={containers:[],containerGroups:[],tabbableGroups:[],adjacentElements:new Set,alreadySilent:new Set,nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,manuallyPaused:!1,delayInitialFocusTimer:void 0,recentNavEvent:void 0},f,d=function(i,o,s){return i&&i[o]!==void 0?i[o]:u[s||o]},h=function(i,o){var s=typeof o?.composedPath=="function"?o.composedPath():void 0;return r.containerGroups.findIndex(function(c){var b=c.container,p=c.tabbableNodes;return b.contains(i)||s?.includes(b)||p.find(function(v){return v===i})})},S=function(i){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=o.hasFallback,c=s===void 0?!1:s,b=o.params,p=b===void 0?[]:b,v=u[i];if(typeof v=="function"&&(v=v.apply(void 0,He(p))),v===!0&&(v=void 0),!v){if(v===void 0||v===!1)return v;throw new Error("`".concat(i,"` was specified but was not a node, or did not return a node"))}var m=v;if(typeof v=="string"){try{m=n.querySelector(v)}catch(g){throw new Error("`".concat(i,'` appears to be an invalid selector; error="').concat(g.message,'"'))}if(!m&&!c)throw new Error("`".concat(i,"` as selector refers to no known node"))}return m},w=function(){var i=S("initialFocus",{hasFallback:!0});if(i===!1)return!1;if(i===void 0||i&&!q(i,u.tabbableOptions))if(h(n.activeElement)>=0)i=n.activeElement;else{var o=r.tabbableGroups[0],s=o&&o.firstTabbableNode;i=s||S("fallbackFocus")}else i===null&&(i=S("fallbackFocus"));if(!i)throw new Error("Your focus-trap needs to have at least one focusable element");return i},k=function(){if(r.containerGroups=r.containers.map(function(i){var o=ye(i,u.tabbableOptions),s=ae(i,u.tabbableOptions),c=o.length>0?o[0]:void 0,b=o.length>0?o[o.length-1]:void 0,p=s.find(function(g){return V(g)}),v=s.slice().reverse().find(function(g){return V(g)}),m=!!o.find(function(g){return L(g)>0});return{container:i,tabbableNodes:o,focusableNodes:s,posTabIndexesFound:m,firstTabbableNode:c,lastTabbableNode:b,firstDomTabbableNode:p,lastDomTabbableNode:v,nextTabbableNode:function(N){var R=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,O=o.indexOf(N);return O<0?R?s.slice(s.indexOf(N)+1).find(function(K){return V(K)}):s.slice(0,s.indexOf(N)).reverse().find(function(K){return V(K)}):o[O+(R?1:-1)]}}}),r.tabbableGroups=r.containerGroups.filter(function(i){return i.tabbableNodes.length>0}),r.tabbableGroups.length<=0&&!S("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(r.containerGroups.find(function(i){return i.posTabIndexesFound})&&r.containerGroups.length>1)throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.")},E=function(i){var o=i.activeElement;if(o)return o.shadowRoot&&o.shadowRoot.activeElement!==null?E(o.shadowRoot):o},F=function(i){if(i!==!1&&i!==E(document)){if(!i||!i.focus){F(w());return}i.focus({preventScroll:!!u.preventScroll}),r.mostRecentlyFocusedNode=i,ze(i)&&i.select()}},B=function(i){var o=S("setReturnFocus",{params:[i]});return o||(o===!1?!1:i)},D=function(i){var o=i.target,s=i.event,c=i.isBackward,b=c===void 0?!1:c;o=o||ne(s),k();var p=null;if(r.tabbableGroups.length>0){var v=h(o,s),m=v>=0?r.containerGroups[v]:void 0;if(v<0)b?p=r.tabbableGroups[r.tabbableGroups.length-1].lastTabbableNode:p=r.tabbableGroups[0].firstTabbableNode;else if(b){var g=r.tabbableGroups.findIndex(function(oe){var ue=oe.firstTabbableNode;return o===ue});if(g<0&&(m.container===o||q(o,u.tabbableOptions)&&!V(o,u.tabbableOptions)&&!m.nextTabbableNode(o,!1))&&(g=v),g>=0){var N=g===0?r.tabbableGroups.length-1:g-1,R=r.tabbableGroups[N];p=L(o)>=0?R.lastTabbableNode:R.lastDomTabbableNode}else Z(s)||(p=m.nextTabbableNode(o,!1))}else{var O=r.tabbableGroups.findIndex(function(oe){var ue=oe.lastTabbableNode;return o===ue});if(O<0&&(m.container===o||q(o,u.tabbableOptions)&&!V(o,u.tabbableOptions)&&!m.nextTabbableNode(o))&&(O=v),O>=0){var K=O===r.tabbableGroups.length-1?0:O+1,_=r.tabbableGroups[K];p=L(o)>=0?_.firstTabbableNode:_.firstDomTabbableNode}else Z(s)||(p=m.nextTabbableNode(o))}}else p=S("fallbackFocus");return p},W=function(i){var o=ne(i);if(!(h(o,i)>=0)){if(Y(u.clickOutsideDeactivates,i)){f.deactivate({returnFocus:u.returnFocusOnDeactivate});return}Y(u.allowOutsideClick,i)||i.preventDefault()}},U=function(i){var o=ne(i),s=h(o,i)>=0;if(s||o instanceof Document)s&&(r.mostRecentlyFocusedNode=o);else{i.stopImmediatePropagation();var c,b=!0;if(r.mostRecentlyFocusedNode)if(L(r.mostRecentlyFocusedNode)>0){var p=h(r.mostRecentlyFocusedNode),v=r.containerGroups[p].tabbableNodes;if(v.length>0){var m=v.findIndex(function(g){return g===r.mostRecentlyFocusedNode});m>=0&&(u.isKeyForward(r.recentNavEvent)?m+1<v.length&&(c=v[m+1],b=!1):m-1>=0&&(c=v[m-1],b=!1))}}else r.containerGroups.some(function(g){return g.tabbableNodes.some(function(N){return L(N)>0})})||(b=!1);else b=!1;b&&(c=D({target:r.mostRecentlyFocusedNode,isBackward:u.isKeyBackward(r.recentNavEvent)})),F(c||r.mostRecentlyFocusedNode||w())}r.recentNavEvent=void 0},ie=function(i){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;r.recentNavEvent=i;var s=D({event:i,isBackward:o});s&&(Z(i)&&i.preventDefault(),F(s))},$=function(i){(u.isKeyForward(i)||u.isKeyBackward(i))&&ie(i,u.isKeyBackward(i))},z=function(i){Xe(i)&&Y(u.escapeDeactivates,i)!==!1&&(i.preventDefault(),f.deactivate())},C=function(i){var o=ne(i);h(o,i)>=0||Y(u.clickOutsideDeactivates,i)||Y(u.allowOutsideClick,i)||(i.preventDefault(),i.stopImmediatePropagation())},T=function(){if(!r.active)return Promise.resolve();j.activateTrap(l,f);var i;return u.delayInitialFocus?i=new Promise(function(o){r.delayInitialFocusTimer=Ne(function(){F(w()),o()})}):(i=Promise.resolve(),F(w())),n.addEventListener("focusin",U,!0),n.addEventListener("mousedown",W,{capture:!0,passive:!1}),n.addEventListener("touchstart",W,{capture:!0,passive:!1}),n.addEventListener("click",C,{capture:!0,passive:!1}),n.addEventListener("keydown",$,{capture:!0,passive:!1}),n.addEventListener("keydown",z),i},I=function(i){r.active&&!r.paused&&f._setSubtreeIsolation(!1),r.adjacentElements.clear(),r.alreadySilent.clear();var o=new Set,s=new Set,c=we(i),b;try{for(c.s();!(b=c.n()).done;){var p=b.value;o.add(p);for(var v=typeof ShadowRoot<"u"&&p.getRootNode()instanceof ShadowRoot,m=p;m;){o.add(m);var g=m.parentElement,N=[];g?N=g.children:!g&&v&&(N=m.getRootNode().children,g=m.getRootNode().host,v=typeof ShadowRoot<"u"&&g.getRootNode()instanceof ShadowRoot);var R=we(N),O;try{for(R.s();!(O=R.n()).done;){var K=O.value;s.add(K)}}catch(_){R.e(_)}finally{R.f()}m=g}}}catch(_){c.e(_)}finally{c.f()}o.forEach(function(_){s.delete(_)}),r.adjacentElements=s},G=function(){if(r.active)return n.removeEventListener("focusin",U,!0),n.removeEventListener("mousedown",W,!0),n.removeEventListener("touchstart",W,!0),n.removeEventListener("click",C,!0),n.removeEventListener("keydown",$,!0),n.removeEventListener("keydown",z),f},X=function(i){var o=i.some(function(s){var c=Array.from(s.removedNodes);return c.some(function(b){return b===r.mostRecentlyFocusedNode})});o&&F(w())},x=typeof window<"u"&&"MutationObserver"in window?new MutationObserver(X):void 0,A=function(){x&&(x.disconnect(),r.active&&!r.paused&&r.containers.map(function(i){x.observe(i,{subtree:!0,childList:!0})}))};return f={get active(){return r.active},get paused(){return r.paused},activate:function(i){if(r.active)return this;var o=d(i,"onActivate"),s=d(i,"onPostActivate"),c=d(i,"checkCanFocusTrap"),b=j.getActiveTrap(l),p=!1;if(b&&!b.paused){var v;(v=b._setSubtreeIsolation)===null||v===void 0||v.call(b,!1),p=!0}try{c||k(),r.active=!0,r.paused=!1,r.nodeFocusedBeforeActivation=E(n),o?.();var m=function(){var N=ge(H().m(function R(){return H().w(function(O){for(;;)switch(O.n){case 0:return c&&k(),O.n=1,T();case 1:f._setSubtreeIsolation(!0),A(),s?.();case 2:return O.a(2)}},R)}));return function(){return N.apply(this,arguments)}}();if(c)return c(r.containers.concat()).then(m,m),this;m()}catch(N){if(b===j.getActiveTrap(l)&&p){var g;(g=b._setSubtreeIsolation)===null||g===void 0||g.call(b,!0)}throw N}return this},deactivate:function(i){if(!r.active)return this;var o=Te({onDeactivate:u.onDeactivate,onPostDeactivate:u.onPostDeactivate,checkCanReturnFocus:u.checkCanReturnFocus},i);clearTimeout(r.delayInitialFocusTimer),r.delayInitialFocusTimer=void 0,r.paused||f._setSubtreeIsolation(!1),r.alreadySilent.clear(),G(),r.active=!1,r.paused=!1,A(),j.deactivateTrap(l,f);var s=d(o,"onDeactivate"),c=d(o,"onPostDeactivate"),b=d(o,"checkCanReturnFocus"),p=d(o,"returnFocus","returnFocusOnDeactivate");s?.();var v=function(){Ne(function(){p&&F(B(r.nodeFocusedBeforeActivation)),c?.()})};return p&&b?(b(B(r.nodeFocusedBeforeActivation)).then(v,v),this):(v(),this)},pause:function(i){return r.active?(r.manuallyPaused=!0,this._setPausedState(!0,i)):this},unpause:function(i){return r.active?(r.manuallyPaused=!1,l[l.length-1]!==this?this:this._setPausedState(!1,i)):this},updateContainerElements:function(i){var o=[].concat(i).filter(Boolean);return r.containers=o.map(function(s){return typeof s=="string"?n.querySelector(s):s}),u.isolateSubtrees&&I(r.containers),r.active&&(k(),r.paused||f._setSubtreeIsolation(!0)),A(),this}},Object.defineProperties(f,{_isManuallyPaused:{value:function(){return r.manuallyPaused}},_setPausedState:{value:function(i,o){if(r.paused===i)return this;if(r.paused=i,i){var s=d(o,"onPause"),c=d(o,"onPostPause");s?.(),G(),f._setSubtreeIsolation(!1),A(),c?.()}else{var b=d(o,"onUnpause"),p=d(o,"onPostUnpause");b?.();var v=function(){var m=ge(H().m(function g(){return H().w(function(N){for(;;)switch(N.n){case 0:return k(),N.n=1,T();case 1:f._setSubtreeIsolation(!0),A(),p?.();case 2:return N.a(2)}},g)}));return function(){return m.apply(this,arguments)}}();v()}return this}},_setSubtreeIsolation:{value:function(i){u.isolateSubtrees&&r.adjacentElements.forEach(function(o){var s;if(i)switch(u.isolateSubtrees){case"aria-hidden":(o.ariaHidden==="true"||((s=o.getAttribute("aria-hidden"))===null||s===void 0?void 0:s.toLowerCase())==="true")&&r.alreadySilent.add(o),o.setAttribute("aria-hidden","true");break;default:(o.inert||o.hasAttribute("inert"))&&r.alreadySilent.add(o),o.setAttribute("inert",!0);break}else if(!r.alreadySilent.has(o))switch(u.isolateSubtrees){case"aria-hidden":o.removeAttribute("aria-hidden");break;default:o.removeAttribute("inert");break}})}}}),f.updateContainerElements(e),f};function ke(a){let e,t;window.addEventListener("focusin",()=>{e=t,t=document.activeElement}),a.magic("focus",n=>{let l=n;return{__noscroll:!1,__wrapAround:!1,within(u){return l=u,this},withoutScrolling(){return this.__noscroll=!0,this},noscroll(){return this.__noscroll=!0,this},withWrapAround(){return this.__wrapAround=!0,this},wrap(){return this.withWrapAround()},focusable(u){return q(u)},previouslyFocused(){return e},lastFocused(){return e},focused(){return t},focusables(){return Array.isArray(l)?l:ae(l,{displayCheck:"none"})},all(){return this.focusables()},isFirst(u){let r=this.all();return r[0]&&r[0].isSameNode(u)},isLast(u){let r=this.all();return r.length&&r.slice(-1)[0].isSameNode(u)},getFirst(){return this.all()[0]},getLast(){return this.all().slice(-1)[0]},getNext(){let u=this.all(),r=document.activeElement;if(u.indexOf(r)!==-1)return this.__wrapAround&&u.indexOf(r)===u.length-1?u[0]:u[u.indexOf(r)+1]},getPrevious(){let u=this.all(),r=document.activeElement;if(u.indexOf(r)!==-1)return this.__wrapAround&&u.indexOf(r)===0?u.slice(-1)[0]:u[u.indexOf(r)-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(u){u&&setTimeout(()=>{u.hasAttribute("tabindex")||u.setAttribute("tabindex","0"),u.focus({preventScroll:this.__noscroll})})}}}),a.directive("trap",a.skipDuringClone((n,{expression:l,modifiers:u},{effect:r,evaluateLater:f,cleanup:d})=>{let h=f(l),S=!1,w={escapeDeactivates:!1,allowOutsideClick:!0,fallbackFocus:()=>n},k=()=>{};if(u.includes("noautofocus"))w.initialFocus=!1;else{let D=n.querySelector("[autofocus]");D&&(w.initialFocus=D)}u.includes("inert")&&(w.onPostActivate=()=>{a.nextTick(()=>{k=Ae(n)})});let E=Fe(n,w),F=()=>{},B=()=>{k(),k=()=>{},F(),F=()=>{},E.deactivate({returnFocus:!u.includes("noreturn")})};r(()=>h(D=>{S!==D&&(D&&!S&&(u.includes("noscroll")&&(F=tt()),setTimeout(()=>{E.activate()},15)),!D&&S&&B(),S=!!D)})),d(B)},(n,{expression:l,modifiers:u},{evaluate:r})=>{u.includes("inert")&&r(l)&&Ae(n)}))}function Ae(a){let e=[];return Ie(a,t=>{let n=t.hasAttribute("aria-hidden");t.setAttribute("aria-hidden","true"),e.push(()=>n||t.removeAttribute("aria-hidden"))}),()=>{for(;e.length;)e.pop()()}}function Ie(a,e){a.isSameNode(document.body)||!a.parentNode||Array.from(a.parentNode.children).forEach(t=>{t.isSameNode(a)?Ie(a.parentNode,e):e(t)})}function tt(){let a=document.documentElement.style.overflow,e=document.documentElement.style.paddingRight,t=window.innerWidth-document.documentElement.clientWidth,n=window.getComputedStyle(document.documentElement).scrollbarGutter;return document.documentElement.style.overflow="hidden",n&&n!=="auto"?()=>{document.documentElement.style.overflow=a}:(document.documentElement.style.paddingRight=`${t}px`,()=>{document.documentElement.style.overflow=a,document.documentElement.style.paddingRight=e})}document.addEventListener("alpine:init",()=>{window.Alpine.plugin(ke)});})();
/*! Bundled license information:
tabbable/dist/index.esm.js:
(*!
* tabbable 6.4.0
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*)
focus-trap/dist/focus-trap.esm.js:
(*!
* focus-trap 8.0.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*)
(*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE *)
*/