@smilodon/core 1.9.1-debug.0 → 1.9.2

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
@@ -1093,12 +1093,16 @@
1093
1093
  * Returns single value for single-select, array for multi-select
1094
1094
  */
1095
1095
  getValue() {
1096
- const values = Array.from(this._selectedItems.values()).map(item => {
1096
+ // Optimized: single-pass iteration, no intermediate arrays
1097
+ const values = [];
1098
+ for (const item of this._selectedItems.values()) {
1097
1099
  if (typeof item === 'object' && item !== null && 'value' in item) {
1098
- return item.value;
1100
+ values.push(item.value);
1099
1101
  }
1100
- return item;
1101
- });
1102
+ else {
1103
+ values.push(item);
1104
+ }
1105
+ }
1102
1106
  return this._multi ? values : (values[0] ?? null);
1103
1107
  }
1104
1108
  render() {
@@ -1244,10 +1248,17 @@
1244
1248
  selected,
1245
1249
  multi: this._multi
1246
1250
  });
1251
+ // Optimized: single-pass iteration for change event data
1252
+ const selectedItems = [];
1253
+ const selectedValues = [];
1254
+ for (const item of this._selectedItems.values()) {
1255
+ selectedItems.push(item);
1256
+ selectedValues.push(item?.value ?? item);
1257
+ }
1247
1258
  // Emit 'change' event for better React compatibility
1248
1259
  this._emit('change', {
1249
- selectedItems: Array.from(this._selectedItems.values()),
1250
- selectedValues: Array.from(this._selectedItems.values()).map(i => i?.value ?? i),
1260
+ selectedItems,
1261
+ selectedValues,
1251
1262
  selectedIndices: Array.from(this._selectedSet)
1252
1263
  });
1253
1264
  this._announce(`Selected ${label}`);
@@ -1481,7 +1492,10 @@
1481
1492
  }
1482
1493
  deepMerge(target, source) {
1483
1494
  const result = { ...target };
1484
- for (const key in source) {
1495
+ // PERF: Avoid for...in, use Object.keys for predictable iteration
1496
+ const keys = Object.keys(source);
1497
+ for (let i = 0; i < keys.length; i++) {
1498
+ const key = keys[i];
1485
1499
  if (Object.prototype.hasOwnProperty.call(source, key)) {
1486
1500
  const sourceValue = source[key];
1487
1501
  const targetValue = result[key];
@@ -1520,15 +1534,33 @@
1520
1534
  class SelectOption extends HTMLElement {
1521
1535
  constructor(config) {
1522
1536
  super();
1537
+ this._hasRendered = false;
1523
1538
  this._config = config;
1524
1539
  this._shadow = this.attachShadow({ mode: 'open' });
1525
1540
  this._container = document.createElement('div');
1526
1541
  this._container.className = 'option-container';
1527
1542
  this._initializeStyles();
1528
- this._render();
1543
+ // NOTE: _render() moved to connectedCallback to comply with Web Components spec
1544
+ // (cannot mutate host element attributes/classes in constructor)
1529
1545
  this._attachEventListeners();
1530
1546
  this._shadow.appendChild(this._container);
1531
1547
  }
1548
+ connectedCallback() {
1549
+ this._ensureRendered();
1550
+ }
1551
+ _ensureRendered() {
1552
+ if (this._hasRendered)
1553
+ return;
1554
+ this._render();
1555
+ this._hasRendered = true;
1556
+ }
1557
+ /**
1558
+ * Ensure option content is rendered. Called by EnhancedSelect after append
1559
+ * when connectedCallback timing is unreliable (Vue/Nuxt, jsdom, Teleport).
1560
+ */
1561
+ ensureRendered() {
1562
+ this._ensureRendered();
1563
+ }
1532
1564
  _initializeStyles() {
1533
1565
  const style = document.createElement('style');
1534
1566
  style.textContent = `
@@ -2016,21 +2048,27 @@
2016
2048
  */
2017
2049
  setSelected(selected) {
2018
2050
  this._config.selected = selected;
2019
- this._render();
2051
+ if (this._hasRendered) {
2052
+ this._render();
2053
+ }
2020
2054
  }
2021
2055
  /**
2022
2056
  * Set active state
2023
2057
  */
2024
2058
  setActive(active) {
2025
2059
  this._config.active = active && (!this._config.disabled || this._getDisabledBehavior().focusable);
2026
- this._render();
2060
+ if (this._hasRendered) {
2061
+ this._render();
2062
+ }
2027
2063
  }
2028
2064
  /**
2029
2065
  * Set disabled state
2030
2066
  */
2031
2067
  setDisabled(disabled) {
2032
2068
  this._config.disabled = disabled;
2033
- this._render();
2069
+ if (this._hasRendered) {
2070
+ this._render();
2071
+ }
2034
2072
  }
2035
2073
  }
2036
2074
  // Register custom element
@@ -2038,6 +2076,42 @@
2038
2076
  customElements.define('select-option', SelectOption);
2039
2077
  }
2040
2078
 
2079
+ /**
2080
+ * Compare select item values with loose primitive coercion.
2081
+ * Treats string/number pairs like `"1"` and `1` as equal.
2082
+ */
2083
+ function valuesEqual(a, b) {
2084
+ if (Object.is(a, b))
2085
+ return true;
2086
+ if (a == null || b == null)
2087
+ return false;
2088
+ if (typeof a === 'string' && typeof b === 'number') {
2089
+ return a === String(b);
2090
+ }
2091
+ if (typeof a === 'number' && typeof b === 'string') {
2092
+ return String(a) === b;
2093
+ }
2094
+ return false;
2095
+ }
2096
+ /** Returns true when `values` contains a value equal to `target`. */
2097
+ function arrayIncludesValue(values, target) {
2098
+ for (let i = 0; i < values.length; i += 1) {
2099
+ if (valuesEqual(values[i], target))
2100
+ return true;
2101
+ }
2102
+ return false;
2103
+ }
2104
+ /** Returns true when two value arrays match positionally with loose equality. */
2105
+ function arraysEqualByValue(a, b) {
2106
+ if (a.length !== b.length)
2107
+ return false;
2108
+ for (let i = 0; i < a.length; i += 1) {
2109
+ if (!valuesEqual(a[i], b[i]))
2110
+ return false;
2111
+ }
2112
+ return true;
2113
+ }
2114
+
2041
2115
  /**
2042
2116
  * Enhanced Select Component
2043
2117
  * Implements all advanced features: infinite scroll, load more, busy state,
@@ -2142,7 +2216,8 @@
2142
2216
  // Initialize styles BEFORE assembling DOM (order matters in shadow DOM)
2143
2217
  this._initializeStyles();
2144
2218
  this._syncStyleConfigVariables();
2145
- this._syncDirectionConfig();
2219
+ // NOTE: _syncDirectionConfig moved to connectedCallback to comply with Web Components spec
2220
+ // (cannot call setAttribute on host element in constructor)
2146
2221
  this._assembleDOM();
2147
2222
  this._attachEventListeners();
2148
2223
  this._initializeObservers();
@@ -2154,6 +2229,8 @@
2154
2229
  // Angular's rendering seems to not apply :host styles correctly in some cases
2155
2230
  // Must be done in connectedCallback when element is attached to DOM
2156
2231
  this.style.display = 'block';
2232
+ // Sync direction attribute (must be in connectedCallback, not constructor)
2233
+ this._syncDirectionConfig();
2157
2234
  if (this._optionRenderer) {
2158
2235
  this._setGlobalStylesMirroring(true);
2159
2236
  }
@@ -2161,6 +2238,12 @@
2161
2238
  if (this._config.serverSide.enabled && this._config.serverSide.initialSelectedValues) {
2162
2239
  this._loadInitialSelectedItems();
2163
2240
  }
2241
+ // Re-render options after connect so SelectOption instances created while
2242
+ // disconnected (common in Vue/Nuxt client mounting) receive connectedCallback.
2243
+ if (this._state.loadedItems.length > 0 || this._state.groupedItems.length > 0) {
2244
+ this._renderOptions();
2245
+ this._updateInputDisplay();
2246
+ }
2164
2247
  // Emit open event if configured to start open
2165
2248
  if (this._config.callbacks.onOpen) {
2166
2249
  this._config.callbacks.onOpen();
@@ -2343,16 +2426,47 @@
2343
2426
  if (!cssText.trim())
2344
2427
  return '';
2345
2428
  try {
2346
- if (typeof CSSStyleSheet !== 'undefined') {
2429
+ if (typeof CSSStyleSheet !== 'undefined' && 'replaceSync' in CSSStyleSheet.prototype) {
2347
2430
  const sheet = new CSSStyleSheet();
2348
2431
  sheet.replaceSync(cssText);
2349
2432
  return this._serializeScopedCssRules(Array.from(sheet.cssRules));
2350
2433
  }
2351
2434
  }
2352
2435
  catch (_error) {
2436
+ // CSSStyleSheet API failed, use fallback parser for test environments (JSDOM)
2437
+ return this._scopeMirroredCssTextFallback(cssText);
2438
+ }
2439
+ // Fallback for environments without CSSStyleSheet.replaceSync
2440
+ return this._scopeMirroredCssTextFallback(cssText);
2441
+ }
2442
+ /**
2443
+ * Fallback CSS parser for environments where CSSStyleSheet API is unavailable (e.g., JSDOM).
2444
+ * Performs simple text-based CSS rule scoping.
2445
+ */
2446
+ _scopeMirroredCssTextFallback(cssText) {
2447
+ if (!cssText.trim())
2353
2448
  return '';
2449
+ const result = [];
2450
+ // Match CSS rules with a simple regex (handles basic cases for testing)
2451
+ // This won't handle all edge cases but works for common CSS patterns
2452
+ const ruleRegex = /([^{}]+)\{([^{}]+)\}/g;
2453
+ let match;
2454
+ while ((match = ruleRegex.exec(cssText)) !== null) {
2455
+ const selectorText = match[1].trim();
2456
+ const declarations = match[2].trim();
2457
+ // Skip @-rules (media, keyframes, etc.) - would need more complex parsing
2458
+ if (selectorText.startsWith('@')) {
2459
+ continue;
2460
+ }
2461
+ // Split multiple selectors and scope each one
2462
+ const selectors = this._splitSelectorList(selectorText)
2463
+ .map((selector) => this._scopeMirroredSelector(selector))
2464
+ .filter(Boolean);
2465
+ if (selectors.length > 0) {
2466
+ result.push(`${selectors.join(', ')} { ${declarations} }`);
2467
+ }
2354
2468
  }
2355
- return '';
2469
+ return result.join('\n');
2356
2470
  }
2357
2471
  _serializeScopedCssRules(rules) {
2358
2472
  return rules.map((rule) => this._serializeScopedCssRule(rule)).filter(Boolean).join('\n');
@@ -2739,6 +2853,8 @@
2739
2853
  this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
2740
2854
  }
2741
2855
  _syncDirectionConfig() {
2856
+ if (!this.isConnected)
2857
+ return;
2742
2858
  this.setAttribute('dir', this._config.direction ?? 'ltr');
2743
2859
  }
2744
2860
  _setIconContent(target, markup, fallback) {
@@ -3015,7 +3131,13 @@
3015
3131
  const icon = document.createElement('span');
3016
3132
  icon.className = 'clear-control-icon';
3017
3133
  icon.setAttribute('part', 'clear-icon');
3018
- 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
+ // Use config icon if provided, otherwise default SVG
3135
+ if (this._config.clearControl.icon) {
3136
+ icon.textContent = this._config.clearControl.icon;
3137
+ }
3138
+ else {
3139
+ 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>`;
3140
+ }
3019
3141
  button.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
3020
3142
  button.appendChild(icon);
3021
3143
  this._clearControlIcon = icon;
@@ -3608,8 +3730,8 @@
3608
3730
  top: 0;
3609
3731
  right: 0;
3610
3732
  bottom: 0;
3611
- width: var(--select-arrow-width, 42px);
3612
- height: var(--select-arrow-height, auto);
3733
+ width: var(--select-arrow-width, var(--select-arrow-size, 42px));
3734
+ height: var(--select-arrow-height, var(--select-arrow-size, auto));
3613
3735
  display: flex;
3614
3736
  align-items: center;
3615
3737
  justify-content: center;
@@ -3713,8 +3835,8 @@
3713
3835
  }
3714
3836
 
3715
3837
  .dropdown-arrow {
3716
- width: var(--select-arrow-size, 18px);
3717
- height: var(--select-arrow-size, 18px);
3838
+ width: var(--select-arrow-width, var(--select-arrow-size, 16px));
3839
+ height: var(--select-arrow-height, var(--select-arrow-size, 16px));
3718
3840
  color: var(--select-arrow-color, var(--select-text-muted));
3719
3841
  transition:
3720
3842
  transform var(--select-transition-smooth),
@@ -3727,7 +3849,7 @@
3727
3849
  }
3728
3850
 
3729
3851
  .dropdown-arrow-container:hover .dropdown-arrow {
3730
- color: var(--select-arrow-hover-color, var(--select-accent));
3852
+ color: var(--select-arrow-hover, var(--select-arrow-hover-color, #667eea));
3731
3853
  }
3732
3854
 
3733
3855
  .dropdown-arrow.open {
@@ -4391,7 +4513,8 @@
4391
4513
  :host-context([darkmode]) .group-header,
4392
4514
  :host-context([data-theme="dark"]) .group-header,
4393
4515
  :host-context([theme="dark"]) .group-header {
4394
- background: var(--select-group-header-bg, #1a1a2e);
4516
+ color: var(--select-dark-group-header-color, var(--select-group-header-color, inherit));
4517
+ background: var(--select-dark-group-header-bg, var(--select-group-header-bg, #1a1a2e));
4395
4518
  border-bottom: var(--select-group-header-border-bottom, 1px solid rgba(255, 255, 255, 0.08));
4396
4519
  box-shadow: var(--select-group-header-shadow, 0 1px 2px rgba(0, 0, 0, 0.3));
4397
4520
  }
@@ -4884,6 +5007,41 @@
4884
5007
  this._perfMeasure('smilodon-search-to-render', 'smilodon-search-input-last', 'smilodon-search-render-complete');
4885
5008
  }
4886
5009
  }
5010
+ /**
5011
+ * Filter items by search query (optimized hot path)
5012
+ * Uses for-loop with hoisted invariants for better performance
5013
+ */
5014
+ _filterItemsByQuery(items, query) {
5015
+ // Early return for empty query
5016
+ if (!query?.trim())
5017
+ return items;
5018
+ // PERF: Hoist invariants outside loop
5019
+ const lowerQuery = query.toLowerCase().trim();
5020
+ const getLabelFn = this._config.serverSide.getLabelFromItem
5021
+ ?? ((item) => item?.label ?? item?.text ?? String(item));
5022
+ const results = [];
5023
+ const len = items.length;
5024
+ // PERF: for-loop instead of filter (no closure allocation)
5025
+ for (let i = 0; i < len; i++) {
5026
+ const item = items[i];
5027
+ if (item == null)
5028
+ continue;
5029
+ try {
5030
+ const label = getLabelFn(item);
5031
+ if (label == null)
5032
+ continue;
5033
+ const labelStr = String(label).toLowerCase();
5034
+ if (labelStr.includes(lowerQuery)) {
5035
+ results.push(item);
5036
+ }
5037
+ }
5038
+ catch (e) {
5039
+ // Silent fail for robustness with external data
5040
+ continue;
5041
+ }
5042
+ }
5043
+ return results;
5044
+ }
4887
5045
  _handleSearch(query) {
4888
5046
  this._state.searchQuery = query;
4889
5047
  this._syncClearControlState();
@@ -4909,25 +5067,12 @@
4909
5067
  // Filter and render options immediately
4910
5068
  this._renderOptions();
4911
5069
  }
4912
- // Get filtered items based on search query - searches ENTIRE phrase
4913
- const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
4914
- // FIX: Do not trim query to allow searching for phrases with spaces
4915
- const searchQuery = query.toLowerCase();
4916
- const filteredItems = searchQuery
4917
- ? this._state.loadedItems.filter((item) => {
4918
- try {
4919
- const label = String(getLabel(item)).toLowerCase();
4920
- // Match the entire search phrase
4921
- return label.includes(searchQuery);
4922
- }
4923
- catch (e) {
4924
- return false;
4925
- }
4926
- })
4927
- : this._state.loadedItems;
5070
+ // PERF: Use optimized filter function
5071
+ const filteredItems = this._filterItemsByQuery(this._state.loadedItems, query);
4928
5072
  const count = filteredItems.length;
4929
5073
  // Announce search results for accessibility
4930
- if (searchQuery) {
5074
+ const trimmedQuery = query.trim();
5075
+ if (trimmedQuery) {
4931
5076
  this._announce(`${count} result${count !== 1 ? 's' : ''} found for "${query}"`);
4932
5077
  }
4933
5078
  // Only notify if query or result count changed to prevent infinite loops
@@ -5776,7 +5921,7 @@
5776
5921
  this._state.selectedIndices.clear();
5777
5922
  this._state.selectedItems.clear();
5778
5923
  this._state.loadedItems.forEach((item, index) => {
5779
- if (values.includes(getValue(item)) && !this._isOptionSelectionBlocked(item)) {
5924
+ if (arrayIncludesValue(values, getValue(item)) && !this._isOptionSelectionBlocked(item)) {
5780
5925
  this._state.selectedIndices.add(index);
5781
5926
  this._state.selectedItems.set(index, item);
5782
5927
  }
@@ -5887,7 +6032,13 @@
5887
6032
  this._clearControl.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
5888
6033
  }
5889
6034
  if (this._clearControlIcon) {
5890
- 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
+ // Use config icon if provided, otherwise default SVG
6036
+ if (this._config.clearControl.icon) {
6037
+ this._clearControlIcon.textContent = this._config.clearControl.icon;
6038
+ }
6039
+ else {
6040
+ 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>`;
6041
+ }
5891
6042
  }
5892
6043
  this._syncStyleConfigVariables();
5893
6044
  if (this._dropdown) {
@@ -5898,23 +6049,38 @@
5898
6049
  this._dropdown.removeAttribute('aria-multiselectable');
5899
6050
  }
5900
6051
  }
5901
- this._syncDirectionConfig();
5902
- this._syncInputContainerMode();
5903
- this._syncMultiSelectDisplayConfig();
5904
- this._syncDropdownPlacement();
5905
- // Re-initialize observers in case infinite scroll was enabled/disabled
5906
- this._initializeObservers();
5907
- this._syncClearControlState();
5908
- this._updateInputDisplay();
5909
- this._renderOptions();
6052
+ if (this.isConnected) {
6053
+ this._syncDirectionConfig();
6054
+ this._syncInputContainerMode();
6055
+ this._syncMultiSelectDisplayConfig();
6056
+ this._syncDropdownPlacement();
6057
+ // Re-initialize observers in case infinite scroll was enabled/disabled
6058
+ this._initializeObservers();
6059
+ this._syncClearControlState();
6060
+ this._updateInputDisplay();
6061
+ this._renderOptions();
6062
+ }
6063
+ else {
6064
+ this._syncInputContainerMode();
6065
+ this._syncMultiSelectDisplayConfig();
6066
+ this._syncClearControlState();
6067
+ this._updateInputDisplay();
6068
+ }
5910
6069
  }
5911
6070
  _mergeConfig(target, source) {
5912
6071
  const result = { ...target };
5913
- for (const key in source) {
6072
+ // PERF: Avoid for...in, use Object.keys for predictable iteration
6073
+ const keys = Object.keys(source);
6074
+ for (let i = 0; i < keys.length; i++) {
6075
+ const key = keys[i];
5914
6076
  if (!Object.prototype.hasOwnProperty.call(source, key))
5915
6077
  continue;
5916
6078
  const sourceValue = source[key];
5917
6079
  const targetValue = result[key];
6080
+ // Optional adapter props are commonly forwarded as undefined. Preserve
6081
+ // the existing/default config in that case instead of erasing a section.
6082
+ if (sourceValue === undefined)
6083
+ continue;
5918
6084
  if (sourceValue && typeof sourceValue === 'object' && !Array.isArray(sourceValue)) {
5919
6085
  result[key] = this._mergeConfig(targetValue && typeof targetValue === 'object' ? targetValue : {}, sourceValue);
5920
6086
  }
@@ -5956,8 +6122,9 @@
5956
6122
  const hasSomethingToClear = (clearSelection && hasSelection) || (clearSearch && hasSearch);
5957
6123
  const hideWhenEmpty = this._config.clearControl.hideWhenEmpty !== false;
5958
6124
  const visible = enabled && (!hideWhenEmpty || hasSomethingToClear);
5959
- this._inputContainer.classList.toggle('has-clear-control', enabled);
5960
- this._arrowContainer.classList.toggle('with-clear-control', enabled);
6125
+ // Reserve the action area only while the clear control is actually visible.
6126
+ this._inputContainer.classList.toggle('has-clear-control', visible);
6127
+ this._arrowContainer.classList.toggle('with-clear-control', visible);
5961
6128
  this._clearControl.hidden = !visible;
5962
6129
  this._clearControl.disabled = !hasSomethingToClear;
5963
6130
  this._clearControl.setAttribute('aria-hidden', String(!visible));
@@ -6252,6 +6419,9 @@
6252
6419
  this._handleOptionRemove(targetIndex);
6253
6420
  });
6254
6421
  targetContainer.appendChild(option);
6422
+ if (option instanceof SelectOption) {
6423
+ option.ensureRendered();
6424
+ }
6255
6425
  }
6256
6426
  _normalizeCustomOptionElement(element, meta) {
6257
6427
  const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
@@ -6428,6 +6598,58 @@
6428
6598
  this.supportsWorkers = false;
6429
6599
  this.supportsSharedArrayBuffer = false;
6430
6600
  this.nextId = 0;
6601
+ /**
6602
+ * Operation handlers for fallback execution
6603
+ */
6604
+ this._fallbackOperations = {
6605
+ 'transform': (payload) => {
6606
+ const { items, transformer } = payload;
6607
+ const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
6608
+ return items.map((item, i) => fn(item, i));
6609
+ },
6610
+ 'search': (payload) => {
6611
+ const { items, query, fuzzy } = payload;
6612
+ const lowerQuery = query.toLowerCase();
6613
+ const results = [];
6614
+ // Use for-loop instead of forEach for better performance (no closure allocation)
6615
+ for (let index = 0; index < items.length; index++) {
6616
+ const item = items[index];
6617
+ // PERF: Check for label/value properties first before converting entire object
6618
+ const itemAny = item;
6619
+ const itemText = itemAny?.label ?? itemAny?.value ?? item;
6620
+ const itemStr = String(itemText).toLowerCase();
6621
+ if (fuzzy) {
6622
+ // Simple fuzzy match - check if all query chars appear in order
6623
+ let queryIndex = 0;
6624
+ for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
6625
+ if (itemStr[i] === lowerQuery[queryIndex]) {
6626
+ queryIndex++;
6627
+ }
6628
+ }
6629
+ if (queryIndex === lowerQuery.length) {
6630
+ results.push({ item, index });
6631
+ }
6632
+ }
6633
+ else {
6634
+ // Exact substring match
6635
+ if (itemStr.includes(lowerQuery)) {
6636
+ results.push({ item, index });
6637
+ }
6638
+ }
6639
+ }
6640
+ return results;
6641
+ },
6642
+ 'filter': (payload) => {
6643
+ const { items, predicate } = payload;
6644
+ const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
6645
+ return items.filter((item, i) => fn(item, i));
6646
+ },
6647
+ 'sort': (payload) => {
6648
+ const { items, comparator } = payload;
6649
+ const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
6650
+ return [...items].sort(fn);
6651
+ },
6652
+ };
6431
6653
  this.detectFeatures();
6432
6654
  this.initWorker();
6433
6655
  }
@@ -6469,27 +6691,23 @@
6469
6691
  const start = performance.now();
6470
6692
  const { id, type, payload } = e.data;
6471
6693
 
6694
+ // Lookup object for O(1) operation dispatch
6695
+ const operations = {
6696
+ 'transform': handleTransform,
6697
+ 'search': handleSearch,
6698
+ 'filter': handleFilter,
6699
+ 'sort': handleSort,
6700
+ };
6701
+
6472
6702
  try {
6473
- let result;
6474
-
6475
- switch (type) {
6476
- case 'transform':
6477
- result = handleTransform(payload);
6478
- break;
6479
- case 'search':
6480
- result = handleSearch(payload);
6481
- break;
6482
- case 'filter':
6483
- result = handleFilter(payload);
6484
- break;
6485
- case 'sort':
6486
- result = handleSort(payload);
6487
- break;
6488
- default:
6489
- throw new Error('Unknown operation: ' + type);
6703
+ const handler = operations[type];
6704
+ if (!handler) {
6705
+ throw new Error('Unknown operation: ' + type);
6490
6706
  }
6491
6707
 
6708
+ const result = handler(payload);
6492
6709
  const duration = performance.now() - start;
6710
+
6493
6711
  self.postMessage({
6494
6712
  id,
6495
6713
  success: true,
@@ -6621,53 +6839,11 @@
6621
6839
  * Fallback to main thread execution
6622
6840
  */
6623
6841
  async executeFallback(type, payload) {
6624
- // Simple synchronous fallback implementations
6625
- switch (type) {
6626
- case 'transform': {
6627
- const { items, transformer } = payload;
6628
- const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
6629
- return items.map((item, i) => fn(item, i));
6630
- }
6631
- case 'search': {
6632
- const { items, query, fuzzy } = payload;
6633
- const lowerQuery = query.toLowerCase();
6634
- const results = [];
6635
- items.forEach((item, index) => {
6636
- const itemStr = String(item).toLowerCase();
6637
- if (fuzzy) {
6638
- // Simple fuzzy match - check if all query chars appear in order
6639
- let queryIndex = 0;
6640
- for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
6641
- if (itemStr[i] === lowerQuery[queryIndex]) {
6642
- queryIndex++;
6643
- }
6644
- }
6645
- if (queryIndex === lowerQuery.length) {
6646
- results.push({ item, index });
6647
- }
6648
- }
6649
- else {
6650
- // Exact substring match
6651
- if (itemStr.includes(lowerQuery)) {
6652
- results.push({ item, index });
6653
- }
6654
- }
6655
- });
6656
- return results;
6657
- }
6658
- case 'filter': {
6659
- const { items, predicate } = payload;
6660
- const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
6661
- return items.filter((item, i) => fn(item, i));
6662
- }
6663
- case 'sort': {
6664
- const { items, comparator } = payload;
6665
- const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
6666
- return [...items].sort(fn);
6667
- }
6668
- default:
6669
- throw new Error(`Unknown operation: ${type}`);
6842
+ const handler = this._fallbackOperations[type];
6843
+ if (!handler) {
6844
+ throw new Error(`Unknown operation: ${type}`);
6670
6845
  }
6846
+ return handler(payload);
6671
6847
  }
6672
6848
  /**
6673
6849
  * Transform items with custom function
@@ -7431,6 +7607,8 @@
7431
7607
  exports.WorkerManager = WorkerManager;
7432
7608
  exports.applyClasses = applyClasses;
7433
7609
  exports.applyDefaultTheme = applyDefaultTheme;
7610
+ exports.arrayIncludesValue = arrayIncludesValue;
7611
+ exports.arraysEqualByValue = arraysEqualByValue;
7434
7612
  exports.configureSelect = configureSelect;
7435
7613
  exports.containsSuspiciousPatterns = containsSuspiciousPatterns;
7436
7614
  exports.createElement = createElement;
@@ -7460,6 +7638,7 @@
7460
7638
  exports.shadowDOMStyles = shadowDOMStyles;
7461
7639
  exports.toggleClass = toggleClass;
7462
7640
  exports.validateTemplate = validateTemplate;
7641
+ exports.valuesEqual = valuesEqual;
7463
7642
  exports.warnCSPViolation = warnCSPViolation;
7464
7643
 
7465
7644
  }));