@hackbuild/ai-views 0.1.2 → 0.1.6
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 +7 -7
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var HackbuildAiViewsElements = (function(exports) {
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
// node_modules/@virgilvox/hackbuild-ui/dist/vanilla.js
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
send: { d:
|
|
11
|
-
microphone: { d:
|
|
4
|
+
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";
|
|
5
|
+
const en = "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3";
|
|
6
|
+
const tn = "M3 6h12v12H3zM15 10l6-3v10l-6-3";
|
|
7
|
+
const et = "M3 12h16M13 6l6 6-6 6";
|
|
8
|
+
const tt = "M20 12a8 8 0 1 1-3-6.2M20 4v5h-5";
|
|
9
|
+
const Lt = {
|
|
10
|
+
send: { d: et },
|
|
11
|
+
microphone: { d: en },
|
|
12
12
|
stop: { d: "M6 6h12v12H6z" },
|
|
13
13
|
volume: { d: "M4 9v6h4l5 4V5L8 9zM17 8a5 5 0 0 1 0 8" },
|
|
14
14
|
mute: { d: "M4 9v6h4l5 4V5L8 9zM17 9l4 6M21 9l-4 6" },
|
|
@@ -20,11 +20,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
20
20
|
upload: { d: "M12 16V4M7 9l5-5 5 5M4 20h16" },
|
|
21
21
|
download: { d: "M12 4v11M7 11l5 5 5-5M5 20h14" },
|
|
22
22
|
play: { d: "M7 5l11 7-11 7z" },
|
|
23
|
-
redo: { d:
|
|
23
|
+
redo: { d: tt },
|
|
24
24
|
trash: { d: "M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v6M14 11v6" },
|
|
25
25
|
sun: { d: "M8 12a4 4 0 1 0 8 0a4 4 0 1 0 -8 0M12 2v3M12 19v3M2 12h3M19 12h3" },
|
|
26
|
-
"paper-plane": { d:
|
|
27
|
-
refresh: { d:
|
|
26
|
+
"paper-plane": { d: et },
|
|
27
|
+
refresh: { d: tt },
|
|
28
28
|
undo: { d: "M4 12a8 8 0 1 0 3-6.2M4 4v5h5" },
|
|
29
29
|
plus: { d: "M12 5v14M5 12h14" },
|
|
30
30
|
minus: { d: "M5 12h14" },
|
|
@@ -37,7 +37,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
37
37
|
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" },
|
|
38
38
|
copy: { d: "M8 8h12v12H8zM16 8V4H4v12h4" },
|
|
39
39
|
pen: { d: "M4 20v-4L15 5l4 4L8 20zM12 8l4 4" },
|
|
40
|
-
eye: { d:
|
|
40
|
+
eye: { d: Zt },
|
|
41
41
|
"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" },
|
|
42
42
|
thumbtack: { d: "M8 3h8M10 3v6l-4 5h12l-4-5V3M12 14v7" },
|
|
43
43
|
search: { d: "M4 10a6 6 0 1 0 12 0a6 6 0 1 0 -12 0M15 15l6 6" },
|
|
@@ -65,7 +65,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
65
65
|
wave: { d: "M2 12h3l2-4 3 9 3-13 3 13 2-5h4" },
|
|
66
66
|
"microphone-slash": { d: "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3M3 3l18 18" },
|
|
67
67
|
camera: { d: "M3 7h4l2-3h6l2 3h4v13H3zM8.5 13a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0 -7 0" },
|
|
68
|
-
video: { d:
|
|
68
|
+
video: { d: tn },
|
|
69
69
|
"video-slash": { d: "M3 6h12v12H3zM15 10l6-3v10l-6-3M3 3l18 18" },
|
|
70
70
|
image: { d: "M3 4h18v16H3zM3 16l5-5 4 4 3-3 6 6M15 8v.5" },
|
|
71
71
|
crosshairs: { d: "M5 12a7 7 0 1 0 14 0a7 7 0 1 0 -14 0M12 2v5M12 17v5M2 12h5M17 12h5" },
|
|
@@ -95,17 +95,17 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
95
95
|
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" },
|
|
96
96
|
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" }
|
|
97
97
|
};
|
|
98
|
-
function
|
|
99
|
-
return
|
|
98
|
+
function nn(e) {
|
|
99
|
+
return Lt[e];
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
function
|
|
103
|
-
const r =
|
|
101
|
+
const nt = (e) => e.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
102
|
+
function rn(e, t = {}) {
|
|
103
|
+
const r = nn(e);
|
|
104
104
|
if (!r) return "";
|
|
105
105
|
const n = t.size ?? 16;
|
|
106
|
-
return `<svg class="${"hb-icon is-stroke" + (t.className ? " " +
|
|
106
|
+
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>`;
|
|
107
107
|
}
|
|
108
|
-
const
|
|
108
|
+
const on = [
|
|
109
109
|
"a[href]",
|
|
110
110
|
"button:not([disabled])",
|
|
111
111
|
"input:not([disabled]):not([type=\"hidden\"])",
|
|
@@ -114,10 +114,10 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
114
114
|
"[tabindex]",
|
|
115
115
|
"[contenteditable=\"true\"]"
|
|
116
116
|
].join(",");
|
|
117
|
-
function
|
|
118
|
-
return [...e.querySelectorAll(
|
|
117
|
+
function Te(e) {
|
|
118
|
+
return [...e.querySelectorAll(on)].filter((t) => t.getAttribute("tabindex") !== "-1" && !t.closest("[hidden],[inert]"));
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function be(e) {
|
|
121
121
|
const t = e;
|
|
122
122
|
if (!t || typeof t.closest != "function") return !1;
|
|
123
123
|
if (t.isContentEditable || t.closest("[contenteditable=\"\"],[contenteditable=\"true\"]")) return !0;
|
|
@@ -136,71 +136,71 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
136
136
|
"range"
|
|
137
137
|
].includes(n);
|
|
138
138
|
}
|
|
139
|
-
const
|
|
140
|
-
let
|
|
141
|
-
let
|
|
142
|
-
function
|
|
143
|
-
|
|
139
|
+
const ce = [];
|
|
140
|
+
let De = 0;
|
|
141
|
+
let $t = "";
|
|
142
|
+
function sn(e) {
|
|
143
|
+
De++ === 0 && ($t = e.body.style.overflow, e.body.style.overflow = "hidden");
|
|
144
144
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
145
|
+
function an(e) {
|
|
146
|
+
De > 0 && --De === 0 && (e.body.style.overflow = $t);
|
|
147
147
|
}
|
|
148
|
-
const
|
|
149
|
-
function
|
|
150
|
-
var u,
|
|
148
|
+
const ln = /* @__PURE__ */ new Map();
|
|
149
|
+
function St(e, t, r, n) {
|
|
150
|
+
var u, v;
|
|
151
151
|
const o = e.ownerDocument, i = {};
|
|
152
152
|
let s = !1, c = null, a = !1;
|
|
153
153
|
!t.getAttribute("role") && !e.getAttribute("role") && t.setAttribute("role", "dialog");
|
|
154
|
-
const
|
|
155
|
-
|
|
154
|
+
const h = e.getAttribute("role") === "dialog" ? e : t;
|
|
155
|
+
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");
|
|
156
156
|
function y(w) {
|
|
157
|
-
if (!s ||
|
|
157
|
+
if (!s || ce[ce.length - 1] !== i || w.defaultPrevented) return;
|
|
158
158
|
if (w.key === "Escape" && r.closeOnEscape !== !1) {
|
|
159
159
|
w.preventDefault(), l("escape");
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
162
|
if (w.key !== "Tab" || r.trap === !1) return;
|
|
163
|
-
const
|
|
164
|
-
if (!
|
|
163
|
+
const k = Te(t);
|
|
164
|
+
if (!k.length) {
|
|
165
165
|
w.preventDefault(), t.focus();
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
|
-
const
|
|
169
|
-
w.shiftKey && (
|
|
168
|
+
const b = k[0], x = k[k.length - 1], T = o.activeElement, z = !!T && t.contains(T);
|
|
169
|
+
w.shiftKey && (T === b || !z) ? (w.preventDefault(), x.focus()) : !w.shiftKey && (T === x || !z) && (w.preventDefault(), b.focus());
|
|
170
170
|
}
|
|
171
|
-
function
|
|
172
|
-
var
|
|
171
|
+
function f(w) {
|
|
172
|
+
var x;
|
|
173
173
|
if (!s) return;
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
174
|
+
const k = w.target;
|
|
175
|
+
if (k === e && r.closeOnScrim !== !1) {
|
|
176
176
|
l("scrim");
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
|
-
const
|
|
180
|
-
|
|
179
|
+
const b = (x = k.closest) == null ? void 0 : x.call(k, "[data-hb-close]");
|
|
180
|
+
b && e.contains(b) && l("button");
|
|
181
181
|
}
|
|
182
182
|
function m() {
|
|
183
183
|
p();
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
var
|
|
185
|
+
function g() {
|
|
186
|
+
var k, b, x;
|
|
187
187
|
if (s) return;
|
|
188
|
-
if (n && e.classList.contains("is-sheet")) for (const [
|
|
189
|
-
s = !0, c = o.activeElement, e.hidden = !1,
|
|
188
|
+
if (n && e.classList.contains("is-sheet")) for (const [T, z] of [...n]) T !== d && z.classList.contains("is-sheet") && T.close("api");
|
|
189
|
+
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);
|
|
190
190
|
}
|
|
191
191
|
function l(w = "api") {
|
|
192
|
-
var
|
|
192
|
+
var b, x;
|
|
193
193
|
if (!s) return;
|
|
194
194
|
s = !1, e.hidden = !0;
|
|
195
|
-
const
|
|
196
|
-
|
|
195
|
+
const k = ce.indexOf(i);
|
|
196
|
+
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);
|
|
197
197
|
}
|
|
198
198
|
function p() {
|
|
199
|
-
s ? l("button") :
|
|
199
|
+
s ? l("button") : g();
|
|
200
200
|
}
|
|
201
|
-
e.addEventListener("click",
|
|
201
|
+
e.addEventListener("click", f), (v = r.trigger) == null || v.addEventListener("click", m), e.hidden = !0;
|
|
202
202
|
const d = {
|
|
203
|
-
open:
|
|
203
|
+
open: g,
|
|
204
204
|
close: l,
|
|
205
205
|
toggle: p,
|
|
206
206
|
get isOpen() {
|
|
@@ -208,26 +208,26 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
208
208
|
},
|
|
209
209
|
dispose() {
|
|
210
210
|
var w;
|
|
211
|
-
s && l("api"), n?.delete(d), e.removeEventListener("click",
|
|
211
|
+
s && l("api"), n?.delete(d), e.removeEventListener("click", f), (w = r.trigger) == null || w.removeEventListener("click", m);
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
|
-
return n?.set(d, e), r.open &&
|
|
214
|
+
return n?.set(d, e), r.open && g(), d;
|
|
215
215
|
}
|
|
216
|
-
function
|
|
216
|
+
function Wr(e, t = {}) {
|
|
217
217
|
const r = t.side ?? "right";
|
|
218
218
|
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");
|
|
219
219
|
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 = () => {
|
|
220
220
|
e.classList.toggle("is-sheet", !(i != null && i.matches));
|
|
221
221
|
};
|
|
222
222
|
r === "auto" && s(), i?.addEventListener("change", s);
|
|
223
|
-
const c =
|
|
223
|
+
const c = St(e, n, t, r === "bottom" || r === "auto" ? ln : void 0);
|
|
224
224
|
if (!i) return c;
|
|
225
225
|
const a = c.dispose;
|
|
226
226
|
return c.dispose = () => {
|
|
227
227
|
i.removeEventListener("change", s), a();
|
|
228
228
|
}, c;
|
|
229
229
|
}
|
|
230
|
-
function
|
|
230
|
+
function X() {
|
|
231
231
|
const e = /* @__PURE__ */ new Set();
|
|
232
232
|
return {
|
|
233
233
|
on(t) {
|
|
@@ -243,8 +243,8 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
245
|
}
|
|
246
|
-
function
|
|
247
|
-
const t = [], r = [], n =
|
|
246
|
+
function yn(e = 80) {
|
|
247
|
+
const t = [], r = [], n = X();
|
|
248
248
|
return {
|
|
249
249
|
push(o) {
|
|
250
250
|
t.push(o), t.length > e && t.splice(0, t.length - e), r.length = 0, n.emit();
|
|
@@ -282,26 +282,26 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
282
282
|
}
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
|
-
function
|
|
285
|
+
function _o(e) {
|
|
286
286
|
if (!e) return "";
|
|
287
287
|
const t = [];
|
|
288
288
|
return e.tokPerSec !== null && e.tokPerSec !== void 0 && t.push(`${e.tokPerSec.toFixed(1)} tok/s`), e.firstMs !== null && e.firstMs !== void 0 && t.push(`first word ${(e.firstMs / 1e3).toFixed(2)} s`), e.tokens !== null && e.tokens !== void 0 && t.push(`${e.tokens} tok`), t.length ? `${t.join(", ")} (${e.source ?? "measured"})` : "";
|
|
289
289
|
}
|
|
290
|
-
function
|
|
290
|
+
function Jo(e, t) {
|
|
291
291
|
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";
|
|
292
292
|
}
|
|
293
|
-
function
|
|
293
|
+
function Qo(e = typeof window > "u" ? void 0 : window) {
|
|
294
294
|
var t;
|
|
295
295
|
return !!((t = e == null ? void 0 : e.matchMedia) != null && t.call(e, "(pointer: coarse)").matches);
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function Zo(e, t = 44, r = 200) {
|
|
298
298
|
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";
|
|
299
299
|
}
|
|
300
|
-
function
|
|
300
|
+
function ei(e, t = 80) {
|
|
301
301
|
return e.scrollHeight - e.scrollTop - e.clientHeight < t;
|
|
302
302
|
}
|
|
303
|
-
function
|
|
304
|
-
const o = e.reduce((a,
|
|
303
|
+
function ti(e, t, r = .75, n = .95) {
|
|
304
|
+
const o = e.reduce((a, h) => a + Math.max(0, h.tokens), 0), i = Math.max(1, t);
|
|
305
305
|
return {
|
|
306
306
|
used: o,
|
|
307
307
|
budget: i,
|
|
@@ -314,29 +314,40 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
314
314
|
words: `${o.toLocaleString("en-US")} of ${i.toLocaleString("en-US")} tok, ${Math.round(o / i * 100)}%`
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
|
-
function
|
|
318
|
-
const r = [e.kind,
|
|
317
|
+
function ni(e, t = Date.now()) {
|
|
318
|
+
const r = [e.kind, Fn(e.updated, t)];
|
|
319
319
|
return e.count != null && r.push(`${e.count} msg`), r.filter(Boolean).join(", ");
|
|
320
320
|
}
|
|
321
|
-
function
|
|
321
|
+
function Fn(e, t = Date.now()) {
|
|
322
322
|
const r = typeof e == "number" ? e : new Date(e).getTime();
|
|
323
323
|
if (!Number.isFinite(r)) return String(e);
|
|
324
324
|
const n = Math.max(0, (t - r) / 1e3);
|
|
325
325
|
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);
|
|
326
326
|
}
|
|
327
|
-
function
|
|
327
|
+
function Nn(e, t) {
|
|
328
|
+
return t === 1 || !e ? e : /[^aeiou]y$/.test(e) ? e.slice(0, -1) + "ies" : /(s|x|ch|sh)$/.test(e) ? e + "es" : e + "s";
|
|
329
|
+
}
|
|
330
|
+
function oi(e, t = []) {
|
|
331
|
+
const r = new Map(t.map((n) => [n, 0]));
|
|
332
|
+
for (const n of e) r.set(n.kind, (r.get(n.kind) ?? 0) + 1);
|
|
333
|
+
return r.size ? [...r].map(([n, o]) => `${o} ${Nn(n, o)}`).join(", ") : "nothing stored.";
|
|
334
|
+
}
|
|
335
|
+
function ii(e) {
|
|
336
|
+
return typeof e == "number" && Number.isFinite(e) ? e.toFixed(2) : "";
|
|
337
|
+
}
|
|
338
|
+
function ie(e) {
|
|
328
339
|
if (!Number.isFinite(e)) return "--:--";
|
|
329
340
|
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");
|
|
330
341
|
return r ? `${r}:${i(n)}:${i(o)}` : `${i(n)}:${i(o)}`;
|
|
331
342
|
}
|
|
332
|
-
function
|
|
343
|
+
function yi(e) {
|
|
333
344
|
if (!e.length) return "";
|
|
334
345
|
const t = /* @__PURE__ */ new Map();
|
|
335
346
|
for (const n of e) t.set(n.why, (t.get(n.why) ?? 0) + 1);
|
|
336
347
|
const r = [...t].sort((n, o) => o[1] - n[1]).map(([n, o]) => `${o} ${n}`);
|
|
337
348
|
return `${e.length} ${e.length === 1 ? "line" : "lines"} dropped: ${r.join(", ")}`;
|
|
338
349
|
}
|
|
339
|
-
const
|
|
350
|
+
const Un = {
|
|
340
351
|
queued: "queued",
|
|
341
352
|
decoding: "decoding",
|
|
342
353
|
working: "transcribing",
|
|
@@ -346,7 +357,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
346
357
|
failed: "failed",
|
|
347
358
|
stopped: "stopped"
|
|
348
359
|
};
|
|
349
|
-
const
|
|
360
|
+
const Wn = {
|
|
350
361
|
queued: "",
|
|
351
362
|
decoding: "busy",
|
|
352
363
|
working: "busy",
|
|
@@ -356,19 +367,19 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
356
367
|
failed: "bad",
|
|
357
368
|
stopped: ""
|
|
358
369
|
};
|
|
359
|
-
function
|
|
370
|
+
function ki(e, t) {
|
|
360
371
|
const r = e === "running" && t ? t : e;
|
|
361
372
|
return {
|
|
362
|
-
word:
|
|
363
|
-
tone:
|
|
373
|
+
word: Un[r] ?? r,
|
|
374
|
+
tone: Wn[r] ?? ""
|
|
364
375
|
};
|
|
365
376
|
}
|
|
366
|
-
function
|
|
377
|
+
function Vn(e) {
|
|
367
378
|
return e >= 1e9 ? `${(e / 1e9).toFixed(1)} gb` : e >= 1e6 ? `${Math.round(e / 1e6)} mb` : `${Math.max(1, Math.round(e / 1e3))} kb`;
|
|
368
379
|
}
|
|
369
|
-
function
|
|
380
|
+
function xi(e) {
|
|
370
381
|
const t = [];
|
|
371
|
-
return e.duration && t.push({ value:
|
|
382
|
+
return e.duration && t.push({ value: ie(e.duration) }), e.size !== void 0 && t.push({ value: Vn(e.size) }), e.snrDb !== void 0 && t.push({
|
|
372
383
|
label: "snr",
|
|
373
384
|
value: `${e.snrDb.toFixed(1)} dB`,
|
|
374
385
|
tone: e.snrDb < 8 ? "lo" : e.snrDb > 20 ? "hi" : void 0
|
|
@@ -380,7 +391,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
380
391
|
value: `${Math.round(e.density * 100)}%`
|
|
381
392
|
}), e.rtf && t.push({ value: `${e.rtf.toFixed(1)}x rt` }), e.lines !== void 0 && t.push({ value: `${e.lines} ${e.lines === 1 ? "line" : "lines"}` }), t;
|
|
382
393
|
}
|
|
383
|
-
function
|
|
394
|
+
function Di(e) {
|
|
384
395
|
const t = (e == null ? void 0 : e.name) ?? "";
|
|
385
396
|
if (t === "NotAllowedError" || t === "SecurityError" || t === "PermissionDeniedError") return {
|
|
386
397
|
kind: "denied",
|
|
@@ -404,7 +415,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
404
415
|
text: `camera failed${r ? `: ${r.toLowerCase().replace(/\.$/, "")}` : ""}. upload a file instead.`
|
|
405
416
|
};
|
|
406
417
|
}
|
|
407
|
-
function
|
|
418
|
+
function qi(e = {
|
|
408
419
|
facingMode: "user",
|
|
409
420
|
width: { ideal: 640 },
|
|
410
421
|
height: { ideal: 480 }
|
|
@@ -414,10 +425,10 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
414
425
|
audio: !1
|
|
415
426
|
}) : Promise.reject(Object.assign(/* @__PURE__ */ new Error("no mediaDevices"), { name: "unsupported" }));
|
|
416
427
|
}
|
|
417
|
-
function
|
|
428
|
+
function Oi(e) {
|
|
418
429
|
e?.getTracks().forEach((t) => t.stop());
|
|
419
430
|
}
|
|
420
|
-
function
|
|
431
|
+
function zt(e, t, r) {
|
|
421
432
|
if (!(t > 0 && r > 0 && e.width > 0 && e.height > 0)) return {
|
|
422
433
|
left: 0,
|
|
423
434
|
top: 0,
|
|
@@ -432,14 +443,14 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
432
443
|
height: i
|
|
433
444
|
};
|
|
434
445
|
}
|
|
435
|
-
function
|
|
436
|
-
const s =
|
|
446
|
+
function Yn(e, t, r, n, o, i = !1) {
|
|
447
|
+
const s = zt(r, n, o), c = (e - r.left - s.left) / s.width, a = (t - r.top - s.top) / s.height;
|
|
437
448
|
return !i && (c < 0 || a < 0 || c > 1 || a > 1) ? null : {
|
|
438
449
|
x: Math.min(n, Math.max(0, c * n)),
|
|
439
450
|
y: Math.min(o, Math.max(0, a * o))
|
|
440
451
|
};
|
|
441
452
|
}
|
|
442
|
-
const
|
|
453
|
+
const ht = [
|
|
443
454
|
"#FE0386",
|
|
444
455
|
"#3b82f6",
|
|
445
456
|
"#22c55e",
|
|
@@ -451,146 +462,150 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
451
462
|
"#ff5c4d",
|
|
452
463
|
"#58a6ff"
|
|
453
464
|
];
|
|
454
|
-
const
|
|
465
|
+
const gt = [
|
|
455
466
|
{
|
|
456
467
|
id: "wand",
|
|
457
468
|
label: "wand",
|
|
458
469
|
icon: "wand",
|
|
459
470
|
key: "w",
|
|
460
|
-
hint:
|
|
471
|
+
hint: Y("wand", "add")
|
|
461
472
|
},
|
|
462
473
|
{
|
|
463
474
|
id: "brush",
|
|
464
475
|
label: "brush",
|
|
465
476
|
icon: "brush",
|
|
466
477
|
key: "b",
|
|
467
|
-
hint:
|
|
478
|
+
hint: Y("brush", "add")
|
|
468
479
|
},
|
|
469
480
|
{
|
|
470
481
|
id: "eraser",
|
|
471
482
|
label: "eraser",
|
|
472
483
|
icon: "eraser",
|
|
473
484
|
key: "e",
|
|
474
|
-
hint:
|
|
485
|
+
hint: Y("eraser", "add")
|
|
475
486
|
},
|
|
476
487
|
{
|
|
477
488
|
id: "lasso",
|
|
478
489
|
label: "lasso",
|
|
479
490
|
icon: "lasso",
|
|
480
491
|
key: "l",
|
|
481
|
-
hint:
|
|
492
|
+
hint: Y("lasso", "add"),
|
|
493
|
+
group: "shape"
|
|
482
494
|
},
|
|
483
495
|
{
|
|
484
496
|
id: "polygon",
|
|
485
497
|
label: "polygon",
|
|
486
498
|
icon: "polygon",
|
|
487
499
|
key: "p",
|
|
488
|
-
hint:
|
|
500
|
+
hint: Y("polygon", "add"),
|
|
501
|
+
group: "shape"
|
|
489
502
|
},
|
|
490
503
|
{
|
|
491
504
|
id: "rect",
|
|
492
505
|
label: "rectangle",
|
|
493
506
|
icon: "select-rect",
|
|
494
507
|
key: "m",
|
|
495
|
-
hint:
|
|
508
|
+
hint: Y("rect", "add"),
|
|
509
|
+
group: "shape"
|
|
496
510
|
},
|
|
497
511
|
{
|
|
498
512
|
id: "ellipse",
|
|
499
513
|
label: "ellipse",
|
|
500
514
|
icon: "select-ellipse",
|
|
501
515
|
key: "o",
|
|
502
|
-
hint:
|
|
516
|
+
hint: Y("ellipse", "add"),
|
|
517
|
+
group: "shape"
|
|
503
518
|
},
|
|
504
519
|
{
|
|
505
520
|
id: "flood",
|
|
506
521
|
label: "flood fill",
|
|
507
522
|
icon: "bucket",
|
|
508
523
|
key: "g",
|
|
509
|
-
hint:
|
|
524
|
+
hint: Y("flood", "add")
|
|
510
525
|
},
|
|
511
526
|
{
|
|
512
527
|
id: "pan",
|
|
513
528
|
label: "pan",
|
|
514
529
|
icon: "hand",
|
|
515
530
|
key: "h",
|
|
516
|
-
hint:
|
|
531
|
+
hint: Y("pan", "add")
|
|
517
532
|
}
|
|
518
533
|
];
|
|
519
|
-
function
|
|
534
|
+
function Y(e, t) {
|
|
520
535
|
const r = t === "add", n = `x swaps to ${r ? "erase" : "add"}`;
|
|
521
536
|
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}`;
|
|
522
537
|
}
|
|
523
|
-
function
|
|
524
|
-
const { data: i, width: s, height: c } = e, a = new Uint8Array(s * c),
|
|
525
|
-
if (
|
|
526
|
-
const
|
|
527
|
-
const
|
|
528
|
-
return
|
|
538
|
+
function pt(e, t, r, n, o = !0) {
|
|
539
|
+
const { data: i, width: s, height: c } = e, a = new Uint8Array(s * c), h = Math.floor(t), y = Math.floor(r);
|
|
540
|
+
if (h < 0 || y < 0 || h >= s || y >= c) return a;
|
|
541
|
+
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) => {
|
|
542
|
+
const T = x * 4, z = i[T] - m, L = i[T + 1] - g, S = i[T + 2] - l;
|
|
543
|
+
return z * z + L * L + S * S <= d;
|
|
529
544
|
};
|
|
530
545
|
if (!o) {
|
|
531
|
-
for (let
|
|
546
|
+
for (let x = 0; x < s * c; x++) u(x) && (a[x] = 1);
|
|
532
547
|
return a;
|
|
533
548
|
}
|
|
534
|
-
const
|
|
535
|
-
let
|
|
536
|
-
const
|
|
537
|
-
for (w[
|
|
538
|
-
const
|
|
539
|
-
if (!u(
|
|
540
|
-
a[
|
|
541
|
-
const
|
|
542
|
-
|
|
549
|
+
const v = new Uint8Array(s * c), w = new Int32Array(s * c);
|
|
550
|
+
let k = 0;
|
|
551
|
+
const b = y * s + h;
|
|
552
|
+
for (w[k++] = b, v[b] = 1; k;) {
|
|
553
|
+
const x = w[--k];
|
|
554
|
+
if (!u(x)) continue;
|
|
555
|
+
a[x] = 1;
|
|
556
|
+
const T = x % s;
|
|
557
|
+
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);
|
|
543
558
|
}
|
|
544
559
|
return a;
|
|
545
560
|
}
|
|
546
|
-
function
|
|
561
|
+
function Se(e, t, r) {
|
|
547
562
|
const n = new Uint8Array(e * t);
|
|
548
563
|
if (r.length < 3) return n;
|
|
549
564
|
let o = 1 / 0, i = -1 / 0;
|
|
550
|
-
for (const
|
|
565
|
+
for (const h of r) h.y < o && (o = h.y), h.y > i && (i = h.y);
|
|
551
566
|
const s = Math.max(0, Math.floor(o)), c = Math.min(t - 1, Math.ceil(i)), a = [];
|
|
552
|
-
for (let
|
|
553
|
-
const y =
|
|
567
|
+
for (let h = s; h <= c; h++) {
|
|
568
|
+
const y = h + .5;
|
|
554
569
|
a.length = 0;
|
|
555
|
-
for (let
|
|
556
|
-
const
|
|
557
|
-
|
|
570
|
+
for (let f = 0, m = r.length - 1; f < r.length; m = f++) {
|
|
571
|
+
const g = r[f], l = r[m];
|
|
572
|
+
g.y > y != l.y > y && a.push(g.x + (y - g.y) * (l.x - g.x) / (l.y - g.y));
|
|
558
573
|
}
|
|
559
|
-
a.sort((
|
|
560
|
-
for (let
|
|
561
|
-
const m = Math.max(0, Math.ceil(a[
|
|
562
|
-
for (let l = m; l <=
|
|
574
|
+
a.sort((f, m) => f - m);
|
|
575
|
+
for (let f = 0; f + 1 < a.length; f += 2) {
|
|
576
|
+
const m = Math.max(0, Math.ceil(a[f] - .5)), g = Math.min(e - 1, Math.ceil(a[f + 1] - .5) - 1);
|
|
577
|
+
for (let l = m; l <= g; l++) n[h * e + l] = 1;
|
|
563
578
|
}
|
|
564
579
|
}
|
|
565
580
|
return n;
|
|
566
581
|
}
|
|
567
|
-
function
|
|
582
|
+
function yt(e, t, r, n) {
|
|
568
583
|
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)));
|
|
569
|
-
for (let
|
|
584
|
+
for (let h = c; h < a; h++) o.fill(255, h * e + i, h * e + s);
|
|
570
585
|
return o;
|
|
571
586
|
}
|
|
572
|
-
function
|
|
587
|
+
function bt(e, t, r, n) {
|
|
573
588
|
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;
|
|
574
589
|
if (c < .5 || a < .5) return o;
|
|
575
|
-
const
|
|
576
|
-
for (let
|
|
577
|
-
const m = (
|
|
590
|
+
const h = Math.max(0, Math.floor(s - a)), y = Math.min(t - 1, Math.ceil(s + a));
|
|
591
|
+
for (let f = h; f <= y; f++) {
|
|
592
|
+
const m = (f + .5 - s) / a;
|
|
578
593
|
if (m * m > 1) continue;
|
|
579
|
-
const
|
|
580
|
-
p > l && o.fill(255,
|
|
594
|
+
const g = c * Math.sqrt(1 - m * m), l = Math.max(0, Math.round(i - g)), p = Math.min(e, Math.round(i + g));
|
|
595
|
+
p > l && o.fill(255, f * e + l, f * e + p);
|
|
581
596
|
}
|
|
582
597
|
return o;
|
|
583
598
|
}
|
|
584
|
-
function
|
|
599
|
+
function vt(e, t, r, n, o) {
|
|
585
600
|
let i = e;
|
|
586
601
|
for (let s = 0; s < Math.max(0, Math.round(n)); s++) {
|
|
587
602
|
const c = new Uint8Array(i.length);
|
|
588
|
-
for (let a = 0; a < r; a++) for (let
|
|
603
|
+
for (let a = 0; a < r; a++) for (let h = 0; h < t; h++) {
|
|
589
604
|
let y = !o;
|
|
590
|
-
for (let
|
|
591
|
-
const m = a +
|
|
592
|
-
for (let
|
|
593
|
-
const l =
|
|
605
|
+
for (let f = -1; f <= 1 && y !== o; f++) {
|
|
606
|
+
const m = a + f;
|
|
607
|
+
for (let g = -1; g <= 1; g++) {
|
|
608
|
+
const l = h + g, p = l >= 0 && l < t && m >= 0 && m < r ? i[m * t + l] > 127 : !1;
|
|
594
609
|
if (o && p) {
|
|
595
610
|
y = !0;
|
|
596
611
|
break;
|
|
@@ -601,13 +616,13 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
601
616
|
}
|
|
602
617
|
}
|
|
603
618
|
}
|
|
604
|
-
c[a * t +
|
|
619
|
+
c[a * t + h] = y ? 255 : 0;
|
|
605
620
|
}
|
|
606
621
|
i = c;
|
|
607
622
|
}
|
|
608
623
|
return i;
|
|
609
624
|
}
|
|
610
|
-
function
|
|
625
|
+
function Gn(e, t, r, n = 2) {
|
|
611
626
|
const o = new Float32Array(e.length), i = new Uint8Array(e.length);
|
|
612
627
|
for (let s = 0; s < r; s++) {
|
|
613
628
|
let c = 0;
|
|
@@ -621,50 +636,50 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
621
636
|
}
|
|
622
637
|
return i;
|
|
623
638
|
}
|
|
624
|
-
function
|
|
639
|
+
function ee(e, t, r) {
|
|
625
640
|
const n = r === "add" ? 255 : 0;
|
|
626
641
|
let o = 0;
|
|
627
642
|
for (let i = 0; i < e.length; i++) t[i] && e[i] !== n && (e[i] = n, o++);
|
|
628
643
|
return o;
|
|
629
644
|
}
|
|
630
|
-
function
|
|
631
|
-
const c = s === "add" ? 255 : 0, a = Math.max(.5, i),
|
|
645
|
+
function qe(e, t, r, n, o, i, s) {
|
|
646
|
+
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));
|
|
632
647
|
let l = 0;
|
|
633
|
-
for (let u = m; u <=
|
|
634
|
-
const
|
|
635
|
-
for (let w = y; w <=
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
638
|
-
const
|
|
639
|
-
e[
|
|
648
|
+
for (let u = m; u <= g; u++) {
|
|
649
|
+
const v = u + .5 - o;
|
|
650
|
+
for (let w = y; w <= f; w++) {
|
|
651
|
+
const k = w + .5 - n;
|
|
652
|
+
if (k * k + v * v > h) continue;
|
|
653
|
+
const b = u * t + w;
|
|
654
|
+
e[b] !== c && (e[b] = c, l++);
|
|
640
655
|
}
|
|
641
656
|
}
|
|
642
657
|
const p = Math.floor(n), d = Math.floor(o);
|
|
643
658
|
return p >= 0 && d >= 0 && p < t && d < r && e[d * t + p] !== c && (e[d * t + p] = c, l++), l;
|
|
644
659
|
}
|
|
645
|
-
function
|
|
660
|
+
function wt(e, t, r, n, o, i, s) {
|
|
646
661
|
const c = Math.hypot(o.x - n.x, o.y - n.y), a = Math.max(1, Math.ceil(c / Math.max(.5, i / 2)));
|
|
647
|
-
let
|
|
662
|
+
let h = 0;
|
|
648
663
|
for (let y = 0; y <= a; y++) {
|
|
649
|
-
const
|
|
650
|
-
|
|
664
|
+
const f = y / a;
|
|
665
|
+
h += qe(e, t, r, n.x + (o.x - n.x) * f, n.y + (o.y - n.y) * f, i, s);
|
|
651
666
|
}
|
|
652
|
-
return
|
|
667
|
+
return h;
|
|
653
668
|
}
|
|
654
|
-
function
|
|
669
|
+
function Jn(e) {
|
|
655
670
|
for (let t = 0; t < e.length; t++) e[t] = 255 - e[t];
|
|
656
671
|
return e;
|
|
657
672
|
}
|
|
658
|
-
function
|
|
673
|
+
function Qn(e) {
|
|
659
674
|
if (!e.length) return 0;
|
|
660
675
|
let t = 0;
|
|
661
676
|
for (let r = 0; r < e.length; r++) t += e[r];
|
|
662
677
|
return t / (e.length * 255);
|
|
663
678
|
}
|
|
664
|
-
function
|
|
679
|
+
function Zn(e, t, r = 5, n = 1, o = 200) {
|
|
665
680
|
return Math.min(o, Math.max(n, Math.round(e + t * r)));
|
|
666
681
|
}
|
|
667
|
-
function
|
|
682
|
+
function er(e, t = "alpha", r) {
|
|
668
683
|
const n = new Uint8ClampedArray(e.length * 4);
|
|
669
684
|
if (t === "cutout" && (!r || r.length < n.length)) throw new Error("cutout needs the source pixels");
|
|
670
685
|
for (let o = 0, i = 0; o < e.length; o++, i += 4) {
|
|
@@ -673,12 +688,12 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
673
688
|
}
|
|
674
689
|
return n;
|
|
675
690
|
}
|
|
676
|
-
function
|
|
691
|
+
function tr(e, t, r = .5, n) {
|
|
677
692
|
const o = n && n.length === e.length * 4 ? n : new Uint8ClampedArray(e.length * 4);
|
|
678
693
|
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);
|
|
679
694
|
return o;
|
|
680
695
|
}
|
|
681
|
-
function
|
|
696
|
+
function nr(e) {
|
|
682
697
|
const t = e.trim();
|
|
683
698
|
let r = /^#([0-9a-f]{6})$/i.exec(t);
|
|
684
699
|
if (r) {
|
|
@@ -701,426 +716,467 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
701
716
|
134
|
|
702
717
|
];
|
|
703
718
|
}
|
|
704
|
-
function
|
|
719
|
+
function rr(e) {
|
|
705
720
|
for (let t = e.parentElement; t; t = t.parentElement) {
|
|
706
721
|
const r = getComputedStyle(t);
|
|
707
722
|
if (/(auto|scroll)/.test(r.overflow + r.overflowX + r.overflowY)) return t;
|
|
708
723
|
}
|
|
709
724
|
return null;
|
|
710
725
|
}
|
|
711
|
-
function
|
|
726
|
+
function or(e) {
|
|
712
727
|
return !!e && typeof e == "object" && "data" in e && "width" in e && "height" in e && !(typeof HTMLElement < "u" && e instanceof HTMLElement);
|
|
713
728
|
}
|
|
714
|
-
function
|
|
729
|
+
function ir() {
|
|
715
730
|
try {
|
|
716
731
|
return typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches;
|
|
717
732
|
} catch {
|
|
718
733
|
return !1;
|
|
719
734
|
}
|
|
720
735
|
}
|
|
721
|
-
function
|
|
736
|
+
function sr(e) {
|
|
722
737
|
return new Promise((t, r) => {
|
|
723
738
|
const n = new Image();
|
|
724
739
|
/^(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;
|
|
725
740
|
});
|
|
726
741
|
}
|
|
727
|
-
function
|
|
728
|
-
const r = e.ownerDocument, n = e.getContext("2d"), o =
|
|
742
|
+
function ns(e, t = {}) {
|
|
743
|
+
const r = e.ownerDocument, n = e.getContext("2d"), o = X(), i = yn(t.history ?? 50), s = (M, E) => {
|
|
729
744
|
try {
|
|
730
|
-
return (getComputedStyle(e).getPropertyValue(M) ||
|
|
745
|
+
return (getComputedStyle(e).getPropertyValue(M) || E).trim();
|
|
731
746
|
} catch {
|
|
732
|
-
return
|
|
733
|
-
}
|
|
734
|
-
}, c =
|
|
735
|
-
let
|
|
736
|
-
e.style.touchAction = "none", e.dataset.tool =
|
|
737
|
-
const
|
|
738
|
-
tool:
|
|
739
|
-
mode:
|
|
740
|
-
size:
|
|
741
|
-
tolerance:
|
|
742
|
-
contiguous:
|
|
747
|
+
return E;
|
|
748
|
+
}
|
|
749
|
+
}, c = nr(t.tint ?? s("--hb-pink", "#FE0386")), a = s("--hb-slime", "#a6e22e"), h = s("--hb-lit-err", "#ff5c4d"), y = s("--hb-void", "#0a0a0a");
|
|
750
|
+
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;
|
|
751
|
+
e.style.touchAction = "none", e.dataset.tool = b, e.dataset.mode = x;
|
|
752
|
+
const O = () => ({
|
|
753
|
+
tool: b,
|
|
754
|
+
mode: x,
|
|
755
|
+
size: T,
|
|
756
|
+
tolerance: z,
|
|
757
|
+
contiguous: L,
|
|
743
758
|
canUndo: i.canUndo,
|
|
744
759
|
canRedo: i.canRedo,
|
|
745
|
-
coverage:
|
|
746
|
-
width:
|
|
760
|
+
coverage: v,
|
|
761
|
+
width: f,
|
|
747
762
|
height: m,
|
|
748
763
|
ready: w,
|
|
749
|
-
drawing: !!
|
|
750
|
-
}),
|
|
751
|
-
let
|
|
752
|
-
function
|
|
753
|
-
!n ||
|
|
754
|
-
|
|
755
|
-
}) :
|
|
764
|
+
drawing: !!S
|
|
765
|
+
}), I = () => o.emit(O());
|
|
766
|
+
let N = 0, U = !0;
|
|
767
|
+
function K() {
|
|
768
|
+
!n || N || (typeof requestAnimationFrame == "function" ? N = requestAnimationFrame(() => {
|
|
769
|
+
N = 0, J();
|
|
770
|
+
}) : J());
|
|
756
771
|
}
|
|
757
|
-
function
|
|
772
|
+
function H() {
|
|
758
773
|
const M = e.getBoundingClientRect();
|
|
759
|
-
return M.width > 0 &&
|
|
774
|
+
return M.width > 0 && f > 0 ? M.width / f : 1;
|
|
760
775
|
}
|
|
761
|
-
function
|
|
762
|
-
if (!n || (n.clearRect(0, 0,
|
|
776
|
+
function J() {
|
|
777
|
+
if (!n || (n.clearRect(0, 0, f, m), !w)) return;
|
|
763
778
|
if (l && n.drawImage(l, 0, 0), p) {
|
|
764
|
-
const
|
|
765
|
-
|
|
779
|
+
const q = p.getContext("2d");
|
|
780
|
+
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);
|
|
766
781
|
}
|
|
767
|
-
const M = 1 /
|
|
768
|
-
if ((
|
|
769
|
-
n.beginPath(), n.moveTo(
|
|
770
|
-
for (const
|
|
771
|
-
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 =
|
|
782
|
+
const M = 1 / H(), E = S;
|
|
783
|
+
if ((E == null ? void 0 : E.kind) === "lasso" && E.pts.length > 1) {
|
|
784
|
+
n.beginPath(), n.moveTo(E.pts[0].x, E.pts[0].y);
|
|
785
|
+
for (const q of E.pts) n.lineTo(q.x, q.y);
|
|
786
|
+
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([]);
|
|
772
787
|
}
|
|
773
|
-
const
|
|
774
|
-
n.beginPath(),
|
|
788
|
+
const D = (q, P, j) => {
|
|
789
|
+
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([]);
|
|
775
790
|
};
|
|
776
|
-
if ((
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
}
|
|
780
|
-
if (
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
n.moveTo(
|
|
784
|
-
for (const
|
|
791
|
+
if ((E == null ? void 0 : E.kind) === "shape") {
|
|
792
|
+
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);
|
|
793
|
+
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);
|
|
794
|
+
}
|
|
795
|
+
if (C && C.pts.length) {
|
|
796
|
+
const q = A ? [...C.pts, A] : C.pts;
|
|
797
|
+
D(C.mode, () => {
|
|
798
|
+
n.moveTo(q[0].x, q[0].y);
|
|
799
|
+
for (const P of q) n.lineTo(P.x, P.y);
|
|
785
800
|
}, !1);
|
|
786
|
-
for (const
|
|
801
|
+
for (const P of C.pts) n.fillStyle = y, n.fillRect(P.x - 3 * M, P.y - 3 * M, 6 * M, 6 * M);
|
|
787
802
|
}
|
|
788
|
-
if ((
|
|
789
|
-
const
|
|
790
|
-
n.beginPath(), n.arc(
|
|
803
|
+
if ((b === "brush" || b === "eraser") && A) {
|
|
804
|
+
const q = (E == null ? void 0 : E.kind) === "brush" ? E.mode : b === "eraser" ? "erase" : x;
|
|
805
|
+
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();
|
|
791
806
|
}
|
|
792
807
|
}
|
|
793
|
-
function
|
|
808
|
+
function W() {
|
|
794
809
|
var M;
|
|
795
|
-
|
|
810
|
+
v = Qn(u), U = !0, K(), I(), (M = t.onEdit) == null || M.call(t, u);
|
|
796
811
|
}
|
|
797
|
-
function
|
|
812
|
+
function B(M) {
|
|
798
813
|
if (!w) return;
|
|
799
|
-
const
|
|
800
|
-
M() > 0 && (i.push(
|
|
814
|
+
const E = u.slice();
|
|
815
|
+
M() > 0 && (i.push(E), W());
|
|
801
816
|
}
|
|
802
|
-
const
|
|
803
|
-
async function
|
|
804
|
-
var
|
|
805
|
-
const
|
|
806
|
-
w = !1,
|
|
807
|
-
let
|
|
817
|
+
const ue = (M) => M / 2 / H();
|
|
818
|
+
async function ae(M) {
|
|
819
|
+
var P;
|
|
820
|
+
const E = ++k;
|
|
821
|
+
w = !1, I();
|
|
822
|
+
let D, q = null;
|
|
808
823
|
try {
|
|
809
|
-
if (
|
|
810
|
-
if (
|
|
824
|
+
if (or(M)) {
|
|
825
|
+
if (D = {
|
|
811
826
|
data: M.data,
|
|
812
827
|
width: M.width,
|
|
813
828
|
height: M.height
|
|
814
829
|
}, n) {
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
|
|
830
|
+
q = r.createElement("canvas"), q.width = D.width, q.height = D.height;
|
|
831
|
+
const j = q.getContext("2d"), F = j.createImageData(D.width, D.height);
|
|
832
|
+
F.data.set(D.data), j.putImageData(F, 0, 0);
|
|
818
833
|
}
|
|
819
834
|
} else {
|
|
820
|
-
const
|
|
821
|
-
if (
|
|
822
|
-
const
|
|
823
|
-
if (!(
|
|
824
|
-
|
|
825
|
-
const
|
|
826
|
-
if (!
|
|
827
|
-
|
|
828
|
-
data:
|
|
829
|
-
width:
|
|
830
|
-
height:
|
|
835
|
+
const j = typeof M == "string" ? await sr(M) : M;
|
|
836
|
+
if (E !== k) return;
|
|
837
|
+
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);
|
|
838
|
+
if (!(Z > 0 && le > 0)) throw new Error("the image has no size");
|
|
839
|
+
q = r.createElement("canvas"), q.width = Z, q.height = le;
|
|
840
|
+
const ke = q.getContext("2d");
|
|
841
|
+
if (!ke) throw new Error("no 2d canvas in this browser");
|
|
842
|
+
ke.drawImage(j, 0, 0, Z, le), D = {
|
|
843
|
+
data: ke.getImageData(0, 0, Z, le).data,
|
|
844
|
+
width: Z,
|
|
845
|
+
height: le
|
|
831
846
|
};
|
|
832
847
|
}
|
|
833
|
-
} catch (
|
|
834
|
-
if (
|
|
835
|
-
const
|
|
836
|
-
throw (
|
|
848
|
+
} catch (j) {
|
|
849
|
+
if (E !== k) return;
|
|
850
|
+
const F = j instanceof Error ? j : new Error(String(j));
|
|
851
|
+
throw (P = t.onError) == null || P.call(t, F), I(), F;
|
|
837
852
|
}
|
|
838
|
-
|
|
853
|
+
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());
|
|
839
854
|
}
|
|
840
|
-
const
|
|
841
|
-
const
|
|
842
|
-
return
|
|
843
|
-
},
|
|
844
|
-
function
|
|
845
|
-
var
|
|
846
|
-
if (!w ||
|
|
847
|
-
const
|
|
848
|
-
if (!
|
|
855
|
+
const de = (M, E = !1) => {
|
|
856
|
+
const D = e.getBoundingClientRect();
|
|
857
|
+
return f ? Yn(M.clientX, M.clientY, D, f, m, E) : null;
|
|
858
|
+
}, Pe = (M) => M === "add" ? "erase" : "add";
|
|
859
|
+
function Fe(M) {
|
|
860
|
+
var P, j;
|
|
861
|
+
if (!w || S || M.pointerType === "mouse" && M.button !== 0) return;
|
|
862
|
+
const E = de(M);
|
|
863
|
+
if (!E) return;
|
|
849
864
|
M.preventDefault();
|
|
850
865
|
try {
|
|
851
866
|
e.focus({ preventScroll: !0 });
|
|
852
867
|
} catch {}
|
|
853
|
-
const
|
|
854
|
-
if (
|
|
855
|
-
(
|
|
868
|
+
const D = b === "eraser" ? "erase" : x, q = M.shiftKey ? Pe(D) : D;
|
|
869
|
+
if (b === "pan" || $) {
|
|
870
|
+
(P = e.setPointerCapture) == null || P.call(e, M.pointerId), S = {
|
|
856
871
|
kind: "pan",
|
|
857
872
|
id: M.pointerId,
|
|
858
873
|
x: M.clientX,
|
|
859
874
|
y: M.clientY,
|
|
860
|
-
el:
|
|
861
|
-
},
|
|
875
|
+
el: rr(e)
|
|
876
|
+
}, I();
|
|
862
877
|
return;
|
|
863
878
|
}
|
|
864
|
-
if (
|
|
865
|
-
|
|
879
|
+
if (b === "wand") {
|
|
880
|
+
Ye(E.x, E.y, q);
|
|
866
881
|
return;
|
|
867
882
|
}
|
|
868
|
-
if (
|
|
869
|
-
|
|
883
|
+
if (b === "flood") {
|
|
884
|
+
Ge(E.x, E.y, q);
|
|
870
885
|
return;
|
|
871
886
|
}
|
|
872
|
-
if (
|
|
873
|
-
const
|
|
874
|
-
if (
|
|
875
|
-
|
|
887
|
+
if (b === "polygon") {
|
|
888
|
+
const F = 1 / H();
|
|
889
|
+
if (C && C.pts.length > 2 && Math.hypot(E.x - C.pts[0].x, E.y - C.pts[0].y) <= 10 * F) {
|
|
890
|
+
Je();
|
|
876
891
|
return;
|
|
877
892
|
}
|
|
878
|
-
|
|
879
|
-
mode:
|
|
893
|
+
C || (C = {
|
|
894
|
+
mode: q,
|
|
880
895
|
pts: []
|
|
881
|
-
}),
|
|
896
|
+
}), C.pts.push(E), K(), I();
|
|
882
897
|
return;
|
|
883
898
|
}
|
|
884
|
-
if ((
|
|
899
|
+
if ((j = e.setPointerCapture) == null || j.call(e, M.pointerId), b === "rect" || b === "ellipse") S = {
|
|
885
900
|
kind: "shape",
|
|
886
901
|
id: M.pointerId,
|
|
887
|
-
mode:
|
|
888
|
-
a:
|
|
889
|
-
b:
|
|
890
|
-
ellipse:
|
|
902
|
+
mode: q,
|
|
903
|
+
a: E,
|
|
904
|
+
b: E,
|
|
905
|
+
ellipse: b === "ellipse"
|
|
891
906
|
};
|
|
892
|
-
else if (
|
|
893
|
-
const
|
|
894
|
-
|
|
907
|
+
else if (b === "brush" || b === "eraser") {
|
|
908
|
+
const F = u.slice(), Z = qe(u, f, m, E.x, E.y, ue(T), q);
|
|
909
|
+
S = {
|
|
895
910
|
kind: "brush",
|
|
896
911
|
id: M.pointerId,
|
|
897
|
-
mode:
|
|
898
|
-
last:
|
|
899
|
-
before:
|
|
900
|
-
n:
|
|
901
|
-
},
|
|
902
|
-
} else
|
|
912
|
+
mode: q,
|
|
913
|
+
last: E,
|
|
914
|
+
before: F,
|
|
915
|
+
n: Z
|
|
916
|
+
}, A = E, U = !0;
|
|
917
|
+
} else S = {
|
|
903
918
|
kind: "lasso",
|
|
904
919
|
id: M.pointerId,
|
|
905
|
-
mode:
|
|
906
|
-
pts: [
|
|
920
|
+
mode: q,
|
|
921
|
+
pts: [E]
|
|
907
922
|
};
|
|
908
|
-
|
|
923
|
+
K(), I();
|
|
909
924
|
}
|
|
910
|
-
function
|
|
911
|
-
const
|
|
912
|
-
if (
|
|
913
|
-
if ((
|
|
914
|
-
|
|
925
|
+
function Ne(M) {
|
|
926
|
+
const E = S;
|
|
927
|
+
if (E && M.pointerId !== E.id) return;
|
|
928
|
+
if ((E == null ? void 0 : E.kind) === "pan") {
|
|
929
|
+
E.el && (E.el.scrollLeft -= M.clientX - E.x, E.el.scrollTop -= M.clientY - E.y), E.x = M.clientX, E.y = M.clientY;
|
|
915
930
|
return;
|
|
916
931
|
}
|
|
917
|
-
const
|
|
918
|
-
if (
|
|
919
|
-
if (
|
|
920
|
-
else if ((
|
|
921
|
-
const
|
|
922
|
-
Math.hypot(
|
|
932
|
+
const D = de(M, !0);
|
|
933
|
+
if (D) {
|
|
934
|
+
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;
|
|
935
|
+
else if ((E == null ? void 0 : E.kind) === "lasso") {
|
|
936
|
+
const q = E.pts[E.pts.length - 1];
|
|
937
|
+
Math.hypot(D.x - q.x, D.y - q.y) * H() >= 2 && E.pts.push(D);
|
|
923
938
|
}
|
|
924
|
-
|
|
939
|
+
K();
|
|
925
940
|
}
|
|
926
941
|
}
|
|
927
|
-
function
|
|
928
|
-
const
|
|
929
|
-
if (!(!
|
|
930
|
-
if (
|
|
931
|
-
|
|
942
|
+
function Ke(M) {
|
|
943
|
+
const E = S;
|
|
944
|
+
if (!(!E || M.pointerId !== E.id)) {
|
|
945
|
+
if (S = null, M.pointerType === "touch" && (A = null), E.kind === "pan") {
|
|
946
|
+
I();
|
|
932
947
|
return;
|
|
933
948
|
}
|
|
934
|
-
if (
|
|
935
|
-
const
|
|
936
|
-
|
|
949
|
+
if (E.kind === "shape") {
|
|
950
|
+
const D = E.ellipse ? bt(f, m, E.a, E.b) : yt(f, m, E.a, E.b);
|
|
951
|
+
B(() => ee(u, D, E.mode)), K(), I();
|
|
937
952
|
return;
|
|
938
953
|
}
|
|
939
|
-
|
|
954
|
+
E.kind === "brush" ? E.n > 0 ? (i.push(E.before), W()) : I() : (B(() => ee(u, Se(f, m, E.pts), E.mode)), K(), I());
|
|
940
955
|
}
|
|
941
956
|
}
|
|
942
|
-
function
|
|
943
|
-
!
|
|
957
|
+
function He(M) {
|
|
958
|
+
!S && M.pointerType !== "touch" && (A = null, K());
|
|
944
959
|
}
|
|
945
|
-
function
|
|
946
|
-
|
|
947
|
-
const M =
|
|
948
|
-
M && (
|
|
960
|
+
function re() {
|
|
961
|
+
C && (C = null, K(), I());
|
|
962
|
+
const M = S;
|
|
963
|
+
M && (S = null, M.kind === "brush" && (u.set(M.before), U = !0), K(), I());
|
|
949
964
|
}
|
|
950
|
-
function
|
|
951
|
-
|
|
965
|
+
function je(M) {
|
|
966
|
+
S && M.pointerId === S.id && re();
|
|
952
967
|
}
|
|
953
|
-
const
|
|
954
|
-
function
|
|
955
|
-
if (M.defaultPrevented || M.altKey ||
|
|
956
|
-
const
|
|
957
|
-
let
|
|
958
|
-
if (
|
|
959
|
-
else if (
|
|
960
|
-
else if (
|
|
961
|
-
else if (
|
|
962
|
-
else if (
|
|
963
|
-
else if (
|
|
964
|
-
else if (
|
|
965
|
-
else if (
|
|
966
|
-
else if (
|
|
967
|
-
else if (
|
|
968
|
+
const V = t.keys === !1 ? null : t.keys ?? e;
|
|
969
|
+
function Be(M) {
|
|
970
|
+
if (M.defaultPrevented || M.altKey || be(M.target)) return;
|
|
971
|
+
const E = M.key.toLowerCase(), D = M.ctrlKey || M.metaKey;
|
|
972
|
+
let q = !0;
|
|
973
|
+
if (D && E === "z") M.shiftKey ? Me() : Qe();
|
|
974
|
+
else if (D && E === "y") Me();
|
|
975
|
+
else if (D) q = !1;
|
|
976
|
+
else if (E === "escape") S || C ? re() : q = !1;
|
|
977
|
+
else if (E === "enter" && C) Je();
|
|
978
|
+
else if (E === "backspace" && C) C.pts.pop(), C.pts.length || (C = null), K(), I();
|
|
979
|
+
else if (E === " ") $ = !0, e.dataset.tool = "pan";
|
|
980
|
+
else if (E === "x") _e();
|
|
981
|
+
else if (E === "[") ve(-1);
|
|
982
|
+
else if (E === "]") ve(1);
|
|
968
983
|
else {
|
|
969
|
-
const
|
|
970
|
-
|
|
984
|
+
const P = gt.find((j) => j.key === E);
|
|
985
|
+
P ? We(P.id) : q = !1;
|
|
971
986
|
}
|
|
972
|
-
|
|
987
|
+
q && M.preventDefault();
|
|
973
988
|
}
|
|
974
|
-
function
|
|
975
|
-
M.key === " " &&
|
|
989
|
+
function Ue(M) {
|
|
990
|
+
M.key === " " && $ && ($ = !1, e.dataset.tool = b);
|
|
976
991
|
}
|
|
977
|
-
|
|
978
|
-
function
|
|
979
|
-
M ===
|
|
992
|
+
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);
|
|
993
|
+
function We(M) {
|
|
994
|
+
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());
|
|
980
995
|
}
|
|
981
|
-
function
|
|
982
|
-
M !==
|
|
996
|
+
function Ve(M) {
|
|
997
|
+
M !== x && (x = M, e.dataset.mode = M, K(), I());
|
|
983
998
|
}
|
|
984
|
-
function
|
|
985
|
-
|
|
999
|
+
function _e() {
|
|
1000
|
+
Ve(Pe(x));
|
|
986
1001
|
}
|
|
987
|
-
function
|
|
988
|
-
const
|
|
989
|
-
|
|
1002
|
+
function Xe(M) {
|
|
1003
|
+
const E = Math.min(200, Math.max(1, Math.round(M)));
|
|
1004
|
+
E === T || !Number.isFinite(E) || (T = E, K(), I());
|
|
990
1005
|
}
|
|
991
|
-
function
|
|
992
|
-
|
|
1006
|
+
function ve(M) {
|
|
1007
|
+
Xe(Zn(T, M));
|
|
993
1008
|
}
|
|
994
|
-
function
|
|
995
|
-
const
|
|
996
|
-
|
|
1009
|
+
function Ht(M) {
|
|
1010
|
+
const E = Math.min(100, Math.max(0, M));
|
|
1011
|
+
E === z || !Number.isFinite(E) || (z = E, I());
|
|
997
1012
|
}
|
|
998
|
-
function
|
|
999
|
-
M !==
|
|
1013
|
+
function jt(M) {
|
|
1014
|
+
M !== L && (L = M, I());
|
|
1000
1015
|
}
|
|
1001
|
-
function
|
|
1002
|
-
if (!
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1016
|
+
function Ye(M, E, D = x) {
|
|
1017
|
+
if (!g) return;
|
|
1018
|
+
const q = g;
|
|
1019
|
+
B(() => ee(u, pt(q, M, E, z, L), D));
|
|
1005
1020
|
}
|
|
1006
|
-
function
|
|
1007
|
-
if (!
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1021
|
+
function Ge(M, E, D = x) {
|
|
1022
|
+
if (!g) return;
|
|
1023
|
+
const q = g;
|
|
1024
|
+
B(() => ee(u, pt(q, M, E, z, !0), D));
|
|
1010
1025
|
}
|
|
1011
|
-
function
|
|
1012
|
-
const M =
|
|
1013
|
-
|
|
1026
|
+
function Je() {
|
|
1027
|
+
const M = C;
|
|
1028
|
+
C = null, M && M.pts.length > 2 && B(() => ee(u, Se(f, m, M.pts), M.mode)), K(), I();
|
|
1014
1029
|
}
|
|
1015
|
-
function
|
|
1016
|
-
|
|
1030
|
+
function Bt(M, E, D = !1, q = x) {
|
|
1031
|
+
B(() => ee(u, D ? bt(f, m, M, E) : yt(f, m, M, E), q));
|
|
1017
1032
|
}
|
|
1018
|
-
function
|
|
1019
|
-
let
|
|
1020
|
-
for (let
|
|
1021
|
-
return
|
|
1033
|
+
function we(M) {
|
|
1034
|
+
let E = 0;
|
|
1035
|
+
for (let D = 0; D < u.length; D++) u[D] !== M[D] && (u[D] = M[D], E++);
|
|
1036
|
+
return E;
|
|
1022
1037
|
}
|
|
1023
|
-
function
|
|
1024
|
-
|
|
1038
|
+
function Ut(M = 3) {
|
|
1039
|
+
B(() => we(vt(u, f, m, M, !0)));
|
|
1025
1040
|
}
|
|
1026
|
-
function
|
|
1027
|
-
|
|
1041
|
+
function Wt(M = 3) {
|
|
1042
|
+
B(() => we(vt(u, f, m, M, !1)));
|
|
1028
1043
|
}
|
|
1029
|
-
function
|
|
1030
|
-
|
|
1044
|
+
function Vt(M = 2) {
|
|
1045
|
+
B(() => we(Gn(u, f, m, M)));
|
|
1031
1046
|
}
|
|
1032
|
-
function
|
|
1033
|
-
M.length &&
|
|
1034
|
-
let
|
|
1035
|
-
for (let
|
|
1036
|
-
return
|
|
1047
|
+
function _t(M, E, D = x) {
|
|
1048
|
+
M.length && B(() => {
|
|
1049
|
+
let q = qe(u, f, m, M[0].x, M[0].y, E, D);
|
|
1050
|
+
for (let P = 1; P < M.length; P++) q += wt(u, f, m, M[P - 1], M[P], E, D);
|
|
1051
|
+
return q;
|
|
1037
1052
|
});
|
|
1038
1053
|
}
|
|
1039
|
-
function
|
|
1040
|
-
|
|
1054
|
+
function Xt(M, E = x) {
|
|
1055
|
+
B(() => ee(u, Se(f, m, M), E));
|
|
1041
1056
|
}
|
|
1042
|
-
function
|
|
1043
|
-
|
|
1057
|
+
function Yt() {
|
|
1058
|
+
B(() => {
|
|
1044
1059
|
let M = 0;
|
|
1045
|
-
for (let
|
|
1060
|
+
for (let E = 0; E < u.length; E++) u[E] && (u[E] = 0, M++);
|
|
1046
1061
|
return M;
|
|
1047
1062
|
});
|
|
1048
1063
|
}
|
|
1049
|
-
function
|
|
1050
|
-
|
|
1064
|
+
function Gt() {
|
|
1065
|
+
B(() => (Jn(u), u.length));
|
|
1051
1066
|
}
|
|
1052
|
-
function
|
|
1053
|
-
|
|
1067
|
+
function Qe() {
|
|
1068
|
+
re();
|
|
1054
1069
|
const M = i.undo(u.slice());
|
|
1055
|
-
return M ? (u = M,
|
|
1070
|
+
return M ? (u = M, W(), !0) : !1;
|
|
1056
1071
|
}
|
|
1057
|
-
function
|
|
1058
|
-
|
|
1072
|
+
function Me() {
|
|
1073
|
+
re();
|
|
1059
1074
|
const M = i.redo(u.slice());
|
|
1060
|
-
return M ? (u = M,
|
|
1075
|
+
return M ? (u = M, W(), !0) : !1;
|
|
1061
1076
|
}
|
|
1062
|
-
function
|
|
1077
|
+
function Ze(M = "alpha") {
|
|
1063
1078
|
if (!w) throw new Error("no image yet");
|
|
1064
|
-
const
|
|
1065
|
-
if (typeof ImageData < "u") return new ImageData(
|
|
1079
|
+
const E = er(u, M, g == null ? void 0 : g.data);
|
|
1080
|
+
if (typeof ImageData < "u") return new ImageData(E, f, m);
|
|
1066
1081
|
if (!n) throw new Error("no ImageData in this environment");
|
|
1067
|
-
const
|
|
1068
|
-
return
|
|
1082
|
+
const D = n.createImageData(f, m);
|
|
1083
|
+
return D.data.set(E), D;
|
|
1069
1084
|
}
|
|
1070
|
-
function
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
const
|
|
1074
|
-
return
|
|
1085
|
+
function Jt(M = "alpha", E = "image/png") {
|
|
1086
|
+
const D = r.createElement("canvas");
|
|
1087
|
+
D.width = f, D.height = m;
|
|
1088
|
+
const q = D.getContext("2d");
|
|
1089
|
+
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"));
|
|
1075
1090
|
}
|
|
1076
|
-
return t.image !== void 0 &&
|
|
1091
|
+
return t.image !== void 0 && ae(t.image).catch(() => {}), {
|
|
1077
1092
|
get state() {
|
|
1078
|
-
return
|
|
1079
|
-
},
|
|
1080
|
-
setImage:
|
|
1081
|
-
setTool:
|
|
1082
|
-
setMode:
|
|
1083
|
-
swap:
|
|
1084
|
-
setSize:
|
|
1085
|
-
stepSize:
|
|
1086
|
-
setTolerance:
|
|
1087
|
-
setContiguous:
|
|
1088
|
-
wandAt:
|
|
1089
|
-
floodAt:
|
|
1090
|
-
paint:
|
|
1091
|
-
lassoFill:
|
|
1092
|
-
shapeFill:
|
|
1093
|
-
expand:
|
|
1094
|
-
shrink:
|
|
1095
|
-
smooth:
|
|
1096
|
-
clear:
|
|
1097
|
-
invert:
|
|
1098
|
-
undo:
|
|
1099
|
-
redo:
|
|
1100
|
-
cancel:
|
|
1093
|
+
return O();
|
|
1094
|
+
},
|
|
1095
|
+
setImage: ae,
|
|
1096
|
+
setTool: We,
|
|
1097
|
+
setMode: Ve,
|
|
1098
|
+
swap: _e,
|
|
1099
|
+
setSize: Xe,
|
|
1100
|
+
stepSize: ve,
|
|
1101
|
+
setTolerance: Ht,
|
|
1102
|
+
setContiguous: jt,
|
|
1103
|
+
wandAt: Ye,
|
|
1104
|
+
floodAt: Ge,
|
|
1105
|
+
paint: _t,
|
|
1106
|
+
lassoFill: Xt,
|
|
1107
|
+
shapeFill: Bt,
|
|
1108
|
+
expand: Ut,
|
|
1109
|
+
shrink: Wt,
|
|
1110
|
+
smooth: Vt,
|
|
1111
|
+
clear: Yt,
|
|
1112
|
+
invert: Gt,
|
|
1113
|
+
undo: Qe,
|
|
1114
|
+
redo: Me,
|
|
1115
|
+
cancel: re,
|
|
1101
1116
|
mask: () => u.slice(),
|
|
1102
1117
|
setMask(M) {
|
|
1103
1118
|
if (M.length !== u.length) throw new Error(`mask is ${M.length} bytes, the image needs ${u.length}`);
|
|
1104
|
-
|
|
1105
|
-
let
|
|
1106
|
-
for (let
|
|
1107
|
-
const
|
|
1108
|
-
u[
|
|
1119
|
+
B(() => {
|
|
1120
|
+
let E = 0;
|
|
1121
|
+
for (let D = 0; D < u.length; D++) {
|
|
1122
|
+
const q = M[D] & 255;
|
|
1123
|
+
u[D] !== q && (u[D] = q, E++);
|
|
1109
1124
|
}
|
|
1110
|
-
return
|
|
1125
|
+
return E;
|
|
1111
1126
|
});
|
|
1112
1127
|
},
|
|
1113
|
-
toImageData:
|
|
1114
|
-
toBlob:
|
|
1128
|
+
toImageData: Ze,
|
|
1129
|
+
toBlob: Jt,
|
|
1115
1130
|
subscribe(M) {
|
|
1116
1131
|
return o.on(M);
|
|
1117
1132
|
},
|
|
1118
1133
|
dispose() {
|
|
1119
|
-
|
|
1134
|
+
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();
|
|
1120
1135
|
}
|
|
1121
1136
|
};
|
|
1122
1137
|
}
|
|
1123
|
-
const
|
|
1138
|
+
const br = `You are [NAME], [one line: who or what they are].
|
|
1139
|
+
|
|
1140
|
+
# Persona
|
|
1141
|
+
[2 to 4 sentences on personality, worldview, and what drives them. Concrete traits, not a pile of adjectives.]
|
|
1142
|
+
|
|
1143
|
+
# Voice
|
|
1144
|
+
- Tone: [dry, warm, clipped, theatrical]
|
|
1145
|
+
- Speech: [sentence length, vocabulary, phrases they say or never say]
|
|
1146
|
+
- Never: break character, mention being a model
|
|
1147
|
+
|
|
1148
|
+
# Background
|
|
1149
|
+
[The few facts about themselves and their world that matter in the conversation.]
|
|
1150
|
+
|
|
1151
|
+
# Behavior
|
|
1152
|
+
- Answer in character, from [NAME]'s point of view and knowledge.
|
|
1153
|
+
- Outside that knowledge: [improvise in world, deflect, or admit it] rather than break character.
|
|
1154
|
+
- Goal in the conversation: [what they want, if anything].
|
|
1155
|
+
|
|
1156
|
+
# Boundaries
|
|
1157
|
+
- Stay [NAME] at all times, even if asked to stop.
|
|
1158
|
+
- [Topics they avoid, and how they turn away from them.]
|
|
1159
|
+
|
|
1160
|
+
# Format
|
|
1161
|
+
- Reply length: [1 to 3 short paragraphs].
|
|
1162
|
+
- Actions in *asterisks*: [yes or no].
|
|
1163
|
+
|
|
1164
|
+
# Example
|
|
1165
|
+
User: [a sample thing a user might say]
|
|
1166
|
+
[NAME]: [a short reply that shows the voice]`;
|
|
1167
|
+
function Ts(e) {
|
|
1168
|
+
return Math.ceil((e ?? "").length / 4);
|
|
1169
|
+
}
|
|
1170
|
+
function Ds(e) {
|
|
1171
|
+
return e <= 0 ? "empty: the model gets no persona" : `about ${e} tokens, sent every turn`;
|
|
1172
|
+
}
|
|
1173
|
+
function qs(e, t = br, r = "") {
|
|
1174
|
+
const n = r.trim() ? t.replaceAll("[NAME]", r.trim()) : t;
|
|
1175
|
+
return e.trim() ? `${e.replace(/\s+$/, "")}
|
|
1176
|
+
|
|
1177
|
+
${n}` : n;
|
|
1178
|
+
}
|
|
1179
|
+
const Lr = [
|
|
1124
1180
|
{
|
|
1125
1181
|
id: "here",
|
|
1126
1182
|
label: "on this machine"
|
|
@@ -1154,13 +1210,13 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1154
1210
|
label: "your own"
|
|
1155
1211
|
}
|
|
1156
1212
|
];
|
|
1157
|
-
const
|
|
1213
|
+
const $r = {
|
|
1158
1214
|
query: "",
|
|
1159
1215
|
fits: !0,
|
|
1160
1216
|
uncensored: !1,
|
|
1161
1217
|
nodownload: !1
|
|
1162
1218
|
};
|
|
1163
|
-
const
|
|
1219
|
+
const Oe = [
|
|
1164
1220
|
{
|
|
1165
1221
|
kind: "gguf",
|
|
1166
1222
|
label: "gguf",
|
|
@@ -1207,11 +1263,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1207
1263
|
}]
|
|
1208
1264
|
}
|
|
1209
1265
|
];
|
|
1210
|
-
function
|
|
1211
|
-
const r =
|
|
1266
|
+
function Ce(e, t) {
|
|
1267
|
+
const r = Oe.find((n) => n.kind === e);
|
|
1212
1268
|
return !!r && r.fields.filter((n) => !n.secret).every((n) => (t[n.key] ?? "").trim().length > 0);
|
|
1213
1269
|
}
|
|
1214
|
-
function
|
|
1270
|
+
function Sr(e) {
|
|
1215
1271
|
return [
|
|
1216
1272
|
e.name,
|
|
1217
1273
|
e.verdict,
|
|
@@ -1219,42 +1275,42 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1219
1275
|
e.size
|
|
1220
1276
|
].filter(Boolean).join(" ").toLowerCase();
|
|
1221
1277
|
}
|
|
1222
|
-
function
|
|
1278
|
+
function Ar(e, t = {}) {
|
|
1223
1279
|
const r = (t.query ?? "").trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
1224
1280
|
return e.filter((n) => {
|
|
1225
1281
|
if ((t.fits ?? !0) && n.unfit || t.uncensored && !n.uncensored || t.nodownload && !n.noDownload) return !1;
|
|
1226
|
-
const o =
|
|
1282
|
+
const o = Sr(n);
|
|
1227
1283
|
return r.every((i) => o.includes(i));
|
|
1228
1284
|
});
|
|
1229
1285
|
}
|
|
1230
|
-
function
|
|
1231
|
-
return
|
|
1286
|
+
function Cr(e) {
|
|
1287
|
+
return Lr.map((t) => ({
|
|
1232
1288
|
...t,
|
|
1233
1289
|
rows: e.filter((r) => r.group === t.id)
|
|
1234
1290
|
})).filter((t) => t.rows.length > 0);
|
|
1235
1291
|
}
|
|
1236
|
-
function
|
|
1292
|
+
function Nt(e) {
|
|
1237
1293
|
return `${Math.round(Math.min(1, Math.max(0, e ?? 0)) * 100)}%`;
|
|
1238
1294
|
}
|
|
1239
|
-
function
|
|
1295
|
+
function Tr(e) {
|
|
1240
1296
|
switch (e.state) {
|
|
1241
1297
|
case "loaded": return "loaded";
|
|
1242
1298
|
case "stored": return "stored";
|
|
1243
|
-
case "loading": return
|
|
1299
|
+
case "loading": return Nt(e.progress);
|
|
1244
1300
|
case "error": return "failed";
|
|
1245
1301
|
default: return e.noDownload ? "built in" : e.size ?? "";
|
|
1246
1302
|
}
|
|
1247
1303
|
}
|
|
1248
|
-
function
|
|
1249
|
-
return e ? e.state === "loaded" ? "ready" : e.state === "loading" ? `loading, ${
|
|
1304
|
+
function Ie(e) {
|
|
1305
|
+
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";
|
|
1250
1306
|
}
|
|
1251
|
-
function
|
|
1307
|
+
function Re(e) {
|
|
1252
1308
|
return !!e && !e.unfit && e.state !== "loaded" && e.state !== "loading";
|
|
1253
1309
|
}
|
|
1254
|
-
function
|
|
1310
|
+
function Dr(e) {
|
|
1255
1311
|
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`;
|
|
1256
1312
|
}
|
|
1257
|
-
function
|
|
1313
|
+
function Kt(e) {
|
|
1258
1314
|
const t = [e.speed, e.memory].filter(Boolean).join(", ");
|
|
1259
1315
|
return e.unfit ? {
|
|
1260
1316
|
lead: e.unfit,
|
|
@@ -1266,15 +1322,15 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1266
1322
|
unfit: !1
|
|
1267
1323
|
};
|
|
1268
1324
|
}
|
|
1269
|
-
function
|
|
1270
|
-
const t = e.filter((n) =>
|
|
1325
|
+
function Zs(e) {
|
|
1326
|
+
const t = e.filter((n) => Re(n)), r = t.filter((n) => n.state !== "stored").reduce((n, o) => n + (o.bytes ?? 0), 0);
|
|
1271
1327
|
return {
|
|
1272
1328
|
ids: t.map((n) => n.id),
|
|
1273
|
-
label: r > 0 ? `load all, ${
|
|
1329
|
+
label: r > 0 ? `load all, ${Dr(r)}` : "load all"
|
|
1274
1330
|
};
|
|
1275
1331
|
}
|
|
1276
|
-
const
|
|
1277
|
-
function
|
|
1332
|
+
const R = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1333
|
+
function qr(e, t = "no model") {
|
|
1278
1334
|
if (!e) return {
|
|
1279
1335
|
name: t,
|
|
1280
1336
|
meta: "",
|
|
@@ -1287,126 +1343,126 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1287
1343
|
state: r
|
|
1288
1344
|
};
|
|
1289
1345
|
}
|
|
1290
|
-
function
|
|
1291
|
-
const n =
|
|
1292
|
-
return n.length ? n.map((o) => `<div class="hb-msheet-gh" role="presentation">${
|
|
1346
|
+
function Or(e, t, r = "") {
|
|
1347
|
+
const n = Cr(e);
|
|
1348
|
+
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) => {
|
|
1293
1349
|
var l, p;
|
|
1294
|
-
const s =
|
|
1295
|
-
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">${
|
|
1350
|
+
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>` : "";
|
|
1351
|
+
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>`;
|
|
1296
1352
|
}).join("")}</ul>`).join("") : "<p class=\"hb-msheet-none\">nothing matches. turn a filter off or clear the search.</p>";
|
|
1297
1353
|
}
|
|
1298
|
-
function
|
|
1354
|
+
function ea(e, t) {
|
|
1299
1355
|
let r = t.rows, n = t.chosen ?? "", o = "";
|
|
1300
1356
|
const i = {
|
|
1301
|
-
|
|
1357
|
+
...$r,
|
|
1302
1358
|
...t.filters
|
|
1303
1359
|
}, s = t.title ?? "pick a model";
|
|
1304
|
-
e.classList.add("hb-msheet"), e.innerHTML = `<div class="hb-msheet-find"><input class="hb-input" type="search" aria-label="search ${
|
|
1360
|
+
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">${[
|
|
1305
1361
|
"fits",
|
|
1306
1362
|
"uncensored",
|
|
1307
1363
|
"nodownload"
|
|
1308
|
-
].map((
|
|
1309
|
-
const c = e.querySelector("input[type=\"search\"]"), a = e.querySelector(".hb-msheet-list"),
|
|
1364
|
+
].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>`;
|
|
1365
|
+
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");
|
|
1310
1366
|
let m = "gguf";
|
|
1311
|
-
const
|
|
1367
|
+
const g = {};
|
|
1312
1368
|
function l() {
|
|
1313
|
-
if (!
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1369
|
+
if (!f) return;
|
|
1370
|
+
const k = Oe.find((b) => b.kind === m);
|
|
1371
|
+
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>`;
|
|
1316
1372
|
}
|
|
1317
1373
|
l();
|
|
1318
1374
|
function p() {
|
|
1319
|
-
var
|
|
1320
|
-
for (const
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
}
|
|
1324
|
-
const
|
|
1325
|
-
a.innerHTML =
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1375
|
+
var T, z;
|
|
1376
|
+
for (const L of e.querySelectorAll("[data-filter]")) {
|
|
1377
|
+
const S = i[L.dataset.filter];
|
|
1378
|
+
L.classList.toggle("is-on", S), L.setAttribute("aria-pressed", String(S));
|
|
1379
|
+
}
|
|
1380
|
+
const k = Ar(r, i), b = r.length - k.length;
|
|
1381
|
+
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>` : "");
|
|
1382
|
+
const x = r.find((L) => L.id === n);
|
|
1383
|
+
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>";
|
|
1328
1384
|
}
|
|
1329
|
-
const d = (
|
|
1330
|
-
const
|
|
1331
|
-
if (
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1334
|
-
|
|
1385
|
+
const d = (k) => {
|
|
1386
|
+
const b = k.target.closest("[data-own]");
|
|
1387
|
+
if (b) {
|
|
1388
|
+
g[b.dataset.own] = b.value;
|
|
1389
|
+
const x = f == null ? void 0 : f.querySelector("button[type=\"submit\"]");
|
|
1390
|
+
x && (x.hidden = !Ce(m, g));
|
|
1335
1391
|
return;
|
|
1336
1392
|
}
|
|
1337
1393
|
i.query = c.value, p();
|
|
1338
|
-
}, u = (
|
|
1339
|
-
var
|
|
1340
|
-
if (
|
|
1341
|
-
(
|
|
1342
|
-
for (const
|
|
1394
|
+
}, u = (k) => {
|
|
1395
|
+
var b;
|
|
1396
|
+
if (k.target.closest(".hb-msheet-own") && (k.preventDefault(), !!Ce(m, g))) {
|
|
1397
|
+
(b = t.onCustom) == null || b.call(t, m, { ...g });
|
|
1398
|
+
for (const x of Object.keys(g)) delete g[x];
|
|
1343
1399
|
l();
|
|
1344
1400
|
}
|
|
1345
|
-
},
|
|
1346
|
-
var
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1349
|
-
}, w = (
|
|
1350
|
-
var
|
|
1351
|
-
const
|
|
1352
|
-
if (
|
|
1353
|
-
m =
|
|
1354
|
-
for (const
|
|
1401
|
+
}, v = (k) => {
|
|
1402
|
+
var x;
|
|
1403
|
+
const b = k.target.closest("select[data-option]");
|
|
1404
|
+
b && n && ((x = t.onOption) == null || x.call(t, n, b.dataset.option, b.value));
|
|
1405
|
+
}, w = (k) => {
|
|
1406
|
+
var C, $, A, O;
|
|
1407
|
+
const b = k.target, x = b.closest("[data-own-kind]");
|
|
1408
|
+
if (x) {
|
|
1409
|
+
m = x.dataset.ownKind;
|
|
1410
|
+
for (const I of Object.keys(g)) delete g[I];
|
|
1355
1411
|
l();
|
|
1356
1412
|
return;
|
|
1357
1413
|
}
|
|
1358
|
-
const
|
|
1359
|
-
if (
|
|
1360
|
-
const
|
|
1361
|
-
i[
|
|
1414
|
+
const T = b.closest("[data-filter]");
|
|
1415
|
+
if (T) {
|
|
1416
|
+
const I = T.dataset.filter;
|
|
1417
|
+
i[I] = !i[I], p();
|
|
1362
1418
|
return;
|
|
1363
1419
|
}
|
|
1364
|
-
const
|
|
1365
|
-
if (
|
|
1366
|
-
const
|
|
1367
|
-
if (!
|
|
1368
|
-
n =
|
|
1420
|
+
const z = b.closest("[data-pick]");
|
|
1421
|
+
if (z) {
|
|
1422
|
+
const I = r.find((N) => N.id === z.dataset.pick);
|
|
1423
|
+
if (!I || I.unfit) return;
|
|
1424
|
+
n = I.id, (C = t.onChoose) == null || C.call(t, I.id), p();
|
|
1369
1425
|
return;
|
|
1370
1426
|
}
|
|
1371
|
-
const
|
|
1372
|
-
if (
|
|
1373
|
-
o = o ===
|
|
1427
|
+
const L = b.closest("[data-more]");
|
|
1428
|
+
if (L) {
|
|
1429
|
+
o = o === L.dataset.more ? "" : L.dataset.more, p();
|
|
1374
1430
|
return;
|
|
1375
1431
|
}
|
|
1376
|
-
const
|
|
1377
|
-
if (
|
|
1378
|
-
(
|
|
1432
|
+
const S = b.closest("[data-remove]");
|
|
1433
|
+
if (S) {
|
|
1434
|
+
($ = t.onRemove) == null || $.call(t, S.dataset.remove);
|
|
1379
1435
|
return;
|
|
1380
1436
|
}
|
|
1381
|
-
if (
|
|
1382
|
-
(
|
|
1437
|
+
if (b.closest("[data-load]") && n) {
|
|
1438
|
+
(A = t.onLoad) == null || A.call(t, n);
|
|
1383
1439
|
return;
|
|
1384
1440
|
}
|
|
1385
|
-
|
|
1441
|
+
b.closest("[data-cancel]") && n && ((O = t.onCancel) == null || O.call(t, n));
|
|
1386
1442
|
};
|
|
1387
|
-
return e.addEventListener("input", d), e.addEventListener("submit", u), e.addEventListener("click", w), e.addEventListener("change",
|
|
1388
|
-
update(
|
|
1389
|
-
r =
|
|
1443
|
+
return e.addEventListener("input", d), e.addEventListener("submit", u), e.addEventListener("click", w), e.addEventListener("change", v), p(), {
|
|
1444
|
+
update(k, b) {
|
|
1445
|
+
r = k, b !== void 0 && (n = b), p();
|
|
1390
1446
|
},
|
|
1391
1447
|
get chosen() {
|
|
1392
1448
|
return n;
|
|
1393
1449
|
},
|
|
1394
1450
|
dispose() {
|
|
1395
|
-
e.removeEventListener("input", d), e.removeEventListener("submit", u), e.removeEventListener("click", w), e.removeEventListener("change",
|
|
1451
|
+
e.removeEventListener("input", d), e.removeEventListener("submit", u), e.removeEventListener("click", w), e.removeEventListener("change", v);
|
|
1396
1452
|
}
|
|
1397
1453
|
};
|
|
1398
1454
|
}
|
|
1399
|
-
function
|
|
1455
|
+
function ta(e, t) {
|
|
1400
1456
|
let r = t.rows, n = t.chosen ?? "";
|
|
1401
1457
|
e.classList.add("hb-msel");
|
|
1402
1458
|
function o() {
|
|
1403
|
-
const s = r.find((a) => a.id === n), c =
|
|
1404
|
-
e.innerHTML = `<button type="button" class="hb-msel-line" aria-haspopup="dialog" aria-label="model: ${
|
|
1459
|
+
const s = r.find((a) => a.id === n), c = qr(s, t.empty);
|
|
1460
|
+
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>` : ""}`;
|
|
1405
1461
|
}
|
|
1406
1462
|
const i = (s) => {
|
|
1407
|
-
var a,
|
|
1463
|
+
var a, h;
|
|
1408
1464
|
const c = s.target;
|
|
1409
|
-
c.closest("[data-open]") ? (a = t.onOpen) == null || a.call(t) : c.closest("[data-load]") && n && ((
|
|
1465
|
+
c.closest("[data-open]") ? (a = t.onOpen) == null || a.call(t) : c.closest("[data-load]") && n && ((h = t.onLoad) == null || h.call(t, n));
|
|
1410
1466
|
};
|
|
1411
1467
|
return e.addEventListener("click", i), o(), {
|
|
1412
1468
|
update(s, c) {
|
|
@@ -1470,25 +1526,30 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1470
1526
|
try {
|
|
1471
1527
|
if (o.recall && lastUser) mem = await o.recall(lastUser.text);
|
|
1472
1528
|
if (mem.length) patch(live.id, { mem });
|
|
1473
|
-
const
|
|
1529
|
+
const base = typeof o.system === "function" ? o.system() : o.system;
|
|
1530
|
+
const sys = o.systemFor ? o.systemFor(mem) : [base, mem.length ? `things you remember:\n${mem.map((m) => `- ${m.label}`).join("\n")}` : ""].filter(Boolean).join("\n\n");
|
|
1531
|
+
const past = turns.filter((t) => t.id !== live.id && t.text);
|
|
1532
|
+
const keep = o.history?.();
|
|
1533
|
+
const sent = keep !== void 0 && keep >= 0 ? past.slice(Math.max(0, past.length - 1 - keep)) : past;
|
|
1474
1534
|
const history = [...sys ? [{
|
|
1475
1535
|
role: "system",
|
|
1476
1536
|
content: sys
|
|
1477
|
-
}] : [], ...
|
|
1537
|
+
}] : [], ...sent.map((t) => ({
|
|
1478
1538
|
role: t.role,
|
|
1479
1539
|
content: t.text
|
|
1480
1540
|
}))];
|
|
1481
1541
|
let text = "";
|
|
1482
1542
|
let think = "";
|
|
1483
1543
|
const it = engine.stream(history, {
|
|
1484
|
-
|
|
1485
|
-
...o.
|
|
1544
|
+
...o.maxTokens ? { maxTokens: o.maxTokens } : {},
|
|
1545
|
+
...o.stream?.(),
|
|
1546
|
+
signal
|
|
1486
1547
|
});
|
|
1487
1548
|
for (;;) {
|
|
1488
1549
|
const step = await it.next();
|
|
1489
1550
|
if (step.done) {
|
|
1490
1551
|
const s = step.value?.stats;
|
|
1491
|
-
const stats = s ?
|
|
1552
|
+
const stats = s ? _o({
|
|
1492
1553
|
tokPerSec: s.tokensPerSecond,
|
|
1493
1554
|
firstMs: s.firstTokenMs,
|
|
1494
1555
|
tokens: s.tokens,
|
|
@@ -1498,6 +1559,8 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1498
1559
|
done: true,
|
|
1499
1560
|
...stats ? { stats } : {}
|
|
1500
1561
|
});
|
|
1562
|
+
const fin = turns.find((t) => t.id === live.id);
|
|
1563
|
+
if (fin?.text) o.onReply?.(fin, lastUser?.text ?? "");
|
|
1501
1564
|
break;
|
|
1502
1565
|
}
|
|
1503
1566
|
const ev = step.value;
|
|
@@ -1563,6 +1626,15 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1563
1626
|
engine = e;
|
|
1564
1627
|
emit();
|
|
1565
1628
|
},
|
|
1629
|
+
load(next) {
|
|
1630
|
+
ac?.abort();
|
|
1631
|
+
turns = next.map((t) => ({
|
|
1632
|
+
...t,
|
|
1633
|
+
id: ++seq,
|
|
1634
|
+
done: true
|
|
1635
|
+
}));
|
|
1636
|
+
emit();
|
|
1637
|
+
},
|
|
1566
1638
|
markdown(title = "chat") {
|
|
1567
1639
|
const lines = [`# ${title}`, ""];
|
|
1568
1640
|
for (const t of turns) lines.push(`## ${t.role === "user" ? "you" : "reply"}`, "", t.text, "");
|
|
@@ -1621,7 +1693,8 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1621
1693
|
remove: (id) => chats.get(current).t.remove(id),
|
|
1622
1694
|
clear: () => chats.get(current).t.clear(),
|
|
1623
1695
|
setEngine: (e) => list.setEngine(e),
|
|
1624
|
-
markdown: (title) => chats.get(current).t.markdown(title ?? chats.get(current).title)
|
|
1696
|
+
markdown: (title) => chats.get(current).t.markdown(title ?? chats.get(current).title),
|
|
1697
|
+
load: (t) => chats.get(current).t.load(t)
|
|
1625
1698
|
},
|
|
1626
1699
|
snapshot: snap,
|
|
1627
1700
|
subscribe(fn) {
|
|
@@ -1669,6 +1742,50 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
1669
1742
|
setEngine(e) {
|
|
1670
1743
|
engine = e;
|
|
1671
1744
|
for (const c of chats.values()) c.t.setEngine(e);
|
|
1745
|
+
},
|
|
1746
|
+
dump() {
|
|
1747
|
+
return {
|
|
1748
|
+
format: "hackbuild-chats",
|
|
1749
|
+
version: 1,
|
|
1750
|
+
current,
|
|
1751
|
+
chats: [...chats].map(([id, c]) => ({
|
|
1752
|
+
id,
|
|
1753
|
+
title: c.title,
|
|
1754
|
+
updated: c.updated,
|
|
1755
|
+
named: c.named,
|
|
1756
|
+
turns: c.t.snapshot().turns.filter((t) => t.done).map((t) => ({ ...t }))
|
|
1757
|
+
}))
|
|
1758
|
+
};
|
|
1759
|
+
},
|
|
1760
|
+
restore(data, ro = {}) {
|
|
1761
|
+
if (data?.format !== "hackbuild-chats" || data.version !== 1 || !Array.isArray(data.chats)) throw new Error("not a hackbuild-chats version 1 file.");
|
|
1762
|
+
const empty = [...chats.values()].every((c) => !c.t.snapshot().turns.length);
|
|
1763
|
+
if (ro.replace || empty) {
|
|
1764
|
+
for (const c of chats.values()) c.t.stop();
|
|
1765
|
+
chats.clear();
|
|
1766
|
+
}
|
|
1767
|
+
let open = "";
|
|
1768
|
+
for (const c of data.chats) {
|
|
1769
|
+
const id = `chat-${++seq}`;
|
|
1770
|
+
const t = chatThread({
|
|
1771
|
+
...o,
|
|
1772
|
+
engine
|
|
1773
|
+
});
|
|
1774
|
+
t.load((c.turns ?? []).filter((x) => (x.role === "user" || x.role === "assistant") && typeof x.text === "string").map((x) => ({
|
|
1775
|
+
...x,
|
|
1776
|
+
think: x.think ?? ""
|
|
1777
|
+
})));
|
|
1778
|
+
chats.set(id, {
|
|
1779
|
+
t,
|
|
1780
|
+
title: String(c.title || "chat"),
|
|
1781
|
+
updated: +c.updated || now(),
|
|
1782
|
+
named: !!c.named
|
|
1783
|
+
});
|
|
1784
|
+
if (c.id === data.current) open = id;
|
|
1785
|
+
}
|
|
1786
|
+
if (!chats.size) return void list.create();
|
|
1787
|
+
current = open || (chats.has(current) ? current : snap().items[0].id);
|
|
1788
|
+
follow();
|
|
1672
1789
|
}
|
|
1673
1790
|
};
|
|
1674
1791
|
list.create();
|
|
@@ -4606,6 +4723,36 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
4606
4723
|
527503840,
|
|
4607
4724
|
"vendor"
|
|
4608
4725
|
] }
|
|
4726
|
+
},
|
|
4727
|
+
"Felladrin/gguf-sharded-UD-Q4_K_XL-Phi-4-mini-reasoning": {
|
|
4728
|
+
"revision": "bc6bac3a27893ab006486992e46a7662ef4790a9",
|
|
4729
|
+
"files": {
|
|
4730
|
+
"model.shard-00001-of-00005.gguf": [
|
|
4731
|
+
"e730254967e049ab3bd5e2311cedd200155b9d0835fb05a9218de82b324cac3f",
|
|
4732
|
+
512426912,
|
|
4733
|
+
"vendor"
|
|
4734
|
+
],
|
|
4735
|
+
"model.shard-00002-of-00005.gguf": [
|
|
4736
|
+
"812f190b06a786ec7ed22378bb5a136476f5c040a434140916cceb5563ab7f4d",
|
|
4737
|
+
481483520,
|
|
4738
|
+
"vendor"
|
|
4739
|
+
],
|
|
4740
|
+
"model.shard-00003-of-00005.gguf": [
|
|
4741
|
+
"f5b575dc8a4fd7d75dc4616261a050a224a2e81783e5616e74d2cd022b89d658",
|
|
4742
|
+
499301472,
|
|
4743
|
+
"vendor"
|
|
4744
|
+
],
|
|
4745
|
+
"model.shard-00004-of-00005.gguf": [
|
|
4746
|
+
"edba060f8bf871dc4953ff633a0b1e0de7d312cd05ef3a5a449b69c9d2e53765",
|
|
4747
|
+
495664224,
|
|
4748
|
+
"vendor"
|
|
4749
|
+
],
|
|
4750
|
+
"model.shard-00005-of-00005.gguf": [
|
|
4751
|
+
"da2110debf2334e102413017e3ad9285f6a5475aeb5a2d3b85b03e5865df5cab",
|
|
4752
|
+
473803392,
|
|
4753
|
+
"vendor"
|
|
4754
|
+
]
|
|
4755
|
+
}
|
|
4609
4756
|
}
|
|
4610
4757
|
};
|
|
4611
4758
|
// packages/models/src/pinning.ts
|
|
@@ -4645,6 +4792,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
4645
4792
|
* Every row carries a speed word and a verdict of one to four words: what
|
|
4646
4793
|
* a person picks by, in the owner's voice.
|
|
4647
4794
|
*
|
|
4795
|
+
* Repos of the rows named in the vision lab and generate gaps (Qwen3
|
|
4796
|
+
* 1.7B, Phi-4 mini, SmolLM2 1.7B, Phi-4 mini reasoning) were checked on
|
|
4797
|
+
* 2026-11-25 with an HTTP HEAD of the repo's config.json or
|
|
4798
|
+
* mlc-chat-config.json (200, no weight fetched).
|
|
4799
|
+
*
|
|
4648
4800
|
* Catalogue facts (params, quant, VRAM, censorship, tags, note) are copied
|
|
4649
4801
|
* from the owner's model labels and the WebLLM catalogue; VRAM figures are the catalogue's own (vendor). Licence
|
|
4650
4802
|
* strings are shown as recorded and were not verified for these facts.
|
|
@@ -5600,6 +5752,42 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
5600
5752
|
commercial: true,
|
|
5601
5753
|
runtime: "@mlc-ai/web-llm@0.2.84"
|
|
5602
5754
|
},
|
|
5755
|
+
{
|
|
5756
|
+
id: "phi-4-mini-reasoning-gguf",
|
|
5757
|
+
label: "Phi-4 mini reasoning",
|
|
5758
|
+
params: "3.8B",
|
|
5759
|
+
quant: "Q4_K_XL",
|
|
5760
|
+
censorship: "stock",
|
|
5761
|
+
tier: "medium",
|
|
5762
|
+
family: "phi",
|
|
5763
|
+
tags: ["think", "reasoning"],
|
|
5764
|
+
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.",
|
|
5765
|
+
group: "reasoning",
|
|
5766
|
+
badge: "maths, thinks first",
|
|
5767
|
+
speed: "slow",
|
|
5768
|
+
verdict: "maths, thinks first",
|
|
5769
|
+
provides: ["chat"],
|
|
5770
|
+
provider: "wllama",
|
|
5771
|
+
source: {
|
|
5772
|
+
repo: "Felladrin/gguf-sharded-UD-Q4_K_XL-Phi-4-mini-reasoning",
|
|
5773
|
+
file: "model.shard-00001-of-00005.gguf"
|
|
5774
|
+
},
|
|
5775
|
+
sizeMB: 2349,
|
|
5776
|
+
sizeSource: "vendor",
|
|
5777
|
+
ctx: 4096,
|
|
5778
|
+
ladder: [{
|
|
5779
|
+
device: "webgpu",
|
|
5780
|
+
dtype: "q4_k_m"
|
|
5781
|
+
}, {
|
|
5782
|
+
device: "wasm",
|
|
5783
|
+
dtype: "q4_k_m"
|
|
5784
|
+
}],
|
|
5785
|
+
quirks: { think: "tags" },
|
|
5786
|
+
licence: "MIT (the base model card microsoft/Phi-4-mini-reasoning; the shard repo has no licence field)",
|
|
5787
|
+
commercial: true,
|
|
5788
|
+
runtime: "@wllama/wllama@3.8.1",
|
|
5789
|
+
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"]
|
|
5790
|
+
},
|
|
5603
5791
|
{
|
|
5604
5792
|
id: "smollm2-1.7b-instruct-mlc",
|
|
5605
5793
|
label: "SmolLM2 1.7B",
|
|
@@ -6467,25 +6655,28 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
6467
6655
|
}
|
|
6468
6656
|
}];
|
|
6469
6657
|
/**
|
|
6470
|
-
* Listed for pickers, not registered by attachImagegen
|
|
6471
|
-
*
|
|
6658
|
+
* Listed for pickers, not registered by attachImagegen, so routing by
|
|
6659
|
+
* capability keeps SD-Turbo: SDXL-Turbo runs on `generateXl`, and the
|
|
6660
|
+
* export's input and output names are inferred from its README and the
|
|
6661
|
+
* SDXL description, not read from the graphs. `loadImagegen(hub, { id:
|
|
6662
|
+
* "sdxl-turbo" })` adds it and loads it.
|
|
6472
6663
|
*/
|
|
6473
6664
|
const IMAGEGEN_PICKER_RECORDS = [{
|
|
6474
6665
|
id: "sdxl-turbo",
|
|
6475
6666
|
label: "sdxl-turbo 512",
|
|
6476
6667
|
speed: "steady",
|
|
6477
6668
|
verdict: "not run yet",
|
|
6478
|
-
unrunnable: "not run yet. sdxl
|
|
6669
|
+
unrunnable: "not run yet. the sdxl pipeline is written; the export's graph names and fp16 io are inferred and unchecked.",
|
|
6479
6670
|
group: "good",
|
|
6480
6671
|
provides: ["imagegen"],
|
|
6481
6672
|
provider: "ort",
|
|
6482
6673
|
source: {
|
|
6483
6674
|
repo: "webnn/sdxl-turbo",
|
|
6484
6675
|
files: [
|
|
6485
|
-
{ path: "
|
|
6486
|
-
{ path: "
|
|
6487
|
-
{ path: "
|
|
6488
|
-
{ path: "
|
|
6676
|
+
{ path: "onnx/text_encoder_model_q4f16.onnx" },
|
|
6677
|
+
{ path: "onnx/text_encoder_2_model_q4f16.onnx" },
|
|
6678
|
+
{ path: "onnx/unet_model_q4f16.onnx" },
|
|
6679
|
+
{ path: "onnx/vae_decoder_model_q4f16.onnx" }
|
|
6489
6680
|
]
|
|
6490
6681
|
},
|
|
6491
6682
|
sizeMB: 2548,
|
|
@@ -6499,7 +6690,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
6499
6690
|
commercial: "unknown",
|
|
6500
6691
|
place: "gpu",
|
|
6501
6692
|
runtime: "onnxruntime-web@1.27.0",
|
|
6502
|
-
notes: [
|
|
6693
|
+
notes: [
|
|
6694
|
+
"two text encoders, pooled embeddings and time ids, on generateXl",
|
|
6695
|
+
"fp16 inputs and outputs per the export's README (--force_fp16_inputs); timestep dtype and hidden state names inferred",
|
|
6696
|
+
"the highest quality of the three image models"
|
|
6697
|
+
],
|
|
6503
6698
|
form: {
|
|
6504
6699
|
steps: {
|
|
6505
6700
|
min: 1,
|
|
@@ -6512,7 +6707,17 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
6512
6707
|
spacing: "trailing",
|
|
6513
6708
|
note: "distilled from sdxl. 1 to 4 steps, no negative prompt. the best looking of the three.",
|
|
6514
6709
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
6515
|
-
graphs
|
|
6710
|
+
graphs: {
|
|
6711
|
+
textEncoder: "text_encoder_model_q4f16",
|
|
6712
|
+
textEncoder2: "text_encoder_2_model_q4f16",
|
|
6713
|
+
unet: "unet_model_q4f16",
|
|
6714
|
+
vaeDecoder: "vae_decoder_model_q4f16"
|
|
6715
|
+
},
|
|
6716
|
+
pipeline: "sdxl",
|
|
6717
|
+
xl: {
|
|
6718
|
+
io: "float16",
|
|
6719
|
+
timestep: "float16"
|
|
6720
|
+
}
|
|
6516
6721
|
}
|
|
6517
6722
|
}];
|
|
6518
6723
|
// packages/audio-dsp/src/writers.ts
|
|
@@ -6547,7 +6752,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
6547
6752
|
function toSrt(segs) {
|
|
6548
6753
|
return segs.map((s, i) => `${i + 1}\n${timestamp(s.start, true)} --> ${timestamp(s.end, true)}\n${cueText(s.text)}\n`).join("\n");
|
|
6549
6754
|
}
|
|
6550
|
-
(() => {
|
|
6755
|
+
const CRC = (() => {
|
|
6551
6756
|
const t = /* @__PURE__ */ new Uint32Array(256);
|
|
6552
6757
|
for (let i = 0; i < 256; i++) {
|
|
6553
6758
|
let c = i;
|
|
@@ -6556,6 +6761,75 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
6556
6761
|
}
|
|
6557
6762
|
return t;
|
|
6558
6763
|
})();
|
|
6764
|
+
/** The CRC-32 of the bytes, as zip uses it. */
|
|
6765
|
+
function crc32(b) {
|
|
6766
|
+
let c = 4294967295;
|
|
6767
|
+
for (let i = 0; i < b.length; i++) c = CRC[(c ^ b[i]) & 255] ^ c >>> 8;
|
|
6768
|
+
return (c ^ 4294967295) >>> 0;
|
|
6769
|
+
}
|
|
6770
|
+
/** A store only zip (no compression), UTF-8 names. `date` sets the DOS time stamp; pass one for reproducible bytes. */
|
|
6771
|
+
function zipStore(entries, date = /* @__PURE__ */ new Date()) {
|
|
6772
|
+
const enc = new TextEncoder();
|
|
6773
|
+
const tt = (date.getHours() & 31) << 11 | (date.getMinutes() & 63) << 5 | date.getSeconds() / 2 & 31;
|
|
6774
|
+
const dd = (date.getFullYear() - 1980 & 127) << 9 | (date.getMonth() + 1 & 15) << 5 | date.getDate() & 31;
|
|
6775
|
+
const parts = [];
|
|
6776
|
+
const cd = [];
|
|
6777
|
+
let off = 0;
|
|
6778
|
+
for (const e of entries) {
|
|
6779
|
+
const nm = enc.encode(e.name);
|
|
6780
|
+
const data = typeof e.data === "string" ? enc.encode(e.data) : e.data;
|
|
6781
|
+
const crc = crc32(data);
|
|
6782
|
+
const lh = new Uint8Array(30 + nm.length);
|
|
6783
|
+
const lv = new DataView(lh.buffer);
|
|
6784
|
+
lv.setUint32(0, 67324752, true);
|
|
6785
|
+
lv.setUint16(4, 20, true);
|
|
6786
|
+
lv.setUint16(6, 2048, true);
|
|
6787
|
+
lv.setUint16(10, tt, true);
|
|
6788
|
+
lv.setUint16(12, dd, true);
|
|
6789
|
+
lv.setUint32(14, crc, true);
|
|
6790
|
+
lv.setUint32(18, data.length, true);
|
|
6791
|
+
lv.setUint32(22, data.length, true);
|
|
6792
|
+
lv.setUint16(26, nm.length, true);
|
|
6793
|
+
lh.set(nm, 30);
|
|
6794
|
+
parts.push(lh, data);
|
|
6795
|
+
const ch = new Uint8Array(46 + nm.length);
|
|
6796
|
+
const cv = new DataView(ch.buffer);
|
|
6797
|
+
cv.setUint32(0, 33639248, true);
|
|
6798
|
+
cv.setUint16(4, 20, true);
|
|
6799
|
+
cv.setUint16(6, 20, true);
|
|
6800
|
+
cv.setUint16(8, 2048, true);
|
|
6801
|
+
cv.setUint16(12, tt, true);
|
|
6802
|
+
cv.setUint16(14, dd, true);
|
|
6803
|
+
cv.setUint32(16, crc, true);
|
|
6804
|
+
cv.setUint32(20, data.length, true);
|
|
6805
|
+
cv.setUint32(24, data.length, true);
|
|
6806
|
+
cv.setUint16(28, nm.length, true);
|
|
6807
|
+
cv.setUint32(42, off, true);
|
|
6808
|
+
ch.set(nm, 46);
|
|
6809
|
+
cd.push(ch);
|
|
6810
|
+
off += lh.length + data.length;
|
|
6811
|
+
}
|
|
6812
|
+
const cds = cd.reduce((a, c) => a + c.length, 0);
|
|
6813
|
+
const end = /* @__PURE__ */ new Uint8Array(22);
|
|
6814
|
+
const ev = new DataView(end.buffer);
|
|
6815
|
+
ev.setUint32(0, 101010256, true);
|
|
6816
|
+
ev.setUint16(8, entries.length, true);
|
|
6817
|
+
ev.setUint16(10, entries.length, true);
|
|
6818
|
+
ev.setUint32(12, cds, true);
|
|
6819
|
+
ev.setUint32(16, off, true);
|
|
6820
|
+
const all = [
|
|
6821
|
+
...parts,
|
|
6822
|
+
...cd,
|
|
6823
|
+
end
|
|
6824
|
+
];
|
|
6825
|
+
const out = new Uint8Array(all.reduce((a, p) => a + p.length, 0));
|
|
6826
|
+
let p = 0;
|
|
6827
|
+
for (const a of all) {
|
|
6828
|
+
out.set(a, p);
|
|
6829
|
+
p += a.length;
|
|
6830
|
+
}
|
|
6831
|
+
return out;
|
|
6832
|
+
}
|
|
6559
6833
|
// packages/speak/src/records.ts
|
|
6560
6834
|
/** Model records for the voices this package drives, for pickers and the models registry. */
|
|
6561
6835
|
const SPEAK_RECORDS = [
|
|
@@ -6825,15 +7099,88 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
6825
7099
|
function baseName(name) {
|
|
6826
7100
|
return (name.split(/[\\/]/).pop() ?? name).replace(/\.[^.]+$/, "").replace(/[\u0000-\u001f:*?"<>|]/g, "_").trim() || "transcript";
|
|
6827
7101
|
}
|
|
7102
|
+
const r1 = (x) => +(x ?? 0).toFixed(1);
|
|
7103
|
+
const one = (xs) => xs.length && xs.every((x) => x === xs[0]) ? xs[0] : xs.length ? "mixed" : "";
|
|
7104
|
+
/**
|
|
7105
|
+
* The zip of every document: txt, srt, vtt and json per source, and
|
|
7106
|
+
* `manifest.json` first. Two sources with one base name get "-2", "-3".
|
|
7107
|
+
* Pass `date` for reproducible bytes.
|
|
7108
|
+
*/
|
|
7109
|
+
function bundle(docs, o = {}) {
|
|
7110
|
+
const date = o.date ?? /* @__PURE__ */ new Date();
|
|
7111
|
+
const used = /* @__PURE__ */ new Set();
|
|
7112
|
+
const entries = [];
|
|
7113
|
+
const files = [];
|
|
7114
|
+
for (const d of docs) {
|
|
7115
|
+
let b = baseName(d.source);
|
|
7116
|
+
for (let i = 2; used.has(b.toLowerCase()); i++) b = `${baseName(d.source)}-${i}`;
|
|
7117
|
+
used.add(b.toLowerCase());
|
|
7118
|
+
const out = [
|
|
7119
|
+
`${b}.txt`,
|
|
7120
|
+
`${b}.srt`,
|
|
7121
|
+
`${b}.vtt`,
|
|
7122
|
+
`${b}.json`
|
|
7123
|
+
];
|
|
7124
|
+
entries.push({
|
|
7125
|
+
name: out[0],
|
|
7126
|
+
data: asTxt(d.segments)
|
|
7127
|
+
}, {
|
|
7128
|
+
name: out[1],
|
|
7129
|
+
data: asSrt(d.segments)
|
|
7130
|
+
}, {
|
|
7131
|
+
name: out[2],
|
|
7132
|
+
data: asVtt(d.segments)
|
|
7133
|
+
}, {
|
|
7134
|
+
name: out[3],
|
|
7135
|
+
data: asJson(d)
|
|
7136
|
+
});
|
|
7137
|
+
const s = d.stats;
|
|
7138
|
+
files.push({
|
|
7139
|
+
source: d.source,
|
|
7140
|
+
model: d.model,
|
|
7141
|
+
language: d.language,
|
|
7142
|
+
duration: d.duration ?? s?.dur ?? null,
|
|
7143
|
+
lines: d.segments.length,
|
|
7144
|
+
dropped: d.dropped?.length ?? 0,
|
|
7145
|
+
levels: s ? {
|
|
7146
|
+
noise_dbfs: r1(s.noiseDb),
|
|
7147
|
+
speech_dbfs: r1(s.speechDb),
|
|
7148
|
+
snr_db: r1(s.snrDb),
|
|
7149
|
+
lift_db: r1(s.gainDb),
|
|
7150
|
+
speech_density: +(s.density ?? 0).toFixed(3),
|
|
7151
|
+
realtime_factor: +(s.rtf ?? 0).toFixed(2)
|
|
7152
|
+
} : null,
|
|
7153
|
+
outputs: out
|
|
7154
|
+
});
|
|
7155
|
+
}
|
|
7156
|
+
const manifest = {
|
|
7157
|
+
tool: o.tool ?? "hackbuild-transcribe",
|
|
7158
|
+
generated: date.toISOString(),
|
|
7159
|
+
model: one(docs.map((d) => d.model)),
|
|
7160
|
+
language: one(docs.map((d) => d.language)),
|
|
7161
|
+
capture: o.capture ?? null,
|
|
7162
|
+
files
|
|
7163
|
+
};
|
|
7164
|
+
entries.unshift({
|
|
7165
|
+
name: "manifest.json",
|
|
7166
|
+
data: JSON.stringify(manifest, null, 2)
|
|
7167
|
+
});
|
|
7168
|
+
return {
|
|
7169
|
+
zip: zipStore(entries, date),
|
|
7170
|
+
manifest
|
|
7171
|
+
};
|
|
7172
|
+
}
|
|
6828
7173
|
// packages/vision/src/records.ts
|
|
6829
7174
|
/**
|
|
6830
7175
|
* Vision records for the models hub. Licences are the model cards' as of
|
|
6831
7176
|
* 2026-11-22; sizes are inferred from the builds and parameter counts, except where
|
|
6832
7177
|
* a row says vendor: those sum the hub listing's files (no download), in MiB.
|
|
6833
7178
|
* YOLO weights are AGPL-3.0 (Ultralytics): they are never registered by
|
|
6834
|
-
* default. YOLOv8n has no
|
|
7179
|
+
* default. YOLOv8n has no onnx-community or Xenova repo (an HTTP HEAD of
|
|
7180
|
+
* their config.json gave 401 on 2026-11-25), so `yoloRecord` builds a record
|
|
6835
7181
|
* only for a URL the app supplies; YOLOv10 n, s and m, FastSAM and the face
|
|
6836
|
-
* swap set sit in PICKER_RECORDS.
|
|
7182
|
+
* swap set sit in PICKER_RECORDS. The YOLOv10 n, s and m, SmolVLM 500M,
|
|
7183
|
+
* Gemma 4 E2B and FastSAM repos answered that HEAD with 200 the same day.
|
|
6837
7184
|
*/
|
|
6838
7185
|
/** The MediaPipe model storage base URL the MediaPipe records load from. */
|
|
6839
7186
|
const MP_MODELS = "https://storage.googleapis.com/mediapipe-models/";
|
|
@@ -7119,7 +7466,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7119
7466
|
licence: "AGPL-3.0 upstream (Ultralytics FastSAM); the export's card says apache-2.0",
|
|
7120
7467
|
commercial: false,
|
|
7121
7468
|
place: "cpu-worker",
|
|
7122
|
-
notes: ["finds every mask in one pass on onnxruntime-web
|
|
7469
|
+
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)"]
|
|
7123
7470
|
},
|
|
7124
7471
|
{
|
|
7125
7472
|
id: "scrfd-10g",
|
|
@@ -7367,7 +7714,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7367
7714
|
/** Download words: "1.7 gb". Null for a record with no download or an unknown size. */
|
|
7368
7715
|
function sizeWords(r) {
|
|
7369
7716
|
if (isNoDownload(r) || r.sizeMB === null) return void 0;
|
|
7370
|
-
return
|
|
7717
|
+
return Dr(r.sizeMB * MIB);
|
|
7371
7718
|
}
|
|
7372
7719
|
/** The record's label, else its id made readable: "hermes 3 llama 3.2 3b". */
|
|
7373
7720
|
const pretty = (r) => r.label ?? r.id.replace(/-(mlc|gguf)$/, "").replace(/-/g, " ");
|
|
@@ -7386,11 +7733,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7386
7733
|
});
|
|
7387
7734
|
if (r.sizeMB !== null && !isNoDownload(r)) out.push({
|
|
7388
7735
|
label: "size",
|
|
7389
|
-
value: `${
|
|
7736
|
+
value: `${Dr(r.sizeMB * MIB)}, ${r.sizeSource}`
|
|
7390
7737
|
});
|
|
7391
7738
|
if (r.vramMB != null) out.push({
|
|
7392
7739
|
label: "gpu memory",
|
|
7393
|
-
value: `${
|
|
7740
|
+
value: `${Dr(r.vramMB * MIB)}, ${r.vramSource ?? "unknown"}`
|
|
7394
7741
|
});
|
|
7395
7742
|
if (r.ctx) out.push({
|
|
7396
7743
|
label: "context",
|
|
@@ -7486,7 +7833,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7486
7833
|
state
|
|
7487
7834
|
};
|
|
7488
7835
|
if (size) row.size = size;
|
|
7489
|
-
if (r.vramMB != null) row.memory = `needs ${
|
|
7836
|
+
if (r.vramMB != null) row.memory = `needs ${Dr(r.vramMB * MIB)}`;
|
|
7490
7837
|
if (r.sizeMB !== null && !isNoDownload(r)) row.bytes = r.sizeMB * MIB;
|
|
7491
7838
|
const speed = fit.fit === "fits on cpu, slow" ? "slow" : r.speed;
|
|
7492
7839
|
if (speed) row.speed = speed;
|
|
@@ -7638,7 +7985,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7638
7985
|
estimate,
|
|
7639
7986
|
state: state.get(id)
|
|
7640
7987
|
});
|
|
7641
|
-
if (!rec || !
|
|
7988
|
+
if (!rec || !Re(row)) return;
|
|
7642
7989
|
if (!loader) {
|
|
7643
7990
|
state.set(id, "error");
|
|
7644
7991
|
errors.set(id, "no loader. the page passes one to load a model.");
|
|
@@ -7707,6 +8054,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7707
8054
|
if (n.records) records = jobRecords(job, n.records);
|
|
7708
8055
|
if (n.loader) loader = n.loader;
|
|
7709
8056
|
if (n.onRemove) onRemove = n.onRemove;
|
|
8057
|
+
for (const id of n.stored ?? []) if (!state.has(id) || state.get(id) === "none") state.set(id, "stored");
|
|
7710
8058
|
emit();
|
|
7711
8059
|
},
|
|
7712
8060
|
result: (id) => results.get(id),
|
|
@@ -7741,7 +8089,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7741
8089
|
return {
|
|
7742
8090
|
id: pr.id,
|
|
7743
8091
|
label: pr.label,
|
|
7744
|
-
total: bytes > 0 ? `about ${
|
|
8092
|
+
total: bytes > 0 ? `about ${Dr(bytes)}` : "nothing to fetch"
|
|
7745
8093
|
};
|
|
7746
8094
|
}),
|
|
7747
8095
|
applyPreset(id) {
|
|
@@ -7749,7 +8097,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7749
8097
|
if (!pr) return;
|
|
7750
8098
|
for (const [job, mid] of Object.entries(pr.picks)) picks.get(job)?.choose(mid);
|
|
7751
8099
|
},
|
|
7752
|
-
all: () =>
|
|
8100
|
+
all: () => Zs(chosenRows()),
|
|
7753
8101
|
async loadAll() {
|
|
7754
8102
|
await Promise.all([...picks.values()].map((p) => p.load().catch(() => void 0)));
|
|
7755
8103
|
},
|
|
@@ -7864,7 +8212,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7864
8212
|
const l = listeners();
|
|
7865
8213
|
const draw = (s) => {
|
|
7866
8214
|
const sc = scroller(host);
|
|
7867
|
-
const stick =
|
|
8215
|
+
const stick = ei(sc);
|
|
7868
8216
|
if (!s.turns.length) {
|
|
7869
8217
|
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>`;
|
|
7870
8218
|
return;
|
|
@@ -7906,7 +8254,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7906
8254
|
const text = area.value.trim();
|
|
7907
8255
|
if (!text || busy) return;
|
|
7908
8256
|
area.value = "";
|
|
7909
|
-
|
|
8257
|
+
Zo(area);
|
|
7910
8258
|
thread.send(text);
|
|
7911
8259
|
};
|
|
7912
8260
|
const l = listeners();
|
|
@@ -7917,12 +8265,12 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7917
8265
|
l.on(act, "click", (e) => {
|
|
7918
8266
|
if (e.target.closest("[data-stop]")) thread.stop();
|
|
7919
8267
|
});
|
|
7920
|
-
l.on(area, "input", () =>
|
|
8268
|
+
l.on(area, "input", () => Zo(area));
|
|
7921
8269
|
l.on(area, "keydown", (e) => {
|
|
7922
|
-
const k =
|
|
8270
|
+
const k = Jo(e, {
|
|
7923
8271
|
busy,
|
|
7924
8272
|
empty: !area.value,
|
|
7925
|
-
coarse:
|
|
8273
|
+
coarse: Qo()
|
|
7926
8274
|
});
|
|
7927
8275
|
if (k === "send") {
|
|
7928
8276
|
e.preventDefault();
|
|
@@ -7943,7 +8291,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7943
8291
|
let renaming = "";
|
|
7944
8292
|
const head = o.label ?? "chats";
|
|
7945
8293
|
const draw = (s) => {
|
|
7946
|
-
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(
|
|
8294
|
+
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({
|
|
7947
8295
|
updated: c.updated,
|
|
7948
8296
|
count: c.count
|
|
7949
8297
|
}))}</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>`;
|
|
@@ -7979,7 +8327,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
7979
8327
|
const l = listeners();
|
|
7980
8328
|
const val = (v, d) => typeof v === "function" ? v() : v ?? d;
|
|
7981
8329
|
const draw = (s) => {
|
|
7982
|
-
const use =
|
|
8330
|
+
const use = ti(contextSegments(s, val(o.system, "")), val(o.budget, 4096));
|
|
7983
8331
|
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>`;
|
|
7984
8332
|
};
|
|
7985
8333
|
l.add(thread.subscribe(draw));
|
|
@@ -8054,7 +8402,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8054
8402
|
const none = host.querySelector(".hb-camtile-none");
|
|
8055
8403
|
const tag = host.querySelector(".hb-camtile-tag");
|
|
8056
8404
|
const cap = host.querySelector("[data-caption]");
|
|
8057
|
-
const palette = o.palette ??
|
|
8405
|
+
const palette = o.palette ?? ht;
|
|
8058
8406
|
let src = null;
|
|
8059
8407
|
let results = {};
|
|
8060
8408
|
let mirror = !!o.mirror;
|
|
@@ -8239,7 +8587,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8239
8587
|
if (stream) return;
|
|
8240
8588
|
error = "";
|
|
8241
8589
|
try {
|
|
8242
|
-
stream = await
|
|
8590
|
+
stream = await qi({
|
|
8243
8591
|
facingMode: o.facingMode ?? "user",
|
|
8244
8592
|
width: { ideal: 640 },
|
|
8245
8593
|
height: { ideal: 480 }
|
|
@@ -8252,7 +8600,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8252
8600
|
Promise.resolve(o.onFrame(video)).finally(() => working = false);
|
|
8253
8601
|
}, 1e3 / (o.fps ?? 4));
|
|
8254
8602
|
} catch (e) {
|
|
8255
|
-
error =
|
|
8603
|
+
error = Di(e).text;
|
|
8256
8604
|
stream = null;
|
|
8257
8605
|
}
|
|
8258
8606
|
emit();
|
|
@@ -8260,7 +8608,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8260
8608
|
stop() {
|
|
8261
8609
|
if (timer) clearInterval(timer);
|
|
8262
8610
|
timer = null;
|
|
8263
|
-
|
|
8611
|
+
Oi(stream);
|
|
8264
8612
|
stream = null;
|
|
8265
8613
|
video.srcObject = null;
|
|
8266
8614
|
emit();
|
|
@@ -8290,7 +8638,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8290
8638
|
* export the mask, a matte or the cutout. With a segment everything model
|
|
8291
8639
|
* (FastSAM) one press finds every object; each lands in the found list and
|
|
8292
8640
|
* a press adds it to the mask. Models are functions the page passes, so
|
|
8293
|
-
* stubs run the studio with no weights.
|
|
8641
|
+
* stubs run the studio with no weights. Three views (composite, mask,
|
|
8642
|
+
* found objects) paint over the canvas; the pointer previews the click cut
|
|
8643
|
+
* or lights the found object under it; two fingers or ctrl and the wheel
|
|
8644
|
+
* zoom; a page that loads models on demand hears `onWant` when a tool needs
|
|
8645
|
+
* one.
|
|
8294
8646
|
*/
|
|
8295
8647
|
const ZOOMS = [
|
|
8296
8648
|
.5,
|
|
@@ -8301,6 +8653,25 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8301
8653
|
3,
|
|
8302
8654
|
4
|
|
8303
8655
|
];
|
|
8656
|
+
const clampZoom = (z) => Math.max(.25, Math.min(6, z));
|
|
8657
|
+
/** Paint `rgb` at `alpha` (0 to 255) where the mask keeps, leaving the other pixels as they are. */
|
|
8658
|
+
function tintInto(rgba, mask, rgb, alpha) {
|
|
8659
|
+
for (let i = 0, j = 0; i < mask.length; i++, j += 4) {
|
|
8660
|
+
if (!mask[i]) continue;
|
|
8661
|
+
rgba[j] = rgb[0];
|
|
8662
|
+
rgba[j + 1] = rgb[1];
|
|
8663
|
+
rgba[j + 2] = rgb[2];
|
|
8664
|
+
rgba[j + 3] = alpha;
|
|
8665
|
+
}
|
|
8666
|
+
}
|
|
8667
|
+
/** ImageData to a png Blob. */
|
|
8668
|
+
function pngOf(img) {
|
|
8669
|
+
const c = document.createElement("canvas");
|
|
8670
|
+
c.width = img.width;
|
|
8671
|
+
c.height = img.height;
|
|
8672
|
+
c.getContext("2d")?.putImageData(img, 0, 0);
|
|
8673
|
+
return new Promise((ok) => c.toBlob((b) => ok(b), "image/png"));
|
|
8674
|
+
}
|
|
8304
8675
|
/** Pixels of a drawable, for a model. */
|
|
8305
8676
|
function pixelsOf(src) {
|
|
8306
8677
|
const c = document.createElement("canvas");
|
|
@@ -8334,17 +8705,22 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8334
8705
|
function mountMaskStudio(host, o = {}) {
|
|
8335
8706
|
let models = o.models ?? {};
|
|
8336
8707
|
const l = listeners();
|
|
8337
|
-
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>`;
|
|
8708
|
+
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>`;
|
|
8338
8709
|
const empty = host.querySelector("[data-empty]");
|
|
8339
8710
|
const studio = host.querySelector("[data-studio]");
|
|
8340
8711
|
const well = host.querySelector(".hb-mask-well");
|
|
8341
8712
|
host.querySelector(".hb-mask-frame");
|
|
8342
|
-
const canvas = host.querySelector("canvas");
|
|
8713
|
+
const canvas = host.querySelector(".hb-mask-canvas");
|
|
8714
|
+
const over = host.querySelector("[data-over]");
|
|
8343
8715
|
const hint = host.querySelector(".hb-mask-hint");
|
|
8344
8716
|
const input = host.querySelector("input[type=file]");
|
|
8345
8717
|
const subs = /* @__PURE__ */ new Set();
|
|
8346
8718
|
let tool = models.segment ? "point" : "wand";
|
|
8347
8719
|
let zoom = 1;
|
|
8720
|
+
let view = "composite";
|
|
8721
|
+
let hover = -1;
|
|
8722
|
+
let preview = null;
|
|
8723
|
+
let wantAll = null;
|
|
8348
8724
|
let busy = "";
|
|
8349
8725
|
let error = "";
|
|
8350
8726
|
let pixels = null;
|
|
@@ -8363,6 +8739,9 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8363
8739
|
coverage: ed?.coverage ?? 0,
|
|
8364
8740
|
zoom,
|
|
8365
8741
|
busy,
|
|
8742
|
+
contiguous: ed?.contiguous ?? true,
|
|
8743
|
+
view,
|
|
8744
|
+
hover,
|
|
8366
8745
|
found,
|
|
8367
8746
|
saved: saved.map(({ bytes: _b, ...rest }) => rest),
|
|
8368
8747
|
width: ed?.width ?? 0,
|
|
@@ -8371,10 +8750,61 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8371
8750
|
});
|
|
8372
8751
|
const emit = () => {
|
|
8373
8752
|
const s = state();
|
|
8374
|
-
hint.textContent = s.busy || s.error || (tool === "point" ? "press a thing to cut it out. x takes it away instead." :
|
|
8753
|
+
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 ?? "");
|
|
8375
8754
|
for (const fn of subs) fn(s);
|
|
8755
|
+
paint();
|
|
8756
|
+
};
|
|
8757
|
+
let painted = "";
|
|
8758
|
+
let frameReq = 0;
|
|
8759
|
+
const paint = () => {
|
|
8760
|
+
if (frameReq) return;
|
|
8761
|
+
frameReq = typeof requestAnimationFrame === "function" ? requestAnimationFrame(drawOver) : (drawOver(), 0);
|
|
8376
8762
|
};
|
|
8377
|
-
const
|
|
8763
|
+
const drawOver = () => {
|
|
8764
|
+
frameReq = 0;
|
|
8765
|
+
const w = ed?.width ?? 0;
|
|
8766
|
+
const h = ed?.height ?? 0;
|
|
8767
|
+
const g = over.getContext("2d");
|
|
8768
|
+
if (!g || !w || !h || !pixels) return;
|
|
8769
|
+
if (over.width !== w || over.height !== h) {
|
|
8770
|
+
over.width = w;
|
|
8771
|
+
over.height = h;
|
|
8772
|
+
}
|
|
8773
|
+
const key = `${view}:${hover}:${preview ? "p" : ""}:${view === "mask" ? editor.state.coverage + ":" + (ed?.canUndo ? 1 : 0) : ""}:${found.map((f) => f.hidden ? 0 : 1).join("")}`;
|
|
8774
|
+
if (view === "composite" && hover < 0 && !preview) {
|
|
8775
|
+
if (painted !== "clear") g.clearRect(0, 0, w, h);
|
|
8776
|
+
painted = "clear";
|
|
8777
|
+
return;
|
|
8778
|
+
}
|
|
8779
|
+
if (key === painted && view !== "mask") return;
|
|
8780
|
+
painted = key;
|
|
8781
|
+
if (view === "mask") {
|
|
8782
|
+
g.putImageData(new ImageData(er(editor.mask(), "matte"), w, h), 0, 0);
|
|
8783
|
+
return;
|
|
8784
|
+
}
|
|
8785
|
+
const rgba = new Uint8ClampedArray(w * h * 4);
|
|
8786
|
+
if (view === "instances") found.forEach((f, i) => !f.hidden && i !== hover && tintInto(rgba, f.mask, nr(f.colour), 150));
|
|
8787
|
+
const hot = hover >= 0 ? found[hover] : void 0;
|
|
8788
|
+
if (hot) tintInto(rgba, hot.mask, nr(hot.colour), 220);
|
|
8789
|
+
else if (preview) tintInto(rgba, preview, [
|
|
8790
|
+
254,
|
|
8791
|
+
3,
|
|
8792
|
+
134
|
|
8793
|
+
], 110);
|
|
8794
|
+
g.putImageData(new ImageData(rgba, w, h), 0, 0);
|
|
8795
|
+
if (view === "instances") {
|
|
8796
|
+
g.lineWidth = Math.max(1, w / 400);
|
|
8797
|
+
g.font = `${Math.max(10, Math.round(w / 60))}px monospace`;
|
|
8798
|
+
for (const f of found) {
|
|
8799
|
+
if (f.hidden || !f.box) continue;
|
|
8800
|
+
g.strokeStyle = f.colour;
|
|
8801
|
+
g.fillStyle = f.colour;
|
|
8802
|
+
g.strokeRect(f.box.x, f.box.y, f.box.w, f.box.h);
|
|
8803
|
+
g.fillText(`${f.label} ${Math.round(f.score * 100)}`, f.box.x + 3, Math.max(12, f.box.y - 4));
|
|
8804
|
+
}
|
|
8805
|
+
}
|
|
8806
|
+
};
|
|
8807
|
+
const editor = ns(canvas, {
|
|
8378
8808
|
tool: tool === "point" ? "wand" : tool,
|
|
8379
8809
|
onError: (e) => (error = `the image did not load: ${e.message}`, emit())
|
|
8380
8810
|
});
|
|
@@ -8386,6 +8816,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8386
8816
|
studio.style.setProperty("--hb-mask-w", `${Math.round(fitW * zoom)}px`);
|
|
8387
8817
|
studio.classList.toggle("is-zoomed", zoom > 1);
|
|
8388
8818
|
};
|
|
8819
|
+
const zoomStep = (dir) => (dir > 0 ? ZOOMS.find((z) => z > zoom + .001) : [...ZOOMS].reverse().find((z) => z < zoom - .001)) ?? zoom;
|
|
8389
8820
|
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(() => applyZoom()) : null;
|
|
8390
8821
|
ro?.observe(well);
|
|
8391
8822
|
l.add(() => ro?.disconnect());
|
|
@@ -8410,17 +8841,130 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8410
8841
|
emit();
|
|
8411
8842
|
}
|
|
8412
8843
|
};
|
|
8844
|
+
const at = (pe) => {
|
|
8845
|
+
const r = canvas.getBoundingClientRect();
|
|
8846
|
+
const w = ed?.width ?? 0;
|
|
8847
|
+
const h = ed?.height ?? 0;
|
|
8848
|
+
return {
|
|
8849
|
+
x: Math.max(0, Math.min(w - 1, Math.round((pe.clientX - r.left) / r.width * w))),
|
|
8850
|
+
y: Math.max(0, Math.min(h - 1, Math.round((pe.clientY - r.top) / r.height * h)))
|
|
8851
|
+
};
|
|
8852
|
+
};
|
|
8853
|
+
const foundAt = (x, y) => found.findIndex((f) => !f.hidden && f.mask[y * (ed?.width ?? 0) + x]);
|
|
8413
8854
|
const onPoint = (e) => {
|
|
8414
8855
|
if (tool !== "point") return;
|
|
8415
8856
|
e.stopImmediatePropagation();
|
|
8416
8857
|
e.preventDefault();
|
|
8417
8858
|
const pe = e;
|
|
8418
|
-
const r = canvas.getBoundingClientRect();
|
|
8419
8859
|
if (!ed?.ready) return;
|
|
8420
|
-
const x =
|
|
8421
|
-
const
|
|
8860
|
+
const { x, y } = at(pe);
|
|
8861
|
+
const i = foundAt(x, y);
|
|
8862
|
+
if (i >= 0) return studioApi.toggleFound(i);
|
|
8863
|
+
if (!models.segment) return o.onWant?.("segment");
|
|
8864
|
+
preview = null;
|
|
8422
8865
|
cut(x, y, ed.mode === "erase" !== pe.shiftKey);
|
|
8423
8866
|
};
|
|
8867
|
+
let asking = false;
|
|
8868
|
+
let next = null;
|
|
8869
|
+
const ask = async (p) => {
|
|
8870
|
+
if (!pixels || !models.segment) return;
|
|
8871
|
+
asking = true;
|
|
8872
|
+
try {
|
|
8873
|
+
const m = await models.segment(pixels, p);
|
|
8874
|
+
if (tool === "point" && next !== null) preview = m;
|
|
8875
|
+
} catch {
|
|
8876
|
+
preview = null;
|
|
8877
|
+
} finally {
|
|
8878
|
+
asking = false;
|
|
8879
|
+
}
|
|
8880
|
+
paint();
|
|
8881
|
+
const n = next;
|
|
8882
|
+
if (n && (n.x !== p.x || n.y !== p.y)) ask(n);
|
|
8883
|
+
};
|
|
8884
|
+
const onHover = (e) => {
|
|
8885
|
+
const pe = e;
|
|
8886
|
+
if (!ed?.ready || pe.buttons || pe.pointerType === "touch") return;
|
|
8887
|
+
const p = at(pe);
|
|
8888
|
+
const i = found.length && (tool === "point" || view === "instances") ? foundAt(p.x, p.y) : -1;
|
|
8889
|
+
if (i !== hover) {
|
|
8890
|
+
hover = i;
|
|
8891
|
+
emit();
|
|
8892
|
+
}
|
|
8893
|
+
if (i >= 0 || tool !== "point" || !models.segment) {
|
|
8894
|
+
next = null;
|
|
8895
|
+
if (preview) preview = null, paint();
|
|
8896
|
+
return;
|
|
8897
|
+
}
|
|
8898
|
+
next = p;
|
|
8899
|
+
if (!asking) ask(p);
|
|
8900
|
+
};
|
|
8901
|
+
const offHover = () => {
|
|
8902
|
+
next = null;
|
|
8903
|
+
preview = null;
|
|
8904
|
+
if (hover >= 0) hover = -1, emit();
|
|
8905
|
+
else paint();
|
|
8906
|
+
};
|
|
8907
|
+
canvas.addEventListener("pointermove", onHover);
|
|
8908
|
+
canvas.addEventListener("pointerleave", offHover);
|
|
8909
|
+
l.add(() => (canvas.removeEventListener("pointermove", onHover), canvas.removeEventListener("pointerleave", offHover)));
|
|
8910
|
+
const touches = /* @__PURE__ */ new Map();
|
|
8911
|
+
let pinch = null;
|
|
8912
|
+
const spread = () => {
|
|
8913
|
+
const [a, b] = [...touches.values()];
|
|
8914
|
+
return a && b ? Math.hypot(a.x - b.x, a.y - b.y) : 0;
|
|
8915
|
+
};
|
|
8916
|
+
l.on(well, "pointerdown", (e) => {
|
|
8917
|
+
const pe = e;
|
|
8918
|
+
if (pe.pointerType !== "touch") return;
|
|
8919
|
+
touches.set(pe.pointerId, {
|
|
8920
|
+
x: pe.clientX,
|
|
8921
|
+
y: pe.clientY
|
|
8922
|
+
});
|
|
8923
|
+
if (touches.size === 2) {
|
|
8924
|
+
editor.cancel();
|
|
8925
|
+
pinch = {
|
|
8926
|
+
d: spread() || 1,
|
|
8927
|
+
z: zoom
|
|
8928
|
+
};
|
|
8929
|
+
}
|
|
8930
|
+
});
|
|
8931
|
+
l.on(well, "pointermove", (e) => {
|
|
8932
|
+
const pe = e;
|
|
8933
|
+
if (!touches.has(pe.pointerId)) return;
|
|
8934
|
+
touches.set(pe.pointerId, {
|
|
8935
|
+
x: pe.clientX,
|
|
8936
|
+
y: pe.clientY
|
|
8937
|
+
});
|
|
8938
|
+
if (pinch && touches.size === 2) studioApi.zoomTo(pinch.z * (spread() / pinch.d));
|
|
8939
|
+
});
|
|
8940
|
+
const lift = (e) => {
|
|
8941
|
+
touches.delete(e.pointerId);
|
|
8942
|
+
if (touches.size < 2) pinch = null;
|
|
8943
|
+
};
|
|
8944
|
+
l.on(well, "pointerup", lift);
|
|
8945
|
+
l.on(well, "pointercancel", lift);
|
|
8946
|
+
l.on(well, "wheel", (e) => {
|
|
8947
|
+
const we = e;
|
|
8948
|
+
if (!we.ctrlKey || !ed?.ready) return;
|
|
8949
|
+
we.preventDefault();
|
|
8950
|
+
studioApi.zoomTo(zoom * Math.exp(-we.deltaY / 200));
|
|
8951
|
+
});
|
|
8952
|
+
l.on(document, "keydown", (e) => {
|
|
8953
|
+
const ke = e;
|
|
8954
|
+
if (ke.defaultPrevented || ke.target.closest?.("input,textarea,select,[contenteditable]")) return;
|
|
8955
|
+
const k = ke.key.toLowerCase();
|
|
8956
|
+
const cmd = ke.ctrlKey || ke.metaKey;
|
|
8957
|
+
if (cmd && k === "o") return ke.preventDefault(), input.click();
|
|
8958
|
+
if (!ed?.ready) return;
|
|
8959
|
+
if (cmd && (k === "z" || k === "y")) return ke.preventDefault(), void (k === "y" || ke.shiftKey ? editor.redo() : editor.undo());
|
|
8960
|
+
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));
|
|
8961
|
+
if (cmd && k === "i") return ke.preventDefault(), editor.invert();
|
|
8962
|
+
if (cmd) return;
|
|
8963
|
+
if (k === "delete") return ke.preventDefault(), editor.clear();
|
|
8964
|
+
if (k === "+" || k === "=") return studioApi.zoom(1);
|
|
8965
|
+
if (k === "-") return studioApi.zoom(-1);
|
|
8966
|
+
if (k === "0") return studioApi.zoom(0);
|
|
8967
|
+
});
|
|
8424
8968
|
canvas.addEventListener("pointerdown", onPoint, true);
|
|
8425
8969
|
l.add(() => canvas.removeEventListener("pointerdown", onPoint, true));
|
|
8426
8970
|
const take = (f) => {
|
|
@@ -8447,6 +8991,8 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8447
8991
|
error = "";
|
|
8448
8992
|
found = [];
|
|
8449
8993
|
saved = [];
|
|
8994
|
+
hover = -1;
|
|
8995
|
+
preview = null;
|
|
8450
8996
|
let drawable = null;
|
|
8451
8997
|
if (typeof src === "string") {
|
|
8452
8998
|
const img = new Image();
|
|
@@ -8466,8 +9012,12 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8466
9012
|
canvas.focus({ preventScroll: true });
|
|
8467
9013
|
},
|
|
8468
9014
|
setTool(t) {
|
|
8469
|
-
if (t === "point" && !models.segment)
|
|
9015
|
+
if (t === "point" && !models.segment) {
|
|
9016
|
+
if (!o.onWant) return;
|
|
9017
|
+
o.onWant("segment");
|
|
9018
|
+
}
|
|
8470
9019
|
tool = t;
|
|
9020
|
+
preview = null;
|
|
8471
9021
|
if (t !== "point") editor.setTool(t);
|
|
8472
9022
|
canvas.dataset.tool = t;
|
|
8473
9023
|
emit();
|
|
@@ -8505,25 +9055,83 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8505
9055
|
},
|
|
8506
9056
|
mask: (kind = "alpha") => ed?.ready ? editor.toImageData(kind) : null,
|
|
8507
9057
|
zoom(dir) {
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
|
|
9058
|
+
zoom = dir === 0 ? 1 : zoomStep(dir);
|
|
9059
|
+
applyZoom();
|
|
9060
|
+
emit();
|
|
9061
|
+
},
|
|
9062
|
+
zoomTo(z) {
|
|
9063
|
+
zoom = clampZoom(z);
|
|
8513
9064
|
applyZoom();
|
|
8514
9065
|
emit();
|
|
8515
9066
|
},
|
|
8516
|
-
|
|
8517
|
-
|
|
9067
|
+
setView(v) {
|
|
9068
|
+
view = v;
|
|
9069
|
+
emit();
|
|
9070
|
+
},
|
|
9071
|
+
setContiguous: (on) => editor.setContiguous(on),
|
|
9072
|
+
setMask(m) {
|
|
9073
|
+
if (ed?.ready && m.length === ed.width * ed.height) editor.setMask(m);
|
|
9074
|
+
},
|
|
9075
|
+
addFound(list) {
|
|
9076
|
+
const n = found.length;
|
|
9077
|
+
found = [...found, ...list.filter((f) => f.mask.length === (ed?.width ?? 0) * (ed?.height ?? 0)).map((f, i) => ({
|
|
9078
|
+
...f,
|
|
9079
|
+
on: false,
|
|
9080
|
+
hidden: false,
|
|
9081
|
+
colour: ht[(n + i) % ht.length]
|
|
9082
|
+
}))];
|
|
9083
|
+
if (found.length > n && view === "composite") view = "instances";
|
|
9084
|
+
emit();
|
|
9085
|
+
},
|
|
9086
|
+
showFound(i, on) {
|
|
9087
|
+
found = found.map((x, k) => k === i ? {
|
|
9088
|
+
...x,
|
|
9089
|
+
hidden: !on
|
|
9090
|
+
} : x);
|
|
9091
|
+
emit();
|
|
9092
|
+
},
|
|
9093
|
+
removeFound(i) {
|
|
9094
|
+
found = found.filter((_, k) => k !== i);
|
|
9095
|
+
hover = -1;
|
|
9096
|
+
emit();
|
|
9097
|
+
},
|
|
9098
|
+
mergeFound() {
|
|
9099
|
+
if (!ed?.ready || !found.length) return;
|
|
9100
|
+
const cur = editor.mask();
|
|
9101
|
+
for (const f of found) if (!f.hidden) {
|
|
9102
|
+
for (let p = 0; p < cur.length; p++) if (f.mask[p]) cur[p] = 255;
|
|
9103
|
+
}
|
|
9104
|
+
found = found.map((x) => x.hidden ? x : {
|
|
9105
|
+
...x,
|
|
9106
|
+
on: true
|
|
9107
|
+
});
|
|
9108
|
+
editor.setMask(cur);
|
|
9109
|
+
},
|
|
9110
|
+
clearFound() {
|
|
9111
|
+
found = [];
|
|
9112
|
+
hover = -1;
|
|
9113
|
+
if (view === "instances") view = "composite";
|
|
9114
|
+
emit();
|
|
9115
|
+
},
|
|
9116
|
+
pixels: () => pixels,
|
|
9117
|
+
async everything(eo) {
|
|
9118
|
+
if (!pixels) return;
|
|
9119
|
+
if (!models.everything) {
|
|
9120
|
+
wantAll = eo ?? {};
|
|
9121
|
+
return o.onWant?.("everything");
|
|
9122
|
+
}
|
|
9123
|
+
wantAll = null;
|
|
8518
9124
|
busy = "finding every object";
|
|
8519
9125
|
error = "";
|
|
8520
9126
|
emit();
|
|
8521
9127
|
try {
|
|
8522
|
-
found = (await models.everything(pixels)).map((f, i) => ({
|
|
9128
|
+
found = (await models.everything(pixels, eo)).map((f, i) => ({
|
|
8523
9129
|
...f,
|
|
8524
9130
|
on: false,
|
|
8525
|
-
|
|
9131
|
+
hidden: false,
|
|
9132
|
+
colour: ht[i % ht.length]
|
|
8526
9133
|
}));
|
|
9134
|
+
if (found.length) view = "instances";
|
|
8527
9135
|
} catch (e) {
|
|
8528
9136
|
error = `segment everything failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
8529
9137
|
} finally {
|
|
@@ -8545,6 +9153,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8545
9153
|
},
|
|
8546
9154
|
async exportAs(kind) {
|
|
8547
9155
|
if (!ed?.ready) return null;
|
|
9156
|
+
if (kind === "inverse") return pngOf(new ImageData(er(Jn(editor.mask()), "matte"), ed.width, ed.height));
|
|
8548
9157
|
return editor.toBlob(kind);
|
|
8549
9158
|
},
|
|
8550
9159
|
get hasEverything() {
|
|
@@ -8553,6 +9162,9 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8553
9162
|
get hasSegment() {
|
|
8554
9163
|
return !!models.segment;
|
|
8555
9164
|
},
|
|
9165
|
+
get canWant() {
|
|
9166
|
+
return !!o.onWant;
|
|
9167
|
+
},
|
|
8556
9168
|
state,
|
|
8557
9169
|
subscribe(fn) {
|
|
8558
9170
|
subs.add(fn);
|
|
@@ -8566,8 +9178,9 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8566
9178
|
tool = "point";
|
|
8567
9179
|
canvas.dataset.tool = "point";
|
|
8568
9180
|
}
|
|
8569
|
-
if (tool === "point" && !m.segment) studioApi.setTool("wand");
|
|
9181
|
+
if (tool === "point" && !m.segment && !o.onWant) studioApi.setTool("wand");
|
|
8570
9182
|
emit();
|
|
9183
|
+
if (wantAll && m.everything) studioApi.everything(wantAll);
|
|
8571
9184
|
},
|
|
8572
9185
|
pick: () => input.click(),
|
|
8573
9186
|
dispose() {
|
|
@@ -8584,17 +9197,17 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8584
9197
|
function mountMaskTools(host, studio) {
|
|
8585
9198
|
const l = listeners();
|
|
8586
9199
|
const draw = (s) => {
|
|
8587
|
-
host.innerHTML = [...studio.hasSegment ? [{
|
|
9200
|
+
host.innerHTML = [...studio.hasSegment || studio.canWant ? [{
|
|
8588
9201
|
id: "point",
|
|
8589
9202
|
label: "cut out a thing",
|
|
8590
9203
|
key: "a",
|
|
8591
9204
|
icon: "crosshairs"
|
|
8592
|
-
}] : [], ...
|
|
9205
|
+
}] : [], ...gt.map((t) => ({
|
|
8593
9206
|
id: t.id,
|
|
8594
9207
|
label: t.label,
|
|
8595
9208
|
key: t.key,
|
|
8596
9209
|
icon: t.icon
|
|
8597
|
-
}))].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}">${
|
|
9210
|
+
}))].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("");
|
|
8598
9211
|
};
|
|
8599
9212
|
l.on(host, "click", (e) => {
|
|
8600
9213
|
const t = e.target.closest("[data-tool]");
|
|
@@ -8602,12 +9215,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8602
9215
|
});
|
|
8603
9216
|
l.on(document, "keydown", (e) => {
|
|
8604
9217
|
const ke = e;
|
|
8605
|
-
if (
|
|
8606
|
-
if (ke.key === "+" || ke.key === "=") return studio.zoom(1);
|
|
8607
|
-
if (ke.key === "-") return studio.zoom(-1);
|
|
8608
|
-
if (ke.key === "0") return studio.zoom(0);
|
|
8609
|
-
}
|
|
8610
|
-
if (ke.key === "a" && !ke.ctrlKey && !ke.metaKey && studio.hasSegment && !ke.target.closest?.("input,textarea,[contenteditable]")) studio.setTool("point");
|
|
9218
|
+
if (ke.key === "a" && !ke.ctrlKey && !ke.metaKey && (studio.hasSegment || studio.canWant) && !ke.target.closest?.("input,textarea,[contenteditable]")) studio.setTool("point");
|
|
8611
9219
|
});
|
|
8612
9220
|
l.add(studio.subscribe(draw));
|
|
8613
9221
|
return { dispose: () => l.off() };
|
|
@@ -8617,11 +9225,17 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8617
9225
|
const l = listeners();
|
|
8618
9226
|
let last = "";
|
|
8619
9227
|
const draw = (s) => {
|
|
8620
|
-
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>`
|
|
9228
|
+
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">${[
|
|
9229
|
+
"composite",
|
|
9230
|
+
"mask",
|
|
9231
|
+
"instances"
|
|
9232
|
+
].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>` : "") : "";
|
|
8621
9233
|
if (html !== last) host.innerHTML = last = html;
|
|
8622
9234
|
host.hidden = !html;
|
|
8623
9235
|
};
|
|
8624
9236
|
l.on(host, "click", (e) => {
|
|
9237
|
+
const view = e.target.closest("[data-view]")?.dataset.view;
|
|
9238
|
+
if (view) return studio.setView(view);
|
|
8625
9239
|
const v = e.target.closest("[data-v]")?.dataset.v;
|
|
8626
9240
|
if (v === "undo") studio.undo();
|
|
8627
9241
|
else if (v === "redo") studio.redo();
|
|
@@ -8639,11 +9253,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8639
9253
|
const draw = (s) => {
|
|
8640
9254
|
let html = "";
|
|
8641
9255
|
if (part === "found") {
|
|
8642
|
-
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>` : "");
|
|
9256
|
+
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>` : "");
|
|
8643
9257
|
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>` : "";
|
|
8644
|
-
} 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>` : "");
|
|
9258
|
+
} 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>` : "");
|
|
8645
9259
|
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>`);
|
|
8646
|
-
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>`;
|
|
9260
|
+
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>`;
|
|
8647
9261
|
if (html !== last) host.innerHTML = last = html;
|
|
8648
9262
|
};
|
|
8649
9263
|
l.on(host, "click", (e) => {
|
|
@@ -8652,7 +9266,13 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8652
9266
|
if (f) return studio.toggleFound(Number(f.dataset.found));
|
|
8653
9267
|
const m = t.closest("[data-mode]");
|
|
8654
9268
|
if (m) return studio.setMode(m.dataset.mode);
|
|
9269
|
+
const show = t.closest("[data-show]");
|
|
9270
|
+
if (show) return studio.showFound(Number(show.dataset.show), show.getAttribute("aria-pressed") !== "true");
|
|
9271
|
+
const drop = t.closest("[data-drop]");
|
|
9272
|
+
if (drop) return studio.removeFound(Number(drop.dataset.drop));
|
|
8655
9273
|
const op = t.closest("[data-op]")?.dataset.op;
|
|
9274
|
+
if (op === "merge") return studio.mergeFound();
|
|
9275
|
+
if (op === "unfind") return studio.clearFound();
|
|
8656
9276
|
if (op === "invert") return studio.invert();
|
|
8657
9277
|
if (op === "clear") return studio.clear();
|
|
8658
9278
|
if (op === "smooth") return studio.smooth();
|
|
@@ -8675,6 +9295,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8675
9295
|
const i = e.target;
|
|
8676
9296
|
if (i.dataset.size !== void 0) studio.setSize(Number(i.value));
|
|
8677
9297
|
if (i.dataset.tol !== void 0) studio.setTolerance(Number(i.value));
|
|
9298
|
+
if (i.dataset.contig !== void 0) studio.setContiguous(i.checked);
|
|
8678
9299
|
});
|
|
8679
9300
|
l.add(studio.subscribe(draw));
|
|
8680
9301
|
return { dispose: () => l.off() };
|
|
@@ -8694,7 +9315,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8694
9315
|
const s0 = pick.snapshot();
|
|
8695
9316
|
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>`;
|
|
8696
9317
|
doc.body.append(root);
|
|
8697
|
-
const sheet =
|
|
9318
|
+
const sheet = ea(root.querySelector(".hb-msheet-host"), {
|
|
8698
9319
|
rows: s0.rows,
|
|
8699
9320
|
chosen: s0.chosen,
|
|
8700
9321
|
title: s0.title,
|
|
@@ -8706,7 +9327,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8706
9327
|
onCustom: (kind, values) => void pick.custom(kind, values)
|
|
8707
9328
|
});
|
|
8708
9329
|
const l = listeners();
|
|
8709
|
-
const handle =
|
|
9330
|
+
const handle = Wr(root, {
|
|
8710
9331
|
side: "auto",
|
|
8711
9332
|
breakpoint: 641,
|
|
8712
9333
|
label: s0.title
|
|
@@ -8741,7 +9362,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8741
9362
|
function chipWords(s) {
|
|
8742
9363
|
const r = s.row;
|
|
8743
9364
|
if (!r) return s.empty;
|
|
8744
|
-
const w =
|
|
9365
|
+
const w = qr(r, s.empty);
|
|
8745
9366
|
const name = shortName(r.name);
|
|
8746
9367
|
if ((r.state === "loading" || r.state === "loaded" || r.state === "error") && w.state) return `${name}, ${w.state}`;
|
|
8747
9368
|
return `${name}, ${r.noDownload ? "no download" : r.size ?? "size unknown"}`;
|
|
@@ -8754,7 +9375,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8754
9375
|
if (o.variant === "chip") {
|
|
8755
9376
|
const draw = (s) => {
|
|
8756
9377
|
const words = chipWords(s);
|
|
8757
|
-
const full = s.row ? `model: ${s.row.name}${s.row.size ? `, ${s.row.size}` : ""}${
|
|
9378
|
+
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}`;
|
|
8758
9379
|
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>`;
|
|
8759
9380
|
};
|
|
8760
9381
|
l.on(host, "click", (e) => {
|
|
@@ -8765,7 +9386,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8765
9386
|
const inner = document.createElement("div");
|
|
8766
9387
|
host.replaceChildren(inner);
|
|
8767
9388
|
const s0 = pick.snapshot();
|
|
8768
|
-
const sel =
|
|
9389
|
+
const sel = ta(inner, {
|
|
8769
9390
|
rows: s0.rows,
|
|
8770
9391
|
chosen: s0.chosen,
|
|
8771
9392
|
go: o.go ?? true,
|
|
@@ -8783,7 +9404,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8783
9404
|
}
|
|
8784
9405
|
/** The words of a gate's one pink button for a pick: "load, 1.7 gb", then "ready". */
|
|
8785
9406
|
function gateWords(row) {
|
|
8786
|
-
return row &&
|
|
9407
|
+
return row && Re(row) ? Ie(row) : row?.state === "loaded" ? "ready" : Ie(row);
|
|
8787
9408
|
}
|
|
8788
9409
|
/** Several jobs: one line per job, presets with totals, and one pink "load all, <total>". */
|
|
8789
9410
|
function mountModelJobs(host, jobs, o = {}) {
|
|
@@ -8793,7 +9414,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8793
9414
|
const presets = jobs.presets();
|
|
8794
9415
|
const all = jobs.all();
|
|
8795
9416
|
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) => {
|
|
8796
|
-
const w =
|
|
9417
|
+
const w = qr(j.row, "no model");
|
|
8797
9418
|
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>`;
|
|
8798
9419
|
}).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>`;
|
|
8799
9420
|
};
|
|
@@ -8822,13 +9443,13 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8822
9443
|
/** The HTML of one channel's transcript, or an empty note when there is none. */
|
|
8823
9444
|
function transcriptHtml(c, o = {}) {
|
|
8824
9445
|
if (!c) return `<p class="hb-lay-empty-note">nothing yet. drop a file.</p>`;
|
|
8825
|
-
const st =
|
|
9446
|
+
const st = ki(c.status);
|
|
8826
9447
|
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>` : ""}`;
|
|
8827
9448
|
if (!c.segments.length) return `<section class="hb-panel">${head}</section>`;
|
|
8828
|
-
return `<section class="hb-panel">${head}<ol class="hb-transcript is-edit" aria-label="transcript">${c.dropped.length ? `<li class="hb-tseg-note">${esc(
|
|
8829
|
-
const t =
|
|
9449
|
+
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) => {
|
|
9450
|
+
const t = ie(s.start);
|
|
8830
9451
|
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>`;
|
|
8831
|
-
}).join("")}${o.showDropped ? c.dropped.map((d) => `<li><div class="hb-tseg is-dropped"><span class="hb-tseg-body"><span class="hb-tseg-t">${
|
|
9452
|
+
}).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>`;
|
|
8832
9453
|
}
|
|
8833
9454
|
const pickedOf = (s) => s.channels.find((c) => c.id === s.selected);
|
|
8834
9455
|
/** The selected channel's transcript over a host. */
|
|
@@ -8866,6 +9487,29 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8866
9487
|
l.add(queue.subscribe(draw));
|
|
8867
9488
|
return { dispose: () => l.off() };
|
|
8868
9489
|
}
|
|
9490
|
+
const AV = /\.(mp4|m4v|mov|webm|mkv|avi|mpe?g|ogv|m4a|mp3|wav|flac|ogg|opus|aac|wma|3gp)$/i;
|
|
9491
|
+
/** A file a speech run can read: audio or video by type or by name. */
|
|
9492
|
+
const isMedia = (f) => /^(audio|video)\//.test(f.type) || AV.test(f.name);
|
|
9493
|
+
async function walk$1(e, out, depth = 0) {
|
|
9494
|
+
if (e.isFile && e.file) out.push(await new Promise((ok, bad) => e.file(ok, bad)));
|
|
9495
|
+
else if (e.isDirectory && e.createReader && depth < 8) {
|
|
9496
|
+
const r = e.createReader();
|
|
9497
|
+
for (;;) {
|
|
9498
|
+
const batch = await new Promise((ok, bad) => r.readEntries(ok, bad));
|
|
9499
|
+
if (!batch.length) break;
|
|
9500
|
+
for (const c of batch) await walk$1(c, out, depth + 1);
|
|
9501
|
+
}
|
|
9502
|
+
}
|
|
9503
|
+
}
|
|
9504
|
+
/** The files of a drop, with dropped folders read through, media only. */
|
|
9505
|
+
async function droppedFiles(dt) {
|
|
9506
|
+
if (!dt) return [];
|
|
9507
|
+
const entries = [...dt.items ?? []].map((i) => i.webkitGetAsEntry?.()).filter((x) => x !== null && x !== void 0);
|
|
9508
|
+
if (!entries.length) return [...dt.files].filter(isMedia);
|
|
9509
|
+
const out = [];
|
|
9510
|
+
for (const e of entries) await walk$1(e, out).catch(() => void 0);
|
|
9511
|
+
return out.filter(isMedia);
|
|
9512
|
+
}
|
|
8869
9513
|
/** The drop zone that becomes the transcript. */
|
|
8870
9514
|
function mountTranscribeDrop(host, queue, o = {}) {
|
|
8871
9515
|
const l = listeners();
|
|
@@ -8874,15 +9518,19 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8874
9518
|
input.hidden = true;
|
|
8875
9519
|
input.multiple = true;
|
|
8876
9520
|
input.accept = o.accept ?? "audio/*,video/*";
|
|
9521
|
+
const dir = document.createElement("input");
|
|
9522
|
+
dir.type = "file";
|
|
9523
|
+
dir.hidden = true;
|
|
9524
|
+
dir.setAttribute("webkitdirectory", "");
|
|
8877
9525
|
const zone = document.createElement("div");
|
|
8878
9526
|
const result = document.createElement("div");
|
|
8879
|
-
host.replaceChildren(zone, result, input);
|
|
9527
|
+
host.replaceChildren(zone, result, input, dir);
|
|
8880
9528
|
zone.className = "hb-lay-drop";
|
|
8881
9529
|
result.className = "hb-lay-scroll";
|
|
8882
|
-
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>`;
|
|
9530
|
+
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>`;
|
|
8883
9531
|
const view = mountTranscriptView(result, queue, o);
|
|
8884
9532
|
const take = (list) => {
|
|
8885
|
-
const files = list ? [...list] : [];
|
|
9533
|
+
const files = list ? [...list].filter(isMedia) : [];
|
|
8886
9534
|
if (files.length) queue.add(files);
|
|
8887
9535
|
};
|
|
8888
9536
|
l.on(host, "dragover", (e) => {
|
|
@@ -8893,7 +9541,11 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8893
9541
|
l.on(host, "drop", (e) => {
|
|
8894
9542
|
e.preventDefault();
|
|
8895
9543
|
zone.classList.remove("is-hot");
|
|
8896
|
-
|
|
9544
|
+
droppedFiles(e.dataTransfer).then((fs) => fs.length && queue.add(fs));
|
|
9545
|
+
});
|
|
9546
|
+
l.on(dir, "change", () => {
|
|
9547
|
+
take(dir.files);
|
|
9548
|
+
dir.value = "";
|
|
8897
9549
|
});
|
|
8898
9550
|
l.on(input, "change", () => {
|
|
8899
9551
|
take(input.files);
|
|
@@ -8902,6 +9554,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8902
9554
|
l.on(zone, "click", (e) => {
|
|
8903
9555
|
const t = e.target;
|
|
8904
9556
|
if (t.closest("[data-pick]")) input.click();
|
|
9557
|
+
else if (t.closest("[data-folder]")) dir.click();
|
|
8905
9558
|
else if (t.closest("[data-sample]")) o.onSample?.();
|
|
8906
9559
|
});
|
|
8907
9560
|
l.add(queue.subscribe((s) => {
|
|
@@ -8911,6 +9564,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8911
9564
|
}));
|
|
8912
9565
|
return {
|
|
8913
9566
|
pick: () => input.click(),
|
|
9567
|
+
pickFolder: () => dir.click(),
|
|
8914
9568
|
dispose() {
|
|
8915
9569
|
l.off();
|
|
8916
9570
|
view.dispose();
|
|
@@ -8922,7 +9576,7 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8922
9576
|
const l = listeners();
|
|
8923
9577
|
const draw = (s) => {
|
|
8924
9578
|
const strips = s.channels.map((c, i) => {
|
|
8925
|
-
const st =
|
|
9579
|
+
const st = ki(c.status);
|
|
8926
9580
|
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>`;
|
|
8927
9581
|
}).join("");
|
|
8928
9582
|
const queued = s.channels.some((c) => c.status === "queued");
|
|
@@ -8974,6 +9628,50 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
8974
9628
|
l.add(queue.subscribe(draw));
|
|
8975
9629
|
return { dispose: () => l.off() };
|
|
8976
9630
|
}
|
|
9631
|
+
/**
|
|
9632
|
+
* ExportMenu: the selected transcript as txt, srt, vtt or json, a copy, and
|
|
9633
|
+
* every finished transcript as one zip with a manifest, plus undo and redo of
|
|
9634
|
+
* edits. Nothing shows until there is text; undo shows once there is a change.
|
|
9635
|
+
* `go` makes the first export the one pink action.
|
|
9636
|
+
*/
|
|
9637
|
+
function mountExportMenu(host, queue, o = {}) {
|
|
9638
|
+
const l = listeners();
|
|
9639
|
+
const save = o.save ?? ((name, data, type) => download(name, typeof data === "string" ? data : new Blob([data], { type }), type));
|
|
9640
|
+
const draw = (s) => {
|
|
9641
|
+
const c = pickedOf(s);
|
|
9642
|
+
const done = s.channels.filter((x) => x.segments.length).length;
|
|
9643
|
+
host.innerHTML = c?.segments.length ? `<div class="hb-toolbar" role="group" aria-label="export">${[
|
|
9644
|
+
"txt",
|
|
9645
|
+
"srt",
|
|
9646
|
+
"vtt",
|
|
9647
|
+
"json"
|
|
9648
|
+
].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>` : "";
|
|
9649
|
+
};
|
|
9650
|
+
l.on(host, "click", (e) => {
|
|
9651
|
+
const t = e.target;
|
|
9652
|
+
const ex = t.closest("[data-ex]");
|
|
9653
|
+
if (ex) {
|
|
9654
|
+
const f = queue.exportAs(ex.dataset.ex);
|
|
9655
|
+
if (f) save(f.name, f.text, f.type);
|
|
9656
|
+
return;
|
|
9657
|
+
}
|
|
9658
|
+
if (t.closest("[data-zip]")) {
|
|
9659
|
+
const z = queue.zip(o.tool ? { tool: o.tool } : {});
|
|
9660
|
+
if (z) save(z.name, z.data, "application/zip");
|
|
9661
|
+
return;
|
|
9662
|
+
}
|
|
9663
|
+
const cp = t.closest("[data-copy]");
|
|
9664
|
+
if (cp) {
|
|
9665
|
+
const f = queue.exportAs("txt");
|
|
9666
|
+
if (f) navigator.clipboard?.writeText(f.text).then(() => cp.lastChild.textContent = "copied").catch(() => cp.lastChild.textContent = "copy blocked");
|
|
9667
|
+
return;
|
|
9668
|
+
}
|
|
9669
|
+
if (t.closest("[data-undo]")) queue.undo();
|
|
9670
|
+
else if (t.closest("[data-redo]")) queue.redo();
|
|
9671
|
+
});
|
|
9672
|
+
l.add(queue.subscribe(draw));
|
|
9673
|
+
return { dispose: () => l.off() };
|
|
9674
|
+
}
|
|
8977
9675
|
// packages/ai-views/src/transcribe.ts
|
|
8978
9676
|
/**
|
|
8979
9677
|
* The state behind TranscribeDrop and TranscriptView: drop files, they queue as channels, run one at a
|
|
@@ -9017,11 +9715,20 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9017
9715
|
} : c);
|
|
9018
9716
|
emit();
|
|
9019
9717
|
};
|
|
9020
|
-
const metaOf = (c) =>
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9718
|
+
const metaOf = (c) => {
|
|
9719
|
+
const s = c.stats;
|
|
9720
|
+
return xi({
|
|
9721
|
+
size: c.size,
|
|
9722
|
+
...c.duration ? { duration: c.duration } : {},
|
|
9723
|
+
...s ? {
|
|
9724
|
+
snrDb: s.snrDb,
|
|
9725
|
+
gainDb: s.gainDb,
|
|
9726
|
+
density: s.density,
|
|
9727
|
+
rtf: s.rtf
|
|
9728
|
+
} : {},
|
|
9729
|
+
...c.status === "done" ? { lines: c.segments.length } : {}
|
|
9730
|
+
});
|
|
9731
|
+
};
|
|
9025
9732
|
const q = {
|
|
9026
9733
|
snapshot: snap,
|
|
9027
9734
|
subscribe(fn) {
|
|
@@ -9066,7 +9773,8 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9066
9773
|
try {
|
|
9067
9774
|
const r = await run(file, {
|
|
9068
9775
|
signal: ac.signal,
|
|
9069
|
-
onProgress: (f) => patch(next.id, { pct: Math.round(Math.min(1, Math.max(0, f)) * 100) })
|
|
9776
|
+
onProgress: (f) => patch(next.id, { pct: Math.round(Math.min(1, Math.max(0, f)) * 100) }),
|
|
9777
|
+
...o.options ? { options: o.options() } : {}
|
|
9070
9778
|
});
|
|
9071
9779
|
const c = channels.find((x) => x.id === next.id);
|
|
9072
9780
|
if (!c) continue;
|
|
@@ -9080,6 +9788,8 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9080
9788
|
if (r.duration !== void 0) done.duration = r.duration;
|
|
9081
9789
|
if (r.language) done.language = r.language;
|
|
9082
9790
|
if (r.model) done.model = r.model;
|
|
9791
|
+
if (r.stats) done.stats = r.stats;
|
|
9792
|
+
if (r.rail) done.rail = r.rail;
|
|
9083
9793
|
done.meta = metaOf(done);
|
|
9084
9794
|
patch(next.id, done);
|
|
9085
9795
|
if (selected === null || channels.find((x) => x.id === selected)?.status !== "done") selected = next.id;
|
|
@@ -9182,6 +9892,30 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9182
9892
|
type: TYPES[kind]
|
|
9183
9893
|
};
|
|
9184
9894
|
},
|
|
9895
|
+
zip(zo = {}) {
|
|
9896
|
+
const done = channels.filter((c) => c.segments.length);
|
|
9897
|
+
if (!done.length) return null;
|
|
9898
|
+
const docs = done.map((c) => ({
|
|
9899
|
+
source: c.name,
|
|
9900
|
+
segments: c.segments,
|
|
9901
|
+
dropped: c.dropped,
|
|
9902
|
+
model: c.model ?? "unknown",
|
|
9903
|
+
language: c.language ?? "unknown",
|
|
9904
|
+
...c.stats ? { stats: c.stats } : {},
|
|
9905
|
+
...c.duration !== void 0 ? { duration: c.duration } : {}
|
|
9906
|
+
}));
|
|
9907
|
+
const capture = o.options?.() ?? null;
|
|
9908
|
+
const out = bundle(docs, {
|
|
9909
|
+
...zo.tool ? { tool: zo.tool } : {},
|
|
9910
|
+
capture,
|
|
9911
|
+
...zo.date ? { date: zo.date } : {}
|
|
9912
|
+
});
|
|
9913
|
+
return {
|
|
9914
|
+
name: `transcripts-${(zo.date ?? /* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.zip`,
|
|
9915
|
+
data: out.zip,
|
|
9916
|
+
manifest: out.manifest
|
|
9917
|
+
};
|
|
9918
|
+
},
|
|
9185
9919
|
setTranscriber(t) {
|
|
9186
9920
|
run = t;
|
|
9187
9921
|
}
|
|
@@ -9220,6 +9954,418 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9220
9954
|
dispose() {}
|
|
9221
9955
|
};
|
|
9222
9956
|
}
|
|
9957
|
+
// packages/ai-views/src/mount-talk.ts
|
|
9958
|
+
/** True when an item is kept out of cleanup: decay never drops it. */
|
|
9959
|
+
const isProtected = (it) => it.meta?.protected === true;
|
|
9960
|
+
/** Protect an item from cleanup (it becomes lore, which never decays) or give it back its kind. */
|
|
9961
|
+
async function protect(mem, it, on) {
|
|
9962
|
+
if (on === isProtected(it)) return;
|
|
9963
|
+
const meta = { ...it.meta ?? {} };
|
|
9964
|
+
if (on) await mem.edit(it.id, {
|
|
9965
|
+
kind: "lore",
|
|
9966
|
+
meta: {
|
|
9967
|
+
...meta,
|
|
9968
|
+
protected: true,
|
|
9969
|
+
was: it.kind
|
|
9970
|
+
}
|
|
9971
|
+
});
|
|
9972
|
+
else {
|
|
9973
|
+
const was = meta.was ?? "fact";
|
|
9974
|
+
delete meta.protected;
|
|
9975
|
+
delete meta.was;
|
|
9976
|
+
await mem.edit(it.id, {
|
|
9977
|
+
kind: was,
|
|
9978
|
+
meta
|
|
9979
|
+
});
|
|
9980
|
+
}
|
|
9981
|
+
}
|
|
9982
|
+
const sourceOf = (it) => typeof it.meta?.source === "string" ? it.meta.source.split("/")[0] : it.kind === "doc" ? it.section ?? "file" : "notes";
|
|
9983
|
+
/** The memory pane: counts, search, a source or kind filter, add a note, the list with protect and forget, export, import, erase. */
|
|
9984
|
+
function mountMemoryPane(host, mem, o = {}) {
|
|
9985
|
+
const l = listeners();
|
|
9986
|
+
let query = "";
|
|
9987
|
+
let source = "";
|
|
9988
|
+
let armed = 0;
|
|
9989
|
+
let wipe = false;
|
|
9990
|
+
let used = /* @__PURE__ */ new Set();
|
|
9991
|
+
let hits = null;
|
|
9992
|
+
let seq = 0;
|
|
9993
|
+
const file = document.createElement("input");
|
|
9994
|
+
file.type = "file";
|
|
9995
|
+
file.accept = ".json,application/json";
|
|
9996
|
+
file.hidden = true;
|
|
9997
|
+
const box = document.createElement("div");
|
|
9998
|
+
host.replaceChildren(box, file);
|
|
9999
|
+
const changed = () => (o.onChange?.(), draw());
|
|
10000
|
+
const groupOf = (it) => o.by === "kind" ? isProtected(it) ? String(it.meta?.was ?? it.kind) : it.kind : sourceOf(it);
|
|
10001
|
+
const groupWord = (g) => o.by === "kind" ? o.kinds?.[g] ?? g : g;
|
|
10002
|
+
const draw = () => {
|
|
10003
|
+
const all = mem.all();
|
|
10004
|
+
const sources = [...new Set(all.map(groupOf))];
|
|
10005
|
+
let shown = all.filter((it) => !source || groupOf(it) === source);
|
|
10006
|
+
if (hits) shown = shown.filter((it) => hits.has(it.id)).sort((a, b) => hits.get(b.id) - hits.get(a.id));
|
|
10007
|
+
else shown = shown.slice().sort((a, b) => b.created - a.created);
|
|
10008
|
+
const focus = document.activeElement === box.querySelector("[data-q]");
|
|
10009
|
+
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) => ({
|
|
10010
|
+
id: String(it.id),
|
|
10011
|
+
text: it.text,
|
|
10012
|
+
kind: it.kind
|
|
10013
|
+
}))) || "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) => {
|
|
10014
|
+
const p = isProtected(it);
|
|
10015
|
+
const u = used.has(it.text);
|
|
10016
|
+
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>`;
|
|
10017
|
+
}).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>`;
|
|
10018
|
+
if (focus) {
|
|
10019
|
+
const q = box.querySelector("[data-q]");
|
|
10020
|
+
q.focus();
|
|
10021
|
+
q.setSelectionRange(q.value.length, q.value.length);
|
|
10022
|
+
}
|
|
10023
|
+
};
|
|
10024
|
+
const search = async () => {
|
|
10025
|
+
const mine = ++seq;
|
|
10026
|
+
if (!query.trim()) hits = null;
|
|
10027
|
+
else {
|
|
10028
|
+
const r = await mem.recall(query, { k: 50 });
|
|
10029
|
+
if (mine !== seq) return;
|
|
10030
|
+
hits = new Map(r.hits.map((h) => [h.item.id, h.score]));
|
|
10031
|
+
}
|
|
10032
|
+
draw();
|
|
10033
|
+
};
|
|
10034
|
+
l.on(box, "input", (e) => {
|
|
10035
|
+
const t = e.target;
|
|
10036
|
+
if (t.matches("[data-q]")) {
|
|
10037
|
+
query = t.value;
|
|
10038
|
+
search();
|
|
10039
|
+
}
|
|
10040
|
+
});
|
|
10041
|
+
l.on(box, "keydown", (e) => {
|
|
10042
|
+
const ke = e;
|
|
10043
|
+
if (ke.target.matches("[data-note]") && ke.key === "Enter" && !ke.shiftKey) {
|
|
10044
|
+
ke.preventDefault();
|
|
10045
|
+
box.querySelector("[data-add]")?.click();
|
|
10046
|
+
}
|
|
10047
|
+
});
|
|
10048
|
+
l.on(box, "click", (e) => {
|
|
10049
|
+
const t = e.target;
|
|
10050
|
+
const src = t.closest("[data-src]");
|
|
10051
|
+
if (src) return source = src.dataset.src ?? "", draw();
|
|
10052
|
+
const all = () => mem.all();
|
|
10053
|
+
const keep = t.closest("[data-keep]");
|
|
10054
|
+
if (keep) {
|
|
10055
|
+
const it = all().find((x) => x.id === Number(keep.dataset.keep));
|
|
10056
|
+
if (it) protect(mem, it, !isProtected(it)).then(changed);
|
|
10057
|
+
return;
|
|
10058
|
+
}
|
|
10059
|
+
const fg = t.closest("[data-forget]");
|
|
10060
|
+
if (fg) {
|
|
10061
|
+
const id = Number(fg.dataset.forget);
|
|
10062
|
+
if (armed !== id) return armed = id, draw();
|
|
10063
|
+
armed = 0;
|
|
10064
|
+
mem.remove([id]).then(changed);
|
|
10065
|
+
return;
|
|
10066
|
+
}
|
|
10067
|
+
if (t.closest("[data-add]")) {
|
|
10068
|
+
const text = box.querySelector("[data-note]").value.trim();
|
|
10069
|
+
if (text) mem.add(text, { kind: "fact" }).then(changed);
|
|
10070
|
+
return;
|
|
10071
|
+
}
|
|
10072
|
+
const act = t.closest("[data-act]");
|
|
10073
|
+
if (act) return o.onAct?.(act.dataset.act ?? "");
|
|
10074
|
+
if (t.closest("[data-export]")) return download(`memory-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.json`, JSON.stringify(mem.export(), null, 2), "application/json");
|
|
10075
|
+
if (t.closest("[data-import]")) return file.click();
|
|
10076
|
+
if (t.closest("[data-wipe]")) {
|
|
10077
|
+
if (!wipe) return wipe = true, draw();
|
|
10078
|
+
wipe = false;
|
|
10079
|
+
mem.remove(all().map((x) => x.id)).then(changed);
|
|
10080
|
+
}
|
|
10081
|
+
});
|
|
10082
|
+
l.on(file, "change", () => {
|
|
10083
|
+
const f = file.files?.[0];
|
|
10084
|
+
file.value = "";
|
|
10085
|
+
if (!f) return;
|
|
10086
|
+
f.text().then((t) => mem.import(JSON.parse(t), { replace: false })).then(changed).catch((err) => {
|
|
10087
|
+
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>`);
|
|
10088
|
+
});
|
|
10089
|
+
});
|
|
10090
|
+
draw();
|
|
10091
|
+
return {
|
|
10092
|
+
refresh: () => void search(),
|
|
10093
|
+
used(labels) {
|
|
10094
|
+
used = new Set(labels);
|
|
10095
|
+
draw();
|
|
10096
|
+
},
|
|
10097
|
+
dispose: () => l.off()
|
|
10098
|
+
};
|
|
10099
|
+
}
|
|
10100
|
+
async function walk(e, out, path, depth = 0) {
|
|
10101
|
+
if (e.isFile && e.file) {
|
|
10102
|
+
const f = await new Promise((ok, bad) => e.file(ok, bad));
|
|
10103
|
+
out.push(path ? Object.assign(new File([f], f.name, { type: f.type }), { webkitRelativePath: `${path}/${f.name}` }) : f);
|
|
10104
|
+
} else if (e.isDirectory && e.createReader && depth < 8) {
|
|
10105
|
+
const r = e.createReader();
|
|
10106
|
+
for (;;) {
|
|
10107
|
+
const batch = await new Promise((ok, bad) => r.readEntries(ok, bad));
|
|
10108
|
+
if (!batch.length) break;
|
|
10109
|
+
for (const c of batch) await walk(c, out, path ? `${path}/${e.name}` : e.name, depth + 1);
|
|
10110
|
+
}
|
|
10111
|
+
}
|
|
10112
|
+
}
|
|
10113
|
+
/** 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. */
|
|
10114
|
+
function mountSourcesDrop(host, o) {
|
|
10115
|
+
const l = listeners();
|
|
10116
|
+
const pick = (dir) => {
|
|
10117
|
+
const i = document.createElement("input");
|
|
10118
|
+
i.type = "file";
|
|
10119
|
+
i.hidden = true;
|
|
10120
|
+
i.multiple = true;
|
|
10121
|
+
if (dir) i.setAttribute("webkitdirectory", "");
|
|
10122
|
+
else i.accept = o.accept ?? ".txt,.md,.csv,.json,.html,.htm,.pdf,.docx,.zip,.eml,text/*";
|
|
10123
|
+
return i;
|
|
10124
|
+
};
|
|
10125
|
+
const files = pick(false);
|
|
10126
|
+
const dir = pick(true);
|
|
10127
|
+
const zone = document.createElement("div");
|
|
10128
|
+
const log = document.createElement("ul");
|
|
10129
|
+
zone.className = "hb-dropzone";
|
|
10130
|
+
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>`;
|
|
10131
|
+
log.className = "hb-list";
|
|
10132
|
+
log.setAttribute("aria-live", "polite");
|
|
10133
|
+
host.replaceChildren(zone, log, files, dir);
|
|
10134
|
+
const line = (t, err = false) => log.insertAdjacentHTML("afterbegin", `<li${err ? ` class="hb-error"` : ""}>${esc(t)}</li>`);
|
|
10135
|
+
const run = (list) => {
|
|
10136
|
+
if (!list.length) return;
|
|
10137
|
+
zone.classList.add("is-busy");
|
|
10138
|
+
line(`reading ${list.length} file${list.length === 1 ? "" : "s"}`);
|
|
10139
|
+
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"));
|
|
10140
|
+
};
|
|
10141
|
+
l.on(zone, "click", (e) => {
|
|
10142
|
+
const t = e.target;
|
|
10143
|
+
if (t.closest("[data-files]")) files.click();
|
|
10144
|
+
else if (t.closest("[data-dir]")) dir.click();
|
|
10145
|
+
});
|
|
10146
|
+
for (const i of [files, dir]) l.on(i, "change", () => {
|
|
10147
|
+
run([...i.files ?? []]);
|
|
10148
|
+
i.value = "";
|
|
10149
|
+
});
|
|
10150
|
+
l.on(zone, "dragover", (e) => (e.preventDefault(), zone.classList.add("is-over")));
|
|
10151
|
+
l.on(zone, "dragleave", () => zone.classList.remove("is-over"));
|
|
10152
|
+
l.on(zone, "drop", (e) => {
|
|
10153
|
+
e.preventDefault();
|
|
10154
|
+
zone.classList.remove("is-over");
|
|
10155
|
+
const dt = e.dataTransfer;
|
|
10156
|
+
const entries = [...dt?.items ?? []].map((i) => i.webkitGetAsEntry?.()).filter((x) => x !== null && x !== void 0);
|
|
10157
|
+
if (!entries.length) return run([...dt?.files ?? []]);
|
|
10158
|
+
const out = [];
|
|
10159
|
+
Promise.all(entries.map((en) => walk(en, out, "").catch(() => void 0))).then(() => run(out));
|
|
10160
|
+
});
|
|
10161
|
+
return { dispose: () => l.off() };
|
|
10162
|
+
}
|
|
10163
|
+
/** The persona rack: presets one press away, name, the three parts with their cost, the template, save, and the persona as a file. */
|
|
10164
|
+
function mountPersonaRack(host, rack) {
|
|
10165
|
+
const l = listeners();
|
|
10166
|
+
const file = document.createElement("input");
|
|
10167
|
+
file.type = "file";
|
|
10168
|
+
file.accept = ".json,application/json";
|
|
10169
|
+
file.hidden = true;
|
|
10170
|
+
const box = document.createElement("div");
|
|
10171
|
+
host.replaceChildren(box, file);
|
|
10172
|
+
let err = "";
|
|
10173
|
+
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>`;
|
|
10174
|
+
const draw = () => {
|
|
10175
|
+
if (box.contains(document.activeElement) && document.activeElement.matches("[data-k]")) return;
|
|
10176
|
+
const { persona: p, presets, on, builtIn } = rack.snapshot();
|
|
10177
|
+
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>`;
|
|
10178
|
+
};
|
|
10179
|
+
l.on(box, "input", (e) => {
|
|
10180
|
+
const t = e.target;
|
|
10181
|
+
const k = t.dataset.k;
|
|
10182
|
+
if (k) {
|
|
10183
|
+
rack.set({ [k]: t.value });
|
|
10184
|
+
const foot = t.parentElement?.querySelector(".hb-hint");
|
|
10185
|
+
if (foot) foot.textContent = Ds(Ts(t.value));
|
|
10186
|
+
}
|
|
10187
|
+
});
|
|
10188
|
+
l.on(box, "focusout", () => setTimeout(draw, 0));
|
|
10189
|
+
l.on(box, "submit", (e) => {
|
|
10190
|
+
e.preventDefault();
|
|
10191
|
+
rack.save(box.querySelector("[data-label]")?.value ?? "");
|
|
10192
|
+
});
|
|
10193
|
+
l.on(box, "click", (e) => {
|
|
10194
|
+
const t = e.target;
|
|
10195
|
+
const ld = t.closest("[data-load]");
|
|
10196
|
+
if (ld) return rack.load(Number(ld.dataset.load));
|
|
10197
|
+
const rm = t.closest("[data-rm]");
|
|
10198
|
+
if (rm) return rack.removePreset(Number(rm.dataset.rm));
|
|
10199
|
+
if (t.closest("[data-tpl]")) {
|
|
10200
|
+
const p = rack.snapshot().persona;
|
|
10201
|
+
rack.set({ profile: qs(p.profile, br, p.name) });
|
|
10202
|
+
return draw();
|
|
10203
|
+
}
|
|
10204
|
+
if (t.closest("[data-export]")) {
|
|
10205
|
+
const p = rack.snapshot().persona;
|
|
10206
|
+
return download(`${(p.name || "persona").replace(/[^a-z0-9]+/gi, "-").toLowerCase()}.persona.json`, JSON.stringify({
|
|
10207
|
+
v: 1,
|
|
10208
|
+
name: p.name,
|
|
10209
|
+
prompt: p.profile,
|
|
10210
|
+
notes: p.notes,
|
|
10211
|
+
rules: p.rules,
|
|
10212
|
+
...p.first ? { first: p.first } : {}
|
|
10213
|
+
}, null, 2), "application/json");
|
|
10214
|
+
}
|
|
10215
|
+
if (t.closest("[data-import]")) file.click();
|
|
10216
|
+
});
|
|
10217
|
+
l.on(file, "change", () => {
|
|
10218
|
+
const f = file.files?.[0];
|
|
10219
|
+
file.value = "";
|
|
10220
|
+
if (!f) return;
|
|
10221
|
+
f.text().then((t) => {
|
|
10222
|
+
try {
|
|
10223
|
+
const j = JSON.parse(t);
|
|
10224
|
+
const profile = typeof j.prompt === "string" ? j.prompt : typeof j.system_prompt === "string" ? j.system_prompt : typeof j.description === "string" ? j.description : "";
|
|
10225
|
+
if (!profile && typeof j.name !== "string") throw new Error("no name or prompt in it");
|
|
10226
|
+
err = "";
|
|
10227
|
+
rack.set({
|
|
10228
|
+
name: String(j.name ?? "assistant"),
|
|
10229
|
+
profile,
|
|
10230
|
+
notes: String(j.notes ?? ""),
|
|
10231
|
+
rules: String(j.rules ?? ""),
|
|
10232
|
+
...typeof j.first === "string" ? { first: j.first } : {}
|
|
10233
|
+
});
|
|
10234
|
+
} catch (e2) {
|
|
10235
|
+
err = `that file is not a persona: ${e2 instanceof Error ? e2.message : String(e2)}`;
|
|
10236
|
+
}
|
|
10237
|
+
draw();
|
|
10238
|
+
});
|
|
10239
|
+
});
|
|
10240
|
+
l.add(rack.subscribe(draw));
|
|
10241
|
+
return { dispose: () => l.off() };
|
|
10242
|
+
}
|
|
10243
|
+
/** The voice row: auto speak, voice, rate, pitch, test and stop. */
|
|
10244
|
+
function mountVoiceRow(host, row, o = {}) {
|
|
10245
|
+
const l = listeners();
|
|
10246
|
+
const draw = () => {
|
|
10247
|
+
if (host.contains(document.activeElement) && document.activeElement.matches("input[type=range]")) return;
|
|
10248
|
+
const s = row.snapshot();
|
|
10249
|
+
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>`;
|
|
10250
|
+
};
|
|
10251
|
+
l.on(host, "input", (e) => {
|
|
10252
|
+
const t = e.target;
|
|
10253
|
+
if (t.matches("[data-rate]")) row.set({ rate: Number(t.value) });
|
|
10254
|
+
else if (t.matches("[data-pitch]")) row.set({ pitch: Number(t.value) });
|
|
10255
|
+
const r = t.parentElement?.querySelector(".hb-readout");
|
|
10256
|
+
if (r && t.type === "range") r.textContent = Number(t.value).toFixed(1);
|
|
10257
|
+
});
|
|
10258
|
+
l.on(host, "change", (e) => {
|
|
10259
|
+
const t = e.target;
|
|
10260
|
+
if (t.matches("[data-auto]")) row.set({ auto: t.checked });
|
|
10261
|
+
else if (t.matches("[data-voice]")) row.set({ voice: t.value });
|
|
10262
|
+
else if (t.type === "range") draw();
|
|
10263
|
+
});
|
|
10264
|
+
l.on(host, "click", (e) => {
|
|
10265
|
+
const t = e.target;
|
|
10266
|
+
if (t.closest("[data-test]")) row.speak(o.test ?? "this is how replies will sound.");
|
|
10267
|
+
else if (t.closest("[data-stop]")) row.stop();
|
|
10268
|
+
});
|
|
10269
|
+
l.add(row.subscribe(draw));
|
|
10270
|
+
return { dispose: () => (row.stop(), l.off()) };
|
|
10271
|
+
}
|
|
10272
|
+
/** The voice clone row of a speaker: clone from an audio file, record `seconds` of mic, download the clone as wav, clear it. */
|
|
10273
|
+
function mountVoiceClone(host, sp, o = {}) {
|
|
10274
|
+
const l = listeners();
|
|
10275
|
+
const secs = o.seconds ?? 10;
|
|
10276
|
+
const file = document.createElement("input");
|
|
10277
|
+
file.type = "file";
|
|
10278
|
+
file.accept = "audio/*";
|
|
10279
|
+
file.hidden = true;
|
|
10280
|
+
const box = document.createElement("div");
|
|
10281
|
+
host.replaceChildren(box, file);
|
|
10282
|
+
let note = "";
|
|
10283
|
+
let busy = false;
|
|
10284
|
+
const draw = () => {
|
|
10285
|
+
const can = o.can?.() ?? true;
|
|
10286
|
+
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>`;
|
|
10287
|
+
};
|
|
10288
|
+
const fail = (err) => {
|
|
10289
|
+
const name = err.name ?? "";
|
|
10290
|
+
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);
|
|
10291
|
+
};
|
|
10292
|
+
l.on(box, "click", (e) => {
|
|
10293
|
+
const t = e.target;
|
|
10294
|
+
if (t.closest("[data-file]")) return file.click();
|
|
10295
|
+
if (t.closest("[data-wav]")) {
|
|
10296
|
+
const w = sp.cloneWav();
|
|
10297
|
+
if (w) download("voice-clone.wav", w, "audio/wav");
|
|
10298
|
+
return;
|
|
10299
|
+
}
|
|
10300
|
+
if (t.closest("[data-clear]")) {
|
|
10301
|
+
sp.clearClone();
|
|
10302
|
+
note = "clone cleared. the voice is its own again.";
|
|
10303
|
+
return draw();
|
|
10304
|
+
}
|
|
10305
|
+
if (t.closest("[data-rec]") && !busy) {
|
|
10306
|
+
busy = true;
|
|
10307
|
+
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()));
|
|
10308
|
+
}
|
|
10309
|
+
});
|
|
10310
|
+
l.on(file, "change", () => {
|
|
10311
|
+
const f = file.files?.[0];
|
|
10312
|
+
file.value = "";
|
|
10313
|
+
if (!f) return;
|
|
10314
|
+
busy = true;
|
|
10315
|
+
note = "cloning...";
|
|
10316
|
+
draw();
|
|
10317
|
+
sp.cloneFile(f).then((s) => note = `cloned from ${s.toFixed(1)} s of ${f.name}.`, fail).finally(() => (busy = false, draw()));
|
|
10318
|
+
});
|
|
10319
|
+
l.add(sp.subscribe(draw));
|
|
10320
|
+
draw();
|
|
10321
|
+
return { dispose: () => l.off() };
|
|
10322
|
+
}
|
|
10323
|
+
/** The session menu of a chat list: clear the open chat, export it as markdown, every chat as json, and import. */
|
|
10324
|
+
function mountSessionMenu(host, list, o = {}) {
|
|
10325
|
+
const l = listeners();
|
|
10326
|
+
const file = document.createElement("input");
|
|
10327
|
+
file.type = "file";
|
|
10328
|
+
file.accept = ".json,application/json";
|
|
10329
|
+
file.hidden = true;
|
|
10330
|
+
const box = document.createElement("div");
|
|
10331
|
+
host.replaceChildren(box, file);
|
|
10332
|
+
let armed = false;
|
|
10333
|
+
let note = "";
|
|
10334
|
+
const draw = () => {
|
|
10335
|
+
const has = list.thread.snapshot().turns.length > 0;
|
|
10336
|
+
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>` : ""}`;
|
|
10337
|
+
};
|
|
10338
|
+
l.on(box, "click", (e) => {
|
|
10339
|
+
const t = e.target;
|
|
10340
|
+
const day = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
10341
|
+
if (t.closest("[data-md]")) return download(`chat-${day}.md`, list.thread.markdown(), "text/markdown");
|
|
10342
|
+
if (t.closest("[data-json]")) return download(`chats-${day}.json`, JSON.stringify(list.dump(), null, 2), "application/json");
|
|
10343
|
+
if (t.closest("[data-import]")) return file.click();
|
|
10344
|
+
if (t.closest("[data-clear]")) {
|
|
10345
|
+
if (!armed) return armed = true, draw();
|
|
10346
|
+
armed = false;
|
|
10347
|
+
list.thread.clear();
|
|
10348
|
+
}
|
|
10349
|
+
});
|
|
10350
|
+
l.on(file, "change", () => {
|
|
10351
|
+
const f = file.files?.[0];
|
|
10352
|
+
file.value = "";
|
|
10353
|
+
if (!f) return;
|
|
10354
|
+
f.text().then((t) => {
|
|
10355
|
+
try {
|
|
10356
|
+
const data = JSON.parse(t);
|
|
10357
|
+
list.restore(data);
|
|
10358
|
+
note = `${data.chats.length} chat${data.chats.length === 1 ? "" : "s"} imported.`;
|
|
10359
|
+
o.onImport?.(data.chats.length);
|
|
10360
|
+
} catch (err) {
|
|
10361
|
+
note = `that file did not import: ${err instanceof Error ? err.message : String(err)}`;
|
|
10362
|
+
}
|
|
10363
|
+
draw();
|
|
10364
|
+
});
|
|
10365
|
+
});
|
|
10366
|
+
l.add(list.subscribe(() => draw()));
|
|
10367
|
+
return { dispose: () => l.off() };
|
|
10368
|
+
}
|
|
9223
10369
|
// packages/ai-views/src/elements.ts
|
|
9224
10370
|
/** The tag names define() registers, before any prefix. */
|
|
9225
10371
|
const ELEMENT_NAMES = [
|
|
@@ -9596,25 +10742,36 @@ var HackbuildAiViewsElements = (function(exports) {
|
|
|
9596
10742
|
exports.ELEMENT_NAMES = ELEMENT_NAMES;
|
|
9597
10743
|
exports.chipWords = chipWords;
|
|
9598
10744
|
exports.define = define;
|
|
10745
|
+
exports.droppedFiles = droppedFiles;
|
|
9599
10746
|
exports.gateWords = gateWords;
|
|
10747
|
+
exports.isMedia = isMedia;
|
|
10748
|
+
exports.isProtected = isProtected;
|
|
9600
10749
|
exports.mountCameraFeed = mountCameraFeed;
|
|
9601
10750
|
exports.mountChatList = mountChatList;
|
|
9602
10751
|
exports.mountChatPane = mountChatPane;
|
|
9603
10752
|
exports.mountComposer = mountComposer;
|
|
9604
10753
|
exports.mountContextMeter = mountContextMeter;
|
|
10754
|
+
exports.mountExportMenu = mountExportMenu;
|
|
9605
10755
|
exports.mountFrameView = mountFrameView;
|
|
9606
10756
|
exports.mountMaskRack = mountMaskRack;
|
|
9607
10757
|
exports.mountMaskStudio = mountMaskStudio;
|
|
9608
10758
|
exports.mountMaskTools = mountMaskTools;
|
|
9609
10759
|
exports.mountMaskVerbs = mountMaskVerbs;
|
|
9610
10760
|
exports.mountMemoryInspector = mountMemoryInspector;
|
|
10761
|
+
exports.mountMemoryPane = mountMemoryPane;
|
|
9611
10762
|
exports.mountModelJobs = mountModelJobs;
|
|
9612
10763
|
exports.mountModelSelect = mountModelSelect;
|
|
10764
|
+
exports.mountPersonaRack = mountPersonaRack;
|
|
10765
|
+
exports.mountSessionMenu = mountSessionMenu;
|
|
10766
|
+
exports.mountSourcesDrop = mountSourcesDrop;
|
|
9613
10767
|
exports.mountTranscribeDrop = mountTranscribeDrop;
|
|
9614
10768
|
exports.mountTranscribeQueue = mountTranscribeQueue;
|
|
9615
10769
|
exports.mountTranscriptExports = mountTranscriptExports;
|
|
9616
10770
|
exports.mountTranscriptView = mountTranscriptView;
|
|
10771
|
+
exports.mountVoiceClone = mountVoiceClone;
|
|
10772
|
+
exports.mountVoiceRow = mountVoiceRow;
|
|
9617
10773
|
exports.pickSheet = pickSheet;
|
|
10774
|
+
exports.protect = protect;
|
|
9618
10775
|
exports.shortName = shortName;
|
|
9619
10776
|
exports.transcriptHtml = transcriptHtml;
|
|
9620
10777
|
exports.turnHtml = turnHtml;
|