@smilodon/core 1.9.3 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +140 -377
  2. package/dist/index.cjs +4030 -297
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +4014 -298
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.min.js +1 -1
  7. package/dist/index.min.js.map +1 -1
  8. package/dist/index.umd.js +4030 -297
  9. package/dist/index.umd.js.map +1 -1
  10. package/dist/index.umd.min.js +1 -1
  11. package/dist/index.umd.min.js.map +1 -1
  12. package/dist/types/src/components/enhanced-select.d.ts +172 -8
  13. package/dist/types/src/components/native-select.d.ts +1 -1
  14. package/dist/types/src/components/select-option.d.ts +2 -2
  15. package/dist/types/src/config/global-config.d.ts +7 -5
  16. package/dist/types/src/data-loading/public-config.d.ts +3 -0
  17. package/dist/types/src/data-loading/public-types.d.ts +171 -0
  18. package/dist/types/src/data-loading/request-coordinator.d.ts +236 -0
  19. package/dist/types/src/engine/accessibility.d.ts +109 -0
  20. package/dist/types/src/engine/contracts.d.ts +4 -0
  21. package/dist/types/src/engine/index.d.ts +9 -0
  22. package/dist/types/src/engine/item-adapter.d.ts +23 -0
  23. package/dist/types/src/engine/item-registry.d.ts +31 -0
  24. package/dist/types/src/engine/select-effects.d.ts +20 -0
  25. package/dist/types/src/engine/select-events.d.ts +55 -0
  26. package/dist/types/src/engine/select-machine.d.ts +9 -0
  27. package/dist/types/src/engine/select-state.d.ts +17 -0
  28. package/dist/types/src/engine/selection-policy.d.ts +33 -0
  29. package/dist/types/src/engine/selectors.d.ts +10 -0
  30. package/dist/types/src/engine/virtualization.d.ts +56 -0
  31. package/dist/types/src/index.d.ts +6 -0
  32. package/dist/types/src/native-types.d.ts +5 -0
  33. package/dist/types/src/platform/web/accessibility-effects.d.ts +19 -0
  34. package/dist/types/src/platform/web/index.d.ts +2 -0
  35. package/dist/types/src/platform/web/select-effect-runner.d.ts +15 -0
  36. package/dist/types/src/platform/web/select-engine-bridge.d.ts +10 -0
  37. package/dist/types/src/renderers/contracts.d.ts +1 -1
  38. package/dist/types/src/types/limitation.d.ts +6 -0
  39. package/dist/types/src/types.d.ts +2 -6
  40. package/dist/types/src/utils/custom-option-pool.d.ts +1 -1
  41. package/dist/types/src/utils/virtualizer.d.ts +48 -1
  42. package/package.json +7 -4
  43. package/dist/types/src/themes/importer.d.ts +0 -112
  44. package/dist/types/tests/capabilities-tracking.spec.d.ts +0 -1
  45. package/dist/types/tests/csp.spec.d.ts +0 -5
  46. package/dist/types/tests/enhanced-option-renderer.spec.d.ts +0 -1
  47. package/dist/types/tests/interaction.spec.d.ts +0 -1
  48. package/dist/types/tests/lifecycle.spec.d.ts +0 -1
  49. package/dist/types/tests/memory-lifecycle.spec.d.ts +0 -1
  50. package/dist/types/tests/setup.d.ts +0 -6
  51. package/dist/types/tests/shadow-dom.spec.d.ts +0 -5
  52. package/dist/types/tests/smoke.spec.d.ts +0 -1
  53. package/dist/types/tests/stress.spec.d.ts +0 -5
  54. package/dist/types/tests/styling-contract.spec.d.ts +0 -1
  55. package/dist/types/tests/virtualizer.spec.d.ts +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <div align="center">
4
4
  <img src="https://raw.githubusercontent.com/navidrezadoost/smilodon/main/.github/logo.jpg" alt="Smilodon Logo" width="220" style="border-radius:16px;" />
5
- <p><strong>High-performance native select component with extreme-scale virtualization</strong></p>
5
+ <p><strong>Custom select component with typed selection, rendering, and adapter APIs</strong></p>
6
6
  <p>
7
7
  <a href="https://www.npmjs.com/package/@smilodon/core"><img src="https://img.shields.io/npm/v/@smilodon/core.svg" alt="npm version"></a>
8
8
  <a href="https://github.com/navidrezadoost/smilodon"><img src="https://img.shields.io/github/stars/navidrezadoost/smilodon.svg" alt="GitHub stars"></a>
@@ -10,6 +10,65 @@
10
10
  </p>
11
11
  </div>
12
12
 
13
+ > **Verification status:** `EnhancedSelect`'s public `virtualize` setting chunks large-list rendering but does not bound the final option DOM. Viewport-windowed rendering remains behind a private test seam and is not production-activated. ARIA and keyboard behaviors have automated coverage in progress; WCAG conformance and manual assistive-technology review have not been certified. See [known limitations](../../docs/KNOWN-LIMITATIONS.md#viewport-virtualization-status) and the [Phase 4 certification record](../../docs/architecture/PHASE-4-CERTIFICATION.md).
14
+
15
+ ## Acknowledged data loading (Phase 2F-D development candidate)
16
+
17
+ The local Phase 2F-D candidate adds a public, per-instance data-loading configuration and completion surface to `EnhancedSelect`. This API is not included in the published `1.10.0` package. The legacy protocol remains the default; remote and hybrid search or cursor pagination require explicit acknowledged-protocol opt-in. There is no global acknowledged-loading default. Cross-browser certification and independent review remain pending, so these examples are illustrative and have not been certified for release.
18
+
19
+ The host owns transport, cancellation, and retry decisions. `completeDataRequest()` accepts a response only when its request identity and query generation are current. A return value of `accepted` means the canonical response was accepted; DOM projection completes separately and is reported by `dataProjection`.
20
+
21
+ ```ts
22
+ import { EnhancedSelect } from '@smilodon/core'
23
+
24
+ const select = document.createElement('enhanced-select') as EnhancedSelect
25
+
26
+ select.updateConfig({
27
+ dataLoading: {
28
+ protocol: 'acknowledged',
29
+ searchMode: 'remote',
30
+ paginationMode: 'page',
31
+ firstPage: 1,
32
+ fetchLimit: 25,
33
+ },
34
+ callbacks: {
35
+ onSearch(query, request) {
36
+ if (!request) return // Legacy callbacks do not carry an acknowledged request.
37
+
38
+ const params = new URLSearchParams({ q: query, limit: String(request.fetchLimit) })
39
+ void fetch(`/api/options?${params}`)
40
+ .then(async (response) => {
41
+ if (!response.ok) throw new Error(`Search failed: ${response.status}`)
42
+ const result = await response.json() as { items: unknown[] }
43
+ return select.completeDataRequest({
44
+ requestId: request.requestId,
45
+ queryGeneration: request.queryGeneration,
46
+ status: 'exhausted',
47
+ items: result.items,
48
+ hasMore: false,
49
+ })
50
+ })
51
+ .catch((error: unknown) => {
52
+ select.completeDataRequest({
53
+ requestId: request.requestId,
54
+ queryGeneration: request.queryGeneration,
55
+ status: 'failed',
56
+ error: { message: error instanceof Error ? error.message : String(error) },
57
+ })
58
+ })
59
+ },
60
+ onDataProjection(detail) {
61
+ if (detail.status === 'failed') console.error('Projection failed', detail.error.message)
62
+ },
63
+ },
64
+ })
65
+
66
+ document.body.append(select)
67
+ select.startDataLoading()
68
+ ```
69
+
70
+ For a paginated response, use `status: 'succeeded'` with `hasMore: true` and the next cursor when cursor pagination is configured. Use `status: 'exhausted'` with `hasMore: false` when the server reports end-of-data. On cancellation, abort the host request and do not complete it as a success. A stale completion result is not a signal to retry the old request.
71
+
13
72
  ## 📖 Documentation
14
73
 
15
74
  **Live documentation & interactive examples:** [navidrezadoost.github.io/Smilodon](https://navidrezadoost.github.io/Smilodon/)
@@ -42,10 +101,12 @@ The complete guide includes:
42
101
 
43
102
  ## Why Smilodon?
44
103
 
45
- Smilodon is a Web Component that renders **1,000,000+ items at 60 FPS** with constant DOM size, sub-millisecond search, and zero framework lock-in. Built for extreme-scale data applications where legacy libraries crash or lag.
104
+ Smilodon is a Web Component-based select with framework adapters and a typed imperative API. `EnhancedSelect` can render large flat lists in chunks, but the public `virtualize` setting does not bound final DOM size; viewport-windowed rendering remains guarded and unactivated.
46
105
 
47
106
  ### Performance Comparison
48
107
 
108
+ > **Historical comparison — unverified.** The measurements and competitor claims below lack a reproducible current benchmark protocol and are not release evidence or performance guarantees. See the [Phase 4 certification record](../../docs/architecture/PHASE-4-CERTIFICATION.md) for current report-only measurements.
109
+
49
110
  | Library | 10K Items | 100K Items | 1M Items | Memory | FPS |
50
111
  |---------|-----------|------------|----------|---------|-----|
51
112
  | **Smilodon** | 38ms | 81ms | 162ms | 18 MB | 60 |
@@ -63,57 +124,56 @@ npm install @smilodon/core
63
124
 
64
125
  ## Quick Start
65
126
 
66
- ### Vanilla JavaScript / Web Components
127
+ Bare imports such as `@smilodon/core` require a bundler or an explicit browser import map. The example below uses Vite's module resolver; an unbundled browser does not resolve npm package names by itself.
128
+
129
+ ### Bundler-based Vanilla JavaScript / Web Components
67
130
 
68
131
  ```html
69
132
  <!DOCTYPE html>
70
133
  <html>
71
- <head>
72
- <script type="module">
73
- import '@smilodon/core';
74
- </script>
75
- </head>
76
134
  <body>
77
- <smilodon-select id="my-select"></smilodon-select>
78
-
79
- <script type="module">
80
- const select = document.getElementById('my-select');
81
-
82
- // Generate 1 million items
83
- const items = Array.from({ length: 1_000_000 }, (_, i) => ({
84
- label: `Item ${i + 1}`,
85
- value: i + 1
86
- }));
87
-
88
- select.items = items;
89
-
90
- select.addEventListener('change', (e) => {
91
- console.log('Selected:', e.detail);
92
- });
93
- </script>
135
+ <enhanced-select id="my-select"></enhanced-select>
136
+ <script type="module" src="/src/main.js"></script>
94
137
  </body>
95
138
  </html>
96
139
  ```
97
140
 
141
+ ```javascript
142
+ // src/main.js (resolved by Vite or another npm-aware bundler)
143
+ import '@smilodon/core';
144
+
145
+ const select = document.querySelector('enhanced-select');
146
+ const items = [
147
+ { label: 'Option 1', value: 1 },
148
+ { label: 'Option 2', value: 2 },
149
+ ];
150
+
151
+ select.setItems(items);
152
+ select.addEventListener('change', (event) => {
153
+ console.log('Selected:', event.detail);
154
+ });
155
+ ```
156
+
98
157
  ### Framework Usage
99
158
 
100
- **`@smilodon/core` works directly in all frameworks** as a Web Component - no adapters needed!
159
+ **In browser DOM frameworks, `@smilodon/core` can be used directly** as a Web Component; framework adapters are available for framework-specific APIs.
101
160
 
102
- Simply import and use `<smilodon-select>` in React, Vue, Svelte, or any framework:
161
+ The maintained Core runtime registers `<enhanced-select>`. Import Core and use that tag in browser-rendered framework templates:
103
162
 
104
163
  ```jsx
105
164
  // React, Vue, Svelte - all work the same way
106
165
  import '@smilodon/core';
107
- <smilodon-select ref={selectRef} />
166
+ <enhanced-select ref={selectRef} />
108
167
  ```
109
168
 
110
- **Optional Framework Adapters** (for enhanced developer experience):
169
+ **Framework adapters** (for framework-specific APIs):
111
170
  - **React**: `npm install @smilodon/react` - React hooks and components
112
171
  - **Vue**: `npm install @smilodon/vue` - Vue composables and components
113
172
  - **Svelte**: `npm install @smilodon/svelte` - Svelte stores and components
173
+ - **Solid**: `npm install @smilodon/solid` - SolidJS component API (Vite/Bundler consumer passes; strict NodeNext declarations currently fail with TS2834; separate fix pending)
114
174
  - **Vanilla**: `npm install @smilodon/vanilla` - Vanilla JS helpers
115
175
 
116
- These adapters provide framework-native APIs (hooks, composables) for enhanced developer experience, but are **not required** - the core package works everywhere!
176
+ React Native uses a separate native WebView bridge and a browser-based React Native Web path; it does not use one shared browser runtime across both platforms.
117
177
 
118
178
  **Note:** Angular support has been discontinued as of December 2025.
119
179
 
@@ -121,31 +181,20 @@ See the [main documentation](https://github.com/navidrezadoost/smilodon#readme)
121
181
 
122
182
  ## Key Features
123
183
 
124
- ### 🚀 Extreme Performance
125
- - **Constant DOM**: Only 10-15 elements rendered regardless of dataset size
126
- - **Work Stealing**: Background search workers with automatic cancellation
127
- - **Sub-millisecond Search**: Fenwick tree indexing for O(log n) queries
128
- - **60 FPS Scrolling**: Hardware-accelerated virtualization
129
-
130
- ### 🎯 Production Ready
131
- - **TypeScript First**: Complete type definitions included
132
- - **Zero Dependencies**: 6.6 KB gzipped runtime
133
- - **Framework Agnostic**: Works with React, Vue, Svelte, or vanilla JS
134
- - **Accessibility**: WCAG 2.2 AA compliant with ARIA 1.2
135
- - **Full keyboard navigation**: Enter/Space, Arrows, Home/End, PageUp/Down, Escape
136
- - **Multi-select modes**: wrap, horizontal, vertical, both (with drag-scroll)
137
-
138
- ### 🎨 CSS Framework Compatibility (`1.5.5`)
139
- - **Scoped mirrored styles**: class-based framework styles used by custom renderers are mirrored only into the options subtree, not the whole shadow root.
140
- - **Dark variant support**: `.dark`, `.dark-mode`, and theme-attribute variants propagate into custom-rendered option content.
141
- - **Stable state hooks**: `classMap`, `data-sm-state`, and Smilodon state classes stay available on custom option roots for hover, active, selected, and disabled styling.
142
- - **Accessible custom renderers**: nested interactive descendants are normalized by default so option renderers stay compatible with listbox semantics.
143
-
144
- ### 🔒 Enterprise Grade
145
- - **SOC2 Compliant**: Audit-ready security controls
146
- - **CSP Compatible**: No eval(), no inline scripts
147
- - **SBOM Included**: Full dependency transparency
148
- - **99.8% Test Coverage**: Unit, integration, and E2E tests
184
+ ### Large-list behavior
185
+ - **Chunked large-list rendering**: Reduces the size of an individual render task; it does not guarantee constant DOM or viewport-bounded mounting.
186
+ - **Search and indexing**: Current behavior and limits are described in the API and performance documentation; no per-query latency guarantee is made here.
187
+ - **Separate legacy virtualizer**: `NativeSelectElement` has its own compatibility implementation; do not infer its behavior from `EnhancedSelect`.
188
+
189
+ ### Capability and verification status
190
+
191
+ - The maintained runtime is the `enhanced-select` browser custom element, with typed declarations and framework adapters.
192
+ - The public `virtualize` setting uses chunked rendering; it does not guarantee a viewport-bounded option DOM.
193
+ - Automated keyboard and ARIA checks exist, but WCAG conformance and manual assistive-technology certification have not been established.
194
+ - SOC 2 certification is not established. This package makes no SOC 2 compliance claim.
195
+ - CSP compatibility is policy-dependent and is not certified. The Core source contains an `eval('true')` capability probe; a CSP that blocks `eval` may block that probe and report a violation.
196
+ - No percentage code-coverage claim is made here. Test counts are not a code-coverage percentage.
197
+ - No blanket XSS-prevention guarantee is made. Treat application-provided renderer content as untrusted input; prefer DOM nodes and `textContent` for user-controlled values.
149
198
 
150
199
  ## API Reference
151
200
 
@@ -191,23 +240,11 @@ The `--select-input-padding-with-clear` token applies only while the clear contr
191
240
  ### Properties
192
241
 
193
242
  ```typescript
194
- interface SmilodonSelectElement extends HTMLElement {
195
- items: SelectItem[] | string[] | number[]; // Dataset (can be millions of items)
196
- value: any; // Current selected value
197
- placeholder?: string; // Placeholder text
198
- searchable?: boolean; // Enable search (default: true)
199
- disabled?: boolean; // Disable the select
200
- multiple?: boolean; // Multiple selection mode
201
- virtualization?: boolean; // Enable virtualization (default: true)
202
- maxHeight?: number; // Max dropdown height in pixels
203
- }
243
+ import type { EnhancedSelect, SelectItem } from '@smilodon/core';
204
244
 
205
- interface SelectItem {
206
- label: string; // Display text
207
- value: any; // Value (can be any type)
208
- disabled?: boolean; // Disable this option
209
- group?: string; // Optgroup name
210
- }
245
+ const items: SelectItem[] = [{ label: 'One', value: 1 }];
246
+ const select = document.querySelector('enhanced-select') as EnhancedSelect | null;
247
+ if (select) select.setItems(items);
211
248
  ```
212
249
 
213
250
  > **Flexible Input Formats:**
@@ -219,16 +256,16 @@ interface SelectItem {
219
256
 
220
257
  #### Object Array (Traditional)
221
258
  ```javascript
222
- select.items = [
259
+ select.setItems([
223
260
  { value: 'apple', label: 'Apple' },
224
261
  { value: 'banana', label: 'Banana' },
225
262
  { value: 'cherry', label: 'Cherry' }
226
- ];
263
+ ]);
227
264
  ```
228
265
 
229
266
  #### String Array (Auto-converted)
230
267
  ```javascript
231
- select.items = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
268
+ select.setItems(['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']);
232
269
  // Automatically becomes:
233
270
  // [
234
271
  // { value: 'Apple', label: 'Apple' },
@@ -239,7 +276,7 @@ select.items = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
239
276
 
240
277
  #### Number Array (Auto-converted)
241
278
  ```javascript
242
- select.items = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
279
+ select.setItems([1, 2, 3, 5, 8, 13, 21, 34, 55, 89]);
243
280
  // Automatically becomes:
244
281
  // [
245
282
  // { value: 1, label: '1' },
@@ -250,302 +287,36 @@ select.items = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
250
287
 
251
288
  ---
252
289
 
253
- ## 🎯 Two Ways to Specify Options
254
-
255
- Smilodon provides **two powerful approaches** for defining select options, each optimized for different use cases:
256
-
257
- ### Method 1: Data-Driven (Object Arrays) 📊
290
+ ## Supplying options and custom rendering
258
291
 
259
- **Use when**: You have structured data and want simple, declarative option rendering.
292
+ Use the declared `setItems()` method to provide options. The public `virtualize` setting can chunk large-list rendering, but the final option DOM is not guaranteed to stay bounded by the viewport.
260
293
 
261
- **Advantages**:
262
- - ✅ Simple and declarative
263
- - ✅ Auto-conversion from strings/numbers
264
- - ✅ Perfect for basic dropdowns
265
- - ✅ Zero boilerplate code
266
- - ✅ Extremely performant (millions of items)
267
- - ✅ Built-in search and filtering
268
- - ✅ TypeScript type safety
269
-
270
- **Examples**:
271
-
272
- ```javascript
273
- // Simple object array
274
- const select = document.querySelector('enhanced-select');
275
-
276
- select.items = [
277
- { value: '1', label: 'Apple' },
278
- { value: '2', label: 'Banana' },
279
- { value: '3', label: 'Cherry' }
280
- ];
294
+ ```typescript
295
+ import type { EnhancedSelect, SelectItem } from '@smilodon/core';
281
296
 
282
- // With additional metadata
283
- select.items = [
284
- { value: 'us', label: 'United States', disabled: false },
285
- { value: 'ca', label: 'Canada', disabled: false },
286
- { value: 'mx', label: 'Mexico', disabled: true } // Disabled option
287
- ];
297
+ const select = document.querySelector('enhanced-select') as EnhancedSelect | null;
298
+ if (!select) throw new Error('EnhancedSelect element not found');
288
299
 
289
- // With grouping
290
- select.items = [
291
- { value: 'apple', label: 'Apple', group: 'Fruits' },
292
- { value: 'banana', label: 'Banana', group: 'Fruits' },
293
- { value: 'carrot', label: 'Carrot', group: 'Vegetables' },
294
- { value: 'broccoli', label: 'Broccoli', group: 'Vegetables' }
300
+ const items: SelectItem[] = [
301
+ { value: 'js', label: 'JavaScript' },
302
+ { value: 'py', label: 'Python' },
295
303
  ];
296
-
297
- // Auto-conversion from strings
298
- select.items = ['Red', 'Green', 'Blue', 'Yellow'];
299
-
300
- // Auto-conversion from numbers
301
- select.items = [10, 20, 30, 40, 50];
302
-
303
- // Large datasets (millions of items)
304
- select.items = Array.from({ length: 1_000_000 }, (_, i) => ({
305
- value: i,
306
- label: `Item ${i + 1}`
307
- }));
304
+ select.setItems(items);
308
305
  ```
309
306
 
310
- ### Method 2: Component-Driven (Custom Renderers) 🎨
311
-
312
- **Use when**: You need rich, interactive option content with custom HTML/styling.
313
-
314
- **Advantages**:
315
- - ✅ Full control over option rendering
316
- - ✅ Rich content (images, icons, badges, multi-line text)
317
- - ✅ Custom HTML and styling
318
- - ✅ Interactive elements within options
319
- - ✅ Conditional rendering based on item data
320
- - ✅ Perfect for complex UIs (user cards, product listings, etc.)
321
-
322
- **How it works**: Provide an `optionTemplate` function that returns HTML string for each option.
323
-
324
- **Examples**:
325
-
326
- ```javascript
327
- const select = document.querySelector('enhanced-select');
328
-
329
- // Example 1: Simple custom template with icons
330
- const items = [
331
- { value: 'js', label: 'JavaScript', icon: '🟨', description: 'Dynamic scripting language' },
332
- { value: 'py', label: 'Python', icon: '🐍', description: 'General-purpose programming' },
333
- { value: 'rs', label: 'Rust', icon: '🦀', description: 'Systems programming language' }
334
- ];
335
-
336
- select.items = items;
337
- select.optionTemplate = (item, index) => `
338
- <div style="display: flex; align-items: center; gap: 12px;">
339
- <span style="font-size: 24px;">${item.icon}</span>
340
- <div>
341
- <div style="font-weight: 600;">${item.label}</div>
342
- <div style="font-size: 12px; color: #6b7280;">${item.description}</div>
343
- </div>
344
- </div>
345
- `;
346
-
347
- // Example 2: User selection with avatars
348
- const users = [
349
- {
350
- value: '1',
351
- label: 'John Doe',
352
- email: 'john@example.com',
353
- avatar: 'https://i.pravatar.cc/150?img=1',
354
- role: 'Admin'
355
- },
356
- {
357
- value: '2',
358
- label: 'Jane Smith',
359
- email: 'jane@example.com',
360
- avatar: 'https://i.pravatar.cc/150?img=2',
361
- role: 'User'
362
- },
363
- {
364
- value: '3',
365
- label: 'Bob Johnson',
366
- email: 'bob@example.com',
367
- avatar: 'https://i.pravatar.cc/150?img=3',
368
- role: 'Moderator'
369
- }
370
- ];
371
-
372
- select.items = users;
373
- select.optionTemplate = (item, index) => `
374
- <div style="display: flex; align-items: center; gap: 12px; padding: 4px 0;">
375
- <img
376
- src="${item.avatar}"
377
- alt="${item.label}"
378
- style="width: 40px; height: 40px; border-radius: 50%; object-fit: cover;"
379
- />
380
- <div style="flex: 1;">
381
- <div style="font-weight: 600; color: #1f2937;">${item.label}</div>
382
- <div style="font-size: 13px; color: #6b7280;">${item.email}</div>
383
- </div>
384
- <span style="
385
- padding: 4px 8px;
386
- background: ${item.role === 'Admin' ? '#dbeafe' : '#f3f4f6'};
387
- color: ${item.role === 'Admin' ? '#1e40af' : '#374151'};
388
- border-radius: 12px;
389
- font-size: 11px;
390
- font-weight: 600;
391
- ">${item.role}</span>
392
- </div>
393
- `;
394
-
395
- // Example 3: Product selection with images and pricing
396
- const products = [
397
- {
398
- value: 'p1',
399
- label: 'Premium Laptop',
400
- price: 1299.99,
401
- stock: 15,
402
- image: 'https://via.placeholder.com/60',
403
- badge: 'Best Seller'
404
- },
405
- {
406
- value: 'p2',
407
- label: 'Wireless Mouse',
408
- price: 29.99,
409
- stock: 150,
410
- image: 'https://via.placeholder.com/60',
411
- badge: null
412
- },
413
- {
414
- value: 'p3',
415
- label: 'Mechanical Keyboard',
416
- price: 89.99,
417
- stock: 0,
418
- image: 'https://via.placeholder.com/60',
419
- badge: 'Out of Stock'
420
- }
421
- ];
422
-
423
- select.items = products;
424
- select.optionTemplate = (item, index) => `
425
- <div style="display: flex; align-items: center; gap: 12px; opacity: ${item.stock === 0 ? '0.5' : '1'};">
426
- <img
427
- src="${item.image}"
428
- alt="${item.label}"
429
- style="width: 60px; height: 60px; border-radius: 8px; object-fit: cover; border: 1px solid #e5e7eb;"
430
- />
431
- <div style="flex: 1;">
432
- <div style="display: flex; align-items: center; gap: 8px;">
433
- <span style="font-weight: 600; color: #1f2937;">${item.label}</span>
434
- ${item.badge ? `
435
- <span style="
436
- padding: 2px 6px;
437
- background: ${item.badge === 'Best Seller' ? '#dcfce7' : '#fee2e2'};
438
- color: ${item.badge === 'Best Seller' ? '#166534' : '#991b1b'};
439
- border-radius: 4px;
440
- font-size: 10px;
441
- font-weight: 600;
442
- ">${item.badge}</span>
443
- ` : ''}
444
- </div>
445
- <div style="margin-top: 4px; display: flex; justify-content: space-between; align-items: center;">
446
- <span style="font-size: 16px; font-weight: 700; color: #059669;">$${item.price.toFixed(2)}</span>
447
- <span style="font-size: 12px; color: #6b7280;">${item.stock > 0 ? `${item.stock} in stock` : 'Out of stock'}</span>
448
- </div>
449
- </div>
450
- </div>
451
- `;
452
-
453
- // Example 4: Status indicators with conditional styling
454
- const tasks = [
455
- { value: 't1', label: 'Design Homepage', status: 'completed', priority: 'high', assignee: 'John' },
456
- { value: 't2', label: 'API Integration', status: 'in-progress', priority: 'high', assignee: 'Jane' },
457
- { value: 't3', label: 'Write Documentation', status: 'pending', priority: 'medium', assignee: 'Bob' },
458
- { value: 't4', label: 'Bug Fixes', status: 'in-progress', priority: 'low', assignee: 'Alice' }
459
- ];
460
-
461
- const statusColors = {
462
- 'completed': { bg: '#dcfce7', color: '#166534', icon: '✓' },
463
- 'in-progress': { bg: '#dbeafe', color: '#1e40af', icon: '⟳' },
464
- 'pending': { bg: '#fef3c7', color: '#92400e', icon: '○' }
465
- };
307
+ For custom option content, assign `optionRenderer`. It returns an `HTMLElement`; this example uses `textContent` so item text is not parsed as HTML.
466
308
 
467
- const priorityColors = {
468
- 'high': '#ef4444',
469
- 'medium': '#f59e0b',
470
- 'low': '#10b981'
471
- };
472
-
473
- select.items = tasks;
474
- select.optionTemplate = (item, index) => {
475
- const status = statusColors[item.status];
476
- return `
477
- <div style="display: flex; align-items: center; gap: 10px; padding: 4px 0;">
478
- <div style="
479
- width: 24px;
480
- height: 24px;
481
- border-radius: 50%;
482
- background: ${status.bg};
483
- color: ${status.color};
484
- display: flex;
485
- align-items: center;
486
- justify-content: center;
487
- font-weight: bold;
488
- ">${status.icon}</div>
489
- <div style="flex: 1;">
490
- <div style="font-weight: 600; color: #1f2937;">${item.label}</div>
491
- <div style="font-size: 12px; color: #6b7280; margin-top: 2px;">
492
- Assigned to ${item.assignee}
493
- </div>
494
- </div>
495
- <div style="
496
- width: 8px;
497
- height: 8px;
498
- border-radius: 50%;
499
- background: ${priorityColors[item.priority]};
500
- " title="${item.priority} priority"></div>
501
- </div>
502
- `;
309
+ ```typescript
310
+ select.optionRenderer = (item, index) => {
311
+ const option = item as SelectItem;
312
+ const row = document.createElement('div');
313
+ row.className = 'language-option';
314
+ row.textContent = `${index + 1}. ${option.label}`;
315
+ return row;
503
316
  };
504
317
  ```
505
318
 
506
- ### Comparison: When to Use Each Method
507
-
508
- | Feature | Method 1: Object Arrays | Method 2: Custom Renderers |
509
- |---------|------------------------|---------------------------|
510
- | **Setup Complexity** | ⭐ Simple | ⭐⭐ Moderate |
511
- | **Rendering Speed** | ⭐⭐⭐ Fastest | ⭐⭐ Fast |
512
- | **Visual Customization** | ⭐⭐ Limited | ⭐⭐⭐ Unlimited |
513
- | **Use Case** | Standard dropdowns | Rich, complex UIs |
514
- | **Code Amount** | Minimal | More code |
515
- | **TypeScript Support** | ⭐⭐⭐ Full | ⭐⭐⭐ Full |
516
- | **Performance (1M items)** | ⭐⭐⭐ Excellent | ⭐⭐ Good |
517
- | **Learning Curve** | ⭐ Easy | ⭐⭐ Medium |
518
-
519
- **Best Practices**:
520
-
521
- ✅ **Use Method 1 (Object Arrays) when**:
522
- - You need simple text-based options
523
- - Performance is critical (millions of items)
524
- - You want minimal code
525
- - Built-in search/filter is sufficient
526
-
527
- ✅ **Use Method 2 (Custom Renderers) when**:
528
- - You need images, icons, or badges
529
- - Options require multiple lines of text
530
- - Custom styling/layout is important
531
- - Conditional rendering based on data
532
- - Rich user experience is priority
533
-
534
- ### Combining Both Methods
535
-
536
- You can start with Method 1 and add Method 2 later as your UI evolves:
537
-
538
- ```javascript
539
- // Start simple
540
- select.items = ['Option 1', 'Option 2', 'Option 3'];
541
-
542
- // Later, add custom rendering without changing items
543
- select.optionTemplate = (item, index) => `
544
- <div style="padding: 8px; background: ${index % 2 ? '#f9fafb' : 'white'};">
545
- <strong>${item.label || item}</strong>
546
- </div>
547
- `;
548
- ```
319
+ `optionRenderer` is the maintained `EnhancedSelect` API. The legacy `NativeSelectElement` has a separate compatibility surface; do not copy its `optionTemplate` examples into `enhanced-select` integrations.
549
320
 
550
321
  ---
551
322
 
@@ -586,8 +357,8 @@ select.clear();
586
357
  // Focus the select
587
358
  select.focus();
588
359
 
589
- // Get filtered items (useful for debugging)
590
- const filtered = select.getFilteredItems();
360
+ // Read selected items through the declared API
361
+ const selectedItems = select.getSelectedItems();
591
362
  ```
592
363
 
593
364
  ## Advanced Usage
@@ -744,7 +515,7 @@ enhanced-select.dark-mode {
744
515
 
745
516
  ### Keyboard Navigation & Accessibility
746
517
 
747
- Smilodon provides full keyboard accessibility (WCAG 2.2 AA compliant):
518
+ The component implements keyboard interaction paths including:
748
519
 
749
520
  | Key | Action |
750
521
  |-----|--------|
@@ -1306,22 +1077,13 @@ if (typeof window !== 'undefined') {
1306
1077
 
1307
1078
  ### Performance Monitoring
1308
1079
 
1309
- Enable telemetry to monitor performance:
1310
-
1311
- ```javascript
1312
- select.enableTelemetry = true;
1313
-
1314
- select.addEventListener('telemetry', (event) => {
1315
- console.log('Performance metrics:', event.detail);
1316
- // { renderTime, searchTime, scrollFPS, memoryUsage }
1317
- });
1318
- ```
1080
+ The Core package exports `getTelemetry()` for frame and long-task measurements in browser environments. See its emitted TypeScript declarations for the available snapshot fields and lifecycle methods. It is not enabled by assigning a property to the custom element.
1319
1081
 
1320
1082
  ## Architecture
1321
1083
 
1322
1084
  Smilodon's performance comes from three core optimizations:
1323
1085
 
1324
- 1. **Virtual Scrolling**: Only renders visible items (10-15 DOM nodes for any dataset size)
1086
+ 1. **Chunked rendering**: Splits large-list rendering work into chunks; the public mode does not guarantee a fixed number of mounted DOM nodes.
1325
1087
  2. **Work Stealing Scheduler**: Search operations run in background workers with automatic cancellation
1326
1088
  3. **Fenwick Tree Indexing**: O(log n) search queries instead of O(n) array scans
1327
1089
 
@@ -1349,15 +1111,16 @@ Requires browsers with native Web Components support (custom elements v1).
1349
1111
  Full TypeScript definitions included. No need for `@types/*` packages.
1350
1112
 
1351
1113
  ```typescript
1352
- import type { SmilodonSelectElement, SelectItem } from '@smilodon/core';
1114
+ import type { EnhancedSelect, SelectItem } from '@smilodon/core';
1353
1115
 
1354
1116
  const items: SelectItem[] = [
1355
1117
  { label: 'Option 1', value: 1 },
1356
1118
  { label: 'Option 2', value: 2 }
1357
1119
  ];
1358
1120
 
1359
- const select = document.querySelector('smilodon-select') as SmilodonSelectElement;
1360
- select.items = items;
1121
+ const select = document.querySelector('enhanced-select') as EnhancedSelect | null;
1122
+ if (!select) throw new Error('EnhancedSelect element not found');
1123
+ select.setItems(items);
1361
1124
  ```
1362
1125
 
1363
1126
  ## Documentation