@hackbuild/ai-views 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Moheeb Zara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # @hackbuild/ai-views
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Views that bind the browser AI packages to the hack.build design system
4
+ (hackbuild-ui): a model picker per job, a chat pane and composer, a drop
5
+ first transcriber, a mask studio, a frame view and a camera feed. Each
6
+ ships as a Vue component and as a custom element, so a plain HTML page
7
+ can use it. The views draw in light DOM with the page's hackbuild-ui
8
+ stylesheet and never style locally. Code MIT; this README CC-BY-4.0 with
9
+ the code samples also MIT. It replaces @hackbuild/ai-elements.
10
+
11
+ # not on npm yet: the @hackbuild scope is unpublished; build from this repository
12
+ npm install @hackbuild/ai-views
13
+
14
+ ## Use
15
+
16
+ import { define } from "@hackbuild/ai-views/elements";
17
+ define(); // define("hb") gives <hb-model-select> and so on
18
+
19
+ <model-select job="chat" variant="chip"></model-select>
20
+ <chat-pane id="chat"></chat-pane>
21
+ <chat-composer for="chat"></chat-composer>
22
+
23
+ document.querySelector("chat-pane").engine = engine; // a @hackbuild/chat engine
24
+
25
+ In Vue:
26
+
27
+ import { ModelSelect, ChatPane, Composer } from "@hackbuild/ai-views/vue";
28
+ import { chatThread } from "@hackbuild/ai-views";
29
+ const thread = chatThread({ engine });
30
+ // <ModelSelect job="chat" variant="chip" /> <ChatPane :thread="thread" /> <Composer :thread="thread" />
31
+
32
+ ## Entries
33
+
34
+ - `@hackbuild/ai-views`: node safe. `JOBS`, `jobRecords(job)`, `rowOf`
35
+ (a record as a hackbuild-ui ModelRow), `useModelPick(job)`,
36
+ `useJobsPick(jobs, presets)`, `weightsLoader(store)`,
37
+ `weightsRemover(store)`, `defaultPick`, `chatThread`, `chatList`,
38
+ `contextSegments`, `transcribeQueue`, the frame geometry and `traceRows`.
39
+ A pick loads only through its loader (none is an error the row shows),
40
+ runs it for every row, a no download row included, and keeps its result
41
+ on `snapshot().loaded`; `remove()` deletes through `onRemove`. It starts
42
+ on the first "start here" record that fits, else the first fast or
43
+ steady one.
44
+ - `@hackbuild/ai-views/elements`: the mount functions and `define()`.
45
+ - `@hackbuild/ai-views/vue`: `ModelSelect`, `ModelJobs`, `ChatPane`,
46
+ `Composer`, `ChatList`, `ContextMeter`, `MemoryInspector`,
47
+ `TranscribeDrop`, `TranscriptView`, `TranscribeQueue`, `MaskStudio`,
48
+ `MaskTools`, `MaskVerbs`, `MaskRack`, `FrameView`, `CameraFeed`. Vue is
49
+ an optional peer. `loaded` and `failed` fire once per load.
50
+
51
+ ## Views
52
+
53
+ | view | element | after | what it does |
54
+ |---|---|---|---|
55
+ | ModelSelect | `<model-select job variant go>` | ferrule, arbor, hackle | one line with the choice and one pink "load, size"; the bar chip; a sheet with search, the fits, uncensored and no download filters, groups, the row detail and the "your own" forms. `<model-jobs jobs>` (properties `env`, `loader`, `records`, `presets`) gives a line per job, presets with totals and "load all" |
56
+ | ChatPane, Composer | `<chat-pane>`, `<chat-composer for>`, `<chat-list for>`, `<chat-context for budget>` | clevis, chatbot-forge | the thread, reasoning in a fold, memory used per reply, copy and redo on the last reply; the chats list (new, open, rename, delete) and the context meter; Enter sends, Escape stops |
57
+ | TranscribeDrop, TranscriptView | `<transcribe-drop>`, `<transcript-view for>`, `<transcribe-queue for>`, `<transcript-exports for>` | scribe | the drop zone becomes the transcript; a queue of files; lines with their time, edit in place with undo; txt, srt, vtt, json |
58
+ | MaskStudio | `<mask-studio>`, `<mask-tools for>`, `<mask-verbs for>`, `<mask-rack for part>` | an earlier mask studio and a fastsam selector | click segment, wand, brush, eraser, lasso, polygon, rectangle, ellipse, flood, pan (the hackbuild-ui mask editor's tools), segment everything, smooth, expand, shrink, saved masks, undo, zoom; `mask()` gives ImageData and `exportAs()` a png Blob |
59
+ | FrameView, CameraFeed | `<frame-view>`, `<camera-feed for>` | the eyes of an earlier room | boxes with word and score, landmarks, a count and the caption over a frame; the camera at a set rate |
60
+ | memory inspector | `<memory-inspector>` | ai-elements | one row per fused recall candidate, the used ones marked |
61
+
62
+ Jobs and their records: chat (40 records, computed), speech to text (6),
63
+ vision language (SmolVLM 256M and 500M, SmolVLM2 256M video, LFM2-VL
64
+ 450M, Gemma 4 E2B), detector (EfficientDet lite0, YOLOv10 n, s and m),
65
+ masks (SlimSAM, FastSAM-s), image (SD-Turbo, SD 1.5, and SDXL-Turbo greyed as not run yet), voice
66
+ (Kokoro, Pocket TTS, the vocal tract, the system voice), depth, embed,
67
+ landmarks and face swap (scrfd, ArcFace, inswapper). Every record carries
68
+ its weight licence; the non commercial ones are marked in the picker.
69
+
70
+ ## What is verified, and what is not
71
+
72
+ - Verified (2026-11-25, `npx vitest run packages/ai-views`): every job
73
+ has the records above with a speed word and a verdict; rows carry size,
74
+ memory, backend, marks, detail and options, and a row that does not fit
75
+ names why; a pick loads with progress, cancels and keeps a failure's
76
+ words; presets total their download; the chat thread streams with the
77
+ reasoning apart and memory used; the queue runs, edits with undo and
78
+ exports; the frame mapping crops and mirrors; define registers every
79
+ element.
80
+ - Verified headless (2026-11-25, `node tools/smoke-views.mjs`): one smoke
81
+ per demo page on stub providers with no weights.
82
+ - Not verified: a real model through any view in this package (the
83
+ demos use stubs); touch drawing on a phone; screen readers.
84
+
85
+ ## Size budget
86
+
87
+ | file | gzip (measured) | ceiling |
88
+ |---|---|---|
89
+ | `dist/index.js` (main entry, imports external) | 12,015 bytes | 12,615 bytes |
90
+ | `dist/single/elements.iife.js` (single file build) | 85,735 bytes | 90,021 bytes |
91
+
92
+ Measured 2026-11-25 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
93
+ tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
94
+ 5 percent from its row.
package/dist/chat.d.ts ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * The state behind ChatPane and Composer, after the earlier chat tools: a
3
+ * thread of turns, one live reply streamed from a @hackbuild/chat engine
4
+ * with its reasoning kept apart for the think fold, the memory each reply
5
+ * used, stop, regenerate, and a markdown export. Framework free.
6
+ */
7
+ import type { ChatEngine } from "@hackbuild/chat";
8
+ export interface MemoryUsed {
9
+ label: string;
10
+ /** 0 to 1, shown beside the label. */
11
+ score?: number;
12
+ }
13
+ export interface Turn {
14
+ id: number;
15
+ role: "user" | "assistant";
16
+ text: string;
17
+ /** Reasoning, shown in a fold under the reply. */
18
+ think: string;
19
+ at: number;
20
+ done: boolean;
21
+ /** Memory recalled for this reply. */
22
+ mem?: MemoryUsed[];
23
+ /** "31.2 tok/s, first word 0.64 s, 44 tok (measured)". */
24
+ stats?: string;
25
+ /** "stopped", "failed: ...". */
26
+ note?: string;
27
+ }
28
+ export interface ThreadSnapshot {
29
+ turns: readonly Turn[];
30
+ busy: boolean;
31
+ /** An engine is set; without one a reply says how to get one. */
32
+ ready: boolean;
33
+ }
34
+ export interface ThreadOptions {
35
+ engine?: ChatEngine | null;
36
+ system?: string;
37
+ /** Memory for a message; its hits ride along in the system prompt and show under the reply. */
38
+ recall?: (query: string) => Promise<MemoryUsed[]>;
39
+ /** What a reply says with no engine. */
40
+ noEngine?: string;
41
+ now?: () => number;
42
+ /** Reply token cap. */
43
+ maxTokens?: number;
44
+ }
45
+ export interface ChatThread {
46
+ snapshot(): ThreadSnapshot;
47
+ subscribe(fn: (s: ThreadSnapshot) => void): () => void;
48
+ send(text: string): Promise<void>;
49
+ stop(): void;
50
+ /** Drop the last reply and ask again. */
51
+ regenerate(): Promise<void>;
52
+ remove(id: number): void;
53
+ clear(): void;
54
+ setEngine(engine: ChatEngine | null): void;
55
+ /** The thread as markdown, for an export. */
56
+ markdown(title?: string): string;
57
+ }
58
+ export declare const NO_ENGINE = "this needs a model. pick one in the bar and load it.";
59
+ export declare function chatThread(o?: ThreadOptions): ChatThread;
60
+ export interface ChatListItem {
61
+ id: string;
62
+ title: string;
63
+ updated: number;
64
+ count: number;
65
+ }
66
+ export interface ChatListSnapshot {
67
+ items: readonly ChatListItem[];
68
+ current: string;
69
+ }
70
+ /**
71
+ * Several chats, as clevis keeps them: a list with the newest first, one
72
+ * open. `thread` always speaks for the open chat, so a pane and a composer
73
+ * bound to it follow a switch.
74
+ */
75
+ export interface ChatList {
76
+ readonly thread: ChatThread;
77
+ snapshot(): ChatListSnapshot;
78
+ subscribe(fn: (s: ChatListSnapshot) => void): () => void;
79
+ create(): string;
80
+ open(id: string): void;
81
+ rename(id: string, title: string): void;
82
+ remove(id: string): void;
83
+ setEngine(engine: ChatEngine | null): void;
84
+ }
85
+ export declare function chatList(o?: ThreadOptions): ChatList;
86
+ /** Tokens the next request carries, by source, for a context meter: about 4 characters a token (inferred). */
87
+ export declare function contextSegments(s: ThreadSnapshot, system?: string): {
88
+ key: string;
89
+ label: string;
90
+ tokens: number;
91
+ }[];
package/dist/chat.js ADDED
@@ -0,0 +1,237 @@
1
+ /**
2
+ * The state behind ChatPane and Composer, after the earlier chat tools: a
3
+ * thread of turns, one live reply streamed from a @hackbuild/chat engine
4
+ * with its reasoning kept apart for the think fold, the memory each reply
5
+ * used, stop, regenerate, and a markdown export. Framework free.
6
+ */
7
+ import { statsText } from "@virgilvox/hackbuild-ui/vanilla";
8
+ export const NO_ENGINE = "this needs a model. pick one in the bar and load it.";
9
+ export function chatThread(o = {}) {
10
+ let engine = o.engine ?? null;
11
+ const now = o.now ?? (() => Date.now());
12
+ let turns = [];
13
+ let busy = false;
14
+ let ac = null;
15
+ let seq = 0;
16
+ const subs = new Set();
17
+ const snap = () => ({ turns, busy, ready: !!engine });
18
+ const emit = () => {
19
+ const s = snap();
20
+ for (const fn of subs)
21
+ fn(s);
22
+ };
23
+ const patch = (id, p) => {
24
+ turns = turns.map((t) => (t.id === id ? { ...t, ...p } : t));
25
+ emit();
26
+ };
27
+ async function reply() {
28
+ const lastUser = [...turns].reverse().find((t) => t.role === "user");
29
+ const live = { id: ++seq, role: "assistant", text: "", think: "", at: now(), done: false };
30
+ turns = [...turns, live];
31
+ busy = true;
32
+ emit();
33
+ if (!engine) {
34
+ patch(live.id, { text: o.noEngine ?? NO_ENGINE, done: true });
35
+ busy = false;
36
+ emit();
37
+ return;
38
+ }
39
+ ac = new AbortController();
40
+ const signal = ac.signal;
41
+ let mem = [];
42
+ try {
43
+ if (o.recall && lastUser)
44
+ mem = await o.recall(lastUser.text);
45
+ if (mem.length)
46
+ patch(live.id, { mem });
47
+ const sys = [o.system, mem.length ? `things you remember:\n${mem.map((m) => `- ${m.label}`).join("\n")}` : ""].filter(Boolean).join("\n\n");
48
+ const history = [
49
+ ...(sys ? [{ role: "system", content: sys }] : []),
50
+ ...turns.filter((t) => t.id !== live.id && t.text).map((t) => ({ role: t.role, content: t.text })),
51
+ ];
52
+ let text = "";
53
+ let think = "";
54
+ const it = engine.stream(history, { signal, ...(o.maxTokens ? { maxTokens: o.maxTokens } : {}) });
55
+ for (;;) {
56
+ const step = await it.next();
57
+ if (step.done) {
58
+ const s = step.value?.stats;
59
+ const stats = s ? statsText({ tokPerSec: s.tokensPerSecond, firstMs: s.firstTokenMs, tokens: s.tokens, source: s.tokensSource }) : "";
60
+ patch(live.id, { done: true, ...(stats ? { stats } : {}) });
61
+ break;
62
+ }
63
+ const ev = step.value;
64
+ if (ev.type === "text")
65
+ text += ev.text;
66
+ else if (ev.type === "think")
67
+ think += ev.text;
68
+ else
69
+ continue;
70
+ patch(live.id, { text, think });
71
+ }
72
+ }
73
+ catch (e) {
74
+ const stopped = signal.aborted;
75
+ patch(live.id, { done: true, note: stopped ? "stopped" : `failed: ${e instanceof Error ? e.message : String(e)}` });
76
+ }
77
+ finally {
78
+ busy = false;
79
+ ac = null;
80
+ emit();
81
+ }
82
+ }
83
+ return {
84
+ snapshot: snap,
85
+ subscribe(fn) {
86
+ subs.add(fn);
87
+ fn(snap());
88
+ return () => subs.delete(fn);
89
+ },
90
+ async send(text) {
91
+ const t = text.trim();
92
+ if (!t || busy)
93
+ return;
94
+ turns = [...turns, { id: ++seq, role: "user", text: t, think: "", at: now(), done: true }];
95
+ await reply();
96
+ },
97
+ stop() {
98
+ ac?.abort();
99
+ },
100
+ async regenerate() {
101
+ if (busy)
102
+ return;
103
+ const last = turns[turns.length - 1];
104
+ if (last?.role === "assistant")
105
+ turns = turns.slice(0, -1);
106
+ if (turns[turns.length - 1]?.role !== "user")
107
+ return emit();
108
+ await reply();
109
+ },
110
+ remove(id) {
111
+ turns = turns.filter((t) => t.id !== id);
112
+ emit();
113
+ },
114
+ clear() {
115
+ ac?.abort();
116
+ turns = [];
117
+ emit();
118
+ },
119
+ setEngine(e) {
120
+ engine = e;
121
+ emit();
122
+ },
123
+ markdown(title = "chat") {
124
+ const lines = [`# ${title}`, ""];
125
+ for (const t of turns)
126
+ lines.push(`## ${t.role === "user" ? "you" : "reply"}`, "", t.text, "");
127
+ return lines.join("\n");
128
+ },
129
+ };
130
+ }
131
+ export function chatList(o = {}) {
132
+ const now = o.now ?? (() => Date.now());
133
+ let engine = o.engine ?? null;
134
+ let seq = 0;
135
+ const chats = new Map();
136
+ let current = "";
137
+ const subs = new Set();
138
+ const threadSubs = new Set();
139
+ let offCurrent = null;
140
+ const snap = () => ({
141
+ items: [...chats].map(([id, c]) => ({ id, title: c.title, updated: c.updated, count: c.t.snapshot().turns.length })).sort((a, b) => b.updated - a.updated),
142
+ current,
143
+ });
144
+ const emit = () => {
145
+ const s = snap();
146
+ for (const fn of subs)
147
+ fn(s);
148
+ };
149
+ const follow = () => {
150
+ offCurrent?.();
151
+ const c = chats.get(current);
152
+ offCurrent = c.t.subscribe((s) => {
153
+ const first = s.turns.find((t) => t.role === "user");
154
+ if (first && !c.named)
155
+ c.title = first.text.length > 40 ? `${first.text.slice(0, 37)}...` : first.text;
156
+ if (s.turns.length)
157
+ c.updated = now();
158
+ for (const fn of threadSubs)
159
+ fn(s);
160
+ emit();
161
+ });
162
+ };
163
+ const list = {
164
+ thread: {
165
+ snapshot: () => chats.get(current).t.snapshot(),
166
+ subscribe(fn) {
167
+ threadSubs.add(fn);
168
+ fn(chats.get(current).t.snapshot());
169
+ return () => threadSubs.delete(fn);
170
+ },
171
+ send: (text) => chats.get(current).t.send(text),
172
+ stop: () => chats.get(current).t.stop(),
173
+ regenerate: () => chats.get(current).t.regenerate(),
174
+ remove: (id) => chats.get(current).t.remove(id),
175
+ clear: () => chats.get(current).t.clear(),
176
+ setEngine: (e) => list.setEngine(e),
177
+ markdown: (title) => chats.get(current).t.markdown(title ?? chats.get(current).title),
178
+ },
179
+ snapshot: snap,
180
+ subscribe(fn) {
181
+ subs.add(fn);
182
+ fn(snap());
183
+ return () => subs.delete(fn);
184
+ },
185
+ create() {
186
+ const id = `chat-${++seq}`;
187
+ chats.set(id, { t: chatThread({ ...o, engine }), title: "new chat", updated: now(), named: false });
188
+ current = id;
189
+ follow();
190
+ return id;
191
+ },
192
+ open(id) {
193
+ if (!chats.has(id) || id === current)
194
+ return;
195
+ chats.get(current)?.t.stop();
196
+ current = id;
197
+ follow();
198
+ },
199
+ rename(id, title) {
200
+ const c = chats.get(id);
201
+ if (!c || !title.trim())
202
+ return;
203
+ c.title = title.trim();
204
+ c.named = true;
205
+ emit();
206
+ },
207
+ remove(id) {
208
+ chats.get(id)?.t.stop();
209
+ chats.delete(id);
210
+ if (!chats.size)
211
+ return void list.create();
212
+ if (id === current) {
213
+ current = snap().items[0].id;
214
+ follow();
215
+ }
216
+ else
217
+ emit();
218
+ },
219
+ setEngine(e) {
220
+ engine = e;
221
+ for (const c of chats.values())
222
+ c.t.setEngine(e);
223
+ },
224
+ };
225
+ list.create();
226
+ return list;
227
+ }
228
+ /** Tokens the next request carries, by source, for a context meter: about 4 characters a token (inferred). */
229
+ export function contextSegments(s, system = "") {
230
+ const tok = (t) => Math.ceil(t.length / 4);
231
+ const mem = s.turns.flatMap((t) => t.mem ?? []).reduce((n, m) => n + tok(m.label), 0);
232
+ return [
233
+ { key: "system", label: "persona", tokens: tok(system) },
234
+ { key: "memory", label: "memory", tokens: mem },
235
+ { key: "chat", label: "chat", tokens: s.turns.reduce((n, t) => n + tok(t.text), 0) },
236
+ ];
237
+ }
package/dist/dom.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /** Small DOM helpers shared by the mount functions. Light DOM only: the page's hackbuild-ui stylesheet draws everything. */
2
+ export declare function esc(s: string): string;
3
+ /** Shows or hides a part; inside a layout hackbuild-ui's `.hb-lay [hidden]` makes it hold on parts that set display. */
4
+ export declare function show(el: HTMLElement, on: boolean): void;
5
+ /** One handle per mount: redraw with new data, then tear down. */
6
+ export interface Mounted {
7
+ dispose(): void;
8
+ }
9
+ /** Listeners that come off together. */
10
+ export declare function listeners(): {
11
+ on<K extends keyof HTMLElementEventMap>(el: EventTarget, type: K | string, fn: (e: HTMLElementEventMap[K]) => void): void;
12
+ add(off: () => void): void;
13
+ off(): void;
14
+ };
15
+ /** The nearest ancestor that scrolls, else the element. */
16
+ export declare function scroller(el: HTMLElement): HTMLElement;
17
+ /** Saves text as a file through a link press. */
18
+ export declare function download(name: string, text: string | Blob, type?: string): void;
19
+ export declare const ICON: {
20
+ readonly undo: string;
21
+ readonly redo: string;
22
+ readonly zoomIn: string;
23
+ readonly zoomOut: string;
24
+ readonly fit: string;
25
+ readonly x: string;
26
+ readonly copy: string;
27
+ readonly redoMsg: string;
28
+ readonly point: string;
29
+ readonly wand: string;
30
+ readonly brush: string;
31
+ readonly lasso: string;
32
+ readonly all: string;
33
+ readonly camera: string;
34
+ readonly menu: string;
35
+ readonly plus: string;
36
+ readonly pen: string;
37
+ readonly trash: string;
38
+ };
package/dist/dom.js ADDED
@@ -0,0 +1,67 @@
1
+ /** Small DOM helpers shared by the mount functions. Light DOM only: the page's hackbuild-ui stylesheet draws everything. */
2
+ export function esc(s) {
3
+ return s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
4
+ }
5
+ /** Shows or hides a part; inside a layout hackbuild-ui's `.hb-lay [hidden]` makes it hold on parts that set display. */
6
+ export function show(el, on) {
7
+ el.hidden = !on;
8
+ }
9
+ /** Listeners that come off together. */
10
+ export function listeners() {
11
+ const offs = [];
12
+ return {
13
+ on(el, type, fn) {
14
+ el.addEventListener(type, fn);
15
+ offs.push(() => el.removeEventListener(type, fn));
16
+ },
17
+ add(off) {
18
+ offs.push(off);
19
+ },
20
+ off() {
21
+ for (const f of offs.splice(0))
22
+ f();
23
+ },
24
+ };
25
+ }
26
+ /** The nearest ancestor that scrolls, else the element. */
27
+ export function scroller(el) {
28
+ for (let p = el; p; p = p.parentElement) {
29
+ const o = getComputedStyle(p).overflowY;
30
+ if ((o === "auto" || o === "scroll") && p.scrollHeight > p.clientHeight)
31
+ return p;
32
+ }
33
+ return el.closest(".hb-lay-subject") ?? el;
34
+ }
35
+ /** Saves text as a file through a link press. */
36
+ export function download(name, text, type = "text/plain") {
37
+ const blob = typeof text === "string" ? new Blob([text], { type }) : text;
38
+ const a = document.createElement("a");
39
+ a.href = URL.createObjectURL(blob);
40
+ a.download = name;
41
+ document.body.append(a);
42
+ a.click();
43
+ a.remove();
44
+ setTimeout(() => URL.revokeObjectURL(a.href), 4000);
45
+ }
46
+ /** Inline SVG icons, stroked in currentColor, 16 px. */
47
+ const svg = (d, size = 16) => `<svg class="hb-icon is-stroke" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" aria-hidden="true">${d}</svg>`;
48
+ export const ICON = {
49
+ undo: svg('<path d="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 0 12h-3"/>'),
50
+ redo: svg('<path d="m15 14 5-5-5-5"/><path d="M20 9H10a6 6 0 0 0 0 12h3"/>'),
51
+ zoomIn: svg('<circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3M11 8v6M8 11h6"/>'),
52
+ zoomOut: svg('<circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3M8 11h6"/>'),
53
+ fit: svg('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),
54
+ x: svg('<path d="M6 6l12 12M18 6 6 18"/>', 13),
55
+ copy: svg('<rect x="9" y="9" width="11" height="11"/><path d="M5 15V4h11"/>', 14),
56
+ redoMsg: svg('<path d="M21 12a9 9 0 1 1-3-6.7L21 8"/><path d="M21 3v5h-5"/>', 14),
57
+ point: svg('<circle cx="12" cy="12" r="3"/><path d="M12 2v5M12 17v5M2 12h5M17 12h5"/>', 18),
58
+ wand: svg('<path d="m3 21 12-12M15 3v3M18 6h3M19 2l-1 1M14 9l1 1"/>', 18),
59
+ brush: svg('<path d="M18 3 9 12l3 3 9-9z"/><path d="M9 12c-3 0-5 2-5 5 0 2-1 3-2 4 4 0 8-1 9-4"/>', 18),
60
+ lasso: svg('<ellipse cx="12" cy="9" rx="8" ry="5"/><path d="M7 13c-1 2 0 4 2 4s2 3 0 5"/>', 18),
61
+ all: svg('<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/>', 18),
62
+ camera: svg('<path d="M3 7h4l2-3h6l2 3h4v13H3z"/><circle cx="12" cy="13" r="4"/>'),
63
+ menu: svg('<path d="M4 6h16M4 12h16M4 18h16"/>'),
64
+ plus: svg('<path d="M12 5v14M5 12h14"/>', 14),
65
+ pen: svg('<path d="M4 20h4L19 9l-4-4L4 16z"/>', 13),
66
+ trash: svg('<path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13"/>', 13),
67
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @hackbuild/ai-views/elements: the views as custom elements for a plain
3
+ * HTML page, and the mount functions they sit on. Light DOM, drawn with
4
+ * the page's hackbuild-ui stylesheet; each element carries `.hb-view`
5
+ * (display contents), so a layout region of hackbuild-ui places its parts. Nothing
6
+ * registers on import: the page calls define().
7
+ *
8
+ * <model-select job="chat" variant="chip"></model-select>
9
+ * <chat-pane id="chat"></chat-pane> <chat-composer for="chat"></chat-composer>
10
+ * <transcribe-drop id="t"></transcribe-drop> <transcript-exports for="t"></transcript-exports>
11
+ * <mask-studio id="m"></mask-studio> <mask-tools for="m"></mask-tools>
12
+ * <frame-view id="f"></frame-view> <camera-feed for="f"></camera-feed>
13
+ */
14
+ import type { Env } from "@hackbuild/ai-env";
15
+ import type { ModelRecord } from "@hackbuild/models";
16
+ import { type Loader, type ModelPick } from "./pick.js";
17
+ export { mountModelSelect, mountModelJobs, pickSheet, gateWords, type ModelSelectOptions } from "./mount-model.js";
18
+ export { mountChatPane, mountComposer, mountChatList, mountContextMeter, turnHtml, type ChatPaneOptions, type ComposerOptions } from "./mount-chat.js";
19
+ export { mountTranscribeDrop, mountTranscriptView, mountTranscribeQueue, mountTranscriptExports, transcriptHtml, type TranscribeDropOptions, type TranscribeDropHandle, type TranscriptViewOptions } from "./mount-transcribe.js";
20
+ export { mountMaskStudio, mountMaskTools, mountMaskVerbs, mountMaskRack, type MaskStudio, type MaskModels, type MaskStudioOptions, type FoundMask, type StudioState, type StudioTool } from "./mount-mask.js";
21
+ export { mountFrameView, mountCameraFeed, type FrameView, type FrameViewOptions, type CameraFeed, type CameraFeedOptions } from "./mount-frame.js";
22
+ export { mountMemoryInspector, type MemoryInspector } from "./memory.js";
23
+ type Base = new () => HTMLElement;
24
+ /** The tag names define() registers, before any prefix. */
25
+ export declare const ELEMENT_NAMES: readonly ["model-select", "model-jobs", "chat-pane", "chat-composer", "chat-list", "chat-context", "transcribe-drop", "transcript-view", "transcribe-queue", "transcript-exports", "mask-studio", "mask-tools", "mask-verbs", "mask-rack", "frame-view", "camera-feed", "memory-inspector"];
26
+ export type ElementName = (typeof ELEMENT_NAMES)[number];
27
+ export interface ModelSelectElement extends HTMLElement {
28
+ pick: ModelPick;
29
+ env: Env | undefined;
30
+ loader: Loader | undefined;
31
+ records: readonly ModelRecord[] | undefined;
32
+ }
33
+ export interface DefineTarget {
34
+ get(name: string): unknown;
35
+ define(name: string, ctor: CustomElementConstructor): void;
36
+ }
37
+ /**
38
+ * Register the elements, bare (`<model-select>`) or under a prefix
39
+ * (`define("hb")` gives `<hb-model-select>`). Names already defined are
40
+ * left alone. Returns the tag names.
41
+ */
42
+ export declare function define(prefix?: string, registry?: DefineTarget, Base?: Base): string[];