UNPKG

@llselect/core

Version:

Low-level select: a minimal, flexible, framework-agnostic replacement for the native HTML select element.

3 lines (2 loc) 43 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).llselect={})}(this,function(t){"use strict";const e=new Set(["hidden","auto","scroll","clip"]);function s(t,s){return s.bottom<0||s.top>window.innerHeight||s.right<0||s.left>window.innerWidth||function(t,s){let i=t.parentElement;for(;i;){const t=window.getComputedStyle(i);if(e.has(t.overflowX)||e.has(t.overflowY)){const t=i.getBoundingClientRect();if(s.bottom<t.top||s.top>t.bottom||s.right<t.left||s.left>t.right)return!0}i=i.parentElement}return!1}(t,s)}function i(t,e,i){let n=!0;const o=i?.widthPolicy??"fit-content",l="rtl"===window.getComputedStyle(t).direction?"rtl":"ltr";let r;function a(a){if(!n)return;const h=t.getBoundingClientRect(),{left:c,top:u,width:d,height:p}=function(){const t=window.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:window.innerWidth,height:window.innerHeight}}();if(a&&s(t,h)&&i?.onHide)return void i.onHide();const g="fit-content"===o?function(t){const e=t.style.width;t.style.width="max-content";const s=t.offsetWidth;return t.style.width=e,s}(e):0,m=i?.innerScrollEl,f=m?Math.max(0,m.scrollHeight-m.clientHeight):0,E=e.offsetHeight+f,I=function(t){const{anchorRect:e,viewportWidth:s,viewportHeight:i,viewportLeft:n=0,viewportTop:o=0,floatingHeight:l,widthPolicy:r="fit-content",floatingNaturalWidth:a=0,direction:h="ltr",currentPlacement:c}=t,u=o+i,d=u-e.bottom-4-8,p=e.top-o-4-8,g=l<=d,m=l<=p;let f,E,I,b,C;if(f=("below"===c&&g||"above"===c&&m)&&void 0!==c?c:g?"below":m||p>d?"above":"below","below"===f?(E=e.bottom+4,I=Math.max(0,u-E-8)):(I=Math.max(0,e.top-o-4-8),E=e.top-4-Math.min(l,I)),"match-trigger"===r)b=e.width,C=e.left;else{const t=Math.max(e.width,a),i=s-16;b=Math.min(t,Math.max(0,i));const o=n+8,l=n+s-8;"rtl"===h?(C=e.right-b,C<o&&(C=o),C+b>l&&(C=l-b)):(C=e.left,C+b>l&&(C=l-b),C<o&&(C=o))}return{top:E,left:C,width:b,maxHeight:I,placement:f}}({anchorRect:{top:h.top,left:h.left,right:h.right,bottom:h.bottom,width:h.width,height:h.height},viewportWidth:d,viewportHeight:p,viewportLeft:c,viewportTop:u,floatingHeight:E,widthPolicy:o,floatingNaturalWidth:g,direction:l,currentPlacement:r});r=I.placement,e.style.position="fixed",e.style.top=`${I.top}px`,e.style.left=`${I.left}px`,e.style.width=`${I.width}px`,e.style.maxHeight=`${I.maxHeight}px`,e.setAttribute("data-placement",I.placement)}const h=()=>a(!0),c=()=>a(!1);window.addEventListener("scroll",h,{passive:!0,capture:!0}),window.addEventListener("resize",c);const u=window.visualViewport;let d;return u?.addEventListener("resize",c),"undefined"!=typeof ResizeObserver&&(d=new ResizeObserver(()=>a(!1)),d.observe(t),d.observe(e)),a(!0),{reposition:()=>a(!1),detach(){n=!1,window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",c),u?.removeEventListener("resize",c),d?.disconnect(),e.style.position="",e.style.top="",e.style.left="",e.style.width="",e.style.maxHeight="",e.removeAttribute("data-placement")}}}function n(t,e,s){const i=s??null,n=null===i?new Map:null,o=[],l=t=>null!==n?n.has(t):o.some(e=>i(e,t)),r=(t,e)=>null!==i?i(t,e):t===e||t!=t&&e!=e;let a=!0,h=null;for(const s of t){const t=e(s);if(null!==t){if(null===h||!r(h,t)){if(l(t)){a=!1;break}null!==n?n.set(t,!0):o.push(t),h=t}}else h=null}if(a)return t;const c=[],u=null===i?new Map:null,d=[];for(const s of t){const t=e(s);if(null===t){c.push([s]);continue}let n=null!==u?u.get(t):d.find(e=>i(e.key,t))?.bucket;void 0===n&&(n=[],c.push(n),null!==u?u.set(t,n):d.push({key:t,bucket:n})),n.push(s)}const p=[];for(const t of c)p.push(...t);return p}var o;!function(t){t[t.Open=0]="Open",t[t.Close=1]="Close",t[t.Select=2]="Select",t[t.Next=3]="Next",t[t.Previous=4]="Previous",t[t.GotoFirst=5]="GotoFirst",t[t.GotoLast=6]="GotoLast",t[t.PageDown=7]="PageDown",t[t.PageUp=8]="PageUp"}(o||(o={}));function l(t,e,s){if(e<0)return-1;switch(s){case o.GotoFirst:return 0;case o.GotoLast:return e;case o.Next:return Math.min(t+1,e);case o.Previous:return Math.max(t-1,0);case o.PageDown:return Math.min(t+10,e);case o.PageUp:return Math.max(t-10,0);default:return t}}function r(t){return[...t].map(t=>t.toLowerCase()).join("").replace(/\u03c2/g,"σ")}function a(t,e){const s=t.getBoundingClientRect(),i=e.getBoundingClientRect().top+e.clientTop,n=i+e.clientHeight;s.top<i?e.scrollTop-=i-s.top:s.bottom>n&&(e.scrollTop+=s.bottom-n)}const h={triggerPlaceholder:"Please select",filterInputAriaLabel:"Search",filterInputPlaceholder:"Filter (Esc to clear)",popupListNoResults:"No results found",triggerClearButtonAriaLabel:"Clear selection",tagRemoveButtonAriaLabel:t=>`Remove ${t}`,triggerCountSummary:(t,e)=>t===e?`All ${t} selected`:`${t} / ${e} selected`,chooseAllRowText:(t,e)=>`Select all (${t} of ${e})`},c="llselect";let u=0;function d(t,e){return t===e||t!=t&&e!=e}function p(t){return null==t||""===t.trim()?null:t}let g=!1,m=!1;class f{constructor(t,e,s){this.labelElIdMinted=!1,this.handleLabelElClick=()=>{this.triggerEl.focus()},this.items=[],this.opened=!1,this.focusedIndex=-1,this.disabled=!1,this.changeSource="api",this.triggerClearButtonEl=null,this.itemEls=[],this.leadingRowFocused=!1,this.lastNoResultsText=null,this.query="",this.typeaheadBuffer="",this.typeaheadLastTime=0,this.composing=!1,this.classIdMap=function(t){const e=`${t}${++u}`;return{rootClass:`${t}-root`,triggerClass:`${t}-trigger`,triggerContentClass:`${t}-trigger-content`,triggerArrowClass:`${t}-trigger-arrow`,triggerClearButtonClass:`${t}-trigger-clear-button`,popupClass:`${t}-popup`,popupListClass:`${t}-popup-list`,popupListNoResultsClass:`${t}-popup-list-no-results`,chooseAllRowClass:`${t}-choose-all-row`,itemClass:`${t}-item`,itemFocusedClass:`${t}-item-focused`,itemDisabledClass:`${t}-item-disabled`,groupClass:`${t}-group`,groupLabelClass:`${t}-group-label`,tagsClass:`${t}-tags`,tagClass:`${t}-tag`,tagRemoveButtonClass:`${t}-tag-remove-button`,tagDisabledClass:`${t}-tag-disabled`,openClass:`${t}-open`,triggerId:`${e}-trigger`,labelId:`${e}-label`,triggerContentId:`${e}-trigger-content`,triggerValueId:`${e}-trigger-value`,popupListId:`${e}-popup-list`,filterInputClass:`${t}-filter-input`,filterInputId:`${e}-filter-input`}}(e?.cssClassPrefix??c),this.explicitPlaceholder=e?.placeholder??null;const i={...h,...e?.uiTranslationPack},n=e?.labelEl??null;null!==n&&""===n.id&&(n.id=this.classIdMap.labelId,this.labelElIdMinted=!0),this.settings={cssClassPrefix:e?.cssClassPrefix??c,placeholder:this.explicitPlaceholder??i.triggerPlaceholder,ariaLabel:p(e?.ariaLabel),ariaLabelledBy:p(e?.ariaLabelledBy)??(null===p(e?.ariaLabel)&&null!==n?n.id:null),labelEl:n,compareFn:e?.compareFn??d,outsideClickBehavior:e?.outsideClickBehavior??"pass-through",createTriggerArrowContentElFn:e?.createTriggerArrowContentElFn??null,clearable:e?.clearable??!1,createTriggerClearButtonContentElFn:e?.createTriggerClearButtonContentElFn??null,filterable:e?.filterable??!1,uiTranslationPack:i,filterFn:e?.filterFn??null,createPopupListNoResultsContentElFn:e?.createPopupListNoResultsContentElFn??null,popupWidthPolicy:e?.popupWidthPolicy??"fit-content",itemDisabledFn:e?.itemDisabledFn??null,focusableWhenDisabled:e?.focusableWhenDisabled??!1,itemToStringFn:e?.itemToStringFn??null,createItemContentElFn:e?.createItemContentElFn??null,itemToGroupKeyFn:e?.itemToGroupKeyFn??null,gatherGroups:e?.gatherGroups??!0,groupKeyCompareFn:e?.groupKeyCompareFn??null,groupKeyToStringFn:e?.groupKeyToStringFn??null,groupDisabledFn:e?.groupDisabledFn??null,createGroupLabelContentElFn:e?.createGroupLabelContentElFn??null,onOpen:e?.onOpen??null,onClose:e?.onClose??null,...s},g||null!==this.settings.ariaLabel||null!==this.settings.ariaLabelledBy||(g=!0,console.warn("llselect: this widget has no accessible name - pass ariaLabelledBy, ariaLabel, or labelEl. An unnamed combobox violates WAI-ARIA 1.2. (warned once per page; first offender:)",t)),null!==n&&n.addEventListener("click",this.handleLabelElClick),this.filterActive=this.computeFilterActive(),this.rootEl=t,this.rootEl.classList.add(this.classIdMap.rootClass),this.rootEl.style.overflowAnchor="none",this.rootEl.replaceChildren(),this.triggerEl=this.createTriggerEl(),this.triggerContentEl=this.triggerEl.querySelector(`.${this.classIdMap.triggerContentClass}`),this.triggerArrowEl=this.triggerEl.querySelector(`.${this.classIdMap.triggerArrowClass}`),this.triggerValueEl=document.createElement("span"),this.triggerValueEl.id=this.classIdMap.triggerValueId,this.triggerValueEl.hidden=!0,this.popupEl=this.createPopupEl(),this.popupListEl=this.createPopupListEl(),this.filterInputEl=this.createFilterInputEl(),this.popupListNoResultsEl=this.createPopupListNoResultsEl(),this.popupEl.append(this.filterInputEl,this.popupListEl,this.popupListNoResultsEl),this.popupEl.hidden=!0,this.syncFilterModeToDom(),this.popupEl.style.boxSizing="border-box",this.popupListEl.style.boxSizing="border-box",this.popupListEl.style.flex="1",this.popupListEl.style.minHeight="0",this.popupListEl.style.overflowY="auto",this.popoverSupported="function"==typeof this.popupEl.showPopover,this.popoverSupported&&this.popupEl.setAttribute("popover","manual"),this.rootEl.append(this.triggerEl,this.triggerValueEl,this.popupEl),this.triggerEl.addEventListener("click",()=>this.toggle()),this.triggerEl.addEventListener("keydown",t=>this.handleKeydown(t)),this.popupEl.addEventListener("mousedown",t=>{const e=this.eventTargetNode(t);e instanceof Node&&this.filterInputEl.contains(e)||t.preventDefault()}),this.filterInputEl.addEventListener("keydown",t=>this.handleKeydown(t)),this.filterInputEl.addEventListener("input",()=>this.handleSearchInputEvent()),this.filterInputEl.addEventListener("compositionstart",()=>{this.composing=!0}),this.filterInputEl.addEventListener("compositionend",()=>{this.composing=!1,this.handleSearchInputEvent()})}computeFilterActive(){const t=this.settings.filterable;return"function"==typeof t?t(this.items):t}syncFilterModeToDom(){this.triggerEl.setAttribute("role",this.filterActive?"button":"combobox"),this.filterInputEl.hidden=!this.filterActive,this.comboboxEl=this.filterActive?this.filterInputEl:this.triggerEl,this.syncFieldNameToDom(),this.syncTriggerTabindex()}syncFieldNameToDom(){const t=(t,e,s)=>{null!==e?t.setAttribute("aria-labelledby",e):t.removeAttribute("aria-labelledby"),null!==s?t.setAttribute("aria-label",s):t.removeAttribute("aria-label")},{ariaLabel:e,ariaLabelledBy:s}=this.settings,{triggerId:i,triggerValueId:n}=this.classIdMap;null!==s?(t(this.triggerEl,this.filterActive?`${s} ${n}`:s,null),t(this.filterInputEl,s,null),t(this.popupListEl,s,null)):null!==e?(t(this.triggerEl,this.filterActive?`${i} ${n}`:null,e),t(this.filterInputEl,null,e),t(this.popupListEl,null,e)):(t(this.triggerEl,null,null),t(this.filterInputEl,null,this.settings.uiTranslationPack.filterInputAriaLabel),t(this.popupListEl,null,null))}open(){if(this.opened||this.disabled)return;if(s(t=this.triggerEl,t.getBoundingClientRect()))return;var t;const e=this.captureWindowScroll();this.opened=!0,this.filterActive=this.computeFilterActive(),this.syncFilterModeToDom(),this.triggerEl.setAttribute("aria-expanded","true"),this.triggerEl.setAttribute("data-state","open"),this.rootEl.classList.add(this.classIdMap.openClass),this.filterActive&&(this.query="",this.filterInputEl.value="",this.filterInputEl.setAttribute("aria-expanded","true"),this.recomputeFilteredItems()),this.popupEl.style.position="fixed",this.popupEl.style.display="flex",this.popupEl.style.flexDirection="column",this.popupEl.hidden=!1,this.popoverSupported&&this.popupEl.isConnected&&(this.popupEl.showPopover(),this.popupEl.style.right="auto",this.popupEl.style.bottom="auto"),this.renderTriggerArrow(),this.renderPopupList(),this.positioner=i(this.triggerEl,this.popupEl,{onHide:()=>this.close(),widthPolicy:this.settings.popupWidthPolicy,innerScrollEl:this.popupListEl}),this.attachOutsideClick(),this.attachFocusOut(),this.focusInitial(),this.onOpened(),this.settings.onOpen?.(),this.filterActive&&this.filterInputEl.focus({preventScroll:!0}),e()}close(){if(!this.opened)return;const t=this.filterActive&&this.isFocused(this.filterInputEl);if(this.opened=!1,this.triggerEl.setAttribute("aria-expanded","false"),this.triggerEl.setAttribute("data-state","closed"),this.syncTriggerTabindex(),this.rootEl.classList.remove(this.classIdMap.openClass),this.filterActive&&(this.filterInputEl.setAttribute("aria-expanded","false"),this.filterInputEl.value="",this.query="",this.filteredItems=void 0),this.positioner?.detach(),this.positioner=void 0,this.detachOutsideClick(),this.detachFocusOut(),this.popupListEl.replaceChildren(),this.lastNoResultsText=null,this.popoverSupported){try{this.popupEl.hidePopover()}catch{}this.popupEl.style.right="",this.popupEl.style.bottom=""}this.popupEl.hidden=!0,this.popupEl.style.position="",this.popupEl.style.display="",this.popupEl.style.flexDirection="",this.itemEls=[],this.focusedEl=void 0,this.focusedIndex=-1,this.typeaheadBuffer="",this.leadingRowEl=void 0,this.leadingRowFocused=!1,this.comboboxEl.removeAttribute("aria-activedescendant"),this.renderTriggerArrow(),this.onClosed(),this.settings.onClose?.(),t&&this.triggerEl.focus({preventScroll:!0})}rerender(){this.gatheredItems=void 0,this.filterActive&&this.recomputeFilteredItems(),this.renderTrigger(),this.opened&&this.renderPopupList()}destroy(){this.close(),null!==this.settings.labelEl&&(this.settings.labelEl.removeEventListener("click",this.handleLabelElClick),this.labelElIdMinted&&this.settings.labelEl.removeAttribute("id")),this.rootEl.classList.remove(this.classIdMap.rootClass,this.classIdMap.openClass),this.rootEl.style.overflowAnchor="",this.rootEl.replaceChildren()}toggle(){this.opened?this.close():this.open()}isOpened(){return this.opened}getItems(){return this.items}getUiTranslationPack(){return this.settings.uiTranslationPack}setUiTranslationPack(t){const e={...h,...t};this.settings.uiTranslationPack=e,this.settings.placeholder=this.explicitPlaceholder??e.triggerPlaceholder,this.syncFieldNameToDom(),null!==e.filterInputPlaceholder?this.filterInputEl.placeholder=e.filterInputPlaceholder:this.filterInputEl.removeAttribute("placeholder"),this.rerender()}setPlaceholder(t){this.explicitPlaceholder!==t&&(this.explicitPlaceholder=t,this.settings.placeholder=t??this.settings.uiTranslationPack.triggerPlaceholder,this.renderTrigger())}setItems(t){this.items=t.slice(),this.warnOnDuplicateItems(),this.gatheredItems=void 0,this.filterActive&&this.recomputeFilteredItems(),this.opened&&this.renderPopupList(),this.onItemsChanged()}warnOnDuplicateItems(){m||this.settings.compareFn!==d||new Set(this.items).size!==this.items.length&&(m=!0,console.warn("llselect: duplicate items passed to setItems - items must be unique under compareFn (it defines item identity, and the selection is a set). Duplicates render stale selection state. (warned once per page)"))}setDisabled(t){this.disabled!==t&&(this.disabled=t,t&&this.opened&&this.close(),this.syncDisabledStateToDom())}isDisabled(){return this.disabled}syncDisabledStateToDom(){this.disabled?(this.triggerEl.setAttribute("aria-disabled","true"),this.triggerEl.setAttribute("data-disabled","true")):(this.triggerEl.removeAttribute("aria-disabled"),this.triggerEl.setAttribute("data-disabled","false")),this.syncTriggerTabindex()}syncTriggerTabindex(){const t=this.disabled&&!this.settings.focusableWhenDisabled,e=this.opened&&this.filterActive;this.triggerEl.setAttribute("tabindex",t||e?"-1":"0")}onOpened(){}onClosed(){}onChosenChanged(){}onItemsChanged(){}renderTrigger(){this.replaceTriggerClearButtonElInDom(),this.renderTriggerContent(),this.renderTriggerArrow()}commitTriggerContentToDom(t,e){"string"==typeof t?(this.triggerContentEl.textContent=t,this.triggerValueEl.textContent=t):(this.triggerContentEl.replaceChildren(t),this.triggerValueEl.textContent=e??t.textContent)}syncEmptyStateToDom(){this.triggerEl.setAttribute("data-empty",this.isEmpty()?"true":"false")}isEmpty(){return!0}renderTriggerContent(){this.syncEmptyStateToDom(),this.commitTriggerContentToDom(this.settings.placeholder)}renderTriggerArrow(){this.commitTriggerArrowContentElToDom(this.createTriggerArrowContentEl({isOpened:this.opened}))}createTriggerArrowContentEl(t){return this.settings.createTriggerArrowContentElFn?this.settings.createTriggerArrowContentElFn(t):null}commitTriggerArrowContentElToDom(t){this.triggerArrowEl.replaceChildren(),t&&this.triggerArrowEl.appendChild(t)}renderPopupList(){const t=this.getVisibleItems(),e=t.map((t,e)=>this.createItemEl(t,e));if(this.itemEls=e,this.focusedEl=void 0,this.leadingRowEl=this.createPopupListLeadingRowEl()??void 0,this.leadingRowEl||(this.leadingRowFocused=!1),this.commitPopupSegmentsToDom(this.computePopupSegments(t,e)),this.syncPopupListNoResultsToDom(),this.positioner?.reposition(),this.focusedIndex>=t.length)this.focusedIndex=0===t.length?-1:this.findNextEnabledIndex(t.length-1,-1,t);else if(this.focusedIndex>=0&&this.isItemEffectivelyDisabled(t[this.focusedIndex])){const e=this.findNextEnabledIndex(this.focusedIndex,-1,t);e>=0?this.focusedIndex=e:this.focusLeadingRow()||(this.focusedIndex=this.findNextEnabledIndex(this.focusedIndex,1,t))}this.syncFocusedIndexToDom()}computePopupSegments(t,e){const s=this.settings.groupKeyCompareFn??d,i=[],n=[];let o=0,l=0;for(;l<t.length;){const r=this.itemToGroupKey(t[l]);if(null===r){i.push({group:!1,el:e[l]}),l+=1;continue}const a=[t[l]],h=[e[l]];let c=l+1;for(;c<t.length;){const i=this.itemToGroupKey(t[c]);if(null===i||!s(r,i))break;a.push(t[c]),h.push(e[c]),c+=1}n.some(t=>s(t,r))&&console.warn("llselect: group key reappears non-contiguously; sort items by group to avoid a duplicate header.",r),n.push(r),i.push({group:!0,key:r,index:o,items:a,els:h}),o+=1,l=c}return i}commitPopupSegmentsToDom(t){const e=t.map(t=>t.group?this.createGroupEl(t.key,t.index,t.items,t.els):t.el);this.leadingRowEl&&e.unshift(this.leadingRowEl),this.popupListEl.replaceChildren(...e)}createGroupEl(t,e,s,i){const n=this.groupKeyToString(t),o=document.createElement("div");o.id=`${this.classIdMap.popupListId}-group${e}`,o.className=this.classIdMap.groupClass,o.setAttribute("role","group"),o.setAttribute("aria-label",n),this.isGroupDisabled(t)&&(o.setAttribute("aria-disabled","true"),o.setAttribute("data-disabled","true"));const l=document.createElement("div");l.className=this.classIdMap.groupLabelClass,l.setAttribute("aria-hidden","true");const r=this.createGroupLabelContentEl(t,s);return null===r?l.textContent=n:l.appendChild(r),o.append(l,...i),o}createGroupLabelContentEl(t,e){return this.settings.createGroupLabelContentElFn?this.settings.createGroupLabelContentElFn(t,e):null}replacePopupListItemElInDom(t){if(!this.opened)return;const e=this.getVisibleItems(),s=e.findIndex(e=>this.settings.compareFn(e,t));if(s<0)return;const i=this.itemEls[s];if(void 0===i)return;const n=this.createItemEl(e[s],s);i.replaceWith(n),this.itemEls[s]=n,this.focusedEl===i&&(n.classList.add(this.classIdMap.itemFocusedClass),this.comboboxEl.setAttribute("aria-activedescendant",n.id),this.focusedEl=n)}createItemEl(t,e){const s=document.createElement("div");s.id=`${this.classIdMap.popupListId}-item${e}`,s.className=this.classIdMap.itemClass,s.setAttribute("role","option");const i=this.createItemContentEl(t);return null===i?s.textContent=this.itemToString(t):(s.setAttribute("aria-label",this.itemToString(t)),s.appendChild(i)),this.isItemEffectivelyDisabled(t)?(s.setAttribute("aria-disabled","true"),s.classList.add(this.classIdMap.itemDisabledClass)):s.addEventListener("click",()=>{this.setFocusedIndex(e),this.withUserChangeSource(()=>this.onItemActivated(t))}),s}itemToString(t){return this.settings.itemToStringFn?this.settings.itemToStringFn(t):String(t)}createItemContentEl(t){return this.settings.createItemContentElFn?this.settings.createItemContentElFn(t):null}isItemEffectivelyDisabled(t){if(this.settings.itemDisabledFn&&this.settings.itemDisabledFn(t))return!0;const e=this.itemToGroupKey(t);return null!==e&&this.isGroupDisabled(e)}itemToGroupKey(t){return this.settings.itemToGroupKeyFn?this.settings.itemToGroupKeyFn(t):null}groupKeyToString(t){return this.settings.groupKeyToStringFn?this.settings.groupKeyToStringFn(t):String(t)}isGroupDisabled(t){return!!this.settings.groupDisabledFn&&this.settings.groupDisabledFn(t)}findNextEnabledIndex(t,e,s){for(let i=t;i>=0&&i<s.length;i+=e)if(!this.isItemEffectivelyDisabled(s[i]))return i;return-1}findEnabledIndexForAction(t,e,s){const i=e===o.Next||e===o.GotoFirst||e===o.PageDown,n=this.findNextEnabledIndex(t,i?1:-1,s);return n>=0?n:e===o.PageDown?this.findNextEnabledIndex(t,-1,s):e===o.PageUp?this.findNextEnabledIndex(t,1,s):-1}onItemActivated(t){}createPopupListLeadingRowEl(){return null}withUserChangeSource(t){const e=this.changeSource;this.changeSource="user";try{return t()}finally{this.changeSource=e}}onLeadingRowActivated(){}focusInitial(){const t=this.findNextEnabledIndex(0,1,this.getVisibleItems());t>=0&&this.setFocusedIndex(t)}setFocusedIndex(t){const e=this.getVisibleItems().length-1,s=Math.max(-1,Math.min(e,t));(s!==this.focusedIndex||this.leadingRowFocused)&&(this.leadingRowFocused=!1,this.focusedIndex=s,this.syncFocusedIndexToDom())}focusLeadingRow(){return!!this.leadingRowEl&&(this.leadingRowFocused||(this.leadingRowFocused=!0,this.focusedIndex=-1,this.syncFocusedIndexToDom()),!0)}replaceLeadingRowElInDom(){if(!this.opened||!this.leadingRowEl)return;const t=this.createPopupListLeadingRowEl();if(null===t)return void this.renderPopupList();const e=this.leadingRowEl;e.replaceWith(t),this.leadingRowEl=t,this.focusedEl===e&&(t.classList.add(this.classIdMap.itemFocusedClass),this.comboboxEl.setAttribute("aria-activedescendant",t.id),this.focusedEl=t)}syncFocusedIndexToDom(){if(this.focusedEl&&(this.focusedEl.classList.remove(this.classIdMap.itemFocusedClass),this.focusedEl=void 0),this.leadingRowFocused&&this.leadingRowEl)return this.leadingRowEl.classList.add(this.classIdMap.itemFocusedClass),this.comboboxEl.setAttribute("aria-activedescendant",this.leadingRowEl.id),this.focusedEl=this.leadingRowEl,void a(this.leadingRowEl,this.popupListEl);const t=this.focusedIndex;if(t>=0&&t<this.itemEls.length){const e=this.itemEls[t];e.classList.add(this.classIdMap.itemFocusedClass),this.comboboxEl.setAttribute("aria-activedescendant",e.id),this.focusedEl=e,a(e,this.popupListEl)}else this.comboboxEl.removeAttribute("aria-activedescendant")}captureWindowScroll(){const{scrollX:t,scrollY:e}=window,s=()=>{window.scrollX===t&&window.scrollY===e||window.scrollTo({left:t,top:e,behavior:"instant"})};return()=>{s(),"function"==typeof requestAnimationFrame&&requestAnimationFrame(s)}}eventTargetNode(t){return t.composedPath?.()?.[0]??t.target}attachOutsideClick(){"pass-through"===this.settings.outsideClickBehavior?(this.outsideHandler=t=>{const e=this.eventTargetNode(t);e instanceof Node&&!this.rootEl.contains(e)&&this.close()},document.addEventListener("mousedown",this.outsideHandler)):(this.blockMouseDownHandler=t=>{const e=this.eventTargetNode(t);e instanceof Node&&!this.rootEl.contains(e)&&t.preventDefault()},document.addEventListener("mousedown",this.blockMouseDownHandler,!0),this.outsideHandler=t=>{const e=this.eventTargetNode(t);e instanceof Node&&!this.rootEl.contains(e)&&(t.stopPropagation(),t.preventDefault(),this.close())},document.addEventListener("click",this.outsideHandler,!0))}detachOutsideClick(){this.outsideHandler&&("pass-through"===this.settings.outsideClickBehavior?document.removeEventListener("mousedown",this.outsideHandler):document.removeEventListener("click",this.outsideHandler,!0),this.outsideHandler=void 0),this.blockMouseDownHandler&&(document.removeEventListener("mousedown",this.blockMouseDownHandler,!0),this.blockMouseDownHandler=void 0)}attachFocusOut(){this.focusOutHandler=t=>{const e=t.relatedTarget;e instanceof Node&&this.rootEl.contains(e)||this.close()},this.rootEl.addEventListener("focusout",this.focusOutHandler)}detachFocusOut(){this.focusOutHandler&&(this.rootEl.removeEventListener("focusout",this.focusOutHandler),this.focusOutHandler=void 0)}handleKeydown(t){if(t.isComposing||this.composing)return;if(this.disabled)return;const e=t.currentTarget===this.filterInputEl;if(!e&&this.handleTypeaheadKeydown(t))return;const s=function(t,e,s=!1){const{key:i,altKey:n}=t;return e?"Escape"===i||"ArrowUp"===i&&n?o.Close:"Enter"===i?o.Select:" "!==i||s?"ArrowDown"===i?o.Next:"ArrowUp"===i?o.Previous:"Home"!==i||s?"End"!==i||s?"PageDown"===i?o.PageDown:"PageUp"===i?o.PageUp:void 0:o.GotoLast:o.GotoFirst:o.Select:"ArrowDown"===i||"ArrowUp"===i||"Enter"===i||" "===i?o.Open:void 0}(t,this.opened,e);if(void 0!==s)switch(t.preventDefault(),this.typeaheadBuffer="",s){case o.Open:return void this.open();case o.Close:return this.filterActive&&""!==this.query?(this.filterInputEl.value="",void this.handleSearchInputEvent()):void this.close();case o.Select:{if(this.leadingRowFocused)return void this.withUserChangeSource(()=>this.onLeadingRowActivated());const t=this.getVisibleItems();if(this.focusedIndex>=0&&this.focusedIndex<t.length){const e=t[this.focusedIndex];this.isItemEffectivelyDisabled(e)||this.withUserChangeSource(()=>this.onItemActivated(e))}return}case o.Next:case o.Previous:case o.GotoFirst:case o.GotoLast:case o.PageDown:case o.PageUp:{const t=this.getVisibleItems();if(0===t.length)return;if(this.leadingRowFocused){if(s===o.Next||s===o.PageDown||s===o.GotoLast){const e=l(-1,t.length-1,s),i=this.findEnabledIndexForAction(e,s,t);i>=0&&this.setFocusedIndex(i)}return}if(s===o.GotoFirst&&this.leadingRowEl)return void this.focusLeadingRow();const e=l(this.focusedIndex,t.length-1,s),i=this.findEnabledIndexForAction(e,s,t),n=s===o.Previous||s===o.PageUp;return this.leadingRowEl&&n&&(i<0||i===this.focusedIndex)?void this.focusLeadingRow():void(i>=0&&this.setFocusedIndex(i))}}}handleTypeaheadKeydown(t){if(" "===t.key||1!==[...t.key].length||t.metaKey||t.ctrlKey&&!t.altKey)return!1;if(t.altKey&&/^[a-zA-Z0-9]$/.test(t.key))return!1;if(this.opened?this.filterActive:this.computeFilterActive())return!1;t.preventDefault();const e=Date.now();var s,i;this.typeaheadBuffer=(s=this.typeaheadBuffer,i=t.key,e-this.typeaheadLastTime>1e3?i:s+i),this.typeaheadLastTime=e;const n=!this.opened;if(n&&(this.open(),!this.opened))return this.typeaheadBuffer="",!0;const o=this.getVisibleItems(),l=n?this.computeTypeaheadClosedStartIndex(o):this.leadingRowFocused?-1:this.focusedIndex,a=function(t,e,s,i){if(e<=0||""===t)return-1;const n=[...t].map(r),o=n.every(t=>t===n[0]),l=o?n[0]:n.join(""),a=((o?s+1:Math.max(s,0))%e+e)%e;for(let t=0;t<e;t++){const s=(a+t)%e,n=i(s);if(void 0!==n&&r(n).startsWith(l))return s}return-1}(this.typeaheadBuffer,o.length,l,t=>this.isItemEffectivelyDisabled(o[t])?void 0:this.itemToString(o[t]));return a>=0&&this.setFocusedIndex(a),!0}computeTypeaheadClosedStartIndex(t){return-1}createTriggerEl(){const t=document.createElement("div");t.id=this.classIdMap.triggerId,t.className=this.classIdMap.triggerClass,t.setAttribute("role",this.filterActive?"button":"combobox"),t.setAttribute("tabindex","0"),t.setAttribute("aria-controls",this.classIdMap.popupListId),t.setAttribute("aria-expanded","false"),t.setAttribute("aria-haspopup","listbox"),t.setAttribute("data-state","closed"),t.setAttribute("data-disabled","false");const e=document.createElement("span");e.id=this.classIdMap.triggerContentId,e.className=this.classIdMap.triggerContentClass,t.append(e);const s=document.createElement("span");return s.className=this.classIdMap.triggerArrowClass,t.append(s),t}createTriggerClearButtonEl(){const t=document.createElement("button");t.type="button",t.className=this.classIdMap.triggerClearButtonClass,t.tabIndex=-1,t.setAttribute("aria-label",this.settings.uiTranslationPack.triggerClearButtonAriaLabel);const e=this.createTriggerClearButtonContentEl();return null!==e&&t.appendChild(e),t.addEventListener("click",t=>{t.stopPropagation(),this.isDisabled()||this.withUserChangeSource(()=>this.clearSelection())}),t}focusedElementIn(t){const e=t.getRootNode().activeElement??null;if(null===e||!t.contains(e))return null;let s=e;for(;null!==s.shadowRoot&&null!==s.shadowRoot.activeElement;)s=s.shadowRoot.activeElement;return s}containsComposed(t,e){let s=e;for(;null!==s;){if(t.contains(s))return!0;const e=s.getRootNode();s=11===e.nodeType?e.host??null:null}return!1}isFocused(t){return null!==this.focusedElementIn(t)}replaceTriggerClearButtonElInDom(){if(!this.settings.clearable)return;const t=this.triggerClearButtonEl,e=null===t?null:this.focusedElementIn(t);null!==t&&null!==e&&t.focus({preventScroll:!0});const s=this.createTriggerClearButtonEl();if(this.triggerClearButtonEl=s,null!==t){if(s===t){const s=e;return void(null!==s&&s!==t&&this.containsComposed(t,s)&&"function"==typeof s.focus&&s.focus({preventScroll:!0}))}t.before(s),null!==e&&(s.focus({preventScroll:!0}),null===this.focusedElementIn(s)&&this.triggerEl.focus({preventScroll:!0})),t.remove()}else this.triggerArrowEl.before(s)}createTriggerClearButtonContentEl(){return this.settings.createTriggerClearButtonContentElFn?this.settings.createTriggerClearButtonContentElFn():null}clearSelection(){}createFilterInputEl(){const t=document.createElement("input");return t.type="text",t.id=this.classIdMap.filterInputId,t.className=this.classIdMap.filterInputClass,t.setAttribute("role","combobox"),t.setAttribute("aria-controls",this.classIdMap.popupListId),t.setAttribute("aria-expanded","false"),t.setAttribute("aria-autocomplete","list"),t.setAttribute("autocomplete","off"),t.setAttribute("autocapitalize","off"),t.setAttribute("spellcheck","false"),null!==this.settings.uiTranslationPack.filterInputPlaceholder&&(t.placeholder=this.settings.uiTranslationPack.filterInputPlaceholder),t}getVisibleItems(){return this.filteredItems??this.getDisplayBaseItems()}getDisplayBaseItems(){return this.settings.gatherGroups?(void 0===this.gatheredItems&&(this.gatheredItems=n(this.items,t=>this.itemToGroupKey(t),this.settings.groupKeyCompareFn)),this.gatheredItems):this.items}getFilterQuery(){return this.query}matchesQuery(t,e){const s=this.settings.filterFn;return s?s(t,e):this.itemToString(t).toLowerCase().includes(e.toLowerCase())}recomputeFilteredItems(){if(!this.filterActive)return;const t=this.query,e=this.getDisplayBaseItems();this.filteredItems=""===t?e.slice():e.filter(e=>this.matchesQuery(e,t))}handleSearchInputEvent(){this.composing||(this.query=this.filterInputEl.value,this.recomputeFilteredItems(),this.focusedIndex=-1,this.renderPopupList(),this.setFocusedIndex(this.findNextEnabledIndex(0,1,this.getVisibleItems())))}createPopupEl(){const t=document.createElement("div");return t.className=this.classIdMap.popupClass,t}createPopupListNoResultsEl(){const t=document.createElement("div");return t.className=this.classIdMap.popupListNoResultsClass,t.setAttribute("role","status"),t.hidden=!0,t}createPopupListNoResultsContentEl(t){return this.settings.createPopupListNoResultsContentElFn?this.settings.createPopupListNoResultsContentElFn(t):null}syncPopupListNoResultsToDom(){const t=0===this.getVisibleItems().length;if(this.popupListNoResultsEl.hidden=!t,!t)return void(this.lastNoResultsText=null);const e=this.createPopupListNoResultsContentEl(this.query),s=null===e?this.settings.uiTranslationPack.popupListNoResults:e.textContent??"";s!==this.lastNoResultsText&&(this.lastNoResultsText=s,null===e?this.popupListNoResultsEl.textContent=this.settings.uiTranslationPack.popupListNoResults:this.popupListNoResultsEl.replaceChildren(e))}createPopupListEl(){const t=document.createElement("div");return t.id=this.classIdMap.popupListId,t.className=this.classIdMap.popupListClass,t.setAttribute("role","listbox"),t.setAttribute("tabindex","-1"),t}}const E="http://www.w3.org/2000/svg";function I(t,e,s){const i=document.createElementNS(E,"svg");i.setAttribute("width",String(s)),i.setAttribute("height",String(s)),i.setAttribute("viewBox",t),i.setAttribute("aria-hidden","true"),i.setAttribute("focusable","false");const n=document.createElementNS(E,"path");return n.setAttribute("d",e),n.setAttribute("fill","currentColor"),i.appendChild(n),i}const b={unchecked:"M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3M19,5V19H5V5H19Z",checked:"M19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3M19,5V19H5V5H19M10,17L6,13L7.41,11.58L10,14.17L16.59,7.58L18,9",indeterminate:"M19,19V5H5V19H19M19,3A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V5C3,3.89 3.9,3 5,3H19M17,11V13H7V11H17Z"};function C(t){return"none"===t?"unchecked":"some"===t?"indeterminate":"all"===t?"checked":t}const v={unchecked:b.unchecked,checked:"M10,17L5,12L6.41,10.58L10,14.17L17.59,6.58L19,8M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Z",indeterminate:"M17,13H7V11H17M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Z"};t.LLSelectBase=f,t.LLSelectMultiple=class extends f{constructor(t,e,s){super(t,e,{...{onChange:e?.onChange??null,createTriggerContentElFn:e?.createTriggerContentElFn??null,triggerDisplay:e?.triggerDisplay??"count",createTagContentElFn:e?.createTagContentElFn??null,createTagRemoveButtonContentElFn:e?.createTagRemoveButtonContentElFn??null,hideChosenRows:e?.hideChosenRows??!1,chooseAllRow:e?.chooseAllRow??!1,createChooseAllRowContentElFn:e?.createChooseAllRowContentElFn??null},...s}),this.chosenItems=[],this.chosenSetCache=null,this.visibleItemsCache=null,this.popupListEl.setAttribute("aria-multiselectable","true"),this.renderTrigger()}getChosenItems(){return this.chosenItems}setChosenItems(t){let e;if(this.settings.compareFn===d)e=[...new Set(t)];else{e=[];for(const s of t)e.some(t=>this.settings.compareFn(t,s))||e.push(s)}if(this.arraysEqual(e,this.chosenItems))return;const s=this.chosenItems;this.chosenItems=e,this.rerender(),this.fireChange(s)}isChosen(t){return this.settings.compareFn===d?this.chosenSet().has(t):this.chosenItems.some(e=>this.settings.compareFn(e,t))}chosenSet(){const t=this.chosenSetCache;if(null!==t&&t.chosen===this.chosenItems)return t.set;const e=new Set(this.chosenItems);return this.chosenSetCache={chosen:this.chosenItems,set:e},e}toggleItem(t){const e=this.chosenItems,s=e.findIndex(e=>this.settings.compareFn(e,t));this.chosenItems=s>=0?[...e.slice(0,s),...e.slice(s+1)]:[...e,t],this.renderTrigger(),this.settings.hideChosenRows?this.isOpened()&&this.renderPopupList():(this.replacePopupListItemElInDom(t),this.replaceLeadingRowElInDom()),this.fireChange(e)}chooseAll(){this.setChosenItems(this.items.filter(t=>!this.isItemEffectivelyDisabled(t)||this.isChosen(t)))}unchooseAll(){this.setChosenItems(this.chosenItems.filter(t=>this.isItemEffectivelyDisabled(t)))}toggleAll(){const t=this.items.filter(t=>!this.isItemEffectivelyDisabled(t));t.length>0&&t.every(t=>this.isChosen(t))?this.unchooseAll():this.chooseAll()}toggleAllVisible(){const t=this.getVisibleEnabledItems();if(0===t.length)return;if(t.every(t=>this.isChosen(t)))this.setChosenItems(this.chosenItems.filter(e=>!t.some(t=>this.settings.compareFn(t,e))));else{const e=t.filter(t=>!this.isChosen(t));this.setChosenItems([...this.chosenItems,...e])}}getVisibleEnabledItems(){return this.getVisibleItems().filter(t=>!this.isItemEffectivelyDisabled(t))}getVisibleItems(){const t=super.getVisibleItems();if(!this.settings.hideChosenRows||0===this.chosenItems.length)return t;const e=this.visibleItemsCache;if(null!==e&&e.base===t&&e.chosen===this.chosenItems)return e.result;let s;if(this.settings.compareFn===d){const e=new Set(this.chosenItems);s=t.filter(t=>!e.has(t))}else s=t.filter(t=>!this.isChosen(t));return this.visibleItemsCache={base:t,chosen:this.chosenItems,result:s},s}renderTriggerContent(){this.syncEmptyStateToDom();const t=this.chosenItems.length,e=0===t?this.settings.placeholder:this.settings.uiTranslationPack.triggerCountSummary(t,this.items.length),s=this.settings.createTriggerContentElFn?.({chosenItems:this.getChosenItems(),items:this.getItems()})??null;null===s?"tags"===this.settings.triggerDisplay&&t>0?this.commitTriggerContentToDom(this.createTagsEl(),this.chosenItems.map(t=>this.itemToString(t)).join(", ")):this.commitTriggerContentToDom(e):this.commitTriggerContentToDom(s,e)}createTagsEl(){const t=document.createElement("span");t.className=this.classIdMap.tagsClass;for(const e of this.chosenItems)t.appendChild(this.createTagEl(e));return t}createTagEl(t){const e=document.createElement("span");e.className=this.classIdMap.tagClass;const s=this.createTagContentEl(t);return null===s?e.textContent=this.itemToString(t):e.appendChild(s),this.isItemEffectivelyDisabled(t)&&(e.setAttribute("aria-disabled","true"),e.classList.add(this.classIdMap.tagDisabledClass)),e.appendChild(this.createTagRemoveButtonEl(t)),e}createTagRemoveButtonEl(t){const e=document.createElement("button");e.type="button",e.className=this.classIdMap.tagRemoveButtonClass,e.tabIndex=-1,e.setAttribute("aria-label",this.itemToTagRemoveButtonAriaLabel(t)),this.isItemEffectivelyDisabled(t)&&e.setAttribute("aria-disabled","true");const s=this.createTagRemoveButtonContentEl(t);return null!==s&&e.appendChild(s),e.addEventListener("click",e=>{e.stopPropagation(),this.isDisabled()||this.isItemEffectivelyDisabled(t)||this.withUserChangeSource(()=>this.toggleItem(t))}),e}createTagRemoveButtonContentEl(t){return this.settings.createTagRemoveButtonContentElFn?this.settings.createTagRemoveButtonContentElFn(t):null}createTagContentEl(t){return this.settings.createTagContentElFn?this.settings.createTagContentElFn(t):null}itemToTagRemoveButtonAriaLabel(t){return this.settings.uiTranslationPack.tagRemoveButtonAriaLabel(this.itemToString(t))}isEmpty(){return 0===this.chosenItems.length}onItemActivated(t){this.toggleItem(t)}clearSelection(){this.setChosenItems([])}createPopupListLeadingRowEl(){if(!this.settings.chooseAllRow)return null;const t=this.getVisibleEnabledItems();if(0===t.length)return null;const e=t.filter(t=>this.isChosen(t)).length,s=0===e?"none":e===t.length?"all":"some",i=document.createElement("div");i.id=`${this.classIdMap.popupListId}-choose-all`,i.className=`${this.classIdMap.itemClass} ${this.classIdMap.chooseAllRowClass}`,i.setAttribute("role","option"),i.setAttribute("data-chosen-state",s),i.setAttribute("aria-selected",String("all"===s));const n=this.settings.uiTranslationPack.chooseAllRowText(e,t.length),o=this.createChooseAllRowContentEl(s,e,t.length);return null===o?i.textContent=n:(i.setAttribute("aria-label",n),i.appendChild(o)),i.addEventListener("click",()=>{this.focusLeadingRow(),this.withUserChangeSource(()=>this.onLeadingRowActivated())}),i}createChooseAllRowContentEl(t,e,s){return this.settings.createChooseAllRowContentElFn?this.settings.createChooseAllRowContentElFn(t,e,s):null}onLeadingRowActivated(){this.toggleAllVisible()}createItemEl(t,e){const s=super.createItemEl(t,e);return s.setAttribute("aria-selected",String(this.isChosen(t))),s}onItemsChanged(){const t=this.chosenItems;let e=!1;const s=[];for(const i of t){const t=this.items.findIndex(t=>this.settings.compareFn(t,i));if(t<0)continue;const n=this.items[t];d(n,i)||(e=!0),s.push(n)}if(s.length!==t.length)return this.chosenItems=s,this.renderTrigger(),void this.fireChange(t);e&&(this.chosenItems=s),this.renderTriggerContent()}focusInitial(){const t=this.getVisibleItems(),e=this.chosenItems[0];if(void 0!==e){const s=t.findIndex(t=>this.settings.compareFn(t,e));if(s>=0&&!this.isItemEffectivelyDisabled(t[s]))return void this.setFocusedIndex(s)}if(this.focusLeadingRow())return;const s=this.findNextEnabledIndex(0,1,t);s>=0&&this.setFocusedIndex(s)}arraysEqual(t,e){if(t.length!==e.length)return!1;const s=this.settings.compareFn;for(let i=0;i<t.length;i++)if(!s(t[i],e[i]))return!1;return!0}fireChange(t){const e={source:this.changeSource};this.changeSource="api",this.onChosenChanged(),this.settings.onChange?.(this.chosenItems,t,e)}},t.LLSelectSingle=class extends f{constructor(t,e,s){super(t,e,{...{onChange:e?.onChange??null,createTriggerContentElFn:e?.createTriggerContentElFn??null},...s}),this.chosenItem=void 0,this.renderTrigger()}getChosenItem(){return this.chosenItem}setChosenItem(t){if(this.areEqual(t,this.chosenItem))return;const e=this.chosenItem;this.chosenItem=t,this.renderTrigger(),void 0!==e&&this.replacePopupListItemElInDom(e),void 0!==t&&this.replacePopupListItemElInDom(t),this.fireChange(e)}renderTriggerContent(){this.syncEmptyStateToDom();const t=void 0===this.chosenItem?this.settings.placeholder:this.itemToString(this.chosenItem),e=this.settings.createTriggerContentElFn?.({chosenItem:this.chosenItem,items:this.getItems()})??null;null===e?this.commitTriggerContentToDom(t):this.commitTriggerContentToDom(e,t)}isEmpty(){return void 0===this.chosenItem}createItemEl(t,e){const s=super.createItemEl(t,e);return s.setAttribute("aria-selected",String(this.areEqual(t,this.chosenItem))),s}onItemActivated(t){this.setChosenItem(t),this.close()}clearSelection(){this.setChosenItem(void 0)}focusInitial(){const t=this.getVisibleItems(),e=this.chosenItem;if(void 0!==e){const s=t.findIndex(t=>this.settings.compareFn(t,e));if(s>=0&&!this.isItemEffectivelyDisabled(t[s]))return void this.setFocusedIndex(s)}const s=this.findNextEnabledIndex(0,1,t);s>=0&&this.setFocusedIndex(s)}computeTypeaheadClosedStartIndex(t){const e=this.chosenItem;return void 0===e?-1:t.findIndex(t=>this.settings.compareFn(t,e))}onItemsChanged(){const t=this.chosenItem;if(void 0!==t){const e=this.items.findIndex(e=>this.settings.compareFn(e,t));if(e<0)return this.chosenItem=void 0,this.renderTrigger(),void this.fireChange(t);const s=this.items[e];d(s,t)||(this.chosenItem=s)}this.renderTriggerContent()}areEqual(t,e){return void 0===t&&void 0===e||void 0!==t&&void 0!==e&&this.settings.compareFn(t,e)}fireChange(t){const e={source:this.changeSource};this.changeSource="api",this.onChosenChanged(),this.settings.onChange?.(this.chosenItem,t,e)}},t.createCheckmarkSvgEl=function(t={}){return I("0 0 24 24","M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z",t.size??16)},t.createChevronDownSvgEl=function(t={}){return I("0 0 24 24","M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z",t.size??16)},t.createFilledCheckboxSvgEl=function(t={}){const e=C(t.state??"unchecked");return I("0 0 24 24",v[e],t.size??16)},t.createHighlightedTextEl=function(t,e,s){const i=document.createElement("span"),n=t.toLowerCase(),o=e.toLowerCase();if(""===e||n.length!==t.length||o.length!==e.length)return i.textContent=t,i;let l=0;for(;;){const r=n.indexOf(o,l);if(-1===r)break;r>l&&i.append(t.slice(l,r));const a=t.slice(r,r+e.length);if(s)i.append(s(a));else{const t=document.createElement("mark");t.textContent=a,i.append(t)}l=r+e.length}return l<t.length&&i.append(t.slice(l)),i},t.createOutlinedCheckboxSvgEl=function(t={}){const e=C(t.state??"unchecked");return I("0 0 24 24",b[e],t.size??16)},t.createTriangleDownSvgEl=function(t={}){return I("0 0 24 24","M4 8l8 10 8-10z",t.size??16)},t.gatherItemsByGroupKey=n,t.version="0.0.8"}); //# sourceMappingURL=index.umd.js.map