UNPKG

preline

Version:

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

16 lines 60 kB
var t={189(t,e,i){i.d(e,{lP:()=>s});const s={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(t,e,i){i.d(e,{A:()=>o});var s=i(1926);const o=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",t=>this.handleGlobalKeydown(t)),document.addEventListener("focusin",t=>this.handleGlobalFocusin(t))}isAllowedKeybinding(t){return!!this.allowedKeybindings.has(t.key)||!(1!==t.key.length||!/^[a-zA-Z]$/.test(t.key)||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)}getActiveComponent(t){if(!t)return null;const e=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));if(0===e.length)return null;if(1===e.length)return e[0];let i=null,s=Number.MAX_SAFE_INTEGER;for(const o of e){let e=0,n=t;for(;n&&n!==o.wrapper&&n!==o.context;)e++,n=n.parentElement;e<s&&(s=e,i=o)}return i}getActiveComponentForKey(t,e){if(!t)return null;const i=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));if(0===i.length)return null;const s=i.filter(t=>{const i=t.handlers;switch(e){case"Escape":return!!i.onEsc;case"Enter":return!!i.onEnter;case" ":case"Space":return!!i.onSpace;case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":return!!i.onArrow;case"Tab":return!!i.onTab||!!i.onShiftTab;case"Home":return!!i.onHome;case"End":return!!i.onEnd;default:return!!i.onFirstLetter}});if(0===s.length)return this.getActiveComponent(t);if(1===s.length)return s[0];let o=null,n=Number.MAX_SAFE_INTEGER;for(const e of s){let i=0,s=t;for(;s&&s!==e.wrapper&&s!==e.context;)i++,s=s.parentElement;i<n&&(n=i,o=e)}return o}getDistanceToComponent(t,e){let i=0,s=t;for(;s&&s!==e.wrapper&&s!==e.context;)i++,s=s.parentElement;return i}getComponentsByNesting(t){if(!t)return[];const e=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));return e.length<=1?e:[...e].sort((e,i)=>this.getDistanceToComponent(t,i)-this.getDistanceToComponent(t,e))}getSequentialHandlersForKey(t,e){const i=this.getComponentsByNesting(t);return 0===i.length?[]:i.map(t=>"Enter"===e?t.handlers.onEnter:t.handlers.onSpace).filter(t=>"function"==typeof t)}executeSequentialHandlers(t,e){let i=!1,s=!1;for(const o of t){i=!0;if(!1===o(e)){s=!0;break}}return{called:i,stopped:s}}handleGlobalFocusin(t){const e=t.target;this.activeComponent=this.getActiveComponent(e)}handleGlobalKeydown(t){var e;const i=t.target;this.activeComponent=this.getActiveComponentForKey(i,t.key);const o=this.activeComponent,n="Enter"===t.key||" "===t.key||"Space"===t.key;if((o||n)&&this.isAllowedKeybinding(t))switch(t.key){case"Escape":if(!o)break;if(o.isOpened){if(o.handlers.onEsc){const e=o.handlers.onEsc();if(t.preventDefault(),t.stopPropagation(),!1===e){const t=this.findClosestOpenParent(i);(null==t?void 0:t.handlers.onEsc)&&t.handlers.onEsc()}}}else{const e=this.findClosestOpenParent(i);(null==e?void 0:e.handlers.onEsc)&&(e.handlers.onEsc(),t.preventDefault(),t.stopPropagation())}break;case"Enter":{const e=this.getSequentialHandlersForKey(i,"Enter");if(0===e.length)break;const{called:o,stopped:n}=this.executeSequentialHandlers(e,t);if(o&&!(0,s.V6)(i)&&(t.stopPropagation(),t.preventDefault()),n)break;break}case" ":case"Space":{if("INPUT"===i.tagName||"TEXTAREA"===i.tagName)return;const e=this.getActiveComponent(i),s=this.getSequentialHandlersForKey(i,"Space");if(0===s.length)break;const{stopped:o}=this.executeSequentialHandlers(s);(o||(null==e?void 0:e.handlers.onSpace))&&(t.preventDefault(),t.stopPropagation());break}case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":if(!o)break;if(o.handlers.onArrow){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;o.handlers.onArrow(t),t.preventDefault(),t.stopPropagation()}break;case"Tab":if(!o)break;if(!o.handlers.onTab)break;const n=t.shiftKey?o.handlers.onShiftTab:o.handlers.onTab;n&&n(t);break;case"Home":if(!o)break;o.handlers.onHome&&(o.handlers.onHome(),t.preventDefault(),t.stopPropagation());break;case"End":if(!o)break;o.handlers.onEnd&&(o.handlers.onEnd(),t.preventDefault(),t.stopPropagation());break;default:if(!o)break;if(o.handlers.onFirstLetter&&1===t.key.length&&/^[a-zA-Z]$/.test(t.key)){if(o.handlers.onFirstLetter(t.key),!(null===(e=o.stopPropagation)||void 0===e?void 0:e.onFirstLetter))return;t.preventDefault(),t.stopPropagation()}}}findClosestOpenParent(t){let e=t.parentElement;for(;e;){const t=this.currentlyOpenedComponents.find(t=>t.wrapper===e&&t!==this.activeComponent);if(t)return t;e=e.parentElement}return null}registerComponent(t,e,i=!0,s="",o="",n,l){const a={wrapper:t,handlers:e,isOpened:i,name:s,selector:o,context:n,isRegistered:!0,stopPropagation:l};return this.components.push(a),a}updateComponentState(t,e){t.isOpened=e,e?this.currentlyOpenedComponents.includes(t)||this.currentlyOpenedComponents.push(t):this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(e=>e!==t)}unregisterComponent(t){this.components=this.components.filter(e=>e!==t),this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(e=>e!==t)}addAllowedKeybinding(t){this.allowedKeybindings.add(t)}removeAllowedKeybinding(t){this.allowedKeybindings.delete(t)}getAllowedKeybindings(){return Array.from(this.allowedKeybindings)}}},7615(t,e,i){i.d(e,{A:()=>s}); /* * 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 s{constructor(t,e,i){this.el=t,this.options=e,this.events=i,this.el=t,this.options=e,this.events={}}createCollection(t,e){var i,s;let o=t;if(!Array.isArray(o)&&"undefined"!=typeof window){const t=null===(i=this.constructor)||void 0===i?void 0:i.name,e="string"==typeof t&&t.startsWith("HS")?`$hs${t.slice(2)}Collection`:null;e&&(Array.isArray(window[e])||(window[e]=[]),o=window[e])}Array.isArray(o)&&o.push({id:(null===(s=null==e?void 0:e.el)||void 0===s?void 0:s.id)||o.length+1,element:e})}fireEvent(t,e=null){if(this.events.hasOwnProperty(t))return this.events[t](e)}on(t,e){this.events[t]=e}}},1926(t,e,i){i.d(e,{JD:()=>l,PR:()=>s,V6:()=>o,en:()=>d,fc:()=>r,sg:()=>n,yd:()=>a}); /* * @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. */ const s=(t,e,i="auto",s=10,o=null)=>{const n=e.getBoundingClientRect(),l=o?o.getBoundingClientRect():null,a=window.innerHeight,r=l?n.top-l.top:n.top,d=(o?l.bottom:a)-n.bottom,h=t.clientHeight+s;return"bottom"===i?d>=h:"top"===i?r>=h:r>=h||d>=h},o=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement,n=(t,e=200)=>{let i;return(...s)=>{clearTimeout(i),i=setTimeout(()=>{t.apply(void 0,s)},e)}},l=(t,e,i=null)=>{const s=new CustomEvent(t,{detail:{payload:i},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(s)},a=(t,e)=>{const i=()=>{e(),t.removeEventListener("transitionend",i,!0)},s=window.getComputedStyle(t),o=s.getPropertyValue("transition-duration");"none"!==s.getPropertyValue("transition-property")&&parseFloat(o)>0?t.addEventListener("transitionend",i,!0):e()},r=t=>{const e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild},d=(t,e,i=" ",s="add")=>{t.split(i).forEach(t=>{t.trim()&&("add"===s?e.classList.add(t):e.classList.remove(t))})}}},e={};function i(s){var o=e[s];if(void 0!==o)return o.exports;var n=e[s]={exports:{}};return t[s](n,n.exports,i),n.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var s={};i.d(s,{A:()=>h});var o=i(1926),n=i(7615),l=i(8862),a=i(189),r=function(t,e,i,s){return new(i||(i=Promise))(function(o,n){function l(t){try{r(s.next(t))}catch(t){n(t)}}function a(t){try{r(s.throw(t))}catch(t){n(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(l,a)}r((s=s.apply(t,e||[])).next())})};class d extends n.A{constructor(t,e){var i,s,o,n,l;super(t,e),this.disabledObserver=null,this.remoteSearchAbortController=null,this.loadMoreAbortController=null,this.requestId=0,this.lastQuery="",this.isLoadEventFired=!1,this.optionId=0;const a=t.getAttribute("data-hs-select"),r=a?JSON.parse(a):{},d=Object.assign(Object.assign({},r),e);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!==(i=null==d?void 0:d.minSearchLength)&&void 0!==i?i: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===(s=null==d?void 0:d.toggleSeparators)||void 0===s?void 0:s.items)||", ",betweenItemsAndCounter:(null===(o=null==d?void 0:d.toggleSeparators)||void 0===o?void 0:o.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===(n=null==d?void 0:d.isAddTagOnEnter)||void 0===n||n,this.isSelectedOptionOnTop=null!==(l=null==d?void 0:d.isSelectedOptionOnTop)&&void 0!==l&&l,this.animationInProcess=!1,this.selectOptions=[],this.staticOptions=[],this.remoteOptions=[],this.tagsInputHelper=null,this.disabledObserver=new MutationObserver(t=>{t.some(t=>"disabled"===t.attributeName)&&this.setDisabledState(this.el.hasAttribute("disabled"))}),this.disabledObserver.observe(this.el,{attributes:!0,attributeFilter:["disabled"]}),this.init()}wrapperClick(t){t.target.closest("[data-hs-select-dropdown]")||t.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(t){this.apiUrl||this.searchOptions(t.target.value)}tagsInputKeydown(t){if("Enter"===t.key&&this.isAddTagOnEnter){const e=t.target.value;if(this.selectOptions.find(t=>t.val===e))return!1;this.addSelectOption(e,e),this.buildOption(e,e),this.buildOriginalOption(e,e),this.dropdown.querySelector(`[data-value="${e}"]`).click(),this.resetTagsInputField()}}searchInput(t){const e=t.target.value;this.lastQuery=e,this.apiUrl?this.remoteSearch(e):this.searchOptions(e)}setValue(t){if(this.value=t,this.clearSelections(),Array.isArray(t))if("tags"===this.mode){this.unselectMultipleItems(),this.selectMultipleItems(),this.selectedItems=[];this.wrapper.querySelectorAll("[data-tag-value]").forEach(t=>t.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(t){this.isDisabled=t;const e="tags"===this.mode?this.wrapper:this.toggle;null==e||e.classList.toggle("disabled",t),t&&this.isOpened()&&this.close()}hasValue(){return this.isMultiple?Array.isArray(this.value)&&this.value.length>0&&this.value.some(t=>null!=t&&""!==t):null!==this.value&&void 0!==this.value&&""!==this.value}init(){d.ensureGlobalHandlers(),this.createCollection(window.$hsSelectCollection,this),this.build(),"undefined"!=typeof window&&(window.HSAccessibilityObserver||(window.HSAccessibilityObserver=new l.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 t=this.el.querySelectorAll("option"),e=Array.from(t).filter(t=>t.selected),i=[];e.forEach(t=>{i.push(t.value)}),this.value=i}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 t=this.el.querySelectorAll("option");Array.from(t).filter(t=>this.optionAllowEmptyOption||!this.optionAllowEmptyOption&&t.value&&""!==t.value).forEach(t=>{var e;const i=t.getAttribute("data-hs-select-option"),s={title:t.textContent,val:t.value,disabled:t.disabled,options:i&&"undefined"!==i?JSON.parse(i):null,optgroupName:"OPTGROUP"===(null===(e=t.parentElement)||void 0===e?void 0:e.tagName)?t.parentElement.label:null};this.selectOptions=[...this.selectOptions,s],this.apiUrl&&(this.staticOptions=[...this.staticOptions,s],t.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=t=>this.wrapperClick(t),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 t=t=>{const e=(0,o.fc)(t);return this.wrapper.append(e),e},e=t=>{t.classList.contains("--prevent-click")||t.addEventListener("click",t=>{t.stopPropagation(),this.isDisabled||this.toggleFn()})};if(Array.isArray(this.extraMarkup))this.extraMarkup.forEach(i=>{const s=t(i);e(s)});else{const i=t(this.extraMarkup);e(i)}}buildToggle(){var t,e;let i,s;this.toggleTextWrapper=document.createElement("span"),this.toggleTextWrapper.classList.add("truncate"),this.toggle=(0,o.fc)(this.toggleTag||"<div></div>"),i=this.toggle.querySelector("[data-icon]"),s=this.toggle.querySelector("[data-title]"),!this.isMultiple&&i&&this.setToggleIcon(),!this.isMultiple&&s&&this.setToggleTitle(),this.isMultiple?this.toggleTextWrapper.innerHTML=this.hasValue()?this.stringFromValue():this.placeholder:this.toggleTextWrapper.innerHTML=(null===(t=this.getItemByValue(this.value))||void 0===t?void 0:t.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===(e=this.toggle)||void 0===e?void 0:e.ariaExpanded)&&(this._isOpened?this.toggle.ariaExpanded="true":this.toggle.ariaExpanded="false"),this.onToggleClickListener=()=>this.toggleClick(),this.toggle.addEventListener("click",this.onToggleClickListener)}setToggleIcon(){var t,e,i,s;const n=this.getItemByValue(this.value),l=this.toggle.querySelector("[data-icon]");if(l){l.innerHTML="";const a=null===(e=null===(t=null==n?void 0:n.options)||void 0===t?void 0:t.apiFields)||void 0===e?void 0:e.icon,r=null==n?void 0:n[null===(i=this.apiFieldsMap)||void 0===i?void 0:i.icon],d=null===(s=null==n?void 0:n.options)||void 0===s?void 0:s.icon,h=(0,o.fc)((this.apiUrl||a)&&this.apiIconTag?this.apiIconTag||"":d||"");this.value&&(a?h.src=a:this.apiUrl&&this.apiIconTag&&r?h.src=r:d&&"string"==typeof d&&!d.trim().startsWith("<")&&(h.src=d)),l.append(h),(h instanceof HTMLImageElement?h.src:h)?l.classList.remove("hidden"):l.classList.add("hidden")}}setToggleTitle(){const t=this.toggle.querySelector("[data-title]");let e=this.placeholder;if(this.optionAllowEmptyOption&&""===this.value){const t=this.selectOptions.find(t=>""===t.val);e=(null==t?void 0:t.title)||this.placeholder}else if(this.value)if(this.apiUrl){const t=this.staticOptions.find(t=>t.val===this.value);if(t)e=t.title;else{const t=this.remoteOptions.find(t=>`${t[this.apiFieldsMap.val]}`===this.value||`${t[this.apiFieldsMap.title]}`===this.value);t&&(e=t[this.apiFieldsMap.title])}}else{const t=this.selectOptions.find(t=>t.val===this.value);t&&(e=t.title)}t?(t.innerHTML=e,t.classList.add("truncate"),this.toggle.append(t)):this.toggleTextWrapper.innerHTML=e}buildTags(){this.isDisabled&&this.wrapper.classList.add("disabled"),this.wrapper.setAttribute("tabindex","0"),this.buildTagsInput(),this.setTagsItems()}reassignTagsInputPlaceholder(t){this.tagsInput.placeholder=t,this.tagsInputHelper.innerHTML=t,this.calculateInputWidth()}buildTagsItem(t){var e,i,s,n,l,a,r,d;const h=this.getItemByValue(t);let p,c,u,g;const v=document.createElement("div");if(v.setAttribute("data-tag-value",t),this.tagsItemClasses&&(0,o.en)(this.tagsItemClasses,v),this.tagsItemTemplate&&(p=(0,o.fc)(this.tagsItemTemplate),v.append(p)),(null===(e=null==h?void 0:h.options)||void 0===e?void 0:e.icon)||this.apiIconTag){const t=(0,o.fc)(this.apiUrl&&this.apiIconTag?this.apiIconTag:null===(i=null==h?void 0:h.options)||void 0===i?void 0:i.icon);if(this.apiUrl&&this.apiIconTag){const e=h[this.apiFieldsMap.icon]||(null===(n=null===(s=null==h?void 0:h.options)||void 0===s?void 0:s.apiFields)||void 0===n?void 0:n.icon)||(null===(l=null==h?void 0:h.options)||void 0===l?void 0:l.icon)||"";e&&(t.src=e)}g=p?p.querySelector("[data-icon]"):document.createElement("span"),g.append(t),p||v.append(g)}!p||!p.querySelector("[data-icon]")||(null===(a=null==h?void 0:h.options)||void 0===a?void 0:a.icon)||this.apiUrl||this.apiIconTag||h[null===(r=this.apiFieldsMap)||void 0===r?void 0:r.icon]||p.querySelector("[data-icon]").classList.add("hidden"),c=p?p.querySelector("[data-title]"):document.createElement("span"),this.apiUrl&&(null===(d=this.apiFieldsMap)||void 0===d?void 0:d.title)&&h[this.apiFieldsMap.title]?c.textContent=h[this.apiFieldsMap.title]:c.textContent=h.title||"",p||v.append(c),p?u=p.querySelector("[data-remove]"):(u=document.createElement("span"),u.textContent="X",v.append(u)),u.addEventListener("click",()=>{this.value=this.value.filter(e=>e!==t),this.selectedItems=this.selectedItems.filter(e=>e!==t),this.hasValue()||this.reassignTagsInputPlaceholder(this.placeholder),this.unselectMultipleItems(),this.selectMultipleItems(),v.remove(),this.triggerChangeEventForNativeSelect()}),this.wrapper.append(v)}getItemByValue(t){if(this.apiUrl){const e=this.staticOptions.find(e=>e.val===t);return e||this.remoteOptions.find(e=>`${e[this.apiFieldsMap.val]}`===t||e[this.apiFieldsMap.title]===t)}return this.selectOptions.find(e=>e.val===t)}setTagsItems(){if(this.value){(Array.isArray(this.value)?this.value:null!=this.value?[this.value]:[]).forEach(t=>{this.selectedItems.includes(t)||this.buildTagsItem(t),this.selectedItems=this.selectedItems.includes(t)?this.selectedItems:[...this.selectedItems,t]})}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)(t=>this.tagsInputInputSecond(t)),this.onTagsInputKeydownListener=t=>this.tagsInputKeydown(t),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 t="";this.selectOptions.forEach((e,i)=>{e.optgroupName&&e.optgroupName!==t&&(this.hasOptgroup=!0,t=e.optgroupName,this.buildOptgroup(t)),this.buildOption(e.title,e.val,e.disabled,e.selected,e.options,`${i}`,void 0,!!this.apiUrl)}),t=""}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(t){const e=(0,o.fc)(this.optgroupTag||"<div></div>");e.textContent=t,e.setAttribute("data-optgroup",""),this.optgroupClasses&&(0,o.en)(this.optgroupClasses,e),this.dropdown.append(e)}setupInfiniteScroll(){this.dropdown.addEventListener("scroll",this.handleScroll.bind(this))}handleScroll(){return r(this,void 0,void 0,function*(){if(!this.dropdown||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const{scrollTop:t,scrollHeight:e,clientHeight:i}=this.dropdown;e-t-i<("object"==typeof this.apiLoadMore?this.apiLoadMore.scrollThreshold:100)&&(yield this.loadMore())})}loadMore(){return r(this,void 0,void 0,function*(){var t,e,i,s,o,n,l,a,r,d,h,p;if(!this.apiUrl||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const c=this.requestId;this.isLoading=!0;try{const u=new URL(this.apiUrl),g=(null!==(t=this.lastQuery)&&void 0!==t?t:"").trim().toLowerCase(),v=new URLSearchParams(null!==(e=this.apiQuery)&&void 0!==e?e:""),m=null!==(i=this.apiSearchQueryKey)&&void 0!==i?i:"q";""!==g&&v.set(m,g),u.search=v.toString();const f=(null===(s=this.apiFieldsMap)||void 0===s?void 0:s.page)||(null===(o=this.apiFieldsMap)||void 0===o?void 0:o.offset)||"page",w=!!(null===(n=this.apiFieldsMap)||void 0===n?void 0:n.offset),y="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,b=this.currentPage+1;if(w){const t=this.currentPage*y;u.searchParams.set(f,String(t))}else u.searchParams.set(f,String(b));if(u.searchParams.set((null===(l=this.apiFieldsMap)||void 0===l?void 0:l.limit)||"limit",String(y)),this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(t){}this.loadMoreAbortController=new AbortController;const S=Object.assign(Object.assign({},this.apiOptions||{}),{signal:this.loadMoreAbortController.signal}),I=yield fetch(u.toString(),S),T=yield I.json();if(c!==this.requestId)return void(this.isLoading=!1);const C=this.apiDataPart?null!==(r=null!==(a=T[this.apiDataPart])&&void 0!==a?a:T.results)&&void 0!==r?r:T:null!==(d=T.results)&&void 0!==d?d:T,A=(t,e)=>e.split(".").reduce((t,e)=>t?t[e]:void 0,t);let O=null;if(this.apiTotalPath){const t=A(T,this.apiTotalPath);O="number"==typeof t?t:null}else O=null!==(p=null!==(h="number"==typeof T.count?T.count:null)&&void 0!==h?h:"number"==typeof T.total?T.total:null)&&void 0!==p?p:T.info&&"number"==typeof T.info.count?T.info.count:null;if(C&&C.length>0){if(this.remoteOptions=[...this.remoteOptions||[],...C],this.buildOptionsFromRemoteData(C),"number"==typeof O){const t=b*y;this.hasMore=t<O}else this.hasMore=C.length===y;this.currentPage=b}else this.hasMore=!1}catch(t){this.hasMore=!1,console.error("Error loading more options:",t)}finally{this.isLoading=!1}})}buildFloatingUI(){if("undefined"!=typeof FloatingUIDOM&&FloatingUIDOM.computePosition){document.body.appendChild(this.dropdown);const t="tags"===this.mode?this.wrapper:this.toggle,e=[FloatingUIDOM.offset([0,5])];this.dropdownAutoPlacement&&"function"==typeof FloatingUIDOM.flip&&e.push(FloatingUIDOM.flip({fallbackPlacements:["bottom-start","bottom-end","top-start","top-end"]}));const i={placement:a.lP[this.dropdownPlacement]||"bottom",strategy:"fixed",middleware:e},s=()=>{Object.assign(this.dropdown.style,{marginLeft:"",marginTop:"",marginRight:"",marginBottom:""}),FloatingUIDOM.computePosition(t,this.dropdown,i).then(({x:t,y:e,placement:i})=>{Object.assign(this.dropdown.style,{position:"fixed",left:`${t}px`,top:`${e}px`,["margin"+(i.startsWith("bottom")||i.startsWith("top")?"Top":i.startsWith("right")?"Left":"Right")]:`${i.startsWith("top")?"-":""}${this.dropdownSpace}px`}),this.dropdown.setAttribute("data-placement",i)})};s();const o=FloatingUIDOM.autoUpdate(t,this.dropdown,s);this.floatingUIInstance={update:s,destroy:o}}else console.error("FloatingUIDOM not found! Please enable it on the page.")}updateDropdownWidth(){const t="tags"===this.mode?this.wrapper:this.toggle;this.dropdown.style.width=`${t.clientWidth}px`}buildSearch(){var t,e,i;if(!this.hasSearch)return;if("tags"===this.mode){const s=null!==(i=null!==(t=this.tagsInput)&&void 0!==t?t:null===(e=this.wrapper)||void 0===e?void 0:e.querySelector(":scope input"))&&void 0!==i?i: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)(t=>this.searchInput(t)),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 n=(0,o.fc)(this.searchTemplate||'<input type="text">');this.search="INPUT"===n.tagName?n:n.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)(t=>this.searchInput(t)),this.search.addEventListener("input",this.onSearchInputListener),s?s.append(n):this.searchWrapper.append(n),this.dropdown.append(this.searchWrapper)}buildOption(t,e,i=!1,s=!1,n,l="1",a,r=!1){var d,h,p,c,u;let g=null,v=null,m=null,f=null;const w=(0,o.fc)(this.optionTag||"<div></div>");if(w.setAttribute("data-value",e),w.setAttribute("data-title-value",t),w.setAttribute("tabIndex",l),w.classList.add("cursor-pointer"),w.setAttribute("data-id",a||`${this.optionId}`),r&&w.setAttribute("data-static","true"),a||this.optionId++,i&&w.classList.add("disabled"),s&&(this.isMultiple?this.value=[...this.value,e]:this.value=e),this.optionTemplate&&(g=(0,o.fc)(this.optionTemplate),w.append(g)),g?(v=g.querySelector("[data-title]"),v.textContent=t||""):w.textContent=t||"",n){const e=null!==(h=null===(d=n.apiFields)||void 0===d?void 0:d.icon)&&void 0!==h?h:n.icon,i=null!==(c=null===(p=n.apiFields)||void 0===p?void 0:p.description)&&void 0!==c?c:n.description;if(e){const i=(0,o.fc)(null!==(u=this.apiIconTag)&&void 0!==u?u:e);if(i.classList.add("max-w-full"),(this.apiUrl||n.apiFields)&&(i.setAttribute("alt",t),i.setAttribute("src",e)),g)m=g.querySelector("[data-icon]"),m.append(i);else{const t=(0,o.fc)("<div></div>");this.iconClasses&&(0,o.en)(this.iconClasses,t),t.append(i),w.append(t)}}if(Array.isArray(n.additionalClasses)&&n.additionalClasses.forEach(([t,e])=>{const i=t?w.querySelector(t):w;i&&e.forEach(t=>i.classList.add(t))}),i)if(w.dataset.description=i,g)f=g.querySelector("[data-description]"),f&&f.append(i);else{const t=(0,o.fc)("<div></div>");t.textContent=i,this.descriptionClasses&&(0,o.en)(this.descriptionClasses,t),w.append(t)}}g&&g.querySelector("[data-icon]")&&!n&&!(null==n?void 0:n.icon)&&g.querySelector("[data-icon]").classList.add("hidden"),this.value&&(this.isMultiple?this.value.includes(e):this.value===e)&&w.classList.add("selected"),i||w.addEventListener("click",()=>this.onSelectOption(e)),this.optionClasses&&(0,o.en)(this.optionClasses,w),this.dropdown&&this.dropdown.append(w),s&&this.setNewValue()}buildOptionFromRemoteData(t,e,i=!1,s=!1,o="1",n,l){o?this.buildOption(t,e,i,s,l,o,n):alert("ID parameter is required for generating remote options! Please check your API endpoint have it.")}buildOptionsFromRemoteData(t){t.forEach((t,e)=>{let i=null,s="",o="";const n={id:"",val:"",title:"",icon:null,description:null,rest:{}};Object.keys(t).forEach(e=>{var l;t[this.apiFieldsMap.id]&&(i=t[this.apiFieldsMap.id],n.id=`${i}`),t[this.apiFieldsMap.val]&&(o=`${t[this.apiFieldsMap.val]}`,n.val=o),t[this.apiFieldsMap.title]&&(s=t[this.apiFieldsMap.title],n.title=s,t[this.apiFieldsMap.val]||(o=s,n.val=o)),t[this.apiFieldsMap.icon]&&(n.icon=t[this.apiFieldsMap.icon]),t[null===(l=this.apiFieldsMap)||void 0===l?void 0:l.description]&&(n.description=t[this.apiFieldsMap.description]),n.rest[e]=t[e]});const l=this.staticOptions.findIndex(t=>t.val===o);if(-1!==l)return void this.mergeRemoteDataIntoStaticOption(l,o,n,e);if(!this.dropdown.querySelector(`[data-value="${o}"]`)){const t=!!this.apiSelectedValues&&(Array.isArray(this.apiSelectedValues)?this.apiSelectedValues.includes(o):this.apiSelectedValues===o);this.buildOriginalOption(s,o,i,!1,t,n),this.buildOptionFromRemoteData(s,o,!1,t,`${e}`,i,n),t&&(this.isMultiple?(this.value||(this.value=[]),Array.isArray(this.value)&&(this.value=[...this.value,o])):this.value=o,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(t,e,i,s){const n=this.staticOptions[t];n.options||(n.options={}),n.options.apiFields||(n.options.apiFields={}),i.title&&(n.title=i.title),i.icon&&(n.options.apiFields.icon=i.icon),i.description&&(n.options.apiFields.description=i.description),Object.keys(i.rest).forEach(t=>{n.options.apiFields[t]=i.rest[t]});const l=this.dropdown.querySelector(`[data-value="${e}"][data-static]`);if(l){if(l.setAttribute("tabIndex",`${s}`),i.id&&l.setAttribute("data-id",`${i.id}`),i.title){l.setAttribute("data-title-value",i.title);const t=l.querySelector("[data-title]");t&&(t.textContent=i.title)}if(i.icon){const t=l.querySelector("[data-icon]");if(t){t.innerHTML="";const e=(0,o.fc)(this.apiIconTag||"<img />");e.classList.add("max-w-full"),e.setAttribute("alt",n.title),e.setAttribute("src",i.icon),t.append(e)}}if(i.description){l.dataset.description=i.description;const t=l.querySelector("[data-description]");t&&(t.textContent=i.description)}}const a=this.el.querySelector(`option[value="${e}"][data-static]`);if(a){i.id&&a.setAttribute("data-id",`${i.id}`),i.title&&(a.textContent=i.title);const t={id:i.id||"",val:i.val||"",title:i.title||"",icon:i.icon||null,description:i.description||null,rest:i.rest};a.setAttribute("data-hs-select-option",JSON.stringify(t))}const r=this.selectOptions.findIndex(t=>t.val===e);-1!==r&&(this.selectOptions[r]=n);(this.isMultiple?Array.isArray(this.value)&&this.value.includes(e):this.value===e)&&this.toggle&&(i.title&&(this.toggle.querySelector("[data-title]")?this.setToggleTitle():this.toggleTextWrapper&&(this.isMultiple?this.toggleTextWrapper.innerHTML=this.stringFromValue():this.toggleTextWrapper.innerHTML=i.title)),i.icon&&this.toggle.querySelector("[data-icon]")&&this.setToggleIcon())}optionsFromRemoteData(){return r(this,arguments,void 0,function*(t=""){const e=(yield this.apiRequest(t))||[];this.remoteOptions=e,e.length?this.buildOptionsFromRemoteData(this.remoteOptions):console.log("There is no data were responded!")})}apiRequest(){return r(this,arguments,void 0,function*(t="",e){var i,s,o,n,l,a,r,d,h,p;try{const c=new URL(this.apiUrl),u=new URLSearchParams(null!==(i=this.apiQuery)&&void 0!==i?i:""),g=null!==(s=this.apiOptions)&&void 0!==s?s:{},v=Object.assign({},g);e&&(v.signal=e);const m=null!==(o=this.apiSearchQueryKey)&&void 0!==o?o:"q",f=(null!=t?t:"").trim().toLowerCase();if(""!==f&&u.set(m,f),this.apiLoadMore){const t="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,e=null!==(r=null!==(l=null===(n=this.apiFieldsMap)||void 0===n?void 0:n.page)&&void 0!==l?l:null===(a=this.apiFieldsMap)||void 0===a?void 0:a.offset)&&void 0!==r?r:"page",i=null!==(h=null===(d=this.apiFieldsMap)||void 0===d?void 0:d.limit)&&void 0!==h?h:"limit",s=Boolean(null===(p=this.apiFieldsMap)||void 0===p?void 0:p.offset)?0:1,o="number"==typeof this.apiPageStart?this.apiPageStart:s;u.delete(e),u.delete(i),u.set(e,String(o)),u.set(i,String(t))}c.search=u.toString();const w=yield fetch(c.toString(),v),y=yield w.json();return this.apiDataPart?y[this.apiDataPart]:y}catch(t){console.error(t)}})}sortElements(t,e){if(this.hasOptgroup)return;const i=Array.from(t.querySelectorAll(e));this.isSelectedOptionOnTop&&i.sort((t,e)=>{const i=t.classList.contains("selected")||t.hasAttribute("selected"),s=e.classList.contains("selected")||e.hasAttribute("selected");return i&&!s?-1:!i&&s?1:0}),i.forEach((e,i)=>{t.appendChild(e),e.hasAttribute("tabindex")&&e.setAttribute("tabIndex",`${i}`)})}remoteSearch(t){return r(this,void 0,void 0,function*(){var e,i,s,o;if(this.requestId++,this.remoteSearchAbortController)try{this.remoteSearchAbortController.abort()}catch(t){}if(this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(t){}if(this.remoteSearchAbortController=new AbortController,this.currentPage=0,this.hasMore=!0,this.isLoading=!1,this.filterStaticOptions(t),t.length<=this.minSearchLength){const t=yield this.apiRequest("",null===(e=this.remoteSearchAbortController)||void 0===e?void 0:e.signal);if(!t)return!1;const s=Boolean(null===(i=this.apiFieldsMap)||void 0===i?void 0:i.offset)?0:1,o="number"==typeof this.apiPageStart?this.apiPageStart:s;this.currentPage=o;const n=Array.isArray(this.value)?this.value:this.value?[this.value]:[],l=this.remoteOptions.filter(t=>{var e;return n.includes(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)}),a=new Set(t.map(t=>{var e;return`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`}));return this.remoteOptions=[...t,...l.filter(t=>{var e;return!a.has(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)})],Array.from(this.dropdown.querySelectorAll("[data-value]:not([data-static])")).forEach(t=>{n.includes(t.getAttribute("data-value"))||t.remove()}),Array.from(this.el.querySelectorAll("option[value][data-hs-select-option]:not([data-static])")).forEach(t=>{n.includes(t.value)||t.remove()}),t.length?this.buildOptionsFromRemoteData(t):console.log("No data responded!"),!1}const n=yield this.apiRequest(t,null===(s=this.remoteSearchAbortController)||void 0===s?void 0:s.signal);if(!n)return;const l=Boolean(null===(o=this.apiFieldsMap)||void 0===o?void 0:o.offset)?0:1,a="number"==typeof this.apiPageStart?this.apiPageStart:l;this.currentPage=a;const r=Array.isArray(this.value)?this.value:this.value?[this.value]:[],d=this.remoteOptions.filter(t=>{var e;return r.includes(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)}),h=new Set(n.map(t=>{var e;return`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`}));this.remoteOptions=[...n,...d.filter(t=>{var e;return!h.has(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)})];let p=n.map(t=>`${t.id}`),c=null;const u=this.dropdown.querySelectorAll("[data-value]:not([data-static])");this.el.querySelectorAll("[data-hs-select-option]:not([data-static])").forEach(t=>{var e;const i=t.getAttribute("data-id");p.includes(i)||(null===(e=this.value)||void 0===e?void 0:e.includes(t.value))||this.destroyOriginalOption(t.value)}),u.forEach(t=>{var e;const i=t.getAttribute("data-id");p.includes(i)||(null===(e=this.value)||void 0===e?void 0:e.includes(t.getAttribute("data-value")))?p=p.filter(t=>t!==i):this.destroyOption(t.getAttribute("data-value"))}),c=n.filter(t=>p.includes(`${t.id}`)),c.length?this.buildOptionsFromRemoteData(c):console.log("No data responded!")})}filterStaticOptions(t){const e=this.dropdown.querySelectorAll("[data-value][data-static]"),i=t.trim().toLowerCase();e.forEach(t=>{var e,s;if(i.length<=this.minSearchLength)t.classList.remove("hidden");else{const o=(null===(e=t.getAttribute("data-title-value"))||void 0===e?void 0:e.toLowerCase())||"",n=(null===(s=t.dataset.description)||void 0===s?void 0:s.toLowerCase())||"";this.optionMatchesQuery(i,o,n)?t.classList.remove("hidden"):t.classList.add("hidden")}})}normalizeSearchText(t=""){return t.toLocaleLowerCase().replace(/\s+/g," ").trim()}tokenizeSearchQuery(t){return this.normalizeSearchText(t).split(" ").filter(Boolean)}charsSequenceMatch(t,e){const i=t.split("").map(t=>/\w/.test(t)?`${t}[\\W_]*`:"\\W*").join("");return new RegExp(i,"i").test(e)}optionMatchesQuery(t,e,i=""){const s=this.normalizeSearchText(t);if(!s)return!0;const o=this.normalizeSearchText(e),n=this.normalizeSearchText(i),l=this.preventSearchInsideDescription?[o]:[o,n];if("token-all"===this.searchMatchMode){const t=this.tokenizeSearchQuery(s);return l.some(e=>t.every(t=>e.includes(t)))}if("hybrid"===this.searchMatchMode){const t=this.tokenizeSearchQuery(s);return l.some(e=>{const i=t.every(t=>e.includes(t)),o=this.charsSequenceMatch(s,e);return i||o})}return"chars-sequence"===this.searchMatchMode?l.some(t=>this.charsSequenceMatch(s,t)):l.some(t=>t.includes(s))}destroyOption(t){const e=this.dropdown.querySelector(`[data-value="${t}"]`);if(!e)return!1;e.remove()}buildOriginalOption(t,e,i,s,n,l){const a=(0,o.fc)("<option></option>");a.setAttribute("value",e),s&&a.setAttribute("disabled","disabled"),n&&a.setAttribute("selected","selected"),i&&a.setAttribute("data-id",i),a.setAttribute("data-hs-select-option",JSON.stringify(l)),a.innerText=t,this.el.append(a)}destroyOriginalOption(t){const e=this.el.querySelector(`[value="${t}"]`);if(!e)return!1;e.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 t=parseInt(window.getComputedStyle(this.tagsInput).paddingLeft)+parseInt(window.getComputedStyle(this.tagsInput).paddingRight),e=parseInt(window.getComputedStyle(this.tagsInput).borderLeftWidth)+parseInt(window.getComputedStyle(this.tagsInput).borderRightWidth),i=this.tagsInputHelper.offsetWidth+t+e,s=this.wrapper.offsetWidth-(parseInt(window.getComputedStyle(this.wrapper).paddingLeft)+parseInt(window.getComputedStyle(this.wrapper).paddingRight));this.tagsInput.style.width=`${Math.min(i,s)+2}px`}adjustInputWidth(){this.buildTagsInputHelper(),this.calculateInputWidth()}onSelectOption(t){if(this.clearSelections(),this.isMultiple?(Array.isArray(this.value)||(this.value=[]),this.value=this.value.includes(t)?this.value.filter(e=>e!==t):[...this.value,t],this.selectMultipleItems(),this.setNewValue()):(this.value=t,this.selectSingleItem(),this.setNewValue()),this.fireEvent("change",this.value),"tags"===this.mode){const t=this.selectedItems.filter(t=>!this.value.includes(t));t.length&&t.forEach(t=>{this.selectedItems=this.selectedItems.filter(e=>e!==t),this.wrapper.querySelector(`[data-tag-value="${t}"]`).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 t=new Event("change",{bubbles:!0});this.el.dispatchEvent(t),(0,o.JD)("change.hs.select",this.el,this.value)}addSelectOption(t,e,i,s,o){this.selectOptions=[...this.selectOptions,{title:t,val:e,disabled:i,selected:s,options:o}]}removeSelectOption(t,e=!1){if(!!!this.selectOptions.some(e=>e.val===t))return!1;this.selectOptions=this.selectOptions.filter(e=>e.val!==t),this.value=e?this.value.filter(e=>e!==t):t}resetTagsInputField(){this.tagsInput.value="",this.reassignTagsInputPlaceholder(""),this.searchOptions("")}clearSelections(){const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(t=>{t.classList.contains("selected")&&t.classList.remove("selected")}),Array.from(t).forEach(t=>{t.selected&&(t.selected=!1)})}setNewValue(){if("tags"===this.mode)this.setTagsItems();else if(this.optionAllowEmptyOption&&""===this.value){const t=this.selectOptions.find(t=>""===t.val);this.toggleTextWrapper.innerHTML=(null==t?void 0:t.title)||this.placeholder}else if(this.hasValue())if(this.apiUrl){const t=this.dropdown.querySelector(`[data-value="${this.value}"]`);if(t)this.toggleTextWrapper.innerHTML=t.getAttribute("data-title-value")||this.placeholder;else{const t=this.staticOptions.find(t=>t.val===this.value);if(t)this.toggleTextWrapper.innerHTML=t.title;else{const t=this.remoteOptions.find(t=>(t[this.apiFieldsMap.val]?`${t[this.apiFieldsMap.val]}`:t[this.apiFieldsMap.title])===this.value);this.toggleTextWrapper.innerHTML=t?`${t[this.apiFieldsMap.title]}`:this.stringFromValue()}}}else this.toggleTextWrapper.innerHTML=this.stringFromValue();else this.toggleTextWrapper.innerHTML=this.placeholder}stringFromValueBasic(t){var e;const i=[];let s="";if(t.forEach(t=>{this.isMultiple?Array.isArray(this.value)&&this.value.includes(t.val)&&i.push(t.title):this.value===t.val&&i.push(t.title)}),void 0!==this.toggleCountText&&null!==this.toggleCountText&&i.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const t=i.slice(0,this.toggleCountTextMinItems-1),o=[t.join(this.toggleSeparators.items)],n=""+(i.length-t.length);if((null===(e=null==this?void 0:this.toggleSeparators)||void 0===e?void 0:e.betweenItemsAndCounter)&&o.push(this.toggleSeparators.betweenItemsAndCounter),this.toggleCountText)switch(this.toggleCountTextPlacement){case"postfix-no-space":o.push(`${n}${this.toggleCountText}`);break;case"prefix-no-space":o.push(`${this.toggleCountText}${n}`);break;case"prefix":o.push(`${this.toggleCountText} ${n}`);break;default:o.push(`${n} ${this.toggleCountText}`)}s=o.join(" ")}else s=`${i.length} ${this.toggleCountText}`;else s=i.join(this.toggleSeparators.items);return s}stringFromValueRemoteData(){if(!this.dropdown)return this.stringFromValueBasic(this.selectOptions);const t=this.dropdown.querySelectorAll("[data-title-value]"),e=[];let i="";if(t.forEach(t=>{const i=t.getAttribute("data-value"),s=t.getAttribute("data-title-value");this.isMultiple?Array.isArray(this.value)&&this.value.includes(i)&&e.push(s):this.value===i&&e.push(s)}),this.toggleCountText&&""!==this.toggleCountText&&e.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const t=e.slice(0,this.toggleCountTextMinItems-1);i=`${t.join(this.toggleSeparators.items)} ${this.toggleSeparators.betweenItemsAndCounter} ${e.length-t.length} ${this.toggleCountText}`}else i=`${e.length} ${this.toggleCountText}`;else i=e.join(this.toggleSeparators.items);return i}stringFromValue(){return this.apiUrl?this.stringFromValueRemoteData():this.stringFromValueBasic(this.selectOptions)}selectSingleItem(){const t=this.el.querySelectorAll("option");Array.from(t).find(t=>this.value===t.value).selected=!0;const e=Array.from(this.dropdown.children).find(t=>this.value===t.getAttribute("data-value"));e&&e.classList.add("selected"),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}selectMultipleItems(){if(!Array.isArray(this.value))return;const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).filter(t=>this.value.includes(t.getAttribute("data-value"))).forEach(t=>t.classList.add("selected")),Array.from(t).filter(t=>this.value.includes(t.value)).forEach(t=>t.selected=!0),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}unselectMultipleItems(){const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(t=>t.classList.remove("selected")),Array.from(t).forEach(t=>t.selected=!1),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}searchOptions(t){if(t.length<=this.minSearchLength){this.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null);return this.dropdown.querySelectorAll("[data-value]").forEach(t=>{t.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 e=this.dropdown.querySelectorAll("[data-value]");let i,s=!1;this.searchLimit&&(i=0),e.forEach(e=>{var o;const n=e.getAttribute("data-title-value")||"",l=(null===(o=null==e?void 0:e.dataset)||void 0===o?void 0:o.description)||"";!this.optionMatchesQuery(t,n,l)||this.searchLimit&&i>=this.searchLimit?e.classList.add("hidden"):(e.classList.remove("hidden"),s=!0,this.searchLimit&&i++)}),s||this.dropdown.append(this.se