@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.umd.js CHANGED
@@ -1604,7 +1604,7 @@
1604
1604
  transform: var(--select-option-selected-hover-transform, var(--select-option-selected-transform, var(--select-option-transform, none)));
1605
1605
  }
1606
1606
 
1607
- .option-container.active {
1607
+ .option-container.active:not(.disabled) {
1608
1608
  background: var(--select-option-active-bg, var(--select-option-hover-bg, #f0f0f0));
1609
1609
  color: var(--select-option-active-color, var(--select-option-hover-color, var(--select-option-color, var(--select-text-color, #1f2937))));
1610
1610
  border: var(--select-option-active-border, var(--select-option-hover-border, var(--select-option-border, none)));
@@ -1732,7 +1732,7 @@
1732
1732
  toggleClasses(this._container, [...selectedClasses, 'smilodon-option--selected'], false);
1733
1733
  toggleClasses(this, [...selectedClasses, 'smilodon-option--selected'], false);
1734
1734
  }
1735
- if (active) {
1735
+ if (active && !disabled) {
1736
1736
  toggleClasses(this._container, [...activeClasses, 'smilodon-option--active'], true);
1737
1737
  toggleClasses(this, [...activeClasses, 'smilodon-option--active'], true); // Make focus ring visible on host
1738
1738
  }
@@ -1800,8 +1800,12 @@
1800
1800
  // Set ARIA attributes and State attributes on Host
1801
1801
  this.setAttribute('role', 'option');
1802
1802
  this.setAttribute('aria-selected', String(selected));
1803
- if (disabled)
1803
+ if (disabled) {
1804
1804
  this.setAttribute('aria-disabled', 'true');
1805
+ }
1806
+ else {
1807
+ this.removeAttribute('aria-disabled');
1808
+ }
1805
1809
  this.id = this._config.id || `select-option-${index}`;
1806
1810
  // Add checkmark (part="checkmark") - standard for object mode
1807
1811
  // Only show if NOT showing remove button (avoid clutter)
@@ -1820,7 +1824,7 @@
1820
1824
  const state = [];
1821
1825
  if (selected)
1822
1826
  state.push('selected');
1823
- if (active)
1827
+ if (active && !disabled)
1824
1828
  state.push('active');
1825
1829
  if (state.length) {
1826
1830
  this.dataset.smState = state.join(' ');
@@ -1944,7 +1948,7 @@
1944
1948
  * Set active state
1945
1949
  */
1946
1950
  setActive(active) {
1947
- this._config.active = active;
1951
+ this._config.active = active && !this._config.disabled;
1948
1952
  this._render();
1949
1953
  }
1950
1954
  /**
@@ -2012,6 +2016,8 @@
2012
2016
  this._mirrorGlobalStylesForCustomOptions = false;
2013
2017
  this._globalStylesObserver = null;
2014
2018
  this._globalStylesContainer = null;
2019
+ this._themeContextObserver = null;
2020
+ this._globalStylesSyncToken = 0;
2015
2021
  this._tracking = { events: [], styles: [], limitations: [] };
2016
2022
  this._suppressBlurClose = false;
2017
2023
  this._renderCycleId = 0;
@@ -2127,6 +2133,7 @@
2127
2133
  return;
2128
2134
  if (!this._mirrorGlobalStylesForCustomOptions)
2129
2135
  return;
2136
+ this._setupThemeContextMirroring();
2130
2137
  this._mirrorDocumentStylesIntoShadow();
2131
2138
  if (this._globalStylesObserver)
2132
2139
  return;
@@ -2145,6 +2152,10 @@
2145
2152
  this._globalStylesObserver.disconnect();
2146
2153
  this._globalStylesObserver = null;
2147
2154
  }
2155
+ if (this._themeContextObserver) {
2156
+ this._themeContextObserver.disconnect();
2157
+ this._themeContextObserver = null;
2158
+ }
2148
2159
  if (this._globalStylesContainer) {
2149
2160
  this._globalStylesContainer.remove();
2150
2161
  this._globalStylesContainer = null;
@@ -2161,34 +2172,232 @@
2161
2172
  this._shadow.appendChild(this._globalStylesContainer);
2162
2173
  }
2163
2174
  const container = this._globalStylesContainer;
2164
- container.innerHTML = '';
2175
+ const syncToken = ++this._globalStylesSyncToken;
2165
2176
  const styleNodes = Array.from(document.querySelectorAll('style,link[rel="stylesheet"]'));
2166
- styleNodes.forEach((node, index) => {
2167
- if (node instanceof HTMLStyleElement) {
2168
- const clonedStyle = document.createElement('style');
2169
- clonedStyle.setAttribute('data-smilodon-global-style', String(index));
2170
- clonedStyle.textContent = node.textContent || '';
2171
- container.appendChild(clonedStyle);
2177
+ void Promise.all(styleNodes.map((node, index) => this._createScopedGlobalStyleNode(node, index))).then((mirroredNodes) => {
2178
+ if (!this._globalStylesContainer || syncToken !== this._globalStylesSyncToken)
2172
2179
  return;
2180
+ container.replaceChildren(...mirroredNodes.filter((node) => Boolean(node)));
2181
+ this._syncMirroredThemeContext();
2182
+ });
2183
+ }
2184
+ _setupThemeContextMirroring() {
2185
+ if (typeof document === 'undefined')
2186
+ return;
2187
+ this._syncMirroredThemeContext();
2188
+ if (this._themeContextObserver)
2189
+ return;
2190
+ this._themeContextObserver = new MutationObserver(() => {
2191
+ this._syncMirroredThemeContext();
2192
+ });
2193
+ const targets = new Set([this, document.documentElement]);
2194
+ if (document.body) {
2195
+ targets.add(document.body);
2196
+ }
2197
+ let ancestor = this.parentElement;
2198
+ while (ancestor) {
2199
+ targets.add(ancestor);
2200
+ ancestor = ancestor.parentElement;
2201
+ }
2202
+ targets.forEach((target) => {
2203
+ this._themeContextObserver?.observe(target, {
2204
+ attributes: true,
2205
+ attributeFilter: ['class', 'dark-mode', 'darkmode', 'data-theme', 'theme'],
2206
+ });
2207
+ });
2208
+ }
2209
+ _syncMirroredThemeContext() {
2210
+ const scopeTarget = this._optionsContainer;
2211
+ if (!scopeTarget)
2212
+ return;
2213
+ const darkSelectors = [
2214
+ '.dark-mode',
2215
+ '.dark',
2216
+ '[dark-mode]',
2217
+ '[darkmode]',
2218
+ '[data-theme="dark"]',
2219
+ '[theme="dark"]',
2220
+ ];
2221
+ const isDark = darkSelectors.some((selector) => this.matches(selector) || Boolean(this.closest(selector)))
2222
+ || document.documentElement.matches('.dark-mode, .dark, [dark-mode], [darkmode], [data-theme="dark"], [theme="dark"]')
2223
+ || Boolean(document.body?.matches('.dark-mode, .dark, [dark-mode], [darkmode], [data-theme="dark"], [theme="dark"]'));
2224
+ scopeTarget.classList.toggle('dark', isDark);
2225
+ scopeTarget.classList.toggle('dark-mode', isDark);
2226
+ if (isDark) {
2227
+ scopeTarget.setAttribute('dark-mode', '');
2228
+ scopeTarget.setAttribute('data-theme', 'dark');
2229
+ scopeTarget.setAttribute('theme', 'dark');
2230
+ }
2231
+ else {
2232
+ scopeTarget.removeAttribute('dark-mode');
2233
+ scopeTarget.removeAttribute('data-theme');
2234
+ scopeTarget.removeAttribute('theme');
2235
+ }
2236
+ }
2237
+ async _createScopedGlobalStyleNode(node, index) {
2238
+ if (node instanceof HTMLStyleElement) {
2239
+ return this._buildScopedStyleElement(node.textContent || '', String(index));
2240
+ }
2241
+ if (node instanceof HTMLLinkElement && node.href) {
2242
+ try {
2243
+ const response = await fetch(node.href, {
2244
+ credentials: node.crossOrigin === 'use-credentials' ? 'include' : 'same-origin',
2245
+ mode: 'cors',
2246
+ });
2247
+ if (!response.ok) {
2248
+ return null;
2249
+ }
2250
+ const cssText = await response.text();
2251
+ return this._buildScopedStyleElement(cssText, String(index));
2173
2252
  }
2174
- if (node instanceof HTMLLinkElement && node.href) {
2175
- const clonedLink = document.createElement('link');
2176
- clonedLink.rel = 'stylesheet';
2177
- clonedLink.href = node.href;
2178
- if (node.media)
2179
- clonedLink.media = node.media;
2180
- if (node.crossOrigin)
2181
- clonedLink.crossOrigin = node.crossOrigin;
2182
- if (node.referrerPolicy)
2183
- clonedLink.referrerPolicy = node.referrerPolicy;
2184
- if (node.integrity)
2185
- clonedLink.integrity = node.integrity;
2186
- if (node.type)
2187
- clonedLink.type = node.type;
2188
- if (node.nonce)
2189
- clonedLink.nonce = node.nonce;
2190
- clonedLink.setAttribute('data-smilodon-global-link', String(index));
2191
- container.appendChild(clonedLink);
2253
+ catch (_error) {
2254
+ return null;
2255
+ }
2256
+ }
2257
+ return null;
2258
+ }
2259
+ _buildScopedStyleElement(cssText, id) {
2260
+ const scopedCss = this._scopeMirroredCssText(cssText);
2261
+ if (!scopedCss.trim())
2262
+ return null;
2263
+ const style = document.createElement('style');
2264
+ style.setAttribute('data-smilodon-global-style', id);
2265
+ style.textContent = scopedCss;
2266
+ return style;
2267
+ }
2268
+ _scopeMirroredCssText(cssText) {
2269
+ if (!cssText.trim())
2270
+ return '';
2271
+ try {
2272
+ if (typeof CSSStyleSheet !== 'undefined') {
2273
+ const sheet = new CSSStyleSheet();
2274
+ sheet.replaceSync(cssText);
2275
+ return this._serializeScopedCssRules(Array.from(sheet.cssRules));
2276
+ }
2277
+ }
2278
+ catch (_error) {
2279
+ return '';
2280
+ }
2281
+ return '';
2282
+ }
2283
+ _serializeScopedCssRules(rules) {
2284
+ return rules.map((rule) => this._serializeScopedCssRule(rule)).filter(Boolean).join('\n');
2285
+ }
2286
+ _serializeScopedCssRule(rule) {
2287
+ if (rule instanceof CSSStyleRule) {
2288
+ const selectors = this._splitSelectorList(rule.selectorText)
2289
+ .map((selector) => this._scopeMirroredSelector(selector))
2290
+ .filter(Boolean);
2291
+ if (selectors.length === 0)
2292
+ return '';
2293
+ return `${selectors.join(', ')} { ${rule.style.cssText} }`;
2294
+ }
2295
+ if (rule instanceof CSSMediaRule) {
2296
+ const nested = this._serializeScopedCssRules(Array.from(rule.cssRules));
2297
+ return nested ? `@media ${rule.conditionText} { ${nested} }` : '';
2298
+ }
2299
+ if (typeof CSSSupportsRule !== 'undefined' && rule instanceof CSSSupportsRule) {
2300
+ const nested = this._serializeScopedCssRules(Array.from(rule.cssRules));
2301
+ return nested ? `@supports ${rule.conditionText} { ${nested} }` : '';
2302
+ }
2303
+ if (rule instanceof CSSFontFaceRule || rule instanceof CSSKeyframesRule) {
2304
+ return rule.cssText;
2305
+ }
2306
+ const nestedRule = rule;
2307
+ if (nestedRule.cssRules) {
2308
+ const nested = this._serializeScopedCssRules(Array.from(nestedRule.cssRules));
2309
+ if (!nested)
2310
+ return '';
2311
+ const ctorName = nestedRule.constructor?.name ?? '';
2312
+ if (ctorName.includes('Layer')) {
2313
+ return `@layer ${nestedRule.name ?? ''} { ${nested} }`;
2314
+ }
2315
+ if (ctorName.includes('Container')) {
2316
+ return `@container ${nestedRule.conditionText ?? ''} { ${nested} }`;
2317
+ }
2318
+ }
2319
+ return '';
2320
+ }
2321
+ _splitSelectorList(selectorText) {
2322
+ const selectors = [];
2323
+ let current = '';
2324
+ let depthRound = 0;
2325
+ let depthSquare = 0;
2326
+ for (const char of selectorText) {
2327
+ if (char === '(')
2328
+ depthRound += 1;
2329
+ if (char === ')')
2330
+ depthRound = Math.max(0, depthRound - 1);
2331
+ if (char === '[')
2332
+ depthSquare += 1;
2333
+ if (char === ']')
2334
+ depthSquare = Math.max(0, depthSquare - 1);
2335
+ if (char === ',' && depthRound === 0 && depthSquare === 0) {
2336
+ if (current.trim())
2337
+ selectors.push(current.trim());
2338
+ current = '';
2339
+ continue;
2340
+ }
2341
+ current += char;
2342
+ }
2343
+ if (current.trim())
2344
+ selectors.push(current.trim());
2345
+ return selectors;
2346
+ }
2347
+ _scopeMirroredSelector(selector) {
2348
+ const scopeClass = `.${EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS}`;
2349
+ let scopedSelector = selector
2350
+ .replace(/(^|\s|>|\+|~)(:root|html|body)(?=\b|\s|[.#[:>+~]|$)/g, `$1${scopeClass}`);
2351
+ const themePatterns = [
2352
+ /\.dark-mode(?![\w-]|\\:)/g,
2353
+ /\.dark(?![\w-]|\\:)/g,
2354
+ /\[dark-mode\]/g,
2355
+ /\[darkmode\]/g,
2356
+ /\[data-theme=(?:"dark"|'dark'|dark)\]/g,
2357
+ /\[theme=(?:"dark"|'dark'|dark)\]/g,
2358
+ ];
2359
+ let injectedThemeScope = false;
2360
+ themePatterns.forEach((pattern) => {
2361
+ scopedSelector = scopedSelector.replace(pattern, (match) => {
2362
+ injectedThemeScope = true;
2363
+ return `${match}${scopeClass}`;
2364
+ });
2365
+ });
2366
+ if (!scopedSelector.includes(EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS) && !injectedThemeScope) {
2367
+ scopedSelector = `${scopeClass} ${scopedSelector}`;
2368
+ }
2369
+ return scopedSelector;
2370
+ }
2371
+ _normalizeCustomOptionAccessibility(optionEl, meta) {
2372
+ if (!optionEl.hasAttribute('aria-label') && !optionEl.hasAttribute('aria-labelledby')) {
2373
+ optionEl.setAttribute('aria-label', meta.label);
2374
+ }
2375
+ const nestedFocusableSelectors = [
2376
+ 'a[href]',
2377
+ 'button',
2378
+ 'input',
2379
+ 'select',
2380
+ 'textarea',
2381
+ 'summary',
2382
+ '[tabindex]',
2383
+ '[contenteditable=""]',
2384
+ '[contenteditable="true"]',
2385
+ '[role="button"]',
2386
+ '[role="link"]',
2387
+ '[role="checkbox"]',
2388
+ '[role="switch"]',
2389
+ '[role="radio"]',
2390
+ '[role="textbox"]',
2391
+ ].join(', ');
2392
+ optionEl.querySelectorAll(nestedFocusableSelectors).forEach((child) => {
2393
+ if (child === optionEl)
2394
+ return;
2395
+ child.tabIndex = -1;
2396
+ if (!child.hasAttribute('data-smilodon-keep-role')) {
2397
+ child.setAttribute('role', 'presentation');
2398
+ }
2399
+ if ((meta.disabled || child.matches('button, input, select, textarea, summary, a[href]')) && !child.hasAttribute('data-smilodon-keep-aria')) {
2400
+ child.setAttribute('aria-hidden', 'true');
2192
2401
  }
2193
2402
  });
2194
2403
  }
@@ -2457,11 +2666,11 @@
2457
2666
  this._inputContainer.removeAttribute('data-multi-scroll-mode');
2458
2667
  this._inputContainer.removeAttribute('data-drag-scroll');
2459
2668
  this._inputContainer.classList.remove('is-dragging-scroll');
2460
- this._inputContainer.style.removeProperty('--select-multi-input-max-height');
2461
- this._inputContainer.style.removeProperty('--select-multi-input-overflow-x');
2462
- this._inputContainer.style.removeProperty('--select-multi-input-overflow-y');
2463
- this._inputContainer.style.removeProperty('--select-multi-input-flex-wrap');
2464
- this._inputContainer.style.removeProperty('--select-multi-input-align-content');
2669
+ this._inputContainer.style.removeProperty('--select-multi-input-max-height-config');
2670
+ this._inputContainer.style.removeProperty('--select-multi-input-overflow-x-config');
2671
+ this._inputContainer.style.removeProperty('--select-multi-input-overflow-y-config');
2672
+ this._inputContainer.style.removeProperty('--select-multi-input-flex-wrap-config');
2673
+ this._inputContainer.style.removeProperty('--select-multi-input-align-content-config');
2465
2674
  return;
2466
2675
  }
2467
2676
  const maxHeight = this._config.multiSelectDisplay?.maxHeight ?? '160px';
@@ -2471,11 +2680,11 @@
2471
2680
  const alignContent = mode === 'horizontal' ? 'center' : 'flex-start';
2472
2681
  this._inputContainer.setAttribute('data-multi-scroll-mode', mode);
2473
2682
  this._inputContainer.setAttribute('data-drag-scroll', String(dragEnabled && mode === 'horizontal'));
2474
- this._inputContainer.style.setProperty('--select-multi-input-max-height', maxHeight);
2475
- this._inputContainer.style.setProperty('--select-multi-input-overflow-x', overflowX);
2476
- this._inputContainer.style.setProperty('--select-multi-input-overflow-y', overflowY);
2477
- this._inputContainer.style.setProperty('--select-multi-input-flex-wrap', flexWrap);
2478
- this._inputContainer.style.setProperty('--select-multi-input-align-content', alignContent);
2683
+ this._inputContainer.style.setProperty('--select-multi-input-max-height-config', maxHeight);
2684
+ this._inputContainer.style.setProperty('--select-multi-input-overflow-x-config', overflowX);
2685
+ this._inputContainer.style.setProperty('--select-multi-input-overflow-y-config', overflowY);
2686
+ this._inputContainer.style.setProperty('--select-multi-input-flex-wrap-config', flexWrap);
2687
+ this._inputContainer.style.setProperty('--select-multi-input-align-content-config', alignContent);
2479
2688
  }
2480
2689
  _canUseHorizontalMultiScroll(target) {
2481
2690
  if (this._config.selection.mode !== 'multi')
@@ -2652,7 +2861,7 @@
2652
2861
  }
2653
2862
  _createOptionsContainer() {
2654
2863
  const container = document.createElement('div');
2655
- container.className = 'options-container';
2864
+ container.className = `options-container ${EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS}`;
2656
2865
  return container;
2657
2866
  }
2658
2867
  _createLiveRegion() {
@@ -3103,14 +3312,14 @@
3103
3312
  }
3104
3313
 
3105
3314
  .input-container.input-container--multi {
3106
- max-height: var(--select-multi-input-max-height, var(--select-input-max-height, 160px));
3315
+ max-height: var(--select-multi-input-max-height, var(--select-multi-input-max-height-config, var(--select-input-max-height, 160px)));
3107
3316
  }
3108
3317
 
3109
3318
  .input-container.input-container--multi .input-content {
3110
- flex-wrap: var(--select-multi-input-flex-wrap, wrap);
3111
- align-content: var(--select-multi-input-align-content, flex-start);
3112
- overflow-x: var(--select-multi-input-overflow-x, hidden);
3113
- overflow-y: var(--select-multi-input-overflow-y, auto);
3319
+ flex-wrap: var(--select-multi-input-flex-wrap, var(--select-multi-input-flex-wrap-config, wrap));
3320
+ align-content: var(--select-multi-input-align-content, var(--select-multi-input-align-content-config, flex-start));
3321
+ overflow-x: var(--select-multi-input-overflow-x, var(--select-multi-input-overflow-x-config, hidden));
3322
+ overflow-y: var(--select-multi-input-overflow-y, var(--select-multi-input-overflow-y-config, auto));
3114
3323
  }
3115
3324
 
3116
3325
  .input-container.input-container--multi::after {
@@ -3127,6 +3336,11 @@
3127
3336
  cursor: var(--select-multi-input-horizontal-cursor, grab);
3128
3337
  overflow-y: hidden;
3129
3338
  overscroll-behavior-x: contain;
3339
+ padding-right: calc(var(--select-arrow-width, 42px) + var(--select-multi-horizontal-end-gap, 12px));
3340
+ }
3341
+
3342
+ .input-container.input-container--multi[data-multi-scroll-mode="horizontal"].has-clear-control .input-content {
3343
+ 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));
3130
3344
  }
3131
3345
 
3132
3346
  .input-container.input-container--multi[data-multi-scroll-mode="horizontal"]::after {
@@ -3168,6 +3382,15 @@
3168
3382
  left: var(--select-arrow-right-with-clear, 34px);
3169
3383
  }
3170
3384
 
3385
+ :host([dir="rtl"]) .input-container.input-container--multi[data-multi-scroll-mode="horizontal"] .input-content {
3386
+ padding-right: 0;
3387
+ padding-left: calc(var(--select-arrow-width, 42px) + var(--select-multi-horizontal-end-gap, 12px));
3388
+ }
3389
+
3390
+ :host([dir="rtl"]) .input-container.input-container--multi[data-multi-scroll-mode="horizontal"].has-clear-control .input-content {
3391
+ 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));
3392
+ }
3393
+
3171
3394
  .input-container.input-container--multi[data-multi-scroll-mode="horizontal"] .clear-control-button {
3172
3395
  background: var(--select-multi-action-surface-bg, var(--select-input-bg, var(--select-surface)));
3173
3396
  z-index: 4;
@@ -3521,8 +3744,10 @@
3521
3744
  }
3522
3745
 
3523
3746
  .group-header:not(:first-child) {
3524
- margin-top: var(--select-group-header-separator-margin-top);
3525
- padding-top: var(--select-group-header-separator-padding-top);
3747
+ margin-top: calc(
3748
+ var(--select-group-header-separator-margin-top, 0px) +
3749
+ var(--select-group-header-separator-padding-top, 0px)
3750
+ );
3526
3751
  border-top: var(--select-group-header-separator-border-top);
3527
3752
  }
3528
3753
 
@@ -3604,7 +3829,7 @@
3604
3829
  color: var(--select-option-selected-hover-color, var(--select-option-selected-color, var(--select-accent)));
3605
3830
  }
3606
3831
 
3607
- .option.active:not(.selected) {
3832
+ .option.active:not(.selected):not(.disabled) {
3608
3833
  background: var(--select-option-active-bg, var(--select-surface-elevated));
3609
3834
  color: var(--select-option-active-color, var(--select-option-hover-color, var(--select-option-color, var(--select-text))));
3610
3835
  border: var(--select-option-active-border, var(--select-option-hover-border, var(--select-option-border, none)));
@@ -3614,7 +3839,7 @@
3614
3839
  transform: var(--select-option-active-transform, none);
3615
3840
  }
3616
3841
 
3617
- .option.selected.active {
3842
+ .option.selected.active:not(.disabled) {
3618
3843
  outline: var(--select-option-selected-active-outline, 2px solid rgba(15, 52, 96, 0.4));
3619
3844
  outline-offset: var(--select-option-selected-active-outline-offset);
3620
3845
  }
@@ -3832,6 +4057,9 @@
3832
4057
 
3833
4058
  --select-badge-bg: var(--select-dark-badge-bg, rgba(99, 102, 241, 0.2));
3834
4059
  --select-badge-color: var(--select-dark-badge-color, #e0e7ff);
4060
+ --select-badge-border: var(--select-dark-badge-border, var(--select-badge-border, none));
4061
+ --select-badge-hover-border: var(--select-dark-badge-hover-border, var(--select-badge-hover-border, var(--select-badge-border, none)));
4062
+ --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))));
3835
4063
 
3836
4064
  --select-group-header-bg: var(--select-group-header-dark-bg, #1a1a2e);
3837
4065
  --select-group-header-color: var(--select-group-header-dark-color, #9ca3af);
@@ -3867,6 +4095,36 @@
3867
4095
  border-color: var(--select-border);
3868
4096
  }
3869
4097
 
4098
+ :host(.dark-mode) .input-container:hover,
4099
+ :host([dark-mode]) .input-container:hover,
4100
+ :host([darkmode]) .input-container:hover,
4101
+ :host([data-theme="dark"]) .input-container:hover,
4102
+ :host([theme="dark"]) .input-container:hover,
4103
+ :host-context(.dark-mode) .input-container:hover,
4104
+ :host-context(.dark) .input-container:hover,
4105
+ :host-context([dark-mode]) .input-container:hover,
4106
+ :host-context([darkmode]) .input-container:hover,
4107
+ :host-context([data-theme="dark"]) .input-container:hover,
4108
+ :host-context([theme="dark"]) .input-container:hover {
4109
+ border-color: var(--select-dark-input-hover-border, var(--select-input-hover-border, var(--select-dark-border-focus, var(--select-border-focus, #6366f1))));
4110
+ 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)));
4111
+ }
4112
+
4113
+ :host(.dark-mode) .input-container:focus-within,
4114
+ :host([dark-mode]) .input-container:focus-within,
4115
+ :host([darkmode]) .input-container:focus-within,
4116
+ :host([data-theme="dark"]) .input-container:focus-within,
4117
+ :host([theme="dark"]) .input-container:focus-within,
4118
+ :host-context(.dark-mode) .input-container:focus-within,
4119
+ :host-context(.dark) .input-container:focus-within,
4120
+ :host-context([dark-mode]) .input-container:focus-within,
4121
+ :host-context([darkmode]) .input-container:focus-within,
4122
+ :host-context([data-theme="dark"]) .input-container:focus-within,
4123
+ :host-context([theme="dark"]) .input-container:focus-within {
4124
+ border-color: var(--select-dark-border-focus, var(--select-border-focus, #6366f1));
4125
+ 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);
4126
+ }
4127
+
3870
4128
  :host(.dark-mode) .input-container::after,
3871
4129
  :host([dark-mode]) .input-container::after,
3872
4130
  :host([darkmode]) .input-container::after,
@@ -3922,7 +4180,8 @@
3922
4180
  :host-context([darkmode]) .selection-badge,
3923
4181
  :host-context([data-theme="dark"]) .selection-badge,
3924
4182
  :host-context([theme="dark"]) .selection-badge {
3925
- background: var(--select-badge-dark-bg);
4183
+ background: var(--select-dark-badge-bg, var(--select-badge-bg, var(--select-badge-dark-bg)));
4184
+ color: var(--select-dark-badge-color, var(--select-badge-color, #e0e7ff));
3926
4185
  }
3927
4186
 
3928
4187
  :host(.dark-mode) .group-header:not(:first-child),
@@ -4103,6 +4362,10 @@
4103
4362
  this._inputContent.addEventListener('wheel', (e) => {
4104
4363
  if (this._config.selection.mode === 'multi'
4105
4364
  && (this._config.multiSelectDisplay?.mode ?? 'wrap') === 'horizontal') {
4365
+ const primaryDelta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
4366
+ if (primaryDelta !== 0) {
4367
+ this._inputContent.scrollLeft += primaryDelta;
4368
+ }
4106
4369
  e.preventDefault();
4107
4370
  }
4108
4371
  }, { passive: false });
@@ -4497,6 +4760,8 @@
4497
4760
  }
4498
4761
  }
4499
4762
  _handleKeydown(e) {
4763
+ if (!this._config.enabled)
4764
+ return;
4500
4765
  switch (e.key) {
4501
4766
  case 'ArrowDown':
4502
4767
  e.preventDefault();
@@ -4519,17 +4784,23 @@
4519
4784
  case 'Home':
4520
4785
  e.preventDefault();
4521
4786
  if (this._state.isOpen) {
4522
- this._setActive(0);
4787
+ const selectableIndices = this._getSelectableOptionIndices();
4788
+ const firstIndex = selectableIndices[0];
4789
+ if (firstIndex === undefined)
4790
+ break;
4791
+ this._setActive(firstIndex);
4523
4792
  if (this._config.selection.mode === 'multi' && e.shiftKey) {
4524
- this._selectRange(this._rangeAnchorIndex ?? 0, 0, { clear: !(e.ctrlKey || e.metaKey) });
4793
+ this._selectRange(this._rangeAnchorIndex ?? firstIndex, firstIndex, { clear: !(e.ctrlKey || e.metaKey) });
4525
4794
  }
4526
4795
  }
4527
4796
  break;
4528
4797
  case 'End':
4529
4798
  e.preventDefault();
4530
4799
  if (this._state.isOpen) {
4531
- const options = this._getSelectableOptions();
4532
- const lastIndex = Math.max(0, options.length - 1);
4800
+ const selectableIndices = this._getSelectableOptionIndices();
4801
+ const lastIndex = selectableIndices[selectableIndices.length - 1];
4802
+ if (lastIndex === undefined)
4803
+ break;
4533
4804
  this._setActive(lastIndex);
4534
4805
  if (this._config.selection.mode === 'multi' && e.shiftKey) {
4535
4806
  this._selectRange(this._rangeAnchorIndex ?? lastIndex, lastIndex, { clear: !(e.ctrlKey || e.metaKey) });
@@ -4583,8 +4854,17 @@
4583
4854
  }
4584
4855
  }
4585
4856
  _moveActive(delta, opts) {
4586
- const options = this._getSelectableOptions();
4587
- const next = Math.max(0, Math.min(options.length - 1, this._state.activeIndex + delta));
4857
+ const selectableIndices = this._getSelectableOptionIndices();
4858
+ if (selectableIndices.length === 0)
4859
+ return;
4860
+ const currentPosition = selectableIndices.indexOf(this._state.activeIndex);
4861
+ const basePosition = currentPosition >= 0
4862
+ ? currentPosition
4863
+ : delta >= 0
4864
+ ? -1
4865
+ : selectableIndices.length;
4866
+ const nextPosition = Math.max(0, Math.min(selectableIndices.length - 1, basePosition + delta));
4867
+ const next = selectableIndices[nextPosition];
4588
4868
  this._setActive(next);
4589
4869
  if (this._config.selection.mode === 'multi' && opts?.shiftKey) {
4590
4870
  const anchor = this._rangeAnchorIndex ?? this._state.activeIndex;
@@ -4596,6 +4876,10 @@
4596
4876
  }
4597
4877
  }
4598
4878
  _setActive(index) {
4879
+ const option = this._getOptionElementByIndex(index);
4880
+ if (!option || option.getAttribute('aria-disabled') === 'true') {
4881
+ return;
4882
+ }
4599
4883
  // Clear previous active state
4600
4884
  if (this._state.activeIndex >= 0) {
4601
4885
  const prevOption = this._getOptionElementByIndex(this._state.activeIndex);
@@ -4612,7 +4896,6 @@
4612
4896
  }
4613
4897
  this._state.activeIndex = index;
4614
4898
  // Set new active state
4615
- const option = this._getOptionElementByIndex(index);
4616
4899
  if (option) {
4617
4900
  // Check if it's a custom SelectOption or a lightweight DOM element
4618
4901
  if ('setActive' in option && typeof option.setActive === 'function') {
@@ -4641,9 +4924,15 @@
4641
4924
  // Filter out group headers and other non-selectable elements
4642
4925
  // Only return elements with data-index or data-sm-selectable attributes
4643
4926
  return Array.from(this._optionsContainer.children).filter((child) => {
4644
- return child.hasAttribute('data-index') || child.hasAttribute('data-sm-selectable');
4927
+ return (child.hasAttribute('data-index') || child.hasAttribute('data-sm-selectable'))
4928
+ && child.getAttribute('aria-disabled') !== 'true';
4645
4929
  });
4646
4930
  }
4931
+ _getSelectableOptionIndices() {
4932
+ return this._getSelectableOptions()
4933
+ .map((option) => Number(option.getAttribute('data-sm-index') ?? option.getAttribute('data-index')))
4934
+ .filter((index) => Number.isFinite(index));
4935
+ }
4647
4936
  _buildRendererHelpers() {
4648
4937
  return {
4649
4938
  onSelect: (_item, index) => this._selectOption(index),
@@ -4680,24 +4969,27 @@
4680
4969
  return;
4681
4970
  const options = this._getSelectableOptions();
4682
4971
  const maxSelections = this._config.selection.maxSelections || 0;
4683
- options.forEach((option, index) => {
4972
+ options.forEach((option) => {
4973
+ const optionIndex = Number(option.getAttribute('data-sm-index') ?? option.getAttribute('data-index'));
4974
+ if (!Number.isFinite(optionIndex))
4975
+ return;
4684
4976
  if (maxSelections > 0 && this._state.selectedIndices.size >= maxSelections) {
4685
4977
  return;
4686
4978
  }
4687
- if (!this._state.selectedIndices.has(index)) {
4979
+ if (!this._state.selectedIndices.has(optionIndex)) {
4688
4980
  // Check if it's a custom SelectOption or a lightweight DOM element
4689
4981
  if ('getConfig' in option && typeof option.getConfig === 'function') {
4690
4982
  const config = option.getConfig();
4691
- this._state.selectedIndices.add(index);
4692
- this._state.selectedItems.set(index, config.item);
4983
+ this._state.selectedIndices.add(optionIndex);
4984
+ this._state.selectedItems.set(optionIndex, config.item);
4693
4985
  option.setSelected(true);
4694
4986
  }
4695
4987
  else {
4696
4988
  // Lightweight option - get item from data attribute or state
4697
- const item = this._state.loadedItems[index];
4989
+ const item = this._state.loadedItems[optionIndex];
4698
4990
  if (item) {
4699
- this._state.selectedIndices.add(index);
4700
- this._state.selectedItems.set(index, item);
4991
+ this._state.selectedIndices.add(optionIndex);
4992
+ this._state.selectedItems.set(optionIndex, item);
4701
4993
  option.classList.add('smilodon-option--selected');
4702
4994
  option.setAttribute('aria-selected', 'true');
4703
4995
  }
@@ -4721,6 +5013,9 @@
4721
5013
  if (maxSelections > 0 && this._state.selectedIndices.size >= maxSelections)
4722
5014
  break;
4723
5015
  const item = this._state.loadedItems[i];
5016
+ const optionEl = this._getOptionElementByIndex(i);
5017
+ if (optionEl?.getAttribute('aria-disabled') === 'true')
5018
+ continue;
4724
5019
  if (!item)
4725
5020
  continue;
4726
5021
  this._state.selectedIndices.add(i);
@@ -4732,8 +5027,8 @@
4732
5027
  this._announce(`${this._state.selectedIndices.size} items selected`);
4733
5028
  }
4734
5029
  _setInitialActiveOption() {
4735
- const options = this._getSelectableOptions();
4736
- if (options.length === 0)
5030
+ const selectableIndices = this._getSelectableOptionIndices();
5031
+ if (selectableIndices.length === 0)
4737
5032
  return;
4738
5033
  const selected = Array.from(this._state.selectedIndices).sort((a, b) => a - b);
4739
5034
  if (this._config.selection.mode === 'multi' && selected.length === 0) {
@@ -4741,8 +5036,8 @@
4741
5036
  this._input.removeAttribute('aria-activedescendant');
4742
5037
  return;
4743
5038
  }
4744
- const target = selected.length > 0 ? selected[0] : 0;
4745
- this._setActive(Math.min(target, options.length - 1));
5039
+ const target = selected.find((index) => selectableIndices.includes(index)) ?? selectableIndices[0];
5040
+ this._setActive(target);
4746
5041
  }
4747
5042
  _announce(message) {
4748
5043
  if (this._liveRegion) {
@@ -5575,6 +5870,9 @@
5575
5870
  if (this._config.styles.classNames?.groupHeader) {
5576
5871
  header.classList.add(...this._config.styles.classNames.groupHeader.split(' ').filter(Boolean));
5577
5872
  }
5873
+ if (!header.hasAttribute('role')) {
5874
+ header.setAttribute('role', 'presentation');
5875
+ }
5578
5876
  header.setAttribute('part', 'group-header');
5579
5877
  this._optionsContainer.appendChild(header);
5580
5878
  group.options.forEach(item => {
@@ -5850,9 +6148,6 @@
5850
6148
  if (!optionEl.getAttribute('role')) {
5851
6149
  optionEl.setAttribute('role', 'option');
5852
6150
  }
5853
- if (!optionEl.getAttribute('aria-label')) {
5854
- optionEl.setAttribute('aria-label', meta.label);
5855
- }
5856
6151
  optionEl.setAttribute('aria-selected', String(meta.selected));
5857
6152
  if (meta.disabled) {
5858
6153
  optionEl.setAttribute('aria-disabled', 'true');
@@ -5869,6 +6164,10 @@
5869
6164
  // Re-attaching here causes the double-click toggle bug if a child component fails to stopPropagation.
5870
6165
  this._customOptionBoundElements.add(optionEl);
5871
6166
  }
6167
+ this._normalizeCustomOptionAccessibility(optionEl, {
6168
+ label: meta.label,
6169
+ disabled: meta.disabled,
6170
+ });
5872
6171
  return optionEl;
5873
6172
  }
5874
6173
  _addLoadMoreTrigger() {
@@ -5903,6 +6202,7 @@
5903
6202
  }
5904
6203
  /** live set of all connected instances; used to auto-close siblings */
5905
6204
  EnhancedSelect._instances = new Set();
6205
+ EnhancedSelect._MIRRORED_STYLES_SCOPE_CLASS = 'smilodon-mirrored-styles-scope';
5906
6206
  // Register custom element
5907
6207
  if (!customElements.get('enhanced-select')) {
5908
6208
  customElements.define('enhanced-select', EnhancedSelect);