UNPKG

preline

Version:

Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.

9 lines 167 kB
var e={189(e,t,n){n.d(t,{lP:()=>o});const o={auto:"auto","auto-start":"auto-start","auto-end":"auto-end",top:"top","top-left":"top-start","top-right":"top-end",bottom:"bottom","bottom-left":"bottom-start","bottom-right":"bottom-end",right:"right","right-start":"right-start","right-end":"right-end",left:"left","left-start":"left-start","left-end":"left-end"}},8862(e,t,n){n.d(t,{A:()=>s});var o=n(1926);const s=class{constructor(){this.components=[],this.currentlyOpenedComponents=[],this.activeComponent=null,this.allowedKeybindings=new Set(["Escape","Enter"," ","Space","ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Home","End"]),this.initGlobalListeners()}initGlobalListeners(){document.addEventListener("keydown",e=>this.handleGlobalKeydown(e)),document.addEventListener("focusin",e=>this.handleGlobalFocusin(e))}isAllowedKeybinding(e){return!!this.allowedKeybindings.has(e.key)||!(1!==e.key.length||!/^[a-zA-Z]$/.test(e.key)||e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)}getActiveComponent(e){if(!e)return null;const t=this.components.filter(t=>t.wrapper.contains(e)||t.context&&t.context.contains(e));if(0===t.length)return null;if(1===t.length)return t[0];let n=null,o=Number.MAX_SAFE_INTEGER;for(const s of t){let t=0,i=e;for(;i&&i!==s.wrapper&&i!==s.context;)t++,i=i.parentElement;t<o&&(o=t,n=s)}return n}getActiveComponentForKey(e,t){if(!e)return null;const n=this.components.filter(t=>t.wrapper.contains(e)||t.context&&t.context.contains(e));if(0===n.length)return null;const o=n.filter(e=>{const n=e.handlers;switch(t){case"Escape":return!!n.onEsc;case"Enter":return!!n.onEnter;case" ":case"Space":return!!n.onSpace;case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":return!!n.onArrow;case"Tab":return!!n.onTab||!!n.onShiftTab;case"Home":return!!n.onHome;case"End":return!!n.onEnd;default:return!!n.onFirstLetter}});if(0===o.length)return this.getActiveComponent(e);if(1===o.length)return o[0];let s=null,i=Number.MAX_SAFE_INTEGER;for(const t of o){let n=0,o=e;for(;o&&o!==t.wrapper&&o!==t.context;)n++,o=o.parentElement;n<i&&(i=n,s=t)}return s}getDistanceToComponent(e,t){let n=0,o=e;for(;o&&o!==t.wrapper&&o!==t.context;)n++,o=o.parentElement;return n}getComponentsByNesting(e){if(!e)return[];const t=this.components.filter(t=>t.wrapper.contains(e)||t.context&&t.context.contains(e));return t.length<=1?t:[...t].sort((t,n)=>this.getDistanceToComponent(e,n)-this.getDistanceToComponent(e,t))}getSequentialHandlersForKey(e,t){const n=this.getComponentsByNesting(e);return 0===n.length?[]:n.map(e=>"Enter"===t?e.handlers.onEnter:e.handlers.onSpace).filter(e=>"function"==typeof e)}executeSequentialHandlers(e,t){let n=!1,o=!1;for(const s of e){n=!0;if(!1===s(t)){o=!0;break}}return{called:n,stopped:o}}handleGlobalFocusin(e){const t=e.target;this.activeComponent=this.getActiveComponent(t)}handleGlobalKeydown(e){var t;const n=e.target;this.activeComponent=this.getActiveComponentForKey(n,e.key);const s=this.activeComponent,i="Enter"===e.key||" "===e.key||"Space"===e.key;if((s||i)&&this.isAllowedKeybinding(e))switch(e.key){case"Escape":if(!s)break;if(s.isOpened){if(s.handlers.onEsc){const t=s.handlers.onEsc();if(e.preventDefault(),e.stopPropagation(),!1===t){const e=this.findClosestOpenParent(n);(null==e?void 0:e.handlers.onEsc)&&e.handlers.onEsc()}}}else{const t=this.findClosestOpenParent(n);(null==t?void 0:t.handlers.onEsc)&&(t.handlers.onEsc(),e.preventDefault(),e.stopPropagation())}break;case"Enter":{const t=this.getSequentialHandlersForKey(n,"Enter");if(0===t.length)break;const{called:s,stopped:i}=this.executeSequentialHandlers(t,e);if(s&&!(0,o.V6)(n)&&(e.stopPropagation(),e.preventDefault()),i)break;break}case" ":case"Space":{if("INPUT"===n.tagName||"TEXTAREA"===n.tagName)return;const t=this.getActiveComponent(n),o=this.getSequentialHandlersForKey(n,"Space");if(0===o.length)break;const{stopped:s}=this.executeSequentialHandlers(o);(s||(null==t?void 0:t.handlers.onSpace))&&(e.preventDefault(),e.stopPropagation());break}case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":if(!s)break;if(s.handlers.onArrow){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;s.handlers.onArrow(e),e.preventDefault(),e.stopPropagation()}break;case"Tab":if(!s)break;if(!s.handlers.onTab)break;const i=e.shiftKey?s.handlers.onShiftTab:s.handlers.onTab;i&&i(e);break;case"Home":if(!s)break;s.handlers.onHome&&(s.handlers.onHome(),e.preventDefault(),e.stopPropagation());break;case"End":if(!s)break;s.handlers.onEnd&&(s.handlers.onEnd(),e.preventDefault(),e.stopPropagation());break;default:if(!s)break;if(s.handlers.onFirstLetter&&1===e.key.length&&/^[a-zA-Z]$/.test(e.key)){if(s.handlers.onFirstLetter(e.key),!(null===(t=s.stopPropagation)||void 0===t?void 0:t.onFirstLetter))return;e.preventDefault(),e.stopPropagation()}}}findClosestOpenParent(e){let t=e.parentElement;for(;t;){const e=this.currentlyOpenedComponents.find(e=>e.wrapper===t&&e!==this.activeComponent);if(e)return e;t=t.parentElement}return null}registerComponent(e,t,n=!0,o="",s="",i,a){const l={wrapper:e,handlers:t,isOpened:n,name:o,selector:s,context:i,isRegistered:!0,stopPropagation:a};return this.components.push(l),l}updateComponentState(e,t){e.isOpened=t,t?this.currentlyOpenedComponents.includes(e)||this.currentlyOpenedComponents.push(e):this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(t=>t!==e)}unregisterComponent(e){this.components=this.components.filter(t=>t!==e),this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(t=>t!==e)}addAllowedKeybinding(e){this.allowedKeybindings.add(e)}removeAllowedKeybinding(e){this.allowedKeybindings.delete(e)}getAllowedKeybindings(){return Array.from(this.allowedKeybindings)}}},7615(e,t,n){n.d(t,{A:()=>o}); /* * HSBasePlugin * @version: 4.2.0 * @author: Preline Labs Ltd. * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html) * Copyright 2024 Preline Labs Ltd. */ class o{constructor(e,t,n){this.el=e,this.options=t,this.events=n,this.el=e,this.options=t,this.events={}}createCollection(e,t){var n,o;let s=e;if(!Array.isArray(s)&&"undefined"!=typeof window){const e=null===(n=this.constructor)||void 0===n?void 0:n.name,t="string"==typeof e&&e.startsWith("HS")?`$hs${e.slice(2)}Collection`:null;t&&(Array.isArray(window[t])||(window[t]=[]),s=window[t])}Array.isArray(s)&&s.push({id:(null===(o=null==t?void 0:t.el)||void 0===o?void 0:o.id)||s.length+1,element:t})}fireEvent(e,t=null){if(this.events.hasOwnProperty(e))return this.events[e](t)}on(e,t){this.events[e]=t}}},4189(e,t,n){n.d(t,{A:()=>d});var o=n(1926),s=n(7615),i=n(8862),a=n(189),l=function(e,t,n,o){return new(n||(n=Promise))(function(s,i){function a(e){try{r(o.next(e))}catch(e){i(e)}}function l(e){try{r(o.throw(e))}catch(e){i(e)}}function r(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,l)}r((o=o.apply(e,t||[])).next())})};class r extends s.A{constructor(e,t){var n,o,s,i,a;super(e,t),this.disabledObserver=null,this.remoteSearchAbortController=null,this.loadMoreAbortController=null,this.requestId=0,this.lastQuery="",this.isLoadEventFired=!1,this.optionId=0;const l=e.getAttribute("data-hs-select"),r=l?JSON.parse(l):{},d=Object.assign(Object.assign({},r),t);this.value=(null==d?void 0:d.value)||this.el.value||null,this.placeholder=(null==d?void 0:d.placeholder)||"Select...",this.hasSearch=(null==d?void 0:d.hasSearch)||!1,this.minSearchLength=null!==(n=null==d?void 0:d.minSearchLength)&&void 0!==n?n:0,this.preventSearchFocus=(null==d?void 0:d.preventSearchFocus)||!1,this.preventSearchInsideDescription=(null==d?void 0:d.preventSearchInsideDescription)||!1,this.mode=(null==d?void 0:d.mode)||"default",this.viewport=void 0!==(null==d?void 0:d.viewport)?document.querySelector(null==d?void 0:d.viewport):null,this.scrollToSelected=void 0!==(null==d?void 0:d.scrollToSelected)&&(null==d?void 0:d.scrollToSelected),this._isOpened=Boolean(null==d?void 0:d.isOpened)||!1,this.isMultiple=this.el.hasAttribute("multiple")||!1,this.isDisabled=this.el.hasAttribute("disabled")||!1,this.selectedItems=[],this.apiUrl=(null==d?void 0:d.apiUrl)||null,this.apiQuery=(null==d?void 0:d.apiQuery)||null,this.apiOptions=(null==d?void 0:d.apiOptions)||null,this.apiSearchQueryKey=(null==d?void 0:d.apiSearchQueryKey)||null,this.apiDataPart=(null==d?void 0:d.apiDataPart)||null,this.apiLoadMore=!0===(null==d?void 0:d.apiLoadMore)?{perPage:10,scrollThreshold:100}:"object"==typeof(null==d?void 0:d.apiLoadMore)&&null!==(null==d?void 0:d.apiLoadMore)&&{perPage:d.apiLoadMore.perPage||10,scrollThreshold:d.apiLoadMore.scrollThreshold||100},this.apiPageStart="number"==typeof(null==d?void 0:d.apiPageStart)?d.apiPageStart:void 0,this.apiTotalPath="string"==typeof(null==d?void 0:d.apiTotalPath)?d.apiTotalPath:null,this.apiFieldsMap=(null==d?void 0:d.apiFieldsMap)||null,this.apiIconTag=(null==d?void 0:d.apiIconTag)||null,this.apiSelectedValues=(null==d?void 0:d.apiSelectedValues)||null,this.currentPage=0,this.isLoading=!1,this.hasMore=!0,this.wrapperClasses=(null==d?void 0:d.wrapperClasses)||null,this.toggleTag=(null==d?void 0:d.toggleTag)||null,this.toggleClasses=(null==d?void 0:d.toggleClasses)||null,this.toggleCountText=void 0===typeof(null==d?void 0:d.toggleCountText)?null:d.toggleCountText,this.toggleCountTextPlacement=(null==d?void 0:d.toggleCountTextPlacement)||"postfix",this.toggleCountTextMinItems=(null==d?void 0:d.toggleCountTextMinItems)||1,this.toggleCountTextMode=(null==d?void 0:d.toggleCountTextMode)||"countAfterLimit",this.toggleSeparators={items:(null===(o=null==d?void 0:d.toggleSeparators)||void 0===o?void 0:o.items)||", ",betweenItemsAndCounter:(null===(s=null==d?void 0:d.toggleSeparators)||void 0===s?void 0:s.betweenItemsAndCounter)||"and"},this.tagsItemTemplate=(null==d?void 0:d.tagsItemTemplate)||null,this.tagsItemClasses=(null==d?void 0:d.tagsItemClasses)||null,this.tagsInputId=(null==d?void 0:d.tagsInputId)||null,this.tagsInputClasses=(null==d?void 0:d.tagsInputClasses)||null,this.dropdownTag=(null==d?void 0:d.dropdownTag)||null,this.dropdownClasses=(null==d?void 0:d.dropdownClasses)||null,this.dropdownDirectionClasses=(null==d?void 0:d.dropdownDirectionClasses)||null,this.dropdownSpace=(null==d?void 0:d.dropdownSpace)||10,this.dropdownPlacement=(null==d?void 0:d.dropdownPlacement)||null,this.dropdownVerticalFixedPlacement=(null==d?void 0:d.dropdownVerticalFixedPlacement)||null,this.dropdownScope=(null==d?void 0:d.dropdownScope)||"parent",this.dropdownAutoPlacement=(null==d?void 0:d.dropdownAutoPlacement)||!1,this.searchTemplate=(null==d?void 0:d.searchTemplate)||null,this.searchWrapperTemplate=(null==d?void 0:d.searchWrapperTemplate)||null,this.searchWrapperClasses=(null==d?void 0:d.searchWrapperClasses)||"bg-white p-2 sticky top-0",this.searchId=(null==d?void 0:d.searchId)||null,this.searchLimit=(null==d?void 0:d.searchLimit)||1/0,this.isSearchDirectMatch=void 0===(null==d?void 0:d.isSearchDirectMatch)||d.isSearchDirectMatch,this.searchMatchMode=(null==d?void 0:d.searchMatchMode)||(this.isSearchDirectMatch?"substring":"chars-sequence"),this.searchClasses=(null==d?void 0:d.searchClasses)||"block w-[calc(100%-32px)] text-sm border-gray-200 rounded-md focus:border-blue-500 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-700 dark:text-neutral-400 py-2 px-3 my-2 mx-4",this.searchPlaceholder=(null==d?void 0:d.searchPlaceholder)||"Search...",this.searchNoResultTemplate=(null==d?void 0:d.searchNoResultTemplate)||"<span></span>",this.searchNoResultText=(null==d?void 0:d.searchNoResultText)||"No results found",this.searchNoResultClasses=(null==d?void 0:d.searchNoResultClasses)||"px-4 text-sm text-gray-800 dark:text-neutral-200",this.optionAllowEmptyOption=void 0!==(null==d?void 0:d.optionAllowEmptyOption)&&(null==d?void 0:d.optionAllowEmptyOption),this.optionTemplate=(null==d?void 0:d.optionTemplate)||null,this.optionTag=(null==d?void 0:d.optionTag)||null,this.optionClasses=(null==d?void 0:d.optionClasses)||null,this.optgroupTag=(null==d?void 0:d.optgroupTag)||null,this.optgroupClasses=(null==d?void 0:d.optgroupClasses)||null,this.extraMarkup=(null==d?void 0:d.extraMarkup)||null,this.descriptionClasses=(null==d?void 0:d.descriptionClasses)||null,this.iconClasses=(null==d?void 0:d.iconClasses)||null,this.isAddTagOnEnter=null===(i=null==d?void 0:d.isAddTagOnEnter)||void 0===i||i,this.isSelectedOptionOnTop=null!==(a=null==d?void 0:d.isSelectedOptionOnTop)&&void 0!==a&&a,this.animationInProcess=!1,this.selectOptions=[],this.staticOptions=[],this.remoteOptions=[],this.tagsInputHelper=null,this.disabledObserver=new MutationObserver(e=>{e.some(e=>"disabled"===e.attributeName)&&this.setDisabledState(this.el.hasAttribute("disabled"))}),this.disabledObserver.observe(this.el,{attributes:!0,attributeFilter:["disabled"]}),this.init()}wrapperClick(e){e.target.closest("[data-hs-select-dropdown]")||e.target.closest("[data-tag-value]")||this.tagsInput.focus()}toggleClick(){if(this.isDisabled)return!1;this.toggleFn()}tagsInputFocus(){this._isOpened||this.open()}tagsInputInput(){this.calculateInputWidth()}tagsInputInputSecond(e){this.apiUrl||this.searchOptions(e.target.value)}tagsInputKeydown(e){if("Enter"===e.key&&this.isAddTagOnEnter){const t=e.target.value;if(this.selectOptions.find(e=>e.val===t))return!1;this.addSelectOption(t,t),this.buildOption(t,t),this.buildOriginalOption(t,t),this.dropdown.querySelector(`[data-value="${t}"]`).click(),this.resetTagsInputField()}}searchInput(e){const t=e.target.value;this.lastQuery=t,this.apiUrl?this.remoteSearch(t):this.searchOptions(t)}setValue(e){if(this.value=e,this.clearSelections(),Array.isArray(e))if("tags"===this.mode){this.unselectMultipleItems(),this.selectMultipleItems(),this.selectedItems=[];this.wrapper.querySelectorAll("[data-tag-value]").forEach(e=>e.remove()),this.setTagsItems(),this.reassignTagsInputPlaceholder(this.hasValue()?"":this.placeholder)}else this.toggleTextWrapper.innerHTML=this.hasValue()?this.stringFromValue():this.placeholder,this.unselectMultipleItems(),this.selectMultipleItems();else this.setToggleTitle(),this.toggle.querySelector("[data-icon]")&&this.setToggleIcon(),this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.selectSingleItem()}setDisabledState(e){this.isDisabled=e;const t="tags"===this.mode?this.wrapper:this.toggle;null==t||t.classList.toggle("disabled",e),e&&this.isOpened()&&this.close()}hasValue(){return this.isMultiple?Array.isArray(this.value)&&this.value.length>0&&this.value.some(e=>null!=e&&""!==e):null!==this.value&&void 0!==this.value&&""!==this.value}init(){r.ensureGlobalHandlers(),this.createCollection(window.$hsSelectCollection,this),this.build(),"undefined"!=typeof window&&(window.HSAccessibilityObserver||(window.HSAccessibilityObserver=new i.A),this.setupAccessibility())}build(){this.el.style.display="none";if(this.el.querySelectorAll("option").length&&this.setOptions(),this.optionAllowEmptyOption&&!this.value&&(this.value=""),this.isMultiple){const e=this.el.querySelectorAll("option"),t=Array.from(e).filter(e=>e.selected),n=[];t.forEach(e=>{n.push(e.value)}),this.value=n}this.buildWrapper(),"tags"===this.mode?this.buildTags():this.buildToggle(),this.buildDropdown(),this.extraMarkup&&this.buildExtraMarkup(),this.apiUrl||this.fireLoadEvent()}fireLoadEvent(){this.isLoadEventFired||(this.isLoadEventFired=!0,setTimeout(()=>{this.fireEvent("load",this.el),(0,o.JD)("load.hs.select",this.el,this.el)}))}setOptions(){const e=this.el.querySelectorAll("option");Array.from(e).filter(e=>this.optionAllowEmptyOption||!this.optionAllowEmptyOption&&e.value&&""!==e.value).forEach(e=>{var t;const n=e.getAttribute("data-hs-select-option"),o={title:e.textContent,val:e.value,disabled:e.disabled,options:n&&"undefined"!==n?JSON.parse(n):null,optgroupName:"OPTGROUP"===(null===(t=e.parentElement)||void 0===t?void 0:t.tagName)?e.parentElement.label:null};this.selectOptions=[...this.selectOptions,o],this.apiUrl&&(this.staticOptions=[...this.staticOptions,o],e.setAttribute("data-static","true"))})}buildWrapper(){this.wrapper=document.createElement("div"),this.wrapper.classList.add("hs-select","relative"),this.setDisabledState(this.isDisabled),"tags"===this.mode&&(this.onWrapperClickListener=e=>this.wrapperClick(e),this.wrapper.addEventListener("click",this.onWrapperClickListener)),this.wrapperClasses&&(0,o.en)(this.wrapperClasses,this.wrapper),this.el.before(this.wrapper),this.wrapper.append(this.el)}buildExtraMarkup(){const e=e=>{const t=(0,o.fc)(e);return this.wrapper.append(t),t},t=e=>{e.classList.contains("--prevent-click")||e.addEventListener("click",e=>{e.stopPropagation(),this.isDisabled||this.toggleFn()})};if(Array.isArray(this.extraMarkup))this.extraMarkup.forEach(n=>{const o=e(n);t(o)});else{const n=e(this.extraMarkup);t(n)}}buildToggle(){var e,t;let n,s;this.toggleTextWrapper=document.createElement("span"),this.toggleTextWrapper.classList.add("truncate"),this.toggle=(0,o.fc)(this.toggleTag||"<div></div>"),n=this.toggle.querySelector("[data-icon]"),s=this.toggle.querySelector("[data-title]"),!this.isMultiple&&n&&this.setToggleIcon(),!this.isMultiple&&s&&this.setToggleTitle(),this.isMultiple?this.toggleTextWrapper.innerHTML=this.hasValue()?this.stringFromValue():this.placeholder:this.toggleTextWrapper.innerHTML=(null===(e=this.getItemByValue(this.value))||void 0===e?void 0:e.title)||this.placeholder,s||this.toggle.append(this.toggleTextWrapper),this.toggleClasses&&(0,o.en)(this.toggleClasses,this.toggle),this.isDisabled&&this.toggle.classList.add("disabled"),this.wrapper&&this.wrapper.append(this.toggle),(null===(t=this.toggle)||void 0===t?void 0:t.ariaExpanded)&&(this._isOpened?this.toggle.ariaExpanded="true":this.toggle.ariaExpanded="false"),this.onToggleClickListener=()=>this.toggleClick(),this.toggle.addEventListener("click",this.onToggleClickListener)}setToggleIcon(){var e,t,n,s;const i=this.getItemByValue(this.value),a=this.toggle.querySelector("[data-icon]");if(a){a.innerHTML="";const l=null===(t=null===(e=null==i?void 0:i.options)||void 0===e?void 0:e.apiFields)||void 0===t?void 0:t.icon,r=null==i?void 0:i[null===(n=this.apiFieldsMap)||void 0===n?void 0:n.icon],d=null===(s=null==i?void 0:i.options)||void 0===s?void 0:s.icon,c=(0,o.fc)((this.apiUrl||l)&&this.apiIconTag?this.apiIconTag||"":d||"");this.value&&(l?c.src=l:this.apiUrl&&this.apiIconTag&&r?c.src=r:d&&"string"==typeof d&&!d.trim().startsWith("<")&&(c.src=d)),a.append(c),(c instanceof HTMLImageElement?c.src:c)?a.classList.remove("hidden"):a.classList.add("hidden")}}setToggleTitle(){const e=this.toggle.querySelector("[data-title]");let t=this.placeholder;if(this.optionAllowEmptyOption&&""===this.value){const e=this.selectOptions.find(e=>""===e.val);t=(null==e?void 0:e.title)||this.placeholder}else if(this.value)if(this.apiUrl){const e=this.staticOptions.find(e=>e.val===this.value);if(e)t=e.title;else{const e=this.remoteOptions.find(e=>`${e[this.apiFieldsMap.val]}`===this.value||`${e[this.apiFieldsMap.title]}`===this.value);e&&(t=e[this.apiFieldsMap.title])}}else{const e=this.selectOptions.find(e=>e.val===this.value);e&&(t=e.title)}e?(e.innerHTML=t,e.classList.add("truncate"),this.toggle.append(e)):this.toggleTextWrapper.innerHTML=t}buildTags(){this.isDisabled&&this.wrapper.classList.add("disabled"),this.wrapper.setAttribute("tabindex","0"),this.buildTagsInput(),this.setTagsItems()}reassignTagsInputPlaceholder(e){this.tagsInput.placeholder=e,this.tagsInputHelper.innerHTML=e,this.calculateInputWidth()}buildTagsItem(e){var t,n,s,i,a,l,r,d;const c=this.getItemByValue(e);let u,h,p,v;const m=document.createElement("div");if(m.setAttribute("data-tag-value",e),this.tagsItemClasses&&(0,o.en)(this.tagsItemClasses,m),this.tagsItemTemplate&&(u=(0,o.fc)(this.tagsItemTemplate),m.append(u)),(null===(t=null==c?void 0:c.options)||void 0===t?void 0:t.icon)||this.apiIconTag){const e=(0,o.fc)(this.apiUrl&&this.apiIconTag?this.apiIconTag:null===(n=null==c?void 0:c.options)||void 0===n?void 0:n.icon);if(this.apiUrl&&this.apiIconTag){const t=c[this.apiFieldsMap.icon]||(null===(i=null===(s=null==c?void 0:c.options)||void 0===s?void 0:s.apiFields)||void 0===i?void 0:i.icon)||(null===(a=null==c?void 0:c.options)||void 0===a?void 0:a.icon)||"";t&&(e.src=t)}v=u?u.querySelector("[data-icon]"):document.createElement("span"),v.append(e),u||m.append(v)}!u||!u.querySelector("[data-icon]")||(null===(l=null==c?void 0:c.options)||void 0===l?void 0:l.icon)||this.apiUrl||this.apiIconTag||c[null===(r=this.apiFieldsMap)||void 0===r?void 0:r.icon]||u.querySelector("[data-icon]").classList.add("hidden"),h=u?u.querySelector("[data-title]"):document.createElement("span"),this.apiUrl&&(null===(d=this.apiFieldsMap)||void 0===d?void 0:d.title)&&c[this.apiFieldsMap.title]?h.textContent=c[this.apiFieldsMap.title]:h.textContent=c.title||"",u||m.append(h),u?p=u.querySelector("[data-remove]"):(p=document.createElement("span"),p.textContent="X",m.append(p)),p.addEventListener("click",()=>{this.value=this.value.filter(t=>t!==e),this.selectedItems=this.selectedItems.filter(t=>t!==e),this.hasValue()||this.reassignTagsInputPlaceholder(this.placeholder),this.unselectMultipleItems(),this.selectMultipleItems(),m.remove(),this.triggerChangeEventForNativeSelect()}),this.wrapper.append(m)}getItemByValue(e){if(this.apiUrl){const t=this.staticOptions.find(t=>t.val===e);return t||this.remoteOptions.find(t=>`${t[this.apiFieldsMap.val]}`===e||t[this.apiFieldsMap.title]===e)}return this.selectOptions.find(t=>t.val===e)}setTagsItems(){if(this.value){(Array.isArray(this.value)?this.value:null!=this.value?[this.value]:[]).forEach(e=>{this.selectedItems.includes(e)||this.buildTagsItem(e),this.selectedItems=this.selectedItems.includes(e)?this.selectedItems:[...this.selectedItems,e]})}this._isOpened&&this.floatingUIInstance&&this.floatingUIInstance.update()}buildTagsInput(){this.tagsInput=document.createElement("input"),this.tagsInputId&&(this.tagsInput.id=this.tagsInputId),this.tagsInputClasses&&(0,o.en)(this.tagsInputClasses,this.tagsInput),this.tagsInput.setAttribute("tabindex","-1"),this.onTagsInputFocusListener=()=>this.tagsInputFocus(),this.onTagsInputInputListener=()=>this.tagsInputInput(),this.onTagsInputInputSecondListener=(0,o.sg)(e=>this.tagsInputInputSecond(e)),this.onTagsInputKeydownListener=e=>this.tagsInputKeydown(e),this.tagsInput.addEventListener("focus",this.onTagsInputFocusListener),this.tagsInput.addEventListener("input",this.onTagsInputInputListener),this.tagsInput.addEventListener("input",this.onTagsInputInputSecondListener),this.tagsInput.addEventListener("keydown",this.onTagsInputKeydownListener),this.wrapper.append(this.tagsInput),setTimeout(()=>{this.adjustInputWidth(),this.reassignTagsInputPlaceholder(this.hasValue()?"":this.placeholder)})}buildDropdown(){if(this.dropdown=(0,o.fc)(this.dropdownTag||"<div></div>"),this.dropdown.setAttribute("data-hs-select-dropdown",""),"parent"===this.dropdownScope&&(this.dropdown.classList.add("absolute"),this.dropdownVerticalFixedPlacement||this.dropdown.classList.add("top-full")),this.dropdown.role="listbox",this.dropdown.tabIndex=-1,this.dropdown.ariaOrientation="vertical",this._isOpened||this.dropdown.classList.add("hidden"),this.dropdownClasses&&(0,o.en)(this.dropdownClasses,this.dropdown),this.wrapper&&this.wrapper.append(this.dropdown),this.dropdown&&this.hasSearch&&this.buildSearch(),this.selectOptions){let e="";this.selectOptions.forEach((t,n)=>{t.optgroupName&&t.optgroupName!==e&&(this.hasOptgroup=!0,e=t.optgroupName,this.buildOptgroup(e)),this.buildOption(t.title,t.val,t.disabled,t.selected,t.options,`${n}`,void 0,!!this.apiUrl)}),e=""}this.apiUrl&&this.optionsFromRemoteData().then(()=>this.fireLoadEvent()),this.apiUrl||(this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")),"window"===this.dropdownScope&&this.buildFloatingUI(),this.dropdown&&this.apiLoadMore&&this.setupInfiniteScroll()}buildOptgroup(e){const t=(0,o.fc)(this.optgroupTag||"<div></div>");t.textContent=e,t.setAttribute("data-optgroup",""),this.optgroupClasses&&(0,o.en)(this.optgroupClasses,t),this.dropdown.append(t)}setupInfiniteScroll(){this.dropdown.addEventListener("scroll",this.handleScroll.bind(this))}handleScroll(){return l(this,void 0,void 0,function*(){if(!this.dropdown||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const{scrollTop:e,scrollHeight:t,clientHeight:n}=this.dropdown;t-e-n<("object"==typeof this.apiLoadMore?this.apiLoadMore.scrollThreshold:100)&&(yield this.loadMore())})}loadMore(){return l(this,void 0,void 0,function*(){var e,t,n,o,s,i,a,l,r,d,c,u;if(!this.apiUrl||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const h=this.requestId;this.isLoading=!0;try{const p=new URL(this.apiUrl),v=(null!==(e=this.lastQuery)&&void 0!==e?e:"").trim().toLowerCase(),m=new URLSearchParams(null!==(t=this.apiQuery)&&void 0!==t?t:""),g=null!==(n=this.apiSearchQueryKey)&&void 0!==n?n:"q";""!==v&&m.set(g,v),p.search=m.toString();const b=(null===(o=this.apiFieldsMap)||void 0===o?void 0:o.page)||(null===(s=this.apiFieldsMap)||void 0===s?void 0:s.offset)||"page",y=!!(null===(i=this.apiFieldsMap)||void 0===i?void 0:i.offset),f="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,w=this.currentPage+1;if(y){const e=this.currentPage*f;p.searchParams.set(b,String(e))}else p.searchParams.set(b,String(w));if(p.searchParams.set((null===(a=this.apiFieldsMap)||void 0===a?void 0:a.limit)||"limit",String(f)),this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(e){}this.loadMoreAbortController=new AbortController;const x=Object.assign(Object.assign({},this.apiOptions||{}),{signal:this.loadMoreAbortController.signal}),M=yield fetch(p.toString(),x),k=yield M.json();if(h!==this.requestId)return void(this.isLoading=!1);const S=this.apiDataPart?null!==(r=null!==(l=k[this.apiDataPart])&&void 0!==l?l:k.results)&&void 0!==r?r:k:null!==(d=k.results)&&void 0!==d?d:k,T=(e,t)=>t.split(".").reduce((e,t)=>e?e[t]:void 0,e);let C=null;if(this.apiTotalPath){const e=T(k,this.apiTotalPath);C="number"==typeof e?e:null}else C=null!==(u=null!==(c="number"==typeof k.count?k.count:null)&&void 0!==c?c:"number"==typeof k.total?k.total:null)&&void 0!==u?u:k.info&&"number"==typeof k.info.count?k.info.count:null;if(S&&S.length>0){if(this.remoteOptions=[...this.remoteOptions||[],...S],this.buildOptionsFromRemoteData(S),"number"==typeof C){const e=w*f;this.hasMore=e<C}else this.hasMore=S.length===f;this.currentPage=w}else this.hasMore=!1}catch(e){this.hasMore=!1,console.error("Error loading more options:",e)}finally{this.isLoading=!1}})}buildFloatingUI(){if("undefined"!=typeof FloatingUIDOM&&FloatingUIDOM.computePosition){document.body.appendChild(this.dropdown);const e="tags"===this.mode?this.wrapper:this.toggle,t=[FloatingUIDOM.offset([0,5])];this.dropdownAutoPlacement&&"function"==typeof FloatingUIDOM.flip&&t.push(FloatingUIDOM.flip({fallbackPlacements:["bottom-start","bottom-end","top-start","top-end"]}));const n={placement:a.lP[this.dropdownPlacement]||"bottom",strategy:"fixed",middleware:t},o=()=>{Object.assign(this.dropdown.style,{marginLeft:"",marginTop:"",marginRight:"",marginBottom:""}),FloatingUIDOM.computePosition(e,this.dropdown,n).then(({x:e,y:t,placement:n})=>{Object.assign(this.dropdown.style,{position:"fixed",left:`${e}px`,top:`${t}px`,["margin"+(n.startsWith("bottom")||n.startsWith("top")?"Top":n.startsWith("right")?"Left":"Right")]:`${n.startsWith("top")?"-":""}${this.dropdownSpace}px`}),this.dropdown.setAttribute("data-placement",n)})};o();const s=FloatingUIDOM.autoUpdate(e,this.dropdown,o);this.floatingUIInstance={update:o,destroy:s}}else console.error("FloatingUIDOM not found! Please enable it on the page.")}updateDropdownWidth(){const e="tags"===this.mode?this.wrapper:this.toggle;this.dropdown.style.width=`${e.clientWidth}px`}buildSearch(){var e,t,n;if(!this.hasSearch)return;if("tags"===this.mode){const s=null!==(n=null!==(e=this.tagsInput)&&void 0!==e?e:null===(t=this.wrapper)||void 0===t?void 0:t.querySelector(":scope input"))&&void 0!==n?n:this.el.querySelector(":scope input");return s?(this.search=s,this.searchPlaceholder&&(this.search.placeholder=this.searchPlaceholder),this.searchId&&(this.search.id=this.searchId),this.searchClasses&&(0,o.en)(this.searchClasses,this.search),void(this.apiUrl&&(this.onSearchInputListener=(0,o.sg)(e=>this.searchInput(e)),this.search.addEventListener("input",this.onSearchInputListener)))):void 0}let s;this.searchWrapper=(0,o.fc)(this.searchWrapperTemplate||"<div></div>"),this.searchWrapperClasses&&(0,o.en)(this.searchWrapperClasses,this.searchWrapper),s=this.searchWrapper.querySelector("[data-input]");const i=(0,o.fc)(this.searchTemplate||'<input type="text">');this.search="INPUT"===i.tagName?i:i.querySelector(":scope input"),this.search.placeholder=this.searchPlaceholder,this.searchClasses&&(0,o.en)(this.searchClasses,this.search),this.searchId&&(this.search.id=this.searchId),this.onSearchInputListener=(0,o.sg)(e=>this.searchInput(e)),this.search.addEventListener("input",this.onSearchInputListener),s?s.append(i):this.searchWrapper.append(i),this.dropdown.append(this.searchWrapper)}buildOption(e,t,n=!1,s=!1,i,a="1",l,r=!1){var d,c,u,h,p;let v=null,m=null,g=null,b=null;const y=(0,o.fc)(this.optionTag||"<div></div>");if(y.setAttribute("data-value",t),y.setAttribute("data-title-value",e),y.setAttribute("tabIndex",a),y.classList.add("cursor-pointer"),y.setAttribute("data-id",l||`${this.optionId}`),r&&y.setAttribute("data-static","true"),l||this.optionId++,n&&y.classList.add("disabled"),s&&(this.isMultiple?this.value=[...this.value,t]:this.value=t),this.optionTemplate&&(v=(0,o.fc)(this.optionTemplate),y.append(v)),v?(m=v.querySelector("[data-title]"),m.textContent=e||""):y.textContent=e||"",i){const t=null!==(c=null===(d=i.apiFields)||void 0===d?void 0:d.icon)&&void 0!==c?c:i.icon,n=null!==(h=null===(u=i.apiFields)||void 0===u?void 0:u.description)&&void 0!==h?h:i.description;if(t){const n=(0,o.fc)(null!==(p=this.apiIconTag)&&void 0!==p?p:t);if(n.classList.add("max-w-full"),(this.apiUrl||i.apiFields)&&(n.setAttribute("alt",e),n.setAttribute("src",t)),v)g=v.querySelector("[data-icon]"),g.append(n);else{const e=(0,o.fc)("<div></div>");this.iconClasses&&(0,o.en)(this.iconClasses,e),e.append(n),y.append(e)}}if(Array.isArray(i.additionalClasses)&&i.additionalClasses.forEach(([e,t])=>{const n=e?y.querySelector(e):y;n&&t.forEach(e=>n.classList.add(e))}),n)if(y.dataset.description=n,v)b=v.querySelector("[data-description]"),b&&b.append(n);else{const e=(0,o.fc)("<div></div>");e.textContent=n,this.descriptionClasses&&(0,o.en)(this.descriptionClasses,e),y.append(e)}}v&&v.querySelector("[data-icon]")&&!i&&!(null==i?void 0:i.icon)&&v.querySelector("[data-icon]").classList.add("hidden"),this.value&&(this.isMultiple?this.value.includes(t):this.value===t)&&y.classList.add("selected"),n||y.addEventListener("click",()=>this.onSelectOption(t)),this.optionClasses&&(0,o.en)(this.optionClasses,y),this.dropdown&&this.dropdown.append(y),s&&this.setNewValue()}buildOptionFromRemoteData(e,t,n=!1,o=!1,s="1",i,a){s?this.buildOption(e,t,n,o,a,s,i):alert("ID parameter is required for generating remote options! Please check your API endpoint have it.")}buildOptionsFromRemoteData(e){e.forEach((e,t)=>{let n=null,o="",s="";const i={id:"",val:"",title:"",icon:null,description:null,rest:{}};Object.keys(e).forEach(t=>{var a;e[this.apiFieldsMap.id]&&(n=e[this.apiFieldsMap.id],i.id=`${n}`),e[this.apiFieldsMap.val]&&(s=`${e[this.apiFieldsMap.val]}`,i.val=s),e[this.apiFieldsMap.title]&&(o=e[this.apiFieldsMap.title],i.title=o,e[this.apiFieldsMap.val]||(s=o,i.val=s)),e[this.apiFieldsMap.icon]&&(i.icon=e[this.apiFieldsMap.icon]),e[null===(a=this.apiFieldsMap)||void 0===a?void 0:a.description]&&(i.description=e[this.apiFieldsMap.description]),i.rest[t]=e[t]});const a=this.staticOptions.findIndex(e=>e.val===s);if(-1!==a)return void this.mergeRemoteDataIntoStaticOption(a,s,i,t);if(!this.dropdown.querySelector(`[data-value="${s}"]`)){const e=!!this.apiSelectedValues&&(Array.isArray(this.apiSelectedValues)?this.apiSelectedValues.includes(s):this.apiSelectedValues===s);this.buildOriginalOption(o,s,n,!1,e,i),this.buildOptionFromRemoteData(o,s,!1,e,`${t}`,n,i),e&&(this.isMultiple?(this.value||(this.value=[]),Array.isArray(this.value)&&(this.value=[...this.value,s])):this.value=s,this.toggle&&(this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.toggle.querySelector("[data-icon]")&&this.setToggleIcon()))}}),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}mergeRemoteDataIntoStaticOption(e,t,n,s){const i=this.staticOptions[e];i.options||(i.options={}),i.options.apiFields||(i.options.apiFields={}),n.title&&(i.title=n.title),n.icon&&(i.options.apiFields.icon=n.icon),n.description&&(i.options.apiFields.description=n.description),Object.keys(n.rest).forEach(e=>{i.options.apiFields[e]=n.rest[e]});const a=this.dropdown.querySelector(`[data-value="${t}"][data-static]`);if(a){if(a.setAttribute("tabIndex",`${s}`),n.id&&a.setAttribute("data-id",`${n.id}`),n.title){a.setAttribute("data-title-value",n.title);const e=a.querySelector("[data-title]");e&&(e.textContent=n.title)}if(n.icon){const e=a.querySelector("[data-icon]");if(e){e.innerHTML="";const t=(0,o.fc)(this.apiIconTag||"<img />");t.classList.add("max-w-full"),t.setAttribute("alt",i.title),t.setAttribute("src",n.icon),e.append(t)}}if(n.description){a.dataset.description=n.description;const e=a.querySelector("[data-description]");e&&(e.textContent=n.description)}}const l=this.el.querySelector(`option[value="${t}"][data-static]`);if(l){n.id&&l.setAttribute("data-id",`${n.id}`),n.title&&(l.textContent=n.title);const e={id:n.id||"",val:n.val||"",title:n.title||"",icon:n.icon||null,description:n.description||null,rest:n.rest};l.setAttribute("data-hs-select-option",JSON.stringify(e))}const r=this.selectOptions.findIndex(e=>e.val===t);-1!==r&&(this.selectOptions[r]=i);(this.isMultiple?Array.isArray(this.value)&&this.value.includes(t):this.value===t)&&this.toggle&&(n.title&&(this.toggle.querySelector("[data-title]")?this.setToggleTitle():this.toggleTextWrapper&&(this.isMultiple?this.toggleTextWrapper.innerHTML=this.stringFromValue():this.toggleTextWrapper.innerHTML=n.title)),n.icon&&this.toggle.querySelector("[data-icon]")&&this.setToggleIcon())}optionsFromRemoteData(){return l(this,arguments,void 0,function*(e=""){const t=(yield this.apiRequest(e))||[];this.remoteOptions=t,t.length?this.buildOptionsFromRemoteData(this.remoteOptions):console.log("There is no data were responded!")})}apiRequest(){return l(this,arguments,void 0,function*(e="",t){var n,o,s,i,a,l,r,d,c,u;try{const h=new URL(this.apiUrl),p=new URLSearchParams(null!==(n=this.apiQuery)&&void 0!==n?n:""),v=null!==(o=this.apiOptions)&&void 0!==o?o:{},m=Object.assign({},v);t&&(m.signal=t);const g=null!==(s=this.apiSearchQueryKey)&&void 0!==s?s:"q",b=(null!=e?e:"").trim().toLowerCase();if(""!==b&&p.set(g,b),this.apiLoadMore){const e="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,t=null!==(r=null!==(a=null===(i=this.apiFieldsMap)||void 0===i?void 0:i.page)&&void 0!==a?a:null===(l=this.apiFieldsMap)||void 0===l?void 0:l.offset)&&void 0!==r?r:"page",n=null!==(c=null===(d=this.apiFieldsMap)||void 0===d?void 0:d.limit)&&void 0!==c?c:"limit",o=Boolean(null===(u=this.apiFieldsMap)||void 0===u?void 0:u.offset)?0:1,s="number"==typeof this.apiPageStart?this.apiPageStart:o;p.delete(t),p.delete(n),p.set(t,String(s)),p.set(n,String(e))}h.search=p.toString();const y=yield fetch(h.toString(),m),f=yield y.json();return this.apiDataPart?f[this.apiDataPart]:f}catch(e){console.error(e)}})}sortElements(e,t){if(this.hasOptgroup)return;const n=Array.from(e.querySelectorAll(t));this.isSelectedOptionOnTop&&n.sort((e,t)=>{const n=e.classList.contains("selected")||e.hasAttribute("selected"),o=t.classList.contains("selected")||t.hasAttribute("selected");return n&&!o?-1:!n&&o?1:0}),n.forEach((t,n)=>{e.appendChild(t),t.hasAttribute("tabindex")&&t.setAttribute("tabIndex",`${n}`)})}remoteSearch(e){return l(this,void 0,void 0,function*(){var t,n,o,s;if(this.requestId++,this.remoteSearchAbortController)try{this.remoteSearchAbortController.abort()}catch(e){}if(this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(e){}if(this.remoteSearchAbortController=new AbortController,this.currentPage=0,this.hasMore=!0,this.isLoading=!1,this.filterStaticOptions(e),e.length<=this.minSearchLength){const e=yield this.apiRequest("",null===(t=this.remoteSearchAbortController)||void 0===t?void 0:t.signal);if(!e)return!1;const o=Boolean(null===(n=this.apiFieldsMap)||void 0===n?void 0:n.offset)?0:1,s="number"==typeof this.apiPageStart?this.apiPageStart:o;this.currentPage=s;const i=Array.isArray(this.value)?this.value:this.value?[this.value]:[],a=this.remoteOptions.filter(e=>{var t;return i.includes(`${e[null===(t=this.apiFieldsMap)||void 0===t?void 0:t.val]}`)}),l=new Set(e.map(e=>{var t;return`${e[null===(t=this.apiFieldsMap)||void 0===t?void 0:t.val]}`}));return this.remoteOptions=[...e,...a.filter(e=>{var t;return!l.has(`${e[null===(t=this.apiFieldsMap)||void 0===t?void 0:t.val]}`)})],Array.from(this.dropdown.querySelectorAll("[data-value]:not([data-static])")).forEach(e=>{i.includes(e.getAttribute("data-value"))||e.remove()}),Array.from(this.el.querySelectorAll("option[value][data-hs-select-option]:not([data-static])")).forEach(e=>{i.includes(e.value)||e.remove()}),e.length?this.buildOptionsFromRemoteData(e):console.log("No data responded!"),!1}const i=yield this.apiRequest(e,null===(o=this.remoteSearchAbortController)||void 0===o?void 0:o.signal);if(!i)return;const a=Boolean(null===(s=this.apiFieldsMap)||void 0===s?void 0:s.offset)?0:1,l="number"==typeof this.apiPageStart?this.apiPageStart:a;this.currentPage=l;const r=Array.isArray(this.value)?this.value:this.value?[this.value]:[],d=this.remoteOptions.filter(e=>{var t;return r.includes(`${e[null===(t=this.apiFieldsMap)||void 0===t?void 0:t.val]}`)}),c=new Set(i.map(e=>{var t;return`${e[null===(t=this.apiFieldsMap)||void 0===t?void 0:t.val]}`}));this.remoteOptions=[...i,...d.filter(e=>{var t;return!c.has(`${e[null===(t=this.apiFieldsMap)||void 0===t?void 0:t.val]}`)})];let u=i.map(e=>`${e.id}`),h=null;const p=this.dropdown.querySelectorAll("[data-value]:not([data-static])");this.el.querySelectorAll("[data-hs-select-option]:not([data-static])").forEach(e=>{var t;const n=e.getAttribute("data-id");u.includes(n)||(null===(t=this.value)||void 0===t?void 0:t.includes(e.value))||this.destroyOriginalOption(e.value)}),p.forEach(e=>{var t;const n=e.getAttribute("data-id");u.includes(n)||(null===(t=this.value)||void 0===t?void 0:t.includes(e.getAttribute("data-value")))?u=u.filter(e=>e!==n):this.destroyOption(e.getAttribute("data-value"))}),h=i.filter(e=>u.includes(`${e.id}`)),h.length?this.buildOptionsFromRemoteData(h):console.log("No data responded!")})}filterStaticOptions(e){const t=this.dropdown.querySelectorAll("[data-value][data-static]"),n=e.trim().toLowerCase();t.forEach(e=>{var t,o;if(n.length<=this.minSearchLength)e.classList.remove("hidden");else{const s=(null===(t=e.getAttribute("data-title-value"))||void 0===t?void 0:t.toLowerCase())||"",i=(null===(o=e.dataset.description)||void 0===o?void 0:o.toLowerCase())||"";this.optionMatchesQuery(n,s,i)?e.classList.remove("hidden"):e.classList.add("hidden")}})}normalizeSearchText(e=""){return e.toLocaleLowerCase().replace(/\s+/g," ").trim()}tokenizeSearchQuery(e){return this.normalizeSearchText(e).split(" ").filter(Boolean)}charsSequenceMatch(e,t){const n=e.split("").map(e=>/\w/.test(e)?`${e}[\\W_]*`:"\\W*").join("");return new RegExp(n,"i").test(t)}optionMatchesQuery(e,t,n=""){const o=this.normalizeSearchText(e);if(!o)return!0;const s=this.normalizeSearchText(t),i=this.normalizeSearchText(n),a=this.preventSearchInsideDescription?[s]:[s,i];if("token-all"===this.searchMatchMode){const e=this.tokenizeSearchQuery(o);return a.some(t=>e.every(e=>t.includes(e)))}if("hybrid"===this.searchMatchMode){const e=this.tokenizeSearchQuery(o);return a.some(t=>{const n=e.every(e=>t.includes(e)),s=this.charsSequenceMatch(o,t);return n||s})}return"chars-sequence"===this.searchMatchMode?a.some(e=>this.charsSequenceMatch(o,e)):a.some(e=>e.includes(o))}destroyOption(e){const t=this.dropdown.querySelector(`[data-value="${e}"]`);if(!t)return!1;t.remove()}buildOriginalOption(e,t,n,s,i,a){const l=(0,o.fc)("<option></option>");l.setAttribute("value",t),s&&l.setAttribute("disabled","disabled"),i&&l.setAttribute("selected","selected"),n&&l.setAttribute("data-id",n),l.setAttribute("data-hs-select-option",JSON.stringify(a)),l.innerText=e,this.el.append(l)}destroyOriginalOption(e){const t=this.el.querySelector(`[value="${e}"]`);if(!t)return!1;t.remove()}buildTagsInputHelper(){this.tagsInputHelper=document.createElement("span"),this.tagsInputHelper.style.fontSize=window.getComputedStyle(this.tagsInput).fontSize,this.tagsInputHelper.style.fontFamily=window.getComputedStyle(this.tagsInput).fontFamily,this.tagsInputHelper.style.fontWeight=window.getComputedStyle(this.tagsInput).fontWeight,this.tagsInputHelper.style.letterSpacing=window.getComputedStyle(this.tagsInput).letterSpacing,this.tagsInputHelper.style.visibility="hidden",this.tagsInputHelper.style.whiteSpace="pre",this.tagsInputHelper.style.position="absolute",this.wrapper.appendChild(this.tagsInputHelper)}calculateInputWidth(){this.tagsInputHelper.textContent=this.tagsInput.value||this.tagsInput.placeholder;const e=parseInt(window.getComputedStyle(this.tagsInput).paddingLeft)+parseInt(window.getComputedStyle(this.tagsInput).paddingRight),t=parseInt(window.getComputedStyle(this.tagsInput).borderLeftWidth)+parseInt(window.getComputedStyle(this.tagsInput).borderRightWidth),n=this.tagsInputHelper.offsetWidth+e+t,o=this.wrapper.offsetWidth-(parseInt(window.getComputedStyle(this.wrapper).paddingLeft)+parseInt(window.getComputedStyle(this.wrapper).paddingRight));this.tagsInput.style.width=`${Math.min(n,o)+2}px`}adjustInputWidth(){this.buildTagsInputHelper(),this.calculateInputWidth()}onSelectOption(e){if(this.clearSelections(),this.isMultiple?(Array.isArray(this.value)||(this.value=[]),this.value=this.value.includes(e)?this.value.filter(t=>t!==e):[...this.value,e],this.selectMultipleItems(),this.setNewValue()):(this.value=e,this.selectSingleItem(),this.setNewValue()),this.fireEvent("change",this.value),"tags"===this.mode){const e=this.selectedItems.filter(e=>!this.value.includes(e));e.length&&e.forEach(e=>{this.selectedItems=this.selectedItems.filter(t=>t!==e),this.wrapper.querySelector(`[data-tag-value="${e}"]`).remove()}),this.resetTagsInputField()}this.isMultiple||(this.toggle.querySelector("[data-icon]")&&this.setToggleIcon(),this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.close(!0)),this.hasValue()||"tags"!==this.mode||this.reassignTagsInputPlaceholder(this.placeholder),this._isOpened&&"tags"===this.mode&&this.tagsInput&&this.tagsInput.focus(),this.triggerChangeEventForNativeSelect()}triggerChangeEventForNativeSelect(){const e=new Event("change",{bubbles:!0});this.el.dispatchEvent(e),(0,o.JD)("change.hs.select",this.el,this.value)}addSelectOption(e,t,n,o,s){this.selectOptions=[...this.selectOptions,{title:e,val:t,disabled:n,selected:o,options:s}]}removeSelectOption(e,t=!1){if(!!!this.selectOptions.some(t=>t.val===e))return!1;this.selectOptions=this.selectOptions.filter(t=>t.val!==e),this.value=t?this.value.filter(t=>t!==e):e}resetTagsInputField(){this.tagsInput.value="",this.reassignTagsInputPlaceholder(""),this.searchOptions("")}clearSelections(){const e=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(e=>{e.classList.contains("selected")&&e.classList.remove("selected")}),Array.from(e).forEach(e=>{e.selected&&(e.selected=!1)})}setNewValue(){if("tags"===this.mode)this.setTagsItems();else if(this.optionAllowEmptyOption&&""===this.value){const e=this.selectOptions.find(e=>""===e.val);this.toggleTextWrapper.innerHTML=(null==e?void 0:e.title)||this.placeholder}else if(this.hasValue())if(this.apiUrl){const e=this.dropdown.querySelector(`[data-value="${this.value}"]`);if(e)this.toggleTextWrapper.innerHTML=e.getAttribute("data-title-value")||this.placeholder;else{const e=this.staticOptions.find(e=>e.val===this.value);if(e)this.toggleTextWrapper.innerHTML=e.title;else{const e=this.remoteOptions.find(e=>(e[this.apiFieldsMap.val]?`${e[this.apiFieldsMap.val]}`:e[this.apiFieldsMap.title])===this.value);this.toggleTextWrapper.innerHTML=e?`${e[this.apiFieldsMap.title]}`:this.stringFromValue()}}}else this.toggleTextWrapper.innerHTML=this.stringFromValue();else this.toggleTextWrapper.innerHTML=this.placeholder}stringFromValueBasic(e){var t;const n=[];let o="";if(e.forEach(e=>{this.isMultiple?Array.isArray(this.value)&&this.value.includes(e.val)&&n.push(e.title):this.value===e.val&&n.push(e.title)}),void 0!==this.toggleCountText&&null!==this.toggleCountText&&n.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const e=n.slice(0,this.toggleCountTextMinItems-1),s=[e.join(this.toggleSeparators.items)],i=""+(n.length-e.length);if((null===(t=null==this?void 0:this.toggleSeparators)||void 0===t?void 0:t.betweenItemsAndCounter)&&s.push(this.toggleSeparators.betweenItemsAndCounter),this.toggleCountText)switch(this.toggleCountTextPlacement){case"postfix-no-space":s.push(`${i}${this.toggleCountText}`);break;case"prefix-no-space":s.push(`${this.toggleCountText}${i}`);break;case"prefix":s.push(`${this.toggleCountText} ${i}`);break;default:s.push(`${i} ${this.toggleCountText}`)}o=s.join(" ")}else o=`${n.length} ${this.toggleCountText}`;else o=n.join(this.toggleSeparators.items);return o}stringFromValueRemoteData(){if(!this.dropdown)return this.stringFromValueBasic(this.selectOptions);const e=this.dropdown.querySelectorAll("[data-title-value]"),t=[];let n="";if(e.forEach(e=>{const n=e.getAttribute("data-value"),o=e.getAttribute("data-title-value");this.isMultiple?Array.isArray(this.value)&&this.value.includes(n)&&t.push(o):this.value===n&&t.push(o)}),this.toggleCountText&&""!==this.toggleCountText&&t.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const e=t.slice(0,this.toggleCountTextMinItems-1);n=`${e.join(this.toggleSeparators.items)} ${this.toggleSeparators.betweenItemsAndCounter} ${t.length-e.length} ${this.toggleCountText}`}else n=`${t.length} ${this.toggleCountText}`;else n=t.join(this.toggleSeparators.items);return n}stringFromValue(){return this.apiUrl?this.stringFromValueRemoteData():this.stringFromValueBasic(this.selectOptions)}selectSingleItem(){const e=this.el.querySelectorAll("option");Array.from(e).find(e=>this.value===e.value).selected=!0;const t=Array.from(this.dropdown.children).find(e=>this.value===e.getAttribute("data-value"));t&&t.classList.add("selected"),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}selectMultipleItems(){if(!Array.isArray(this.value))return;const e=this.el.querySelectorAll("option");Array.from(this.dropdown.children).filter(e=>this.value.includes(e.getAttribute("data-value"))).forEach(e=>e.classList.add("selected")),Array.from(e).filter(e=>this.value.includes(e.value)).forEach(e=>e.selected=!0),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}unselectMultipleItems(){const e=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(e=>e.classList.remove("selected")),Array.from(e).forEach(e=>e.selected=!1),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}searchOptions(e){if(e.length<=this.minSearchLength){this.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null);return this.dropdown.querySelectorAll("[data-value]").forEach(e=>{e.classList.remove("hidden")}),!1}this.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null),this.searchNoResult=(0,o.fc)(this.searchNoResultTemplate),this.searchNoResult.innerText=this.searchNoResultText,(0,o.en)(this.searchNoResultClasses,this.searchNoResult);const t=this.dropdown.querySelectorAll("[data-value]");let n,s=!1;this.searchLimit&&(n=0),t.forEach(t=>{var o;const i=t.getAttribute("data-title-value")||"",a=(null===(o=null==t?void 0:t.dataset)||void 0===o?void 0:o.description)||"";!this.optionMatchesQuery(e,i,a)||this.searchLimit&&n>=this.searchLimit?t.classList.add("hidden"):(t.classList.remove("hidden"),s=!0,this.searchLimit&&n++)}),s||this.dropdown.append(this.searchNoResult)}eraseToggleIcon(){const e=this.toggle.querySelector("[data-icon]");e&&(e.innerHTML=null,e.classList.add("hidden"))}eraseToggleTitle(){const e=this.toggle.querySelector("[data-title]");e?e.innerHTML=this.placeholder:this.toggleTextWrapper.innerHTML=this.placeholder}toggleFn(){this._isOpened?this.close():this.open()}setupAccessibility(){this.accessibilityComponent=window.HSAccessibilityObserver.registerComponent(this.wrapper,{onEnter:()=>{if(this._isOpened){const e=this.dropdown.querySelector(".hs-select-option-highlighted");e&&(this.onSelectOption(e.getAttribute("data-value")||""),this._isOpened&&e.focus())}else this.open()},onSpace:()=>{if(this._isOpened){const e=this.dropdown.querySelector(".hs-select-option-highlighted");e&&(this.onSelectOption(e.getAttribute("data-value")||""),this._isOpened&&e.focus())}else this.open()},onEsc:()=>{this._isOpened&&this.close(!0)},onArrow:e=>{if(!e.metaKey)if(this._isOpened||"ArrowDown"!==e.key){if(this._isOpened)switch(e.key){case"ArrowDown":this.focusMenuItem("next");break;case"ArrowUp":this.focusMenuItem("prev");break;case"Home":this.onStartEnd(!0);break;case"End":this.onStartEnd(!1)}}else this.open()},onHome:()=>{this._isOpened&&this.onStartEnd(!0)},onEnd:()=>{this._isOpened&&this.onStartEnd(!1)},onTab:()=>{this._isOpened&&this.close()}},this._isOpened,"Select",".hs-select",this.dropdown)}focusMenuItem(e){const t=Array.from(this.dropdown.querySelectorAll(":scope > *:not(.hidden)")).filter(e=>!e.classList.contains("disabled")&&!e.hasAttribute("data-optgroup"));if(!t.length)return;const n=this.dropdown.querySelect