@smilodon/svelte 1.9.3 → 1.10.0

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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @smilodon/svelte
2
2
 
3
- Production-ready, accessible select component for Svelte applications. Part of the [Smilodon](https://github.com/navidrezadoost/smilodon) UI toolkit.
3
+ Select component for Svelte applications. The shared core has scoped automated Phase 4 browser coverage; exhaustive Svelte integration parity and manual assistive-technology certification remain unverified. Part of the [Smilodon](https://github.com/navidrezadoost/smilodon) UI toolkit.
4
+
5
+ > Large-list status: the public `virtualized` prop enables legacy chunked rendering for large flat lists; it does not window rows to the viewport, and all results may eventually be mounted. True viewport virtualization remains guarded by a private test seam and is not a supported production mode. The shared core passed its scoped Phase 4 automated browser matrix in Chromium, Firefox, and WebKit; this does not establish exhaustive Svelte integration parity, minimum-browser-version support, or WCAG conformance. Manual assistive-technology assessment remains pending. See the [current limitation record](../../docs/KNOWN-LIMITATIONS.md#viewport-virtualization-status).
4
6
 
5
7
  ## 📖 Documentation
6
8
 
@@ -12,12 +14,14 @@ Production-ready, accessible select component for Svelte applications. Part of t
12
14
 
13
15
  👉 **[Complete Svelte Guide](./COMPLETE-GUIDE.md)** 👈
14
16
 
17
+ The Quick Start and examples with a complete `<script>` block are intended to stand alone. Short renderer, accessibility, and troubleshooting examples are explicitly identified as fragments when they rely on surrounding component state.
18
+
15
19
  The complete guide includes:
16
20
  - ✅ Complete styling token coverage for colors, layout, chips, motion, and accessibility
17
21
  - ✅ Svelte-specific patterns (reactive statements, stores, bind:value)
18
22
  - ✅ Complete API reference with TypeScript types
19
23
  - ✅ Svelte stores integration (writable, derived)
20
- - ✅ Custom renderers returning HTML strings
24
+ - ✅ DOM option renderers returning `HTMLElement` values; do not return HTML strings
21
25
  - ✅ Theme examples with :global() styling
22
26
  - ✅ Advanced patterns (Context API, reactive dependencies)
23
27
  - ✅ Troubleshooting and accessibility information
@@ -26,40 +30,35 @@ The complete guide includes:
26
30
 
27
31
  ## Features
28
32
 
29
- - New: `optionRenderer` prop (Option B) lets you return an `HTMLElement` for custom DOM-driven option layouts.
33
+ - `optionRenderer` is the Svelte adapter's DOM renderer prop and must return an `HTMLElement`. There is no HTML-string template prop on this adapter.
30
34
 
31
35
  ### Advanced scenarios (Svelte)
32
- - **A11y-first**:
36
+ - **Accessibility labels**: use a literal `aria-label` for the internal combobox; host IDREF attributes are not forwarded across the shadow boundary. A neighboring external label is not proof of native label association:
33
37
  ```svelte
34
- <label id="city-label" for="city-picker">City</label>
35
- <Select id="city-picker" aria-labelledby="city-label" />
38
+ <label for="city-picker">City</label>
39
+ <Select id="city-picker" aria-label="City" />
36
40
  ```
37
41
  - **Server-side lookup**:
38
42
  ```svelte
39
- <Select bind:this={picker} searchable on:search={(e) => load(e.detail.query)} />
40
-
41
- async function load(q) {
42
- const res = await fetch(`/api/cities?q=${encodeURIComponent(q)}`);
43
- const items = await res.json();
44
- picker?.setItems(items);
45
- }
43
+ <!-- Fragment: assumes items and handleSearch are declared in this component. -->
44
+ <Select {items} searchable on:search={handleSearch} />
46
45
  ```
47
- - **Heavy lists (100k+)**:
46
+ - **Large flat lists**: the public setting enables chunked rendering, not viewport windowing:
48
47
  ```svelte
49
- <Select {items} virtualized estimatedItemHeight={44} />
50
48
  <script>
51
49
  export let items = Array.from({ length: 100_000 }, (_, i) => ({ value: i, label: `Item ${i}` }));
52
50
  </script>
51
+ <Select {items} virtualized />
53
52
  ```
54
53
 
55
54
  - ✨ **Single & Multi-Select** - Choose one or multiple options
56
55
  - 🔍 **Searchable** - Filter options with built-in or custom search
57
- - ♿ **Fully Accessible** - WCAG 2.1 AAA compliant
58
- - ⚡ **Virtual Scrolling** - Handle 100k+ options smoothly
56
+ - ♿ **Accessibility behaviors** - Shared-core scenarios passed in the scoped Chromium/Firefox/WebKit Phase 4 matrix; exhaustive Svelte adapter parity, manual AT, and WCAG conformance are not established
57
+ - ⚡ **Large-list chunk rendering** - Incrementally render large flat lists; not viewport windowing
59
58
  - 📜 **Infinite Scroll** - Load data progressively
60
59
  - 👥 **Grouped Options** - Organize options into categories
61
60
  - 🎨 **Customizable** - Style with CSS variables or custom themes
62
- - 📦 **Tiny Bundle** - ~2KB gzipped
61
+ - 📦 **Bundle guidance** - No version-specific bundle-size measurement is claimed; measure your published entry and bundler output if size is a release requirement
63
62
  - 🔧 **TypeScript** - Full type safety included
64
63
 
65
64
  ## Installation
@@ -70,7 +69,7 @@ npm install @smilodon/svelte @smilodon/core
70
69
 
71
70
  ## SvelteKit / SSR Notes
72
71
 
73
- The Svelte adapter waits for `enhanced-select` to be defined during `onMount()`, so it is safe to use in SvelteKit pages as long as imperative browser-only code stays inside lifecycle hooks.
72
+ The adapter imports the core package and performs imperative element work from its browser lifecycle. This helps avoid server-only DOM access, but does not by itself certify SSR/hydration behavior across all SvelteKit versions, render modes, or bundler configurations.
74
73
 
75
74
  ### Recommended pattern
76
75
 
@@ -95,6 +94,7 @@ The Svelte adapter waits for `enhanced-select` to be defined during `onMount()`,
95
94
  - Avoid direct `window`, `document`, or custom-element access outside `onMount()`.
96
95
  - Use `bind:value` for regular selection flow and exported instance methods for imperative control.
97
96
  - Prefer `optionRenderer` when you need DOM-driven custom options and plain markup when you do not.
97
+ - If your SSR/hydration setup reports mismatches, keep this interactive control behind the framework's client-only lifecycle boundary and verify the exact production build mode.
98
98
 
99
99
  ## Quick Start
100
100
 
@@ -143,7 +143,7 @@ The Svelte adapter waits for `enhanced-select` to be defined during `onMount()`,
143
143
 
144
144
  Styling hooks: `::part(clear-button)` and `::part(clear-icon)` plus `--select-clear-*` CSS tokens.
145
145
 
146
- An empty clearable field reserves no clear-button space by default. The control and its coordinated input/arrow spacing appear when a selected value or enabled search query can be cleared, then disappear once both targets are empty. The same rule applies to single, multi-select, LTR, and RTL layouts.
146
+ An empty clearable field reserves no clear-button space by default. The control and its coordinated input/arrow spacing appear when a selected value or enabled search query can be cleared, then disappear once both targets are empty. This describes the shared runtime's intended behavior across single/multi-select and LTR/RTL configurations, not exhaustive Svelte integration certification.
147
147
 
148
148
  Use full config passthrough when a permanently visible disabled-when-empty action is required:
149
149
 
@@ -322,7 +322,7 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
322
322
  { value: 'mx', label: 'Mexico' },
323
323
  ];
324
324
 
325
- let country;
325
+ let country: string | number = '';
326
326
  </script>
327
327
 
328
328
  <Select
@@ -345,7 +345,7 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
345
345
  { value: 'py', label: 'Python' },
346
346
  ];
347
347
 
348
- let languages = [];
348
+ let languages: Array<string | number> = [];
349
349
  </script>
350
350
 
351
351
  <Select
@@ -358,28 +358,30 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
358
358
 
359
359
  ### Grouped Options
360
360
 
361
+ Svelte uses the core grouped-data contract `{ label, options }`. This differs from the Vanilla helper contract `{ group, items }`; do not copy the Vanilla shape into a Svelte `groupedItems` prop.
362
+
361
363
  ```svelte
362
364
  <script lang="ts">
363
365
  import { Select } from '@smilodon/svelte';
364
366
 
365
367
  const groupedItems = [
366
368
  {
367
- group: 'Fruits',
368
- items: [
369
+ label: 'Fruits',
370
+ options: [
369
371
  { value: 'apple', label: 'Apple' },
370
372
  { value: 'banana', label: 'Banana' },
371
373
  ],
372
374
  },
373
375
  {
374
- group: 'Vegetables',
375
- items: [
376
+ label: 'Vegetables',
377
+ options: [
376
378
  { value: 'carrot', label: 'Carrot' },
377
379
  { value: 'potato', label: 'Potato' },
378
380
  ],
379
381
  },
380
382
  ];
381
383
 
382
- let food;
384
+ let food: string | number = '';
383
385
  </script>
384
386
 
385
387
  <Select {groupedItems} bind:value={food} />
@@ -391,17 +393,25 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
391
393
  <script lang="ts">
392
394
  import { Select } from '@smilodon/svelte';
393
395
 
394
- let items = generateItems(1, 50);
395
- let page = 1;
396
-
397
- function handleLoadMore() {
398
- page++;
399
- const newItems = generateItems(page * 50 + 1, (page + 1) * 50);
400
- items = [...items, ...newItems];
396
+ const pageSize = 50;
397
+ const total = 500;
398
+ let items = makeItems(1, pageSize);
399
+ let loading = false;
400
+ const loadedPages = new Set<number>([1]);
401
+
402
+ function handleLoadMore(event: CustomEvent<{ page: number }>) {
403
+ const requestedPage = event.detail.page;
404
+ if (loading || loadedPages.has(requestedPage) || items.length >= total) return;
405
+ loading = true;
406
+ const start = items.length + 1;
407
+ const count = Math.min(pageSize, total - items.length);
408
+ items = [...items, ...makeItems(start, count)];
409
+ loadedPages.add(requestedPage);
410
+ loading = false;
401
411
  }
402
412
 
403
- function generateItems(start, end) {
404
- return Array.from({ length: end - start + 1 }, (_, i) => ({
413
+ function makeItems(start: number, count: number) {
414
+ return Array.from({ length: count }, (_, i) => ({
405
415
  value: start + i,
406
416
  label: `Item ${start + i}`,
407
417
  }));
@@ -411,13 +421,15 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
411
421
  <Select
412
422
  {items}
413
423
  infiniteScroll
414
- pageSize={50}
424
+ pageSize={pageSize}
415
425
  on:loadMore={handleLoadMore}
416
426
  placeholder="Scroll to load more..."
417
427
  />
418
428
  ```
419
429
 
420
- ### Virtual Scrolling (Large Datasets)
430
+ This local example guards synchronous repeated callbacks and fills consecutive item ranges (1–50, 51–100, and so on). For remote pagination, keep the guard active until the request settles, handle errors and server end-of-data, and track pages so duplicate events cannot append the same page twice. The component forwards a `loadMore` event; the host owns data transport and state.
431
+
432
+ ### Incremental Chunk Rendering (Large Datasets)
421
433
 
422
434
  ```svelte
423
435
  <script lang="ts">
@@ -434,7 +446,7 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
434
446
  {items}
435
447
  virtualized
436
448
  searchable
437
- placeholder="100k items with virtual scrolling..."
449
+ placeholder="100k items with incremental chunk rendering..."
438
450
  />
439
451
  ```
440
452
 
@@ -442,25 +454,42 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
442
454
 
443
455
  ```svelte
444
456
  <script lang="ts">
445
- import { Select } from '@smilodon/svelte';
457
+ import { Select, type SelectItem } from '@smilodon/svelte';
458
+ import { onDestroy } from 'svelte';
446
459
 
447
- let items = [];
460
+ let items: SelectItem[] = [];
448
461
  let isLoading = false;
462
+ let searchError = '';
463
+ let controller: AbortController | undefined;
464
+ let requestId = 0;
449
465
 
450
- async function handleSearch(event) {
466
+ async function handleSearch(event: CustomEvent<{ query: string }>) {
451
467
  const query = event.detail.query;
468
+ const id = ++requestId;
469
+ controller?.abort();
452
470
 
453
471
  if (!query) {
454
472
  items = [];
473
+ isLoading = false;
474
+ searchError = '';
455
475
  return;
456
476
  }
457
477
 
478
+ const current = new AbortController();
479
+ controller = current;
458
480
  isLoading = true;
459
- const response = await fetch(`/api/search?q=${query}`);
460
- const data = await response.json();
461
- items = data.results;
462
- isLoading = false;
481
+ try {
482
+ const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`, { signal: current.signal });
483
+ if (!response.ok) throw new Error(`Search failed: ${response.status}`);
484
+ const data = await response.json() as { results: SelectItem[] };
485
+ if (id === requestId) { items = data.results; searchError = ''; }
486
+ } catch (error) {
487
+ if (!(error instanceof DOMException && error.name === 'AbortError') && id === requestId) searchError = String(error);
488
+ } finally {
489
+ if (id === requestId) isLoading = false;
490
+ }
463
491
  }
492
+ onDestroy(() => controller?.abort());
464
493
  </script>
465
494
 
466
495
  <Select
@@ -469,10 +498,16 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
469
498
  on:search={handleSearch}
470
499
  placeholder="Type to search..."
471
500
  />
501
+ {#if isLoading}<p role="status">Searching…</p>{/if}
502
+ {#if searchError}<p role="alert">{searchError}</p>{/if}
472
503
  ```
473
504
 
505
+ The `search` callback can fire rapidly while typing. Cancellation plus a request sequence check prevents a slower old response from replacing newer results. Render `isLoading` and `searchError` in the host UI as needed; Smilodon does not own the network request.
506
+
474
507
  ### Controlled Component
475
508
 
509
+ Use `bind:value` when the Svelte component's two-way binding is the intended state contract. Use explicit `value` plus `on:change` when the parent/store owns updates, and pass a changed value back to the component. `defaultValue` is for an initial value that the component then manages; do not mix these models in one example.
510
+
476
511
  ```svelte
477
512
  <script lang="ts">
478
513
  import { Select } from '@smilodon/svelte';
@@ -483,11 +518,12 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
483
518
  { value: 'archived', label: 'Archived' },
484
519
  ];
485
520
 
486
- let status = 'draft';
521
+ let status: string | number = 'draft';
487
522
 
488
- function handleChange(event) {
523
+ function handleChange(event: CustomEvent<{ value: string | number | (string | number)[] }>) {
489
524
  console.log('Status changed:', event.detail.value);
490
- status = event.detail.value;
525
+ const next = event.detail.value;
526
+ status = Array.isArray(next) ? next[0] ?? '' : next;
491
527
  }
492
528
  </script>
493
529
 
@@ -508,15 +544,15 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
508
544
  <script lang="ts">
509
545
  import { Select } from '@smilodon/svelte';
510
546
 
511
- let selectRef;
512
- const items = [...];
547
+ let selectRef: { open: () => void; clear: () => void } | undefined;
548
+ const items = [{ value: 'alpha', label: 'Alpha' }];
513
549
 
514
550
  function programmaticOpen() {
515
- selectRef.open();
551
+ selectRef?.open();
516
552
  }
517
553
 
518
554
  function programmaticClear() {
519
- selectRef.clear();
555
+ selectRef?.clear();
520
556
  }
521
557
  </script>
522
558
 
@@ -542,11 +578,15 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
542
578
  | `error` | `boolean` | `false` | Show error state |
543
579
  | `infiniteScroll` | `boolean` | `false` | Enable infinite scroll |
544
580
  | `pageSize` | `number` | `50` | Items per page (infinite scroll) |
545
- | `virtualized` | `boolean` | `true` | Enable virtual scrolling |
581
+ | `virtualized` | `boolean` | `true` | Enable legacy chunked rendering for large flat lists; not viewport windowing |
546
582
  | `maxSelections` | `number` | `undefined` | Max selections (multi-select) |
547
583
  | `placement` | `'bottom' \| 'top' \| 'auto'` | `'auto'` | Dropdown placement |
548
584
  | `className` | `string` | `''` | Custom CSS class |
549
585
  | `style` | `string` | `''` | Custom inline styles |
586
+ | `selectionConfig`, `multiSelectDisplay`, `scrollToSelected`, `styles`, `config` | core configuration types | - | Shared runtime configuration groups |
587
+ | `optionRenderer` | `(item, index, helpers) => HTMLElement` | - | DOM option renderer; must return an element, not an HTML string |
588
+ | `clearable`, `clearSelectionOnClear`, `clearSearchOnClear`, `clearAriaLabel`, `clearIcon` | booleans / strings | - | Clear-control configuration |
589
+ | `trackingEnabled`, `trackEvents`, `trackStyling`, `trackLimitations`, `emitDiagnostics`, `trackingMaxEntries`, `limitationPolicies`, `autoMitigateRuntimeModeSwitch` | documented tracking/limitation types | - | Runtime diagnostics and limitation policies |
550
590
 
551
591
  ## Events
552
592
 
@@ -559,6 +599,8 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
559
599
  | `search` | `{ query }` | Search query changed |
560
600
  | `loadMore` | `{ page }` | Load more requested |
561
601
  | `create` | `{ value }` | New item creation |
602
+ | `clear` | `{ clearedSelection, clearedSearch }` | Clear control used |
603
+ | `diagnostic` | Diagnostic detail | Runtime diagnostics enabled |
562
604
 
563
605
  ## Methods
564
606
 
@@ -572,6 +614,14 @@ Access these methods using `bind:this`:
572
614
  | `clear()` | `() => void` | Clear selection |
573
615
  | `setItems()` | `(items: SelectItem[]) => void` | Update items |
574
616
  | `setGroupedItems()` | `(groups: GroupedItem[]) => void` | Update grouped items |
617
+ | `clearSearch()` | `() => void` | Clear the search query |
618
+ | `updateCoreConfig()` | `(config: Partial<GlobalSelectConfig>) => void` | Apply core runtime configuration |
619
+ | `setError()` / `clearError()` | message / no arguments | Set or clear validation error state |
620
+ | `setRequiredState()` | `(required: boolean) => void` | Change required state |
621
+ | `validate()` | `() => boolean` | Validate current state |
622
+ | `getCapabilities()` / `getKnownLimitations()` | reports | Read capabilities and current limitations |
623
+ | `getTrackingSnapshot()` / `clearTracking(source?)` | snapshot / source | Inspect or clear tracking data |
624
+ | `setLimitationPolicies()` | `(policies) => void` | Set limitation-handling policies |
575
625
 
576
626
  ## Types
577
627
 
@@ -585,8 +635,8 @@ interface SelectItem {
585
635
  }
586
636
 
587
637
  interface GroupedItem {
588
- group: string;
589
- items: SelectItem[];
638
+ label: string;
639
+ options: SelectItem[];
590
640
  }
591
641
  ```
592
642
 
@@ -605,7 +655,7 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
605
655
  - ✅ Auto-conversion from strings/numbers
606
656
  - ✅ Perfect for basic dropdowns
607
657
  - ✅ Works seamlessly with Svelte stores
608
- - ✅ Extremely performant (millions of items)
658
+ - ✅ Suitable for host-managed datasets whose scale has been measured in the target application; no millions-of-items or constant-DOM guarantee is made
609
659
  - ✅ Built-in search and filtering
610
660
  - ✅ Full TypeScript type safety
611
661
 
@@ -730,7 +780,7 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
730
780
 
731
781
  ### Method 2: Component-Driven (Custom Renderers) 🎨
732
782
 
733
- **Use when**: You need rich, interactive option content with custom HTML/styling.
783
+ **Use when**: You need richer text, images, icons, badges, or multi-line option content with custom styling. The option remains one listbox option: do not put nested buttons, links, or other independently interactive controls inside it.
734
784
 
735
785
  **Advantages**:
736
786
  - ✅ Full control over option rendering
@@ -741,7 +791,7 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
741
791
  - ✅ Works with Svelte stores
742
792
  - ✅ Perfect for complex UIs (user cards, product listings, etc.)
743
793
 
744
- **How it works**: Provide an `optionTemplate` function that returns HTML string for each option.
794
+ **How it works**: Provide the exported `optionRenderer` prop and return an `HTMLElement` for each option. Build nodes with DOM APIs and put labels or other untrusted data in `textContent`; the Svelte adapter does not accept HTML strings as renderer output.
745
795
 
746
796
  **Examples**:
747
797
 
@@ -763,21 +813,25 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
763
813
  { value: 'rs', label: 'Rust', icon: '🦀', description: 'Systems programming language' }
764
814
  ];
765
815
 
766
- const languageRenderer = (item: Language, index: number) => `
767
- <div style="display: flex; align-items: center; gap: 12px;">
768
- <span style="font-size: 24px;">${item.icon}</span>
769
- <div>
770
- <div style="font-weight: 600;">${item.label}</div>
771
- <div style="font-size: 12px; color: #6b7280;">${item.description}</div>
772
- </div>
773
- </div>
774
- `;
816
+ const languageRenderer = (item: Language, index: number): HTMLElement => {
817
+ const row = document.createElement('div');
818
+ row.style.cssText = 'display:flex;align-items:center;gap:12px';
819
+ const icon = document.createElement('span');
820
+ icon.style.fontSize = '24px'; icon.textContent = item.icon;
821
+ const content = document.createElement('div');
822
+ const title = document.createElement('strong'); title.textContent = item.label;
823
+ const description = document.createElement('small');
824
+ description.style.cssText = 'display:block;font-size:12px;color:#6b7280';
825
+ description.textContent = item.description;
826
+ content.append(title, description); row.append(icon, content);
827
+ return row;
828
+ };
775
829
  </script>
776
830
 
777
831
  <Select
778
832
  items={languages}
779
833
  bind:value={lang}
780
- optionTemplate={languageRenderer}
834
+ optionRenderer={languageRenderer}
781
835
  placeholder="Select a language..."
782
836
  />
783
837
  ```
@@ -819,33 +873,28 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
819
873
  }
820
874
  ];
821
875
 
822
- const userRenderer = (item: User) => `
823
- <div style="display: flex; align-items: center; gap: 12px; padding: 4px 0;">
824
- <img
825
- src="${item.avatar}"
826
- alt="${item.label}"
827
- style="width: 40px; height: 40px; border-radius: 50%; object-fit: cover;"
828
- />
829
- <div style="flex: 1;">
830
- <div style="font-weight: 600; color: #1f2937;">${item.label}</div>
831
- <div style="font-size: 13px; color: #6b7280;">${item.email}</div>
832
- </div>
833
- <span style="
834
- padding: 4px 8px;
835
- background: ${item.role === 'Admin' ? '#dbeafe' : '#f3f4f6'};
836
- color: ${item.role === 'Admin' ? '#1e40af' : '#374151'};
837
- border-radius: 12px;
838
- font-size: 11px;
839
- font-weight: 600;
840
- ">${item.role}</span>
841
- </div>
842
- `;
876
+ const userRenderer = (item: User): HTMLElement => {
877
+ const row = document.createElement('div');
878
+ row.style.cssText = 'display:flex;align-items:center;gap:12px;padding:4px 0';
879
+ const image = document.createElement('img');
880
+ // Only use avatar URLs from a trusted/validated source.
881
+ image.src = item.avatar; image.alt = ''; image.setAttribute('aria-hidden', 'true');
882
+ image.style.cssText = 'width:40px;height:40px;border-radius:50%;object-fit:cover';
883
+ const details = document.createElement('div'); details.style.flex = '1';
884
+ const name = document.createElement('strong'); name.style.color = '#1f2937'; name.textContent = item.label;
885
+ const email = document.createElement('div'); email.style.cssText = 'font-size:13px;color:#6b7280'; email.textContent = item.email;
886
+ details.append(name, email);
887
+ const role = document.createElement('span'); role.textContent = item.role;
888
+ role.style.cssText = `padding:4px 8px;border-radius:12px;font-size:11px;font-weight:600;background:${item.role === 'Admin' ? '#dbeafe' : '#f3f4f6'};color:${item.role === 'Admin' ? '#1e40af' : '#374151'}`;
889
+ row.append(image, details, role);
890
+ return row;
891
+ };
843
892
  </script>
844
893
 
845
894
  <Select
846
895
  items={users}
847
896
  bind:value={userId}
848
- optionTemplate={userRenderer}
897
+ optionRenderer={userRenderer}
849
898
  placeholder="Select a user..."
850
899
  />
851
900
  ```
@@ -890,40 +939,36 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
890
939
  }
891
940
  ];
892
941
 
893
- const productRenderer = (item: Product) => `
894
- <div style="display: flex; align-items: center; gap: 12px; opacity: ${item.stock === 0 ? '0.5' : '1'};">
895
- <img
896
- src="${item.image}"
897
- alt="${item.label}"
898
- style="width: 60px; height: 60px; border-radius: 8px; object-fit: cover; border: 1px solid #e5e7eb;"
899
- />
900
- <div style="flex: 1;">
901
- <div style="display: flex; align-items: center; gap: 8px;">
902
- <span style="font-weight: 600; color: #1f2937;">${item.label}</span>
903
- ${item.badge ? `
904
- <span style="
905
- padding: 2px 6px;
906
- background: ${item.badge === 'Best Seller' ? '#dcfce7' : '#fee2e2'};
907
- color: ${item.badge === 'Best Seller' ? '#166534' : '#991b1b'};
908
- border-radius: 4px;
909
- font-size: 10px;
910
- font-weight: 600;
911
- ">${item.badge}</span>
912
- ` : ''}
913
- </div>
914
- <div style="margin-top: 4px; display: flex; justify-content: space-between; align-items: center;">
915
- <span style="font-size: 16px; font-weight: 700; color: #059669;">$${item.price.toFixed(2)}</span>
916
- <span style="font-size: 12px; color: #6b7280;">${item.stock > 0 ? `${item.stock} in stock` : 'Out of stock'}</span>
917
- </div>
918
- </div>
919
- </div>
920
- `;
942
+ const productRenderer = (item: Product): HTMLElement => {
943
+ const row = document.createElement('div');
944
+ row.style.cssText = `display:flex;align-items:center;gap:12px;opacity:${item.stock === 0 ? '0.5' : '1'}`;
945
+ const image = document.createElement('img');
946
+ // Only use image URLs from a trusted/validated source.
947
+ image.src = item.image; image.alt = ''; image.setAttribute('aria-hidden', 'true');
948
+ image.style.cssText = 'width:60px;height:60px;border-radius:8px;object-fit:cover;border:1px solid #e5e7eb';
949
+ const content = document.createElement('div'); content.style.flex = '1';
950
+ const heading = document.createElement('div'); heading.style.cssText = 'display:flex;align-items:center;gap:8px';
951
+ const title = document.createElement('strong'); title.style.color = '#1f2937'; title.textContent = item.label;
952
+ heading.append(title);
953
+ if (item.badge) {
954
+ const badge = document.createElement('span'); badge.textContent = item.badge;
955
+ badge.style.cssText = `padding:2px 6px;border-radius:4px;font-size:10px;font-weight:600;background:${item.badge === 'Best Seller' ? '#dcfce7' : '#fee2e2'};color:${item.badge === 'Best Seller' ? '#166534' : '#991b1b'}`;
956
+ heading.append(badge);
957
+ }
958
+ const metadata = document.createElement('div');
959
+ metadata.style.cssText = 'margin-top:4px;display:flex;justify-content:space-between;align-items:center';
960
+ const price = document.createElement('strong'); price.style.cssText = 'font-size:16px;color:#059669'; price.textContent = `$${item.price.toFixed(2)}`;
961
+ const stock = document.createElement('span'); stock.style.cssText = 'font-size:12px;color:#6b7280';
962
+ stock.textContent = item.stock > 0 ? `${item.stock} in stock` : 'Out of stock';
963
+ metadata.append(price, stock); content.append(heading, metadata); row.append(image, content);
964
+ return row;
965
+ };
921
966
  </script>
922
967
 
923
968
  <Select
924
969
  items={products}
925
970
  bind:value={productId}
926
- optionTemplate={productRenderer}
971
+ optionRenderer={productRenderer}
927
972
  placeholder="Select a product..."
928
973
  />
929
974
  ```
@@ -960,42 +1005,28 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
960
1005
  'low': '#10b981'
961
1006
  };
962
1007
 
963
- const taskRenderer = (item: Task) => {
1008
+ const taskRenderer = (item: Task): HTMLElement => {
964
1009
  const status = statusConfig[item.status];
965
- return `
966
- <div style="display: flex; align-items: center; gap: 10px; padding: 4px 0;">
967
- <div style="
968
- width: 24px;
969
- height: 24px;
970
- border-radius: 50%;
971
- background: ${status.bg};
972
- color: ${status.color};
973
- display: flex;
974
- align-items: center;
975
- justify-content: center;
976
- font-weight: bold;
977
- ">${status.icon}</div>
978
- <div style="flex: 1;">
979
- <div style="font-weight: 600; color: #1f2937;">${item.label}</div>
980
- <div style="font-size: 12px; color: #6b7280; margin-top: 2px;">
981
- Assigned to ${item.assignee}
982
- </div>
983
- </div>
984
- <div style="
985
- width: 8px;
986
- height: 8px;
987
- border-radius: 50%;
988
- background: ${priorityColors[item.priority]};
989
- " title="${item.priority} priority"></div>
990
- </div>
991
- `;
1010
+ const row = document.createElement('div'); row.style.cssText = 'display:flex;align-items:center;gap:10px;padding:4px 0';
1011
+ const icon = document.createElement('div'); icon.textContent = status.icon;
1012
+ icon.style.cssText = `width:24px;height:24px;border-radius:50%;background:${status.bg};color:${status.color};display:flex;align-items:center;justify-content:center;font-weight:bold`;
1013
+ const details = document.createElement('div'); details.style.flex = '1';
1014
+ const title = document.createElement('strong'); title.style.color = '#1f2937'; title.textContent = item.label;
1015
+ const assignee = document.createElement('div'); assignee.style.cssText = 'font-size:12px;color:#6b7280;margin-top:2px';
1016
+ assignee.textContent = `Assigned to ${item.assignee}`;
1017
+ details.append(title, assignee);
1018
+ const priority = document.createElement('span');
1019
+ priority.title = `${item.priority} priority`;
1020
+ priority.style.cssText = `width:8px;height:8px;border-radius:50%;background:${priorityColors[item.priority]}`;
1021
+ row.append(icon, details, priority);
1022
+ return row;
992
1023
  };
993
1024
  </script>
994
1025
 
995
1026
  <Select
996
1027
  items={tasks}
997
1028
  bind:value={taskId}
998
- optionTemplate={taskRenderer}
1029
+ optionRenderer={taskRenderer}
999
1030
  placeholder="Select a task..."
1000
1031
  />
1001
1032
  ```
@@ -1019,21 +1050,24 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
1019
1050
  { value: 'angular', label: 'Angular', color: 'red', count: 420 }
1020
1051
  ];
1021
1052
 
1022
- const tagRenderer = (item: Tag) => `
1023
- <div style="display: flex; align-items: center; justify-content: space-between; padding: 8px;">
1024
- <div style="display: flex; align-items: center; gap: 8px;">
1025
- <span style="width: 12px; height: 12px; border-radius: 50%; background: ${item.color};"></span>
1026
- <span style="font-weight: 600; color: #1f2937;">${item.label}</span>
1027
- </div>
1028
- <span style="font-size: 14px; color: #6b7280;">${item.count} posts</span>
1029
- </div>
1030
- `;
1053
+ const tagRenderer = (item: Tag): HTMLElement => {
1054
+ const row = document.createElement('div');
1055
+ row.style.cssText = 'display:flex;align-items:center;justify-content:space-between;padding:8px';
1056
+ const details = document.createElement('div'); details.style.cssText = 'display:flex;align-items:center;gap:8px';
1057
+ const marker = document.createElement('span');
1058
+ marker.style.cssText = `width:12px;height:12px;border-radius:50%;background:${item.color}`;
1059
+ const label = document.createElement('strong'); label.style.color = '#1f2937'; label.textContent = item.label;
1060
+ const count = document.createElement('span'); count.style.cssText = 'font-size:14px;color:#6b7280';
1061
+ count.textContent = `${item.count} posts`;
1062
+ details.append(marker, label); row.append(details, count);
1063
+ return row;
1064
+ };
1031
1065
  </script>
1032
1066
 
1033
1067
  <Select
1034
1068
  items={tags}
1035
1069
  bind:value={$tag}
1036
- optionTemplate={tagRenderer}
1070
+ optionRenderer={tagRenderer}
1037
1071
  placeholder="Select a tag..."
1038
1072
  />
1039
1073
  ```
@@ -1042,20 +1076,20 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
1042
1076
 
1043
1077
  | Feature | Method 1: Object Arrays | Method 2: Custom Renderers |
1044
1078
  |---------|------------------------|---------------------------|
1045
- | **Setup Complexity** | ⭐ Simple | ⭐⭐ Moderate |
1046
- | **Rendering Speed** | ⭐⭐⭐ Fastest | ⭐⭐ Fast |
1047
- | **Visual Customization** | ⭐⭐ Limited | ⭐⭐⭐ Unlimited |
1048
- | **Svelte Integration** | ⭐⭐⭐ Seamless | ⭐⭐⭐ Seamless |
1049
- | **Store Support** | ⭐⭐⭐ Full | ⭐⭐⭐ Full |
1050
- | **TypeScript Support** | ⭐⭐⭐ Full | ⭐⭐⭐ Full |
1051
- | **Performance (1M items)** | ⭐⭐⭐ Excellent | ⭐⭐ Good |
1052
- | **Learning Curve** | ⭐ Easy | ⭐⭐ Medium |
1079
+ | **Setup** | Pass an array of option data | Provide a renderer callback |
1080
+ | **Rendering behavior** | Shared runtime renders option labels | Adapter uses the documented HTMLElement renderer |
1081
+ | **Customization** | Data-driven labels and state | Custom non-interactive content; nested controls are not promised |
1082
+ | **Svelte integration** | Bound values and Svelte component events | Same adapter API with custom DOM-rendered content |
1083
+ | **Reactive state** | Bind or control the value using the documented contract | Renderer output follows the adapter's renderer lifecycle |
1084
+ | **TypeScript** | Typed item data and props | Typed renderer callback and props |
1085
+ | **Very large datasets** | No 1M-item certification or performance comparison is claimed | No 1M-item certification or performance comparison is claimed |
1086
+ | **Choosing a method** | Direct for simple options | Use when custom content is required |
1053
1087
 
1054
1088
  **Best Practices**:
1055
1089
 
1056
1090
  ✅ **Use Method 1 (Object Arrays) when**:
1057
1091
  - You need simple text-based options
1058
- - Performance is critical (millions of items)
1092
+ - You have a large dataset and will profile the workload and use host-managed pagination or search where appropriate; no millions-of-items guarantee is made
1059
1093
  - You want minimal code
1060
1094
  - Built-in search/filter is sufficient
1061
1095
  - Working with external APIs returning plain data
@@ -1078,36 +1112,42 @@ You can start with Method 1 and add Method 2 later as your UI evolves:
1078
1112
 
1079
1113
  let value = '';
1080
1114
 
1081
- // Start simple
1082
- const items = ['Option 1', 'Option 2', 'Option 3'];
1115
+ // Start simple with the documented SelectItem shape
1116
+ const items = [
1117
+ { value: 'one', label: 'Option 1' },
1118
+ { value: 'two', label: 'Option 2' },
1119
+ { value: 'three', label: 'Option 3' },
1120
+ ];
1083
1121
 
1084
1122
  // Later, add custom rendering without changing items
1085
- const customRenderer = (item: any, index: number) => `
1086
- <div style="padding: 8px; background: ${index % 2 ? '#f9fafb' : 'white'};">
1087
- <strong>${item.label || item}</strong>
1088
- </div>
1089
- `;
1123
+ const optionRenderer = (item: (typeof items)[number], index: number): HTMLElement => {
1124
+ const row = document.createElement('div');
1125
+ row.style.cssText = `padding:8px;background:${index % 2 ? '#f9fafb' : 'white'}`;
1126
+ const label = document.createElement('strong'); label.textContent = item.label;
1127
+ row.append(label);
1128
+ return row;
1129
+ };
1090
1130
  </script>
1091
1131
 
1092
1132
  <Select
1093
1133
  items={items}
1094
1134
  bind:value
1095
- optionTemplate={customRenderer}
1135
+ optionRenderer={optionRenderer}
1096
1136
  />
1097
1137
  ```
1098
1138
 
1099
1139
  ### Performance Tips
1100
1140
 
1101
1141
  **For Method 1**:
1102
- - Use reactive statements (`$:`) to memoize large item arrays
1103
- - Enable `virtualized` prop for 1000+ items
1142
+ - Use reactive statements (`$:`) only when their dependencies and recomputation behavior are understood; `$:` is not a general-purpose memoization mechanism
1143
+ - `virtualized` enables chunked rendering; it does not bound mounted DOM to the viewport.
1104
1144
  - Enable `infiniteScroll` for dynamic loading
1105
1145
 
1106
1146
  **For Method 2**:
1107
1147
  - Keep renderer function pure (no side effects)
1108
1148
  - Avoid heavy computations in renderer
1109
1149
  - Cache renderer functions when possible
1110
- - Use template literals for cleaner HTML strings
1150
+ - Use DOM APIs and `textContent` in `optionRenderer`; do not interpolate option data into HTML strings
1111
1151
 
1112
1152
  ```svelte
1113
1153
  <script lang="ts">
@@ -1115,28 +1155,30 @@ You can start with Method 1 and add Method 2 later as your UI evolves:
1115
1155
 
1116
1156
  let value = '';
1117
1157
 
1118
- // Memoize items with reactive statement
1119
- $: items = Array.from({ length: 10000 }, (_, i) => ({
1158
+ // Stable example data. A Svelte reactive declaration is not a general-purpose memoization cache.
1159
+ const items = Array.from({ length: 10000 }, (_, i) => ({
1120
1160
  value: i.toString(),
1121
1161
  label: `Item ${i + 1}`,
1122
1162
  description: `Description for item ${i + 1}`
1123
1163
  }));
1124
1164
 
1125
1165
  // Pure renderer function
1126
- const renderer = (item: any, index: number) => `
1127
- <div>
1128
- <div style="font-weight: 600;">${item.label}</div>
1129
- <div style="font-size: 12px; color: #666;">${item.description}</div>
1130
- </div>
1131
- `;
1166
+ const renderer = (item: (typeof items)[number]): HTMLElement => {
1167
+ const row = document.createElement('div');
1168
+ const title = document.createElement('strong'); title.textContent = item.label;
1169
+ const description = document.createElement('div');
1170
+ description.style.cssText = 'font-size:12px;color:#666';
1171
+ description.textContent = item.description;
1172
+ row.append(title, description);
1173
+ return row;
1174
+ };
1132
1175
  </script>
1133
1176
 
1134
1177
  <Select
1135
1178
  items={items}
1136
1179
  bind:value
1137
- optionTemplate={renderer}
1180
+ optionRenderer={renderer}
1138
1181
  virtualized
1139
- estimatedItemHeight={60}
1140
1182
  />
1141
1183
  ```
1142
1184
 
@@ -1162,14 +1204,16 @@ enhanced-select {
1162
1204
 
1163
1205
  ### Important: Passing inline functions as renderers
1164
1206
 
1165
- If you define `optionRenderer` or `customRenderer` inline (like function inside template), it may cause unnecessary re-creation.
1207
+ If you define `optionRenderer` inline in a template, it may cause unnecessary replacement of generated option content. A stable function reference is usually easier to reason about.
1166
1208
 
1167
1209
  **Highly recommended:** For best performance and to avoid potential issues, always use stable function references:
1168
1210
 
1169
1211
  ```svelte
1170
1212
  <script>
1171
- let myRenderer = (item, index, helpers) => {
1172
- return document.createElement('div');
1213
+ const myRenderer = (item, index, helpers) => {
1214
+ const element = document.createElement('div');
1215
+ element.textContent = item.label;
1216
+ return element;
1173
1217
  };
1174
1218
  // or define outside reactive blocks
1175
1219
  </script>
@@ -1179,19 +1223,17 @@ Adapters are designed to not loop even without memoization, but stability still
1179
1223
 
1180
1224
  ## Accessibility
1181
1225
 
1182
- This component is fully accessible and compliant with WCAG 2.1 AAA standards:
1226
+ Implemented behavior includes selected Arrow/Enter/Escape/Tab paths, ARIA naming/description forwarding, and focus restoration. The shared core passed its scoped Phase 4 automated browser matrix in Chromium, Firefox, and WebKit. This does not establish exhaustive Svelte adapter parity, minimum-browser-version compatibility, or WCAG conformance. Manual Windows/NVDA and macOS/VoiceOver assessments remain pending.
1183
1227
 
1184
- - ✅ Keyboard navigation (Arrow keys, Enter, Escape, Tab)
1185
- - ✅ Screen reader support (ARIA labels and live regions)
1228
+ - ✅ Selected keyboard navigation paths (not an exhaustive interaction certification)
1229
+ - ✅ ARIA naming and selected live-region announcements
1186
1230
  - ✅ Focus management
1187
1231
  - ✅ High contrast mode support
1188
1232
  - ✅ Reduced motion support
1189
1233
 
1190
1234
  ## Browser Support
1191
1235
 
1192
- - Chrome/Edge 90+
1193
- - Firefox 88+
1194
- - Safari 14+
1236
+ The browser versions listed in repository policy are compatibility targets, not proof that every minimum-version integration has passed certification. The completed Phase 4 browser matrix uses current pinned Chromium, Firefox, and WebKit builds; consult the [browser support policy](../../docs/compliance/BROWSER-SUPPORT.md) for declared compatibility and support details.
1195
1237
  - Opera 76+
1196
1238
 
1197
1239
  ## License