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