@smilodon/core 1.5.3 → 1.5.5

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/dist/index.js CHANGED
@@ -1598,7 +1598,7 @@ class SelectOption extends HTMLElement {
1598
1598
  transform: var(--select-option-selected-hover-transform, var(--select-option-selected-transform, var(--select-option-transform, none)));
1599
1599
  }
1600
1600
 
1601
- .option-container.active {
1601
+ .option-container.active:not(.disabled) {
1602
1602
  background: var(--select-option-active-bg, var(--select-option-hover-bg, #f0f0f0));
1603
1603
  color: var(--select-option-active-color, var(--select-option-hover-color, var(--select-option-color, var(--select-text-color, #1f2937))));
1604
1604
  border: var(--select-option-active-border, var(--select-option-hover-border, var(--select-option-border, none)));
@@ -1726,7 +1726,7 @@ class SelectOption extends HTMLElement {
1726
1726
  toggleClasses(this._container, [...selectedClasses, 'smilodon-option--selected'], false);
1727
1727
  toggleClasses(this, [...selectedClasses, 'smilodon-option--selected'], false);
1728
1728
  }
1729
- if (active) {
1729
+ if (active && !disabled) {
1730
1730
  toggleClasses(this._container, [...activeClasses, 'smilodon-option--active'], true);
1731
1731
  toggleClasses(this, [...activeClasses, 'smilodon-option--active'], true); // Make focus ring visible on host
1732
1732
  }
@@ -1794,8 +1794,12 @@ class SelectOption extends HTMLElement {
1794
1794
  // Set ARIA attributes and State attributes on Host
1795
1795
  this.setAttribute('role', 'option');
1796
1796
  this.setAttribute('aria-selected', String(selected));
1797
- if (disabled)
1797
+ if (disabled) {
1798
1798
  this.setAttribute('aria-disabled', 'true');
1799
+ }
1800
+ else {
1801
+ this.removeAttribute('aria-disabled');
1802
+ }
1799
1803
  this.id = this._config.id || `select-option-${index}`;
1800
1804
  // Add checkmark (part="checkmark") - standard for object mode
1801
1805
  // Only show if NOT showing remove button (avoid clutter)
@@ -1814,7 +1818,7 @@ class SelectOption extends HTMLElement {
1814
1818
  const state = [];
1815
1819
  if (selected)
1816
1820
  state.push('selected');
1817
- if (active)
1821
+ if (active && !disabled)
1818
1822
  state.push('active');
1819
1823
  if (state.length) {
1820
1824
  this.dataset.smState = state.join(' ');
@@ -1938,7 +1942,7 @@ class SelectOption extends HTMLElement {
1938
1942
  * Set active state
1939
1943
  */
1940
1944
  setActive(active) {
1941
- this._config.active = active;
1945
+ this._config.active = active && !this._config.disabled;
1942
1946
  this._render();
1943
1947
  }
1944
1948
  /**
@@ -2006,6 +2010,8 @@ class EnhancedSelect extends HTMLElement {
2006
2010
  this._mirrorGlobalStylesForCustomOptions = false;
2007
2011
  this._globalStylesObserver = null;
2008
2012
  this._globalStylesContainer = null;
2013
+ this._themeContextObserver = null;
2014
+ this._globalStylesSyncToken = 0;
2009
2015
  this._tracking = { events: [], styles: [], limitations: [] };
2010
2016
  this._suppressBlurClose = false;
2011
2017
  this._renderCycleId = 0;
@@ -2121,6 +2127,7 @@ class EnhancedSelect extends HTMLElement {
2121
2127
  return;
2122
2128
  if (!this._mirrorGlobalStylesForCustomOptions)
2123
2129
  return;
2130
+ this._setupThemeContextMirroring();
2124
2131
  this._mirrorDocumentStylesIntoShadow();
2125
2132
  if (this._globalStylesObserver)
2126
2133
  return;
@@ -2139,6 +2146,10 @@ class EnhancedSelect extends HTMLElement {
2139
2146
  this._globalStylesObserver.disconnect();
2140
2147
  this._globalStylesObserver = null;
2141
2148
  }
2149
+ if (this._themeContextObserver) {
2150
+ this._themeContextObserver.disconnect();
2151
+ this._themeContextObserver = null;
2152
+ }
2142
2153
  if (this._globalStylesContainer) {
2143
2154
  this._globalStylesContainer.remove();
2144
2155
  this._globalStylesContainer = null;
@@ -2155,34 +2166,232 @@ class EnhancedSelect extends HTMLElement {
2155
2166
  this._shadow.appendChild(this._globalStylesContainer);
2156
2167
  }
2157
2168
  const container = this._globalStylesContainer;
2158
- container.innerHTML = '';
2169
+ const syncToken = ++this._globalStylesSyncToken;
2159
2170
  const styleNodes = Array.from(document.querySelectorAll('style,link[rel="stylesheet"]'));
2160
- styleNodes.forEach((node, index) => {
2161
- if (node instanceof HTMLStyleElement) {
2162
- const clonedStyle = document.createElement('style');
2163
- clonedStyle.setAttribute('data-smilodon-global-style', String(index));
2164
- clonedStyle.textContent = node.textContent || '';
2165
- container.appendChild(clonedStyle);
2171
+ void Promise.all(styleNodes.map((node, index) => this._createScopedGlobalStyleNode(node, index))).then((mirroredNodes) => {
2172
+ if (!this._globalStylesContainer || syncToken !== this._globalStylesSyncToken)
2166
2173
  return;
2174
+ container.replaceChildren(...mirroredNodes.filter((node) => Boolean(node)));
2175
+ this._syncMirroredThemeContext();
2176
+ });
2177
+ }
2178
+ _setupThemeContextMirroring() {
2179
+ if (typeof document === 'undefined')
2180
+ return;
2181
+ this._syncMirroredThemeContext();
2182
+ if (this._themeContextObserver)
2183
+ return;
2184
+ this._themeContextObserver = new MutationObserver(() => {
2185
+ this._syncMirroredThemeContext();
2186
+ });
2187
+ const targets = new Set([this, document.documentElement]);
2188
+ if (document.body) {
2189
+ targets.add(document.body);
2190
+ }
2191
+ let ancestor = this.parentElement;
2192
+ while (ancestor) {
2193
+ targets.add(ancestor);
2194
+ ancestor = ancestor.parentElement;
2195
+ }
2196
+ targets.forEach((target) => {
2197
+ this._themeContextObserver?.observe(target, {
2198
+ attributes: true,
2199
+ attributeFilter: ['class', 'dark-mode', 'darkmode', 'data-theme', 'theme'],
2200
+ });
2201
+ });
2202
+ }
2203
+ _syncMirroredThemeContext() {
2204
+ const scopeTarget = this._optionsContainer;
2205
+ if (!scopeTarget)
2206
+ return;
2207
+ const darkSelectors = [
2208
+ '.dark-mode',
2209
+ '.dark',
2210
+ '[dark-mode]',
2211
+ '[darkmode]',
2212
+ '[data-theme="dark"]',
2213
+ '[theme="dark"]',
2214
+ ];
2215
+ const isDark = darkSelectors.some((selector) => this.matches(selector) || Boolean(this.closest(selector)))
2216
+ || document.documentElement.matches('.dark-mode, .dark, [dark-mode], [darkmode], [data-theme="dark"], [theme="dark"]')
2217
+ || Boolean(document.body?.matches('.dark-mode, .dark, [dark-mode], [darkmode], [data-theme="dark"], [theme="dark"]'));
2218
+ scopeTarget.classList.toggle('dark', isDark);
2219
+ scopeTarget.classList.toggle('dark-mode', isDark);
2220
+ if (isDark) {
2221
+ scopeTarget.setAttribute('dark-mode', '');
2222
+ scopeTarget.setAttribute('data-theme', 'dark');
2223
+ scopeTarget.setAttribute('theme', 'dark');
2224
+ }
2225
+ else {
2226
+ scopeTarget.removeAttribute('dark-mode');
2227
+ scopeTarget.removeAttribute('data-theme');
2228
+ scopeTarget.removeAttribute('theme');
2229
+ }
2230
+ }
2231
+ async _createScopedGlobalStyleNode(node, index) {
2232
+ if (node instanceof HTMLStyleElement) {
2233
+ return this._buildScopedStyleElement(node.textContent || '', String(index));
2234
+ }
2235
+ if (node instanceof HTMLLinkElement && node.href) {
2236
+ try {
2237
+ const response = await fetch(node.href, {
2238
+ credentials: node.crossOrigin === 'use-credentials' ? 'include' : 'same-origin',
2239
+ mode: 'cors',
2240
+ });
2241
+ if (!response.ok) {
2242
+ return null;
2243
+ }
2244
+ const cssText = await response.text();
2245
+ return this._buildScopedStyleElement(cssText, String(index));
2167
2246
  }
2168
- if (node instanceof HTMLLinkElement && node.href) {
2169
- const clonedLink = document.createElement('link');
2170
- clonedLink.rel = 'stylesheet';
2171
- clonedLink.href = node.href;
2172
- if (node.media)
2173
- clonedLink.media = node.media;
2174
- if (node.crossOrigin)
2175
- clonedLink.crossOrigin = node.crossOrigin;
2176
- if (node.referrerPolicy)
2177
- clonedLink.referrerPolicy = node.referrerPolicy;
2178
- if (node.integrity)
2179
- clonedLink.integrity = node.integrity;
2180
- if (node.type)
2181
- clonedLink.type = node.type;
2182
- if (node.nonce)
2183
- clonedLink.nonce = node.nonce;
2184
- clonedLink.setAttribute('data-smilodon-global-link', String(index));
2185
- container.appendChild(clonedLink);
2247
+ catch (_error) {
2248
+ return null;
2249
+ }
2250
+ }
2251
+ return null;
2252
+ }
2253
+ _buildScopedStyleElement(cssText, id) {
2254
+ const scopedCss = this._scopeMirroredCssText(cssText);
2255
+ if (!scopedCss.trim())
2256
+ return null;
2257
+ const style = document.createElement('style');
2258
+ style.setAttribute('data-smilodon-global-style', id);
2259
+ style.textContent = scopedCss;
2260
+ return style;
2261
+ }
2262
+ _scopeMirroredCssText(cssText) {
2263
+ if (!cssText.trim())
2264
+ return '';
2265
+ try {
2266
+ if (typeof CSSStyleSheet !== 'undefined') {
2267
+ const sheet = new CSSStyleSheet();
2268
+ sheet.replaceSync(cssText);
2269
+ return this._serializeScopedCssRules(Array.from(sheet.cssRules));
2270
+ }
2271
+ }
2272
+ catch (_error) {
2273
+ return '';
2274
+ }
2275
+ return '';
2276
+ }
2277
+ _serializeScopedCssRules(rules) {
2278
+ return rules.map((rule) => this._serializeScopedCssRule(rule)).filter(Boolean).join('\n');
2279
+ }
2280
+ _serializeScopedCssRule(rule) {
2281
+ if (rule instanceof CSSStyleRule) {
2282
+ const selectors = this._splitSelectorList(rule.selectorText)
2283
+ .map((selector) => this._scopeMirroredSelector(selector))
2284
+ .filter(Boolean);
2285
+ if (selectors.length === 0)
2286
+ return '';
2287
+ return `${selectors.join(', ')} { ${rule.style.cssText} }`;
2288
+ }
2289
+ if (rule instanceof CSSMediaRule) {
2290
+ const nested = this._serializeScopedCssRules(Array.from(rule.cssRules));
2291
+ return nested ? `@media ${rule.conditionText} { ${nested} }` : '';
2292
+ }
2293
+ if (typeof CSSSupportsRule !== 'undefined' && rule instanceof CSSSupportsRule) {
2294
+ const nested = this._serializeScopedCssRules(Array.from(rule.cssRules));
2295
+ return nested ? `@supports ${rule.conditionText} { ${nested} }` : '';
2296
+ }
2297
+ if (rule instanceof CSSFontFaceRule || rule instanceof CSSKeyframesRule) {
2298
+ return rule.cssText;
2299
+ }
2300
+ const nestedRule = rule;
2301
+ if (nestedRule.cssRules) {
2302
+ const nested = this._serializeScopedCssRules(Array.from(nestedRule.cssRules));
2303
+ if (!nested)
2304
+ return '';
2305
+ const ctorName = nestedRule.constructor?.name ?? '';
2306
+ if (ctorName.includes('Layer')) {
2307
+ return `@layer ${nestedRule.name ?? ''} { ${nested} }`;
2308
+ }
2309
+ if (ctorName.includes('Container')) {
2310
+ return `@container ${nestedRule.conditionText ?? ''} { ${nested} }`;
2311
+ }
2312
+ }
2313
+ return '';
2314
+ }
2315
+ _splitSelectorList(selectorText) {
2316
+ const selectors = [];
2317
+ let current = '';
2318
+ let depthRound = 0;
2319
+ let depthSquare = 0;
2320
+ for (const char of selectorText) {
2321
+ if (char === '(')
2322
+ depthRound += 1;
2323
+ if (char === ')')
2324
+ depthRound = Math.max(0, depthRound - 1);
2325
+ if (char === '[')
2326
+ depthSquare += 1;
2327
+ if (char === ']')
2328
+ depthSquare = Math.max(0, depthSquare - 1);
2329
+ if (char === ',' && depthRound === 0 && depthSquare === 0) {
2330
+ if (current.trim())
2331
+ selectors.push(current.trim());
2332
+ current = '';
2333
+ continue;
2334
+ }
2335
+ current += char;
2336
+ }
2337
+ if (current.trim())
2338
+ selectors.push(current.trim());
2339
+ return selectors;
2340
+ }
2341
+ _scopeMirroredSelector(selector) {
2342
+ const scopeClass = `.${EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS}`;
2343
+ let scopedSelector = selector
2344
+ .replace(/(^|\s|>|\+|~)(:root|html|body)(?=\b|\s|[.#[:>+~]|$)/g, `$1${scopeClass}`);
2345
+ const themePatterns = [
2346
+ /\.dark-mode(?![\w-]|\\:)/g,
2347
+ /\.dark(?![\w-]|\\:)/g,
2348
+ /\[dark-mode\]/g,
2349
+ /\[darkmode\]/g,
2350
+ /\[data-theme=(?:"dark"|'dark'|dark)\]/g,
2351
+ /\[theme=(?:"dark"|'dark'|dark)\]/g,
2352
+ ];
2353
+ let injectedThemeScope = false;
2354
+ themePatterns.forEach((pattern) => {
2355
+ scopedSelector = scopedSelector.replace(pattern, (match) => {
2356
+ injectedThemeScope = true;
2357
+ return `${match}${scopeClass}`;
2358
+ });
2359
+ });
2360
+ if (!scopedSelector.includes(EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS) && !injectedThemeScope) {
2361
+ scopedSelector = `${scopeClass} ${scopedSelector}`;
2362
+ }
2363
+ return scopedSelector;
2364
+ }
2365
+ _normalizeCustomOptionAccessibility(optionEl, meta) {
2366
+ if (!optionEl.hasAttribute('aria-label') && !optionEl.hasAttribute('aria-labelledby')) {
2367
+ optionEl.setAttribute('aria-label', meta.label);
2368
+ }
2369
+ const nestedFocusableSelectors = [
2370
+ 'a[href]',
2371
+ 'button',
2372
+ 'input',
2373
+ 'select',
2374
+ 'textarea',
2375
+ 'summary',
2376
+ '[tabindex]',
2377
+ '[contenteditable=""]',
2378
+ '[contenteditable="true"]',
2379
+ '[role="button"]',
2380
+ '[role="link"]',
2381
+ '[role="checkbox"]',
2382
+ '[role="switch"]',
2383
+ '[role="radio"]',
2384
+ '[role="textbox"]',
2385
+ ].join(', ');
2386
+ optionEl.querySelectorAll(nestedFocusableSelectors).forEach((child) => {
2387
+ if (child === optionEl)
2388
+ return;
2389
+ child.tabIndex = -1;
2390
+ if (!child.hasAttribute('data-smilodon-keep-role')) {
2391
+ child.setAttribute('role', 'presentation');
2392
+ }
2393
+ if ((meta.disabled || child.matches('button, input, select, textarea, summary, a[href]')) && !child.hasAttribute('data-smilodon-keep-aria')) {
2394
+ child.setAttribute('aria-hidden', 'true');
2186
2395
  }
2187
2396
  });
2188
2397
  }
@@ -2451,11 +2660,11 @@ class EnhancedSelect extends HTMLElement {
2451
2660
  this._inputContainer.removeAttribute('data-multi-scroll-mode');
2452
2661
  this._inputContainer.removeAttribute('data-drag-scroll');
2453
2662
  this._inputContainer.classList.remove('is-dragging-scroll');
2454
- this._inputContainer.style.removeProperty('--select-multi-input-max-height');
2455
- this._inputContainer.style.removeProperty('--select-multi-input-overflow-x');
2456
- this._inputContainer.style.removeProperty('--select-multi-input-overflow-y');
2457
- this._inputContainer.style.removeProperty('--select-multi-input-flex-wrap');
2458
- this._inputContainer.style.removeProperty('--select-multi-input-align-content');
2663
+ this._inputContainer.style.removeProperty('--select-multi-input-max-height-config');
2664
+ this._inputContainer.style.removeProperty('--select-multi-input-overflow-x-config');
2665
+ this._inputContainer.style.removeProperty('--select-multi-input-overflow-y-config');
2666
+ this._inputContainer.style.removeProperty('--select-multi-input-flex-wrap-config');
2667
+ this._inputContainer.style.removeProperty('--select-multi-input-align-content-config');
2459
2668
  return;
2460
2669
  }
2461
2670
  const maxHeight = this._config.multiSelectDisplay?.maxHeight ?? '160px';
@@ -2465,11 +2674,11 @@ class EnhancedSelect extends HTMLElement {
2465
2674
  const alignContent = mode === 'horizontal' ? 'center' : 'flex-start';
2466
2675
  this._inputContainer.setAttribute('data-multi-scroll-mode', mode);
2467
2676
  this._inputContainer.setAttribute('data-drag-scroll', String(dragEnabled && mode === 'horizontal'));
2468
- this._inputContainer.style.setProperty('--select-multi-input-max-height', maxHeight);
2469
- this._inputContainer.style.setProperty('--select-multi-input-overflow-x', overflowX);
2470
- this._inputContainer.style.setProperty('--select-multi-input-overflow-y', overflowY);
2471
- this._inputContainer.style.setProperty('--select-multi-input-flex-wrap', flexWrap);
2472
- this._inputContainer.style.setProperty('--select-multi-input-align-content', alignContent);
2677
+ this._inputContainer.style.setProperty('--select-multi-input-max-height-config', maxHeight);
2678
+ this._inputContainer.style.setProperty('--select-multi-input-overflow-x-config', overflowX);
2679
+ this._inputContainer.style.setProperty('--select-multi-input-overflow-y-config', overflowY);
2680
+ this._inputContainer.style.setProperty('--select-multi-input-flex-wrap-config', flexWrap);
2681
+ this._inputContainer.style.setProperty('--select-multi-input-align-content-config', alignContent);
2473
2682
  }
2474
2683
  _canUseHorizontalMultiScroll(target) {
2475
2684
  if (this._config.selection.mode !== 'multi')
@@ -2646,7 +2855,7 @@ class EnhancedSelect extends HTMLElement {
2646
2855
  }
2647
2856
  _createOptionsContainer() {
2648
2857
  const container = document.createElement('div');
2649
- container.className = 'options-container';
2858
+ container.className = `options-container ${EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS}`;
2650
2859
  return container;
2651
2860
  }
2652
2861
  _createLiveRegion() {
@@ -3097,14 +3306,14 @@ class EnhancedSelect extends HTMLElement {
3097
3306
  }
3098
3307
 
3099
3308
  .input-container.input-container--multi {
3100
- max-height: var(--select-multi-input-max-height, var(--select-input-max-height, 160px));
3309
+ max-height: var(--select-multi-input-max-height, var(--select-multi-input-max-height-config, var(--select-input-max-height, 160px)));
3101
3310
  }
3102
3311
 
3103
3312
  .input-container.input-container--multi .input-content {
3104
- flex-wrap: var(--select-multi-input-flex-wrap, wrap);
3105
- align-content: var(--select-multi-input-align-content, flex-start);
3106
- overflow-x: var(--select-multi-input-overflow-x, hidden);
3107
- overflow-y: var(--select-multi-input-overflow-y, auto);
3313
+ flex-wrap: var(--select-multi-input-flex-wrap, var(--select-multi-input-flex-wrap-config, wrap));
3314
+ align-content: var(--select-multi-input-align-content, var(--select-multi-input-align-content-config, flex-start));
3315
+ overflow-x: var(--select-multi-input-overflow-x, var(--select-multi-input-overflow-x-config, hidden));
3316
+ overflow-y: var(--select-multi-input-overflow-y, var(--select-multi-input-overflow-y-config, auto));
3108
3317
  }
3109
3318
 
3110
3319
  .input-container.input-container--multi::after {
@@ -3121,6 +3330,11 @@ class EnhancedSelect extends HTMLElement {
3121
3330
  cursor: var(--select-multi-input-horizontal-cursor, grab);
3122
3331
  overflow-y: hidden;
3123
3332
  overscroll-behavior-x: contain;
3333
+ padding-right: calc(var(--select-arrow-width, 42px) + var(--select-multi-horizontal-end-gap, 12px));
3334
+ }
3335
+
3336
+ .input-container.input-container--multi[data-multi-scroll-mode="horizontal"].has-clear-control .input-content {
3337
+ padding-right: calc(var(--select-arrow-width, 42px) + var(--select-clear-button-size, 26px) + var(--select-clear-button-right, 8px) + var(--select-multi-horizontal-end-gap, 12px));
3124
3338
  }
3125
3339
 
3126
3340
  .input-container.input-container--multi[data-multi-scroll-mode="horizontal"]::after {
@@ -3162,6 +3376,15 @@ class EnhancedSelect extends HTMLElement {
3162
3376
  left: var(--select-arrow-right-with-clear, 34px);
3163
3377
  }
3164
3378
 
3379
+ :host([dir="rtl"]) .input-container.input-container--multi[data-multi-scroll-mode="horizontal"] .input-content {
3380
+ padding-right: 0;
3381
+ padding-left: calc(var(--select-arrow-width, 42px) + var(--select-multi-horizontal-end-gap, 12px));
3382
+ }
3383
+
3384
+ :host([dir="rtl"]) .input-container.input-container--multi[data-multi-scroll-mode="horizontal"].has-clear-control .input-content {
3385
+ padding-left: calc(var(--select-arrow-width, 42px) + var(--select-clear-button-size, 26px) + var(--select-clear-button-right, 8px) + var(--select-multi-horizontal-end-gap, 12px));
3386
+ }
3387
+
3165
3388
  .input-container.input-container--multi[data-multi-scroll-mode="horizontal"] .clear-control-button {
3166
3389
  background: var(--select-multi-action-surface-bg, var(--select-input-bg, var(--select-surface)));
3167
3390
  z-index: 4;
@@ -3515,8 +3738,10 @@ class EnhancedSelect extends HTMLElement {
3515
3738
  }
3516
3739
 
3517
3740
  .group-header:not(:first-child) {
3518
- margin-top: var(--select-group-header-separator-margin-top);
3519
- padding-top: var(--select-group-header-separator-padding-top);
3741
+ margin-top: calc(
3742
+ var(--select-group-header-separator-margin-top, 0px) +
3743
+ var(--select-group-header-separator-padding-top, 0px)
3744
+ );
3520
3745
  border-top: var(--select-group-header-separator-border-top);
3521
3746
  }
3522
3747
 
@@ -3598,7 +3823,7 @@ class EnhancedSelect extends HTMLElement {
3598
3823
  color: var(--select-option-selected-hover-color, var(--select-option-selected-color, var(--select-accent)));
3599
3824
  }
3600
3825
 
3601
- .option.active:not(.selected) {
3826
+ .option.active:not(.selected):not(.disabled) {
3602
3827
  background: var(--select-option-active-bg, var(--select-surface-elevated));
3603
3828
  color: var(--select-option-active-color, var(--select-option-hover-color, var(--select-option-color, var(--select-text))));
3604
3829
  border: var(--select-option-active-border, var(--select-option-hover-border, var(--select-option-border, none)));
@@ -3608,7 +3833,7 @@ class EnhancedSelect extends HTMLElement {
3608
3833
  transform: var(--select-option-active-transform, none);
3609
3834
  }
3610
3835
 
3611
- .option.selected.active {
3836
+ .option.selected.active:not(.disabled) {
3612
3837
  outline: var(--select-option-selected-active-outline, 2px solid rgba(15, 52, 96, 0.4));
3613
3838
  outline-offset: var(--select-option-selected-active-outline-offset);
3614
3839
  }
@@ -3826,6 +4051,9 @@ class EnhancedSelect extends HTMLElement {
3826
4051
 
3827
4052
  --select-badge-bg: var(--select-dark-badge-bg, rgba(99, 102, 241, 0.2));
3828
4053
  --select-badge-color: var(--select-dark-badge-color, #e0e7ff);
4054
+ --select-badge-border: var(--select-dark-badge-border, var(--select-badge-border, none));
4055
+ --select-badge-hover-border: var(--select-dark-badge-hover-border, var(--select-badge-hover-border, var(--select-badge-border, none)));
4056
+ --select-badge-active-border: var(--select-dark-badge-active-border, var(--select-badge-active-border, var(--select-badge-hover-border, var(--select-badge-border, none))));
3829
4057
 
3830
4058
  --select-group-header-bg: var(--select-group-header-dark-bg, #1a1a2e);
3831
4059
  --select-group-header-color: var(--select-group-header-dark-color, #9ca3af);
@@ -3861,6 +4089,36 @@ class EnhancedSelect extends HTMLElement {
3861
4089
  border-color: var(--select-border);
3862
4090
  }
3863
4091
 
4092
+ :host(.dark-mode) .input-container:hover,
4093
+ :host([dark-mode]) .input-container:hover,
4094
+ :host([darkmode]) .input-container:hover,
4095
+ :host([data-theme="dark"]) .input-container:hover,
4096
+ :host([theme="dark"]) .input-container:hover,
4097
+ :host-context(.dark-mode) .input-container:hover,
4098
+ :host-context(.dark) .input-container:hover,
4099
+ :host-context([dark-mode]) .input-container:hover,
4100
+ :host-context([darkmode]) .input-container:hover,
4101
+ :host-context([data-theme="dark"]) .input-container:hover,
4102
+ :host-context([theme="dark"]) .input-container:hover {
4103
+ border-color: var(--select-dark-input-hover-border, var(--select-input-hover-border, var(--select-dark-border-focus, var(--select-border-focus, #6366f1))));
4104
+ box-shadow: var(--select-dark-input-hover-shadow, var(--select-input-hover-shadow, var(--select-shadow-sm), 0 0 0 1px rgba(99, 102, 241, 0.12)));
4105
+ }
4106
+
4107
+ :host(.dark-mode) .input-container:focus-within,
4108
+ :host([dark-mode]) .input-container:focus-within,
4109
+ :host([darkmode]) .input-container:focus-within,
4110
+ :host([data-theme="dark"]) .input-container:focus-within,
4111
+ :host([theme="dark"]) .input-container:focus-within,
4112
+ :host-context(.dark-mode) .input-container:focus-within,
4113
+ :host-context(.dark) .input-container:focus-within,
4114
+ :host-context([dark-mode]) .input-container:focus-within,
4115
+ :host-context([darkmode]) .input-container:focus-within,
4116
+ :host-context([data-theme="dark"]) .input-container:focus-within,
4117
+ :host-context([theme="dark"]) .input-container:focus-within {
4118
+ border-color: var(--select-dark-border-focus, var(--select-border-focus, #6366f1));
4119
+ box-shadow: var(--select-dark-shadow-focus, var(--select-shadow-focus, 0 0 0 3px rgba(99, 102, 241, 0.25))), var(--select-shadow-sm);
4120
+ }
4121
+
3864
4122
  :host(.dark-mode) .input-container::after,
3865
4123
  :host([dark-mode]) .input-container::after,
3866
4124
  :host([darkmode]) .input-container::after,
@@ -3916,7 +4174,8 @@ class EnhancedSelect extends HTMLElement {
3916
4174
  :host-context([darkmode]) .selection-badge,
3917
4175
  :host-context([data-theme="dark"]) .selection-badge,
3918
4176
  :host-context([theme="dark"]) .selection-badge {
3919
- background: var(--select-badge-dark-bg);
4177
+ background: var(--select-dark-badge-bg, var(--select-badge-bg, var(--select-badge-dark-bg)));
4178
+ color: var(--select-dark-badge-color, var(--select-badge-color, #e0e7ff));
3920
4179
  }
3921
4180
 
3922
4181
  :host(.dark-mode) .group-header:not(:first-child),
@@ -4097,6 +4356,10 @@ class EnhancedSelect extends HTMLElement {
4097
4356
  this._inputContent.addEventListener('wheel', (e) => {
4098
4357
  if (this._config.selection.mode === 'multi'
4099
4358
  && (this._config.multiSelectDisplay?.mode ?? 'wrap') === 'horizontal') {
4359
+ const primaryDelta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
4360
+ if (primaryDelta !== 0) {
4361
+ this._inputContent.scrollLeft += primaryDelta;
4362
+ }
4100
4363
  e.preventDefault();
4101
4364
  }
4102
4365
  }, { passive: false });
@@ -4491,6 +4754,8 @@ class EnhancedSelect extends HTMLElement {
4491
4754
  }
4492
4755
  }
4493
4756
  _handleKeydown(e) {
4757
+ if (!this._config.enabled)
4758
+ return;
4494
4759
  switch (e.key) {
4495
4760
  case 'ArrowDown':
4496
4761
  e.preventDefault();
@@ -4513,17 +4778,23 @@ class EnhancedSelect extends HTMLElement {
4513
4778
  case 'Home':
4514
4779
  e.preventDefault();
4515
4780
  if (this._state.isOpen) {
4516
- this._setActive(0);
4781
+ const selectableIndices = this._getSelectableOptionIndices();
4782
+ const firstIndex = selectableIndices[0];
4783
+ if (firstIndex === undefined)
4784
+ break;
4785
+ this._setActive(firstIndex);
4517
4786
  if (this._config.selection.mode === 'multi' && e.shiftKey) {
4518
- this._selectRange(this._rangeAnchorIndex ?? 0, 0, { clear: !(e.ctrlKey || e.metaKey) });
4787
+ this._selectRange(this._rangeAnchorIndex ?? firstIndex, firstIndex, { clear: !(e.ctrlKey || e.metaKey) });
4519
4788
  }
4520
4789
  }
4521
4790
  break;
4522
4791
  case 'End':
4523
4792
  e.preventDefault();
4524
4793
  if (this._state.isOpen) {
4525
- const options = this._getSelectableOptions();
4526
- const lastIndex = Math.max(0, options.length - 1);
4794
+ const selectableIndices = this._getSelectableOptionIndices();
4795
+ const lastIndex = selectableIndices[selectableIndices.length - 1];
4796
+ if (lastIndex === undefined)
4797
+ break;
4527
4798
  this._setActive(lastIndex);
4528
4799
  if (this._config.selection.mode === 'multi' && e.shiftKey) {
4529
4800
  this._selectRange(this._rangeAnchorIndex ?? lastIndex, lastIndex, { clear: !(e.ctrlKey || e.metaKey) });
@@ -4577,8 +4848,17 @@ class EnhancedSelect extends HTMLElement {
4577
4848
  }
4578
4849
  }
4579
4850
  _moveActive(delta, opts) {
4580
- const options = this._getSelectableOptions();
4581
- const next = Math.max(0, Math.min(options.length - 1, this._state.activeIndex + delta));
4851
+ const selectableIndices = this._getSelectableOptionIndices();
4852
+ if (selectableIndices.length === 0)
4853
+ return;
4854
+ const currentPosition = selectableIndices.indexOf(this._state.activeIndex);
4855
+ const basePosition = currentPosition >= 0
4856
+ ? currentPosition
4857
+ : delta >= 0
4858
+ ? -1
4859
+ : selectableIndices.length;
4860
+ const nextPosition = Math.max(0, Math.min(selectableIndices.length - 1, basePosition + delta));
4861
+ const next = selectableIndices[nextPosition];
4582
4862
  this._setActive(next);
4583
4863
  if (this._config.selection.mode === 'multi' && opts?.shiftKey) {
4584
4864
  const anchor = this._rangeAnchorIndex ?? this._state.activeIndex;
@@ -4590,6 +4870,10 @@ class EnhancedSelect extends HTMLElement {
4590
4870
  }
4591
4871
  }
4592
4872
  _setActive(index) {
4873
+ const option = this._getOptionElementByIndex(index);
4874
+ if (!option || option.getAttribute('aria-disabled') === 'true') {
4875
+ return;
4876
+ }
4593
4877
  // Clear previous active state
4594
4878
  if (this._state.activeIndex >= 0) {
4595
4879
  const prevOption = this._getOptionElementByIndex(this._state.activeIndex);
@@ -4606,7 +4890,6 @@ class EnhancedSelect extends HTMLElement {
4606
4890
  }
4607
4891
  this._state.activeIndex = index;
4608
4892
  // Set new active state
4609
- const option = this._getOptionElementByIndex(index);
4610
4893
  if (option) {
4611
4894
  // Check if it's a custom SelectOption or a lightweight DOM element
4612
4895
  if ('setActive' in option && typeof option.setActive === 'function') {
@@ -4635,9 +4918,15 @@ class EnhancedSelect extends HTMLElement {
4635
4918
  // Filter out group headers and other non-selectable elements
4636
4919
  // Only return elements with data-index or data-sm-selectable attributes
4637
4920
  return Array.from(this._optionsContainer.children).filter((child) => {
4638
- return child.hasAttribute('data-index') || child.hasAttribute('data-sm-selectable');
4921
+ return (child.hasAttribute('data-index') || child.hasAttribute('data-sm-selectable'))
4922
+ && child.getAttribute('aria-disabled') !== 'true';
4639
4923
  });
4640
4924
  }
4925
+ _getSelectableOptionIndices() {
4926
+ return this._getSelectableOptions()
4927
+ .map((option) => Number(option.getAttribute('data-sm-index') ?? option.getAttribute('data-index')))
4928
+ .filter((index) => Number.isFinite(index));
4929
+ }
4641
4930
  _buildRendererHelpers() {
4642
4931
  return {
4643
4932
  onSelect: (_item, index) => this._selectOption(index),
@@ -4674,24 +4963,27 @@ class EnhancedSelect extends HTMLElement {
4674
4963
  return;
4675
4964
  const options = this._getSelectableOptions();
4676
4965
  const maxSelections = this._config.selection.maxSelections || 0;
4677
- options.forEach((option, index) => {
4966
+ options.forEach((option) => {
4967
+ const optionIndex = Number(option.getAttribute('data-sm-index') ?? option.getAttribute('data-index'));
4968
+ if (!Number.isFinite(optionIndex))
4969
+ return;
4678
4970
  if (maxSelections > 0 && this._state.selectedIndices.size >= maxSelections) {
4679
4971
  return;
4680
4972
  }
4681
- if (!this._state.selectedIndices.has(index)) {
4973
+ if (!this._state.selectedIndices.has(optionIndex)) {
4682
4974
  // Check if it's a custom SelectOption or a lightweight DOM element
4683
4975
  if ('getConfig' in option && typeof option.getConfig === 'function') {
4684
4976
  const config = option.getConfig();
4685
- this._state.selectedIndices.add(index);
4686
- this._state.selectedItems.set(index, config.item);
4977
+ this._state.selectedIndices.add(optionIndex);
4978
+ this._state.selectedItems.set(optionIndex, config.item);
4687
4979
  option.setSelected(true);
4688
4980
  }
4689
4981
  else {
4690
4982
  // Lightweight option - get item from data attribute or state
4691
- const item = this._state.loadedItems[index];
4983
+ const item = this._state.loadedItems[optionIndex];
4692
4984
  if (item) {
4693
- this._state.selectedIndices.add(index);
4694
- this._state.selectedItems.set(index, item);
4985
+ this._state.selectedIndices.add(optionIndex);
4986
+ this._state.selectedItems.set(optionIndex, item);
4695
4987
  option.classList.add('smilodon-option--selected');
4696
4988
  option.setAttribute('aria-selected', 'true');
4697
4989
  }
@@ -4715,6 +5007,9 @@ class EnhancedSelect extends HTMLElement {
4715
5007
  if (maxSelections > 0 && this._state.selectedIndices.size >= maxSelections)
4716
5008
  break;
4717
5009
  const item = this._state.loadedItems[i];
5010
+ const optionEl = this._getOptionElementByIndex(i);
5011
+ if (optionEl?.getAttribute('aria-disabled') === 'true')
5012
+ continue;
4718
5013
  if (!item)
4719
5014
  continue;
4720
5015
  this._state.selectedIndices.add(i);
@@ -4726,8 +5021,8 @@ class EnhancedSelect extends HTMLElement {
4726
5021
  this._announce(`${this._state.selectedIndices.size} items selected`);
4727
5022
  }
4728
5023
  _setInitialActiveOption() {
4729
- const options = this._getSelectableOptions();
4730
- if (options.length === 0)
5024
+ const selectableIndices = this._getSelectableOptionIndices();
5025
+ if (selectableIndices.length === 0)
4731
5026
  return;
4732
5027
  const selected = Array.from(this._state.selectedIndices).sort((a, b) => a - b);
4733
5028
  if (this._config.selection.mode === 'multi' && selected.length === 0) {
@@ -4735,8 +5030,8 @@ class EnhancedSelect extends HTMLElement {
4735
5030
  this._input.removeAttribute('aria-activedescendant');
4736
5031
  return;
4737
5032
  }
4738
- const target = selected.length > 0 ? selected[0] : 0;
4739
- this._setActive(Math.min(target, options.length - 1));
5033
+ const target = selected.find((index) => selectableIndices.includes(index)) ?? selectableIndices[0];
5034
+ this._setActive(target);
4740
5035
  }
4741
5036
  _announce(message) {
4742
5037
  if (this._liveRegion) {
@@ -5569,6 +5864,9 @@ class EnhancedSelect extends HTMLElement {
5569
5864
  if (this._config.styles.classNames?.groupHeader) {
5570
5865
  header.classList.add(...this._config.styles.classNames.groupHeader.split(' ').filter(Boolean));
5571
5866
  }
5867
+ if (!header.hasAttribute('role')) {
5868
+ header.setAttribute('role', 'presentation');
5869
+ }
5572
5870
  header.setAttribute('part', 'group-header');
5573
5871
  this._optionsContainer.appendChild(header);
5574
5872
  group.options.forEach(item => {
@@ -5844,9 +6142,6 @@ class EnhancedSelect extends HTMLElement {
5844
6142
  if (!optionEl.getAttribute('role')) {
5845
6143
  optionEl.setAttribute('role', 'option');
5846
6144
  }
5847
- if (!optionEl.getAttribute('aria-label')) {
5848
- optionEl.setAttribute('aria-label', meta.label);
5849
- }
5850
6145
  optionEl.setAttribute('aria-selected', String(meta.selected));
5851
6146
  if (meta.disabled) {
5852
6147
  optionEl.setAttribute('aria-disabled', 'true');
@@ -5863,6 +6158,10 @@ class EnhancedSelect extends HTMLElement {
5863
6158
  // Re-attaching here causes the double-click toggle bug if a child component fails to stopPropagation.
5864
6159
  this._customOptionBoundElements.add(optionEl);
5865
6160
  }
6161
+ this._normalizeCustomOptionAccessibility(optionEl, {
6162
+ label: meta.label,
6163
+ disabled: meta.disabled,
6164
+ });
5866
6165
  return optionEl;
5867
6166
  }
5868
6167
  _addLoadMoreTrigger() {
@@ -5897,6 +6196,7 @@ class EnhancedSelect extends HTMLElement {
5897
6196
  }
5898
6197
  /** live set of all connected instances; used to auto-close siblings */
5899
6198
  EnhancedSelect._instances = new Set();
6199
+ EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS = 'smilodon-mirrored-styles-scope';
5900
6200
  // Register custom element
5901
6201
  if (!customElements.get('enhanced-select')) {
5902
6202
  customElements.define('enhanced-select', EnhancedSelect);