@lynn123411/dsh-model-submenu 0.3.14 → 0.3.15

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/lib/client.js CHANGED
@@ -117,9 +117,13 @@ window.__ModuleLoader__.load({
117
117
  * @returns the metadata, or undefined when no model is live or it advertises none.
118
118
  */
119
119
  function liveReasoning(state) {
120
+ return currentCatalogModel(state)?.reasoning;
121
+ }
122
+ /** Find the current model by its provider and model IDs. */
123
+ function currentCatalogModel(state) {
120
124
  const current = state.current;
121
125
  if (current === null) return void 0;
122
- return state.groups.find((group) => group.id === current.provider)?.models.find((model) => model.id === current.model)?.reasoning;
126
+ return state.groups.find((group) => group.id === current.provider)?.models.find((model) => model.id === current.model);
123
127
  }
124
128
  /**
125
129
  * The selection in force, or null while the Host has not resolved one.
@@ -254,18 +258,7 @@ window.__ModuleLoader__.load({
254
258
  }
255
259
  //#endregion
256
260
  //#region \0dsh-css:/home/runner/work/my-dsh/my-dsh/plugins/dsh-model-submenu/src/client/ModelOptions.module.css.mjs
257
- const css = ".TcCbqa_pickerHost{display:contents}.TcCbqa_sliderCell{flex:auto;align-self:stretch;align-items:center;min-width:96px;display:flex}.TcCbqa_slider{cursor:pointer;touch-action:none;-webkit-user-select:none;user-select:none;outline:none;flex:1;align-items:center;min-width:0;height:100%;display:flex}.TcCbqa_slider[data-busy]{cursor:default}.TcCbqa_sliderTrack{corner-shape:round;background:var(--dsw-alias-border-l3);border-radius:999px;width:100%;height:16px;position:relative}.TcCbqa_sliderFill{corner-shape:round;pointer-events:none;border-radius:999px;transition:width .16s cubic-bezier(.2,0,0,1);position:absolute;top:0;bottom:0;left:0}.TcCbqa_sliderTick{corner-shape:round;background:var(--dsw-alias-label-tertiary);pointer-events:none;border-radius:50%;width:4px;height:4px;margin:-2px 0 0 -2px;position:absolute;top:50%}.TcCbqa_sliderTick[data-on]{background:#00000047}.TcCbqa_sliderKnob{box-sizing:border-box;corner-shape:round;background:var(--dsw-alias-label-primary-foreground);width:20px;height:20px;box-shadow:var(--dsw-elevation-soft);pointer-events:none;border-radius:50%;margin:-10px 0 0 -10px;transition:left .16s cubic-bezier(.2,0,0,1);position:absolute;top:50%}.TcCbqa_slider[data-dragging] .TcCbqa_sliderKnob,.TcCbqa_slider[data-dragging] .TcCbqa_sliderFill{transition:none}@media (prefers-reduced-motion:reduce){.TcCbqa_sliderKnob,.TcCbqa_sliderFill{transition:none}}.TcCbqa_slider[data-default] .TcCbqa_sliderKnob{background:var(--dsw-alias-bg-layer-1);border:1.5px solid var(--dsw-alias-label-tertiary);box-shadow:none}.TcCbqa_slider[data-busy] .TcCbqa_sliderKnob{opacity:.6}.TcCbqa_slider:focus-visible .TcCbqa_sliderTrack{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:3px}.TcCbqa_rowBadge{flex:none;margin-inline-start:6px}.TcCbqa_row{align-items:center;gap:2px;display:flex}.TcCbqa_rowPick{box-sizing:border-box;width:100%;min-width:0;min-height:34px;color:inherit;text-align:left;cursor:pointer;border-radius:var(--dsw-radius-md);padding-inline:6px;background:0 0;border:none;outline:none;flex:1;align-items:center;gap:4px;padding:5px 7px;display:flex}.TcCbqa_rowPick:hover:not(:disabled),.TcCbqa_rowPick:focus-visible{background:var(--dsw-alias-interactive-bg-hover)}.TcCbqa_rowPick:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}.TcCbqa_rowCopy{flex-direction:column;flex:1;min-width:0;display:flex}.TcCbqa_rowName{color:inherit;text-overflow:ellipsis;white-space:nowrap;font-size:11.5px;font-weight:400;line-height:17px;overflow:hidden}.TcCbqa_rowMeta{color:var(--dsw-alias-label-tertiary);text-overflow:ellipsis;white-space:nowrap;font-size:12px;line-height:18px;overflow:hidden}.TcCbqa_check{color:var(--dsw-alias-label-primary);flex:0 0 15px;place-items:center;display:grid}.TcCbqa_starButton{color:var(--dsw-alias-label-tertiary);cursor:pointer;border-radius:var(--dsw-radius-sm);opacity:0;background:0 0;border:none;outline:none;flex:none;place-items:center;width:26px;height:26px;display:grid}.TcCbqa_starButton:focus-visible{outline:2px solid var(--dsw-alias-border-l3)}.TcCbqa_row:hover .TcCbqa_starButton,.TcCbqa_row:focus-within .TcCbqa_starButton{opacity:1}.TcCbqa_starButton[aria-pressed=true]{color:var(--dsw-alias-state-warn-primary);opacity:1}@media (hover:none){.TcCbqa_starButton{opacity:1}}.TcCbqa_star{flex:none}.TcCbqa_notice{color:var(--dsw-alias-label-tertiary);justify-content:space-between;align-items:flex-start;gap:8px;padding:6px 10px;font-size:12px;line-height:18px;display:flex}.TcCbqa_retry{color:inherit;font:inherit;cursor:pointer;background:0 0;border:none;flex:none;padding:0;font-weight:600;text-decoration:underline}.TcCbqa_pickerDialog{gap:0;width:min(680px,100%);height:min(640px,80vh);padding:0}.TcCbqa_pickerContent,.TcCbqa_pickerContent>:last-child{flex-direction:column;flex:1;min-height:0;display:flex}.TcCbqa_pickerSearch{padding:0 20px 12px}.TcCbqa_pickerSearchInput{width:100%}.TcCbqa_pickerTabs{border-bottom:.5px solid var(--dsw-alias-border-l2);overscroll-behavior-x:contain;scrollbar-width:none;flex-wrap:nowrap;gap:2px;padding:0 16px;display:flex;overflow-x:auto}.TcCbqa_pickerTabs::-webkit-scrollbar{display:none}.TcCbqa_pickerTab{color:var(--dsw-alias-label-secondary);cursor:pointer;border-radius:var(--dsw-radius-sm);white-space:nowrap;background:0 0;border:none;outline:none;flex:none;padding:6px 10px;font-size:13px;line-height:18px}.TcCbqa_pickerTab:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}.TcCbqa_pickerTab[aria-selected=true]{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover);font-weight:600}.TcCbqa_pickerTab:focus-visible{outline:2px solid var(--dsw-alias-border-l3)}.TcCbqa_pickerList{flex:1;min-height:0;padding:8px 12px;overflow-y:auto}.TcCbqa_pickerFooter{border-top:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);align-items:center;gap:6px;padding:10px 20px;font-size:12px;line-height:18px;display:flex}.TcCbqa_footerHint{flex-wrap:wrap;align-items:center;gap:6px;display:flex}";
258
- const tagId = "@lynn123411/dsh-model-submenu/ModelOptions.module.css";
259
- if (typeof document !== "undefined") {
260
- let tag = document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]");
261
- if (tag === null) {
262
- tag = document.createElement("style");
263
- tag.dataset.plugin = "@lynn123411/dsh-model-submenu";
264
- tag.dataset.pluginCss = tagId;
265
- document.head.appendChild(tag);
266
- }
267
- tag.textContent = css;
268
- }
261
+ const stylesheet = ".TcCbqa_pickerHost{display:contents}.TcCbqa_sliderCell{flex:auto;align-self:stretch;align-items:center;min-width:96px;display:flex}.TcCbqa_slider{cursor:pointer;touch-action:none;-webkit-user-select:none;user-select:none;outline:none;flex:1;align-items:center;min-width:0;height:100%;display:flex}.TcCbqa_slider[data-busy]{cursor:default}.TcCbqa_sliderTrack{corner-shape:round;background:var(--dsw-alias-border-l3);border-radius:999px;width:100%;height:16px;position:relative}.TcCbqa_sliderFill{corner-shape:round;pointer-events:none;border-radius:999px;transition:width .16s cubic-bezier(.2,0,0,1);position:absolute;top:0;bottom:0;left:0}.TcCbqa_sliderTick{corner-shape:round;background:var(--dsw-alias-label-tertiary);pointer-events:none;border-radius:50%;width:4px;height:4px;margin:-2px 0 0 -2px;position:absolute;top:50%}.TcCbqa_sliderTick[data-on]{background:#00000047}.TcCbqa_sliderKnob{box-sizing:border-box;corner-shape:round;background:var(--dsw-alias-label-primary-foreground);width:20px;height:20px;box-shadow:var(--dsw-elevation-soft);pointer-events:none;border-radius:50%;margin:-10px 0 0 -10px;transition:left .16s cubic-bezier(.2,0,0,1);position:absolute;top:50%}.TcCbqa_slider[data-dragging] .TcCbqa_sliderKnob,.TcCbqa_slider[data-dragging] .TcCbqa_sliderFill{transition:none}@media (prefers-reduced-motion:reduce){.TcCbqa_sliderKnob,.TcCbqa_sliderFill{transition:none}}.TcCbqa_slider[data-default] .TcCbqa_sliderKnob{background:var(--dsw-alias-bg-layer-1);border:1.5px solid var(--dsw-alias-label-tertiary);box-shadow:none}.TcCbqa_slider[data-busy] .TcCbqa_sliderKnob{opacity:.6}.TcCbqa_slider:focus-visible .TcCbqa_sliderTrack{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:3px}.TcCbqa_rowBadge{flex:none;margin-inline-start:6px}.TcCbqa_row{align-items:center;gap:2px;display:flex}.TcCbqa_rowPick{box-sizing:border-box;width:100%;min-width:0;min-height:34px;color:inherit;text-align:left;cursor:pointer;border-radius:var(--dsw-radius-md);padding-inline:6px;background:0 0;border:none;outline:none;flex:1;align-items:center;gap:4px;padding:5px 7px;display:flex}.TcCbqa_rowPick:hover:not(:disabled),.TcCbqa_rowPick:focus-visible{background:var(--dsw-alias-interactive-bg-hover)}.TcCbqa_rowPick:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}.TcCbqa_rowCopy{flex-direction:column;flex:1;min-width:0;display:flex}.TcCbqa_rowName{color:inherit;text-overflow:ellipsis;white-space:nowrap;font-size:11.5px;font-weight:400;line-height:17px;overflow:hidden}.TcCbqa_rowMeta{color:var(--dsw-alias-label-tertiary);text-overflow:ellipsis;white-space:nowrap;font-size:12px;line-height:18px;overflow:hidden}.TcCbqa_check{color:var(--dsw-alias-label-primary);flex:0 0 15px;place-items:center;display:grid}.TcCbqa_starButton{color:var(--dsw-alias-label-tertiary);cursor:pointer;border-radius:var(--dsw-radius-sm);opacity:0;background:0 0;border:none;outline:none;flex:none;place-items:center;width:26px;height:26px;display:grid}.TcCbqa_starButton:focus-visible{outline:2px solid var(--dsw-alias-border-l3)}.TcCbqa_row:hover .TcCbqa_starButton,.TcCbqa_row:focus-within .TcCbqa_starButton{opacity:1}.TcCbqa_starButton[aria-pressed=true]{color:var(--dsw-alias-state-warn-primary);opacity:1}@media (hover:none){.TcCbqa_starButton{opacity:1}}.TcCbqa_star{flex:none}.TcCbqa_notice{color:var(--dsw-alias-label-tertiary);justify-content:space-between;align-items:flex-start;gap:8px;padding:6px 10px;font-size:12px;line-height:18px;display:flex}.TcCbqa_retry{color:inherit;font:inherit;cursor:pointer;background:0 0;border:none;flex:none;padding:0;font-weight:600;text-decoration:underline}.TcCbqa_pickerDialog{gap:0;width:min(680px,100%);height:min(640px,80vh);padding:0}.TcCbqa_pickerContent,.TcCbqa_pickerContent>:last-child{flex-direction:column;flex:1;min-height:0;display:flex}.TcCbqa_pickerSearch{padding:0 20px 12px}.TcCbqa_pickerSearchInput{width:100%}.TcCbqa_pickerTabs{border-bottom:.5px solid var(--dsw-alias-border-l2);overscroll-behavior-x:contain;scrollbar-width:none;flex-wrap:nowrap;gap:2px;padding:0 16px;display:flex;overflow-x:auto}.TcCbqa_pickerTabs::-webkit-scrollbar{display:none}.TcCbqa_pickerTab{color:var(--dsw-alias-label-secondary);cursor:pointer;border-radius:var(--dsw-radius-sm);white-space:nowrap;background:0 0;border:none;outline:none;flex:none;padding:6px 10px;font-size:13px;line-height:18px}.TcCbqa_pickerTab:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}.TcCbqa_pickerTab[aria-selected=true]{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover);font-weight:600}.TcCbqa_pickerTab:focus-visible{outline:2px solid var(--dsw-alias-border-l3)}.TcCbqa_pickerList{flex:1;min-height:0;padding:8px 12px;overflow-y:auto}.TcCbqa_pickerFooter{border-top:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);align-items:center;gap:6px;padding:10px 20px;font-size:12px;line-height:18px;display:flex}.TcCbqa_footerHint{flex-wrap:wrap;align-items:center;gap:6px;display:flex}";
269
262
  var ModelOptions_module_css_default = {
270
263
  "check": "TcCbqa_check",
271
264
  "footerHint": "TcCbqa_footerHint",
@@ -322,6 +315,7 @@ window.__ModuleLoader__.load({
322
315
  function EffortSlider({ steps, current, defaultActive, defaultIndex, defaultLabel, busy, label, onCommit }) {
323
316
  const trackRef = (0, react.useRef)(null);
324
317
  const dragRef = (0, react.useRef)(null);
318
+ const pointerRef = (0, react.useRef)(null);
325
319
  const [drag, setDrag] = (0, react.useState)(null);
326
320
  const [hold, setHold] = (0, react.useState)(null);
327
321
  const dragging = drag !== null;
@@ -334,7 +328,13 @@ window.__ModuleLoader__.load({
334
328
  setDrag(fraction);
335
329
  };
336
330
  (0, react.useEffect)(() => {
337
- if (!busy) setHold(null);
331
+ if (!busy) {
332
+ setHold(null);
333
+ return;
334
+ }
335
+ pointerRef.current = null;
336
+ dragRef.current = null;
337
+ setDrag(null);
338
338
  }, [busy]);
339
339
  (0, react.useEffect)(() => {
340
340
  setHold(null);
@@ -346,10 +346,11 @@ window.__ModuleLoader__.load({
346
346
  return fractionAt(clientX, rect.left, rect.width);
347
347
  };
348
348
  const onPointerDown = (event) => {
349
- if (busy) return;
349
+ if (busy || event.button !== 0 || pointerRef.current !== null) return;
350
350
  event.preventDefault();
351
351
  event.stopPropagation();
352
352
  setHold(null);
353
+ pointerRef.current = event.pointerId;
353
354
  beginDrag(fractionAtPointer(event.clientX));
354
355
  try {
355
356
  event.currentTarget.setPointerCapture(event.pointerId);
@@ -357,27 +358,28 @@ window.__ModuleLoader__.load({
357
358
  event.currentTarget.focus();
358
359
  };
359
360
  const onPointerMove = (event) => {
360
- if (dragRef.current === null || busy) return;
361
+ if (pointerRef.current !== event.pointerId || busy) return;
361
362
  beginDrag(fractionAtPointer(event.clientX));
362
363
  };
363
364
  const settle = (event, commit) => {
364
- if (dragRef.current === null) return;
365
- const next = detentAt(fractionAtPointer(event.clientX), steps.length);
365
+ if (pointerRef.current !== event.pointerId) return;
366
+ pointerRef.current = null;
366
367
  beginDrag(null);
367
- if (!commit) return;
368
+ if (!commit || busy) return;
369
+ const next = detentAt(fractionAtPointer(event.clientX), steps.length);
368
370
  if (next !== current || defaultActive) {
369
371
  setHold(offsetOf(next, steps.length));
370
372
  onCommit(next);
371
373
  }
372
374
  };
373
375
  const onKeyDown = (event) => {
374
- if (busy) return;
376
+ if (event.nativeEvent.isComposing) return;
375
377
  const last = steps.length - 1;
376
378
  const next = event.key === "ArrowRight" || event.key === "ArrowUp" ? Math.min(active + 1, last) : event.key === "ArrowLeft" || event.key === "ArrowDown" ? Math.max(active - 1, 0) : event.key === "Home" ? 0 : event.key === "End" ? last : null;
377
379
  if (next === null) return;
378
380
  event.preventDefault();
379
381
  event.stopPropagation();
380
- if (next !== current || defaultActive) onCommit(next);
382
+ if (!busy && (next !== current || defaultActive)) onCommit(next);
381
383
  };
382
384
  const offset = knobOffset(knobFraction);
383
385
  const idle = defaultActive && !dragging && hold === null;
@@ -405,6 +407,9 @@ window.__ModuleLoader__.load({
405
407
  onPointerCancel: (event) => {
406
408
  settle(event, false);
407
409
  },
410
+ onLostPointerCapture: (event) => {
411
+ settle(event, false);
412
+ },
408
413
  onKeyDown,
409
414
  onClick: (event) => {
410
415
  event.stopPropagation();
@@ -439,29 +444,33 @@ window.__ModuleLoader__.load({
439
444
  * Bridge the Host's own model menu: the model cell opens the all-provider
440
445
  * picker, and the effort cell carries the reasoning-level slider.
441
446
  *
442
- * The Host draws the root menu's first two cells itself: the model cell drills
443
- * into the current provider's list, the effort cell into the levels. This plugin
444
- * wants the first to open its dialog and the second to stop drilling, and the
445
- * Host exposes no hook for either. This entry is mounted exactly while the root
446
- * pane is open, so it can take the click on the menu surface before the cells'
447
- * own handlers run and mount the slider into the effort cell.
447
+ * The Host owns the root menu's model and effort cells and opens a submenu for each.
448
+ * While the root pane is open, this entry redirects the first cell to the model
449
+ * dialog and mounts the slider in the second cell.
448
450
  *
449
- * The cells are recognized as the menu surface's direct `role="menuitem"`
450
- * children, which is the Host's root-menu shape; the options slot output sits in
451
- * its own wrapper, so other plugins' rows never join that list. When the second
452
- * cell is missing the model declares no reasoning levels and the row is left
453
- * alone; when the first is missing the click falls through to the Host.
451
+ * Only the model menu's own direct buttons with the expected label, value and
452
+ * chevron are recognized. The options slot output sits in its own wrapper,
453
+ * so other plugins' rows never join that list.
454
454
  *
455
455
  * Clicking the cell's label switches to the provider default, which is a state
456
456
  * rather than a detent: the slider shows it as an empty track under a hollow
457
457
  * knob, so it never reads as the weakest level.
458
458
  */
459
+ const cellLabel = ":scope > span[class*=\"cellLabel\"]";
460
+ const cellValue = ":scope > span[class*=\"cellValue\"]";
461
+ const cellChevron = ":scope > svg[class*=\"cellChevron\"]";
462
+ /** Match only the host-owned buttons in the root model menu. */
463
+ function hostCell(surface, index) {
464
+ const button = surface.querySelectorAll(":scope > button[role=\"menuitem\"]")[index];
465
+ if (!button?.querySelector(cellLabel) || !button.querySelector(cellValue) || !button.querySelector(cellChevron)) return null;
466
+ return button;
467
+ }
459
468
  /**
460
469
  * Render the marker, redirect the model cell, and mount the effort slider.
461
470
  * @param props - menu state, session, catalog face, and localized copy.
462
471
  * @returns an inert marker plus the slider while the effort cell is present.
463
472
  */
464
- function ModelMenuBridge({ sessionId, picker, dismiss, reportFailure, available, directory, select, t }) {
473
+ function ModelMenuBridge({ sessionId, picker, locked, dismiss, reportFailure, available, directory, select, t }) {
465
474
  const markerRef = (0, react.useRef)(null);
466
475
  const sliderRef = (0, react.useRef)(null);
467
476
  const [surface, setSurface] = (0, react.useState)(null);
@@ -476,21 +485,19 @@ window.__ModuleLoader__.load({
476
485
  const defaultActive = current !== null && current.reasoningEffort === void 0;
477
486
  const currentIndex = chosen >= 0 ? chosen : declared >= 0 ? declared : 0;
478
487
  const defaultIndex = declared >= 0 ? declared : 0;
479
- const canDefault = !defaultActive;
480
- const busy = state.pending !== null;
488
+ const busy = locked || state.pending !== null;
489
+ const canDefault = !busy && !defaultActive;
481
490
  const showSlider = available && levels.length >= 2 && effortRow !== null;
482
491
  (0, react.useLayoutEffect)(() => {
483
- const foundSurface = markerRef.current?.closest("[data-menu-material]");
484
- const nextSurface = foundSurface instanceof HTMLElement ? foundSurface : null;
492
+ const nextSurface = markerRef.current?.closest("[data-model-menu][role=\"menu\"]") ?? null;
485
493
  if (nextSurface !== surface) setSurface(nextSurface);
486
- const cells = nextSurface === null ? [] : [...nextSurface.querySelectorAll(":scope > button[role=\"menuitem\"]")];
487
- const nextRow = cells.length >= 2 ? cells[1] ?? null : null;
494
+ const nextRow = nextSurface === null ? null : hostCell(nextSurface, 1);
488
495
  if (nextRow !== effortRow) setEffortRow(nextRow);
489
- const nextLabel = nextRow?.querySelector("span[class*='cellLabel']")?.textContent?.trim() ?? "";
496
+ const nextLabel = nextRow?.querySelector(cellLabel)?.textContent?.trim() ?? "";
490
497
  if (nextLabel !== (rowLabel ?? "")) setRowLabel(nextLabel);
491
498
  });
492
499
  const submit = (selection) => {
493
- if (selection === null) return;
500
+ if (selection === null || busy || directory.getSnapshot().pending !== null) return;
494
501
  select(selection).then((result) => {
495
502
  if (result === void 0 || result.ok) return;
496
503
  reportFailure(result.error.code === "session/writer-held" ? t("error.sessionInUse") : t("error.action", { message: `${result.error.code}: ${result.error.message}` }));
@@ -511,41 +518,47 @@ window.__ModuleLoader__.load({
511
518
  sessionId,
512
519
  picker,
513
520
  dismiss,
521
+ available,
522
+ busy,
514
523
  showSlider,
524
+ effortRow,
515
525
  canDefault,
516
526
  commitDefault
517
527
  });
518
- latest.current = {
519
- sessionId,
520
- picker,
521
- dismiss,
522
- showSlider,
523
- canDefault,
524
- commitDefault
525
- };
526
- (0, react.useEffect)(() => {
528
+ (0, react.useLayoutEffect)(() => {
529
+ latest.current = {
530
+ sessionId,
531
+ picker,
532
+ dismiss,
533
+ available,
534
+ busy,
535
+ showSlider,
536
+ effortRow,
537
+ canDefault,
538
+ commitDefault
539
+ };
540
+ });
541
+ (0, react.useLayoutEffect)(() => {
527
542
  if (surface === null) return;
528
543
  const redirect = (event) => {
529
544
  const target = event.target;
530
- if (!(target instanceof Node)) return;
531
- const cells = [...surface.querySelectorAll(":scope > button[role=\"menuitem\"]")];
532
- const modelCell = cells[0];
533
- if (modelCell !== void 0 && modelCell.contains(target)) {
545
+ const request = latest.current;
546
+ if (!(target instanceof Node) || event.defaultPrevented || !request.available) return;
547
+ if (hostCell(surface, 0)?.contains(target)) {
534
548
  event.preventDefault();
535
549
  event.stopPropagation();
536
- const request = latest.current;
550
+ if (request.busy) return;
537
551
  request.dismiss();
538
552
  request.picker.open(request.sessionId);
539
553
  return;
540
554
  }
541
- const row = cells[1];
542
- if (row === void 0 || !row.contains(target) || !latest.current.showSlider) return;
543
- if (sliderRef.current?.contains(target) === true) return;
555
+ const row = request.effortRow;
556
+ if (row === null || !surface.contains(row) || !row.contains(target) || !request.showSlider) return;
544
557
  event.preventDefault();
545
558
  event.stopPropagation();
546
- const label = row.querySelector("span[class*='cellLabel']");
547
- if (latest.current.canDefault && label !== null && label.contains(target)) {
548
- latest.current.commitDefault();
559
+ if (request.busy || sliderRef.current?.contains(target)) return;
560
+ if (request.canDefault && row.querySelector(cellLabel)?.contains(target)) {
561
+ request.commitDefault();
549
562
  return;
550
563
  }
551
564
  sliderRef.current?.querySelector("[role=\"slider\"]")?.focus();
@@ -557,9 +570,9 @@ window.__ModuleLoader__.load({
557
570
  }, [surface]);
558
571
  (0, react.useLayoutEffect)(() => {
559
572
  if (effortRow === null || !showSlider) return;
560
- const label = effortRow.querySelector("span[class*='cellLabel']");
561
- const value = effortRow.querySelector("span[class*='cellValue']");
562
- const chevron = effortRow.querySelector("svg[class*='cellChevron']");
573
+ const label = effortRow.querySelector(cellLabel);
574
+ const value = effortRow.querySelector(cellValue);
575
+ const chevron = effortRow.querySelector(cellChevron);
563
576
  const saved = {
564
577
  value: value?.style.display ?? "",
565
578
  chevron: chevron?.style.display ?? "",
@@ -602,7 +615,7 @@ window.__ModuleLoader__.load({
602
615
  busy,
603
616
  label: rowLabel !== null && rowLabel !== "" ? rowLabel : t("effort.label"),
604
617
  onCommit: commit
605
- })
618
+ }, JSON.stringify([current?.provider, current?.model]))
606
619
  }), effortRow)] });
607
620
  }
608
621
  //#endregion
@@ -882,6 +895,1605 @@ window.__ModuleLoader__.load({
882
895
  function isRecord(value) {
883
896
  return typeof value === "object" && value !== null && !Array.isArray(value);
884
897
  }
898
+ //#endregion
899
+ //#region node_modules/.pnpm/fuzzysort@4.0.2/node_modules/fuzzysort/fuzzysort.js
900
+ function single(search, target) {
901
+ if (!search || !target) return null;
902
+ let query = getQuery(search);
903
+ if (!isPrepared(target)) target = getPrepared(target);
904
+ if ((query.bitflags & target._bitflags) !== query.bitflags) return null;
905
+ let result = !query.hasSpace && query.lowerCodes.length === 2 ? algorithm2(query, target) : algorithm(query, target);
906
+ return result && materialize(result);
907
+ }
908
+ function go(search, targets, options) {
909
+ if (targets instanceof SnapshotTargets) return goSnapshot(search, targets, options);
910
+ let key = options?.key;
911
+ let keys = !key && options?.keys;
912
+ let firstTarget = targets[0];
913
+ if (!key && !keys && typeof firstTarget === "object" && firstTarget !== null && !isPrepared(firstTarget)) throw new Error("fuzzysort: key or keys is required when searching object targets");
914
+ if (!search) return all(targets, options);
915
+ let query = getQuery(search);
916
+ if (keys) return goKeys(query, targets, options);
917
+ let searchBitflags = query.bitflags;
918
+ let twoChar = !query.hasSpace && query.lowerCodes.length === 2;
919
+ let threshold = denormalizeScore(options?.threshold ?? .5);
920
+ let limit = getLimit(options);
921
+ let scoreFn = options?.scoreFn;
922
+ let resultCount = 0;
923
+ let limited = 0;
924
+ let getter = key && makeGetter(key);
925
+ for (let i = 0; i < targets.length; i++) {
926
+ let obj = targets[i];
927
+ let target = key ? getter === null ? obj[key] : getter(obj) : obj;
928
+ if (!target) continue;
929
+ if (!isPrepared(target)) target = getPrepared(target);
930
+ if ((searchBitflags & target._bitflags) !== searchBitflags) continue;
931
+ let result = twoChar ? algorithm2(query, target) : algorithm(query, target);
932
+ if (result === null) continue;
933
+ let resultScore = result._score;
934
+ if (scoreFn) {
935
+ result = materialize(result, key ? obj : void 0);
936
+ resultScore = scoreFn(result);
937
+ if (!resultScore) continue;
938
+ result._score = resultScore = denormalizeScore(resultScore);
939
+ }
940
+ if (resultScore < threshold) continue;
941
+ let room = resultCount < limit;
942
+ if (room) resultCount++;
943
+ else {
944
+ limited++;
945
+ if (resultScore <= heap.peek()._score) continue;
946
+ }
947
+ if (!scoreFn) result = materialize(result, key ? obj : void 0);
948
+ room ? heap.add(result) : heap.replaceTop(result);
949
+ }
950
+ return finishResults(resultCount, limited);
951
+ }
952
+ function highlight(result, open = "<b>", close = "</b>", threshold = .5) {
953
+ let callback = typeof open === "function" ? open : null;
954
+ let target = result.target;
955
+ if (result._bestKeyScore !== void 0 && normalizeScore(result._score) < normalizeScore(result._bestKeyScore) * threshold) return callback ? [target] : target;
956
+ let raw = result._indexes;
957
+ let indexes = raw === void 0 ? result.indexes : raw.slice(0, raw.len ?? raw.length).sort((a, b) => a - b);
958
+ if (!indexes.length) return callback ? [target] : target;
959
+ let output = callback ? [] : "";
960
+ let lastIndex = 0;
961
+ let matchI = 0;
962
+ for (let i = 0; i < indexes.length;) {
963
+ let start = indexes[i++];
964
+ let end = start + 1;
965
+ while (indexes[i] === end) {
966
+ i++;
967
+ end++;
968
+ }
969
+ let before = target.slice(lastIndex, start);
970
+ let match = target.slice(start, end);
971
+ if (callback) output.push(before, callback(match, matchI++));
972
+ else output += before + open + match + close;
973
+ lastIndex = end;
974
+ }
975
+ if (callback) output.push(target.slice(lastIndex));
976
+ else output += target.slice(lastIndex);
977
+ return output;
978
+ }
979
+ function score(result) {
980
+ let value = result.score;
981
+ return value === void 0 ? normalizeScore(result._score) : value;
982
+ }
983
+ function remap(mappings) {
984
+ for (let char in mappings) {
985
+ remappings[char] = mappings[char];
986
+ if (char.charCodeAt(0) < 128) customAsciiRemappings = true;
987
+ }
988
+ cleanup();
989
+ }
990
+ function prepare(target) {
991
+ return prepTarget(target);
992
+ }
993
+ function snapshot(targets, options) {
994
+ return new SnapshotTargets(targets, options);
995
+ }
996
+ function cleanup() {
997
+ targetCache.clear();
998
+ searchCache.clear();
999
+ heap.clear();
1000
+ simpleMatch = [];
1001
+ strictMatch = [];
1002
+ seen = [];
1003
+ seenAt = [];
1004
+ changes = [];
1005
+ partials = [];
1006
+ spaceScores = [];
1007
+ partIndexes = [];
1008
+ winnerIndexes = [];
1009
+ winnerScores = [];
1010
+ winnerKeys = [];
1011
+ keyTargets = [];
1012
+ keyResults = [];
1013
+ candidateBitOffsets = [];
1014
+ seenGeneration = 0;
1015
+ }
1016
+ function goSnapshotValues(search, snapshot, options, singleChar) {
1017
+ let targets = snapshot._targets;
1018
+ let objects = snapshot._objects;
1019
+ let threshold = denormalizeScore(options?.threshold ?? .5);
1020
+ let limit = getLimit(options);
1021
+ let scoreFn = options?.scoreFn;
1022
+ let searchLen = search.lowerCodes.length;
1023
+ let shortSearch = !search.hasSpace && searchLen <= 3;
1024
+ let twoChar = !search.hasSpace && searchLen === 2;
1025
+ let rows = snapshot._candidateRows;
1026
+ let rowsLength = snapshot._candidateLength;
1027
+ let matchedRows = snapshot._rows;
1028
+ let matchedCount = 0;
1029
+ let resultCount = 0;
1030
+ let limited = 0;
1031
+ for (let n = 0; n < rowsLength; n++) {
1032
+ let i = rows === null ? n : rows[n];
1033
+ let target = targets[i];
1034
+ if (target === noTarget || (search.bitflags & target._bitflags) !== search.bitflags) continue;
1035
+ let targetShort = shortSearch && target.target.length < 65535;
1036
+ let cutoff = !scoreFn && threshold === -INF && resultCount >= limit ? heap.peek()._score : -INF;
1037
+ let result;
1038
+ if (singleChar && targetShort) result = algorithm1(search, target, snapshot._first, i);
1039
+ else if (twoChar && targetShort) {
1040
+ let start = snapshot._offsets[i];
1041
+ let end = snapshot._offsets[i + 1];
1042
+ result = algorithm2(search, target, snapshot._beginnings, start, end, cutoff);
1043
+ } else if (twoChar) result = algorithm2(search, target, null, 0, 0, cutoff);
1044
+ else if (targetShort) {
1045
+ let start = snapshot._offsets[i];
1046
+ let end = snapshot._offsets[i + 1];
1047
+ result = algorithm(search, target, false, false, false, true, snapshot._beginnings, start, end, cutoff);
1048
+ } else result = algorithm(search, target, false, false, false, true, null, 0, 0, cutoff);
1049
+ if (result === null) continue;
1050
+ matchedRows[matchedCount++] = i;
1051
+ if (result === prunedMatch) {
1052
+ limited++;
1053
+ continue;
1054
+ }
1055
+ let resultScore = result._score;
1056
+ if (scoreFn) {
1057
+ result = materialize(result, objects?.[i]);
1058
+ resultScore = scoreFn(result);
1059
+ if (!resultScore) continue;
1060
+ result._score = resultScore = denormalizeScore(resultScore);
1061
+ }
1062
+ if (resultScore < threshold) continue;
1063
+ let room = resultCount < limit;
1064
+ if (room) resultCount++;
1065
+ else {
1066
+ limited++;
1067
+ if (resultScore <= heap.peek()._score) continue;
1068
+ }
1069
+ if (objects && !scoreFn) result = materialize(result, objects[i]);
1070
+ room ? heap.add(result) : heap.replaceTop(result);
1071
+ }
1072
+ snapshot._matchedRowsLen = matchedCount;
1073
+ return finishResults(resultCount, limited, !objects && !scoreFn && materialize);
1074
+ }
1075
+ function goSnapshot(search, snapshot, options) {
1076
+ if (options?.key || options?.keys) throw new Error("fuzzysort: key/keys must be provided to snapshot(), not go()");
1077
+ snapshot._finish();
1078
+ if (!search) return allSnapshot(snapshot, options);
1079
+ let query = getQuery(search);
1080
+ let backtrack = snapshot._backtrack(query, options);
1081
+ if (backtrack) return backtrack;
1082
+ snapshot._beginSearch(query);
1083
+ try {
1084
+ let results;
1085
+ if (snapshot._mode < 2) {
1086
+ let searchLen = query.lowerCodes.length;
1087
+ let code = query.lowerCodes[0];
1088
+ results = goSnapshotValues(query, snapshot, options, searchLen === 1 && code >= 97 && code <= 122);
1089
+ } else results = goKeys(query, snapshot._objects, options, snapshot);
1090
+ snapshot._endSearch(query);
1091
+ snapshot._remember(query, results, options);
1092
+ return results;
1093
+ } catch (error) {
1094
+ snapshot._resetSearch();
1095
+ throw error;
1096
+ }
1097
+ }
1098
+ function goKeys(query, objects, options, snapshot) {
1099
+ let indexed = snapshot !== void 0;
1100
+ let keys = indexed ? null : options.keys;
1101
+ let getters = indexed ? null : keys.map(makeGetter);
1102
+ let targets = indexed ? snapshot._targets : null;
1103
+ let keysLength = indexed ? snapshot._keysLength : keys.length;
1104
+ let searchBitflags = query.bitflags;
1105
+ let hasSpace = query.hasSpace;
1106
+ let spaceCount = query.parts.length;
1107
+ let threshold = denormalizeScore(options?.threshold ?? .5);
1108
+ let limit = getLimit(options);
1109
+ let searchLen = query.lowerCodes.length;
1110
+ let short = indexed && !hasSpace && searchLen <= 3;
1111
+ let twoChar = !hasSpace && searchLen === 2;
1112
+ let code = query.lowerCodes[0];
1113
+ let singleChar = short && searchLen === 1 && code >= 97 && code <= 122;
1114
+ let scoreFn = options?.scoreFn;
1115
+ let deferMaterialization = indexed && !scoreFn && (limit !== INF || threshold > -INF);
1116
+ let rows = indexed ? snapshot._candidateRows : null;
1117
+ let rowsLength = indexed ? snapshot._candidateLength : objects.length;
1118
+ let matchedRows = indexed ? snapshot._rows : null;
1119
+ let matchedCount = 0;
1120
+ let resultCount = 0;
1121
+ let limited = 0;
1122
+ outer: for (let n = 0; n < rowsLength; n++) {
1123
+ let i = rows === null ? n : rows[n];
1124
+ let row = i * keysLength;
1125
+ if (indexed) {
1126
+ if ((searchBitflags & snapshot._bitflags[i]) !== searchBitflags) continue;
1127
+ } else {
1128
+ let obj = objects[i];
1129
+ let keysBitflags = 0;
1130
+ for (let k = 0; k < keysLength; k++) {
1131
+ let target = getters[k] === null ? obj[keys[k]] : getters[k](obj);
1132
+ if (!target) target = noTarget;
1133
+ else if (!isPrepared(target)) target = getPrepared(target);
1134
+ keyTargets[k] = target;
1135
+ keysBitflags |= target._bitflags;
1136
+ }
1137
+ if ((searchBitflags & keysBitflags) !== searchBitflags) continue;
1138
+ }
1139
+ if (hasSpace) for (let s = 0; s < spaceCount; s++) {
1140
+ spaceScores[s] = winnerScores[s] = -INF;
1141
+ winnerKeys[s] = -1;
1142
+ }
1143
+ for (let k = 0; k < keysLength; k++) {
1144
+ let target = indexed ? targets[row + k] : keyTargets[k];
1145
+ if (target === noTarget) {
1146
+ keyResults[k] = noTarget;
1147
+ continue;
1148
+ }
1149
+ if (hasSpace && indexed) {
1150
+ let possible = false;
1151
+ for (let s = 0; s < spaceCount; s++) {
1152
+ let partBitflags = query.parts[s].bitflags;
1153
+ if ((partBitflags & target._bitflags) === partBitflags) {
1154
+ possible = true;
1155
+ break;
1156
+ }
1157
+ }
1158
+ if (!possible) {
1159
+ keyResults[k] = noTarget;
1160
+ continue;
1161
+ }
1162
+ } else if (!hasSpace && (searchBitflags & target._bitflags) !== searchBitflags) {
1163
+ keyResults[k] = noTarget;
1164
+ continue;
1165
+ }
1166
+ let match;
1167
+ if (indexed) {
1168
+ let valueRow = row + k;
1169
+ let targetShort = short && target.target.length < 65535;
1170
+ if (singleChar && targetShort) match = algorithm1(query, target, snapshot._first, valueRow);
1171
+ else if (twoChar && targetShort) {
1172
+ let start = snapshot._offsets[valueRow];
1173
+ let end = snapshot._offsets[valueRow + 1];
1174
+ match = algorithm2(query, target, snapshot._beginnings, start, end);
1175
+ } else if (twoChar) match = algorithm2(query, target);
1176
+ else if (targetShort) {
1177
+ let start = snapshot._offsets[valueRow];
1178
+ let end = snapshot._offsets[valueRow + 1];
1179
+ match = algorithm(query, target, false, false, false, true, snapshot._beginnings, start, end);
1180
+ } else match = algorithm(query, target, false, hasSpace);
1181
+ } else match = twoChar ? algorithm2(query, target) : algorithm(query, target, false, hasSpace);
1182
+ if (match === null) {
1183
+ keyResults[k] = noTarget;
1184
+ continue;
1185
+ }
1186
+ keyResults[k] = deferMaterialization ? match : materialize(match);
1187
+ if (hasSpace) {
1188
+ mergePartScores(spaceCount);
1189
+ for (let s = 0; s < spaceCount; s++) {
1190
+ let partScore = partials[s];
1191
+ if (partScore <= winnerScores[s]) continue;
1192
+ winnerScores[s] = partScore;
1193
+ winnerKeys[s] = k;
1194
+ let source = partIndexes[s];
1195
+ let winner = winnerIndexes[s] ||= [];
1196
+ winner.length = source.length;
1197
+ for (let j = 0; j < source.length; j++) winner[j] = source[j];
1198
+ }
1199
+ }
1200
+ }
1201
+ if (hasSpace) {
1202
+ for (let s = 0; s < spaceCount; s++) if (winnerKeys[s] !== -1) appendIndexes(keyResults[winnerKeys[s]]._indexes, winnerIndexes[s]);
1203
+ }
1204
+ let resultScore;
1205
+ if (hasSpace) {
1206
+ resultScore = 0;
1207
+ for (let s = 0; s < spaceCount; s++) {
1208
+ let partScore = spaceScores[s];
1209
+ if (partScore === -INF) continue outer;
1210
+ resultScore += partScore;
1211
+ }
1212
+ } else {
1213
+ resultScore = mergeScores(keyResults, keysLength);
1214
+ if (resultScore === -INF) continue;
1215
+ }
1216
+ if (indexed) matchedRows[matchedCount++] = i;
1217
+ let result = deferMaterialization ? null : captureKeysResult(keyResults, keysLength, objects[i], resultScore, hasSpace);
1218
+ if (scoreFn) {
1219
+ resultScore = scoreFn(result);
1220
+ if (!resultScore) continue;
1221
+ result._score = resultScore = denormalizeScore(resultScore);
1222
+ }
1223
+ if (resultScore < threshold) continue;
1224
+ let room = resultCount < limit;
1225
+ if (room) resultCount++;
1226
+ else {
1227
+ limited++;
1228
+ if (resultScore <= heap.peek()._score) continue;
1229
+ }
1230
+ if (result === null) result = captureKeysResult(keyResults, keysLength, objects[i], resultScore, hasSpace);
1231
+ room ? heap.add(result) : heap.replaceTop(result);
1232
+ }
1233
+ if (indexed) snapshot._matchedRowsLen = matchedCount;
1234
+ return finishResults(resultCount, limited, deferMaterialization && materializeKeys);
1235
+ }
1236
+ function allSnapshot(snapshot, options) {
1237
+ let results = [];
1238
+ let targets = snapshot._targets;
1239
+ let objects = snapshot._objects;
1240
+ let keysLength = snapshot._keysLength;
1241
+ let total = keysLength === void 0 ? targets.length : objects.length;
1242
+ results.total = total;
1243
+ let limit = getLimit(options);
1244
+ for (let i = 0, length = Math.min(total, limit); i < length; i++) {
1245
+ if (keysLength === void 0) {
1246
+ results.push(newResult(targets[i].target, -INF, objects?.[i]));
1247
+ continue;
1248
+ }
1249
+ let row = i * keysLength;
1250
+ for (let k = 0; k < keysLength; k++) {
1251
+ let target = targets[row + k];
1252
+ keyResults[k] = target === noTarget ? noTarget : newResult(target.target, -INF);
1253
+ }
1254
+ results.push(captureKeysResult(keyResults, keysLength, objects[i], -INF));
1255
+ }
1256
+ return results;
1257
+ }
1258
+ function all(targets, options) {
1259
+ let results = [];
1260
+ results.total = targets.length;
1261
+ let limit = getLimit(options);
1262
+ let key = options?.key;
1263
+ let keys = !key && options?.keys;
1264
+ if (keys) {
1265
+ let getters = keys.map(makeGetter);
1266
+ for (let obj of targets) {
1267
+ for (let k = keys.length - 1; k >= 0; k--) {
1268
+ let target = getters[k] === null ? obj[keys[k]] : getters[k](obj);
1269
+ if (!target) keyResults[k] = noTarget;
1270
+ else {
1271
+ if (!isPrepared(target)) target = getPrepared(target);
1272
+ target._score = -INF;
1273
+ target._indexes.len = 0;
1274
+ keyResults[k] = target;
1275
+ }
1276
+ }
1277
+ results.push(captureKeysResult(keyResults, keys.length, obj, -INF));
1278
+ if (results.length >= limit) break;
1279
+ }
1280
+ return results;
1281
+ }
1282
+ let getter = key && makeGetter(key);
1283
+ for (let obj of targets) {
1284
+ let target = key ? getter === null ? obj[key] : getter(obj) : obj;
1285
+ if (target == null) continue;
1286
+ if (!isPrepared(target)) target = getPrepared(target);
1287
+ if (key) target = newResult(target.target, -INF, obj);
1288
+ else {
1289
+ target._score = -INF;
1290
+ target._indexes.len = 0;
1291
+ }
1292
+ results.push(target);
1293
+ if (results.length >= limit) break;
1294
+ }
1295
+ return results;
1296
+ }
1297
+ function finishResults(length, limited, transform) {
1298
+ if (!length) return noResults;
1299
+ let results = new Array(length);
1300
+ for (let i = length - 1; i >= 0; i--) {
1301
+ let result = heap.poll();
1302
+ if (transform) result = transform(result);
1303
+ if (result instanceof KeysResult && !result._partWinners) markBestKeyScore(result);
1304
+ results[i] = result;
1305
+ }
1306
+ results.total = length + limited;
1307
+ return results;
1308
+ }
1309
+ function materializeKeys(result) {
1310
+ for (let k = 0; k < result.length; k++) if (result[k] !== noTarget) result[k] = materialize(result[k]);
1311
+ return result;
1312
+ }
1313
+ function algorithm1(search, target, firstTable, row) {
1314
+ let matchI = target._targetLower.indexOf(search._lower);
1315
+ if (matchI === -1) return null;
1316
+ let beginning = firstTable[row * 26 + search.lowerCodes[0] - 97];
1317
+ let strict = beginning !== 0;
1318
+ if (strict) matchI = beginning - 1;
1319
+ let score = matchI === 0 ? 0 : -matchI * matchI * .2;
1320
+ if (!strict) score *= 1e3;
1321
+ else if (target._beginningsLen > 24) score *= (target._beginningsLen - 24) * 10;
1322
+ target._score = score - target._targetLowerCodes.length + 1;
1323
+ target._indexes[0] = matchI;
1324
+ target._indexes.len = 1;
1325
+ return target;
1326
+ }
1327
+ function algorithm2(search, target, beginnings = null, start = 0, end = 0, cutoff = -INF) {
1328
+ let targetCodes = target._targetLowerCodes;
1329
+ let targetLen = targetCodes.length;
1330
+ let firstCode = search.lowerCodes[0];
1331
+ let secondCode = search.lowerCodes[1];
1332
+ let first = 0;
1333
+ while (targetCodes[first] !== firstCode) if (++first >= targetLen) return null;
1334
+ let second = first + 1;
1335
+ while (targetCodes[second] !== secondCode) if (++second >= targetLen) return null;
1336
+ if (cutoff !== -INF && scoreCeiling(2, targetLen) <= cutoff) return prunedMatch;
1337
+ if (beginnings === null) {
1338
+ beginnings = target._beginnings;
1339
+ if (beginnings === null) target._beginnings = beginnings = makeBeginnings(target);
1340
+ end = beginnings.length;
1341
+ }
1342
+ let substringI = target._targetLower.indexOf(search._lower, first);
1343
+ let substring = substringI !== -1;
1344
+ let low = lowerBound(beginnings, start, end, substringI);
1345
+ let substringStart = substring && low < end && beginnings[low] === substringI;
1346
+ let strict = substringStart && substringI === first;
1347
+ if (!strict) {
1348
+ let firstBeginning = start;
1349
+ while (firstBeginning < end && beginnings[firstBeginning] < first) firstBeginning++;
1350
+ for (let backtracks = 0; firstBeginning < end;) {
1351
+ let strictFirst = beginnings[firstBeginning];
1352
+ if (targetCodes[strictFirst] !== firstCode) {
1353
+ firstBeginning++;
1354
+ continue;
1355
+ }
1356
+ let consecutive = strictFirst + 1;
1357
+ if (targetCodes[consecutive] === secondCode) {
1358
+ first = strictFirst;
1359
+ second = consecutive;
1360
+ strict = true;
1361
+ break;
1362
+ }
1363
+ let secondBeginning = firstBeginning + 1;
1364
+ while (secondBeginning < end && beginnings[secondBeginning] <= consecutive) secondBeginning++;
1365
+ while (secondBeginning < end && targetCodes[beginnings[secondBeginning]] !== secondCode) secondBeginning++;
1366
+ if (secondBeginning < end) {
1367
+ first = strictFirst;
1368
+ second = beginnings[secondBeginning];
1369
+ strict = true;
1370
+ break;
1371
+ }
1372
+ if (++backtracks > 200) break;
1373
+ firstBeginning++;
1374
+ }
1375
+ }
1376
+ if (substring && !substringStart) {
1377
+ while (low < end && beginnings[low] <= substringI) low++;
1378
+ for (; low < end; low++) {
1379
+ let index = beginnings[low];
1380
+ if (targetCodes[index] === firstCode && targetCodes[index + 1] === secondCode) {
1381
+ substringI = index;
1382
+ substringStart = true;
1383
+ break;
1384
+ }
1385
+ }
1386
+ }
1387
+ if (substring && (!strict || substringStart)) {
1388
+ first = substringI;
1389
+ second = substringI + 1;
1390
+ }
1391
+ let resultScore = second - first === 1 ? 0 : first - second * 2 - 11;
1392
+ if (first) resultScore -= first * first * .2;
1393
+ if (!strict) resultScore *= 1e3;
1394
+ else if (end - start > 24) resultScore *= (end - start - 24) * 10;
1395
+ let lengthPenalty = (targetLen - 2) / 2;
1396
+ resultScore -= lengthPenalty;
1397
+ if (substring) resultScore /= 5;
1398
+ if (substringStart) resultScore /= 5;
1399
+ resultScore -= lengthPenalty;
1400
+ target._score = substring && second === first + 1 && (second + 1 === targetLen || isBeginning(beginnings, start, end, second + 1)) ? resultScore + Math.min(4, -resultScore / 2) : resultScore;
1401
+ target._indexes[0] = first;
1402
+ target._indexes[1] = second;
1403
+ target._indexes.len = 2;
1404
+ return target;
1405
+ }
1406
+ function algorithm(search, target, spaces = false, partial = false, changed = false, singleMatch = true, beginnings = null, start = 0, end = 0, cutoff = -INF) {
1407
+ if (!spaces && search.hasSpace) return algorithmSpaces(search, target, partial);
1408
+ let searchCodes = search.lowerCodes;
1409
+ let targetCodes = target._targetLowerCodes;
1410
+ let searchLen = searchCodes.length;
1411
+ let targetLen = targetCodes.length;
1412
+ let searchCode = searchCodes[0];
1413
+ let searchI = 0;
1414
+ let targetI = 0;
1415
+ for (;;) {
1416
+ if (searchCode === targetCodes[targetI]) {
1417
+ simpleMatch[searchI] = targetI;
1418
+ if (++searchI === searchLen) break;
1419
+ searchCode = searchCodes[searchI];
1420
+ }
1421
+ if (++targetI >= targetLen) return null;
1422
+ }
1423
+ if (cutoff !== -INF && searchLen > 1 && scoreCeiling(searchLen, targetLen) <= cutoff) return prunedMatch;
1424
+ if (searchLen === 1 && !changed && singleMatch) {
1425
+ let matchI;
1426
+ let strict;
1427
+ if (target._singleMatchCode === searchCode) {
1428
+ matchI = target._singleMatchIndex;
1429
+ strict = target._singleMatchStrict;
1430
+ } else if (target._nextBeginningIndexes !== null) {
1431
+ let next = target._nextBeginningIndexes;
1432
+ targetI = simpleMatch[0] === 0 ? 0 : next[simpleMatch[0] - 1];
1433
+ while (targetI < targetLen && searchCode !== targetCodes[targetI]) targetI = next[targetI];
1434
+ strict = targetI < targetLen;
1435
+ matchI = strict ? targetI : simpleMatch[0];
1436
+ } else {
1437
+ prepareSingleMatch(target, searchCode, simpleMatch[0]);
1438
+ matchI = target._singleMatchIndex;
1439
+ strict = target._singleMatchStrict;
1440
+ }
1441
+ let resultScore = matchI === 0 ? 0 : -matchI * matchI * .2;
1442
+ if (!strict) resultScore *= 1e3;
1443
+ else if (target._beginningsLen > 24) resultScore *= (target._beginningsLen - 24) * 10;
1444
+ target._score = resultScore - (targetLen - 1);
1445
+ target._indexes[0] = matchI;
1446
+ target._indexes.len = 1;
1447
+ return target;
1448
+ }
1449
+ searchI = 0;
1450
+ let strict = false;
1451
+ let strictLen = 0;
1452
+ let next = target._nextBeginningIndexes;
1453
+ if (beginnings === null && next === null) next = target._nextBeginningIndexes = makeNextBeginnings(target);
1454
+ let beginningLen = beginnings === null ? changed ? 0 : target._beginningsLen : end - start;
1455
+ if (!beginningLen) {
1456
+ beginningLen = 1;
1457
+ for (let i = next[0]; i < targetLen; i = next[i]) beginningLen++;
1458
+ if (!changed) target._beginningsLen = beginningLen;
1459
+ }
1460
+ let substringI = searchLen <= 1 ? -1 : target._targetLower.indexOf(search._lower, simpleMatch[0]);
1461
+ let isSubstring = substringI !== -1;
1462
+ let substringStart = isSubstring && (substringI === 0 || (beginnings ? isBeginning(beginnings, start, end, substringI) : next[substringI - 1] === substringI));
1463
+ if (substringStart && substringI === simpleMatch[0]) strict = true;
1464
+ else {
1465
+ targetI = simpleMatch[0] === 0 ? 0 : beginnings ? nextBeginning(beginnings, start, end, simpleMatch[0] - 1, targetLen) : next[simpleMatch[0] - 1];
1466
+ let backtracks = 0;
1467
+ if (targetI !== targetLen) for (;;) if (targetI >= targetLen) {
1468
+ if (searchI <= 0 || ++backtracks > 200) break;
1469
+ searchI--;
1470
+ let previous = strictMatch[--strictLen];
1471
+ targetI = beginnings ? nextBeginning(beginnings, start, end, previous, targetLen) : next[previous];
1472
+ } else if (searchCodes[searchI] === targetCodes[targetI]) {
1473
+ strictMatch[strictLen++] = targetI;
1474
+ if (++searchI === searchLen) {
1475
+ strict = true;
1476
+ break;
1477
+ }
1478
+ targetI++;
1479
+ } else targetI = beginnings ? nextBeginning(beginnings, start, end, targetI, targetLen) : next[targetI];
1480
+ }
1481
+ if (isSubstring && !substringStart) {
1482
+ if (beginnings) for (let b = start; b < end; b++) {
1483
+ let i = beginnings[b];
1484
+ if (i <= substringI) continue;
1485
+ let s = 0;
1486
+ for (; s < searchLen && searchCodes[s] === targetCodes[i + s]; s++);
1487
+ if (s === searchLen) {
1488
+ substringI = i;
1489
+ substringStart = true;
1490
+ break;
1491
+ }
1492
+ }
1493
+ else for (let i = 0; i < next.length; i = next[i]) {
1494
+ if (i <= substringI) continue;
1495
+ let s = 0;
1496
+ for (; s < searchLen && searchCodes[s] === targetCodes[i + s]; s++);
1497
+ if (s === searchLen) {
1498
+ substringI = i;
1499
+ substringStart = true;
1500
+ break;
1501
+ }
1502
+ }
1503
+ }
1504
+ let matches;
1505
+ if (!strict) {
1506
+ if (isSubstring) for (let i = 0; i < searchLen; i++) simpleMatch[i] = substringI + i;
1507
+ matches = simpleMatch;
1508
+ } else if (substringStart) {
1509
+ for (let i = 0; i < searchLen; i++) simpleMatch[i] = substringI + i;
1510
+ matches = simpleMatch;
1511
+ } else matches = strictMatch;
1512
+ let matchEnd = matches[searchLen - 1] + 1;
1513
+ let substringEnd = isSubstring && matchEnd - matches[0] === searchLen && (matchEnd === targetLen || (beginnings ? isBeginning(beginnings, start, end, matchEnd) : next[matchEnd - 1] === matchEnd));
1514
+ target._score = calculateScore(matches, searchLen, targetLen, strict, beginningLen, isSubstring, substringStart, substringEnd);
1515
+ for (let i = 0; i < searchLen; i++) target._indexes[i] = matches[i];
1516
+ target._indexes.len = searchLen;
1517
+ return target;
1518
+ }
1519
+ function mergePartScores(length) {
1520
+ for (let i = 0; i < length; i++) {
1521
+ let partial = partials[i];
1522
+ let best = spaceScores[i];
1523
+ if (partial > -1e3 && best > -INF) best = Math.max(best, (best + partial) / 4);
1524
+ spaceScores[i] = Math.max(best, partial);
1525
+ }
1526
+ }
1527
+ function appendIndexes(indexes, additions) {
1528
+ let length = indexes.len;
1529
+ outer: for (let i = 0; i < additions.length; i++) {
1530
+ let index = additions[i];
1531
+ for (let j = 0; j < length; j++) if (indexes[j] === index) continue outer;
1532
+ indexes[length++] = index;
1533
+ }
1534
+ indexes.len = length;
1535
+ }
1536
+ function mergeScores(results, length) {
1537
+ let total = -INF;
1538
+ for (let i = 0; i < length; i++) {
1539
+ let score = results[i]._score;
1540
+ if (score > -1e3 && total > -INF) total = Math.max(total, (total + score) / 4);
1541
+ if (score > total) total = score;
1542
+ }
1543
+ return total;
1544
+ }
1545
+ function calculateScore(matches, searchLen, targetLen, strict, beginningLen, substring, substringStart, substringEnd) {
1546
+ let score = 0;
1547
+ let groups = 0;
1548
+ for (let i = 1; i < searchLen; i++) if (matches[i] - matches[i - 1] !== 1) {
1549
+ score -= matches[i];
1550
+ groups++;
1551
+ }
1552
+ let unmatchedDistance = matches[searchLen - 1] - matches[0] - (searchLen - 1);
1553
+ score -= (12 + unmatchedDistance) * groups;
1554
+ if (matches[0] !== 0) score -= matches[0] * matches[0] * .2;
1555
+ if (!strict) score *= 1e3;
1556
+ else if (beginningLen > 24) score *= (beginningLen - 24) * 10;
1557
+ let lengthPenalty = (targetLen - searchLen) / 2;
1558
+ score -= lengthPenalty;
1559
+ let substringBonus = 1 + searchLen * searchLen;
1560
+ if (substring) score /= substringBonus;
1561
+ if (substringStart) score /= substringBonus;
1562
+ score -= lengthPenalty;
1563
+ return substringEnd ? score + Math.min(4, -score / 2) : score;
1564
+ }
1565
+ function algorithmSpaces(search, target, partial) {
1566
+ let seenLen = 0;
1567
+ let generation = ++seenGeneration;
1568
+ let score = 0;
1569
+ let result = null;
1570
+ let previousFirst = 0;
1571
+ let searches = search.parts;
1572
+ let changesLen = 0;
1573
+ let matched = false;
1574
+ for (let i = 0; i < searches.length; i++) {
1575
+ partials[i] = -INF;
1576
+ if (partial) (partIndexes[i] ||= []).length = 0;
1577
+ result = algorithm(searches[i], target, false, false, changesLen !== 0, false);
1578
+ if (result === null) {
1579
+ if (partial) continue;
1580
+ resetBeginnings(target, changesLen);
1581
+ return null;
1582
+ }
1583
+ matched = true;
1584
+ if (i < searches.length - 1) {
1585
+ let indexes = result._indexes;
1586
+ let consecutive = true;
1587
+ for (let j = 0; j < indexes.len - 1; j++) if (indexes[j + 1] - indexes[j] !== 1) {
1588
+ consecutive = false;
1589
+ break;
1590
+ }
1591
+ if (consecutive) {
1592
+ let beginning = indexes[indexes.len - 1] + 1;
1593
+ let previous = target._nextBeginningIndexes[beginning - 1];
1594
+ for (let j = beginning - 1; j >= 0 && target._nextBeginningIndexes[j] === previous; j--) {
1595
+ target._nextBeginningIndexes[j] = beginning;
1596
+ changes[changesLen * 2] = j;
1597
+ changes[changesLen * 2 + 1] = previous;
1598
+ changesLen++;
1599
+ }
1600
+ }
1601
+ }
1602
+ if (partial) {
1603
+ let indexes = partIndexes[i];
1604
+ indexes.length = result._indexes.len;
1605
+ for (let j = 0; j < indexes.length; j++) indexes[j] = result._indexes[j];
1606
+ }
1607
+ let partScore = result._score / searches.length;
1608
+ score += partScore;
1609
+ partials[i] = partScore;
1610
+ if (result._indexes[0] < previousFirst) score -= (previousFirst - result._indexes[0]) * 2;
1611
+ previousFirst = result._indexes[0];
1612
+ if (!partial) for (let j = 0; j < result._indexes.len; j++) {
1613
+ let index = result._indexes[j];
1614
+ if (seenAt[index] === generation) continue;
1615
+ seenAt[index] = generation;
1616
+ seen[seenLen++] = index;
1617
+ }
1618
+ }
1619
+ if (partial && !matched) return null;
1620
+ resetBeginnings(target, changesLen);
1621
+ if (target._bitflags & SPACE_BIT) {
1622
+ let spacedResult = algorithm(search, target, true);
1623
+ if (spacedResult !== null && spacedResult._score > score) {
1624
+ if (partial) {
1625
+ let searchFrom = 0;
1626
+ for (let i = 0; i < searches.length; i++) {
1627
+ partials[i] = spacedResult._score / searches.length;
1628
+ let part = searches[i]._lower;
1629
+ let searchI = search._lower.indexOf(part, searchFrom);
1630
+ let indexes = partIndexes[i];
1631
+ indexes.length = part.length;
1632
+ for (let j = 0; j < part.length; j++) indexes[j] = spacedResult._indexes[searchI + j];
1633
+ searchFrom = searchI + part.length;
1634
+ }
1635
+ if (spacedResult._score < GOOD_PART_SCORE) spacedResult._indexes.len = 0;
1636
+ }
1637
+ return spacedResult;
1638
+ }
1639
+ }
1640
+ if (partial) {
1641
+ result = target;
1642
+ let targetLower = target._targetLower;
1643
+ for (let i = 1; i < searches.length; i++) {
1644
+ let previous = partIndexes[i - 1];
1645
+ if (!previous.length || !partIndexes[i].length) continue;
1646
+ let previousEnd = previous[previous.length - 1] + 1;
1647
+ let at = previousEnd;
1648
+ let code;
1649
+ while ((code = targetLower.charCodeAt(at)) === 32 || code >= 9 && code <= 13) at++;
1650
+ let part = searches[i]._lower;
1651
+ if (!targetLower.startsWith(part, at)) continue;
1652
+ for (let j = previousEnd; j < at; j++) previous.push(j);
1653
+ let indexes = partIndexes[i];
1654
+ indexes.length = part.length;
1655
+ for (let j = 0; j < part.length; j++) indexes[j] = at + j;
1656
+ }
1657
+ result._indexes.len = 0;
1658
+ for (let i = 0; i < searches.length; i++) if (partials[i] * searches.length >= GOOD_PART_SCORE) appendIndexes(result._indexes, partIndexes[i]);
1659
+ } else {
1660
+ for (let i = 0; i < seenLen; i++) result._indexes[i] = seen[i];
1661
+ result._indexes.len = seenLen;
1662
+ }
1663
+ result._score = score;
1664
+ return result;
1665
+ }
1666
+ function resetBeginnings(target, changesLen) {
1667
+ for (let i = changesLen - 1; i >= 0; i--) target._nextBeginningIndexes[changes[i * 2]] = changes[i * 2 + 1];
1668
+ }
1669
+ var SnapshotTargets = class {
1670
+ constructor(targets, options) {
1671
+ this._mode = options?.keys ? 2 : options?.key ? 1 : 0;
1672
+ this._keys = this._mode === 2 ? options.keys.slice() : [options?.key];
1673
+ this._input = targets.slice();
1674
+ this._index = 0;
1675
+ this._done = false;
1676
+ this._error = null;
1677
+ this._scheduled = null;
1678
+ if (targets.length === 0) this._finish();
1679
+ else this._schedule();
1680
+ }
1681
+ _schedule() {
1682
+ if (this._scheduled !== null) return;
1683
+ this._scheduled = scheduleTask((deadline) => {
1684
+ this._scheduled = null;
1685
+ this._run(deadline);
1686
+ });
1687
+ }
1688
+ _cancel() {
1689
+ if (this._scheduled !== null) this._scheduled();
1690
+ this._scheduled = null;
1691
+ }
1692
+ _initialize() {
1693
+ if (this._targets) return;
1694
+ let keysLength = this._mode === 2 ? this._keys.length : 1;
1695
+ let valueCount = this._input.length * keysLength;
1696
+ let rowCount = this._input.length;
1697
+ this._targets = new Array(valueCount);
1698
+ this._first = new Uint16Array(valueCount * 26);
1699
+ this._offsets = new Uint32Array(valueCount + 1);
1700
+ this._buildingBeginnings = [];
1701
+ this._rowCount = rowCount;
1702
+ this._rowWords = rowCount + 31 >> 5;
1703
+ this._rowBits = new Uint32Array(this._rowWords * 32);
1704
+ this._rows = new Uint32Array(rowCount);
1705
+ this._lastRowsLen = 0;
1706
+ this._matchedRowsLen = 0;
1707
+ this._lastQuery = null;
1708
+ this._candidateRows = null;
1709
+ this._candidateLength = rowCount;
1710
+ this._history = [];
1711
+ if (this._mode) {
1712
+ this._objects = this._input;
1713
+ this._getters = this._keys.map(makeGetter);
1714
+ }
1715
+ if (this._mode === 2) {
1716
+ this._keysLength = keysLength;
1717
+ this._bitflags = new Int32Array(rowCount);
1718
+ }
1719
+ }
1720
+ _run(deadline) {
1721
+ if (this._done || this._error) return;
1722
+ let end = Date.now() + 4;
1723
+ let hasTime = () => deadline && !deadline.didTimeout ? deadline.timeRemaining() > 1 : Date.now() < end;
1724
+ try {
1725
+ this._initialize();
1726
+ do
1727
+ this._prepareOne();
1728
+ while (this._index < this._input.length && hasTime());
1729
+ if (this._index === this._input.length) this._complete();
1730
+ else this._schedule();
1731
+ } catch (error) {
1732
+ this._error = error;
1733
+ this._done = true;
1734
+ }
1735
+ }
1736
+ _indexRow(row, bitflags) {
1737
+ let flags = bitflags >>> 0;
1738
+ let word = row >> 5;
1739
+ let mask = 1 << (row & 31);
1740
+ let words = this._rowWords;
1741
+ let bits = this._rowBits;
1742
+ while (flags) {
1743
+ let lowest = flags & -flags;
1744
+ let bit = 31 - Math.clz32(lowest);
1745
+ bits[bit * words + word] |= mask;
1746
+ flags = (flags & flags - 1) >>> 0;
1747
+ }
1748
+ }
1749
+ _prepareOne() {
1750
+ let i = this._index++;
1751
+ let mode = this._mode;
1752
+ let obj = this._input[i];
1753
+ let keysLength = mode === 2 ? this._keysLength : 1;
1754
+ let bitflags = 0;
1755
+ for (let k = 0; k < keysLength; k++) {
1756
+ let value = mode === 0 ? obj : this._getters[k] === null ? obj[this._keys[k]] : this._getters[k](obj);
1757
+ let row = mode === 2 ? i * keysLength + k : i;
1758
+ let prepared = this._targets[row] = value ? prepTarget(value) : noTarget;
1759
+ if (prepared !== noTarget) indexBeginnings(prepared, this._first, row, this._buildingBeginnings);
1760
+ this._offsets[row + 1] = this._buildingBeginnings.length;
1761
+ bitflags |= prepared._bitflags;
1762
+ }
1763
+ if (mode === 2) this._bitflags[i] = bitflags;
1764
+ this._indexRow(i, bitflags);
1765
+ }
1766
+ _complete() {
1767
+ this._beginnings = Uint16Array.from(this._buildingBeginnings);
1768
+ this._buildingBeginnings = this._input = this._getters = this._keys = null;
1769
+ this._done = true;
1770
+ }
1771
+ _bitOffsets(bitflags) {
1772
+ let offsetsLen = 0;
1773
+ let words = this._rowWords;
1774
+ for (let bit = 0; bit < 32; bit++) if (bitflags & 1 << bit) candidateBitOffsets[offsetsLen++] = bit * words;
1775
+ return offsetsLen;
1776
+ }
1777
+ _matchRows(bitflags, fill = false, stop = INF) {
1778
+ let offsetsLen = this._bitOffsets(bitflags);
1779
+ if (!offsetsLen) {
1780
+ if (fill) {
1781
+ this._candidateRows = null;
1782
+ this._candidateLength = this._rowCount;
1783
+ }
1784
+ return this._rowCount;
1785
+ }
1786
+ let bits = this._rowBits;
1787
+ let words = this._rowWords;
1788
+ let rowsLen = 0;
1789
+ for (let word = 0; word < words; word++) {
1790
+ let matches = bits[candidateBitOffsets[0] + word];
1791
+ for (let i = 1; i < offsetsLen && matches; i++) matches &= bits[candidateBitOffsets[i] + word];
1792
+ if (!fill) {
1793
+ rowsLen += bitCount(matches);
1794
+ if (rowsLen >= stop) return rowsLen;
1795
+ continue;
1796
+ }
1797
+ while (matches) {
1798
+ let lowest = matches & -matches;
1799
+ this._rows[rowsLen++] = (word << 5) + 31 - Math.clz32(lowest);
1800
+ matches = (matches & matches - 1) >>> 0;
1801
+ }
1802
+ }
1803
+ if (fill) {
1804
+ this._candidateRows = this._rows;
1805
+ this._candidateLength = rowsLen;
1806
+ }
1807
+ return rowsLen;
1808
+ }
1809
+ _beginSearch(query) {
1810
+ this._matchedRowsLen = 0;
1811
+ let previousQuery = this._lastQuery;
1812
+ let previousLength = this._lastRowsLen;
1813
+ this._lastQuery = null;
1814
+ let bitflags = query.bitflags >>> 0;
1815
+ if (previousQuery !== null && query._lower.startsWith(previousQuery)) {
1816
+ if (previousLength <= this._matchRows(bitflags, false, previousLength)) {
1817
+ this._candidateRows = this._rows;
1818
+ this._candidateLength = previousLength;
1819
+ return;
1820
+ }
1821
+ }
1822
+ this._matchRows(bitflags, true);
1823
+ }
1824
+ _endSearch(query) {
1825
+ this._lastRowsLen = this._matchedRowsLen;
1826
+ this._matchedRowsLen = 0;
1827
+ this._lastQuery = query._lower || null;
1828
+ this._candidateRows = null;
1829
+ this._candidateLength = 0;
1830
+ }
1831
+ _backtrack(query, options) {
1832
+ let history = this._history;
1833
+ if (history.length < 2 || options?.scoreFn || options?.threshold !== void 0) return null;
1834
+ let limit = getLimit(options);
1835
+ if (limit === INF) return null;
1836
+ let current = history[history.length - 1];
1837
+ let value = query._lower;
1838
+ if (current.query === value && current.limit === limit && current.results) return copyResults(current.results);
1839
+ if (value.length >= current.query.length || !current.query.startsWith(value)) return null;
1840
+ let i = history.length - 2;
1841
+ while (i >= 0 && history[i].query.length > value.length) i--;
1842
+ let entry = history[i];
1843
+ if (!entry || entry.query !== value || entry.limit !== limit) return null;
1844
+ history.length = i + 1;
1845
+ if (!entry.results) return null;
1846
+ this._resetSearch();
1847
+ return copyResults(entry.results);
1848
+ }
1849
+ _remember(query, results, options) {
1850
+ let history = this._history;
1851
+ let limit = getLimit(options);
1852
+ if (options?.scoreFn || options?.threshold !== void 0 || limit === INF || results.length > 256) {
1853
+ history.length = 0;
1854
+ return;
1855
+ }
1856
+ let value = query._lower;
1857
+ let last = history[history.length - 1];
1858
+ if (last && !value.startsWith(last.query)) history.length = 0;
1859
+ else if (last?.query === value && last.limit === limit) history.pop();
1860
+ history.push({
1861
+ query: value,
1862
+ limit,
1863
+ results: value.length <= 32 ? copyResults(results) : null
1864
+ });
1865
+ }
1866
+ _resetSearch() {
1867
+ this._lastQuery = null;
1868
+ this._lastRowsLen = this._matchedRowsLen = this._candidateLength = 0;
1869
+ this._candidateRows = null;
1870
+ }
1871
+ _finish() {
1872
+ if (this._error) throw this._error;
1873
+ if (this._done) return;
1874
+ this._cancel();
1875
+ try {
1876
+ this._initialize();
1877
+ while (this._index < this._input.length) this._prepareOne();
1878
+ this._complete();
1879
+ } catch (error) {
1880
+ this._error = error;
1881
+ this._done = true;
1882
+ throw error;
1883
+ }
1884
+ }
1885
+ };
1886
+ function copyResult(result) {
1887
+ if (result === noTarget) return noTarget;
1888
+ if (result instanceof KeysResult) {
1889
+ let copy = result.map(copyResult);
1890
+ copy.obj = result.obj;
1891
+ copy._score = result._score;
1892
+ if (result._partWinners) copy._partWinners = true;
1893
+ return copy;
1894
+ }
1895
+ let copy = materialize(result, result.obj);
1896
+ if (result._bestKeyScore !== void 0) copy._bestKeyScore = result._bestKeyScore;
1897
+ let indexes = result._indexes;
1898
+ copy._indexes = indexes.slice(0, indexes.len ?? indexes.length);
1899
+ copy._indexes.len = copy._indexes.length;
1900
+ return copy;
1901
+ }
1902
+ function copyResults(results) {
1903
+ let copies = results.map(copyResult);
1904
+ copies.total = results.total;
1905
+ return copies;
1906
+ }
1907
+ function prepTarget(target) {
1908
+ if (isPrepared(target)) target = target.target;
1909
+ else if (typeof target === "number") target = "" + target;
1910
+ else if (typeof target !== "string") target = "";
1911
+ let info = lowerInfo(target);
1912
+ return newResult(target, -INF, null, info._lower, info.lowerCodes, info.bitflags);
1913
+ }
1914
+ function prepQuery(search) {
1915
+ if (typeof search === "number") search = "" + search;
1916
+ else if (typeof search !== "string") search = "";
1917
+ search = remapChars(search).trim();
1918
+ let info = lowerInfoRemapped(search);
1919
+ info.bitflags &= ~SPACE_BIT;
1920
+ info.parts = info.hasSpace ? [...new Set(info._lower.split(/\s+/))].map(prepQuery) : [];
1921
+ return info;
1922
+ }
1923
+ function getPrepared(target) {
1924
+ if (target.length > 999) return prepTarget(target);
1925
+ let prepared = targetCache.get(target);
1926
+ if (prepared === void 0) targetCache.set(target, prepared = prepTarget(target));
1927
+ return prepared;
1928
+ }
1929
+ function getQuery(search) {
1930
+ if (search.length > 999) return prepQuery(search);
1931
+ let prepared = searchCache.get(search);
1932
+ if (prepared === void 0) {
1933
+ if (searchCache.size >= 512) searchCache.clear();
1934
+ searchCache.set(search, prepared = prepQuery(search));
1935
+ }
1936
+ return prepared;
1937
+ }
1938
+ function scanBeginnings(prepared, visit) {
1939
+ let target = remapChars(prepared.target);
1940
+ let wasUpper = false;
1941
+ let wasAlnum = false;
1942
+ let count = 0;
1943
+ for (let i = 0; i < target.length; i++) {
1944
+ let code = target.charCodeAt(i);
1945
+ let upper = code >= 65 && code <= 90;
1946
+ let alnum = upper || code >= 97 && code <= 122 || code >= 48 && code <= 57;
1947
+ let beginning = upper && !wasUpper || !wasAlnum || !alnum;
1948
+ wasUpper = upper;
1949
+ wasAlnum = alnum;
1950
+ if (beginning) {
1951
+ count++;
1952
+ visit(i);
1953
+ }
1954
+ }
1955
+ prepared._beginningsLen = count;
1956
+ }
1957
+ function indexBeginnings(prepared, firstTable, row, packed) {
1958
+ if (prepared.target.length >= 65535) return;
1959
+ let target = remapChars(prepared.target);
1960
+ let lowerCodes = prepared._targetLowerCodes;
1961
+ let offset = row * 26;
1962
+ let wasUpper = false;
1963
+ let wasAlnum = false;
1964
+ let count = 0;
1965
+ for (let i = 0; i < target.length; i++) {
1966
+ let code = target.charCodeAt(i);
1967
+ let upper = code >= 65 && code <= 90;
1968
+ let alnum = upper || code >= 97 && code <= 122 || code >= 48 && code <= 57;
1969
+ let beginning = upper && !wasUpper || !wasAlnum || !alnum;
1970
+ wasUpper = upper;
1971
+ wasAlnum = alnum;
1972
+ if (!beginning) continue;
1973
+ count++;
1974
+ packed.push(i);
1975
+ code = lowerCodes[i];
1976
+ if (code >= 97 && code <= 122) {
1977
+ let slot = offset + code - 97;
1978
+ if (firstTable[slot] === 0) firstTable[slot] = i + 1;
1979
+ }
1980
+ }
1981
+ prepared._beginningsLen = count;
1982
+ }
1983
+ function prepareSingleMatch(prepared, searchCode, fallbackIndex) {
1984
+ let matchI = fallbackIndex;
1985
+ let strict = false;
1986
+ scanBeginnings(prepared, (i) => {
1987
+ if (!strict && searchCode === prepared._targetLowerCodes[i]) {
1988
+ matchI = i;
1989
+ strict = true;
1990
+ }
1991
+ });
1992
+ prepared._singleMatchCode = searchCode;
1993
+ prepared._singleMatchIndex = matchI;
1994
+ prepared._singleMatchStrict = strict;
1995
+ }
1996
+ function makeBeginnings(prepared) {
1997
+ let beginnings = [];
1998
+ scanBeginnings(prepared, (i) => beginnings.push(i));
1999
+ return beginnings;
2000
+ }
2001
+ function makeNextBeginnings(prepared) {
2002
+ let next = [];
2003
+ let fill = 0;
2004
+ scanBeginnings(prepared, (i) => {
2005
+ for (; fill < i; fill++) next[fill] = i;
2006
+ });
2007
+ for (; fill < prepared.target.length; fill++) next[fill] = prepared.target.length;
2008
+ return next;
2009
+ }
2010
+ function remapCharacter(char) {
2011
+ let remapped = remappings[char];
2012
+ if (remapped !== void 0) return remapped;
2013
+ if (char.charCodeAt(0) < 128) return char;
2014
+ remapped = char.normalize("NFKD").replace(/[\u0300-\u036f]/g, "");
2015
+ return remapped.length === 1 ? remapped : char;
2016
+ }
2017
+ function remapChars(value) {
2018
+ if (customAsciiRemappings) return value.replace(/[\s\S]/g, remapCharacter);
2019
+ return /[^\x00-\x7F]|[\\"`]/.test(value) ? value.replace(/[^\x00-\x7F]|[\\"`]/g, remapCharacter) : value;
2020
+ }
2021
+ function lowerInfo(value) {
2022
+ return lowerInfoRemapped(remapChars(value));
2023
+ }
2024
+ function lowerInfoRemapped(value) {
2025
+ let lower = value.toLowerCase();
2026
+ let lowerCodes = [];
2027
+ let bitflags = 0;
2028
+ let hasSpace = false;
2029
+ for (let i = 0; i < lower.length; i++) {
2030
+ let code = lowerCodes[i] = lower.charCodeAt(i);
2031
+ if (code === 32) {
2032
+ hasSpace = true;
2033
+ bitflags |= SPACE_BIT;
2034
+ continue;
2035
+ }
2036
+ let bit = code >= 97 && code <= 122 ? code - 97 : code >= 48 && code <= 57 ? 26 : code <= 127 ? 30 : 31;
2037
+ bitflags |= 1 << bit;
2038
+ }
2039
+ return {
2040
+ lowerCodes,
2041
+ bitflags,
2042
+ hasSpace,
2043
+ _lower: lower
2044
+ };
2045
+ }
2046
+ var Result = class {
2047
+ get ["indexes"]() {
2048
+ return this._indexes.slice(0, this._indexes.len).sort((a, b) => a - b);
2049
+ }
2050
+ set ["indexes"](value) {
2051
+ this._indexes = value;
2052
+ }
2053
+ ["highlight"](open, close, threshold) {
2054
+ return highlight(this, open, close, threshold);
2055
+ }
2056
+ get ["score"]() {
2057
+ return normalizeScore(this._score);
2058
+ }
2059
+ };
2060
+ var KeysResult = class extends Array {
2061
+ get ["score"]() {
2062
+ return normalizeScore(this._score);
2063
+ }
2064
+ };
2065
+ function newResult(target, score = -INF, obj = null, lower = "", lowerCodes = null, bitflags = 0) {
2066
+ let result = new Result();
2067
+ result.target = target;
2068
+ result.obj = obj;
2069
+ result._score = score;
2070
+ result._indexes = [];
2071
+ result._targetLower = lower;
2072
+ result._targetLowerCodes = lowerCodes;
2073
+ result._nextBeginningIndexes = null;
2074
+ result._beginnings = null;
2075
+ result._beginningsLen = 0;
2076
+ result._singleMatchCode = result._singleMatchIndex = -1;
2077
+ result._singleMatchStrict = false;
2078
+ result._bitflags = bitflags;
2079
+ return result;
2080
+ }
2081
+ function materialize(prepared, obj = null) {
2082
+ let result = new Result();
2083
+ result.target = prepared.target;
2084
+ result.obj = obj;
2085
+ result._score = prepared._score;
2086
+ result._indexes = prepared._indexes;
2087
+ return result;
2088
+ }
2089
+ function markBestKeyScore(result) {
2090
+ let best = -INF;
2091
+ for (let i = 0; i < result.length; i++) if (result[i] !== noTarget && result[i]._score > best) best = result[i]._score;
2092
+ for (let i = 0; i < result.length; i++) if (result[i] !== noTarget) result[i]._bestKeyScore = best;
2093
+ return result;
2094
+ }
2095
+ function captureKeysResult(matches, keysLength, obj, score, partWinners = false) {
2096
+ let result = new KeysResult(keysLength);
2097
+ for (let k = 0; k < keysLength; k++) result[k] = matches[k];
2098
+ result.obj = obj;
2099
+ result._score = score;
2100
+ if (partWinners) result._partWinners = true;
2101
+ return result;
2102
+ }
2103
+ let normalizeScore = (value) => value === -INF ? 0 : value > 1 ? value : Math.E ** (((-value + 1) ** .04307 - 1) * -2);
2104
+ let denormalizeScore = (value) => value === 0 ? -INF : value > 1 ? value : 1 - Math.pow(Math.log(value) / -2 + 1, 1 / .04307);
2105
+ let GOOD_PART_SCORE = denormalizeScore(.5);
2106
+ let isPrepared = (value) => typeof value === "object" && typeof value?._bitflags === "number";
2107
+ function makeGetter(key) {
2108
+ if (typeof key === "function") return key;
2109
+ let path = Array.isArray(key) ? key : typeof key === "string" && key.includes(".") ? key.split(".") : null;
2110
+ if (path === null) return null;
2111
+ return (obj) => {
2112
+ if (path !== key) {
2113
+ let direct = obj[key];
2114
+ if (direct !== void 0) return direct;
2115
+ }
2116
+ for (let i = 0; obj && i < path.length; i++) obj = obj[path[i]];
2117
+ return obj;
2118
+ };
2119
+ }
2120
+ function scoreCeiling(searchLen, targetLen) {
2121
+ let lengthPenalty = (targetLen - searchLen) / 2;
2122
+ let bonus = 1 + searchLen * searchLen;
2123
+ let score = -lengthPenalty - lengthPenalty / (bonus * bonus);
2124
+ return score + Math.min(4, -score / 2);
2125
+ }
2126
+ function bitCount(value) {
2127
+ value -= value >>> 1 & 1431655765;
2128
+ value = (value & 858993459) + (value >>> 2 & 858993459);
2129
+ return (value + (value >>> 4) & 252645135) * 16843009 >>> 24;
2130
+ }
2131
+ function lowerBound(values, start, end, value) {
2132
+ while (start < end) {
2133
+ let middle = start + end >> 1;
2134
+ if (values[middle] < value) start = middle + 1;
2135
+ else end = middle;
2136
+ }
2137
+ return start;
2138
+ }
2139
+ function nextBeginning(indexes, start, end, index, targetLen) {
2140
+ let next = lowerBound(indexes, start, end, index + 1);
2141
+ return next < end ? indexes[next] : targetLen;
2142
+ }
2143
+ function isBeginning(indexes, start, end, index) {
2144
+ let found = lowerBound(indexes, start, end, index);
2145
+ return found < end && indexes[found] === index;
2146
+ }
2147
+ function getLimit(options) {
2148
+ return (options?.limit ?? 10) || INF;
2149
+ }
2150
+ function scheduleTask(run) {
2151
+ let id;
2152
+ if (typeof requestIdleCallback === "function") {
2153
+ id = requestIdleCallback(run, { timeout: 100 });
2154
+ return () => typeof cancelIdleCallback === "function" && cancelIdleCallback(id);
2155
+ }
2156
+ if (typeof setImmediate === "function") {
2157
+ id = setImmediate(run);
2158
+ return () => typeof clearImmediate === "function" && clearImmediate(id);
2159
+ }
2160
+ id = setTimeout(run);
2161
+ return () => clearTimeout(id);
2162
+ }
2163
+ function createHeap() {
2164
+ let items = [];
2165
+ let length = 0;
2166
+ function down() {
2167
+ let index = 0;
2168
+ let item = items[0];
2169
+ for (let child = 1; child < length; child = 1 + index * 2) {
2170
+ let right = child + 1;
2171
+ index = right < length && items[right]._score < items[child]._score ? right : child;
2172
+ items[index - 1 >> 1] = items[index];
2173
+ }
2174
+ for (let parent = index - 1 >> 1; index > 0 && item._score < items[parent]._score; parent = (index = parent) - 1 >> 1) items[index] = items[parent];
2175
+ items[index] = item;
2176
+ }
2177
+ return {
2178
+ add(item) {
2179
+ let index = length++;
2180
+ for (let parent = index - 1 >> 1; index > 0 && item._score < items[parent]._score; parent = (index = parent) - 1 >> 1) items[index] = items[parent];
2181
+ items[index] = item;
2182
+ },
2183
+ poll() {
2184
+ if (!length) return;
2185
+ let root = items[0];
2186
+ let last = items[--length];
2187
+ items[length] = void 0;
2188
+ if (length) {
2189
+ items[0] = last;
2190
+ down();
2191
+ }
2192
+ return root;
2193
+ },
2194
+ peek() {
2195
+ return length ? items[0] : void 0;
2196
+ },
2197
+ replaceTop(item) {
2198
+ items[0] = item;
2199
+ down();
2200
+ },
2201
+ clear() {
2202
+ items.length = length = 0;
2203
+ }
2204
+ };
2205
+ }
2206
+ let INF = Infinity;
2207
+ let SPACE_BIT = 1 << 27;
2208
+ let noResults = [];
2209
+ noResults.total = 0;
2210
+ let targetCache = /* @__PURE__ */ new Map();
2211
+ let searchCache = /* @__PURE__ */ new Map();
2212
+ let simpleMatch = [];
2213
+ let strictMatch = [];
2214
+ let seen = [];
2215
+ let seenAt = [];
2216
+ let changes = [];
2217
+ let partials = [];
2218
+ let spaceScores = [];
2219
+ let partIndexes = [];
2220
+ let winnerIndexes = [];
2221
+ let winnerScores = [];
2222
+ let winnerKeys = [];
2223
+ let keyTargets = [];
2224
+ let keyResults = [];
2225
+ let candidateBitOffsets = [];
2226
+ let seenGeneration = 0;
2227
+ let remappings = {};
2228
+ let remapFrom = "\\\"`‘’‚‛“”„‟«»‹›‐–—−⁄∕…øØłŁđĐðÐıħĦŧŦ";
2229
+ let remapTo = "/''''''''''''''----//.oOlLdDdDihHtT";
2230
+ for (let i = 0; i < 35; i++) remappings[remapFrom[i]] = remapTo[i];
2231
+ let customAsciiRemappings = false;
2232
+ let heap = createHeap();
2233
+ let noTarget = prepTarget("");
2234
+ let prunedMatch = {};
2235
+ var fuzzysort_default = {
2236
+ single,
2237
+ go,
2238
+ highlight,
2239
+ score,
2240
+ remap,
2241
+ prepare,
2242
+ snapshot,
2243
+ cleanup
2244
+ };
2245
+ //#endregion
2246
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-util-text-search@0.2.3-alpha.2_@deepseek-ai+cordis@4.2.0-alpha.1/node_modules/@deepseek-ai/dsh-util-text-search/lib/index.js
2247
+ /**
2248
+ * Multilingual fuzzy search over an in-memory list.
2249
+ *
2250
+ * A {@link TextSearchIndex} prepares every key of a list once, then answers
2251
+ * any number of queries over that list. `fuzzy` keys (names, titles, labels,
2252
+ * readable ids) match as substrings or as fuzzysort subsequences that start at
2253
+ * a word start, so `cpt` finds `compact` while `fab` does not match inside
2254
+ * `Refactor build`. `substring` keys (descriptions, prompts, paths, opaque
2255
+ * ids) match only as a contiguous substring of each query term: a subsequence
2256
+ * scattered across a long sentence is noise. Every key may carry several
2257
+ * values, such as every language of a localized title. Both key kinds ignore
2258
+ * case, width (NFKC), U+0300–U+036F diacritics, and the stroke of letters such
2259
+ * as `ł` and `ø`. Matching requires every whitespace-separated query term to
2260
+ * match some key of the item.
2261
+ *
2262
+ * Each term scores by its best tier: a fuzzy-key prefix, then a fuzzy-key
2263
+ * substring, then a fuzzy subsequence ordered by fuzzysort score, then a
2264
+ * substring-key hit. Equal scores keep the build order, so a term that
2265
+ * prefixes every name leaves the list in product order.
2266
+ *
2267
+ * @module @deepseek-ai/dsh-util-text-search
2268
+ */
2269
+ /** Tier bases; a fuzzy subsequence hit adds its fuzzysort score in [0, 1) to its base. */
2270
+ const FUZZY_PREFIX = 4;
2271
+ const FUZZY_SUBSTRING = 3;
2272
+ const FUZZY_SUBSEQUENCE = 2;
2273
+ const SUBSTRING = 1;
2274
+ const WORD_CHAR = /[\p{L}\p{N}]/u;
2275
+ const UPPER = /\p{Lu}/u;
2276
+ const LOWER = /\p{Ll}/u;
2277
+ /** Scripts written without spaces between words; each of their characters starts a word. */
2278
+ const UNSPACED = /[\p{scx=Han}\p{scx=Hira}\p{scx=Kana}\p{scx=Hang}]/u;
2279
+ /** The code point starting at UTF-16 offset `index`, which callers keep inside `text`. */
2280
+ function codePointAt(text, index) {
2281
+ return String.fromCodePoint(text.codePointAt(index));
2282
+ }
2283
+ /** The code point ending just before UTF-16 offset `index`. */
2284
+ function codePointBefore(text, index) {
2285
+ const low = text.charCodeAt(index - 1);
2286
+ return codePointAt(text, low >= 56320 && low <= 57343 && index >= 2 ? index - 2 : index - 1);
2287
+ }
2288
+ /**
2289
+ * Whether the code point at UTF-16 offset `index` of `text` starts a word: after a separator,
2290
+ * at a camel-case hump, or in an unspaced script.
2291
+ */
2292
+ function wordStart(text, index) {
2293
+ if (index === 0) return true;
2294
+ const char = codePointAt(text, index);
2295
+ const previous = codePointBefore(text, index);
2296
+ return !WORD_CHAR.test(previous) || UNSPACED.test(char) || UPPER.test(char) && LOWER.test(previous);
2297
+ }
2298
+ const PRINTABLE_ASCII = /^[\x20-\x7e]*$/;
2299
+ /** Combining diacritical marks; other scripts' combining marks, such as kana voicing or Indic vowel signs, change the letter and stay. */
2300
+ const DIACRITIC = /[\u0300-\u036f]/gu;
2301
+ /** Letters with a built-in stroke that decomposition leaves intact, mapped to their base letter. */
2302
+ const STROKED = {
2303
+ "ø": "o",
2304
+ "Ø": "O",
2305
+ "ł": "l",
2306
+ "Ł": "L",
2307
+ "đ": "d",
2308
+ "Đ": "D",
2309
+ "ð": "d",
2310
+ "Ð": "D",
2311
+ "ı": "i",
2312
+ "ħ": "h",
2313
+ "Ħ": "H",
2314
+ "ŧ": "t",
2315
+ "Ŧ": "T"
2316
+ };
2317
+ const STROKED_CHAR = /[øØłŁđĐðÐıħĦŧŦ]/gu;
2318
+ /** Width- and diacritic-insensitive form that keeps case, so camel-case humps survive for word starts. */
2319
+ function strip(value) {
2320
+ if (PRINTABLE_ASCII.test(value)) return value;
2321
+ return value.normalize("NFKD").replace(DIACRITIC, "").normalize("NFKC").replace(STROKED_CHAR, (char) => STROKED[char]);
2322
+ }
2323
+ /** Case-, width-, and diacritic-insensitive form used for substring tests. */
2324
+ function fold(value) {
2325
+ return strip(value).toLowerCase();
2326
+ }
2327
+ /**
2328
+ * Prepare one item's keys, reusing an earlier index's preparation of the same string.
2329
+ * @param keys - the item's search text.
2330
+ * @param reuse - preparations of the index being updated, if any.
2331
+ * @param into - preparations of the index being built; receives every string this item uses.
2332
+ */
2333
+ function prepareKeys(keys, reuse, into) {
2334
+ return {
2335
+ fuzzy: (keys.fuzzy ?? []).flatMap((value) => {
2336
+ if (value === void 0 || value === "") return [];
2337
+ let name = into.fuzzy.get(value) ?? reuse?.fuzzy.get(value);
2338
+ if (name === void 0) {
2339
+ const stripped = strip(value);
2340
+ name = {
2341
+ stripped,
2342
+ folded: stripped.toLowerCase(),
2343
+ starts: void 0,
2344
+ tails: /* @__PURE__ */ new Map()
2345
+ };
2346
+ }
2347
+ into.fuzzy.set(value, name);
2348
+ return [name];
2349
+ }),
2350
+ substring: (keys.substring ?? []).flatMap((value) => {
2351
+ if (value === void 0 || value === "") return [];
2352
+ const folded = into.substring.get(value) ?? reuse?.substring.get(value) ?? fold(value);
2353
+ into.substring.set(value, folded);
2354
+ return [folded];
2355
+ })
2356
+ };
2357
+ }
2358
+ /** Prepare every item's keys. */
2359
+ function build(items, keys, reuse) {
2360
+ const preparations = {
2361
+ fuzzy: /* @__PURE__ */ new Map(),
2362
+ substring: /* @__PURE__ */ new Map()
2363
+ };
2364
+ return {
2365
+ keys: items.map((item) => prepareKeys(keys(item), reuse, preparations)),
2366
+ preparations
2367
+ };
2368
+ }
2369
+ /** Whether every character of `term` occurs in `text` in order; a cheap filter before fuzzysort. */
2370
+ function inOrder(term, text) {
2371
+ let at = 0;
2372
+ for (const char of term) {
2373
+ at = text.indexOf(char, at);
2374
+ if (at === -1) return false;
2375
+ at += char.length;
2376
+ }
2377
+ return true;
2378
+ }
2379
+ /**
2380
+ * The best fuzzysort score of a term over the subsequences of `name` that start at a word start.
2381
+ * fuzzysort reports one alignment per target, so each word start whose character equals the term's
2382
+ * first character is tried as its own target.
2383
+ */
2384
+ function fuzzyNameScore(term, name) {
2385
+ if (!inOrder(term.folded, name.folded)) return void 0;
2386
+ if (name.starts === void 0) {
2387
+ const starts = [];
2388
+ let index = 0;
2389
+ for (const char of name.stripped) {
2390
+ if (wordStart(name.stripped, index)) starts.push(index);
2391
+ index += char.length;
2392
+ }
2393
+ name.starts = starts;
2394
+ }
2395
+ const first = codePointAt(term.stripped, 0).toLowerCase();
2396
+ let best;
2397
+ for (const start of name.starts) {
2398
+ if (codePointAt(name.stripped, start).toLowerCase() !== first) continue;
2399
+ let tail = name.tails.get(start);
2400
+ if (tail === void 0) {
2401
+ tail = fuzzysort_default.prepare(name.stripped.slice(start));
2402
+ name.tails.set(start, tail);
2403
+ }
2404
+ const result = fuzzysort_default.single(term.stripped, tail);
2405
+ if (result !== null && wordStart(name.stripped, start + result.indexes[0])) best = best === void 0 ? result.score : Math.max(best, result.score);
2406
+ }
2407
+ return best;
2408
+ }
2409
+ /** The best score of one term over one item's keys, or undefined when no key matches. */
2410
+ function termScore(term, keys) {
2411
+ let best;
2412
+ const take = (score) => {
2413
+ best = best === void 0 ? score : Math.max(best, score);
2414
+ };
2415
+ for (const name of keys.fuzzy) {
2416
+ const at = name.folded.indexOf(term.folded);
2417
+ if (at === 0) take(FUZZY_PREFIX);
2418
+ else if (at > 0) take(FUZZY_SUBSTRING);
2419
+ else {
2420
+ const score = fuzzyNameScore(term, name);
2421
+ if (score !== void 0) take(FUZZY_SUBSEQUENCE + Math.min(score, .99));
2422
+ }
2423
+ }
2424
+ for (const text of keys.substring) if (text.includes(term.folded)) take(SUBSTRING);
2425
+ return best;
2426
+ }
2427
+ /**
2428
+ * Search index over one list. The constructor prepares every key of every
2429
+ * item; {@link TextSearchIndex.search} then answers queries without
2430
+ * re-reading the items or their keys. An index holds its list by reference and
2431
+ * never changes: callers must not mutate the list or its items, and call
2432
+ * {@link TextSearchIndex.update} with a new list when the list or any item's
2433
+ * keys change.
2434
+ */
2435
+ var TextSearchIndex = class TextSearchIndex {
2436
+ #items;
2437
+ #keys;
2438
+ #preparations;
2439
+ /**
2440
+ * Prepare every key of every item.
2441
+ * @param items - candidates in their display order, which ties keep.
2442
+ * @param keys - the search text of one item, called once per item here.
2443
+ */
2444
+ constructor(items, keys) {
2445
+ const built = build(items, keys, void 0);
2446
+ this.#items = items;
2447
+ this.#keys = built.keys;
2448
+ this.#preparations = built.preparations;
2449
+ }
2450
+ /**
2451
+ * Build the index of a changed list. Items added, removed, reordered, or
2452
+ * changed are all expressed by the complete new list; a key string that this
2453
+ * index already prepared is reused instead of prepared again, and strings no
2454
+ * item uses any more are not carried over. This index stays valid.
2455
+ * @param items - the complete new list in display order.
2456
+ * @param keys - the search text of one item, called once per item here.
2457
+ * @returns a new index over `items`.
2458
+ */
2459
+ update(items, keys) {
2460
+ const next = new TextSearchIndex([], keys);
2461
+ const built = build(items, keys, this.#preparations);
2462
+ next.#items = items;
2463
+ next.#keys = built.keys;
2464
+ next.#preparations = built.preparations;
2465
+ return next;
2466
+ }
2467
+ /**
2468
+ * Filter and rank the indexed items by a query.
2469
+ * @param query - the user's search text.
2470
+ * @returns the build list itself when the query is blank or holds only
2471
+ * combining marks; otherwise the items matching every query term, best total
2472
+ * score first and build order on ties.
2473
+ */
2474
+ search(query) {
2475
+ const terms = query.trim().split(/\s+/u).map((term) => ({
2476
+ stripped: strip(term),
2477
+ folded: fold(term)
2478
+ })).filter((term) => term.folded !== "");
2479
+ if (terms.length === 0) return this.#items;
2480
+ const ranked = [];
2481
+ this.#keys.forEach((itemKeys, index) => {
2482
+ let score = 0;
2483
+ for (const term of terms) {
2484
+ const hit = termScore(term, itemKeys);
2485
+ if (hit === void 0) return;
2486
+ score += hit;
2487
+ }
2488
+ ranked.push({
2489
+ index,
2490
+ score
2491
+ });
2492
+ });
2493
+ ranked.sort((left, right) => right.score - left.score || left.index - right.index);
2494
+ return ranked.map((entry) => this.#items[entry.index]);
2495
+ }
2496
+ };
885
2497
  /**
886
2498
  * Flatten the catalog to one row per model.
887
2499
  * @param groups - the shared directory's provider groups, in display order.
@@ -918,18 +2530,14 @@ window.__ModuleLoader__.load({
918
2530
  function rowsForTab(rows, tab) {
919
2531
  return tab === "*" ? rows : rows.filter((row) => row.provider === tab);
920
2532
  }
921
- /**
922
- * Shape rows as the shell's ranker candidates: the model name is the name, the
923
- * provider display name is the second key, so a query reaches either.
924
- * @param rows - the rows to search.
925
- * @returns candidates in row order.
926
- */
927
- function searchCandidates(rows) {
928
- return rows.map((row) => ({
929
- name: row.entry.name,
930
- label: row.providerName,
931
- row
932
- }));
2533
+ /** Build a reusable search index for the rows in the current provider tab. */
2534
+ function createModelSearch(rows) {
2535
+ return new TextSearchIndex(rows, (row) => ({ fuzzy: [
2536
+ row.entry.name,
2537
+ row.model,
2538
+ row.providerName,
2539
+ row.provider
2540
+ ] }));
933
2541
  }
934
2542
  /**
935
2543
  * Read the reasoning metadata the catalog advertises for one model.
@@ -939,22 +2547,10 @@ window.__ModuleLoader__.load({
939
2547
  function reasoningOf(groups) {
940
2548
  return (provider, model) => groups.find((group) => group.id === provider)?.models.find((candidate) => candidate.id === model)?.reasoning;
941
2549
  }
942
- /**
943
- * Filter rows by a query over the model name and the provider name.
944
- * @param rows - the rows to search.
945
- * @param query - the typed text; an empty or blank query keeps every row.
946
- * @param rank - the shell's own ranker, so this search behaves like every other one.
947
- * @returns the matching rows.
948
- */
949
- function searchRows(rows, query, rank) {
950
- const trimmed = query.trim();
951
- if (trimmed === "") return rows;
952
- return rank(searchCandidates(rows), trimmed).map((match) => match.row);
953
- }
954
2550
  //#endregion
955
2551
  //#region src/client/ModelPicker.tsx
956
2552
  /**
957
- * The model picker: the centered dialog opened from the menu's last row.
2553
+ * The model picker: the centered dialog opened from the menu's model row.
958
2554
  *
959
2555
  * It is the one place every provider is visible at once — a search field, a tab
960
2556
  * per provider with a model, and one flat list with each model's metadata line.
@@ -969,19 +2565,14 @@ window.__ModuleLoader__.load({
969
2565
  */
970
2566
  function ModelPicker({ open, resolveText, state, live, facts, favorites, busy, rememberedOf, onPick, onToggleFavorite, onReload, onClose, t }) {
971
2567
  const id = (0, react.useId)();
972
- const searchRef = (0, react.useRef)(null);
973
2568
  const listRef = (0, react.useRef)(null);
974
2569
  const [query, setQuery] = (0, react.useState)("");
975
2570
  const [tab, setTab] = (0, react.useState)("*");
976
2571
  const tabs = (0, react.useMemo)(() => pickerTabs(state.groups, t("picker.all")), [state.groups, t]);
977
2572
  const reason = (0, react.useMemo)(() => reasoningOf(state.groups), [state.groups]);
978
- const rows = (0, react.useMemo)(() => orderWithFavorites(rowsForTab(flattenGroups(state.groups), tab), (row) => isFavorite(favorites, row.provider, row.model)), [
979
- state.groups,
980
- tab,
981
- favorites
982
- ]);
983
- const visible = (0, react.useMemo)(() => orderWithFavorites(searchRows(rows, query, _deepseek_ai_dsh_client_ui_primitives.rankByName), (row) => isFavorite(favorites, row.provider, row.model)), [
984
- rows,
2573
+ const search = (0, react.useMemo)(() => createModelSearch(rowsForTab(flattenGroups(state.groups), tab)), [state.groups, tab]);
2574
+ const visible = (0, react.useMemo)(() => orderWithFavorites(search.search(query), (row) => isFavorite(favorites, row.provider, row.model)), [
2575
+ search,
985
2576
  query,
986
2577
  favorites
987
2578
  ]);
@@ -990,12 +2581,6 @@ window.__ModuleLoader__.load({
990
2581
  setQuery("");
991
2582
  setTab("*");
992
2583
  if (listRef.current !== null) listRef.current.scrollTop = 0;
993
- const frame = requestAnimationFrame(() => {
994
- if (!(0, _deepseek_ai_dsh_client_ui_primitives.isMobileDevice)()) searchRef.current?.focus();
995
- });
996
- return () => {
997
- cancelAnimationFrame(frame);
998
- };
999
2584
  }, [open]);
1000
2585
  if (!open) return null;
1001
2586
  const pick = (row) => {
@@ -1020,7 +2605,6 @@ window.__ModuleLoader__.load({
1020
2605
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1021
2606
  className: ModelOptions_module_css_default.pickerSearch,
1022
2607
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Input, {
1023
- ref: searchRef,
1024
2608
  className: ModelOptions_module_css_default.pickerSearchInput ?? "",
1025
2609
  type: "text",
1026
2610
  role: "searchbox",
@@ -1033,7 +2617,7 @@ window.__ModuleLoader__.load({
1033
2617
  onChange: (event) => {
1034
2618
  setQuery(event.target.value);
1035
2619
  },
1036
- "data-modal-autofocus": ""
2620
+ "data-modal-autofocus": (0, _deepseek_ai_dsh_client_ui_primitives.isMobileDevice)() ? void 0 : ""
1037
2621
  })
1038
2622
  }),
1039
2623
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -1197,9 +2781,9 @@ window.__ModuleLoader__.load({
1197
2781
  /**
1198
2782
  * The composer overlay's picker view: the dialog, its catalog, and its verbs.
1199
2783
  *
1200
- * It lives in `conversation.input.overlay` rather than beside the row, because
1201
- * the Host unmounts the model menu as soon as a row is clicked. Everything the
1202
- * dialog reads arrives through this entry's injected face.
2784
+ * It lives in `conversation.input.overlay` so it can open after the Host's menu
2785
+ * closes or from the toolbar when the current model is missing. Its data comes
2786
+ * from the slot entry's injected face.
1203
2787
  */
1204
2788
  /**
1205
2789
  * Render the picker for this session.
@@ -1214,10 +2798,21 @@ window.__ModuleLoader__.load({
1214
2798
  const [toast, setToast] = (0, react.useState)(null);
1215
2799
  const toastSeq = (0, react.useRef)(0);
1216
2800
  const rootRef = (0, react.useRef)(null);
1217
- const busy = state.status === "selecting";
2801
+ const busy = state.pending !== null;
1218
2802
  const live = (0, react.useMemo)(() => selectionOf(state), [state]);
1219
2803
  const facts = (0, react.useSyncExternalStore)((listener) => factsSource.subscribe(listener), () => factsSource.getSnapshot());
1220
- const open = request.sessionId === sessionId;
2804
+ const open = available && request.sessionId === sessionId;
2805
+ (0, react.useEffect)(() => {
2806
+ const trigger = request.returnFocus;
2807
+ if (!open || trigger === void 0) return;
2808
+ return () => {
2809
+ if (picker.getSnapshot().sessionId === null && trigger.isConnected && !trigger.closest("[inert], [hidden]")) trigger.focus({ preventScroll: true });
2810
+ };
2811
+ }, [
2812
+ open,
2813
+ picker,
2814
+ request
2815
+ ]);
1221
2816
  const loadRef = (0, react.useRef)(load);
1222
2817
  loadRef.current = load;
1223
2818
  (0, react.useEffect)(() => {
@@ -1241,12 +2836,14 @@ window.__ModuleLoader__.load({
1241
2836
  });
1242
2837
  };
1243
2838
  const submit = (selection) => {
2839
+ if (directory.getSnapshot().pending !== null) return;
1244
2840
  select(selection).then((result) => {
1245
- if (result === void 0 || result.ok) {
2841
+ if (result?.ok) {
1246
2842
  setMemory(rememberEffort(storageOf(), selection.provider, selection.model, selection.reasoningEffort));
1247
- picker.close();
2843
+ if (picker.getSnapshot() === request) picker.close();
1248
2844
  return;
1249
2845
  }
2846
+ if (result === void 0 || picker.getSnapshot() !== request) return;
1250
2847
  raiseToast(result.error.code === "session/writer-held" ? t("error.sessionInUse") : t("error.action", { message: `${result.error.code}: ${result.error.message}` }));
1251
2848
  });
1252
2849
  };
@@ -1281,6 +2878,21 @@ window.__ModuleLoader__.load({
1281
2878
  }, toast.seq)]
1282
2879
  });
1283
2880
  }
2881
+ /** The Host skips the root menu when the current model is absent from its catalog. */
2882
+ function ModelPickerFallback({ sessionId, picker, available, directory, t }) {
2883
+ const state = (0, react.useSyncExternalStore)((listener) => directory.subscribe(listener), () => directory.getSnapshot());
2884
+ if (!available || currentCatalogModel(state) !== void 0) return null;
2885
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2886
+ variant: "toolbar",
2887
+ size: "sm",
2888
+ "aria-haspopup": "dialog",
2889
+ disabled: state.pending !== null,
2890
+ onClick: (event) => {
2891
+ if (directory.getSnapshot().pending === null) picker.open(sessionId, event.currentTarget);
2892
+ },
2893
+ children: t("picker.browse")
2894
+ });
2895
+ }
1284
2896
  /** Isolate the browser's storage so a locked-down browser reads as "no favorites". */
1285
2897
  function storageOf() {
1286
2898
  try {
@@ -1310,8 +2922,11 @@ window.__ModuleLoader__.load({
1310
2922
  listeners.delete(listener);
1311
2923
  };
1312
2924
  },
1313
- open: (sessionId) => {
1314
- publish({ sessionId });
2925
+ open: (sessionId, returnFocus) => {
2926
+ publish(returnFocus === void 0 ? { sessionId } : {
2927
+ sessionId,
2928
+ returnFocus
2929
+ });
1315
2930
  },
1316
2931
  close: () => {
1317
2932
  publish({ sessionId: null });
@@ -1379,6 +2994,7 @@ window.__ModuleLoader__.load({
1379
2994
  "error.action": "模型操作失败:{message}",
1380
2995
  "error.sessionInUse": "当前会话已被占用,可能是其他正在运行的 DSH 导致的(如其他 dsh web、桌面端),请退出其他正在运行的 DSH 后重试。",
1381
2996
  "picker.title": "切换模型",
2997
+ "picker.browse": "浏览模型",
1382
2998
  "picker.close": "关闭",
1383
2999
  "picker.search": "搜索模型或提供商…",
1384
3000
  "picker.searchEmpty": "没有匹配的模型。",
@@ -1402,6 +3018,7 @@ window.__ModuleLoader__.load({
1402
3018
  "error.action": "Model operation failed: {message}",
1403
3019
  "error.sessionInUse": "This session is already in use, possibly by another running DSH instance (such as dsh web or the desktop app). Quit other running DSH instances and try again.",
1404
3020
  "picker.title": "Switch model",
3021
+ "picker.browse": "Browse models",
1405
3022
  "picker.close": "Close",
1406
3023
  "picker.search": "Search models or providers…",
1407
3024
  "picker.searchEmpty": "No matching models.",
@@ -1440,16 +3057,22 @@ window.__ModuleLoader__.load({
1440
3057
  ];
1441
3058
  /**
1442
3059
  * Client plugin body: register this plugin's dictionaries, then contribute the
1443
- * bridge that turns the Host's model cell into the picker's door and its effort
1444
- * cell into the reasoning-level slider, the overlay that renders the picker, and
1445
- * the tint that keeps the collapsed trigger's effort caption on the same color.
3060
+ * menu bridge, the toolbar entry for a missing current model, the picker
3061
+ * overlay, and the tint for the collapsed trigger's effort caption.
1446
3062
  *
1447
- * The two are separate entries because the Host unmounts the model menu the
1448
- * moment a row is clicked; the overlay slot stays mounted, so the dialog
1449
- * survives the menu's teardown.
3063
+ * The overlay stays mounted when the Host closes the model menu, allowing the
3064
+ * picker to open after the menu has been removed.
1450
3065
  * @param ctx - client root context.
1451
3066
  */
1452
3067
  function apply(ctx) {
3068
+ if (typeof document !== "undefined") ctx.effect(() => {
3069
+ const style = document.createElement("style");
3070
+ style.dataset.plugin = "@lynn123411/dsh-model-submenu";
3071
+ style.dataset.pluginCss = "@lynn123411/dsh-model-submenu/ModelOptions.module.css";
3072
+ style.textContent = stylesheet;
3073
+ document.head.append(style);
3074
+ return () => style.remove();
3075
+ }, "dsh-model-submenu: styles");
1453
3076
  ctx.effect(() => ctx.locale.register(NS, {
1454
3077
  zh,
1455
3078
  en
@@ -1467,7 +3090,7 @@ window.__ModuleLoader__.load({
1467
3090
  describe: scope.configForms.describe(),
1468
3091
  listProviders: () => scope.remote.llm.listConfigurableProviders()
1469
3092
  });
1470
- ctx.effect(() => facts.start(), "dsh-model-submenu: model metadata");
3093
+ scope.effect(() => facts.start(), "dsh-model-submenu: model metadata");
1471
3094
  /**
1472
3095
  * Build one entry's business face for a session.
1473
3096
  * @param sessionId - the slot's session scope.
@@ -1504,6 +3127,13 @@ window.__ModuleLoader__.load({
1504
3127
  locale: NS,
1505
3128
  inject: faceOf
1506
3129
  }, ModelPickerHost));
3130
+ scope.slots.inject("conversation.input.right", () => scope.slots.register({
3131
+ name: "conversation.input.right",
3132
+ id: "model-picker-fallback",
3133
+ registrant: "@lynn123411/dsh-model-submenu",
3134
+ locale: NS,
3135
+ inject: faceOf
3136
+ }, ModelPickerFallback));
1507
3137
  scope.slots.inject("conversation.input.overlay", () => scope.slots.register({
1508
3138
  name: "conversation.input.overlay",
1509
3139
  id: "model-effort-tint",