@khanglvm/relay 0.17.0 → 0.17.1

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 CHANGED
@@ -1,269 +1,71 @@
1
- # relay
1
+ # Relay
2
2
 
3
- **The relay between AI agents and humans — browser boards instead of terminal walls.**
3
+ Relay gives your AI coding agent a board for showing work and asking for
4
+ feedback. Review a design, compare a diff, or answer several questions in one
5
+ place, in your browser or inside a chat app that supports MCP Apps.
4
6
 
5
- `rly` is a CLI that lets your AI agent ask questions and present work in a
6
- local browser board — real forms, charts, diagrams, sortable tables, images,
7
- and live prototypes instead of terminal text and ASCII art. You click, comment
8
- on any element, and Submit; the agent gets your answers and comments back as
9
- JSON and keeps working.
7
+ Feedback stays attached to the thing you mean: a chart point, a line of text,
8
+ or a marked area of an image. When you submit, the agent gets your choices
9
+ and comments as structured JSON, including the target of each comment.
10
+ It works with agents such as Claude Code and Codex.
10
11
 
11
- ## See it
12
+ ![An agent opens a Relay board, the user reviews and submits, and the agent continues](https://raw.githubusercontent.com/khanglvm/relay/main/docs/assets/demo.gif)
12
13
 
13
- **The whole loop** — your agent asks in the terminal, a board opens in your
14
- browser; you pick a style, expand the chart, comment on a data point, leave a
15
- note, Submit — and the agent picks up your answers and keeps going:
14
+ ## Install and try it
16
15
 
17
- ![Full flow: Claude Code opens a relay board, the user answers, comments and submits, the agent continues](https://raw.githubusercontent.com/khanglvm/relay/main/docs/assets/demo.gif)
18
-
19
- ## Quick start
16
+ Requires Node.js 18.3 or newer.
20
17
 
21
18
  ```sh
22
- # the rly CLI
23
19
  npm i -g @khanglvm/relay
24
-
25
- # the agent skill → every detected agent (Claude Code, Codex, Cursor, …)
26
- npx skills add khanglvm/relay --skill relay --all
27
-
28
- # enforce it (recommended) — a skill alone is an ignorable hint; `rly install`
29
- # writes relay's usage rules into the file each agent reads (run `rly install`
30
- # with no args to see every supported target and where it lands):
31
- rly install --all # every agent detected on this machine
20
+ rly ask -q "Which layout?::single::Sidebar,Top navigation"
32
21
  ```
33
22
 
34
- That's it. Next time your agent needs a decision or wants to show you a plan,
35
- it opens a board like the ones above and waits for your Submit.
23
+ A board opens in your browser. Choose an option and submit to see the result
24
+ in your terminal.
36
25
 
37
- Keep relay current with **`rly upgrade`** — it installs the latest CLI and
38
- refreshes the skill (via `npx skills`, falling back to the bundled copy) in one
39
- step, leaving any boards you have open untouched.
40
-
41
- ## Inside the Claude & Codex apps (MCP App)
42
-
43
- relay also runs as an **MCP App** ([SEP-1865](https://modelcontextprotocol.io/seps/1865-mcp-apps-interactive-user-interfaces-for-mcp))
44
- — so the same board renders **inline, right in the conversation**, on Claude
45
- desktop **and mobile** and in Codex, no browser tab. `rly mcp` is a
46
- stdio MCP server with no npm runtime dependencies; register it once and the agent gets two tools,
47
- `relay_ask` (collect decisions/feedback with real form controls) and
48
- `relay_show` (present a plan, diagram, diff, table, or prototype):
26
+ You can also open local files or review changes from a Git repository:
49
27
 
50
28
  ```sh
51
- # Claude Code
52
- claude mcp add relay -- rly mcp
53
-
54
- # Claude Desktop / Codex — write the host config for you
55
- rly mcp install --target claude # claude_desktop_config.json
56
- rly mcp install --target codex # ~/.codex/config.toml
57
-
58
- # or print the snippet for any MCP host (incl. the raw JSON/TOML)
59
- rly mcp config
29
+ rly view README.md
30
+ rly diff --staged
60
31
  ```
61
32
 
62
- When the agent calls a relay tool, the host renders relay's `ui://relay/board`
63
- resource in a sandboxed iframe, hands it the board spec, and the user's answers
64
- flow back to the agent as a `ui/message` user turn, with
65
- `ui/update-model-context` used as a best-effort structured context sync —
66
- markdown, code, diffs, tables, charts, mermaid/graphviz diagrams, images, and
67
- forms, all in-chat. The classic browser board (`rly ask` / `rly show`) is
68
- unchanged; pick whichever surface fits.
69
-
70
- ## What it improves
71
-
72
- | Without relay | With relay |
73
- |---|---|
74
- | Six questions asked one at a time in the terminal | One board, all questions, real form controls, optional "Other" + notes |
75
- | "Option B is the one with caching (see my last message)" | Each answer option carries its own image / chart / diagram — pick by looking |
76
- | ASCII architecture art | Mermaid, Graphviz, PlantUML — zoomable, full-screen, even user-editable |
77
- | Numbers buried in prose | Charts and sortable tables; screenshots and HTML prototypes in a sandbox |
78
- | "Here's the diff — paste it in your editor" | Side-by-side **diff** blocks, syntax-highlighted **code**, **video** walkthroughs, and **file paths you click to open** in the default app |
79
- | "Which commits should I pick? Resolve this conflict manually." | `rly git pick` / `rly git cherry-pick` boards and color-coded `git-conflict` resolvers with ours/theirs/custom hunk choices |
80
- | "Type *done* when finished reviewing" | A Submit button; answers, notes, and inline comments returned as JSON |
81
- | Feedback = another wall of text | Click any chart point, diagram node, table cell, or sentence; drag an image region to attach a local crop — the agent replies and the thread grows on the board |
33
+ ## What you can review
82
34
 
83
- Everything autosaves in real time, detached board links keep serving after
84
- agent timeouts, multiple boards run at once, and the package has **zero npm
85
- runtime dependencies** — plain Node ≥ 18. Browser-side Chart.js, Mermaid, and
86
- Viz.js assets are vendored in the package and lazy-loaded offline when a board
87
- actually needs them.
35
+ - Plans, documents, charts, and diagrams.
36
+ - Images and HTML prototypes, with comments on individual elements or areas.
37
+ - Source files and diffs, including commit choices and merge conflicts.
38
+ - Questions with choices, notes, and other form controls.
88
39
 
89
- ## Learn more
40
+ Answers and comments autosave. To stop a board, run `rly list` to find its
41
+ ID, then `rly stop <board-id>`.
90
42
 
91
- | | |
92
- |---|---|
93
- | `rly help` | every command at a glance |
94
- | `rly git pick` / `rly git cherry-pick` | choose commit actions and rank the order directly on a board; add `--code` to cherry-pick with split code review and per-hunk Apply/Skip/Hold |
95
- | `rly git conflict [files…]` | auto-detect unmerged conflict files, or open specific local paths, and return resolved content in `result.blockEdits` |
96
- | `rly share <board-id>` | activate/list/revoke same-Wi-Fi collaborator, reference-only reviewer, or read-only links for a running browser board |
97
- | `rly view <file.md> …` | open a quick read-only board that renders local markdown file(s), data files, or PDFs — library-free; great for plans, READMEs, reports, quotes |
98
- | `rly show --file spec.json --display-only` | present a browser board and continue immediately — no comment/note or acknowledgement required; inline `relay_show` uses this mode by default |
99
- | `rly install --target <agent>` | write relay's rules into an agent's instruction file — `claude` `codex` `cursor` `copilot` `kiro` `windsurf` `cline` `gemini` `opencode` `droid` `agents`; `--all`, `--scope`, `--print`, `--list` |
100
- | `rly upgrade` | update the CLI **and** refresh the skill in one step (safe around open boards; `--dry-run`, `--cli-only`, `--skill-only`) |
101
- | `rly mcp` | run relay as an MCP App server so boards render **inline** in the chat — **stdio** for local desktop hosts (Claude Desktop, Codex), or `rly mcp --http` (Streamable HTTP) for web/mobile/remote; `rly mcp config` / `rly mcp install --target claude\|codex` to register it |
102
- | `rly agent` | the full agent guide — spec format, all block types, annotations, patterns ([docs/AGENT.md](docs/AGENT.md)) |
103
- | `rly schema` | board spec JSON Schema |
104
- | [skills/relay/SKILL.md](skills/relay/SKILL.md) | the bundled skill |
43
+ ## For AI agents
105
44
 
106
- ## Development
45
+ Install the skill so your agent knows how to create boards and read feedback:
107
46
 
108
47
  ```sh
109
- npm test # smoke tests with no external services (spawns real servers, fake-submits)
48
+ npx skills add khanglvm/relay --skill relay --all
110
49
  ```
111
50
 
112
- ## Changelog
113
-
114
- ### 0.16.1 — reliable area-comment zones
115
-
116
- - Primary drag now draws a comment area directly on image and comparison views;
117
- **Area** remains as a visible one-shot lock. Image pan uses Space-drag or the
118
- middle button, while the comparison divider moves only from its handle.
119
- - The selected rectangle remains visible while its comment is composed. Saved
120
- zones carry a comment icon plus count, reopen for add/edit/delete, and disappear
121
- automatically when their final comment is removed.
51
+ Give your agent this instruction:
122
52
 
123
- ### 0.17.0 — file reference previews
124
-
125
- - Local source references now resolve `:line[:column]` and `#Lstart-Lend` and
126
- open in a keyboard-accessible modal at the cited lines.
127
- - Preview Markdown, source/config/logs, CSV/TSV, static sandboxed HTML, images,
128
- PDFs, and browser-compatible audio/video. Text is bounded to 1 MiB/20,000
129
- lines; unsupported files retain an explicit **Open in app** fallback.
130
- - Shorter agent skill and installed instructions, with clear display-only,
131
- feedback, file-preview, and existing-board workflows.
132
-
133
- ### 0.16.0 — native viewer chrome, area comments, and durable agent waits
134
-
135
- - Viewer toolbars now use browser-native sticky positioning instead of a
136
- scroll-event counter-translation; open comment composers re-anchor on scroll
137
- and preserve unsaved per-target drafts.
138
- - Hold then drag on an image to comment on an exact rectangular area. Relay
139
- saves the crop beside the browser-board record and returns its path; comparison
140
- crops also identify and capture the selected Before/After source.
141
- - Browser boards support `responseRequired:false` / `--display-only`; inline
142
- `relay_show` is display-only by default. Board and waiter deadlines now default
143
- to one day (`--timeout 0` removes Relay's deadline), with client-specific
144
- background/polling guidance in the agent docs.
145
-
146
- ### 0.11.0 — render inline inside the Claude & Codex apps (MCP App)
147
- - **`rly mcp` — relay as an MCP App** ([SEP-1865](https://modelcontextprotocol.io/seps/1865-mcp-apps-interactive-user-interfaces-for-mcp),
148
- extension `io.modelcontextprotocol/ui`). A stdio MCP server with no npm runtime dependencies
149
- that declares a `ui://relay/board` resource (`text/html;profile=mcp-app`) and
150
- two tools, **`relay_ask`** and **`relay_show`**, linked to it via
151
- `_meta.ui.resourceUri` (plus `openai/outputTemplate` for ChatGPT/Codex). The
152
- host renders the board **inline in the conversation** — Claude desktop **and
153
- mobile**, Codex — instead of opening a browser tab.
154
- - **Same board, postMessage transport.** The inline board reuses relay's block
155
- renderer (markdown, code, diff, table, chart, mermaid, graphviz, image, html)
156
- over the MCP Apps JSON-RPC bridge: the spec arrives as the tool result, the
157
- user's submit goes back via `ui/message` so the agent resumes, the structured
158
- payload is also offered through `ui/update-model-context`, the iframe
159
- auto-sizes via `ui/notifications/size-changed`, and vendored Chart.js /
160
- Mermaid / Viz.js load on demand through the host's `resources/read` (no
161
- `/vendor` route, no server in the sandbox).
162
- - **One-command setup** — `rly mcp install --target claude|codex` writes the
163
- host config; `rly mcp config` prints the snippet for any MCP host. The classic
164
- browser board is untouched.
165
- - **Streamable HTTP transport for web/mobile/remote** — `rly mcp --http
166
- [--port N --host H --token SECRET --allow-origin ORIGIN]` serves the same tools
167
- over MCP's Streamable HTTP transport (single `/mcp` endpoint, JSON responses,
168
- CORS, Origin validation, bearer auth, `Mcp-Session-Id`, `$PORT`-aware). relay is
169
- **stateless**, so one instance serves everyone — deploy it once with the repo
170
- **`Dockerfile`** on any free MCP host (mcpdeploy.dev, mcphosting.io,
171
- Render/Railway/Fly, Glama) or publish to **Smithery**, then add the URL as a
172
- custom connector. Only the relay CLI is required — no tunnel/tailscale. stdio
173
- stays the zero-setup path for local desktop.
174
- - **Native look** — the inline board **color-blends** onto the host's SEP-1865
175
- style variables (surfaces, text, borders, primary button, fonts), pins
176
- `color-scheme` so `light-dark()` tokens resolve, and uses the host's **own
177
- full-screen** control (centering content to a readable column in fullscreen).
178
- After submit it collapses to a one-line confirmation so the iframe shrinks.
179
- - **Progressive rendering** — when the host streams the tool call
180
- (`ui/notifications/tool-input-partial`), the board renders valid blocks as they
181
- arrive (a "Composing…" preview) instead of waiting for the whole spec.
182
- - **`palette` block** — color palettes as swatch cards (hover reveals hex, click
183
- copies); mark one `featured` for a spotlight. **`color` question type** — native
184
- picker + hex field + optional `presets`, returns a hex string. Both work on the
185
- browser board and inline.
186
- - **Element annotations inline** — comment on chart points, diagram nodes, table
187
- cells, images and text selections in the MCP board too, returned in
188
- `annotations` exactly like the CLI board.
189
-
190
- ### 0.10.0 — open files, richer code, diffs & video
191
- - **Clickable local file-links.** Write a path in any markdown (`~/clip.mp4`,
192
- `./src/app.ts`, `/abs/report.pdf`, a `file://` URL, a backtick-wrapped path,
193
- or `[label](path)`) and it renders as a link that opens the file in the OS
194
- default app — guarded by a same-origin check + an allowlist of paths the
195
- board actually references. `RLY_OPEN_CMD` overrides the opener.
196
- - **`code` blocks leveled up** — syntax highlighting for ~20 languages (js, ts,
197
- py, go, rust, java, c, cpp, csharp, ruby, php, swift, kotlin, sql, yaml, json,
198
- sh, css, html…), a line-number gutter, a filename/lang header, and `codeFile`
199
- to load source straight from a local file.
200
- - **`diff` block** — render a unified git diff as a colored, line-numbered
201
- comparison with a live **Unified ⇄ Split (side-by-side)** toggle. No git
202
- required; the agent supplies the diff text (`diff`/`diffFile`, `view`).
203
- - **`video` block** — YouTube/Vimeo embeds, a direct media URL, or a local
204
- video file streamed from the server with HTTP Range (seekable), never
205
- embedded in the payload.
206
- - **`pdf` block** — render local `.pdf` files or PDF URLs inline. Local PDFs
207
- stream from the board server and are never embedded in the page payload.
208
- - **Durable boards / rescue** — detached boards keep serving after timeout
209
- until Submit or `rly stop`; every autosave mirrors to `localStorage`; a board
210
- whose connection drops blocks further input instead of losing it, and
211
- `rly rescue <id>` re-serves on the same port so an open tab reconnects. Active
212
- same-Wi-Fi share links stay tied to the board and survive a same-port re-serve
213
- until revoked. Reviewer submissions are isolated, reference-only side reviews
214
- that never finish the owner's board; read-only links cannot mutate feedback.
215
- - Still **zero npm runtime dependencies**, offline, and cross-platform. Vendored
216
- browser libraries are loaded only for boards that need them.
217
-
218
- ### 0.9.1
219
- - The board **intro renders as markdown** (bold/italic/code/links/lists).
220
-
221
- ### 0.9.0 — interactive visual annotations
222
- - Drag/zoom/full-screen viewer, per-element **and** whole-block comments, chart
223
- data-point comment badges, and inline-SVG PlantUML rendering.
224
-
225
- ### 0.8.1
226
- - `rly install` adds **OpenCode** (`~/.config/opencode/AGENTS.md`) and **Droid /
227
- Factory** (`~/.factory/AGENTS.md`) targets.
228
- - README documents `rly install` and `rly upgrade`.
229
-
230
- ### 0.8.0 — install into any agent
231
- - **`rly install --target <agent>`** writes relay's usage rules into the right
232
- file for Claude Code, Codex, Cursor, GitHub Copilot (VS Code / Visual Studio /
233
- JetBrains), Kiro, Windsurf, Cline, Gemini, or the generic `AGENTS.md` —
234
- cross-platform (macOS / Linux / Windows), idempotent, with `--all`, `--scope`,
235
- and `--print`.
236
- - Fixed `rly skill install` crashing when the target skill dir was a symlink.
237
-
238
- ### 0.7.0 — sturdier boards, self-update
239
- - **Markdown blocks render GFM tables**; element comments moved to an
240
- Outline-style right sidebar with inline highlights on commented text.
241
- - **Seamless timeouts** — a detached board that runs past its deadline keeps
242
- serving until Submit or explicit stop, so you can still submit (it lands as
243
- `submitted`); the page shows a calm note instead of disconnecting.
244
- - **`rly upgrade`** — install the latest CLI and refresh the skill in one step.
245
- - Per-question notes are multi-line textboxes.
246
-
247
- ### 0.6.0 — comment on anything
248
- - **Comment on any part of a custom-HTML mockup.** Hover any element — a heading,
249
- a button, a card, the price — and a pin appears to leave an inline note. No
250
- setup needed; the agent writes zero annotation code. Want to scope it? Mark
251
- specific elements with `data-relay-annotate="label"`.
252
- - **Radio questions can carry a note.** Pick an option *and* say why, in one
253
- optional field — now shown by default (set `"note": false` to hide it).
254
- - **Edge-to-edge fullscreen** for charts and HTML mockups, with the toolbar
255
- pinned to the top while you scroll.
256
- - The board **title and intro are commentable** too.
257
-
258
- ### 0.5.0
259
- - Visual answer options, image blocks, viewer redesign, adoption rules.
53
+ ```text
54
+ Use Relay to show work or collect visual feedback. Install the CLI with
55
+ `npm i -g @khanglvm/relay` if missing. Run `rly agent` for the board format.
56
+ Create with `rly ask --file spec.json --detach`, then use `rly wait <board-id>`
57
+ to collect answers. On timeout, check `rly result <board-id>` before continuing.
58
+ ```
260
59
 
261
- ## Migration from quest-board
60
+ To make this a standing preference, `rly install --target codex` adds Relay
61
+ rules to Codex's instruction file. Run `rly install` to see other targets.
262
62
 
263
- relay was formerly `@khanglvm/quest-board` (CLI: `qbd`) — that package is
264
- deprecated. Storage moved from `~/.quest-board` to `~/.relay` (override with
265
- `RLY_HOME`); legacy `"html"` / `"htmlFile"` spec fields keep working.
63
+ ## More help
266
64
 
267
- ## License
65
+ - [Setup and MCP Apps](docs/SETUP.md): agent configuration, in-chat boards, sharing, and updates.
66
+ - [Agent guide](docs/AGENT.md): board examples, block types, and JSON schemas; also available as `rly agent`.
67
+ - `rly help` lists commands. `rly upgrade` updates the CLI and skill.
68
+ - [Changelog](CHANGELOG.md) · [MIT license](LICENSE)
268
69
 
269
- [MIT](LICENSE) © Le Vu Minh Khang
70
+ For development, clone the repo and run `npm test`. The smoke tests use local
71
+ servers and do not require external services.
package/docs/SETUP.md ADDED
@@ -0,0 +1,74 @@
1
+ # Relay setup
2
+
3
+ [Back to the README](../README.md)
4
+
5
+ ## Agent instructions
6
+
7
+ Install the CLI and bundled skill:
8
+
9
+ ```sh
10
+ npm i -g @khanglvm/relay
11
+ npx skills add khanglvm/relay --skill relay --all
12
+ ```
13
+
14
+ To add Relay usage rules to an agent's instruction file:
15
+
16
+ ```sh
17
+ rly install --target codex
18
+ ```
19
+
20
+ Run `rly install` to list supported targets and paths. Use `--all` for all
21
+ detected agents, `--scope project` for project instructions, or `--print`
22
+ to inspect the rules first.
23
+
24
+ `rly upgrade` updates the CLI and refreshes the skill, leaving open boards
25
+ running. It supports `--dry-run`, `--cli-only`, and `--skill-only`.
26
+
27
+ ## Boards inside a chat app
28
+
29
+ Relay can serve boards through MCP Apps. A host that supports MCP Apps can
30
+ render the board inside the conversation. Register the server for your client:
31
+
32
+ ```sh
33
+ claude mcp add relay -- rly mcp
34
+ rly mcp install --target claude
35
+ rly mcp install --target codex
36
+ ```
37
+
38
+ The first command configures Claude Code; the others write Claude Desktop
39
+ and Codex config respectively. Use `rly mcp config` to print config snippets.
40
+ The server exposes `relay_ask` for feedback and `relay_show` for display.
41
+
42
+ For remote clients, `rly mcp --http` serves Streamable HTTP. Run `rly help`
43
+ for host, port, token, and origin flags. The repo includes a `Dockerfile`.
44
+ See the [agent guide](AGENT.md) for board schemas, transport details,
45
+ and host requirements.
46
+
47
+ ## More commands
48
+
49
+ | Command | Use it to |
50
+ | --- | --- |
51
+ | `rly view <file.md>` | Read local Markdown, tables, or PDFs in a board |
52
+ | `rly diff --staged` | Review a staged Git diff |
53
+ | `rly git pick` / `rly git cherry-pick` | Choose commits and their order; add `--code` for per-hunk review |
54
+ | `rly git conflict [files…]` | Review conflict hunks and return resolved text |
55
+ | `rly share <board-id>` | Manage links for collaborators or reviewers on the same Wi-Fi |
56
+ | `rly show --file spec.json --display-only` | Display a board without requiring feedback |
57
+ | `rly rescue <board-id>` | Restore a disconnected board on its original port |
58
+ | `rly agent` | Read the full guide to blocks, annotations, and agent workflows |
59
+ | `rly schema` | Print the board JSON Schema |
60
+
61
+ Boards autosave answers and comments. Detached boards keep serving after
62
+ a wait times out, until submission or `rly stop <board-id>`. Multiple boards
63
+ can run at once.
64
+
65
+ Relay has no npm runtime dependencies. It bundles the browser libraries for
66
+ charts and diagrams and loads them only when a board needs them. Local
67
+ file links open referenced paths in the default app; `RLY_OPEN_CMD` overrides
68
+ the opener.
69
+
70
+ ## Migration from quest-board
71
+
72
+ relay was formerly `@khanglvm/quest-board` (CLI: `qbd`) — that package is
73
+ deprecated. Storage moved from `~/.quest-board` to `~/.relay` (override with
74
+ `RLY_HOME`); legacy `"html"` / `"htmlFile"` spec fields keep working.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanglvm/relay",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Question boards with rich blocks (markdown, charts, mermaid, tables, code, diffs, video, sandboxed HTML), clickable local file-links, and element-level annotations for AI coding agents (Claude Code, Codex, …): ask users structured questions, present interactive visuals, collect inline comments, read answers as JSON — in a local browser board OR rendered INLINE inside the Claude & Codex apps as an MCP App (SEP-1865).",
5
5
  "keywords": [
6
6
  "ai-agents",
package/src/ui/blocks.css CHANGED
@@ -846,18 +846,23 @@ body.blk-space-pan .blk-has-regions.blk-pannable * { cursor: grab !important; }
846
846
  background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
847
847
  }
848
848
  .blk-tools .tool-comment.has-comment:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-fg); }
849
- .blk-tools .tool-region {
849
+ .blk-tools .tool-region,
850
+ .blk-tools .tool-hover-comments {
850
851
  display: inline-flex; align-items: center; gap: 5px;
851
852
  }
852
- .blk-tools .tool-region svg { display: block; }
853
- .blk-tools .tool-region.is-active {
853
+ .blk-tools .tool-region svg,
854
+ .blk-tools .tool-hover-comments svg { display: block; }
855
+ .blk-tools .tool-region.is-active,
856
+ .blk-tools .tool-hover-comments.is-active {
854
857
  background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
855
858
  }
856
- .blk-tools .tool-region.is-active:hover {
859
+ .blk-tools .tool-region.is-active:hover,
860
+ .blk-tools .tool-hover-comments.is-active:hover {
857
861
  background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-fg);
858
862
  }
859
863
  @media (max-width: 520px) {
860
- .blk-tools .tool-region-label { display: none; }
864
+ .blk-tools .tool-region-label,
865
+ .blk-tools .tool-hover-label { display: none; }
861
866
  }
862
867
 
863
868
  /* code blocks reuse the viewer toolbar (comment + full-screen); the pre keeps
package/src/ui/blocks.js CHANGED
@@ -2483,6 +2483,9 @@
2483
2483
  '<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
2484
2484
  '<rect x="3" y="4" width="14" height="12" rx="2" stroke-dasharray="3 2"/>' +
2485
2485
  '<path d="M14 14.5h6.5v4H18l-2.5 2v-2H14z" fill="currentColor" stroke="none"/></svg>';
2486
+ const ICON_EYE =
2487
+ '<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
2488
+ '<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"/><circle cx="12" cy="12" r="3"/></svg>';
2486
2489
 
2487
2490
  function exitFull() {
2488
2491
  if (!fullOpen) return;
@@ -2784,6 +2787,30 @@
2784
2787
  }
2785
2788
  }
2786
2789
 
2790
+ if (opts && opts.comment && opts.hoverComments) {
2791
+ const hoverCtl = opts.hoverComments;
2792
+ const hoverBtn = el('button', {
2793
+ class: 'tool-hover-comments',
2794
+ type: 'button',
2795
+ 'aria-label': 'Show element comment overlays',
2796
+ });
2797
+ hoverBtn.innerHTML = ICON_EYE;
2798
+ hoverBtn.append(el('span', { class: 'tool-hover-label' }, 'Hover comments'));
2799
+ const syncHoverMode = () => {
2800
+ const enabled = hoverCtl.isEnabled();
2801
+ hoverBtn.classList.toggle('is-active', enabled);
2802
+ hoverBtn.setAttribute('aria-pressed', String(enabled));
2803
+ hoverBtn.title = enabled ? 'Hide element comment overlays' : 'Show element comment overlays';
2804
+ };
2805
+ hoverBtn.addEventListener('click', (e) => {
2806
+ e.stopPropagation();
2807
+ hoverCtl.setEnabled(!hoverCtl.isEnabled());
2808
+ syncHoverMode();
2809
+ });
2810
+ syncHoverMode();
2811
+ tools.append(hoverBtn);
2812
+ }
2813
+
2787
2814
  if (opts && opts.region) {
2788
2815
  const regionCtl = opts.region;
2789
2816
  const regionLabel = el('span', { class: 'tool-region-label' }, 'Area');
@@ -2894,19 +2921,47 @@
2894
2921
  }
2895
2922
 
2896
2923
  // ---------- html (sandboxed iframe) ----------
2924
+ function syncHtmlHoverComments(frame) {
2925
+ try {
2926
+ frame.contentWindow.postMessage({ relay: 'annotate-hover', enabled: frame.dataset.relayHoverComments !== 'off' }, '*');
2927
+ } catch (_) {}
2928
+ }
2929
+
2930
+ // The kit can load after the iframe's load event; its ready message also
2931
+ // restores the current toggle when the embedded page reloads.
2932
+ window.addEventListener('message', (e) => {
2933
+ if (!e.data || e.data.relay !== 'annotate-ready') return;
2934
+ for (const frame of document.querySelectorAll('iframe.viz[data-relay-hover-comments]')) {
2935
+ if (frame.contentWindow === e.source) { syncHtmlHoverComments(frame); break; }
2936
+ }
2937
+ });
2938
+
2897
2939
  function renderHtml(block, ctx, blockId) {
2898
2940
  const height = clampHeight(block.height, 360);
2899
2941
  const iframe = el('iframe', {
2900
2942
  class: 'viz',
2901
2943
  'data-block-id': blockId,
2902
2944
  'data-question-id': ctx.questionId || '',
2945
+ 'data-relay-hover-comments': 'on',
2903
2946
  src: ctx.htmlSrc(blockId),
2904
2947
  height: String(height),
2905
2948
  sandbox: 'allow-scripts allow-forms allow-popups allow-modals',
2906
2949
  loading: 'lazy',
2907
2950
  });
2951
+ iframe.addEventListener('load', () => syncHtmlHoverComments(iframe));
2908
2952
  const wrap = el('div', { class: 'blk-htmlwrap' }, iframe);
2909
- attachViewer(wrap, { zoomEl: null, label: 'embed', comment: wholeBlockComment(ctx, blockId, 'embed') });
2953
+ attachViewer(wrap, {
2954
+ zoomEl: null,
2955
+ label: 'embed',
2956
+ comment: wholeBlockComment(ctx, blockId, 'embed'),
2957
+ hoverComments: {
2958
+ isEnabled: () => iframe.dataset.relayHoverComments !== 'off',
2959
+ setEnabled: (enabled) => {
2960
+ iframe.dataset.relayHoverComments = enabled ? 'on' : 'off';
2961
+ syncHtmlHoverComments(iframe);
2962
+ },
2963
+ },
2964
+ });
2910
2965
  return wrap;
2911
2966
  }
2912
2967
 
package/src/ui/kit.js CHANGED
@@ -401,6 +401,7 @@
401
401
  let started = false;
402
402
  let hot = null; // currently outlined element
403
403
  let pin = null; // floating pin button
404
+ let hoverEnabled = true;
404
405
  let hideTimer = 0;
405
406
  let lastCounts = {};
406
407
  let overlayBadges = []; // [{el, badge}] for replaced elements
@@ -453,18 +454,25 @@
453
454
  function ensurePin() {
454
455
  if (pin || !document.body) return pin;
455
456
  pin = document.createElement('button');
457
+ pin.className = 'relay-ann-pin';
456
458
  pin.type = 'button';
457
459
  pin.setAttribute('aria-label', 'Add a comment');
458
460
  pin.title = 'Add a comment';
459
461
  pin.style.cssText = [
460
- 'position:fixed', 'z-index:2147483647', 'display:none', 'width:22px', 'height:22px',
462
+ 'all:initial', 'position:fixed', 'z-index:2147483647', 'display:none', 'width:22px', 'height:22px',
463
+ 'box-sizing:border-box', 'margin:0',
461
464
  'padding:0', 'border:none', 'border-radius:50%', 'cursor:pointer', 'background:' + accent(),
462
465
  'color:#fff', 'align-items:center', 'justify-content:center', 'line-height:0',
463
466
  'box-shadow:0 1px 4px rgba(0,0,0,.3)',
464
- ].join(';');
467
+ ].map((rule) => rule + ' !important').join(';');
465
468
  pin.innerHTML =
466
469
  '<svg viewBox="0 0 16 16" width="11" height="11" aria-hidden="true">' +
467
470
  '<path d="M3 2.5h10A1.5 1.5 0 0 1 14.5 4v5a1.5 1.5 0 0 1-1.5 1.5H8.4L5 13.4v-2.9H3A1.5 1.5 0 0 1 1.5 9V4A1.5 1.5 0 0 1 3 2.5Z" fill="currentColor"/></svg>';
471
+ pin.querySelector('svg').style.cssText =
472
+ 'all:initial !important;display:block !important;width:11px !important;height:11px !important;fill:currentColor !important;color:inherit !important;';
473
+ pin.querySelector('path').style.setProperty('fill', 'currentColor', 'important');
474
+ pin.addEventListener('focus', () => pin.style.setProperty('outline', '2px solid ' + accent(), 'important'));
475
+ pin.addEventListener('blur', () => pin.style.removeProperty('outline'));
468
476
  pin.addEventListener('mouseenter', () => clearTimeout(hideTimer));
469
477
  pin.addEventListener('mouseleave', scheduleHide);
470
478
  pin.addEventListener('click', (e) => {
@@ -478,16 +486,16 @@
478
486
  }
479
487
 
480
488
  function showPinFor(el) {
481
- if (!ensurePin()) return;
489
+ if (!hoverEnabled || !ensurePin()) return;
482
490
  clearTimeout(hideTimer);
483
491
  if (hot && hot !== el) hot.classList.remove('relay-ann-hot');
484
492
  hot = el;
485
493
  el.classList.add('relay-ann-hot');
486
494
  const r = el.getBoundingClientRect();
487
495
  const w = 22;
488
- pin.style.display = 'flex';
489
- pin.style.left = Math.max(2, Math.min(r.right - w / 2, window.innerWidth - w - 2)) + 'px';
490
- pin.style.top = Math.max(2, Math.min(r.top - w / 2, window.innerHeight - w - 2)) + 'px';
496
+ pin.style.setProperty('display', 'flex', 'important');
497
+ pin.style.setProperty('left', Math.max(2, Math.min(r.right - w / 2, window.innerWidth - w - 2)) + 'px', 'important');
498
+ pin.style.setProperty('top', Math.max(2, Math.min(r.top - w / 2, window.innerHeight - w - 2)) + 'px', 'important');
491
499
  }
492
500
 
493
501
  function scheduleHide() {
@@ -499,7 +507,7 @@
499
507
  clearTimeout(hideTimer);
500
508
  if (hot) hot.classList.remove('relay-ann-hot');
501
509
  hot = null;
502
- if (pin) pin.style.display = 'none';
510
+ if (pin) pin.style.setProperty('display', 'none', 'important');
503
511
  }
504
512
 
505
513
  // Ask the parent to open its annotation popover for this element.
@@ -631,8 +639,13 @@
631
639
  }, true);
632
640
  window.addEventListener('resize', () => { hidePin(); repositionOverlays(); });
633
641
  window.addEventListener('message', (e) => {
642
+ if (e.source !== parent) return;
634
643
  const m = e.data;
635
644
  if (m && typeof m === 'object' && m.relay === 'annotate-counts') renderBadges(m.counts || {});
645
+ if (m && typeof m === 'object' && m.relay === 'annotate-hover' && typeof m.enabled === 'boolean') {
646
+ hoverEnabled = m.enabled;
647
+ if (!hoverEnabled) hidePin();
648
+ }
636
649
  });
637
650
  // Re-pick up DOM that author JS builds after load. We observe childList
638
651
  // only (not attributes, so our own hover-class toggles don't fire it) and