@danielgindi/selectbox 2.0.54 → 2.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.54
2
+ * @danielgindi/selectbox 2.0.56
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
- import{closestUntil as e,createElement as t,next as s,prev as i,setElementAttrs as l}from"@danielgindi/dom-utils/lib/Dom";import{append as r,before as n,getRootNode as o,remove as a,toggleClass as u}from"@danielgindi/dom-utils/lib/DomCompat";import{anchoredPosition as c,getCssProps as d,getElementHeight as h,getElementOffset as m,getElementWidth as p,getPseudoElementWidth as _,parseTransition as f,setCssProps as g,setElementHeight as I,setElementWidth as b}from"@danielgindi/dom-utils/lib/Css";import v from"@danielgindi/dom-utils/lib/DomEventsSink";import y from"@danielgindi/virtual-list-helper";import{VALUE_BACK_SPACE as S,VALUE_DELETE as C,VALUE_DOWN as L,VALUE_END as k,VALUE_ENTER as x,VALUE_ESCAPE as E,VALUE_HOME as w,VALUE_LEFT as T,VALUE_PAGE_DOWN as F,VALUE_PAGE_UP as N,VALUE_RIGHT as P,VALUE_SPACE as O,VALUE_TAB as M,VALUE_UP as V}from"keycode-js";import W from"mitt";var B=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),R=(e,t,s)=>{let i,l,r,n,o=0;s||(s={});const a=()=>{o=!1===s.leading?0:Date.now(),i=null,n=e.apply(l,r),i||(l=r=null)},u=function(){const u=Date.now();o||!1!==s.leading||(o=u);const c=t-(u-o);return l=this,r=arguments,c<=0||c>t?(i&&(clearTimeout(i),i=null),o=u,n=e.apply(l,r),i||(l=r=null)):i||!1===s.trailing||(i=setTimeout(a,c)),n};return u.cancel=()=>{clearTimeout(i),o=0,i=l=r=null},u.isScheduled=()=>!!i,u},D=Symbol("item"),$=Symbol("destroyed"),A=Symbol("ghost"),H=Symbol("no_results_items"),G=Object.prototype.hasOwnProperty,z={baseClassName:"droplist",autoItemBlur:!0,autoItemBlurDelay:300,capturesFocus:!0,multi:!1,keyDownHandler:null,autoCheckGroupChildren:!0,useExactTargetWidth:!1,constrainToWindow:!0,autoFlipDirection:!0,estimateWidth:!1,virtualMinItems:100,labelProp:"label",valueProp:"value",on:null,isHeaderVisible:!1,isFooterVisible:!1,searchable:!1,noResultsText:"No matching results",filterThrottleWindow:300,filterOnEmptyTerm:!1,filterGroups:!1,filterEmptyGroups:!1},K=class s{constructor(e){const s={...z};for(let[t,a]of Object.entries(e))void 0!==a&&(s[t]=a);const i=this._p={ownsEl:!0,elOriginalDisplay:"",baseClassName:s.baseClassName,additionalClasses:s.additionalClasses,direction:"ltr"===s.direction?"ltr":"rtl"===s.direction?"rtl":"auto",autoItemBlur:s.autoItemBlur,autoItemBlurDelay:s.autoItemBlurDelay,capturesFocus:s.capturesFocus,multi:s.multi,keyDownHandler:s.keyDownHandler,autoCheckGroupChildren:s.autoCheckGroupChildren,useExactTargetWidth:s.useExactTargetWidth,constrainToWindow:s.constrainToWindow,autoFlipDirection:s.autoFlipDirection,estimatedItemHeight:s.estimatedItemHeight,estimateWidth:s.estimateWidth,virtualMinItems:s.virtualMinItems,labelProp:s.labelProp,valueProp:s.valueProp,renderItem:s.renderItem,unrenderItem:s.unrenderItem,renderNoResultsItem:s.renderNoResultsItem,unrenderNoResultsItem:s.unrenderNoResultsItem,on:s.on||null,positionOptionsProvider:s.positionOptionsProvider??null,searchable:s.searchable,isHeaderVisible:s.isHeaderVisible,isFooterVisible:s.isFooterVisible,silenceEvents:!0,mitt:W(),filterThrottleWindow:s.filterThrottleWindow,filterOnEmptyTerm:s.filterOnEmptyTerm,filterGroups:s.filterGroups,filterEmptyGroups:s.filterEmptyGroups,filterFn:s.filterFn,filteredItems:null,filterTerm:"",needsRefilter:!1,throttledRefilterItems:null,focusItemIndex:-1,focusItemEl:null,sink:new v};let l=[i.baseClassName+"_wrapper"];i.additionalClasses&&(l=l.concat((i.additionalClasses+"").split(" ").filter(e=>e)));const r={top:"-9999px"};let n=s.el;n instanceof Element?(i.elOriginalDisplay=n.style.display||"",n.classList.add(...l),g(n,r),i.ownsEl=!1):n=t("div",{class:l.join(" "),css:r}),i.el=n;let o=t("ul");o.role="menu",i.menuEl=o,i.headerEl=t("div",{class:i.baseClassName+"_header"}),i.footerEl=t("div",{class:i.baseClassName+"_footer"}),s.searchable&&this.setSearchable(!0),s.isHeaderVisible&&this.setHeaderVisible(s.isHeaderVisible),n.appendChild(o),s.isFooterVisible&&this.setFooterVisible(s.isFooterVisible),i.items=[],i.groupCount=0,i.mouseHandled=!1,i.virtualListHelper=new y({list:i.menuEl,virtual:!0,buffer:5,estimatedItemHeight:s.estimatedItemHeight||20,itemElementCreatorFn:()=>t("li",{role:"menuitem",tabIndex:i.capturesFocus?-1:null}),onItemRender:(e,t)=>{let s;if(t===A)s={label:i.lastMeasureLongestLabelText,value:"Measure",[D]:{[i.labelProp]:i.lastMeasureLongestLabelText,[i.valueProp]:"Measure"}},e.setAttribute("aria-hidden","true");else{const e=i.filteredItems??i.items;s=0===e.length&&i.noResultsText?{value:H,label:i.noResultsText,_nointeraction:!0,_nocheck:!0,[D]:H}:e[t]}s||console.warn("onItemRender called for ("+t+") which has no item"),e.className=`${i.baseClassName}__item`;const l=e.classList;i.multi?s._nocheck?l.add(`${i.baseClassName}__item_multi_nocheck`):(l.add(`${i.baseClassName}__item_multi`),s._checked&&l.add(`${i.baseClassName}__item_checked`)):l.add(`${i.baseClassName}__item_single`),s._group&&l.add(`${i.baseClassName}__item_group`),s._child&&l.add(`${i.baseClassName}__item_child`),s._nointeraction&&l.add(`${i.baseClassName}__item_nointeraction`),i.focusItemIndex===t&&(i.focusItemEl=e,l.add(`${i.baseClassName}__item_focus`)),this._renderItemContent(s,e),e[D]=s}}),this._setupUnrenderFunction(),i.capturesFocus&&(n.tabIndex=0),this.setFilterThrottleWindow(s.filterThrottleWindow),this.setNoResultsText(s.noResultsText),this._hookMouseEvents(),this._hookTouchEvents(),this._hookFocusEvents(),this._hookKeyEvents(),this._hookSearchEvents(),this.silenceEvents=!1}destroy(){if(this[$])return;this[$]=!0;const e=this._p;if(clearTimeout(e.blurTimer),clearTimeout(e.filterTimer),e.sink.remove(),e.virtualListHelper.destroy(),e.el?.parentNode&&a(e.el),e.currentSubDropList&&(e.currentSubDropList?.droplist?.destroy(),e.currentSubDropList=null),e.throttledRefilterItems&&e.throttledRefilterItems.cancel(),!e.ownsEl){for(let t of Array.from(e.el.classList))t.startsWith(e.baseClassName)&&e.el.classList.remove(t);for(let t of["position","left","top","right","bottom","z-index"])e.el.style[t]="";e.el.style.display=e.elOriginalDisplay}e.lastPositionTarget&&(e.lastPositionTarget.classList.remove(`has_${e.baseClassName}`,`has_${e.baseClassName}_above`,`has_${e.baseClassName}_below`),delete e.lastPositionTarget),delete e.lastPositionOptions,this._p=null}get el(){return this._p?.el??null}elContains(e,t=!0){return!!this.el.contains(e)||!(!t||!this._p.currentSubDropList?.droplist?.elContains(e))}setAdditionalClasses(e){return this._p.additionalClasses=e,this._syncBaseClasses(),this}setDirection(e){return this._p.direction="ltr"===e?"ltr":"rtl"===e?"rtl":"auto",this._syncBaseClasses(),this}getDirection(){return this._p.direction}setLabelProp(e){return this._p.labelProp=e,this}setRenderItem(e){return this._p.renderItem=e,this}setUnrenderItem(e){return this._p.unrenderItem=e,this._setupUnrenderFunction(),this}setRenderNoResultsItem(e,t){const s=this._p;return s.renderNoResultsItem=e,s.unrenderNoResultsItem=t,this._setupUnrenderFunction(),this}_setupUnrenderFunction(){const e=this._p;if("function"==typeof e.unrenderItem||"function"==typeof e.unrenderNoResultsItem){const t=e.unrenderItem,s=e.unrenderNoResultsItem;e.virtualListHelper.setOnItemUnrender(i=>{const l=i[D];if(l===H)try{s(l,i)}catch(r){console.error(r)}else try{t(l[D],i)}catch(r){console.error(r)}delete i[D],e.focusItemEl===i&&(e.focusItemEl=null)})}else e.virtualListHelper.setOnItemUnrender(t=>{delete t[D],e.focusItemEl===t&&(e.focusItemEl=null)});return this}setValueProp(e){return this._p.valueProp=e,this}_syncBaseClasses(){const e=this._p,t=e.el;if(!t)return;let s=[e.baseClassName+"_wrapper"];"ltr"!==e.direction&&"rtl"!==e.direction||s.push(`${e.baseClassName}__`+e.direction),e.additionalClasses&&(s=s.concat(e.additionalClasses)),t.className=s.join(" ")}blurFocusedItem(){const e=this._p;if(clearTimeout(e.blurTimer),!this.hasFocusedItem())return;let t=e.focusItemEl;t&&(t.classList.remove(`${e.baseClassName}__item_focus`),e.focusItemEl=null);const s=(e.filteredItems??e.items)[e.focusItemIndex];e.focusItemIndex=-1,s&&(e.currentSubDropList&&this._hideSublist(),this._trigger("itemblur",{value:s.value,item:s[D]??s}))}nextPage(e){this._move("next_page",e)}previousPage(e){this._move("prev_page",e)}goToFirst(e){this._move("first",e)}goToLast(e){this._move("last",e)}toggleFocusedItem(){const e=this._p;if(this.hasFocusedItem()&&e.multi){let t=(e.filteredItems??e.items)[e.focusItemIndex];if(!t||t._nocheck||t._nointeraction)return this;t._checked=!t._checked,e.focusItemEl&&u(e.focusItemEl,`${e.baseClassName}__item_checked`,t._checked),this._trigger("check",{value:t.value,item:t[D]??t,checked:t._checked,isGroup:t._group,isCheckingGroup:!1}),this._updateGroupStateForItem(t)}return this}triggerItemSelection(t,s){const i=this._p;return i.focusItemEl=i.focusItemEl||e(s.target,"li",i.el),i.focusItemIndex=i.virtualListHelper.getItemIndexFromElement(i.focusItemEl),void 0===i.focusItemIndex&&(i.focusItemIndex=-1),!(t=t??i.focusItemEl[D])._nointeraction&&(t._subitems?.length?(this._showSublist(t,i.focusItemEl),!1):(i.multi?this.hasFocusedItem()&&this.toggleFocusedItem():(this._setSingleSelectedItemEl(i.focusItemEl),this._trigger("select",{value:t?t.value:void 0,item:t[D]??t,event:s,el:i.focusItemEl})),!0))}addItem(e,t=-1){return this.addItems([e],t)}addItems(e,t=-1){const s=this._p,i=s.labelProp,l=s.valueProp;let r=s.multi;const n=s.items;(null==t||t<0||t>=s.items.length)&&(t=-1),this._determineVirtualMode(n.length+e.length);for(let o=0,a=e.length;o<a;o++){let a=e[o],u={[D]:a,label:a[i],value:a[l],_nocheck:!!a._nocheck,_nointeraction:!!a._nointeraction,_subitems:a._subitems};r&&(u._checked=!!a._checked),a._group&&(u._group=!0,s.groupCount++),"number"==typeof a._level&&(u._level=a._level),a._child&&(u._child=!0),-1!==t?n.splice(t,0,u):n.push(u),-1!==t&&t++}if(s.filteredItems)s.needsRefilter=!0;else{let i=s.hasNoResultsItem;s.hasNoResultsItem=0===s.items.length&&!!s.noResultsText,s.hasNoResultsItem?s.virtualListHelper.setCount(1).render():(i&&s.virtualListHelper.removeItemsAt(1,0),s.virtualListHelper.addItemsAt(e.length,-1===t?t:t-e.length).render())}return this}setItems(e){const t=this._p;return t.items.length=0,t.filteredItems=null,t.groupCount=0,t.hasNoResultsItem=!!t.noResultsText,t.virtualListHelper.setCount(t.hasNoResultsItem?1:0),this.addItems(e),this.updateSublist(),this}updateItemByValue(e,t){const s=this._p;let i=this.itemIndexByValue(e);if(-1===i)return this;let l=this.itemAtIndex(i);l[D]=t,G.call(t,s.labelProp)&&(l.label=t[s.labelProp]),G.call(t,s.valueProp)&&(l.value=t[s.valueProp]),G.call(t,"_nocheck")&&(l._nocheck=!!t._nocheck),G.call(t,"_nointeraction")&&(l._nointeraction=!!t._nointeraction),G.call(t,"_subitems")&&(l._subitems=!!t._subitems),s.multi&&G.call(t,"_checked")&&(l._checked=!!t._checked),G.call(t,"_group")&&!!t._group!==l._group&&(l._group?s.groupCount--:s.groupCount++,t._group=!!l._group),G.call(t,"_level")&&(t._level=l._level),G.call(t,"_child")&&(l._child=!!t._child);let r=i;return s.filteredItems&&(r=s.filteredItems.indexOf(l),-1!==r&&s.filteredItems.splice(r,1)),-1!==r&&s.virtualListHelper.isItemRendered(r)&&s.virtualListHelper.refreshItemAt(r).render(),this}removeItem(e,t){const s=this._p;let i=this.itemIndexByValueOrLabel(e,t);if(-1===i)return this;let l=s.items.splice(i,1);l[0]._group&&s.groupCount--;let r=i;return s.filteredItems&&(r=s.filteredItems.indexOf(l[0]),-1!==r&&s.filteredItems.splice(r,1)),-1!==r&&(s.hasNoResultsItem=0===(s.filteredItems??s.items).length&&!!s.noResultsText,s.hasNoResultsItem?s.virtualListHelper.setCount(1).render():s.virtualListHelper.removeItemsAt(r,1).render()),this}removeAllItems(){const e=this._p;return e.items.length=0,e.filteredItems=null,e.groupCount=0,e.hasNoResultsItem=!!e.noResultsText,e.virtualListHelper.setCount(e.hasNoResultsItem?1:0).render(),this}invalidate(){return this._p.virtualListHelper.invalidate().render(),this}itemDataByValue(e){const t=this._p;for(let s=0,i=t.items.length;s<i;s++){let i=t.items[s];if(i.value===e)return i[D]}return null}itemIndexByValue(e){const t=this._p.items;for(let s=0,i=t.length;s<i;s++)if(t[s].value===e)return s;return-1}filteredItemIndexByValue(e){const t=this._p,s=t.filteredItems??t.items;for(let i=0,l=s.length;i<l;i++)if(s[i].value===e)return i;return-1}itemIndexByValueOrLabel(e,t){const s=this._p.items;for(let i=0,l=s.length;i<l;i++){let l=s[i];if(l.value===e||l.label===t)return i}return-1}filteredItemIndexByValueOrLabel(e,t){const s=this._p,i=s.filteredItems??s.items;for(let l=0,r=i.length;l<r;l++){let s=i[l];if(s.value===e||s.label===t)return l}return-1}itemIndexByItem(e){const t=this._p.items;for(let s=0,i=t.length;s<i;s++)if(t[s][D]===e)return s;return-1}filteredItemIndexByItem(e){const t=this._p,s=t.filteredItems??t.items;for(let i=0,l=s.length;i<l;i++)if(s[i][D]===e)return i;return-1}items(){return this._p.items.map(e=>e[D])}itemsReference(){return this._p.items}itemCount(){return this._p.items.length}itemAtIndex(e){return this._p.items[e]?.[D]}filteredItemAtIndex(e){const t=this._p,s=t.filteredItems??t.items;return s[e]?.[D]}itemElementAtIndex(e){const t=this._p;return t.filteredItems?(e=t.filteredItems.indexOf(this._p.items[e]),t.virtualListHelper.getItemElementAt(e)??null):this.filteredElementItemAtIndex(e)}filteredElementItemAtIndex(e){return this._p.virtualListHelper.getItemElementAt(e)??null}setPositionOptionsProvider(e){const t=this._p;return t.positionOptionsProvider===e||(t.positionOptionsProvider=e??null,this.relayout()),this}getPositionOptionsProvider(){return this._p.positionOptionsProvider}setSearchTerm(e,t=!1){const s=this._p;return s.searchInput&&(s.searchInput.value=e),t&&(s.filterTerm=e.trim(),s.filteredItems=null,this._trigger("search",{value:e}),s.throttledRefilterItems()),this}isFilterPending(){const e=this._p;return!!(e.throttledRefilterItems.isScheduled()||!e.filteredItems&&(e.filterTerm||e.filterOnEmptyTerm&&e.filterFn))}_refilterItems(){const e=this._p,t=e.filterTerm,s=e.filterGroups,i=e.filterEmptyGroups;if(t||e.filterOnEmptyTerm&&e.filterFn){let l;if("function"==typeof e.filterFn&&(l=e.filterFn(e.items.map(e=>{const t=e[D];return void 0!==t?(t[D]=Object.seal({[D]:e}),t):e}),t),Array.isArray(l)&&(l=l.map(t=>{let s=t[D]?.[D];return s||(s={[D]:t,label:t[e.labelProp],value:t[e.valueProp],_nocheck:!!t._nocheck,_nointeraction:!!t._nointeraction,_subitems:t._subitems,_group:!!t._group,_level:!!t._level,_checked:!!t._checked}),s}))),!Array.isArray(l))if(t){const i=new RegExp(B(t),"i");l=e.items.filter(e=>!(s||!e._group)||i.test(e.label))}else l=null;if(e.filteredItems=l,l&&i){let e=-1,t=l.length;for(let s=0;s<t;s++)l[s]._group&&(-1!==e&&e===s-1&&(l.splice(e,1),s--,t--),e=s);-1!==e&&e===t-1&&l.splice(e,1)}}else e.filteredItems=null;e.needsRefilter=!1;const l=e.filteredItems??e.items;e.hasNoResultsItem=0===l.length&&!!e.noResultsText,e.virtualListHelper.setCount(l.length+(e.hasNoResultsItem?1:0)).render(),this._trigger("itemschanged",{term:t,mutated:!1,count:this.getFilteredItemCount()}),this.relayout()}invokeRefilter(){const e=this._p;return e.filterTerm||e.filterOnEmptyTerm||e.filteredItems?(e.filteredItems=null,e.throttledRefilterItems(),this):this}rushRefilter(){return this._p.needsRefilter&&this._refilterItems(),this}getFilteredItemCount(){const e=this._p;return this.rushRefilter(),e.filteredItems?e.filteredItems.length:e.items?e.items.length:0}setNoResultsText(e){const t=this._p;return t.noResultsText=e,t.hasNoResultsItem&&t.virtualListHelper.refreshItemAt(0).render(),this}getNoResultsText(){return this._p.noResultsText}setFilterThrottleWindow(e){const t=this._p;t.filterThrottleWindow=e;let s=!!t.throttledRefilterItems&&t.throttledRefilterItems.isScheduled();return t.throttledRefilterItems&&t.throttledRefilterItems.cancel(),t.throttledRefilterItems=R(()=>this._refilterItems(),t.filterThrottleWindow,!0),s&&t.throttledRefilterItems(),this}getFilterThrottleWindow(){return this._p.filterThrottleWindow}setFilterOnEmptyTerm(e){const t=this._p;return t.filterOnEmptyTerm===e||(t.filterOnEmptyTerm=e,t.throttledRefilterItems()),this}getFilterOnEmptyTerm(){return this._p.filterOnEmptyTerm}setFilterGroups(e){const t=this._p;return t.filterGroups===e||(t.filterGroups=e,t.throttledRefilterItems()),this}getFilterGroups(){return this._p.filterGroups}setFilterEmptyGroups(e){const t=this._p;return t.filterEmptyGroups===e||(t.filterEmptyGroups=e,t.throttledRefilterItems()),this}getFilterEmptyGroups(){return this._p.filterEmptyGroups}setFilterFn(e){const t=this._p;return t.filterFn===e||(t.filterFn=e,t.throttledRefilterItems()),this}getFilterFn(){return this._p.filterFn}relayout(e){const t=this._p,s=t.el,i=t.menuEl;if(!this.isVisible())return this;let l=window;e||(e=t.positionOptionsProvider?.()??t.lastPositionOptions),e||(e={targetOffset:{left:window.innerWidth/2,top:window.innerHeight/2},targetWidth:0,targetHeight:0,position:{x:"center",y:"center"},anchor:{x:"center",y:"center"},targetRtl:"rtl"===getComputedStyle(document.body).direction});let r={},n=e.targetOffset||m(e.target);r.left=n.left,r.top=n.top,r.height=null==e.targetHeight?h(e.target,!0,!0):e.targetHeight,r.width=null==e.targetWidth?p(e.target,!0,!0):e.targetWidth,r.bottom=r.top+r.height;let o={};o.top=l.pageYOffset,o.left=l.pageXOffset,o.width=l.innerWidth,o.height=l.innerHeight,o.bottom=o.top+o.height,o.right=o.left+o.width;let a=e.position&&"bottom"===e.position.y?"above":"below";s.style.width="",(t.estimateWidth||t.virtualListHelper.isVirtual())&&this._measureItem(),t.virtualListHelper.isVirtual()&&(i.style.height=Math.min(s.clientHeight,document.body.clientHeight)+"px",t.virtualListHelper.render()),e.updateWidth||"number"==typeof e.updateWidth?this._updateWidth(e):this._updateWidth(),t.virtualListHelper.isVirtual()&&t.virtualListHelper.render();let d,_=r.top-o.top,f=o.bottom-r.bottom;const b=getComputedStyle(s);let v="border-box"===b.boxSizing,y=(parseFloat(b.paddingTop)||0)+(parseFloat(b.paddingBottom)||0),S=(parseFloat(b.borderTopWidth)||0)+(parseFloat(b.borderBottomWidth)||0),C=0;t.headerEl&&(C=h(t.headerEl,!0,!0));let L=0;t.footerEl&&(L=h(t.footerEl,!0,!0)),t.virtualListHelper.isVirtual()?d=t.virtualListHelper.estimateFullHeight()+y+S+C+L:(s.style.height="",i.style.height="",s.style.top="-9999px",d=Math.max(h(t.el),i.scrollHeight),d+=y+S);let k=parseFloat(b.maxHeight);isNaN(k)||(v||(k+=y+S),d=Math.min(d,k));let x=_>=d,E=f>=d,w=t.currentDirection||a;"above"===w&&!x&&E?w="below":"below"===w&&!E&&x?w="above":x&&E?w!==a&&("above"===a&&_>=f||"below"===a&&f>=_)&&(w=a):x||E||(_>f?w="above":f>_&&(w="below")),t.currentDirection=w;let T={width:p(s,!0,!0),height:Math.min(d,Math.max(_,f,0))},F=void 0!==e.targetRtl?e.targetRtl:null!=e.target&&"rtl"===getComputedStyle(e.target).direction,N="rtl"===getComputedStyle(document.documentElement).direction,P=c(e.target,e.anchor?e.anchor.x:"start",e.anchor?e.anchor.y:"bottom",r,F),O=c(s,e.position?e.position.x:"start",e.position?e.position.y:"top",T,F),M="top"===O.ySpec&&"above"===w||"bottom"===O.ySpec&&"below"===w||"bottom"!==O.ySpec&&"top"!==O.ySpec&&"above"===w,V=void 0!==l.pageXOffset?l.pageXOffset:(document.documentElement||document.body.parentNode||document.body).scrollLeft;V=Math.abs(V),N&&(V=document.documentElement.scrollWidth-V-document.documentElement.clientWidth);let W=V,B=document.documentElement.clientWidth+V-T.width,R={position:"absolute",left:r.left,top:r.top+(M?P.bottom-O.bottom:P.top-O.top)};if(N&&(R.left-=document.documentElement.clientWidth-document.documentElement.scrollWidth),R.left+=P.left-O.left,e.offset&&(e.offset.y&&(M?R.top-=e.offset.y:R.top+=e.offset.y),e.offset.x)){let t="rtl"===b.direction;R.left+=t?-e.offset.x:e.offset.x}if(t.autoFlipDirection&&("right"===O.xSpec&&R.left<W&&(Math.max(R.left,W)+T.width-r.left)/r.width>.5||"left"===O.xSpec&&R.left>B&&(Math.min(R.left,B)-r.left)/r.width<.5)&&(R.left-=P.left-O.left,R.left+=P.right-O.right),t.constrainToWindow)for(let u of N?["min","max"]:["max","min"])"min"===u&&R.left<W?R.left=W:"max"===u&&R.left>B&&(R.left=B);return R.left+="px",R.top+="px",g(s,R),I(s,T.height,!0,!0),i!==s&&I(i,T.height-C-L-S-y,!0,!0),t.virtualListHelper.render(),e&&e.target&&(t.lastPositionTarget=e.target,u(e.target,`has_${t.baseClassName}`,!0),u(e.target,`has_${t.baseClassName}_below`,"below"===w),u(e.target,`has_${t.baseClassName}_above`,"above"===w),u(s,`${t.baseClassName}__is_below`,"below"===w),u(s,`${t.baseClassName}__is_above`,"above"===w)),this}setItemChecked(e,t){const s=this._p;t=!!t;let i=this.itemIndexByValue(e);if(-1===i)return this;let l=s.virtualListHelper.getItemElementAt(i);if(!l)return this;let r=l[D];return t=t&&!r._nocheck,r._checked!==t&&(r._checked=t,u(l,`${s.baseClassName}__item_checked`,r._checked),this._updateGroupStateForItem(r)),this}setCheckedValues(e){const t=this._p;this.rushRefilter();let s=[];for(let i=0,l=t.items.length;i<l;i++){let l=t.items[i],r=!l._nocheck&&-1!==e.indexOf(l.value),n=t.filteredItems?t.filteredItems.indexOf(l):i;if(l._group&&-1!==n&&s.push(n),l._checked===r)continue;if(l._checked=r,-1===n)continue;let o=t.virtualListHelper.getItemElementAt(n);o&&u(o,`${t.baseClassName}__item_checked`,l._checked)}if(t.autoCheckGroupChildren)for(let i=0,l=s.length;i<l;i++)this._updateGroupCheckedState(s[i],!1);return this}getCheckedValues(e){const t=this._p;e=e&&t.groupCount>0;let s=[];for(let i=0,l=t.items.length;i<l;i++){let l=t.items[i];l._checked&&(e&&l._group||s.push(l.value))}return s}getCheckedItems(e){const t=this._p;e=e&&t.groupCount>0;const s=[];for(let i=0,l=t.items.length;i<l;i++){let l=t.items[i];l._checked&&(e&&l._group||s.push(l[D]))}return s}show(e){const t=this._p;t.hiding=!1,this.isVisible()||this._trigger("show:before"),t.mouseHandled=!1,setTimeout(()=>{this[$]||t.onDocumentMouseDown||t.sink.add(document,"mousedown",t.onDocumentMouseDown=e=>{this.elContains(e.target,!0)||this._delayBlurItemOnBlur()})}),this.rushRefilter();const s=t.el;if(s.style.position="absolute",s.classList.remove(`${t.baseClassName}__is-hiding`),document.body.appendChild(s),t.visible=!0,t.el.style.display="","none"===getComputedStyle(t.el).display&&(t.el.style.display="block"),t.lastPositionOptions=null,void 0===e?e=t.positionOptionsProvider?.()??t.lastPositionOptions:t.lastPositionOptions=e,e){const t=getComputedStyle(s),i=s.style.maxHeight;let l=document.body.clientHeight-(parseFloat(t.marginTop)||0)-(parseFloat(t.marginBottom)||0)-("border-box"===t.boxSizing?0:(parseFloat(t.borderTopWidth)||0)+(parseFloat(t.borderBottomWidth)||0));s.style.maxHeight=Math.min(l,parseFloat(t.maxHeight)||l)+"px",this.relayout(e),s.style.maxHeight=i}else t.virtualListHelper.isVirtual()&&t.virtualListHelper.render();return this.isVisible()&&this._trigger("show"),this}hide(){const e=this._p,t=e.el;if(e.onDocumentMouseDown&&(e.sink.remove(document,"mousedown",e.onDocumentMouseDown),e.onDocumentMouseDown=null),this.isVisible()){if(this._trigger("hide:before"),e.hiding=!0,this.isFilterPending()&&(e.throttledRefilterItems.cancel(),e.needsRefilter=!0),t&&(t.classList.add(`${e.baseClassName}__is-hiding`),f(getComputedStyle(e.el).transition).reduce((e,t)=>Math.max(e,t.delay+t.duration),0)>0?setTimeout(()=>{this[$]||this._p&&t.parentNode&&e.hiding&&(a(t),t.classList.remove(`${e.baseClassName}__is-hiding`),e.visible=!1,this._trigger("hide:after"))}):(t.parentNode&&a(t),t.classList.remove(`${e.baseClassName}__is-hiding`))),e.visible=!1,this.blurFocusedItem(),this._trigger("hide"),this[$])return;this._trigger("hide:after"),e.currentSubDropList&&this._hideSublist()}return e.lastPositionTarget&&(e.lastPositionTarget.classList.remove(`has_${e.baseClassName}`,`has_${e.baseClassName}_above`,`has_${e.baseClassName}_below`),delete e.lastPositionTarget),this}isVisible(){const e=this._p;return!!e.visible&&e.el.parentNode&&"none"!==getComputedStyle(e.el).display}setHeaderVisible(e){this.isHeaderVisible()!==!!e&&(e?this._p.el.insertBefore(this._p.headerEl,this._p.el.firstChild??null):this._p.headerEl.remove())}isHeaderVisible(){return!!this._p.headerEl.parentNode}getHeaderElement(){return this._p.headerEl}setFooterVisible(e){this.isFooterVisible()!==!!e&&(e?this._p.el.appendChild(this._p.footerEl):this._p.footerEl.remove())}isFooterVisible(){return!!this._p.footerEl.parentNode}getFooterElement(){return this._p.footerEl}setSearchable(e){const s=this._p;!!s.searchInput!=!!e&&(e?(s.searchInput=t("input",{type:"search",role:"searchbox",tabindex:"0",autocorrect:"off",autocomplete:"off",autocapitalize:"off",spellcheck:"false","aria-autocomplete":"list"}),s.headerEl.appendChild(s.searchInput)):(s.searchInput.parentNode&&s.searchInput.remove(),s.searchInput=null),this.setHeaderVisible(e))}hasFocusedItem(){return this._p.focusItemIndex>-1&&this._p.focusItemIndex<this._p.items.length}getFocusedItemIndex(){return this.hasFocusedItem()?this._p.focusItemIndex:-1}setFocusedItemAtIndex(e){const t=this._p;if(this.rushRefilter(),t.filteredItems){const s=t.filteredItems[e];e=t.items.indexOf(s)}t.focusItemIndex=e;const s=t.filteredItems??t.items;let i=null;e>-1&&(i=s[e]),i&&i._nointeraction&&(i=null),e>-1&&this._scrollItemIndexIntoView(e);let l=i?t.virtualListHelper.getItemElementAt(e):null;if(t.focusItemEl!==l&&(t.focusItemEl&&(t.focusItemEl.classList.remove(`${t.baseClassName}__item_focus`),t.focusItemEl=null),l)){l.classList.add(`${t.baseClassName}__item_focus`),t.focusItemEl=l;const e=l[D];this._trigger("itemfocus",{value:e.value,item:e[D]??e,event:null,el:l}),this._showSublist(e,l)}return this}_showSublist(e,t){if(!e._subitems?.length)return;const i=this._p;if(i.currentSubDropList?.item===e)return;const l=new s({baseClassName:i.baseClassName,additionalClasses:i.additionalClasses,direction:i.direction,autoItemBlur:i.autoItemBlur,autoItemBlurDelay:i.autoItemBlurDelay,capturesFocus:i.capturesFocus,multi:i.multi,keyDownHandler:i.keyDownHandler,autoCheckGroupChildren:i.autoCheckGroupChildren,useExactTargetWidth:i.useExactTargetWidth,constrainToWindow:i.constrainToWindow,autoFlipDirection:i.autoFlipDirection,estimatedItemHeight:i.estimatedItemHeight,estimateWidth:i.estimateWidth,virtualMinItems:i.virtualMinItems,labelProp:i.labelProp,valueProp:i.valueProp,renderItem:i.renderItem,unrenderItem:i.unrenderItem,positionOptionsProvider:()=>i.currentSubDropList.showOptions});let r=e=>{this[$]||e.relatedTarget&&this.elContains(e.relatedTarget,!0)||(this._delayBlurItemOnBlur(),this._trigger("subitems:blur",e))};l.on("select",e=>{this._trigger("subitems:select",e)}).on("subitems:select",e=>{this._trigger("subitems:select",e)}).on("show_subitems",e=>{this._trigger("show_subitems",e)}).on("hide_subitems",e=>{this._trigger("hide_subitems",e)}).on("blur",r).on("subitems:blur",r).on("_back_key_pressed",()=>{this._hideSublist()}),l.setItems(e._subitems),this._trigger("show_subitems",{value:e.value,item:e[D]??e,el:t,droplist:l}),i.currentSubDropList={item:e,itemElement:t,droplist:l,showOptions:{target:t,position:{x:"start",y:"top"},anchor:{x:"end",y:"top"},offset:{x:0,y:0},updateWidth:!1}},l.show(),l.el.focus()}_hideSublist(){const e=this._p;if(!e.currentSubDropList)return;const t=e.currentSubDropList;let s=!!document.activeElement&&t.droplist.elContains(document.activeElement,!0);t.droplist.hide(),t.droplist.destroy(),e.currentSubDropList=null,s&&!this[$]&&this.el.focus(),this._trigger("hide_subitems",{value:t.item.value,item:t.item,el:t.itemElement,droplist:t.droplist})}updateSublist(){const e=this._p;if(!e.currentSubDropList)return;const t=e.currentSubDropList.item,s=e.currentSubDropList,i=e.items.find(e=>e===t)||e.items.find(e=>e.value===s.item.value);if(i){e.currentSubDropList.item=i;const t=e.virtualListHelper.getItemElementAt(this._getItemIndex(i));e.currentSubDropList.itemElement=t,i._subitems&&(e.currentSubDropList.droplist.setItems(i._subitems),t&&(e.currentSubDropList.showOptions.target=t,e.currentSubDropList.droplist.relayout()))}}setFocusedItem(e){const t=this._p;let s=e._nointeraction?-1:this._getItemIndex(e);const i=t.items;return s>-1&&i[s]._nointeraction&&(s=-1),this.setFocusedItemAtIndex(s)}setFocusedItemByValue(e){return this.setFocusedItemAtIndex(this.itemIndexByValue(e))}setSingleSelectedItemAtIndex(e){const t=this._p;this.rushRefilter();let s=null;if(e>-1&&!t.items[e]._nointeraction){if(t.filteredItems){const s=t.items[e];e=t.filteredItems.indexOf(s)}e>-1&&(s=t.virtualListHelper.getItemElementAt(e))}return this._setSingleSelectedItemEl(s),this}setSingleSelectedItem(e){const t=this._p;let s=e._nointeraction?-1:this._getItemIndex(e);const i=t.items;return s>-1&&i[s]._nointeraction&&(s=-1),this.setSingleSelectedItemAtIndex(s)}setSingleSelectedItemByValue(e){return this.setSingleSelectedItemAtIndex(this.itemIndexByValue(e))}next(e){this._move("next",e)}previous(e){this._move("prev",e)}isFirstItem(){const e=this._p,t=e.filteredItems??e.items;return 0===e.focusItemIndex&&e.focusItemIndex<t.length}isLastItem(){const e=this._p,t=e.filteredItems??e.items;return e.focusItemIndex>-1&&e.focusItemIndex===t.length-1}scrollItemIndexIntoView(e){const t=this._p;if(this._hasScroll()){if(t.filteredItems){const s=t.items[e];e=t.items.indexOf(s)}-1!==e&&this._scrollItemIndexIntoView(e)}return this}_scrollItemIndexIntoView(e){const t=this._p;if(this._hasScroll()){const s=t.menuEl,i=s.scrollTop;let l,r=-1,n=30;for(;n-- >0&&(l=t.virtualListHelper.getItemPosition(e),l!==r);){r=l;let n=t.virtualListHelper.getItemSize(e),o=s.clientHeight;l<i?s.scrollTop=l:l+n>i+o&&(s.scrollTop=l+n-o),t.virtualListHelper.render()}}}on(e,t){return this._p.mitt.on(e,t),this}once(e,t){let s=i=>{this._p.mitt.off(e,s),t(i)};return this._p.mitt.on(e,s),this}off(e,t){return e||e?this._p.mitt.off(e,t):this._p.mitt.all.clear(),this}emit(e,t){return this._p.mitt.emit(e,t),this}_getItemIndex(e){const t=this._p;let s=-1;if(e&&(s=(t.filteredItems??t.items).indexOf(e),-1===s)){let t=e&&void 0!==e.value?e.value:e,i=e&&e.label?e.label:t;s=this.itemIndexByValueOrLabel(t,i)}return s}_setSingleSelectedItemEl(e){const t=this._p;return t.singleSelectedItemEl&&(t.singleSelectedItemEl.classList.remove(`${t.baseClassName}__item_checked`),t.singleSelectedItemEl=null),e&&(e.classList.add(`${t.baseClassName}__item_checked`),t.singleSelectedItemEl=e),this}_trigger(e,t){const s=this._p;s.on&&s.on(e,...void 0===t?[]:[t]),s.mitt.emit(e,t)}_itemUpAction(t,s){if(e(t.target,".requires-pointer-events,button",s))return;let i=this._p;if(!this._mouseHandled){if(this.triggerItemSelection(null,t),this[$])return;document.activeElement!==this.el&&i.focusItemEl&&clearTimeout(i.blurTimer),setTimeout(()=>{this._mouseHandled=!1},0)}}_hookMouseEvents(){const t=this._p;t.sink.add(t.el,"mouseup",t=>{const s=e(t.target,"li",t.currentTarget);s&&0===t.button&&this._itemUpAction(t,s)}).add(t.el,"mouseover",t=>{const s=e(t.target,"li",t.currentTarget);s&&this._handleMouseOver(t,s)})}_handleMouseOver(e,t){this._focus(e,t,null,!0)}_hookTouchEvents(){const t=this._p;let s;t.sink.add(t.el,"touchstart",i=>{const l=e(i.target,"li",i.currentTarget);if(!l)return;if(s)return;if(e(i.target,".requires-pointer-events,button",l))return;s=i.changedTouches[0].identifier,this._handleMouseOver(i,l);let r=!1,n=()=>{r=!0},o=()=>{s=null,t.sink.remove(null,".dropdown_touchextra")},a=l.parentNode;for(;a;)t.sink.add(a,"scroll.dropdown_touchextra",n),a=a.parentNode;t.sink.add(window,"scroll.dropdown_touchextra",n),t.sink.add(window,"touchcancel.dropdown_touchextra",o),t.sink.add(t.el,"touchend.dropdown_touchextra",t=>{const i=e(t.target,"li",t.currentTarget);return i&&Array.prototype.find.call(t.changedTouches,e=>e.identifier===s)?(o(),void(r||(this._itemUpAction(t,i),t.preventDefault()))):o()})})}_hookFocusEvents(){const e=this._p;e.sink.add(e.el,"focus",t=>{if(t.target===this.el&&e.searchable&&e.searchInput.focus(),t.relatedTarget&&this.elContains(t.relatedTarget,!0)&&this.elContains(t.target,!0))return;let s=e.focusItemEl||e.el.firstChild;this._focus(t,s,null,!1)},!0).add(e.el,"blur",e=>{e.relatedTarget&&this.elContains(e.relatedTarget,!0)&&this.elContains(e.target,!0)||setTimeout(()=>{this[$]||document.activeElement&&this.elContains(document.activeElement,!0)||(this._delayBlurItemOnBlur(),this._trigger("blur",e))})},!0)}_hookKeyEvents(){const e=this._p;e.sink.add(e.el,"keydown",e=>this._keydown(e))}_hookSearchEvents(){const e=this._p;e.searchInput&&e.sink.add(e.searchInput,"input",()=>{e.filterTerm=e.searchInput.value.trim(),e.filteredItems=null,this._trigger("search",{value:e.searchInput.value}),e.throttledRefilterItems()})}_keydown(e){const t=this._p;if(t.keyDownHandler&&t.keyDownHandler.call(this,e))return;let s=!0;switch(e.key){case N:case F:case w:case k:case V:case L:switch(t.lastKeyWasChar=!1,e.preventDefault(),e.key){case N:this.previousPage(e);break;case F:this.nextPage(e);break;case w:this._move("first",e);break;case k:this._move("last",e);break;case V:this.previous(e);break;case L:this.next(e)}break;case T:case P:if(t.lastKeyWasChar=!1,e.key===P&&"rtl"!==getComputedStyle(e.target).direction||e.key===T&&"rtl"===getComputedStyle(e.target).direction){let e=(t.filteredItems??t.items)[t.focusItemIndex];t.focusItemIndex>-1&&e._subitems&&this._showSublist(e,t.focusItemEl)}else t.currentSubDropList?(this._hideSublist(),s=!1):this._trigger("_back_key_pressed");break;case x:t.lastKeyWasChar=!1,this.triggerItemSelection(null,e),e.preventDefault();break;case O:if("BUTTON"===e.target.tagName||"INPUT"===e.target.tagName&&t.lastKeyWasChar)return;this.toggleFocusedItem(),e.preventDefault();break;case E:t.lastKeyWasChar=!1,e.preventDefault(),this.hide();break;default:if("INPUT"===e.target.tagName||"TEXTAREA"===e.target.tagName){const s=e.key||String.fromCharCode(e.keyCode);t.lastKeyWasChar=1===s.length||e.key===S}t.searchable||this._keydownFreeType(e,!this.isVisible()),s=!1}}_keydownFreeType(e,t){const s=this._p,i=e.key||String.fromCharCode(e.keyCode),l=1===i.length;if(s.lastKeyWasChar=l||e.key===S,!l)return;clearTimeout(s.filterTimer);let r,n=(s.previousFilter||"")+i,o=new RegExp(`^${B(n)}`,"i"),a=-1,u=s.focusItemIndex;const c=s.filteredItems??s.items;for(let d=0,h=c.length;d<h&&(-1!==a&&d<u||(r=c[d],!(o.test(r.label)&&(a=d,-1===u||d>=u))));d++);if(-1===a){n=i,o=new RegExp(`^${B(n)}`,"i");for(let e=0,t=c.length;e<t&&(-1!==a&&e<u||(r=c[e],!(o.test(r.label)&&(a=e,-1===u||e>=u))));e++);}if(a>-1){let i=s.virtualListHelper.getItemElementAt(a);this._focus(e,i||null,a,!0),t&&this.triggerItemSelection(i?null:c[a],e),s.previousFilter=n,s.filterTimer=setTimeout(()=>{delete s.previousFilter},1e3)}else delete s.previousFilter}_focus(e,t,s,i){const l=this._p;if(l._isFocusingItem)return;l._isFocusingItem=!0,!s&&t&&(s=l.virtualListHelper.getItemIndexFromElement(t)),s>-1&&t?.[D]?.[D]===H&&(s=void 0),s>-1?this.scrollItemIndexIntoView(s):void 0===s&&(t=null);let r=t||l.virtualListHelper.getItemElementAt(s);if(!r||r[D]._nointeraction)return l._isFocusingItem=!1,void this.blurFocusedItem();if(r===l.focusItemEl)return l._isFocusingItem=!1,void clearTimeout(l.blurTimer);this.blurFocusedItem(),r.classList.add(`${l.baseClassName}__item_focus`),l.focusItemEl=r,l.focusItemIndex=s;const n=(l.filteredItems??l.items)[s];this._trigger("itemfocus",{value:n.value,item:n[D]??n,event:e,el:r}),l._isFocusingItem=!1,i&&this._showSublist(n,r)}_delayBlurItemOnBlur(){if(this[$])return;const e=this._p;e.autoItemBlur&&(clearTimeout(e.blurTimer),e.blurTimer=setTimeout(()=>{this[$]||this.blurFocusedItem()},e.autoItemBlurDelay))}_move(e,t){const s=this._p;let i,l,r;const n=s.filteredItems??s.items;if("first"===e)l=0,r=!1;else if("last"===e)l=n.length-1,r=!0;else if("prev"===e){if(!this.hasFocusedItem())return this._move("last",t);l=s.focusItemIndex-1,-1===l&&(l=n.length-1),r=!0}else if("next"===e){if(!this.hasFocusedItem())return this._move("first",t);l=s.focusItemIndex+1,l===n.length&&(l=0),r=!1}else{if("prev_page"!==e&&"next_page"!==e)return;if(!this.hasFocusedItem())return this._move("prev_page"===e?"prev":"next",t);if("prev_page"===e&&this.isFirstItem()||"next_page"===e&&this.isLastItem())return;if(!this._hasScroll())return this._move("prev_page"===e?"first":"last",t);if(s.virtualListHelper.isVirtual()){let t=s.virtualListHelper.getVisibleItemCount();l=s.focusItemIndex,"prev_page"===e?l-=t:l+=t,l<0?l=0:l>=n.length&&(l=n.length)}else if(s.focusItemEl){let t=m(s.focusItemEl).top,r=h(s.el,!0);for(;;){if(i=s.focusItemEl.nextElementSibling,!i)return;if("LI"===i.tagName)if("prev_page"===e){if(m(i).top-t+r<=0)break}else if(m(i).top-t-r>=0)break}i&&(l=s.virtualListHelper.getItemIndexFromElement(i),void 0===l&&(l=-1))}r="prev_page"===e}let o=n.length;if(l>=o)return;let a=n[l],u=l;for(;a&&a._nointeraction&&(r?(l--,-1===l&&(l=o)):(l++,l===o&&(l=0)),a=n[l],l!==u););i=s.virtualListHelper.getItemElementAt(l),this._focus(t,i||null,l,!1),this.isVisible()||this.triggerItemSelection(a,t)}_hasScroll(){const e=this._p.menuEl;return e.clientHeight<e.scrollHeight}_updateGroupStateForItem(e){const t=this._p;if(!t.multi)return this;if(e._group){let s=0;if(t.autoCheckGroupChildren){const i=t.filteredItems??t.items;let l=i.indexOf(e);const r=e._level;for(let n=l+1,o=i.length;n<o;n++){let l=i[n];if(!l._child&&i[n-1]._child||(void 0===r?l._group||void 0!==l._level:l._level<=r))break;if(!!l._checked===e._checked)continue;l._checked=e._checked,s++;let o=t.virtualListHelper.getItemElementAt(n);o&&u(o,`${t.baseClassName}__item_checked`,e._checked),this._trigger("check",{value:l.value,item:l[D]??l,checked:l._checked,isGroup:l._group,isCheckingGroup:!0})}}this._trigger("groupcheck",{value:e.value,item:e[D]??e,affectedCount:s})}else if(t.groupCount>0&&t.autoCheckGroupChildren){const s=t.filteredItems??t.items;let i=-1;for(let t=s.indexOf(e)-1;t>=0;t--)if(s[t]._group){i=t;break}i>-1&&this._updateGroupCheckedState(i,!0)}return this}_updateGroupCheckedState(e,t){const s=this._p;if(!(s.multi&&s.autoCheckGroupChildren&&e>-1))return this;const i=s.filteredItems??s.items;let l=i[e];if(!l||!l._group)return this;let r,n=!1,o=!1;const a=l._level;for(let u=e+1,d=i.length;u<d&&(r=i[u],!(!r._child&&i[u-1]._child||(void 0===a?r._group||void 0!==r._level:r._level<=a)));u++)r._checked?n=!0:r._checked||(o=!0);if(!n&&!o)return this;let c=n&&!o;if(!!l._checked!==c){l._checked=c;let i=s.virtualListHelper.getItemElementAt(e);i&&u(i,`${s.baseClassName}__item_checked`,l._checked),t&&this._trigger("check",{value:l.value,item:l[D]??l,checked:l._checked,isGroup:l._group,isCheckingGroup:!1})}return this}_measureItem(){const e=this._p;if(e.lastMeasureItemCount!==e.items.length){let t=e.lastMeasureLongestLabel||1,s=e.lastMeasureLongestLabelText||"";for(let i=0,l=e.items,r=l.length;i<r;i++){const e=l[i];let r=e.label;null==r&&(r=e.value),null==r&&(r="");let n=r.length;n>t&&(t=n,s=r)}e.lastMeasureItemCount=e.items.length,e.lastMeasureLongestLabel=t,e.lastMeasureLongestLabelText=s}return(e.estimateWidth||e.virtualListHelper.isVirtual())&&e.virtualListHelper.createGhostItemElement(A,!0,s=>{let i=t("span",{css:{display:"block",width:"100px",height:"100px",overflow:"scroll",position:"absolute"}}),l=t("span",{css:{display:"block",position:"relative",width:"0",height:"0",overflow:"hidden"}},[i]);s.appendChild(l);let r=i.offsetWidth-i.clientWidth;s.removeChild(l),e.lastMeasureItemWidth=p(s,!0,!0)+r}),this}_determineVirtualMode(e){const t=this._p,s=t.filteredItems??t.items;void 0===e&&(e=s.length);let i=e>=t.virtualMinItems;return i!==t.virtualListHelper.isVirtual()&&t.virtualListHelper.setVirtual(i).render(),this}_renderItemContent(e,s){const i=this._p,l=e[D];if(l===H)return!(!i.renderNoResultsItem||!1===i.renderNoResultsItem(e,s))||void s.appendChild(t("div",{class:"droplist-no-results-content",textContent:i.noResultsText}));i.renderItem&&!1!==i.renderItem(l||e,s)||(s.appendChild(t("span",{class:`${i.baseClassName}__item_label`,textContent:e.label})),i.multi&&(e._nocheck||s.insertBefore(t("span",{class:"checkbox"}),s.firstChild)))}_updateWidth(e){const t=this._p,s=t.el;let i=0;e&&(i="number"==typeof e.updateWidth||null!=e.targetWidth?e.updateWidth:p(e.target,!0,!0));let l=0;t.useExactTargetWidth&&i||(t.estimateWidth||t.virtualListHelper.isVirtual()?l=t.lastMeasureItemWidth:(s.style.width="",l=p(s,!0,!0)));let r=Math.max(l,i);b(s,r,!0,!0);const n=getComputedStyle(s);let o=(parseFloat(n.borderLeftWidth)||0)+(parseFloat(n.borderRightWidth)||0),a=s.scrollWidth+o;if(a>r){let e=a-r;s.style.width=`${parseFloat(s.style.width)+e}px`,r=a}return r}},U=Symbol("destroyed"),j=Symbol("rest_multi_items"),q=!!("ontouchstart"in window||window.DocumentTouch&&window.document instanceof window.DocumentTouch||window.navigator.maxTouchPoints),Q=function(e,t){return e instanceof Element&&e.classList.contains(t)},X=["font-family","font-size","font-weight","font-size","letter-spacing","text-transform","word-spacing","text-indent","box-sizing","padding-left","padding-right"],Y={el:null,baseClassName:"selectbox",disabled:!1,readOnly:!1,clearable:!0,hasOpenIndicator:!0,placeholder:"",sortSelectedItems:!0,sortListItems:!1,sortListCheckedFirst:!0,stickyValues:null,sortItemComparator:null,splitListCheckedGroups:!0,treatGroupSelectionAsItems:!1,blurOnSingleSelection:"touch",multi:!1,showSelection:!0,showPlaceholderInTooltip:!1,multiPlaceholderFormatter:null,searchable:!0,noResultsText:"No matching results",autoSelectTextOnCheck:!0,filterThrottleWindow:300,filterOnEmptyTerm:!1,labelProp:"label",valueProp:"value",multiItemLabelProp:"short_label",multiItemRemovePosition:"after",maxMultiItems:null,multiItemsRestLabelProvider:null,items:[],selectedValues:void 0,value:void 0,isLoadingMode:!1,closeListWhenLoading:!0,clearInputWhen:["single_close","multi_select_single"]},J=class{constructor(e){const s={...Y};for(let[t,l]of Object.entries(e))void 0!==l&&(s[t]=l);const i=this._p={ownsEl:!0,baseClassName:s.baseClassName,additionalClasses:s.additionalClasses,direction:"ltr"===s.direction?"ltr":"rtl"===s.direction?"rtl":"auto",listOptions:s.listOptions,disabled:!!s.disabled,readOnly:!!s.readOnly,clearable:!!s.clearable,hasOpenIndicator:!!s.hasOpenIndicator,placeholder:s.placeholder,sortSelectedItems:!!s.sortSelectedItems,sortListItems:!!s.sortListItems,sortListCheckedFirst:!!s.sortListCheckedFirst,stickyValues:Array.isArray(s.stickyValues)?new Set(s.stickyValues):null,sortItemComparator:s.sortItemComparator,splitListCheckedGroups:!!s.splitListCheckedGroups,treatGroupSelectionAsItems:s.treatGroupSelectionAsItems,blurOnSingleSelection:s.blurOnSingleSelection,multi:s.multi,showSelection:s.showSelection,showPlaceholderInTooltip:s.showPlaceholderInTooltip,multiPlaceholderFormatter:s.multiPlaceholderFormatter,searchable:s.searchable,allowTypeToSelect:s.allowTypeToSelect,noResultsText:s.noResultsText,autoSelectTextOnCheck:s.autoSelectTextOnCheck,labelProp:s.labelProp,valueProp:s.valueProp,multiItemLabelProp:s.multiItemLabelProp,multiItemRemovePosition:s.multiItemRemovePosition,maxMultiItems:s.maxMultiItems,multiItemsRestLabelProvider:s.multiItemsRestLabelProvider,renderSingleItem:s.renderSingleItem,unrenderSingleItem:s.unrenderSingleItem,renderMultiItem:s.renderMultiItem,unrenderMultiItem:s.unrenderMultiItem,renderRestMultiItem:s.renderRestMultiItem,unrenderRestMultiItem:s.unrenderRestMultiItem,on:s.on||null,silenceEvents:!0,mitt:W(),isLoadingMode:!!s.isLoadingMode,closeListWhenLoading:!!s.closeListWhenLoading,clearInputWhen:Array.isArray(s.clearInputWhen)?s.clearInputWhen.slice(0):[],items:[],itemsChanged:!0,sink:new v,resizeObserver:null,selectedItems:[],selectedValues:[],selectionChanged:!0,resortBySelectionNeeded:!1,filterThrottleWindow:s.filterThrottleWindow,filterOnEmptyTerm:s.filterOnEmptyTerm,filterFn:null,filterTerm:""};let r=s.el;r instanceof Element?i.ownsEl=!1:r=t("span"),l(r,{role:"combobox","aria-haspopup":"true","aria-expanded":"false"}),i.el=r,this._syncBaseClasses(),this._renderBase(),i.multiItemEls=[],this.enable(!i.disabled),this.setReadOnly(i.readOnly),this._setupDropdownMenu(),i.sink.add(r,"click",e=>{i.clearButtonWrapper&&i.clearButtonWrapper.contains(e.target)||r.contains(document.activeElement)||(i.input.focus(),i.input.selectionStart=i.input.selectionEnd=i.input.value.length)}),i.sink.add(r,"focus",e=>{const t=e.target;if(!r.contains(e.relatedTarget)&&!Q(t,`${i.baseClassName}__search_field`)&&!Q(t,`${i.baseClassName}__item`)){let e=r.querySelector(`.${i.baseClassName}__search_field`);e&&e.focus()}},!0),i.sink.add(i.input,"keydown",e=>{this._handleInputKeydown(e)}).add(i.input,"input",()=>{this._resizeInput()});const n=(()=>{let e;return()=>{e&&clearTimeout(e),e=setTimeout(()=>{u(r,`${i.baseClassName}__focus`,r.contains(document.activeElement))})}})();if(i.sink.add(r,"focus",n,!0),i.sink.add(r,"blur",n,!0),i.sink.add(window,"resize",()=>this._resizeInput()),i.sink.add(window,"orientationchange",()=>this._resizeInput()),void 0!==window.ResizeObserver){let e={borderBoxSize:{blockSize:null,inlineSize:null},contentBoxSize:{blockSize:null,inlineSize:null}};i.resizeObserver=new ResizeObserver(t=>{if(this[U])return;const s=t[0];e&&s.borderBoxSize[0].blockSize===e.borderBoxSize.blockSize&&s.borderBoxSize[0].inlineSize===e.borderBoxSize.inlineSize&&s.contentBoxSize[0].blockSize===e.contentBoxSize.blockSize&&s.contentBoxSize[0].inlineSize===e.contentBoxSize.inlineSize||(i.resizeObserver.unobserve(i.el),this._resizeInput(),requestAnimationFrame(()=>i.resizeObserver.observe(i.el))),e.borderBoxSize=s.borderBoxSize[0],e.contentBoxSize=s.contentBoxSize[0]}),i.resizeObserver.observe(i.el)}return this.setFilterFn(s.filterFn),this.setItems(s.items),delete s.items,s.multi&&Array.isArray(s.selectedValues)?this.setSelectedValues(s.selectedValues):null!=s.value&&this.setValue(s.value),this._scheduleSync("full"),this.silenceEvents=!1,this}destroy(){if(this[U])return;this[U]=!0;const e=this._p;if(e.syncTimeout&&(clearTimeout(e.syncTimeout),delete e.syncTimeout),this._stopTrackingPresence(),e.sink.remove(),e.dropList&&e.dropList.destroy(),this._cleanupSingleWrapper(),e.unrenderMultiItem||e.unrenderRestMultiItem)for(;e.multiItemEls.length>0;)this._removeMultiItemElementByIndex(e.multiItemEls.length-1);if(a(e.list),a(e.singleWrapper),a(e.input),a(e.inputBackBuffer),a(e.clearButtonWrapper),a(e.openIndicator),!e.ownsEl){for(let t of Array.from(e.el.classList))t.startsWith(e.baseClassName)&&e.el.classList.remove(t);e.el.removeAttribute("role"),e.el.removeAttribute("aria-haspopup"),e.el.removeAttribute("aria-expanded")}e.resizeObserver?.disconnect(),this._p=null}get el(){return this._p?.el??null}get droplistInstance(){return this._p.dropList}droplistElContains(e,t=!0){return this._p.dropList?.elContains(e,t)}enable(e){const t=this._p;void 0===e&&(e=!0),t.disabled=!e,t.el.setAttribute("aria-disabled",t.disabled.toString()),t.input.disabled=!!t.disabled;const s=t.multiItemEls;for(let i of s)t.disabled?i.removeAttribute("tabindex"):i.setAttribute("tabindex","0");return this}isEnabled(){return!this._p.disabled}disable(e){return this.enable(void 0!==e&&!e)}isDisabled(){return this._p.disabled}setReadOnly(e){const t=this._p;return void 0===e&&(e=!0),t.readOnly=e,t.el.setAttribute("aria-readOnly",t.readOnly.toString()),t.input.readOnly=!(t.searchable||t.multi)||!!t.readOnly,this}isReadOnly(){return this._p.readOnly}setAdditionalClasses(e){return this._p.additionalClasses=e,this._syncBaseClasses(),this}setItems(e,t=!0){const s=this._p;return e||(e=[]),s.items=e.slice(0),s.itemsChanged=!0,this._refreshItemByValueMap(),t&&this.setSelectedValues(this.getSelectedValues()),this._trigger("itemschanged",{term:null,mutated:!0,count:this.getFilteredItemCount()}),this}getFilteredItemCount(){const e=this._p;return e.dropList?e.dropList.getFilteredItemCount():e.items?e.items.length:0}isFilterPending(){const e=this._p;return!0===e.dropList?.isFilterPending()}updateItemByValue(e,t){const s=this._p;let i=this._getItemByValue(e);if(i){const e=i[s.valueProp];s.itemByValueMap?.has(e)&&s.itemByValueMap.delete(e),Object.assign(i,t),s.itemByValueMap.set(i[s.valueProp],i)}s.dropList&&s.dropList.updateItemByValue(e,t)}getItems(){return this._p.items}setClearable(e){return e=!!e,this._p.clearable===e||(this._p.clearable=!!e,this._scheduleSync("render_clear")),this}getClearable(){return this._p.clearable}setHasOpenIndicator(e){return e=!!e,this._p.hasOpenIndicator===e||(this._p.hasOpenIndicator=e,this._scheduleSync("render_base")),this}getHasOpenIndicator(){return this._p.hasOpenIndicator}setPlaceholder(e){return this._p.placeholder=null==e?"":String(e),this._scheduleSync("render_base"),this}getPlaceHolder(){return this._p.placeholder}setSearchTerm(e,t=!1){const s=this._p;return s.input?(s.input.value=e,this._scheduleSync("resize_input"),t&&(s.filterTerm=s.input.value.trim(),this._trigger("search:term",s.filterTerm),s.dropList?.setSearchTerm(s.filterTerm,t)),this):this}getSearchTerm(){const e=this._p;return e.input?e.input.value:""}invokeRefilter(){const e=this._p;return e.dropList?.invokeRefilter(),this}setSortSelectedItems(e){const t=this._p;return e=!!e,t.sortSelectedItems===e||(t.sortSelectedItems=e,this._scheduleSync("render_items")),this}isSortSelectedItemsEnabled(){return this._p.sortSelectedItems}setSortListItems(e){const t=this._p;return e=!!e,t.sortListItems===e||(t.sortListItems=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}isSortListItemsEnabled(){return this._p.sortListItems}setSortListCheckedFirst(e){const t=this._p;return e=!!e,t.sortListCheckedFirst===e||(t.sortListCheckedFirst=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}isSortListCheckedFirstEnabled(){return this._p.sortListCheckedFirst}setStickyValues(e){const t=this._p;return t.stickyValues=Array.isArray(e)?new Set(e):null,t.itemsChanged=!0,this._scheduleSync("render_list"),this}getStickyValues(){return this._p.stickyValues?Array.from(this._p.stickyValues):null}setSortItemComparator(e){const t=this._p;return t.sortItemComparator===e||(t.sortItemComparator=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}getSortItemComparator(){return this._p.sortItemComparator}setTreatGroupSelectionAsItems(e){const t=this._p;return e=!!e,t.treatGroupSelectionAsItems===e||(t.treatGroupSelectionAsItems=e,t.dropList?.setFilterGroups(e),t.dropList?.setFilterEmptyGroups(!e),t.itemsChanged=!0,this._scheduleSync("render_list")),this}isTreatGroupSelectionAsItemsEnabled(){return!this._p.treatGroupSelectionAsItems}setSplitListCheckedGroups(e){const t=this._p;return e=!!e,t.splitListCheckedGroups===e||(t.splitListCheckedGroups=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}isSplitListCheckedGroupsEnabled(){return this._p.splitListCheckedGroups}setShowSelection(e){const t=this._p;return e=!!e,t.showSelection===e||(t.showSelection=e,this._scheduleSync("render_items")),this}isShowSelectionEnabled(){return this._p.showSelection}setShowPlaceholderInTooltip(e){const t=this._p;return e=!!e,t.showPlaceholderInTooltip===e||(t.showPlaceholderInTooltip=e,this._scheduleSync("render_base")),this}isShowPlaceholderInTooltipEnabled(){return this._p.showPlaceholderInTooltip}setMultiPlaceholderFormatter(e){const t=this._p;return t.multiPlaceholderFormatter===e||(t.multiPlaceholderFormatter=e,this._scheduleSync("render_base")),this}setBlurOnSingleSelection(e){const t=this._p;return t.blurOnSingleSelection===e||(t.blurOnSingleSelection=e),this}getBlurOnSingleSelection(){return this._p.blurOnSingleSelection}setMulti(e){const t=this._p;return e=!!e,t.multi===e||(t.multi=e,this._setupDropdownMenu(),a(t.clearButtonWrapper),delete t.clearButtonWrapper,e&&t.selectedValues&&1===t.selectedValues.length&&Array.isArray(t.selectedValues[0])&&this.setSelectedValues(t.selectedValues[0]),this._scheduleSync("full")),this}isMultiEnabled(){return this._p.multi}setSearchable(e){const t=this._p;return e=!!e,t.searchable===e||(t.searchable=e,this._scheduleSync("full")),this}setAllowTypeToSelect(e){const t=this._p;return e=!!e,t.allowTypeToSelect===e||(t.allowTypeToSelect=e),this}isSearchableEnabled(){return this._p.searchable}setNoResultsText(e){return this._p.dropList?.setNoResultsText(e),this}getNoResultsText(){return this._p.noResultsText}setAutoSelectTextOnCheck(e){return this._p.autoSelectTextOnCheck=e,this}getAutoSelectTextOnCheck(){return this._p.autoSelectTextOnCheck}setFilterThrottleWindow(e){const t=this._p;return t.filterThrottleWindow=e,t.dropList?.setFilterThrottleWindow(e),this}getFilterThrottleWindow(){return this._p.filterThrottleWindow}setFilterOnEmptyTerm(e){const t=this._p;return t.filterOnEmptyTerm===e||t.dropList?.setFilterOnEmptyTerm(e),this}getFilterOnEmptyTerm(){return this._p.filterOnEmptyTerm}setListOptions(e){return this._p.listOptions=e,this._setupDropdownMenu(),this}setRenderSingleItem(e,t){const s=this._p;return s.renderSingleItem=e,s.unrenderSingleItem=t,this}setRenderMultiItem(e,t){const s=this._p;return s.renderMultiItem=e,s.unrenderMultiItem=t,this}setRenderRestMultiItem(e,t){const s=this._p;return s.renderRestMultiItem=e,s.unrenderRestMultiItem=t,this}setLabelProp(e){const t=this._p;return t.labelProp=e,t.dropList&&t.dropList.setLabelProp(e),this}setValueProp(e){const t=this._p;return t.valueProp===e||(t.valueProp=e,t.dropList&&t.dropList.setValueProp(e),this._refreshItemByValueMap()),this}setMultiItemLabelProp(e){return this._p.multiItemLabelProp=e,this._scheduleSync("render_items"),this}setMultiItemRemovePosition(e){return this._p.multiItemRemovePosition=e,this._scheduleSync("render_items"),this}setMaxMultiItems(e){return this._p.maxMultiItems=e,this}setMultiItemsRestLabelProvider(e){return this._p.multiItemsRestLabelProvider=e,this}setFilterFn(e){const t=this._p;return t.filterFn===e||(t.filterFn=e,e||(e=(e,s)=>{const i=new RegExp(B(s),"i"),l=t.labelProp,r=t.multiItemLabelProp;return t.items.filter(e=>!(t.treatGroupSelectionAsItems||!e._group)||i.test(e[l]||e[r]))}),t.actualFilterFn=e,t.dropList?.setFilterFn(e)),this}getFilterFn(){return this._p.filterFn}focusInput(){const e=this._p;return e.input&&e.input.focus(),this}blurInput(){const e=this._p;return e.input&&e.input.blur(),this}clear(){return this._performClearWithEvent(!0)?(this[U],this):this}getValue(){const e=this._p;return e.multi?e.selectedValues.slice(0):e.selectedValues.length>0?e.selectedValues[0]:void 0}setValue(e){return this._p.multi?this.setSelectedValues(Array.isArray(e)?e:void 0!==e?[e]:[]):this.setSelectedValues(void 0!==e?[e]:[])}getSelectedValues(){return this._p.selectedValues.slice(0)}setSelectedValues(e){const t=this._p,s=t.valueProp;t.multi||(e=e.slice(0,1));let i=new Set,l=[],r=[];for(let n of e){if(i.has(n))continue;i.add(n),l.push(n);let e=this._getItemByValue(n);void 0!==e?r.push(e):r.push({[s]:n})}return t.selectedValues=l,t.selectedItems=r,t.selectionChanged=!0,t.resortBySelectionNeeded=!0,this._scheduleSync("full"),this}getSelectedValueCount(){return this._p.selectedValues.length}getSelectedItems(){return this._p.selectedItems.slice(0)}setSelectedItems(e){return this._setSelectedItems(e),this}openList(){const e=this._p;return e.dropList.isVisible()||e.isLoadingMode&&0===e.items.length||(this._trigger("open:before",{list:e.dropList}),document.activeElement!==e.input&&(e.lastActiveElement=document.activeElement===document.body?null:function(e){if(!e)return null;const t={element:e};return"number"==typeof e.selectionStart&&"number"==typeof e.selectionEnd&&(t.selectionStart=e.selectionStart,t.selectionEnd=e.selectionEnd,t.selectionDirection=e.selectionDirection),t}(document.activeElement)),e.dropList.setDirection(getComputedStyle(e.el).direction),e.dropList.show(),this._repositionDropList(),this._repositionDropList(),e.dropList.hasFocusedItem()?e.dropList.setFocusedItemAtIndex(e.dropList.getFocusedItemIndex()):e.multi||void 0===this.getValue()||e.dropList.setFocusedItemByValue(this.getValue())),this}closeList(){const e=this._p;return this[U]?this:e.dropList.isVisible()?(e.dropList.hide(),e.lastActiveElement&&(e.multi||e.searchable||(t=e.lastActiveElement,t?.element&&document.body.contains(t.element)&&(t.element.focus(),"number"==typeof t.selectionStart&&"number"==typeof t.selectionEnd&&"function"==typeof t.element.setSelectionRange&&t.element.setSelectionRange(t.selectionStart,t.selectionEnd,t.selectionDirection??"none"))),e.lastActiveElement=null),this):this;var t}toggleList(e){const t=this._p;return(void 0===e?!t.dropList.isVisible():e)?this.openList():this.closeList()}isListOpen(){return!!this._p.dropListVisible}toggleLoading(e){return this.setIsLoadingMode(void 0===e?!this.getIsLoadingMode():!!e)}setIsLoadingMode(e){const t=this._p;return e=void 0===e||!!e,t.isLoadingMode===e||(t.isLoadingMode=e,t.isLoadingMode&&t.closeListWhenLoading&&0===t.items.length&&this.isListOpen()?this.closeList():!t.isLoadingMode&&t.closeListWhenLoading&&document.activeElement&&((t.multi||t.searchable)&&t.input.contains(document.activeElement)||!t.multi&&!t.searchable&&t.el.contains(document.activeElement))&&this.openList(),this._scheduleSync("render_base")),this}getIsLoadingMode(){return this._p.isLoadingMode}setCloseListWhenLoading(e){return this._p.closeListWhenLoading=e,this}getCloseListWhenLoading(){return this._p.closeListWhenLoading}setClearInputWhen(e){return this._p.clearInputWhen=Array.isArray(e)?e.slice(0):[],this}getClearInputWhen(){return this._p.clearInputWhen}setDirection(e){return this._p.direction="ltr"===e?"ltr":"rtl"===e?"rtl":"auto",this._syncBaseClasses(),this}getDirection(){return this._p.direction}refreshSize(){return this._resizeInput(),this}on(e,t){return this._p.mitt.on(e,t),this}once(e,t){let s=i=>{this._p.mitt.off(e,s),t(i)};return this._p.mitt.on(e,s),this}off(e,t){return e||e?this._p.mitt.off(e,t):this._p.mitt.all.clear(),this}emit(e,t){return this._p.mitt.emit(e,t),this}_refreshItemByValueMap(){const e=this._p,t=e.itemByValueMap=new Map,s=e.valueProp;for(let i of e.items)t.set(i[s],i);e.subitemByValueMap=null}_getItemByValue(e){const t=this._p;let s=t.itemByValueMap.get(e);return void 0!==s?s:(t.subitemByValueMap||this._refreshSubitemByValueMap(),t.subitemByValueMap.get(e))}_refreshSubitemByValueMap(){const e=this._p,t=e.subitemByValueMap=new Map;this._addSubitemsToValueMap(e.items,t,e.valueProp)}_addSubitemsToValueMap(e,t,s){for(let i of e)if(i._subitems?.length){for(let e of i._subitems)t.has(e[s])||t.set(e[s],e);this._addSubitemsToValueMap(i._subitems,t,s)}}_renderBase(){const s=this._p;if(s.inputBackBuffer||(s.inputBackBuffer=t("span",{css:{position:"absolute",zIndex:-1,left:0,top:"-9999px",whiteSpace:"pre"}})),s.input||(s.inputWrapper=t("span",{class:`${s.baseClassName}__search_wrapper`},s.input=t("input",{class:`${s.baseClassName}__search_field`,type:"search",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox","aria-autocomplete":"list",readOnly:!(s.searchable||s.multi)||!!s.readOnly}))),s.multi){if(s.singleWrapper&&(this._cleanupSingleWrapper(),a(s.singleWrapper),delete s.singleWrapper),!s.list){this._unregisterDropdownEvents();const i=document.activeElement;s.list=t("ul",{class:`${s.baseClassName}__list`}),s.el.appendChild(s.list),s.list.appendChild(s.inputWrapper),s.el.classList.remove(`${s.baseClassName}__single`),s.el.classList.add(`${s.baseClassName}__multi`),s.sink.add(s.list,"click",t=>{e(t.target,`.${s.baseClassName}__item_remove`,t.currentTarget)&&(s.disabled||s.readOnly||this._removeMultiItemFromEvent(e(t.target,`.${s.baseClassName}__item`,t.currentTarget),t))}).add(s.list,"keydown",t=>{e(t.target,`.${s.baseClassName}__item`,t.currentTarget)&&this._handleMultiKeydown(t)}),i===s.input&&s.input.focus(),this._registerDropdownEvents()}}else if(s.list&&(a(s.list),s.sink.remove(s.list),delete s.list),!s.singleWrapper){this._unregisterDropdownEvents();const e=document.activeElement;s.singleWrapper=t("div",{class:`${s.baseClassName}__single_wrapper`}),s.el.appendChild(s.singleWrapper),s.el.appendChild(s.inputWrapper),s.el.classList.remove(`${s.baseClassName}__multi`),s.el.classList.add(`${s.baseClassName}__single`),e===s.input&&s.input.focus(),this._registerDropdownEvents()}s.hasOpenIndicator!==!!s.openIndicator&&(s.hasOpenIndicator?(s.openIndicator=t("span",{class:`${s.baseClassName}__open_indicator`}),s.el.appendChild(s.openIndicator),s.el.classList.add(`${s.baseClassName}__has_open_indicator`)):(a(s.openIndicator),delete s.openIndicator,s.el.classList.remove(`${s.baseClassName}__has_open_indicator`))),s.isLoadingMode!==!!s.spinner&&(s.isLoadingMode?(s.spinner=t("span",{class:`${s.baseClassName}__spinner`}),s.el.appendChild(s.spinner),s.el.classList.add(`${s.baseClassName}__has_spinner`)):(a(s.spinner),delete s.spinner,s.el.classList.remove(`${s.baseClassName}__has_spinner`)))}_syncBaseClasses(){const e=this._p,t=e.el;if(!t)return;let s=[e.baseClassName];e.multi?s.push(`${e.baseClassName}__multi`):s.push(`${e.baseClassName}__single`),this.isListOpen()?s.push(`${e.baseClassName}__open_list`):s.push(`${e.baseClassName}__closed_list`),e.hasOpenIndicator&&s.push(`${e.baseClassName}__has_open_indicator`),e.clearButtonWrapper&&s.push(`${e.baseClassName}__has_clear`),e.isLoadingMode&&s.push(`${e.baseClassName}__has_spinner`),0===e.selectedValues.length&&s.push(`${e.baseClassName}__empty_selection`),e.selectedValues.length>0&&s.push(`${e.baseClassName}__has_selection`),(e.searchable||e.multi)&&s.push(`${e.baseClassName}__searchable`),"ltr"!==e.direction&&"rtl"!==e.direction||s.push(`${e.baseClassName}__`+e.direction),e.additionalClasses&&(s=s.concat(e.additionalClasses)),t.className=s.join(" ")}_setupDropdownMenu(){const t=this._p;t.valueProp,t.dropList&&(t.dropList.destroy(),delete t.dropList,t.itemsChanged=!0,t.selectionChanged=!0,t.resortBySelectionNeeded=!0);const s=t=>{e(t.target,"li",t.currentTarget)&&t.preventDefault()},i=t.dropList=new K({virtualMinItems:10,searchable:!1,...t.listOptions,multi:t.multi,capturesFocus:!1,labelProp:t.labelProp,valueProp:t.valueProp,noResultsText:t.noResultsText,filterThrottleWindow:t.filterThrottleWindow,filterOnEmptyTerm:t.filterOnEmptyTerm,filterGroups:t.treatGroupSelectionAsItems,filterEmptyGroups:!t.treatGroupSelectionAsItems,filterFn:t.actualFilterFn,positionOptionsProvider:()=>this._getDropListPositionOptions(),on:(e,l)=>{switch(e){case"show:before":{t.dropListVisible=!0,t.el.setAttribute("aria-expanded","true"),t.el.classList.add(`${t.baseClassName}__open_list`),t.el.classList.remove(`${t.baseClassName}__closed_list`),t.resortBySelectionNeeded&&t.sortListCheckedFirst&&t.multi&&(t.itemsChanged=!0),this._updateListItems(),this._trigger("open",{list:i}),this._startTrackingPresence(),t.sink.add(window,"resize.trackposition",()=>this._repositionDropList());let e=t.el.parentNode;for(;e;)(e.scrollHeight>e.offsetHeight||e.scrollWidth>e.offsetWidth)&&(e===document.documentElement&&(e=window),t.sink.add(e,"scroll.trackposition",()=>this._repositionDropList())),e=e.parentNode}break;case"hide":if(t.dropListVisible=!1,t.el.setAttribute("aria-expanded","false"),t.el.classList.remove(`${t.baseClassName}__open_list`),t.el.classList.add(`${t.baseClassName}__closed_list`),t.multi?t.clearInputWhen.includes("multi_close")&&this._setInputText(""):(t.clearInputWhen.includes("single_close")&&this._setInputText(""),this._scheduleSync("render_base")),this._trigger("close"),this[U])return;this._stopTrackingPresence(),t.sink.remove(null,".trackposition");break;case"check":{if(!t.multi)return;t.autoSelectTextOnCheck&&t.input&&document.activeElement===t.input&&t.input.setSelectionRange(0,t.input.value.length);const e=l.item,s=l.value;let r=l.checked;if(l.isGroup&&!t.treatGroupSelectionAsItems)return;let n={value:s,item:e,cancel:!1,isCheckingGroup:l.isCheckingGroup};if(this._trigger((r?"addsel":"removesel")+":before",n),n.cancel)return void t.dropList.setItemChecked(s,!r);if(r)t.selectedItems.push(e),t.selectedValues.push(s);else{const e=t.selectedValues.indexOf(s);-1!==e&&(t.selectedItems.splice(e,1),t.selectedValues.splice(e,1))}t.selectionChanged=!0,t.resortBySelectionNeeded=!0;const o=!!l.isCheckingGroup;t.showSelection?r?(1===i.itemCount()&&t.clearInputWhen.includes("multi_select_single")&&this._setInputText(""),t.sortSelectedItems?o||this._scheduleSync("full"):(null!=t.maxMultiItems&&(t.treatGroupSelectionAsItems?t.selectedItems:t.selectedItems.filter(e=>!e._group)).length>t.maxMultiItems?this._scheduleSync("addOrUpdateMultiItemRestElement"):this._scheduleSync("addMultiItemElement",e),o||this._scheduleSync("render_base"))):(null!=t.maxMultiItems&&(t.treatGroupSelectionAsItems?t.selectedItems:t.selectedItems.filter(e=>!e._group)).length===t.maxMultiItems?this._scheduleSync("removeMultiItemRestElement"):this._scheduleSync("removeMultiItemElement",e),o||this._scheduleSync("render_base")):t.multi&&this._scheduleSync("syncPlaceholder"),this._trigger(r?"addsel":"removesel",{value:s,item:e,isCheckingGroup:l.isCheckingGroup})}break;case"groupcheck":if(!t.multi)return;t.autoSelectTextOnCheck&&t.input&&document.activeElement===t.input&&t.input.setSelectionRange(0,t.input.value.length),l.affectedCount&&this._scheduleSync(t.sortSelectedItems?"full":"render_base"),this._trigger("groupcheck",{value:l.value,item:l.item,affectedCount:l.affectedCount});break;case"select":case"subitems:select":{if(t.multi)return;const e=l.item,s=l.value;if(!this._performSelectWithEvent(e,s))return;if(this[U])return;this.closeList(),("touch"===t.blurOnSingleSelection&&q||"touch"!==t.blurOnSingleSelection&&t.blurOnSingleSelection)&&t.input&&document.activeElement===t.input&&t.input.blur()}break;case"show_subitems":t.sink.add(l.droplist.el,"mousedown.subitems",s);break;case"hide_subitems":t.sink.remove(l.droplist.el,".subitems");break;case"blur":this._handleOnBlur();break;case"search":this._trigger("search",l);break;case"itemschanged":this._trigger("itemschanged",l)}}});t.sink.add(i.el,"mousedown",s),this._registerDropdownEvents()}_handleOnBlur(){const e=this._p;setTimeout(()=>{this[U]||e.disabled||e.readOnly||(this._trigger("search:blur"),this[U]||document.activeElement&&(e.input&&e.input.contains(document.activeElement)||e.dropList&&this.droplistElContains(document.activeElement,!0))||this.closeList())})}_unregisterDropdownEvents(){this._p.sink.remove(null,".dropdown")}_registerDropdownEvents(){const t=this._p;this._unregisterDropdownEvents();const s=t.dropList;if(!s)return;let i=!1,l=null;const r=t.multi||t.searchable?t.input:t.el;t.sink.add(r,"keydown.dropdown",e=>{if(e.currentTarget.readOnly)return;let i=!1,l=t.lastKeyAllowsNonTypeKeys;t.lastKeyAllowsNonTypeKeys=!1;let r=t.input&&t.input.value.length>0;switch(e.key){case N:case F:case V:case L:case w:case k:if((e.key===w||e.key===k)&&r&&!l){s._keydownFreeType(e);break}switch(t.lastKeyAllowsNonTypeKeys=!0,e.preventDefault(),e.key){case N:s.isVisible()&&s.previousPage(e);break;case F:s.isVisible()&&s.nextPage(e);break;case V:s.isVisible()?s.previous(e):this._movePrev();break;case L:s.isVisible()?s.next(e):this._moveNext();break;case w:s.goToFirst(e);break;case k:s.goToLast(e)}break;case O:l&&(t.lastKeyAllowsNonTypeKeys=!0,s.isVisible()&&s.hasFocusedItem()&&(i=!0,t.multi?s.toggleFocusedItem(e):s.triggerItemSelection(null,e),e.preventDefault()));break;case x:s.isVisible()&&s.hasFocusedItem()&&(i=!0,e.preventDefault(),s.triggerItemSelection(null,e));break;case M:s.isVisible()&&s.hasFocusedItem()&&s.triggerItemSelection(null,e);break;case E:s.isVisible()&&(s.hide(e),e.preventDefault());break;default:s.isVisible()?s._keydownFreeType(e,!1):t.allowTypeToSelect?s._keydownFreeType(e,!0):(this.openList(),setTimeout(()=>{this[U]||s._keydownFreeType(e,!1)}))}i||e.key!==x&&(e.key!==O||!t.lastKeyAllowsNonTypeKeys||t.multi||s.hasFocusedItem()||t.disabled||t.readOnly)||(this.toggleList(),e.preventDefault(),e.stopPropagation())}),t.input&&t.sink.add(t.input,"input.dropdown",()=>{t.disabled||t.readOnly||(t.filterTerm=t.input.value.trim(),this._trigger("search:term",t.filterTerm),t.dropList?.setSearchTerm(t.filterTerm,!0))}).add(t.input,"click.dropdown",()=>{t.disabled||t.readOnly||!t.multi&&t.searchable&&this.openList()}).add(t.input,"focus.dropdown",()=>{t.disabled||t.readOnly||(this._trigger("search:focus"),this[U]||(i=!1,this.openList(),i=!0,setTimeout(()=>{i=!1},10)))}).add(t.input,"blur.dropdown",()=>this._handleOnBlur()),t.sink.add(t.el,"mousedown.dropdown",()=>{t.multi||t.searchable||i||t.disabled||t.readOnly||this.toggleList(),i=!1}).add(t.el,"touchstart.dropdown",s=>{if(l)return;if(l=s.changedTouches[0].identifier,this.isDisabled()||this.isReadOnly())return;if(e(s.target,`.${t.baseClassName}__item,.${t.baseClassName}__clear`,t.el))return;let i=()=>{l=null,t.sink.remove(t.el,".dropdown_touchextra")};(t.input||t.el).focus(),t.sink.add(t.el,"touchend.dropdown_touchextra",e=>{if(!Array.prototype.find.call(s.changedTouches,e=>e.identifier===l))return i();e.preventDefault(),i()}).add(t.el,"touchmove.dropdown_touchextra",e=>{e.preventDefault()}).add(t.el,"touchcancel.dropdown_touchextra",i)})}_performSelectWithEvent(e,t){let s={value:t,item:e,cancel:!1};return this._trigger("select:before",s),!s.cancel&&!this[U]&&(this._setSelectedItems([e]),this._trigger("select",{value:t,item:e}),!0)}_performClearWithEvent(e=!1){let t={cancel:!1};return this._trigger("clear:before",t),!t.cancel&&!this[U]&&(this._setSelectedItems([]),e&&this._setInputText(""),this._trigger("clear"),!0)}_movePrev(){const e=this._p;if(this.isMultiEnabled())return;let t=this.getSelectedItems(),s=e.dropList.getFilteredItemCount();if(s+(e.clearable?1:0)>1){let i=t.length>0?e.dropList.filteredItemIndexByItem(t[0])-1:s-1;-1!==i||e.clearable||(i=s-1);let l=-1===i?null:e.dropList.filteredItemAtIndex(i);l?this._performSelectWithEvent(l,l[e.valueProp]):this._performClearWithEvent()}}_moveNext(){const e=this._p;if(this.isMultiEnabled())return;let t=this.getSelectedItems(),s=e.dropList.getFilteredItemCount();if(s+(e.clearable?1:0)>1){let i=t.length>0?e.dropList.filteredItemIndexByItem(t[0])+1:0;i===s&&(i=e.clearable?-1:0);let l=-1===i?null:e.dropList.filteredItemAtIndex(i);l?this._performSelectWithEvent(l,l[e.valueProp]):this._performClearWithEvent()}}_updateListItems(){const e=this._p,t=e.dropList;if(!t||!e.dropListVisible)return;if((e.itemsChanged||e.selectionChanged)&&(e.dropList._lastSerializedBox=null),e.itemsChanged){let s=e.items;(e.sortListItems||e.sortListCheckedFirst&&e.multi)&&(s=this._sortItems(s,e.sortListItems,e.sortListCheckedFirst&&e.multi,e.splitListCheckedGroups)),t.setItems(s),t.invokeRefilter(),e.itemsChanged=!1,e.selectionChanged=!0,e.resortBySelectionNeeded=!1}let s=!1;if(e.selectionChanged){if(e.multi)e.dropList.setCheckedValues(e.selectedValues);else{const t=e.dropList.itemIndexByValue(this.getValue());e.dropList.setFocusedItemAtIndex(t).setSingleSelectedItemAtIndex(t),s=e.dropList.hasFocusedItem()}e.selectionChanged=!1}this._repositionDropList(),s&&e.dropList.setFocusedItemAtIndex(e.dropList.getFocusedItemIndex())}_setSelectedItems(e){const t=this._p,s=t.valueProp;t.multi?(t.selectedItems=e.filter(e=>void 0!==e[s]),t.selectedValues=t.selectedItems.map(e=>e[s])):(t.selectedItems=e.slice(0,1),t.selectedValues=e.slice(0,1).map(e=>e[s])),t.selectionChanged=!0,t.resortBySelectionNeeded=!0,this._updateListItems(),this._scheduleSync("full")}_scheduleSync(e,t){const s=this._p;s.syncQueue||(s.syncQueue=[]),("full"===e||"render_items"===e&&!s.syncQueue.some(e=>"full"===e.mode))&&(s.syncQueue.length=0),0!==s.syncQueue.length&&["full","render_items"].includes(e)||s.syncQueue.push({mode:e,data:t}),s.syncTimeout||(s.syncTimeout=setTimeout(()=>{delete s.syncTimeout;let e=s.syncQueue;delete s.syncQueue,this._performSync(e)}))}_performSync(e){const t=this._p;if(!this[U])for(let s of e)switch(s.mode){case"full":this._syncFull(!0,!0);break;case"render_base":this._syncFull(!1,!1);break;case"render_items":this._syncFull(!0,!1);break;case"render_list":this._syncFull(!1,!0);break;case"render_clear":this._syncClearButton(),this._resizeInput();break;case"singleItem":this._syncSingleItem();break;case"syncPlaceholder":this._syncPlaceholder();break;case"removeMultiItemElement":if(t.showSelection)this._syncPlaceholder();else{const e=t.valueProp,i=s.data[e];let l=t.multiItemEls.findIndex(t=>t[D][e]===i);-1!==l&&this._removeMultiItemElementByIndex(l)}break;case"addMultiItemElement":t.showSelection?this._addMultiItemElement(s.data):this._syncPlaceholder();break;case"addOrUpdateMultiItemRestElement":t.showSelection?this._addMultiItemRestElement():this._syncPlaceholder();break;case"removeMultiItemRestElement":if(t.showSelection){let e=t.multiItemEls[t.multiItemEls.length-1];e?.[D]?.[t.valueProp]===j&&this._removeMultiItemElementByIndex(t.multiItemEls.length-1)}else this._syncPlaceholder();break;case"resize_input":this._resizeInput()}}_cleanupSingleWrapper(){const e=this._p;if(e.singleWrapper){if(e.unrenderSingleItem&&e.singleWrapper.childNodes.length>0)try{e.unrenderSingleItem(e.singleWrapper[D],e.singleWrapper)}catch(t){console.error(t)}delete e.singleWrapper[D],e.singleWrapper.innerHTML=""}}_removeMultiItemElementByIndex(e){const t=this._p,s=t.multiItemEls;if(s.length>e){const l=s[e],r=l[D];let n=r?.[t.valueProp]===j?t.unrenderRestMultiItem??t.unrenderMultiItem:t.unrenderMultiItem;if(n&&l.childNodes.length>0)try{n(r,l)}catch(i){console.error(i)}a(l),e===s.length-1?s.pop():s.splice(e,1)}}_renderSingleItemContent(e){const t=this._p;if(!t.renderSingleItem||!1===t.renderSingleItem(e,t.singleWrapper)){const s=t.labelProp;let i=e[t.multiItemLabelProp]||e[s];null==i&&(i=""),t.singleWrapper.appendChild(document.createTextNode(i))}}_renderMultiItemContent(e,s){const i=this._p;let l=e[i.valueProp]===j?i.renderRestMultiItem??i.renderMultiItem:i.renderMultiItem;if(!l||!1===l(e,s)){const l=i.labelProp,r=e[i.multiItemLabelProp]||e[l];s.appendChild(t("span",{textContent:r}))}}_addMultiItemElement(e){const t=this._p,s=this._renderMultiItem(e);return!!s&&(n(t.inputWrapper,s),t.multiItemEls.push(s),!0)}_addMultiItemRestElement(){const e=this._p;let t=e.selectedItems.slice(0),s=(e.treatGroupSelectionAsItems?t:t.filter(e=>!e._group)).length-e.maxMultiItems,i=e.multiItemsRestLabelProvider?e.multiItemsRestLabelProvider(s,t):`+ ${s}`;this._addMultiItemElement({items:t,[e.valueProp]:j,[e.labelProp]:i})}_syncClearButton(){const e=this._p,s=e.multiItemLabelProp;e.selectedItems.length>0&&e.selectedItems.some(e=>!1!==e[s])&&e.clearable&&e.showSelection?e.clearButtonWrapper||(e.clearButtonWrapper=t(e.multi?"li":"span",{class:`${e.baseClassName}__clear`},e.clearButton=t("button")),e.multi?r(e.list,e.clearButtonWrapper):r(e.el,e.clearButtonWrapper),e.el.classList.add(`${e.baseClassName}__has_clear`),e.sink.add(e.clearButton,"click",()=>{this.isDisabled()||this.isReadOnly()||this.clear()})):e.clearButtonWrapper&&(e.sink.remove(e.clearButton,"click"),a(e.clearButtonWrapper),delete e.clearButtonWrapper,delete e.clearButton,e.el.classList.remove(`${e.baseClassName}__has_clear`))}_syncPlaceholder(){const e=this._p,t=e.multiItemLabelProp;let s="";e.multi&&!e.showSelection?s="function"==typeof e.multiPlaceholderFormatter?e.multiPlaceholderFormatter(e.selectedItems):0===e.selectedItems.length?e.placeholder||"":((e,t)=>{if(0===e.length)return"";let s=e[0][t]+"";return e.length>1&&(s+=` (+${e.length-1})`),s})(e.selectedItems,e.labelProp):0!==e.selectedItems.length&&e.showSelection&&!e.selectedItems.every(e=>!1===e[t])||(s=null==e.placeholder?"":e.placeholder+""),e.input.setAttribute("placeholder",s),e.showPlaceholderInTooltip?e.input.setAttribute("title",s):e.input.removeAttribute("title")}_syncSingleItem(){const e=this._p;e.singleWrapper&&this._cleanupSingleWrapper();const t=e.selectedItems;t.length>0&&(this._renderSingleItemContent(t[0]),e.singleWrapper[D]=t[0])}_syncFull(e,t){const s=this._p,i=s.multiItemLabelProp;if(this._renderBase(),this._syncClearButton(),this._syncPlaceholder(),(e=s.multi&&s.showSelection&&(e||s.selectedItems.filter(e=>!1!==e[i]).length!==s.multiItemEls.length))||!s.showSelection||!s.multi)for(;s.multiItemEls.length>0;)this._removeMultiItemElementByIndex(s.multiItemEls.length-1);if(s.multi){if(e){const e=s.selectedItems,t=s.treatGroupSelectionAsItems;if(s.sortSelectedItems){const t=s.labelProp,i=s.multiItemLabelProp,l=s.valueProp,r=s.stickyValues,n=s.sortItemComparator||((e,s)=>{if(null!==r){let t=r.has(e[l]),i=r.has(s[l]);if(t&&!i)return-1;if(!t&&i)return 1}const n=e[i]||e[t],o=s[i]||s[t];return n<o?-1:n>o?1:0});e.sort(n),s.selectedValues=e.map(e=>e[l])}let i=0,l=s.maxMultiItems,r=!1;for(let s=0;s<e.length;s++)if(t||!e[s]._group){if(null!=l&&i===l){r=!0;break}this._addMultiItemElement(e[s])&&i++}r&&this._addMultiItemRestElement()}}else s.multi||this._syncSingleItem();return o(s.el)!==document||(u(s.el,`${s.baseClassName}__empty_selection`,0===s.selectedValues.length),u(s.el,`${s.baseClassName}__has_selection`,s.selectedValues.length>0),s.searchable?(s.input&&(s.input.readOnly=s.readOnly),s.el.classList.add(`${s.baseClassName}__searchable`)):(s.input&&(s.input.readOnly=!0),s.el.classList.remove(`${s.baseClassName}__searchable`)),this._resizeInput(),t&&this._updateListItems()),this}_trigger(e,t){const s=this._p;void 0!==s&&(s.on&&s.on(e,...void 0===t?[]:[t]),s.mitt.emit(e,t))}_renderMultiItem(e){const s=this._p,i=s.labelProp,l=e[s.multiItemLabelProp]??e[i];if(!1===l)return null;const r=t("span",{class:`${s.baseClassName}__item_remove`,role:"presentation"}),n=t("li",{class:`${s.baseClassName}__item`,tabindex:"0",title:l});return"before"===s.multiItemRemovePosition&&n.appendChild(r),this._renderMultiItemContent(e,n),"after"===s.multiItemRemovePosition&&n.appendChild(r),n[D]=e,n}_removeMultiItemFromEvent(e,t){const l=this._p;let r;if(/key/.test(t.type)){const n=t;n.key===C?r=s(e,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`):n.key===S&&(r=i(e,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`))}else/click|mouse|touch/.test(t.type)&&(r=s(e,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`));const n=e[D],o=n[l.valueProp];if(void 0!==n)if(o===j){let e=(l.treatGroupSelectionAsItems?l.selectedItems:l.selectedItems.filter(e=>!e._group)).slice(l.maxMultiItems),t=[];for(let s of e){let e={value:o,item:s,cancel:!1};this._trigger("removesel:before",e),e.cancel||t.push(s)}if(t.length>0){this._removeMultiItemElementByIndex(l.multiItemEls.length-1);for(let e of t){let t=l.selectedItems.indexOf(e);-1===t&&(t=l.selectedValues.indexOf(o[l.valueProp])),-1!==t&&(l.selectedItems.splice(t,1),l.selectedValues.splice(t,1),l.selectionChanged=!0,l.resortBySelectionNeeded=!0)}}e.length>t.length&&this._addMultiItemRestElement(),t.length>0&&this._scheduleSync("render_list")}else{let e={value:o,item:n,cancel:!1};if(this._trigger("removesel:before",e),e.cancel)return this;this._removeMultiItem(n),this._trigger("removesel",{value:o,item:n})}return r||(r=l.el.querySelector(`.${l.baseClassName}__item, .${l.baseClassName}__search_field`)),Q(r,`${l.baseClassName}__search_wrapper`)&&(r=r.querySelector("input")),r&&r.focus(),this}_removeMultiItem(e,t=!1){const s=this._p,i=s.valueProp,l=s.labelProp,r=e[i];let n=s.selectedItems.indexOf(e);-1===n&&(n=s.selectedValues.indexOf(r)),-1!==n&&(s.selectedItems.splice(n,1),s.selectedValues.splice(n,1),s.selectionChanged=!0,s.resortBySelectionNeeded=!0),n=s.multiItemEls.findIndex(t=>t[D]===e),-1===n&&(n=s.multiItemEls.findIndex(e=>e[D][i]===r)),-1!==n&&this._removeMultiItemElementByIndex(n),t&&(this._setInputText(e[s.multiItemLabelProp]||e[l]),s.input.focus(),s.input.selectionStart=s.input.selectionEnd=s.input.value.length),this._scheduleSync("render_list")}_setInputText(e){const t=this._p;t.input.value=null==e?"":String(e),t.filterTerm="",this._trigger("search:term",t.filterTerm),t.dropList?.setSearchTerm("",!0)}_resizeInput(){const e=this._p,t=e.el;if(!t.parentNode||!document.body.contains(t))return this;const s=e.input,i=e.inputBackBuffer;let l=s.value||s.placeholder;u(t,`${e.baseClassName}__has_input`,!!l),u(t,`${e.baseClassName}__empty_input`,!l);let r=!1;if(e.multi&&0===e.multiItemEls.length&&e.showSelection){s.style.width="";let i=0,l=0,n=getComputedStyle(e.list||t,"::before");n.content&&"none"!==n.content&&"absolute"!==n.position&&"none"!==n.float&&(i=_(e.list||t,"::before",!0,!0,!0));let o=getComputedStyle(e.list||t,"::after");o.content&&"none"!==o.content&&"absolute"!==o.position&&"none"!==o.float&&(l=_(e.list||t,"::after",!0,!0,!0));let a=p(e.list||t);a-=i+l,s.style.width=`${a}px`,r=!0}else{g(i,d(s,X)),i.textContent=l,t.appendChild(i);const n=getComputedStyle(s),o=(parseFloat(n.paddingLeft)||0)+(parseFloat(n.paddingRight)||0),u=.75*(parseFloat(n["font-size"])||0)+o,c=p(i,!0,!0),h=p(s,!0,!0);let m=Math.max(c,u);if(m!==h){b(s,m,!0,!0);let t=(parseFloat(n.borderLeftWidth)||0)+(parseFloat(n.borderRightWidth)||0),i=s.scrollWidth+t;if(i>m){let e=i-m;s.style.width=`${parseFloat(s.style.width)+e}px`,m+=e}if(e.singleWrapper&&(e.singleWrapper.style.width="",l)){let s=m-o-t;p(e.singleWrapper,!1,!1)<s&&b(e.singleWrapper,s,!1,!1)}r=!0}a(i)}return r&&this._trigger("input:resize"),this}_repositionDropList(){const e=this._p,t=e.el;if(!e.dropList||!e.dropListVisible||!e.dropList.isVisible())return this;const s=t.getBoundingClientRect(),i=s.left+","+s.top+","+s.right+","+s.bottom;return e.dropList._lastSerializedBox!==i&&(e.dropList.relayout(),e.dropList._lastSerializedBox=i),this}_handleInputKeydown(e){const t=this._p,s=e.target;if(e.key===S&&e.ctrlKey&&0===s.value.length)this.clear(),e.preventDefault();else if(e.key===S&&0===s.value.length){const s=t.multiItemEls[t.multiItemEls.length-1];if(!s)return;const i=s[D],l=i[t.valueProp];if(void 0===l)return;let r={value:l,item:i,cancel:!1};if(this._trigger("removesel:before",r),r.cancel)return;this._removeMultiItem(i,!0),this._trigger("removesel",{value:l,item:i}),e.preventDefault()}}_handleMultiKeydown(t){const l=this._p;if(l.disabled||l.readOnly)return;const r="rtl"===getComputedStyle(l.el).direction;let n;if(t.key===(r?T:P))n=s(t.target,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`),Q(n,`${l.baseClassName}__search_wrapper`)&&(n=n.querySelector("input")),n&&n.focus(),t.preventDefault();else if(t.key===(r?P:T))n=i(t.target,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`),Q(n,`${l.baseClassName}__search_wrapper`)&&(n=n.querySelector("input")),n&&n.focus(),t.preventDefault();else if(t.key===S&&t.ctrlKey){const e=[];let s=t.target;for(;s;)e.push(s),s=i(s,`.${l.baseClassName}__item`);for(;e.length;)this._removeMultiItemFromEvent(e.shift(),t);t.preventDefault()}else t.key!==C&&t.key!==S||(this._removeMultiItemFromEvent(e(t.target,`.${l.baseClassName}__item`,l.el),t),t.preventDefault())}_getDropListPositionOptions(){return{target:this._p.el,offset:{x:0,y:0},anchor:{x:"start",y:"bottom"},position:{x:"start",y:"top"},updateWidth:!0}}_startTrackingPresence(){const e=this._p;this._stopTrackingPresence(),e.presenceInt=setInterval(()=>{o(e.el)!==document&&this.closeList()},200)}_stopTrackingPresence(){const e=this._p;e.presenceInt&&(clearInterval(e.presenceInt),e.presenceInt=null)}_sortItems(e,t,s,i){const l=this._p;if(!t&&!s)return e;const r=l.labelProp,n=l.multiItemLabelProp,o=l.valueProp,a=l.stickyValues,u=l.sortItemComparator||((e,t)=>{if(null!==a){let s=a.has(e[o]),i=a.has(t[o]);if(s&&!i)return-1;if(!s&&i)return 1}const s=e[r]||e[n],i=t[r]||t[n];return s<i?-1:s>i?1:0});let c=[],d=null,h=[c],m=!1;const p=new Set(l.selectedValues);let _,f,g;for(f=0,g=e.length;f<g;f++)_=e[f],(_._group&&c.length||m&&!_._group&&!_._child)&&(m=!!_._group,c=[],h.push(c)),c.push(_);c.length||(h.length=0),a&&e.length>0&&!e[0]._group&&(d=h[0].filter(e=>a.has(e[o])),d.length>0?(h[0]=h[0].filter(e=>!a.has(e[o])),0===h[0].length&&h.shift()):d=null),t&&h.sort((e,t)=>{if(e=e[0],t=t[0],null!==a){let s=a.has(e[o]),i=a.has(t[o]);if(s&&!i)return-1;if(!s&&i)return 1}return!e._group&&t._group?-1:e._group&&!t._group?1:u(e,t)}),d&&h.unshift(d);const I=[],b=[];for(let S=0,C=h.length;S<C;S++)c=h[S],c.sort((e,i)=>{if(e._group&&!i._group)return-1;if(!e._group&&i._group)return 1;if(s){const t=p.has(e[o]),s=p.has(i[o]);if(t&&!s)return-1;if(!t&&s)return 1}return t?u(e,i):0}),b.push(c);if(s&&i){let e;for(let t=0,s=h.length;t<s;t++){if(c=h[t],c===d){I.push(d);let e=b.indexOf(d);-1!==e&&b.splice(e,1);continue}e=null;for(let t=0,s=c.length;t<s;t++)if(_=c[t],!_._group){if(!p.has(_[l.valueProp]))break;e||(e=[],c[0]._group&&e.push(c[0])),e.push(_),c.splice(t--,1),s--}if(e&&(I.push(e),0===c.length||1===c.length&&c[0]._group)){h.splice(t--,1),s--;let e=b.indexOf(c);-1!==e&&b.splice(e,1)}}}const v=[];v.length=e.length;let y=0;h=I.length?I.concat(b):b;for(let S=0,C=h.length;S<C;S++)for(c=h[S],f=0,g=c.length;f<g;f++)v[y++]=c[f];return v}};export{K as DropList,z as DropListDefaultOptions,D as ItemSymbol,J as SelectBox,Y as SelectBoxDefaultOptions};
5
+ import{closestUntil as e,createElement as t,next as s,prev as i,setElementAttrs as l}from"@danielgindi/dom-utils/lib/Dom";import{append as r,before as n,getRootNode as o,remove as a,toggleClass as u}from"@danielgindi/dom-utils/lib/DomCompat";import{anchoredPosition as c,getCssProps as d,getElementHeight as h,getElementOffset as m,getElementWidth as p,getPseudoElementWidth as _,parseTransition as g,setCssProps as f,setElementHeight as I,setElementWidth as b}from"@danielgindi/dom-utils/lib/Css";import v from"@danielgindi/dom-utils/lib/DomEventsSink";import y from"@danielgindi/virtual-list-helper";import{VALUE_BACK_SPACE as S,VALUE_DELETE as C,VALUE_DOWN as L,VALUE_END as k,VALUE_ENTER as x,VALUE_ESCAPE as E,VALUE_HOME as w,VALUE_LEFT as T,VALUE_PAGE_DOWN as F,VALUE_PAGE_UP as N,VALUE_RIGHT as P,VALUE_SPACE as V,VALUE_TAB as O,VALUE_UP as M}from"keycode-js";import W from"mitt";var B=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),R=(e,t,s)=>{let i,l,r,n,o=0;s||(s={});const a=()=>{o=!1===s.leading?0:Date.now(),i=null,n=e.apply(l,r),i||(l=r=null)},u=function(){const u=Date.now();o||!1!==s.leading||(o=u);const c=t-(u-o);return l=this,r=arguments,c<=0||c>t?(i&&(clearTimeout(i),i=null),o=u,n=e.apply(l,r),i||(l=r=null)):i||!1===s.trailing||(i=setTimeout(a,c)),n};return u.cancel=()=>{clearTimeout(i),o=0,i=l=r=null},u.isScheduled=()=>!!i,u},D=Symbol("item"),$=Symbol("destroyed"),A=Symbol("ghost"),H=Symbol("no_results_items"),G=Object.prototype.hasOwnProperty,z={baseClassName:"droplist",autoItemBlur:!0,autoItemBlurDelay:300,capturesFocus:!0,multi:!1,singleSelectedValue:void 0,keyDownHandler:null,autoCheckGroupChildren:!0,useExactTargetWidth:!1,constrainToWindow:!0,autoFlipDirection:!0,estimateWidth:!1,virtualMinItems:100,labelProp:"label",valueProp:"value",on:null,isHeaderVisible:!1,isFooterVisible:!1,searchable:!1,noResultsText:"No matching results",filterThrottleWindow:300,filterOnEmptyTerm:!1,filterGroups:!1,filterEmptyGroups:!1},K=class s{constructor(e){const s={...z};for(let[t,a]of Object.entries(e))void 0!==a&&(s[t]=a);const i=this._p={ownsEl:!0,elOriginalDisplay:"",baseClassName:s.baseClassName,additionalClasses:s.additionalClasses,direction:"ltr"===s.direction?"ltr":"rtl"===s.direction?"rtl":"auto",autoItemBlur:s.autoItemBlur,autoItemBlurDelay:s.autoItemBlurDelay,capturesFocus:s.capturesFocus,multi:s.multi,singleSelectedValue:s.singleSelectedValue,keyDownHandler:s.keyDownHandler,autoCheckGroupChildren:s.autoCheckGroupChildren,useExactTargetWidth:s.useExactTargetWidth,constrainToWindow:s.constrainToWindow,autoFlipDirection:s.autoFlipDirection,estimatedItemHeight:s.estimatedItemHeight,estimateWidth:s.estimateWidth,virtualMinItems:s.virtualMinItems,labelProp:s.labelProp,valueProp:s.valueProp,renderItem:s.renderItem,unrenderItem:s.unrenderItem,renderNoResultsItem:s.renderNoResultsItem,unrenderNoResultsItem:s.unrenderNoResultsItem,on:s.on||null,positionOptionsProvider:s.positionOptionsProvider??null,searchable:s.searchable,isHeaderVisible:s.isHeaderVisible,isFooterVisible:s.isFooterVisible,silenceEvents:!0,mitt:W(),filterThrottleWindow:s.filterThrottleWindow,filterOnEmptyTerm:s.filterOnEmptyTerm,filterGroups:s.filterGroups,filterEmptyGroups:s.filterEmptyGroups,filterFn:s.filterFn,filteredItems:null,filterTerm:"",needsRefilter:!1,throttledRefilterItems:null,focusItemIndex:-1,focusItemEl:null,sink:new v};let l=[i.baseClassName+"_wrapper"];i.additionalClasses&&(l=l.concat((i.additionalClasses+"").split(" ").filter(e=>e)));const r={top:"-9999px"};let n=s.el;n instanceof Element?(i.elOriginalDisplay=n.style.display||"",n.classList.add(...l),f(n,r),i.ownsEl=!1):n=t("div",{class:l.join(" "),css:r}),i.el=n;let o=t("ul");o.role="menu",i.menuEl=o,i.headerEl=t("div",{class:i.baseClassName+"_header"}),i.footerEl=t("div",{class:i.baseClassName+"_footer"}),s.searchable&&this.setSearchable(!0),s.isHeaderVisible&&this.setHeaderVisible(s.isHeaderVisible),n.appendChild(o),s.isFooterVisible&&this.setFooterVisible(s.isFooterVisible),i.items=[],i.groupCount=0,i.mouseHandled=!1,i.virtualListHelper=new y({list:i.menuEl,virtual:!0,buffer:5,estimatedItemHeight:s.estimatedItemHeight||20,itemElementCreatorFn:()=>t("li",{role:"menuitem",tabIndex:i.capturesFocus?-1:null}),onItemRender:(e,t)=>{let s;if(t===A)s={label:i.lastMeasureLongestLabelText,value:"Measure",[D]:{[i.labelProp]:i.lastMeasureLongestLabelText,[i.valueProp]:"Measure"}},e.setAttribute("aria-hidden","true");else{const e=i.filteredItems??i.items;s=0===e.length&&i.noResultsText?{value:H,label:i.noResultsText,_nointeraction:!0,_nocheck:!0,[D]:H}:e[t]}s||console.warn("onItemRender called for ("+t+") which has no item"),e.className=`${i.baseClassName}__item`;const l=e.classList;s&&(i.multi?s._nocheck?l.add(`${i.baseClassName}__item_multi_nocheck`):(l.add(`${i.baseClassName}__item_multi`),s._checked&&l.add(`${i.baseClassName}__item_checked`)):(l.add(`${i.baseClassName}__item_single`),void 0!==i.singleSelectedValue&&s.value===i.singleSelectedValue?(l.add(`${i.baseClassName}__item_selected`),i.singleSelectedItemEl=e):i.singleSelectedItemEl===e&&(i.singleSelectedItemEl=null)),s._group&&l.add(`${i.baseClassName}__item_group`),s._child&&l.add(`${i.baseClassName}__item_child`),s._nointeraction&&l.add(`${i.baseClassName}__item_nointeraction`)),i.focusItemIndex===t&&(i.focusItemEl=e,l.add(`${i.baseClassName}__item_focus`)),this._renderItemContent(s,e),e[D]=s}}),this._setupUnrenderFunction(),i.capturesFocus&&(n.tabIndex=0),this.setFilterThrottleWindow(s.filterThrottleWindow),this.setNoResultsText(s.noResultsText),this._hookMouseEvents(),this._hookTouchEvents(),this._hookFocusEvents(),this._hookKeyEvents(),this._hookSearchEvents(),this.silenceEvents=!1}destroy(){if(this[$])return;this[$]=!0;const e=this._p;if(clearTimeout(e.blurTimer),clearTimeout(e.filterTimer),e.sink.remove(),e.virtualListHelper.destroy(),e.el?.parentNode&&a(e.el),e.currentSubDropList&&(e.currentSubDropList?.droplist?.destroy(),e.currentSubDropList=null),e.throttledRefilterItems&&e.throttledRefilterItems.cancel(),!e.ownsEl){for(let t of Array.from(e.el.classList))t.startsWith(e.baseClassName)&&e.el.classList.remove(t);for(let t of["position","left","top","right","bottom","z-index"])e.el.style[t]="";e.el.style.display=e.elOriginalDisplay}e.lastPositionTarget&&(e.lastPositionTarget.classList.remove(`has_${e.baseClassName}`,`has_${e.baseClassName}_above`,`has_${e.baseClassName}_below`),delete e.lastPositionTarget),delete e.lastPositionOptions,this._p=null}get el(){return this._p?.el??null}elContains(e,t=!0){return!!this.el.contains(e)||!(!t||!this._p.currentSubDropList?.droplist?.elContains(e))}setAdditionalClasses(e){return this._p.additionalClasses=e,this._syncBaseClasses(),this}setDirection(e){return this._p.direction="ltr"===e?"ltr":"rtl"===e?"rtl":"auto",this._syncBaseClasses(),this}getDirection(){return this._p.direction}setLabelProp(e){return this._p.labelProp=e,this}setRenderItem(e){return this._p.renderItem=e,this}setUnrenderItem(e){return this._p.unrenderItem=e,this._setupUnrenderFunction(),this}setRenderNoResultsItem(e,t){const s=this._p;return s.renderNoResultsItem=e,s.unrenderNoResultsItem=t,this._setupUnrenderFunction(),this}_setupUnrenderFunction(){const e=this._p;if("function"==typeof e.unrenderItem||"function"==typeof e.unrenderNoResultsItem){const t=e.unrenderItem,s=e.unrenderNoResultsItem;e.virtualListHelper.setOnItemUnrender(i=>{const l=i[D];if(l===H)try{s(l,i)}catch(r){console.error(r)}else try{t(l[D],i)}catch(r){console.error(r)}delete i[D],e.focusItemEl===i&&(e.focusItemEl=null)})}else e.virtualListHelper.setOnItemUnrender(t=>{delete t[D],e.focusItemEl===t&&(e.focusItemEl=null)});return this}setValueProp(e){return this._p.valueProp=e,this}_syncBaseClasses(){const e=this._p,t=e.el;if(!t)return;let s=[e.baseClassName+"_wrapper"];"ltr"!==e.direction&&"rtl"!==e.direction||s.push(`${e.baseClassName}__`+e.direction),e.additionalClasses&&(s=s.concat(e.additionalClasses)),t.className=s.join(" ")}blurFocusedItem(){const e=this._p;if(clearTimeout(e.blurTimer),!this.hasFocusedItem())return;let t=e.focusItemEl;t&&(t.classList.remove(`${e.baseClassName}__item_focus`),e.focusItemEl=null);const s=(e.filteredItems??e.items)[e.focusItemIndex];e.focusItemIndex=-1,s&&(e.currentSubDropList&&this._hideSublist(),this._trigger("itemblur",{value:s.value,item:s[D]??s}))}nextPage(e){this._move("next_page",e)}previousPage(e){this._move("prev_page",e)}goToFirst(e){this._move("first",e)}goToLast(e){this._move("last",e)}toggleFocusedItem(){const e=this._p;if(this.hasFocusedItem()&&e.multi){let t=(e.filteredItems??e.items)[e.focusItemIndex];if(!t||t._nocheck||t._nointeraction)return this;t._checked=!t._checked,e.focusItemEl&&u(e.focusItemEl,`${e.baseClassName}__item_checked`,t._checked),this._trigger("check",{value:t.value,item:t[D]??t,checked:t._checked,isGroup:t._group,isCheckingGroup:!1}),this._updateGroupStateForItem(t)}return this}triggerItemSelection(t,s){const i=this._p;return i.focusItemEl=i.focusItemEl||e(s.target,"li",i.el),i.focusItemIndex=i.virtualListHelper.getItemIndexFromElement(i.focusItemEl),void 0===i.focusItemIndex&&(i.focusItemIndex=-1),!(t=t??i.focusItemEl[D])._nointeraction&&(t._subitems?.length?(this._showSublist(t,i.focusItemEl),!1):(i.multi?this.hasFocusedItem()&&this.toggleFocusedItem():(this._setSingleSelectedItemEl(i.focusItemEl,t?t.value:void 0),this._trigger("select",{value:t?t.value:void 0,item:t[D]??t,event:s,el:i.focusItemEl})),!0))}addItem(e,t=-1){return this.addItems([e],t)}addItems(e,t=-1){const s=this._p,i=s.labelProp,l=s.valueProp;let r=s.multi;const n=s.items;(null==t||t<0||t>=s.items.length)&&(t=-1),this._determineVirtualMode(n.length+e.length);for(let o=0,a=e.length;o<a;o++){let a=e[o],u={[D]:a,label:a[i],value:a[l],_nocheck:!!a._nocheck,_nointeraction:!!a._nointeraction,_subitems:a._subitems};r&&(u._checked=!!a._checked),a._group&&(u._group=!0,s.groupCount++),"number"==typeof a._level&&(u._level=a._level),a._child&&(u._child=!0),-1!==t?n.splice(t,0,u):n.push(u),-1!==t&&t++}if(s.filteredItems)s.needsRefilter=!0;else{let i=s.hasNoResultsItem;s.hasNoResultsItem=0===s.items.length&&!!s.noResultsText,s.hasNoResultsItem?s.virtualListHelper.setCount(1).render():(i&&s.virtualListHelper.removeItemsAt(1,0),s.virtualListHelper.addItemsAt(e.length,-1===t?t:t-e.length).render())}return this}setItems(e){const t=this._p;return t.items.length=0,t.filteredItems=null,t.groupCount=0,t.hasNoResultsItem=!!t.noResultsText,t.virtualListHelper.setCount(t.hasNoResultsItem?1:0),this.addItems(e),this.updateSublist(),this}updateItemByValue(e,t){const s=this._p;let i=this.itemIndexByValue(e);if(-1===i)return this;let l=this.itemAtIndex(i);l[D]=t,G.call(t,s.labelProp)&&(l.label=t[s.labelProp]),G.call(t,s.valueProp)&&(l.value=t[s.valueProp]),G.call(t,"_nocheck")&&(l._nocheck=!!t._nocheck),G.call(t,"_nointeraction")&&(l._nointeraction=!!t._nointeraction),G.call(t,"_subitems")&&(l._subitems=!!t._subitems),s.multi&&G.call(t,"_checked")&&(l._checked=!!t._checked),G.call(t,"_group")&&!!t._group!==l._group&&(l._group?s.groupCount--:s.groupCount++,t._group=!!l._group),G.call(t,"_level")&&(t._level=l._level),G.call(t,"_child")&&(l._child=!!t._child);let r=i;return s.filteredItems&&(r=s.filteredItems.indexOf(l),-1!==r&&s.filteredItems.splice(r,1)),-1!==r&&s.virtualListHelper.isItemRendered(r)&&s.virtualListHelper.refreshItemAt(r).render(),this}removeItem(e,t){const s=this._p;let i=this.itemIndexByValueOrLabel(e,t);if(-1===i)return this;let l=s.items.splice(i,1);l[0]._group&&s.groupCount--;let r=i;return s.filteredItems&&(r=s.filteredItems.indexOf(l[0]),-1!==r&&s.filteredItems.splice(r,1)),-1!==r&&(s.hasNoResultsItem=0===(s.filteredItems??s.items).length&&!!s.noResultsText,s.hasNoResultsItem?s.virtualListHelper.setCount(1).render():s.virtualListHelper.removeItemsAt(r,1).render()),this}removeAllItems(){const e=this._p;return e.items.length=0,e.filteredItems=null,e.groupCount=0,e.hasNoResultsItem=!!e.noResultsText,e.virtualListHelper.setCount(e.hasNoResultsItem?1:0).render(),this}invalidate(){return this._p.virtualListHelper.invalidate().render(),this}itemDataByValue(e){const t=this._p;for(let s=0,i=t.items.length;s<i;s++){let i=t.items[s];if(i.value===e)return i[D]}return null}itemIndexByValue(e){const t=this._p.items;for(let s=0,i=t.length;s<i;s++)if(t[s].value===e)return s;return-1}filteredItemIndexByValue(e){const t=this._p,s=t.filteredItems??t.items;for(let i=0,l=s.length;i<l;i++)if(s[i].value===e)return i;return-1}itemIndexByValueOrLabel(e,t){const s=this._p.items;for(let i=0,l=s.length;i<l;i++){let l=s[i];if(l.value===e||l.label===t)return i}return-1}filteredItemIndexByValueOrLabel(e,t){const s=this._p,i=s.filteredItems??s.items;for(let l=0,r=i.length;l<r;l++){let s=i[l];if(s.value===e||s.label===t)return l}return-1}itemIndexByItem(e){const t=this._p.items;for(let s=0,i=t.length;s<i;s++)if(t[s][D]===e)return s;return-1}filteredItemIndexByItem(e){const t=this._p,s=t.filteredItems??t.items;for(let i=0,l=s.length;i<l;i++)if(s[i][D]===e)return i;return-1}items(){return this._p.items.map(e=>e[D])}itemsReference(){return this._p.items}itemCount(){return this._p.items.length}itemAtIndex(e){return this._p.items[e]?.[D]}filteredItemAtIndex(e){const t=this._p,s=t.filteredItems??t.items;return s[e]?.[D]}itemElementAtIndex(e){const t=this._p;return t.filteredItems?(e=t.filteredItems.indexOf(this._p.items[e]),t.virtualListHelper.getItemElementAt(e)??null):this.filteredElementItemAtIndex(e)}filteredElementItemAtIndex(e){return this._p.virtualListHelper.getItemElementAt(e)??null}setPositionOptionsProvider(e){const t=this._p;return t.positionOptionsProvider===e||(t.positionOptionsProvider=e??null,this.relayout()),this}getPositionOptionsProvider(){return this._p.positionOptionsProvider}setSearchTerm(e,t=!1){const s=this._p;return s.searchInput&&(s.searchInput.value=e),t&&(s.filterTerm=e.trim(),s.filteredItems=null,this._trigger("search",{value:e}),s.throttledRefilterItems()),this}isFilterPending(){const e=this._p;return!!(e.throttledRefilterItems.isScheduled()||!e.filteredItems&&(e.filterTerm||e.filterOnEmptyTerm&&e.filterFn))}_refilterItems(){const e=this._p,t=e.filterTerm,s=e.filterGroups,i=e.filterEmptyGroups;if(t||e.filterOnEmptyTerm&&e.filterFn){let l;if("function"==typeof e.filterFn&&(l=e.filterFn(e.items.map(e=>{const t=e[D];return void 0!==t?(t[D]=Object.seal({[D]:e}),t):e}),t),Array.isArray(l)&&(l=l.map(t=>{let s=t[D]?.[D];return s||(s={[D]:t,label:t[e.labelProp],value:t[e.valueProp],_nocheck:!!t._nocheck,_nointeraction:!!t._nointeraction,_subitems:t._subitems,_group:!!t._group,_level:!!t._level,_checked:!!t._checked}),s}))),!Array.isArray(l))if(t){const i=new RegExp(B(t),"i");l=e.items.filter(e=>!(s||!e._group)||i.test(e.label))}else l=null;if(e.filteredItems=l,l&&i){let e=-1,t=l.length;for(let s=0;s<t;s++)l[s]._group&&(-1!==e&&e===s-1&&(l.splice(e,1),s--,t--),e=s);-1!==e&&e===t-1&&l.splice(e,1)}}else e.filteredItems=null;e.needsRefilter=!1;const l=e.filteredItems??e.items;e.hasNoResultsItem=0===l.length&&!!e.noResultsText,e.virtualListHelper.setCount(l.length+(e.hasNoResultsItem?1:0)).render(),this._trigger("itemschanged",{term:t,mutated:!1,count:this.getFilteredItemCount()}),this.relayout()}invokeRefilter(){const e=this._p;return e.filterTerm||e.filterOnEmptyTerm||e.filteredItems?(e.filteredItems=null,e.throttledRefilterItems(),this):this}rushRefilter(){return this._p.needsRefilter&&this._refilterItems(),this}getFilteredItemCount(){const e=this._p;return this.rushRefilter(),e.filteredItems?e.filteredItems.length:e.items?e.items.length:0}setNoResultsText(e){const t=this._p;return t.noResultsText=e,t.hasNoResultsItem&&t.virtualListHelper.refreshItemAt(0).render(),this}getNoResultsText(){return this._p.noResultsText}setFilterThrottleWindow(e){const t=this._p;t.filterThrottleWindow=e;let s=!!t.throttledRefilterItems&&t.throttledRefilterItems.isScheduled();return t.throttledRefilterItems&&t.throttledRefilterItems.cancel(),t.throttledRefilterItems=R(()=>this._refilterItems(),t.filterThrottleWindow,!0),s&&t.throttledRefilterItems(),this}getFilterThrottleWindow(){return this._p.filterThrottleWindow}setFilterOnEmptyTerm(e){const t=this._p;return t.filterOnEmptyTerm===e||(t.filterOnEmptyTerm=e,t.throttledRefilterItems()),this}getFilterOnEmptyTerm(){return this._p.filterOnEmptyTerm}setFilterGroups(e){const t=this._p;return t.filterGroups===e||(t.filterGroups=e,t.throttledRefilterItems()),this}getFilterGroups(){return this._p.filterGroups}setFilterEmptyGroups(e){const t=this._p;return t.filterEmptyGroups===e||(t.filterEmptyGroups=e,t.throttledRefilterItems()),this}getFilterEmptyGroups(){return this._p.filterEmptyGroups}setFilterFn(e){const t=this._p;return t.filterFn===e||(t.filterFn=e,t.throttledRefilterItems()),this}getFilterFn(){return this._p.filterFn}relayout(e){const t=this._p,s=t.el,i=t.menuEl;if(!this.isVisible())return this;let l=window;e||(e=t.positionOptionsProvider?.()??t.lastPositionOptions),e||(e={targetOffset:{left:window.innerWidth/2,top:window.innerHeight/2},targetWidth:0,targetHeight:0,position:{x:"center",y:"center"},anchor:{x:"center",y:"center"},targetRtl:"rtl"===getComputedStyle(document.body).direction});let r={},n=e.targetOffset||m(e.target);r.left=n.left,r.top=n.top,r.height=null==e.targetHeight?h(e.target,!0,!0):e.targetHeight,r.width=null==e.targetWidth?p(e.target,!0,!0):e.targetWidth,r.bottom=r.top+r.height;let o={};o.top=l.pageYOffset,o.left=l.pageXOffset,o.width=l.innerWidth,o.height=l.innerHeight,o.bottom=o.top+o.height,o.right=o.left+o.width;let a=e.position&&"bottom"===e.position.y?"above":"below";s.style.width="",(t.estimateWidth||t.virtualListHelper.isVirtual())&&this._measureItem(),t.virtualListHelper.isVirtual()&&(i.style.height=Math.min(s.clientHeight,document.body.clientHeight)+"px",t.virtualListHelper.render()),e.updateWidth||"number"==typeof e.updateWidth?this._updateWidth(e):this._updateWidth(),t.virtualListHelper.isVirtual()&&t.virtualListHelper.render();let d,_=r.top-o.top,g=o.bottom-r.bottom;const b=getComputedStyle(s);let v="border-box"===b.boxSizing,y=(parseFloat(b.paddingTop)||0)+(parseFloat(b.paddingBottom)||0),S=(parseFloat(b.borderTopWidth)||0)+(parseFloat(b.borderBottomWidth)||0),C=0;t.headerEl&&(C=h(t.headerEl,!0,!0));let L=0;t.footerEl&&(L=h(t.footerEl,!0,!0)),t.virtualListHelper.isVirtual()?d=t.virtualListHelper.estimateFullHeight()+y+S+C+L:(s.style.height="",i.style.height="",s.style.top="-9999px",d=Math.max(h(t.el),i.scrollHeight),d+=y+S);let k=parseFloat(b.maxHeight);isNaN(k)||(v||(k+=y+S),d=Math.min(d,k));let x=_>=d,E=g>=d,w=t.currentDirection||a;"above"===w&&!x&&E?w="below":"below"===w&&!E&&x?w="above":x&&E?w!==a&&("above"===a&&_>=g||"below"===a&&g>=_)&&(w=a):x||E||(_>g?w="above":g>_&&(w="below")),t.currentDirection=w;let T={width:p(s,!0,!0),height:Math.min(d,Math.max(_,g,0))},F=void 0!==e.targetRtl?e.targetRtl:null!=e.target&&"rtl"===getComputedStyle(e.target).direction,N="rtl"===getComputedStyle(document.documentElement).direction,P=c(e.target,e.anchor?e.anchor.x:"start",e.anchor?e.anchor.y:"bottom",r,F),V=c(s,e.position?e.position.x:"start",e.position?e.position.y:"top",T,F),O="top"===V.ySpec&&"above"===w||"bottom"===V.ySpec&&"below"===w||"bottom"!==V.ySpec&&"top"!==V.ySpec&&"above"===w,M=void 0!==l.pageXOffset?l.pageXOffset:(document.documentElement||document.body.parentNode||document.body).scrollLeft;M=Math.abs(M),N&&(M=document.documentElement.scrollWidth-M-document.documentElement.clientWidth);let W=M,B=document.documentElement.clientWidth+M-T.width,R={position:"absolute",left:r.left,top:r.top+(O?P.bottom-V.bottom:P.top-V.top)};if(N&&(R.left-=document.documentElement.clientWidth-document.documentElement.scrollWidth),R.left+=P.left-V.left,e.offset&&(e.offset.y&&(O?R.top-=e.offset.y:R.top+=e.offset.y),e.offset.x)){let t="rtl"===b.direction;R.left+=t?-e.offset.x:e.offset.x}if(t.autoFlipDirection&&("right"===V.xSpec&&R.left<W&&(Math.max(R.left,W)+T.width-r.left)/r.width>.5||"left"===V.xSpec&&R.left>B&&(Math.min(R.left,B)-r.left)/r.width<.5)&&(R.left-=P.left-V.left,R.left+=P.right-V.right),t.constrainToWindow)for(let u of N?["min","max"]:["max","min"])"min"===u&&R.left<W?R.left=W:"max"===u&&R.left>B&&(R.left=B);return R.left+="px",R.top+="px",f(s,R),I(s,T.height,!0,!0),i!==s&&I(i,T.height-C-L-S-y,!0,!0),t.virtualListHelper.render(),e&&e.target&&(t.lastPositionTarget=e.target,u(e.target,`has_${t.baseClassName}`,!0),u(e.target,`has_${t.baseClassName}_below`,"below"===w),u(e.target,`has_${t.baseClassName}_above`,"above"===w),u(s,`${t.baseClassName}__is_below`,"below"===w),u(s,`${t.baseClassName}__is_above`,"above"===w)),this}setItemChecked(e,t){const s=this._p;t=!!t;let i=this.itemIndexByValue(e);if(-1===i)return this;let l=s.virtualListHelper.getItemElementAt(i);if(!l)return this;let r=l[D];return t=t&&!r._nocheck,r._checked!==t&&(r._checked=t,u(l,`${s.baseClassName}__item_checked`,r._checked),this._updateGroupStateForItem(r)),this}setCheckedValues(e){const t=this._p;this.rushRefilter();let s=[];for(let i=0,l=t.items.length;i<l;i++){let l=t.items[i],r=!l._nocheck&&-1!==e.indexOf(l.value),n=t.filteredItems?t.filteredItems.indexOf(l):i;if(l._group&&-1!==n&&s.push(n),l._checked===r)continue;if(l._checked=r,-1===n)continue;let o=t.virtualListHelper.getItemElementAt(n);o&&u(o,`${t.baseClassName}__item_checked`,l._checked)}if(t.autoCheckGroupChildren)for(let i=0,l=s.length;i<l;i++)this._updateGroupCheckedState(s[i],!1);return this}getCheckedValues(e){const t=this._p;e=e&&t.groupCount>0;let s=[];for(let i=0,l=t.items.length;i<l;i++){let l=t.items[i];l._checked&&(e&&l._group||s.push(l.value))}return s}getCheckedItems(e){const t=this._p;e=e&&t.groupCount>0;const s=[];for(let i=0,l=t.items.length;i<l;i++){let l=t.items[i];l._checked&&(e&&l._group||s.push(l[D]))}return s}show(e){const t=this._p;t.hiding=!1,this.isVisible()||this._trigger("show:before"),t.mouseHandled=!1,setTimeout(()=>{this[$]||t.onDocumentMouseDown||t.sink.add(document,"mousedown",t.onDocumentMouseDown=e=>{this.elContains(e.target,!0)||this._delayBlurItemOnBlur()})}),this.rushRefilter();const s=t.el;if(s.style.position="absolute",s.classList.remove(`${t.baseClassName}__is-hiding`),document.body.appendChild(s),t.visible=!0,t.el.style.display="","none"===getComputedStyle(t.el).display&&(t.el.style.display="block"),t.lastPositionOptions=null,void 0===e?e=t.positionOptionsProvider?.()??t.lastPositionOptions:t.lastPositionOptions=e,e){const t=getComputedStyle(s),i=s.style.maxHeight;let l=document.body.clientHeight-(parseFloat(t.marginTop)||0)-(parseFloat(t.marginBottom)||0)-("border-box"===t.boxSizing?0:(parseFloat(t.borderTopWidth)||0)+(parseFloat(t.borderBottomWidth)||0));s.style.maxHeight=Math.min(l,parseFloat(t.maxHeight)||l)+"px",this.relayout(e),s.style.maxHeight=i}else t.virtualListHelper.isVirtual()&&t.virtualListHelper.render();return this.isVisible()&&this._trigger("show"),this}hide(){const e=this._p,t=e.el;if(e.onDocumentMouseDown&&(e.sink.remove(document,"mousedown",e.onDocumentMouseDown),e.onDocumentMouseDown=null),this.isVisible()){if(this._trigger("hide:before"),e.hiding=!0,this.isFilterPending()&&(e.throttledRefilterItems.cancel(),e.needsRefilter=!0),t&&(t.classList.add(`${e.baseClassName}__is-hiding`),g(getComputedStyle(e.el).transition).reduce((e,t)=>Math.max(e,t.delay+t.duration),0)>0?setTimeout(()=>{this[$]||this._p&&t.parentNode&&e.hiding&&(a(t),t.classList.remove(`${e.baseClassName}__is-hiding`),e.visible=!1,this._trigger("hide:after"))}):(t.parentNode&&a(t),t.classList.remove(`${e.baseClassName}__is-hiding`))),e.visible=!1,this.blurFocusedItem(),this._trigger("hide"),this[$])return;this._trigger("hide:after"),e.currentSubDropList&&this._hideSublist()}return e.lastPositionTarget&&(e.lastPositionTarget.classList.remove(`has_${e.baseClassName}`,`has_${e.baseClassName}_above`,`has_${e.baseClassName}_below`),delete e.lastPositionTarget),this}isVisible(){const e=this._p;return!!e.visible&&e.el.parentNode&&"none"!==getComputedStyle(e.el).display}setHeaderVisible(e){this.isHeaderVisible()!==!!e&&(e?this._p.el.insertBefore(this._p.headerEl,this._p.el.firstChild??null):this._p.headerEl.remove())}isHeaderVisible(){return!!this._p.headerEl.parentNode}getHeaderElement(){return this._p.headerEl}setFooterVisible(e){this.isFooterVisible()!==!!e&&(e?this._p.el.appendChild(this._p.footerEl):this._p.footerEl.remove())}isFooterVisible(){return!!this._p.footerEl.parentNode}getFooterElement(){return this._p.footerEl}setSearchable(e){const s=this._p;!!s.searchInput!=!!e&&(e?(s.searchInput=t("input",{type:"search",role:"searchbox",tabindex:"0",autocorrect:"off",autocomplete:"off",autocapitalize:"off",spellcheck:"false","aria-autocomplete":"list"}),s.headerEl.appendChild(s.searchInput)):(s.searchInput.parentNode&&s.searchInput.remove(),s.searchInput=null),this.setHeaderVisible(e))}hasFocusedItem(){return this._p.focusItemIndex>-1&&this._p.focusItemIndex<this._p.items.length}getFocusedItemIndex(){return this.hasFocusedItem()?this._p.focusItemIndex:-1}setFocusedItemAtIndex(e){const t=this._p;if(this.rushRefilter(),t.filteredItems){const s=t.filteredItems[e];e=t.items.indexOf(s)}t.focusItemIndex=e;const s=t.filteredItems??t.items;let i=null;e>-1&&(i=s[e]),i&&i._nointeraction&&(i=null),e>-1&&this._scrollItemIndexIntoView(e);let l=i?t.virtualListHelper.getItemElementAt(e):null;if(t.focusItemEl!==l&&(t.focusItemEl&&(t.focusItemEl.classList.remove(`${t.baseClassName}__item_focus`),t.focusItemEl=null),l)){l.classList.add(`${t.baseClassName}__item_focus`),t.focusItemEl=l;const e=l[D];this._trigger("itemfocus",{value:e.value,item:e[D]??e,event:null,el:l}),this._showSublist(e,l)}return this}_showSublist(e,t){if(!e._subitems?.length)return;const i=this._p;if(i.currentSubDropList?.item===e)return;const l=new s({baseClassName:i.baseClassName,additionalClasses:i.additionalClasses,direction:i.direction,autoItemBlur:i.autoItemBlur,autoItemBlurDelay:i.autoItemBlurDelay,capturesFocus:i.capturesFocus,multi:i.multi,keyDownHandler:i.keyDownHandler,autoCheckGroupChildren:i.autoCheckGroupChildren,useExactTargetWidth:i.useExactTargetWidth,constrainToWindow:i.constrainToWindow,autoFlipDirection:i.autoFlipDirection,estimatedItemHeight:i.estimatedItemHeight,estimateWidth:i.estimateWidth,virtualMinItems:i.virtualMinItems,singleSelectedValue:i.singleSelectedValue,labelProp:i.labelProp,valueProp:i.valueProp,renderItem:i.renderItem,unrenderItem:i.unrenderItem,positionOptionsProvider:()=>i.currentSubDropList.showOptions});let r=e=>{this[$]||e.relatedTarget&&this.elContains(e.relatedTarget,!0)||(this._delayBlurItemOnBlur(),this._trigger("subitems:blur",e))};l.on("select",e=>{this._trigger("subitems:select",e)}).on("subitems:select",e=>{this._trigger("subitems:select",e)}).on("show_subitems",e=>{this._trigger("show_subitems",e)}).on("hide_subitems",e=>{this._trigger("hide_subitems",e)}).on("blur",r).on("subitems:blur",r).on("_back_key_pressed",()=>{this._hideSublist()}),l.setItems(e._subitems),this._trigger("show_subitems",{value:e.value,item:e[D]??e,el:t,droplist:l}),i.currentSubDropList={item:e,itemElement:t,droplist:l,showOptions:{target:t,position:{x:"start",y:"top"},anchor:{x:"end",y:"top"},offset:{x:0,y:0},updateWidth:!1}},l.show(),l.el.focus()}_hideSublist(){const e=this._p;if(!e.currentSubDropList)return;const t=e.currentSubDropList;let s=!!document.activeElement&&t.droplist.elContains(document.activeElement,!0);t.droplist.hide(),t.droplist.destroy(),e.currentSubDropList=null,s&&!this[$]&&this.el.focus(),this._trigger("hide_subitems",{value:t.item.value,item:t.item,el:t.itemElement,droplist:t.droplist})}updateSublist(){const e=this._p;if(!e.currentSubDropList)return;const t=e.currentSubDropList.item,s=e.currentSubDropList,i=e.items.find(e=>e===t)||e.items.find(e=>e.value===s.item.value);if(i){e.currentSubDropList.item=i;const t=e.virtualListHelper.getItemElementAt(this._getItemIndex(i));e.currentSubDropList.itemElement=t,i._subitems&&(e.currentSubDropList.droplist.setItems(i._subitems),t&&(e.currentSubDropList.showOptions.target=t,e.currentSubDropList.droplist.relayout()))}}setFocusedItem(e){const t=this._p;let s=e._nointeraction?-1:this._getItemIndex(e);const i=t.items;return s>-1&&i[s]._nointeraction&&(s=-1),this.setFocusedItemAtIndex(s)}setFocusedItemByValue(e){return this.setFocusedItemAtIndex(this.itemIndexByValue(e))}setSingleSelectedItemAtIndex(e,t){const s=this._p;this.rushRefilter();let i,l=null;return e>-1&&!s.items[e]._nointeraction&&(i=s.items[e],t=i.value,s.filteredItems&&(e=s.filteredItems.indexOf(i)),e>-1&&(l=s.virtualListHelper.getItemElementAt(e))),this._setSingleSelectedItemEl(l,t),this}setSingleSelectedItem(e){const t=this._p;let s=e._nointeraction?-1:this._getItemIndex(e);const i=t.items;return s>-1&&i[s]._nointeraction&&(s=-1),this.setSingleSelectedItemAtIndex(s)}setSingleSelectedItemByValue(e){return this.setSingleSelectedItemAtIndex(this.itemIndexByValue(e),e)}next(e){this._move("next",e)}previous(e){this._move("prev",e)}isFirstItem(){const e=this._p,t=e.filteredItems??e.items;return 0===e.focusItemIndex&&e.focusItemIndex<t.length}isLastItem(){const e=this._p,t=e.filteredItems??e.items;return e.focusItemIndex>-1&&e.focusItemIndex===t.length-1}scrollItemIndexIntoView(e){const t=this._p;if(this._hasScroll()){if(t.filteredItems){const s=t.items[e];e=t.items.indexOf(s)}-1!==e&&this._scrollItemIndexIntoView(e)}return this}_scrollItemIndexIntoView(e){const t=this._p;if(this._hasScroll()){const s=t.menuEl,i=s.scrollTop;let l,r=-1,n=30;for(;n-- >0&&(l=t.virtualListHelper.getItemPosition(e),l!==r);){r=l;let n=t.virtualListHelper.getItemSize(e),o=s.clientHeight;l<i?s.scrollTop=l:l+n>i+o&&(s.scrollTop=l+n-o),t.virtualListHelper.render()}}}on(e,t){return this._p.mitt.on(e,t),this}once(e,t){let s=i=>{this._p.mitt.off(e,s),t(i)};return this._p.mitt.on(e,s),this}off(e,t){return e||e?this._p.mitt.off(e,t):this._p.mitt.all.clear(),this}emit(e,t){return this._p.mitt.emit(e,t),this}_getItemIndex(e){const t=this._p;let s=-1;if(e&&(s=(t.filteredItems??t.items).indexOf(e),-1===s)){let t=e&&void 0!==e.value?e.value:e,i=e&&e.label?e.label:t;s=this.itemIndexByValueOrLabel(t,i)}return s}_setSingleSelectedItemEl(e,t){const s=this._p;return s.singleSelectedItemEl&&(s.singleSelectedItemEl.classList.remove(`${s.baseClassName}__item_selected`),s.singleSelectedItemEl=null),s.singleSelectedValue=t,e&&void 0!==t&&(e.classList.add(`${s.baseClassName}__item_selected`),s.singleSelectedItemEl=e),this}_trigger(e,t){const s=this._p;s.on&&s.on(e,...void 0===t?[]:[t]),s.mitt.emit(e,t)}_itemUpAction(t,s){if(e(t.target,".requires-pointer-events,button",s))return;let i=this._p;if(!this._mouseHandled){if(this.triggerItemSelection(null,t),this[$])return;document.activeElement!==this.el&&i.focusItemEl&&clearTimeout(i.blurTimer),setTimeout(()=>{this._mouseHandled=!1},0)}}_hookMouseEvents(){const t=this._p;t.sink.add(t.el,"mouseup",t=>{const s=e(t.target,"li",t.currentTarget);s&&0===t.button&&this._itemUpAction(t,s)}).add(t.el,"mouseover",t=>{const s=e(t.target,"li",t.currentTarget);s&&this._handleMouseOver(t,s)})}_handleMouseOver(e,t){this._focus(e,t,null,!0)}_hookTouchEvents(){const t=this._p;let s;t.sink.add(t.el,"touchstart",i=>{const l=e(i.target,"li",i.currentTarget);if(!l)return;if(s)return;if(e(i.target,".requires-pointer-events,button",l))return;s=i.changedTouches[0].identifier,this._handleMouseOver(i,l);let r=!1,n=()=>{r=!0},o=()=>{s=null,t.sink.remove(null,".dropdown_touchextra")},a=l.parentNode;for(;a;)t.sink.add(a,"scroll.dropdown_touchextra",n),a=a.parentNode;t.sink.add(window,"scroll.dropdown_touchextra",n),t.sink.add(window,"touchcancel.dropdown_touchextra",o),t.sink.add(t.el,"touchend.dropdown_touchextra",t=>{const i=e(t.target,"li",t.currentTarget);return i&&Array.prototype.find.call(t.changedTouches,e=>e.identifier===s)?(o(),void(r||(this._itemUpAction(t,i),t.preventDefault()))):o()})})}_hookFocusEvents(){const e=this._p;e.sink.add(e.el,"focus",t=>{if(t.target===this.el&&e.searchable&&e.searchInput.focus(),t.relatedTarget&&this.elContains(t.relatedTarget,!0)&&this.elContains(t.target,!0))return;let s=e.focusItemEl||e.el.firstChild;this._focus(t,s,null,!1)},!0).add(e.el,"blur",e=>{e.relatedTarget&&this.elContains(e.relatedTarget,!0)&&this.elContains(e.target,!0)||setTimeout(()=>{this[$]||document.activeElement&&this.elContains(document.activeElement,!0)||(this._delayBlurItemOnBlur(),this._trigger("blur",e))})},!0)}_hookKeyEvents(){const e=this._p;e.sink.add(e.el,"keydown",e=>this._keydown(e))}_hookSearchEvents(){const e=this._p;e.searchInput&&e.sink.add(e.searchInput,"input",()=>{e.filterTerm=e.searchInput.value.trim(),e.filteredItems=null,this._trigger("search",{value:e.searchInput.value}),e.throttledRefilterItems()})}_keydown(e){const t=this._p;if(t.keyDownHandler&&t.keyDownHandler.call(this,e))return;let s=!0;switch(e.key){case N:case F:case w:case k:case M:case L:switch(t.lastKeyWasChar=!1,e.preventDefault(),e.key){case N:this.previousPage(e);break;case F:this.nextPage(e);break;case w:this._move("first",e);break;case k:this._move("last",e);break;case M:this.previous(e);break;case L:this.next(e)}break;case T:case P:if(t.lastKeyWasChar=!1,e.key===P&&"rtl"!==getComputedStyle(e.target).direction||e.key===T&&"rtl"===getComputedStyle(e.target).direction){let e=(t.filteredItems??t.items)[t.focusItemIndex];t.focusItemIndex>-1&&e._subitems&&this._showSublist(e,t.focusItemEl)}else t.currentSubDropList?(this._hideSublist(),s=!1):this._trigger("_back_key_pressed");break;case x:t.lastKeyWasChar=!1,this.triggerItemSelection(null,e),e.preventDefault();break;case V:if("BUTTON"===e.target.tagName||"INPUT"===e.target.tagName&&t.lastKeyWasChar)return;this.toggleFocusedItem(),e.preventDefault();break;case E:t.lastKeyWasChar=!1,e.preventDefault(),this.hide();break;default:if("INPUT"===e.target.tagName||"TEXTAREA"===e.target.tagName){const s=e.key||String.fromCharCode(e.keyCode);t.lastKeyWasChar=1===s.length||e.key===S}t.searchable||this._keydownFreeType(e,!this.isVisible()),s=!1}}_keydownFreeType(e,t){const s=this._p,i=e.key||String.fromCharCode(e.keyCode),l=1===i.length;if(s.lastKeyWasChar=l||e.key===S,!l)return;clearTimeout(s.filterTimer);let r,n=(s.previousFilter||"")+i,o=new RegExp(`^${B(n)}`,"i"),a=-1,u=s.focusItemIndex;const c=s.filteredItems??s.items;for(let d=0,h=c.length;d<h&&(-1!==a&&d<u||(r=c[d],!(o.test(r.label)&&(a=d,-1===u||d>=u))));d++);if(-1===a){n=i,o=new RegExp(`^${B(n)}`,"i");for(let e=0,t=c.length;e<t&&(-1!==a&&e<u||(r=c[e],!(o.test(r.label)&&(a=e,-1===u||e>=u))));e++);}if(a>-1){let i=s.virtualListHelper.getItemElementAt(a);this._focus(e,i||null,a,!0),t&&this.triggerItemSelection(i?null:c[a],e),s.previousFilter=n,s.filterTimer=setTimeout(()=>{delete s.previousFilter},1e3)}else delete s.previousFilter}_focus(e,t,s,i){const l=this._p;if(l._isFocusingItem)return;l._isFocusingItem=!0,!s&&t&&(s=l.virtualListHelper.getItemIndexFromElement(t)),s>-1&&t?.[D]?.[D]===H&&(s=void 0),s>-1?this.scrollItemIndexIntoView(s):void 0===s&&(t=null);let r=t||l.virtualListHelper.getItemElementAt(s);if(!r||r[D]._nointeraction)return l._isFocusingItem=!1,void this.blurFocusedItem();if(r===l.focusItemEl)return l._isFocusingItem=!1,void clearTimeout(l.blurTimer);this.blurFocusedItem(),r.classList.add(`${l.baseClassName}__item_focus`),l.focusItemEl=r,l.focusItemIndex=s;const n=(l.filteredItems??l.items)[s];this._trigger("itemfocus",{value:n.value,item:n[D]??n,event:e,el:r}),l._isFocusingItem=!1,i&&this._showSublist(n,r)}_delayBlurItemOnBlur(){if(this[$])return;const e=this._p;e.autoItemBlur&&(clearTimeout(e.blurTimer),e.blurTimer=setTimeout(()=>{this[$]||this.blurFocusedItem()},e.autoItemBlurDelay))}_move(e,t){const s=this._p;let i,l,r;const n=s.filteredItems??s.items;if("first"===e)l=0,r=!1;else if("last"===e)l=n.length-1,r=!0;else if("prev"===e){if(!this.hasFocusedItem())return this._move("last",t);l=s.focusItemIndex-1,-1===l&&(l=n.length-1),r=!0}else if("next"===e){if(!this.hasFocusedItem())return this._move("first",t);l=s.focusItemIndex+1,l===n.length&&(l=0),r=!1}else{if("prev_page"!==e&&"next_page"!==e)return;if(!this.hasFocusedItem())return this._move("prev_page"===e?"prev":"next",t);if("prev_page"===e&&this.isFirstItem()||"next_page"===e&&this.isLastItem())return;if(!this._hasScroll())return this._move("prev_page"===e?"first":"last",t);if(s.virtualListHelper.isVirtual()){let t=s.virtualListHelper.getVisibleItemCount();l=s.focusItemIndex,"prev_page"===e?l-=t:l+=t,l<0?l=0:l>=n.length&&(l=n.length)}else if(s.focusItemEl){let t=m(s.focusItemEl).top,r=h(s.el,!0);for(;;){if(i=s.focusItemEl.nextElementSibling,!i)return;if("LI"===i.tagName)if("prev_page"===e){if(m(i).top-t+r<=0)break}else if(m(i).top-t-r>=0)break}i&&(l=s.virtualListHelper.getItemIndexFromElement(i),void 0===l&&(l=-1))}r="prev_page"===e}let o=n.length;if(l>=o)return;let a=n[l],u=l;for(;a&&a._nointeraction&&(r?(l--,-1===l&&(l=o)):(l++,l===o&&(l=0)),a=n[l],l!==u););i=s.virtualListHelper.getItemElementAt(l),this._focus(t,i||null,l,!1),this.isVisible()||this.triggerItemSelection(a,t)}_hasScroll(){const e=this._p.menuEl;return e.clientHeight<e.scrollHeight}_updateGroupStateForItem(e){const t=this._p;if(!t.multi)return this;if(e._group){let s=0;if(t.autoCheckGroupChildren){const i=t.filteredItems??t.items;let l=i.indexOf(e);const r=e._level;for(let n=l+1,o=i.length;n<o;n++){let l=i[n];if(!l._child&&i[n-1]._child||(void 0===r?l._group||void 0!==l._level:l._level<=r))break;if(!!l._checked===e._checked)continue;l._checked=e._checked,s++;let o=t.virtualListHelper.getItemElementAt(n);o&&u(o,`${t.baseClassName}__item_checked`,e._checked),this._trigger("check",{value:l.value,item:l[D]??l,checked:l._checked,isGroup:l._group,isCheckingGroup:!0})}}this._trigger("groupcheck",{value:e.value,item:e[D]??e,affectedCount:s})}else if(t.groupCount>0&&t.autoCheckGroupChildren){const s=t.filteredItems??t.items;let i=-1;for(let t=s.indexOf(e)-1;t>=0;t--)if(s[t]._group){i=t;break}i>-1&&this._updateGroupCheckedState(i,!0)}return this}_updateGroupCheckedState(e,t){const s=this._p;if(!(s.multi&&s.autoCheckGroupChildren&&e>-1))return this;const i=s.filteredItems??s.items;let l=i[e];if(!l||!l._group)return this;let r,n=!1,o=!1;const a=l._level;for(let u=e+1,d=i.length;u<d&&(r=i[u],!(!r._child&&i[u-1]._child||(void 0===a?r._group||void 0!==r._level:r._level<=a)));u++)r._checked?n=!0:r._checked||(o=!0);if(!n&&!o)return this;let c=n&&!o;if(!!l._checked!==c){l._checked=c;let i=s.virtualListHelper.getItemElementAt(e);i&&u(i,`${s.baseClassName}__item_checked`,l._checked),t&&this._trigger("check",{value:l.value,item:l[D]??l,checked:l._checked,isGroup:l._group,isCheckingGroup:!1})}return this}_measureItem(){const e=this._p;if(e.lastMeasureItemCount!==e.items.length){let t=e.lastMeasureLongestLabel||1,s=e.lastMeasureLongestLabelText||"";for(let i=0,l=e.items,r=l.length;i<r;i++){const e=l[i];let r=e.label;null==r&&(r=e.value),null==r&&(r="");let n=r.length;n>t&&(t=n,s=r)}e.lastMeasureItemCount=e.items.length,e.lastMeasureLongestLabel=t,e.lastMeasureLongestLabelText=s}return(e.estimateWidth||e.virtualListHelper.isVirtual())&&e.virtualListHelper.createGhostItemElement(A,!0,s=>{let i=t("span",{css:{display:"block",width:"100px",height:"100px",overflow:"scroll",position:"absolute"}}),l=t("span",{css:{display:"block",position:"relative",width:"0",height:"0",overflow:"hidden"}},[i]);s.appendChild(l);let r=i.offsetWidth-i.clientWidth;s.removeChild(l),e.lastMeasureItemWidth=p(s,!0,!0)+r}),this}_determineVirtualMode(e){const t=this._p,s=t.filteredItems??t.items;void 0===e&&(e=s.length);let i=e>=t.virtualMinItems;return i!==t.virtualListHelper.isVirtual()&&t.virtualListHelper.setVirtual(i).render(),this}_renderItemContent(e,s){const i=this._p,l=e[D];if(l===H)return!(!i.renderNoResultsItem||!1===i.renderNoResultsItem(e,s))||void s.appendChild(t("div",{class:"droplist-no-results-content",textContent:i.noResultsText}));i.renderItem&&!1!==i.renderItem(l||e,s)||(s.appendChild(t("span",{class:`${i.baseClassName}__item_label`,textContent:e.label})),i.multi&&(e._nocheck||s.insertBefore(t("span",{class:"checkbox"}),s.firstChild)))}_updateWidth(e){const t=this._p,s=t.el;let i=0;e&&(i="number"==typeof e.updateWidth||null!=e.targetWidth?e.updateWidth:p(e.target,!0,!0));let l=0;t.useExactTargetWidth&&i||(t.estimateWidth||t.virtualListHelper.isVirtual()?l=t.lastMeasureItemWidth:(s.style.width="",l=p(s,!0,!0)));let r=Math.max(l,i);b(s,r,!0,!0);const n=getComputedStyle(s);let o=(parseFloat(n.borderLeftWidth)||0)+(parseFloat(n.borderRightWidth)||0)+(parseFloat(n.paddingLeft)||0)+(parseFloat(n.paddingRight)||0),a=s.scrollWidth+o;if(a>r){let e=a-r;s.style.width=`${parseFloat(s.style.width)+e}px`,r=a}return r}},U=Symbol("destroyed"),j=Symbol("rest_multi_items"),q=!!("ontouchstart"in window||window.DocumentTouch&&window.document instanceof window.DocumentTouch||window.navigator.maxTouchPoints),Q=function(e,t){return e instanceof Element&&e.classList.contains(t)},X=["font-family","font-size","font-weight","font-size","letter-spacing","text-transform","word-spacing","text-indent","box-sizing","padding-left","padding-right"],Y={el:null,baseClassName:"selectbox",disabled:!1,readOnly:!1,clearable:!0,hasOpenIndicator:!0,placeholder:"",sortSelectedItems:!0,sortListItems:!1,sortListCheckedFirst:!0,stickyValues:null,sortItemComparator:null,splitListCheckedGroups:!0,treatGroupSelectionAsItems:!1,blurOnSingleSelection:"touch",multi:!1,showSelection:!0,showPlaceholderInTooltip:!1,multiPlaceholderFormatter:null,searchable:!0,noResultsText:"No matching results",autoSelectTextOnCheck:!0,filterThrottleWindow:300,filterOnEmptyTerm:!1,labelProp:"label",valueProp:"value",multiItemLabelProp:"short_label",multiItemRemovePosition:"after",maxMultiItems:null,multiItemsRestLabelProvider:null,items:[],selectedValues:void 0,value:void 0,isLoadingMode:!1,closeListWhenLoading:!0,clearInputWhen:["single_close","multi_select_single"]},J=class{constructor(e){const s={...Y};for(let[t,l]of Object.entries(e))void 0!==l&&(s[t]=l);const i=this._p={ownsEl:!0,baseClassName:s.baseClassName,additionalClasses:s.additionalClasses,direction:"ltr"===s.direction?"ltr":"rtl"===s.direction?"rtl":"auto",listOptions:s.listOptions,disabled:!!s.disabled,readOnly:!!s.readOnly,clearable:!!s.clearable,hasOpenIndicator:!!s.hasOpenIndicator,placeholder:s.placeholder,sortSelectedItems:!!s.sortSelectedItems,sortListItems:!!s.sortListItems,sortListCheckedFirst:!!s.sortListCheckedFirst,stickyValues:Array.isArray(s.stickyValues)?new Set(s.stickyValues):null,sortItemComparator:s.sortItemComparator,splitListCheckedGroups:!!s.splitListCheckedGroups,treatGroupSelectionAsItems:s.treatGroupSelectionAsItems,blurOnSingleSelection:s.blurOnSingleSelection,multi:s.multi,showSelection:s.showSelection,showPlaceholderInTooltip:s.showPlaceholderInTooltip,multiPlaceholderFormatter:s.multiPlaceholderFormatter,searchable:s.searchable,allowTypeToSelect:s.allowTypeToSelect,noResultsText:s.noResultsText,autoSelectTextOnCheck:s.autoSelectTextOnCheck,labelProp:s.labelProp,valueProp:s.valueProp,multiItemLabelProp:s.multiItemLabelProp,multiItemRemovePosition:s.multiItemRemovePosition,maxMultiItems:s.maxMultiItems,multiItemsRestLabelProvider:s.multiItemsRestLabelProvider,renderSingleItem:s.renderSingleItem,unrenderSingleItem:s.unrenderSingleItem,renderMultiItem:s.renderMultiItem,unrenderMultiItem:s.unrenderMultiItem,renderRestMultiItem:s.renderRestMultiItem,unrenderRestMultiItem:s.unrenderRestMultiItem,on:s.on||null,silenceEvents:!0,mitt:W(),isLoadingMode:!!s.isLoadingMode,closeListWhenLoading:!!s.closeListWhenLoading,clearInputWhen:Array.isArray(s.clearInputWhen)?s.clearInputWhen.slice(0):[],items:[],itemsChanged:!0,sink:new v,resizeObserver:null,selectedItems:[],selectedValues:[],selectionChanged:!0,resortBySelectionNeeded:!1,filterThrottleWindow:s.filterThrottleWindow,filterOnEmptyTerm:s.filterOnEmptyTerm,filterFn:null,filterTerm:""};let r=s.el;r instanceof Element?i.ownsEl=!1:r=t("span"),l(r,{role:"combobox","aria-haspopup":"true","aria-expanded":"false"}),i.el=r,this._syncBaseClasses(),this._renderBase(),i.multiItemEls=[],this.enable(!i.disabled),this.setReadOnly(i.readOnly),this._setupDropdownMenu(),i.sink.add(r,"click",e=>{i.clearButtonWrapper&&i.clearButtonWrapper.contains(e.target)||r.contains(document.activeElement)||(i.input.focus(),i.input.selectionStart=i.input.selectionEnd=i.input.value.length)}),i.sink.add(r,"focus",e=>{const t=e.target;if(!r.contains(e.relatedTarget)&&!Q(t,`${i.baseClassName}__search_field`)&&!Q(t,`${i.baseClassName}__item`)){let e=r.querySelector(`.${i.baseClassName}__search_field`);e&&e.focus()}},!0),i.sink.add(i.input,"keydown",e=>{this._handleInputKeydown(e)}).add(i.input,"input",()=>{this._resizeInput()});const n=(()=>{let e;return()=>{e&&clearTimeout(e),e=setTimeout(()=>{u(r,`${i.baseClassName}__focus`,r.contains(document.activeElement))})}})();if(i.sink.add(r,"focus",n,!0),i.sink.add(r,"blur",n,!0),i.sink.add(window,"resize",()=>this._resizeInput()),i.sink.add(window,"orientationchange",()=>this._resizeInput()),void 0!==window.ResizeObserver){let e={borderBoxSize:{blockSize:null,inlineSize:null},contentBoxSize:{blockSize:null,inlineSize:null}};i.resizeObserver=new ResizeObserver(t=>{if(this[U])return;const s=t[0];e&&s.borderBoxSize[0].blockSize===e.borderBoxSize.blockSize&&s.borderBoxSize[0].inlineSize===e.borderBoxSize.inlineSize&&s.contentBoxSize[0].blockSize===e.contentBoxSize.blockSize&&s.contentBoxSize[0].inlineSize===e.contentBoxSize.inlineSize||(i.resizeObserver.unobserve(i.el),this._resizeInput(),requestAnimationFrame(()=>i.resizeObserver.observe(i.el))),e.borderBoxSize=s.borderBoxSize[0],e.contentBoxSize=s.contentBoxSize[0]}),i.resizeObserver.observe(i.el)}return this.setFilterFn(s.filterFn),this.setItems(s.items),delete s.items,s.multi&&Array.isArray(s.selectedValues)?this.setSelectedValues(s.selectedValues):null!=s.value&&this.setValue(s.value),this._scheduleSync("full"),this.silenceEvents=!1,this}destroy(){if(this[U])return;this[U]=!0;const e=this._p;if(e.syncTimeout&&(clearTimeout(e.syncTimeout),delete e.syncTimeout),this._stopTrackingPresence(),e.sink.remove(),e.dropList&&e.dropList.destroy(),this._cleanupSingleWrapper(),e.unrenderMultiItem||e.unrenderRestMultiItem)for(;e.multiItemEls.length>0;)this._removeMultiItemElementByIndex(e.multiItemEls.length-1);if(a(e.list),a(e.singleWrapper),a(e.input),a(e.inputBackBuffer),a(e.clearButtonWrapper),a(e.openIndicator),!e.ownsEl){for(let t of Array.from(e.el.classList))t.startsWith(e.baseClassName)&&e.el.classList.remove(t);e.el.removeAttribute("role"),e.el.removeAttribute("aria-haspopup"),e.el.removeAttribute("aria-expanded")}e.resizeObserver?.disconnect(),this._p=null}get el(){return this._p?.el??null}get droplistInstance(){return this._p.dropList}droplistElContains(e,t=!0){return this._p.dropList?.elContains(e,t)}enable(e){const t=this._p;void 0===e&&(e=!0),t.disabled=!e,t.el.setAttribute("aria-disabled",t.disabled.toString()),t.input.disabled=!!t.disabled;const s=t.multiItemEls;for(let i of s)t.disabled?i.removeAttribute("tabindex"):i.setAttribute("tabindex","0");return this}isEnabled(){return!this._p.disabled}disable(e){return this.enable(void 0!==e&&!e)}isDisabled(){return this._p.disabled}setReadOnly(e){const t=this._p;return void 0===e&&(e=!0),t.readOnly=e,t.el.setAttribute("aria-readOnly",t.readOnly.toString()),t.input.readOnly=!(t.searchable||t.multi)||!!t.readOnly,this}isReadOnly(){return this._p.readOnly}setAdditionalClasses(e){return this._p.additionalClasses=e,this._syncBaseClasses(),this}setItems(e,t=!0){const s=this._p;return e||(e=[]),s.items=e.slice(0),s.itemsChanged=!0,this._refreshItemByValueMap(),t&&this.setSelectedValues(this.getSelectedValues()),this._trigger("itemschanged",{term:null,mutated:!0,count:this.getFilteredItemCount()}),this}getFilteredItemCount(){const e=this._p;return e.dropList?e.dropList.getFilteredItemCount():e.items?e.items.length:0}isFilterPending(){const e=this._p;return!0===e.dropList?.isFilterPending()}updateItemByValue(e,t){const s=this._p;let i=this._getItemByValue(e);if(i){const e=i[s.valueProp];s.itemByValueMap?.has(e)&&s.itemByValueMap.delete(e),Object.assign(i,t),s.itemByValueMap.set(i[s.valueProp],i)}s.dropList&&s.dropList.updateItemByValue(e,t)}getItems(){return this._p.items}setClearable(e){return e=!!e,this._p.clearable===e||(this._p.clearable=!!e,this._scheduleSync("render_clear")),this}getClearable(){return this._p.clearable}setHasOpenIndicator(e){return e=!!e,this._p.hasOpenIndicator===e||(this._p.hasOpenIndicator=e,this._scheduleSync("render_base")),this}getHasOpenIndicator(){return this._p.hasOpenIndicator}setPlaceholder(e){return this._p.placeholder=null==e?"":String(e),this._scheduleSync("render_base"),this}getPlaceHolder(){return this._p.placeholder}setSearchTerm(e,t=!1){const s=this._p;return s.input?(s.input.value=e,this._scheduleSync("resize_input"),t&&(s.filterTerm=s.input.value.trim(),this._trigger("search:term",s.filterTerm),s.dropList?.setSearchTerm(s.filterTerm,t)),this):this}getSearchTerm(){const e=this._p;return e.input?e.input.value:""}invokeRefilter(){const e=this._p;return e.dropList?.invokeRefilter(),this}setSortSelectedItems(e){const t=this._p;return e=!!e,t.sortSelectedItems===e||(t.sortSelectedItems=e,this._scheduleSync("render_items")),this}isSortSelectedItemsEnabled(){return this._p.sortSelectedItems}setSortListItems(e){const t=this._p;return e=!!e,t.sortListItems===e||(t.sortListItems=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}isSortListItemsEnabled(){return this._p.sortListItems}setSortListCheckedFirst(e){const t=this._p;return e=!!e,t.sortListCheckedFirst===e||(t.sortListCheckedFirst=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}isSortListCheckedFirstEnabled(){return this._p.sortListCheckedFirst}setStickyValues(e){const t=this._p;return t.stickyValues=Array.isArray(e)?new Set(e):null,t.itemsChanged=!0,this._scheduleSync("render_list"),this}getStickyValues(){return this._p.stickyValues?Array.from(this._p.stickyValues):null}setSortItemComparator(e){const t=this._p;return t.sortItemComparator===e||(t.sortItemComparator=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}getSortItemComparator(){return this._p.sortItemComparator}setTreatGroupSelectionAsItems(e){const t=this._p;return e=!!e,t.treatGroupSelectionAsItems===e||(t.treatGroupSelectionAsItems=e,t.dropList?.setFilterGroups(e),t.dropList?.setFilterEmptyGroups(!e),t.itemsChanged=!0,this._scheduleSync("render_list")),this}isTreatGroupSelectionAsItemsEnabled(){return!this._p.treatGroupSelectionAsItems}setSplitListCheckedGroups(e){const t=this._p;return e=!!e,t.splitListCheckedGroups===e||(t.splitListCheckedGroups=e,t.itemsChanged=!0,this._scheduleSync("render_list")),this}isSplitListCheckedGroupsEnabled(){return this._p.splitListCheckedGroups}setShowSelection(e){const t=this._p;return e=!!e,t.showSelection===e||(t.showSelection=e,this._scheduleSync("render_items")),this}isShowSelectionEnabled(){return this._p.showSelection}setShowPlaceholderInTooltip(e){const t=this._p;return e=!!e,t.showPlaceholderInTooltip===e||(t.showPlaceholderInTooltip=e,this._scheduleSync("render_base")),this}isShowPlaceholderInTooltipEnabled(){return this._p.showPlaceholderInTooltip}setMultiPlaceholderFormatter(e){const t=this._p;return t.multiPlaceholderFormatter===e||(t.multiPlaceholderFormatter=e,this._scheduleSync("render_base")),this}setBlurOnSingleSelection(e){const t=this._p;return t.blurOnSingleSelection===e||(t.blurOnSingleSelection=e),this}getBlurOnSingleSelection(){return this._p.blurOnSingleSelection}setMulti(e){const t=this._p;return e=!!e,t.multi===e||(t.multi=e,this._setupDropdownMenu(),a(t.clearButtonWrapper),delete t.clearButtonWrapper,e&&t.selectedValues&&1===t.selectedValues.length&&Array.isArray(t.selectedValues[0])&&this.setSelectedValues(t.selectedValues[0]),this._scheduleSync("full")),this}isMultiEnabled(){return this._p.multi}setSearchable(e){const t=this._p;return e=!!e,t.searchable===e||(t.searchable=e,this._scheduleSync("full")),this}setAllowTypeToSelect(e){const t=this._p;return e=!!e,t.allowTypeToSelect===e||(t.allowTypeToSelect=e),this}isSearchableEnabled(){return this._p.searchable}setNoResultsText(e){return this._p.dropList?.setNoResultsText(e),this}getNoResultsText(){return this._p.noResultsText}setAutoSelectTextOnCheck(e){return this._p.autoSelectTextOnCheck=e,this}getAutoSelectTextOnCheck(){return this._p.autoSelectTextOnCheck}setFilterThrottleWindow(e){const t=this._p;return t.filterThrottleWindow=e,t.dropList?.setFilterThrottleWindow(e),this}getFilterThrottleWindow(){return this._p.filterThrottleWindow}setFilterOnEmptyTerm(e){const t=this._p;return t.filterOnEmptyTerm===e||t.dropList?.setFilterOnEmptyTerm(e),this}getFilterOnEmptyTerm(){return this._p.filterOnEmptyTerm}setListOptions(e){return this._p.listOptions=e,this._setupDropdownMenu(),this}setRenderSingleItem(e,t){const s=this._p;return s.renderSingleItem=e,s.unrenderSingleItem=t,this}setRenderMultiItem(e,t){const s=this._p;return s.renderMultiItem=e,s.unrenderMultiItem=t,this}setRenderRestMultiItem(e,t){const s=this._p;return s.renderRestMultiItem=e,s.unrenderRestMultiItem=t,this}setLabelProp(e){const t=this._p;return t.labelProp=e,t.dropList&&t.dropList.setLabelProp(e),this}setValueProp(e){const t=this._p;return t.valueProp===e||(t.valueProp=e,t.dropList&&t.dropList.setValueProp(e),this._refreshItemByValueMap()),this}setMultiItemLabelProp(e){return this._p.multiItemLabelProp=e,this._scheduleSync("render_items"),this}setMultiItemRemovePosition(e){return this._p.multiItemRemovePosition=e,this._scheduleSync("render_items"),this}setMaxMultiItems(e){return this._p.maxMultiItems=e,this}setMultiItemsRestLabelProvider(e){return this._p.multiItemsRestLabelProvider=e,this}setFilterFn(e){const t=this._p;return t.filterFn===e||(t.filterFn=e,e||(e=(e,s)=>{const i=new RegExp(B(s),"i"),l=t.labelProp,r=t.multiItemLabelProp;return t.items.filter(e=>!(t.treatGroupSelectionAsItems||!e._group)||i.test(e[l]||e[r]))}),t.actualFilterFn=e,t.dropList?.setFilterFn(e)),this}getFilterFn(){return this._p.filterFn}focusInput(){const e=this._p;return e.input&&e.input.focus(),this}blurInput(){const e=this._p;return e.input&&e.input.blur(),this}clear(){return this._performClearWithEvent(!0)?(this[U],this):this}getValue(){const e=this._p;return e.multi?e.selectedValues.slice(0):e.selectedValues.length>0?e.selectedValues[0]:void 0}setValue(e){return this._p.multi?this.setSelectedValues(Array.isArray(e)?e:void 0!==e?[e]:[]):this.setSelectedValues(void 0!==e?[e]:[])}getSelectedValues(){return this._p.selectedValues.slice(0)}setSelectedValues(e){const t=this._p,s=t.valueProp;t.multi||(e=e.slice(0,1));let i=new Set,l=[],r=[];for(let n of e){if(i.has(n))continue;i.add(n),l.push(n);let e=this._getItemByValue(n);void 0!==e?r.push(e):r.push({[s]:n})}return t.selectedValues=l,t.selectedItems=r,t.selectionChanged=!0,t.resortBySelectionNeeded=!0,this._scheduleSync("full"),this}getSelectedValueCount(){return this._p.selectedValues.length}getSelectedItems(){return this._p.selectedItems.slice(0)}setSelectedItems(e){return this._setSelectedItems(e),this}openList(){const e=this._p;return e.dropList.isVisible()||e.isLoadingMode&&0===e.items.length||(this._trigger("open:before",{list:e.dropList}),document.activeElement!==e.input&&(e.lastActiveElement=document.activeElement===document.body?null:function(e){if(!e)return null;const t={element:e};return"number"==typeof e.selectionStart&&"number"==typeof e.selectionEnd&&(t.selectionStart=e.selectionStart,t.selectionEnd=e.selectionEnd,t.selectionDirection=e.selectionDirection),t}(document.activeElement)),e.dropList.setDirection(getComputedStyle(e.el).direction),e.dropList.show(),this._repositionDropList(),this._repositionDropList(),e.dropList.hasFocusedItem()?e.dropList.setFocusedItemAtIndex(e.dropList.getFocusedItemIndex()):e.multi||void 0===this.getValue()||e.dropList.setFocusedItemByValue(this.getValue())),this}closeList(){const e=this._p;return this[U]?this:e.dropList.isVisible()?(e.dropList.hide(),e.lastActiveElement&&(e.multi||e.searchable||(t=e.lastActiveElement,t?.element&&document.body.contains(t.element)&&(t.element.focus(),"number"==typeof t.selectionStart&&"number"==typeof t.selectionEnd&&"function"==typeof t.element.setSelectionRange&&t.element.setSelectionRange(t.selectionStart,t.selectionEnd,t.selectionDirection??"none"))),e.lastActiveElement=null),this):this;var t}toggleList(e){const t=this._p;return(void 0===e?!t.dropList.isVisible():e)?this.openList():this.closeList()}isListOpen(){return!!this._p.dropListVisible}toggleLoading(e){return this.setIsLoadingMode(void 0===e?!this.getIsLoadingMode():!!e)}setIsLoadingMode(e){const t=this._p;return e=void 0===e||!!e,t.isLoadingMode===e||(t.isLoadingMode=e,t.isLoadingMode&&t.closeListWhenLoading&&0===t.items.length&&this.isListOpen()?this.closeList():!t.isLoadingMode&&t.closeListWhenLoading&&document.activeElement&&((t.multi||t.searchable)&&t.input.contains(document.activeElement)||!t.multi&&!t.searchable&&t.el.contains(document.activeElement))&&this.openList(),this._scheduleSync("render_base")),this}getIsLoadingMode(){return this._p.isLoadingMode}setCloseListWhenLoading(e){return this._p.closeListWhenLoading=e,this}getCloseListWhenLoading(){return this._p.closeListWhenLoading}setClearInputWhen(e){return this._p.clearInputWhen=Array.isArray(e)?e.slice(0):[],this}getClearInputWhen(){return this._p.clearInputWhen}setDirection(e){return this._p.direction="ltr"===e?"ltr":"rtl"===e?"rtl":"auto",this._syncBaseClasses(),this}getDirection(){return this._p.direction}refreshSize(){return this._resizeInput(),this}on(e,t){return this._p.mitt.on(e,t),this}once(e,t){let s=i=>{this._p.mitt.off(e,s),t(i)};return this._p.mitt.on(e,s),this}off(e,t){return e||e?this._p.mitt.off(e,t):this._p.mitt.all.clear(),this}emit(e,t){return this._p.mitt.emit(e,t),this}_refreshItemByValueMap(){const e=this._p,t=e.itemByValueMap=new Map,s=e.valueProp;for(let i of e.items)t.set(i[s],i);e.subitemByValueMap=null}_getItemByValue(e){const t=this._p;let s=t.itemByValueMap.get(e);return void 0!==s?s:(t.subitemByValueMap||this._refreshSubitemByValueMap(),t.subitemByValueMap.get(e))}_refreshSubitemByValueMap(){const e=this._p,t=e.subitemByValueMap=new Map;this._addSubitemsToValueMap(e.items,t,e.valueProp)}_addSubitemsToValueMap(e,t,s){for(let i of e)if(i._subitems?.length){for(let e of i._subitems)t.has(e[s])||t.set(e[s],e);this._addSubitemsToValueMap(i._subitems,t,s)}}_renderBase(){const s=this._p;if(s.inputBackBuffer||(s.inputBackBuffer=t("span",{css:{position:"absolute",zIndex:-1,left:0,top:"-9999px",whiteSpace:"pre"}})),s.input||(s.inputWrapper=t("span",{class:`${s.baseClassName}__search_wrapper`},s.input=t("input",{class:`${s.baseClassName}__search_field`,type:"search",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox","aria-autocomplete":"list",readOnly:!(s.searchable||s.multi)||!!s.readOnly}))),s.multi){if(s.singleWrapper&&(this._cleanupSingleWrapper(),a(s.singleWrapper),delete s.singleWrapper),!s.list){this._unregisterDropdownEvents();const i=document.activeElement;s.list=t("ul",{class:`${s.baseClassName}__list`}),s.el.appendChild(s.list),s.list.appendChild(s.inputWrapper),s.el.classList.remove(`${s.baseClassName}__single`),s.el.classList.add(`${s.baseClassName}__multi`),s.sink.add(s.list,"click",t=>{e(t.target,`.${s.baseClassName}__item_remove`,t.currentTarget)&&(s.disabled||s.readOnly||this._removeMultiItemFromEvent(e(t.target,`.${s.baseClassName}__item`,t.currentTarget),t))}).add(s.list,"keydown",t=>{e(t.target,`.${s.baseClassName}__item`,t.currentTarget)&&this._handleMultiKeydown(t)}),i===s.input&&s.input.focus(),this._registerDropdownEvents()}}else if(s.list&&(a(s.list),s.sink.remove(s.list),delete s.list),!s.singleWrapper){this._unregisterDropdownEvents();const e=document.activeElement;s.singleWrapper=t("div",{class:`${s.baseClassName}__single_wrapper`}),s.el.appendChild(s.singleWrapper),s.el.appendChild(s.inputWrapper),s.el.classList.remove(`${s.baseClassName}__multi`),s.el.classList.add(`${s.baseClassName}__single`),e===s.input&&s.input.focus(),this._registerDropdownEvents()}s.hasOpenIndicator!==!!s.openIndicator&&(s.hasOpenIndicator?(s.openIndicator=t("span",{class:`${s.baseClassName}__open_indicator`}),s.el.appendChild(s.openIndicator),s.el.classList.add(`${s.baseClassName}__has_open_indicator`)):(a(s.openIndicator),delete s.openIndicator,s.el.classList.remove(`${s.baseClassName}__has_open_indicator`))),s.isLoadingMode!==!!s.spinner&&(s.isLoadingMode?(s.spinner=t("span",{class:`${s.baseClassName}__spinner`}),s.el.appendChild(s.spinner),s.el.classList.add(`${s.baseClassName}__has_spinner`)):(a(s.spinner),delete s.spinner,s.el.classList.remove(`${s.baseClassName}__has_spinner`)))}_syncBaseClasses(){const e=this._p,t=e.el;if(!t)return;let s=[e.baseClassName];e.multi?s.push(`${e.baseClassName}__multi`):s.push(`${e.baseClassName}__single`),this.isListOpen()?s.push(`${e.baseClassName}__open_list`):s.push(`${e.baseClassName}__closed_list`),e.hasOpenIndicator&&s.push(`${e.baseClassName}__has_open_indicator`),e.clearButtonWrapper&&s.push(`${e.baseClassName}__has_clear`),e.isLoadingMode&&s.push(`${e.baseClassName}__has_spinner`),0===e.selectedValues.length&&s.push(`${e.baseClassName}__empty_selection`),e.selectedValues.length>0&&s.push(`${e.baseClassName}__has_selection`),(e.searchable||e.multi)&&s.push(`${e.baseClassName}__searchable`),"ltr"!==e.direction&&"rtl"!==e.direction||s.push(`${e.baseClassName}__`+e.direction),e.additionalClasses&&(s=s.concat(e.additionalClasses)),t.className=s.join(" ")}_setupDropdownMenu(){const t=this._p;t.valueProp,t.dropList&&(t.dropList.destroy(),delete t.dropList,t.itemsChanged=!0,t.selectionChanged=!0,t.resortBySelectionNeeded=!0);const s=t=>{e(t.target,"li",t.currentTarget)&&t.preventDefault()},i=t.dropList=new K({virtualMinItems:10,searchable:!1,...t.listOptions,multi:t.multi,singleSelectedValue:t.multi?void 0:this.getValue(),capturesFocus:!1,labelProp:t.labelProp,valueProp:t.valueProp,noResultsText:t.noResultsText,filterThrottleWindow:t.filterThrottleWindow,filterOnEmptyTerm:t.filterOnEmptyTerm,filterGroups:t.treatGroupSelectionAsItems,filterEmptyGroups:!t.treatGroupSelectionAsItems,filterFn:t.actualFilterFn,positionOptionsProvider:()=>this._getDropListPositionOptions(),on:(e,l)=>{switch(e){case"show:before":{t.dropListVisible=!0,t.el.setAttribute("aria-expanded","true"),t.el.classList.add(`${t.baseClassName}__open_list`),t.el.classList.remove(`${t.baseClassName}__closed_list`),t.resortBySelectionNeeded&&t.sortListCheckedFirst&&t.multi&&(t.itemsChanged=!0),this._updateListItems(),this._trigger("open",{list:i}),this._startTrackingPresence(),t.sink.add(window,"resize.trackposition",()=>this._repositionDropList());let e=t.el.parentNode;for(;e;)(e.scrollHeight>e.offsetHeight||e.scrollWidth>e.offsetWidth)&&(e===document.documentElement&&(e=window),t.sink.add(e,"scroll.trackposition",()=>this._repositionDropList())),e=e.parentNode}break;case"hide":if(t.dropListVisible=!1,t.el.setAttribute("aria-expanded","false"),t.el.classList.remove(`${t.baseClassName}__open_list`),t.el.classList.add(`${t.baseClassName}__closed_list`),t.multi?t.clearInputWhen.includes("multi_close")&&this._setInputText(""):(t.clearInputWhen.includes("single_close")&&this._setInputText(""),this._scheduleSync("render_base")),this._trigger("close"),this[U])return;this._stopTrackingPresence(),t.sink.remove(null,".trackposition");break;case"check":{if(!t.multi)return;t.autoSelectTextOnCheck&&t.input&&document.activeElement===t.input&&t.input.setSelectionRange(0,t.input.value.length);const e=l.item,s=l.value;let r=l.checked;if(l.isGroup&&!t.treatGroupSelectionAsItems)return;let n={value:s,item:e,cancel:!1,isCheckingGroup:l.isCheckingGroup};if(this._trigger((r?"addsel":"removesel")+":before",n),n.cancel)return void t.dropList.setItemChecked(s,!r);if(r)t.selectedItems.push(e),t.selectedValues.push(s);else{const e=t.selectedValues.indexOf(s);-1!==e&&(t.selectedItems.splice(e,1),t.selectedValues.splice(e,1))}t.selectionChanged=!0,t.resortBySelectionNeeded=!0;const o=!!l.isCheckingGroup;t.showSelection?r?(1===i.itemCount()&&t.clearInputWhen.includes("multi_select_single")&&this._setInputText(""),t.sortSelectedItems?o||this._scheduleSync("full"):(null!=t.maxMultiItems&&(t.treatGroupSelectionAsItems?t.selectedItems:t.selectedItems.filter(e=>!e._group)).length>t.maxMultiItems?this._scheduleSync("addOrUpdateMultiItemRestElement"):this._scheduleSync("addMultiItemElement",e),o||this._scheduleSync("render_base"))):(null!=t.maxMultiItems&&(t.treatGroupSelectionAsItems?t.selectedItems:t.selectedItems.filter(e=>!e._group)).length===t.maxMultiItems?this._scheduleSync("removeMultiItemRestElement"):this._scheduleSync("removeMultiItemElement",e),o||this._scheduleSync("render_base")):t.multi&&this._scheduleSync("syncPlaceholder"),this._trigger(r?"addsel":"removesel",{value:s,item:e,isCheckingGroup:l.isCheckingGroup})}break;case"groupcheck":if(!t.multi)return;t.autoSelectTextOnCheck&&t.input&&document.activeElement===t.input&&t.input.setSelectionRange(0,t.input.value.length),l.affectedCount&&this._scheduleSync(t.sortSelectedItems?"full":"render_base"),this._trigger("groupcheck",{value:l.value,item:l.item,affectedCount:l.affectedCount});break;case"select":case"subitems:select":{if(t.multi)return;const e=l.item,s=l.value;if(!this._performSelectWithEvent(e,s))return;if(this[U])return;this.closeList(),("touch"===t.blurOnSingleSelection&&q||"touch"!==t.blurOnSingleSelection&&t.blurOnSingleSelection)&&t.input&&document.activeElement===t.input&&t.input.blur()}break;case"show_subitems":t.sink.add(l.droplist.el,"mousedown.subitems",s);break;case"hide_subitems":t.sink.remove(l.droplist.el,".subitems");break;case"blur":this._handleOnBlur();break;case"search":this._trigger("search",l);break;case"itemschanged":this._trigger("itemschanged",l)}}});t.sink.add(i.el,"mousedown",s),this._registerDropdownEvents()}_handleOnBlur(){const e=this._p;setTimeout(()=>{this[U]||e.disabled||e.readOnly||(this._trigger("search:blur"),this[U]||document.activeElement&&(e.input&&e.input.contains(document.activeElement)||e.dropList&&this.droplistElContains(document.activeElement,!0))||this.closeList())})}_unregisterDropdownEvents(){this._p.sink.remove(null,".dropdown")}_registerDropdownEvents(){const t=this._p;this._unregisterDropdownEvents();const s=t.dropList;if(!s)return;let i=!1,l=null;const r=t.multi||t.searchable?t.input:t.el;t.sink.add(r,"keydown.dropdown",e=>{if(e.currentTarget.readOnly)return;let i=!1,l=t.lastKeyAllowsNonTypeKeys;t.lastKeyAllowsNonTypeKeys=!1;let r=t.input&&t.input.value.length>0;switch(e.key){case N:case F:case M:case L:case w:case k:if((e.key===w||e.key===k)&&r&&!l){s._keydownFreeType(e);break}switch(t.lastKeyAllowsNonTypeKeys=!0,e.preventDefault(),e.key){case N:s.isVisible()&&s.previousPage(e);break;case F:s.isVisible()&&s.nextPage(e);break;case M:s.isVisible()?s.previous(e):this._movePrev();break;case L:s.isVisible()?s.next(e):this._moveNext();break;case w:s.goToFirst(e);break;case k:s.goToLast(e)}break;case V:l&&(t.lastKeyAllowsNonTypeKeys=!0,s.isVisible()&&s.hasFocusedItem()&&(i=!0,t.multi?s.toggleFocusedItem(e):s.triggerItemSelection(null,e),e.preventDefault()));break;case x:s.isVisible()&&s.hasFocusedItem()&&(i=!0,e.preventDefault(),s.triggerItemSelection(null,e));break;case O:s.isVisible()&&s.hasFocusedItem()&&s.triggerItemSelection(null,e);break;case E:s.isVisible()&&(s.hide(e),e.preventDefault());break;default:s.isVisible()?s._keydownFreeType(e,!1):t.allowTypeToSelect?s._keydownFreeType(e,!0):(this.openList(),setTimeout(()=>{this[U]||s._keydownFreeType(e,!1)}))}i||e.key!==x&&(e.key!==V||!t.lastKeyAllowsNonTypeKeys||t.multi||s.hasFocusedItem()||t.disabled||t.readOnly)||(this.toggleList(),e.preventDefault(),e.stopPropagation())}),t.input&&t.sink.add(t.input,"input.dropdown",()=>{t.disabled||t.readOnly||(t.filterTerm=t.input.value.trim(),this._trigger("search:term",t.filterTerm),t.dropList?.setSearchTerm(t.filterTerm,!0))}).add(t.input,"click.dropdown",()=>{t.disabled||t.readOnly||!t.multi&&t.searchable&&this.openList()}).add(t.input,"focus.dropdown",()=>{t.disabled||t.readOnly||(this._trigger("search:focus"),this[U]||(i=!1,this.openList(),i=!0,setTimeout(()=>{i=!1},10)))}).add(t.input,"blur.dropdown",()=>this._handleOnBlur()),t.sink.add(t.el,"mousedown.dropdown",()=>{t.multi||t.searchable||i||t.disabled||t.readOnly||this.toggleList(),i=!1}).add(t.el,"touchstart.dropdown",s=>{if(l)return;if(l=s.changedTouches[0].identifier,this.isDisabled()||this.isReadOnly())return;if(e(s.target,`.${t.baseClassName}__item,.${t.baseClassName}__clear`,t.el))return;let i=()=>{l=null,t.sink.remove(t.el,".dropdown_touchextra")};(t.input||t.el).focus(),t.sink.add(t.el,"touchend.dropdown_touchextra",e=>{if(!Array.prototype.find.call(s.changedTouches,e=>e.identifier===l))return i();e.preventDefault(),i()}).add(t.el,"touchmove.dropdown_touchextra",e=>{e.preventDefault()}).add(t.el,"touchcancel.dropdown_touchextra",i)})}_performSelectWithEvent(e,t){let s={value:t,item:e,cancel:!1};return this._trigger("select:before",s),!s.cancel&&!this[U]&&(this._setSelectedItems([e]),this._trigger("select",{value:t,item:e}),!0)}_performClearWithEvent(e=!1){let t={cancel:!1};return this._trigger("clear:before",t),!t.cancel&&!this[U]&&(this._setSelectedItems([]),e&&this._setInputText(""),this._trigger("clear"),!0)}_movePrev(){const e=this._p;if(this.isMultiEnabled())return;let t=this.getSelectedItems(),s=e.dropList.getFilteredItemCount();if(s+(e.clearable?1:0)>1){let i=t.length>0?e.dropList.filteredItemIndexByItem(t[0])-1:s-1;-1!==i||e.clearable||(i=s-1);let l=-1===i?null:e.dropList.filteredItemAtIndex(i);l?this._performSelectWithEvent(l,l[e.valueProp]):this._performClearWithEvent()}}_moveNext(){const e=this._p;if(this.isMultiEnabled())return;let t=this.getSelectedItems(),s=e.dropList.getFilteredItemCount();if(s+(e.clearable?1:0)>1){let i=t.length>0?e.dropList.filteredItemIndexByItem(t[0])+1:0;i===s&&(i=e.clearable?-1:0);let l=-1===i?null:e.dropList.filteredItemAtIndex(i);l?this._performSelectWithEvent(l,l[e.valueProp]):this._performClearWithEvent()}}_updateListItems(){const e=this._p,t=e.dropList;if(!t||!e.dropListVisible)return;if((e.itemsChanged||e.selectionChanged)&&(e.dropList._lastSerializedBox=null),e.itemsChanged){let s=e.items;(e.sortListItems||e.sortListCheckedFirst&&e.multi)&&(s=this._sortItems(s,e.sortListItems,e.sortListCheckedFirst&&e.multi,e.splitListCheckedGroups)),t.setItems(s),t.invokeRefilter(),e.itemsChanged=!1,e.selectionChanged=!0,e.resortBySelectionNeeded=!1}let s=!1;if(e.selectionChanged){if(e.multi)e.dropList.setCheckedValues(e.selectedValues);else{const t=this.getValue(),i=e.dropList.itemIndexByValue(t);e.dropList.setFocusedItemAtIndex(i).setSingleSelectedItemByValue(t),s=e.dropList.hasFocusedItem()}e.selectionChanged=!1}this._repositionDropList(),s&&e.dropList.setFocusedItemAtIndex(e.dropList.getFocusedItemIndex())}_setSelectedItems(e){const t=this._p,s=t.valueProp;t.multi?(t.selectedItems=e.filter(e=>void 0!==e[s]),t.selectedValues=t.selectedItems.map(e=>e[s])):(t.selectedItems=e.slice(0,1),t.selectedValues=e.slice(0,1).map(e=>e[s])),t.selectionChanged=!0,t.resortBySelectionNeeded=!0,this._updateListItems(),this._scheduleSync("full")}_scheduleSync(e,t){const s=this._p;s.syncQueue||(s.syncQueue=[]),("full"===e||"render_items"===e&&!s.syncQueue.some(e=>"full"===e.mode))&&(s.syncQueue.length=0),0!==s.syncQueue.length&&["full","render_items"].includes(e)||s.syncQueue.push({mode:e,data:t}),s.syncTimeout||(s.syncTimeout=setTimeout(()=>{delete s.syncTimeout;let e=s.syncQueue;delete s.syncQueue,this._performSync(e)}))}_performSync(e){const t=this._p;if(!this[U])for(let s of e)switch(s.mode){case"full":this._syncFull(!0,!0);break;case"render_base":this._syncFull(!1,!1);break;case"render_items":this._syncFull(!0,!1);break;case"render_list":this._syncFull(!1,!0);break;case"render_clear":this._syncClearButton(),this._resizeInput();break;case"singleItem":this._syncSingleItem();break;case"syncPlaceholder":this._syncPlaceholder();break;case"removeMultiItemElement":if(t.showSelection)this._syncPlaceholder();else{const e=t.valueProp,i=s.data[e];let l=t.multiItemEls.findIndex(t=>t[D][e]===i);-1!==l&&this._removeMultiItemElementByIndex(l)}break;case"addMultiItemElement":t.showSelection?this._addMultiItemElement(s.data):this._syncPlaceholder();break;case"addOrUpdateMultiItemRestElement":t.showSelection?this._addMultiItemRestElement():this._syncPlaceholder();break;case"removeMultiItemRestElement":if(t.showSelection){let e=t.multiItemEls[t.multiItemEls.length-1];e?.[D]?.[t.valueProp]===j&&this._removeMultiItemElementByIndex(t.multiItemEls.length-1)}else this._syncPlaceholder();break;case"resize_input":this._resizeInput()}}_cleanupSingleWrapper(){const e=this._p;if(e.singleWrapper){if(e.unrenderSingleItem&&e.singleWrapper.childNodes.length>0)try{e.unrenderSingleItem(e.singleWrapper[D],e.singleWrapper)}catch(t){console.error(t)}delete e.singleWrapper[D],e.singleWrapper.innerHTML=""}}_removeMultiItemElementByIndex(e){const t=this._p,s=t.multiItemEls;if(s.length>e){const l=s[e],r=l[D];let n=r?.[t.valueProp]===j?t.unrenderRestMultiItem??t.unrenderMultiItem:t.unrenderMultiItem;if(n&&l.childNodes.length>0)try{n(r,l)}catch(i){console.error(i)}a(l),e===s.length-1?s.pop():s.splice(e,1)}}_renderSingleItemContent(e){const t=this._p;if(!t.renderSingleItem||!1===t.renderSingleItem(e,t.singleWrapper)){const s=t.labelProp;let i=e[t.multiItemLabelProp]||e[s];null==i&&(i=""),t.singleWrapper.appendChild(document.createTextNode(i))}}_renderMultiItemContent(e,s){const i=this._p;let l=e[i.valueProp]===j?i.renderRestMultiItem??i.renderMultiItem:i.renderMultiItem;if(!l||!1===l(e,s)){const l=i.labelProp,r=e[i.multiItemLabelProp]||e[l];s.appendChild(t("span",{textContent:r}))}}_addMultiItemElement(e){const t=this._p,s=this._renderMultiItem(e);return!!s&&(n(t.inputWrapper,s),t.multiItemEls.push(s),!0)}_addMultiItemRestElement(){const e=this._p;let t=e.selectedItems.slice(0),s=(e.treatGroupSelectionAsItems?t:t.filter(e=>!e._group)).length-e.maxMultiItems,i=e.multiItemsRestLabelProvider?e.multiItemsRestLabelProvider(s,t):`+ ${s}`;this._addMultiItemElement({items:t,[e.valueProp]:j,[e.labelProp]:i})}_syncClearButton(){const e=this._p,s=e.multiItemLabelProp;e.selectedItems.length>0&&e.selectedItems.some(e=>!1!==e[s])&&e.clearable&&e.showSelection?e.clearButtonWrapper||(e.clearButtonWrapper=t(e.multi?"li":"span",{class:`${e.baseClassName}__clear`},e.clearButton=t("button")),e.multi?r(e.list,e.clearButtonWrapper):r(e.el,e.clearButtonWrapper),e.el.classList.add(`${e.baseClassName}__has_clear`),e.sink.add(e.clearButton,"click",()=>{this.isDisabled()||this.isReadOnly()||this.clear()})):e.clearButtonWrapper&&(e.sink.remove(e.clearButton,"click"),a(e.clearButtonWrapper),delete e.clearButtonWrapper,delete e.clearButton,e.el.classList.remove(`${e.baseClassName}__has_clear`))}_syncPlaceholder(){const e=this._p,t=e.multiItemLabelProp;let s="";e.multi&&!e.showSelection?s="function"==typeof e.multiPlaceholderFormatter?e.multiPlaceholderFormatter(e.selectedItems):0===e.selectedItems.length?e.placeholder||"":((e,t)=>{if(0===e.length)return"";let s=e[0][t]+"";return e.length>1&&(s+=` (+${e.length-1})`),s})(e.selectedItems,e.labelProp):0!==e.selectedItems.length&&e.showSelection&&!e.selectedItems.every(e=>!1===e[t])||(s=null==e.placeholder?"":e.placeholder+""),e.input.setAttribute("placeholder",s),e.showPlaceholderInTooltip?e.input.setAttribute("title",s):e.input.removeAttribute("title")}_syncSingleItem(){const e=this._p;e.singleWrapper&&this._cleanupSingleWrapper();const t=e.selectedItems;t.length>0&&(this._renderSingleItemContent(t[0]),e.singleWrapper[D]=t[0])}_syncFull(e,t){const s=this._p,i=s.multiItemLabelProp;if(this._renderBase(),this._syncClearButton(),this._syncPlaceholder(),(e=s.multi&&s.showSelection&&(e||s.selectedItems.filter(e=>!1!==e[i]).length!==s.multiItemEls.length))||!s.showSelection||!s.multi)for(;s.multiItemEls.length>0;)this._removeMultiItemElementByIndex(s.multiItemEls.length-1);if(s.multi){if(e){const e=s.selectedItems,t=s.treatGroupSelectionAsItems;if(s.sortSelectedItems){const t=s.labelProp,i=s.multiItemLabelProp,l=s.valueProp,r=s.stickyValues,n=s.sortItemComparator||((e,s)=>{if(null!==r){let t=r.has(e[l]),i=r.has(s[l]);if(t&&!i)return-1;if(!t&&i)return 1}const n=e[i]||e[t],o=s[i]||s[t];return n<o?-1:n>o?1:0});e.sort(n),s.selectedValues=e.map(e=>e[l])}let i=0,l=s.maxMultiItems,r=!1;for(let s=0;s<e.length;s++)if(t||!e[s]._group){if(null!=l&&i===l){r=!0;break}this._addMultiItemElement(e[s])&&i++}r&&this._addMultiItemRestElement()}}else s.multi||this._syncSingleItem();return o(s.el)!==document||(u(s.el,`${s.baseClassName}__empty_selection`,0===s.selectedValues.length),u(s.el,`${s.baseClassName}__has_selection`,s.selectedValues.length>0),s.searchable?(s.input&&(s.input.readOnly=s.readOnly),s.el.classList.add(`${s.baseClassName}__searchable`)):(s.input&&(s.input.readOnly=!0),s.el.classList.remove(`${s.baseClassName}__searchable`)),this._resizeInput(),t&&this._updateListItems()),this}_trigger(e,t){const s=this._p;void 0!==s&&(s.on&&s.on(e,...void 0===t?[]:[t]),s.mitt.emit(e,t))}_renderMultiItem(e){const s=this._p,i=s.labelProp,l=e[s.multiItemLabelProp]??e[i];if(!1===l)return null;const r=t("span",{class:`${s.baseClassName}__item_remove`,role:"presentation"}),n=t("li",{class:`${s.baseClassName}__item`,tabindex:"0",title:l});return"before"===s.multiItemRemovePosition&&n.appendChild(r),this._renderMultiItemContent(e,n),"after"===s.multiItemRemovePosition&&n.appendChild(r),n[D]=e,n}_removeMultiItemFromEvent(e,t){const l=this._p;let r;if(/key/.test(t.type)){const n=t;n.key===C?r=s(e,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`):n.key===S&&(r=i(e,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`))}else/click|mouse|touch/.test(t.type)&&(r=s(e,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`));const n=e[D],o=n[l.valueProp];if(void 0!==n)if(o===j){let e=(l.treatGroupSelectionAsItems?l.selectedItems:l.selectedItems.filter(e=>!e._group)).slice(l.maxMultiItems),t=[];for(let s of e){let e={value:o,item:s,cancel:!1};this._trigger("removesel:before",e),e.cancel||t.push(s)}if(t.length>0){this._removeMultiItemElementByIndex(l.multiItemEls.length-1);for(let e of t){let t=l.selectedItems.indexOf(e);-1===t&&(t=l.selectedValues.indexOf(o[l.valueProp])),-1!==t&&(l.selectedItems.splice(t,1),l.selectedValues.splice(t,1),l.selectionChanged=!0,l.resortBySelectionNeeded=!0)}}e.length>t.length&&this._addMultiItemRestElement(),t.length>0&&this._scheduleSync("render_list")}else{let e={value:o,item:n,cancel:!1};if(this._trigger("removesel:before",e),e.cancel)return this;this._removeMultiItem(n),this._trigger("removesel",{value:o,item:n})}return r||(r=l.el.querySelector(`.${l.baseClassName}__item, .${l.baseClassName}__search_field`)),Q(r,`${l.baseClassName}__search_wrapper`)&&(r=r.querySelector("input")),r&&r.focus(),this}_removeMultiItem(e,t=!1){const s=this._p,i=s.valueProp,l=s.labelProp,r=e[i];let n=s.selectedItems.indexOf(e);-1===n&&(n=s.selectedValues.indexOf(r)),-1!==n&&(s.selectedItems.splice(n,1),s.selectedValues.splice(n,1),s.selectionChanged=!0,s.resortBySelectionNeeded=!0),n=s.multiItemEls.findIndex(t=>t[D]===e),-1===n&&(n=s.multiItemEls.findIndex(e=>e[D][i]===r)),-1!==n&&this._removeMultiItemElementByIndex(n),t&&(this._setInputText(e[s.multiItemLabelProp]||e[l]),s.input.focus(),s.input.selectionStart=s.input.selectionEnd=s.input.value.length),this._scheduleSync("render_list")}_setInputText(e){const t=this._p;t.input.value=null==e?"":String(e),t.filterTerm="",this._trigger("search:term",t.filterTerm),t.dropList?.setSearchTerm("",!0)}_resizeInput(){const e=this._p,t=e.el;if(!t.parentNode||!document.body.contains(t))return this;const s=e.input,i=e.inputBackBuffer;let l=s.value||s.placeholder;u(t,`${e.baseClassName}__has_input`,!!l),u(t,`${e.baseClassName}__empty_input`,!l);let r=!1;if(e.multi&&0===e.multiItemEls.length&&e.showSelection){s.style.width="";let i=0,l=0,n=getComputedStyle(e.list||t,"::before");n.content&&"none"!==n.content&&"absolute"!==n.position&&"none"!==n.float&&(i=_(e.list||t,"::before",!0,!0,!0));let o=getComputedStyle(e.list||t,"::after");o.content&&"none"!==o.content&&"absolute"!==o.position&&"none"!==o.float&&(l=_(e.list||t,"::after",!0,!0,!0));let a=p(e.list||t);a-=i+l,s.style.width=`${a}px`,r=!0}else{f(i,d(s,X)),i.textContent=l,t.appendChild(i);const n=getComputedStyle(s),o=(parseFloat(n.paddingLeft)||0)+(parseFloat(n.paddingRight)||0),u=.75*(parseFloat(n["font-size"])||0)+o,c=p(i,!0,!0),h=p(s,!0,!0);let m=Math.max(c,u);if(m!==h){b(s,m,!0,!0);let t=(parseFloat(n.borderLeftWidth)||0)+(parseFloat(n.borderRightWidth)||0),i=s.scrollWidth+t;if(i>m){let e=i-m;s.style.width=`${parseFloat(s.style.width)+e}px`,m+=e}if(e.singleWrapper&&(e.singleWrapper.style.width="",l)){let s=m-o-t;p(e.singleWrapper,!1,!1)<s&&b(e.singleWrapper,s,!1,!1)}r=!0}a(i)}return r&&this._trigger("input:resize"),this}_repositionDropList(){const e=this._p,t=e.el;if(!e.dropList||!e.dropListVisible||!e.dropList.isVisible())return this;const s=t.getBoundingClientRect(),i=s.left+","+s.top+","+s.right+","+s.bottom;return e.dropList._lastSerializedBox!==i&&(e.dropList.relayout(),e.dropList._lastSerializedBox=i),this}_handleInputKeydown(e){const t=this._p,s=e.target;if(e.key===S&&e.ctrlKey&&0===s.value.length)this.clear(),e.preventDefault();else if(e.key===S&&0===s.value.length){const s=t.multiItemEls[t.multiItemEls.length-1];if(!s)return;const i=s[D],l=i[t.valueProp];if(void 0===l)return;let r={value:l,item:i,cancel:!1};if(this._trigger("removesel:before",r),r.cancel)return;this._removeMultiItem(i,!0),this._trigger("removesel",{value:l,item:i}),e.preventDefault()}}_handleMultiKeydown(t){const l=this._p;if(l.disabled||l.readOnly)return;const r="rtl"===getComputedStyle(l.el).direction;let n;if(t.key===(r?T:P))n=s(t.target,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`),Q(n,`${l.baseClassName}__search_wrapper`)&&(n=n.querySelector("input")),n&&n.focus(),t.preventDefault();else if(t.key===(r?P:T))n=i(t.target,`.${l.baseClassName}__item,.${l.baseClassName}__search_wrapper`),Q(n,`${l.baseClassName}__search_wrapper`)&&(n=n.querySelector("input")),n&&n.focus(),t.preventDefault();else if(t.key===S&&t.ctrlKey){const e=[];let s=t.target;for(;s;)e.push(s),s=i(s,`.${l.baseClassName}__item`);for(;e.length;)this._removeMultiItemFromEvent(e.shift(),t);t.preventDefault()}else t.key!==C&&t.key!==S||(this._removeMultiItemFromEvent(e(t.target,`.${l.baseClassName}__item`,l.el),t),t.preventDefault())}_getDropListPositionOptions(){return{target:this._p.el,offset:{x:0,y:0},anchor:{x:"start",y:"bottom"},position:{x:"start",y:"top"},updateWidth:!0}}_startTrackingPresence(){const e=this._p;this._stopTrackingPresence(),e.presenceInt=setInterval(()=>{o(e.el)!==document&&this.closeList()},200)}_stopTrackingPresence(){const e=this._p;e.presenceInt&&(clearInterval(e.presenceInt),e.presenceInt=null)}_sortItems(e,t,s,i){const l=this._p;if(!t&&!s)return e;const r=l.labelProp,n=l.multiItemLabelProp,o=l.valueProp,a=l.stickyValues,u=l.sortItemComparator||((e,t)=>{if(null!==a){let s=a.has(e[o]),i=a.has(t[o]);if(s&&!i)return-1;if(!s&&i)return 1}const s=e[r]||e[n],i=t[r]||t[n];return s<i?-1:s>i?1:0});let c=[],d=null,h=[c],m=!1;const p=new Set(l.selectedValues);let _,g,f;for(g=0,f=e.length;g<f;g++)_=e[g],(_._group&&c.length||m&&!_._group&&!_._child)&&(m=!!_._group,c=[],h.push(c)),c.push(_);c.length||(h.length=0),a&&e.length>0&&!e[0]._group&&(d=h[0].filter(e=>a.has(e[o])),d.length>0?(h[0]=h[0].filter(e=>!a.has(e[o])),0===h[0].length&&h.shift()):d=null),t&&h.sort((e,t)=>{if(e=e[0],t=t[0],null!==a){let s=a.has(e[o]),i=a.has(t[o]);if(s&&!i)return-1;if(!s&&i)return 1}return!e._group&&t._group?-1:e._group&&!t._group?1:u(e,t)}),d&&h.unshift(d);const I=[],b=[];for(let S=0,C=h.length;S<C;S++)c=h[S],c.sort((e,i)=>{if(e._group&&!i._group)return-1;if(!e._group&&i._group)return 1;if(s){const t=p.has(e[o]),s=p.has(i[o]);if(t&&!s)return-1;if(!t&&s)return 1}return t?u(e,i):0}),b.push(c);if(s&&i){let e;for(let t=0,s=h.length;t<s;t++){if(c=h[t],c===d){I.push(d);let e=b.indexOf(d);-1!==e&&b.splice(e,1);continue}e=null;for(let t=0,s=c.length;t<s;t++)if(_=c[t],!_._group){if(!p.has(_[l.valueProp]))break;e||(e=[],c[0]._group&&e.push(c[0])),e.push(_),c.splice(t--,1),s--}if(e&&(I.push(e),0===c.length||1===c.length&&c[0]._group)){h.splice(t--,1),s--;let e=b.indexOf(c);-1!==e&&b.splice(e,1)}}}const v=[];v.length=e.length;let y=0;h=I.length?I.concat(b):b;for(let S=0,C=h.length;S<C;S++)for(c=h[S],g=0,f=c.length;g<f;g++)v[y++]=c[g];return v}};export{K as DropList,z as DropListDefaultOptions,D as ItemSymbol,J as SelectBox,Y as SelectBoxDefaultOptions};
6
6
  //# sourceMappingURL=lib.es6.min.js.map