NakliTechie commited on
Commit
2a67fa4
·
1 Parent(s): f4899fa

Sync from GitHub 2026-10-22T16:51:41Z

Browse files
Files changed (1) hide show
  1. index.html +54 -7
index.html CHANGED
@@ -1900,6 +1900,11 @@
1900
  /* Delete control on stored rows: removes that model's files without selecting it. */
1901
  .mp-del { align-self: center; flex: none; padding: 2px 6px; font-size: 0.68rem; }
1902
  .mp-del:focus-visible { outline: 2px solid var(--indigo-500); }
 
 
 
 
 
1903
  .model-picker-note { font-size: 0.7rem; color: var(--gray-600); padding: 6px 8px 2px; border-top: 1px solid var(--gray-200); margin-top: 4px; }
1904
 
1905
  .mode-divider { width: 1px; height: 16px; background: var(--gray-200); margin: 0 4px; flex: none; align-self: center; }
@@ -2298,6 +2303,7 @@
2298
  .actions-bar .model-picker-wrap { order: -1; flex: 1 1 100%; max-width: 100%; }
2299
  .model-picker-btn { max-width: 100%; width: 100%; }
2300
  .model-picker { left: 0; right: 0; width: auto; }
 
2301
  .actions-bar .flex-spacer { display: none; }
2302
  .btn-icon { padding: 7px 10px; font-size: 0.8rem; }
2303
  .mode-chip { padding: 6px 11px; }
@@ -3005,6 +3011,8 @@
3005
  already in this browser; picking sets the select's value and fires its change event. -->
3006
  <span class="model-picker-wrap">
3007
  <button type="button" class="model-select model-picker-btn" id="modelPickerBtn" aria-haspopup="listbox" aria-expanded="false" aria-controls="modelPickerList"></button>
 
 
3008
  <div class="model-picker" id="modelPicker" hidden>
3009
  <div role="listbox" id="modelPickerList" aria-label="Models" tabindex="-1"></div>
3010
  <p class="model-picker-note">A model downloads once, then loads from this browser.</p>
@@ -19334,6 +19342,7 @@ self.addEventListener('message', async (e) => {
19334
  const modelPickerBtn = document.getElementById('modelPickerBtn');
19335
  const modelPicker = document.getElementById('modelPicker');
19336
  const modelPickerList = document.getElementById('modelPickerList');
 
19337
  const ENGINE_STORES = {
19338
  'transformers': ['transformers-cache'], 'wllama': ['wllama'], 'lfm2-webgpu': ['gguf-v1'],
19339
  'bonsai2-webgpu': ['gguf-cache-v1'], 'gemma4-webgpu': ['safetensors-cache-v1', 'bonsai-pipeline-v1'],
@@ -19372,8 +19381,10 @@ self.addEventListener('message', async (e) => {
19372
  let pickerGroups = null;
19373
  function renderModelPicker() {
19374
  const rows = { device: [], partial: [], download: [] };
 
19375
  for (const o of modelSelect.options) {
19376
  const m = MODELS[o.value]; if (!m) continue;
 
19377
  const state = modelCacheState(m, pickerGroups);
19378
  const meta = m.backend === 'chrome-ai' ? 'built into Chrome'
19379
  : m.backend === 'endpoint' ? 'local server'
@@ -19409,6 +19420,14 @@ self.addEventListener('message', async (e) => {
19409
  }
19410
  modelPickerList.appendChild(group);
19411
  }
 
 
 
 
 
 
 
 
19412
  }
19413
  const pickerRows = () => [...modelPickerList.querySelectorAll('.mp-opt:not([aria-disabled="true"])')];
19414
  function focusPickerRow(row) {
@@ -19416,27 +19435,32 @@ self.addEventListener('message', async (e) => {
19416
  if (!row) return;
19417
  row.classList.add('focused');
19418
  modelPickerList.setAttribute('aria-activedescendant', row.id);
 
19419
  row.scrollIntoView({ block: 'nearest' });
19420
  }
19421
- function openModelPicker() {
19422
  if (modelPickerBtn.disabled) return;
 
 
19423
  renderModelPicker();
19424
  modelPicker.hidden = false;
 
19425
  modelPickerBtn.setAttribute('aria-expanded', 'true');
19426
- focusPickerRow(modelPickerList.querySelector('.mp-opt[aria-selected="true"]') || pickerRows()[0]);
19427
- modelPickerList.focus();
19428
  // Cache state needs a storage walk; draw first, then redraw with it.
19429
  inventoryModelCaches().then((g) => {
19430
  pickerGroups = g;
19431
  if (modelPicker.hidden) return;
19432
  const focused = modelPickerList.querySelector('.mp-opt.focused')?.dataset.value;
19433
  renderModelPicker();
19434
- focusPickerRow(modelPickerList.querySelector(`.mp-opt[data-value="${CSS.escape(focused || modelSelect.value)}"]`));
19435
  }).catch(() => {});
19436
  }
19437
  function closeModelPicker(returnFocus) {
19438
  if (modelPicker.hidden) return;
19439
  modelPicker.hidden = true;
 
19440
  modelPickerBtn.setAttribute('aria-expanded', 'false');
19441
  if (returnFocus) modelPickerBtn.focus();
19442
  }
@@ -19453,6 +19477,29 @@ self.addEventListener('message', async (e) => {
19453
  modelPickerBtn.addEventListener('click', () => (modelPicker.hidden ? openModelPicker() : closeModelPicker(false)));
19454
  modelPickerBtn.addEventListener('keydown', (e) => {
19455
  if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); openModelPicker(); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19456
  });
19457
  // A picker row's delete control: confirm with the name and the bytes it frees, then delete that model's stores
19458
  // (deleteModelCaches unloads it first when it is the loaded model). Never selects or loads the row.
@@ -19464,11 +19511,11 @@ self.addEventListener('message', async (e) => {
19464
  const shared = others.length ? ` This also removes ${others.join(' and ')}, which use${others.length === 1 ? 's' : ''} the same files.` : '';
19465
  const active = value === activeModelKey || (MODELS[activeModelKey] && repoForModel(MODELS[activeModelKey]) === g.repo);
19466
  if (!confirm(`Delete ${name} from this device? This frees ${fmtBytes(g.bytes)}.${shared}${active ? ' The model is unloaded first.' : ''} It downloads again the next time you load it.`)) {
19467
- modelPickerList.focus();
19468
  return;
19469
  }
19470
  if (await deleteModelCaches([g])) showToast(`Deleted ${name} — ${fmtBytes(g.bytes)} freed`);
19471
- if (!modelPicker.hidden) { modelPickerList.focus(); focusPickerRow(modelPickerList.querySelector(`.mp-opt[data-value="${CSS.escape(value)}"]`) || pickerRows()[0]); }
19472
  }
19473
  modelPickerList.addEventListener('click', (e) => {
19474
  const del = e.target.closest('.mp-del');
@@ -19480,7 +19527,7 @@ self.addEventListener('message', async (e) => {
19480
  // On a delete control: Enter/Space press it (the button's own click), Shift+Tab goes back to the list, Escape closes.
19481
  if (e.target.closest('.mp-del')) {
19482
  if (e.key === 'Escape') { e.preventDefault(); closeModelPicker(true); }
19483
- else if (e.key === 'Tab' && e.shiftKey) { e.preventDefault(); modelPickerList.focus(); }
19484
  else if (e.key === 'Tab') closeModelPicker(false);
19485
  return;
19486
  }
 
1900
  /* Delete control on stored rows: removes that model's files without selecting it. */
1901
  .mp-del { align-self: center; flex: none; padding: 2px 6px; font-size: 0.68rem; }
1902
  .mp-del:focus-visible { outline: 2px solid var(--indigo-500); }
1903
+ /* Type-to-filter field at the top of the picker: the picker is a combo box. */
1904
+ .mp-filter { position: absolute; top: 0; bottom: 0; right: 0; width: max(100%, 260px); box-sizing: border-box; z-index: 81; cursor: text; }
1905
+ .mp-filter[hidden] { display: none; }
1906
+ .mp-filter:focus, .mp-filter:focus-visible { outline: none; border-color: var(--indigo-500); }
1907
+ .mp-empty { font-size: 0.78rem; color: var(--gray-600); padding: 8px; }
1908
  .model-picker-note { font-size: 0.7rem; color: var(--gray-600); padding: 6px 8px 2px; border-top: 1px solid var(--gray-200); margin-top: 4px; }
1909
 
1910
  .mode-divider { width: 1px; height: 16px; background: var(--gray-200); margin: 0 4px; flex: none; align-self: center; }
 
2303
  .actions-bar .model-picker-wrap { order: -1; flex: 1 1 100%; max-width: 100%; }
2304
  .model-picker-btn { max-width: 100%; width: 100%; }
2305
  .model-picker { left: 0; right: 0; width: auto; }
2306
+ .mp-filter { font-size: 16px; } /* under 16px, iPhone Safari zooms the page on focus */
2307
  .actions-bar .flex-spacer { display: none; }
2308
  .btn-icon { padding: 7px 10px; font-size: 0.8rem; }
2309
  .mode-chip { padding: 6px 11px; }
 
3011
  already in this browser; picking sets the select's value and fires its change event. -->
3012
  <span class="model-picker-wrap">
3013
  <button type="button" class="model-select model-picker-btn" id="modelPickerBtn" aria-haspopup="listbox" aria-expanded="false" aria-controls="modelPickerList"></button>
3014
+ <!-- While the list is open, this field sits over the button: you type in place to narrow the list. -->
3015
+ <input type="text" class="model-select mp-filter" id="modelPickerFilter" role="combobox" aria-autocomplete="list" aria-expanded="true" aria-controls="modelPickerList" aria-label="Find a model" placeholder="Type to find a model" autocomplete="off" spellcheck="false" hidden>
3016
  <div class="model-picker" id="modelPicker" hidden>
3017
  <div role="listbox" id="modelPickerList" aria-label="Models" tabindex="-1"></div>
3018
  <p class="model-picker-note">A model downloads once, then loads from this browser.</p>
 
19342
  const modelPickerBtn = document.getElementById('modelPickerBtn');
19343
  const modelPicker = document.getElementById('modelPicker');
19344
  const modelPickerList = document.getElementById('modelPickerList');
19345
+ const modelPickerFilter = document.getElementById('modelPickerFilter');
19346
  const ENGINE_STORES = {
19347
  'transformers': ['transformers-cache'], 'wllama': ['wllama'], 'lfm2-webgpu': ['gguf-v1'],
19348
  'bonsai2-webgpu': ['gguf-cache-v1'], 'gemma4-webgpu': ['safetensors-cache-v1', 'bonsai-pipeline-v1'],
 
19381
  let pickerGroups = null;
19382
  function renderModelPicker() {
19383
  const rows = { device: [], partial: [], download: [] };
19384
+ const terms = modelPickerFilter.value.toLowerCase().split(/\s+/).filter(Boolean);
19385
  for (const o of modelSelect.options) {
19386
  const m = MODELS[o.value]; if (!m) continue;
19387
+ if (!pickerMatches(o, m, terms)) continue;
19388
  const state = modelCacheState(m, pickerGroups);
19389
  const meta = m.backend === 'chrome-ai' ? 'built into Chrome'
19390
  : m.backend === 'endpoint' ? 'local server'
 
19420
  }
19421
  modelPickerList.appendChild(group);
19422
  }
19423
+ if (!modelPickerList.children.length) modelPickerList.innerHTML = `<div class="mp-empty">No model matches "${escapeHtml(modelPickerFilter.value.trim())}".</div>`;
19424
+ }
19425
+ // Every typed word must appear in the option's text, the model's label, its id, or its engine name
19426
+ // ("ssd", "agent", "vision", "gguf", "27b" all work).
19427
+ function pickerMatches(o, m, terms) {
19428
+ if (!terms.length) return true;
19429
+ const hay = [o.textContent, m.label, o.value, m.id, m.backend].filter(Boolean).join(' ').toLowerCase();
19430
+ return terms.every(t => hay.includes(t));
19431
  }
19432
  const pickerRows = () => [...modelPickerList.querySelectorAll('.mp-opt:not([aria-disabled="true"])')];
19433
  function focusPickerRow(row) {
 
19435
  if (!row) return;
19436
  row.classList.add('focused');
19437
  modelPickerList.setAttribute('aria-activedescendant', row.id);
19438
+ modelPickerFilter.setAttribute('aria-activedescendant', row.id);
19439
  row.scrollIntoView({ block: 'nearest' });
19440
  }
19441
+ function openModelPicker(initial) {
19442
  if (modelPickerBtn.disabled) return;
19443
+ modelPickerFilter.value = typeof initial === 'string' ? initial : '';
19444
+ modelPickerFilter.placeholder = modelPickerBtn.textContent || 'Type to find a model';
19445
  renderModelPicker();
19446
  modelPicker.hidden = false;
19447
+ modelPickerFilter.hidden = false;
19448
  modelPickerBtn.setAttribute('aria-expanded', 'true');
19449
+ focusPickerRow((!modelPickerFilter.value && modelPickerList.querySelector('.mp-opt[aria-selected="true"]')) || pickerRows()[0]);
19450
+ modelPickerFilter.focus();
19451
  // Cache state needs a storage walk; draw first, then redraw with it.
19452
  inventoryModelCaches().then((g) => {
19453
  pickerGroups = g;
19454
  if (modelPicker.hidden) return;
19455
  const focused = modelPickerList.querySelector('.mp-opt.focused')?.dataset.value;
19456
  renderModelPicker();
19457
+ focusPickerRow(modelPickerList.querySelector(`.mp-opt[data-value="${CSS.escape(focused || modelSelect.value)}"]`) || pickerRows()[0]);
19458
  }).catch(() => {});
19459
  }
19460
  function closeModelPicker(returnFocus) {
19461
  if (modelPicker.hidden) return;
19462
  modelPicker.hidden = true;
19463
+ modelPickerFilter.hidden = true;
19464
  modelPickerBtn.setAttribute('aria-expanded', 'false');
19465
  if (returnFocus) modelPickerBtn.focus();
19466
  }
 
19477
  modelPickerBtn.addEventListener('click', () => (modelPicker.hidden ? openModelPicker() : closeModelPicker(false)));
19478
  modelPickerBtn.addEventListener('keydown', (e) => {
19479
  if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); openModelPicker(); }
19480
+ // Typing a letter on the closed picker opens it with that letter in the filter.
19481
+ else if (e.key.length === 1 && e.key !== ' ' && !e.ctrlKey && !e.metaKey && !e.altKey) { e.preventDefault(); openModelPicker(e.key); }
19482
+ });
19483
+ modelPickerFilter.addEventListener('input', () => {
19484
+ renderModelPicker();
19485
+ focusPickerRow(pickerRows()[0]);
19486
+ });
19487
+ // The filter owns the keyboard while the picker is open: arrows move the highlighted row, Enter picks it,
19488
+ // Escape clears the text first and closes on an empty field. Home/End and Backspace stay text editing.
19489
+ modelPickerFilter.addEventListener('keydown', (e) => {
19490
+ const rows = pickerRows();
19491
+ const i = rows.indexOf(modelPickerList.querySelector('.mp-opt.focused'));
19492
+ if (e.key === 'ArrowDown') { e.preventDefault(); focusPickerRow(rows[Math.min(rows.length - 1, i + 1)]); }
19493
+ else if (e.key === 'ArrowUp') { e.preventDefault(); focusPickerRow(rows[Math.max(0, i - 1)]); }
19494
+ else if (e.key === 'PageDown') { e.preventDefault(); focusPickerRow(rows[rows.length - 1]); }
19495
+ else if (e.key === 'PageUp') { e.preventDefault(); focusPickerRow(rows[0]); }
19496
+ else if (e.key === 'Enter') { e.preventDefault(); if (rows[i]) pickModel(rows[i].dataset.value); }
19497
+ else if (e.key === 'Escape') {
19498
+ e.preventDefault();
19499
+ if (modelPickerFilter.value) { modelPickerFilter.value = ''; renderModelPicker(); focusPickerRow(modelPickerList.querySelector('.mp-opt[aria-selected="true"]') || pickerRows()[0]); }
19500
+ else closeModelPicker(true);
19501
+ }
19502
+ else if (e.key === 'Tab') closeModelPicker(false);
19503
  });
19504
  // A picker row's delete control: confirm with the name and the bytes it frees, then delete that model's stores
19505
  // (deleteModelCaches unloads it first when it is the loaded model). Never selects or loads the row.
 
19511
  const shared = others.length ? ` This also removes ${others.join(' and ')}, which use${others.length === 1 ? 's' : ''} the same files.` : '';
19512
  const active = value === activeModelKey || (MODELS[activeModelKey] && repoForModel(MODELS[activeModelKey]) === g.repo);
19513
  if (!confirm(`Delete ${name} from this device? This frees ${fmtBytes(g.bytes)}.${shared}${active ? ' The model is unloaded first.' : ''} It downloads again the next time you load it.`)) {
19514
+ modelPickerFilter.focus();
19515
  return;
19516
  }
19517
  if (await deleteModelCaches([g])) showToast(`Deleted ${name} — ${fmtBytes(g.bytes)} freed`);
19518
+ if (!modelPicker.hidden) { modelPickerFilter.focus(); focusPickerRow(modelPickerList.querySelector(`.mp-opt[data-value="${CSS.escape(value)}"]`) || pickerRows()[0]); }
19519
  }
19520
  modelPickerList.addEventListener('click', (e) => {
19521
  const del = e.target.closest('.mp-del');
 
19527
  // On a delete control: Enter/Space press it (the button's own click), Shift+Tab goes back to the list, Escape closes.
19528
  if (e.target.closest('.mp-del')) {
19529
  if (e.key === 'Escape') { e.preventDefault(); closeModelPicker(true); }
19530
+ else if (e.key === 'Tab' && e.shiftKey) { e.preventDefault(); modelPickerFilter.focus(); }
19531
  else if (e.key === 'Tab') closeModelPicker(false);
19532
  return;
19533
  }