Choices/assets/scripts/choices.search-basic.min.js
2024-08-23 02:44:27 +08:00

2 lines
70 KiB
JavaScript

/*! choices.js v11.0.0-rc8 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Choices=t()}(this,(function(){"use strict";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},e(t,i)};function t(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return i=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var s in t=arguments[i])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},i.apply(this,arguments)};function n(e,t,i){if(i||2===arguments.length)for(var n,s=0,o=t.length;s<o;s++)!n&&s in t||(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var s,o="ADD_CHOICE",r="REMOVE_CHOICE",a="FILTER_CHOICES",c="ACTIVATE_CHOICES",l="CLEAR_CHOICES",h="ADD_GROUP",u="ADD_ITEM",d="REMOVE_ITEM",p="HIGHLIGHT_ITEM",m=["fuseOptions","classNames"],f=function(e,t){return{type:p,item:e,highlighted:t}},v=function(e){return Array.from({length:e},(function(){return Math.floor(36*Math.random()+0).toString(36)})).join("")},_=function(e){if("string"!=typeof e){if(null==e)return"";if("object"==typeof e){if("raw"in e)return _(e.raw);if("trusted"in e)return e.trusted}return e}return e.replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/'/g,"&#039;").replace(/"/g,"&quot;")},g=(s=document.createElement("div"),function(e){s.innerHTML=e.trim();for(var t=s.children[0];s.firstChild;)s.removeChild(s.firstChild);return t}),y=function(e,t){return"function"==typeof e?e(_(t),t):e},b=function(e){return"function"==typeof e?e():e},E=function(e){if("string"==typeof e)return e;if("object"==typeof e){if("trusted"in e)return e.trusted;if("raw"in e)return e.raw}return""},w=function(e,t){return e?function(e){if("string"==typeof e)return e;if("object"==typeof e){if("escaped"in e)return e.escaped;if("trusted"in e)return e.trusted}return""}(t):_(t)},S=function(e,t,i){e.innerHTML=w(t,i)},C=function(e,t){return e.rank-t.rank},I=function(e){return Array.isArray(e)?e:[e]},A=function(e){return e&&Array.isArray(e)?e.map((function(e){return".".concat(e)})).join(""):".".concat(e)},O=function(e){if(void 0!==e)try{return JSON.parse(e)}catch(t){return e}return{}},L=function(){function e(e){var t=e.type,i=e.classNames;this.element=e.element,this.classNames=i,this.type=t,this.isActive=!1}return Object.defineProperty(e.prototype,"distanceFromTopWindow",{get:function(){return this.element.getBoundingClientRect().bottom},enumerable:!1,configurable:!0}),e.prototype.show=function(){var e;return(e=this.element.classList).add.apply(e,I(this.classNames.activeState)),this.element.setAttribute("aria-expanded","true"),this.isActive=!0,this},e.prototype.hide=function(){var e;return(e=this.element.classList).remove.apply(e,I(this.classNames.activeState)),this.element.setAttribute("aria-expanded","false"),this.isActive=!1,this},e}(),x="text",T="select-one",N="select-multiple",F=function(){function e(e){var t=e.type,i=e.classNames,n=e.position;this.element=e.element,this.classNames=i,this.type=t,this.position=n,this.isOpen=!1,this.isFlipped=!1,this.isDisabled=!1,this.isLoading=!1}return e.prototype.shouldFlip=function(e){var t=!1;return"auto"===this.position?t=!window.matchMedia("(min-height: ".concat(e+1,"px)")).matches:"top"===this.position&&(t=!0),t},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype.open=function(e){var t,i;(t=this.element.classList).add.apply(t,I(this.classNames.openState)),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e)&&((i=this.element.classList).add.apply(i,I(this.classNames.flippedState)),this.isFlipped=!0)},e.prototype.close=function(){var e,t;(e=this.element.classList).remove.apply(e,I(this.classNames.openState)),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&((t=this.element.classList).remove.apply(t,I(this.classNames.flippedState)),this.isFlipped=!1)},e.prototype.addFocusState=function(){var e;(e=this.element.classList).add.apply(e,I(this.classNames.focusState))},e.prototype.removeFocusState=function(){var e;(e=this.element.classList).remove.apply(e,I(this.classNames.focusState))},e.prototype.enable=function(){var e;(e=this.element.classList).remove.apply(e,I(this.classNames.disabledState)),this.element.removeAttribute("aria-disabled"),this.type===T&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){var e;(e=this.element.classList).add.apply(e,I(this.classNames.disabledState)),this.element.setAttribute("aria-disabled","true"),this.type===T&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){var t=e.parentNode;t&&(e.nextSibling?t.insertBefore(this.element,e.nextSibling):t.appendChild(this.element)),this.element.appendChild(e)},e.prototype.unwrap=function(e){var t=this.element.parentNode;t&&(t.insertBefore(e,this.element),t.removeChild(this.element))},e.prototype.addLoadingState=function(){var e;(e=this.element.classList).add.apply(e,I(this.classNames.loadingState)),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){var e;(e=this.element.classList).remove.apply(e,I(this.classNames.loadingState)),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),M=function(){function e(e){var t=e.element,i=e.type,n=e.classNames,s=e.preventPaste;this.element=t,this.type=i,this.classNames=n,this.preventPaste=s,this.isFocussed=this.element.isEqualNode(document.activeElement),this.isDisabled=t.disabled,this._onPaste=this._onPaste.bind(this),this._onInput=this._onInput.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}return Object.defineProperty(e.prototype,"placeholder",{set:function(e){this.element.placeholder=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.addEventListeners=function(){var e=this.element;e.addEventListener("paste",this._onPaste),e.addEventListener("input",this._onInput,{passive:!0}),e.addEventListener("focus",this._onFocus,{passive:!0}),e.addEventListener("blur",this._onBlur,{passive:!0})},e.prototype.removeEventListeners=function(){var e=this.element;e.removeEventListener("input",this._onInput),e.removeEventListener("paste",this._onPaste),e.removeEventListener("focus",this._onFocus),e.removeEventListener("blur",this._onBlur)},e.prototype.enable=function(){this.element.removeAttribute("disabled"),this.isDisabled=!1},e.prototype.disable=function(){this.element.setAttribute("disabled",""),this.isDisabled=!0},e.prototype.focus=function(){this.isFocussed||this.element.focus()},e.prototype.blur=function(){this.isFocussed&&this.element.blur()},e.prototype.clear=function(e){return void 0===e&&(e=!0),this.element.value="",e&&this.setWidth(),this},e.prototype.setWidth=function(){var e=this.element,t=e.style,i=e.value;t.minWidth="".concat(e.placeholder.length+1,"ch"),t.width="".concat(i.length+1,"ch")},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype._onInput=function(){this.type!==T&&this.setWidth()},e.prototype._onPaste=function(e){this.preventPaste&&e.preventDefault()},e.prototype._onFocus=function(){this.isFocussed=!0},e.prototype._onBlur=function(){this.isFocussed=!1},e}(),D=function(){function e(e){this.element=e.element,this.scrollPos=this.element.scrollTop,this.height=this.element.offsetHeight}return e.prototype.clear=function(){this.element.innerHTML=""},e.prototype.prepend=function(e){var t=this.element.firstElementChild;t?this.element.insertBefore(e,t):this.element.append(e)},e.prototype.scrollToTop=function(){this.element.scrollTop=0},e.prototype.scrollToChildElement=function(e,t){var i=this;if(e){var n=t>0?this.element.scrollTop+(e.offsetTop+e.offsetHeight)-(this.element.scrollTop+this.element.offsetHeight):e.offsetTop;requestAnimationFrame((function(){i._animateScroll(n,t)}))}},e.prototype._scrollDown=function(e,t,i){var n=(i-e)/t;this.element.scrollTop=e+(n>1?n:1)},e.prototype._scrollUp=function(e,t,i){var n=(e-i)/t;this.element.scrollTop=e-(n>1?n:1)},e.prototype._animateScroll=function(e,t){var i=this,n=this.element.scrollTop,s=!1;t>0?(this._scrollDown(n,4,e),n<e&&(s=!0)):(this._scrollUp(n,4,e),n>e&&(s=!0)),s&&requestAnimationFrame((function(){i._animateScroll(e,t)}))},e}(),k=function(){function e(e){var t=e.classNames;this.element=e.element,this.classNames=t,this.isDisabled=!1}return Object.defineProperty(e.prototype,"isActive",{get:function(){return"active"===this.element.dataset.choice},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dir",{get:function(){return this.element.dir},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.setAttribute("value",e),this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.conceal=function(){var e,t=this.element;(e=t.classList).add.apply(e,I(this.classNames.input)),t.hidden=!0,t.tabIndex=-1;var i=t.getAttribute("style");i&&t.setAttribute("data-choice-orig-style",i),t.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e,t=this.element;(e=t.classList).remove.apply(e,I(this.classNames.input)),t.hidden=!1,t.removeAttribute("tabindex");var i=t.getAttribute("data-choice-orig-style");i?(t.removeAttribute("data-choice-orig-style"),t.setAttribute("style",i)):t.removeAttribute("style"),t.removeAttribute("data-choice")},e.prototype.enable=function(){var e=this.element;e.removeAttribute("disabled"),e.disabled=!1,this.isDisabled=!1},e.prototype.disable=function(){var e=this.element;e.setAttribute("disabled",""),e.disabled=!0,this.isDisabled=!0},e.prototype.triggerEvent=function(e,t){var i;void 0===(i=t||{})&&(i=null),this.element.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,cancelable:!0}))},e}(),P=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(k),j=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},K=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},B=function(e,t){if("string"==typeof e)return B({value:e,label:e},!1);var i=e;if("choices"in i){if(!t)throw new TypeError("optGroup is not allowed");var n=i,s=n.choices.map((function(e){return B(e,!1)}));return{id:0,label:E(n.label)||n.value,active:!!s.length,disabled:!!n.disabled,choices:s}}var o=i;return{id:0,groupId:0,score:0,rank:0,value:o.value,label:o.label||o.value,active:j(o.active),selected:j(o.selected,!1),disabled:j(o.disabled,!1),placeholder:j(o.placeholder,!1),highlighted:!1,labelClass:K(o.labelClass),labelDescription:o.labelDescription,customProperties:o.customProperties}},H=function(e){return"SELECT"===e.tagName},V=function(e){function i(t){var i=t.template,n=t.extractPlaceholder,s=e.call(this,{element:t.element,classNames:t.classNames})||this;return s.template=i,s.extractPlaceholder=n,s}return t(i,e),Object.defineProperty(i.prototype,"placeholderOption",{get:function(){return this.element.querySelector('option[value=""]')||this.element.querySelector("option[placeholder]")},enumerable:!1,configurable:!0}),i.prototype.addOptions=function(e){var t=this,i=document.createDocumentFragment();e.forEach((function(e){var n=e;if(!n.element){var s=t.template(n);i.appendChild(s),n.element=s}})),this.element.appendChild(i)},i.prototype.optionsAsChoices=function(){var e=this,t=[];return this.element.querySelectorAll(":scope > option, :scope > optgroup").forEach((function(i){!function(e){return"OPTION"===e.tagName}(i)?function(e){return"OPTGROUP"===e.tagName}(i)&&t.push(e._optgroupToChoice(i)):t.push(e._optionToChoice(i))})),t},i.prototype._optionToChoice=function(e){!e.hasAttribute("value")&&e.hasAttribute("placeholder")&&(e.setAttribute("value",""),e.value="");var t=e.dataset;return{id:0,groupId:0,score:0,rank:0,value:e.value,label:e.innerHTML,element:e,active:!0,selected:this.extractPlaceholder?e.selected:e.hasAttribute("selected"),disabled:e.disabled,highlighted:!1,placeholder:this.extractPlaceholder&&(!e.value||e.hasAttribute("placeholder")),labelClass:void 0!==t.labelClass?K(t.labelClass):void 0,labelDescription:void 0!==t.labelDescription?t.labelDescription:void 0,customProperties:O(t.customProperties)}},i.prototype._optgroupToChoice=function(e){var t=this,i=e.querySelectorAll("option"),n=Array.from(i).map((function(e){return t._optionToChoice(e)}));return{id:0,label:e.label||"",element:e,active:!!n.length,disabled:e.disabled,choices:n}},i}(k),R={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,closeDropdownOnSelect:"auto",singleModeForMultiSelect:!1,addChoices:!1,addItems:!0,addItemFilter:function(e){return!!e&&""!==e},removeItems:!0,removeItemButton:!1,removeItemButtonAlignLeft:!1,editItems:!1,allowHTML:!1,allowHtmlUserInput:!1,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sorter:function(e,t){var i=e.label,n=t.label,s=void 0===n?t.value:n;return E(void 0===i?e.value:i).localeCompare(E(s),[],{sensitivity:"base",ignorePunctuation:!0,numeric:!0})},shadowRoot:null,placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:function(e){return'Press Enter to add <b>"'.concat(e,'"</b>')},removeItemIconText:function(){return"Remove item"},removeItemLabelText:function(e){return"Remove item: ".concat(e)},maxItemText:function(e){return"Only ".concat(e," values can be added")},valueComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},labelId:"",callbackOnInit:null,callbackOnCreateTemplates:null,classNames:{containerOuter:["choices"],containerInner:["choices__inner"],input:["choices__input"],inputCloned:["choices__input--cloned"],list:["choices__list"],listItems:["choices__list--multiple"],listSingle:["choices__list--single"],listDropdown:["choices__list--dropdown"],item:["choices__item"],itemSelectable:["choices__item--selectable"],itemDisabled:["choices__item--disabled"],itemChoice:["choices__item--choice"],description:["choices__description"],placeholder:["choices__placeholder"],group:["choices__group"],groupHeading:["choices__heading"],button:["choices__button"],activeState:["is-active"],focusState:["is-focused"],openState:["is-open"],disabledState:["is-disabled"],highlightedState:["is-highlighted"],selectedState:["is-selected"],flippedState:["is-flipped"],loadingState:["is-loading"],notice:["choices__notice"],addChoice:["choices__item--selectable","add-choice"],noResults:["has-no-results"],noChoices:["has-no-choices"]},appendGroupInSearch:!1},q={groups:function(e,t){var i=e,n=!0;switch(t.type){case h:i.push(t.group);break;case l:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t){var i=e,n=!0;switch(t.type){case u:var s=t.item;s.selected=!0,(o=s.element)&&(o.selected=!0,o.setAttribute("selected","")),i.push(s),i.forEach((function(e){e.highlighted=!1}));break;case d:var o,a=t.item;if(a.selected=!1,o=a.element){o.selected=!1,o.removeAttribute("selected");var c=o.parentElement;c&&H(c)&&c.type===T&&(c.value="")}i=i.filter((function(e){return e.id!==a.id}));break;case r:i=i.filter((function(e){return e.id!==t.choice.id}));break;case p:var l=t;i.forEach((function(e){e.id===l.item.id&&(e.highlighted=l.highlighted)}));break;default:n=!1}return{state:i,update:n}},choices:function(e,t){var i=e,n=!0;switch(t.type){case o:i.push(t.choice);break;case r:i=i.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:break;case a:var s=[];t.results.forEach((function(e){s[e.item.id]=e})),i.forEach((function(e){var t=s[e.id];void 0!==t?(e.score=t.score,e.rank=t.rank,e.active=!0):(e.score=0,e.rank=0,e.active=!1)}));break;case c:i.forEach((function(e){e.active=t.active}));break;case l:i=[];break;default:n=!1}return{state:i,update:n}}},G=function(){function e(){this._state=this.defaultState,this._listeners=[],this._txn=0}return Object.defineProperty(e.prototype,"defaultState",{get:function(){return{groups:[],items:[],choices:[]}},enumerable:!1,configurable:!0}),e.prototype.changeSet=function(e){return{groups:e,items:e,choices:e}},e.prototype.reset=function(){this._state=this.defaultState;var e=this.changeSet(!0);this._txn?this._changeSet=e:this._listeners.forEach((function(t){return t(e)}))},e.prototype.subscribe=function(e){this._listeners.push(e)},e.prototype.dispatch=function(e){var t=this._state,i=!1,n=this._changeSet||this.changeSet(!1);Object.keys(q).forEach((function(s){var o=q[s](t[s],e);o.update&&(i=!0,n[s]=!0,t[s]=o.state)})),i&&(this._txn?this._changeSet=n:this._listeners.forEach((function(e){return e(n)})))},e.prototype.withTxn=function(e){this._txn++;try{e()}finally{if(this._txn=Math.max(0,this._txn-1),!this._txn){var t=this._changeSet;t&&(this._changeSet=void 0,this._listeners.forEach((function(e){return e(t)})))}}},Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"items",{get:function(){return this.state.items},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"highlightedActiveItems",{get:function(){return this.items.filter((function(e){return!e.disabled&&e.active&&e.highlighted}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"choices",{get:function(){return this.state.choices},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeChoices",{get:function(){return this.choices.filter((function(e){return e.active}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"searchableChoices",{get:function(){return this.choices.filter((function(e){return!e.disabled&&!e.placeholder}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"groups",{get:function(){return this.state.groups},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeGroups",{get:function(){var e=this;return this.state.groups.filter((function(t){var i=t.active&&!t.disabled,n=e.state.choices.some((function(e){return e.active&&!e.disabled}));return i&&n}),[])},enumerable:!1,configurable:!0}),e.prototype.inTxn=function(){return this._txn>0},e.prototype.getChoiceById=function(e){return this.activeChoices.find((function(t){return t.id===e}))},e.prototype.getGroupById=function(e){return this.groups.find((function(t){return t.id===e}))},e}(),U="no-choices",W="no-results",$="add-choice";function J(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function z(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function X(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?z(Object(i),!0).forEach((function(t){J(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):z(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function Q(e){return Array.isArray?Array.isArray(e):"[object Array]"===ne(e)}function Y(e){return"string"==typeof e}function Z(e){return"number"==typeof e}function ee(e){return"object"==typeof e}function te(e){return null!=e}function ie(e){return!e.trim().length}function ne(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}const se=e=>`Missing ${e} property in key`,oe=e=>`Property 'weight' in key '${e}' must be a positive integer`,re=Object.prototype.hasOwnProperty;class ae{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let i=ce(e);this._keys.push(i),this._keyMap[i.id]=i,t+=i.weight})),this._keys.forEach((e=>{e.weight/=t}))}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ce(e){let t=null,i=null,n=null,s=1,o=null;if(Y(e)||Q(e))n=e,t=le(e),i=he(e);else{if(!re.call(e,"name"))throw new Error(se("name"));const r=e.name;if(n=r,re.call(e,"weight")&&(s=e.weight,s<=0))throw new Error(oe(r));t=le(r),i=he(r),o=e.getFn}return{path:t,id:i,weight:s,src:n,getFn:o}}function le(e){return Q(e)?e:e.split(".")}function he(e){return Q(e)?e.join("."):e}const ue={useExtendedSearch:!1,getFn:function(e,t){let i=[],n=!1;const s=(e,t,o)=>{if(te(e))if(t[o]){const r=e[t[o]];if(!te(r))return;if(o===t.length-1&&(Y(r)||Z(r)||function(e){return!0===e||!1===e||function(e){return ee(e)&&null!==e}(e)&&"[object Boolean]"==ne(e)}(r)))i.push(function(e){return null==e?"":function(e){if("string"==typeof e)return e;let t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(e)}(r));else if(Q(r)){n=!0;for(let e=0,i=r.length;e<i;e+=1)s(r[e],t,o+1)}else t.length&&s(r,t,o+1)}else i.push(e)};return s(e,Y(t)?t.split("."):t,0),n?i:i[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var de=X(X(X(X({},{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1}),{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1}),{location:0,threshold:.6,distance:100}),ue);const pe=/[^ ]+/g;class me{constructor({getFn:e=de.getFn,fieldNormWeight:t=de.fieldNormWeight}={}){this.norm=function(e=1,t=3){const i=new Map,n=Math.pow(10,t);return{get(t){const s=t.match(pe).length;if(i.has(s))return i.get(s);const o=1/Math.pow(s,.5*e),r=parseFloat(Math.round(o*n)/n);return i.set(s,r),r},clear(){i.clear()}}}(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach(((e,t)=>{this._keysMap[e.id]=t}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,Y(this.docs[0])?this.docs.forEach(((e,t)=>{this._addString(e,t)})):this.docs.forEach(((e,t)=>{this._addObject(e,t)})),this.norm.clear())}add(e){const t=this.size();Y(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,i=this.size();t<i;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!te(e)||ie(e))return;let i={v:e,i:t,n:this.norm.get(e)};this.records.push(i)}_addObject(e,t){let i={i:t,$:{}};this.keys.forEach(((t,n)=>{let s=t.getFn?t.getFn(e):this.getFn(e,t.path);if(te(s))if(Q(s)){let e=[];const t=[{nestedArrIndex:-1,value:s}];for(;t.length;){const{nestedArrIndex:i,value:n}=t.pop();if(te(n))if(Y(n)&&!ie(n)){let t={v:n,i:i,n:this.norm.get(n)};e.push(t)}else Q(n)&&n.forEach(((e,i)=>{t.push({nestedArrIndex:i,value:e})}))}i.$[n]=e}else if(Y(s)&&!ie(s)){let e={v:s,n:this.norm.get(s)};i.$[n]=e}})),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function fe(e,t,{getFn:i=de.getFn,fieldNormWeight:n=de.fieldNormWeight}={}){const s=new me({getFn:i,fieldNormWeight:n});return s.setKeys(e.map(ce)),s.setSources(t),s.create(),s}function ve(e,{errors:t=0,currentLocation:i=0,expectedLocation:n=0,distance:s=de.distance,ignoreLocation:o=de.ignoreLocation}={}){const r=t/e.length;if(o)return r;const a=Math.abs(n-i);return s?r+a/s:a?1:r}const _e=32;function ge(e){let t={};for(let i=0,n=e.length;i<n;i+=1){const s=e.charAt(i);t[s]=(t[s]||0)|1<<n-i-1}return t}class ye{constructor(e,{location:t=de.location,threshold:i=de.threshold,distance:n=de.distance,includeMatches:s=de.includeMatches,findAllMatches:o=de.findAllMatches,minMatchCharLength:r=de.minMatchCharLength,isCaseSensitive:a=de.isCaseSensitive,ignoreLocation:c=de.ignoreLocation}={}){if(this.options={location:t,threshold:i,distance:n,includeMatches:s,findAllMatches:o,minMatchCharLength:r,isCaseSensitive:a,ignoreLocation:c},this.pattern=a?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const l=(e,t)=>{this.chunks.push({pattern:e,alphabet:ge(e),startIndex:t})},h=this.pattern.length;if(h>_e){let e=0;const t=h%_e,i=h-t;for(;e<i;)l(this.pattern.substr(e,_e),e),e+=_e;if(t){const e=h-_e;l(this.pattern.substr(e),e)}}else l(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,includeMatches:i}=this.options;if(t||(e=e.toLowerCase()),this.pattern===e){let t={isMatch:!0,score:0};return i&&(t.indices=[[0,e.length-1]]),t}const{location:n,distance:s,threshold:o,findAllMatches:r,minMatchCharLength:a,ignoreLocation:c}=this.options;let l=[],h=0,u=!1;this.chunks.forEach((({pattern:t,alphabet:d,startIndex:p})=>{const{isMatch:m,score:f,indices:v}=function(e,t,i,{location:n=de.location,distance:s=de.distance,threshold:o=de.threshold,findAllMatches:r=de.findAllMatches,minMatchCharLength:a=de.minMatchCharLength,includeMatches:c=de.includeMatches,ignoreLocation:l=de.ignoreLocation}={}){if(t.length>_e)throw new Error("Pattern length exceeds max of 32.");const h=t.length,u=e.length,d=Math.max(0,Math.min(n,u));let p=o,m=d;const f=a>1||c,v=f?Array(u):[];let _;for(;(_=e.indexOf(t,m))>-1;){let e=ve(t,{currentLocation:_,expectedLocation:d,distance:s,ignoreLocation:l});if(p=Math.min(e,p),m=_+h,f){let e=0;for(;e<h;)v[_+e]=1,e+=1}}m=-1;let g=[],y=1,b=h+u;const E=1<<h-1;for(let n=0;n<h;n+=1){let o=0,a=b;for(;o<a;)ve(t,{errors:n,currentLocation:d+a,expectedLocation:d,distance:s,ignoreLocation:l})<=p?o=a:b=a,a=Math.floor((b-o)/2+o);b=a;let c=Math.max(1,d-a+1),_=r?u:Math.min(d+a,u)+h,w=Array(_+2);w[_+1]=(1<<n)-1;for(let o=_;o>=c;o-=1){let r=o-1,a=i[e.charAt(r)];if(f&&(v[r]=+!!a),w[o]=(w[o+1]<<1|1)&a,n&&(w[o]|=(g[o+1]|g[o])<<1|1|g[o+1]),w[o]&E&&(y=ve(t,{errors:n,currentLocation:r,expectedLocation:d,distance:s,ignoreLocation:l}),y<=p)){if(p=y,m=r,m<=d)break;c=Math.max(1,2*d-m)}}if(ve(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:s,ignoreLocation:l})>p)break;g=w}const w={isMatch:m>=0,score:Math.max(.001,y)};if(f){const e=function(e=[],t=de.minMatchCharLength){let i=[],n=-1,s=-1,o=0;for(let r=e.length;o<r;o+=1){let r=e[o];r&&-1===n?n=o:r||-1===n||(s=o-1,s-n+1>=t&&i.push([n,s]),n=-1)}return e[o-1]&&o-n>=t&&i.push([n,o-1]),i}(v,a);e.length?c&&(w.indices=e):w.isMatch=!1}return w}(e,t,d,{location:n+p,distance:s,threshold:o,findAllMatches:r,minMatchCharLength:a,includeMatches:i,ignoreLocation:c});m&&(u=!0),h+=f,m&&v&&(l=[...l,...v])}));let d={isMatch:u,score:u?h/this.chunks.length:1};return u&&i&&(d.indices=l),d}}const be=[];function Ee(e,t){for(let i=0,n=be.length;i<n;i+=1){let n=be[i];if(n.condition(e,t))return new n(e,t)}return new ye(e,t)}const we="$and",Se="$path",Ce=e=>!(!e[we]&&!e.$or),Ie=e=>({[we]:Object.keys(e).map((t=>({[t]:e[t]})))});function Ae(e,t){const i=e.matches;t.matches=[],te(i)&&i.forEach((e=>{if(!te(e.indices)||!e.indices.length)return;const{indices:i,value:n}=e;let s={indices:i,value:n};e.key&&(s.key=e.key.src),e.idx>-1&&(s.refIndex=e.idx),t.matches.push(s)}))}function Oe(e,t){t.score=e.score}class Le{constructor(e,t={},i){if(this.options=X(X({},de),t),this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new ae(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof me))throw new Error("Incorrect 'index' type");this._myIndex=t||fe(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){te(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let i=0,n=this._docs.length;i<n;i+=1){const s=this._docs[i];e(s,i)&&(this.removeAt(i),i-=1,n-=1,t.push(s))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:i,includeScore:n,shouldSort:s,sortFn:o,ignoreFieldNorm:r}=this.options;let a=Y(e)?Y(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return function(e,{ignoreFieldNorm:t=de.ignoreFieldNorm}){e.forEach((e=>{let i=1;e.matches.forEach((({key:e,norm:n,score:s})=>{const o=e?e.weight:null;i*=Math.pow(0===s&&o?Number.EPSILON:s,(o||1)*(t?1:n))})),e.score=i}))}(a,{ignoreFieldNorm:r}),s&&a.sort(o),Z(t)&&t>-1&&(a=a.slice(0,t)),function(e,t,{includeMatches:i=de.includeMatches,includeScore:n=de.includeScore}={}){const s=[];return i&&s.push(Ae),n&&s.push(Oe),e.map((e=>{const{idx:i}=e,n={item:t[i],refIndex:i};return s.length&&s.forEach((t=>{t(e,n)})),n}))}(a,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(e){const t=Ee(e,this.options),{records:i}=this._myIndex,n=[];return i.forEach((({v:e,i:i,n:s})=>{if(!te(e))return;const{isMatch:o,score:r,indices:a}=t.searchIn(e);o&&n.push({item:e,idx:i,matches:[{score:r,value:e,norm:s,indices:a}]})})),n}_searchLogical(e){throw new Error("Logical search is not available")}_searchObjectList(e){const t=Ee(e,this.options),{keys:i,records:n}=this._myIndex,s=[];return n.forEach((({$:e,i:n})=>{if(!te(e))return;let o=[];i.forEach(((i,n)=>{o.push(...this._findMatches({key:i,value:e[n],searcher:t}))})),o.length&&s.push({idx:n,item:e,matches:o})})),s}_findMatches({key:e,value:t,searcher:i}){if(!te(t))return[];let n=[];if(Q(t))t.forEach((({v:t,i:s,n:o})=>{if(!te(t))return;const{isMatch:r,score:a,indices:c}=i.searchIn(t);r&&n.push({score:a,key:e,value:t,idx:s,norm:o,indices:c})}));else{const{v:s,n:o}=t,{isMatch:r,score:a,indices:c}=i.searchIn(s);r&&n.push({score:a,key:e,value:s,norm:o,indices:c})}return n}}Le.version="7.0.0",Le.createIndex=fe,Le.parseIndex=function(e,{getFn:t=de.getFn,fieldNormWeight:i=de.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new me({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},Le.config=de,Le.parseQuery=function(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Se])(e);if(!o&&s.length>1&&!Ce(e))return n(Ie(e));if((e=>!Q(e)&&ee(e)&&!Ce(e))(e)){const n=o?e[Se]:s[0],r=o?e.$val:e[n];if(!Y(r))throw new Error((e=>`Invalid value for key ${e}`)(n));const a={keyId:he(n),pattern:r};return i&&(a.searcher=Ee(r,t)),a}let r={children:[],operator:s[0]};return s.forEach((t=>{const i=e[t];Q(i)&&i.forEach((e=>{r.children.push(n(e))}))})),r};return Ce(e)||(e=Ie(e)),n(e)};var xe=function(){function e(e){this._haystack=[],this._fuseOptions=i(i({},e.fuseOptions),{keys:n([],e.searchFields,!0),includeMatches:!0})}return e.prototype.index=function(e){this._haystack=e,this._fuse&&this._fuse.setCollection(e)},e.prototype.reset=function(){this._haystack=[],this._fuse=void 0},e.prototype.isEmptyIndex=function(){return!this._haystack.length},e.prototype.search=function(e){return this._fuse||(this._fuse=new Le(this._haystack,this._fuseOptions)),this._fuse.search(e).map((function(e,t){return{item:e.item,score:e.score||0,rank:t+1}}))},e}(),Te=function(e,t,i){var n=e.dataset,s=t.customProperties,o=t.labelClass,r=t.labelDescription;o&&(n.labelClass=I(o).join(" ")),r&&(n.labelDescription=r),i&&s&&("string"==typeof s?n.customProperties=s:"object"!=typeof s||function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}(s)||(n.customProperties=JSON.stringify(s)))},Ne=function(e,t,i){var n=t&&e.querySelector("label[for='".concat(t,"']")),s=n&&n.innerText;s&&i.setAttribute("aria-label",s)},Fe={containerOuter:function(e,t,i,n,s,o,r){var a=e.classNames.containerOuter,c=document.createElement("div");return c.className=I(a).join(" "),c.dataset.type=o,t&&(c.dir=t),n&&(c.tabIndex=0),i&&(c.setAttribute("role",s?"combobox":"listbox"),s?c.setAttribute("aria-autocomplete","list"):r||Ne(this._docRoot,this.passedElement.element.id,c),c.setAttribute("aria-haspopup","true"),c.setAttribute("aria-expanded","false")),r&&c.setAttribute("aria-labelledby",r),c},containerInner:function(e){var t=e.classNames.containerInner,i=document.createElement("div");return i.className=I(t).join(" "),i},itemList:function(e,t){var i=e.searchEnabled,n=e.classNames,s=n.list,o=n.listSingle,r=n.listItems,a=document.createElement("div");return a.className="".concat(I(s).join(" ")," ").concat(t?I(o).join(" "):I(r).join(" ")),this._isSelectElement&&i&&a.setAttribute("role","listbox"),a},placeholder:function(e,t){var i=e.allowHTML,n=e.classNames.placeholder,s=document.createElement("div");return s.className=I(n).join(" "),S(s,i,t),s},item:function(e,t,i){var n,s,o,r=e.allowHTML,a=e.removeItemButtonAlignLeft,c=e.removeItemIconText,l=e.removeItemLabelText,h=e.classNames,u=h.item,d=h.button,p=h.highlightedState,m=h.itemSelectable,f=h.placeholder,v=t.labelClass,_=t.label,g=t.disabled,b=t.value,w=E(b),C=document.createElement("div");if(C.className=I(u).join(" "),v){var A=document.createElement("span");S(A,r,_),A.className=I(v).join(" "),C.appendChild(A)}else S(C,r,_);var O=C.dataset;if(O.item="",O.id=t.id,O.value=w,Te(C,t,!0),(g||this.containerOuter.isDisabled)&&C.setAttribute("aria-disabled","true"),this._isSelectElement&&(C.setAttribute("aria-selected","true"),C.setAttribute("role","option")),t.placeholder&&((n=C.classList).add.apply(n,I(f)),O.placeholder=""),(s=C.classList).add.apply(s,I(t.highlighted?p:m)),i){g&&(o=C.classList).remove.apply(o,I(m)),O.deletable="";var L=document.createElement("button");L.type="button",L.className=I(d).join(" "),S(L,!0,y(c,b));var x=y(l,b);x&&L.setAttribute("aria-label",x),L.dataset.button="",a?C.insertAdjacentElement("afterbegin",L):C.appendChild(L)}return C},choiceList:function(e,t){var i=e.classNames.list,n=document.createElement("div");return n.className=I(i).join(" "),t||n.setAttribute("aria-multiselectable","true"),n.setAttribute("role","listbox"),n},choiceGroup:function(e,t){var i=e.allowHTML,n=e.classNames,s=n.group,o=n.groupHeading,r=n.itemDisabled,a=t.id,c=t.label,l=t.disabled,h=E(c),u=document.createElement("div");u.className="".concat(I(s).join(" ")," ").concat(l?I(r).join(" "):""),u.setAttribute("role","group");var d=u.dataset;d.group="",d.id=a,d.value=h,l&&u.setAttribute("aria-disabled","true");var p=document.createElement("div");return p.className=I(o).join(" "),S(p,i,c),u.appendChild(p),u},choice:function(e,t,i){var n,s,o,r,a,c=e.allowHTML,l=e.classNames,h=l.item,u=l.itemChoice,d=l.itemSelectable,p=l.selectedState,m=l.itemDisabled,f=l.description,v=l.placeholder,_=t.elementId,g=t.groupId,y=t.label,b=t.labelClass,w=t.labelDescription,C=E(t.value),A=document.createElement("div");A.id=_,A.className="".concat(I(h).join(" ")," ").concat(I(u).join(" "));var O=A;if(b){var L=document.createElement("span");S(L,c,y),L.className=I(b).join(" "),O=L,A.appendChild(L)}else S(A,c,y);if(w){var x="".concat(_,"-description");O.setAttribute("aria-describedby",x);var T=document.createElement("span");S(T,c,w),T.id=x,(n=T.classList).add.apply(n,I(f)),A.appendChild(T)}t.selected&&(s=A.classList).add.apply(s,I(p)),t.placeholder&&(o=A.classList).add.apply(o,I(v));var N=A.dataset,F=g&&g>0;return A.setAttribute("role",F?"treeitem":"option"),F&&(N.groupId="".concat(g)),N.choice="",N.id=t.id,N.value=C,N.selectText=i,Te(A,t,!1),t.disabled?((r=A.classList).add.apply(r,I(m)),N.choiceDisabled="",A.setAttribute("aria-disabled","true")):((a=A.classList).add.apply(a,I(d)),N.choiceSelectable=""),A},input:function(e,t){var i=e.classNames,n=i.input,s=i.inputCloned,o=e.labelId,r=document.createElement("input");return r.type="search",r.className="".concat(I(n).join(" ")," ").concat(I(s).join(" ")),r.autocomplete="off",r.autocapitalize="off",r.spellcheck=!1,r.setAttribute("role","textbox"),r.setAttribute("aria-autocomplete","list"),t?r.setAttribute("aria-label",t):o||Ne(this._docRoot,this.passedElement.element.id,r),r},dropdown:function(e){var t,i,n=e.classNames,s=n.list,o=n.listDropdown,r=document.createElement("div");return(t=r.classList).add.apply(t,I(s)),(i=r.classList).add.apply(i,I(o)),r.setAttribute("aria-expanded","false"),r},notice:function(e,t,i){var s=e.classNames,o=s.itemChoice,r=s.addChoice,a=s.noResults,c=s.noChoices,l=s.notice;void 0===i&&(i="");var h=n(n(n([],I(s.item),!0),I(o),!0),I(l),!0);switch(i){case $:h.push.apply(h,I(r));break;case W:h.push.apply(h,I(a));break;case U:h.push.apply(h,I(c))}var u=document.createElement("div");if(S(u,!0,t),u.className=h.join(" "),i===$){var d=u.dataset;d.choiceSelectable="",d.choice=""}return u},option:function(e){var t=E(e.label),i=new Option(t,e.value,!1,e.selected);return Te(i,e,!0),i.disabled=e.disabled,e.selected&&i.setAttribute("selected",""),i}},Me="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,De={},ke=function(e){if(e){var t=e.dataset.id;return t?parseInt(t,10):void 0}};return function(){function e(t,n){void 0===t&&(t="[data-choice]"),void 0===n&&(n={});var s=this;this.initialisedOK=void 0,this._hasNonChoicePlaceholder=!1,this._lastAddedChoiceId=0,this._lastAddedGroupId=0;var o=e.defaults;this.config=i(i(i({},o.allOptions),o.options),n),m.forEach((function(e){s.config[e]=i(i(i({},o.allOptions[e]),o.options[e]),n[e])}));var r=this.config;r.silent||this._validateConfig();var a=r.shadowRoot||document.documentElement;this._docRoot=a;var c="string"==typeof t?a.querySelector(t):t;if(!c||"object"!=typeof c||"INPUT"!==c.tagName&&!H(c)){if(!c&&"string"==typeof t)throw TypeError("Selector ".concat(t," failed to find an element"));throw TypeError("Expected one of the following types text|select-one|select-multiple")}if(this._elementType=c.type,this._isTextElement=this._elementType===x,(this._isTextElement||1!==r.maxItemCount)&&(r.singleModeForMultiSelect=!1),r.singleModeForMultiSelect&&(this._elementType=N),this._isSelectOneElement=this._elementType===T,this._isSelectMultipleElement=this._elementType===N,this._isSelectElement=this._isSelectOneElement||this._isSelectMultipleElement,this._canAddUserChoices=this._isTextElement&&r.addItems||this._isSelectElement&&r.addChoices,["auto","always"].includes("".concat(r.renderSelectedChoices))||(r.renderSelectedChoices="auto"),r.closeDropdownOnSelect="auto"===r.closeDropdownOnSelect?this._isTextElement||this._isSelectOneElement||r.singleModeForMultiSelect:j(r.closeDropdownOnSelect),r.placeholder&&(r.placeholderValue?this._hasNonChoicePlaceholder=!0:c.dataset.placeholder&&(this._hasNonChoicePlaceholder=!0,r.placeholderValue=c.dataset.placeholder)),n.addItemFilter&&"function"!=typeof n.addItemFilter){var l=n.addItemFilter instanceof RegExp?n.addItemFilter:new RegExp(n.addItemFilter);r.addItemFilter=l.test.bind(l)}if(this.passedElement=this._isTextElement?new P({element:c,classNames:r.classNames}):new V({element:c,classNames:r.classNames,template:function(e){return s._templates.option(e)},extractPlaceholder:r.placeholder&&!this._hasNonChoicePlaceholder}),this.initialised=!1,this._store=new G,this._currentValue="",r.searchEnabled=!this._isTextElement&&r.searchEnabled||this._elementType===N,this._canSearch=r.searchEnabled,this._isScrollingOnIe=!1,this._highlightPosition=0,this._wasTap=!0,this._placeholderValue=this._generatePlaceholderValue(),this._baseId=function(e){var t=e.id||e.name&&"".concat(e.name,"-").concat(v(2))||v(4);return t=t.replace(/(:|\.|\[|\]|,)/g,""),"".concat("choices-","-").concat(t)}(c),this._direction=this.passedElement.dir,!this._direction){var h=window.getComputedStyle(this.passedElement.element).direction;h!==window.getComputedStyle(document.documentElement).direction&&(this._direction=h)}if(this._idNames={itemChoice:"item-choice"},this._templates=o.templates,this._render=this._render.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onInput=this._onInput.bind(this),this._onClick=this._onClick.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this._onFormReset=this._onFormReset.bind(this),this._onSelectKey=this._onSelectKey.bind(this),this._onEnterKey=this._onEnterKey.bind(this),this._onEscapeKey=this._onEscapeKey.bind(this),this._onDirectionKey=this._onDirectionKey.bind(this),this._onDeleteKey=this._onDeleteKey.bind(this),this.passedElement.isActive)return r.silent||console.warn("Trying to initialise Choices on element already initialised",{element:t}),this.initialised=!0,void(this.initialisedOK=!1);this.init(),this._initialItems=this._store.items.map((function(e){return e.value}))}return Object.defineProperty(e,"defaults",{get:function(){return Object.preventExtensions({get options(){return De},get allOptions(){return R},get templates(){return Fe}})},enumerable:!1,configurable:!0}),e.prototype.init=function(){if(!this.initialised&&void 0===this.initialisedOK){this._searcher=new xe(this.config),this._loadChoices(),this._createTemplates(),this._createElements(),this._createStructure(),this._isTextElement&&!this.config.addItems||this.passedElement.element.hasAttribute("disabled")||this.passedElement.element.closest("fieldset:disabled")?this.disable():(this.enable(),this._addEventListeners()),this._initStore(),this.initialised=!0,this.initialisedOK=!0;var e=this.config.callbackOnInit;e&&"function"==typeof e&&e.call(this)}},e.prototype.destroy=function(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this._store._listeners=[],this.clearStore(),this._stopSearch(),this._templates=e.defaults.templates,this.initialised=!1,this.initialisedOK=void 0)},e.prototype.enable=function(){var e=this.passedElement,t=this.containerOuter;return e.isDisabled&&e.enable(),t.isDisabled&&(this._addEventListeners(),this.input.enable(),t.enable(),this._render()),this},e.prototype.disable=function(){var e=this.passedElement,t=this.containerOuter;return e.isDisabled||e.disable(),t.isDisabled||(this._removeEventListeners(),this.input.disable(),t.disable(),this._render()),this},e.prototype.highlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.choices.find((function(t){return t.id===e.id}));return!i||i.highlighted||(this._store.dispatch(f(i,!0)),t&&this.passedElement.triggerEvent("highlightItem",this._getChoiceForOutput(i))),this},e.prototype.unhighlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.choices.find((function(t){return t.id===e.id}));return i&&i.highlighted?(this._store.dispatch(f(i,!1)),t&&this.passedElement.triggerEvent("highlightItem",this._getChoiceForOutput(i)),this):this},e.prototype.highlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){return e.highlightItem(t)}))})),this},e.prototype.unhighlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){return e.unhighlightItem(t)}))})),this},e.prototype.removeActiveItemsByValue=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.value===e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeActiveItems=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.id!==e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeHighlightedItems=function(e){var t=this;return void 0===e&&(e=!1),this._store.withTxn((function(){t._store.highlightedActiveItems.forEach((function(i){t._removeItem(i),e&&t._triggerChange(i.value)}))})),this},e.prototype.showDropdown=function(e){var t=this;return this.dropdown.isActive||requestAnimationFrame((function(){t.dropdown.show(),t.containerOuter.open(t.dropdown.distanceFromTopWindow),!e&&t._canSearch&&t.input.focus(),t.passedElement.triggerEvent("showDropdown")})),this},e.prototype.hideDropdown=function(e){var t=this;return this.dropdown.isActive?(requestAnimationFrame((function(){t.dropdown.hide(),t.containerOuter.close(),!e&&t._canSearch&&(t.input.removeActiveDescendant(),t.input.blur()),t.passedElement.triggerEvent("hideDropdown")})),this):this},e.prototype.getValue=function(e){var t=this;void 0===e&&(e=!1);var i=this._store.items.reduce((function(i,n){var s=e?n.value:t._getChoiceForOutput(n);return i.push(s),i}),[]);return this._isSelectOneElement||this.config.singleModeForMultiSelect?i[0]:i},e.prototype.setValue=function(e){var t=this;return this.initialisedOK?(this._store.withTxn((function(){e.forEach((function(e){e&&t._addChoice(B(e,!1))}))})),this._searcher.reset(),this):(this._warnChoicesInitFailed("setValue"),this)},e.prototype.setChoiceByValue=function(e){var t=this;return this.initialisedOK?(this._isTextElement||(this._store.withTxn((function(){(Array.isArray(e)?e:[e]).forEach((function(e){return t._findAndSelectChoiceByValue(e)}))})),this._searcher.reset()),this):(this._warnChoicesInitFailed("setChoiceByValue"),this)},e.prototype.setChoices=function(e,t,n,s){var o=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===n&&(n="label"),void 0===s&&(s=!1),!this.initialisedOK)return this._warnChoicesInitFailed("setChoices"),this;if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(s&&this.clearChoices(),"function"==typeof e){var r=e(this);if("function"==typeof Promise&&r instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return o._handleLoadingState(!0)})).then((function(){return r})).then((function(e){return o.setChoices(e,t,n,s)})).catch((function(e){o.config.silent||console.error(e)})).then((function(){return o._handleLoadingState(!1)})).then((function(){return o}));if(!Array.isArray(r))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof r));return this.setChoices(r,t,n,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._store.withTxn((function(){var s="value"===t,r="label"===n;e.forEach((function(e){if("choices"in e){var a=e;r||(a=i(i({},a),{label:a[n]})),o._addGroup(B(a,!0))}else{var c=e;r&&s||(c=i(i({},c),{value:c[t],label:c[n]})),o._addChoice(B(c,!1))}}))})),this._searcher.reset(),this},e.prototype.refresh=function(e,t,i){var n=this;return void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===i&&(i=!1),this._isSelectElement?(this._store.withTxn((function(){var s=n.passedElement.optionsAsChoices(),o={};i||n._store.items.forEach((function(e){e.id&&e.active&&e.selected&&!e.disabled&&(o[e.value]=!0)})),s.forEach((function(e){if(!("choices"in e)){var t=e;i?t.selected=!1:o[t.value]&&(t.selected=!0)}})),n.clearStore(),n._addPredefinedChoices(s,t,e),n._isSearching&&n._searchChoices(n.input.value)})),this):(this.config.silent||console.warn("refresh method can only be used on choices backed by a <select> element"),this)},e.prototype.removeChoice=function(e){var t=this._store.choices.find((function(t){return t.value===e}));return t?(this._store.dispatch(function(e){return{type:r,choice:e}}(t)),this._searcher.reset(),t.selected&&this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(t)),this):this},e.prototype.clearChoices=function(){return this.passedElement.element.innerHTML="",this._store.dispatch({type:l}),this._searcher.reset(),this},e.prototype.clearStore=function(){return this._store.reset(),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this._searcher.reset(),this},e.prototype.clearInput=function(){return this.input.clear(!this._isSelectOneElement),this._clearNotice(),this._isSearching&&this._stopSearch(),this},e.prototype._validateConfig=function(){var e,t,i,n=this.config,s=(e=R,t=Object.keys(n).sort(),i=Object.keys(e).sort(),t.filter((function(e){return i.indexOf(e)<0})));s.length&&console.warn("Unknown config option(s) passed",s.join(", ")),n.allowHTML&&n.allowHtmlUserInput&&(n.addItems&&console.warn("Warning: allowHTML/allowHtmlUserInput/addItems all being true is strongly not recommended and may lead to XSS attacks"),n.addChoices&&console.warn("Warning: allowHTML/allowHtmlUserInput/addChoices all being true is strongly not recommended and may lead to XSS attacks"))},e.prototype._render=function(e){void 0===e&&(e={choices:!0,groups:!0,items:!0}),this._store.inTxn()||(this._isSelectElement&&(e.choices||e.groups)&&this._renderChoices(),e.items&&this._renderItems())},e.prototype._renderChoices=function(){var e=this;if(this.choiceList.clear(),this._canAddItems()){var t=this.config,i=this._store,n=i.activeGroups,s=i.activeChoices,o=document.createDocumentFragment(),r=!0;if(s.length){if(t.resetScrollPosition&&requestAnimationFrame((function(){return e.choiceList.scrollToTop()})),n.length&&!this._isSearching){if(!this._hasNonChoicePlaceholder){var a=s.filter((function(e){return e.placeholder&&-1===e.groupId}));a.length&&(o=this._createChoicesFragment(a,o))}o=this._createGroupsFragment(n,s,o)}else o=this._createChoicesFragment(s,o);r=!o.childNodes.length}var c=this._notice;r?c||(this._notice={text:b(t.noChoicesText),type:U}):c&&c.type===U&&(this._notice=void 0),this._renderNotice(),r||(this.choiceList.element.append(o),this._highlightChoice())}},e.prototype._renderItems=function(){var e=this._store.items||[];this.itemList.clear();var t=this._createItemsFragment(e);t.childNodes.length&&this.itemList.element.append(t)},e.prototype._createGroupsFragment=function(e,t,i){var n=this;void 0===i&&(i=document.createDocumentFragment());var s=this.config;s.shouldSort&&e.sort(s.sorter);var o=t.filter((function(e){return!e.groupId}));return o.length&&this._createChoicesFragment(o,i,!1),e.forEach((function(e){var o=function(e){return t.filter((function(t){return n._isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===s.renderSelectedChoices||!t.selected)}))}(e);if(o.length){var r=n._templates.choiceGroup(n.config,e);i.appendChild(r),n._createChoicesFragment(o,i,!0)}})),i},e.prototype._createChoicesFragment=function(e,t,i){var s=this;void 0===t&&(t=document.createDocumentFragment()),void 0===i&&(i=!1);var o=this,r=o.config,a=o._isSearching,c=o._isSelectOneElement,l=r.searchResultLimit,h=r.renderChoiceLimit,u=[],d=r.appendGroupInSearch&&a;if(d&&this._store.groups.forEach((function(e){u[e.id]=e.label})),this._isSelectElement){var p=e.filter((function(e){return!e.element}));p.length&&this.passedElement.addOptions(p)}var m="auto"===r.renderSelectedChoices&&!c,f=[],v=[];e.forEach((function(e){a&&!e.rank||m&&e.selected||(s._hasNonChoicePlaceholder||!e.placeholder?v.push(e):f.push(e))})),a?v.sort(C):r.shouldSort&&v.sort(r.sorter);var _=c&&f.length?n(n([],f,!0),v,!0):v,g=_.length,y=g;return a&&l>0?y=l:h>0&&!i&&(y=h),y<g&&(g=y),g--,_.every((function(e,i){var n=s._templates.choice(r,e,r.itemSelectText);if(d&&e.groupId>0){var o=u[e.groupId];o&&(n.innerHTML+=" (".concat(o,")"))}return t.appendChild(n),i<g})),t},e.prototype._createItemsFragment=function(e,t){var i=this;void 0===t&&(t=document.createDocumentFragment());var n=this.config,s=n.removeItemButton,o=n.delimiter;n.shouldSortItems&&!this._isSelectOneElement&&e.sort(n.sorter),this._isTextElement&&(this.passedElement.value=e.map((function(e){return e.value})).join(o));var r=function(e){var o=i._templates.item(n,e,s);t.appendChild(o)};return e.forEach(r),this._isSelectOneElement&&this._hasNonChoicePlaceholder&&!e.length&&r(B({selected:!0,value:"",label:this.config.placeholderValue||"",active:!0,placeholder:!0},!1)),t},e.prototype._displayNotice=function(e,t,i){void 0===i&&(i=!0);var n=this._notice;n&&(n.type===t&&n.text===e||n.type===$&&(t===W||t===U))?i&&this.showDropdown(!0):(this._clearNotice(),this._notice=e?{text:e,type:t}:void 0,this._renderNotice(),i&&e&&this.showDropdown(!0))},e.prototype._clearNotice=function(){if(this._notice){var e=this.choiceList.element.querySelector(A(this.config.classNames.notice));e&&e.remove(),this._notice=void 0}},e.prototype._renderNotice=function(){var e=this._notice;if(e){var t=this._templates.notice(this.config,e.text,e.type);this.choiceList.prepend(t)}},e.prototype._getChoiceForOutput=function(e,t){if(e){var i=e.groupId>0?this._store.getGroupById(e.groupId):null;return{id:e.id,highlighted:e.highlighted,labelClass:e.labelClass,labelDescription:e.labelDescription,customProperties:e.customProperties,disabled:e.disabled,active:e.active,label:e.label,placeholder:e.placeholder,value:e.value,groupValue:i&&i.label?i.label:void 0,element:e.element,keyCode:t}}},e.prototype._triggerChange=function(e){null!=e&&this.passedElement.triggerEvent("change",{value:e})},e.prototype._handleButtonAction=function(e){var t=this._store.items;if(t.length&&this.config.removeItems&&this.config.removeItemButton){var i=e&&ke(e.parentNode),n=i&&t.find((function(e){return e.id===i}));if(n&&(this._removeItem(n),this._triggerChange(n.value),this._isSelectOneElement&&!this._hasNonChoicePlaceholder)){var s=this._store.choices.reverse().find((function(e){return!e.disabled&&e.placeholder}));s&&(this._addItem(s),s.value&&this._triggerChange(s.value))}}},e.prototype._handleItemAction=function(e,t){var i=this;void 0===t&&(t=!1);var n=this._store.items;if(n.length&&this.config.removeItems&&!this._isSelectOneElement){var s=ke(e);s&&(n.forEach((function(e){e.id!==s||e.highlighted?!t&&e.highlighted&&i.unhighlightItem(e):i.highlightItem(e)})),this.input.focus())}},e.prototype._handleChoiceAction=function(e){var t=this,i=ke(e),n=i&&this._store.getChoiceById(i);if(!n||n.disabled)return!1;var s=this.dropdown.isActive;if(!n.selected){if(!this._canAddItems())return!0;this._store.withTxn((function(){t._addItem(n,!0,!0),t.clearInput(),t.unhighlightAll()})),this._triggerChange(n.value)}return s&&this.config.closeDropdownOnSelect&&(this.hideDropdown(!0),this.containerOuter.element.focus()),!0},e.prototype._handleBackspace=function(e){var t=this.config;if(t.removeItems&&e.length){var i=e[e.length-1],n=e.some((function(e){return e.highlighted}));t.editItems&&!n&&i?(this.input.value=i.value,this.input.setWidth(),this._removeItem(i),this._triggerChange(i.value)):(n||this.highlightItem(i,!1),this.removeHighlightedItems(!0))}},e.prototype._loadChoices=function(){var e,t=this.config;if(this._isTextElement){this._presetChoices=t.items.map((function(e){return B(e,!1)}));var i=this.passedElement.value;if(i){var n=i.split(t.delimiter).map((function(e){return B(e,!1)}));this._presetChoices=this._presetChoices.concat(n)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=t.choices.map((function(e){return B(e,!0)}));var s=this.passedElement.optionsAsChoices();s&&(e=this._presetChoices).push.apply(e,s)}},e.prototype._handleLoadingState=function(e){void 0===e&&(e=!0);var t=this.config;e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?(this.itemList.clear(),this.itemList.element.append(this._templates.placeholder(t,t.loadingText))):this.input.placeholder=t.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement||(this.input.placeholder=this._placeholderValue||""))},e.prototype._handleSearch=function(e){if(this.input.isFocussed){var t=this.config,i=t.searchFloor,n=t.searchChoices,s=this._store.choices.some((function(e){return!e.active}));if(null!=e&&e.length>=i){var o=n?this._searchChoices(e):0;null!==o&&this.passedElement.triggerEvent("search",{value:e,resultCount:o})}else s&&this._stopSearch()}},e.prototype._canAddItems=function(){var e=this.config,t=e.maxItemCount,i=e.maxItemText;return!(!e.singleModeForMultiSelect&&t>0&&t<=this._store.items.length&&(this._displayNotice("function"==typeof i?i(t):i,$),1))},e.prototype._canCreateItem=function(e){var t=this.config,i=!0,n="";if(i&&"function"==typeof t.addItemFilter&&!t.addItemFilter(e)&&(i=!1,n=y(t.customAddItemText,e)),i){var s=this._store.choices.find((function(i){return t.valueComparer(i.value,e)}));if(this._isSelectElement){if(s)return this._displayNotice("",$),!1}else this._isTextElement&&!t.duplicateItemsAllowed&&s&&(i=!1,n=y(t.uniqueItemText,e))}return i&&(n=y(t.addItemText,e)),n&&this._displayNotice(n,$),i},e.prototype._searchChoices=function(e){var t=e.trim().replace(/\s{2,}/," ");if(!t.length||t===this._currentValue)return null;var i=this._searcher;i.isEmptyIndex()&&i.index(this._store.searchableChoices);var n=i.search(t);this._currentValue=t,this._highlightPosition=0,this._isSearching=!0;var s=this._notice,o=s&&s.type;return o!==$&&(n.length?o===W&&this._clearNotice():this._displayNotice(b(this.config.noResultsText),W)),this._store.dispatch(function(e){return{type:a,results:e}}(n)),n.length},e.prototype._stopSearch=function(){var e=this._isSearching;this._currentValue="",this._isSearching=!1,e&&(this._store.dispatch({type:c,active:!0}),this.passedElement.triggerEvent("search",{value:"",resultCount:0}))},e.prototype._addEventListeners=function(){var e=this._docRoot,t=this.containerOuter.element,i=this.input.element;e.addEventListener("touchend",this._onTouchEnd,!0),t.addEventListener("keydown",this._onKeyDown,!0),t.addEventListener("mousedown",this._onMouseDown,!0),e.addEventListener("click",this._onClick,{passive:!0}),e.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.dropdown.element.addEventListener("mouseover",this._onMouseOver,{passive:!0}),this._isSelectOneElement&&(t.addEventListener("focus",this._onFocus,{passive:!0}),t.addEventListener("blur",this._onBlur,{passive:!0})),i.addEventListener("keyup",this._onKeyUp,{passive:!0}),i.addEventListener("input",this._onInput,{passive:!0}),i.addEventListener("focus",this._onFocus,{passive:!0}),i.addEventListener("blur",this._onBlur,{passive:!0}),i.form&&i.form.addEventListener("reset",this._onFormReset,{passive:!0}),this.input.addEventListeners()},e.prototype._removeEventListeners=function(){var e=this._docRoot,t=this.containerOuter.element,i=this.input.element;e.removeEventListener("touchend",this._onTouchEnd,!0),t.removeEventListener("keydown",this._onKeyDown,!0),t.removeEventListener("mousedown",this._onMouseDown,!0),e.removeEventListener("click",this._onClick),e.removeEventListener("touchmove",this._onTouchMove),this.dropdown.element.removeEventListener("mouseover",this._onMouseOver),this._isSelectOneElement&&(t.removeEventListener("focus",this._onFocus),t.removeEventListener("blur",this._onBlur)),i.removeEventListener("keyup",this._onKeyUp),i.removeEventListener("input",this._onInput),i.removeEventListener("focus",this._onFocus),i.removeEventListener("blur",this._onBlur),i.form&&i.form.removeEventListener("reset",this._onFormReset),this.input.removeEventListeners()},e.prototype._onKeyDown=function(e){var t=e.keyCode,i=this._store.items,n=this.input.isFocussed,s=this.dropdown.isActive,o=this.itemList.element.hasChildNodes(),r=1===e.key.length||2===e.key.length&&e.key.charCodeAt(0)>=55296||"Unidentified"===e.key;switch(this._isTextElement||s||(this.showDropdown(),!this.input.isFocussed&&r&&(this.input.value+=e.key," "===e.key&&e.preventDefault())),t){case 65:return this._onSelectKey(e,o);case 13:return this._onEnterKey(e,s);case 27:return this._onEscapeKey(e,s);case 38:case 33:case 40:case 34:return this._onDirectionKey(e,s);case 8:case 46:return this._onDeleteKey(e,i,n)}},e.prototype._onKeyUp=function(){this._canSearch=this.config.searchEnabled},e.prototype._onInput=function(){var e=this.input.value;if(!e)return this._isTextElement?this.hideDropdown(!0):this._stopSearch(),void this._clearNotice();this._canAddItems()&&(this._canSearch&&this._handleSearch(e),this._canAddUserChoices&&(this._canCreateItem(e),this._isSelectElement&&(this._highlightPosition=0,this._highlightChoice())))},e.prototype._onSelectKey=function(e,t){(e.ctrlKey||e.metaKey)&&t&&(this._canSearch=!1,this.config.removeItems&&!this.input.value&&this.input.element===document.activeElement&&this.highlightAll())},e.prototype._onEnterKey=function(e,t){var i=this,n=this.config,s=this.input.value,o=e.target,r=o&&o.hasAttribute("data-button");if(e.preventDefault(),r)this._handleButtonAction(o);else if(t){var a=this.dropdown.element.querySelector(A(n.classNames.highlightedState));if(!a||!this._handleChoiceAction(a))if(o&&s){if(this._canAddItems()){var c=!1;this._store.withTxn((function(){if(!(c=i._findAndSelectChoiceByValue(s,!0))){if(!i._canAddUserChoices)return;if(!i._canCreateItem(s))return;var e=_(s),t=n.allowHtmlUserInput||e===s?s:{escaped:e,raw:s};i._addChoice(B({value:t,label:t,selected:!0},!1),!0,!0),c=!0}i.clearInput(),i.unhighlightAll()})),c&&(this._triggerChange(s),n.closeDropdownOnSelect&&this.hideDropdown(!0))}}else this.hideDropdown(!0)}else(this._isSelectElement||this._notice)&&this.showDropdown()},e.prototype._onEscapeKey=function(e,t){t&&(e.stopPropagation(),this.hideDropdown(!0),this.containerOuter.element.focus())},e.prototype._onDirectionKey=function(e,t){var i,n,s,o=e.keyCode,r=e.metaKey;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var a=40===o||34===o?1:-1,c="[data-choice-selectable]",l=void 0;if(r||34===o||33===o)l=this.dropdown.element.querySelector(a>0?"".concat(c,":last-of-type"):c);else{var h=this.dropdown.element.querySelector(A(this.config.classNames.highlightedState));l=h?function(e,t,i){void 0===i&&(i=1);for(var n="".concat(i>0?"next":"previous","ElementSibling"),s=e[n];s;){if(s.matches(t))return s;s=s[n]}return null}(h,c,a):this.dropdown.element.querySelector(c)}l&&(i=l,n=this.choiceList.element,void 0===(s=a)&&(s=1),(s>0?n.scrollTop+n.offsetHeight>=i.offsetTop+i.offsetHeight:i.offsetTop>=n.scrollTop)||this.choiceList.scrollToChildElement(l,a),this._highlightChoice(l)),e.preventDefault()}},e.prototype._onDeleteKey=function(e,t,i){this._isSelectOneElement||e.target.value||!i||(this._handleBackspace(t),e.preventDefault())},e.prototype._onTouchMove=function(){this._wasTap&&(this._wasTap=!1)},e.prototype._onTouchEnd=function(e){var t=(e||e.touches[0]).target;this._wasTap&&this.containerOuter.element.contains(t)&&((t===this.containerOuter.element||t===this.containerInner.element)&&(this._isTextElement?this.input.focus():this._isSelectMultipleElement&&this.showDropdown()),e.stopPropagation()),this._wasTap=!0},e.prototype._onMouseDown=function(e){var t=e.target;if(t instanceof HTMLElement){if(Me&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetX<i.offsetLeft}if(t!==this.input.element){var n=t.closest("[data-button],[data-item],[data-choice]");if(n instanceof HTMLElement){var s=e.shiftKey,o=n.dataset;"button"in o?this._handleButtonAction(n):"item"in o?this._handleItemAction(n,s):"choice"in o&&this._handleChoiceAction(n)}e.preventDefault()}}},e.prototype._onMouseOver=function(e){var t=e.target;t instanceof HTMLElement&&"choice"in t.dataset&&this._highlightChoice(t)},e.prototype._onClick=function(e){var t=e.target,i=this.containerOuter;i.element.contains(t)?this.dropdown.isActive||this.containerOuter.isDisabled?this._isSelectOneElement&&t!==this.input.element&&!this.dropdown.element.contains(t)&&this.hideDropdown():this._isTextElement?document.activeElement!==this.input.element&&this.input.focus():(this.showDropdown(),i.element.focus()):(!!this._store.highlightedActiveItems.length&&this.unhighlightAll(),i.removeFocusState(),this.hideDropdown(!0))},e.prototype._onFocus=function(e){var t,i=this,n=e.target,s=this.containerOuter;if(n&&s.element.contains(n)){var o=n===this.input.element;((t={})[x]=function(){o&&s.addFocusState()},t[T]=function(){s.addFocusState(),o&&i.showDropdown(!0)},t[N]=function(){o&&(i.showDropdown(!0),s.addFocusState())},t)[this._elementType]()}},e.prototype._onBlur=function(e){var t,i=this,n=e.target,s=this.containerOuter;if(n&&s.element.contains(n)&&!this._isScrollingOnIe){var o=this._store.activeChoices.some((function(e){return e.highlighted})),r=n===this.input.element;((t={})[x]=function(){r&&(s.removeFocusState(),o&&i.unhighlightAll(),i.hideDropdown(!0))},t[T]=function(){s.removeFocusState(),(r||n===s.element&&!i._canSearch)&&i.hideDropdown(!0)},t[N]=function(){r&&(s.removeFocusState(),i.hideDropdown(!0),o&&i.unhighlightAll())},t)[this._elementType]()}else this._isScrollingOnIe=!1,this.input.element.focus()},e.prototype._onFormReset=function(){var e=this;this._store.withTxn((function(){e.clearInput(),e.hideDropdown(),e.refresh(!1,!1,!0),e._initialItems.length&&e.setChoiceByValue(e._initialItems)}))},e.prototype._highlightChoice=function(e){var t;void 0===e&&(e=null);var i=this.config.classNames.highlightedState,n=Array.from(this.dropdown.element.querySelectorAll("[data-choice-selectable]"));if(n.length){var s=e;Array.from(this.dropdown.element.querySelectorAll(A(i))).forEach((function(e){var t;(t=e.classList).remove.apply(t,I(i)),e.setAttribute("aria-selected","false")})),s?this._highlightPosition=n.indexOf(s):(s=n.length>this._highlightPosition?n[this._highlightPosition]:n[n.length-1])||(s=n[0]),(t=s.classList).add.apply(t,I(i)),s.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:s}),this.dropdown.isActive&&(this.input.setActiveDescendant(s.id),this.containerOuter.setActiveDescendant(s.id))}},e.prototype._addItem=function(e,t,i){void 0===t&&(t=!0),void 0===i&&(i=!1);var n=e.id;if(!n)throw new TypeError("item.id must be set before _addItem is called for a choice/item");(this.config.singleModeForMultiSelect||this._isSelectOneElement)&&this.removeActiveItems(n),this._store.dispatch(function(e){return{type:u,item:e}}(e)),t&&(this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e)),i&&this.passedElement.triggerEvent("choice",this._getChoiceForOutput(e)))},e.prototype._removeItem=function(e){e.id&&(this._store.dispatch(function(e){return{type:d,item:e}}(e)),this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(e)))},e.prototype._addChoice=function(e,t,i){if(void 0===t&&(t=!0),void 0===i&&(i=!1),e.id)throw new TypeError("Can not re-add a choice which has already been added");this._lastAddedChoiceId++,e.id=this._lastAddedChoiceId,e.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(e.id);var n=this.config,s=n.prependValue,r=n.appendValue;s&&(e.value=s+e.value),r&&(e.value+=r.toString()),(s||r)&&e.element&&(e.element.value=e.value),this._store.dispatch(function(e){return{type:o,choice:e}}(e)),e.selected&&this._addItem(e,t,i)},e.prototype._addGroup=function(e,t){var i=this;if(void 0===t&&(t=!0),e.id)throw new TypeError("Can not re-add a group which has already been added");if(this._store.dispatch(function(e){return{type:h,group:e}}(e)),e.choices){var n=e;this._lastAddedGroupId++,n.id=this._lastAddedGroupId;var s=e.id,o=e.choices;n.choices=[],o.forEach((function(n){n.groupId=s,e.disabled&&(n.disabled=!0),i._addChoice(n,t)}))}},e.prototype._createTemplates=function(){var e=this,t=this.config.callbackOnCreateTemplates,i={};t&&"function"==typeof t&&(i=t.call(this,g,w));var n={};Object.keys(this._templates).forEach((function(t){n[t]=t in i?i[t].bind(e):e._templates[t].bind(e)})),this._templates=n},e.prototype._createElements=function(){var e=this._templates,t=this.config,i=t.position,n=t.classNames,s=this._elementType;this.containerOuter=new F({element:e.containerOuter(t,this._direction,this._isSelectElement,this._isSelectOneElement,t.searchEnabled,s,t.labelId),classNames:n,type:s,position:i}),this.containerInner=new F({element:e.containerInner(t),classNames:n,type:s,position:i}),this.input=new M({element:e.input(t,this._placeholderValue),classNames:n,type:s,preventPaste:!t.paste}),this.choiceList=new D({element:e.choiceList(t,this._isSelectOneElement)}),this.itemList=new D({element:e.itemList(t,this._isSelectOneElement)}),this.dropdown=new L({element:e.dropdown(t),classNames:n,type:s})},e.prototype._createStructure=function(){var e=this,t=e.containerInner,i=e.containerOuter,n=e.passedElement,s=e.dropdown,o=e.input;n.conceal(),t.wrap(n.element),i.wrap(t.element),this._isSelectOneElement?o.placeholder=this.config.searchPlaceholderValue||"":(this._placeholderValue&&(o.placeholder=this._placeholderValue),o.setWidth()),i.element.appendChild(t.element),i.element.appendChild(s.element),t.element.appendChild(this.itemList.element),s.element.appendChild(this.choiceList.element),this._isSelectOneElement?this.config.searchEnabled&&s.element.insertBefore(o.element,s.element.firstChild):t.element.appendChild(o.element),this._highlightPosition=0,this._isSearching=!1},e.prototype._initStore=function(){var e=this;this._store.subscribe(this._render),this._store.withTxn((function(){e._addPredefinedChoices(e._presetChoices,e._isSelectOneElement&&!e._hasNonChoicePlaceholder,!1)})),this._isSelectOneElement&&this._hasNonChoicePlaceholder&&this._render({choices:!1,groups:!1,items:!0})},e.prototype._addPredefinedChoices=function(e,t,i){var n=this;void 0===t&&(t=!1),void 0===i&&(i=!0),t&&-1===e.findIndex((function(e){return e.selected}))&&e.some((function(e){return!e.disabled&&!("choices"in e)&&(e.selected=!0,!0)})),e.forEach((function(e){"choices"in e?n._isSelectElement&&n._addGroup(e,i):n._addChoice(e,i)}))},e.prototype._findAndSelectChoiceByValue=function(e,t){var i=this;void 0===t&&(t=!1);var n=this._store.choices.find((function(t){return i.config.valueComparer(t.value,e)}));return!(!n||n.disabled||n.selected||(this._addItem(n,!0,t),0))},e.prototype._generatePlaceholderValue=function(){var e=this.config;if(!e.placeholder)return null;if(this._hasNonChoicePlaceholder)return e.placeholderValue;if(this._isSelectElement){var t=this.passedElement.placeholderOption;return t?t.text:null}return null},e.prototype._warnChoicesInitFailed=function(e){if(!this.config.silent){if(!this.initialised)throw new TypeError("".concat(e," called on a non-initialised instance of Choices"));if(!this.initialisedOK)throw new TypeError("".concat(e," called for an element which has multiple instances of Choices initialised on it"))}},e.version="11.0.0-rc8",e}()}));