@smilodon/core 1.10.0 → 1.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +130 -371
  2. package/dist/index.cjs +1931 -24
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +1931 -25
  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 +1931 -24
  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 +71 -7
  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 +5 -3
  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/index.d.ts +2 -0
  20. package/dist/types/src/native-types.d.ts +5 -0
  21. package/dist/types/src/renderers/contracts.d.ts +1 -1
  22. package/dist/types/src/types/limitation.d.ts +6 -0
  23. package/dist/types/src/types.d.ts +2 -6
  24. package/dist/types/src/utils/custom-option-pool.d.ts +1 -1
  25. package/package.json +7 -4
  26. package/dist/types/src/themes/importer.d.ts +0 -112
  27. package/dist/types/tests/accessibility-contract.spec.d.ts +0 -1
  28. package/dist/types/tests/capabilities-tracking.spec.d.ts +0 -1
  29. package/dist/types/tests/csp.spec.d.ts +0 -5
  30. package/dist/types/tests/enhanced-option-renderer.spec.d.ts +0 -1
  31. package/dist/types/tests/enhanced-select-accessibility-integration.spec.d.ts +0 -1
  32. package/dist/types/tests/enhanced-select-active-authority.spec.d.ts +0 -1
  33. package/dist/types/tests/enhanced-select-active-parity.spec.d.ts +0 -1
  34. package/dist/types/tests/enhanced-select-authority.spec.d.ts +0 -1
  35. package/dist/types/tests/enhanced-select-compatibility-projection.spec.d.ts +0 -1
  36. package/dist/types/tests/enhanced-select-selection-parity.spec.d.ts +0 -1
  37. package/dist/types/tests/enhanced-select-virtualization-integration.spec.d.ts +0 -1
  38. package/dist/types/tests/interaction.spec.d.ts +0 -1
  39. package/dist/types/tests/item-adapter.spec.d.ts +0 -1
  40. package/dist/types/tests/item-registry.spec.d.ts +0 -1
  41. package/dist/types/tests/lifecycle.spec.d.ts +0 -1
  42. package/dist/types/tests/memory-lifecycle.spec.d.ts +0 -1
  43. package/dist/types/tests/select-accessibility.spec.d.ts +0 -1
  44. package/dist/types/tests/select-selection.spec.d.ts +0 -1
  45. package/dist/types/tests/setup.d.ts +0 -6
  46. package/dist/types/tests/shadow-dom.spec.d.ts +0 -5
  47. package/dist/types/tests/smoke.spec.d.ts +0 -1
  48. package/dist/types/tests/stress.spec.d.ts +0 -5
  49. package/dist/types/tests/styling-contract.spec.d.ts +0 -1
  50. package/dist/types/tests/virtualization-contract.spec.d.ts +0 -1
  51. package/dist/types/tests/virtualizer.spec.d.ts +0 -1
  52. package/dist/types/tests/web-accessibility-effects.spec.d.ts +0 -1
package/README.md CHANGED
@@ -12,6 +12,63 @@
12
12
 
13
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
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
+
15
72
  ## 📖 Documentation
16
73
 
17
74
  **Live documentation & interactive examples:** [navidrezadoost.github.io/Smilodon](https://navidrezadoost.github.io/Smilodon/)
@@ -67,57 +124,56 @@ npm install @smilodon/core
67
124
 
68
125
  ## Quick Start
69
126
 
70
- ### 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
71
130
 
72
131
  ```html
73
132
  <!DOCTYPE html>
74
133
  <html>
75
- <head>
76
- <script type="module">
77
- import '@smilodon/core';
78
- </script>
79
- </head>
80
134
  <body>
81
- <smilodon-select id="my-select"></smilodon-select>
82
-
83
- <script type="module">
84
- const select = document.getElementById('my-select');
85
-
86
- // Generate 1 million items
87
- const items = Array.from({ length: 1_000_000 }, (_, i) => ({
88
- label: `Item ${i + 1}`,
89
- value: i + 1
90
- }));
91
-
92
- select.items = items;
93
-
94
- select.addEventListener('change', (e) => {
95
- console.log('Selected:', e.detail);
96
- });
97
- </script>
135
+ <enhanced-select id="my-select"></enhanced-select>
136
+ <script type="module" src="/src/main.js"></script>
98
137
  </body>
99
138
  </html>
100
139
  ```
101
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
+
102
157
  ### Framework Usage
103
158
 
104
- **`@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.
105
160
 
106
- 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:
107
162
 
108
163
  ```jsx
109
164
  // React, Vue, Svelte - all work the same way
110
165
  import '@smilodon/core';
111
- <smilodon-select ref={selectRef} />
166
+ <enhanced-select ref={selectRef} />
112
167
  ```
113
168
 
114
- **Optional Framework Adapters** (for enhanced developer experience):
169
+ **Framework adapters** (for framework-specific APIs):
115
170
  - **React**: `npm install @smilodon/react` - React hooks and components
116
171
  - **Vue**: `npm install @smilodon/vue` - Vue composables and components
117
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)
118
174
  - **Vanilla**: `npm install @smilodon/vanilla` - Vanilla JS helpers
119
175
 
120
- 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.
121
177
 
122
178
  **Note:** Angular support has been discontinued as of December 2025.
123
179
 
@@ -125,31 +181,20 @@ See the [main documentation](https://github.com/navidrezadoost/smilodon#readme)
125
181
 
126
182
  ## Key Features
127
183
 
128
- ### 🚀 Extreme Performance
184
+ ### Large-list behavior
129
185
  - **Chunked large-list rendering**: Reduces the size of an individual render task; it does not guarantee constant DOM or viewport-bounded mounting.
130
- - **Work Stealing**: Background search workers with automatic cancellation
131
- - **Sub-millisecond Search**: Fenwick tree indexing for O(log n) queries
186
+ - **Search and indexing**: Current behavior and limits are described in the API and performance documentation; no per-query latency guarantee is made here.
132
187
  - **Separate legacy virtualizer**: `NativeSelectElement` has its own compatibility implementation; do not infer its behavior from `EnhancedSelect`.
133
188
 
134
- ### 🎯 Production Ready
135
- - **TypeScript First**: Complete type definitions included
136
- - **Zero Dependencies**: 6.6 KB gzipped runtime
137
- - **Framework Agnostic**: Works with React, Vue, Svelte, or vanilla JS
138
- - **Accessibility**: ARIA and keyboard behavior is implemented; cross-browser and manual assistive-technology certification remains pending.
139
- - **Full keyboard navigation**: Enter/Space, Arrows, Home/End, PageUp/Down, Escape
140
- - **Multi-select modes**: wrap, horizontal, vertical, both (with drag-scroll)
141
-
142
- ### 🎨 CSS Framework Compatibility (`1.5.5`)
143
- - **Scoped mirrored styles**: class-based framework styles used by custom renderers are mirrored only into the options subtree, not the whole shadow root.
144
- - **Dark variant support**: `.dark`, `.dark-mode`, and theme-attribute variants propagate into custom-rendered option content.
145
- - **Stable state hooks**: `classMap`, `data-sm-state`, and Smilodon state classes stay available on custom option roots for hover, active, selected, and disabled styling.
146
- - **Accessible custom renderers**: nested interactive descendants are normalized by default so option renderers stay compatible with listbox semantics.
147
-
148
- ### 🔒 Enterprise Grade
149
- - **SOC2 Compliant**: Audit-ready security controls
150
- - **CSP Compatible**: No eval(), no inline scripts
151
- - **SBOM Included**: Full dependency transparency
152
- - **99.8% Test Coverage**: Unit, integration, and E2E tests
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.
153
198
 
154
199
  ## API Reference
155
200
 
@@ -195,23 +240,11 @@ The `--select-input-padding-with-clear` token applies only while the clear contr
195
240
  ### Properties
196
241
 
197
242
  ```typescript
198
- interface SmilodonSelectElement extends HTMLElement {
199
- items: SelectItem[] | string[] | number[]; // Dataset (can be millions of items)
200
- value: any; // Current selected value
201
- placeholder?: string; // Placeholder text
202
- searchable?: boolean; // Enable search (default: true)
203
- disabled?: boolean; // Disable the select
204
- multiple?: boolean; // Multiple selection mode
205
- virtualization?: boolean; // Enable virtualization (default: true)
206
- maxHeight?: number; // Max dropdown height in pixels
207
- }
243
+ import type { EnhancedSelect, SelectItem } from '@smilodon/core';
208
244
 
209
- interface SelectItem {
210
- label: string; // Display text
211
- value: any; // Value (can be any type)
212
- disabled?: boolean; // Disable this option
213
- group?: string; // Optgroup name
214
- }
245
+ const items: SelectItem[] = [{ label: 'One', value: 1 }];
246
+ const select = document.querySelector('enhanced-select') as EnhancedSelect | null;
247
+ if (select) select.setItems(items);
215
248
  ```
216
249
 
217
250
  > **Flexible Input Formats:**
@@ -223,16 +256,16 @@ interface SelectItem {
223
256
 
224
257
  #### Object Array (Traditional)
225
258
  ```javascript
226
- select.items = [
259
+ select.setItems([
227
260
  { value: 'apple', label: 'Apple' },
228
261
  { value: 'banana', label: 'Banana' },
229
262
  { value: 'cherry', label: 'Cherry' }
230
- ];
263
+ ]);
231
264
  ```
232
265
 
233
266
  #### String Array (Auto-converted)
234
267
  ```javascript
235
- select.items = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
268
+ select.setItems(['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']);
236
269
  // Automatically becomes:
237
270
  // [
238
271
  // { value: 'Apple', label: 'Apple' },
@@ -243,7 +276,7 @@ select.items = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
243
276
 
244
277
  #### Number Array (Auto-converted)
245
278
  ```javascript
246
- 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]);
247
280
  // Automatically becomes:
248
281
  // [
249
282
  // { value: 1, label: '1' },
@@ -254,302 +287,36 @@ select.items = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
254
287
 
255
288
  ---
256
289
 
257
- ## 🎯 Two Ways to Specify Options
258
-
259
- Smilodon provides **two powerful approaches** for defining select options, each optimized for different use cases:
260
-
261
- ### Method 1: Data-Driven (Object Arrays) 📊
262
-
263
- **Use when**: You have structured data and want simple, declarative option rendering.
264
-
265
- **Advantages**:
266
- - ✅ Simple and declarative
267
- - ✅ Auto-conversion from strings/numbers
268
- - ✅ Perfect for basic dropdowns
269
- - ✅ Zero boilerplate code
270
- - ✅ Extremely performant (millions of items)
271
- - ✅ Built-in search and filtering
272
- - ✅ TypeScript type safety
290
+ ## Supplying options and custom rendering
273
291
 
274
- **Examples**:
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.
275
293
 
276
- ```javascript
277
- // Simple object array
278
- const select = document.querySelector('enhanced-select');
279
-
280
- select.items = [
281
- { value: '1', label: 'Apple' },
282
- { value: '2', label: 'Banana' },
283
- { value: '3', label: 'Cherry' }
284
- ];
294
+ ```typescript
295
+ import type { EnhancedSelect, SelectItem } from '@smilodon/core';
285
296
 
286
- // With additional metadata
287
- select.items = [
288
- { value: 'us', label: 'United States', disabled: false },
289
- { value: 'ca', label: 'Canada', disabled: false },
290
- { value: 'mx', label: 'Mexico', disabled: true } // Disabled option
291
- ];
297
+ const select = document.querySelector('enhanced-select') as EnhancedSelect | null;
298
+ if (!select) throw new Error('EnhancedSelect element not found');
292
299
 
293
- // With grouping
294
- select.items = [
295
- { value: 'apple', label: 'Apple', group: 'Fruits' },
296
- { value: 'banana', label: 'Banana', group: 'Fruits' },
297
- { value: 'carrot', label: 'Carrot', group: 'Vegetables' },
298
- { value: 'broccoli', label: 'Broccoli', group: 'Vegetables' }
300
+ const items: SelectItem[] = [
301
+ { value: 'js', label: 'JavaScript' },
302
+ { value: 'py', label: 'Python' },
299
303
  ];
300
-
301
- // Auto-conversion from strings
302
- select.items = ['Red', 'Green', 'Blue', 'Yellow'];
303
-
304
- // Auto-conversion from numbers
305
- select.items = [10, 20, 30, 40, 50];
306
-
307
- // Large datasets (millions of items)
308
- select.items = Array.from({ length: 1_000_000 }, (_, i) => ({
309
- value: i,
310
- label: `Item ${i + 1}`
311
- }));
304
+ select.setItems(items);
312
305
  ```
313
306
 
314
- ### Method 2: Component-Driven (Custom Renderers) 🎨
307
+ For custom option content, assign `optionRenderer`. It returns an `HTMLElement`; this example uses `textContent` so item text is not parsed as HTML.
315
308
 
316
- **Use when**: You need rich, interactive option content with custom HTML/styling.
317
-
318
- **Advantages**:
319
- - ✅ Full control over option rendering
320
- - ✅ Rich content (images, icons, badges, multi-line text)
321
- - ✅ Custom HTML and styling
322
- - ✅ Interactive elements within options
323
- - ✅ Conditional rendering based on item data
324
- - ✅ Perfect for complex UIs (user cards, product listings, etc.)
325
-
326
- **How it works**: Provide an `optionTemplate` function that returns HTML string for each option.
327
-
328
- **Examples**:
329
-
330
- ```javascript
331
- const select = document.querySelector('enhanced-select');
332
-
333
- // Example 1: Simple custom template with icons
334
- const items = [
335
- { value: 'js', label: 'JavaScript', icon: '🟨', description: 'Dynamic scripting language' },
336
- { value: 'py', label: 'Python', icon: '🐍', description: 'General-purpose programming' },
337
- { value: 'rs', label: 'Rust', icon: '🦀', description: 'Systems programming language' }
338
- ];
339
-
340
- select.items = items;
341
- select.optionTemplate = (item, index) => `
342
- <div style="display: flex; align-items: center; gap: 12px;">
343
- <span style="font-size: 24px;">${item.icon}</span>
344
- <div>
345
- <div style="font-weight: 600;">${item.label}</div>
346
- <div style="font-size: 12px; color: #6b7280;">${item.description}</div>
347
- </div>
348
- </div>
349
- `;
350
-
351
- // Example 2: User selection with avatars
352
- const users = [
353
- {
354
- value: '1',
355
- label: 'John Doe',
356
- email: 'john@example.com',
357
- avatar: 'https://i.pravatar.cc/150?img=1',
358
- role: 'Admin'
359
- },
360
- {
361
- value: '2',
362
- label: 'Jane Smith',
363
- email: 'jane@example.com',
364
- avatar: 'https://i.pravatar.cc/150?img=2',
365
- role: 'User'
366
- },
367
- {
368
- value: '3',
369
- label: 'Bob Johnson',
370
- email: 'bob@example.com',
371
- avatar: 'https://i.pravatar.cc/150?img=3',
372
- role: 'Moderator'
373
- }
374
- ];
375
-
376
- select.items = users;
377
- select.optionTemplate = (item, index) => `
378
- <div style="display: flex; align-items: center; gap: 12px; padding: 4px 0;">
379
- <img
380
- src="${item.avatar}"
381
- alt="${item.label}"
382
- style="width: 40px; height: 40px; border-radius: 50%; object-fit: cover;"
383
- />
384
- <div style="flex: 1;">
385
- <div style="font-weight: 600; color: #1f2937;">${item.label}</div>
386
- <div style="font-size: 13px; color: #6b7280;">${item.email}</div>
387
- </div>
388
- <span style="
389
- padding: 4px 8px;
390
- background: ${item.role === 'Admin' ? '#dbeafe' : '#f3f4f6'};
391
- color: ${item.role === 'Admin' ? '#1e40af' : '#374151'};
392
- border-radius: 12px;
393
- font-size: 11px;
394
- font-weight: 600;
395
- ">${item.role}</span>
396
- </div>
397
- `;
398
-
399
- // Example 3: Product selection with images and pricing
400
- const products = [
401
- {
402
- value: 'p1',
403
- label: 'Premium Laptop',
404
- price: 1299.99,
405
- stock: 15,
406
- image: 'https://via.placeholder.com/60',
407
- badge: 'Best Seller'
408
- },
409
- {
410
- value: 'p2',
411
- label: 'Wireless Mouse',
412
- price: 29.99,
413
- stock: 150,
414
- image: 'https://via.placeholder.com/60',
415
- badge: null
416
- },
417
- {
418
- value: 'p3',
419
- label: 'Mechanical Keyboard',
420
- price: 89.99,
421
- stock: 0,
422
- image: 'https://via.placeholder.com/60',
423
- badge: 'Out of Stock'
424
- }
425
- ];
426
-
427
- select.items = products;
428
- select.optionTemplate = (item, index) => `
429
- <div style="display: flex; align-items: center; gap: 12px; opacity: ${item.stock === 0 ? '0.5' : '1'};">
430
- <img
431
- src="${item.image}"
432
- alt="${item.label}"
433
- style="width: 60px; height: 60px; border-radius: 8px; object-fit: cover; border: 1px solid #e5e7eb;"
434
- />
435
- <div style="flex: 1;">
436
- <div style="display: flex; align-items: center; gap: 8px;">
437
- <span style="font-weight: 600; color: #1f2937;">${item.label}</span>
438
- ${item.badge ? `
439
- <span style="
440
- padding: 2px 6px;
441
- background: ${item.badge === 'Best Seller' ? '#dcfce7' : '#fee2e2'};
442
- color: ${item.badge === 'Best Seller' ? '#166534' : '#991b1b'};
443
- border-radius: 4px;
444
- font-size: 10px;
445
- font-weight: 600;
446
- ">${item.badge}</span>
447
- ` : ''}
448
- </div>
449
- <div style="margin-top: 4px; display: flex; justify-content: space-between; align-items: center;">
450
- <span style="font-size: 16px; font-weight: 700; color: #059669;">$${item.price.toFixed(2)}</span>
451
- <span style="font-size: 12px; color: #6b7280;">${item.stock > 0 ? `${item.stock} in stock` : 'Out of stock'}</span>
452
- </div>
453
- </div>
454
- </div>
455
- `;
456
-
457
- // Example 4: Status indicators with conditional styling
458
- const tasks = [
459
- { value: 't1', label: 'Design Homepage', status: 'completed', priority: 'high', assignee: 'John' },
460
- { value: 't2', label: 'API Integration', status: 'in-progress', priority: 'high', assignee: 'Jane' },
461
- { value: 't3', label: 'Write Documentation', status: 'pending', priority: 'medium', assignee: 'Bob' },
462
- { value: 't4', label: 'Bug Fixes', status: 'in-progress', priority: 'low', assignee: 'Alice' }
463
- ];
464
-
465
- const statusColors = {
466
- 'completed': { bg: '#dcfce7', color: '#166534', icon: '✓' },
467
- 'in-progress': { bg: '#dbeafe', color: '#1e40af', icon: '⟳' },
468
- 'pending': { bg: '#fef3c7', color: '#92400e', icon: '○' }
469
- };
470
-
471
- const priorityColors = {
472
- 'high': '#ef4444',
473
- 'medium': '#f59e0b',
474
- 'low': '#10b981'
475
- };
476
-
477
- select.items = tasks;
478
- select.optionTemplate = (item, index) => {
479
- const status = statusColors[item.status];
480
- return `
481
- <div style="display: flex; align-items: center; gap: 10px; padding: 4px 0;">
482
- <div style="
483
- width: 24px;
484
- height: 24px;
485
- border-radius: 50%;
486
- background: ${status.bg};
487
- color: ${status.color};
488
- display: flex;
489
- align-items: center;
490
- justify-content: center;
491
- font-weight: bold;
492
- ">${status.icon}</div>
493
- <div style="flex: 1;">
494
- <div style="font-weight: 600; color: #1f2937;">${item.label}</div>
495
- <div style="font-size: 12px; color: #6b7280; margin-top: 2px;">
496
- Assigned to ${item.assignee}
497
- </div>
498
- </div>
499
- <div style="
500
- width: 8px;
501
- height: 8px;
502
- border-radius: 50%;
503
- background: ${priorityColors[item.priority]};
504
- " title="${item.priority} priority"></div>
505
- </div>
506
- `;
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;
507
316
  };
508
317
  ```
509
318
 
510
- ### Comparison: When to Use Each Method
511
-
512
- | Feature | Method 1: Object Arrays | Method 2: Custom Renderers |
513
- |---------|------------------------|---------------------------|
514
- | **Setup Complexity** | ⭐ Simple | ⭐⭐ Moderate |
515
- | **Rendering Speed** | ⭐⭐⭐ Fastest | ⭐⭐ Fast |
516
- | **Visual Customization** | ⭐⭐ Limited | ⭐⭐⭐ Unlimited |
517
- | **Use Case** | Standard dropdowns | Rich, complex UIs |
518
- | **Code Amount** | Minimal | More code |
519
- | **TypeScript Support** | ⭐⭐⭐ Full | ⭐⭐⭐ Full |
520
- | **Performance (1M items)** | ⭐⭐⭐ Excellent | ⭐⭐ Good |
521
- | **Learning Curve** | ⭐ Easy | ⭐⭐ Medium |
522
-
523
- **Best Practices**:
524
-
525
- ✅ **Use Method 1 (Object Arrays) when**:
526
- - You need simple text-based options
527
- - Performance is critical (millions of items)
528
- - You want minimal code
529
- - Built-in search/filter is sufficient
530
-
531
- ✅ **Use Method 2 (Custom Renderers) when**:
532
- - You need images, icons, or badges
533
- - Options require multiple lines of text
534
- - Custom styling/layout is important
535
- - Conditional rendering based on data
536
- - Rich user experience is priority
537
-
538
- ### Combining Both Methods
539
-
540
- You can start with Method 1 and add Method 2 later as your UI evolves:
541
-
542
- ```javascript
543
- // Start simple
544
- select.items = ['Option 1', 'Option 2', 'Option 3'];
545
-
546
- // Later, add custom rendering without changing items
547
- select.optionTemplate = (item, index) => `
548
- <div style="padding: 8px; background: ${index % 2 ? '#f9fafb' : 'white'};">
549
- <strong>${item.label || item}</strong>
550
- </div>
551
- `;
552
- ```
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.
553
320
 
554
321
  ---
555
322
 
@@ -590,8 +357,8 @@ select.clear();
590
357
  // Focus the select
591
358
  select.focus();
592
359
 
593
- // Get filtered items (useful for debugging)
594
- const filtered = select.getFilteredItems();
360
+ // Read selected items through the declared API
361
+ const selectedItems = select.getSelectedItems();
595
362
  ```
596
363
 
597
364
  ## Advanced Usage
@@ -1310,22 +1077,13 @@ if (typeof window !== 'undefined') {
1310
1077
 
1311
1078
  ### Performance Monitoring
1312
1079
 
1313
- Enable telemetry to monitor performance:
1314
-
1315
- ```javascript
1316
- select.enableTelemetry = true;
1317
-
1318
- select.addEventListener('telemetry', (event) => {
1319
- console.log('Performance metrics:', event.detail);
1320
- // { renderTime, searchTime, scrollFPS, memoryUsage }
1321
- });
1322
- ```
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.
1323
1081
 
1324
1082
  ## Architecture
1325
1083
 
1326
1084
  Smilodon's performance comes from three core optimizations:
1327
1085
 
1328
- 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.
1329
1087
  2. **Work Stealing Scheduler**: Search operations run in background workers with automatic cancellation
1330
1088
  3. **Fenwick Tree Indexing**: O(log n) search queries instead of O(n) array scans
1331
1089
 
@@ -1353,15 +1111,16 @@ Requires browsers with native Web Components support (custom elements v1).
1353
1111
  Full TypeScript definitions included. No need for `@types/*` packages.
1354
1112
 
1355
1113
  ```typescript
1356
- import type { SmilodonSelectElement, SelectItem } from '@smilodon/core';
1114
+ import type { EnhancedSelect, SelectItem } from '@smilodon/core';
1357
1115
 
1358
1116
  const items: SelectItem[] = [
1359
1117
  { label: 'Option 1', value: 1 },
1360
1118
  { label: 'Option 2', value: 2 }
1361
1119
  ];
1362
1120
 
1363
- const select = document.querySelector('smilodon-select') as SmilodonSelectElement;
1364
- 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);
1365
1124
  ```
1366
1125
 
1367
1126
  ## Documentation