@hackbuild/ai-views 0.1.1 → 0.1.5

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.
@@ -2448,14 +2448,14 @@ function initDev() {
2448
2448
  }
2449
2449
  initDev();
2450
2450
  // node_modules/@virgilvox/hackbuild-ui/dist/vanilla.js
2451
- const Yt = "M2 12c3-5 6.5-7 10-7s7 2 10 7c-3 5-6.5 7-10 7s-7-2-10-7zM9 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0";
2452
- const Xt = "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3";
2453
- const Gt = "M3 6h12v12H3zM15 10l6-3v10l-6-3";
2454
- const Je = "M3 12h16M13 6l6 6-6 6";
2455
- const Qe = "M20 12a8 8 0 1 1-3-6.2M20 4v5h-5";
2456
- const Mt = {
2457
- send: { d: Je },
2458
- microphone: { d: Xt },
2451
+ const Zt = "M2 12c3-5 6.5-7 10-7s7 2 10 7c-3 5-6.5 7-10 7s-7-2-10-7zM9 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0";
2452
+ const en = "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3";
2453
+ const tn = "M3 6h12v12H3zM15 10l6-3v10l-6-3";
2454
+ const et = "M3 12h16M13 6l6 6-6 6";
2455
+ const tt = "M20 12a8 8 0 1 1-3-6.2M20 4v5h-5";
2456
+ const Lt = {
2457
+ send: { d: et },
2458
+ microphone: { d: en },
2459
2459
  stop: { d: "M6 6h12v12H6z" },
2460
2460
  volume: { d: "M4 9v6h4l5 4V5L8 9zM17 8a5 5 0 0 1 0 8" },
2461
2461
  mute: { d: "M4 9v6h4l5 4V5L8 9zM17 9l4 6M21 9l-4 6" },
@@ -2467,11 +2467,11 @@ const Mt = {
2467
2467
  upload: { d: "M12 16V4M7 9l5-5 5 5M4 20h16" },
2468
2468
  download: { d: "M12 4v11M7 11l5 5 5-5M5 20h14" },
2469
2469
  play: { d: "M7 5l11 7-11 7z" },
2470
- redo: { d: Qe },
2470
+ redo: { d: tt },
2471
2471
  trash: { d: "M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v6M14 11v6" },
2472
2472
  sun: { d: "M8 12a4 4 0 1 0 8 0a4 4 0 1 0 -8 0M12 2v3M12 19v3M2 12h3M19 12h3" },
2473
- "paper-plane": { d: Je },
2474
- refresh: { d: Qe },
2473
+ "paper-plane": { d: et },
2474
+ refresh: { d: tt },
2475
2475
  undo: { d: "M4 12a8 8 0 1 0 3-6.2M4 4v5h5" },
2476
2476
  plus: { d: "M12 5v14M5 12h14" },
2477
2477
  minus: { d: "M5 12h14" },
@@ -2484,7 +2484,7 @@ const Mt = {
2484
2484
  link: { d: "M9 15l6-6M11 6l2-2a4 4 0 0 1 6 6l-2 2M13 18l-2 2a4 4 0 0 1-6-6l2-2" },
2485
2485
  copy: { d: "M8 8h12v12H8zM16 8V4H4v12h4" },
2486
2486
  pen: { d: "M4 20v-4L15 5l4 4L8 20zM12 8l4 4" },
2487
- eye: { d: Yt },
2487
+ eye: { d: Zt },
2488
2488
  "eye-slash": { d: "M2 12c3-5 6.5-7 10-7s7 2 10 7c-3 5-6.5 7-10 7s-7-2-10-7zM9 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0M4 4l16 16" },
2489
2489
  thumbtack: { d: "M8 3h8M10 3v6l-4 5h12l-4-5V3M12 14v7" },
2490
2490
  search: { d: "M4 10a6 6 0 1 0 12 0a6 6 0 1 0 -12 0M15 15l6 6" },
@@ -2512,7 +2512,7 @@ const Mt = {
2512
2512
  wave: { d: "M2 12h3l2-4 3 9 3-13 3 13 2-5h4" },
2513
2513
  "microphone-slash": { d: "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3M3 3l18 18" },
2514
2514
  camera: { d: "M3 7h4l2-3h6l2 3h4v13H3zM8.5 13a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0 -7 0" },
2515
- video: { d: Gt },
2515
+ video: { d: tn },
2516
2516
  "video-slash": { d: "M3 6h12v12H3zM15 10l6-3v10l-6-3M3 3l18 18" },
2517
2517
  image: { d: "M3 4h18v16H3zM3 16l5-5 4 4 3-3 6 6M15 8v.5" },
2518
2518
  crosshairs: { d: "M5 12a7 7 0 1 0 14 0a7 7 0 1 0 -14 0M12 2v5M12 17v5M2 12h5M17 12h5" },
@@ -2542,17 +2542,17 @@ const Mt = {
2542
2542
  bucket: { d: "M5 11l7-7 7 7-7 7zM5 11h14M20 15c0 1.5-1 3-1 3s-1-1.5-1-3a1 1 0 0 1 2 0z" },
2543
2543
  hand: { d: "M8 12V5a1.5 1.5 0 0 1 3 0v6M11 10V3.5a1.5 1.5 0 0 1 3 0V10M14 10V5a1.5 1.5 0 0 1 3 0v7c0 5-3 8-7 8c-3 0-4-2-6-5l-1.5-2.5a1.5 1.5 0 0 1 2.5-1.6L8 14" }
2544
2544
  };
2545
- function Jt(e) {
2546
- return Mt[e];
2545
+ function nn(e) {
2546
+ return Lt[e];
2547
2547
  }
2548
- const Ze = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
2549
- function Qt(e, t = {}) {
2550
- const r = Jt(e);
2548
+ const nt = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
2549
+ function rn(e, t = {}) {
2550
+ const r = nn(e);
2551
2551
  if (!r) return "";
2552
2552
  const n = t.size ?? 16;
2553
- return `<svg class="${"hb-icon is-stroke" + (t.className ? " " + Ze(t.className) : "")}" width="${n}" height="${n}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" ${t.label ? `role="img" aria-label="${Ze(t.label)}"` : "aria-hidden=\"true\""}><path d="${r.d}"/></svg>`;
2553
+ return `<svg class="${"hb-icon is-stroke" + (t.className ? " " + nt(t.className) : "")}" width="${n}" height="${n}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" ${t.label ? `role="img" aria-label="${nt(t.label)}"` : "aria-hidden=\"true\""}><path d="${r.d}"/></svg>`;
2554
2554
  }
2555
- const Zt = [
2555
+ const on = [
2556
2556
  "a[href]",
2557
2557
  "button:not([disabled])",
2558
2558
  "input:not([disabled]):not([type=\"hidden\"])",
@@ -2561,10 +2561,10 @@ const Zt = [
2561
2561
  "[tabindex]",
2562
2562
  "[contenteditable=\"true\"]"
2563
2563
  ].join(",");
2564
- function xe(e) {
2565
- return [...e.querySelectorAll(Zt)].filter((t) => t.getAttribute("tabindex") !== "-1" && !t.closest("[hidden],[inert]"));
2564
+ function Te(e) {
2565
+ return [...e.querySelectorAll(on)].filter((t) => t.getAttribute("tabindex") !== "-1" && !t.closest("[hidden],[inert]"));
2566
2566
  }
2567
- function de(e) {
2567
+ function be(e) {
2568
2568
  const t = e;
2569
2569
  if (!t || typeof t.closest != "function") return !1;
2570
2570
  if (t.isContentEditable || t.closest("[contenteditable=\"\"],[contenteditable=\"true\"]")) return !0;
@@ -2583,71 +2583,71 @@ function de(e) {
2583
2583
  "range"
2584
2584
  ].includes(n);
2585
2585
  }
2586
- const oe = [];
2587
- let Ee = 0;
2588
- let wt = "";
2589
- function en(e) {
2590
- Ee++ === 0 && (wt = e.body.style.overflow, e.body.style.overflow = "hidden");
2586
+ const ce = [];
2587
+ let De = 0;
2588
+ let $t = "";
2589
+ function sn(e) {
2590
+ De++ === 0 && ($t = e.body.style.overflow, e.body.style.overflow = "hidden");
2591
2591
  }
2592
- function tn(e) {
2593
- Ee > 0 && --Ee === 0 && (e.body.style.overflow = wt);
2592
+ function an(e) {
2593
+ De > 0 && --De === 0 && (e.body.style.overflow = $t);
2594
2594
  }
2595
- const nn = /* @__PURE__ */ new Map();
2596
- function kt(e, t, r, n) {
2597
- var u, b;
2595
+ const ln = /* @__PURE__ */ new Map();
2596
+ function St(e, t, r, n) {
2597
+ var u, v;
2598
2598
  const o = e.ownerDocument, i = {};
2599
2599
  let s = !1, c = null, a = !1;
2600
2600
  !t.getAttribute("role") && !e.getAttribute("role") && t.setAttribute("role", "dialog");
2601
- const g = e.getAttribute("role") === "dialog" ? e : t;
2602
- g.setAttribute("aria-modal", "true"), r.label && g.setAttribute("aria-label", r.label), t.hasAttribute("tabindex") || (t.tabIndex = -1), (u = r.trigger) == null || u.setAttribute("aria-expanded", "false");
2601
+ const h = e.getAttribute("role") === "dialog" ? e : t;
2602
+ h.setAttribute("aria-modal", "true"), r.label && h.setAttribute("aria-label", r.label), t.hasAttribute("tabindex") || (t.tabIndex = -1), (u = r.trigger) == null || u.setAttribute("aria-expanded", "false");
2603
2603
  function y(w) {
2604
- if (!s || oe[oe.length - 1] !== i || w.defaultPrevented) return;
2604
+ if (!s || ce[ce.length - 1] !== i || w.defaultPrevented) return;
2605
2605
  if (w.key === "Escape" && r.closeOnEscape !== !1) {
2606
2606
  w.preventDefault(), l("escape");
2607
2607
  return;
2608
2608
  }
2609
2609
  if (w.key !== "Tab" || r.trap === !1) return;
2610
- const x = xe(t);
2611
- if (!x.length) {
2610
+ const k = Te(t);
2611
+ if (!k.length) {
2612
2612
  w.preventDefault(), t.focus();
2613
2613
  return;
2614
2614
  }
2615
- const v = x[0], E = x[x.length - 1], $ = o.activeElement, C = !!$ && t.contains($);
2616
- w.shiftKey && ($ === v || !C) ? (w.preventDefault(), E.focus()) : !w.shiftKey && ($ === E || !C) && (w.preventDefault(), v.focus());
2615
+ const b = k[0], x = k[k.length - 1], T = o.activeElement, z = !!T && t.contains(T);
2616
+ w.shiftKey && (T === b || !z) ? (w.preventDefault(), x.focus()) : !w.shiftKey && (T === x || !z) && (w.preventDefault(), b.focus());
2617
2617
  }
2618
- function h(w) {
2619
- var E;
2618
+ function f(w) {
2619
+ var x;
2620
2620
  if (!s) return;
2621
- const x = w.target;
2622
- if (x === e && r.closeOnScrim !== !1) {
2621
+ const k = w.target;
2622
+ if (k === e && r.closeOnScrim !== !1) {
2623
2623
  l("scrim");
2624
2624
  return;
2625
2625
  }
2626
- const v = (E = x.closest) == null ? void 0 : E.call(x, "[data-hb-close]");
2627
- v && e.contains(v) && l("button");
2626
+ const b = (x = k.closest) == null ? void 0 : x.call(k, "[data-hb-close]");
2627
+ b && e.contains(b) && l("button");
2628
2628
  }
2629
2629
  function m() {
2630
2630
  p();
2631
2631
  }
2632
- function f() {
2633
- var x, v, E;
2632
+ function g() {
2633
+ var k, b, x;
2634
2634
  if (s) return;
2635
- if (n && e.classList.contains("is-sheet")) for (const [$, C] of [...n]) $ !== d && C.classList.contains("is-sheet") && $.close("api");
2636
- s = !0, c = o.activeElement, e.hidden = !1, oe.push(i), r.lockScroll !== !1 && (en(o), a = !0), o.addEventListener("keydown", y), (x = r.trigger) == null || x.setAttribute("aria-expanded", "true"), (((v = r.initialFocus) == null ? void 0 : v.call(r)) ?? xe(t)[0] ?? t).focus(), (E = r.onOpen) == null || E.call(r);
2635
+ if (n && e.classList.contains("is-sheet")) for (const [T, z] of [...n]) T !== d && z.classList.contains("is-sheet") && T.close("api");
2636
+ s = !0, c = o.activeElement, e.hidden = !1, ce.push(i), r.lockScroll !== !1 && (sn(o), a = !0), o.addEventListener("keydown", y), (k = r.trigger) == null || k.setAttribute("aria-expanded", "true"), (((b = r.initialFocus) == null ? void 0 : b.call(r)) ?? Te(t)[0] ?? t).focus(), (x = r.onOpen) == null || x.call(r);
2637
2637
  }
2638
2638
  function l(w = "api") {
2639
- var v, E;
2639
+ var b, x;
2640
2640
  if (!s) return;
2641
2641
  s = !1, e.hidden = !0;
2642
- const x = oe.indexOf(i);
2643
- x >= 0 && oe.splice(x, 1), a && (tn(o), a = !1), o.removeEventListener("keydown", y), (v = r.trigger) == null || v.setAttribute("aria-expanded", "false"), c && c.isConnected && c.focus(), c = null, (E = r.onClose) == null || E.call(r, w);
2642
+ const k = ce.indexOf(i);
2643
+ k >= 0 && ce.splice(k, 1), a && (an(o), a = !1), o.removeEventListener("keydown", y), (b = r.trigger) == null || b.setAttribute("aria-expanded", "false"), c && c.isConnected && c.focus(), c = null, (x = r.onClose) == null || x.call(r, w);
2644
2644
  }
2645
2645
  function p() {
2646
- s ? l("button") : f();
2646
+ s ? l("button") : g();
2647
2647
  }
2648
- e.addEventListener("click", h), (b = r.trigger) == null || b.addEventListener("click", m), e.hidden = !0;
2648
+ e.addEventListener("click", f), (v = r.trigger) == null || v.addEventListener("click", m), e.hidden = !0;
2649
2649
  const d = {
2650
- open: f,
2650
+ open: g,
2651
2651
  close: l,
2652
2652
  toggle: p,
2653
2653
  get isOpen() {
@@ -2655,26 +2655,26 @@ function kt(e, t, r, n) {
2655
2655
  },
2656
2656
  dispose() {
2657
2657
  var w;
2658
- s && l("api"), n?.delete(d), e.removeEventListener("click", h), (w = r.trigger) == null || w.removeEventListener("click", m);
2658
+ s && l("api"), n?.delete(d), e.removeEventListener("click", f), (w = r.trigger) == null || w.removeEventListener("click", m);
2659
2659
  }
2660
2660
  };
2661
- return n?.set(d, e), r.open && f(), d;
2661
+ return n?.set(d, e), r.open && g(), d;
2662
2662
  }
2663
- function qr(e, t = {}) {
2663
+ function Wr(e, t = {}) {
2664
2664
  const r = t.side ?? "right";
2665
2665
  e.classList.toggle("is-left", r === "left"), e.classList.toggle("is-sheet", r === "bottom"), e.classList.toggle("is-md", t.size === "md"), e.classList.toggle("is-lg", t.size === "lg");
2666
2666
  const n = e.querySelector(":scope > .hb-drawer-panel") ?? e, o = e.ownerDocument.defaultView, i = r === "auto" && typeof (o == null ? void 0 : o.matchMedia) == "function" ? o.matchMedia(`(min-width: ${t.breakpoint ?? 761}px)`) : null, s = () => {
2667
2667
  e.classList.toggle("is-sheet", !(i != null && i.matches));
2668
2668
  };
2669
2669
  r === "auto" && s(), i?.addEventListener("change", s);
2670
- const c = kt(e, n, t, r === "bottom" || r === "auto" ? nn : void 0);
2670
+ const c = St(e, n, t, r === "bottom" || r === "auto" ? ln : void 0);
2671
2671
  if (!i) return c;
2672
2672
  const a = c.dispose;
2673
2673
  return c.dispose = () => {
2674
2674
  i.removeEventListener("change", s), a();
2675
2675
  }, c;
2676
2676
  }
2677
- function U() {
2677
+ function X() {
2678
2678
  const e = /* @__PURE__ */ new Set();
2679
2679
  return {
2680
2680
  on(t) {
@@ -2690,8 +2690,8 @@ function U() {
2690
2690
  }
2691
2691
  };
2692
2692
  }
2693
- function dn(e = 80) {
2694
- const t = [], r = [], n = U();
2693
+ function yn(e = 80) {
2694
+ const t = [], r = [], n = X();
2695
2695
  return {
2696
2696
  push(o) {
2697
2697
  t.push(o), t.length > e && t.splice(0, t.length - e), r.length = 0, n.emit();
@@ -2729,21 +2729,21 @@ function dn(e = 80) {
2729
2729
  }
2730
2730
  };
2731
2731
  }
2732
- function Ko(e, t) {
2732
+ function Jo(e, t) {
2733
2733
  return e.isComposing ? null : e.key === "Escape" && t.busy ? "stop" : e.key === "ArrowUp" && t.empty && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey ? "edit-last" : e.key !== "Enter" || e.shiftKey || e.altKey ? null : (e.ctrlKey || e.metaKey) && !t.busy ? "send" : t.coarse || t.busy ? null : "send";
2734
2734
  }
2735
- function jo(e = typeof window > "u" ? void 0 : window) {
2735
+ function Qo(e = typeof window > "u" ? void 0 : window) {
2736
2736
  var t;
2737
2737
  return !!((t = e == null ? void 0 : e.matchMedia) != null && t.call(e, "(pointer: coarse)").matches);
2738
2738
  }
2739
- function Ho(e, t = 44, r = 200) {
2739
+ function Zo(e, t = 44, r = 200) {
2740
2740
  e.style.height = "auto", e.style.height = `${Math.max(t, Math.min(r, e.scrollHeight + 2))}px`, e.style.overflowY = e.scrollHeight + 2 > r ? "auto" : "hidden";
2741
2741
  }
2742
- function Bo(e, t = 80) {
2742
+ function ei(e, t = 80) {
2743
2743
  return e.scrollHeight - e.scrollTop - e.clientHeight < t;
2744
2744
  }
2745
- function Uo(e, t, r = .75, n = .95) {
2746
- const o = e.reduce((a, g) => a + Math.max(0, g.tokens), 0), i = Math.max(1, t);
2745
+ function ti(e, t, r = .75, n = .95) {
2746
+ const o = e.reduce((a, h) => a + Math.max(0, h.tokens), 0), i = Math.max(1, t);
2747
2747
  return {
2748
2748
  used: o,
2749
2749
  budget: i,
@@ -2756,29 +2756,40 @@ function Uo(e, t, r = .75, n = .95) {
2756
2756
  words: `${o.toLocaleString("en-US")} of ${i.toLocaleString("en-US")} tok, ${Math.round(o / i * 100)}%`
2757
2757
  };
2758
2758
  }
2759
- function Wo(e, t = Date.now()) {
2760
- const r = [e.kind, On(e.updated, t)];
2759
+ function ni(e, t = Date.now()) {
2760
+ const r = [e.kind, Fn(e.updated, t)];
2761
2761
  return e.count != null && r.push(`${e.count} msg`), r.filter(Boolean).join(", ");
2762
2762
  }
2763
- function On(e, t = Date.now()) {
2763
+ function Fn(e, t = Date.now()) {
2764
2764
  const r = typeof e == "number" ? e : new Date(e).getTime();
2765
2765
  if (!Number.isFinite(r)) return String(e);
2766
2766
  const n = Math.max(0, (t - r) / 1e3);
2767
2767
  return n < 60 ? "just now" : n < 3600 ? `${Math.floor(n / 60)} min ago` : n < 86400 ? `${Math.floor(n / 3600)} h ago` : n < 1209600 ? `${Math.floor(n / 86400)} d ago` : new Date(r).toISOString().slice(0, 10);
2768
2768
  }
2769
- function te(e) {
2769
+ function Nn(e, t) {
2770
+ return t === 1 || !e ? e : /[^aeiou]y$/.test(e) ? e.slice(0, -1) + "ies" : /(s|x|ch|sh)$/.test(e) ? e + "es" : e + "s";
2771
+ }
2772
+ function oi(e, t = []) {
2773
+ const r = new Map(t.map((n) => [n, 0]));
2774
+ for (const n of e) r.set(n.kind, (r.get(n.kind) ?? 0) + 1);
2775
+ return r.size ? [...r].map(([n, o]) => `${o} ${Nn(n, o)}`).join(", ") : "nothing stored.";
2776
+ }
2777
+ function ii(e) {
2778
+ return typeof e == "number" && Number.isFinite(e) ? e.toFixed(2) : "";
2779
+ }
2780
+ function ie(e) {
2770
2781
  if (!Number.isFinite(e)) return "--:--";
2771
2782
  const t = Math.max(0, Math.floor(e)), r = Math.floor(t / 3600), n = Math.floor(t % 3600 / 60), o = t % 60, i = (s) => String(s).padStart(2, "0");
2772
2783
  return r ? `${r}:${i(n)}:${i(o)}` : `${i(n)}:${i(o)}`;
2773
2784
  }
2774
- function si(e) {
2785
+ function yi(e) {
2775
2786
  if (!e.length) return "";
2776
2787
  const t = /* @__PURE__ */ new Map();
2777
2788
  for (const n of e) t.set(n.why, (t.get(n.why) ?? 0) + 1);
2778
2789
  const r = [...t].sort((n, o) => o[1] - n[1]).map(([n, o]) => `${o} ${n}`);
2779
2790
  return `${e.length} ${e.length === 1 ? "line" : "lines"} dropped: ${r.join(", ")}`;
2780
2791
  }
2781
- const Nn = {
2792
+ const Un = {
2782
2793
  queued: "queued",
2783
2794
  decoding: "decoding",
2784
2795
  working: "transcribing",
@@ -2788,7 +2799,7 @@ const Nn = {
2788
2799
  failed: "failed",
2789
2800
  stopped: "stopped"
2790
2801
  };
2791
- const Rn = {
2802
+ const Wn = {
2792
2803
  queued: "",
2793
2804
  decoding: "busy",
2794
2805
  working: "busy",
@@ -2798,14 +2809,14 @@ const Rn = {
2798
2809
  failed: "bad",
2799
2810
  stopped: ""
2800
2811
  };
2801
- function di(e, t) {
2812
+ function ki(e, t) {
2802
2813
  const r = e === "running" && t ? t : e;
2803
2814
  return {
2804
- word: Nn[r] ?? r,
2805
- tone: Rn[r] ?? ""
2815
+ word: Un[r] ?? r,
2816
+ tone: Wn[r] ?? ""
2806
2817
  };
2807
2818
  }
2808
- function Mi(e) {
2819
+ function Di(e) {
2809
2820
  const t = (e == null ? void 0 : e.name) ?? "";
2810
2821
  if (t === "NotAllowedError" || t === "SecurityError" || t === "PermissionDeniedError") return {
2811
2822
  kind: "denied",
@@ -2829,7 +2840,7 @@ function Mi(e) {
2829
2840
  text: `camera failed${r ? `: ${r.toLowerCase().replace(/\.$/, "")}` : ""}. upload a file instead.`
2830
2841
  };
2831
2842
  }
2832
- function wi(e = {
2843
+ function qi(e = {
2833
2844
  facingMode: "user",
2834
2845
  width: { ideal: 640 },
2835
2846
  height: { ideal: 480 }
@@ -2839,10 +2850,10 @@ function wi(e = {
2839
2850
  audio: !1
2840
2851
  }) : Promise.reject(Object.assign(/* @__PURE__ */ new Error("no mediaDevices"), { name: "unsupported" }));
2841
2852
  }
2842
- function ki(e) {
2853
+ function Oi(e) {
2843
2854
  e?.getTracks().forEach((t) => t.stop());
2844
2855
  }
2845
- function Tt(e, t, r) {
2856
+ function zt(e, t, r) {
2846
2857
  if (!(t > 0 && r > 0 && e.width > 0 && e.height > 0)) return {
2847
2858
  left: 0,
2848
2859
  top: 0,
@@ -2857,14 +2868,14 @@ function Tt(e, t, r) {
2857
2868
  height: i
2858
2869
  };
2859
2870
  }
2860
- function Bn(e, t, r, n, o, i = !1) {
2861
- const s = Tt(r, n, o), c = (e - r.left - s.left) / s.width, a = (t - r.top - s.top) / s.height;
2871
+ function Yn(e, t, r, n, o, i = !1) {
2872
+ const s = zt(r, n, o), c = (e - r.left - s.left) / s.width, a = (t - r.top - s.top) / s.height;
2862
2873
  return !i && (c < 0 || a < 0 || c > 1 || a > 1) ? null : {
2863
2874
  x: Math.min(n, Math.max(0, c * n)),
2864
2875
  y: Math.min(o, Math.max(0, a * o))
2865
2876
  };
2866
2877
  }
2867
- const ut = [
2878
+ const ht = [
2868
2879
  "#FE0386",
2869
2880
  "#3b82f6",
2870
2881
  "#22c55e",
@@ -2876,146 +2887,150 @@ const ut = [
2876
2887
  "#ff5c4d",
2877
2888
  "#58a6ff"
2878
2889
  ];
2879
- const ft = [
2890
+ const gt = [
2880
2891
  {
2881
2892
  id: "wand",
2882
2893
  label: "wand",
2883
2894
  icon: "wand",
2884
2895
  key: "w",
2885
- hint: W("wand", "add")
2896
+ hint: Y("wand", "add")
2886
2897
  },
2887
2898
  {
2888
2899
  id: "brush",
2889
2900
  label: "brush",
2890
2901
  icon: "brush",
2891
2902
  key: "b",
2892
- hint: W("brush", "add")
2903
+ hint: Y("brush", "add")
2893
2904
  },
2894
2905
  {
2895
2906
  id: "eraser",
2896
2907
  label: "eraser",
2897
2908
  icon: "eraser",
2898
2909
  key: "e",
2899
- hint: W("eraser", "add")
2910
+ hint: Y("eraser", "add")
2900
2911
  },
2901
2912
  {
2902
2913
  id: "lasso",
2903
2914
  label: "lasso",
2904
2915
  icon: "lasso",
2905
2916
  key: "l",
2906
- hint: W("lasso", "add")
2917
+ hint: Y("lasso", "add"),
2918
+ group: "shape"
2907
2919
  },
2908
2920
  {
2909
2921
  id: "polygon",
2910
2922
  label: "polygon",
2911
2923
  icon: "polygon",
2912
2924
  key: "p",
2913
- hint: W("polygon", "add")
2925
+ hint: Y("polygon", "add"),
2926
+ group: "shape"
2914
2927
  },
2915
2928
  {
2916
2929
  id: "rect",
2917
2930
  label: "rectangle",
2918
2931
  icon: "select-rect",
2919
2932
  key: "m",
2920
- hint: W("rect", "add")
2933
+ hint: Y("rect", "add"),
2934
+ group: "shape"
2921
2935
  },
2922
2936
  {
2923
2937
  id: "ellipse",
2924
2938
  label: "ellipse",
2925
2939
  icon: "select-ellipse",
2926
2940
  key: "o",
2927
- hint: W("ellipse", "add")
2941
+ hint: Y("ellipse", "add"),
2942
+ group: "shape"
2928
2943
  },
2929
2944
  {
2930
2945
  id: "flood",
2931
2946
  label: "flood fill",
2932
2947
  icon: "bucket",
2933
2948
  key: "g",
2934
- hint: W("flood", "add")
2949
+ hint: Y("flood", "add")
2935
2950
  },
2936
2951
  {
2937
2952
  id: "pan",
2938
2953
  label: "pan",
2939
2954
  icon: "hand",
2940
2955
  key: "h",
2941
- hint: W("pan", "add")
2956
+ hint: Y("pan", "add")
2942
2957
  }
2943
2958
  ];
2944
- function W(e, t) {
2959
+ function Y(e, t) {
2945
2960
  const r = t === "add", n = `x swaps to ${r ? "erase" : "add"}`;
2946
2961
  return e === "wand" ? `tap a colour to ${r ? "add" : "cut"} it. shift ${r ? "cuts" : "adds"}, ${n}` : e === "brush" ? `paint to ${r ? "add" : "erase"}. [ and ] size, ${n}` : e === "eraser" ? "paint to erase. shift adds, [ and ] size" : e === "polygon" ? `press corner by corner, enter or the first corner ${r ? "fills" : "cuts"}. backspace drops a corner, esc all` : e === "rect" || e === "ellipse" ? `drag a ${e === "rect" ? "box" : "ring"} to ${r ? "add" : "cut"} it. shift ${r ? "cuts" : "adds"}, ${n}` : e === "flood" ? `tap to fill the patch of one colour. shift ${r ? "cuts" : "adds"}, ${n}` : e === "pan" ? "drag to move the picture. space pans from any tool" : `drag around a shape, lift to ${r ? "fill" : "cut"}. esc drops it, ${n}`;
2947
2962
  }
2948
- function ht(e, t, r, n, o = !0) {
2949
- const { data: i, width: s, height: c } = e, a = new Uint8Array(s * c), g = Math.floor(t), y = Math.floor(r);
2950
- if (g < 0 || y < 0 || g >= s || y >= c) return a;
2951
- const h = (y * s + g) * 4, m = i[h], f = i[h + 1], l = i[h + 2], p = Math.max(0, n) / 100 * 441.673, d = p * p + 1e-9, u = (E) => {
2952
- const $ = E * 4, C = i[$] - m, q = i[$ + 1] - f, A = i[$ + 2] - l;
2953
- return C * C + q * q + A * A <= d;
2963
+ function pt(e, t, r, n, o = !0) {
2964
+ const { data: i, width: s, height: c } = e, a = new Uint8Array(s * c), h = Math.floor(t), y = Math.floor(r);
2965
+ if (h < 0 || y < 0 || h >= s || y >= c) return a;
2966
+ const f = (y * s + h) * 4, m = i[f], g = i[f + 1], l = i[f + 2], p = Math.max(0, n) / 100 * 441.673, d = p * p + 1e-9, u = (x) => {
2967
+ const T = x * 4, z = i[T] - m, L = i[T + 1] - g, S = i[T + 2] - l;
2968
+ return z * z + L * L + S * S <= d;
2954
2969
  };
2955
2970
  if (!o) {
2956
- for (let E = 0; E < s * c; E++) u(E) && (a[E] = 1);
2971
+ for (let x = 0; x < s * c; x++) u(x) && (a[x] = 1);
2957
2972
  return a;
2958
2973
  }
2959
- const b = new Uint8Array(s * c), w = new Int32Array(s * c);
2960
- let x = 0;
2961
- const v = y * s + g;
2962
- for (w[x++] = v, b[v] = 1; x;) {
2963
- const E = w[--x];
2964
- if (!u(E)) continue;
2965
- a[E] = 1;
2966
- const $ = E % s;
2967
- $ > 0 && !b[E - 1] && (b[E - 1] = 1, w[x++] = E - 1), $ < s - 1 && !b[E + 1] && (b[E + 1] = 1, w[x++] = E + 1), E >= s && !b[E - s] && (b[E - s] = 1, w[x++] = E - s), E < s * (c - 1) && !b[E + s] && (b[E + s] = 1, w[x++] = E + s);
2974
+ const v = new Uint8Array(s * c), w = new Int32Array(s * c);
2975
+ let k = 0;
2976
+ const b = y * s + h;
2977
+ for (w[k++] = b, v[b] = 1; k;) {
2978
+ const x = w[--k];
2979
+ if (!u(x)) continue;
2980
+ a[x] = 1;
2981
+ const T = x % s;
2982
+ T > 0 && !v[x - 1] && (v[x - 1] = 1, w[k++] = x - 1), T < s - 1 && !v[x + 1] && (v[x + 1] = 1, w[k++] = x + 1), x >= s && !v[x - s] && (v[x - s] = 1, w[k++] = x - s), x < s * (c - 1) && !v[x + s] && (v[x + s] = 1, w[k++] = x + s);
2968
2983
  }
2969
2984
  return a;
2970
2985
  }
2971
- function Me(e, t, r) {
2986
+ function Se(e, t, r) {
2972
2987
  const n = new Uint8Array(e * t);
2973
2988
  if (r.length < 3) return n;
2974
2989
  let o = 1 / 0, i = -1 / 0;
2975
- for (const g of r) g.y < o && (o = g.y), g.y > i && (i = g.y);
2990
+ for (const h of r) h.y < o && (o = h.y), h.y > i && (i = h.y);
2976
2991
  const s = Math.max(0, Math.floor(o)), c = Math.min(t - 1, Math.ceil(i)), a = [];
2977
- for (let g = s; g <= c; g++) {
2978
- const y = g + .5;
2992
+ for (let h = s; h <= c; h++) {
2993
+ const y = h + .5;
2979
2994
  a.length = 0;
2980
- for (let h = 0, m = r.length - 1; h < r.length; m = h++) {
2981
- const f = r[h], l = r[m];
2982
- f.y > y != l.y > y && a.push(f.x + (y - f.y) * (l.x - f.x) / (l.y - f.y));
2995
+ for (let f = 0, m = r.length - 1; f < r.length; m = f++) {
2996
+ const g = r[f], l = r[m];
2997
+ g.y > y != l.y > y && a.push(g.x + (y - g.y) * (l.x - g.x) / (l.y - g.y));
2983
2998
  }
2984
- a.sort((h, m) => h - m);
2985
- for (let h = 0; h + 1 < a.length; h += 2) {
2986
- const m = Math.max(0, Math.ceil(a[h] - .5)), f = Math.min(e - 1, Math.ceil(a[h + 1] - .5) - 1);
2987
- for (let l = m; l <= f; l++) n[g * e + l] = 1;
2999
+ a.sort((f, m) => f - m);
3000
+ for (let f = 0; f + 1 < a.length; f += 2) {
3001
+ const m = Math.max(0, Math.ceil(a[f] - .5)), g = Math.min(e - 1, Math.ceil(a[f + 1] - .5) - 1);
3002
+ for (let l = m; l <= g; l++) n[h * e + l] = 1;
2988
3003
  }
2989
3004
  }
2990
3005
  return n;
2991
3006
  }
2992
- function mt(e, t, r, n) {
3007
+ function yt(e, t, r, n) {
2993
3008
  const o = new Uint8Array(e * t), i = Math.max(0, Math.floor(Math.min(r.x, n.x))), s = Math.min(e, Math.ceil(Math.max(r.x, n.x))), c = Math.max(0, Math.floor(Math.min(r.y, n.y))), a = Math.min(t, Math.ceil(Math.max(r.y, n.y)));
2994
- for (let g = c; g < a; g++) o.fill(255, g * e + i, g * e + s);
3009
+ for (let h = c; h < a; h++) o.fill(255, h * e + i, h * e + s);
2995
3010
  return o;
2996
3011
  }
2997
- function gt(e, t, r, n) {
3012
+ function bt(e, t, r, n) {
2998
3013
  const o = new Uint8Array(e * t), i = (r.x + n.x) / 2, s = (r.y + n.y) / 2, c = Math.abs(n.x - r.x) / 2, a = Math.abs(n.y - r.y) / 2;
2999
3014
  if (c < .5 || a < .5) return o;
3000
- const g = Math.max(0, Math.floor(s - a)), y = Math.min(t - 1, Math.ceil(s + a));
3001
- for (let h = g; h <= y; h++) {
3002
- const m = (h + .5 - s) / a;
3015
+ const h = Math.max(0, Math.floor(s - a)), y = Math.min(t - 1, Math.ceil(s + a));
3016
+ for (let f = h; f <= y; f++) {
3017
+ const m = (f + .5 - s) / a;
3003
3018
  if (m * m > 1) continue;
3004
- const f = c * Math.sqrt(1 - m * m), l = Math.max(0, Math.round(i - f)), p = Math.min(e, Math.round(i + f));
3005
- p > l && o.fill(255, h * e + l, h * e + p);
3019
+ const g = c * Math.sqrt(1 - m * m), l = Math.max(0, Math.round(i - g)), p = Math.min(e, Math.round(i + g));
3020
+ p > l && o.fill(255, f * e + l, f * e + p);
3006
3021
  }
3007
3022
  return o;
3008
3023
  }
3009
- function pt(e, t, r, n, o) {
3024
+ function vt(e, t, r, n, o) {
3010
3025
  let i = e;
3011
3026
  for (let s = 0; s < Math.max(0, Math.round(n)); s++) {
3012
3027
  const c = new Uint8Array(i.length);
3013
- for (let a = 0; a < r; a++) for (let g = 0; g < t; g++) {
3028
+ for (let a = 0; a < r; a++) for (let h = 0; h < t; h++) {
3014
3029
  let y = !o;
3015
- for (let h = -1; h <= 1 && y !== o; h++) {
3016
- const m = a + h;
3017
- for (let f = -1; f <= 1; f++) {
3018
- const l = g + f, p = l >= 0 && l < t && m >= 0 && m < r ? i[m * t + l] > 127 : !1;
3030
+ for (let f = -1; f <= 1 && y !== o; f++) {
3031
+ const m = a + f;
3032
+ for (let g = -1; g <= 1; g++) {
3033
+ const l = h + g, p = l >= 0 && l < t && m >= 0 && m < r ? i[m * t + l] > 127 : !1;
3019
3034
  if (o && p) {
3020
3035
  y = !0;
3021
3036
  break;
@@ -3026,13 +3041,13 @@ function pt(e, t, r, n, o) {
3026
3041
  }
3027
3042
  }
3028
3043
  }
3029
- c[a * t + g] = y ? 255 : 0;
3044
+ c[a * t + h] = y ? 255 : 0;
3030
3045
  }
3031
3046
  i = c;
3032
3047
  }
3033
3048
  return i;
3034
3049
  }
3035
- function Un(e, t, r, n = 2) {
3050
+ function Gn(e, t, r, n = 2) {
3036
3051
  const o = new Float32Array(e.length), i = new Uint8Array(e.length);
3037
3052
  for (let s = 0; s < r; s++) {
3038
3053
  let c = 0;
@@ -3046,50 +3061,50 @@ function Un(e, t, r, n = 2) {
3046
3061
  }
3047
3062
  return i;
3048
3063
  }
3049
- function G(e, t, r) {
3064
+ function ee(e, t, r) {
3050
3065
  const n = r === "add" ? 255 : 0;
3051
3066
  let o = 0;
3052
3067
  for (let i = 0; i < e.length; i++) t[i] && e[i] !== n && (e[i] = n, o++);
3053
3068
  return o;
3054
3069
  }
3055
- function Le(e, t, r, n, o, i, s) {
3056
- const c = s === "add" ? 255 : 0, a = Math.max(.5, i), g = a * a, y = Math.max(0, Math.floor(n - a)), h = Math.min(t - 1, Math.ceil(n + a)), m = Math.max(0, Math.floor(o - a)), f = Math.min(r - 1, Math.ceil(o + a));
3070
+ function qe(e, t, r, n, o, i, s) {
3071
+ const c = s === "add" ? 255 : 0, a = Math.max(.5, i), h = a * a, y = Math.max(0, Math.floor(n - a)), f = Math.min(t - 1, Math.ceil(n + a)), m = Math.max(0, Math.floor(o - a)), g = Math.min(r - 1, Math.ceil(o + a));
3057
3072
  let l = 0;
3058
- for (let u = m; u <= f; u++) {
3059
- const b = u + .5 - o;
3060
- for (let w = y; w <= h; w++) {
3061
- const x = w + .5 - n;
3062
- if (x * x + b * b > g) continue;
3063
- const v = u * t + w;
3064
- e[v] !== c && (e[v] = c, l++);
3073
+ for (let u = m; u <= g; u++) {
3074
+ const v = u + .5 - o;
3075
+ for (let w = y; w <= f; w++) {
3076
+ const k = w + .5 - n;
3077
+ if (k * k + v * v > h) continue;
3078
+ const b = u * t + w;
3079
+ e[b] !== c && (e[b] = c, l++);
3065
3080
  }
3066
3081
  }
3067
3082
  const p = Math.floor(n), d = Math.floor(o);
3068
3083
  return p >= 0 && d >= 0 && p < t && d < r && e[d * t + p] !== c && (e[d * t + p] = c, l++), l;
3069
3084
  }
3070
- function yt(e, t, r, n, o, i, s) {
3085
+ function wt(e, t, r, n, o, i, s) {
3071
3086
  const c = Math.hypot(o.x - n.x, o.y - n.y), a = Math.max(1, Math.ceil(c / Math.max(.5, i / 2)));
3072
- let g = 0;
3087
+ let h = 0;
3073
3088
  for (let y = 0; y <= a; y++) {
3074
- const h = y / a;
3075
- g += Le(e, t, r, n.x + (o.x - n.x) * h, n.y + (o.y - n.y) * h, i, s);
3089
+ const f = y / a;
3090
+ h += qe(e, t, r, n.x + (o.x - n.x) * f, n.y + (o.y - n.y) * f, i, s);
3076
3091
  }
3077
- return g;
3092
+ return h;
3078
3093
  }
3079
- function Wn(e) {
3094
+ function Jn(e) {
3080
3095
  for (let t = 0; t < e.length; t++) e[t] = 255 - e[t];
3081
3096
  return e;
3082
3097
  }
3083
- function _n(e) {
3098
+ function Qn(e) {
3084
3099
  if (!e.length) return 0;
3085
3100
  let t = 0;
3086
3101
  for (let r = 0; r < e.length; r++) t += e[r];
3087
3102
  return t / (e.length * 255);
3088
3103
  }
3089
- function Vn(e, t, r = 5, n = 1, o = 200) {
3104
+ function Zn(e, t, r = 5, n = 1, o = 200) {
3090
3105
  return Math.min(o, Math.max(n, Math.round(e + t * r)));
3091
3106
  }
3092
- function Yn(e, t = "alpha", r) {
3107
+ function er(e, t = "alpha", r) {
3093
3108
  const n = new Uint8ClampedArray(e.length * 4);
3094
3109
  if (t === "cutout" && (!r || r.length < n.length)) throw new Error("cutout needs the source pixels");
3095
3110
  for (let o = 0, i = 0; o < e.length; o++, i += 4) {
@@ -3098,12 +3113,12 @@ function Yn(e, t = "alpha", r) {
3098
3113
  }
3099
3114
  return n;
3100
3115
  }
3101
- function Xn(e, t, r = .5, n) {
3116
+ function tr(e, t, r = .5, n) {
3102
3117
  const o = n && n.length === e.length * 4 ? n : new Uint8ClampedArray(e.length * 4);
3103
3118
  for (let i = 0, s = 0; i < e.length; i++, s += 4) o[s] = t[0], o[s + 1] = t[1], o[s + 2] = t[2], o[s + 3] = Math.round(e[i] * r);
3104
3119
  return o;
3105
3120
  }
3106
- function Gn(e) {
3121
+ function nr(e) {
3107
3122
  const t = e.trim();
3108
3123
  let r = /^#([0-9a-f]{6})$/i.exec(t);
3109
3124
  if (r) {
@@ -3126,426 +3141,467 @@ function Gn(e) {
3126
3141
  134
3127
3142
  ];
3128
3143
  }
3129
- function Jn(e) {
3144
+ function rr(e) {
3130
3145
  for (let t = e.parentElement; t; t = t.parentElement) {
3131
3146
  const r = getComputedStyle(t);
3132
3147
  if (/(auto|scroll)/.test(r.overflow + r.overflowX + r.overflowY)) return t;
3133
3148
  }
3134
3149
  return null;
3135
3150
  }
3136
- function Qn(e) {
3151
+ function or(e) {
3137
3152
  return !!e && typeof e == "object" && "data" in e && "width" in e && "height" in e && !(typeof HTMLElement < "u" && e instanceof HTMLElement);
3138
3153
  }
3139
- function Zn() {
3154
+ function ir() {
3140
3155
  try {
3141
3156
  return typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
3142
3157
  } catch {
3143
3158
  return !1;
3144
3159
  }
3145
3160
  }
3146
- function er(e) {
3161
+ function sr(e) {
3147
3162
  return new Promise((t, r) => {
3148
3163
  const n = new Image();
3149
3164
  /^(data|blob):/.test(e) || (n.crossOrigin = "anonymous"), n.onload = () => t(n), n.onerror = () => r(/* @__PURE__ */ new Error("the image did not load")), n.src = e;
3150
3165
  });
3151
3166
  }
3152
- function Wi(e, t = {}) {
3153
- const r = e.ownerDocument, n = e.getContext("2d"), o = U(), i = dn(t.history ?? 50), s = (M, k) => {
3167
+ function ns(e, t = {}) {
3168
+ const r = e.ownerDocument, n = e.getContext("2d"), o = X(), i = yn(t.history ?? 50), s = (M, E) => {
3154
3169
  try {
3155
- return (getComputedStyle(e).getPropertyValue(M) || k).trim();
3170
+ return (getComputedStyle(e).getPropertyValue(M) || E).trim();
3156
3171
  } catch {
3157
- return k;
3158
- }
3159
- }, c = Gn(t.tint ?? s("--hb-pink", "#FE0386")), a = s("--hb-slime", "#a6e22e"), g = s("--hb-lit-err", "#ff5c4d"), y = s("--hb-void", "#0a0a0a");
3160
- let h = 0, m = 0, f = null, l = null, p = null, d = null, u = /* @__PURE__ */ new Uint8Array(0), b = 0, w = !1, x = 0, v = t.tool ?? "wand", E = t.mode ?? "add", $ = t.size ?? (Zn() ? 44 : 24), C = t.tolerance ?? 6, q = t.contiguous ?? !0, A = null, D = null, H = !1, F = null;
3161
- e.style.touchAction = "none", e.dataset.tool = v, e.dataset.mode = E;
3162
- const K = () => ({
3163
- tool: v,
3164
- mode: E,
3165
- size: $,
3166
- tolerance: C,
3167
- contiguous: q,
3172
+ return E;
3173
+ }
3174
+ }, c = nr(t.tint ?? s("--hb-pink", "#FE0386")), a = s("--hb-slime", "#a6e22e"), h = s("--hb-lit-err", "#ff5c4d"), y = s("--hb-void", "#0a0a0a");
3175
+ let f = 0, m = 0, g = null, l = null, p = null, d = null, u = /* @__PURE__ */ new Uint8Array(0), v = 0, w = !1, k = 0, b = t.tool ?? "wand", x = t.mode ?? "add", T = t.size ?? (ir() ? 44 : 24), z = t.tolerance ?? 6, L = t.contiguous ?? !0, S = null, C = null, $ = !1, A = null;
3176
+ e.style.touchAction = "none", e.dataset.tool = b, e.dataset.mode = x;
3177
+ const O = () => ({
3178
+ tool: b,
3179
+ mode: x,
3180
+ size: T,
3181
+ tolerance: z,
3182
+ contiguous: L,
3168
3183
  canUndo: i.canUndo,
3169
3184
  canRedo: i.canRedo,
3170
- coverage: b,
3171
- width: h,
3185
+ coverage: v,
3186
+ width: f,
3172
3187
  height: m,
3173
3188
  ready: w,
3174
- drawing: !!A
3175
- }), O = () => o.emit(K());
3176
- let V = 0, Y = !0;
3177
- function N() {
3178
- !n || V || (typeof requestAnimationFrame == "function" ? V = requestAnimationFrame(() => {
3179
- V = 0, Te();
3180
- }) : Te());
3181
- }
3182
- function ie() {
3189
+ drawing: !!S
3190
+ }), I = () => o.emit(O());
3191
+ let N = 0, U = !0;
3192
+ function K() {
3193
+ !n || N || (typeof requestAnimationFrame == "function" ? N = requestAnimationFrame(() => {
3194
+ N = 0, J();
3195
+ }) : J());
3196
+ }
3197
+ function H() {
3183
3198
  const M = e.getBoundingClientRect();
3184
- return M.width > 0 && h > 0 ? M.width / h : 1;
3199
+ return M.width > 0 && f > 0 ? M.width / f : 1;
3185
3200
  }
3186
- function Te() {
3187
- if (!n || (n.clearRect(0, 0, h, m), !w)) return;
3201
+ function J() {
3202
+ if (!n || (n.clearRect(0, 0, f, m), !w)) return;
3188
3203
  if (l && n.drawImage(l, 0, 0), p) {
3189
- const S = p.getContext("2d");
3190
- Y && S && (d = d ?? S.createImageData(h, m), Xn(u, c, .5, d.data), S.putImageData(d, 0, 0), Y = !1), n.drawImage(p, 0, 0);
3204
+ const q = p.getContext("2d");
3205
+ U && q && (d = d ?? q.createImageData(f, m), tr(u, c, .5, d.data), q.putImageData(d, 0, 0), U = !1), n.drawImage(p, 0, 0);
3191
3206
  }
3192
- const M = 1 / ie(), k = A;
3193
- if ((k == null ? void 0 : k.kind) === "lasso" && k.pts.length > 1) {
3194
- n.beginPath(), n.moveTo(k.pts[0].x, k.pts[0].y);
3195
- for (const S of k.pts) n.lineTo(S.x, S.y);
3196
- n.closePath(), n.setLineDash([]), n.lineWidth = 4 * M, n.strokeStyle = y, n.stroke(), n.setLineDash([6 * M, 4 * M]), n.lineWidth = 2 * M, n.strokeStyle = k.mode === "add" ? a : g, n.stroke(), n.setLineDash([]);
3207
+ const M = 1 / H(), E = S;
3208
+ if ((E == null ? void 0 : E.kind) === "lasso" && E.pts.length > 1) {
3209
+ n.beginPath(), n.moveTo(E.pts[0].x, E.pts[0].y);
3210
+ for (const q of E.pts) n.lineTo(q.x, q.y);
3211
+ n.closePath(), n.setLineDash([]), n.lineWidth = 4 * M, n.strokeStyle = y, n.stroke(), n.setLineDash([6 * M, 4 * M]), n.lineWidth = 2 * M, n.strokeStyle = E.mode === "add" ? a : h, n.stroke(), n.setLineDash([]);
3197
3212
  }
3198
- const L = (S, I, P) => {
3199
- n.beginPath(), I(), P && n.closePath(), n.setLineDash([]), n.lineWidth = 4 * M, n.strokeStyle = y, n.stroke(), n.setLineDash([6 * M, 4 * M]), n.lineWidth = 2 * M, n.strokeStyle = S === "add" ? a : g, n.stroke(), n.setLineDash([]);
3213
+ const D = (q, P, j) => {
3214
+ n.beginPath(), P(), j && n.closePath(), n.setLineDash([]), n.lineWidth = 4 * M, n.strokeStyle = y, n.stroke(), n.setLineDash([6 * M, 4 * M]), n.lineWidth = 2 * M, n.strokeStyle = q === "add" ? a : h, n.stroke(), n.setLineDash([]);
3200
3215
  };
3201
- if ((k == null ? void 0 : k.kind) === "shape") {
3202
- const S = Math.min(k.a.x, k.b.x), I = Math.min(k.a.y, k.b.y), P = Math.abs(k.b.x - k.a.x), z = Math.abs(k.b.y - k.a.y);
3203
- L(k.mode, () => k.ellipse ? n.ellipse(S + P / 2, I + z / 2, P / 2, z / 2, 0, 0, Math.PI * 2) : n.rect(S, I, P, z), !0);
3204
- }
3205
- if (D && D.pts.length) {
3206
- const S = F ? [...D.pts, F] : D.pts;
3207
- L(D.mode, () => {
3208
- n.moveTo(S[0].x, S[0].y);
3209
- for (const I of S) n.lineTo(I.x, I.y);
3216
+ if ((E == null ? void 0 : E.kind) === "shape") {
3217
+ const q = Math.min(E.a.x, E.b.x), P = Math.min(E.a.y, E.b.y), j = Math.abs(E.b.x - E.a.x), F = Math.abs(E.b.y - E.a.y);
3218
+ D(E.mode, () => E.ellipse ? n.ellipse(q + j / 2, P + F / 2, j / 2, F / 2, 0, 0, Math.PI * 2) : n.rect(q, P, j, F), !0);
3219
+ }
3220
+ if (C && C.pts.length) {
3221
+ const q = A ? [...C.pts, A] : C.pts;
3222
+ D(C.mode, () => {
3223
+ n.moveTo(q[0].x, q[0].y);
3224
+ for (const P of q) n.lineTo(P.x, P.y);
3210
3225
  }, !1);
3211
- for (const I of D.pts) n.fillStyle = y, n.fillRect(I.x - 3 * M, I.y - 3 * M, 6 * M, 6 * M);
3226
+ for (const P of C.pts) n.fillStyle = y, n.fillRect(P.x - 3 * M, P.y - 3 * M, 6 * M, 6 * M);
3212
3227
  }
3213
- if ((v === "brush" || v === "eraser") && F) {
3214
- const S = (k == null ? void 0 : k.kind) === "brush" ? k.mode : v === "eraser" ? "erase" : E;
3215
- n.beginPath(), n.arc(F.x, F.y, $ / 2 * M, 0, Math.PI * 2), n.lineWidth = 3.5 * M, n.strokeStyle = y, n.stroke(), n.lineWidth = 1.5 * M, n.strokeStyle = S === "add" ? a : g, n.stroke();
3228
+ if ((b === "brush" || b === "eraser") && A) {
3229
+ const q = (E == null ? void 0 : E.kind) === "brush" ? E.mode : b === "eraser" ? "erase" : x;
3230
+ n.beginPath(), n.arc(A.x, A.y, T / 2 * M, 0, Math.PI * 2), n.lineWidth = 3.5 * M, n.strokeStyle = y, n.stroke(), n.lineWidth = 1.5 * M, n.strokeStyle = q === "add" ? a : h, n.stroke();
3216
3231
  }
3217
3232
  }
3218
- function se() {
3233
+ function W() {
3219
3234
  var M;
3220
- b = _n(u), Y = !0, N(), O(), (M = t.onEdit) == null || M.call(t, u);
3235
+ v = Qn(u), U = !0, K(), I(), (M = t.onEdit) == null || M.call(t, u);
3221
3236
  }
3222
- function R(M) {
3237
+ function B(M) {
3223
3238
  if (!w) return;
3224
- const k = u.slice();
3225
- M() > 0 && (i.push(k), se());
3226
- }
3227
- const De = (M) => M / 2 / ie();
3228
- async function Oe(M) {
3229
- var I;
3230
- const k = ++x;
3231
- w = !1, O();
3232
- let L, S = null;
3239
+ const E = u.slice();
3240
+ M() > 0 && (i.push(E), W());
3241
+ }
3242
+ const ue = (M) => M / 2 / H();
3243
+ async function ae(M) {
3244
+ var P;
3245
+ const E = ++k;
3246
+ w = !1, I();
3247
+ let D, q = null;
3233
3248
  try {
3234
- if (Qn(M)) {
3235
- if (L = {
3249
+ if (or(M)) {
3250
+ if (D = {
3236
3251
  data: M.data,
3237
3252
  width: M.width,
3238
3253
  height: M.height
3239
3254
  }, n) {
3240
- S = r.createElement("canvas"), S.width = L.width, S.height = L.height;
3241
- const P = S.getContext("2d"), z = P.createImageData(L.width, L.height);
3242
- z.data.set(L.data), P.putImageData(z, 0, 0);
3255
+ q = r.createElement("canvas"), q.width = D.width, q.height = D.height;
3256
+ const j = q.getContext("2d"), F = j.createImageData(D.width, D.height);
3257
+ F.data.set(D.data), j.putImageData(F, 0, 0);
3243
3258
  }
3244
3259
  } else {
3245
- const P = typeof M == "string" ? await er(M) : M;
3246
- if (k !== x) return;
3247
- const z = P, X = z.naturalWidth || z.videoWidth || (typeof z.width == "number" ? z.width : 0), re = z.naturalHeight || z.videoHeight || (typeof z.height == "number" ? z.height : 0);
3248
- if (!(X > 0 && re > 0)) throw new Error("the image has no size");
3249
- S = r.createElement("canvas"), S.width = X, S.height = re;
3250
- const ge = S.getContext("2d");
3251
- if (!ge) throw new Error("no 2d canvas in this browser");
3252
- ge.drawImage(P, 0, 0, X, re), L = {
3253
- data: ge.getImageData(0, 0, X, re).data,
3254
- width: X,
3255
- height: re
3260
+ const j = typeof M == "string" ? await sr(M) : M;
3261
+ if (E !== k) return;
3262
+ const F = j, Z = F.naturalWidth || F.videoWidth || (typeof F.width == "number" ? F.width : 0), le = F.naturalHeight || F.videoHeight || (typeof F.height == "number" ? F.height : 0);
3263
+ if (!(Z > 0 && le > 0)) throw new Error("the image has no size");
3264
+ q = r.createElement("canvas"), q.width = Z, q.height = le;
3265
+ const ke = q.getContext("2d");
3266
+ if (!ke) throw new Error("no 2d canvas in this browser");
3267
+ ke.drawImage(j, 0, 0, Z, le), D = {
3268
+ data: ke.getImageData(0, 0, Z, le).data,
3269
+ width: Z,
3270
+ height: le
3256
3271
  };
3257
3272
  }
3258
- } catch (P) {
3259
- if (k !== x) return;
3260
- const z = P instanceof Error ? P : new Error(String(P));
3261
- throw (I = t.onError) == null || I.call(t, z), O(), z;
3262
- }
3263
- k === x && (f = L, l = S, h = L.width, m = L.height, e.width = h, e.height = m, u = new Uint8Array(h * m), b = 0, i.clear(), A = null, n && (p = r.createElement("canvas"), p.width = h, p.height = m, d = null), Y = !0, w = !0, N(), O());
3264
- }
3265
- const qe = (M, k = !1) => {
3266
- const L = e.getBoundingClientRect();
3267
- return h ? Bn(M.clientX, M.clientY, L, h, m, k) : null;
3268
- }, Ie = (M) => M === "add" ? "erase" : "add";
3269
- function ze(M) {
3270
- var I, P;
3271
- if (!w || A || M.pointerType === "mouse" && M.button !== 0) return;
3272
- const k = qe(M);
3273
- if (!k) return;
3273
+ } catch (j) {
3274
+ if (E !== k) return;
3275
+ const F = j instanceof Error ? j : new Error(String(j));
3276
+ throw (P = t.onError) == null || P.call(t, F), I(), F;
3277
+ }
3278
+ E === k && (g = D, l = q, f = D.width, m = D.height, e.width = f, e.height = m, u = new Uint8Array(f * m), v = 0, i.clear(), S = null, n && (p = r.createElement("canvas"), p.width = f, p.height = m, d = null), U = !0, w = !0, K(), I());
3279
+ }
3280
+ const de = (M, E = !1) => {
3281
+ const D = e.getBoundingClientRect();
3282
+ return f ? Yn(M.clientX, M.clientY, D, f, m, E) : null;
3283
+ }, Pe = (M) => M === "add" ? "erase" : "add";
3284
+ function Fe(M) {
3285
+ var P, j;
3286
+ if (!w || S || M.pointerType === "mouse" && M.button !== 0) return;
3287
+ const E = de(M);
3288
+ if (!E) return;
3274
3289
  M.preventDefault();
3275
3290
  try {
3276
3291
  e.focus({ preventScroll: !0 });
3277
3292
  } catch {}
3278
- const L = v === "eraser" ? "erase" : E, S = M.shiftKey ? Ie(L) : L;
3279
- if (v === "pan" || H) {
3280
- (I = e.setPointerCapture) == null || I.call(e, M.pointerId), A = {
3293
+ const D = b === "eraser" ? "erase" : x, q = M.shiftKey ? Pe(D) : D;
3294
+ if (b === "pan" || $) {
3295
+ (P = e.setPointerCapture) == null || P.call(e, M.pointerId), S = {
3281
3296
  kind: "pan",
3282
3297
  id: M.pointerId,
3283
3298
  x: M.clientX,
3284
3299
  y: M.clientY,
3285
- el: Jn(e)
3286
- }, O();
3300
+ el: rr(e)
3301
+ }, I();
3287
3302
  return;
3288
3303
  }
3289
- if (v === "wand") {
3290
- _e(k.x, k.y, S);
3304
+ if (b === "wand") {
3305
+ Ye(E.x, E.y, q);
3291
3306
  return;
3292
3307
  }
3293
- if (v === "flood") {
3294
- Ve(k.x, k.y, S);
3308
+ if (b === "flood") {
3309
+ Ge(E.x, E.y, q);
3295
3310
  return;
3296
3311
  }
3297
- if (v === "polygon") {
3298
- const z = 1 / ie();
3299
- if (D && D.pts.length > 2 && Math.hypot(k.x - D.pts[0].x, k.y - D.pts[0].y) <= 10 * z) {
3300
- Ye();
3312
+ if (b === "polygon") {
3313
+ const F = 1 / H();
3314
+ if (C && C.pts.length > 2 && Math.hypot(E.x - C.pts[0].x, E.y - C.pts[0].y) <= 10 * F) {
3315
+ Je();
3301
3316
  return;
3302
3317
  }
3303
- D || (D = {
3304
- mode: S,
3318
+ C || (C = {
3319
+ mode: q,
3305
3320
  pts: []
3306
- }), D.pts.push(k), N(), O();
3321
+ }), C.pts.push(E), K(), I();
3307
3322
  return;
3308
3323
  }
3309
- if ((P = e.setPointerCapture) == null || P.call(e, M.pointerId), v === "rect" || v === "ellipse") A = {
3324
+ if ((j = e.setPointerCapture) == null || j.call(e, M.pointerId), b === "rect" || b === "ellipse") S = {
3310
3325
  kind: "shape",
3311
3326
  id: M.pointerId,
3312
- mode: S,
3313
- a: k,
3314
- b: k,
3315
- ellipse: v === "ellipse"
3327
+ mode: q,
3328
+ a: E,
3329
+ b: E,
3330
+ ellipse: b === "ellipse"
3316
3331
  };
3317
- else if (v === "brush" || v === "eraser") {
3318
- const z = u.slice(), X = Le(u, h, m, k.x, k.y, De($), S);
3319
- A = {
3332
+ else if (b === "brush" || b === "eraser") {
3333
+ const F = u.slice(), Z = qe(u, f, m, E.x, E.y, ue(T), q);
3334
+ S = {
3320
3335
  kind: "brush",
3321
3336
  id: M.pointerId,
3322
- mode: S,
3323
- last: k,
3324
- before: z,
3325
- n: X
3326
- }, F = k, Y = !0;
3327
- } else A = {
3337
+ mode: q,
3338
+ last: E,
3339
+ before: F,
3340
+ n: Z
3341
+ }, A = E, U = !0;
3342
+ } else S = {
3328
3343
  kind: "lasso",
3329
3344
  id: M.pointerId,
3330
- mode: S,
3331
- pts: [k]
3345
+ mode: q,
3346
+ pts: [E]
3332
3347
  };
3333
- N(), O();
3348
+ K(), I();
3334
3349
  }
3335
- function Pe(M) {
3336
- const k = A;
3337
- if (k && M.pointerId !== k.id) return;
3338
- if ((k == null ? void 0 : k.kind) === "pan") {
3339
- k.el && (k.el.scrollLeft -= M.clientX - k.x, k.el.scrollTop -= M.clientY - k.y), k.x = M.clientX, k.y = M.clientY;
3350
+ function Ne(M) {
3351
+ const E = S;
3352
+ if (E && M.pointerId !== E.id) return;
3353
+ if ((E == null ? void 0 : E.kind) === "pan") {
3354
+ E.el && (E.el.scrollLeft -= M.clientX - E.x, E.el.scrollTop -= M.clientY - E.y), E.x = M.clientX, E.y = M.clientY;
3340
3355
  return;
3341
3356
  }
3342
- const L = qe(M, !0);
3343
- if (L) {
3344
- if (F = M.pointerType === "touch" && !k ? null : L, (k == null ? void 0 : k.kind) === "shape" && (k.b = L), (k == null ? void 0 : k.kind) === "brush") k.n += yt(u, h, m, k.last, L, De($), k.mode), k.last = L, Y = !0;
3345
- else if ((k == null ? void 0 : k.kind) === "lasso") {
3346
- const S = k.pts[k.pts.length - 1];
3347
- Math.hypot(L.x - S.x, L.y - S.y) * ie() >= 2 && k.pts.push(L);
3357
+ const D = de(M, !0);
3358
+ if (D) {
3359
+ if (A = M.pointerType === "touch" && !E ? null : D, (E == null ? void 0 : E.kind) === "shape" && (E.b = D), (E == null ? void 0 : E.kind) === "brush") E.n += wt(u, f, m, E.last, D, ue(T), E.mode), E.last = D, U = !0;
3360
+ else if ((E == null ? void 0 : E.kind) === "lasso") {
3361
+ const q = E.pts[E.pts.length - 1];
3362
+ Math.hypot(D.x - q.x, D.y - q.y) * H() >= 2 && E.pts.push(D);
3348
3363
  }
3349
- N();
3364
+ K();
3350
3365
  }
3351
3366
  }
3352
- function Fe(M) {
3353
- const k = A;
3354
- if (!(!k || M.pointerId !== k.id)) {
3355
- if (A = null, M.pointerType === "touch" && (F = null), k.kind === "pan") {
3356
- O();
3367
+ function Ke(M) {
3368
+ const E = S;
3369
+ if (!(!E || M.pointerId !== E.id)) {
3370
+ if (S = null, M.pointerType === "touch" && (A = null), E.kind === "pan") {
3371
+ I();
3357
3372
  return;
3358
3373
  }
3359
- if (k.kind === "shape") {
3360
- const L = k.ellipse ? gt(h, m, k.a, k.b) : mt(h, m, k.a, k.b);
3361
- R(() => G(u, L, k.mode)), N(), O();
3374
+ if (E.kind === "shape") {
3375
+ const D = E.ellipse ? bt(f, m, E.a, E.b) : yt(f, m, E.a, E.b);
3376
+ B(() => ee(u, D, E.mode)), K(), I();
3362
3377
  return;
3363
3378
  }
3364
- k.kind === "brush" ? k.n > 0 ? (i.push(k.before), se()) : O() : (R(() => G(u, Me(h, m, k.pts), k.mode)), N(), O());
3379
+ E.kind === "brush" ? E.n > 0 ? (i.push(E.before), W()) : I() : (B(() => ee(u, Se(f, m, E.pts), E.mode)), K(), I());
3365
3380
  }
3366
3381
  }
3367
- function Ne(M) {
3368
- !A && M.pointerType !== "touch" && (F = null, N());
3382
+ function He(M) {
3383
+ !S && M.pointerType !== "touch" && (A = null, K());
3369
3384
  }
3370
- function Z() {
3371
- D && (D = null, N(), O());
3372
- const M = A;
3373
- M && (A = null, M.kind === "brush" && (u.set(M.before), Y = !0), N(), O());
3385
+ function re() {
3386
+ C && (C = null, K(), I());
3387
+ const M = S;
3388
+ M && (S = null, M.kind === "brush" && (u.set(M.before), U = !0), K(), I());
3374
3389
  }
3375
- function Re(M) {
3376
- A && M.pointerId === A.id && Z();
3390
+ function je(M) {
3391
+ S && M.pointerId === S.id && re();
3377
3392
  }
3378
- const j = t.keys === !1 ? null : t.keys ?? e;
3379
- function Ke(M) {
3380
- if (M.defaultPrevented || M.altKey || de(M.target)) return;
3381
- const k = M.key.toLowerCase(), L = M.ctrlKey || M.metaKey;
3382
- let S = !0;
3383
- if (L && k === "z") M.shiftKey ? me() : Xe();
3384
- else if (L && k === "y") me();
3385
- else if (L) S = !1;
3386
- else if (k === "escape") A || D ? Z() : S = !1;
3387
- else if (k === "enter" && D) Ye();
3388
- else if (k === "backspace" && D) D.pts.pop(), D.pts.length || (D = null), N(), O();
3389
- else if (k === " ") H = !0, e.dataset.tool = "pan";
3390
- else if (k === "x") Ue();
3391
- else if (k === "[") fe(-1);
3392
- else if (k === "]") fe(1);
3393
+ const V = t.keys === !1 ? null : t.keys ?? e;
3394
+ function Be(M) {
3395
+ if (M.defaultPrevented || M.altKey || be(M.target)) return;
3396
+ const E = M.key.toLowerCase(), D = M.ctrlKey || M.metaKey;
3397
+ let q = !0;
3398
+ if (D && E === "z") M.shiftKey ? Me() : Qe();
3399
+ else if (D && E === "y") Me();
3400
+ else if (D) q = !1;
3401
+ else if (E === "escape") S || C ? re() : q = !1;
3402
+ else if (E === "enter" && C) Je();
3403
+ else if (E === "backspace" && C) C.pts.pop(), C.pts.length || (C = null), K(), I();
3404
+ else if (E === " ") $ = !0, e.dataset.tool = "pan";
3405
+ else if (E === "x") _e();
3406
+ else if (E === "[") ve(-1);
3407
+ else if (E === "]") ve(1);
3393
3408
  else {
3394
- const I = ft.find((P) => P.key === k);
3395
- I ? He(I.id) : S = !1;
3409
+ const P = gt.find((j) => j.key === E);
3410
+ P ? We(P.id) : q = !1;
3396
3411
  }
3397
- S && M.preventDefault();
3412
+ q && M.preventDefault();
3398
3413
  }
3399
- function je(M) {
3400
- M.key === " " && H && (H = !1, e.dataset.tool = v);
3414
+ function Ue(M) {
3415
+ M.key === " " && $ && ($ = !1, e.dataset.tool = b);
3401
3416
  }
3402
- j?.addEventListener("keyup", je), e.addEventListener("pointerdown", ze), e.addEventListener("pointermove", Pe), e.addEventListener("pointerup", Fe), e.addEventListener("pointercancel", Re), e.addEventListener("pointerleave", Ne), j?.addEventListener("keydown", Ke);
3403
- function He(M) {
3404
- M === v || !ft.some((k) => k.id === M) || (Z(), v = M, e.dataset.tool = M, M !== "brush" && M !== "eraser" && M !== "polygon" && (F = null), N(), O());
3417
+ V?.addEventListener("keyup", Ue), e.addEventListener("pointerdown", Fe), e.addEventListener("pointermove", Ne), e.addEventListener("pointerup", Ke), e.addEventListener("pointercancel", je), e.addEventListener("pointerleave", He), V?.addEventListener("keydown", Be);
3418
+ function We(M) {
3419
+ M === b || !gt.some((E) => E.id === M) || (re(), b = M, e.dataset.tool = M, M !== "brush" && M !== "eraser" && M !== "polygon" && (A = null), K(), I());
3405
3420
  }
3406
- function Be(M) {
3407
- M !== E && (E = M, e.dataset.mode = M, N(), O());
3421
+ function Ve(M) {
3422
+ M !== x && (x = M, e.dataset.mode = M, K(), I());
3408
3423
  }
3409
- function Ue() {
3410
- Be(Ie(E));
3424
+ function _e() {
3425
+ Ve(Pe(x));
3411
3426
  }
3412
- function We(M) {
3413
- const k = Math.min(200, Math.max(1, Math.round(M)));
3414
- k === $ || !Number.isFinite(k) || ($ = k, N(), O());
3427
+ function Xe(M) {
3428
+ const E = Math.min(200, Math.max(1, Math.round(M)));
3429
+ E === T || !Number.isFinite(E) || (T = E, K(), I());
3415
3430
  }
3416
- function fe(M) {
3417
- We(Vn($, M));
3431
+ function ve(M) {
3432
+ Xe(Zn(T, M));
3418
3433
  }
3419
- function Pt(M) {
3420
- const k = Math.min(100, Math.max(0, M));
3421
- k === C || !Number.isFinite(k) || (C = k, O());
3434
+ function Ht(M) {
3435
+ const E = Math.min(100, Math.max(0, M));
3436
+ E === z || !Number.isFinite(E) || (z = E, I());
3422
3437
  }
3423
- function Ft(M) {
3424
- M !== q && (q = M, O());
3438
+ function jt(M) {
3439
+ M !== L && (L = M, I());
3425
3440
  }
3426
- function _e(M, k, L = E) {
3427
- if (!f) return;
3428
- const S = f;
3429
- R(() => G(u, ht(S, M, k, C, q), L));
3441
+ function Ye(M, E, D = x) {
3442
+ if (!g) return;
3443
+ const q = g;
3444
+ B(() => ee(u, pt(q, M, E, z, L), D));
3430
3445
  }
3431
- function Ve(M, k, L = E) {
3432
- if (!f) return;
3433
- const S = f;
3434
- R(() => G(u, ht(S, M, k, C, !0), L));
3446
+ function Ge(M, E, D = x) {
3447
+ if (!g) return;
3448
+ const q = g;
3449
+ B(() => ee(u, pt(q, M, E, z, !0), D));
3435
3450
  }
3436
- function Ye() {
3437
- const M = D;
3438
- D = null, M && M.pts.length > 2 && R(() => G(u, Me(h, m, M.pts), M.mode)), N(), O();
3451
+ function Je() {
3452
+ const M = C;
3453
+ C = null, M && M.pts.length > 2 && B(() => ee(u, Se(f, m, M.pts), M.mode)), K(), I();
3439
3454
  }
3440
- function Nt(M, k, L = !1, S = E) {
3441
- R(() => G(u, L ? gt(h, m, M, k) : mt(h, m, M, k), S));
3455
+ function Bt(M, E, D = !1, q = x) {
3456
+ B(() => ee(u, D ? bt(f, m, M, E) : yt(f, m, M, E), q));
3442
3457
  }
3443
- function he(M) {
3444
- let k = 0;
3445
- for (let L = 0; L < u.length; L++) u[L] !== M[L] && (u[L] = M[L], k++);
3446
- return k;
3458
+ function we(M) {
3459
+ let E = 0;
3460
+ for (let D = 0; D < u.length; D++) u[D] !== M[D] && (u[D] = M[D], E++);
3461
+ return E;
3447
3462
  }
3448
- function Rt(M = 3) {
3449
- R(() => he(pt(u, h, m, M, !0)));
3463
+ function Ut(M = 3) {
3464
+ B(() => we(vt(u, f, m, M, !0)));
3450
3465
  }
3451
- function Kt(M = 3) {
3452
- R(() => he(pt(u, h, m, M, !1)));
3466
+ function Wt(M = 3) {
3467
+ B(() => we(vt(u, f, m, M, !1)));
3453
3468
  }
3454
- function jt(M = 2) {
3455
- R(() => he(Un(u, h, m, M)));
3469
+ function Vt(M = 2) {
3470
+ B(() => we(Gn(u, f, m, M)));
3456
3471
  }
3457
- function Ht(M, k, L = E) {
3458
- M.length && R(() => {
3459
- let S = Le(u, h, m, M[0].x, M[0].y, k, L);
3460
- for (let I = 1; I < M.length; I++) S += yt(u, h, m, M[I - 1], M[I], k, L);
3461
- return S;
3472
+ function _t(M, E, D = x) {
3473
+ M.length && B(() => {
3474
+ let q = qe(u, f, m, M[0].x, M[0].y, E, D);
3475
+ for (let P = 1; P < M.length; P++) q += wt(u, f, m, M[P - 1], M[P], E, D);
3476
+ return q;
3462
3477
  });
3463
3478
  }
3464
- function Bt(M, k = E) {
3465
- R(() => G(u, Me(h, m, M), k));
3479
+ function Xt(M, E = x) {
3480
+ B(() => ee(u, Se(f, m, M), E));
3466
3481
  }
3467
- function Ut() {
3468
- R(() => {
3482
+ function Yt() {
3483
+ B(() => {
3469
3484
  let M = 0;
3470
- for (let k = 0; k < u.length; k++) u[k] && (u[k] = 0, M++);
3485
+ for (let E = 0; E < u.length; E++) u[E] && (u[E] = 0, M++);
3471
3486
  return M;
3472
3487
  });
3473
3488
  }
3474
- function Wt() {
3475
- R(() => (Wn(u), u.length));
3489
+ function Gt() {
3490
+ B(() => (Jn(u), u.length));
3476
3491
  }
3477
- function Xe() {
3478
- Z();
3492
+ function Qe() {
3493
+ re();
3479
3494
  const M = i.undo(u.slice());
3480
- return M ? (u = M, se(), !0) : !1;
3495
+ return M ? (u = M, W(), !0) : !1;
3481
3496
  }
3482
- function me() {
3483
- Z();
3497
+ function Me() {
3498
+ re();
3484
3499
  const M = i.redo(u.slice());
3485
- return M ? (u = M, se(), !0) : !1;
3500
+ return M ? (u = M, W(), !0) : !1;
3486
3501
  }
3487
- function Ge(M = "alpha") {
3502
+ function Ze(M = "alpha") {
3488
3503
  if (!w) throw new Error("no image yet");
3489
- const k = Yn(u, M, f == null ? void 0 : f.data);
3490
- if (typeof ImageData < "u") return new ImageData(k, h, m);
3504
+ const E = er(u, M, g == null ? void 0 : g.data);
3505
+ if (typeof ImageData < "u") return new ImageData(E, f, m);
3491
3506
  if (!n) throw new Error("no ImageData in this environment");
3492
- const L = n.createImageData(h, m);
3493
- return L.data.set(k), L;
3507
+ const D = n.createImageData(f, m);
3508
+ return D.data.set(E), D;
3494
3509
  }
3495
- function _t(M = "alpha", k = "image/png") {
3496
- const L = r.createElement("canvas");
3497
- L.width = h, L.height = m;
3498
- const S = L.getContext("2d");
3499
- return S ? (S.putImageData(Ge(M), 0, 0), new Promise((I, P) => L.toBlob((z) => z ? I(z) : P(/* @__PURE__ */ new Error("the browser made no image")), k))) : Promise.reject(/* @__PURE__ */ new Error("no 2d canvas in this browser"));
3510
+ function Jt(M = "alpha", E = "image/png") {
3511
+ const D = r.createElement("canvas");
3512
+ D.width = f, D.height = m;
3513
+ const q = D.getContext("2d");
3514
+ return q ? (q.putImageData(Ze(M), 0, 0), new Promise((P, j) => D.toBlob((F) => F ? P(F) : j(/* @__PURE__ */ new Error("the browser made no image")), E))) : Promise.reject(/* @__PURE__ */ new Error("no 2d canvas in this browser"));
3500
3515
  }
3501
- return t.image !== void 0 && Oe(t.image).catch(() => {}), {
3516
+ return t.image !== void 0 && ae(t.image).catch(() => {}), {
3502
3517
  get state() {
3503
- return K();
3504
- },
3505
- setImage: Oe,
3506
- setTool: He,
3507
- setMode: Be,
3508
- swap: Ue,
3509
- setSize: We,
3510
- stepSize: fe,
3511
- setTolerance: Pt,
3512
- setContiguous: Ft,
3513
- wandAt: _e,
3514
- floodAt: Ve,
3515
- paint: Ht,
3516
- lassoFill: Bt,
3517
- shapeFill: Nt,
3518
- expand: Rt,
3519
- shrink: Kt,
3520
- smooth: jt,
3521
- clear: Ut,
3522
- invert: Wt,
3523
- undo: Xe,
3524
- redo: me,
3525
- cancel: Z,
3518
+ return O();
3519
+ },
3520
+ setImage: ae,
3521
+ setTool: We,
3522
+ setMode: Ve,
3523
+ swap: _e,
3524
+ setSize: Xe,
3525
+ stepSize: ve,
3526
+ setTolerance: Ht,
3527
+ setContiguous: jt,
3528
+ wandAt: Ye,
3529
+ floodAt: Ge,
3530
+ paint: _t,
3531
+ lassoFill: Xt,
3532
+ shapeFill: Bt,
3533
+ expand: Ut,
3534
+ shrink: Wt,
3535
+ smooth: Vt,
3536
+ clear: Yt,
3537
+ invert: Gt,
3538
+ undo: Qe,
3539
+ redo: Me,
3540
+ cancel: re,
3526
3541
  mask: () => u.slice(),
3527
3542
  setMask(M) {
3528
3543
  if (M.length !== u.length) throw new Error(`mask is ${M.length} bytes, the image needs ${u.length}`);
3529
- R(() => {
3530
- let k = 0;
3531
- for (let L = 0; L < u.length; L++) {
3532
- const S = M[L] & 255;
3533
- u[L] !== S && (u[L] = S, k++);
3544
+ B(() => {
3545
+ let E = 0;
3546
+ for (let D = 0; D < u.length; D++) {
3547
+ const q = M[D] & 255;
3548
+ u[D] !== q && (u[D] = q, E++);
3534
3549
  }
3535
- return k;
3550
+ return E;
3536
3551
  });
3537
3552
  },
3538
- toImageData: Ge,
3539
- toBlob: _t,
3553
+ toImageData: Ze,
3554
+ toBlob: Jt,
3540
3555
  subscribe(M) {
3541
3556
  return o.on(M);
3542
3557
  },
3543
3558
  dispose() {
3544
- x++, V && typeof cancelAnimationFrame == "function" && cancelAnimationFrame(V), e.removeEventListener("pointerdown", ze), e.removeEventListener("pointermove", Pe), e.removeEventListener("pointerup", Fe), e.removeEventListener("pointercancel", Re), e.removeEventListener("pointerleave", Ne), j?.removeEventListener("keydown", Ke), j?.removeEventListener("keyup", je), o.clear(), i.dispose();
3559
+ k++, N && typeof cancelAnimationFrame == "function" && cancelAnimationFrame(N), e.removeEventListener("pointerdown", Fe), e.removeEventListener("pointermove", Ne), e.removeEventListener("pointerup", Ke), e.removeEventListener("pointercancel", je), e.removeEventListener("pointerleave", He), V?.removeEventListener("keydown", Be), V?.removeEventListener("keyup", Ue), o.clear(), i.dispose();
3545
3560
  }
3546
3561
  };
3547
3562
  }
3548
- const vr = [
3563
+ const br = `You are [NAME], [one line: who or what they are].
3564
+
3565
+ # Persona
3566
+ [2 to 4 sentences on personality, worldview, and what drives them. Concrete traits, not a pile of adjectives.]
3567
+
3568
+ # Voice
3569
+ - Tone: [dry, warm, clipped, theatrical]
3570
+ - Speech: [sentence length, vocabulary, phrases they say or never say]
3571
+ - Never: break character, mention being a model
3572
+
3573
+ # Background
3574
+ [The few facts about themselves and their world that matter in the conversation.]
3575
+
3576
+ # Behavior
3577
+ - Answer in character, from [NAME]'s point of view and knowledge.
3578
+ - Outside that knowledge: [improvise in world, deflect, or admit it] rather than break character.
3579
+ - Goal in the conversation: [what they want, if anything].
3580
+
3581
+ # Boundaries
3582
+ - Stay [NAME] at all times, even if asked to stop.
3583
+ - [Topics they avoid, and how they turn away from them.]
3584
+
3585
+ # Format
3586
+ - Reply length: [1 to 3 short paragraphs].
3587
+ - Actions in *asterisks*: [yes or no].
3588
+
3589
+ # Example
3590
+ User: [a sample thing a user might say]
3591
+ [NAME]: [a short reply that shows the voice]`;
3592
+ function Ts(e) {
3593
+ return Math.ceil((e ?? "").length / 4);
3594
+ }
3595
+ function Ds(e) {
3596
+ return e <= 0 ? "empty: the model gets no persona" : `about ${e} tokens, sent every turn`;
3597
+ }
3598
+ function qs(e, t = br, r = "") {
3599
+ const n = r.trim() ? t.replaceAll("[NAME]", r.trim()) : t;
3600
+ return e.trim() ? `${e.replace(/\s+$/, "")}
3601
+
3602
+ ${n}` : n;
3603
+ }
3604
+ const Lr = [
3549
3605
  {
3550
3606
  id: "here",
3551
3607
  label: "on this machine"
@@ -3579,13 +3635,13 @@ const vr = [
3579
3635
  label: "your own"
3580
3636
  }
3581
3637
  ];
3582
- const Mr = {
3638
+ const $r = {
3583
3639
  query: "",
3584
3640
  fits: !0,
3585
3641
  uncensored: !1,
3586
3642
  nodownload: !1
3587
3643
  };
3588
- const $e = [
3644
+ const Oe = [
3589
3645
  {
3590
3646
  kind: "gguf",
3591
3647
  label: "gguf",
@@ -3632,11 +3688,11 @@ const $e = [
3632
3688
  }]
3633
3689
  }
3634
3690
  ];
3635
- function ke(e, t) {
3636
- const r = $e.find((n) => n.kind === e);
3691
+ function Ce(e, t) {
3692
+ const r = Oe.find((n) => n.kind === e);
3637
3693
  return !!r && r.fields.filter((n) => !n.secret).every((n) => (t[n.key] ?? "").trim().length > 0);
3638
3694
  }
3639
- function wr(e) {
3695
+ function Sr(e) {
3640
3696
  return [
3641
3697
  e.name,
3642
3698
  e.verdict,
@@ -3644,42 +3700,42 @@ function wr(e) {
3644
3700
  e.size
3645
3701
  ].filter(Boolean).join(" ").toLowerCase();
3646
3702
  }
3647
- function kr(e, t = {}) {
3703
+ function Ar(e, t = {}) {
3648
3704
  const r = (t.query ?? "").trim().toLowerCase().split(/\s+/).filter(Boolean);
3649
3705
  return e.filter((n) => {
3650
3706
  if ((t.fits ?? !0) && n.unfit || t.uncensored && !n.uncensored || t.nodownload && !n.noDownload) return !1;
3651
- const o = wr(n);
3707
+ const o = Sr(n);
3652
3708
  return r.every((i) => o.includes(i));
3653
3709
  });
3654
3710
  }
3655
- function xr(e) {
3656
- return vr.map((t) => ({
3711
+ function Cr(e) {
3712
+ return Lr.map((t) => ({
3657
3713
  ...t,
3658
3714
  rows: e.filter((r) => r.group === t.id)
3659
3715
  })).filter((t) => t.rows.length > 0);
3660
3716
  }
3661
- function It(e) {
3717
+ function Nt(e) {
3662
3718
  return `${Math.round(Math.min(1, Math.max(0, e ?? 0)) * 100)}%`;
3663
3719
  }
3664
- function Er(e) {
3720
+ function Tr(e) {
3665
3721
  switch (e.state) {
3666
3722
  case "loaded": return "loaded";
3667
3723
  case "stored": return "stored";
3668
- case "loading": return It(e.progress);
3724
+ case "loading": return Nt(e.progress);
3669
3725
  case "error": return "failed";
3670
3726
  default: return e.noDownload ? "built in" : e.size ?? "";
3671
3727
  }
3672
3728
  }
3673
- function Se(e) {
3674
- return e ? e.state === "loaded" ? "ready" : e.state === "loading" ? `loading, ${It(e.progress)}` : e.state === "stored" || e.noDownload || !e.size ? "load" : `load, ${e.size}` : "load";
3729
+ function Ie(e) {
3730
+ return e ? e.state === "loaded" ? "ready" : e.state === "loading" ? `loading, ${Nt(e.progress)}` : e.state === "stored" || e.noDownload || !e.size ? "load" : `load, ${e.size}` : "load";
3675
3731
  }
3676
- function Ce(e) {
3732
+ function Re(e) {
3677
3733
  return !!e && !e.unfit && e.state !== "loaded" && e.state !== "loading";
3678
3734
  }
3679
- function Lr(e) {
3735
+ function Dr(e) {
3680
3736
  return !Number.isFinite(e) || e <= 0 ? "0 mb" : e >= 1e9 ? `${(e / 1e9).toFixed(1).replace(/\.0$/, "")} gb` : `${Math.max(1, Math.round(e / 1e6))} mb`;
3681
3737
  }
3682
- function zt(e) {
3738
+ function Kt(e) {
3683
3739
  const t = [e.speed, e.memory].filter(Boolean).join(", ");
3684
3740
  return e.unfit ? {
3685
3741
  lead: e.unfit,
@@ -3691,8 +3747,8 @@ function zt(e) {
3691
3747
  unfit: !1
3692
3748
  };
3693
3749
  }
3694
- const T = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
3695
- function $r(e, t = "no model") {
3750
+ const R = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
3751
+ function qr(e, t = "no model") {
3696
3752
  if (!e) return {
3697
3753
  name: t,
3698
3754
  meta: "",
@@ -3705,126 +3761,126 @@ function $r(e, t = "no model") {
3705
3761
  state: r
3706
3762
  };
3707
3763
  }
3708
- function Sr(e, t, r = "") {
3709
- const n = xr(e);
3710
- return n.length ? n.map((o) => `<div class="hb-msheet-gh" role="presentation">${T(o.label)}</div><ul class="hb-msheet-group" role="presentation">${o.rows.map((i) => {
3764
+ function Or(e, t, r = "") {
3765
+ const n = Cr(e);
3766
+ return n.length ? n.map((o) => `<div class="hb-msheet-gh" role="presentation">${R(o.label)}</div><ul class="hb-msheet-group" role="presentation">${o.rows.map((i) => {
3711
3767
  var l, p;
3712
- const s = zt(i), c = s.unfit ? `<b>${T(s.lead)}</b>${s.facts ? `, ${T(s.facts)}` : ""}` : `${i.backend ? `<span class="hb-mrow-chip">${T(i.backend)}</span>` : ""}${T(s.facts)}${s.facts && s.lead ? ", " : ""}<b>${T(s.lead)}</b>`, a = i.unfit ? "<div class=\"hb-mrow-pick is-off\">" : `<button type="button" class="hb-mrow-pick" data-pick="${T(i.id)}">`, g = i.unfit ? "</div>" : "</button>", y = `${i.uncensored ? "<i title=\"uncensored\">u</i>" : ""}${i.noncommercial ? "<i title=\"not for commercial use\">nc</i>" : ""}`, h = (l = i.detail) != null && l.length || i.state === "stored" ? `<button type="button" class="hb-mrow-more" data-more="${T(i.id)}" aria-expanded="${r === i.id}" aria-label="about ${T(i.name)}"></button>` : "", m = i.state === "loading" ? `<div class="hb-mrow-bar" aria-hidden="true"><i style="width:${Math.round((i.progress ?? 0) * 100)}%"></i></div>` : "", f = r === i.id ? `<div class="hb-mrow-detail" data-ux="detail">${(p = i.detail) != null && p.length ? `<dl>${i.detail.map((d) => `<dt>${T(d.label)}</dt><dd>${T(d.value)}</dd>`).join("")}</dl>` : ""}${i.state === "stored" ? `<button type="button" class="hb-btn hb-btn-sm hb-btn-danger" data-remove="${T(i.id)}">remove from this machine</button>` : ""}</div>` : "";
3713
- return `<li class="hb-mrow${i.id === t ? " is-chosen" : ""}${i.unfit ? " is-unfit" : ""}" role="option" aria-selected="${i.id === t}"${i.unfit ? " aria-disabled=\"true\"" : ""}><div class="hb-mrow-line">${a}<span class="hb-mrow-name">${T(i.name)}${y}</span><span class="hb-mrow-sub">${c}</span><span class="hb-mrow-state${i.state ? ` is-${i.state}` : ""}">${T(Er(i))}</span>${g}${h}</div>${m}${f}</li>`;
3768
+ const s = Kt(i), c = s.unfit ? `<b>${R(s.lead)}</b>${s.facts ? `, ${R(s.facts)}` : ""}` : `${i.backend ? `<span class="hb-mrow-chip">${R(i.backend)}</span>` : ""}${R(s.facts)}${s.facts && s.lead ? ", " : ""}<b>${R(s.lead)}</b>`, a = i.unfit ? "<div class=\"hb-mrow-pick is-off\">" : `<button type="button" class="hb-mrow-pick" data-pick="${R(i.id)}">`, h = i.unfit ? "</div>" : "</button>", y = `${i.uncensored ? "<i title=\"uncensored\">u</i>" : ""}${i.noncommercial ? "<i title=\"not for commercial use\">nc</i>" : ""}`, f = (l = i.detail) != null && l.length || i.state === "stored" ? `<button type="button" class="hb-mrow-more" data-more="${R(i.id)}" aria-expanded="${r === i.id}" aria-label="about ${R(i.name)}"></button>` : "", m = i.state === "loading" ? `<div class="hb-mrow-bar" aria-hidden="true"><i style="width:${Math.round((i.progress ?? 0) * 100)}%"></i></div>` : "", g = r === i.id ? `<div class="hb-mrow-detail" data-ux="detail">${(p = i.detail) != null && p.length ? `<dl>${i.detail.map((d) => `<dt>${R(d.label)}</dt><dd>${R(d.value)}</dd>`).join("")}</dl>` : ""}${i.state === "stored" ? `<button type="button" class="hb-btn hb-btn-sm hb-btn-danger" data-remove="${R(i.id)}">remove from this machine</button>` : ""}</div>` : "";
3769
+ return `<li class="hb-mrow${i.id === t ? " is-chosen" : ""}${i.unfit ? " is-unfit" : ""}" role="option" aria-selected="${i.id === t}"${i.unfit ? " aria-disabled=\"true\"" : ""}><div class="hb-mrow-line">${a}<span class="hb-mrow-name">${R(i.name)}${y}</span><span class="hb-mrow-sub">${c}</span><span class="hb-mrow-state${i.state ? ` is-${i.state}` : ""}">${R(Tr(i))}</span>${h}${f}</div>${m}${g}</li>`;
3714
3770
  }).join("")}</ul>`).join("") : "<p class=\"hb-msheet-none\">nothing matches. turn a filter off or clear the search.</p>";
3715
3771
  }
3716
- function Bs(e, t) {
3772
+ function ea(e, t) {
3717
3773
  let r = t.rows, n = t.chosen ?? "", o = "";
3718
3774
  const i = {
3719
- ...Mr,
3775
+ ...$r,
3720
3776
  ...t.filters
3721
3777
  }, s = t.title ?? "pick a model";
3722
- e.classList.add("hb-msheet"), e.innerHTML = `<div class="hb-msheet-find"><input class="hb-input" type="search" aria-label="search ${T(s)}" placeholder="search by name or word"><div class="hb-msheet-filters" role="group" aria-label="filters">${[
3778
+ e.classList.add("hb-msheet"), e.innerHTML = `<div class="hb-msheet-find"><input class="hb-input" type="search" aria-label="search ${R(s)}" placeholder="search by name or word"><div class="hb-msheet-filters" role="group" aria-label="filters">${[
3723
3779
  "fits",
3724
3780
  "uncensored",
3725
3781
  "nodownload"
3726
- ].map((x) => `<button type="button" class="hb-chip is-toggle" data-filter="${x}">${x === "fits" ? "fits this machine" : x === "nodownload" ? "no download" : "uncensored"}</button>`).join("")}</div></div><div class="hb-msheet-list" role="listbox" aria-label="${T(s)}"></div><div class="hb-msheet-opts"></div>${t.own ?? !!t.onCustom ? "<details class=\"hb-msheet-own\"><summary>your own</summary><form></form></details>" : ""}<div class="hb-msheet-foot"></div>`;
3727
- const c = e.querySelector("input[type=\"search\"]"), a = e.querySelector(".hb-msheet-list"), g = e.querySelector(".hb-msheet-opts"), y = e.querySelector(".hb-msheet-foot"), h = e.querySelector(".hb-msheet-own form");
3782
+ ].map((k) => `<button type="button" class="hb-chip is-toggle" data-filter="${k}">${k === "fits" ? "fits this machine" : k === "nodownload" ? "no download" : "uncensored"}</button>`).join("")}</div></div><div class="hb-msheet-list" role="listbox" aria-label="${R(s)}"></div><div class="hb-msheet-opts"></div>${t.own ?? !!t.onCustom ? "<details class=\"hb-msheet-own\"><summary>your own</summary><form></form></details>" : ""}<div class="hb-msheet-foot"></div>`;
3783
+ const c = e.querySelector("input[type=\"search\"]"), a = e.querySelector(".hb-msheet-list"), h = e.querySelector(".hb-msheet-opts"), y = e.querySelector(".hb-msheet-foot"), f = e.querySelector(".hb-msheet-own form");
3728
3784
  let m = "gguf";
3729
- const f = {};
3785
+ const g = {};
3730
3786
  function l() {
3731
- if (!h) return;
3732
- const x = $e.find((v) => v.kind === m);
3733
- h.innerHTML = `<div class="hb-seg" role="group" aria-label="kind">${$e.map((v) => `<button type="button" data-own-kind="${v.kind}" class="${v.kind === m ? "is-on" : ""}" aria-pressed="${v.kind === m}">${T(v.label)}</button>`).join("")}</div>` + x.fields.map((v) => `<label class="hb-field"><span class="hb-label">${T(v.label)}</span><input class="hb-input" data-own="${v.key}" type="${v.secret ? "password" : "text"}" placeholder="${T(v.placeholder)}" autocomplete="off" spellcheck="false" value="${T(f[v.key] ?? "")}"></label>`).join("") + `<button type="submit" class="hb-btn"${ke(m, f) ? "" : " hidden"}>add</button>`;
3787
+ if (!f) return;
3788
+ const k = Oe.find((b) => b.kind === m);
3789
+ f.innerHTML = `<div class="hb-seg" role="group" aria-label="kind">${Oe.map((b) => `<button type="button" data-own-kind="${b.kind}" class="${b.kind === m ? "is-on" : ""}" aria-pressed="${b.kind === m}">${R(b.label)}</button>`).join("")}</div>` + k.fields.map((b) => `<label class="hb-field"><span class="hb-label">${R(b.label)}</span><input class="hb-input" data-own="${b.key}" type="${b.secret ? "password" : "text"}" placeholder="${R(b.placeholder)}" autocomplete="off" spellcheck="false" value="${R(g[b.key] ?? "")}"></label>`).join("") + `<button type="submit" class="hb-btn"${Ce(m, g) ? "" : " hidden"}>add</button>`;
3734
3790
  }
3735
3791
  l();
3736
3792
  function p() {
3737
- var $, C;
3738
- for (const q of e.querySelectorAll("[data-filter]")) {
3739
- const A = i[q.dataset.filter];
3740
- q.classList.toggle("is-on", A), q.setAttribute("aria-pressed", String(A));
3741
- }
3742
- const x = kr(r, i), v = r.length - x.length;
3743
- a.innerHTML = Sr(x, n, o) + (x.length && v > 0 && i.fits ? `<p class="hb-msheet-none">${v} more do not fit this machine or the filters.</p>` : "");
3744
- const E = r.find((q) => q.id === n);
3745
- g.innerHTML = ($ = E == null ? void 0 : E.options) != null && $.length ? E.options.map((q) => `<label class="hb-field"><span class="hb-label">${T(q.label)}</span><select class="hb-select" data-option="${T(q.key)}">${q.choices.map((A) => `<option value="${T(A.value)}"${A.value === q.value ? " selected" : ""}>${T(A.label)}</option>`).join("")}</select></label>`).join("") : "", g.hidden = !((C = E == null ? void 0 : E.options) != null && C.length), y.innerHTML = E && Ce(E) ? `<button type="button" class="hb-btn hb-btn-go" data-load>${T(Se(E))}</button>` : (E == null ? void 0 : E.state) === "loading" ? `<span class="hb-msel-state" role="status">${T(Se(E))}</span><button type="button" class="hb-btn" data-cancel>cancel</button>` : (E == null ? void 0 : E.state) === "loaded" ? `<span class="hb-msel-state is-loaded">${T(E.name)}, ready</span>` : "<span class=\"hb-msel-state\">pick a row</span>";
3746
- }
3747
- const d = (x) => {
3748
- const v = x.target.closest("[data-own]");
3749
- if (v) {
3750
- f[v.dataset.own] = v.value;
3751
- const E = h == null ? void 0 : h.querySelector("button[type=\"submit\"]");
3752
- E && (E.hidden = !ke(m, f));
3793
+ var T, z;
3794
+ for (const L of e.querySelectorAll("[data-filter]")) {
3795
+ const S = i[L.dataset.filter];
3796
+ L.classList.toggle("is-on", S), L.setAttribute("aria-pressed", String(S));
3797
+ }
3798
+ const k = Ar(r, i), b = r.length - k.length;
3799
+ a.innerHTML = Or(k, n, o) + (k.length && b > 0 && i.fits ? `<p class="hb-msheet-none">${b} more do not fit this machine or the filters.</p>` : "");
3800
+ const x = r.find((L) => L.id === n);
3801
+ h.innerHTML = (T = x == null ? void 0 : x.options) != null && T.length ? x.options.map((L) => `<label class="hb-field"><span class="hb-label">${R(L.label)}</span><select class="hb-select" data-option="${R(L.key)}">${L.choices.map((S) => `<option value="${R(S.value)}"${S.value === L.value ? " selected" : ""}>${R(S.label)}</option>`).join("")}</select></label>`).join("") : "", h.hidden = !((z = x == null ? void 0 : x.options) != null && z.length), y.innerHTML = x && Re(x) ? `<button type="button" class="hb-btn hb-btn-go" data-load>${R(Ie(x))}</button>` : (x == null ? void 0 : x.state) === "loading" ? `<span class="hb-msel-state" role="status">${R(Ie(x))}</span><button type="button" class="hb-btn" data-cancel>cancel</button>` : (x == null ? void 0 : x.state) === "loaded" ? `<span class="hb-msel-state is-loaded">${R(x.name)}, ready</span>` : "<span class=\"hb-msel-state\">pick a row</span>";
3802
+ }
3803
+ const d = (k) => {
3804
+ const b = k.target.closest("[data-own]");
3805
+ if (b) {
3806
+ g[b.dataset.own] = b.value;
3807
+ const x = f == null ? void 0 : f.querySelector("button[type=\"submit\"]");
3808
+ x && (x.hidden = !Ce(m, g));
3753
3809
  return;
3754
3810
  }
3755
3811
  i.query = c.value, p();
3756
- }, u = (x) => {
3757
- var v;
3758
- if (x.target.closest(".hb-msheet-own") && (x.preventDefault(), !!ke(m, f))) {
3759
- (v = t.onCustom) == null || v.call(t, m, { ...f });
3760
- for (const E of Object.keys(f)) delete f[E];
3812
+ }, u = (k) => {
3813
+ var b;
3814
+ if (k.target.closest(".hb-msheet-own") && (k.preventDefault(), !!Ce(m, g))) {
3815
+ (b = t.onCustom) == null || b.call(t, m, { ...g });
3816
+ for (const x of Object.keys(g)) delete g[x];
3761
3817
  l();
3762
3818
  }
3763
- }, b = (x) => {
3764
- var E;
3765
- const v = x.target.closest("select[data-option]");
3766
- v && n && ((E = t.onOption) == null || E.call(t, n, v.dataset.option, v.value));
3767
- }, w = (x) => {
3768
- var D, H, F, K;
3769
- const v = x.target, E = v.closest("[data-own-kind]");
3770
- if (E) {
3771
- m = E.dataset.ownKind;
3772
- for (const O of Object.keys(f)) delete f[O];
3819
+ }, v = (k) => {
3820
+ var x;
3821
+ const b = k.target.closest("select[data-option]");
3822
+ b && n && ((x = t.onOption) == null || x.call(t, n, b.dataset.option, b.value));
3823
+ }, w = (k) => {
3824
+ var C, $, A, O;
3825
+ const b = k.target, x = b.closest("[data-own-kind]");
3826
+ if (x) {
3827
+ m = x.dataset.ownKind;
3828
+ for (const I of Object.keys(g)) delete g[I];
3773
3829
  l();
3774
3830
  return;
3775
3831
  }
3776
- const $ = v.closest("[data-filter]");
3777
- if ($) {
3778
- const O = $.dataset.filter;
3779
- i[O] = !i[O], p();
3832
+ const T = b.closest("[data-filter]");
3833
+ if (T) {
3834
+ const I = T.dataset.filter;
3835
+ i[I] = !i[I], p();
3780
3836
  return;
3781
3837
  }
3782
- const C = v.closest("[data-pick]");
3783
- if (C) {
3784
- const O = r.find((V) => V.id === C.dataset.pick);
3785
- if (!O || O.unfit) return;
3786
- n = O.id, (D = t.onChoose) == null || D.call(t, O.id), p();
3838
+ const z = b.closest("[data-pick]");
3839
+ if (z) {
3840
+ const I = r.find((N) => N.id === z.dataset.pick);
3841
+ if (!I || I.unfit) return;
3842
+ n = I.id, (C = t.onChoose) == null || C.call(t, I.id), p();
3787
3843
  return;
3788
3844
  }
3789
- const q = v.closest("[data-more]");
3790
- if (q) {
3791
- o = o === q.dataset.more ? "" : q.dataset.more, p();
3845
+ const L = b.closest("[data-more]");
3846
+ if (L) {
3847
+ o = o === L.dataset.more ? "" : L.dataset.more, p();
3792
3848
  return;
3793
3849
  }
3794
- const A = v.closest("[data-remove]");
3795
- if (A) {
3796
- (H = t.onRemove) == null || H.call(t, A.dataset.remove);
3850
+ const S = b.closest("[data-remove]");
3851
+ if (S) {
3852
+ ($ = t.onRemove) == null || $.call(t, S.dataset.remove);
3797
3853
  return;
3798
3854
  }
3799
- if (v.closest("[data-load]") && n) {
3800
- (F = t.onLoad) == null || F.call(t, n);
3855
+ if (b.closest("[data-load]") && n) {
3856
+ (A = t.onLoad) == null || A.call(t, n);
3801
3857
  return;
3802
3858
  }
3803
- v.closest("[data-cancel]") && n && ((K = t.onCancel) == null || K.call(t, n));
3859
+ b.closest("[data-cancel]") && n && ((O = t.onCancel) == null || O.call(t, n));
3804
3860
  };
3805
- return e.addEventListener("input", d), e.addEventListener("submit", u), e.addEventListener("click", w), e.addEventListener("change", b), p(), {
3806
- update(x, v) {
3807
- r = x, v !== void 0 && (n = v), p();
3861
+ return e.addEventListener("input", d), e.addEventListener("submit", u), e.addEventListener("click", w), e.addEventListener("change", v), p(), {
3862
+ update(k, b) {
3863
+ r = k, b !== void 0 && (n = b), p();
3808
3864
  },
3809
3865
  get chosen() {
3810
3866
  return n;
3811
3867
  },
3812
3868
  dispose() {
3813
- e.removeEventListener("input", d), e.removeEventListener("submit", u), e.removeEventListener("click", w), e.removeEventListener("change", b);
3869
+ e.removeEventListener("input", d), e.removeEventListener("submit", u), e.removeEventListener("click", w), e.removeEventListener("change", v);
3814
3870
  }
3815
3871
  };
3816
3872
  }
3817
- function Us(e, t) {
3873
+ function ta(e, t) {
3818
3874
  let r = t.rows, n = t.chosen ?? "";
3819
3875
  e.classList.add("hb-msel");
3820
3876
  function o() {
3821
- const s = r.find((a) => a.id === n), c = $r(s, t.empty);
3822
- e.innerHTML = `<button type="button" class="hb-msel-line" aria-haspopup="dialog" aria-label="model: ${T(c.name)}" data-open><span class="hb-msel-name">${T(c.name)}</span>${c.meta ? `<span class="hb-msel-meta">${T(c.meta)}</span>` : ""}${c.state ? `<span class="hb-msel-state${(s == null ? void 0 : s.state) === "loaded" ? " is-loaded" : ""}">${T(c.state)}</span>` : ""}</button>${(t.go ?? !0) && Ce(s) ? `<button type="button" class="hb-btn hb-btn-go" data-load>${T(Se(s))}</button>` : ""}`;
3877
+ const s = r.find((a) => a.id === n), c = qr(s, t.empty);
3878
+ e.innerHTML = `<button type="button" class="hb-msel-line" aria-haspopup="dialog" aria-label="model: ${R(c.name)}" data-open><span class="hb-msel-name">${R(c.name)}</span>${c.meta ? `<span class="hb-msel-meta">${R(c.meta)}</span>` : ""}${c.state ? `<span class="hb-msel-state${(s == null ? void 0 : s.state) === "loaded" ? " is-loaded" : ""}">${R(c.state)}</span>` : ""}</button>${(t.go ?? !0) && Re(s) ? `<button type="button" class="hb-btn hb-btn-go" data-load>${R(Ie(s))}</button>` : ""}`;
3823
3879
  }
3824
3880
  const i = (s) => {
3825
- var a, g;
3881
+ var a, h;
3826
3882
  const c = s.target;
3827
- c.closest("[data-open]") ? (a = t.onOpen) == null || a.call(t) : c.closest("[data-load]") && n && ((g = t.onLoad) == null || g.call(t, n));
3883
+ c.closest("[data-open]") ? (a = t.onOpen) == null || a.call(t) : c.closest("[data-load]") && n && ((h = t.onLoad) == null || h.call(t, n));
3828
3884
  };
3829
3885
  return e.addEventListener("click", i), o(), {
3830
3886
  update(s, c) {
@@ -6745,6 +6801,36 @@ const PINS = {
6745
6801
  527503840,
6746
6802
  "vendor"
6747
6803
  ] }
6804
+ },
6805
+ "Felladrin/gguf-sharded-UD-Q4_K_XL-Phi-4-mini-reasoning": {
6806
+ "revision": "bc6bac3a27893ab006486992e46a7662ef4790a9",
6807
+ "files": {
6808
+ "model.shard-00001-of-00005.gguf": [
6809
+ "e730254967e049ab3bd5e2311cedd200155b9d0835fb05a9218de82b324cac3f",
6810
+ 512426912,
6811
+ "vendor"
6812
+ ],
6813
+ "model.shard-00002-of-00005.gguf": [
6814
+ "812f190b06a786ec7ed22378bb5a136476f5c040a434140916cceb5563ab7f4d",
6815
+ 481483520,
6816
+ "vendor"
6817
+ ],
6818
+ "model.shard-00003-of-00005.gguf": [
6819
+ "f5b575dc8a4fd7d75dc4616261a050a224a2e81783e5616e74d2cd022b89d658",
6820
+ 499301472,
6821
+ "vendor"
6822
+ ],
6823
+ "model.shard-00004-of-00005.gguf": [
6824
+ "edba060f8bf871dc4953ff633a0b1e0de7d312cd05ef3a5a449b69c9d2e53765",
6825
+ 495664224,
6826
+ "vendor"
6827
+ ],
6828
+ "model.shard-00005-of-00005.gguf": [
6829
+ "da2110debf2334e102413017e3ad9285f6a5475aeb5a2d3b85b03e5865df5cab",
6830
+ 473803392,
6831
+ "vendor"
6832
+ ]
6833
+ }
6748
6834
  }
6749
6835
  };
6750
6836
  // packages/models/src/pinning.ts
@@ -6784,6 +6870,11 @@ function pinnedBase(repo, fallback = "main") {
6784
6870
  * Every row carries a speed word and a verdict of one to four words: what
6785
6871
  * a person picks by, in the owner's voice.
6786
6872
  *
6873
+ * Repos of the rows named in the vision lab and generate gaps (Qwen3
6874
+ * 1.7B, Phi-4 mini, SmolLM2 1.7B, Phi-4 mini reasoning) were checked on
6875
+ * 2026-11-25 with an HTTP HEAD of the repo's config.json or
6876
+ * mlc-chat-config.json (200, no weight fetched).
6877
+ *
6787
6878
  * Catalogue facts (params, quant, VRAM, censorship, tags, note) are copied
6788
6879
  * from the owner's model labels and the WebLLM catalogue; VRAM figures are the catalogue's own (vendor). Licence
6789
6880
  * strings are shown as recorded and were not verified for these facts.
@@ -7739,6 +7830,42 @@ const CATALOG = [
7739
7830
  commercial: true,
7740
7831
  runtime: "@mlc-ai/web-llm@0.2.84"
7741
7832
  },
7833
+ {
7834
+ id: "phi-4-mini-reasoning-gguf",
7835
+ label: "Phi-4 mini reasoning",
7836
+ params: "3.8B",
7837
+ quant: "Q4_K_XL",
7838
+ censorship: "stock",
7839
+ tier: "medium",
7840
+ family: "phi",
7841
+ tags: ["think", "reasoning"],
7842
+ note: "phi-4 mini tuned for maths with a think trace, unsloth dynamic q4. five 500 MB shards, so it loads past the 2 GB file cap.",
7843
+ group: "reasoning",
7844
+ badge: "maths, thinks first",
7845
+ speed: "slow",
7846
+ verdict: "maths, thinks first",
7847
+ provides: ["chat"],
7848
+ provider: "wllama",
7849
+ source: {
7850
+ repo: "Felladrin/gguf-sharded-UD-Q4_K_XL-Phi-4-mini-reasoning",
7851
+ file: "model.shard-00001-of-00005.gguf"
7852
+ },
7853
+ sizeMB: 2349,
7854
+ sizeSource: "vendor",
7855
+ ctx: 4096,
7856
+ ladder: [{
7857
+ device: "webgpu",
7858
+ dtype: "q4_k_m"
7859
+ }, {
7860
+ device: "wasm",
7861
+ dtype: "q4_k_m"
7862
+ }],
7863
+ quirks: { think: "tags" },
7864
+ licence: "MIT (the base model card microsoft/Phi-4-mini-reasoning; the shard repo has no licence field)",
7865
+ commercial: true,
7866
+ runtime: "@wllama/wllama@3.8.1",
7867
+ notes: ["no webllm or transformers.js build on the hub as of 2026-11-25: the microsoft onnx export is an onnxruntime-genai layout, so the gguf shards are the browser path"]
7868
+ },
7742
7869
  {
7743
7870
  id: "smollm2-1.7b-instruct-mlc",
7744
7871
  label: "SmolLM2 1.7B",
@@ -8606,25 +8733,28 @@ const IMAGEGEN_RECORDS = [{
8606
8733
  }
8607
8734
  }];
8608
8735
  /**
8609
- * Listed for pickers, not registered by attachImagegen: SDXL-Turbo has two
8610
- * text encoders and the pipeline here runs one, so routing must not pick it.
8736
+ * Listed for pickers, not registered by attachImagegen, so routing by
8737
+ * capability keeps SD-Turbo: SDXL-Turbo runs on `generateXl`, and the
8738
+ * export's input and output names are inferred from its README and the
8739
+ * SDXL description, not read from the graphs. `loadImagegen(hub, { id:
8740
+ * "sdxl-turbo" })` adds it and loads it.
8611
8741
  */
8612
8742
  const IMAGEGEN_PICKER_RECORDS = [{
8613
8743
  id: "sdxl-turbo",
8614
8744
  label: "sdxl-turbo 512",
8615
8745
  speed: "steady",
8616
8746
  verdict: "not run yet",
8617
- unrunnable: "not run yet. sdxl-turbo needs two text encoders and this pipeline runs one.",
8747
+ unrunnable: "not run yet. the sdxl pipeline is written; the export's graph names and fp16 io are inferred and unchecked.",
8618
8748
  group: "good",
8619
8749
  provides: ["imagegen"],
8620
8750
  provider: "ort",
8621
8751
  source: {
8622
8752
  repo: "webnn/sdxl-turbo",
8623
8753
  files: [
8624
- { path: "text_encoder/model.onnx" },
8625
- { path: "text_encoder_2/model.onnx" },
8626
- { path: "unet/model.onnx" },
8627
- { path: "vae_decoder/model.onnx" }
8754
+ { path: "onnx/text_encoder_model_q4f16.onnx" },
8755
+ { path: "onnx/text_encoder_2_model_q4f16.onnx" },
8756
+ { path: "onnx/unet_model_q4f16.onnx" },
8757
+ { path: "onnx/vae_decoder_model_q4f16.onnx" }
8628
8758
  ]
8629
8759
  },
8630
8760
  sizeMB: 2548,
@@ -8638,7 +8768,11 @@ const IMAGEGEN_PICKER_RECORDS = [{
8638
8768
  commercial: "unknown",
8639
8769
  place: "gpu",
8640
8770
  runtime: "onnxruntime-web@1.27.0",
8641
- notes: ["two text encoders; the pipeline in this package runs one, so this record is listed and not run yet", "the highest quality of the three image models"],
8771
+ notes: [
8772
+ "two text encoders, pooled embeddings and time ids, on generateXl",
8773
+ "fp16 inputs and outputs per the export's README (--force_fp16_inputs); timestep dtype and hidden state names inferred",
8774
+ "the highest quality of the three image models"
8775
+ ],
8642
8776
  form: {
8643
8777
  steps: {
8644
8778
  min: 1,
@@ -8651,7 +8785,17 @@ const IMAGEGEN_PICKER_RECORDS = [{
8651
8785
  spacing: "trailing",
8652
8786
  note: "distilled from sdxl. 1 to 4 steps, no negative prompt. the best looking of the three.",
8653
8787
  tokenizer: "Xenova/clip-vit-base-patch16",
8654
- graphs
8788
+ graphs: {
8789
+ textEncoder: "text_encoder_model_q4f16",
8790
+ textEncoder2: "text_encoder_2_model_q4f16",
8791
+ unet: "unet_model_q4f16",
8792
+ vaeDecoder: "vae_decoder_model_q4f16"
8793
+ },
8794
+ pipeline: "sdxl",
8795
+ xl: {
8796
+ io: "float16",
8797
+ timestep: "float16"
8798
+ }
8655
8799
  }
8656
8800
  }];
8657
8801
  // packages/speak/src/records.ts
@@ -8856,9 +9000,11 @@ const TRANSCRIBE_RECORDS = [
8856
9000
  * 2026-11-22; sizes are inferred from the builds and parameter counts, except where
8857
9001
  * a row says vendor: those sum the hub listing's files (no download), in MiB.
8858
9002
  * YOLO weights are AGPL-3.0 (Ultralytics): they are never registered by
8859
- * default. YOLOv8n has no public hub repo, so `yoloRecord` builds a record
9003
+ * default. YOLOv8n has no onnx-community or Xenova repo (an HTTP HEAD of
9004
+ * their config.json gave 401 on 2026-11-25), so `yoloRecord` builds a record
8860
9005
  * only for a URL the app supplies; YOLOv10 n, s and m, FastSAM and the face
8861
- * swap set sit in PICKER_RECORDS.
9006
+ * swap set sit in PICKER_RECORDS. The YOLOv10 n, s and m, SmolVLM 500M,
9007
+ * Gemma 4 E2B and FastSAM repos answered that HEAD with 200 the same day.
8862
9008
  */
8863
9009
  /** The MediaPipe model storage base URL the MediaPipe records load from. */
8864
9010
  const MP_MODELS = "https://storage.googleapis.com/mediapipe-models/";
@@ -9144,7 +9290,7 @@ const PICKER_RECORDS = [
9144
9290
  licence: "AGPL-3.0 upstream (Ultralytics FastSAM); the export's card says apache-2.0",
9145
9291
  commercial: false,
9146
9292
  place: "cpu-worker",
9147
- notes: ["finds every mask in one pass on onnxruntime-web (93 MB, vendor)", "segment everything: prototype masks, nms, then a pick by click"]
9293
+ notes: ["finds every mask in one pass on onnxruntime-web; the original page loaded a 93 MB build (vendor, its review)", "segment everything: prototype masks, nms, then a pick by click (segmentEverything, instanceAt)"]
9148
9294
  },
9149
9295
  {
9150
9296
  id: "scrfd-10g",
@@ -9388,7 +9534,7 @@ function backendOf(r, env) {
9388
9534
  /** Download words: "1.7 gb". Null for a record with no download or an unknown size. */
9389
9535
  function sizeWords(r) {
9390
9536
  if (isNoDownload(r) || r.sizeMB === null) return void 0;
9391
- return Lr(r.sizeMB * MIB);
9537
+ return Dr(r.sizeMB * MIB);
9392
9538
  }
9393
9539
  /** The record's label, else its id made readable: "hermes 3 llama 3.2 3b". */
9394
9540
  const pretty = (r) => r.label ?? r.id.replace(/-(mlc|gguf)$/, "").replace(/-/g, " ");
@@ -9407,11 +9553,11 @@ function detailOf(r) {
9407
9553
  });
9408
9554
  if (r.sizeMB !== null && !isNoDownload(r)) out.push({
9409
9555
  label: "size",
9410
- value: `${Lr(r.sizeMB * MIB)}, ${r.sizeSource}`
9556
+ value: `${Dr(r.sizeMB * MIB)}, ${r.sizeSource}`
9411
9557
  });
9412
9558
  if (r.vramMB != null) out.push({
9413
9559
  label: "gpu memory",
9414
- value: `${Lr(r.vramMB * MIB)}, ${r.vramSource ?? "unknown"}`
9560
+ value: `${Dr(r.vramMB * MIB)}, ${r.vramSource ?? "unknown"}`
9415
9561
  });
9416
9562
  if (r.ctx) out.push({
9417
9563
  label: "context",
@@ -9507,7 +9653,7 @@ function rowOf(r, ctx = {}) {
9507
9653
  state
9508
9654
  };
9509
9655
  if (size) row.size = size;
9510
- if (r.vramMB != null) row.memory = `needs ${Lr(r.vramMB * MIB)}`;
9656
+ if (r.vramMB != null) row.memory = `needs ${Dr(r.vramMB * MIB)}`;
9511
9657
  if (r.sizeMB !== null && !isNoDownload(r)) row.bytes = r.sizeMB * MIB;
9512
9658
  const speed = fit.fit === "fits on cpu, slow" ? "slow" : r.speed;
9513
9659
  if (speed) row.speed = speed;
@@ -9659,7 +9805,7 @@ function useModelPick(job, o = {}) {
9659
9805
  estimate,
9660
9806
  state: state.get(id)
9661
9807
  });
9662
- if (!rec || !Ce(row)) return;
9808
+ if (!rec || !Re(row)) return;
9663
9809
  if (!loader) {
9664
9810
  state.set(id, "error");
9665
9811
  errors.set(id, "no loader. the page passes one to load a model.");
@@ -9728,6 +9874,7 @@ function useModelPick(job, o = {}) {
9728
9874
  if (n.records) records = jobRecords(job, n.records);
9729
9875
  if (n.loader) loader = n.loader;
9730
9876
  if (n.onRemove) onRemove = n.onRemove;
9877
+ for (const id of n.stored ?? []) if (!state.has(id) || state.get(id) === "none") state.set(id, "stored");
9731
9878
  emit();
9732
9879
  },
9733
9880
  result: (id) => results.get(id),
@@ -9822,7 +9969,7 @@ function pickSheet(pick) {
9822
9969
  const s0 = pick.snapshot();
9823
9970
  root.innerHTML = `<div class="hb-drawer-panel" role="dialog" aria-modal="true"><div class="hb-drawer-hd"><span>${esc(s0.title)}</span><button type="button" class="hb-iconbtn" aria-label="close" data-hb-close><svg class="hb-icon is-stroke" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg></button></div><div class="hb-msheet-host"></div></div>`;
9824
9971
  doc.body.append(root);
9825
- const sheet = Bs(root.querySelector(".hb-msheet-host"), {
9972
+ const sheet = ea(root.querySelector(".hb-msheet-host"), {
9826
9973
  rows: s0.rows,
9827
9974
  chosen: s0.chosen,
9828
9975
  title: s0.title,
@@ -9834,7 +9981,7 @@ function pickSheet(pick) {
9834
9981
  onCustom: (kind, values) => void pick.custom(kind, values)
9835
9982
  });
9836
9983
  const l = listeners();
9837
- const handle = qr(root, {
9984
+ const handle = Wr(root, {
9838
9985
  side: "auto",
9839
9986
  breakpoint: 641,
9840
9987
  label: s0.title
@@ -9850,9 +9997,29 @@ function pickSheet(pick) {
9850
9997
  }
9851
9998
  };
9852
9999
  }
10000
+ const FILLER = /^(instruct|chat|it|mlc|onnx|gguf|hf|q\d\w*|f16|f32|fp16|int8|bf16|uniform)$/i;
10001
+ /**
10002
+ * A model name cut for the bar chip: filler words (instruct, chat, quant tags)
10003
+ * go, and a name of more than three words keeps its first two and its last,
10004
+ * which is usually the size: "hermes 3 llama 3.2 3b" reads "hermes 3 3b".
10005
+ * A note in brackets goes first: "slimsam 77 uniform (point prompts)" reads "slimsam 77".
10006
+ */
10007
+ function shortName(name) {
10008
+ const w = name.replace(/\s*\([^)]*\)/g, "").split(/\s+/).filter((x) => x && !FILLER.test(x));
10009
+ return (w.length > 3 ? [
10010
+ w[0],
10011
+ w[1],
10012
+ w[w.length - 1]
10013
+ ] : w).join(" ") || name;
10014
+ }
10015
+ /** The chip's words: the short name, then the download size, or the state once it moves. */
9853
10016
  function chipWords(s) {
9854
- const w = $r(s.row, s.empty);
9855
- return w.state ? `${w.name}, ${w.state}` : w.name;
10017
+ const r = s.row;
10018
+ if (!r) return s.empty;
10019
+ const w = qr(r, s.empty);
10020
+ const name = shortName(r.name);
10021
+ if ((r.state === "loading" || r.state === "loaded" || r.state === "error") && w.state) return `${name}, ${w.state}`;
10022
+ return `${name}, ${r.noDownload ? "no download" : r.size ?? "size unknown"}`;
9856
10023
  }
9857
10024
  /** The closed picker over a host; pressing it opens the sheet. */
9858
10025
  function mountModelSelect(host, pick, o = {}) {
@@ -9862,7 +10029,8 @@ function mountModelSelect(host, pick, o = {}) {
9862
10029
  if (o.variant === "chip") {
9863
10030
  const draw = (s) => {
9864
10031
  const words = chipWords(s);
9865
- host.innerHTML = `<button type="button" class="hb-msel-chip${s.row?.state ? ` is-${s.row.state}` : ""}" aria-haspopup="dialog" aria-label="model: ${esc(words)}"><span>${esc(words)}</span></button>`;
10032
+ const full = s.row ? `model: ${s.row.name}${s.row.size ? `, ${s.row.size}` : ""}${qr(s.row, s.empty).state ? `, ${qr(s.row, s.empty).state}` : ""}` : `model: ${s.empty}`;
10033
+ host.innerHTML = `<button type="button" class="hb-msel-chip${s.row?.state ? ` is-${s.row.state}` : ""}" aria-haspopup="dialog" aria-label="${esc(full)}" title="${esc(full)}"><span>${esc(words)}</span></button>`;
9866
10034
  };
9867
10035
  l.on(host, "click", (e) => {
9868
10036
  if (e.target.closest(".hb-msel-chip")) sheet.open();
@@ -9872,7 +10040,7 @@ function mountModelSelect(host, pick, o = {}) {
9872
10040
  const inner = document.createElement("div");
9873
10041
  host.replaceChildren(inner);
9874
10042
  const s0 = pick.snapshot();
9875
- const sel = Us(inner, {
10043
+ const sel = ta(inner, {
9876
10044
  rows: s0.rows,
9877
10045
  chosen: s0.chosen,
9878
10046
  go: o.go ?? true,
@@ -9896,7 +10064,7 @@ function mountModelJobs(host, jobs, o = {}) {
9896
10064
  const presets = jobs.presets();
9897
10065
  const all = jobs.all();
9898
10066
  host.innerHTML = `<div class="hb-msel-jobs">` + (presets.length ? `<div class="hb-msel-presets" role="group" aria-label="presets">${presets.map((p) => `<button type="button" class="hb-chip" data-preset="${esc(p.id)}">${esc(p.label)}, ${esc(p.total)}</button>`).join("")}</div>` : "") + jobs.lines().map((j) => {
9899
- const w = $r(j.row, "no model");
10067
+ const w = qr(j.row, "no model");
9900
10068
  return `<div class="hb-msel-job"><span class="hb-msel-joblabel">${esc(j.label)}${j.required ? "<b> required</b>" : ""}</span><button type="button" class="hb-msel-line" data-job="${j.job}" aria-haspopup="dialog" aria-label="${esc(j.label)}: ${esc(w.name)}"><span class="hb-msel-name">${esc(w.name)}</span>${w.meta ? `<span class="hb-msel-meta">${esc(w.meta)}</span>` : ""}${w.state ? `<span class="hb-msel-state${j.row?.state === "loaded" ? " is-loaded" : ""}">${esc(w.state)}</span>` : ""}</button></div>`;
9901
10069
  }).join("") + ((o.go ?? true) && all.ids.length ? `<div class="hb-msel"><button type="button" class="hb-btn hb-btn-go" data-all>${esc(all.label)}</button></div>` : "") + `</div>`;
9902
10070
  };
@@ -9964,7 +10132,7 @@ function mountChatPane(host, thread, o = {}) {
9964
10132
  const l = listeners();
9965
10133
  const draw = (s) => {
9966
10134
  const sc = scroller(host);
9967
- const stick = Bo(sc);
10135
+ const stick = ei(sc);
9968
10136
  if (!s.turns.length) {
9969
10137
  host.innerHTML = `<div class="hb-lay-convempty"><h2 class="hb-lay-convempty-name">${esc(o.emptyName ?? "what are we working on?")}</h2>${o.emptyNote ? `<p class="hb-lay-convempty-note">${esc(o.emptyNote)}</p>` : ""}</div>`;
9970
10138
  return;
@@ -10006,7 +10174,7 @@ function mountComposer(host, thread, o = {}) {
10006
10174
  const text = area.value.trim();
10007
10175
  if (!text || busy) return;
10008
10176
  area.value = "";
10009
- Ho(area);
10177
+ Zo(area);
10010
10178
  thread.send(text);
10011
10179
  };
10012
10180
  const l = listeners();
@@ -10017,12 +10185,12 @@ function mountComposer(host, thread, o = {}) {
10017
10185
  l.on(act, "click", (e) => {
10018
10186
  if (e.target.closest("[data-stop]")) thread.stop();
10019
10187
  });
10020
- l.on(area, "input", () => Ho(area));
10188
+ l.on(area, "input", () => Zo(area));
10021
10189
  l.on(area, "keydown", (e) => {
10022
- const k = Ko(e, {
10190
+ const k = Jo(e, {
10023
10191
  busy,
10024
10192
  empty: !area.value,
10025
- coarse: jo()
10193
+ coarse: Qo()
10026
10194
  });
10027
10195
  if (k === "send") {
10028
10196
  e.preventDefault();
@@ -10043,7 +10211,7 @@ function mountChatList(host, list, o = {}) {
10043
10211
  let renaming = "";
10044
10212
  const head = o.label ?? "chats";
10045
10213
  const draw = (s) => {
10046
- host.innerHTML = `<nav class="hb-convs" aria-label="${esc(head)}"><div class="hb-convs-hd"><span>${esc(head)}</span><button type="button" class="hb-convs-new" data-new aria-label="new chat">${ICON.plus}</button></div><ul class="hb-convs-list">` + s.items.map((c) => renaming === c.id ? `<li class="hb-convs-item"><form class="hb-convs-rename" data-rename="${esc(c.id)}"><input class="hb-input" aria-label="chat name" value="${esc(c.title)}"></form></li>` : `<li class="hb-convs-item"${c.id === s.current ? " aria-current=\"true\"" : ""}><button type="button" class="hb-convs-open" data-open="${esc(c.id)}"><span class="hb-convs-title">${esc(c.title)}</span><span class="hb-convs-meta">${esc(Wo({
10214
+ host.innerHTML = `<nav class="hb-convs" aria-label="${esc(head)}"><div class="hb-convs-hd"><span>${esc(head)}</span><button type="button" class="hb-convs-new" data-new aria-label="new chat">${ICON.plus}</button></div><ul class="hb-convs-list">` + s.items.map((c) => renaming === c.id ? `<li class="hb-convs-item"><form class="hb-convs-rename" data-rename="${esc(c.id)}"><input class="hb-input" aria-label="chat name" value="${esc(c.title)}"></form></li>` : `<li class="hb-convs-item"${c.id === s.current ? " aria-current=\"true\"" : ""}><button type="button" class="hb-convs-open" data-open="${esc(c.id)}"><span class="hb-convs-title">${esc(c.title)}</span><span class="hb-convs-meta">${esc(ni({
10047
10215
  updated: c.updated,
10048
10216
  count: c.count
10049
10217
  }))}</span></button><span class="hb-convs-acts"><button type="button" class="hb-convs-act" data-ren="${esc(c.id)}" aria-label="rename ${esc(c.title)}" title="rename">${ICON.pen}</button><button type="button" class="hb-convs-act is-del${armed === c.id ? " is-armed" : ""}" data-del="${esc(c.id)}" aria-label="${armed === c.id ? `press again to delete ${esc(c.title)}` : `delete ${esc(c.title)}`}">${armed === c.id ? "delete?" : ICON.trash}</button></span></li>`).join("") + `</ul></nav>`;
@@ -10079,7 +10247,7 @@ function mountContextMeter(host, thread, o = {}) {
10079
10247
  const l = listeners();
10080
10248
  const val = (v, d) => typeof v === "function" ? v() : v ?? d;
10081
10249
  const draw = (s) => {
10082
- const use = Uo(contextSegments(s, val(o.system, "")), val(o.budget, 4096));
10250
+ const use = ti(contextSegments(s, val(o.system, "")), val(o.budget, 4096));
10083
10251
  host.innerHTML = `<div class="hb-ctxmeter is-${use.tone}"><div class="hb-ctxmeter-hd"><span class="hb-ctxmeter-label">context</span><span class="hb-ctxmeter-words">${esc(use.words)}</span></div><div class="hb-ctxmeter-bar" role="meter" aria-label="context used" aria-valuemin="0" aria-valuemax="${use.budget}" aria-valuenow="${use.used}" aria-valuetext="${esc(use.words)}">${use.rows.map((r, n) => `<i class="hb-ctxmeter-p${n % 6}" style="width:${Math.min(100, r.fraction * 100)}%"></i>`).join("")}</div><ul class="hb-ctxmeter-legend">${use.rows.map((r, n) => `<li><i class="hb-ctxmeter-p${n % 6}" aria-hidden="true"></i>${esc(r.label)} <b>${r.tokens.toLocaleString("en-US")}</b></li>`).join("")}</ul></div>`;
10084
10252
  };
10085
10253
  l.add(thread.subscribe(draw));
@@ -10094,13 +10262,13 @@ function mountContextMeter(host, thread, o = {}) {
10094
10262
  /** The HTML of one channel's transcript, or an empty note when there is none. */
10095
10263
  function transcriptHtml(c, o = {}) {
10096
10264
  if (!c) return `<p class="hb-lay-empty-note">nothing yet. drop a file.</p>`;
10097
- const st = di(c.status);
10265
+ const st = ki(c.status);
10098
10266
  const head = `<div class="hb-panel-hd-inst" role="status">${esc(c.name)}, ${esc(st.word)}${c.status === "working" ? `, ${c.pct}%` : ""}</div>${c.error ? `<p class="hb-lay-empty-note">${esc(c.error)}</p>` : ""}`;
10099
10267
  if (!c.segments.length) return `<section class="hb-panel">${head}</section>`;
10100
- return `<section class="hb-panel">${head}<ol class="hb-transcript is-edit" aria-label="transcript">${c.dropped.length ? `<li class="hb-tseg-note">${esc(si(c.dropped))}</li>` : ""}${c.segments.map((s, i) => {
10101
- const t = te(s.start);
10268
+ return `<section class="hb-panel">${head}<ol class="hb-transcript is-edit" aria-label="transcript">${c.dropped.length ? `<li class="hb-tseg-note">${esc(yi(c.dropped))}</li>` : ""}${c.segments.map((s, i) => {
10269
+ const t = ie(s.start);
10102
10270
  return `<li><div class="hb-tseg"><span class="hb-tseg-body">${o.onSeek ? `<button type="button" class="hb-tseg-t" data-seek="${s.start}" aria-label="play from ${t}">${t}</button>` : `<span class="hb-tseg-t">${t}</span>`}${o.speakers ? `<input class="hb-tseg-who" data-who="${i}" placeholder="speaker" aria-label="speaker at ${t}" value="${esc(s.speaker ?? "")}">` : s.speaker ? `<b>${esc(s.speaker)}: </b>` : ""}<span class="hb-tseg-text" contenteditable="true" role="textbox" aria-label="text at ${t}" data-line="${i}">${esc(s.text)}</span>${s.edited ? `<span class="hb-tseg-why">edited</span>` : ""}</span></div></li>`;
10103
- }).join("")}${o.showDropped ? c.dropped.map((d) => `<li><div class="hb-tseg is-dropped"><span class="hb-tseg-body"><span class="hb-tseg-t">${te(d.start)}</span><span class="hb-tseg-text">${esc(d.text)}</span><span class="hb-tseg-why">[${esc(d.why)}]</span></span></div></li>`).join("") : ""}</ol></section>`;
10271
+ }).join("")}${o.showDropped ? c.dropped.map((d) => `<li><div class="hb-tseg is-dropped"><span class="hb-tseg-body"><span class="hb-tseg-t">${ie(d.start)}</span><span class="hb-tseg-text">${esc(d.text)}</span><span class="hb-tseg-why">[${esc(d.why)}]</span></span></div></li>`).join("") : ""}</ol></section>`;
10104
10272
  }
10105
10273
  const pickedOf = (s) => s.channels.find((c) => c.id === s.selected);
10106
10274
  /** The selected channel's transcript over a host. */
@@ -10138,6 +10306,29 @@ function mountTranscriptView(host, queue, o = {}) {
10138
10306
  l.add(queue.subscribe(draw));
10139
10307
  return { dispose: () => l.off() };
10140
10308
  }
10309
+ const AV = /\.(mp4|m4v|mov|webm|mkv|avi|mpe?g|ogv|m4a|mp3|wav|flac|ogg|opus|aac|wma|3gp)$/i;
10310
+ /** A file a speech run can read: audio or video by type or by name. */
10311
+ const isMedia = (f) => /^(audio|video)\//.test(f.type) || AV.test(f.name);
10312
+ async function walk$1(e, out, depth = 0) {
10313
+ if (e.isFile && e.file) out.push(await new Promise((ok, bad) => e.file(ok, bad)));
10314
+ else if (e.isDirectory && e.createReader && depth < 8) {
10315
+ const r = e.createReader();
10316
+ for (;;) {
10317
+ const batch = await new Promise((ok, bad) => r.readEntries(ok, bad));
10318
+ if (!batch.length) break;
10319
+ for (const c of batch) await walk$1(c, out, depth + 1);
10320
+ }
10321
+ }
10322
+ }
10323
+ /** The files of a drop, with dropped folders read through, media only. */
10324
+ async function droppedFiles(dt) {
10325
+ if (!dt) return [];
10326
+ const entries = [...dt.items ?? []].map((i) => i.webkitGetAsEntry?.()).filter((x) => x !== null && x !== void 0);
10327
+ if (!entries.length) return [...dt.files].filter(isMedia);
10328
+ const out = [];
10329
+ for (const e of entries) await walk$1(e, out).catch(() => void 0);
10330
+ return out.filter(isMedia);
10331
+ }
10141
10332
  /** The drop zone that becomes the transcript. */
10142
10333
  function mountTranscribeDrop(host, queue, o = {}) {
10143
10334
  const l = listeners();
@@ -10146,15 +10337,19 @@ function mountTranscribeDrop(host, queue, o = {}) {
10146
10337
  input.hidden = true;
10147
10338
  input.multiple = true;
10148
10339
  input.accept = o.accept ?? "audio/*,video/*";
10340
+ const dir = document.createElement("input");
10341
+ dir.type = "file";
10342
+ dir.hidden = true;
10343
+ dir.setAttribute("webkitdirectory", "");
10149
10344
  const zone = document.createElement("div");
10150
10345
  const result = document.createElement("div");
10151
- host.replaceChildren(zone, result, input);
10346
+ host.replaceChildren(zone, result, input, dir);
10152
10347
  zone.className = "hb-lay-drop";
10153
10348
  result.className = "hb-lay-scroll";
10154
- zone.innerHTML = `<div class="hb-lay-empty"><span class="hb-lay-empty-name">${esc(o.title ?? "drop audio or video")}</span><p class="hb-lay-empty-note">${esc(o.note ?? "any length. the words are worked out on this machine and the file never leaves it.")}</p><div class="hb-lay-empty-acts"><button type="button" class="hb-btn hb-btn-go" data-pick>${esc(o.pickLabel ?? "choose a file")}</button>${o.sampleLabel ? `<button type="button" class="hb-btn" data-sample>${esc(o.sampleLabel)}</button>` : ""}</div></div>`;
10349
+ zone.innerHTML = `<div class="hb-lay-empty"><span class="hb-lay-empty-name">${esc(o.title ?? "drop audio or video")}</span><p class="hb-lay-empty-note">${esc(o.note ?? "any length. the words are worked out on this machine and the file never leaves it.")}</p><div class="hb-lay-empty-acts"><button type="button" class="hb-btn hb-btn-go" data-pick>${esc(o.pickLabel ?? "choose a file")}</button>${o.folders ? `<button type="button" class="hb-btn" data-folder>a folder</button>` : ""}${o.sampleLabel ? `<button type="button" class="hb-btn" data-sample>${esc(o.sampleLabel)}</button>` : ""}</div></div>`;
10155
10350
  const view = mountTranscriptView(result, queue, o);
10156
10351
  const take = (list) => {
10157
- const files = list ? [...list] : [];
10352
+ const files = list ? [...list].filter(isMedia) : [];
10158
10353
  if (files.length) queue.add(files);
10159
10354
  };
10160
10355
  l.on(host, "dragover", (e) => {
@@ -10165,7 +10360,11 @@ function mountTranscribeDrop(host, queue, o = {}) {
10165
10360
  l.on(host, "drop", (e) => {
10166
10361
  e.preventDefault();
10167
10362
  zone.classList.remove("is-hot");
10168
- take(e.dataTransfer?.files);
10363
+ droppedFiles(e.dataTransfer).then((fs) => fs.length && queue.add(fs));
10364
+ });
10365
+ l.on(dir, "change", () => {
10366
+ take(dir.files);
10367
+ dir.value = "";
10169
10368
  });
10170
10369
  l.on(input, "change", () => {
10171
10370
  take(input.files);
@@ -10174,6 +10373,7 @@ function mountTranscribeDrop(host, queue, o = {}) {
10174
10373
  l.on(zone, "click", (e) => {
10175
10374
  const t = e.target;
10176
10375
  if (t.closest("[data-pick]")) input.click();
10376
+ else if (t.closest("[data-folder]")) dir.click();
10177
10377
  else if (t.closest("[data-sample]")) o.onSample?.();
10178
10378
  });
10179
10379
  l.add(queue.subscribe((s) => {
@@ -10183,6 +10383,7 @@ function mountTranscribeDrop(host, queue, o = {}) {
10183
10383
  }));
10184
10384
  return {
10185
10385
  pick: () => input.click(),
10386
+ pickFolder: () => dir.click(),
10186
10387
  dispose() {
10187
10388
  l.off();
10188
10389
  view.dispose();
@@ -10194,7 +10395,7 @@ function mountTranscribeQueue(host, queue) {
10194
10395
  const l = listeners();
10195
10396
  const draw = (s) => {
10196
10397
  const strips = s.channels.map((c, i) => {
10197
- const st = di(c.status);
10398
+ const st = ki(c.status);
10198
10399
  return `<li class="hb-qstrip is-${st.tone || "idle"}${c.id === s.selected ? " is-sel" : ""}${c.status === "done" ? " is-done" : ""}"><button type="button" class="hb-qstrip-main" data-sel="${c.id}" aria-pressed="${c.id === s.selected}"><span class="hb-qstrip-n">${String(i + 1).padStart(2, "0")}</span><span class="hb-qstrip-body"><span class="hb-qstrip-hd"><span class="hb-qstrip-name">${esc(c.name)}</span><span class="hb-qstrip-stat">${esc(st.word)}</span></span>` + (c.meta.length || c.error ? `<span class="hb-qstrip-meta">${c.meta.map((m) => `<span>${m.label ? `${esc(m.label)} ` : ""}<b${m.tone ? ` class="is-${m.tone}"` : ""}>${esc(m.value)}</b></span>`).join("")}${c.error ? `<span class="is-lo">${esc(c.error)}</span>` : ""}</span>` : "") + (c.status === "working" ? `<span class="hb-qstrip-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${c.pct}" aria-label="${esc(c.name)} progress"><i style="--hb-v:${c.pct / 100}"></i></span>` : "") + `</span></button>` + (s.running ? "" : `<button type="button" class="hb-qstrip-x" data-rm="${c.id}" aria-label="remove ${esc(c.name)}" title="remove">${ICON.x}</button>`) + `</li>`;
10199
10400
  }).join("");
10200
10401
  const queued = s.channels.some((c) => c.status === "queued");
@@ -10246,6 +10447,462 @@ function mountTranscriptExports(host, queue, o = {}) {
10246
10447
  l.add(queue.subscribe(draw));
10247
10448
  return { dispose: () => l.off() };
10248
10449
  }
10450
+ /**
10451
+ * ExportMenu: the selected transcript as txt, srt, vtt or json, a copy, and
10452
+ * every finished transcript as one zip with a manifest, plus undo and redo of
10453
+ * edits. Nothing shows until there is text; undo shows once there is a change.
10454
+ * `go` makes the first export the one pink action.
10455
+ */
10456
+ function mountExportMenu(host, queue, o = {}) {
10457
+ const l = listeners();
10458
+ const save = o.save ?? ((name, data, type) => download(name, typeof data === "string" ? data : new Blob([data], { type }), type));
10459
+ const draw = (s) => {
10460
+ const c = pickedOf(s);
10461
+ const done = s.channels.filter((x) => x.segments.length).length;
10462
+ host.innerHTML = c?.segments.length ? `<div class="hb-toolbar" role="group" aria-label="export">${[
10463
+ "txt",
10464
+ "srt",
10465
+ "vtt",
10466
+ "json"
10467
+ ].map((k, i) => `<button type="button" class="hb-btn${o.go && i === 0 ? " hb-btn-go" : ""}" data-ex="${k}">${o.go && i === 0 ? `save ${k}` : k}</button>`).join("")}<button type="button" class="hb-btn" data-copy>${ICON.copy}copy</button>${done ? `<button type="button" class="hb-btn" data-zip>all ${done} as zip</button>` : ""}${s.canUndo ? `<button type="button" class="hb-iconbtn" data-undo aria-label="undo the last edit" title="undo">${ICON.undo}</button>` : ""}${s.canRedo ? `<button type="button" class="hb-iconbtn" data-redo aria-label="redo" title="redo">${ICON.redo}</button>` : ""}</div>` : "";
10468
+ };
10469
+ l.on(host, "click", (e) => {
10470
+ const t = e.target;
10471
+ const ex = t.closest("[data-ex]");
10472
+ if (ex) {
10473
+ const f = queue.exportAs(ex.dataset.ex);
10474
+ if (f) save(f.name, f.text, f.type);
10475
+ return;
10476
+ }
10477
+ if (t.closest("[data-zip]")) {
10478
+ const z = queue.zip(o.tool ? { tool: o.tool } : {});
10479
+ if (z) save(z.name, z.data, "application/zip");
10480
+ return;
10481
+ }
10482
+ const cp = t.closest("[data-copy]");
10483
+ if (cp) {
10484
+ const f = queue.exportAs("txt");
10485
+ if (f) navigator.clipboard?.writeText(f.text).then(() => cp.lastChild.textContent = "copied").catch(() => cp.lastChild.textContent = "copy blocked");
10486
+ return;
10487
+ }
10488
+ if (t.closest("[data-undo]")) queue.undo();
10489
+ else if (t.closest("[data-redo]")) queue.redo();
10490
+ });
10491
+ l.add(queue.subscribe(draw));
10492
+ return { dispose: () => l.off() };
10493
+ }
10494
+ // packages/ai-views/src/mount-talk.ts
10495
+ /** True when an item is kept out of cleanup: decay never drops it. */
10496
+ const isProtected = (it) => it.meta?.protected === true;
10497
+ /** Protect an item from cleanup (it becomes lore, which never decays) or give it back its kind. */
10498
+ async function protect(mem, it, on) {
10499
+ if (on === isProtected(it)) return;
10500
+ const meta = { ...it.meta ?? {} };
10501
+ if (on) await mem.edit(it.id, {
10502
+ kind: "lore",
10503
+ meta: {
10504
+ ...meta,
10505
+ protected: true,
10506
+ was: it.kind
10507
+ }
10508
+ });
10509
+ else {
10510
+ const was = meta.was ?? "fact";
10511
+ delete meta.protected;
10512
+ delete meta.was;
10513
+ await mem.edit(it.id, {
10514
+ kind: was,
10515
+ meta
10516
+ });
10517
+ }
10518
+ }
10519
+ const sourceOf = (it) => typeof it.meta?.source === "string" ? it.meta.source.split("/")[0] : it.kind === "doc" ? it.section ?? "file" : "notes";
10520
+ /** The memory pane: counts, search, a source or kind filter, add a note, the list with protect and forget, export, import, erase. */
10521
+ function mountMemoryPane(host, mem, o = {}) {
10522
+ const l = listeners();
10523
+ let query = "";
10524
+ let source = "";
10525
+ let armed = 0;
10526
+ let wipe = false;
10527
+ let used = /* @__PURE__ */ new Set();
10528
+ let hits = null;
10529
+ let seq = 0;
10530
+ const file = document.createElement("input");
10531
+ file.type = "file";
10532
+ file.accept = ".json,application/json";
10533
+ file.hidden = true;
10534
+ const box = document.createElement("div");
10535
+ host.replaceChildren(box, file);
10536
+ const changed = () => (o.onChange?.(), draw());
10537
+ const groupOf = (it) => o.by === "kind" ? isProtected(it) ? String(it.meta?.was ?? it.kind) : it.kind : sourceOf(it);
10538
+ const groupWord = (g) => o.by === "kind" ? o.kinds?.[g] ?? g : g;
10539
+ const draw = () => {
10540
+ const all = mem.all();
10541
+ const sources = [...new Set(all.map(groupOf))];
10542
+ let shown = all.filter((it) => !source || groupOf(it) === source);
10543
+ if (hits) shown = shown.filter((it) => hits.has(it.id)).sort((a, b) => hits.get(b.id) - hits.get(a.id));
10544
+ else shown = shown.slice().sort((a, b) => b.created - a.created);
10545
+ const focus = document.activeElement === box.querySelector("[data-q]");
10546
+ box.innerHTML = `<section class="hb-mempanel" aria-label="${esc(o.name ?? "memory")}"><div class="hb-mempanel-sec"><p class="hb-mempanel-counts">${esc(oi(all.map((it) => ({
10547
+ id: String(it.id),
10548
+ text: it.text,
10549
+ kind: it.kind
10550
+ }))) || "nothing stored")}</p></div><div class="hb-mempanel-sec"><input class="hb-input" type="search" data-q placeholder="search memory" aria-label="search memory" value="${esc(query)}">` + (sources.length > 1 ? `<div class="hb-chipgroup" role="group" aria-label="${o.by === "kind" ? "kind" : "source"}"><button type="button" class="hb-chip${source ? "" : " is-on"}" data-src="" aria-pressed="${!source}">all</button>${sources.map((s) => `<button type="button" class="hb-chip${s === source ? " is-on" : ""}" data-src="${esc(s)}" aria-pressed="${s === source}">${esc(groupWord(s))}</button>`).join("")}</div>` : "") + `</div><div class="hb-mempanel-sec"><textarea class="hb-textarea" rows="2" data-note placeholder="a fact to keep" aria-label="add a note"></textarea><div class="hb-mempanel-row"><button type="button" class="hb-btn hb-btn-sm" data-add>add</button></div></div><div class="hb-mempanel-sec"><h3 class="hb-mempanel-hd">${query ? "matches" : "notes"} (${shown.length})</h3>` + (shown.length ? `<div class="hb-mempanel-list">${shown.slice(0, 200).map((it) => {
10551
+ const p = isProtected(it);
10552
+ const u = used.has(it.text);
10553
+ return `<div class="hb-mem${u ? " is-used" : ""}${p ? " is-pinned" : ""}"><div class="hb-mem-body">${p ? `<span class="hb-mem-pin">kept</span>` : ""}<span class="hb-mem-kind">${esc(p ? String(it.meta?.was ?? it.kind) : it.kind)}${hits?.has(it.id) ? `<b class="hb-mem-score">${esc(ii(hits.get(it.id)))}</b>` : ""}</span><span class="hb-mem-text">${esc(it.text.length > 280 ? `${it.text.slice(0, 277)}...` : it.text)}</span><span class="hb-mem-when">${esc([u ? "used last reply" : "", sourceOf(it) === "notes" ? "" : sourceOf(it)].filter(Boolean).join(", "))}</span></div><div class="hb-mem-acts"><button type="button" class="hb-mem-act${p ? " is-on" : ""}" data-keep="${it.id}" aria-pressed="${p}" aria-label="${p ? "let cleanup drop it" : "keep from cleanup"}" title="${p ? "kept from cleanup" : "keep"}">keep</button><button type="button" class="hb-mem-act is-forget${armed === it.id ? " is-armed" : ""}" data-forget="${it.id}">${armed === it.id ? "forget?" : "forget"}</button></div></div>`;
10554
+ }).join("")}</div>` : `<p class="hb-mempanel-empty">${query ? "nothing matches. try other words." : "nothing stored yet. add a note, drop a file, or talk and it fills."}</p>`) + `</div><div class="hb-mempanel-foot">${all.length ? (o.acts ?? []).map((a) => `<button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-act="${esc(a.id)}">${esc(a.label)}</button>`).join("") : ""}<button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-export>${esc(o.exportLabel ?? "export")}</button><button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-import>import</button>${all.length ? `<button type="button" class="hb-btn hb-btn-2 hb-btn-sm hb-mempanel-wipe${wipe ? " is-armed" : ""}" data-wipe>${wipe ? "erase everything?" : "erase all"}</button>` : ""}</div></section>`;
10555
+ if (focus) {
10556
+ const q = box.querySelector("[data-q]");
10557
+ q.focus();
10558
+ q.setSelectionRange(q.value.length, q.value.length);
10559
+ }
10560
+ };
10561
+ const search = async () => {
10562
+ const mine = ++seq;
10563
+ if (!query.trim()) hits = null;
10564
+ else {
10565
+ const r = await mem.recall(query, { k: 50 });
10566
+ if (mine !== seq) return;
10567
+ hits = new Map(r.hits.map((h) => [h.item.id, h.score]));
10568
+ }
10569
+ draw();
10570
+ };
10571
+ l.on(box, "input", (e) => {
10572
+ const t = e.target;
10573
+ if (t.matches("[data-q]")) {
10574
+ query = t.value;
10575
+ search();
10576
+ }
10577
+ });
10578
+ l.on(box, "keydown", (e) => {
10579
+ const ke = e;
10580
+ if (ke.target.matches("[data-note]") && ke.key === "Enter" && !ke.shiftKey) {
10581
+ ke.preventDefault();
10582
+ box.querySelector("[data-add]")?.click();
10583
+ }
10584
+ });
10585
+ l.on(box, "click", (e) => {
10586
+ const t = e.target;
10587
+ const src = t.closest("[data-src]");
10588
+ if (src) return source = src.dataset.src ?? "", draw();
10589
+ const all = () => mem.all();
10590
+ const keep = t.closest("[data-keep]");
10591
+ if (keep) {
10592
+ const it = all().find((x) => x.id === Number(keep.dataset.keep));
10593
+ if (it) protect(mem, it, !isProtected(it)).then(changed);
10594
+ return;
10595
+ }
10596
+ const fg = t.closest("[data-forget]");
10597
+ if (fg) {
10598
+ const id = Number(fg.dataset.forget);
10599
+ if (armed !== id) return armed = id, draw();
10600
+ armed = 0;
10601
+ mem.remove([id]).then(changed);
10602
+ return;
10603
+ }
10604
+ if (t.closest("[data-add]")) {
10605
+ const text = box.querySelector("[data-note]").value.trim();
10606
+ if (text) mem.add(text, { kind: "fact" }).then(changed);
10607
+ return;
10608
+ }
10609
+ const act = t.closest("[data-act]");
10610
+ if (act) return o.onAct?.(act.dataset.act ?? "");
10611
+ if (t.closest("[data-export]")) return download(`memory-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.json`, JSON.stringify(mem.export(), null, 2), "application/json");
10612
+ if (t.closest("[data-import]")) return file.click();
10613
+ if (t.closest("[data-wipe]")) {
10614
+ if (!wipe) return wipe = true, draw();
10615
+ wipe = false;
10616
+ mem.remove(all().map((x) => x.id)).then(changed);
10617
+ }
10618
+ });
10619
+ l.on(file, "change", () => {
10620
+ const f = file.files?.[0];
10621
+ file.value = "";
10622
+ if (!f) return;
10623
+ f.text().then((t) => mem.import(JSON.parse(t), { replace: false })).then(changed).catch((err) => {
10624
+ box.querySelector(".hb-mempanel-foot")?.insertAdjacentHTML("beforeend", `<p class="hb-error" role="alert">that file did not import: ${esc(err instanceof Error ? err.message : String(err))}</p>`);
10625
+ });
10626
+ });
10627
+ draw();
10628
+ return {
10629
+ refresh: () => void search(),
10630
+ used(labels) {
10631
+ used = new Set(labels);
10632
+ draw();
10633
+ },
10634
+ dispose: () => l.off()
10635
+ };
10636
+ }
10637
+ async function walk(e, out, path, depth = 0) {
10638
+ if (e.isFile && e.file) {
10639
+ const f = await new Promise((ok, bad) => e.file(ok, bad));
10640
+ out.push(path ? Object.assign(new File([f], f.name, { type: f.type }), { webkitRelativePath: `${path}/${f.name}` }) : f);
10641
+ } else if (e.isDirectory && e.createReader && depth < 8) {
10642
+ const r = e.createReader();
10643
+ for (;;) {
10644
+ const batch = await new Promise((ok, bad) => r.readEntries(ok, bad));
10645
+ if (!batch.length) break;
10646
+ for (const c of batch) await walk(c, out, path ? `${path}/${e.name}` : e.name, depth + 1);
10647
+ }
10648
+ }
10649
+ }
10650
+ /** A drop zone for sources: files or a whole folder of text, pdf, docx, zip and mail go into memory; a line per file says what came in. */
10651
+ function mountSourcesDrop(host, o) {
10652
+ const l = listeners();
10653
+ const pick = (dir) => {
10654
+ const i = document.createElement("input");
10655
+ i.type = "file";
10656
+ i.hidden = true;
10657
+ i.multiple = true;
10658
+ if (dir) i.setAttribute("webkitdirectory", "");
10659
+ else i.accept = o.accept ?? ".txt,.md,.csv,.json,.html,.htm,.pdf,.docx,.zip,.eml,text/*";
10660
+ return i;
10661
+ };
10662
+ const files = pick(false);
10663
+ const dir = pick(true);
10664
+ const zone = document.createElement("div");
10665
+ const log = document.createElement("ul");
10666
+ zone.className = "hb-dropzone";
10667
+ zone.innerHTML = `<p class="hb-note">drop files or a folder: text, pdf, docx, zip, mail. they are read here and kept in this browser.</p><div class="hb-toolbar"><button type="button" class="hb-btn hb-btn-sm" data-files>add files</button><button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-dir>a folder</button></div>`;
10668
+ log.className = "hb-list";
10669
+ log.setAttribute("aria-live", "polite");
10670
+ host.replaceChildren(zone, log, files, dir);
10671
+ const line = (t, err = false) => log.insertAdjacentHTML("afterbegin", `<li${err ? ` class="hb-error"` : ""}>${esc(t)}</li>`);
10672
+ const run = (list) => {
10673
+ if (!list.length) return;
10674
+ zone.classList.add("is-busy");
10675
+ line(`reading ${list.length} file${list.length === 1 ? "" : "s"}`);
10676
+ o.ingest(list, { onFile: (e) => line(e.note ? `${e.name}: ${e.note}` : `${e.name}: ${e.chunks} part${e.chunks === 1 ? "" : "s"}`, !!e.note && e.note.startsWith("failed")) }).then((r) => line(`done. ${r.files} file${r.files === 1 ? "" : "s"}, ${r.chunks} parts in memory.`)).catch((err) => line(`stopped: ${err instanceof Error ? err.message : String(err)}`, true)).finally(() => zone.classList.remove("is-busy"));
10677
+ };
10678
+ l.on(zone, "click", (e) => {
10679
+ const t = e.target;
10680
+ if (t.closest("[data-files]")) files.click();
10681
+ else if (t.closest("[data-dir]")) dir.click();
10682
+ });
10683
+ for (const i of [files, dir]) l.on(i, "change", () => {
10684
+ run([...i.files ?? []]);
10685
+ i.value = "";
10686
+ });
10687
+ l.on(zone, "dragover", (e) => (e.preventDefault(), zone.classList.add("is-over")));
10688
+ l.on(zone, "dragleave", () => zone.classList.remove("is-over"));
10689
+ l.on(zone, "drop", (e) => {
10690
+ e.preventDefault();
10691
+ zone.classList.remove("is-over");
10692
+ const dt = e.dataTransfer;
10693
+ const entries = [...dt?.items ?? []].map((i) => i.webkitGetAsEntry?.()).filter((x) => x !== null && x !== void 0);
10694
+ if (!entries.length) return run([...dt?.files ?? []]);
10695
+ const out = [];
10696
+ Promise.all(entries.map((en) => walk(en, out, "").catch(() => void 0))).then(() => run(out));
10697
+ });
10698
+ return { dispose: () => l.off() };
10699
+ }
10700
+ /** The persona rack: presets one press away, name, the three parts with their cost, the template, save, and the persona as a file. */
10701
+ function mountPersonaRack(host, rack) {
10702
+ const l = listeners();
10703
+ const file = document.createElement("input");
10704
+ file.type = "file";
10705
+ file.accept = ".json,application/json";
10706
+ file.hidden = true;
10707
+ const box = document.createElement("div");
10708
+ host.replaceChildren(box, file);
10709
+ let err = "";
10710
+ const field = (key, label, hint, rows, v) => `<div class="hb-field"><span class="hb-field-head"><label class="hb-label" for="pr-${key}">${label}</label></span><textarea id="pr-${key}" class="hb-textarea" rows="${rows}" data-k="${key}" placeholder="${esc(hint)}">${esc(v)}</textarea><span class="hb-field-foot"><span class="hb-hint">${esc(Ds(Ts(v)))}</span></span></div>`;
10711
+ const draw = () => {
10712
+ if (box.contains(document.activeElement) && document.activeElement.matches("[data-k]")) return;
10713
+ const { persona: p, presets, on, builtIn } = rack.snapshot();
10714
+ box.innerHTML = `<div class="hb-persona"><div class="hb-persona-presets"><div class="hb-persona-chips" role="group" aria-label="personas">${presets.map((x, i) => `<span class="hb-persona-chip${i === on ? " is-on" : ""}"><button type="button" class="hb-persona-chip-n" data-load="${i}" aria-pressed="${i === on}">${esc(x.label)}</button>${i < builtIn ? "" : `<button type="button" class="hb-persona-chip-x" data-rm="${i}" aria-label="remove ${esc(x.label)}">&times;</button>`}</span>`).join("")}</div></div><div class="hb-field"><span class="hb-field-head"><label class="hb-label" for="pr-name">name</label></span><input id="pr-name" class="hb-input" data-k="name" value="${esc(p.name)}" autocomplete="off"></div>` + field("profile", "profile", "who you are talking to and how to answer. always sent.", 5, p.profile) + `<div class="hb-persona-row"><button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-tpl>insert template</button></div>` + field("notes", "extra notes", "sent after memory; dropped before the profile when room runs out.", 3, p.notes) + field("rules", "extra rules", "dropped first when room runs out.", 3, p.rules) + `<form class="hb-persona-save" data-save><input class="hb-input" data-label placeholder="${esc(p.name || "preset name")}" aria-label="preset name" autocomplete="off"><button type="submit" class="hb-btn hb-btn-2 hb-btn-sm">save</button></form><div class="hb-persona-row"><button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-import>import</button><button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-export>export</button></div>${err ? `<p class="hb-error" role="alert">${esc(err)}</p>` : ""}</div>`;
10715
+ };
10716
+ l.on(box, "input", (e) => {
10717
+ const t = e.target;
10718
+ const k = t.dataset.k;
10719
+ if (k) {
10720
+ rack.set({ [k]: t.value });
10721
+ const foot = t.parentElement?.querySelector(".hb-hint");
10722
+ if (foot) foot.textContent = Ds(Ts(t.value));
10723
+ }
10724
+ });
10725
+ l.on(box, "focusout", () => setTimeout(draw, 0));
10726
+ l.on(box, "submit", (e) => {
10727
+ e.preventDefault();
10728
+ rack.save(box.querySelector("[data-label]")?.value ?? "");
10729
+ });
10730
+ l.on(box, "click", (e) => {
10731
+ const t = e.target;
10732
+ const ld = t.closest("[data-load]");
10733
+ if (ld) return rack.load(Number(ld.dataset.load));
10734
+ const rm = t.closest("[data-rm]");
10735
+ if (rm) return rack.removePreset(Number(rm.dataset.rm));
10736
+ if (t.closest("[data-tpl]")) {
10737
+ const p = rack.snapshot().persona;
10738
+ rack.set({ profile: qs(p.profile, br, p.name) });
10739
+ return draw();
10740
+ }
10741
+ if (t.closest("[data-export]")) {
10742
+ const p = rack.snapshot().persona;
10743
+ return download(`${(p.name || "persona").replace(/[^a-z0-9]+/gi, "-").toLowerCase()}.persona.json`, JSON.stringify({
10744
+ v: 1,
10745
+ name: p.name,
10746
+ prompt: p.profile,
10747
+ notes: p.notes,
10748
+ rules: p.rules,
10749
+ ...p.first ? { first: p.first } : {}
10750
+ }, null, 2), "application/json");
10751
+ }
10752
+ if (t.closest("[data-import]")) file.click();
10753
+ });
10754
+ l.on(file, "change", () => {
10755
+ const f = file.files?.[0];
10756
+ file.value = "";
10757
+ if (!f) return;
10758
+ f.text().then((t) => {
10759
+ try {
10760
+ const j = JSON.parse(t);
10761
+ const profile = typeof j.prompt === "string" ? j.prompt : typeof j.system_prompt === "string" ? j.system_prompt : typeof j.description === "string" ? j.description : "";
10762
+ if (!profile && typeof j.name !== "string") throw new Error("no name or prompt in it");
10763
+ err = "";
10764
+ rack.set({
10765
+ name: String(j.name ?? "assistant"),
10766
+ profile,
10767
+ notes: String(j.notes ?? ""),
10768
+ rules: String(j.rules ?? ""),
10769
+ ...typeof j.first === "string" ? { first: j.first } : {}
10770
+ });
10771
+ } catch (e2) {
10772
+ err = `that file is not a persona: ${e2 instanceof Error ? e2.message : String(e2)}`;
10773
+ }
10774
+ draw();
10775
+ });
10776
+ });
10777
+ l.add(rack.subscribe(draw));
10778
+ return { dispose: () => l.off() };
10779
+ }
10780
+ /** The voice row: auto speak, voice, rate, pitch, test and stop. */
10781
+ function mountVoiceRow(host, row, o = {}) {
10782
+ const l = listeners();
10783
+ const draw = () => {
10784
+ if (host.contains(document.activeElement) && document.activeElement.matches("input[type=range]")) return;
10785
+ const s = row.snapshot();
10786
+ host.innerHTML = `<div class="hb-panel"><label class="hb-check"><input type="checkbox" data-auto${s.auto ? " checked" : ""}> speak each reply</label><div class="hb-field"><span class="hb-field-head"><label class="hb-label" for="vr-voice">voice</label></span><select id="vr-voice" class="hb-select" data-voice><option value="">system default</option>${s.voices.map((v) => `<option${v === s.voice ? " selected" : ""}>${esc(v)}</option>`).join("")}</select></div><div class="hb-slider"><span class="hb-label">rate</span><span class="hb-readout">${s.rate.toFixed(1)}</span><input type="range" min="0.5" max="2" step="0.1" value="${s.rate}" data-rate aria-label="rate"></div><div class="hb-slider"><span class="hb-label">pitch</span><span class="hb-readout">${s.pitch.toFixed(1)}</span><input type="range" min="0" max="2" step="0.1" value="${s.pitch}" data-pitch aria-label="pitch"></div><div class="hb-toolbar">${s.speaking ? `<button type="button" class="hb-btn hb-btn-sm" data-stop>stop</button>` : `<button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-test>test</button>`}</div>${s.error ? `<p class="hb-error" role="alert">${esc(s.error)}</p>` : ""}</div>`;
10787
+ };
10788
+ l.on(host, "input", (e) => {
10789
+ const t = e.target;
10790
+ if (t.matches("[data-rate]")) row.set({ rate: Number(t.value) });
10791
+ else if (t.matches("[data-pitch]")) row.set({ pitch: Number(t.value) });
10792
+ const r = t.parentElement?.querySelector(".hb-readout");
10793
+ if (r && t.type === "range") r.textContent = Number(t.value).toFixed(1);
10794
+ });
10795
+ l.on(host, "change", (e) => {
10796
+ const t = e.target;
10797
+ if (t.matches("[data-auto]")) row.set({ auto: t.checked });
10798
+ else if (t.matches("[data-voice]")) row.set({ voice: t.value });
10799
+ else if (t.type === "range") draw();
10800
+ });
10801
+ l.on(host, "click", (e) => {
10802
+ const t = e.target;
10803
+ if (t.closest("[data-test]")) row.speak(o.test ?? "this is how replies will sound.");
10804
+ else if (t.closest("[data-stop]")) row.stop();
10805
+ });
10806
+ l.add(row.subscribe(draw));
10807
+ return { dispose: () => (row.stop(), l.off()) };
10808
+ }
10809
+ /** The voice clone row of a speaker: clone from an audio file, record `seconds` of mic, download the clone as wav, clear it. */
10810
+ function mountVoiceClone(host, sp, o = {}) {
10811
+ const l = listeners();
10812
+ const secs = o.seconds ?? 10;
10813
+ const file = document.createElement("input");
10814
+ file.type = "file";
10815
+ file.accept = "audio/*";
10816
+ file.hidden = true;
10817
+ const box = document.createElement("div");
10818
+ host.replaceChildren(box, file);
10819
+ let note = "";
10820
+ let busy = false;
10821
+ const draw = () => {
10822
+ const can = o.can?.() ?? true;
10823
+ box.innerHTML = `<div>` + (can ? `<div class="hb-toolbar" role="group" aria-label="voice clone"><button type="button" class="hb-btn hb-btn-sm" data-file${busy ? " disabled" : ""}>clone from audio file</button><button type="button" class="hb-btn hb-btn-sm" data-rec${busy ? " disabled" : ""}>record ${secs} s</button>${sp.cloned ? `<button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-wav>download clone, wav</button><button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-clear>clear clone</button>` : ""}</div>` : "") + `<p class="hb-note" role="status">${esc(note || (can ? o.hint ?? `clones a voice from ${secs} s of audio. nothing leaves this tab.` : "this voice cannot clone. load pocket in the voice list."))}</p></div>`;
10824
+ };
10825
+ const fail = (err) => {
10826
+ const name = err.name ?? "";
10827
+ note = name === "NotAllowedError" || name === "SecurityError" ? "the mic is blocked. allow it in the address bar, or clone from a file." : err instanceof Error ? err.message : String(err);
10828
+ };
10829
+ l.on(box, "click", (e) => {
10830
+ const t = e.target;
10831
+ if (t.closest("[data-file]")) return file.click();
10832
+ if (t.closest("[data-wav]")) {
10833
+ const w = sp.cloneWav();
10834
+ if (w) download("voice-clone.wav", w, "audio/wav");
10835
+ return;
10836
+ }
10837
+ if (t.closest("[data-clear]")) {
10838
+ sp.clearClone();
10839
+ note = "clone cleared. the voice is its own again.";
10840
+ return draw();
10841
+ }
10842
+ if (t.closest("[data-rec]") && !busy) {
10843
+ busy = true;
10844
+ sp.cloneMic(secs, (left) => (note = `recording, ${left} s left`, draw())).then((s) => note = `cloned from ${s.toFixed(1)} s of your mic.`, fail).finally(() => (busy = false, draw()));
10845
+ }
10846
+ });
10847
+ l.on(file, "change", () => {
10848
+ const f = file.files?.[0];
10849
+ file.value = "";
10850
+ if (!f) return;
10851
+ busy = true;
10852
+ note = "cloning...";
10853
+ draw();
10854
+ sp.cloneFile(f).then((s) => note = `cloned from ${s.toFixed(1)} s of ${f.name}.`, fail).finally(() => (busy = false, draw()));
10855
+ });
10856
+ l.add(sp.subscribe(draw));
10857
+ draw();
10858
+ return { dispose: () => l.off() };
10859
+ }
10860
+ /** The session menu of a chat list: clear the open chat, export it as markdown, every chat as json, and import. */
10861
+ function mountSessionMenu(host, list, o = {}) {
10862
+ const l = listeners();
10863
+ const file = document.createElement("input");
10864
+ file.type = "file";
10865
+ file.accept = ".json,application/json";
10866
+ file.hidden = true;
10867
+ const box = document.createElement("div");
10868
+ host.replaceChildren(box, file);
10869
+ let armed = false;
10870
+ let note = "";
10871
+ const draw = () => {
10872
+ const has = list.thread.snapshot().turns.length > 0;
10873
+ box.innerHTML = `<div class="hb-toolbar" role="group" aria-label="session">${has ? `<button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-md>save as markdown</button>` : ""}<button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-json>export chats</button><button type="button" class="hb-btn hb-btn-2 hb-btn-sm" data-import>import chats</button>${has ? `<button type="button" class="hb-btn hb-btn-2 hb-btn-sm${armed ? " is-armed" : ""}" data-clear>${armed ? "clear this chat?" : "clear"}</button>` : ""}</div>${note ? `<p class="hb-note" role="status">${esc(note)}</p>` : ""}`;
10874
+ };
10875
+ l.on(box, "click", (e) => {
10876
+ const t = e.target;
10877
+ const day = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
10878
+ if (t.closest("[data-md]")) return download(`chat-${day}.md`, list.thread.markdown(), "text/markdown");
10879
+ if (t.closest("[data-json]")) return download(`chats-${day}.json`, JSON.stringify(list.dump(), null, 2), "application/json");
10880
+ if (t.closest("[data-import]")) return file.click();
10881
+ if (t.closest("[data-clear]")) {
10882
+ if (!armed) return armed = true, draw();
10883
+ armed = false;
10884
+ list.thread.clear();
10885
+ }
10886
+ });
10887
+ l.on(file, "change", () => {
10888
+ const f = file.files?.[0];
10889
+ file.value = "";
10890
+ if (!f) return;
10891
+ f.text().then((t) => {
10892
+ try {
10893
+ const data = JSON.parse(t);
10894
+ list.restore(data);
10895
+ note = `${data.chats.length} chat${data.chats.length === 1 ? "" : "s"} imported.`;
10896
+ o.onImport?.(data.chats.length);
10897
+ } catch (err) {
10898
+ note = `that file did not import: ${err instanceof Error ? err.message : String(err)}`;
10899
+ }
10900
+ draw();
10901
+ });
10902
+ });
10903
+ l.add(list.subscribe(() => draw()));
10904
+ return { dispose: () => l.off() };
10905
+ }
10249
10906
  // packages/ai-views/src/mount-mask.ts
10250
10907
  /**
10251
10908
  * MaskStudio: drop an image, press a thing
@@ -10255,7 +10912,11 @@ function mountTranscriptExports(host, queue, o = {}) {
10255
10912
  * export the mask, a matte or the cutout. With a segment everything model
10256
10913
  * (FastSAM) one press finds every object; each lands in the found list and
10257
10914
  * a press adds it to the mask. Models are functions the page passes, so
10258
- * stubs run the studio with no weights.
10915
+ * stubs run the studio with no weights. Three views (composite, mask,
10916
+ * found objects) paint over the canvas; the pointer previews the click cut
10917
+ * or lights the found object under it; two fingers or ctrl and the wheel
10918
+ * zoom; a page that loads models on demand hears `onWant` when a tool needs
10919
+ * one.
10259
10920
  */
10260
10921
  const ZOOMS = [
10261
10922
  .5,
@@ -10266,6 +10927,25 @@ const ZOOMS = [
10266
10927
  3,
10267
10928
  4
10268
10929
  ];
10930
+ const clampZoom = (z) => Math.max(.25, Math.min(6, z));
10931
+ /** Paint `rgb` at `alpha` (0 to 255) where the mask keeps, leaving the other pixels as they are. */
10932
+ function tintInto(rgba, mask, rgb, alpha) {
10933
+ for (let i = 0, j = 0; i < mask.length; i++, j += 4) {
10934
+ if (!mask[i]) continue;
10935
+ rgba[j] = rgb[0];
10936
+ rgba[j + 1] = rgb[1];
10937
+ rgba[j + 2] = rgb[2];
10938
+ rgba[j + 3] = alpha;
10939
+ }
10940
+ }
10941
+ /** ImageData to a png Blob. */
10942
+ function pngOf(img) {
10943
+ const c = document.createElement("canvas");
10944
+ c.width = img.width;
10945
+ c.height = img.height;
10946
+ c.getContext("2d")?.putImageData(img, 0, 0);
10947
+ return new Promise((ok) => c.toBlob((b) => ok(b), "image/png"));
10948
+ }
10269
10949
  /** Pixels of a drawable, for a model. */
10270
10950
  function pixelsOf(src) {
10271
10951
  const c = document.createElement("canvas");
@@ -10299,17 +10979,22 @@ function thumbOf(img) {
10299
10979
  function mountMaskStudio(host, o = {}) {
10300
10980
  let models = o.models ?? {};
10301
10981
  const l = listeners();
10302
- host.innerHTML = `<div class="hb-lay-empty" data-empty><span class="hb-lay-empty-name">${esc(o.title ?? "drop an image")}</span><p class="hb-lay-empty-note">${esc(o.note ?? "press a thing to cut it out. the picture stays on this machine.")}</p><div class="hb-lay-empty-acts"><button type="button" class="hb-btn hb-btn-go" data-pick>open an image</button>${o.sampleLabel ? `<button type="button" class="hb-btn" data-sample>${esc(o.sampleLabel)}</button>` : ""}</div></div><div class="hb-mask is-fill" data-studio hidden><div class="hb-mask-well"><div class="hb-mask-frame"><canvas class="hb-mask-canvas" tabindex="0" role="img" aria-label="image and mask"></canvas><p class="hb-mask-hint" aria-live="polite"></p></div></div></div><input type="file" accept="image/*" hidden>`;
10982
+ host.innerHTML = `<div class="hb-lay-empty" data-empty><span class="hb-lay-empty-name">${esc(o.title ?? "drop an image")}</span><p class="hb-lay-empty-note">${esc(o.note ?? "press a thing to cut it out. the picture stays on this machine.")}</p><div class="hb-lay-empty-acts"><button type="button" class="hb-btn hb-btn-go" data-pick>open an image</button>${o.sampleLabel ? `<button type="button" class="hb-btn" data-sample>${esc(o.sampleLabel)}</button>` : ""}</div></div><div class="hb-mask is-fill" data-studio hidden><div class="hb-mask-well"><div class="hb-mask-frame"><canvas class="hb-mask-canvas" tabindex="0" role="img" aria-label="image and mask"></canvas><canvas class="hb-pc-img" data-over aria-hidden="true"></canvas><p class="hb-mask-hint" aria-live="polite"></p></div></div></div><input type="file" accept="image/*" hidden>`;
10303
10983
  const empty = host.querySelector("[data-empty]");
10304
10984
  const studio = host.querySelector("[data-studio]");
10305
10985
  const well = host.querySelector(".hb-mask-well");
10306
10986
  host.querySelector(".hb-mask-frame");
10307
- const canvas = host.querySelector("canvas");
10987
+ const canvas = host.querySelector(".hb-mask-canvas");
10988
+ const over = host.querySelector("[data-over]");
10308
10989
  const hint = host.querySelector(".hb-mask-hint");
10309
10990
  const input = host.querySelector("input[type=file]");
10310
10991
  const subs = /* @__PURE__ */ new Set();
10311
10992
  let tool = models.segment ? "point" : "wand";
10312
10993
  let zoom = 1;
10994
+ let view = "composite";
10995
+ let hover = -1;
10996
+ let preview = null;
10997
+ let wantAll = null;
10313
10998
  let busy = "";
10314
10999
  let error = "";
10315
11000
  let pixels = null;
@@ -10328,6 +11013,9 @@ function mountMaskStudio(host, o = {}) {
10328
11013
  coverage: ed?.coverage ?? 0,
10329
11014
  zoom,
10330
11015
  busy,
11016
+ contiguous: ed?.contiguous ?? true,
11017
+ view,
11018
+ hover,
10331
11019
  found,
10332
11020
  saved: saved.map(({ bytes: _b, ...rest }) => rest),
10333
11021
  width: ed?.width ?? 0,
@@ -10336,10 +11024,61 @@ function mountMaskStudio(host, o = {}) {
10336
11024
  });
10337
11025
  const emit = () => {
10338
11026
  const s = state();
10339
- hint.textContent = s.busy || s.error || (tool === "point" ? "press a thing to cut it out. x takes it away instead." : ft.find((t) => t.id === tool)?.hint ?? "");
11027
+ hint.textContent = s.busy || s.error || (tool === "point" ? "press a thing to cut it out. x takes it away instead." : gt.find((t) => t.id === tool)?.hint ?? "");
10340
11028
  for (const fn of subs) fn(s);
11029
+ paint();
11030
+ };
11031
+ let painted = "";
11032
+ let frameReq = 0;
11033
+ const paint = () => {
11034
+ if (frameReq) return;
11035
+ frameReq = typeof requestAnimationFrame === "function" ? requestAnimationFrame(drawOver) : (drawOver(), 0);
11036
+ };
11037
+ const drawOver = () => {
11038
+ frameReq = 0;
11039
+ const w = ed?.width ?? 0;
11040
+ const h = ed?.height ?? 0;
11041
+ const g = over.getContext("2d");
11042
+ if (!g || !w || !h || !pixels) return;
11043
+ if (over.width !== w || over.height !== h) {
11044
+ over.width = w;
11045
+ over.height = h;
11046
+ }
11047
+ const key = `${view}:${hover}:${preview ? "p" : ""}:${view === "mask" ? editor.state.coverage + ":" + (ed?.canUndo ? 1 : 0) : ""}:${found.map((f) => f.hidden ? 0 : 1).join("")}`;
11048
+ if (view === "composite" && hover < 0 && !preview) {
11049
+ if (painted !== "clear") g.clearRect(0, 0, w, h);
11050
+ painted = "clear";
11051
+ return;
11052
+ }
11053
+ if (key === painted && view !== "mask") return;
11054
+ painted = key;
11055
+ if (view === "mask") {
11056
+ g.putImageData(new ImageData(er(editor.mask(), "matte"), w, h), 0, 0);
11057
+ return;
11058
+ }
11059
+ const rgba = new Uint8ClampedArray(w * h * 4);
11060
+ if (view === "instances") found.forEach((f, i) => !f.hidden && i !== hover && tintInto(rgba, f.mask, nr(f.colour), 150));
11061
+ const hot = hover >= 0 ? found[hover] : void 0;
11062
+ if (hot) tintInto(rgba, hot.mask, nr(hot.colour), 220);
11063
+ else if (preview) tintInto(rgba, preview, [
11064
+ 254,
11065
+ 3,
11066
+ 134
11067
+ ], 110);
11068
+ g.putImageData(new ImageData(rgba, w, h), 0, 0);
11069
+ if (view === "instances") {
11070
+ g.lineWidth = Math.max(1, w / 400);
11071
+ g.font = `${Math.max(10, Math.round(w / 60))}px monospace`;
11072
+ for (const f of found) {
11073
+ if (f.hidden || !f.box) continue;
11074
+ g.strokeStyle = f.colour;
11075
+ g.fillStyle = f.colour;
11076
+ g.strokeRect(f.box.x, f.box.y, f.box.w, f.box.h);
11077
+ g.fillText(`${f.label} ${Math.round(f.score * 100)}`, f.box.x + 3, Math.max(12, f.box.y - 4));
11078
+ }
11079
+ }
10341
11080
  };
10342
- const editor = Wi(canvas, {
11081
+ const editor = ns(canvas, {
10343
11082
  tool: tool === "point" ? "wand" : tool,
10344
11083
  onError: (e) => (error = `the image did not load: ${e.message}`, emit())
10345
11084
  });
@@ -10351,6 +11090,7 @@ function mountMaskStudio(host, o = {}) {
10351
11090
  studio.style.setProperty("--hb-mask-w", `${Math.round(fitW * zoom)}px`);
10352
11091
  studio.classList.toggle("is-zoomed", zoom > 1);
10353
11092
  };
11093
+ const zoomStep = (dir) => (dir > 0 ? ZOOMS.find((z) => z > zoom + .001) : [...ZOOMS].reverse().find((z) => z < zoom - .001)) ?? zoom;
10354
11094
  const ro = typeof ResizeObserver === "function" ? new ResizeObserver(() => applyZoom()) : null;
10355
11095
  ro?.observe(well);
10356
11096
  l.add(() => ro?.disconnect());
@@ -10375,17 +11115,130 @@ function mountMaskStudio(host, o = {}) {
10375
11115
  emit();
10376
11116
  }
10377
11117
  };
11118
+ const at = (pe) => {
11119
+ const r = canvas.getBoundingClientRect();
11120
+ const w = ed?.width ?? 0;
11121
+ const h = ed?.height ?? 0;
11122
+ return {
11123
+ x: Math.max(0, Math.min(w - 1, Math.round((pe.clientX - r.left) / r.width * w))),
11124
+ y: Math.max(0, Math.min(h - 1, Math.round((pe.clientY - r.top) / r.height * h)))
11125
+ };
11126
+ };
11127
+ const foundAt = (x, y) => found.findIndex((f) => !f.hidden && f.mask[y * (ed?.width ?? 0) + x]);
10378
11128
  const onPoint = (e) => {
10379
11129
  if (tool !== "point") return;
10380
11130
  e.stopImmediatePropagation();
10381
11131
  e.preventDefault();
10382
11132
  const pe = e;
10383
- const r = canvas.getBoundingClientRect();
10384
11133
  if (!ed?.ready) return;
10385
- const x = Math.round((pe.clientX - r.left) / r.width * ed.width);
10386
- const y = Math.round((pe.clientY - r.top) / r.height * ed.height);
11134
+ const { x, y } = at(pe);
11135
+ const i = foundAt(x, y);
11136
+ if (i >= 0) return studioApi.toggleFound(i);
11137
+ if (!models.segment) return o.onWant?.("segment");
11138
+ preview = null;
10387
11139
  cut(x, y, ed.mode === "erase" !== pe.shiftKey);
10388
11140
  };
11141
+ let asking = false;
11142
+ let next = null;
11143
+ const ask = async (p) => {
11144
+ if (!pixels || !models.segment) return;
11145
+ asking = true;
11146
+ try {
11147
+ const m = await models.segment(pixels, p);
11148
+ if (tool === "point" && next !== null) preview = m;
11149
+ } catch {
11150
+ preview = null;
11151
+ } finally {
11152
+ asking = false;
11153
+ }
11154
+ paint();
11155
+ const n = next;
11156
+ if (n && (n.x !== p.x || n.y !== p.y)) ask(n);
11157
+ };
11158
+ const onHover = (e) => {
11159
+ const pe = e;
11160
+ if (!ed?.ready || pe.buttons || pe.pointerType === "touch") return;
11161
+ const p = at(pe);
11162
+ const i = found.length && (tool === "point" || view === "instances") ? foundAt(p.x, p.y) : -1;
11163
+ if (i !== hover) {
11164
+ hover = i;
11165
+ emit();
11166
+ }
11167
+ if (i >= 0 || tool !== "point" || !models.segment) {
11168
+ next = null;
11169
+ if (preview) preview = null, paint();
11170
+ return;
11171
+ }
11172
+ next = p;
11173
+ if (!asking) ask(p);
11174
+ };
11175
+ const offHover = () => {
11176
+ next = null;
11177
+ preview = null;
11178
+ if (hover >= 0) hover = -1, emit();
11179
+ else paint();
11180
+ };
11181
+ canvas.addEventListener("pointermove", onHover);
11182
+ canvas.addEventListener("pointerleave", offHover);
11183
+ l.add(() => (canvas.removeEventListener("pointermove", onHover), canvas.removeEventListener("pointerleave", offHover)));
11184
+ const touches = /* @__PURE__ */ new Map();
11185
+ let pinch = null;
11186
+ const spread = () => {
11187
+ const [a, b] = [...touches.values()];
11188
+ return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : 0;
11189
+ };
11190
+ l.on(well, "pointerdown", (e) => {
11191
+ const pe = e;
11192
+ if (pe.pointerType !== "touch") return;
11193
+ touches.set(pe.pointerId, {
11194
+ x: pe.clientX,
11195
+ y: pe.clientY
11196
+ });
11197
+ if (touches.size === 2) {
11198
+ editor.cancel();
11199
+ pinch = {
11200
+ d: spread() || 1,
11201
+ z: zoom
11202
+ };
11203
+ }
11204
+ });
11205
+ l.on(well, "pointermove", (e) => {
11206
+ const pe = e;
11207
+ if (!touches.has(pe.pointerId)) return;
11208
+ touches.set(pe.pointerId, {
11209
+ x: pe.clientX,
11210
+ y: pe.clientY
11211
+ });
11212
+ if (pinch && touches.size === 2) studioApi.zoomTo(pinch.z * (spread() / pinch.d));
11213
+ });
11214
+ const lift = (e) => {
11215
+ touches.delete(e.pointerId);
11216
+ if (touches.size < 2) pinch = null;
11217
+ };
11218
+ l.on(well, "pointerup", lift);
11219
+ l.on(well, "pointercancel", lift);
11220
+ l.on(well, "wheel", (e) => {
11221
+ const we = e;
11222
+ if (!we.ctrlKey || !ed?.ready) return;
11223
+ we.preventDefault();
11224
+ studioApi.zoomTo(zoom * Math.exp(-we.deltaY / 200));
11225
+ });
11226
+ l.on(document, "keydown", (e) => {
11227
+ const ke = e;
11228
+ if (ke.defaultPrevented || ke.target.closest?.("input,textarea,select,[contenteditable]")) return;
11229
+ const k = ke.key.toLowerCase();
11230
+ const cmd = ke.ctrlKey || ke.metaKey;
11231
+ if (cmd && k === "o") return ke.preventDefault(), input.click();
11232
+ if (!ed?.ready) return;
11233
+ if (cmd && (k === "z" || k === "y")) return ke.preventDefault(), void (k === "y" || ke.shiftKey ? editor.redo() : editor.undo());
11234
+ if (cmd && k === "s") return ke.preventDefault(), void studioApi.exportAs(ke.shiftKey ? "cutout" : "matte").then((b) => b && download(`${o.name ?? "mask"}-${ke.shiftKey ? "cutout" : "matte"}.png`, b));
11235
+ if (cmd && k === "i") return ke.preventDefault(), editor.invert();
11236
+ if (cmd) return;
11237
+ if (k === "delete") return ke.preventDefault(), editor.clear();
11238
+ if (k === "+" || k === "=") return studioApi.zoom(1);
11239
+ if (k === "-") return studioApi.zoom(-1);
11240
+ if (k === "0") return studioApi.zoom(0);
11241
+ });
10389
11242
  canvas.addEventListener("pointerdown", onPoint, true);
10390
11243
  l.add(() => canvas.removeEventListener("pointerdown", onPoint, true));
10391
11244
  const take = (f) => {
@@ -10412,6 +11265,8 @@ function mountMaskStudio(host, o = {}) {
10412
11265
  error = "";
10413
11266
  found = [];
10414
11267
  saved = [];
11268
+ hover = -1;
11269
+ preview = null;
10415
11270
  let drawable = null;
10416
11271
  if (typeof src === "string") {
10417
11272
  const img = new Image();
@@ -10431,8 +11286,12 @@ function mountMaskStudio(host, o = {}) {
10431
11286
  canvas.focus({ preventScroll: true });
10432
11287
  },
10433
11288
  setTool(t) {
10434
- if (t === "point" && !models.segment) return;
11289
+ if (t === "point" && !models.segment) {
11290
+ if (!o.onWant) return;
11291
+ o.onWant("segment");
11292
+ }
10435
11293
  tool = t;
11294
+ preview = null;
10436
11295
  if (t !== "point") editor.setTool(t);
10437
11296
  canvas.dataset.tool = t;
10438
11297
  emit();
@@ -10470,25 +11329,83 @@ function mountMaskStudio(host, o = {}) {
10470
11329
  },
10471
11330
  mask: (kind = "alpha") => ed?.ready ? editor.toImageData(kind) : null,
10472
11331
  zoom(dir) {
10473
- if (dir === 0) zoom = 1;
10474
- else {
10475
- const i = ZOOMS.indexOf(zoom);
10476
- zoom = ZOOMS[Math.max(0, Math.min(ZOOMS.length - 1, i + dir))];
10477
- }
11332
+ zoom = dir === 0 ? 1 : zoomStep(dir);
10478
11333
  applyZoom();
10479
11334
  emit();
10480
11335
  },
10481
- async everything() {
10482
- if (!models.everything || !pixels) return;
11336
+ zoomTo(z) {
11337
+ zoom = clampZoom(z);
11338
+ applyZoom();
11339
+ emit();
11340
+ },
11341
+ setView(v) {
11342
+ view = v;
11343
+ emit();
11344
+ },
11345
+ setContiguous: (on) => editor.setContiguous(on),
11346
+ setMask(m) {
11347
+ if (ed?.ready && m.length === ed.width * ed.height) editor.setMask(m);
11348
+ },
11349
+ addFound(list) {
11350
+ const n = found.length;
11351
+ found = [...found, ...list.filter((f) => f.mask.length === (ed?.width ?? 0) * (ed?.height ?? 0)).map((f, i) => ({
11352
+ ...f,
11353
+ on: false,
11354
+ hidden: false,
11355
+ colour: ht[(n + i) % ht.length]
11356
+ }))];
11357
+ if (found.length > n && view === "composite") view = "instances";
11358
+ emit();
11359
+ },
11360
+ showFound(i, on) {
11361
+ found = found.map((x, k) => k === i ? {
11362
+ ...x,
11363
+ hidden: !on
11364
+ } : x);
11365
+ emit();
11366
+ },
11367
+ removeFound(i) {
11368
+ found = found.filter((_, k) => k !== i);
11369
+ hover = -1;
11370
+ emit();
11371
+ },
11372
+ mergeFound() {
11373
+ if (!ed?.ready || !found.length) return;
11374
+ const cur = editor.mask();
11375
+ for (const f of found) if (!f.hidden) {
11376
+ for (let p = 0; p < cur.length; p++) if (f.mask[p]) cur[p] = 255;
11377
+ }
11378
+ found = found.map((x) => x.hidden ? x : {
11379
+ ...x,
11380
+ on: true
11381
+ });
11382
+ editor.setMask(cur);
11383
+ },
11384
+ clearFound() {
11385
+ found = [];
11386
+ hover = -1;
11387
+ if (view === "instances") view = "composite";
11388
+ emit();
11389
+ },
11390
+ pixels: () => pixels,
11391
+ async everything(eo) {
11392
+ if (!pixels) return;
11393
+ if (!models.everything) {
11394
+ wantAll = eo ?? {};
11395
+ return o.onWant?.("everything");
11396
+ }
11397
+ wantAll = null;
10483
11398
  busy = "finding every object";
10484
11399
  error = "";
10485
11400
  emit();
10486
11401
  try {
10487
- found = (await models.everything(pixels)).map((f, i) => ({
11402
+ found = (await models.everything(pixels, eo)).map((f, i) => ({
10488
11403
  ...f,
10489
11404
  on: false,
10490
- colour: ut[i % ut.length]
11405
+ hidden: false,
11406
+ colour: ht[i % ht.length]
10491
11407
  }));
11408
+ if (found.length) view = "instances";
10492
11409
  } catch (e) {
10493
11410
  error = `segment everything failed: ${e instanceof Error ? e.message : String(e)}`;
10494
11411
  } finally {
@@ -10510,6 +11427,7 @@ function mountMaskStudio(host, o = {}) {
10510
11427
  },
10511
11428
  async exportAs(kind) {
10512
11429
  if (!ed?.ready) return null;
11430
+ if (kind === "inverse") return pngOf(new ImageData(er(Jn(editor.mask()), "matte"), ed.width, ed.height));
10513
11431
  return editor.toBlob(kind);
10514
11432
  },
10515
11433
  get hasEverything() {
@@ -10518,6 +11436,9 @@ function mountMaskStudio(host, o = {}) {
10518
11436
  get hasSegment() {
10519
11437
  return !!models.segment;
10520
11438
  },
11439
+ get canWant() {
11440
+ return !!o.onWant;
11441
+ },
10521
11442
  state,
10522
11443
  subscribe(fn) {
10523
11444
  subs.add(fn);
@@ -10531,8 +11452,9 @@ function mountMaskStudio(host, o = {}) {
10531
11452
  tool = "point";
10532
11453
  canvas.dataset.tool = "point";
10533
11454
  }
10534
- if (tool === "point" && !m.segment) studioApi.setTool("wand");
11455
+ if (tool === "point" && !m.segment && !o.onWant) studioApi.setTool("wand");
10535
11456
  emit();
11457
+ if (wantAll && m.everything) studioApi.everything(wantAll);
10536
11458
  },
10537
11459
  pick: () => input.click(),
10538
11460
  dispose() {
@@ -10549,17 +11471,17 @@ function mountMaskStudio(host, o = {}) {
10549
11471
  function mountMaskTools(host, studio) {
10550
11472
  const l = listeners();
10551
11473
  const draw = (s) => {
10552
- host.innerHTML = [...studio.hasSegment ? [{
11474
+ host.innerHTML = [...studio.hasSegment || studio.canWant ? [{
10553
11475
  id: "point",
10554
11476
  label: "cut out a thing",
10555
11477
  key: "a",
10556
11478
  icon: "crosshairs"
10557
- }] : [], ...ft.map((t) => ({
11479
+ }] : [], ...gt.map((t) => ({
10558
11480
  id: t.id,
10559
11481
  label: t.label,
10560
11482
  key: t.key,
10561
11483
  icon: t.icon
10562
- }))].map((t) => `<button type="button" class="hb-iconbtn" data-tool="${t.id}" aria-label="${esc(t.label)} (${t.key})" title="${esc(t.label)} (${t.key})" aria-pressed="${s.tool === t.id}" aria-keyshortcuts="${t.key}">${Qt(t.icon, { size: 18 })}</button>`).join("");
11484
+ }))].map((t) => `<button type="button" class="hb-iconbtn" data-tool="${t.id}" aria-label="${esc(t.label)} (${t.key})" title="${esc(t.label)} (${t.key})" aria-pressed="${s.tool === t.id}" aria-keyshortcuts="${t.key}">${rn(t.icon, { size: 18 })}</button>`).join("");
10563
11485
  };
10564
11486
  l.on(host, "click", (e) => {
10565
11487
  const t = e.target.closest("[data-tool]");
@@ -10567,12 +11489,7 @@ function mountMaskTools(host, studio) {
10567
11489
  });
10568
11490
  l.on(document, "keydown", (e) => {
10569
11491
  const ke = e;
10570
- if (!!!ke.target.closest?.("input,textarea,[contenteditable]") && !ke.ctrlKey && !ke.metaKey && studio.state().ready) {
10571
- if (ke.key === "+" || ke.key === "=") return studio.zoom(1);
10572
- if (ke.key === "-") return studio.zoom(-1);
10573
- if (ke.key === "0") return studio.zoom(0);
10574
- }
10575
- if (ke.key === "a" && !ke.ctrlKey && !ke.metaKey && studio.hasSegment && !ke.target.closest?.("input,textarea,[contenteditable]")) studio.setTool("point");
11492
+ if (ke.key === "a" && !ke.ctrlKey && !ke.metaKey && (studio.hasSegment || studio.canWant) && !ke.target.closest?.("input,textarea,[contenteditable]")) studio.setTool("point");
10576
11493
  });
10577
11494
  l.add(studio.subscribe(draw));
10578
11495
  return { dispose: () => l.off() };
@@ -10582,11 +11499,17 @@ function mountMaskVerbs(host, studio) {
10582
11499
  const l = listeners();
10583
11500
  let last = "";
10584
11501
  const draw = (s) => {
10585
- const html = s.ready ? `${s.canUndo ? `<button type="button" class="hb-iconbtn" data-v="undo" aria-label="undo" title="undo (ctrl z)">${ICON.undo}</button>` : ""}${s.canRedo ? `<button type="button" class="hb-iconbtn" data-v="redo" aria-label="redo" title="redo (ctrl shift z)">${ICON.redo}</button>` : ""}` + (s.zoom !== 1 ? `<button type="button" class="hb-iconbtn" data-v="out" aria-label="zoom out" title="zoom out (-)">${ICON.zoomOut}</button><button type="button" class="hb-iconbtn" data-v="fit" aria-label="fit, now ${Math.round(s.zoom * 100)} percent" title="fit (0)">${ICON.fit}</button>` : "") + `<button type="button" class="hb-iconbtn" data-v="in" aria-label="zoom in" title="zoom in (+)">${ICON.zoomIn}</button>` : "";
11502
+ const html = s.ready ? `${s.canUndo ? `<button type="button" class="hb-iconbtn" data-v="undo" aria-label="undo" title="undo (ctrl z)">${ICON.undo}</button>` : ""}${s.canRedo ? `<button type="button" class="hb-iconbtn" data-v="redo" aria-label="redo" title="redo (ctrl shift z)">${ICON.redo}</button>` : ""}` + (s.zoom !== 1 ? `<button type="button" class="hb-iconbtn" data-v="out" aria-label="zoom out" title="zoom out (-)">${ICON.zoomOut}</button><button type="button" class="hb-iconbtn" data-v="fit" aria-label="fit, now ${Math.round(s.zoom * 100)} percent" title="fit (0)">${ICON.fit}</button>` : "") + `<button type="button" class="hb-iconbtn" data-v="in" aria-label="zoom in" title="zoom in (+)">${ICON.zoomIn}</button>` + (s.coverage > 0 || s.found.length ? `<div class="hb-seg is-toggle" role="group" aria-label="view">${[
11503
+ "composite",
11504
+ "mask",
11505
+ "instances"
11506
+ ].filter((v) => v !== "instances" || s.found.length).map((v) => `<button type="button" data-view="${v}" class="${s.view === v ? "is-on" : ""}" aria-pressed="${s.view === v}">${v === "instances" ? "objects" : v === "composite" ? "picture" : "mask"}</button>`).join("")}</div>` : "") : "";
10586
11507
  if (html !== last) host.innerHTML = last = html;
10587
11508
  host.hidden = !html;
10588
11509
  };
10589
11510
  l.on(host, "click", (e) => {
11511
+ const view = e.target.closest("[data-view]")?.dataset.view;
11512
+ if (view) return studio.setView(view);
10590
11513
  const v = e.target.closest("[data-v]")?.dataset.v;
10591
11514
  if (v === "undo") studio.undo();
10592
11515
  else if (v === "redo") studio.redo();
@@ -10604,11 +11527,11 @@ function mountMaskRack(host, studio, part, o = {}) {
10604
11527
  const draw = (s) => {
10605
11528
  let html = "";
10606
11529
  if (part === "found") {
10607
- html = s.found.length ? `<div class="hb-inst"><ul class="hb-inst-list">${s.found.map((f, i) => `<li class="hb-inst-row${f.on ? " is-on" : ""}" style="--hb-inst-c:${f.colour}"><button type="button" class="hb-inst-pick" data-found="${i}" aria-pressed="${f.on}"><span class="hb-inst-sw"></span><span class="hb-inst-name">${esc(f.label)}</span><span class="hb-inst-score">${Math.round(f.score * 100)}%</span></button></li>`).join("")}</ul></div>` : `<p class="hb-lay-empty-note">${s.ready ? studio.hasEverything ? "find every object at once, or press a thing on the picture." : "press a thing to cut it out." : "nothing yet. open an image or try the sample."}</p>` + (s.ready && studio.hasEverything && !s.busy ? `<button type="button" class="hb-btn hb-btn-go" data-all>find every object</button>` : "");
11530
+ html = s.found.length ? `<div class="hb-inst"><p class="hb-inst-empty">${s.found.length} found, ${s.found.filter((f) => f.on).length} in the mask</p><div class="hb-toolbar hb-inst-foot"><button type="button" class="hb-btn hb-btn-go" data-op="merge">merge all</button><button type="button" class="hb-btn" data-op="unfind">clear all</button></div><ul class="hb-inst-list">${s.found.map((f, i) => `<li class="hb-inst-row${f.on || s.hover === i ? " is-on" : ""}${f.hidden ? " is-hidden" : ""}" style="--hb-inst-c:${f.colour}"><button type="button" class="hb-inst-pick" data-found="${i}" aria-pressed="${f.on}"><span class="hb-inst-sw"></span><span class="hb-inst-name">${esc(f.label)}</span><span class="hb-inst-score">${Math.min(100, Math.round(f.score * 100))}%</span></button><button type="button" class="hb-inst-act" data-show="${i}" aria-pressed="${!f.hidden}" aria-label="${f.hidden ? "show" : "hide"} ${esc(f.label)}" title="${f.hidden ? "show" : "hide"}">${rn("eye", { size: 14 })}</button><button type="button" class="hb-inst-act" data-drop="${i}" aria-label="delete ${esc(f.label)}" title="delete">${ICON.trash}</button></li>`).join("")}</ul></div>` : `<p class="hb-lay-empty-note">${s.ready ? studio.hasEverything || studio.canWant ? "find every object at once, or press a thing on the picture." : "press a thing to cut it out." : "nothing yet. open an image or try the sample."}</p>` + (s.ready && (studio.hasEverything || studio.canWant) && !s.busy ? `<button type="button" class="hb-btn hb-btn-go" data-all>find every object</button>` : "");
10608
11531
  html += s.ready ? `<div class="hb-kv"><span class="hb-label">mask keeps</span><span class="hb-readout">${Math.round(s.coverage * 100)}%</span></div>` : "";
10609
- } else if (part === "mask") html = `<div class="hb-seg is-toggle" role="group" aria-label="mode">${["add", "erase"].map((m) => `<button type="button" data-mode="${m}" class="${s.mode === m ? "is-on" : ""}" aria-pressed="${s.mode === m}">${m}<span class="hb-mask-key" aria-hidden="true">x</span></button>`).join("")}</div>` + (s.tool === "brush" || s.tool === "eraser" ? `<label class="hb-field"><span class="hb-label">brush, ${s.size} px</span><input class="hb-range" type="range" min="4" max="160" step="2" value="${s.size}" data-size></label>` : "") + (s.tool === "wand" || s.tool === "flood" ? `<label class="hb-field"><span class="hb-label">reach, ${s.tolerance}</span><input class="hb-range" type="range" min="0" max="100" step="1" value="${s.tolerance}" data-tol></label>` : "") + (s.coverage > 0 ? `<div class="hb-toolbar"><button type="button" class="hb-btn" data-op="smooth">smooth</button><button type="button" class="hb-btn" data-op="expand">expand</button><button type="button" class="hb-btn" data-op="shrink">shrink</button><button type="button" class="hb-btn" data-op="invert">invert</button><button type="button" class="hb-btn" data-op="clear">clear</button></div>` : "");
11532
+ } else if (part === "mask") html = `<div class="hb-seg is-toggle" role="group" aria-label="mode">${["add", "erase"].map((m) => `<button type="button" data-mode="${m}" class="${s.mode === m ? "is-on" : ""}" aria-pressed="${s.mode === m}">${m}<span class="hb-mask-key" aria-hidden="true">x</span></button>`).join("")}</div>` + (s.tool === "brush" || s.tool === "eraser" ? `<label class="hb-field"><span class="hb-label">brush, ${s.size} px</span><input class="hb-range" type="range" min="4" max="160" step="2" value="${s.size}" data-size></label>` : "") + (s.tool === "wand" || s.tool === "flood" ? `<label class="hb-field"><span class="hb-label">reach, ${s.tolerance}</span><input class="hb-range" type="range" min="0" max="100" step="1" value="${s.tolerance}" data-tol></label>` : "") + (s.tool === "wand" ? `<label class="hb-check"><input type="checkbox" data-contig${s.contiguous ? " checked" : ""}><span>touching pixels only</span></label>` : "") + (s.coverage > 0 ? `<div class="hb-toolbar"><button type="button" class="hb-btn" data-op="smooth">smooth</button><button type="button" class="hb-btn" data-op="expand">expand</button><button type="button" class="hb-btn" data-op="shrink">shrink</button><button type="button" class="hb-btn" data-op="invert">invert</button><button type="button" class="hb-btn" data-op="clear">clear</button></div>` : "");
10610
11533
  else if (part === "saved") html = (s.coverage > 0 ? `<div class="hb-toolbar"><button type="button" class="hb-btn" data-op="save">save this mask</button></div>` : "") + (s.saved.length ? `<div class="hb-inst"><ul class="hb-inst-list">${s.saved.map((m) => `<li class="hb-inst-row"><button type="button" class="hb-inst-pick" data-restore="${m.id}"><img class="hb-inst-sw" src="${m.thumb}" alt=""><span class="hb-inst-name">${esc(m.name)}</span><span class="hb-inst-score">${Math.round(m.coverage * 100)}%</span></button><button type="button" class="hb-inst-act" data-forget="${m.id}" aria-label="forget ${esc(m.name)}" title="forget">${ICON.x}</button></li>`).join("")}</ul></div>` : `<p class="hb-lay-empty-note">no saved masks. save one to come back to it.</p>`);
10611
- else html = s.coverage > 0 ? `<div class="hb-toolbar" role="group" aria-label="export"><button type="button" class="hb-btn" data-ex="cutout">cutout png</button><button type="button" class="hb-btn" data-ex="alpha">mask png</button><button type="button" class="hb-btn" data-ex="matte">matte png</button></div>` : `<p class="hb-lay-empty-note">exports show once there is a mask.</p>`;
11534
+ else html = s.coverage > 0 ? `<div class="hb-toolbar" role="group" aria-label="export"><button type="button" class="hb-btn" data-ex="cutout">cutout png</button><button type="button" class="hb-btn" data-ex="alpha">mask png</button><button type="button" class="hb-btn" data-ex="matte">matte png</button><button type="button" class="hb-btn" data-ex="inverse">inverse png</button></div>` : `<p class="hb-lay-empty-note">exports show once there is a mask.</p>`;
10612
11535
  if (html !== last) host.innerHTML = last = html;
10613
11536
  };
10614
11537
  l.on(host, "click", (e) => {
@@ -10617,7 +11540,13 @@ function mountMaskRack(host, studio, part, o = {}) {
10617
11540
  if (f) return studio.toggleFound(Number(f.dataset.found));
10618
11541
  const m = t.closest("[data-mode]");
10619
11542
  if (m) return studio.setMode(m.dataset.mode);
11543
+ const show = t.closest("[data-show]");
11544
+ if (show) return studio.showFound(Number(show.dataset.show), show.getAttribute("aria-pressed") !== "true");
11545
+ const drop = t.closest("[data-drop]");
11546
+ if (drop) return studio.removeFound(Number(drop.dataset.drop));
10620
11547
  const op = t.closest("[data-op]")?.dataset.op;
11548
+ if (op === "merge") return studio.mergeFound();
11549
+ if (op === "unfind") return studio.clearFound();
10621
11550
  if (op === "invert") return studio.invert();
10622
11551
  if (op === "clear") return studio.clear();
10623
11552
  if (op === "smooth") return studio.smooth();
@@ -10640,6 +11569,7 @@ function mountMaskRack(host, studio, part, o = {}) {
10640
11569
  const i = e.target;
10641
11570
  if (i.dataset.size !== void 0) studio.setSize(Number(i.value));
10642
11571
  if (i.dataset.tol !== void 0) studio.setTolerance(Number(i.value));
11572
+ if (i.dataset.contig !== void 0) studio.setContiguous(i.checked);
10643
11573
  });
10644
11574
  l.add(studio.subscribe(draw));
10645
11575
  return { dispose: () => l.off() };
@@ -10745,7 +11675,7 @@ function mountFrameView(host, o = {}) {
10745
11675
  const none = host.querySelector(".hb-camtile-none");
10746
11676
  const tag = host.querySelector(".hb-camtile-tag");
10747
11677
  const cap = host.querySelector("[data-caption]");
10748
- const palette = o.palette ?? ut;
11678
+ const palette = o.palette ?? ht;
10749
11679
  let src = null;
10750
11680
  let results = {};
10751
11681
  let mirror = !!o.mirror;
@@ -10930,7 +11860,7 @@ function mountCameraFeed(host, o = {}) {
10930
11860
  if (stream) return;
10931
11861
  error = "";
10932
11862
  try {
10933
- stream = await wi({
11863
+ stream = await qi({
10934
11864
  facingMode: o.facingMode ?? "user",
10935
11865
  width: { ideal: 640 },
10936
11866
  height: { ideal: 480 }
@@ -10943,7 +11873,7 @@ function mountCameraFeed(host, o = {}) {
10943
11873
  Promise.resolve(o.onFrame(video)).finally(() => working = false);
10944
11874
  }, 1e3 / (o.fps ?? 4));
10945
11875
  } catch (e) {
10946
- error = Mi(e).text;
11876
+ error = Di(e).text;
10947
11877
  stream = null;
10948
11878
  }
10949
11879
  emit();
@@ -10951,7 +11881,7 @@ function mountCameraFeed(host, o = {}) {
10951
11881
  stop() {
10952
11882
  if (timer) clearInterval(timer);
10953
11883
  timer = null;
10954
- ki(stream);
11884
+ Oi(stream);
10955
11885
  stream = null;
10956
11886
  video.srcObject = null;
10957
11887
  emit();
@@ -11101,7 +12031,7 @@ const Composer = /* @__PURE__ */ defineComponent({
11101
12031
  },
11102
12032
  setup: hosted((host, p) => mountComposer(host, p.thread, { placeholder: p.placeholder }), (p) => [p.thread])
11103
12033
  });
11104
- /** Vue component for the drop zone that becomes the transcript; emits `sample`. */
12034
+ /** Vue component for the drop zone that becomes the transcript; emits `sample` and `drop` (the handle, whose `pick` opens the file picker). */
11105
12035
  const TranscribeDrop = /* @__PURE__ */ defineComponent({
11106
12036
  name: "TranscribeDrop",
11107
12037
  props: {
@@ -11116,16 +12046,189 @@ const TranscribeDrop = /* @__PURE__ */ defineComponent({
11116
12046
  sampleLabel: {
11117
12047
  type: String,
11118
12048
  default: ""
12049
+ },
12050
+ title: {
12051
+ type: String,
12052
+ default: ""
12053
+ },
12054
+ note: {
12055
+ type: String,
12056
+ default: ""
12057
+ },
12058
+ folders: {
12059
+ type: Boolean,
12060
+ default: false
12061
+ },
12062
+ showDropped: {
12063
+ type: Boolean,
12064
+ default: false
12065
+ }
12066
+ },
12067
+ emits: ["sample", "drop"],
12068
+ setup: hosted((host, p, emit) => {
12069
+ const d = mountTranscribeDrop(host, p.queue, {
12070
+ accept: p.accept,
12071
+ folders: p.folders,
12072
+ showDropped: p.showDropped,
12073
+ ...p.title ? { title: p.title } : {},
12074
+ ...p.note ? { note: p.note } : {},
12075
+ ...p.sampleLabel ? {
12076
+ sampleLabel: p.sampleLabel,
12077
+ onSample: () => emit("sample")
12078
+ } : {}
12079
+ });
12080
+ emit("drop", d);
12081
+ return d;
12082
+ }, (p) => [p.queue, p.showDropped])
12083
+ });
12084
+ /** Vue component for the export menu of a transcribe queue: four formats, copy, all as zip, undo and redo. */
12085
+ const ExportMenu = /* @__PURE__ */ defineComponent({
12086
+ name: "ExportMenu",
12087
+ props: {
12088
+ queue: {
12089
+ type: Object,
12090
+ required: true
12091
+ },
12092
+ tool: {
12093
+ type: String,
12094
+ default: ""
12095
+ },
12096
+ go: {
12097
+ type: Boolean,
12098
+ default: false
12099
+ }
12100
+ },
12101
+ setup: hosted((host, p) => mountExportMenu(host, p.queue, {
12102
+ go: p.go,
12103
+ ...p.tool ? { tool: p.tool } : {}
12104
+ }), (p) => [p.queue, p.go])
12105
+ });
12106
+ /** Vue component for a memory pane over a store; emits `pane` with the handle (refresh, used). */
12107
+ const MemoryPane = /* @__PURE__ */ defineComponent({
12108
+ name: "MemoryPane",
12109
+ props: {
12110
+ memory: {
12111
+ type: Object,
12112
+ required: true
12113
+ },
12114
+ name: {
12115
+ type: String,
12116
+ default: "memory"
12117
+ },
12118
+ by: {
12119
+ type: String,
12120
+ default: "source"
12121
+ },
12122
+ kinds: {
12123
+ type: Object,
12124
+ default: void 0
12125
+ },
12126
+ exportLabel: {
12127
+ type: String,
12128
+ default: "export"
12129
+ },
12130
+ acts: {
12131
+ type: Array,
12132
+ default: void 0
12133
+ }
12134
+ },
12135
+ emits: [
12136
+ "pane",
12137
+ "change",
12138
+ "act"
12139
+ ],
12140
+ setup: hosted((host, p, emit) => {
12141
+ const m = mountMemoryPane(host, p.memory, {
12142
+ name: p.name,
12143
+ by: p.by,
12144
+ exportLabel: p.exportLabel,
12145
+ onChange: () => emit("change"),
12146
+ onAct: (id) => emit("act", id),
12147
+ ...p.kinds ? { kinds: p.kinds } : {},
12148
+ ...p.acts ? { acts: p.acts } : {}
12149
+ });
12150
+ emit("pane", m);
12151
+ return m;
12152
+ }, (p) => [p.memory])
12153
+ });
12154
+ /** Vue component for a sources drop: files and folders into memory through `ingest`. */
12155
+ const SourcesDrop = /* @__PURE__ */ defineComponent({
12156
+ name: "SourcesDrop",
12157
+ props: {
12158
+ ingest: {
12159
+ type: Function,
12160
+ required: true
12161
+ },
12162
+ accept: {
12163
+ type: String,
12164
+ default: ""
11119
12165
  }
11120
12166
  },
11121
- emits: ["sample"],
11122
- setup: hosted((host, p, emit) => mountTranscribeDrop(host, p.queue, {
11123
- accept: p.accept,
11124
- ...p.sampleLabel ? {
11125
- sampleLabel: p.sampleLabel,
11126
- onSample: () => emit("sample")
11127
- } : {}
11128
- }), (p) => [p.queue])
12167
+ setup: hosted((host, p) => mountSourcesDrop(host, {
12168
+ ingest: p.ingest,
12169
+ ...p.accept ? { accept: p.accept } : {}
12170
+ }), (p) => [p.ingest])
12171
+ });
12172
+ /** Vue component for a persona rack. */
12173
+ const PersonaRack = /* @__PURE__ */ defineComponent({
12174
+ name: "PersonaRack",
12175
+ props: { rack: {
12176
+ type: Object,
12177
+ required: true
12178
+ } },
12179
+ setup: hosted((host, p) => mountPersonaRack(host, p.rack), (p) => [p.rack])
12180
+ });
12181
+ /** Vue component for a voice row. */
12182
+ const VoiceRow = /* @__PURE__ */ defineComponent({
12183
+ name: "VoiceRow",
12184
+ props: {
12185
+ row: {
12186
+ type: Object,
12187
+ required: true
12188
+ },
12189
+ test: {
12190
+ type: String,
12191
+ default: ""
12192
+ }
12193
+ },
12194
+ setup: hosted((host, p) => mountVoiceRow(host, p.row, p.test ? { test: p.test } : {}), (p) => [p.row])
12195
+ });
12196
+ /** Vue component for the voice clone row of a speaker; `can` says the loaded voice clones. */
12197
+ const VoiceClone = /* @__PURE__ */ defineComponent({
12198
+ name: "VoiceClone",
12199
+ props: {
12200
+ speaker: {
12201
+ type: Object,
12202
+ required: true
12203
+ },
12204
+ can: {
12205
+ type: Boolean,
12206
+ default: true
12207
+ },
12208
+ seconds: {
12209
+ type: Number,
12210
+ default: 10
12211
+ },
12212
+ hint: {
12213
+ type: String,
12214
+ default: ""
12215
+ }
12216
+ },
12217
+ setup: hosted((host, p) => mountVoiceClone(host, p.speaker, {
12218
+ seconds: p.seconds,
12219
+ can: () => p.can,
12220
+ ...p.hint ? { hint: p.hint } : {}
12221
+ }), (p) => [p.speaker, p.can])
12222
+ });
12223
+ /** Vue component for the session menu of a chat list; emits `import` with the number of chats. */
12224
+ const SessionMenu = /* @__PURE__ */ defineComponent({
12225
+ name: "SessionMenu",
12226
+ props: { list: {
12227
+ type: Object,
12228
+ required: true
12229
+ } },
12230
+ emits: ["import"],
12231
+ setup: hosted((host, p, emit) => mountSessionMenu(host, p.list, { onImport: (n) => emit("import", n) }), (p) => [p.list])
11129
12232
  });
11130
12233
  /** Vue component for the selected transcript, or its export buttons when `exports` is set. */
11131
12234
  const TranscriptView = /* @__PURE__ */ defineComponent({
@@ -11143,8 +12246,8 @@ const TranscriptView = /* @__PURE__ */ defineComponent({
11143
12246
  setup: hosted((host, p) => p.exports ? mountTranscriptExports(host, p.queue) : mountTranscriptView(host, p.queue), (p) => [p.queue, p.exports])
11144
12247
  });
11145
12248
  /**
11146
- * Vue component for a mask studio; emits `studio` with the mounted studio and `sample` when the
11147
- * sample button is pressed.
12249
+ * Vue component for a mask studio; emits `studio` with the mounted studio, `sample` when the
12250
+ * sample button is pressed, and with `demand` set, `want` when a tool needs a model not loaded yet.
11148
12251
  */
11149
12252
  const MaskStudio = /* @__PURE__ */ defineComponent({
11150
12253
  name: "MaskStudio",
@@ -11156,9 +12259,17 @@ const MaskStudio = /* @__PURE__ */ defineComponent({
11156
12259
  sampleLabel: {
11157
12260
  type: String,
11158
12261
  default: ""
12262
+ },
12263
+ demand: {
12264
+ type: Boolean,
12265
+ default: false
11159
12266
  }
11160
12267
  },
11161
- emits: ["studio", "sample"],
12268
+ emits: [
12269
+ "studio",
12270
+ "sample",
12271
+ "want"
12272
+ ],
11162
12273
  setup(props, { emit }) {
11163
12274
  const el = /* @__PURE__ */ ref(null);
11164
12275
  const studio = /* @__PURE__ */ shallowRef(null);
@@ -11168,7 +12279,8 @@ const MaskStudio = /* @__PURE__ */ defineComponent({
11168
12279
  ...props.sampleLabel ? {
11169
12280
  sampleLabel: props.sampleLabel,
11170
12281
  onSample: () => emit("sample")
11171
- } : {}
12282
+ } : {},
12283
+ ...props.demand ? { onWant: (k) => emit("want", k) } : {}
11172
12284
  });
11173
12285
  emit("studio", studio.value);
11174
12286
  });
@@ -11356,4 +12468,4 @@ const CameraFeed = /* @__PURE__ */ defineComponent({
11356
12468
  return feed;
11357
12469
  }, (p) => [p.fps])
11358
12470
  });
11359
- export { CameraFeed, ChatList, ChatPane, Composer, ContextMeter, FrameView, MaskRack, MaskStudio, MaskTools, MaskVerbs, MemoryInspector, ModelJobs, ModelSelect, TranscribeDrop, TranscribeQueue, TranscriptView };
12471
+ export { CameraFeed, ChatList, ChatPane, Composer, ContextMeter, ExportMenu, FrameView, MaskRack, MaskStudio, MaskTools, MaskVerbs, MemoryInspector, MemoryPane, ModelJobs, ModelSelect, PersonaRack, SessionMenu, SourcesDrop, TranscribeDrop, TranscribeQueue, TranscriptView, VoiceClone, VoiceRow };