(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=class{#e=new Map;on(e,t){let n=this.#e.get(e)??[];return n.push(t),this.#e.set(e,n),this}emit(e,...t){let n=this.#e.get(e);return n?(n.forEach(e=>{e(...t)}),!0):!1}off(e,t){let n=this.#e.get(e);return n&&this.#e.set(e,n.filter(e=>e!==t)),this}},t=(e,t)=>{e.classList.add(t)},n=(e,t)=>{e.classList.remove(t)},r=(e,t)=>{e.classList.toggle(t)},i=(e,t)=>{e.hasAttribute(t)?e.removeAttribute(t):e.setAttribute(t,``)},a=class extends e{constructor(e,t=!0,n=!1){super(),this.keys=``,this.active=-1,this.multiple=!1,this.activeDescendant=null,this.options=[],this.searchIndex=0,this.keyClear=null,this.rootElement=e,this.selectOnFocus=t,this.blurOnFocus=n,this.multiple&&(this.selectOnFocus=!1),this.onFocus=this.onFocus.bind(this),this.onKeydown=this.onKeydown.bind(this),this.onClick=this.onClick.bind(this),this.blur=this.blur.bind(this)}init(){this.activeDescendant=this.rootElement.getAttribute(`aria-activedescendant`),this.options=[...this.rootElement.querySelectorAll(`[role="option"]`)],this.initEvents()}initEvents(){this.rootElement.addEventListener(`focus`,this.onFocus),this.rootElement.addEventListener(`keydown`,this.onKeydown),this.rootElement.addEventListener(`click`,this.onClick),this.rootElement.addEventListener(`blur`,this.blur)}blur(){this.emit(`Box.blur`)}onClick(e){let{target:t}=e;t instanceof HTMLElement&&t.getAttribute(`role`)===`option`&&(this.focusOption(t),this.multiple||this.emit(`Box.click`,t),this.blurOnFocus&&this.rootElement.blur())}onFocus(){return!this.activeDescendant&&this.focusOption(this.options[0])}onKeydown(e){this.emit(`Box.keydown`,e);let t=e.keyCode||e.which,n=this.activeDescendant?this.rootElement.querySelector(`#${this.activeDescendant}`):null;if(this.active=n?this.options.indexOf(n):-1,!n)return!1;let r=t=>{e.preventDefault(),this.focusOption(t)},i={36:()=>r(this.options[0]),35:()=>r(this.options[this.options.length-1]),38:()=>n.previousElementSibling instanceof HTMLElement&&r(n.previousElementSibling),40:()=>n.nextElementSibling instanceof HTMLElement&&r(n.nextElementSibling),33:()=>{0{this.options.length-1>this.active+5?r(this.options[this.active+5]):r(this.options[this.options.length-1])},default:()=>{let e=this.find(t);return e?this.focusOption(e):!1}};return(i[t]||i.default)()}focusOption(e){if(this.multiple)r(e,`is-active`),i(e,`aria-selected`);else{let r=this.activeDescendant?this.rootElement.querySelector(`#${this.activeDescendant}`):null;r&&(n(r,`is-active`),r.removeAttribute(`aria-selected`)),t(e,`is-active`),e.setAttribute(`aria-selected`,`true`)}if(this.rootElement.setAttribute(`aria-activedescendant`,e.id),this.activeDescendant=e.id,this.rootElement.scrollHeight>this.rootElement.clientHeight){let t=this.rootElement.clientHeight+this.rootElement.scrollTop,n=e.offsetTop+e.offsetHeight;n>t?this.rootElement.scrollTop=n-this.rootElement.clientHeight:e.offsetTop{this.keys=``,this.emit(`Box.keysChange`,this.keys),this.keyClear=null},e)}findMatchInRange(e,t,n){for(let r=t;rthis.close()),this.box.on(`Box.keydown`,this.onKeydown),this.box.on(`Box.focus`,this.onFocus),this.box.on(`Box.click`,this.onFocus),this.box.on(`Box.keysChange`,this.onKeysChange)}onKeyup(e){let t=e.keyCode||e.which,n=()=>{e.preventDefault(),this.open()},r={38:n,40:n,default:()=>!1};return(r[t]||r.default)()}onKeydown(e){let t=e.keyCode||e.which,n=()=>{e.preventDefault(),this.close(),this.rootElement.focus()},r={13:n,27:n,default:()=>!1};return(r[t]||r.default)()}onClick(){return this.isOpen?this.close():this.open()}onFocus(e){this.$label&&(this.$label.innerText=e.innerText);let t=new CustomEvent(`Button.change`,{detail:{item:e}});this.rootElement.dispatchEvent(t)}open(){return this.isOpen?!1:(this.isOpen=!0,t(this.box.rootElement,`is-active`),this.rootElement.setAttribute(`aria-expanded`,`true`),setTimeout(()=>{this.box.rootElement.focus()},this.options.delay),!0)}close(){return this.isOpen?(this.isOpen=!1,n(this.box.rootElement,`is-active`),this.rootElement.removeAttribute(`aria-expanded`),!0):!1}onKeysChange(e){let t=new CustomEvent(`Button.keys`,{detail:{keys:e}});this.rootElement.dispatchEvent(t)}},s=[...document.querySelectorAll(`.js-list`)],c=`https://www.dnd5eapi.co/api/`,l=async e=>await(await fetch(e)).json(),u=(e,t)=>`
  • ${t}
  • `,d=e=>{let t=document.createElement(`div`);return t.className=`toast fade show`,t.innerHTML=`
    ${e}
    `,t.setAttribute(`role`,`alert`),t.setAttribute(`aria-live`,`assertive`),t.setAttribute(`aria-atomic`,`true`),t},f=document.querySelector(`.js-alert`);s.forEach(e=>{let t=e.querySelector(`[role="listbox"]`),n=e.querySelector(`.js-list-button`),r=e.querySelector(`.js-keys`),{id:i}=e;i===`monster`&&l(`${c}monsters`).then(e=>{e.results.forEach(e=>{t.innerHTML+=u(e.index,e.name)});let r=new a(t,!1);r.init(),new o(n,r).init()}),i===`spells`&&l(`${c}spells`).then(e=>{e.results.forEach(e=>{t.innerHTML+=u(e.index,e.name)});let r=new a(t);r.init(),new o(n,r).init()}),n.addEventListener(`Button.change`,({detail:e})=>{let t=d(e.item.innerHTML);f.appendChild(t),t.addEventListener(`click`,()=>t.style.setProperty(`display`,`none`),!1),setTimeout(()=>t.parentNode.removeChild(t),2e3)}),n.addEventListener(`Button.keys`,({detail:e})=>{let{keys:t}=e;r.innerHTML=t})});