@hackbuild/agents-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.
@@ -0,0 +1,107 @@
1
+ // AssociationsTable: what the creature has learned, cues by acts. Ported
2
+ // from hackle's train tab: the heat table always open, the attention column,
3
+ // the explanation under it and reset learning.
4
+ import { clamp01, el, panel, stack } from "./dom.js";
5
+ /** Builds the table from a CueLearner: net strength is excitation minus inhibition. */
6
+ export function associationsState(learner, o = {}) {
7
+ const actions = [...learner.actions];
8
+ const cues = Object.entries(learner.toJSON().cues).map(([cue, r]) => ({
9
+ cue,
10
+ values: actions.map((a) => clamp01((r.w[a] ?? 0) - (r.n[a] ?? 0))),
11
+ attention: clamp01(r.associability),
12
+ }));
13
+ const s = { actions, cues };
14
+ if (o.last)
15
+ s.last = o.last;
16
+ if (o.trial)
17
+ s.trial = o.trial;
18
+ return s;
19
+ }
20
+ export const ASSOCIATIONS_NOTE = "rows are cues, columns are acts. cells show net strength, excitation minus a separate inhibition that fades faster, so an extinguished cue partly comes back after a break. the attn column is each cue's associability: it rises after surprises and falls as the outcome becomes predictable. credit fades with delay, so a slow treat can reward whatever it is doing when it lands. if nothing is strong it offers tricks it was rewarded for before; teach a new word by praising whatever it does.";
21
+ /** hackle's cell: .hb-heat.is-pink fills by --v, the figure paper past 0.55. */
22
+ function paint(td, v) {
23
+ const t = clamp01(v);
24
+ td.style.setProperty("--v", t.toFixed(2));
25
+ td.classList.toggle("is-hi", t > 0.55);
26
+ td.textContent = String(Math.round(t * 99));
27
+ }
28
+ /** Renders the associations panel into `host`. */
29
+ export function associationsTable(host, o = {}) {
30
+ const doc = host.ownerDocument;
31
+ const col = stack(host);
32
+ const p = panel(doc, "associations", "rw + pearce kaye hall");
33
+ const scroll = el(doc, "div", "hb-scroll-x");
34
+ const table = el(doc, "table", "hb-heat is-pink");
35
+ const cap = el(doc, "caption", "hb-hint", "link strength 0 to 99, cue by act");
36
+ const thead = el(doc, "thead");
37
+ const tbody = el(doc, "tbody");
38
+ table.append(cap, thead, tbody);
39
+ scroll.append(table);
40
+ const trial = el(doc, "p", "hb-hint");
41
+ const note = el(doc, "p", "hb-note", o.note ?? ASSOCIATIONS_NOTE);
42
+ const reset = el(doc, "button", "hb-btn", "reset learning");
43
+ reset.type = "button";
44
+ reset.addEventListener("click", () => o.onReset?.());
45
+ p.root.append(scroll, trial, note, reset);
46
+ col.append(p.root);
47
+ host.replaceChildren(col);
48
+ let head = "";
49
+ return {
50
+ root: host,
51
+ update(s) {
52
+ const key = s.actions.join("\n");
53
+ if (key !== head) {
54
+ head = key;
55
+ const tr = el(doc, "tr");
56
+ const corner = el(doc, "th", "", "cue");
57
+ corner.scope = "col";
58
+ tr.append(corner);
59
+ for (const a of s.actions) {
60
+ const th = el(doc, "th", "", a.slice(0, 4));
61
+ th.scope = "col";
62
+ th.title = a;
63
+ tr.append(th);
64
+ }
65
+ const at = el(doc, "th", "", "attn");
66
+ at.scope = "col";
67
+ at.title = "how much it still pays attention to the cue";
68
+ tr.append(at);
69
+ thead.replaceChildren(tr);
70
+ }
71
+ const shown = s.cues.slice(-(o.limit ?? 16));
72
+ if (!shown.length) {
73
+ const tr = el(doc, "tr");
74
+ const td = el(doc, "td", "hb-hint", "no cues yet. say a word, then praise whatever it does.");
75
+ td.colSpan = s.actions.length + 2;
76
+ tr.append(td);
77
+ tbody.replaceChildren(tr);
78
+ }
79
+ else {
80
+ tbody.replaceChildren(...shown.map((r) => {
81
+ const tr = el(doc, "tr");
82
+ const th = el(doc, "th", "", r.cue.replace("gesture:", "g:"));
83
+ th.scope = "row";
84
+ th.title = r.cue;
85
+ tr.append(th);
86
+ s.actions.forEach((a, i) => {
87
+ const td = el(doc, "td");
88
+ paint(td, r.values[i] ?? 0);
89
+ // the last rewarded cell; hackbuild-ui has no outline mark for it yet
90
+ if (s.last && s.last.cue === r.cue && s.last.action === a)
91
+ td.setAttribute("aria-current", "true");
92
+ tr.append(td);
93
+ });
94
+ const td = el(doc, "td");
95
+ paint(td, r.attention);
96
+ tr.append(td);
97
+ return tr;
98
+ }));
99
+ }
100
+ trial.textContent = s.trial ?? "";
101
+ trial.hidden = !s.trial;
102
+ },
103
+ dispose() {
104
+ host.replaceChildren();
105
+ },
106
+ };
107
+ }
package/dist/dom.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare function el<K extends keyof HTMLElementTagNameMap>(doc: Document, tag: K, cls?: string, text?: string): HTMLElementTagNameMap[K];
2
+ /** An instrument panel: an ink head with a quieter value at its right. */
3
+ export declare function panel(doc: Document, title: string, aux?: string): {
4
+ root: HTMLElement;
5
+ aux: HTMLElement;
6
+ };
7
+ export declare const clamp01: (v: number) => number;
8
+ export declare const f2: (v: number) => string;
9
+ /** The panels of a view, stacked as hackle's blocks (.hb-rack-stack). The column is a
10
+ * child, so the host keeps its own display and a hidden rack pane stays hidden. */
11
+ export declare function stack(host: HTMLElement): HTMLElement;
package/dist/dom.js ADDED
@@ -0,0 +1,26 @@
1
+ // A small element maker for the views. The look is the hackbuild-ui class
2
+ // layer; the views write classes and data, never colours or faces of their own.
3
+ export function el(doc, tag, cls = "", text) {
4
+ const e = doc.createElement(tag);
5
+ if (cls)
6
+ e.className = cls;
7
+ if (text !== undefined)
8
+ e.textContent = text;
9
+ return e;
10
+ }
11
+ /** An instrument panel: an ink head with a quieter value at its right. */
12
+ export function panel(doc, title, aux = "") {
13
+ const root = el(doc, "section", "hb-panel");
14
+ const hd = el(doc, "h3", "hb-panel-hd-inst");
15
+ const aside = el(doc, "span", "hb-hd-aux", aux);
16
+ hd.append(el(doc, "span", "", title), aside);
17
+ root.append(hd);
18
+ return { root, aux: aside };
19
+ }
20
+ export const clamp01 = (v) => (Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0);
21
+ export const f2 = (v) => (Number.isFinite(v) ? v.toFixed(2) : "0.00");
22
+ /** The panels of a view, stacked as hackle's blocks (.hb-rack-stack). The column is a
23
+ * child, so the host keeps its own display and a hidden rack pane stays hidden. */
24
+ export function stack(host) {
25
+ return el(host.ownerDocument, "div", "hb-rack-stack");
26
+ }
@@ -0,0 +1,67 @@
1
+ /** What the view draws. Built from @hackbuild/drives with `drivesBarsState`, or by hand. */
2
+ export interface DrivesBarsState {
3
+ /** what it is doing now */
4
+ behavior: string;
5
+ /** seconds in it */
6
+ seconds?: number;
7
+ /** why it is doing it, one line */
8
+ why?: string;
9
+ /** how it chooses, the utility head's right end: sampled or argmax */
10
+ mode?: string;
11
+ /** what each act is worth now; any scale, drawn against the largest (at least 1) */
12
+ utilities: Record<string, number>;
13
+ /** the act drawn pink; defaults to `behavior` */
14
+ current?: string;
15
+ /** need per drive, 0 to 1 */
16
+ drives: Record<string, number>;
17
+ /** drive rows drawn pink, as hackle drew prey and bond */
18
+ pink?: readonly string[];
19
+ /** a switch that is on its way */
20
+ pending?: {
21
+ id: string;
22
+ inMs: number;
23
+ } | null;
24
+ }
25
+ /** The parts of a @hackbuild/drives Chooser decision the view reads. */
26
+ export interface DecisionLike {
27
+ current: string;
28
+ reason: string;
29
+ why: string;
30
+ utilities: Record<string, number>;
31
+ pending: {
32
+ id: string;
33
+ at: number;
34
+ latency: number;
35
+ } | null;
36
+ }
37
+ /** Drives values, or a @hackbuild/drives Drives object. */
38
+ export type DrivesLike = Record<string, number> | {
39
+ readonly values: Record<string, number>;
40
+ };
41
+ export interface DrivesBarsFrom {
42
+ /** sim seconds now, for the pending switch */
43
+ now?: number;
44
+ /** seconds in the current act */
45
+ seconds?: number;
46
+ /** false when the chooser runs argmax */
47
+ sampled?: boolean;
48
+ /** a longer name than the act id, as "fetch / chase" */
49
+ behavior?: string;
50
+ /** a why of your own in place of the decision's */
51
+ why?: string;
52
+ pink?: readonly string[];
53
+ }
54
+ /** Builds the view state from a Chooser decision and the drives. */
55
+ export declare function drivesBarsState(d: DecisionLike, drives: DrivesLike, o?: DrivesBarsFrom): DrivesBarsState;
56
+ export interface DrivesBarsOptions {
57
+ /** the note under the utility rows while no switch is pending */
58
+ note?: string;
59
+ }
60
+ export interface DrivesBarsHandle {
61
+ readonly root: HTMLElement;
62
+ update(state: DrivesBarsState): void;
63
+ dispose(): void;
64
+ }
65
+ export declare const DRIVES_NOTE = "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
66
+ /** Renders the behavior, utility and drives panels into `host`. */
67
+ export declare function drivesBars(host: HTMLElement, o?: DrivesBarsOptions): DrivesBarsHandle;
@@ -0,0 +1,98 @@
1
+ // DrivesBars: what the creature is doing and why, what each act is worth to
2
+ // it now, and how much it needs each thing. Ported from hackle's brain tab:
3
+ // the behavior block (the name in Permanent Marker, the why under it), the
4
+ // utility rows with the current choice in pink, and the drive rows.
5
+ import { clamp01, el, f2, panel, stack } from "./dom.js";
6
+ /** Builds the view state from a Chooser decision and the drives. */
7
+ export function drivesBarsState(d, drives, o = {}) {
8
+ const values = "values" in drives && typeof drives.values === "object" ? drives.values : drives;
9
+ const s = {
10
+ behavior: o.behavior ?? d.current,
11
+ current: d.current,
12
+ why: o.why ?? d.why,
13
+ mode: o.sampled === false ? "argmax" : "sampled",
14
+ utilities: { ...d.utilities },
15
+ drives: { ...values },
16
+ pending: d.pending && o.now !== undefined ? { id: d.pending.id, inMs: Math.max(0, (d.pending.at - o.now) * 1000) } : null,
17
+ };
18
+ if (o.seconds !== undefined)
19
+ s.seconds = o.seconds;
20
+ if (o.pink)
21
+ s.pink = o.pink;
22
+ return s;
23
+ }
24
+ export const DRIVES_NOTE = "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
25
+ /** One gauge row per key, rebuilt only when the keys change. */
26
+ function rows(doc, r, label, items) {
27
+ const keys = items.map((i) => i.k).join("\n");
28
+ if (keys !== r.keys) {
29
+ r.keys = keys;
30
+ r.host.replaceChildren(...items.map((i) => {
31
+ const row = el(doc, "div", "hb-gauge");
32
+ row.setAttribute("role", "listitem");
33
+ const meter = el(doc, "div", "hb-meter");
34
+ meter.setAttribute("role", "meter");
35
+ meter.setAttribute("aria-label", `${label} ${i.k}`);
36
+ meter.setAttribute("aria-valuemin", "0");
37
+ meter.append(el(doc, "i"));
38
+ const lab = el(doc, "span", "hb-gauge-label", i.k);
39
+ lab.title = i.k;
40
+ row.append(lab, meter, el(doc, "span", "hb-gauge-value"));
41
+ return row;
42
+ }));
43
+ }
44
+ items.forEach((i, n) => {
45
+ const row = r.host.children[n];
46
+ row.classList.toggle("is-cur", i.cur);
47
+ const meter = row.children[1];
48
+ meter.setAttribute("aria-valuemax", String(i.max));
49
+ meter.setAttribute("aria-valuenow", f2(i.v));
50
+ meter.firstChild.style.width = `${(clamp01(i.v / i.max) * 100).toFixed(1)}%`;
51
+ row.children[2].textContent = f2(i.v);
52
+ });
53
+ }
54
+ /** Renders the behavior, utility and drives panels into `host`. */
55
+ export function drivesBars(host, o = {}) {
56
+ const doc = host.ownerDocument;
57
+ const col = stack(host);
58
+ const beh = panel(doc, "behavior", "0.0 s");
59
+ const name = el(doc, "p", "hb-marker", "idle");
60
+ name.setAttribute("aria-live", "polite");
61
+ const why = el(doc, "p", "hb-note");
62
+ beh.root.append(name, why);
63
+ const util = panel(doc, "utility", "sampled");
64
+ const utilRows = el(doc, "div", "hb-gauges");
65
+ utilRows.setAttribute("role", "list");
66
+ utilRows.setAttribute("aria-label", "what each act is worth now");
67
+ const note = el(doc, "p", "hb-note", o.note ?? DRIVES_NOTE);
68
+ util.root.append(utilRows, note);
69
+ const drv = panel(doc, "drives", "need 0 to 1");
70
+ const driveRows = el(doc, "div", "hb-gauges");
71
+ driveRows.setAttribute("role", "list");
72
+ driveRows.setAttribute("aria-label", "drives");
73
+ drv.root.append(driveRows);
74
+ col.append(beh.root, util.root, drv.root);
75
+ host.replaceChildren(col);
76
+ const ur = { host: utilRows, keys: "" };
77
+ const dr = { host: driveRows, keys: "" };
78
+ return {
79
+ root: host,
80
+ update(s) {
81
+ name.textContent = s.behavior;
82
+ beh.aux.textContent = `${(s.seconds ?? 0).toFixed(1)} s`;
83
+ why.textContent = s.why ?? "";
84
+ why.hidden = !s.why;
85
+ util.aux.textContent = s.mode ?? "sampled";
86
+ const cur = s.current ?? s.behavior;
87
+ const u = Object.entries(s.utilities).map(([k, v]) => ({ k, v: Number.isFinite(v) ? Math.max(0, v) : 0 }));
88
+ const max = Math.max(1, ...u.map((x) => x.v));
89
+ rows(doc, ur, "utility", u.map((x) => ({ ...x, max, cur: x.k === cur })));
90
+ note.textContent = s.pending ? `next: ${s.pending.id} in ${Math.round(s.pending.inMs)} ms` : (o.note ?? DRIVES_NOTE);
91
+ const pink = new Set(s.pink ?? []);
92
+ rows(doc, dr, "drive", Object.entries(s.drives).map(([k, v]) => ({ k, v: clamp01(v), max: 1, cur: pink.has(k) })));
93
+ },
94
+ dispose() {
95
+ host.replaceChildren();
96
+ },
97
+ };
98
+ }
@@ -0,0 +1,25 @@
1
+ import { type AssociationsState } from "./associations-table.js";
2
+ import { type DrivesBarsState } from "./drives-bars.js";
3
+ import { type EyeInsetHandle, type EyeInsetOptions } from "./eye-inset.js";
4
+ export declare const ELEMENT_NAMES: {
5
+ readonly drivesBars: "hb-drives-bars";
6
+ readonly associationsTable: "hb-associations-table";
7
+ readonly eyeInset: "hb-eye-inset";
8
+ };
9
+ /** `<hb-drives-bars>`: set `.state` to a DrivesBarsState. */
10
+ export interface DrivesBarsElement extends HTMLElement {
11
+ state: DrivesBarsState | null;
12
+ }
13
+ /** `<hb-associations-table>`: set `.state`; fires `reset` when reset learning is pressed. */
14
+ export interface AssociationsTableElement extends HTMLElement {
15
+ state: AssociationsState | null;
16
+ }
17
+ /** `<hb-eye-inset>`: set `.options` (who and draw), then call `frame()` each frame; fires `who` with the id in `detail`. */
18
+ export interface EyeInsetElement extends HTMLElement {
19
+ options: EyeInsetOptions | null;
20
+ readonly view: EyeInsetHandle | null;
21
+ frame(): void;
22
+ mode(text: string): void;
23
+ }
24
+ /** Defines the three elements once; safe to call again. */
25
+ export declare function defineViews(registry?: CustomElementRegistry): void;
@@ -0,0 +1,86 @@
1
+ // The custom elements, for a plain HTML page as the originals are. Classes
2
+ // are made inside defineViews, so importing this module touches no DOM.
3
+ import { associationsTable } from "./associations-table.js";
4
+ import { drivesBars } from "./drives-bars.js";
5
+ import { eyeInset } from "./eye-inset.js";
6
+ export const ELEMENT_NAMES = { drivesBars: "hb-drives-bars", associationsTable: "hb-associations-table", eyeInset: "hb-eye-inset" };
7
+ /** Defines the three elements once; safe to call again. */
8
+ export function defineViews(registry = customElements) {
9
+ if (!registry.get(ELEMENT_NAMES.drivesBars)) {
10
+ registry.define(ELEMENT_NAMES.drivesBars, class extends HTMLElement {
11
+ #view = null;
12
+ #state = null;
13
+ get state() {
14
+ return this.#state;
15
+ }
16
+ set state(s) {
17
+ this.#state = s;
18
+ if (s)
19
+ this.#view?.update(s);
20
+ }
21
+ connectedCallback() {
22
+ const note = this.getAttribute("note");
23
+ this.#view ??= drivesBars(this, note ? { note } : {});
24
+ if (this.#state)
25
+ this.#view.update(this.#state);
26
+ }
27
+ });
28
+ }
29
+ if (!registry.get(ELEMENT_NAMES.associationsTable)) {
30
+ registry.define(ELEMENT_NAMES.associationsTable, class extends HTMLElement {
31
+ #view = null;
32
+ #state = null;
33
+ get state() {
34
+ return this.#state;
35
+ }
36
+ set state(s) {
37
+ this.#state = s;
38
+ if (s)
39
+ this.#view?.update(s);
40
+ }
41
+ connectedCallback() {
42
+ this.#view ??= associationsTable(this, { onReset: () => this.dispatchEvent(new CustomEvent("reset", { bubbles: true })) });
43
+ if (this.#state)
44
+ this.#view.update(this.#state);
45
+ }
46
+ });
47
+ }
48
+ if (!registry.get(ELEMENT_NAMES.eyeInset)) {
49
+ registry.define(ELEMENT_NAMES.eyeInset, class extends HTMLElement {
50
+ #view = null;
51
+ #options = null;
52
+ get options() {
53
+ return this.#options;
54
+ }
55
+ set options(o) {
56
+ this.#options = o;
57
+ this.#mount();
58
+ }
59
+ get view() {
60
+ return this.#view;
61
+ }
62
+ connectedCallback() {
63
+ this.#mount();
64
+ }
65
+ #mount() {
66
+ if (!this.#options || !this.isConnected)
67
+ return;
68
+ this.#view?.dispose();
69
+ const o = this.#options;
70
+ this.#view = eyeInset(this, {
71
+ ...o,
72
+ onWho: (id) => {
73
+ o.onWho?.(id);
74
+ this.dispatchEvent(new CustomEvent("who", { detail: id, bubbles: true }));
75
+ },
76
+ });
77
+ }
78
+ frame() {
79
+ this.#view?.frame();
80
+ }
81
+ mode(text) {
82
+ this.#view?.mode(text);
83
+ }
84
+ });
85
+ }
86
+ }
@@ -0,0 +1,42 @@
1
+ /** A @hackbuild/cameras FirstPerson, or anything that hides a head round a draw. */
2
+ export interface EyeLike {
3
+ render(draw: () => void): void;
4
+ }
5
+ export interface EyeWho {
6
+ id: string;
7
+ /** the switch label, as "dog eye" */
8
+ label: string;
9
+ /** a longer name for assistive tech, as "what the dog sees" */
10
+ title?: string;
11
+ /** the eye whose render wraps the draw, so its own head is hidden */
12
+ eye?: EyeLike;
13
+ }
14
+ export interface EyeInsetOptions {
15
+ who: readonly EyeWho[];
16
+ /** the selected id; the first by default */
17
+ selected?: string;
18
+ /**
19
+ * Draws one frame of `who` on the canvas, inside `who.eye.render` when there
20
+ * is an eye. A returned string becomes the mode line.
21
+ */
22
+ draw: (canvas: HTMLCanvasElement, who: EyeWho) => string | void;
23
+ /** canvas pixels (default 320 by 160, hackle's 2 to 1) */
24
+ width?: number;
25
+ height?: number;
26
+ /** the canvas, when a renderer owns it already (a three WebGLRenderer's) */
27
+ canvas?: HTMLCanvasElement;
28
+ onWho?: (id: string) => void;
29
+ }
30
+ export interface EyeInsetHandle {
31
+ readonly root: HTMLElement;
32
+ readonly canvas: HTMLCanvasElement;
33
+ readonly who: EyeWho;
34
+ select(id: string): void;
35
+ /** draws one frame of the selected eye */
36
+ frame(): void;
37
+ /** sets the mode line */
38
+ mode(text: string): void;
39
+ dispose(): void;
40
+ }
41
+ /** Makes `host` the eye card: head with the mode line, the who switch, the canvas. */
42
+ export declare function eyeInset(host: HTMLElement, o: EyeInsetOptions): EyeInsetHandle;
@@ -0,0 +1,84 @@
1
+ // EyeInset: the eye card on the stage. Ported from hackle's eye card: a
2
+ // canvas of what one of them sees, a who switch (the dog's eye, his eyes)
3
+ // and a mode line (dichromat, human colour). The card is a hackbuild-ui
4
+ // inset marked data-ux="inset", so a layout and the screen gate find it.
5
+ import { el } from "./dom.js";
6
+ /** Makes `host` the eye card: head with the mode line, the who switch, the canvas. */
7
+ export function eyeInset(host, o) {
8
+ if (!o.who.length)
9
+ throw new Error("@hackbuild/agents-views: eyeInset needs at least one who");
10
+ const doc = host.ownerDocument;
11
+ host.classList.add("hb-inset");
12
+ host.dataset.ux = "inset";
13
+ host.setAttribute("role", "figure");
14
+ const w = o.width ?? 320;
15
+ const h = o.height ?? 160;
16
+ let sel = o.who.find((x) => x.id === o.selected) ?? o.who[0];
17
+ // the head as hackbuild-ui's HbInset with who: title, the who switch (.hb-inset-who), the mode line
18
+ const hd = el(doc, "div", "hb-inset-hd");
19
+ const title = el(doc, "span", "hb-inset-title", "eye");
20
+ const aux = el(doc, "span", "hb-hd-aux");
21
+ const whoGroup = el(doc, "span", "hb-inset-who");
22
+ whoGroup.setAttribute("role", "group");
23
+ whoGroup.setAttribute("aria-label", "whose eyes");
24
+ const buttons = o.who.map((x) => {
25
+ const b = el(doc, "button", "", x.label);
26
+ b.type = "button";
27
+ if (x.title)
28
+ b.title = x.title;
29
+ b.addEventListener("click", () => pick(x.id, true));
30
+ return b;
31
+ });
32
+ whoGroup.append(...buttons);
33
+ hd.append(title, ...(o.who.length > 1 ? [whoGroup] : []), aux);
34
+ const media = el(doc, "div", "hb-inset-media");
35
+ media.style.setProperty("--hb-inset-ratio", `${w} / ${h}`);
36
+ const canvas = o.canvas ?? el(doc, "canvas");
37
+ if (!o.canvas) {
38
+ canvas.width = w;
39
+ canvas.height = h;
40
+ }
41
+ canvas.setAttribute("role", "img");
42
+ media.append(canvas);
43
+ host.replaceChildren(hd, media);
44
+ function pick(id, user) {
45
+ const next = o.who.find((x) => x.id === id);
46
+ if (!next)
47
+ return;
48
+ sel = next;
49
+ canvas.setAttribute("aria-label", sel.title ?? sel.label);
50
+ buttons.forEach((b, i) => b.setAttribute("aria-pressed", String(o.who[i] === sel)));
51
+ if (user)
52
+ o.onWho?.(sel.id);
53
+ }
54
+ pick(sel.id, false);
55
+ const handle = {
56
+ root: host,
57
+ canvas,
58
+ get who() {
59
+ return sel;
60
+ },
61
+ select: (id) => pick(id, false),
62
+ frame() {
63
+ const who = sel;
64
+ const run = () => {
65
+ const m = o.draw(canvas, who);
66
+ if (typeof m === "string")
67
+ aux.textContent = m;
68
+ };
69
+ if (who.eye)
70
+ who.eye.render(run);
71
+ else
72
+ run();
73
+ },
74
+ mode(text) {
75
+ aux.textContent = text;
76
+ },
77
+ dispose() {
78
+ host.replaceChildren();
79
+ host.classList.remove("hb-inset");
80
+ delete host.dataset.ux;
81
+ },
82
+ };
83
+ return handle;
84
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./associations-table.js";
2
+ export * from "./drives-bars.js";
3
+ export * from "./elements.js";
4
+ export * from "./eye-inset.js";
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // @hackbuild/agents-views: views that bind the agents packages to the
2
+ // hackbuild-ui class layer. Each view is a vanilla function over a host
3
+ // element, a custom element (defineViews) and a Vue component
4
+ // (@hackbuild/agents-views/vue). Load hackbuild-ui's hackbuild.css for the look.
5
+ export * from "./associations-table.js";
6
+ export * from "./drives-bars.js";
7
+ export * from "./elements.js";
8
+ export * from "./eye-inset.js";
@@ -0,0 +1 @@
1
+ export * from "./index.js";
package/dist/single.js ADDED
@@ -0,0 +1,6 @@
1
+ // Entry for the single file IIFE build (dist/agents-views.iife.js): a script
2
+ // tag defines the three elements at once.
3
+ import { defineViews } from "./elements.js";
4
+ export * from "./index.js";
5
+ if (typeof customElements !== "undefined")
6
+ defineViews();