@smilodon/svelte 1.9.3 → 2.0.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,14 @@
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
+ **Supported peer:** Svelte 5.x. Svelte 3 and 4 are not supported by this package artifact. The published peer range is limited to the major version validated by the packed-consumer check; see [ADR 179](../../docs/architecture/179-SVELTE-MULTI-VERSION-DISTRIBUTION-ADR.md).
6
+
7
+ > 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).
8
+
9
+ ## Acknowledged data-loading adapter status
10
+
11
+ The Phase 2F-D development candidate currently integrates acknowledged data loading through the core API and React adapter only. This Svelte adapter does not publish a typed props/events/component-method contract for request identity, completion, cancellation, and projection lifecycle. Passing `dataLoading` via casts or relying on the underlying element is undocumented and unsupported for this adapter. Svelte adapter parity remains a separate, pending work package; the existing legacy host-managed path remains supported.
4
12
 
5
13
  ## 📖 Documentation
6
14
 
@@ -12,12 +20,14 @@ Production-ready, accessible select component for Svelte applications. Part of t
12
20
 
13
21
  👉 **[Complete Svelte Guide](./COMPLETE-GUIDE.md)** 👈
14
22
 
23
+ 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.
24
+
15
25
  The complete guide includes:
16
26
  - ✅ Complete styling token coverage for colors, layout, chips, motion, and accessibility
17
27
  - ✅ Svelte-specific patterns (reactive statements, stores, bind:value)
18
28
  - ✅ Complete API reference with TypeScript types
19
29
  - ✅ Svelte stores integration (writable, derived)
20
- - ✅ Custom renderers returning HTML strings
30
+ - ✅ DOM option renderers returning `HTMLElement` values; do not return HTML strings
21
31
  - ✅ Theme examples with :global() styling
22
32
  - ✅ Advanced patterns (Context API, reactive dependencies)
23
33
  - ✅ Troubleshooting and accessibility information
@@ -26,40 +36,35 @@ The complete guide includes:
26
36
 
27
37
  ## Features
28
38
 
29
- - New: `optionRenderer` prop (Option B) lets you return an `HTMLElement` for custom DOM-driven option layouts.
39
+ - `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
40
 
31
41
  ### Advanced scenarios (Svelte)
32
- - **A11y-first**:
42
+ - **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
43
  ```svelte
34
- <label id="city-label" for="city-picker">City</label>
35
- <Select id="city-picker" aria-labelledby="city-label" />
44
+ <label for="city-picker">City</label>
45
+ <Select id="city-picker" aria-label="City" />
36
46
  ```
37
47
  - **Server-side lookup**:
38
48
  ```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
- }
49
+ <!-- Fragment: assumes items and handleSearch are declared in this component. -->
50
+ <Select {items} searchable on:search={handleSearch} />
46
51
  ```
47
- - **Heavy lists (100k+)**:
52
+ - **Large flat lists**: the public setting enables chunked rendering, not viewport windowing:
48
53
  ```svelte
49
- <Select {items} virtualized estimatedItemHeight={44} />
50
54
  <script>
51
55
  export let items = Array.from({ length: 100_000 }, (_, i) => ({ value: i, label: `Item ${i}` }));
52
56
  </script>
57
+ <Select {items} virtualized />
53
58
  ```
54
59
 
55
60
  - ✨ **Single & Multi-Select** - Choose one or multiple options
56
61
  - 🔍 **Searchable** - Filter options with built-in or custom search
57
- - ♿ **Fully Accessible** - WCAG 2.1 AAA compliant
58
- - ⚡ **Virtual Scrolling** - Handle 100k+ options smoothly
62
+ - ♿ **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
63
+ - ⚡ **Large-list chunk rendering** - Incrementally render large flat lists; not viewport windowing
59
64
  - 📜 **Infinite Scroll** - Load data progressively
60
65
  - 👥 **Grouped Options** - Organize options into categories
61
66
  - 🎨 **Customizable** - Style with CSS variables or custom themes
62
- - 📦 **Tiny Bundle** - ~2KB gzipped
67
+ - 📦 **Bundle guidance** - No version-specific bundle-size measurement is claimed; measure your published entry and bundler output if size is a release requirement
63
68
  - 🔧 **TypeScript** - Full type safety included
64
69
 
65
70
  ## Installation
@@ -70,7 +75,7 @@ npm install @smilodon/svelte @smilodon/core
70
75
 
71
76
  ## SvelteKit / SSR Notes
72
77
 
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.
78
+ 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
79
 
75
80
  ### Recommended pattern
76
81
 
@@ -95,6 +100,7 @@ The Svelte adapter waits for `enhanced-select` to be defined during `onMount()`,
95
100
  - Avoid direct `window`, `document`, or custom-element access outside `onMount()`.
96
101
  - Use `bind:value` for regular selection flow and exported instance methods for imperative control.
97
102
  - Prefer `optionRenderer` when you need DOM-driven custom options and plain markup when you do not.
103
+ - 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
104
 
99
105
  ## Quick Start
100
106
 
@@ -143,7 +149,7 @@ The Svelte adapter waits for `enhanced-select` to be defined during `onMount()`,
143
149
 
144
150
  Styling hooks: `::part(clear-button)` and `::part(clear-icon)` plus `--select-clear-*` CSS tokens.
145
151
 
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.
152
+ 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
153
 
148
154
  Use full config passthrough when a permanently visible disabled-when-empty action is required:
149
155
 
@@ -322,7 +328,7 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
322
328
  { value: 'mx', label: 'Mexico' },
323
329
  ];
324
330
 
325
- let country;
331
+ let country: string | number = '';
326
332
  </script>
327
333
 
328
334
  <Select
@@ -345,7 +351,7 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
345
351
  { value: 'py', label: 'Python' },
346
352
  ];
347
353
 
348
- let languages = [];
354
+ let languages: Array<string | number> = [];
349
355
  </script>
350
356
 
351
357
  <Select
@@ -358,28 +364,30 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
358
364
 
359
365
  ### Grouped Options
360
366
 
367
+ 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.
368
+
361
369
  ```svelte
362
370
  <script lang="ts">
363
371
  import { Select } from '@smilodon/svelte';
364
372
 
365
373
  const groupedItems = [
366
374
  {
367
- group: 'Fruits',
368
- items: [
375
+ label: 'Fruits',
376
+ options: [
369
377
  { value: 'apple', label: 'Apple' },
370
378
  { value: 'banana', label: 'Banana' },
371
379
  ],
372
380
  },
373
381
  {
374
- group: 'Vegetables',
375
- items: [
382
+ label: 'Vegetables',
383
+ options: [
376
384
  { value: 'carrot', label: 'Carrot' },
377
385
  { value: 'potato', label: 'Potato' },
378
386
  ],
379
387
  },
380
388
  ];
381
389
 
382
- let food;
390
+ let food: string | number = '';
383
391
  </script>
384
392
 
385
393
  <Select {groupedItems} bind:value={food} />
@@ -391,17 +399,25 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
391
399
  <script lang="ts">
392
400
  import { Select } from '@smilodon/svelte';
393
401
 
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];
402
+ const pageSize = 50;
403
+ const total = 500;
404
+ let items = makeItems(1, pageSize);
405
+ let loading = false;
406
+ const loadedPages = new Set<number>([1]);
407
+
408
+ function handleLoadMore(event: CustomEvent<{ page: number }>) {
409
+ const requestedPage = event.detail.page;
410
+ if (loading || loadedPages.has(requestedPage) || items.length >= total) return;
411
+ loading = true;
412
+ const start = items.length + 1;
413
+ const count = Math.min(pageSize, total - items.length);
414
+ items = [...items, ...makeItems(start, count)];
415
+ loadedPages.add(requestedPage);
416
+ loading = false;
401
417
  }
402
418
 
403
- function generateItems(start, end) {
404
- return Array.from({ length: end - start + 1 }, (_, i) => ({
419
+ function makeItems(start: number, count: number) {
420
+ return Array.from({ length: count }, (_, i) => ({
405
421
  value: start + i,
406
422
  label: `Item ${start + i}`,
407
423
  }));
@@ -411,13 +427,15 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
411
427
  <Select
412
428
  {items}
413
429
  infiniteScroll
414
- pageSize={50}
430
+ pageSize={pageSize}
415
431
  on:loadMore={handleLoadMore}
416
432
  placeholder="Scroll to load more..."
417
433
  />
418
434
  ```
419
435
 
420
- ### Virtual Scrolling (Large Datasets)
436
+ 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.
437
+
438
+ ### Incremental Chunk Rendering (Large Datasets)
421
439
 
422
440
  ```svelte
423
441
  <script lang="ts">
@@ -434,7 +452,7 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
434
452
  {items}
435
453
  virtualized
436
454
  searchable
437
- placeholder="100k items with virtual scrolling..."
455
+ placeholder="100k items with incremental chunk rendering..."
438
456
  />
439
457
  ```
440
458
 
@@ -442,25 +460,42 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
442
460
 
443
461
  ```svelte
444
462
  <script lang="ts">
445
- import { Select } from '@smilodon/svelte';
463
+ import { Select, type SelectItem } from '@smilodon/svelte';
464
+ import { onDestroy } from 'svelte';
446
465
 
447
- let items = [];
466
+ let items: SelectItem[] = [];
448
467
  let isLoading = false;
468
+ let searchError = '';
469
+ let controller: AbortController | undefined;
470
+ let requestId = 0;
449
471
 
450
- async function handleSearch(event) {
472
+ async function handleSearch(event: CustomEvent<{ query: string }>) {
451
473
  const query = event.detail.query;
474
+ const id = ++requestId;
475
+ controller?.abort();
452
476
 
453
477
  if (!query) {
454
478
  items = [];
479
+ isLoading = false;
480
+ searchError = '';
455
481
  return;
456
482
  }
457
483
 
484
+ const current = new AbortController();
485
+ controller = current;
458
486
  isLoading = true;
459
- const response = await fetch(`/api/search?q=${query}`);
460
- const data = await response.json();
461
- items = data.results;
462
- isLoading = false;
487
+ try {
488
+ const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`, { signal: current.signal });
489
+ if (!response.ok) throw new Error(`Search failed: ${response.status}`);
490
+ const data = await response.json() as { results: SelectItem[] };
491
+ if (id === requestId) { items = data.results; searchError = ''; }
492
+ } catch (error) {
493
+ if (!(error instanceof DOMException && error.name === 'AbortError') && id === requestId) searchError = String(error);
494
+ } finally {
495
+ if (id === requestId) isLoading = false;
496
+ }
463
497
  }
498
+ onDestroy(() => controller?.abort());
464
499
  </script>
465
500
 
466
501
  <Select
@@ -469,10 +504,16 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
469
504
  on:search={handleSearch}
470
505
  placeholder="Type to search..."
471
506
  />
507
+ {#if isLoading}<p role="status">Searching…</p>{/if}
508
+ {#if searchError}<p role="alert">{searchError}</p>{/if}
472
509
  ```
473
510
 
511
+ 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.
512
+
474
513
  ### Controlled Component
475
514
 
515
+ 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.
516
+
476
517
  ```svelte
477
518
  <script lang="ts">
478
519
  import { Select } from '@smilodon/svelte';
@@ -483,11 +524,12 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
483
524
  { value: 'archived', label: 'Archived' },
484
525
  ];
485
526
 
486
- let status = 'draft';
527
+ let status: string | number = 'draft';
487
528
 
488
- function handleChange(event) {
529
+ function handleChange(event: CustomEvent<{ value: string | number | (string | number)[] }>) {
489
530
  console.log('Status changed:', event.detail.value);
490
- status = event.detail.value;
531
+ const next = event.detail.value;
532
+ status = Array.isArray(next) ? next[0] ?? '' : next;
491
533
  }
492
534
  </script>
493
535
 
@@ -508,15 +550,15 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
508
550
  <script lang="ts">
509
551
  import { Select } from '@smilodon/svelte';
510
552
 
511
- let selectRef;
512
- const items = [...];
553
+ let selectRef: { open: () => void; clear: () => void } | undefined;
554
+ const items = [{ value: 'alpha', label: 'Alpha' }];
513
555
 
514
556
  function programmaticOpen() {
515
- selectRef.open();
557
+ selectRef?.open();
516
558
  }
517
559
 
518
560
  function programmaticClear() {
519
- selectRef.clear();
561
+ selectRef?.clear();
520
562
  }
521
563
  </script>
522
564
 
@@ -542,11 +584,15 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
542
584
  | `error` | `boolean` | `false` | Show error state |
543
585
  | `infiniteScroll` | `boolean` | `false` | Enable infinite scroll |
544
586
  | `pageSize` | `number` | `50` | Items per page (infinite scroll) |
545
- | `virtualized` | `boolean` | `true` | Enable virtual scrolling |
587
+ | `virtualized` | `boolean` | `true` | Enable legacy chunked rendering for large flat lists; not viewport windowing |
546
588
  | `maxSelections` | `number` | `undefined` | Max selections (multi-select) |
547
589
  | `placement` | `'bottom' \| 'top' \| 'auto'` | `'auto'` | Dropdown placement |
548
590
  | `className` | `string` | `''` | Custom CSS class |
549
591
  | `style` | `string` | `''` | Custom inline styles |
592
+ | `selectionConfig`, `multiSelectDisplay`, `scrollToSelected`, `styles`, `config` | core configuration types | - | Shared runtime configuration groups |
593
+ | `optionRenderer` | `(item, index, helpers) => HTMLElement` | - | DOM option renderer; must return an element, not an HTML string |
594
+ | `clearable`, `clearSelectionOnClear`, `clearSearchOnClear`, `clearAriaLabel`, `clearIcon` | booleans / strings | - | Clear-control configuration |
595
+ | `trackingEnabled`, `trackEvents`, `trackStyling`, `trackLimitations`, `emitDiagnostics`, `trackingMaxEntries`, `limitationPolicies`, `autoMitigateRuntimeModeSwitch` | documented tracking/limitation types | - | Runtime diagnostics and limitation policies |
550
596
 
551
597
  ## Events
552
598
 
@@ -559,6 +605,8 @@ The Svelte component exports additional runtime helpers beyond `open()` and `cle
559
605
  | `search` | `{ query }` | Search query changed |
560
606
  | `loadMore` | `{ page }` | Load more requested |
561
607
  | `create` | `{ value }` | New item creation |
608
+ | `clear` | `{ clearedSelection, clearedSearch }` | Clear control used |
609
+ | `diagnostic` | Diagnostic detail | Runtime diagnostics enabled |
562
610
 
563
611
  ## Methods
564
612
 
@@ -572,6 +620,14 @@ Access these methods using `bind:this`:
572
620
  | `clear()` | `() => void` | Clear selection |
573
621
  | `setItems()` | `(items: SelectItem[]) => void` | Update items |
574
622
  | `setGroupedItems()` | `(groups: GroupedItem[]) => void` | Update grouped items |
623
+ | `clearSearch()` | `() => void` | Clear the search query |
624
+ | `updateCoreConfig()` | `(config: Partial<GlobalSelectConfig>) => void` | Apply core runtime configuration |
625
+ | `setError()` / `clearError()` | message / no arguments | Set or clear validation error state |
626
+ | `setRequiredState()` | `(required: boolean) => void` | Change required state |
627
+ | `validate()` | `() => boolean` | Validate current state |
628
+ | `getCapabilities()` / `getKnownLimitations()` | reports | Read capabilities and current limitations |
629
+ | `getTrackingSnapshot()` / `clearTracking(source?)` | snapshot / source | Inspect or clear tracking data |
630
+ | `setLimitationPolicies()` | `(policies) => void` | Set limitation-handling policies |
575
631
 
576
632
  ## Types
577
633
 
@@ -585,8 +641,8 @@ interface SelectItem {
585
641
  }
586
642
 
587
643
  interface GroupedItem {
588
- group: string;
589
- items: SelectItem[];
644
+ label: string;
645
+ options: SelectItem[];
590
646
  }
591
647
  ```
592
648
 
@@ -605,7 +661,7 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
605
661
  - ✅ Auto-conversion from strings/numbers
606
662
  - ✅ Perfect for basic dropdowns
607
663
  - ✅ Works seamlessly with Svelte stores
608
- - ✅ Extremely performant (millions of items)
664
+ - ✅ 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
665
  - ✅ Built-in search and filtering
610
666
  - ✅ Full TypeScript type safety
611
667
 
@@ -730,7 +786,7 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
730
786
 
731
787
  ### Method 2: Component-Driven (Custom Renderers) 🎨
732
788
 
733
- **Use when**: You need rich, interactive option content with custom HTML/styling.
789
+ **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
790
 
735
791
  **Advantages**:
736
792
  - ✅ Full control over option rendering
@@ -741,7 +797,7 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
741
797
  - ✅ Works with Svelte stores
742
798
  - ✅ Perfect for complex UIs (user cards, product listings, etc.)
743
799
 
744
- **How it works**: Provide an `optionTemplate` function that returns HTML string for each option.
800
+ **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
801
 
746
802
  **Examples**:
747
803
 
@@ -763,21 +819,25 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
763
819
  { value: 'rs', label: 'Rust', icon: '🦀', description: 'Systems programming language' }
764
820
  ];
765
821
 
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
- `;
822
+ const languageRenderer = (item: Language, index: number): HTMLElement => {
823
+ const row = document.createElement('div');
824
+ row.style.cssText = 'display:flex;align-items:center;gap:12px';
825
+ const icon = document.createElement('span');
826
+ icon.style.fontSize = '24px'; icon.textContent = item.icon;
827
+ const content = document.createElement('div');
828
+ const title = document.createElement('strong'); title.textContent = item.label;
829
+ const description = document.createElement('small');
830
+ description.style.cssText = 'display:block;font-size:12px;color:#6b7280';
831
+ description.textContent = item.description;
832
+ content.append(title, description); row.append(icon, content);
833
+ return row;
834
+ };
775
835
  </script>
776
836
 
777
837
  <Select
778
838
  items={languages}
779
839
  bind:value={lang}
780
- optionTemplate={languageRenderer}
840
+ optionRenderer={languageRenderer}
781
841
  placeholder="Select a language..."
782
842
  />
783
843
  ```
@@ -819,33 +879,28 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
819
879
  }
820
880
  ];
821
881
 
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
- `;
882
+ const userRenderer = (item: User): HTMLElement => {
883
+ const row = document.createElement('div');
884
+ row.style.cssText = 'display:flex;align-items:center;gap:12px;padding:4px 0';
885
+ const image = document.createElement('img');
886
+ // Only use avatar URLs from a trusted/validated source.
887
+ image.src = item.avatar; image.alt = ''; image.setAttribute('aria-hidden', 'true');
888
+ image.style.cssText = 'width:40px;height:40px;border-radius:50%;object-fit:cover';
889
+ const details = document.createElement('div'); details.style.flex = '1';
890
+ const name = document.createElement('strong'); name.style.color = '#1f2937'; name.textContent = item.label;
891
+ const email = document.createElement('div'); email.style.cssText = 'font-size:13px;color:#6b7280'; email.textContent = item.email;
892
+ details.append(name, email);
893
+ const role = document.createElement('span'); role.textContent = item.role;
894
+ 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'}`;
895
+ row.append(image, details, role);
896
+ return row;
897
+ };
843
898
  </script>
844
899
 
845
900
  <Select
846
901
  items={users}
847
902
  bind:value={userId}
848
- optionTemplate={userRenderer}
903
+ optionRenderer={userRenderer}
849
904
  placeholder="Select a user..."
850
905
  />
851
906
  ```
@@ -890,40 +945,36 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
890
945
  }
891
946
  ];
892
947
 
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
- `;
948
+ const productRenderer = (item: Product): HTMLElement => {
949
+ const row = document.createElement('div');
950
+ row.style.cssText = `display:flex;align-items:center;gap:12px;opacity:${item.stock === 0 ? '0.5' : '1'}`;
951
+ const image = document.createElement('img');
952
+ // Only use image URLs from a trusted/validated source.
953
+ image.src = item.image; image.alt = ''; image.setAttribute('aria-hidden', 'true');
954
+ image.style.cssText = 'width:60px;height:60px;border-radius:8px;object-fit:cover;border:1px solid #e5e7eb';
955
+ const content = document.createElement('div'); content.style.flex = '1';
956
+ const heading = document.createElement('div'); heading.style.cssText = 'display:flex;align-items:center;gap:8px';
957
+ const title = document.createElement('strong'); title.style.color = '#1f2937'; title.textContent = item.label;
958
+ heading.append(title);
959
+ if (item.badge) {
960
+ const badge = document.createElement('span'); badge.textContent = item.badge;
961
+ 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'}`;
962
+ heading.append(badge);
963
+ }
964
+ const metadata = document.createElement('div');
965
+ metadata.style.cssText = 'margin-top:4px;display:flex;justify-content:space-between;align-items:center';
966
+ const price = document.createElement('strong'); price.style.cssText = 'font-size:16px;color:#059669'; price.textContent = `$${item.price.toFixed(2)}`;
967
+ const stock = document.createElement('span'); stock.style.cssText = 'font-size:12px;color:#6b7280';
968
+ stock.textContent = item.stock > 0 ? `${item.stock} in stock` : 'Out of stock';
969
+ metadata.append(price, stock); content.append(heading, metadata); row.append(image, content);
970
+ return row;
971
+ };
921
972
  </script>
922
973
 
923
974
  <Select
924
975
  items={products}
925
976
  bind:value={productId}
926
- optionTemplate={productRenderer}
977
+ optionRenderer={productRenderer}
927
978
  placeholder="Select a product..."
928
979
  />
929
980
  ```
@@ -960,42 +1011,28 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
960
1011
  'low': '#10b981'
961
1012
  };
962
1013
 
963
- const taskRenderer = (item: Task) => {
1014
+ const taskRenderer = (item: Task): HTMLElement => {
964
1015
  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
- `;
1016
+ const row = document.createElement('div'); row.style.cssText = 'display:flex;align-items:center;gap:10px;padding:4px 0';
1017
+ const icon = document.createElement('div'); icon.textContent = status.icon;
1018
+ 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`;
1019
+ const details = document.createElement('div'); details.style.flex = '1';
1020
+ const title = document.createElement('strong'); title.style.color = '#1f2937'; title.textContent = item.label;
1021
+ const assignee = document.createElement('div'); assignee.style.cssText = 'font-size:12px;color:#6b7280;margin-top:2px';
1022
+ assignee.textContent = `Assigned to ${item.assignee}`;
1023
+ details.append(title, assignee);
1024
+ const priority = document.createElement('span');
1025
+ priority.title = `${item.priority} priority`;
1026
+ priority.style.cssText = `width:8px;height:8px;border-radius:50%;background:${priorityColors[item.priority]}`;
1027
+ row.append(icon, details, priority);
1028
+ return row;
992
1029
  };
993
1030
  </script>
994
1031
 
995
1032
  <Select
996
1033
  items={tasks}
997
1034
  bind:value={taskId}
998
- optionTemplate={taskRenderer}
1035
+ optionRenderer={taskRenderer}
999
1036
  placeholder="Select a task..."
1000
1037
  />
1001
1038
  ```
@@ -1019,21 +1056,24 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
1019
1056
  { value: 'angular', label: 'Angular', color: 'red', count: 420 }
1020
1057
  ];
1021
1058
 
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
- `;
1059
+ const tagRenderer = (item: Tag): HTMLElement => {
1060
+ const row = document.createElement('div');
1061
+ row.style.cssText = 'display:flex;align-items:center;justify-content:space-between;padding:8px';
1062
+ const details = document.createElement('div'); details.style.cssText = 'display:flex;align-items:center;gap:8px';
1063
+ const marker = document.createElement('span');
1064
+ marker.style.cssText = `width:12px;height:12px;border-radius:50%;background:${item.color}`;
1065
+ const label = document.createElement('strong'); label.style.color = '#1f2937'; label.textContent = item.label;
1066
+ const count = document.createElement('span'); count.style.cssText = 'font-size:14px;color:#6b7280';
1067
+ count.textContent = `${item.count} posts`;
1068
+ details.append(marker, label); row.append(details, count);
1069
+ return row;
1070
+ };
1031
1071
  </script>
1032
1072
 
1033
1073
  <Select
1034
1074
  items={tags}
1035
1075
  bind:value={$tag}
1036
- optionTemplate={tagRenderer}
1076
+ optionRenderer={tagRenderer}
1037
1077
  placeholder="Select a tag..."
1038
1078
  />
1039
1079
  ```
@@ -1042,20 +1082,20 @@ Smilodon Svelte provides **two powerful approaches** for defining select options
1042
1082
 
1043
1083
  | Feature | Method 1: Object Arrays | Method 2: Custom Renderers |
1044
1084
  |---------|------------------------|---------------------------|
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 |
1085
+ | **Setup** | Pass an array of option data | Provide a renderer callback |
1086
+ | **Rendering behavior** | Shared runtime renders option labels | Adapter uses the documented HTMLElement renderer |
1087
+ | **Customization** | Data-driven labels and state | Custom non-interactive content; nested controls are not promised |
1088
+ | **Svelte integration** | Bound values and Svelte component events | Same adapter API with custom DOM-rendered content |
1089
+ | **Reactive state** | Bind or control the value using the documented contract | Renderer output follows the adapter's renderer lifecycle |
1090
+ | **TypeScript** | Typed item data and props | Typed renderer callback and props |
1091
+ | **Very large datasets** | No 1M-item certification or performance comparison is claimed | No 1M-item certification or performance comparison is claimed |
1092
+ | **Choosing a method** | Direct for simple options | Use when custom content is required |
1053
1093
 
1054
1094
  **Best Practices**:
1055
1095
 
1056
1096
  ✅ **Use Method 1 (Object Arrays) when**:
1057
1097
  - You need simple text-based options
1058
- - Performance is critical (millions of items)
1098
+ - 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
1099
  - You want minimal code
1060
1100
  - Built-in search/filter is sufficient
1061
1101
  - Working with external APIs returning plain data
@@ -1078,36 +1118,42 @@ You can start with Method 1 and add Method 2 later as your UI evolves:
1078
1118
 
1079
1119
  let value = '';
1080
1120
 
1081
- // Start simple
1082
- const items = ['Option 1', 'Option 2', 'Option 3'];
1121
+ // Start simple with the documented SelectItem shape
1122
+ const items = [
1123
+ { value: 'one', label: 'Option 1' },
1124
+ { value: 'two', label: 'Option 2' },
1125
+ { value: 'three', label: 'Option 3' },
1126
+ ];
1083
1127
 
1084
1128
  // 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
- `;
1129
+ const optionRenderer = (item: (typeof items)[number], index: number): HTMLElement => {
1130
+ const row = document.createElement('div');
1131
+ row.style.cssText = `padding:8px;background:${index % 2 ? '#f9fafb' : 'white'}`;
1132
+ const label = document.createElement('strong'); label.textContent = item.label;
1133
+ row.append(label);
1134
+ return row;
1135
+ };
1090
1136
  </script>
1091
1137
 
1092
1138
  <Select
1093
1139
  items={items}
1094
1140
  bind:value
1095
- optionTemplate={customRenderer}
1141
+ optionRenderer={optionRenderer}
1096
1142
  />
1097
1143
  ```
1098
1144
 
1099
1145
  ### Performance Tips
1100
1146
 
1101
1147
  **For Method 1**:
1102
- - Use reactive statements (`$:`) to memoize large item arrays
1103
- - Enable `virtualized` prop for 1000+ items
1148
+ - Use reactive statements (`$:`) only when their dependencies and recomputation behavior are understood; `$:` is not a general-purpose memoization mechanism
1149
+ - `virtualized` enables chunked rendering; it does not bound mounted DOM to the viewport.
1104
1150
  - Enable `infiniteScroll` for dynamic loading
1105
1151
 
1106
1152
  **For Method 2**:
1107
1153
  - Keep renderer function pure (no side effects)
1108
1154
  - Avoid heavy computations in renderer
1109
1155
  - Cache renderer functions when possible
1110
- - Use template literals for cleaner HTML strings
1156
+ - Use DOM APIs and `textContent` in `optionRenderer`; do not interpolate option data into HTML strings
1111
1157
 
1112
1158
  ```svelte
1113
1159
  <script lang="ts">
@@ -1115,28 +1161,30 @@ You can start with Method 1 and add Method 2 later as your UI evolves:
1115
1161
 
1116
1162
  let value = '';
1117
1163
 
1118
- // Memoize items with reactive statement
1119
- $: items = Array.from({ length: 10000 }, (_, i) => ({
1164
+ // Stable example data. A Svelte reactive declaration is not a general-purpose memoization cache.
1165
+ const items = Array.from({ length: 10000 }, (_, i) => ({
1120
1166
  value: i.toString(),
1121
1167
  label: `Item ${i + 1}`,
1122
1168
  description: `Description for item ${i + 1}`
1123
1169
  }));
1124
1170
 
1125
1171
  // 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
- `;
1172
+ const renderer = (item: (typeof items)[number]): HTMLElement => {
1173
+ const row = document.createElement('div');
1174
+ const title = document.createElement('strong'); title.textContent = item.label;
1175
+ const description = document.createElement('div');
1176
+ description.style.cssText = 'font-size:12px;color:#666';
1177
+ description.textContent = item.description;
1178
+ row.append(title, description);
1179
+ return row;
1180
+ };
1132
1181
  </script>
1133
1182
 
1134
1183
  <Select
1135
1184
  items={items}
1136
1185
  bind:value
1137
- optionTemplate={renderer}
1186
+ optionRenderer={renderer}
1138
1187
  virtualized
1139
- estimatedItemHeight={60}
1140
1188
  />
1141
1189
  ```
1142
1190
 
@@ -1162,14 +1210,16 @@ enhanced-select {
1162
1210
 
1163
1211
  ### Important: Passing inline functions as renderers
1164
1212
 
1165
- If you define `optionRenderer` or `customRenderer` inline (like function inside template), it may cause unnecessary re-creation.
1213
+ 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
1214
 
1167
1215
  **Highly recommended:** For best performance and to avoid potential issues, always use stable function references:
1168
1216
 
1169
1217
  ```svelte
1170
1218
  <script>
1171
- let myRenderer = (item, index, helpers) => {
1172
- return document.createElement('div');
1219
+ const myRenderer = (item, index, helpers) => {
1220
+ const element = document.createElement('div');
1221
+ element.textContent = item.label;
1222
+ return element;
1173
1223
  };
1174
1224
  // or define outside reactive blocks
1175
1225
  </script>
@@ -1179,19 +1229,17 @@ Adapters are designed to not loop even without memoization, but stability still
1179
1229
 
1180
1230
  ## Accessibility
1181
1231
 
1182
- This component is fully accessible and compliant with WCAG 2.1 AAA standards:
1232
+ 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
1233
 
1184
- - ✅ Keyboard navigation (Arrow keys, Enter, Escape, Tab)
1185
- - ✅ Screen reader support (ARIA labels and live regions)
1234
+ - ✅ Selected keyboard navigation paths (not an exhaustive interaction certification)
1235
+ - ✅ ARIA naming and selected live-region announcements
1186
1236
  - ✅ Focus management
1187
1237
  - ✅ High contrast mode support
1188
1238
  - ✅ Reduced motion support
1189
1239
 
1190
1240
  ## Browser Support
1191
1241
 
1192
- - Chrome/Edge 90+
1193
- - Firefox 88+
1194
- - Safari 14+
1242
+ 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
1243
  - Opera 76+
1196
1244
 
1197
1245
  ## License