@smilodon/core 1.9.1-debug.0 → 1.9.1

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
@@ -1087,12 +1087,16 @@ class NativeSelectElement extends HTMLElement {
1087
1087
  * Returns single value for single-select, array for multi-select
1088
1088
  */
1089
1089
  getValue() {
1090
- const values = Array.from(this._selectedItems.values()).map(item => {
1090
+ // Optimized: single-pass iteration, no intermediate arrays
1091
+ const values = [];
1092
+ for (const item of this._selectedItems.values()) {
1091
1093
  if (typeof item === 'object' && item !== null && 'value' in item) {
1092
- return item.value;
1094
+ values.push(item.value);
1093
1095
  }
1094
- return item;
1095
- });
1096
+ else {
1097
+ values.push(item);
1098
+ }
1099
+ }
1096
1100
  return this._multi ? values : (values[0] ?? null);
1097
1101
  }
1098
1102
  render() {
@@ -1238,10 +1242,17 @@ class NativeSelectElement extends HTMLElement {
1238
1242
  selected,
1239
1243
  multi: this._multi
1240
1244
  });
1245
+ // Optimized: single-pass iteration for change event data
1246
+ const selectedItems = [];
1247
+ const selectedValues = [];
1248
+ for (const item of this._selectedItems.values()) {
1249
+ selectedItems.push(item);
1250
+ selectedValues.push(item?.value ?? item);
1251
+ }
1241
1252
  // Emit 'change' event for better React compatibility
1242
1253
  this._emit('change', {
1243
- selectedItems: Array.from(this._selectedItems.values()),
1244
- selectedValues: Array.from(this._selectedItems.values()).map(i => i?.value ?? i),
1254
+ selectedItems,
1255
+ selectedValues,
1245
1256
  selectedIndices: Array.from(this._selectedSet)
1246
1257
  });
1247
1258
  this._announce(`Selected ${label}`);
@@ -1475,7 +1486,10 @@ class SelectConfigManager {
1475
1486
  }
1476
1487
  deepMerge(target, source) {
1477
1488
  const result = { ...target };
1478
- for (const key in source) {
1489
+ // PERF: Avoid for...in, use Object.keys for predictable iteration
1490
+ const keys = Object.keys(source);
1491
+ for (let i = 0; i < keys.length; i++) {
1492
+ const key = keys[i];
1479
1493
  if (Object.prototype.hasOwnProperty.call(source, key)) {
1480
1494
  const sourceValue = source[key];
1481
1495
  const targetValue = result[key];
@@ -1514,15 +1528,33 @@ function resetSelectConfig() {
1514
1528
  class SelectOption extends HTMLElement {
1515
1529
  constructor(config) {
1516
1530
  super();
1531
+ this._hasRendered = false;
1517
1532
  this._config = config;
1518
1533
  this._shadow = this.attachShadow({ mode: 'open' });
1519
1534
  this._container = document.createElement('div');
1520
1535
  this._container.className = 'option-container';
1521
1536
  this._initializeStyles();
1522
- this._render();
1537
+ // NOTE: _render() moved to connectedCallback to comply with Web Components spec
1538
+ // (cannot mutate host element attributes/classes in constructor)
1523
1539
  this._attachEventListeners();
1524
1540
  this._shadow.appendChild(this._container);
1525
1541
  }
1542
+ connectedCallback() {
1543
+ this._ensureRendered();
1544
+ }
1545
+ _ensureRendered() {
1546
+ if (this._hasRendered)
1547
+ return;
1548
+ this._render();
1549
+ this._hasRendered = true;
1550
+ }
1551
+ /**
1552
+ * Ensure option content is rendered. Called by EnhancedSelect after append
1553
+ * when connectedCallback timing is unreliable (Vue/Nuxt, jsdom, Teleport).
1554
+ */
1555
+ ensureRendered() {
1556
+ this._ensureRendered();
1557
+ }
1526
1558
  _initializeStyles() {
1527
1559
  const style = document.createElement('style');
1528
1560
  style.textContent = `
@@ -2010,21 +2042,27 @@ class SelectOption extends HTMLElement {
2010
2042
  */
2011
2043
  setSelected(selected) {
2012
2044
  this._config.selected = selected;
2013
- this._render();
2045
+ if (this._hasRendered) {
2046
+ this._render();
2047
+ }
2014
2048
  }
2015
2049
  /**
2016
2050
  * Set active state
2017
2051
  */
2018
2052
  setActive(active) {
2019
2053
  this._config.active = active && (!this._config.disabled || this._getDisabledBehavior().focusable);
2020
- this._render();
2054
+ if (this._hasRendered) {
2055
+ this._render();
2056
+ }
2021
2057
  }
2022
2058
  /**
2023
2059
  * Set disabled state
2024
2060
  */
2025
2061
  setDisabled(disabled) {
2026
2062
  this._config.disabled = disabled;
2027
- this._render();
2063
+ if (this._hasRendered) {
2064
+ this._render();
2065
+ }
2028
2066
  }
2029
2067
  }
2030
2068
  // Register custom element
@@ -2032,6 +2070,42 @@ if (!customElements.get('select-option')) {
2032
2070
  customElements.define('select-option', SelectOption);
2033
2071
  }
2034
2072
 
2073
+ /**
2074
+ * Compare select item values with loose primitive coercion.
2075
+ * Treats string/number pairs like `"1"` and `1` as equal.
2076
+ */
2077
+ function valuesEqual(a, b) {
2078
+ if (Object.is(a, b))
2079
+ return true;
2080
+ if (a == null || b == null)
2081
+ return false;
2082
+ if (typeof a === 'string' && typeof b === 'number') {
2083
+ return a === String(b);
2084
+ }
2085
+ if (typeof a === 'number' && typeof b === 'string') {
2086
+ return String(a) === b;
2087
+ }
2088
+ return false;
2089
+ }
2090
+ /** Returns true when `values` contains a value equal to `target`. */
2091
+ function arrayIncludesValue(values, target) {
2092
+ for (let i = 0; i < values.length; i += 1) {
2093
+ if (valuesEqual(values[i], target))
2094
+ return true;
2095
+ }
2096
+ return false;
2097
+ }
2098
+ /** Returns true when two value arrays match positionally with loose equality. */
2099
+ function arraysEqualByValue(a, b) {
2100
+ if (a.length !== b.length)
2101
+ return false;
2102
+ for (let i = 0; i < a.length; i += 1) {
2103
+ if (!valuesEqual(a[i], b[i]))
2104
+ return false;
2105
+ }
2106
+ return true;
2107
+ }
2108
+
2035
2109
  /**
2036
2110
  * Enhanced Select Component
2037
2111
  * Implements all advanced features: infinite scroll, load more, busy state,
@@ -2136,7 +2210,8 @@ class EnhancedSelect extends HTMLElement {
2136
2210
  // Initialize styles BEFORE assembling DOM (order matters in shadow DOM)
2137
2211
  this._initializeStyles();
2138
2212
  this._syncStyleConfigVariables();
2139
- this._syncDirectionConfig();
2213
+ // NOTE: _syncDirectionConfig moved to connectedCallback to comply with Web Components spec
2214
+ // (cannot call setAttribute on host element in constructor)
2140
2215
  this._assembleDOM();
2141
2216
  this._attachEventListeners();
2142
2217
  this._initializeObservers();
@@ -2148,6 +2223,8 @@ class EnhancedSelect extends HTMLElement {
2148
2223
  // Angular's rendering seems to not apply :host styles correctly in some cases
2149
2224
  // Must be done in connectedCallback when element is attached to DOM
2150
2225
  this.style.display = 'block';
2226
+ // Sync direction attribute (must be in connectedCallback, not constructor)
2227
+ this._syncDirectionConfig();
2151
2228
  if (this._optionRenderer) {
2152
2229
  this._setGlobalStylesMirroring(true);
2153
2230
  }
@@ -2155,6 +2232,12 @@ class EnhancedSelect extends HTMLElement {
2155
2232
  if (this._config.serverSide.enabled && this._config.serverSide.initialSelectedValues) {
2156
2233
  this._loadInitialSelectedItems();
2157
2234
  }
2235
+ // Re-render options after connect so SelectOption instances created while
2236
+ // disconnected (common in Vue/Nuxt client mounting) receive connectedCallback.
2237
+ if (this._state.loadedItems.length > 0 || this._state.groupedItems.length > 0) {
2238
+ this._renderOptions();
2239
+ this._updateInputDisplay();
2240
+ }
2158
2241
  // Emit open event if configured to start open
2159
2242
  if (this._config.callbacks.onOpen) {
2160
2243
  this._config.callbacks.onOpen();
@@ -2337,16 +2420,47 @@ class EnhancedSelect extends HTMLElement {
2337
2420
  if (!cssText.trim())
2338
2421
  return '';
2339
2422
  try {
2340
- if (typeof CSSStyleSheet !== 'undefined') {
2423
+ if (typeof CSSStyleSheet !== 'undefined' && 'replaceSync' in CSSStyleSheet.prototype) {
2341
2424
  const sheet = new CSSStyleSheet();
2342
2425
  sheet.replaceSync(cssText);
2343
2426
  return this._serializeScopedCssRules(Array.from(sheet.cssRules));
2344
2427
  }
2345
2428
  }
2346
2429
  catch (_error) {
2430
+ // CSSStyleSheet API failed, use fallback parser for test environments (JSDOM)
2431
+ return this._scopeMirroredCssTextFallback(cssText);
2432
+ }
2433
+ // Fallback for environments without CSSStyleSheet.replaceSync
2434
+ return this._scopeMirroredCssTextFallback(cssText);
2435
+ }
2436
+ /**
2437
+ * Fallback CSS parser for environments where CSSStyleSheet API is unavailable (e.g., JSDOM).
2438
+ * Performs simple text-based CSS rule scoping.
2439
+ */
2440
+ _scopeMirroredCssTextFallback(cssText) {
2441
+ if (!cssText.trim())
2347
2442
  return '';
2443
+ const result = [];
2444
+ // Match CSS rules with a simple regex (handles basic cases for testing)
2445
+ // This won't handle all edge cases but works for common CSS patterns
2446
+ const ruleRegex = /([^{}]+)\{([^{}]+)\}/g;
2447
+ let match;
2448
+ while ((match = ruleRegex.exec(cssText)) !== null) {
2449
+ const selectorText = match[1].trim();
2450
+ const declarations = match[2].trim();
2451
+ // Skip @-rules (media, keyframes, etc.) - would need more complex parsing
2452
+ if (selectorText.startsWith('@')) {
2453
+ continue;
2454
+ }
2455
+ // Split multiple selectors and scope each one
2456
+ const selectors = this._splitSelectorList(selectorText)
2457
+ .map((selector) => this._scopeMirroredSelector(selector))
2458
+ .filter(Boolean);
2459
+ if (selectors.length > 0) {
2460
+ result.push(`${selectors.join(', ')} { ${declarations} }`);
2461
+ }
2348
2462
  }
2349
- return '';
2463
+ return result.join('\n');
2350
2464
  }
2351
2465
  _serializeScopedCssRules(rules) {
2352
2466
  return rules.map((rule) => this._serializeScopedCssRule(rule)).filter(Boolean).join('\n');
@@ -2733,6 +2847,8 @@ class EnhancedSelect extends HTMLElement {
2733
2847
  this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
2734
2848
  }
2735
2849
  _syncDirectionConfig() {
2850
+ if (!this.isConnected)
2851
+ return;
2736
2852
  this.setAttribute('dir', this._config.direction ?? 'ltr');
2737
2853
  }
2738
2854
  _setIconContent(target, markup, fallback) {
@@ -3009,7 +3125,13 @@ class EnhancedSelect extends HTMLElement {
3009
3125
  const icon = document.createElement('span');
3010
3126
  icon.className = 'clear-control-icon';
3011
3127
  icon.setAttribute('part', 'clear-icon');
3012
- icon.innerHTML = `<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
3128
+ // Use config icon if provided, otherwise default SVG
3129
+ if (this._config.clearControl.icon) {
3130
+ icon.textContent = this._config.clearControl.icon;
3131
+ }
3132
+ else {
3133
+ icon.innerHTML = `<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
3134
+ }
3013
3135
  button.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
3014
3136
  button.appendChild(icon);
3015
3137
  this._clearControlIcon = icon;
@@ -3602,8 +3724,8 @@ class EnhancedSelect extends HTMLElement {
3602
3724
  top: 0;
3603
3725
  right: 0;
3604
3726
  bottom: 0;
3605
- width: var(--select-arrow-width, 42px);
3606
- height: var(--select-arrow-height, auto);
3727
+ width: var(--select-arrow-width, var(--select-arrow-size, 42px));
3728
+ height: var(--select-arrow-height, var(--select-arrow-size, auto));
3607
3729
  display: flex;
3608
3730
  align-items: center;
3609
3731
  justify-content: center;
@@ -3707,8 +3829,8 @@ class EnhancedSelect extends HTMLElement {
3707
3829
  }
3708
3830
 
3709
3831
  .dropdown-arrow {
3710
- width: var(--select-arrow-size, 18px);
3711
- height: var(--select-arrow-size, 18px);
3832
+ width: var(--select-arrow-width, var(--select-arrow-size, 16px));
3833
+ height: var(--select-arrow-height, var(--select-arrow-size, 16px));
3712
3834
  color: var(--select-arrow-color, var(--select-text-muted));
3713
3835
  transition:
3714
3836
  transform var(--select-transition-smooth),
@@ -3721,7 +3843,7 @@ class EnhancedSelect extends HTMLElement {
3721
3843
  }
3722
3844
 
3723
3845
  .dropdown-arrow-container:hover .dropdown-arrow {
3724
- color: var(--select-arrow-hover-color, var(--select-accent));
3846
+ color: var(--select-arrow-hover, var(--select-arrow-hover-color, #667eea));
3725
3847
  }
3726
3848
 
3727
3849
  .dropdown-arrow.open {
@@ -4385,7 +4507,8 @@ class EnhancedSelect extends HTMLElement {
4385
4507
  :host-context([darkmode]) .group-header,
4386
4508
  :host-context([data-theme="dark"]) .group-header,
4387
4509
  :host-context([theme="dark"]) .group-header {
4388
- background: var(--select-group-header-bg, #1a1a2e);
4510
+ color: var(--select-dark-group-header-color, var(--select-group-header-color, inherit));
4511
+ background: var(--select-dark-group-header-bg, var(--select-group-header-bg, #1a1a2e));
4389
4512
  border-bottom: var(--select-group-header-border-bottom, 1px solid rgba(255, 255, 255, 0.08));
4390
4513
  box-shadow: var(--select-group-header-shadow, 0 1px 2px rgba(0, 0, 0, 0.3));
4391
4514
  }
@@ -4878,6 +5001,41 @@ class EnhancedSelect extends HTMLElement {
4878
5001
  this._perfMeasure('smilodon-search-to-render', 'smilodon-search-input-last', 'smilodon-search-render-complete');
4879
5002
  }
4880
5003
  }
5004
+ /**
5005
+ * Filter items by search query (optimized hot path)
5006
+ * Uses for-loop with hoisted invariants for better performance
5007
+ */
5008
+ _filterItemsByQuery(items, query) {
5009
+ // Early return for empty query
5010
+ if (!query?.trim())
5011
+ return items;
5012
+ // PERF: Hoist invariants outside loop
5013
+ const lowerQuery = query.toLowerCase().trim();
5014
+ const getLabelFn = this._config.serverSide.getLabelFromItem
5015
+ ?? ((item) => item?.label ?? item?.text ?? String(item));
5016
+ const results = [];
5017
+ const len = items.length;
5018
+ // PERF: for-loop instead of filter (no closure allocation)
5019
+ for (let i = 0; i < len; i++) {
5020
+ const item = items[i];
5021
+ if (item == null)
5022
+ continue;
5023
+ try {
5024
+ const label = getLabelFn(item);
5025
+ if (label == null)
5026
+ continue;
5027
+ const labelStr = String(label).toLowerCase();
5028
+ if (labelStr.includes(lowerQuery)) {
5029
+ results.push(item);
5030
+ }
5031
+ }
5032
+ catch (e) {
5033
+ // Silent fail for robustness with external data
5034
+ continue;
5035
+ }
5036
+ }
5037
+ return results;
5038
+ }
4881
5039
  _handleSearch(query) {
4882
5040
  this._state.searchQuery = query;
4883
5041
  this._syncClearControlState();
@@ -4903,25 +5061,12 @@ class EnhancedSelect extends HTMLElement {
4903
5061
  // Filter and render options immediately
4904
5062
  this._renderOptions();
4905
5063
  }
4906
- // Get filtered items based on search query - searches ENTIRE phrase
4907
- const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
4908
- // FIX: Do not trim query to allow searching for phrases with spaces
4909
- const searchQuery = query.toLowerCase();
4910
- const filteredItems = searchQuery
4911
- ? this._state.loadedItems.filter((item) => {
4912
- try {
4913
- const label = String(getLabel(item)).toLowerCase();
4914
- // Match the entire search phrase
4915
- return label.includes(searchQuery);
4916
- }
4917
- catch (e) {
4918
- return false;
4919
- }
4920
- })
4921
- : this._state.loadedItems;
5064
+ // PERF: Use optimized filter function
5065
+ const filteredItems = this._filterItemsByQuery(this._state.loadedItems, query);
4922
5066
  const count = filteredItems.length;
4923
5067
  // Announce search results for accessibility
4924
- if (searchQuery) {
5068
+ const trimmedQuery = query.trim();
5069
+ if (trimmedQuery) {
4925
5070
  this._announce(`${count} result${count !== 1 ? 's' : ''} found for "${query}"`);
4926
5071
  }
4927
5072
  // Only notify if query or result count changed to prevent infinite loops
@@ -5770,7 +5915,7 @@ class EnhancedSelect extends HTMLElement {
5770
5915
  this._state.selectedIndices.clear();
5771
5916
  this._state.selectedItems.clear();
5772
5917
  this._state.loadedItems.forEach((item, index) => {
5773
- if (values.includes(getValue(item)) && !this._isOptionSelectionBlocked(item)) {
5918
+ if (arrayIncludesValue(values, getValue(item)) && !this._isOptionSelectionBlocked(item)) {
5774
5919
  this._state.selectedIndices.add(index);
5775
5920
  this._state.selectedItems.set(index, item);
5776
5921
  }
@@ -5881,7 +6026,13 @@ class EnhancedSelect extends HTMLElement {
5881
6026
  this._clearControl.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
5882
6027
  }
5883
6028
  if (this._clearControlIcon) {
5884
- this._clearControlIcon.innerHTML = `<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
6029
+ // Use config icon if provided, otherwise default SVG
6030
+ if (this._config.clearControl.icon) {
6031
+ this._clearControlIcon.textContent = this._config.clearControl.icon;
6032
+ }
6033
+ else {
6034
+ this._clearControlIcon.innerHTML = `<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
6035
+ }
5885
6036
  }
5886
6037
  this._syncStyleConfigVariables();
5887
6038
  if (this._dropdown) {
@@ -5892,19 +6043,30 @@ class EnhancedSelect extends HTMLElement {
5892
6043
  this._dropdown.removeAttribute('aria-multiselectable');
5893
6044
  }
5894
6045
  }
5895
- this._syncDirectionConfig();
5896
- this._syncInputContainerMode();
5897
- this._syncMultiSelectDisplayConfig();
5898
- this._syncDropdownPlacement();
5899
- // Re-initialize observers in case infinite scroll was enabled/disabled
5900
- this._initializeObservers();
5901
- this._syncClearControlState();
5902
- this._updateInputDisplay();
5903
- this._renderOptions();
6046
+ if (this.isConnected) {
6047
+ this._syncDirectionConfig();
6048
+ this._syncInputContainerMode();
6049
+ this._syncMultiSelectDisplayConfig();
6050
+ this._syncDropdownPlacement();
6051
+ // Re-initialize observers in case infinite scroll was enabled/disabled
6052
+ this._initializeObservers();
6053
+ this._syncClearControlState();
6054
+ this._updateInputDisplay();
6055
+ this._renderOptions();
6056
+ }
6057
+ else {
6058
+ this._syncInputContainerMode();
6059
+ this._syncMultiSelectDisplayConfig();
6060
+ this._syncClearControlState();
6061
+ this._updateInputDisplay();
6062
+ }
5904
6063
  }
5905
6064
  _mergeConfig(target, source) {
5906
6065
  const result = { ...target };
5907
- for (const key in source) {
6066
+ // PERF: Avoid for...in, use Object.keys for predictable iteration
6067
+ const keys = Object.keys(source);
6068
+ for (let i = 0; i < keys.length; i++) {
6069
+ const key = keys[i];
5908
6070
  if (!Object.prototype.hasOwnProperty.call(source, key))
5909
6071
  continue;
5910
6072
  const sourceValue = source[key];
@@ -6246,6 +6408,9 @@ class EnhancedSelect extends HTMLElement {
6246
6408
  this._handleOptionRemove(targetIndex);
6247
6409
  });
6248
6410
  targetContainer.appendChild(option);
6411
+ if (option instanceof SelectOption) {
6412
+ option.ensureRendered();
6413
+ }
6249
6414
  }
6250
6415
  _normalizeCustomOptionElement(element, meta) {
6251
6416
  const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
@@ -6422,6 +6587,58 @@ class WorkerManager {
6422
6587
  this.supportsWorkers = false;
6423
6588
  this.supportsSharedArrayBuffer = false;
6424
6589
  this.nextId = 0;
6590
+ /**
6591
+ * Operation handlers for fallback execution
6592
+ */
6593
+ this._fallbackOperations = {
6594
+ 'transform': (payload) => {
6595
+ const { items, transformer } = payload;
6596
+ const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
6597
+ return items.map((item, i) => fn(item, i));
6598
+ },
6599
+ 'search': (payload) => {
6600
+ const { items, query, fuzzy } = payload;
6601
+ const lowerQuery = query.toLowerCase();
6602
+ const results = [];
6603
+ // Use for-loop instead of forEach for better performance (no closure allocation)
6604
+ for (let index = 0; index < items.length; index++) {
6605
+ const item = items[index];
6606
+ // PERF: Check for label/value properties first before converting entire object
6607
+ const itemAny = item;
6608
+ const itemText = itemAny?.label ?? itemAny?.value ?? item;
6609
+ const itemStr = String(itemText).toLowerCase();
6610
+ if (fuzzy) {
6611
+ // Simple fuzzy match - check if all query chars appear in order
6612
+ let queryIndex = 0;
6613
+ for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
6614
+ if (itemStr[i] === lowerQuery[queryIndex]) {
6615
+ queryIndex++;
6616
+ }
6617
+ }
6618
+ if (queryIndex === lowerQuery.length) {
6619
+ results.push({ item, index });
6620
+ }
6621
+ }
6622
+ else {
6623
+ // Exact substring match
6624
+ if (itemStr.includes(lowerQuery)) {
6625
+ results.push({ item, index });
6626
+ }
6627
+ }
6628
+ }
6629
+ return results;
6630
+ },
6631
+ 'filter': (payload) => {
6632
+ const { items, predicate } = payload;
6633
+ const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
6634
+ return items.filter((item, i) => fn(item, i));
6635
+ },
6636
+ 'sort': (payload) => {
6637
+ const { items, comparator } = payload;
6638
+ const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
6639
+ return [...items].sort(fn);
6640
+ },
6641
+ };
6425
6642
  this.detectFeatures();
6426
6643
  this.initWorker();
6427
6644
  }
@@ -6463,27 +6680,23 @@ class WorkerManager {
6463
6680
  const start = performance.now();
6464
6681
  const { id, type, payload } = e.data;
6465
6682
 
6683
+ // Lookup object for O(1) operation dispatch
6684
+ const operations = {
6685
+ 'transform': handleTransform,
6686
+ 'search': handleSearch,
6687
+ 'filter': handleFilter,
6688
+ 'sort': handleSort,
6689
+ };
6690
+
6466
6691
  try {
6467
- let result;
6468
-
6469
- switch (type) {
6470
- case 'transform':
6471
- result = handleTransform(payload);
6472
- break;
6473
- case 'search':
6474
- result = handleSearch(payload);
6475
- break;
6476
- case 'filter':
6477
- result = handleFilter(payload);
6478
- break;
6479
- case 'sort':
6480
- result = handleSort(payload);
6481
- break;
6482
- default:
6483
- throw new Error('Unknown operation: ' + type);
6692
+ const handler = operations[type];
6693
+ if (!handler) {
6694
+ throw new Error('Unknown operation: ' + type);
6484
6695
  }
6485
6696
 
6697
+ const result = handler(payload);
6486
6698
  const duration = performance.now() - start;
6699
+
6487
6700
  self.postMessage({
6488
6701
  id,
6489
6702
  success: true,
@@ -6615,53 +6828,11 @@ class WorkerManager {
6615
6828
  * Fallback to main thread execution
6616
6829
  */
6617
6830
  async executeFallback(type, payload) {
6618
- // Simple synchronous fallback implementations
6619
- switch (type) {
6620
- case 'transform': {
6621
- const { items, transformer } = payload;
6622
- const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
6623
- return items.map((item, i) => fn(item, i));
6624
- }
6625
- case 'search': {
6626
- const { items, query, fuzzy } = payload;
6627
- const lowerQuery = query.toLowerCase();
6628
- const results = [];
6629
- items.forEach((item, index) => {
6630
- const itemStr = String(item).toLowerCase();
6631
- if (fuzzy) {
6632
- // Simple fuzzy match - check if all query chars appear in order
6633
- let queryIndex = 0;
6634
- for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
6635
- if (itemStr[i] === lowerQuery[queryIndex]) {
6636
- queryIndex++;
6637
- }
6638
- }
6639
- if (queryIndex === lowerQuery.length) {
6640
- results.push({ item, index });
6641
- }
6642
- }
6643
- else {
6644
- // Exact substring match
6645
- if (itemStr.includes(lowerQuery)) {
6646
- results.push({ item, index });
6647
- }
6648
- }
6649
- });
6650
- return results;
6651
- }
6652
- case 'filter': {
6653
- const { items, predicate } = payload;
6654
- const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
6655
- return items.filter((item, i) => fn(item, i));
6656
- }
6657
- case 'sort': {
6658
- const { items, comparator } = payload;
6659
- const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
6660
- return [...items].sort(fn);
6661
- }
6662
- default:
6663
- throw new Error(`Unknown operation: ${type}`);
6831
+ const handler = this._fallbackOperations[type];
6832
+ if (!handler) {
6833
+ throw new Error(`Unknown operation: ${type}`);
6664
6834
  }
6835
+ return handler(payload);
6665
6836
  }
6666
6837
  /**
6667
6838
  * Transform items with custom function
@@ -7412,5 +7583,5 @@ function warnCSPViolation(feature, fallback) {
7412
7583
  }
7413
7584
  }
7414
7585
 
7415
- export { CSPFeatures, CustomOptionPool, DOMPool, EnhancedSelect, FenwickTree, NativeSelectElement, OptionRenderer, PerformanceTelemetry, SelectOption, Virtualizer, WorkerManager, applyClasses, applyDefaultTheme, configureSelect, containsSuspiciousPatterns, createElement, createRendererHelpers, createTextNode, defaultTheme, detectEnvironment, escapeAttribute, escapeHTML, getCustomProperty, getHTMLSanitizer, getTelemetry, getWorkerManager, hasOverflowHiddenAncestor, injectShadowStyles, measureAsync, measureSync, removeCustomProperty, renderTemplate, resetSelectConfig, sanitizeHTML, selectConfig, setCSSProperties, setCustomProperties, setHTMLSanitizer, setTextContent, shadowDOMStyles, toggleClass, validateTemplate, warnCSPViolation };
7586
+ export { CSPFeatures, CustomOptionPool, DOMPool, EnhancedSelect, FenwickTree, NativeSelectElement, OptionRenderer, PerformanceTelemetry, SelectOption, Virtualizer, WorkerManager, applyClasses, applyDefaultTheme, arrayIncludesValue, arraysEqualByValue, configureSelect, containsSuspiciousPatterns, createElement, createRendererHelpers, createTextNode, defaultTheme, detectEnvironment, escapeAttribute, escapeHTML, getCustomProperty, getHTMLSanitizer, getTelemetry, getWorkerManager, hasOverflowHiddenAncestor, injectShadowStyles, measureAsync, measureSync, removeCustomProperty, renderTemplate, resetSelectConfig, sanitizeHTML, selectConfig, setCSSProperties, setCustomProperties, setHTMLSanitizer, setTextContent, shadowDOMStyles, toggleClass, validateTemplate, valuesEqual, warnCSPViolation };
7416
7587
  //# sourceMappingURL=index.js.map