@nuralyui/select 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bundle.js CHANGED
@@ -1,12 +1,776 @@
1
- import{css as t,nothing as e,html as i,LitElement as s}from"lit";import{property as o,query as r,customElement as n}from"lit/decorators.js";import{map as a}from"lit/directives/map.js";import{choose as l}from"lit/directives/choose.js";import{classMap as c}from"lit/directives/class-map.js";import{styleMap as h}from"lit/directives/style-map.js";import{NuralyUIBaseMixin as d}from"@nuralyui/common/mixins";const u=t`:host{--nuraly-select-local-min-height:40px;--nuraly-select-local-padding-top:8px;--nuraly-select-local-padding-bottom:8px;--nuraly-select-local-padding-left:12px;--nuraly-select-local-padding-right:12px;--nuraly-select-local-wrapper-margin:0;--nuraly-select-local-border-radius:6px;--nuraly-select-local-border-width:1px;--nuraly-select-local-dropdown-z-index:9999;--nuraly-select-local-dropdown-max-height:200px;--nuraly-select-local-dropdown-width:max-content;--nuraly-select-local-placeholder-font-size:14px;--nuraly-select-local-option-font-size:14px;--nuraly-select-local-medium-height:40px;--nuraly-select-local-medium-font-size:14px;--nuraly-select-local-medium-padding:8px 12px;--nuraly-select-local-small-font-size:12px;--nuraly-select-local-dropdown-animation-duration:0.15s;--nuraly-select-local-tag-border-radius:4px;--nuraly-select-local-tag-padding:2px 6px;--nuraly-select-local-tag-margin:2px;--nuraly-select-local-message-font-size:12px;--nuraly-select-local-message-margin-top:4px}:host{width:fit-content;display:block;font-family:var(--nuraly-select-font-family, Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif);font-size:var(--nuraly-select-font-size,14px);line-height:var(--nuraly-select-line-height,1.5);margin:var(--nuraly-select-margin,var(--nuraly-select-local-wrapper-margin))}:host([disabled]){opacity:var(--nuraly-select-disabled-opacity,.5);pointer-events:none}:host([disabled]) .wrapper{background-color:var(--nuraly-select-disabled-background,#f9fafb);border-color:var(--nuraly-select-disabled-border-color,#d9d9d9);color:var(--nuraly-select-disabled-text-color,#8c8c8c);cursor:not-allowed}:host([size=small]) .wrapper{height:var(--nuraly-select-small-height,24px);min-height:var(--nuraly-select-small-height,24px);font-size:var(--nuraly-select-small-font-size,var(--nuraly-select-local-small-font-size))}:host([size=small]) .select-trigger{padding:var(--nuraly-select-small-padding,2px 8px);padding-right:calc(var(--nuraly-select-icon-size,16px) + 20px)}:host([size=medium]) .wrapper{min-height:var(--nuraly-select-medium-height,var(--nuraly-select-local-medium-height));font-size:var(--nuraly-select-medium-font-size,var(--nuraly-select-local-medium-font-size))}:host([size=medium]) .select-trigger{padding:var(--nuraly-select-medium-padding,var(--nuraly-select-local-medium-padding));padding-right:calc(var(--nuraly-select-icon-size,16px) + 20px)}:host([size=large]) .wrapper{min-height:var(--nuraly-select-large-height,48px);font-size:var(--nuraly-select-large-font-size,16px)}:host([size=large]) .select-trigger{padding:var(--nuraly-select-large-padding,12px 16px);padding-right:calc(var(--nuraly-select-icon-size,16px) + 20px)}:host([status=error]) .wrapper{border-color:var(--nuraly-select-error-border-color,#ef4444)}:host([status=warning]) .wrapper{border-color:var(--nuraly-select-warning-border-color,#f59e0b)}:host([status=success]) .wrapper{border-color:var(--nuraly-select-success-border-color,#10b981)}:host([type=inline]){display:flex;align-items:center;gap:8px}:host([type=inline]) .wrapper{flex:1}:host([block]){width:100%}:host([block]) .wrapper{width:100%}:host([show]) .options{display:flex!important}.wrapper{position:relative;width:var(--nuraly-select-width,fit-content);background-color:var(--nuraly-select-background-color,#fff);border:var(--nuraly-select-border-width,var(--nuraly-select-local-border-width)) solid var(--nuraly-select-border-color,#d9d9d9);border-radius:var(--nuraly-select-border-radius,var(--nuraly-select-local-border-radius));transition:all var(--nuraly-select-transition-duration,.2s) var(--nuraly-select-transition-timing,ease-in-out);cursor:pointer;outline:0;margin:var(--nuraly-select-wrapper-margin,0);min-height:var(--nuraly-select-min-height,var(--nuraly-select-local-min-height));box-sizing:border-box;display:flex;align-items:center;overflow:visible}.wrapper:hover:not(:disabled){border-color:var(--nuraly-select-border-hover,#7c3aed)}.wrapper:focus,.wrapper:focus-within{border-color:var(--nuraly-select-border-focus,#7c3aed);box-shadow:0 0 0 2px var(--nuraly-select-focus-outline,rgba(124,58,237,.2))}.select{display:flex;flex-direction:column}.select-trigger{display:flex;align-items:center;padding:var(--nuraly-select-padding-top,var(--nuraly-select-local-padding-top)) calc(var(--nuraly-select-icon-size,16px) + 20px) var(--nuraly-select-padding-bottom,var(--nuraly-select-local-padding-bottom)) var(--nuraly-select-padding-left,var(--nuraly-select-local-padding-left));color:var(--nuraly-select-text-color,#262626);font-size:inherit;line-height:inherit;word-break:break-word;flex:1;min-height:0;flex-wrap:wrap;gap:var(--nuraly-select-tag-margin,var(--nuraly-select-local-tag-margin));box-sizing:border-box}.select-trigger:empty:before{content:attr(data-placeholder);color:var(--nuraly-select-placeholder-color,#8c8c8c);font-size:var(--nuraly-select-placeholder-font-size,var(--nuraly-select-local-placeholder-font-size))}.tag{display:inline-flex;align-items:center;gap:4px;background-color:var(--nuraly-select-tag-background,var(--nuraly-select-local-tag-background));color:var(--nuraly-select-tag-color,var(--nuraly-select-local-tag-color));padding:var(--nuraly-select-tag-padding,var(--nuraly-select-local-tag-padding));border-radius:var(--nuraly-select-tag-border-radius,var(--nuraly-select-local-tag-border-radius));font-size:calc(var(--nuraly-select-font-size,var(--nuraly-select-local-font-size)) - 1px);max-width:100%}.tag-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tag-close{color:var(--nuraly-select-tag-close-color,var(--nuraly-select-local-tag-close-color));cursor:pointer;display:flex;align-items:center;justify-content:center;width:var(--nuraly-select-icon-size,var(--nuraly-select-local-icon-size));height:var(--nuraly-select-icon-size,var(--nuraly-select-local-icon-size));border-radius:50%;transition:color var(--nuraly-select-transition-duration,var(--nuraly-select-local-transition-duration))}.tag-close:hover{color:var(--nuraly-select-tag-close-hover-color,var(--nuraly-select-local-tag-close-hover-color))}.icons-container{position:absolute;top:50%;right:12px;transform:translateY(-50%);display:flex;align-items:center;gap:4px;pointer-events:none}.icons-container nr-icon{--nuraly-icon-width:var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));--nuraly-icon-color:var(--nuraly-select-icon-color, var(--nuraly-select-local-icon-color));pointer-events:auto;cursor:pointer;transition:color var(--nuraly-select-transition-duration,var(--nuraly-select-local-transition-duration))}.icons-container nr-icon:hover{--nuraly-icon-color:var(--nuraly-select-icon-hover-color, var(--nuraly-select-local-icon-hover-color))}.arrow-icon{--nuraly-icon-width:var(--nuraly-select-arrow-icon-size, var(--nuraly-select-local-arrow-icon-size));transition:transform var(--nuraly-select-transition-duration,var(--nuraly-select-local-transition-duration));pointer-events:none!important}:host([show]) .arrow-icon{transform:rotate(180deg)}.options{position:absolute;top:100%;margin-top:1px;left:0;right:0;background-color:var(--nuraly-select-dropdown-background,#fff);border:var(--nuraly-select-dropdown-border-width,var(--nuraly-select-border-width,1px)) solid var(--nuraly-select-dropdown-border-color,#d9d9d9);border-radius:var(--nuraly-select-dropdown-border-radius,var(--nuraly-select-border-radius,6px));box-shadow:var(--nuraly-select-dropdown-shadow,0 6px 16px 0 rgba(0,0,0,.08));z-index:var(--nuraly-select-dropdown-z-index,9999);max-height:var(--nuraly-select-dropdown-max-height,200px);overflow-y:auto;overflow-x:hidden;display:none;flex-direction:column;animation:dropdown-enter var(--nuraly-select-dropdown-animation-duration,.15s) ease-out;box-sizing:border-box;width:var(--nuraly-select-dropdown-width,var(--select-dropdown-width,var(--nuraly-select-local-dropdown-width)));min-width:100%;isolation:isolate;backdrop-filter:none;-webkit-backdrop-filter:none;transform:translateZ(0)}.options.placement-top{top:auto;bottom:100%;margin-bottom:1px;margin-top:0;animation:dropdown-enter-top var(--nuraly-select-dropdown-animation-duration,var(--nuraly-select-local-dropdown-animation-duration)) ease-out}@keyframes dropdown-enter{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}@keyframes dropdown-enter-top{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.search-container{position:sticky;top:0;z-index:10;background-color:var(--nuraly-select-dropdown-background,#fff);border-bottom:var(--nuraly-select-border-width,1px) solid var(--nuraly-select-dropdown-border-color,#d9d9d9);padding:8px;margin:0;backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);will-change:transform;transform:translateZ(0)}.search-container .search-input{width:100%;--nuraly-input-border-radius:var(--nuraly-select-border-radius, var(--nuraly-select-local-border-radius));--nuraly-input-background-color:var(--nuraly-select-background-color, var(--nuraly-select-local-background-color));--nuraly-input-border-color:var(--nuraly-select-border-color, var(--nuraly-select-local-border-color));--nuraly-input-text-color:var(--nuraly-select-text-color, var(--nuraly-select-local-text-color));--nuraly-input-placeholder-color:var(--nuraly-select-placeholder-color, var(--nuraly-select-local-placeholder-color))}.search-container .search-icon{--nuraly-icon-color:var(--nuraly-select-icon-color, var(--nuraly-select-local-icon-color))}.options:has(.search-container){padding-top:0}.option{display:flex;align-items:center;gap:8px;padding:var(--nuraly-select-option-padding,8px 12px);min-height:var(--nuraly-select-option-min-height,auto);color:var(--nuraly-select-option-text-color,var(--nuraly-select-text-color,#262626));font-size:var(--nuraly-select-option-font-size,14px);cursor:pointer;transition:background-color var(--nuraly-select-transition-duration,.2s);position:relative}.search-container+.option{margin-top:0}.option:hover{background-color:var(--nuraly-select-option-hover-background,#f5f5f5)}.option.selected{background-color:var(--nuraly-select-option-selected-background,#e0e0e0);color:var(--nuraly-select-option-selected-color,#7c3aed)}.option.focused{background-color:var(--nuraly-select-option-hover-background,#f5f5f5);outline:2px solid var(--nuraly-select-border-focus,#7c3aed);outline-offset:-2px}.option.disabled{opacity:var(--nuraly-select-disabled-opacity,var(--nuraly-select-local-disabled-opacity));cursor:not-allowed}.option-content{flex:1;display:flex;align-items:center;gap:8px}.option-icon{--nuraly-icon-width:var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));--nuraly-icon-color:currentColor}.option-text{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.option-description{font-size:calc(var(--nuraly-select-option-font-size,var(--nuraly-select-local-option-font-size)) - 1px);opacity:.7;margin-top:2px}.check-icon{--nuraly-icon-width:var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));--nuraly-icon-color:var(--nuraly-select-option-selected-color, var(--nuraly-select-local-option-selected-color))}.no-options{display:flex;align-items:center;justify-content:center;padding:var(--select-no-options-padding,24px 16px);color:var(--select-no-options-color,#8c8c8c);font-size:var(--nuraly-select-option-font-size,var(--nuraly-select-local-option-font-size));cursor:default;user-select:none}.no-options-content{display:flex;flex-direction:column;align-items:center;gap:var(--select-no-options-gap,8px);text-align:center}.no-options-icon{--nuraly-icon-width:24px;--nuraly-icon-color:var(--select-no-options-icon-color, #d9d9d9);opacity:.8}.no-options-text{font-size:var(--nuraly-select-option-font-size,var(--nuraly-select-local-option-font-size));color:var(--select-no-options-color,#8c8c8c);line-height:1.4}.validation-message{display:block;margin-top:var(--nuraly-select-message-margin-top,var(--nuraly-select-local-message-margin-top));font-size:var(--nuraly-select-message-font-size,var(--nuraly-select-local-message-font-size));color:var(--nuraly-select-error-message-color,var(--nuraly-select-local-error-message-color))}.validation-message.warning{color:var(--nuraly-select-warning-message-color,var(--nuraly-select-local-warning-message-color))}.validation-message.success{color:var(--nuraly-select-success-message-color,var(--nuraly-select-local-success-message-color))}::slotted([slot=label]){display:block;margin-bottom:4px;font-weight:500;color:var(--nuraly-select-text-color,var(--nuraly-select-local-text-color))}::slotted([slot=helper-text]){display:block;margin-top:var(--nuraly-select-message-margin-top,var(--nuraly-select-local-message-margin-top));font-size:var(--nuraly-select-message-font-size,var(--nuraly-select-local-message-font-size));color:var(--nuraly-select-placeholder-color,var(--nuraly-select-local-placeholder-color))}@media (prefers-reduced-motion:reduce){.arrow-icon,.option,.options,.tag-close,.wrapper{transition:none;animation:none}}@media (prefers-contrast:high){.wrapper{border-width:2px}.wrapper:focus,.wrapper:focus-within{outline:3px solid}}`;var p,v,y,g,m,f,b,w,x;!function(t){t.Default="default",t.Inline="inline",t.Button="button",t.Slot="slot"}(p||(p={})),function(t){t.Default="default",t.Warning="warning",t.Error="error",t.Success="success"}(v||(v={})),function(t){t.Small="small",t.Medium="medium",t.Large="large"}(y||(y={})),function(t){t.Small="small",t.Medium="medium",t.Large="large"}(g||(g={})),function(t){t.Horizontal="horizontal",t.Vertical="vertical"}(m||(m={})),function(t){t.Default="default",t.Solid="solid",t.Outline="outline",t.Borderless="borderless"}(f||(f={})),function(t){t.Bottom="bottom",t.Top="top",t.Auto="auto"}(b||(b={})),function(t){t.None="none",t.StartsWith="starts-with",t.Contains="contains",t.Fuzzy="fuzzy"}(w||(w={}));class O{constructor(t){this._host=t,this._host.addController(this)}get host(){return this._host}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}handleError(t,e){console.error(`[SelectController:${this.constructor.name}] Error in ${e}:`,t),this._host.dispatchEvent(new CustomEvent("nr-select-error",{detail:{error:t.message,context:e,controller:this.constructor.name},bubbles:!0,composed:!0}))}requestUpdate(){try{this._host.requestUpdate()}catch(t){this.handleError(t,"requestUpdate")}}dispatchEvent(t){try{return this._host.dispatchEvent(t)}catch(t){return this.handleError(t,"dispatchEvent"),!1}}}class E extends O{constructor(){super(...arguments),this._selectedOptions=[],this._initialized=!1}getSelectedOptions(){return[...this._selectedOptions]}getSelectedOption(){return this._selectedOptions[0]}selectOption(t){try{if(this.isOptionDisabled(t))return;const e=this.host.multiple,i=this.getCurrentValue();e?this.isOptionSelected(t)||(this._selectedOptions=[...this._selectedOptions,t],this.updateHostValue(),this.dispatchChangeEvent(i)):(this.isOptionSelected(t)?this._selectedOptions=[]:this._selectedOptions=[t],this.updateHostValue(),this.dispatchChangeEvent(i)),this.requestUpdate()}catch(t){this.handleError(t,"selectOption")}}unselectOption(t){try{if(this.isOptionSelected(t)){const e=this.getCurrentValue();this._selectedOptions=this._selectedOptions.filter((e=>e.value!==t.value)),this.updateHostValue(),this.dispatchChangeEvent(e),this.requestUpdate()}}catch(t){this.handleError(t,"unselectOption")}}clearSelection(){try{if(this._selectedOptions.length>0){const t=this.getCurrentValue();this._selectedOptions=[],this.updateHostValue(),this.dispatchChangeEvent(t),this.requestUpdate()}}catch(t){this.handleError(t,"clearSelection")}}isOptionSelected(t){return this._selectedOptions.some((e=>e.value===t.value))}isOptionDisabled(t){return Boolean(t.disabled)||this.host.disabled}toggleOption(t){this.isOptionSelected(t)?this.unselectOption(t):this.selectOption(t)}initializeFromValue(){try{if(this._initialized)return;const t=this.host.value;if(!t||Array.isArray(t)&&0===t.length)return;const e=Array.isArray(t)?t:[t],i=this.host.options.filter((t=>e.includes(t.value)));i.length>0&&(this._selectedOptions=this.host.multiple?i:[i[0]],this.requestUpdate()),this._initialized=!0}catch(t){this.handleError(t,"initializeFromValue")}}updateHostValue(){var t;const e=this.host.multiple?this._selectedOptions.map((t=>t.value)):(null===(t=this._selectedOptions[0])||void 0===t?void 0:t.value)||"",i=this.host.value;let s=!1;if(this.host.multiple){const t=Array.isArray(i)?i:[],o=Array.isArray(e)?e:[];s=t.length===o.length&&t.every(((t,e)=>t===o[e]))}else s=i===e;s||(this.host.value=e)}getCurrentValue(){var t;return this.host.multiple?this._selectedOptions.map((t=>t.value)):(null===(t=this._selectedOptions[0])||void 0===t?void 0:t.value)||""}dispatchChangeEvent(t){const e={value:this.getCurrentValue(),selectedOptions:this.getSelectedOptions(),previousValue:t};this.dispatchEvent(new CustomEvent("nr-change",{detail:e,bubbles:!0,composed:!0}))}hostUpdated(){this.syncWithHostOptions()}syncWithHostOptions(){try{this._selectedOptions=this._selectedOptions.filter((t=>this.host.options.some((e=>e.value===t.value)))),this._selectedOptions=this._selectedOptions.map((t=>this.host.options.find((e=>e.value===t.value))||t)),this.updateHostValue()}catch(t){this.handleError(t,"syncWithHostOptions")}}}class z extends O{constructor(t,e,i){super(t),this.selectionController=e,this.dropdownController=i,this._focusedIndex=-1,this._hasKeyboardNavigated=!1}handleKeyDown(t){try{const e=this.isSearchInputFocused();switch(t.key){case"ArrowDown":t.preventDefault(),this.dropdownController.isOpen?this.navigateNext():this.openDropdown();break;case"ArrowUp":t.preventDefault(),this.dropdownController.isOpen?this.navigatePrevious():this.openDropdown();break;case"Enter":this.dropdownController.isOpen?e&&this._focusedIndex>=0?(t.preventDefault(),this.selectFocused()):e||(t.preventDefault(),this.selectFocused()):(t.preventDefault(),this.openDropdown());break;case" ":e||(t.preventDefault(),this.dropdownController.isOpen?this.selectFocused():this.openDropdown());break;case"Escape":t.preventDefault(),this.closeDropdown();break;case"Tab":this.closeDropdown();break;case"Home":this.dropdownController.isOpen&&(t.preventDefault(),this.setFocusedIndex(0));break;case"End":this.dropdownController.isOpen&&(t.preventDefault(),this.setFocusedIndex(this.host.options.length-1));break;default:1===t.key.length&&/[a-zA-Z0-9]/.test(t.key)&&this.handleAlphanumericKey(t.key.toLowerCase())}}catch(t){this.handleError(t,"handleKeyDown")}}navigateNext(){try{const t=this.getNavigableOptions();if(0===t.length)return;if(this.isSearchInputFocused()&&(this._focusedIndex<0||!this._hasKeyboardNavigated))return this._hasKeyboardNavigated=!0,void this.setFocusedIndex(0);let e=this._focusedIndex+1;e>=t.length&&(e=0),this.setFocusedIndex(e)}catch(t){this.handleError(t,"navigateNext")}}navigatePrevious(){try{const t=this.getNavigableOptions();if(0===t.length)return;if(this.isSearchInputFocused()&&(this._focusedIndex<0||!this._hasKeyboardNavigated))return this._hasKeyboardNavigated=!0,void this.setFocusedIndex(t.length-1);let e=this._focusedIndex-1;e<0&&(e=t.length-1),this.setFocusedIndex(e)}catch(t){this.handleError(t,"navigatePrevious")}}selectFocused(){try{const t=this.getNavigableOptions()[this._focusedIndex];t&&!this.selectionController.isOptionDisabled(t)&&(this.selectionController.selectOption(t),this.host.multiple||this.closeDropdown())}catch(t){this.handleError(t,"selectFocused")}}openDropdown(){try{this.dropdownController.open(),this._hasKeyboardNavigated=!1,this._focusedIndex=-1}catch(t){this.handleError(t,"openDropdown")}}closeDropdown(){try{this.dropdownController.close(),this._focusedIndex=-1,this._hasKeyboardNavigated=!1}catch(t){this.handleError(t,"closeDropdown")}}setFocusedIndex(t){try{const e=this.getNavigableOptions();t>=0&&t<e.length&&(this._focusedIndex=t,this.dispatchFocusEvent(e[t],t),this.requestUpdate(),this.scrollToFocusedOption(t))}catch(t){this.handleError(t,"setFocusedIndex")}}scrollToFocusedOption(t){var e;try{const i=null===(e=this.host.shadowRoot)||void 0===e?void 0:e.querySelector(".options");if(!i)return;setTimeout((()=>{const e=i.querySelector(".option.focused");if(e)e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const e=40,s=i.clientHeight,o=i.scrollTop,r=t*e,n=r+e,a=o+s;r<o?i.scrollTo({top:r,behavior:"smooth"}):n>a&&i.scrollTo({top:n-s,behavior:"smooth"})}}),10)}catch(t){console.warn("Failed to scroll to focused option:",t)}}get focusedIndex(){return this._focusedIndex}get focusedOption(){return this.getNavigableOptions()[this._focusedIndex]}handleAlphanumericKey(t){try{const e=this.getNavigableOptions(),i=this._focusedIndex+1;for(let s=0;s<e.length;s++){const o=(i+s)%e.length;if(e[o].label.toLowerCase().startsWith(t)){this.setFocusedIndex(o),this.dropdownController.isOpen||this.openDropdown();break}}}catch(t){this.handleError(t,"handleAlphanumericKey")}}getNavigableOptions(){const t=this.host;if(!t.options||!Array.isArray(t.options))return[];let e=t.options;return t.searchable&&t.searchQuery&&"function"==typeof t.getFilteredOptions&&(e=t.getFilteredOptions()),e.filter((t=>!t.disabled))}dispatchFocusEvent(t,e){const i={focusedOption:t,focusedIndex:e};this.dispatchEvent(new CustomEvent("nr-select-focus",{detail:i,bubbles:!0,composed:!0}))}isSearchInputFocused(){var t;try{const e=this.host;if(!e.searchable)return!1;const i=null===(t=e.shadowRoot)||void 0===t?void 0:t.querySelector(".search-input");return!!i&&(document.activeElement===i||i.shadowRoot&&i.shadowRoot.querySelector("input")===i.shadowRoot.activeElement||i.contains(document.activeElement))}catch(t){return!1}}hostUpdated(){this.dropdownController.isOpen||-1===this._focusedIndex||(this._focusedIndex=-1)}}class $ extends O{constructor(){super(...arguments),this._isOpen=!1,this._position={top:0,left:0,width:0,placement:"bottom"},this._dropdownElement=null,this._triggerElement=null,this.handleResize=()=>{this._isOpen&&this.calculatePosition()},this.handleScroll=()=>{var t;if(this._isOpen&&this._triggerElement){const e=this._triggerElement.getBoundingClientRect(),i=(null===(t=window.visualViewport)||void 0===t?void 0:t.height)||window.innerHeight;(e.bottom<0||e.top>i)&&this.close()}}}get isOpen(){return this._isOpen}get position(){return Object.assign({},this._position)}open(){try{this._isOpen||(this._isOpen=!0,this.host.show=!0,this.requestUpdate(),this.findElements(),setTimeout((()=>{this.calculatePosition()}),10),this.host&&"function"==typeof this.host.setupEventListeners&&setTimeout((()=>{this.host.setupEventListeners()}),50),this.focusSearchInput(),this.dispatchEvent(new CustomEvent("nr-dropdown-open",{bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"open")}}close(){try{this._isOpen&&(this._isOpen=!1,this.host.show=!1,this.resetPosition(),this.requestUpdate(),this.host&&"function"==typeof this.host.removeEventListeners&&this.host.removeEventListeners(),this.dispatchEvent(new CustomEvent("nr-dropdown-close",{bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"close")}}toggle(){this._isOpen?this.close():this.open()}focusSearchInput(){try{const t=this.host;t&&t.searchable&&setTimeout((()=>{var e;const i=null===(e=t.shadowRoot)||void 0===e?void 0:e.querySelector(".search-input");i&&"function"==typeof i.focus&&i.focus()}),100)}catch(t){console.warn("Failed to focus search input:",t)}}calculatePosition(){var t;try{if(this._dropdownElement&&this._triggerElement||this.findElements(),!this._dropdownElement||!this._triggerElement)return;const e=this._triggerElement.getBoundingClientRect(),i=((null===(t=window.visualViewport)||void 0===t?void 0:t.height)||window.innerHeight)-e.bottom,s=e.top,o=200,r=this.determineOptimalPlacement(o,s,i);this._position={left:0,width:0,placement:r,top:0},this.applyPosition()}catch(t){this.handleError(t,"calculatePosition")}}resetPosition(){try{if(this._dropdownElement){this._dropdownElement.style.removeProperty("position"),this._dropdownElement.style.removeProperty("top"),this._dropdownElement.style.removeProperty("left"),this._dropdownElement.style.removeProperty("width"),this._dropdownElement.style.removeProperty("min-width");this.host.maxHeight||this._dropdownElement.style.removeProperty("max-height"),this._dropdownElement.style.removeProperty("min-height"),this._dropdownElement.style.removeProperty("height"),this._dropdownElement.style.removeProperty("overflow-y"),this._dropdownElement.style.removeProperty("transform"),this._dropdownElement.style.removeProperty("display"),this._dropdownElement.style.removeProperty("opacity"),this._dropdownElement.style.removeProperty("visibility"),this._dropdownElement.style.removeProperty("z-index"),this._dropdownElement.classList.remove("placement-top","placement-bottom")}}catch(t){this.handleError(t,"resetPosition")}}setElements(t,e){this._dropdownElement=t,this._triggerElement=e}findElements(){try{const t=this._host;if(t.optionsElement&&t.wrapper)return this._dropdownElement=t.optionsElement,void(this._triggerElement=t.wrapper);t.shadowRoot&&(this._dropdownElement=t.shadowRoot.querySelector(".options"),this._triggerElement=t.shadowRoot.querySelector(".wrapper"))}catch(t){this.handleError(t,"findElements")}}determineOptimalPlacement(t,e,i){return i>=t?"bottom":e>=t||e>i?"top":"bottom"}applyPosition(){var t;try{if(!this._dropdownElement||!this._triggerElement)return;const e=this.host.maxHeight,{placement:i}=this._position,s=this._triggerElement.getBoundingClientRect(),o=s.width;this._dropdownElement.style.position="absolute",this._dropdownElement.style.left="0",this._dropdownElement.style.right="auto",this._dropdownElement.style.minWidth=`${o}px`,this._dropdownElement.style.removeProperty("width"),this._dropdownElement.style.zIndex="1000",this._dropdownElement.style.height="auto",e||(this._dropdownElement.style.maxHeight="none"),this._dropdownElement.style.minHeight="auto","bottom"===i?(this._dropdownElement.style.top="100%",this._dropdownElement.style.bottom="auto"):(this._dropdownElement.style.top="auto",this._dropdownElement.style.bottom="100%");const r=this._dropdownElement.scrollHeight,n=(null===(t=window.visualViewport)||void 0===t?void 0:t.height)||window.innerHeight;let a;a="bottom"===i?n-s.bottom-10:s.top-10,e?(this._dropdownElement.style.maxHeight=e,this._dropdownElement.style.overflowY="auto"):r>a?(this._dropdownElement.style.maxHeight=`${a}px`,this._dropdownElement.style.overflowY="auto"):(this._dropdownElement.style.maxHeight=`${r}px`,this._dropdownElement.style.overflowY="auto"),this._dropdownElement.classList.remove("placement-top","placement-bottom"),this._dropdownElement.classList.add(`placement-${i}`)}catch(t){this.handleError(t,"applyPosition")}}getAvailableSpace(){var t,e;if(!this._triggerElement)return{above:0,below:0,left:0,right:0};const i=this._triggerElement.getBoundingClientRect(),s=(null===(t=window.visualViewport)||void 0===t?void 0:t.height)||window.innerHeight,o=(null===(e=window.visualViewport)||void 0===e?void 0:e.width)||window.innerWidth;return{above:i.top,below:s-i.bottom,left:i.left,right:o-i.right}}hostConnected(){window.addEventListener("resize",this.handleResize),window.addEventListener("scroll",this.handleScroll,!0)}hostDisconnected(){window.removeEventListener("resize",this.handleResize),window.removeEventListener("scroll",this.handleScroll,!0)}}class S extends O{constructor(){super(...arguments),this._focusedIndex=-1,this._hasFocus=!1}get focusedIndex(){return this._focusedIndex}getFocusedOption(){if(this._focusedIndex>=0&&this._focusedIndex<this.host.options.length)return this.host.options[this._focusedIndex]}get hasFocus(){return this._hasFocus}setFocusedOption(t){try{t>=0&&t<this.host.options.length&&(this._focusedIndex=t,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-focus-change",{detail:{focusedIndex:t,focusedOption:this.getFocusedOption()},bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"setFocusedOption")}}focus(){var t;try{const e=null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(".wrapper");e&&(e.focus(),this._hasFocus=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-focus",{bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"focus")}}blur(){var t;try{const e=null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(".wrapper");e&&e.blur(),this._hasFocus=!1,this._focusedIndex=-1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-blur",{bubbles:!0,composed:!0}))}catch(t){this.handleError(t,"blur")}}focusNext(){try{const t=this.getNextFocusableIndex(this._focusedIndex);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusNext")}}focusPrevious(){try{const t=this.getPreviousFocusableIndex(this._focusedIndex);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusPrevious")}}focusFirst(){try{const t=this.getNextFocusableIndex(-1);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusFirst")}}focusLast(){try{const t=this.getPreviousFocusableIndex(this.host.options.length);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusLast")}}clearFocus(){this._focusedIndex=-1,this._hasFocus=!1,this.requestUpdate()}handleFocus(){this._hasFocus=!0,this.requestUpdate()}handleBlur(){this._hasFocus=!1,this._focusedIndex=-1,this.requestUpdate()}getNextFocusableIndex(t){const e=this.host.options;for(let i=t+1;i<e.length;i++)if(!e[i].disabled)return i;for(let i=0;i<=t;i++)if(!e[i].disabled)return i;return-1}getPreviousFocusableIndex(t){const e=this.host.options;for(let i=t-1;i>=0;i--)if(!e[i].disabled)return i;for(let i=e.length-1;i>=t;i--)if(!e[i].disabled)return i;return-1}findOptionIndex(t){return this.host.options.findIndex((e=>e.value===t))}focusOptionByValue(t){const e=this.findOptionIndex(t);-1!==e&&this.setFocusedOption(e)}}!function(t){t.Valid="valid",t.Invalid="invalid",t.Pending="pending",t.Pristine="pristine"}(x||(x={}));class k extends O{constructor(t,e){super(t),this.selectionController=e,this._isValid=!0,this._validationMessage="",this._validationState=x.Pristine}get isValid(){return this._isValid}get validationMessage(){return this._validationMessage}get validationState(){return this._validationState}validate(){try{this._validationState=x.Pending;const t=this.selectionController.getSelectedOptions().length>0;return this.host.required&&!t?(this.setValidationResult(!1,"This field is required",x.Invalid),!1):(this.setValidationResult(!0,"",x.Valid),!0)}catch(t){return this.handleError(t,"validate"),this.setValidationResult(!1,"Validation error occurred",x.Invalid),!1}}reset(){try{this._isValid=!0,this._validationMessage="",this._validationState=x.Pristine,this.requestUpdate(),this.dispatchValidationEvent()}catch(t){this.handleError(t,"reset")}}getFormData(){var t;try{const e=this._host,i=e.name||e.getAttribute("name")||"select",s=this.selectionController.getSelectedOptions();return this.host.multiple?{[i]:s.map((t=>t.value))}:{[i]:(null===(t=s[0])||void 0===t?void 0:t.value)||""}}catch(t){return this.handleError(t,"getFormData"),{}}}checkValidity(){return this.validate()}reportValidity(){var t;const e=this.validate();if(!e){const e=null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(".wrapper");e&&e.focus()}return e}setCustomValidity(t){try{t?this.setValidationResult(!1,t,x.Invalid):this.validate()}catch(t){this.handleError(t,"setCustomValidity")}}validateOnChange(){this._validationState!==x.Pristine&&this.validate()}validateOnBlur(){this._validationState===x.Pristine&&(this._validationState=x.Pending),this.validate()}setValidationResult(t,e,i){const s=this._isValid!==t||this._validationMessage!==e||this._validationState!==i;this._isValid=t,this._validationMessage=e,this._validationState=i,s&&(this.requestUpdate(),this.dispatchValidationEvent())}dispatchValidationEvent(){const t={isValid:this._isValid,validationMessage:this._validationMessage,validationState:this._validationState};this.dispatchEvent(new CustomEvent("nr-validation",{detail:t,bubbles:!0,composed:!0}))}hostUpdated(){this.validateOnChange()}getValidationClasses(){return{valid:this._isValid&&this._validationState===x.Valid,invalid:!this._isValid&&this._validationState===x.Invalid,pending:this._validationState===x.Pending,pristine:this._validationState===x.Pristine}}getAriaAttributes(){const t={};return this.host.required&&(t["aria-required"]="true"),this._isValid||(t["aria-invalid"]="true",this._validationMessage&&(t["aria-describedby"]="validation-message")),t}}class C extends O{constructor(){super(...arguments),this._searchQuery="",this.handleSearchInput=t=>{this.setSearchQuery(t.detail.value||"")},this.handleSearchClear=()=>{this.clearSearch()},this.handleSearchKeyDown=t=>{if(["ArrowDown","ArrowUp","Enter","Home","End"].includes(t.key)){const e=this.host.keyboardController;e&&e.handleKeyDown(t)}else t.stopPropagation(),"Escape"===t.key&&(this.host.closeDropdown(),this.host.focus())}}get searchQuery(){return this._searchQuery}get hasSearch(){return""!==this._searchQuery.trim()}setSearchQuery(t){this._searchQuery=t,this.host.searchQuery=t,this.host.requestUpdate()}search(t){this.setSearchQuery(t)}clearSearch(){this.setSearchQuery("")}getFilteredOptions(t){if(!this.host.searchable||!this._searchQuery.trim())return t;const e=this._searchQuery.toLowerCase().trim();return t.filter((t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e)))}renderSearchInput(){return this.host.searchable?i`<div class="search-container"><nr-input type="text" class="search-input" placeholder="${this.host.searchPlaceholder}" .value="${this._searchQuery}" allowClear @nr-input="${this.handleSearchInput}" @nr-clear="${this.handleSearchClear}" @keydown="${this.handleSearchKeyDown}" @click="${t=>t.stopPropagation()}"><nr-icon name="search" class="search-icon" slot="prefix" aria-hidden="true"></nr-icon></nr-input></div>`:e}renderNoResults(){return i`<div class="no-options" role="option" aria-disabled="true"><div class="no-options-content"><nr-icon name="search" class="no-options-icon" aria-hidden="true"></nr-icon><span class="no-options-text">No results found for "${this._searchQuery}"</span></div></div>`}hasNoResults(t){return this.host.searchable&&""!==this._searchQuery.trim()&&0===this.getFilteredOptions(t).length}getCurrentQuery(){return this.host.searchQuery||this._searchQuery}hostUpdated(){super.hostUpdated(),this.host.searchQuery!==this._searchQuery&&(this._searchQuery=this.host.searchQuery)}hostConnected(){super.hostConnected(),this._searchQuery=""}}class A extends O{constructor(){super(...arguments),this.handleTriggerClick=t=>{this.host.disabled||(t.preventDefault(),t.stopPropagation(),this.host.toggleDropdown())},this.handleOptionClick=(t,e)=>{t.stopPropagation(),e.disabled||(this.host.multiple?this.host.toggleOption(e):(this.host.selectOption(e),this.host.closeDropdown()))},this.handleTagRemove=(t,e)=>{t.stopPropagation(),this.host.unselectOption(e)},this.handleClearAll=t=>{t.stopPropagation(),this.host.clearSelection()},this.handleKeyDown=t=>{const e=this.host.keyboardController;e&&e.handleKeyDown(t)},this.handleFocus=()=>{const t=this.host.focusController;t&&t.handleFocus()},this.handleBlur=()=>{const t=this.host.focusController;t&&t.handleBlur()},this.handleWindowClick=t=>{const e=t.target;this.host.contains(e)||this.host.closeDropdown()}}setupEventListeners(){window.addEventListener("click",this.handleWindowClick)}removeEventListeners(){window.removeEventListener("click",this.handleWindowClick)}hostDisconnected(){super.hostDisconnected(),this.removeEventListeners()}}
1
+ import{css as t,nothing as e,html as i,LitElement as s}from"lit";import{property as r,query as o,customElement as a}from"lit/decorators.js";import{map as n}from"lit/directives/map.js";import{choose as l}from"lit/directives/choose.js";import{classMap as c}from"lit/directives/class-map.js";import{styleMap as h}from"lit/directives/style-map.js";import{NuralyUIBaseMixin as d}from"@nuralyui/common/mixins";const u=t`
2
+ :host {
3
+ /* Layout and sizing */
4
+ --nuraly-select-local-min-height: 40px;
5
+ --nuraly-select-local-padding-top: 8px;
6
+ --nuraly-select-local-padding-bottom: 8px;
7
+ --nuraly-select-local-padding-left: 12px;
8
+ --nuraly-select-local-padding-right: 12px;
9
+ --nuraly-select-local-wrapper-margin: 0;
10
+ --nuraly-select-local-border-radius: 6px;
11
+ --nuraly-select-local-border-width: 1px;
12
+
13
+ /* Dropdown settings */
14
+ --nuraly-select-local-dropdown-z-index: 9999;
15
+ --nuraly-select-local-dropdown-max-height: auto;
16
+ --nuraly-select-local-dropdown-width: max-content;
17
+ --nuraly-select-local-placeholder-font-size: 14px;
18
+ --nuraly-select-local-option-font-size: 14px;
19
+
20
+ /* Search input container settings */
21
+ --nuraly-select-local-input-container-max-width: var(--nuraly-select-width);
22
+
23
+ /* Size tokens - small */
24
+ --nuraly-select-local-small-height: 24px;
25
+ --nuraly-select-local-small-font-size: 12px;
26
+ --nuraly-select-local-small-padding: 2px 8px;
27
+ --nuraly-select-local-small-icon-size: 14px;
28
+
29
+ /* Size tokens - medium */
30
+ --nuraly-select-local-medium-height: 40px;
31
+ --nuraly-select-local-medium-font-size: 14px;
32
+ --nuraly-select-local-medium-padding: 8px 12px;
33
+ --nuraly-select-local-medium-icon-size: 16px;
34
+
35
+ /* Size tokens - large */
36
+ --nuraly-select-local-large-height: 48px;
37
+ --nuraly-select-local-large-font-size: 16px;
38
+ --nuraly-select-local-large-padding: 12px 16px;
39
+ --nuraly-select-local-large-icon-size: 20px;
40
+
41
+ /* Animation and transitions */
42
+ --nuraly-select-local-dropdown-animation-duration: 0.15s;
43
+ --nuraly-select-local-transition-duration: 0.2s;
44
+
45
+ /* Multi-select specific */
46
+ --nuraly-select-local-tag-border-radius: 4px;
47
+ --nuraly-select-local-tag-padding: 2px 6px;
48
+ --nuraly-select-local-tag-margin: 2px;
49
+
50
+ /* Icon sizes */
51
+ --nuraly-select-local-icon-size: 16px;
52
+ --nuraly-select-local-arrow-icon-size: 16px;
53
+
54
+ /* Validation message */
55
+ --nuraly-select-local-message-font-size: 12px;
56
+ --nuraly-select-local-message-margin-top: 4px;
57
+
58
+ /* Font settings */
59
+ --nuraly-select-local-font-size: 14px;
60
+ }
61
+
62
+ :host {
63
+ width: fit-content;
64
+ display: block;
65
+ font-family: var(--nuraly-select-font-family, Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif);
66
+ font-size: var(--nuraly-select-font-size, 14px);
67
+ line-height: var(--nuraly-select-line-height, 1.5);
68
+ margin: var(--nuraly-select-margin, var(--nuraly-select-local-wrapper-margin));
69
+ }
70
+
71
+ /* Host attribute selectors for configuration */
72
+ :host([disabled]) {
73
+ opacity: var(--nuraly-select-disabled-opacity, 0.5);
74
+ pointer-events: none;
75
+ }
76
+
77
+ :host([disabled]) .wrapper {
78
+ background-color: var(--nuraly-select-disabled-background, var(--nuraly-color-background-disabled));
79
+ border-color: var(--nuraly-select-disabled-border-color, var(--nuraly-color-border));
80
+ color: var(--nuraly-select-disabled-text-color, var(--nuraly-color-text-disabled));
81
+ cursor: not-allowed;
82
+ }
83
+
84
+ /* Size variants */
85
+ :host([size='small']) .wrapper {
86
+ height: var(--nuraly-select-small-height, var(--nuraly-select-local-small-height));
87
+ min-height: var(--nuraly-select-small-height, var(--nuraly-select-local-small-height));
88
+ font-size: var(--nuraly-select-small-font-size, var(--nuraly-select-local-small-font-size));
89
+ }
90
+
91
+ :host([size='small']) .select-trigger {
92
+ padding: var(--nuraly-select-small-padding, var(--nuraly-select-local-small-padding));
93
+ padding-right: calc(var(--nuraly-select-small-icon-size, var(--nuraly-select-local-small-icon-size)) + 20px);
94
+ }
95
+
96
+ :host([size='small']) .icons-container nr-icon {
97
+ --nuraly-icon-width: var(--nuraly-select-small-icon-size, var(--nuraly-select-local-small-icon-size));
98
+ }
99
+
100
+ :host([size='small']) .option {
101
+ padding: var(--nuraly-select-small-padding, var(--nuraly-select-local-small-padding));
102
+ font-size: var(--nuraly-select-small-font-size, var(--nuraly-select-local-small-font-size));
103
+ min-height: var(--nuraly-select-small-height, var(--nuraly-select-local-small-height));
104
+ }
105
+
106
+ :host([size='small']) .option-icon,
107
+ :host([size='small']) .option nr-icon {
108
+ --nuraly-icon-width: var(--nuraly-select-small-icon-size, var(--nuraly-select-local-small-icon-size));
109
+ }
110
+
111
+ :host([size='medium']) .wrapper {
112
+ min-height: var(--nuraly-select-medium-height, var(--nuraly-select-local-medium-height));
113
+ font-size: var(--nuraly-select-medium-font-size, var(--nuraly-select-local-medium-font-size));
114
+ }
115
+
116
+ :host([size='medium']) .select-trigger {
117
+ padding: var(--nuraly-select-medium-padding, var(--nuraly-select-local-medium-padding));
118
+ padding-right: calc(var(--nuraly-select-medium-icon-size, var(--nuraly-select-local-medium-icon-size)) + 20px);
119
+ }
120
+
121
+ :host([size='medium']) .icons-container nr-icon {
122
+ --nuraly-icon-width: var(--nuraly-select-medium-icon-size, var(--nuraly-select-local-medium-icon-size));
123
+ }
124
+
125
+ :host([size='medium']) .option {
126
+ padding: var(--nuraly-select-medium-padding, var(--nuraly-select-local-medium-padding));
127
+ font-size: var(--nuraly-select-medium-font-size, var(--nuraly-select-local-medium-font-size));
128
+ min-height: var(--nuraly-select-medium-height, var(--nuraly-select-local-medium-height));
129
+ }
130
+
131
+ :host([size='medium']) .option-icon,
132
+ :host([size='medium']) .option nr-icon {
133
+ --nuraly-icon-width: var(--nuraly-select-medium-icon-size, var(--nuraly-select-local-medium-icon-size));
134
+ }
135
+
136
+ :host([size='large']) .wrapper {
137
+ min-height: var(--nuraly-select-large-height, var(--nuraly-select-local-large-height));
138
+ font-size: var(--nuraly-select-large-font-size, var(--nuraly-select-local-large-font-size));
139
+ }
140
+
141
+ :host([size='large']) .select-trigger {
142
+ padding: var(--nuraly-select-large-padding, var(--nuraly-select-local-large-padding));
143
+ padding-right: calc(var(--nuraly-select-large-icon-size, var(--nuraly-select-local-large-icon-size)) + 20px);
144
+ }
145
+
146
+ :host([size='large']) .icons-container nr-icon {
147
+ --nuraly-icon-width: var(--nuraly-select-large-icon-size, var(--nuraly-select-local-large-icon-size));
148
+ }
149
+
150
+ :host([size='large']) .option {
151
+ padding: var(--nuraly-select-large-padding, var(--nuraly-select-local-large-padding));
152
+ font-size: var(--nuraly-select-large-font-size, var(--nuraly-select-local-large-font-size));
153
+ min-height: var(--nuraly-select-large-height, var(--nuraly-select-local-large-height));
154
+ }
155
+
156
+ :host([size='large']) .option-icon,
157
+ :host([size='large']) .option nr-icon {
158
+ --nuraly-icon-width: var(--nuraly-select-large-icon-size, var(--nuraly-select-local-large-icon-size));
159
+ }
160
+
161
+ /* Status variants */
162
+ :host([status='error']) .wrapper {
163
+ border-color: var(--nuraly-select-error-border-color, var(--nuraly-color-danger));
164
+ }
165
+
166
+ :host([status='warning']) .wrapper {
167
+ border-color: var(--nuraly-select-warning-border-color, var(--nuraly-color-warning));
168
+ }
169
+
170
+ :host([status='success']) .wrapper {
171
+ border-color: var(--nuraly-select-success-border-color, var(--nuraly-color-success));
172
+ }
173
+
174
+ /* Type variants */
175
+ :host([type='inline']) {
176
+ display: flex;
177
+ align-items: center;
178
+ gap: 8px;
179
+ }
180
+
181
+ :host([type='inline']) .wrapper {
182
+ flex: 1;
183
+ }
184
+
185
+ /* Block (full width) */
186
+ :host([block]) {
187
+ width: 100%;
188
+ }
189
+
190
+ :host([block]) .wrapper {
191
+ width: 100%;
192
+ }
193
+
194
+ /* Show dropdown */
195
+ :host([show]) .options {
196
+ display: flex !important;
197
+ }
198
+
199
+ /* Main wrapper container */
200
+ .wrapper {
201
+ position: relative;
202
+ width: var(--nuraly-select-width, fit-content);
203
+ background-color: var(--nuraly-select-background, var(--nuraly-color-background-panel));
204
+ border: var(--nuraly-select-border-width, var(--nuraly-select-local-border-width)) solid
205
+ var(--nuraly-select-border-color, var(--nuraly-color-border));
206
+ border-radius: var(--nuraly-select-border-radius, var(--nuraly-select-local-border-radius));
207
+ transition: all var(--nuraly-select-transition-duration, var(--nuraly-select-local-transition-duration))
208
+ var(--nuraly-select-transition-timing, ease-in-out);
209
+ cursor: pointer;
210
+ outline: none;
211
+ margin: var(--nuraly-select-wrapper-margin, 0);
212
+ min-height: var(--nuraly-select-min-height, var(--nuraly-select-local-min-height));
213
+ box-sizing: border-box;
214
+ display: flex;
215
+ align-items: center;
216
+ /* Ensure dropdown can overflow the wrapper */
217
+ overflow: visible;
218
+ }
219
+
220
+ .wrapper:hover:not(:disabled) {
221
+ border-color: var(--nuraly-select-border-hover, var(--nuraly-color-primary));
222
+ }
223
+
224
+ .wrapper:focus,
225
+ .wrapper:focus-within {
226
+ border-color: var(--nuraly-select-border-focus, var(--nuraly-color-primary));
227
+ box-shadow: 0 0 0 2px var(--nuraly-color-primary-light);
228
+ }
229
+
230
+ /* Select container */
231
+ .select {
232
+ display: flex;
233
+ flex-direction: column;
234
+ }
235
+
236
+ /* Select trigger (main display area) */
237
+ .select-trigger {
238
+ display: flex;
239
+ align-items: center;
240
+ padding: var(--nuraly-select-padding-top, var(--nuraly-select-local-padding-top))
241
+ calc(var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size)) + 20px)
242
+ var(--nuraly-select-padding-bottom, var(--nuraly-select-local-padding-bottom))
243
+ var(--nuraly-select-padding-left, var(--nuraly-select-local-padding-left));
244
+ color: var(--nuraly-select-color, var(--nuraly-color-text));
245
+ font-size: inherit;
246
+ line-height: inherit;
247
+ word-break: break-word;
248
+ flex: 1;
249
+ min-height: 0;
250
+ flex-wrap: wrap;
251
+ gap: var(--nuraly-select-tag-margin, var(--nuraly-select-local-tag-margin));
252
+ box-sizing: border-box;
253
+ }
254
+
255
+ .select-trigger:empty:before {
256
+ content: attr(data-placeholder);
257
+ color: var(--nuraly-select-placeholder-color, var(--nuraly-color-text-secondary));
258
+ font-size: var(--nuraly-select-placeholder-font-size, var(--nuraly-select-local-placeholder-font-size));
259
+ }
260
+
261
+ /* Multi-select tags */
262
+ .tag {
263
+ display: inline-flex;
264
+ align-items: center;
265
+ gap: 4px;
266
+ background-color: var(--nuraly-select-tag-background, var(--nuraly-color-background-active));
267
+ color: var(--nuraly-select-tag-color, var(--nuraly-color-text));
268
+ padding: var(--nuraly-select-tag-padding, var(--nuraly-select-local-tag-padding));
269
+ border-radius: var(--nuraly-select-tag-border-radius, var(--nuraly-select-local-tag-border-radius));
270
+ font-size: calc(var(--nuraly-select-font-size, var(--nuraly-select-local-font-size)) - 1px);
271
+ max-width: 100%;
272
+ }
273
+
274
+ .tag-label {
275
+ overflow: hidden;
276
+ text-overflow: ellipsis;
277
+ white-space: nowrap;
278
+ }
279
+
280
+ .tag-close {
281
+ color: var(--nuraly-select-tag-close-color, var(--nuraly-color-text-secondary));
282
+ cursor: pointer;
283
+ display: flex;
284
+ align-items: center;
285
+ justify-content: center;
286
+ width: var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));
287
+ height: var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));
288
+ border-radius: 50%;
289
+ transition: color var(--nuraly-select-transition-duration, var(--nuraly-select-local-transition-duration));
290
+ }
291
+
292
+ .tag-close:hover {
293
+ color: var(--nuraly-select-tag-close-hover-color, var(--nuraly-color-text));
294
+ }
295
+
296
+ /* Icons container */
297
+ .icons-container {
298
+ position: absolute;
299
+ top: 50%;
300
+ right: 12px;
301
+ transform: translateY(-50%);
302
+ display: flex;
303
+ align-items: center;
304
+ gap: 4px;
305
+ pointer-events: none;
306
+ }
307
+
308
+ .icons-container nr-icon {
309
+ --nuraly-icon-width: var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));
310
+ --nuraly-icon-color: var(--nuraly-color-select-icon, var(--nuraly-color-text-secondary));
311
+ pointer-events: auto;
312
+ cursor: pointer;
313
+ transition: color var(--nuraly-select-transition-duration, var(--nuraly-select-local-transition-duration));
314
+ }
315
+
316
+ .icons-container nr-icon:hover {
317
+ --nuraly-icon-color: var(--nuraly-color-select-icon-hover, var(--nuraly-color-text));
318
+ }
319
+
320
+ .arrow-icon {
321
+ --nuraly-icon-width: var(--nuraly-select-arrow-icon-size, var(--nuraly-select-local-arrow-icon-size));
322
+ transition: transform var(--nuraly-select-transition-duration, var(--nuraly-select-local-transition-duration));
323
+ pointer-events: none !important;
324
+ }
325
+
326
+ :host([show]) .arrow-icon {
327
+ transform: rotate(180deg);
328
+ }
329
+
330
+ /* Dropdown options */
331
+ .options {
332
+ /* Default positioning - will be overridden by controller when opened */
333
+ position: absolute;
334
+ top: 100%;
335
+ margin-top: 1px;
336
+ left: 0;
337
+ right: 0;
338
+ background-color: var(--nuraly-select-dropdown-background, var(--nuraly-color-background-panel));
339
+ border: var(--nuraly-select-dropdown-border-width, var(--nuraly-select-border-width, var(--nuraly-select-local-border-width))) solid
340
+ var(--nuraly-select-dropdown-border-color, var(--nuraly-color-border));
341
+ border-radius: var(--nuraly-select-dropdown-border-radius, var(--nuraly-select-border-radius, var(--nuraly-select-local-border-radius)));
342
+ box-shadow: var(--nuraly-select-dropdown-shadow, 0 6px 16px 0 rgba(0, 0, 0, 0.08));
343
+ z-index: var(--nuraly-select-dropdown-z-index, var(--nuraly-select-local-dropdown-z-index));
344
+ max-height: var(--nuraly-select-dropdown-max-height, var(--nuraly-select-local-dropdown-max-height, auto));
345
+ overflow-y: auto;
346
+ overflow-x: hidden;
347
+ display: none;
348
+ flex-direction: column;
349
+ animation: dropdown-enter var(--nuraly-select-dropdown-animation-duration, var(--nuraly-select-local-dropdown-animation-duration)) ease-out;
350
+ /* Ensure proper containment and exact wrapper width */
351
+ box-sizing: border-box;
352
+ /* Allow overriding width via either of these custom props */
353
+ width: var(
354
+ --nuraly-select-dropdown-width,
355
+ var(--select-dropdown-width, var(--nuraly-select-local-dropdown-width))
356
+ );
357
+ min-width: 100%; /* Ensure dropdown is at least as wide as the wrapper */
358
+ /* Create new stacking context to prevent layering issues */
359
+ isolation: isolate;
360
+ /* Ensure solid background to prevent visual bleed-through */
361
+ backdrop-filter: none;
362
+ -webkit-backdrop-filter: none;
363
+ /* Force above other elements */
364
+ transform: translateZ(0);
365
+ }
366
+
367
+ .options.placement-top {
368
+ top: auto;
369
+ bottom: 100%;
370
+ margin-bottom: 1px;
371
+ margin-top: 0;
372
+ animation: dropdown-enter-top var(--nuraly-select-dropdown-animation-duration, var(--nuraly-select-local-dropdown-animation-duration)) ease-out;
373
+ }
374
+
375
+ @keyframes dropdown-enter {
376
+ from {
377
+ opacity: 0;
378
+ transform: translateY(-8px);
379
+ }
380
+ to {
381
+ opacity: 1;
382
+ transform: translateY(0);
383
+ }
384
+ }
385
+
386
+ @keyframes dropdown-enter-top {
387
+ from {
388
+ opacity: 0;
389
+ transform: translateY(8px);
390
+ }
391
+ to {
392
+ opacity: 1;
393
+ transform: translateY(0);
394
+ }
395
+ }
396
+
397
+ /* Search container - sticky at top of dropdown */
398
+ .search-container {
399
+ position: sticky;
400
+ top: 0;
401
+ z-index: 10;
402
+ background-color: var(--nuraly-select-dropdown-background, var(--nuraly-color-background-panel));
403
+ border-bottom: var(--nuraly-select-border-width, var(--nuraly-select-local-border-width)) solid
404
+ var(--nuraly-select-dropdown-border-color, var(--nuraly-color-border));
405
+ padding: 8px;
406
+ margin: 0;
407
+ /* Ensure it stays above options during scroll */
408
+ backdrop-filter: blur(8px);
409
+ -webkit-backdrop-filter: blur(8px);
410
+ /* Ensure proper stacking and smooth scrolling */
411
+ will-change: transform;
412
+ transform: translateZ(0);
413
+ }
414
+
415
+ /* Search input styling */
416
+ .search-container .search-input {
417
+ width: 100%;
418
+ max-width: var(--nuraly-select-input-container-max-width, var(--nuraly-select-local-input-container-max-width));
419
+ --nuraly-input-border-radius: var(--nuraly-select-border-radius, var(--nuraly-select-local-border-radius));
420
+ --nuraly-input-background-color: var(--nuraly-select-background, var(--nuraly-color-background-panel));
421
+ --nuraly-input-border-color: var(--nuraly-select-border-color, var(--nuraly-color-border));
422
+ --nuraly-input-text-color: var(--nuraly-select-color, var(--nuraly-color-text));
423
+ --nuraly-input-placeholder-color: var(--nuraly-select-placeholder-color, var(--nuraly-color-text-secondary));
424
+ }
425
+
426
+ /* Search icon in the search input */
427
+ .search-container .search-icon {
428
+ --nuraly-icon-color: var(--nuraly-color-select-icon, var(--nuraly-color-text-secondary));
429
+ }
430
+
431
+ /* Options list container - ensure proper scroll behavior with sticky search */
432
+ .options:has(.search-container) {
433
+ /* Add small padding-top when search is present to ensure proper separation */
434
+ padding-top: 0;
435
+ }
436
+
437
+ /* Option items */
438
+ .option {
439
+ display: flex;
440
+ align-items: center;
441
+ gap: 8px;
442
+ padding: var(--nuraly-select-option-padding, 8px 12px);
443
+ min-height: var(--nuraly-select-option-min-height, auto);
444
+ color: var(--nuraly-select-option-color, var(--nuraly-color-text));
445
+ font-size: var(--nuraly-select-option-font-size, var(--nuraly-select-local-option-font-size));
446
+ cursor: pointer;
447
+ transition: background-color var(--nuraly-select-transition-duration, var(--nuraly-select-local-transition-duration));
448
+ position: relative;
449
+ }
450
+
451
+ /* First option after search container should have no extra margin */
452
+ .search-container + .option {
453
+ margin-top: 0;
454
+ }
455
+
456
+ .option:hover {
457
+ background-color: var(--nuraly-select-option-hover-background, var(--nuraly-color-background-hover));
458
+ }
459
+
460
+ .option.selected {
461
+ background-color: var(--nuraly-select-option-selected-background, var(--nuraly-color-primary-light));
462
+ color: var(--nuraly-select-option-selected-color, var(--nuraly-color-primary));
463
+ }
464
+
465
+ .option.focused {
466
+ background-color: var(--nuraly-select-option-hover-background, var(--nuraly-color-background-hover));
467
+ outline: 2px solid var(--nuraly-select-border-focus, var(--nuraly-color-primary));
468
+ outline-offset: -2px;
469
+ }
470
+
471
+ .option.disabled {
472
+ opacity: var(--nuraly-select-disabled-opacity, var(--nuraly-select-local-disabled-opacity));
473
+ cursor: not-allowed;
474
+ }
475
+
476
+ .option-content {
477
+ flex: 1;
478
+ display: flex;
479
+ align-items: center;
480
+ gap: 8px;
481
+ }
482
+
483
+ .option-icon {
484
+ --nuraly-icon-width: var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));
485
+ --nuraly-icon-color: currentColor;
486
+ }
487
+
488
+ .option-text {
489
+ flex: 1;
490
+ overflow: hidden;
491
+ text-overflow: ellipsis;
492
+ white-space: nowrap;
493
+ }
494
+
495
+ .option-description {
496
+ font-size: calc(var(--nuraly-select-option-font-size, var(--nuraly-select-local-option-font-size)) - 1px);
497
+ opacity: 0.7;
498
+ margin-top: 2px;
499
+ }
500
+
501
+ .check-icon {
502
+ --nuraly-icon-width: var(--nuraly-select-icon-size, var(--nuraly-select-local-icon-size));
503
+ --nuraly-icon-color: var(--nuraly-select-option-selected-color, var(--nuraly-color-primary));
504
+ }
505
+
506
+ .no-options {
507
+ display: flex;
508
+ align-items: center;
509
+ justify-content: center;
510
+ padding: var(--select-no-options-padding, 24px 16px);
511
+ color: var(--select-no-options-color, var(--nuraly-color-text-secondary));
512
+ font-size: var(--nuraly-select-option-font-size, var(--nuraly-select-local-option-font-size));
513
+ cursor: default;
514
+ user-select: none;
515
+ }
516
+
517
+ .no-options-content {
518
+ display: flex;
519
+ flex-direction: column;
520
+ align-items: center;
521
+ gap: var(--select-no-options-gap, 8px);
522
+ text-align: center;
523
+ }
524
+
525
+ .no-options-icon {
526
+ --nuraly-icon-width: 24px;
527
+ --nuraly-icon-color: var(--select-no-options-icon-color, var(--nuraly-color-border));
528
+ opacity: 0.8;
529
+ }
530
+
531
+ .no-options-text {
532
+ font-size: var(--nuraly-select-option-font-size, var(--nuraly-select-local-option-font-size));
533
+ color: var(--select-no-options-color, var(--nuraly-color-text-secondary));
534
+ line-height: 1.4;
535
+ }
536
+
537
+ /* Validation message */
538
+ .validation-message {
539
+ display: block;
540
+ margin-top: var(--nuraly-select-message-margin-top, var(--nuraly-select-local-message-margin-top));
541
+ font-size: var(--nuraly-select-message-font-size, var(--nuraly-select-local-message-font-size));
542
+ color: var(--nuraly-select-error-message-color, var(--nuraly-color-danger));
543
+ }
544
+
545
+ .validation-message.warning {
546
+ color: var(--nuraly-select-warning-message-color, var(--nuraly-color-warning));
547
+ }
548
+
549
+ .validation-message.success {
550
+ color: var(--nuraly-select-success-message-color, var(--nuraly-color-success));
551
+ }
552
+
553
+ /* Slotted content styles */
554
+ ::slotted([slot='label']) {
555
+ display: block;
556
+ margin-bottom: 4px;
557
+ font-weight: 500;
558
+ color: var(--nuraly-select-color, var(--nuraly-color-text));
559
+ }
560
+
561
+ ::slotted([slot='helper-text']) {
562
+ display: block;
563
+ margin-top: var(--nuraly-select-message-margin-top, var(--nuraly-select-local-message-margin-top));
564
+ font-size: var(--nuraly-select-message-font-size, var(--nuraly-select-local-message-font-size));
565
+ color: var(--nuraly-select-placeholder-color, var(--nuraly-color-text-secondary));
566
+ }
567
+
568
+ /* Accessibility improvements */
569
+ @media (prefers-reduced-motion: reduce) {
570
+ .options,
571
+ .wrapper,
572
+ .tag-close,
573
+ .arrow-icon,
574
+ .option {
575
+ transition: none;
576
+ animation: none;
577
+ }
578
+ }
579
+
580
+ /* High contrast mode support */
581
+ @media (prefers-contrast: high) {
582
+ .wrapper {
583
+ border-width: 2px;
584
+ }
585
+
586
+ .wrapper:focus,
587
+ .wrapper:focus-within {
588
+ outline: 3px solid;
589
+ }
590
+ }
591
+ `;var p,v,y,g,m,b,f,w,x;!function(t){t.Default="default",t.Inline="inline",t.Button="button",t.Slot="slot"}(p||(p={})),function(t){t.Default="default",t.Warning="warning",t.Error="error",t.Success="success"}(v||(v={})),function(t){t.Small="small",t.Medium="medium",t.Large="large"}(y||(y={})),function(t){t.Small="small",t.Medium="medium",t.Large="large"}(g||(g={})),function(t){t.Horizontal="horizontal",t.Vertical="vertical"}(m||(m={})),function(t){t.Default="default",t.Solid="solid",t.Outline="outline",t.Borderless="borderless"}(b||(b={})),function(t){t.Bottom="bottom",t.Top="top",t.Auto="auto"}(f||(f={})),function(t){t.None="none",t.StartsWith="starts-with",t.Contains="contains",t.Fuzzy="fuzzy"}(w||(w={}));class z{constructor(t){this._host=t,this._host.addController(this)}get host(){return this._host}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}handleError(t,e){console.error(`[SelectController:${this.constructor.name}] Error in ${e}:`,t),this._host.dispatchEvent(new CustomEvent("nr-select-error",{detail:{error:t.message,context:e,controller:this.constructor.name},bubbles:!0,composed:!0}))}requestUpdate(){try{this._host.requestUpdate()}catch(t){this.handleError(t,"requestUpdate")}}dispatchEvent(t){try{return this._host.dispatchEvent(t)}catch(t){return this.handleError(t,"dispatchEvent"),!1}}}class O extends z{constructor(){super(...arguments),this._selectedOptions=[],this._initialized=!1}getSelectedOptions(){return[...this._selectedOptions]}getSelectedOption(){return this._selectedOptions[0]}selectOption(t){try{if(this.isOptionDisabled(t))return;const e=this.host.multiple,i=this.getCurrentValue();e?this.isOptionSelected(t)||(this._selectedOptions=[...this._selectedOptions,t],this.updateHostValue(),this.dispatchChangeEvent(i)):(this.isOptionSelected(t)?this._selectedOptions=[]:this._selectedOptions=[t],this.updateHostValue(),this.dispatchChangeEvent(i)),this.requestUpdate()}catch(t){this.handleError(t,"selectOption")}}unselectOption(t){try{if(this.isOptionSelected(t)){const e=this.getCurrentValue();this._selectedOptions=this._selectedOptions.filter(e=>e.value!==t.value),this.updateHostValue(),this.dispatchChangeEvent(e),this.requestUpdate()}}catch(t){this.handleError(t,"unselectOption")}}clearSelection(){try{if(this._selectedOptions.length>0){const t=this.getCurrentValue();this._selectedOptions=[],this.updateHostValue(),this.dispatchChangeEvent(t),this.requestUpdate()}}catch(t){this.handleError(t,"clearSelection")}}isOptionSelected(t){return this._selectedOptions.some(e=>e.value===t.value)}isOptionDisabled(t){return Boolean(t.disabled)||this.host.disabled}toggleOption(t){this.isOptionSelected(t)?this.unselectOption(t):this.selectOption(t)}initializeFromValue(){try{if(this._initialized)return;const t=this.host.value;if(!t||Array.isArray(t)&&0===t.length)return;const e=Array.isArray(t)?t:[t],i=this.host.options.filter(t=>e.includes(t.value));i.length>0&&(this._selectedOptions=this.host.multiple?i:[i[0]],this.requestUpdate()),this._initialized=!0}catch(t){this.handleError(t,"initializeFromValue")}}updateHostValue(){var t;const e=this.host.multiple?this._selectedOptions.map(t=>t.value):(null===(t=this._selectedOptions[0])||void 0===t?void 0:t.value)||"",i=this.host.value;let s=!1;if(this.host.multiple){const t=Array.isArray(i)?i:[],r=Array.isArray(e)?e:[];s=t.length===r.length&&t.every((t,e)=>t===r[e])}else s=i===e;s||(this.host.value=e)}getCurrentValue(){var t;return this.host.multiple?this._selectedOptions.map(t=>t.value):(null===(t=this._selectedOptions[0])||void 0===t?void 0:t.value)||""}dispatchChangeEvent(t){const e={value:this.getCurrentValue(),selectedOptions:this.getSelectedOptions(),previousValue:t};this.dispatchEvent(new CustomEvent("nr-change",{detail:e,bubbles:!0,composed:!0}))}hostUpdated(){this.syncWithHostOptions()}syncWithHostOptions(){try{this._selectedOptions=this._selectedOptions.filter(t=>this.host.options.some(e=>e.value===t.value)),this._selectedOptions=this._selectedOptions.map(t=>this.host.options.find(e=>e.value===t.value)||t),this.updateHostValue()}catch(t){this.handleError(t,"syncWithHostOptions")}}}class E extends z{constructor(t,e,i){super(t),this.selectionController=e,this.dropdownController=i,this._focusedIndex=-1,this._hasKeyboardNavigated=!1}handleKeyDown(t){try{const e=this.isSearchInputFocused();switch(t.key){case"ArrowDown":t.preventDefault(),this.dropdownController.isOpen?this.navigateNext():this.openDropdown();break;case"ArrowUp":t.preventDefault(),this.dropdownController.isOpen?this.navigatePrevious():this.openDropdown();break;case"Enter":this.dropdownController.isOpen?e&&this._focusedIndex>=0?(t.preventDefault(),this.selectFocused()):e||(t.preventDefault(),this.selectFocused()):(t.preventDefault(),this.openDropdown());break;case" ":e||(t.preventDefault(),this.dropdownController.isOpen?this.selectFocused():this.openDropdown());break;case"Escape":t.preventDefault(),this.closeDropdown();break;case"Tab":this.closeDropdown();break;case"Home":this.dropdownController.isOpen&&(t.preventDefault(),this.setFocusedIndex(0));break;case"End":this.dropdownController.isOpen&&(t.preventDefault(),this.setFocusedIndex(this.host.options.length-1));break;default:1===t.key.length&&/[a-zA-Z0-9]/.test(t.key)&&this.handleAlphanumericKey(t.key.toLowerCase())}}catch(t){this.handleError(t,"handleKeyDown")}}navigateNext(){try{const t=this.getNavigableOptions();if(0===t.length)return;if(this.isSearchInputFocused()&&(this._focusedIndex<0||!this._hasKeyboardNavigated))return this._hasKeyboardNavigated=!0,void this.setFocusedIndex(0);let e=this._focusedIndex+1;e>=t.length&&(e=0),this.setFocusedIndex(e)}catch(t){this.handleError(t,"navigateNext")}}navigatePrevious(){try{const t=this.getNavigableOptions();if(0===t.length)return;if(this.isSearchInputFocused()&&(this._focusedIndex<0||!this._hasKeyboardNavigated))return this._hasKeyboardNavigated=!0,void this.setFocusedIndex(t.length-1);let e=this._focusedIndex-1;e<0&&(e=t.length-1),this.setFocusedIndex(e)}catch(t){this.handleError(t,"navigatePrevious")}}selectFocused(){try{const t=this.getNavigableOptions()[this._focusedIndex];t&&!this.selectionController.isOptionDisabled(t)&&(this.selectionController.selectOption(t),this.host.multiple||this.closeDropdown())}catch(t){this.handleError(t,"selectFocused")}}openDropdown(){try{this.dropdownController.open(),this._hasKeyboardNavigated=!1,this._focusedIndex=-1}catch(t){this.handleError(t,"openDropdown")}}closeDropdown(){try{this.dropdownController.close(),this._focusedIndex=-1,this._hasKeyboardNavigated=!1}catch(t){this.handleError(t,"closeDropdown")}}setFocusedIndex(t){try{const e=this.getNavigableOptions();t>=0&&t<e.length&&(this._focusedIndex=t,this.dispatchFocusEvent(e[t],t),this.requestUpdate(),this.scrollToFocusedOption(t))}catch(t){this.handleError(t,"setFocusedIndex")}}scrollToFocusedOption(t){var e;try{const i=null===(e=this.host.shadowRoot)||void 0===e?void 0:e.querySelector(".options");if(!i)return;setTimeout(()=>{const e=i.querySelector(".option.focused");if(e)e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const e=40,s=i.clientHeight,r=i.scrollTop,o=t*e,a=o+e,n=r+s;o<r?i.scrollTo({top:o,behavior:"smooth"}):a>n&&i.scrollTo({top:a-s,behavior:"smooth"})}},10)}catch(t){console.warn("Failed to scroll to focused option:",t)}}get focusedIndex(){return this._focusedIndex}get focusedOption(){return this.getNavigableOptions()[this._focusedIndex]}handleAlphanumericKey(t){try{const e=this.getNavigableOptions(),i=this._focusedIndex+1;for(let s=0;s<e.length;s++){const r=(i+s)%e.length;if(e[r].label.toLowerCase().startsWith(t)){this.setFocusedIndex(r),this.dropdownController.isOpen||this.openDropdown();break}}}catch(t){this.handleError(t,"handleAlphanumericKey")}}getNavigableOptions(){const t=this.host;if(!t.options||!Array.isArray(t.options))return[];let e=t.options;return t.searchable&&t.searchQuery&&"function"==typeof t.getFilteredOptions&&(e=t.getFilteredOptions()),e.filter(t=>!t.disabled)}dispatchFocusEvent(t,e){const i={focusedOption:t,focusedIndex:e};this.dispatchEvent(new CustomEvent("nr-select-focus",{detail:i,bubbles:!0,composed:!0}))}isSearchInputFocused(){var t;try{const e=this.host;if(!e.searchable)return!1;const i=null===(t=e.shadowRoot)||void 0===t?void 0:t.querySelector(".search-input");return!!i&&(document.activeElement===i||i.shadowRoot&&i.shadowRoot.querySelector("input")===i.shadowRoot.activeElement||i.contains(document.activeElement))}catch(t){return!1}}hostUpdated(){this.dropdownController.isOpen||-1===this._focusedIndex||(this._focusedIndex=-1)}}class S extends z{constructor(){super(...arguments),this._isOpen=!1,this._position={top:0,left:0,width:0,placement:"bottom"},this._dropdownElement=null,this._triggerElement=null,this.handleResize=()=>{this._isOpen&&this.calculatePosition()},this.handleScroll=()=>{var t;if(this._isOpen&&this._triggerElement){const e=this._triggerElement.getBoundingClientRect(),i=(null===(t=window.visualViewport)||void 0===t?void 0:t.height)||window.innerHeight;(e.bottom<0||e.top>i)&&this.close()}}}get isOpen(){return this._isOpen}get position(){return Object.assign({},this._position)}open(){try{this._isOpen||(this._isOpen=!0,this.host.show=!0,this.requestUpdate(),this.findElements(),setTimeout(()=>{this.calculatePosition()},10),this.host&&"function"==typeof this.host.setupEventListeners&&setTimeout(()=>{this.host.setupEventListeners()},50),this.focusSearchInput(),this.dispatchEvent(new CustomEvent("nr-dropdown-open",{bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"open")}}close(){try{this._isOpen&&(this._isOpen=!1,this.host.show=!1,this.resetPosition(),this.requestUpdate(),this.host&&"function"==typeof this.host.removeEventListeners&&this.host.removeEventListeners(),this.dispatchEvent(new CustomEvent("nr-dropdown-close",{bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"close")}}toggle(){this._isOpen?this.close():this.open()}focusSearchInput(){try{const t=this.host;t&&t.searchable&&setTimeout(()=>{var e;const i=null===(e=t.shadowRoot)||void 0===e?void 0:e.querySelector(".search-input");i&&"function"==typeof i.focus&&i.focus()},100)}catch(t){console.warn("Failed to focus search input:",t)}}calculatePosition(){var t;try{if(this._dropdownElement&&this._triggerElement||this.findElements(),!this._dropdownElement||!this._triggerElement)return;const e=this._triggerElement.getBoundingClientRect(),i=((null===(t=window.visualViewport)||void 0===t?void 0:t.height)||window.innerHeight)-e.bottom,s=e.top,r=200,o=this.determineOptimalPlacement(r,s,i);this._position={left:0,width:0,placement:o,top:0},this.applyPosition()}catch(t){this.handleError(t,"calculatePosition")}}resetPosition(){try{if(this._dropdownElement){this._dropdownElement.style.removeProperty("position"),this._dropdownElement.style.removeProperty("top"),this._dropdownElement.style.removeProperty("left"),this._dropdownElement.style.removeProperty("width"),this._dropdownElement.style.removeProperty("min-width");this.host.maxHeight||this._dropdownElement.style.removeProperty("max-height"),this._dropdownElement.style.removeProperty("min-height"),this._dropdownElement.style.removeProperty("height"),this._dropdownElement.style.removeProperty("overflow-y"),this._dropdownElement.style.removeProperty("transform"),this._dropdownElement.style.removeProperty("display"),this._dropdownElement.style.removeProperty("opacity"),this._dropdownElement.style.removeProperty("visibility"),this._dropdownElement.style.removeProperty("z-index"),this._dropdownElement.classList.remove("placement-top","placement-bottom")}}catch(t){this.handleError(t,"resetPosition")}}setElements(t,e){this._dropdownElement=t,this._triggerElement=e}findElements(){try{const t=this._host;if(t.optionsElement&&t.wrapper)return this._dropdownElement=t.optionsElement,void(this._triggerElement=t.wrapper);t.shadowRoot&&(this._dropdownElement=t.shadowRoot.querySelector(".options"),this._triggerElement=t.shadowRoot.querySelector(".wrapper"))}catch(t){this.handleError(t,"findElements")}}determineOptimalPlacement(t,e,i){return i>=t?"bottom":e>=t||e>i?"top":"bottom"}applyPosition(){var t,e;try{if(!this._dropdownElement||!this._triggerElement)return;const i=this.host.maxHeight,s=null===(t=getComputedStyle(this._dropdownElement).getPropertyValue("--nuraly-select-local-dropdown-max-height"))||void 0===t?void 0:t.trim(),r="auto"===s||!i&&"auto"===s,{placement:o}=this._position,a=this._triggerElement.getBoundingClientRect(),n=a.width;this._dropdownElement.style.position="absolute",this._dropdownElement.style.left="0",this._dropdownElement.style.right="auto",this._dropdownElement.style.minWidth=`${n}px`,this._dropdownElement.style.removeProperty("width"),this._dropdownElement.style.zIndex="1000",this._dropdownElement.style.height="auto",i||r||(this._dropdownElement.style.maxHeight="none"),this._dropdownElement.style.minHeight="auto","bottom"===o?(this._dropdownElement.style.top="100%",this._dropdownElement.style.bottom="auto"):(this._dropdownElement.style.top="auto",this._dropdownElement.style.bottom="100%");const l=this._dropdownElement.scrollHeight,c=(null===(e=window.visualViewport)||void 0===e?void 0:e.height)||window.innerHeight;let h;h="bottom"===o?c-a.bottom-10:a.top-10,i?(this._dropdownElement.style.maxHeight=i,this._dropdownElement.style.overflowY="auto"):r?(this._dropdownElement.style.removeProperty("max-height"),this._dropdownElement.style.overflowY="visible"):l>h?(this._dropdownElement.style.maxHeight=`${h}px`,this._dropdownElement.style.overflowY="auto"):(this._dropdownElement.style.maxHeight=`${l}px`,this._dropdownElement.style.overflowY="auto"),this._dropdownElement.classList.remove("placement-top","placement-bottom"),this._dropdownElement.classList.add(`placement-${o}`)}catch(t){this.handleError(t,"applyPosition")}}getAvailableSpace(){var t,e;if(!this._triggerElement)return{above:0,below:0,left:0,right:0};const i=this._triggerElement.getBoundingClientRect(),s=(null===(t=window.visualViewport)||void 0===t?void 0:t.height)||window.innerHeight,r=(null===(e=window.visualViewport)||void 0===e?void 0:e.width)||window.innerWidth;return{above:i.top,below:s-i.bottom,left:i.left,right:r-i.right}}hostConnected(){window.addEventListener("resize",this.handleResize),window.addEventListener("scroll",this.handleScroll,!0)}hostDisconnected(){window.removeEventListener("resize",this.handleResize),window.removeEventListener("scroll",this.handleScroll,!0)}}class k extends z{constructor(){super(...arguments),this._focusedIndex=-1,this._hasFocus=!1}get focusedIndex(){return this._focusedIndex}getFocusedOption(){if(this._focusedIndex>=0&&this._focusedIndex<this.host.options.length)return this.host.options[this._focusedIndex]}get hasFocus(){return this._hasFocus}setFocusedOption(t){try{t>=0&&t<this.host.options.length&&(this._focusedIndex=t,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-focus-change",{detail:{focusedIndex:t,focusedOption:this.getFocusedOption()},bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"setFocusedOption")}}focus(){var t;try{const e=null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(".wrapper");e&&(e.focus(),this._hasFocus=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-focus",{bubbles:!0,composed:!0})))}catch(t){this.handleError(t,"focus")}}blur(){var t;try{const e=null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(".wrapper");e&&e.blur(),this._hasFocus=!1,this._focusedIndex=-1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-blur",{bubbles:!0,composed:!0}))}catch(t){this.handleError(t,"blur")}}focusNext(){try{const t=this.getNextFocusableIndex(this._focusedIndex);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusNext")}}focusPrevious(){try{const t=this.getPreviousFocusableIndex(this._focusedIndex);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusPrevious")}}focusFirst(){try{const t=this.getNextFocusableIndex(-1);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusFirst")}}focusLast(){try{const t=this.getPreviousFocusableIndex(this.host.options.length);-1!==t&&this.setFocusedOption(t)}catch(t){this.handleError(t,"focusLast")}}clearFocus(){this._focusedIndex=-1,this._hasFocus=!1,this.requestUpdate()}handleFocus(){this._hasFocus=!0,this.requestUpdate()}handleBlur(){this._hasFocus=!1,this._focusedIndex=-1,this.requestUpdate()}getNextFocusableIndex(t){const e=this.host.options;for(let i=t+1;i<e.length;i++)if(!e[i].disabled)return i;for(let i=0;i<=t;i++)if(!e[i].disabled)return i;return-1}getPreviousFocusableIndex(t){const e=this.host.options;for(let i=t-1;i>=0;i--)if(!e[i].disabled)return i;for(let i=e.length-1;i>=t;i--)if(!e[i].disabled)return i;return-1}findOptionIndex(t){return this.host.options.findIndex(e=>e.value===t)}focusOptionByValue(t){const e=this.findOptionIndex(t);-1!==e&&this.setFocusedOption(e)}}!function(t){t.Valid="valid",t.Invalid="invalid",t.Pending="pending",t.Pristine="pristine"}(x||(x={}));class $ extends z{constructor(t,e){super(t),this.selectionController=e,this._isValid=!0,this._validationMessage="",this._validationState=x.Pristine}get isValid(){return this._isValid}get validationMessage(){return this._validationMessage}get validationState(){return this._validationState}validate(){try{this._validationState=x.Pending;const t=this.selectionController.getSelectedOptions().length>0;return this.host.required&&!t?(this.setValidationResult(!1,"This field is required",x.Invalid),!1):(this.setValidationResult(!0,"",x.Valid),!0)}catch(t){return this.handleError(t,"validate"),this.setValidationResult(!1,"Validation error occurred",x.Invalid),!1}}reset(){try{this._isValid=!0,this._validationMessage="",this._validationState=x.Pristine,this.requestUpdate(),this.dispatchValidationEvent()}catch(t){this.handleError(t,"reset")}}getFormData(){var t;try{const e=this._host,i=e.name||e.getAttribute("name")||"select",s=this.selectionController.getSelectedOptions();return this.host.multiple?{[i]:s.map(t=>t.value)}:{[i]:(null===(t=s[0])||void 0===t?void 0:t.value)||""}}catch(t){return this.handleError(t,"getFormData"),{}}}checkValidity(){return this.validate()}reportValidity(){var t;const e=this.validate();if(!e){const e=null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(".wrapper");e&&e.focus()}return e}setCustomValidity(t){try{t?this.setValidationResult(!1,t,x.Invalid):this.validate()}catch(t){this.handleError(t,"setCustomValidity")}}validateOnChange(){this._validationState!==x.Pristine&&this.validate()}validateOnBlur(){this._validationState===x.Pristine&&(this._validationState=x.Pending),this.validate()}setValidationResult(t,e,i){const s=this._isValid!==t||this._validationMessage!==e||this._validationState!==i;this._isValid=t,this._validationMessage=e,this._validationState=i,s&&(this.requestUpdate(),this.dispatchValidationEvent())}dispatchValidationEvent(){const t={isValid:this._isValid,validationMessage:this._validationMessage,validationState:this._validationState};this.dispatchEvent(new CustomEvent("nr-validation",{detail:t,bubbles:!0,composed:!0}))}hostUpdated(){this.validateOnChange()}getValidationClasses(){return{valid:this._isValid&&this._validationState===x.Valid,invalid:!this._isValid&&this._validationState===x.Invalid,pending:this._validationState===x.Pending,pristine:this._validationState===x.Pristine}}getAriaAttributes(){const t={};return this.host.required&&(t["aria-required"]="true"),this._isValid||(t["aria-invalid"]="true",this._validationMessage&&(t["aria-describedby"]="validation-message")),t}}class C extends z{constructor(){super(...arguments),this._searchQuery="",this.handleSearchInput=t=>{this.setSearchQuery(t.detail.value||"")},this.handleSearchClear=()=>{this.clearSearch()},this.handleSearchKeyDown=t=>{if(["ArrowDown","ArrowUp","Enter","Home","End"].includes(t.key)){const e=this.host.keyboardController;return void(e&&e.handleKeyDown(t))}t.stopPropagation(),"Escape"===t.key&&(this.host.closeDropdown(),this.host.focus())}}get searchQuery(){return this._searchQuery}get hasSearch(){return""!==this._searchQuery.trim()}setSearchQuery(t){this._searchQuery=t,this.host.searchQuery=t,this.host.requestUpdate()}search(t){this.setSearchQuery(t)}clearSearch(){this.setSearchQuery("")}getFilteredOptions(t){if(!this.host.searchable||!this._searchQuery.trim())return t;const e=this._searchQuery.toLowerCase().trim();return t.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))}renderSearchInput(){return this.host.searchable?i`
592
+ <div class="search-container">
593
+ <nr-input
594
+ type="text"
595
+ class="search-input"
596
+ placeholder="${this.host.searchPlaceholder}"
597
+ .value="${this._searchQuery}"
598
+ allowClear
599
+ @nr-input="${this.handleSearchInput}"
600
+ @nr-clear="${this.handleSearchClear}"
601
+ @keydown="${this.handleSearchKeyDown}"
602
+ @click="${t=>t.stopPropagation()}"
603
+ >
604
+ <nr-icon
605
+ name="search"
606
+ class="search-icon"
607
+ slot="prefix"
608
+ aria-hidden="true">
609
+ </nr-icon>
610
+ </nr-input>
611
+ </div>
612
+ `:e}renderNoResults(){return i`
613
+ <div class="no-options" role="option" aria-disabled="true">
614
+ <div class="no-options-content">
615
+ <nr-icon
616
+ name="search"
617
+ class="no-options-icon"
618
+ aria-hidden="true">
619
+ </nr-icon>
620
+ <span class="no-options-text">No results found for "${this._searchQuery}"</span>
621
+ </div>
622
+ </div>
623
+ `}hasNoResults(t){return this.host.searchable&&""!==this._searchQuery.trim()&&0===this.getFilteredOptions(t).length}getCurrentQuery(){return this.host.searchQuery||this._searchQuery}hostUpdated(){super.hostUpdated(),this.host.searchQuery!==this._searchQuery&&(this._searchQuery=this.host.searchQuery)}hostConnected(){super.hostConnected(),this._searchQuery=""}}class A extends z{constructor(){super(...arguments),this.handleTriggerClick=t=>{this.host.disabled||(t.preventDefault(),t.stopPropagation(),this.host.toggleDropdown())},this.handleOptionClick=(t,e)=>{t.stopPropagation(),e.disabled||(this.host.multiple?this.host.toggleOption(e):(this.host.selectOption(e),this.host.closeDropdown()))},this.handleTagRemove=(t,e)=>{t.stopPropagation(),this.host.unselectOption(e)},this.handleClearAll=t=>{t.stopPropagation(),this.host.clearSelection()},this.handleKeyDown=t=>{const e=this.host.keyboardController;e&&e.handleKeyDown(t)},this.handleFocus=()=>{const t=this.host.focusController;t&&t.handleFocus()},this.handleBlur=()=>{const t=this.host.focusController;t&&t.handleBlur()},this.handleWindowClick=t=>{const e=t.target;this.host.contains(e)||this.host.closeDropdown()}}setupEventListeners(){window.addEventListener("click",this.handleWindowClick)}removeEventListeners(){window.removeEventListener("click",this.handleWindowClick)}hostDisconnected(){super.hostDisconnected(),this.removeEventListeners()}}
2
624
  /**
3
625
  * @license
4
626
  * Copyright 2023 Nuraly, Laabidi Aymen
5
627
  * SPDX-License-Identifier: MIT
6
- */var I=function(t,e,i,s){for(var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let N=class extends(d(s)){constructor(){super(...arguments),this.requiredComponents=["nr-input","nr-icon"],this.options=[],this.placeholder="Select an option",this.disabled=!1,this.type=p.Default,this.multiple=!1,this.show=!1,this.status=v.Default,this.size=y.Medium,this.required=!1,this.name="",this.value="",this.noOptionsMessage="No options available",this.noOptionsIcon="circle-info",this.searchable=!1,this.clearable=!1,this.searchPlaceholder="Search options...",this.searchQuery="",this.useCustomSelectedDisplay=!1,this.maxHeight="",this.block=!1,this.selectionController=new E(this),this.dropdownController=new $(this),this.keyboardController=new z(this,this.selectionController,this.dropdownController),this.focusController=new S(this),this.validationController=new k(this,this.selectionController),this.searchController=new C(this),this.eventController=new A(this),this.handleTriggerClick=t=>{this.eventController.handleTriggerClick(t)},this.handleOptionClick=(t,e)=>{this.eventController.handleOptionClick(t,e)},this.handleTagRemove=(t,e)=>{this.eventController.handleTagRemove(t,e)},this.handleClearAll=t=>{this.eventController.handleClearAll(t)},this.handleKeyDown=t=>{this.eventController.handleKeyDown(t)},this.handleFocus=()=>{this.eventController.handleFocus()},this.handleBlur=()=>{this.eventController.handleBlur()}}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback()}willUpdate(t){super.willUpdate(t),(t.has("options")||t.has("value"))&&this.options.length>0&&this.value&&(Array.isArray(this.value)?this.value.length>0:""!==this.value)&&(this.selectionController._initialized=!1,this.selectionController.initializeFromValue())}firstUpdated(t){super.firstUpdated(t),this.optionsElement&&this.wrapper?this.dropdownController.setElements(this.optionsElement,this.wrapper):setTimeout((()=>{this.optionsElement&&this.wrapper&&this.dropdownController.setElements(this.optionsElement,this.wrapper)}),100),this.value&&(Array.isArray(this.value)?this.value.length>0:""!==this.value)&&this.selectionController.initializeFromValue()}get selectedOptions(){return this.selectionController.getSelectedOptions()}get selectedOption(){return this.selectionController.getSelectedOption()}selectOption(t){this.selectionController.selectOption(t)}unselectOption(t){this.selectionController.unselectOption(t)}toggleOption(t){this.selectionController.toggleOption(t)}clearSelection(){this.selectionController.clearSelection()}isOptionSelected(t){return this.selectionController.isOptionSelected(t)}toggleDropdown(){this.dropdownController.toggle()}openDropdown(){this.dropdownController.open()}closeDropdown(){this.dropdownController.close()}focus(){this.focusController.focus()}blur(){this.focusController.blur()}validate(){return this.validationController.validate()}checkValidity(){return this.validationController.checkValidity()}reportValidity(){return this.validationController.reportValidity()}setCustomValidity(t){this.validationController.setCustomValidity(t)}searchOptions(t){this.searchController.search(t)}clearSearch(){this.searchController.clearSearch()}getSearchFilteredOptions(){return this.searchController.getFilteredOptions(this.options)}getCurrentSearchQuery(){return this.searchController.searchQuery}getSelectedOptions(){return this.selectedOptions}setupGlobalEventListeners(){this.eventController.setupEventListeners()}removeGlobalEventListeners(){this.eventController.removeEventListeners()}getFilteredOptions(){return this.searchController.getFilteredOptions(this.options)}setupEventListeners(){this.eventController.setupEventListeners()}removeEventListeners(){this.eventController.removeEventListeners()}render(){return i`${l(this.type,[[p.Default,()=>this.renderDefault()],[p.Inline,()=>this.renderInline()],[p.Button,()=>this.renderButton()],[p.Slot,()=>this.renderSlot()]])}`}renderDefault(){const t=this.selectedOptions,s=this.validationController.getValidationClasses();return i`<slot name="label"></slot><div class="${c(Object.assign({wrapper:!0},s))}" data-theme="${this.currentTheme}" tabindex="0" role="combobox" aria-expanded="${this.show}" aria-haspopup="listbox" aria-labelledby="select-label" @click="${this.handleTriggerClick}" @keydown="${this.handleKeyDown}" @focus="${this.handleFocus}" @blur="${this.handleBlur}"><div class="select"><div class="select-trigger">${this.renderSelectedContent(t)}</div><div class="icons-container">${this.renderStatusIcon()} ${this.renderClearButton(t)}<nr-icon name="angle-down" size="${this.size}" class="arrow-icon" aria-hidden="true"></nr-icon></div><div class="options" role="listbox" aria-multiselectable="${this.multiple}" style="${this.maxHeight?h({"max-height":this.maxHeight}):e}">${this.searchable?this.renderSearchInput():e} ${this.renderSelectOptions()}</div></div></div>${this.renderValidationMessage()}<slot name="helper-text"></slot>`}renderInline(){return i`<slot name="label"></slot>${this.renderDefault()}<slot name="helper-text"></slot>`}renderButton(){const t=this.selectedOptions;return i`<button class="select-button" ?disabled="${this.disabled}" @click="${this.handleTriggerClick}" @keydown="${this.handleKeyDown}">${t.length>0?t[0].label:this.placeholder}<nr-icon name="angle-down" class="arrow-icon"></nr-icon></button><div class="options" role="listbox" style="${this.maxHeight?h({"max-height":this.maxHeight}):e}">${this.searchable?this.renderSearchInput():e} ${this.renderSelectOptions()}</div>`}renderSlot(){return i`<slot name="trigger" @click="${this.handleTriggerClick}"></slot><div class="options" role="listbox" style="${this.maxHeight?h({"max-height":this.maxHeight}):e}">${this.searchable?this.renderSearchInput():e} ${this.renderSelectOptions()}</div>`}renderSelectedContent(t){return 0===t.length?i`<span class="placeholder" aria-hidden="true">${this.placeholder}</span>`:this.multiple?this.useCustomSelectedDisplay?i`<slot name="selected-display" .selectedOptions="${t}"></slot>`:a(t,(t=>i`<span class="tag"><span class="tag-label">${t.label}</span><nr-icon name="remove" size="${this.size}" class="tag-close" @click="${e=>this.handleTagRemove(e,t)}" aria-label="Remove ${t.label}"></nr-icon></span>`)):i`${t[0].label}`}renderStatusIcon(){switch(this.status){case v.Warning:return i`<nr-icon name="warning" size="${this.size}" class="status-icon warning"></nr-icon>`;case v.Error:return i`<nr-icon name="exclamation-circle" size="${this.size}" class="status-icon error"></nr-icon>`;case v.Success:return i`<nr-icon name="check-circle" size="${this.size}" class="status-icon success"></nr-icon>`;default:return e}}renderClearButton(t){return!this.clearable||0===t.length||this.disabled?e:i`<nr-icon name="remove" size="${this.size}" class="clear-icon" @click="${this.handleClearAll}" aria-label="Clear selection" tabindex="-1"></nr-icon>`}renderSelectOptions(){const t=this.getFilteredOptions();if(!this.options||0===this.options.length)return i`<div class="no-options" role="option" aria-disabled="true"><div class="no-options-content"><nr-icon name="${this.noOptionsIcon}" class="no-options-icon" aria-hidden="true"></nr-icon><span class="no-options-text">${this.noOptionsMessage}</span></div></div>`;if(this.searchController.hasNoResults(this.options))return this.searchController.renderNoResults();const s=this.keyboardController.focusedOption;return a(t,(t=>{const o=this.isOptionSelected(t),r=s&&s.value===t.value;return i`<div class="${c({option:!0,selected:o,focused:r,disabled:Boolean(t.disabled)})}" role="option" aria-selected="${o}" aria-disabled="${Boolean(t.disabled)}" data-value="${t.value}" @click="${e=>this.handleOptionClick(e,t)}" style="${h(t.style?{style:t.style}:{})}" title="${t.title||""}"><div class="option-content">${t.icon?i`<nr-icon name="${t.icon}" size="${this.size}" class="option-icon"></nr-icon>`:e}<div class="option-text">${t.htmlContent?i`<div .innerHTML="${t.htmlContent}"></div>`:t.label} ${t.description?i`<div class="option-description">${t.description}</div>`:e}</div></div>${o?i`<nr-icon name="check" size="${this.size}" class="check-icon" aria-hidden="true"></nr-icon>`:e} ${t.state&&t.message?i`<div class="option-message ${t.state}"><nr-icon name="${"error"===t.state?"exclamation-circle":"warning"}" size="${this.size}"></nr-icon><span>${t.message}</span></div>`:e}</div>`}))}renderSearchInput(){return this.searchController.renderSearchInput()}renderValidationMessage(){const t=this.validationController.validationMessage;return t?i`<div class="validation-message ${this.status}" id="validation-message">${t}</div>`:e}};N.styles=u,I([o({type:Array})],N.prototype,"options",void 0),I([o({type:String})],N.prototype,"placeholder",void 0),I([o({type:Boolean,reflect:!0})],N.prototype,"disabled",void 0),I([o({type:String,reflect:!0})],N.prototype,"type",void 0),I([o({type:Boolean,attribute:"multiple"})],N.prototype,"multiple",void 0),I([o({type:Boolean,reflect:!0})],N.prototype,"show",void 0),I([o({type:String,reflect:!0})],N.prototype,"status",void 0),I([o({type:String,reflect:!0})],N.prototype,"size",void 0),I([o({type:Boolean,reflect:!0})],N.prototype,"required",void 0),I([o({type:String})],N.prototype,"name",void 0),I([o()],N.prototype,"value",void 0),I([o({type:String,attribute:"no-options-message"})],N.prototype,"noOptionsMessage",void 0),I([o({type:String,attribute:"no-options-icon"})],N.prototype,"noOptionsIcon",void 0),I([o({type:Boolean,reflect:!0})],N.prototype,"searchable",void 0),I([o({type:Boolean,reflect:!0})],N.prototype,"clearable",void 0),I([o({type:String,attribute:"search-placeholder"})],N.prototype,"searchPlaceholder",void 0),I([o({type:String})],N.prototype,"searchQuery",void 0),I([o({type:Boolean,attribute:"use-custom-selected-display"})],N.prototype,"useCustomSelectedDisplay",void 0),I([o({type:String,attribute:"max-height"})],N.prototype,"maxHeight",void 0),I([o({type:Boolean,reflect:!0})],N.prototype,"block",void 0),I([r(".options")],N.prototype,"optionsElement",void 0),I([r(".wrapper")],N.prototype,"wrapper",void 0),I([r(".search-input")],N.prototype,"searchInput",void 0),N=I([n("nr-select")],N);
628
+ */var I=function(t,e,i,s){for(var r,o=arguments.length,a=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,n=t.length-1;n>=0;n--)(r=t[n])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a};let D=class extends(d(s)){constructor(){super(...arguments),this.requiredComponents=["nr-input","nr-icon"],this.options=[],this.placeholder="Select an option",this.disabled=!1,this.type=p.Default,this.multiple=!1,this.show=!1,this.status=v.Default,this.size=y.Medium,this.required=!1,this.name="",this.value="",this.noOptionsMessage="No options available",this.noOptionsIcon="info",this.searchable=!1,this.clearable=!1,this.searchPlaceholder="Search options...",this.searchQuery="",this.useCustomSelectedDisplay=!1,this.maxHeight="",this.block=!1,this.selectionController=new O(this),this.dropdownController=new S(this),this.keyboardController=new E(this,this.selectionController,this.dropdownController),this.focusController=new k(this),this.validationController=new $(this,this.selectionController),this.searchController=new C(this),this.eventController=new A(this),this.handleTriggerClick=t=>{this.eventController.handleTriggerClick(t)},this.handleOptionClick=(t,e)=>{this.eventController.handleOptionClick(t,e)},this.handleTagRemove=(t,e)=>{this.eventController.handleTagRemove(t,e)},this.handleClearAll=t=>{this.eventController.handleClearAll(t)},this.handleKeyDown=t=>{this.eventController.handleKeyDown(t)},this.handleFocus=()=>{this.eventController.handleFocus()},this.handleBlur=()=>{this.eventController.handleBlur()}}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback()}willUpdate(t){super.willUpdate(t),(t.has("options")||t.has("value"))&&this.options.length>0&&this.value&&(Array.isArray(this.value)?this.value.length>0:""!==this.value)&&(this.selectionController._initialized=!1,this.selectionController.initializeFromValue())}firstUpdated(t){super.firstUpdated(t),this.optionsElement&&this.wrapper?this.dropdownController.setElements(this.optionsElement,this.wrapper):setTimeout(()=>{this.optionsElement&&this.wrapper&&this.dropdownController.setElements(this.optionsElement,this.wrapper)},100),this.value&&(Array.isArray(this.value)?this.value.length>0:""!==this.value)&&this.selectionController.initializeFromValue()}get selectedOptions(){return this.selectionController.getSelectedOptions()}get selectedOption(){return this.selectionController.getSelectedOption()}selectOption(t){this.selectionController.selectOption(t)}unselectOption(t){this.selectionController.unselectOption(t)}toggleOption(t){this.selectionController.toggleOption(t)}clearSelection(){this.selectionController.clearSelection()}isOptionSelected(t){return this.selectionController.isOptionSelected(t)}toggleDropdown(){this.dropdownController.toggle()}openDropdown(){this.dropdownController.open()}closeDropdown(){this.dropdownController.close()}focus(){this.focusController.focus()}blur(){this.focusController.blur()}validate(){return this.validationController.validate()}checkValidity(){return this.validationController.checkValidity()}reportValidity(){return this.validationController.reportValidity()}setCustomValidity(t){this.validationController.setCustomValidity(t)}searchOptions(t){this.searchController.search(t)}clearSearch(){this.searchController.clearSearch()}getSearchFilteredOptions(){return this.searchController.getFilteredOptions(this.options)}getCurrentSearchQuery(){return this.searchController.searchQuery}getSelectedOptions(){return this.selectedOptions}setupGlobalEventListeners(){this.eventController.setupEventListeners()}removeGlobalEventListeners(){this.eventController.removeEventListeners()}getFilteredOptions(){return this.searchController.getFilteredOptions(this.options)}setupEventListeners(){this.eventController.setupEventListeners()}removeEventListeners(){this.eventController.removeEventListeners()}render(){return i`${l(this.type,[[p.Default,()=>this.renderDefault()],[p.Inline,()=>this.renderInline()],[p.Button,()=>this.renderButton()],[p.Slot,()=>this.renderSlot()]])}`}renderDefault(){const t=this.selectedOptions,s=this.validationController.getValidationClasses();return i`
629
+ <slot name="label"></slot>
630
+ <div
631
+ class="${c(Object.assign({wrapper:!0},s))}"
632
+ data-theme="${this.currentTheme}"
633
+ tabindex="0"
634
+ role="combobox"
635
+ aria-expanded="${this.show}"
636
+ aria-haspopup="listbox"
637
+ aria-labelledby="select-label"
638
+
639
+ @click=${this.handleTriggerClick}
640
+ @keydown=${this.handleKeyDown}
641
+ @focus=${this.handleFocus}
642
+ @blur=${this.handleBlur}
643
+ >
644
+ <div class="select">
645
+ <div class="select-trigger">
646
+ ${this.renderSelectedContent(t)}
647
+ </div>
648
+
649
+ <div class="icons-container">
650
+ ${this.renderStatusIcon()}
651
+ ${this.renderClearButton(t)}
652
+ <nr-icon
653
+ name="chevron-down"
654
+ size="${this.size}"
655
+ class="arrow-icon"
656
+ aria-hidden="true"
657
+ ></nr-icon>
658
+ </div>
659
+
660
+ <div
661
+ class="options"
662
+ role="listbox"
663
+ aria-multiselectable="${this.multiple}"
664
+ style=${this.maxHeight?h({"max-height":this.maxHeight}):e}
665
+ >
666
+ ${this.searchable?this.renderSearchInput():e}
667
+ ${this.renderSelectOptions()}
668
+ </div>
669
+ </div>
670
+ </div>
671
+
672
+ ${this.renderValidationMessage()}
673
+ <slot name="helper-text"></slot>
674
+ `}renderInline(){return i`
675
+ <slot name="label"></slot>
676
+ ${this.renderDefault()}
677
+ <slot name="helper-text"></slot>
678
+ `}renderButton(){const t=this.selectedOptions;return i`
679
+ <button
680
+ class="select-button"
681
+ ?disabled=${this.disabled}
682
+ @click=${this.handleTriggerClick}
683
+ @keydown=${this.handleKeyDown}
684
+ >
685
+ ${t.length>0?t[0].label:this.placeholder}
686
+ <nr-icon name="chevron-down" class="arrow-icon"></nr-icon>
687
+ </button>
688
+
689
+ <div
690
+ class="options"
691
+ role="listbox"
692
+ style=${this.maxHeight?h({"max-height":this.maxHeight}):e}
693
+ >
694
+ ${this.searchable?this.renderSearchInput():e}
695
+ ${this.renderSelectOptions()}
696
+ </div>
697
+ `}renderSlot(){return i`
698
+ <slot name="trigger" @click=${this.handleTriggerClick}></slot>
699
+ <div
700
+ class="options"
701
+ role="listbox"
702
+ style=${this.maxHeight?h({"max-height":this.maxHeight}):e}
703
+ >
704
+ ${this.searchable?this.renderSearchInput():e}
705
+ ${this.renderSelectOptions()}
706
+ </div>
707
+ `}renderSelectedContent(t){return 0===t.length?i`<span class="placeholder" aria-hidden="true">${this.placeholder}</span>`:this.multiple?this.useCustomSelectedDisplay?i`<slot name="selected-display" .selectedOptions=${t}></slot>`:n(t,t=>i`
708
+ <span class="tag">
709
+ <span class="tag-label">${t.label}</span>
710
+ <nr-icon
711
+ name="x"
712
+ size="${this.size}"
713
+ class="tag-close"
714
+ @click=${e=>this.handleTagRemove(e,t)}
715
+ aria-label="Remove ${t.label}"
716
+ ></nr-icon>
717
+ </span>
718
+ `):i`${t[0].label}`}renderStatusIcon(){switch(this.status){case v.Warning:return i`<nr-icon name="alert-triangle" size="${this.size}" class="status-icon warning"></nr-icon>`;case v.Error:return i`<nr-icon name="alert-circle" size="${this.size}" class="status-icon error"></nr-icon>`;case v.Success:return i`<nr-icon name="circle-check" size="${this.size}" class="status-icon success"></nr-icon>`;default:return e}}renderClearButton(t){return!this.clearable||0===t.length||this.disabled?e:i`
719
+ <nr-icon
720
+ name="x"
721
+ size="${this.size}"
722
+ class="clear-icon"
723
+ @click=${this.handleClearAll}
724
+ aria-label="Clear selection"
725
+ tabindex="-1"
726
+ ></nr-icon>
727
+ `}renderSelectOptions(){const t=this.getFilteredOptions();if(!this.options||0===this.options.length)return i`
728
+ <div class="no-options" role="option" aria-disabled="true">
729
+ <div class="no-options-content">
730
+ <nr-icon
731
+ name="${this.noOptionsIcon}"
732
+ class="no-options-icon"
733
+ aria-hidden="true">
734
+ </nr-icon>
735
+ <span class="no-options-text">${this.noOptionsMessage}</span>
736
+ </div>
737
+ </div>
738
+ `;if(this.searchController.hasNoResults(this.options))return this.searchController.renderNoResults();const s=this.keyboardController.focusedOption;return n(t,t=>{const r=this.isOptionSelected(t),o=s&&s.value===t.value;return i`
739
+ <div
740
+ class="${c({option:!0,selected:r,focused:o,disabled:Boolean(t.disabled)})}"
741
+ role="option"
742
+ aria-selected="${r}"
743
+ aria-disabled="${Boolean(t.disabled)}"
744
+ data-value="${t.value}"
745
+ @click=${e=>this.handleOptionClick(e,t)}
746
+ style=${h(t.style?{style:t.style}:{})}
747
+ title="${t.title||""}"
748
+ >
749
+ <div class="option-content">
750
+ ${t.icon?i`<nr-icon name="${t.icon}" size="${this.size}" class="option-icon"></nr-icon>`:e}
751
+ <div class="option-text">
752
+ ${t.htmlContent?i`<div .innerHTML=${t.htmlContent}></div>`:t.label}
753
+ ${t.description?i`<div class="option-description">${t.description}</div>`:e}
754
+ </div>
755
+ </div>
756
+
757
+ ${r?i`<nr-icon name="check" size="${this.size}" class="check-icon" aria-hidden="true"></nr-icon>`:e}
758
+
759
+ ${t.state&&t.message?i`
760
+ <div class="option-message ${t.state}">
761
+ <nr-icon name="${"error"===t.state?"alert-circle":"alert-triangle"}" size="${this.size}"></nr-icon>
762
+ <span>${t.message}</span>
763
+ </div>
764
+ `:e}
765
+ </div>
766
+ `})}renderSearchInput(){return this.searchController.renderSearchInput()}renderValidationMessage(){const t=this.validationController.validationMessage;return t?i`
767
+ <div class="validation-message ${this.status}" id="validation-message">
768
+ ${t}
769
+ </div>
770
+ `:e}};D.styles=u,I([r({type:Array})],D.prototype,"options",void 0),I([r({type:String})],D.prototype,"placeholder",void 0),I([r({type:Boolean,reflect:!0})],D.prototype,"disabled",void 0),I([r({type:String,reflect:!0})],D.prototype,"type",void 0),I([r({type:Boolean,attribute:"multiple"})],D.prototype,"multiple",void 0),I([r({type:Boolean,reflect:!0})],D.prototype,"show",void 0),I([r({type:String,reflect:!0})],D.prototype,"status",void 0),I([r({type:String,reflect:!0})],D.prototype,"size",void 0),I([r({type:Boolean,reflect:!0})],D.prototype,"required",void 0),I([r({type:String})],D.prototype,"name",void 0),I([r()],D.prototype,"value",void 0),I([r({type:String,attribute:"no-options-message"})],D.prototype,"noOptionsMessage",void 0),I([r({type:String,attribute:"no-options-icon"})],D.prototype,"noOptionsIcon",void 0),I([r({type:Boolean,reflect:!0})],D.prototype,"searchable",void 0),I([r({type:Boolean,reflect:!0})],D.prototype,"clearable",void 0),I([r({type:String,attribute:"search-placeholder"})],D.prototype,"searchPlaceholder",void 0),I([r({type:String})],D.prototype,"searchQuery",void 0),I([r({type:Boolean,attribute:"use-custom-selected-display"})],D.prototype,"useCustomSelectedDisplay",void 0),I([r({type:String,attribute:"max-height"})],D.prototype,"maxHeight",void 0),I([r({type:Boolean,reflect:!0})],D.prototype,"block",void 0),I([o(".options")],D.prototype,"optionsElement",void 0),I([o(".wrapper")],D.prototype,"wrapper",void 0),I([o(".search-input")],D.prototype,"searchInput",void 0),D=I([a("nr-select")],D);
7
771
  /**
8
772
  * @license
9
773
  * Copyright 2023 Nuraly, Laabidi Aymen
10
774
  * SPDX-License-Identifier: MIT
11
775
  */
12
- const D={CHANGE:"nr-change",FOCUS:"nr-focus",BLUR:"nr-blur",DROPDOWN_OPEN:"nr-dropdown-open",DROPDOWN_CLOSE:"nr-dropdown-close",VALIDATION:"nr-validation",ERROR:"nr-select-error"},T={WRAPPER:"wrapper",SELECT:"select",TRIGGER:"select-trigger",OPTIONS:"options",OPTION:"option",SELECTED:"selected",FOCUSED:"focused",DISABLED:"disabled",TAG:"tag",TAG_LABEL:"tag-label",TAG_CLOSE:"tag-close",ICONS_CONTAINER:"icons-container",ARROW_ICON:"arrow-icon",CLEAR_ICON:"clear-icon",STATUS_ICON:"status-icon",CHECK_ICON:"check-icon",VALIDATION_MESSAGE:"validation-message",PLACEHOLDER:"placeholder",NO_OPTIONS:"no-options",NO_OPTIONS_CONTENT:"no-options-content",NO_OPTIONS_ICON:"no-options-icon",NO_OPTIONS_TEXT:"no-options-text",SEARCH_CONTAINER:"search-container",SEARCH_INPUT:"search-input",SEARCH_ICON:"search-icon",SEARCH_CLEAR:"search-clear"},R={COMBOBOX:"combobox",LISTBOX:"listbox",OPTION:"option",EXPANDED:"aria-expanded",HASPOPUP:"aria-haspopup",MULTISELECTABLE:"aria-multiselectable",SELECTED:"aria-selected",DISABLED:"aria-disabled",REQUIRED:"aria-required",INVALID:"aria-invalid",DESCRIBEDBY:"aria-describedby",LABELLEDBY:"aria-labelledby"},L={PLACEHOLDER:"Select an option",MAX_HEIGHT:"200px",DROPDOWN_OFFSET:4,TAG_MAX_WIDTH:"150px",TRANSITION_DURATION:200,DEBOUNCE_DELAY:300},P={ENTER:"Enter",SPACE:" ",ESCAPE:"Escape",ARROW_DOWN:"ArrowDown",ARROW_UP:"ArrowUp",HOME:"Home",END:"End",TAB:"Tab"},B="",F=", ";export{O as BaseSelectController,b as DropdownPlacement,B as EMPTY_STRING,N as HySelectComponent,F as MULTIPLE_OPTIONS_SEPARATOR,g as OptionSize,R as SELECT_ARIA,T as SELECT_CLASSES,L as SELECT_DEFAULTS,D as SELECT_EVENTS,P as SELECT_KEYS,w as SearchMode,m as SelectDirection,$ as SelectDropdownController,A as SelectEventController,S as SelectFocusController,z as SelectKeyboardController,C as SelectSearchController,E as SelectSelectionController,y as SelectSize,v as SelectStatus,p as SelectType,k as SelectValidationController,f as SelectVariant};
776
+ const N={CHANGE:"nr-change",FOCUS:"nr-focus",BLUR:"nr-blur",DROPDOWN_OPEN:"nr-dropdown-open",DROPDOWN_CLOSE:"nr-dropdown-close",VALIDATION:"nr-validation",ERROR:"nr-select-error"},T={WRAPPER:"wrapper",SELECT:"select",TRIGGER:"select-trigger",OPTIONS:"options",OPTION:"option",SELECTED:"selected",FOCUSED:"focused",DISABLED:"disabled",TAG:"tag",TAG_LABEL:"tag-label",TAG_CLOSE:"tag-close",ICONS_CONTAINER:"icons-container",ARROW_ICON:"arrow-icon",CLEAR_ICON:"clear-icon",STATUS_ICON:"status-icon",CHECK_ICON:"check-icon",VALIDATION_MESSAGE:"validation-message",PLACEHOLDER:"placeholder",NO_OPTIONS:"no-options",NO_OPTIONS_CONTENT:"no-options-content",NO_OPTIONS_ICON:"no-options-icon",NO_OPTIONS_TEXT:"no-options-text",SEARCH_CONTAINER:"search-container",SEARCH_INPUT:"search-input",SEARCH_ICON:"search-icon",SEARCH_CLEAR:"search-clear"},R={COMBOBOX:"combobox",LISTBOX:"listbox",OPTION:"option",EXPANDED:"aria-expanded",HASPOPUP:"aria-haspopup",MULTISELECTABLE:"aria-multiselectable",SELECTED:"aria-selected",DISABLED:"aria-disabled",REQUIRED:"aria-required",INVALID:"aria-invalid",DESCRIBEDBY:"aria-describedby",LABELLEDBY:"aria-labelledby"},L={PLACEHOLDER:"Select an option",MAX_HEIGHT:"auto",DROPDOWN_OFFSET:4,TAG_MAX_WIDTH:"150px",TRANSITION_DURATION:200,DEBOUNCE_DELAY:300},P={ENTER:"Enter",SPACE:" ",ESCAPE:"Escape",ARROW_DOWN:"ArrowDown",ARROW_UP:"ArrowUp",HOME:"Home",END:"End",TAB:"Tab"},F="",B=", ";export{z as BaseSelectController,f as DropdownPlacement,F as EMPTY_STRING,D as HySelectComponent,B as MULTIPLE_OPTIONS_SEPARATOR,g as OptionSize,R as SELECT_ARIA,T as SELECT_CLASSES,L as SELECT_DEFAULTS,N as SELECT_EVENTS,P as SELECT_KEYS,w as SearchMode,m as SelectDirection,S as SelectDropdownController,A as SelectEventController,k as SelectFocusController,E as SelectKeyboardController,C as SelectSearchController,O as SelectSelectionController,y as SelectSize,v as SelectStatus,p as SelectType,$ as SelectValidationController,b as SelectVariant};