@hackbuild/ai-views 0.1.2 → 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.
- package/README.md +3 -3
- package/dist/chat.d.ts +35 -2
- package/dist/chat.js +47 -3
- package/dist/elements.d.ts +3 -1
- package/dist/elements.js +2 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -1
- package/dist/loaders.js +40 -7
- package/dist/mount-mask.d.ts +56 -6
- package/dist/mount-mask.js +334 -36
- package/dist/mount-talk.d.ts +92 -0
- package/dist/mount-talk.js +502 -0
- package/dist/mount-transcribe.d.ts +22 -0
- package/dist/mount-transcribe.js +90 -4
- package/dist/pick.d.ts +23 -0
- package/dist/pick.js +51 -0
- package/dist/single/elements.iife.js +1784 -627
- package/dist/single/elements.js +1774 -628
- package/dist/single/index.iife.js +1478 -56
- package/dist/single/index.js +1473 -57
- package/dist/single/vue.iife.js +1720 -622
- package/dist/single/vue.js +1714 -623
- package/dist/speaker.d.ts +55 -0
- package/dist/speaker.js +109 -0
- package/dist/talk.d.ts +89 -0
- package/dist/talk.js +121 -0
- package/dist/transcribe.d.ts +36 -1
- package/dist/transcribe.js +19 -3
- package/dist/vue.d.ts +137 -5
- package/dist/vue.js +80 -9
- package/llms.md +376 -14
- package/package.json +5 -5
package/dist/single/vue.js
CHANGED
|
@@ -2448,14 +2448,14 @@ function initDev() {
|
|
|
2448
2448
|
}
|
|
2449
2449
|
initDev();
|
|
2450
2450
|
// node_modules/@virgilvox/hackbuild-ui/dist/vanilla.js
|
|
2451
|
-
const
|
|
2452
|
-
const
|
|
2453
|
-
const
|
|
2454
|
-
const
|
|
2455
|
-
const
|
|
2456
|
-
const
|
|
2457
|
-
send: { d:
|
|
2458
|
-
microphone: { d:
|
|
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:
|
|
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:
|
|
2474
|
-
refresh: { d:
|
|
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:
|
|
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:
|
|
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
|
|
2546
|
-
return
|
|
2545
|
+
function nn(e) {
|
|
2546
|
+
return Lt[e];
|
|
2547
2547
|
}
|
|
2548
|
-
const
|
|
2549
|
-
function
|
|
2550
|
-
const r =
|
|
2548
|
+
const nt = (e) => e.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
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 ? " " +
|
|
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
|
|
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
|
|
2565
|
-
return [...e.querySelectorAll(
|
|
2564
|
+
function Te(e) {
|
|
2565
|
+
return [...e.querySelectorAll(on)].filter((t) => t.getAttribute("tabindex") !== "-1" && !t.closest("[hidden],[inert]"));
|
|
2566
2566
|
}
|
|
2567
|
-
function
|
|
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
|
|
2587
|
-
let
|
|
2588
|
-
let
|
|
2589
|
-
function
|
|
2590
|
-
|
|
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
|
|
2593
|
-
|
|
2592
|
+
function an(e) {
|
|
2593
|
+
De > 0 && --De === 0 && (e.body.style.overflow = $t);
|
|
2594
2594
|
}
|
|
2595
|
-
const
|
|
2596
|
-
function
|
|
2597
|
-
var u,
|
|
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
|
|
2602
|
-
|
|
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 ||
|
|
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
|
|
2611
|
-
if (!
|
|
2610
|
+
const k = Te(t);
|
|
2611
|
+
if (!k.length) {
|
|
2612
2612
|
w.preventDefault(), t.focus();
|
|
2613
2613
|
return;
|
|
2614
2614
|
}
|
|
2615
|
-
const
|
|
2616
|
-
w.shiftKey && (
|
|
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
|
|
2619
|
-
var
|
|
2618
|
+
function f(w) {
|
|
2619
|
+
var x;
|
|
2620
2620
|
if (!s) return;
|
|
2621
|
-
const
|
|
2622
|
-
if (
|
|
2621
|
+
const k = w.target;
|
|
2622
|
+
if (k === e && r.closeOnScrim !== !1) {
|
|
2623
2623
|
l("scrim");
|
|
2624
2624
|
return;
|
|
2625
2625
|
}
|
|
2626
|
-
const
|
|
2627
|
-
|
|
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
|
|
2633
|
-
var
|
|
2632
|
+
function g() {
|
|
2633
|
+
var k, b, x;
|
|
2634
2634
|
if (s) return;
|
|
2635
|
-
if (n && e.classList.contains("is-sheet")) for (const [
|
|
2636
|
-
s = !0, c = o.activeElement, e.hidden = !1,
|
|
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
|
|
2639
|
+
var b, x;
|
|
2640
2640
|
if (!s) return;
|
|
2641
2641
|
s = !1, e.hidden = !0;
|
|
2642
|
-
const
|
|
2643
|
-
|
|
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") :
|
|
2646
|
+
s ? l("button") : g();
|
|
2647
2647
|
}
|
|
2648
|
-
e.addEventListener("click",
|
|
2648
|
+
e.addEventListener("click", f), (v = r.trigger) == null || v.addEventListener("click", m), e.hidden = !0;
|
|
2649
2649
|
const d = {
|
|
2650
|
-
open:
|
|
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",
|
|
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 &&
|
|
2661
|
+
return n?.set(d, e), r.open && g(), d;
|
|
2662
2662
|
}
|
|
2663
|
-
function
|
|
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 =
|
|
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
|
|
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
|
|
2694
|
-
const t = [], r = [], n =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2742
|
+
function ei(e, t = 80) {
|
|
2743
2743
|
return e.scrollHeight - e.scrollTop - e.clientHeight < t;
|
|
2744
2744
|
}
|
|
2745
|
-
function
|
|
2746
|
-
const o = e.reduce((a,
|
|
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
|
|
2760
|
-
const r = [e.kind,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2812
|
+
function ki(e, t) {
|
|
2802
2813
|
const r = e === "running" && t ? t : e;
|
|
2803
2814
|
return {
|
|
2804
|
-
word:
|
|
2805
|
-
tone:
|
|
2815
|
+
word: Un[r] ?? r,
|
|
2816
|
+
tone: Wn[r] ?? ""
|
|
2806
2817
|
};
|
|
2807
2818
|
}
|
|
2808
|
-
function
|
|
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
|
|
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
|
|
2853
|
+
function Oi(e) {
|
|
2843
2854
|
e?.getTracks().forEach((t) => t.stop());
|
|
2844
2855
|
}
|
|
2845
|
-
function
|
|
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
|
|
2861
|
-
const s =
|
|
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
|
|
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
|
|
2890
|
+
const gt = [
|
|
2880
2891
|
{
|
|
2881
2892
|
id: "wand",
|
|
2882
2893
|
label: "wand",
|
|
2883
2894
|
icon: "wand",
|
|
2884
2895
|
key: "w",
|
|
2885
|
-
hint:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
2956
|
+
hint: Y("pan", "add")
|
|
2942
2957
|
}
|
|
2943
2958
|
];
|
|
2944
|
-
function
|
|
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
|
|
2949
|
-
const { data: i, width: s, height: c } = e, a = new Uint8Array(s * c),
|
|
2950
|
-
if (
|
|
2951
|
-
const
|
|
2952
|
-
const
|
|
2953
|
-
return
|
|
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
|
|
2971
|
+
for (let x = 0; x < s * c; x++) u(x) && (a[x] = 1);
|
|
2957
2972
|
return a;
|
|
2958
2973
|
}
|
|
2959
|
-
const
|
|
2960
|
-
let
|
|
2961
|
-
const
|
|
2962
|
-
for (w[
|
|
2963
|
-
const
|
|
2964
|
-
if (!u(
|
|
2965
|
-
a[
|
|
2966
|
-
const
|
|
2967
|
-
|
|
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
|
|
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
|
|
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
|
|
2978
|
-
const y =
|
|
2992
|
+
for (let h = s; h <= c; h++) {
|
|
2993
|
+
const y = h + .5;
|
|
2979
2994
|
a.length = 0;
|
|
2980
|
-
for (let
|
|
2981
|
-
const
|
|
2982
|
-
|
|
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((
|
|
2985
|
-
for (let
|
|
2986
|
-
const m = Math.max(0, Math.ceil(a[
|
|
2987
|
-
for (let l = m; l <=
|
|
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
|
|
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
|
|
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
|
|
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
|
|
3001
|
-
for (let
|
|
3002
|
-
const m = (
|
|
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
|
|
3005
|
-
p > l && o.fill(255,
|
|
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
|
|
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
|
|
3028
|
+
for (let a = 0; a < r; a++) for (let h = 0; h < t; h++) {
|
|
3014
3029
|
let y = !o;
|
|
3015
|
-
for (let
|
|
3016
|
-
const m = a +
|
|
3017
|
-
for (let
|
|
3018
|
-
const l =
|
|
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 +
|
|
3044
|
+
c[a * t + h] = y ? 255 : 0;
|
|
3030
3045
|
}
|
|
3031
3046
|
i = c;
|
|
3032
3047
|
}
|
|
3033
3048
|
return i;
|
|
3034
3049
|
}
|
|
3035
|
-
function
|
|
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
|
|
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
|
|
3056
|
-
const c = s === "add" ? 255 : 0, a = Math.max(.5, i),
|
|
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 <=
|
|
3059
|
-
const
|
|
3060
|
-
for (let w = y; w <=
|
|
3061
|
-
const
|
|
3062
|
-
if (
|
|
3063
|
-
const
|
|
3064
|
-
e[
|
|
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
|
|
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
|
|
3087
|
+
let h = 0;
|
|
3073
3088
|
for (let y = 0; y <= a; y++) {
|
|
3074
|
-
const
|
|
3075
|
-
|
|
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
|
|
3092
|
+
return h;
|
|
3078
3093
|
}
|
|
3079
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
3153
|
-
const r = e.ownerDocument, n = e.getContext("2d"), o =
|
|
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) ||
|
|
3170
|
+
return (getComputedStyle(e).getPropertyValue(M) || E).trim();
|
|
3156
3171
|
} catch {
|
|
3157
|
-
return
|
|
3158
|
-
}
|
|
3159
|
-
}, c =
|
|
3160
|
-
let
|
|
3161
|
-
e.style.touchAction = "none", e.dataset.tool =
|
|
3162
|
-
const
|
|
3163
|
-
tool:
|
|
3164
|
-
mode:
|
|
3165
|
-
size:
|
|
3166
|
-
tolerance:
|
|
3167
|
-
contiguous:
|
|
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:
|
|
3171
|
-
width:
|
|
3185
|
+
coverage: v,
|
|
3186
|
+
width: f,
|
|
3172
3187
|
height: m,
|
|
3173
3188
|
ready: w,
|
|
3174
|
-
drawing: !!
|
|
3175
|
-
}),
|
|
3176
|
-
let
|
|
3177
|
-
function
|
|
3178
|
-
!n ||
|
|
3179
|
-
|
|
3180
|
-
}) :
|
|
3181
|
-
}
|
|
3182
|
-
function
|
|
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 &&
|
|
3199
|
+
return M.width > 0 && f > 0 ? M.width / f : 1;
|
|
3185
3200
|
}
|
|
3186
|
-
function
|
|
3187
|
-
if (!n || (n.clearRect(0, 0,
|
|
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
|
|
3190
|
-
|
|
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 /
|
|
3193
|
-
if ((
|
|
3194
|
-
n.beginPath(), n.moveTo(
|
|
3195
|
-
for (const
|
|
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 =
|
|
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
|
|
3199
|
-
n.beginPath(),
|
|
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 ((
|
|
3202
|
-
const
|
|
3203
|
-
|
|
3204
|
-
}
|
|
3205
|
-
if (
|
|
3206
|
-
const
|
|
3207
|
-
|
|
3208
|
-
n.moveTo(
|
|
3209
|
-
for (const
|
|
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
|
|
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 ((
|
|
3214
|
-
const
|
|
3215
|
-
n.beginPath(), n.arc(
|
|
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
|
|
3233
|
+
function W() {
|
|
3219
3234
|
var M;
|
|
3220
|
-
|
|
3235
|
+
v = Qn(u), U = !0, K(), I(), (M = t.onEdit) == null || M.call(t, u);
|
|
3221
3236
|
}
|
|
3222
|
-
function
|
|
3237
|
+
function B(M) {
|
|
3223
3238
|
if (!w) return;
|
|
3224
|
-
const
|
|
3225
|
-
M() > 0 && (i.push(
|
|
3226
|
-
}
|
|
3227
|
-
const
|
|
3228
|
-
async function
|
|
3229
|
-
var
|
|
3230
|
-
const
|
|
3231
|
-
w = !1,
|
|
3232
|
-
let
|
|
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 (
|
|
3235
|
-
if (
|
|
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
|
-
|
|
3241
|
-
const
|
|
3242
|
-
|
|
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
|
|
3246
|
-
if (
|
|
3247
|
-
const
|
|
3248
|
-
if (!(
|
|
3249
|
-
|
|
3250
|
-
const
|
|
3251
|
-
if (!
|
|
3252
|
-
|
|
3253
|
-
data:
|
|
3254
|
-
width:
|
|
3255
|
-
height:
|
|
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 (
|
|
3259
|
-
if (
|
|
3260
|
-
const
|
|
3261
|
-
throw (
|
|
3262
|
-
}
|
|
3263
|
-
|
|
3264
|
-
}
|
|
3265
|
-
const
|
|
3266
|
-
const
|
|
3267
|
-
return
|
|
3268
|
-
},
|
|
3269
|
-
function
|
|
3270
|
-
var
|
|
3271
|
-
if (!w ||
|
|
3272
|
-
const
|
|
3273
|
-
if (!
|
|
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
|
|
3279
|
-
if (
|
|
3280
|
-
(
|
|
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:
|
|
3286
|
-
},
|
|
3300
|
+
el: rr(e)
|
|
3301
|
+
}, I();
|
|
3287
3302
|
return;
|
|
3288
3303
|
}
|
|
3289
|
-
if (
|
|
3290
|
-
|
|
3304
|
+
if (b === "wand") {
|
|
3305
|
+
Ye(E.x, E.y, q);
|
|
3291
3306
|
return;
|
|
3292
3307
|
}
|
|
3293
|
-
if (
|
|
3294
|
-
|
|
3308
|
+
if (b === "flood") {
|
|
3309
|
+
Ge(E.x, E.y, q);
|
|
3295
3310
|
return;
|
|
3296
3311
|
}
|
|
3297
|
-
if (
|
|
3298
|
-
const
|
|
3299
|
-
if (
|
|
3300
|
-
|
|
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
|
-
|
|
3304
|
-
mode:
|
|
3318
|
+
C || (C = {
|
|
3319
|
+
mode: q,
|
|
3305
3320
|
pts: []
|
|
3306
|
-
}),
|
|
3321
|
+
}), C.pts.push(E), K(), I();
|
|
3307
3322
|
return;
|
|
3308
3323
|
}
|
|
3309
|
-
if ((
|
|
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:
|
|
3313
|
-
a:
|
|
3314
|
-
b:
|
|
3315
|
-
ellipse:
|
|
3327
|
+
mode: q,
|
|
3328
|
+
a: E,
|
|
3329
|
+
b: E,
|
|
3330
|
+
ellipse: b === "ellipse"
|
|
3316
3331
|
};
|
|
3317
|
-
else if (
|
|
3318
|
-
const
|
|
3319
|
-
|
|
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:
|
|
3323
|
-
last:
|
|
3324
|
-
before:
|
|
3325
|
-
n:
|
|
3326
|
-
},
|
|
3327
|
-
} else
|
|
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:
|
|
3331
|
-
pts: [
|
|
3345
|
+
mode: q,
|
|
3346
|
+
pts: [E]
|
|
3332
3347
|
};
|
|
3333
|
-
|
|
3348
|
+
K(), I();
|
|
3334
3349
|
}
|
|
3335
|
-
function
|
|
3336
|
-
const
|
|
3337
|
-
if (
|
|
3338
|
-
if ((
|
|
3339
|
-
|
|
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
|
|
3343
|
-
if (
|
|
3344
|
-
if (
|
|
3345
|
-
else if ((
|
|
3346
|
-
const
|
|
3347
|
-
Math.hypot(
|
|
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
|
-
|
|
3364
|
+
K();
|
|
3350
3365
|
}
|
|
3351
3366
|
}
|
|
3352
|
-
function
|
|
3353
|
-
const
|
|
3354
|
-
if (!(!
|
|
3355
|
-
if (
|
|
3356
|
-
|
|
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 (
|
|
3360
|
-
const
|
|
3361
|
-
|
|
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
|
-
|
|
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
|
|
3368
|
-
!
|
|
3382
|
+
function He(M) {
|
|
3383
|
+
!S && M.pointerType !== "touch" && (A = null, K());
|
|
3369
3384
|
}
|
|
3370
|
-
function
|
|
3371
|
-
|
|
3372
|
-
const M =
|
|
3373
|
-
M && (
|
|
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
|
|
3376
|
-
|
|
3390
|
+
function je(M) {
|
|
3391
|
+
S && M.pointerId === S.id && re();
|
|
3377
3392
|
}
|
|
3378
|
-
const
|
|
3379
|
-
function
|
|
3380
|
-
if (M.defaultPrevented || M.altKey ||
|
|
3381
|
-
const
|
|
3382
|
-
let
|
|
3383
|
-
if (
|
|
3384
|
-
else if (
|
|
3385
|
-
else if (
|
|
3386
|
-
else if (
|
|
3387
|
-
else if (
|
|
3388
|
-
else if (
|
|
3389
|
-
else if (
|
|
3390
|
-
else if (
|
|
3391
|
-
else if (
|
|
3392
|
-
else if (
|
|
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
|
|
3395
|
-
|
|
3409
|
+
const P = gt.find((j) => j.key === E);
|
|
3410
|
+
P ? We(P.id) : q = !1;
|
|
3396
3411
|
}
|
|
3397
|
-
|
|
3412
|
+
q && M.preventDefault();
|
|
3398
3413
|
}
|
|
3399
|
-
function
|
|
3400
|
-
M.key === " " &&
|
|
3414
|
+
function Ue(M) {
|
|
3415
|
+
M.key === " " && $ && ($ = !1, e.dataset.tool = b);
|
|
3401
3416
|
}
|
|
3402
|
-
|
|
3403
|
-
function
|
|
3404
|
-
M ===
|
|
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
|
|
3407
|
-
M !==
|
|
3421
|
+
function Ve(M) {
|
|
3422
|
+
M !== x && (x = M, e.dataset.mode = M, K(), I());
|
|
3408
3423
|
}
|
|
3409
|
-
function
|
|
3410
|
-
|
|
3424
|
+
function _e() {
|
|
3425
|
+
Ve(Pe(x));
|
|
3411
3426
|
}
|
|
3412
|
-
function
|
|
3413
|
-
const
|
|
3414
|
-
|
|
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
|
|
3417
|
-
|
|
3431
|
+
function ve(M) {
|
|
3432
|
+
Xe(Zn(T, M));
|
|
3418
3433
|
}
|
|
3419
|
-
function
|
|
3420
|
-
const
|
|
3421
|
-
|
|
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
|
|
3424
|
-
M !==
|
|
3438
|
+
function jt(M) {
|
|
3439
|
+
M !== L && (L = M, I());
|
|
3425
3440
|
}
|
|
3426
|
-
function
|
|
3427
|
-
if (!
|
|
3428
|
-
const
|
|
3429
|
-
|
|
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
|
|
3432
|
-
if (!
|
|
3433
|
-
const
|
|
3434
|
-
|
|
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
|
|
3437
|
-
const M =
|
|
3438
|
-
|
|
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
|
|
3441
|
-
|
|
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
|
|
3444
|
-
let
|
|
3445
|
-
for (let
|
|
3446
|
-
return
|
|
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
|
|
3449
|
-
|
|
3463
|
+
function Ut(M = 3) {
|
|
3464
|
+
B(() => we(vt(u, f, m, M, !0)));
|
|
3450
3465
|
}
|
|
3451
|
-
function
|
|
3452
|
-
|
|
3466
|
+
function Wt(M = 3) {
|
|
3467
|
+
B(() => we(vt(u, f, m, M, !1)));
|
|
3453
3468
|
}
|
|
3454
|
-
function
|
|
3455
|
-
|
|
3469
|
+
function Vt(M = 2) {
|
|
3470
|
+
B(() => we(Gn(u, f, m, M)));
|
|
3456
3471
|
}
|
|
3457
|
-
function
|
|
3458
|
-
M.length &&
|
|
3459
|
-
let
|
|
3460
|
-
for (let
|
|
3461
|
-
return
|
|
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
|
|
3465
|
-
|
|
3479
|
+
function Xt(M, E = x) {
|
|
3480
|
+
B(() => ee(u, Se(f, m, M), E));
|
|
3466
3481
|
}
|
|
3467
|
-
function
|
|
3468
|
-
|
|
3482
|
+
function Yt() {
|
|
3483
|
+
B(() => {
|
|
3469
3484
|
let M = 0;
|
|
3470
|
-
for (let
|
|
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
|
|
3475
|
-
|
|
3489
|
+
function Gt() {
|
|
3490
|
+
B(() => (Jn(u), u.length));
|
|
3476
3491
|
}
|
|
3477
|
-
function
|
|
3478
|
-
|
|
3492
|
+
function Qe() {
|
|
3493
|
+
re();
|
|
3479
3494
|
const M = i.undo(u.slice());
|
|
3480
|
-
return M ? (u = M,
|
|
3495
|
+
return M ? (u = M, W(), !0) : !1;
|
|
3481
3496
|
}
|
|
3482
|
-
function
|
|
3483
|
-
|
|
3497
|
+
function Me() {
|
|
3498
|
+
re();
|
|
3484
3499
|
const M = i.redo(u.slice());
|
|
3485
|
-
return M ? (u = M,
|
|
3500
|
+
return M ? (u = M, W(), !0) : !1;
|
|
3486
3501
|
}
|
|
3487
|
-
function
|
|
3502
|
+
function Ze(M = "alpha") {
|
|
3488
3503
|
if (!w) throw new Error("no image yet");
|
|
3489
|
-
const
|
|
3490
|
-
if (typeof ImageData < "u") return new ImageData(
|
|
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
|
|
3493
|
-
return
|
|
3507
|
+
const D = n.createImageData(f, m);
|
|
3508
|
+
return D.data.set(E), D;
|
|
3494
3509
|
}
|
|
3495
|
-
function
|
|
3496
|
-
const
|
|
3497
|
-
|
|
3498
|
-
const
|
|
3499
|
-
return
|
|
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 &&
|
|
3516
|
+
return t.image !== void 0 && ae(t.image).catch(() => {}), {
|
|
3502
3517
|
get state() {
|
|
3503
|
-
return
|
|
3504
|
-
},
|
|
3505
|
-
setImage:
|
|
3506
|
-
setTool:
|
|
3507
|
-
setMode:
|
|
3508
|
-
swap:
|
|
3509
|
-
setSize:
|
|
3510
|
-
stepSize:
|
|
3511
|
-
setTolerance:
|
|
3512
|
-
setContiguous:
|
|
3513
|
-
wandAt:
|
|
3514
|
-
floodAt:
|
|
3515
|
-
paint:
|
|
3516
|
-
lassoFill:
|
|
3517
|
-
shapeFill:
|
|
3518
|
-
expand:
|
|
3519
|
-
shrink:
|
|
3520
|
-
smooth:
|
|
3521
|
-
clear:
|
|
3522
|
-
invert:
|
|
3523
|
-
undo:
|
|
3524
|
-
redo:
|
|
3525
|
-
cancel:
|
|
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
|
-
|
|
3530
|
-
let
|
|
3531
|
-
for (let
|
|
3532
|
-
const
|
|
3533
|
-
u[
|
|
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
|
|
3550
|
+
return E;
|
|
3536
3551
|
});
|
|
3537
3552
|
},
|
|
3538
|
-
toImageData:
|
|
3539
|
-
toBlob:
|
|
3553
|
+
toImageData: Ze,
|
|
3554
|
+
toBlob: Jt,
|
|
3540
3555
|
subscribe(M) {
|
|
3541
3556
|
return o.on(M);
|
|
3542
3557
|
},
|
|
3543
3558
|
dispose() {
|
|
3544
|
-
|
|
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
|
|
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
|
|
3638
|
+
const $r = {
|
|
3583
3639
|
query: "",
|
|
3584
3640
|
fits: !0,
|
|
3585
3641
|
uncensored: !1,
|
|
3586
3642
|
nodownload: !1
|
|
3587
3643
|
};
|
|
3588
|
-
const
|
|
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
|
|
3636
|
-
const r =
|
|
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
|
|
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
|
|
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 =
|
|
3707
|
+
const o = Sr(n);
|
|
3652
3708
|
return r.every((i) => o.includes(i));
|
|
3653
3709
|
});
|
|
3654
3710
|
}
|
|
3655
|
-
function
|
|
3656
|
-
return
|
|
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
|
|
3717
|
+
function Nt(e) {
|
|
3662
3718
|
return `${Math.round(Math.min(1, Math.max(0, e ?? 0)) * 100)}%`;
|
|
3663
3719
|
}
|
|
3664
|
-
function
|
|
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
|
|
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
|
|
3674
|
-
return e ? e.state === "loaded" ? "ready" : e.state === "loading" ? `loading, ${
|
|
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
|
|
3732
|
+
function Re(e) {
|
|
3677
3733
|
return !!e && !e.unfit && e.state !== "loaded" && e.state !== "loading";
|
|
3678
3734
|
}
|
|
3679
|
-
function
|
|
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
|
|
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
|
|
3695
|
-
function
|
|
3750
|
+
const R = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
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
|
|
3709
|
-
const n =
|
|
3710
|
-
return n.length ? n.map((o) => `<div class="hb-msheet-gh" role="presentation">${
|
|
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 =
|
|
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">${
|
|
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
|
|
3772
|
+
function ea(e, t) {
|
|
3717
3773
|
let r = t.rows, n = t.chosen ?? "", o = "";
|
|
3718
3774
|
const i = {
|
|
3719
|
-
|
|
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 ${
|
|
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((
|
|
3727
|
-
const c = e.querySelector("input[type=\"search\"]"), a = e.querySelector(".hb-msheet-list"),
|
|
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
|
|
3785
|
+
const g = {};
|
|
3730
3786
|
function l() {
|
|
3731
|
-
if (!
|
|
3732
|
-
const
|
|
3733
|
-
|
|
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
|
|
3738
|
-
for (const
|
|
3739
|
-
const
|
|
3740
|
-
|
|
3741
|
-
}
|
|
3742
|
-
const
|
|
3743
|
-
a.innerHTML =
|
|
3744
|
-
const
|
|
3745
|
-
|
|
3746
|
-
}
|
|
3747
|
-
const d = (
|
|
3748
|
-
const
|
|
3749
|
-
if (
|
|
3750
|
-
|
|
3751
|
-
const
|
|
3752
|
-
|
|
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 = (
|
|
3757
|
-
var
|
|
3758
|
-
if (
|
|
3759
|
-
(
|
|
3760
|
-
for (const
|
|
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
|
-
},
|
|
3764
|
-
var
|
|
3765
|
-
const
|
|
3766
|
-
|
|
3767
|
-
}, w = (
|
|
3768
|
-
var
|
|
3769
|
-
const
|
|
3770
|
-
if (
|
|
3771
|
-
m =
|
|
3772
|
-
for (const
|
|
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
|
|
3777
|
-
if (
|
|
3778
|
-
const
|
|
3779
|
-
i[
|
|
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
|
|
3783
|
-
if (
|
|
3784
|
-
const
|
|
3785
|
-
if (!
|
|
3786
|
-
n =
|
|
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
|
|
3790
|
-
if (
|
|
3791
|
-
o = o ===
|
|
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
|
|
3795
|
-
if (
|
|
3796
|
-
(
|
|
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 (
|
|
3800
|
-
(
|
|
3855
|
+
if (b.closest("[data-load]") && n) {
|
|
3856
|
+
(A = t.onLoad) == null || A.call(t, n);
|
|
3801
3857
|
return;
|
|
3802
3858
|
}
|
|
3803
|
-
|
|
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",
|
|
3806
|
-
update(
|
|
3807
|
-
r =
|
|
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",
|
|
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
|
|
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 =
|
|
3822
|
-
e.innerHTML = `<button type="button" class="hb-msel-line" aria-haspopup="dialog" aria-label="model: ${
|
|
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,
|
|
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 && ((
|
|
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
|
|
8610
|
-
*
|
|
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
|
|
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: "
|
|
8625
|
-
{ path: "
|
|
8626
|
-
{ path: "
|
|
8627
|
-
{ path: "
|
|
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: [
|
|
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
|
|
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
|
|
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
|
|
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: `${
|
|
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: `${
|
|
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 ${
|
|
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 || !
|
|
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 =
|
|
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 =
|
|
9984
|
+
const handle = Wr(root, {
|
|
9838
9985
|
side: "auto",
|
|
9839
9986
|
breakpoint: 641,
|
|
9840
9987
|
label: s0.title
|
|
@@ -9869,7 +10016,7 @@ function shortName(name) {
|
|
|
9869
10016
|
function chipWords(s) {
|
|
9870
10017
|
const r = s.row;
|
|
9871
10018
|
if (!r) return s.empty;
|
|
9872
|
-
const w =
|
|
10019
|
+
const w = qr(r, s.empty);
|
|
9873
10020
|
const name = shortName(r.name);
|
|
9874
10021
|
if ((r.state === "loading" || r.state === "loaded" || r.state === "error") && w.state) return `${name}, ${w.state}`;
|
|
9875
10022
|
return `${name}, ${r.noDownload ? "no download" : r.size ?? "size unknown"}`;
|
|
@@ -9882,7 +10029,7 @@ function mountModelSelect(host, pick, o = {}) {
|
|
|
9882
10029
|
if (o.variant === "chip") {
|
|
9883
10030
|
const draw = (s) => {
|
|
9884
10031
|
const words = chipWords(s);
|
|
9885
|
-
const full = s.row ? `model: ${s.row.name}${s.row.size ? `, ${s.row.size}` : ""}${
|
|
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}`;
|
|
9886
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>`;
|
|
9887
10034
|
};
|
|
9888
10035
|
l.on(host, "click", (e) => {
|
|
@@ -9893,7 +10040,7 @@ function mountModelSelect(host, pick, o = {}) {
|
|
|
9893
10040
|
const inner = document.createElement("div");
|
|
9894
10041
|
host.replaceChildren(inner);
|
|
9895
10042
|
const s0 = pick.snapshot();
|
|
9896
|
-
const sel =
|
|
10043
|
+
const sel = ta(inner, {
|
|
9897
10044
|
rows: s0.rows,
|
|
9898
10045
|
chosen: s0.chosen,
|
|
9899
10046
|
go: o.go ?? true,
|
|
@@ -9917,7 +10064,7 @@ function mountModelJobs(host, jobs, o = {}) {
|
|
|
9917
10064
|
const presets = jobs.presets();
|
|
9918
10065
|
const all = jobs.all();
|
|
9919
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) => {
|
|
9920
|
-
const w =
|
|
10067
|
+
const w = qr(j.row, "no model");
|
|
9921
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>`;
|
|
9922
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>`;
|
|
9923
10070
|
};
|
|
@@ -9985,7 +10132,7 @@ function mountChatPane(host, thread, o = {}) {
|
|
|
9985
10132
|
const l = listeners();
|
|
9986
10133
|
const draw = (s) => {
|
|
9987
10134
|
const sc = scroller(host);
|
|
9988
|
-
const stick =
|
|
10135
|
+
const stick = ei(sc);
|
|
9989
10136
|
if (!s.turns.length) {
|
|
9990
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>`;
|
|
9991
10138
|
return;
|
|
@@ -10027,7 +10174,7 @@ function mountComposer(host, thread, o = {}) {
|
|
|
10027
10174
|
const text = area.value.trim();
|
|
10028
10175
|
if (!text || busy) return;
|
|
10029
10176
|
area.value = "";
|
|
10030
|
-
|
|
10177
|
+
Zo(area);
|
|
10031
10178
|
thread.send(text);
|
|
10032
10179
|
};
|
|
10033
10180
|
const l = listeners();
|
|
@@ -10038,12 +10185,12 @@ function mountComposer(host, thread, o = {}) {
|
|
|
10038
10185
|
l.on(act, "click", (e) => {
|
|
10039
10186
|
if (e.target.closest("[data-stop]")) thread.stop();
|
|
10040
10187
|
});
|
|
10041
|
-
l.on(area, "input", () =>
|
|
10188
|
+
l.on(area, "input", () => Zo(area));
|
|
10042
10189
|
l.on(area, "keydown", (e) => {
|
|
10043
|
-
const k =
|
|
10190
|
+
const k = Jo(e, {
|
|
10044
10191
|
busy,
|
|
10045
10192
|
empty: !area.value,
|
|
10046
|
-
coarse:
|
|
10193
|
+
coarse: Qo()
|
|
10047
10194
|
});
|
|
10048
10195
|
if (k === "send") {
|
|
10049
10196
|
e.preventDefault();
|
|
@@ -10064,7 +10211,7 @@ function mountChatList(host, list, o = {}) {
|
|
|
10064
10211
|
let renaming = "";
|
|
10065
10212
|
const head = o.label ?? "chats";
|
|
10066
10213
|
const draw = (s) => {
|
|
10067
|
-
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(
|
|
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({
|
|
10068
10215
|
updated: c.updated,
|
|
10069
10216
|
count: c.count
|
|
10070
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>`;
|
|
@@ -10100,7 +10247,7 @@ function mountContextMeter(host, thread, o = {}) {
|
|
|
10100
10247
|
const l = listeners();
|
|
10101
10248
|
const val = (v, d) => typeof v === "function" ? v() : v ?? d;
|
|
10102
10249
|
const draw = (s) => {
|
|
10103
|
-
const use =
|
|
10250
|
+
const use = ti(contextSegments(s, val(o.system, "")), val(o.budget, 4096));
|
|
10104
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>`;
|
|
10105
10252
|
};
|
|
10106
10253
|
l.add(thread.subscribe(draw));
|
|
@@ -10115,13 +10262,13 @@ function mountContextMeter(host, thread, o = {}) {
|
|
|
10115
10262
|
/** The HTML of one channel's transcript, or an empty note when there is none. */
|
|
10116
10263
|
function transcriptHtml(c, o = {}) {
|
|
10117
10264
|
if (!c) return `<p class="hb-lay-empty-note">nothing yet. drop a file.</p>`;
|
|
10118
|
-
const st =
|
|
10265
|
+
const st = ki(c.status);
|
|
10119
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>` : ""}`;
|
|
10120
10267
|
if (!c.segments.length) return `<section class="hb-panel">${head}</section>`;
|
|
10121
|
-
return `<section class="hb-panel">${head}<ol class="hb-transcript is-edit" aria-label="transcript">${c.dropped.length ? `<li class="hb-tseg-note">${esc(
|
|
10122
|
-
const t =
|
|
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);
|
|
10123
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>`;
|
|
10124
|
-
}).join("")}${o.showDropped ? c.dropped.map((d) => `<li><div class="hb-tseg is-dropped"><span class="hb-tseg-body"><span class="hb-tseg-t">${
|
|
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>`;
|
|
10125
10272
|
}
|
|
10126
10273
|
const pickedOf = (s) => s.channels.find((c) => c.id === s.selected);
|
|
10127
10274
|
/** The selected channel's transcript over a host. */
|
|
@@ -10159,6 +10306,29 @@ function mountTranscriptView(host, queue, o = {}) {
|
|
|
10159
10306
|
l.add(queue.subscribe(draw));
|
|
10160
10307
|
return { dispose: () => l.off() };
|
|
10161
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
|
+
}
|
|
10162
10332
|
/** The drop zone that becomes the transcript. */
|
|
10163
10333
|
function mountTranscribeDrop(host, queue, o = {}) {
|
|
10164
10334
|
const l = listeners();
|
|
@@ -10167,15 +10337,19 @@ function mountTranscribeDrop(host, queue, o = {}) {
|
|
|
10167
10337
|
input.hidden = true;
|
|
10168
10338
|
input.multiple = true;
|
|
10169
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", "");
|
|
10170
10344
|
const zone = document.createElement("div");
|
|
10171
10345
|
const result = document.createElement("div");
|
|
10172
|
-
host.replaceChildren(zone, result, input);
|
|
10346
|
+
host.replaceChildren(zone, result, input, dir);
|
|
10173
10347
|
zone.className = "hb-lay-drop";
|
|
10174
10348
|
result.className = "hb-lay-scroll";
|
|
10175
|
-
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>`;
|
|
10176
10350
|
const view = mountTranscriptView(result, queue, o);
|
|
10177
10351
|
const take = (list) => {
|
|
10178
|
-
const files = list ? [...list] : [];
|
|
10352
|
+
const files = list ? [...list].filter(isMedia) : [];
|
|
10179
10353
|
if (files.length) queue.add(files);
|
|
10180
10354
|
};
|
|
10181
10355
|
l.on(host, "dragover", (e) => {
|
|
@@ -10186,7 +10360,11 @@ function mountTranscribeDrop(host, queue, o = {}) {
|
|
|
10186
10360
|
l.on(host, "drop", (e) => {
|
|
10187
10361
|
e.preventDefault();
|
|
10188
10362
|
zone.classList.remove("is-hot");
|
|
10189
|
-
|
|
10363
|
+
droppedFiles(e.dataTransfer).then((fs) => fs.length && queue.add(fs));
|
|
10364
|
+
});
|
|
10365
|
+
l.on(dir, "change", () => {
|
|
10366
|
+
take(dir.files);
|
|
10367
|
+
dir.value = "";
|
|
10190
10368
|
});
|
|
10191
10369
|
l.on(input, "change", () => {
|
|
10192
10370
|
take(input.files);
|
|
@@ -10195,6 +10373,7 @@ function mountTranscribeDrop(host, queue, o = {}) {
|
|
|
10195
10373
|
l.on(zone, "click", (e) => {
|
|
10196
10374
|
const t = e.target;
|
|
10197
10375
|
if (t.closest("[data-pick]")) input.click();
|
|
10376
|
+
else if (t.closest("[data-folder]")) dir.click();
|
|
10198
10377
|
else if (t.closest("[data-sample]")) o.onSample?.();
|
|
10199
10378
|
});
|
|
10200
10379
|
l.add(queue.subscribe((s) => {
|
|
@@ -10204,6 +10383,7 @@ function mountTranscribeDrop(host, queue, o = {}) {
|
|
|
10204
10383
|
}));
|
|
10205
10384
|
return {
|
|
10206
10385
|
pick: () => input.click(),
|
|
10386
|
+
pickFolder: () => dir.click(),
|
|
10207
10387
|
dispose() {
|
|
10208
10388
|
l.off();
|
|
10209
10389
|
view.dispose();
|
|
@@ -10215,7 +10395,7 @@ function mountTranscribeQueue(host, queue) {
|
|
|
10215
10395
|
const l = listeners();
|
|
10216
10396
|
const draw = (s) => {
|
|
10217
10397
|
const strips = s.channels.map((c, i) => {
|
|
10218
|
-
const st =
|
|
10398
|
+
const st = ki(c.status);
|
|
10219
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>`;
|
|
10220
10400
|
}).join("");
|
|
10221
10401
|
const queued = s.channels.some((c) => c.status === "queued");
|
|
@@ -10267,6 +10447,462 @@ function mountTranscriptExports(host, queue, o = {}) {
|
|
|
10267
10447
|
l.add(queue.subscribe(draw));
|
|
10268
10448
|
return { dispose: () => l.off() };
|
|
10269
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)}">×</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
|
+
}
|
|
10270
10906
|
// packages/ai-views/src/mount-mask.ts
|
|
10271
10907
|
/**
|
|
10272
10908
|
* MaskStudio: drop an image, press a thing
|
|
@@ -10276,7 +10912,11 @@ function mountTranscriptExports(host, queue, o = {}) {
|
|
|
10276
10912
|
* export the mask, a matte or the cutout. With a segment everything model
|
|
10277
10913
|
* (FastSAM) one press finds every object; each lands in the found list and
|
|
10278
10914
|
* a press adds it to the mask. Models are functions the page passes, so
|
|
10279
|
-
* 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.
|
|
10280
10920
|
*/
|
|
10281
10921
|
const ZOOMS = [
|
|
10282
10922
|
.5,
|
|
@@ -10287,6 +10927,25 @@ const ZOOMS = [
|
|
|
10287
10927
|
3,
|
|
10288
10928
|
4
|
|
10289
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
|
+
}
|
|
10290
10949
|
/** Pixels of a drawable, for a model. */
|
|
10291
10950
|
function pixelsOf(src) {
|
|
10292
10951
|
const c = document.createElement("canvas");
|
|
@@ -10320,17 +10979,22 @@ function thumbOf(img) {
|
|
|
10320
10979
|
function mountMaskStudio(host, o = {}) {
|
|
10321
10980
|
let models = o.models ?? {};
|
|
10322
10981
|
const l = listeners();
|
|
10323
|
-
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>`;
|
|
10324
10983
|
const empty = host.querySelector("[data-empty]");
|
|
10325
10984
|
const studio = host.querySelector("[data-studio]");
|
|
10326
10985
|
const well = host.querySelector(".hb-mask-well");
|
|
10327
10986
|
host.querySelector(".hb-mask-frame");
|
|
10328
|
-
const canvas = host.querySelector("canvas");
|
|
10987
|
+
const canvas = host.querySelector(".hb-mask-canvas");
|
|
10988
|
+
const over = host.querySelector("[data-over]");
|
|
10329
10989
|
const hint = host.querySelector(".hb-mask-hint");
|
|
10330
10990
|
const input = host.querySelector("input[type=file]");
|
|
10331
10991
|
const subs = /* @__PURE__ */ new Set();
|
|
10332
10992
|
let tool = models.segment ? "point" : "wand";
|
|
10333
10993
|
let zoom = 1;
|
|
10994
|
+
let view = "composite";
|
|
10995
|
+
let hover = -1;
|
|
10996
|
+
let preview = null;
|
|
10997
|
+
let wantAll = null;
|
|
10334
10998
|
let busy = "";
|
|
10335
10999
|
let error = "";
|
|
10336
11000
|
let pixels = null;
|
|
@@ -10349,6 +11013,9 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10349
11013
|
coverage: ed?.coverage ?? 0,
|
|
10350
11014
|
zoom,
|
|
10351
11015
|
busy,
|
|
11016
|
+
contiguous: ed?.contiguous ?? true,
|
|
11017
|
+
view,
|
|
11018
|
+
hover,
|
|
10352
11019
|
found,
|
|
10353
11020
|
saved: saved.map(({ bytes: _b, ...rest }) => rest),
|
|
10354
11021
|
width: ed?.width ?? 0,
|
|
@@ -10357,10 +11024,61 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10357
11024
|
});
|
|
10358
11025
|
const emit = () => {
|
|
10359
11026
|
const s = state();
|
|
10360
|
-
hint.textContent = s.busy || s.error || (tool === "point" ? "press a thing to cut it out. x takes it away instead." :
|
|
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 ?? "");
|
|
10361
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
|
+
}
|
|
10362
11080
|
};
|
|
10363
|
-
const editor =
|
|
11081
|
+
const editor = ns(canvas, {
|
|
10364
11082
|
tool: tool === "point" ? "wand" : tool,
|
|
10365
11083
|
onError: (e) => (error = `the image did not load: ${e.message}`, emit())
|
|
10366
11084
|
});
|
|
@@ -10372,6 +11090,7 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10372
11090
|
studio.style.setProperty("--hb-mask-w", `${Math.round(fitW * zoom)}px`);
|
|
10373
11091
|
studio.classList.toggle("is-zoomed", zoom > 1);
|
|
10374
11092
|
};
|
|
11093
|
+
const zoomStep = (dir) => (dir > 0 ? ZOOMS.find((z) => z > zoom + .001) : [...ZOOMS].reverse().find((z) => z < zoom - .001)) ?? zoom;
|
|
10375
11094
|
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(() => applyZoom()) : null;
|
|
10376
11095
|
ro?.observe(well);
|
|
10377
11096
|
l.add(() => ro?.disconnect());
|
|
@@ -10396,17 +11115,130 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10396
11115
|
emit();
|
|
10397
11116
|
}
|
|
10398
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]);
|
|
10399
11128
|
const onPoint = (e) => {
|
|
10400
11129
|
if (tool !== "point") return;
|
|
10401
11130
|
e.stopImmediatePropagation();
|
|
10402
11131
|
e.preventDefault();
|
|
10403
11132
|
const pe = e;
|
|
10404
|
-
const r = canvas.getBoundingClientRect();
|
|
10405
11133
|
if (!ed?.ready) return;
|
|
10406
|
-
const x =
|
|
10407
|
-
const
|
|
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;
|
|
10408
11139
|
cut(x, y, ed.mode === "erase" !== pe.shiftKey);
|
|
10409
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
|
+
});
|
|
10410
11242
|
canvas.addEventListener("pointerdown", onPoint, true);
|
|
10411
11243
|
l.add(() => canvas.removeEventListener("pointerdown", onPoint, true));
|
|
10412
11244
|
const take = (f) => {
|
|
@@ -10433,6 +11265,8 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10433
11265
|
error = "";
|
|
10434
11266
|
found = [];
|
|
10435
11267
|
saved = [];
|
|
11268
|
+
hover = -1;
|
|
11269
|
+
preview = null;
|
|
10436
11270
|
let drawable = null;
|
|
10437
11271
|
if (typeof src === "string") {
|
|
10438
11272
|
const img = new Image();
|
|
@@ -10452,8 +11286,12 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10452
11286
|
canvas.focus({ preventScroll: true });
|
|
10453
11287
|
},
|
|
10454
11288
|
setTool(t) {
|
|
10455
|
-
if (t === "point" && !models.segment)
|
|
11289
|
+
if (t === "point" && !models.segment) {
|
|
11290
|
+
if (!o.onWant) return;
|
|
11291
|
+
o.onWant("segment");
|
|
11292
|
+
}
|
|
10456
11293
|
tool = t;
|
|
11294
|
+
preview = null;
|
|
10457
11295
|
if (t !== "point") editor.setTool(t);
|
|
10458
11296
|
canvas.dataset.tool = t;
|
|
10459
11297
|
emit();
|
|
@@ -10491,25 +11329,83 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10491
11329
|
},
|
|
10492
11330
|
mask: (kind = "alpha") => ed?.ready ? editor.toImageData(kind) : null,
|
|
10493
11331
|
zoom(dir) {
|
|
10494
|
-
|
|
10495
|
-
else {
|
|
10496
|
-
const i = ZOOMS.indexOf(zoom);
|
|
10497
|
-
zoom = ZOOMS[Math.max(0, Math.min(ZOOMS.length - 1, i + dir))];
|
|
10498
|
-
}
|
|
11332
|
+
zoom = dir === 0 ? 1 : zoomStep(dir);
|
|
10499
11333
|
applyZoom();
|
|
10500
11334
|
emit();
|
|
10501
11335
|
},
|
|
10502
|
-
|
|
10503
|
-
|
|
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;
|
|
10504
11398
|
busy = "finding every object";
|
|
10505
11399
|
error = "";
|
|
10506
11400
|
emit();
|
|
10507
11401
|
try {
|
|
10508
|
-
found = (await models.everything(pixels)).map((f, i) => ({
|
|
11402
|
+
found = (await models.everything(pixels, eo)).map((f, i) => ({
|
|
10509
11403
|
...f,
|
|
10510
11404
|
on: false,
|
|
10511
|
-
|
|
11405
|
+
hidden: false,
|
|
11406
|
+
colour: ht[i % ht.length]
|
|
10512
11407
|
}));
|
|
11408
|
+
if (found.length) view = "instances";
|
|
10513
11409
|
} catch (e) {
|
|
10514
11410
|
error = `segment everything failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
10515
11411
|
} finally {
|
|
@@ -10531,6 +11427,7 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10531
11427
|
},
|
|
10532
11428
|
async exportAs(kind) {
|
|
10533
11429
|
if (!ed?.ready) return null;
|
|
11430
|
+
if (kind === "inverse") return pngOf(new ImageData(er(Jn(editor.mask()), "matte"), ed.width, ed.height));
|
|
10534
11431
|
return editor.toBlob(kind);
|
|
10535
11432
|
},
|
|
10536
11433
|
get hasEverything() {
|
|
@@ -10539,6 +11436,9 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10539
11436
|
get hasSegment() {
|
|
10540
11437
|
return !!models.segment;
|
|
10541
11438
|
},
|
|
11439
|
+
get canWant() {
|
|
11440
|
+
return !!o.onWant;
|
|
11441
|
+
},
|
|
10542
11442
|
state,
|
|
10543
11443
|
subscribe(fn) {
|
|
10544
11444
|
subs.add(fn);
|
|
@@ -10552,8 +11452,9 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10552
11452
|
tool = "point";
|
|
10553
11453
|
canvas.dataset.tool = "point";
|
|
10554
11454
|
}
|
|
10555
|
-
if (tool === "point" && !m.segment) studioApi.setTool("wand");
|
|
11455
|
+
if (tool === "point" && !m.segment && !o.onWant) studioApi.setTool("wand");
|
|
10556
11456
|
emit();
|
|
11457
|
+
if (wantAll && m.everything) studioApi.everything(wantAll);
|
|
10557
11458
|
},
|
|
10558
11459
|
pick: () => input.click(),
|
|
10559
11460
|
dispose() {
|
|
@@ -10570,17 +11471,17 @@ function mountMaskStudio(host, o = {}) {
|
|
|
10570
11471
|
function mountMaskTools(host, studio) {
|
|
10571
11472
|
const l = listeners();
|
|
10572
11473
|
const draw = (s) => {
|
|
10573
|
-
host.innerHTML = [...studio.hasSegment ? [{
|
|
11474
|
+
host.innerHTML = [...studio.hasSegment || studio.canWant ? [{
|
|
10574
11475
|
id: "point",
|
|
10575
11476
|
label: "cut out a thing",
|
|
10576
11477
|
key: "a",
|
|
10577
11478
|
icon: "crosshairs"
|
|
10578
|
-
}] : [], ...
|
|
11479
|
+
}] : [], ...gt.map((t) => ({
|
|
10579
11480
|
id: t.id,
|
|
10580
11481
|
label: t.label,
|
|
10581
11482
|
key: t.key,
|
|
10582
11483
|
icon: t.icon
|
|
10583
|
-
}))].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}">${
|
|
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("");
|
|
10584
11485
|
};
|
|
10585
11486
|
l.on(host, "click", (e) => {
|
|
10586
11487
|
const t = e.target.closest("[data-tool]");
|
|
@@ -10588,12 +11489,7 @@ function mountMaskTools(host, studio) {
|
|
|
10588
11489
|
});
|
|
10589
11490
|
l.on(document, "keydown", (e) => {
|
|
10590
11491
|
const ke = e;
|
|
10591
|
-
if (
|
|
10592
|
-
if (ke.key === "+" || ke.key === "=") return studio.zoom(1);
|
|
10593
|
-
if (ke.key === "-") return studio.zoom(-1);
|
|
10594
|
-
if (ke.key === "0") return studio.zoom(0);
|
|
10595
|
-
}
|
|
10596
|
-
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");
|
|
10597
11493
|
});
|
|
10598
11494
|
l.add(studio.subscribe(draw));
|
|
10599
11495
|
return { dispose: () => l.off() };
|
|
@@ -10603,11 +11499,17 @@ function mountMaskVerbs(host, studio) {
|
|
|
10603
11499
|
const l = listeners();
|
|
10604
11500
|
let last = "";
|
|
10605
11501
|
const draw = (s) => {
|
|
10606
|
-
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>` : "") : "";
|
|
10607
11507
|
if (html !== last) host.innerHTML = last = html;
|
|
10608
11508
|
host.hidden = !html;
|
|
10609
11509
|
};
|
|
10610
11510
|
l.on(host, "click", (e) => {
|
|
11511
|
+
const view = e.target.closest("[data-view]")?.dataset.view;
|
|
11512
|
+
if (view) return studio.setView(view);
|
|
10611
11513
|
const v = e.target.closest("[data-v]")?.dataset.v;
|
|
10612
11514
|
if (v === "undo") studio.undo();
|
|
10613
11515
|
else if (v === "redo") studio.redo();
|
|
@@ -10625,11 +11527,11 @@ function mountMaskRack(host, studio, part, o = {}) {
|
|
|
10625
11527
|
const draw = (s) => {
|
|
10626
11528
|
let html = "";
|
|
10627
11529
|
if (part === "found") {
|
|
10628
|
-
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>` : "");
|
|
10629
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>` : "";
|
|
10630
|
-
} 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>` : "");
|
|
10631
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>`);
|
|
10632
|
-
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>`;
|
|
10633
11535
|
if (html !== last) host.innerHTML = last = html;
|
|
10634
11536
|
};
|
|
10635
11537
|
l.on(host, "click", (e) => {
|
|
@@ -10638,7 +11540,13 @@ function mountMaskRack(host, studio, part, o = {}) {
|
|
|
10638
11540
|
if (f) return studio.toggleFound(Number(f.dataset.found));
|
|
10639
11541
|
const m = t.closest("[data-mode]");
|
|
10640
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));
|
|
10641
11547
|
const op = t.closest("[data-op]")?.dataset.op;
|
|
11548
|
+
if (op === "merge") return studio.mergeFound();
|
|
11549
|
+
if (op === "unfind") return studio.clearFound();
|
|
10642
11550
|
if (op === "invert") return studio.invert();
|
|
10643
11551
|
if (op === "clear") return studio.clear();
|
|
10644
11552
|
if (op === "smooth") return studio.smooth();
|
|
@@ -10661,6 +11569,7 @@ function mountMaskRack(host, studio, part, o = {}) {
|
|
|
10661
11569
|
const i = e.target;
|
|
10662
11570
|
if (i.dataset.size !== void 0) studio.setSize(Number(i.value));
|
|
10663
11571
|
if (i.dataset.tol !== void 0) studio.setTolerance(Number(i.value));
|
|
11572
|
+
if (i.dataset.contig !== void 0) studio.setContiguous(i.checked);
|
|
10664
11573
|
});
|
|
10665
11574
|
l.add(studio.subscribe(draw));
|
|
10666
11575
|
return { dispose: () => l.off() };
|
|
@@ -10766,7 +11675,7 @@ function mountFrameView(host, o = {}) {
|
|
|
10766
11675
|
const none = host.querySelector(".hb-camtile-none");
|
|
10767
11676
|
const tag = host.querySelector(".hb-camtile-tag");
|
|
10768
11677
|
const cap = host.querySelector("[data-caption]");
|
|
10769
|
-
const palette = o.palette ??
|
|
11678
|
+
const palette = o.palette ?? ht;
|
|
10770
11679
|
let src = null;
|
|
10771
11680
|
let results = {};
|
|
10772
11681
|
let mirror = !!o.mirror;
|
|
@@ -10951,7 +11860,7 @@ function mountCameraFeed(host, o = {}) {
|
|
|
10951
11860
|
if (stream) return;
|
|
10952
11861
|
error = "";
|
|
10953
11862
|
try {
|
|
10954
|
-
stream = await
|
|
11863
|
+
stream = await qi({
|
|
10955
11864
|
facingMode: o.facingMode ?? "user",
|
|
10956
11865
|
width: { ideal: 640 },
|
|
10957
11866
|
height: { ideal: 480 }
|
|
@@ -10964,7 +11873,7 @@ function mountCameraFeed(host, o = {}) {
|
|
|
10964
11873
|
Promise.resolve(o.onFrame(video)).finally(() => working = false);
|
|
10965
11874
|
}, 1e3 / (o.fps ?? 4));
|
|
10966
11875
|
} catch (e) {
|
|
10967
|
-
error =
|
|
11876
|
+
error = Di(e).text;
|
|
10968
11877
|
stream = null;
|
|
10969
11878
|
}
|
|
10970
11879
|
emit();
|
|
@@ -10972,7 +11881,7 @@ function mountCameraFeed(host, o = {}) {
|
|
|
10972
11881
|
stop() {
|
|
10973
11882
|
if (timer) clearInterval(timer);
|
|
10974
11883
|
timer = null;
|
|
10975
|
-
|
|
11884
|
+
Oi(stream);
|
|
10976
11885
|
stream = null;
|
|
10977
11886
|
video.srcObject = null;
|
|
10978
11887
|
emit();
|
|
@@ -11122,7 +12031,7 @@ const Composer = /* @__PURE__ */ defineComponent({
|
|
|
11122
12031
|
},
|
|
11123
12032
|
setup: hosted((host, p) => mountComposer(host, p.thread, { placeholder: p.placeholder }), (p) => [p.thread])
|
|
11124
12033
|
});
|
|
11125
|
-
/** 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). */
|
|
11126
12035
|
const TranscribeDrop = /* @__PURE__ */ defineComponent({
|
|
11127
12036
|
name: "TranscribeDrop",
|
|
11128
12037
|
props: {
|
|
@@ -11137,16 +12046,189 @@ const TranscribeDrop = /* @__PURE__ */ defineComponent({
|
|
|
11137
12046
|
sampleLabel: {
|
|
11138
12047
|
type: String,
|
|
11139
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: ""
|
|
11140
12165
|
}
|
|
11141
12166
|
},
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
accept: p.accept
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
|
|
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])
|
|
11150
12232
|
});
|
|
11151
12233
|
/** Vue component for the selected transcript, or its export buttons when `exports` is set. */
|
|
11152
12234
|
const TranscriptView = /* @__PURE__ */ defineComponent({
|
|
@@ -11164,8 +12246,8 @@ const TranscriptView = /* @__PURE__ */ defineComponent({
|
|
|
11164
12246
|
setup: hosted((host, p) => p.exports ? mountTranscriptExports(host, p.queue) : mountTranscriptView(host, p.queue), (p) => [p.queue, p.exports])
|
|
11165
12247
|
});
|
|
11166
12248
|
/**
|
|
11167
|
-
* Vue component for a mask studio; emits `studio` with the mounted studio
|
|
11168
|
-
* 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.
|
|
11169
12251
|
*/
|
|
11170
12252
|
const MaskStudio = /* @__PURE__ */ defineComponent({
|
|
11171
12253
|
name: "MaskStudio",
|
|
@@ -11177,9 +12259,17 @@ const MaskStudio = /* @__PURE__ */ defineComponent({
|
|
|
11177
12259
|
sampleLabel: {
|
|
11178
12260
|
type: String,
|
|
11179
12261
|
default: ""
|
|
12262
|
+
},
|
|
12263
|
+
demand: {
|
|
12264
|
+
type: Boolean,
|
|
12265
|
+
default: false
|
|
11180
12266
|
}
|
|
11181
12267
|
},
|
|
11182
|
-
emits: [
|
|
12268
|
+
emits: [
|
|
12269
|
+
"studio",
|
|
12270
|
+
"sample",
|
|
12271
|
+
"want"
|
|
12272
|
+
],
|
|
11183
12273
|
setup(props, { emit }) {
|
|
11184
12274
|
const el = /* @__PURE__ */ ref(null);
|
|
11185
12275
|
const studio = /* @__PURE__ */ shallowRef(null);
|
|
@@ -11189,7 +12279,8 @@ const MaskStudio = /* @__PURE__ */ defineComponent({
|
|
|
11189
12279
|
...props.sampleLabel ? {
|
|
11190
12280
|
sampleLabel: props.sampleLabel,
|
|
11191
12281
|
onSample: () => emit("sample")
|
|
11192
|
-
} : {}
|
|
12282
|
+
} : {},
|
|
12283
|
+
...props.demand ? { onWant: (k) => emit("want", k) } : {}
|
|
11193
12284
|
});
|
|
11194
12285
|
emit("studio", studio.value);
|
|
11195
12286
|
});
|
|
@@ -11377,4 +12468,4 @@ const CameraFeed = /* @__PURE__ */ defineComponent({
|
|
|
11377
12468
|
return feed;
|
|
11378
12469
|
}, (p) => [p.fps])
|
|
11379
12470
|
});
|
|
11380
|
-
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 };
|