visualproof 0.4.4 → 0.6.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.
Files changed (82) hide show
  1. package/README.md +16 -7
  2. package/dist/assets/tips/phone-fingers.light.mp4 +0 -0
  3. package/dist/assets/tips/phone-fingers.light.webp +0 -0
  4. package/dist/assets/tips/tour-agent.webp +0 -0
  5. package/dist/assets/tips/tour-arrange.webp +0 -0
  6. package/dist/assets/tips/tour-artwork.webp +0 -0
  7. package/dist/assets/tips/tour-checks.webp +0 -0
  8. package/dist/assets/tips/tour-keys.webp +0 -0
  9. package/dist/assets/tips/tour-library.webp +0 -0
  10. package/dist/assets/tips/tour-project.webp +0 -0
  11. package/dist/assets/tips/tour-review.webp +0 -0
  12. package/dist/assets/tips/tour-share.webp +0 -0
  13. package/dist/assets/tips/tour-source.webp +0 -0
  14. package/dist/assets/tips/tour-target.webp +0 -0
  15. package/dist/assets/tips/tour-view.webp +0 -0
  16. package/dist/assets/tips/tour.json +132 -117
  17. package/dist/assets/tips/tour.webp +0 -0
  18. package/dist/mcp/visualproof-mcp.mjs +20 -9
  19. package/dist/server/access.js +31 -1
  20. package/dist/server/accesspage.js +130 -0
  21. package/dist/server/agent.js +143 -50
  22. package/dist/server/askfollow.js +1 -1
  23. package/dist/server/buildwatch.js +133 -0
  24. package/dist/server/deploy.js +995 -0
  25. package/dist/server/doctor.js +15 -3
  26. package/dist/server/film.js +1 -1
  27. package/dist/server/historyapi.js +100 -50
  28. package/dist/server/historythread.js +206 -0
  29. package/dist/server/hover.js +8 -0
  30. package/dist/server/invites.js +113 -20
  31. package/dist/server/live.js +308 -60
  32. package/dist/server/main.js +450 -77
  33. package/dist/server/mcptools.js +33 -20
  34. package/dist/server/presence.js +3 -3
  35. package/dist/server/prompt.js +8 -3
  36. package/dist/server/readonlygate.js +4 -4
  37. package/dist/server/review.js +27 -7
  38. package/dist/server/reviewapi.js +51 -17
  39. package/dist/server/status.js +119 -46
  40. package/dist/server/talk.js +231 -115
  41. package/dist/server/tokens.js +10 -2
  42. package/dist/server/usage.js +51 -0
  43. package/dist/shared/board.js +2 -1
  44. package/dist/shared/build.js +35 -1
  45. package/dist/shared/collab.js +8 -0
  46. package/dist/shared/deploy.js +35 -0
  47. package/dist/shared/keys.js +66 -37
  48. package/dist/shared/layout.js +297 -70
  49. package/dist/shared/libm.js +366 -0
  50. package/dist/shared/lostfound.js +1 -0
  51. package/dist/shared/mentions.js +83 -0
  52. package/dist/shared/palette.js +1 -1
  53. package/dist/shared/query.js +13 -4
  54. package/dist/shared/review.js +91 -21
  55. package/dist/shared/reviewqueue.js +6 -1
  56. package/dist/shared/separate.js +556 -32
  57. package/dist/web/bundle/app.js +5022 -2736
  58. package/dist/web/bundle/edges.js +2 -1
  59. package/dist/web/bundle/layout.js +1026 -80
  60. package/dist/web/index.html +45 -9
  61. package/dist/web/src/canvas.js +47 -34
  62. package/dist/web/src/overview.js +4 -1
  63. package/dist/web/src/reviewqueue.js +52 -19
  64. package/dist/web/src/scene.js +13 -12
  65. package/dist/web/src/status.js +28 -0
  66. package/dist/web/src/theme.js +108 -0
  67. package/dist/web/src/trust.js +271 -0
  68. package/dist/web/style.css +283 -105
  69. package/docs/agent-api/README.md +13 -11
  70. package/docs/agent-api/advice.md +8 -2
  71. package/docs/agent-api/export.md +1 -1
  72. package/docs/agent-api/following.md +11 -12
  73. package/docs/agent-api/history.md +6 -2
  74. package/docs/agent-api/mcp.md +15 -15
  75. package/docs/agent-api/notes.md +1 -1
  76. package/docs/agent-api/reading.md +2 -2
  77. package/docs/agent-api/requests.md +16 -18
  78. package/docs/agent-api/talking.md +60 -55
  79. package/docs/agent-api/tcb.md +21 -21
  80. package/docs/agent-api/views.md +3 -4
  81. package/docs/agent-api/words.md +8 -8
  82. package/package.json +2 -1
@@ -0,0 +1,108 @@
1
+ // Light, dark, or as the system is: the reader's choice, kept for every project in this browser;
2
+ // light unless they chose otherwise, on every platform (the owner's decision of 2026-10-14). The
3
+ // page's colours follow `data-theme` on <html> (style.css); a script in index.html's <head> sets it
4
+ // before the first paint, from the same stored choice, so a dark page never flashes light.
5
+ //
6
+ // What draws in the theme's colours itself — the board's canvas, the linear form — reads them from
7
+ // the page's custom properties as it draws, and keeps what it drew: it draws again when the theme on
8
+ // show changes (onThemeChange), whoever changed it, in either direction.
9
+ //
10
+ // The system's other preference the page follows is reduced motion (reducedMotion): nothing on the
11
+ // page glides then — style.css's one rule for its transitions and animations, and here for what
12
+ // moves by itself (the board's camera, the linear form coming and going).
13
+ const KEY = "visualproof:theme";
14
+ // none without a browser: the artwork command reads the board's module, which reads this one
15
+ const dark = typeof matchMedia === "function" ? matchMedia("(prefers-color-scheme: dark)") : null;
16
+ /** the theme something holds on show over the reader's choice (holdTheme), or none */
17
+ let held = null;
18
+ /** Whether the system asks for reduced motion: what would glide is where it goes at once (GuideSpec
19
+ * decision 4; the camera, web/src/canvas.ts animate; the linear form, web/src/linear.ts). Read as
20
+ * it is asked, so that a change of the setting holds from the next motion. */
21
+ export const reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
22
+ export function themeChoice() {
23
+ try {
24
+ const v = localStorage.getItem(KEY);
25
+ if (v === "dark" || v === "system")
26
+ return v;
27
+ }
28
+ catch {
29
+ // storage blocked: the default
30
+ }
31
+ return "light";
32
+ }
33
+ /** Put the choice in force: what <html> says, now and (for "system") whenever the system changes;
34
+ * while a theme is held (holdTheme), that one. */
35
+ export function applyTheme(choice = themeChoice()) {
36
+ const t = held ?? (choice === "system" ? (dark?.matches ? "dark" : "light") : choice);
37
+ if (document.documentElement.dataset.theme !== t)
38
+ document.documentElement.dataset.theme = t;
39
+ }
40
+ /** Show `t` whatever the reader chose, until it is let go (null): the artwork mode's theme (web/src/
41
+ * main.ts, drawLook), which a change of the system's, followed by "As the system", must not undo
42
+ * while the mode is on. Let go, the reader's choice is in force again. */
43
+ export function holdTheme(t) {
44
+ held = t;
45
+ applyTheme();
46
+ }
47
+ const followers = [];
48
+ let watching = null;
49
+ let shown;
50
+ /** Call `f` whenever the theme on show changes, light to dark or back: by the reader's choice, the
51
+ * system's while it is followed, an artwork's look. It is read from <html> itself, so that no way of
52
+ * changing it is missed; setting it to what it is already is no change. */
53
+ export function onThemeChange(f) {
54
+ followers.push(f);
55
+ if (watching || typeof MutationObserver === "undefined")
56
+ return;
57
+ shown = document.documentElement.dataset.theme;
58
+ watching = new MutationObserver(() => {
59
+ const now = document.documentElement.dataset.theme;
60
+ if (now === shown)
61
+ return;
62
+ shown = now;
63
+ for (const g of followers)
64
+ g();
65
+ });
66
+ watching.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
67
+ }
68
+ export function setTheme(choice) {
69
+ try {
70
+ // the default is kept as nothing, so that a later change of the default reaches whoever never chose
71
+ if (choice === "light")
72
+ localStorage.removeItem(KEY);
73
+ else
74
+ localStorage.setItem(KEY, choice);
75
+ }
76
+ catch {
77
+ // not kept: in force for this page only
78
+ }
79
+ applyTheme(choice);
80
+ }
81
+ dark?.addEventListener("change", () => {
82
+ if (themeChoice() === "system")
83
+ applyTheme("system");
84
+ });
85
+ const ICONS = {
86
+ light: `<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.4 3.4l1 1M11.6 11.6l1 1M3.4 12.6l1-1M11.6 4.4l1-1"/></svg>`,
87
+ dark: `<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M13 9.5A5.5 5.5 0 0 1 6.5 3a5.5 5.5 0 1 0 6.5 6.5Z"/></svg>`,
88
+ system: `<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><rect x="2" y="3" width="12" height="8.5" rx="1.5"/><path d="M6 14h4M8 11.5V14"/></svg>`,
89
+ };
90
+ const LABELS = { light: "Light", dark: "Dark", system: "As the system" };
91
+ /** The theme's three choices side by side, in the eyes' ⋯ menu at the bottom right (since
92
+ * 2026-10-08; a switch of its own under the zoom buttons before). */
93
+ export function themeChoices(el) {
94
+ const render = () => {
95
+ const c = themeChoice();
96
+ el.innerHTML = ["light", "dark", "system"]
97
+ .map((k) => `<button data-theme-choice="${k}" class="${k === c ? "on" : ""}" role="radio" aria-checked="${k === c}" title="${LABELS[k]}" aria-label="${LABELS[k]}">${ICONS[k]}</button>`)
98
+ .join("");
99
+ };
100
+ render();
101
+ el.addEventListener("click", (e) => {
102
+ const b = e.target.closest("[data-theme-choice]");
103
+ if (!b)
104
+ return;
105
+ setTheme(b.dataset.themeChoice);
106
+ render();
107
+ });
108
+ }
@@ -0,0 +1,271 @@
1
+ // What is trusted without review (ReviewSpec decision 3), chosen from the page: the trusted
2
+ // prefixes listed in a popover from the side panel's Trusted button, each with a way to stop
3
+ // trusting it, and a way to trust a cluster from its row in the outline. Each asks first, and says
4
+ // what it means and what it changes: how many declarations the prefix covers, and how many each
5
+ // target then counts for review.
6
+ import { SITE_BODY, SITE_STMT } from "../../shared/graph.js";
7
+ import { covers, DEFAULT_TRUSTED, OUTSIDE, prefixLabel, under, validPrefix } from "../../shared/review.js";
8
+ import { escapeHtml } from "./highlight.js";
9
+ /** The declarations of a set of the graph, as the review reads them. */
10
+ export function membersOf(g, set) {
11
+ const out = [];
12
+ for (let j = 0; j < set.length; j++)
13
+ if (set[j])
14
+ out.push({ name: g.nodes[j].name, module: g.nodes[j].module, ext: g.isExt(j), hash: g.nodes[j].hash });
15
+ return out;
16
+ }
17
+ /** A target's TCB, the target included, as the panel and the Targets list read it:
18
+ * statement and body edges. */
19
+ export function tcbMembers(g, roots) {
20
+ return membersOf(g, g.reach(roots, SITE_STMT | SITE_BODY, "out"));
21
+ }
22
+ const EXT = "⟨external⟩";
23
+ /** The prefix a cluster of the outline stands for, or null where trust cannot name it. A cluster of
24
+ * the project is a namespace or a folder of files, and its key is the prefix either way; one
25
+ * outside the project only when clustered by file, since the outside world is trusted by module
26
+ * (clustered by namespace, its clusters are names, which say nothing of where they come from). */
27
+ export function clusterPrefix(c, mode) {
28
+ if (!c.ext)
29
+ return validPrefix(c.key) ? c.key : null;
30
+ // the outside world as a whole, in either clustering
31
+ if (c.key === EXT)
32
+ return OUTSIDE;
33
+ if (mode !== "module" || !c.key.startsWith(EXT + "."))
34
+ return null;
35
+ const p = c.key.slice(EXT.length + 1);
36
+ return validPrefix(p) ? p : null;
37
+ }
38
+ /** What trusting a prefix (or no longer trusting it) changes: how many of the graph's declarations
39
+ * it covers, in the project and outside it, and each target's count for review before and after. */
40
+ export function effectOf(g, d, prefix, on, targets) {
41
+ let own = 0, outside = 0;
42
+ for (let j = 0; j < g.n; j++) {
43
+ const v = g.nodes[j];
44
+ if (covers(prefix, v.name, v.module, g.isExt(j)))
45
+ g.isExt(j) ? outside++ : own++;
46
+ }
47
+ // the same review with the list changed (its opinions and targets shared, not copied)
48
+ const next = { ...d, trusted: on ? [...d.trusted, prefix].sort() : d.trusted.filter((p) => p !== prefix) };
49
+ const counts = targets.map((t) => ({ name: t.name, before: t.count(d), after: t.count(next) })).filter((t) => t.before !== t.after);
50
+ return { own, outside, targets: counts };
51
+ }
52
+ /** Where trusting `prefix` (`on`), or no longer trusting it, is undone, as the question says it:
53
+ * Trusted lists every trusted prefix, and of those taken off only the defaults (ReviewSpec decision
54
+ * 3) and the outside world, which has its own button there; any other leaves the list, and is
55
+ * trusted again from the shield on its row — a module outside the project only where the cluster
56
+ * tree is by file (`clusterPrefix`). `outside`: the prefix covers only declarations outside the
57
+ * project. */
58
+ export function undoNote(prefix, on, outside) {
59
+ if (on)
60
+ return "Undo it from Trusted in the side panel.";
61
+ if (DEFAULT_TRUSTED.includes(prefix))
62
+ return "It stays listed under Trusted, to be trusted again.";
63
+ if (prefix === OUTSIDE)
64
+ return "It can be trusted again from Trusted in the side panel.";
65
+ return `It leaves the Trusted list: the shield on its row in the side panel${outside ? ", clustered by file," : ""} trusts it again.`;
66
+ }
67
+ export const SHIELD = `<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1.8 3 3.6v3.9c0 3.1 2.1 5.5 5 6.7 2.9-1.2 5-3.6 5-6.7V3.6z"/></svg>`;
68
+ export class Trust {
69
+ list;
70
+ pop;
71
+ hooks;
72
+ /** what the open question is about */
73
+ asking = null;
74
+ constructor(list, pop, hooks) {
75
+ this.list = list;
76
+ this.pop = pop;
77
+ this.hooks = hooks;
78
+ list.addEventListener("click", (e) => {
79
+ const t = e.target;
80
+ const off = t.closest("[data-untrust]");
81
+ if (off)
82
+ return this.ask(off.dataset.untrust, false, off);
83
+ const on = t.closest("[data-retrust]");
84
+ if (on)
85
+ return this.ask(on.dataset.retrust, true, on);
86
+ const show = t.closest("[data-show]");
87
+ if (show)
88
+ this.hooks.show(show.dataset.show);
89
+ });
90
+ pop.addEventListener("click", (e) => {
91
+ const t = e.target;
92
+ if (t.closest("[data-tp-cancel]"))
93
+ this.close();
94
+ else if (t.closest("[data-tp-ok]"))
95
+ void this.confirm();
96
+ });
97
+ // a click anywhere else is a no; one on another trust action asks about that instead
98
+ document.addEventListener("pointerdown", (e) => {
99
+ const t = e.target;
100
+ if (this.asking && !pop.contains(t) && !t.closest("[data-trust], [data-untrust], [data-retrust]") && !t.closest("#modal"))
101
+ this.close();
102
+ });
103
+ }
104
+ get open() {
105
+ return this.asking !== null;
106
+ }
107
+ writable() {
108
+ const R = this.hooks.review();
109
+ return !R.readOnly && !R.blocked;
110
+ }
111
+ /** The list in its popover: every trusted prefix, and the defaults no longer trusted, which
112
+ * can be trusted again from here (the outline names only what the graph holds). */
113
+ render() {
114
+ const d = this.hooks.review().data;
115
+ const g = this.hooks.graph();
116
+ const can = this.writable();
117
+ const esc = escapeHtml;
118
+ const count = (p) => {
119
+ let n = 0;
120
+ for (let j = 0; j < g.n; j++)
121
+ if (covers(p, g.nodes[j].name, g.nodes[j].module, g.isExt(j)))
122
+ n++;
123
+ return n;
124
+ };
125
+ const chip = (p) => {
126
+ const n = count(p);
127
+ const own = !DEFAULT_TRUSTED.includes(p);
128
+ return (`<span class="tl-chip${own ? " own" : ""}${p === OUTSIDE ? " world" : ""}">` +
129
+ `<button class="tl-name" data-show="${esc(p)}" title="${esc(prefixLabel(p))}: ${n.toLocaleString()} declaration${n === 1 ? "" : "s"} here trusted without review — click to show ${own ? "them" : "it"}">${esc(prefixLabel(p))}</button>` +
130
+ (can ? `<button class="tl-x" data-untrust="${esc(p)}" title="Stop trusting ${esc(prefixLabel(p))}…" aria-label="Stop trusting ${esc(prefixLabel(p))}">✕</button>` : "") +
131
+ `</span>`);
132
+ };
133
+ // a default taken off stays in sight, so that it can be put back
134
+ const gone = DEFAULT_TRUSTED.filter((p) => !d.trusted.includes(p));
135
+ const off = (p) => `<span class="tl-chip off"><button class="tl-name" data-show="${esc(p)}" title="${esc(p)}: one of the defaults, not trusted now — its declarations count for review">${esc(p)}</button>` +
136
+ (can ? `<button class="tl-x" data-retrust="${esc(p)}" title="Trust ${esc(p)} again…" aria-label="Trust ${esc(p)} again">+</button>` : "") +
137
+ `</span>`;
138
+ this.list.innerHTML =
139
+ `<div class="tl-h"><span class="tl-t">Trusted</span><span class="muted">not reviewed, not counted · the same on every board</span></div>` +
140
+ `<div class="tl-chips">${d.trusted.map(chip).join("")}${gone.map(off).join("")}</div>` +
141
+ (can && !d.trusted.includes(OUTSIDE)
142
+ ? `<button class="tl-all" data-retrust="${OUTSIDE}" title="Trust every declaration outside the project, whatever its module…">Trust the whole outside world</button>`
143
+ : "") +
144
+ (can ? `<div class="tl-hint muted">To trust a namespace or a folder, use <span class="tl-shield">${SHIELD}</span> on its row in the side panel.</div>` : "") +
145
+ (this.hooks.review().note ? `<div class="tl-hint muted">${esc(this.hooks.review().note)}</div>` : "");
146
+ }
147
+ /** A cluster row's trust mark and action in the outline, as HTML: a shield where a trusted prefix
148
+ * covers the cluster, and on the row under the pointer a shield to trust it. */
149
+ cell(c, mode) {
150
+ const p = clusterPrefix(c, mode);
151
+ if (!p)
152
+ return "";
153
+ const d = this.hooks.review().data;
154
+ const esc = escapeHtml;
155
+ const by = d.trusted.filter((t) => under(p, t) || (t === OUTSIDE && c.ext));
156
+ const can = this.writable();
157
+ // a trusted one's shield is its mark and its action
158
+ if (by.includes(p))
159
+ return can
160
+ ? `<button class="o-trust on" data-trust title="${esc(prefixLabel(p))} is trusted without review — click to stop trusting it">${SHIELD}</button>`
161
+ : `<span class="o-trust on" title="${esc(prefixLabel(p))} is trusted without review">${SHIELD}</span>`;
162
+ // a broader prefix covers it: taking that one off is done where it is
163
+ if (by.length)
164
+ return `<span class="o-trust on under" title="Trusted without review, under ${esc(prefixLabel(by[0]))}">${SHIELD}</span>`;
165
+ return can ? `<button class="o-trust" data-trust title="Trust ${esc(prefixLabel(p))}: its declarations are not counted in reviews and need no opinion…" aria-label="Trust ${esc(prefixLabel(p))}">${SHIELD}</button>` : "";
166
+ }
167
+ /** Whether a cluster is trusted without review, as its panel says it (web/src/clusterpanel.ts):
168
+ * the prefix it stands for (null where trust cannot name it), whether that prefix is trusted
169
+ * itself, the broader trusted prefix that covers it otherwise, whether this page may change it,
170
+ * and why not where the review is read-only here. */
171
+ state(c, mode) {
172
+ const p = clusterPrefix(c, mode);
173
+ const can = this.writable();
174
+ const note = this.hooks.review().note;
175
+ if (!p)
176
+ return { prefix: null, on: false, by: null, can };
177
+ const by = this.hooks.review().data.trusted.filter((t) => under(p, t) || (t === OUTSIDE && c.ext));
178
+ return { prefix: p, on: by.includes(p), by: by.includes(p) ? null : by[0] ?? null, can, ...(note ? { note } : {}) };
179
+ }
180
+ /** A click on a cluster row's action: trust it, or stop trusting it. */
181
+ clicked(c, mode, anchor) {
182
+ const p = clusterPrefix(c, mode);
183
+ if (p && this.writable())
184
+ this.ask(p, !this.hooks.review().data.trusted.includes(p), anchor);
185
+ }
186
+ /** Ask before trusting a prefix or no longer trusting it: what it means, and what it changes.
187
+ * Beside `anchor`, or (the canvas's menu) at a point of the window, kept inside it. */
188
+ ask(prefix, on, anchor) {
189
+ if (!this.writable())
190
+ return;
191
+ this.asking = { prefix, on };
192
+ const g = this.hooks.graph();
193
+ const d = this.hooks.review().data;
194
+ const esc = escapeHtml;
195
+ const code = prefix === OUTSIDE ? "everything outside the project" : `<code>${esc(prefix)}</code>`;
196
+ const e = effectOf(g, d, prefix, on, this.hooks.targets());
197
+ const n = (x) => x.toLocaleString();
198
+ const one = e.own + e.outside === 1;
199
+ const which = prefix === OUTSIDE
200
+ ? `${n(e.outside)} declaration${one ? "" : "s"} outside the project`
201
+ : e.own && e.outside
202
+ ? `${n(e.own)} declarations of the project whose name or module starts with ${code}, and the ${n(e.outside)} outside it whose module does,`
203
+ : e.outside
204
+ ? `${n(e.outside)} declaration${one ? "" : "s"} outside the project whose module starts with ${code}`
205
+ : `${n(e.own)} declaration${one ? "" : "s"} whose name or module starts with ${code}`;
206
+ const text = on
207
+ ? `The ${which} ${one ? "is" : "are"} then trusted without review: not counted in any target's progress, and in need of no opinion. Opinions given on ${one ? "it" : "them"} are kept.`
208
+ : `The ${which} then need${one ? "s" : ""} review again, unless another trusted prefix covers ${one ? "it" : "them"}: counted in each target's progress.`;
209
+ const effect = e.targets.length
210
+ ? `<div class="tp-effect"><div class="muted">Counted for review</div>` +
211
+ e.targets.map((t) => `<div><span class="star">★</span>${esc(t.name.split(".").pop())} <b>${n(t.before)} → ${n(t.after)}</b></div>`).join("") +
212
+ `</div>`
213
+ : `<div class="tp-effect muted">No target's count changes.</div>`;
214
+ const deflt = DEFAULT_TRUSTED.includes(prefix) && !on ? `<div class="tp-text">${code} is one of the defaults: what a review of a Lean project usually takes on trust.</div>` : "";
215
+ this.pop.innerHTML =
216
+ `<div class="tp-title">${on ? "Trust" : "Stop trusting"} ${code}?</div>` +
217
+ `<div class="tp-text">${text}</div>${deflt}${effect}` +
218
+ `<div class="tp-note muted">For everyone on this server, recorded under your name in the review; Activity says who did it. ${undoNote(prefix, on, !e.own && e.outside > 0)}</div>` +
219
+ `<div class="rv-err" hidden></div>` +
220
+ `<div class="modal-actions"><button class="rv-btn" data-tp-cancel>Cancel</button>` +
221
+ `<button class="rv-btn primary" data-tp-ok>${on ? "Trust" : "Stop trusting"}</button></div>`;
222
+ this.pop.hidden = false;
223
+ if (!(anchor instanceof HTMLElement)) {
224
+ const w = this.pop.offsetWidth, hh = this.pop.offsetHeight;
225
+ this.pop.style.left = `${Math.round(Math.max(12, Math.min(anchor.x, innerWidth - w - 12)))}px`;
226
+ this.pop.style.top = `${Math.round(Math.max(70, Math.min(anchor.y, innerHeight - hh - 12)))}px`;
227
+ return;
228
+ }
229
+ // beside the panel it was asked from — the side panel's right (or the Trusted popover's), the
230
+ // cluster panel's left — level with what was clicked, inside the window
231
+ const right = anchor.closest("#panel");
232
+ const side = (anchor.closest("#trust-list:not([hidden])") ?? anchor.closest("#side") ?? right ?? anchor).getBoundingClientRect();
233
+ const at = anchor.getBoundingClientRect();
234
+ const h = this.pop.offsetHeight;
235
+ this.pop.style.left = `${Math.round(right ? Math.max(12, side.left - 10 - this.pop.offsetWidth) : side.right + 10)}px`;
236
+ this.pop.style.top = `${Math.round(Math.max(70, Math.min(innerHeight - h - 12, at.top - 12)))}px`;
237
+ }
238
+ /** The review changed: the list follows, and a question someone else has answered meanwhile
239
+ * goes away. */
240
+ reviewChanged() {
241
+ this.render();
242
+ if (this.asking && this.hooks.review().data.trusted.includes(this.asking.prefix) === this.asking.on)
243
+ this.close();
244
+ }
245
+ close() {
246
+ this.asking = null;
247
+ this.pop.hidden = true;
248
+ }
249
+ async confirm() {
250
+ const q = this.asking;
251
+ if (!q)
252
+ return;
253
+ const me = await this.hooks.ensureReviewer();
254
+ if (!me || this.asking !== q)
255
+ return;
256
+ // one answer per question: a second click while the first is on its way does nothing
257
+ const ok = this.pop.querySelector("[data-tp-ok]");
258
+ if (ok)
259
+ ok.disabled = true;
260
+ const why = await this.hooks.submit({ op: "trust", prefix: q.prefix, on: q.on });
261
+ if (ok)
262
+ ok.disabled = false;
263
+ if (!why)
264
+ return this.close();
265
+ const err = this.pop.querySelector(".rv-err");
266
+ if (err) {
267
+ err.textContent = why;
268
+ err.hidden = false;
269
+ }
270
+ }
271
+ }