@nxxxsooo/opencode-annotate 0.17.1 → 0.19.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/CHANGELOG.md +20 -0
- package/README.md +10 -4
- package/browser/capture.js +248 -40
- package/browser/inspector.js +66 -1
- package/browser/manifest.json +1 -1
- package/browser/panel.css +2 -2
- package/browser/panel.html +1 -1
- package/browser/panel.mjs +82 -16
- package/browser/protocol.mjs +27 -8
- package/browser/worker.mjs +123 -36
- package/package.json +1 -1
- package/review.mjs +75 -11
- package/tui/bin/darwin-arm64/annotate-tui +0 -0
- package/tui/bin/darwin-x64/annotate-tui +0 -0
- package/tui/bin/linux-arm64/annotate-tui +0 -0
- package/tui/bin/linux-x64/annotate-tui +0 -0
- package/tui/bin/win32-x64/annotate-tui.exe +0 -0
- package/tui.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.19.0 — Annotate files
|
|
4
|
+
|
|
5
|
+
- Choose **Annotate a file (TUI)** or run `/annotate-file [query]` to find text
|
|
6
|
+
and config files in the current session's directory using OpenCode's `@`
|
|
7
|
+
file search.
|
|
8
|
+
- Pass a supported file path directly to `/annotate` as before. Non-Markdown
|
|
9
|
+
files display as code blocks, preserving their formatting. `.env` and
|
|
10
|
+
credential-looking filenames are excluded.
|
|
11
|
+
|
|
12
|
+
## 0.18.0 — Select page areas
|
|
13
|
+
|
|
14
|
+
- Choose **Select area** in the browser panel and drag a rectangle. Feedback
|
|
15
|
+
includes page coordinates, visible text and element selectors when available.
|
|
16
|
+
No screenshot is captured.
|
|
17
|
+
- Unsent areas keep their numbered outlines when you scroll, reload or return
|
|
18
|
+
to the page. Select an outline to move or resize it and refresh its evidence
|
|
19
|
+
without changing the note number.
|
|
20
|
+
- Reload the Chrome extension and restart OpenCode after updating for browser
|
|
21
|
+
protocol 10.
|
|
22
|
+
|
|
3
23
|
## 0.17.1 — picking inside modal drawers
|
|
4
24
|
|
|
5
25
|
- Keep element highlights, saved-note markers and reveal outlines visible above
|
package/README.md
CHANGED
|
@@ -63,15 +63,19 @@ Empty and cancelled reviews submit nothing. Opening a review makes no model call
|
|
|
63
63
|
|
|
64
64
|
For a selection that spans messages, `/annotate-selection` reviews just the selected text.
|
|
65
65
|
|
|
66
|
-
### Review
|
|
66
|
+
### Review text and config files
|
|
67
67
|
|
|
68
68
|
```text
|
|
69
69
|
/annotate docs/plan.md # Review a Markdown document
|
|
70
70
|
/annotate "docs/release plan.md" # Path with spaces
|
|
71
71
|
/annotate ~/Documents/notes.txt # Plain text
|
|
72
|
+
/annotate-file # Pick a file from this session's directory
|
|
73
|
+
/annotate-file settings # Narrow the file search
|
|
72
74
|
```
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
`/annotate-file` uses OpenCode's `@` file search in the session's directory and its subdirectories, then lets you filter the results in the picker. You can also pass a supported path directly to `/annotate`.
|
|
77
|
+
|
|
78
|
+
Supported files include Markdown, plain text, CSV, logs, JSON, YAML, TOML, XML, and common config files such as `.editorconfig`, `.gitignore`, `Dockerfile`, and `Makefile`. Files must be local UTF-8 and no larger than 2 MiB. `.env` and credential-looking names are excluded. Relative paths resolve against the captured session's working directory; absolute and `~/` paths work too.
|
|
75
79
|
|
|
76
80
|
The reviewer reads a fixed snapshot and does not edit the original file. Feedback includes the original path and snapshot hash, with instructions to re-read the current file before applying suggestions. Document review works even before the session has an assistant reply.
|
|
77
81
|
|
|
@@ -99,6 +103,7 @@ Browser setup is separate from the plugin install. Safari supports local notes a
|
|
|
99
103
|
/annotate docs/plan.md Review a Markdown document
|
|
100
104
|
/annotate "docs/release plan.md" Review a path containing spaces
|
|
101
105
|
/annotate ~/Documents/notes.txt Review a plain-text document
|
|
106
|
+
/annotate-file [query] Choose a text or config file in the session directory
|
|
102
107
|
/annotate-pick Choose a recent reply or mid-turn progress update
|
|
103
108
|
/annotate-selection Review the message containing your last transcript selection
|
|
104
109
|
/annotate page.html Review local HTML in the configured browser
|
|
@@ -197,7 +202,7 @@ After updates, run `npm run build:safari` with the signing variables again, then
|
|
|
197
202
|
|
|
198
203
|
Click the destination beside **To** to filter sessions by title or directory and sort by recent activity, creation or title. The picker refreshes automatically and shows current session titles. **New session** creates an empty session with the chosen session's location/model, or the blank OpenCode home's current selection, without starting a model turn. **Disconnect** keeps the destination named and notes local; choosing that session again reconnects. A disconnected destination never silently switches to another session. Restarted receivers reconnect by stable provider/session identity, carrying any retry batch to the replacement.
|
|
199
204
|
|
|
200
|
-
Choose **Pick element** or select text, then write a comment or question.
|
|
205
|
+
Choose **Pick element**, drag a rectangle with **Select area**, or select text directly, then write a comment or question. Unsent areas stay marked: click a dashed outline or badge to activate it, drag the rectangle to move it, or drag a handle to resize. Esc cancels an adjustment. Area notes include the rectangle's position, visible text, and element hints, without a screenshot. **Send N notes & continue** saves current feedback and sends all pending notes across pages; **Add note** collects feedback locally. Cmd/Ctrl+Enter adds a note or saves an edit. Confirmed sends use `steer` / `resume: true`: idle sessions start immediately and running turns receive feedback at their next processing boundary. Registering, creating sessions and saving notes make no model call. Switching terminal tabs never changes the captured destination.
|
|
201
206
|
|
|
202
207
|
The queue groups notes by page, with contiguous numbers matching page markers and delivered Markdown. Click a note's quoted target to show it on its page without activating the element; off-page notes can open their page. **Edit** changes the feedback, and **Undo** restores a deleted note. The delivery bar shows the whole round's count and destination; drafts remain page-local.
|
|
203
208
|
|
|
@@ -211,7 +216,7 @@ After a page reload or same-site navigation, the panel reconnects its page tools
|
|
|
211
216
|
|
|
212
217
|
### Explicit routing
|
|
213
218
|
|
|
214
|
-
Plain `/annotate`, `/annotate-pick` and `/annotate-selection` use the TUI;
|
|
219
|
+
Plain `/annotate`, `/annotate-file`, `/annotate-pick` and `/annotate-selection` use the TUI; text and config paths do too. Explicit URLs and HTML paths passed to `/annotate` enter the browser workflow. A reply containing HTML links or code fences does not change the default.
|
|
215
220
|
|
|
216
221
|
### Browser safeguards and limitations
|
|
217
222
|
|
|
@@ -366,6 +371,7 @@ See [release instructions](docs/releasing.md) and [changelog](CHANGELOG.md).
|
|
|
366
371
|
|
|
367
372
|
- `/annotate`:批注上一条完整回复。
|
|
368
373
|
- `/annotate 文档.md`:批注文档,支持中文、空格和相对路径。
|
|
374
|
+
- `/annotate-file [关键词]`:从当前会话目录及其子目录中选择文本或配置文件。
|
|
369
375
|
- `/annotate-pick`:从最近的回复和运行中的进度说明里选一条批注。
|
|
370
376
|
- `/annotate-selection`:先在会话里拖选文字,再批注包含这段文字的消息。
|
|
371
377
|
- 0.16.0 移除 `/ref` 和代理会话搜索/读取工具,交由 Another 提供跨代理引用:安装 Another 0.28.0 或更高版本并运行 `another setup` 即可。原有插件配置继续有效,请移除 `annotate_session_*` 权限规则。
|
package/browser/capture.js
CHANGED
|
@@ -1,30 +1,56 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
if (globalThis.__opencodeAnnotate === true) throw new Error("Refresh this page once to update annotation tools. Saved notes will remain.")
|
|
3
|
-
if (globalThis.__opencodeAnnotate?.version ===
|
|
3
|
+
if (globalThis.__opencodeAnnotate?.version === 10) return
|
|
4
4
|
globalThis.__opencodeAnnotate?.dispose()
|
|
5
5
|
if (!["text/html", "application/xhtml+xml"].includes(document.contentType)) throw new Error("Only HTML pages are supported")
|
|
6
6
|
const listeners = new AbortController()
|
|
7
7
|
const on = (target, event, handler, options = {}) => target.addEventListener(event, handler, { ...options, signal: listeners.signal })
|
|
8
8
|
const host = document.createElement("div")
|
|
9
9
|
host.setAttribute("data-opencode-annotate", "")
|
|
10
|
-
|
|
11
|
-
//
|
|
10
|
+
host.setAttribute("aria-hidden", "true")
|
|
11
|
+
// A manual popover keeps viewport coordinates even under a transformed dialog.
|
|
12
12
|
host.setAttribute("popover", "manual")
|
|
13
13
|
host.style.cssText = "all:initial!important;position:fixed!important;inset:0!important;pointer-events:none!important;z-index:2147483647!important"
|
|
14
14
|
const root = host.attachShadow({ mode: "closed" })
|
|
15
15
|
const style = document.createElement("style")
|
|
16
|
-
style.textContent =
|
|
16
|
+
style.textContent = `
|
|
17
|
+
.box{position:fixed;pointer-events:none;border:2px solid #c96442;background:#c9644210}
|
|
18
|
+
.area{box-sizing:border-box}
|
|
19
|
+
.pin{position:fixed;display:grid;place-items:center;background:#c96442;color:#fff;border:2px solid #fff;border-radius:50%;font:600 12px/1 system-ui;width:26px;height:26px;pointer-events:none}
|
|
20
|
+
.area-mark{border-style:dashed}
|
|
21
|
+
.area-mark.is-active{border-style:solid;z-index:1}
|
|
22
|
+
.area-mark .pin,.edge,.handle{position:absolute;touch-action:none}
|
|
23
|
+
.area-mark .pin{left:-12px;top:-12px}
|
|
24
|
+
.edge[data-side="n"],.edge[data-side="s"]{left:0;right:0;height:4px}
|
|
25
|
+
.edge[data-side="w"],.edge[data-side="e"]{top:0;bottom:0;width:4px}
|
|
26
|
+
.edge[data-side="n"]{top:-3px}.edge[data-side="s"]{bottom:-3px}
|
|
27
|
+
.edge[data-side="w"]{left:-3px}.edge[data-side="e"]{right:-3px}
|
|
28
|
+
.handle{width:8px;height:8px;border:1px solid #c96442;background:#fff;transform:translate(-50%,-50%)}
|
|
29
|
+
.area-layer:not(.passive) .area-mark.is-active,.area-layer:not(.passive) :is(.edge,.pin,.handle){pointer-events:auto;cursor:move;touch-action:none}
|
|
30
|
+
`
|
|
17
31
|
root.append(style); document.documentElement.append(host)
|
|
32
|
+
const areaLayer = document.createElement("div"); areaLayer.className = "area-layer"; root.append(areaLayer)
|
|
18
33
|
const box = document.createElement("div"); box.className = "box"
|
|
19
34
|
const highlight = document.createElement("div"); highlight.className = "box"
|
|
35
|
+
const shield = document.createElement("div")
|
|
36
|
+
shield.style.cssText = "position:fixed;inset:0;pointer-events:auto;cursor:crosshair;touch-action:none"
|
|
20
37
|
let highlighted, highlightTimer
|
|
21
|
-
|
|
38
|
+
const MIN_AREA = 5
|
|
39
|
+
let mode = null, areaEvents, drag, areaDrag, url = location.href, timer, markers = [], active = true
|
|
40
|
+
let draftMarker, markerFocus, markerKey
|
|
22
41
|
let modals = []
|
|
23
42
|
function syncLayer(force = false) {
|
|
24
43
|
const next = [...document.querySelectorAll("dialog:modal")]
|
|
25
|
-
|
|
26
|
-
|
|
44
|
+
// Hit testing through the backdrop finds the top modal even when another
|
|
45
|
+
// modal follows it in DOM order. The active modal's subtree is the only
|
|
46
|
+
// place where top-layer area controls can receive pointer events.
|
|
47
|
+
const modal = next.length > 1 ? document.elementFromPoint(0, 0)?.closest("dialog:modal") || next.at(-1) : next[0]
|
|
48
|
+
const parent = modal || document.documentElement
|
|
49
|
+
const move = host.parentElement !== parent
|
|
50
|
+
const changed = move || force || next.length !== modals.length || next.some((node, index) => node !== modals[index])
|
|
51
|
+
if (changed && mode === "element") box.remove()
|
|
27
52
|
if (changed && host.matches(":popover-open")) host.hidePopover()
|
|
53
|
+
if (move) parent.append(host)
|
|
28
54
|
if (!host.matches(":popover-open")) host.showPopover()
|
|
29
55
|
modals = next
|
|
30
56
|
}
|
|
@@ -32,18 +58,152 @@
|
|
|
32
58
|
function send(anchor = null, error = null, modeOnly = false, ready = false) {
|
|
33
59
|
if (!active) return
|
|
34
60
|
try {
|
|
35
|
-
chrome.runtime.sendMessage({ action: "capture", page: { url: location.href, title: document.title }, frame: AnnotateInspector.frame(), anchor, error,
|
|
61
|
+
chrome.runtime.sendMessage({ action: "capture", page: { url: location.href, title: document.title }, frame: AnnotateInspector.frame(), anchor, error, mode, modeOnly, ready }).catch(dispose)
|
|
36
62
|
} catch { dispose() }
|
|
37
63
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
64
|
+
function setMode(value, notify = true) {
|
|
65
|
+
if (mode === value) return
|
|
66
|
+
areaEvents?.abort(); areaEvents = null
|
|
67
|
+
clearDrag(); shield.remove(); box.remove()
|
|
68
|
+
cancelAdjust()
|
|
69
|
+
mode = value
|
|
70
|
+
areaLayer.classList.toggle("passive", !!mode)
|
|
71
|
+
box.classList.toggle("area", mode === "area")
|
|
72
|
+
if (mode === "area") startArea()
|
|
43
73
|
if (notify) send(null, null, true)
|
|
44
74
|
}
|
|
75
|
+
const point = event => ({ x: event.clientX, y: event.clientY })
|
|
76
|
+
function documentRect() {
|
|
77
|
+
const x = drag.end.x + scrollX, y = drag.end.y + scrollY
|
|
78
|
+
return { x: Math.round(Math.min(drag.start.x, x)), y: Math.round(Math.min(drag.start.y, y)),
|
|
79
|
+
width: Math.round(Math.abs(drag.start.x - x)), height: Math.round(Math.abs(drag.start.y - y)) }
|
|
80
|
+
}
|
|
81
|
+
const areaRect = ({ rect }) => new DOMRect(rect.x - scrollX, rect.y - scrollY, rect.width, rect.height)
|
|
82
|
+
function paint(node, rect) {
|
|
83
|
+
node.style.cssText = `left:${rect.x}px;top:${rect.y}px;width:${rect.width}px;height:${rect.height}px`
|
|
84
|
+
}
|
|
85
|
+
function clearDrag() {
|
|
86
|
+
if (!drag) return
|
|
87
|
+
const { target, id } = drag
|
|
88
|
+
drag = null
|
|
89
|
+
if (target.hasPointerCapture(id)) target.releasePointerCapture(id)
|
|
90
|
+
box.remove()
|
|
91
|
+
}
|
|
92
|
+
function startArea() {
|
|
93
|
+
areaEvents = new AbortController()
|
|
94
|
+
const listen = (event, handler) => window.addEventListener(event, handler, { capture: true, signal: areaEvents.signal })
|
|
95
|
+
const block = event => { event.preventDefault(); event.stopImmediatePropagation() }
|
|
96
|
+
root.prepend(shield)
|
|
97
|
+
listen("pointerdown", event => {
|
|
98
|
+
block(event)
|
|
99
|
+
if (event.button !== 0 || drag) return
|
|
100
|
+
const target = event.target === host ? shield : event.target
|
|
101
|
+
drag = { id: event.pointerId, target, start: { x: event.clientX + scrollX, y: event.clientY + scrollY }, end: point(event) }
|
|
102
|
+
target.setPointerCapture(drag.id)
|
|
103
|
+
})
|
|
104
|
+
listen("pointermove", event => {
|
|
105
|
+
if (drag?.id !== event.pointerId) return
|
|
106
|
+
block(event)
|
|
107
|
+
drag.end = point(event); drawArea()
|
|
108
|
+
})
|
|
109
|
+
let finishTimer, completed
|
|
110
|
+
const finish = () => {
|
|
111
|
+
clearTimeout(finishTimer)
|
|
112
|
+
if (!completed) return
|
|
113
|
+
const rect = completed; completed = null
|
|
114
|
+
setMode(null, false)
|
|
115
|
+
try { send(captureArea(rect)) } catch (error) { send(null, error.message) }
|
|
116
|
+
}
|
|
117
|
+
listen("pointerup", event => {
|
|
118
|
+
block(event)
|
|
119
|
+
if (drag?.id !== event.pointerId) return
|
|
120
|
+
drag.end = point(event)
|
|
121
|
+
const rect = documentRect()
|
|
122
|
+
clearDrag()
|
|
123
|
+
if (rect.width < MIN_AREA || rect.height < MIN_AREA) return
|
|
124
|
+
completed = rect; finishTimer = setTimeout(finish, 0)
|
|
125
|
+
})
|
|
126
|
+
listen("click", event => { block(event); finish() })
|
|
127
|
+
const cancelDrag = event => { if (drag?.id === event.pointerId) clearDrag() }
|
|
128
|
+
listen("pointercancel", cancelDrag)
|
|
129
|
+
listen("lostpointercapture", cancelDrag)
|
|
130
|
+
listen("keydown", event => { if (event.key === "Escape") { block(event); setMode(null) } })
|
|
131
|
+
areaEvents.signal.addEventListener("abort", () => clearTimeout(finishTimer), { once: true })
|
|
132
|
+
}
|
|
133
|
+
function drawArea() {
|
|
134
|
+
if (!drag) return
|
|
135
|
+
root.append(box)
|
|
136
|
+
paint(box, areaRect({ rect: documentRect() }))
|
|
137
|
+
}
|
|
138
|
+
const captureArea = rect => AnnotateInspector.captureArea(rect, host.closest("dialog:modal") || document.body)
|
|
139
|
+
const directions = ["n", "ne", "e", "se", "s", "sw", "w", "nw"]
|
|
140
|
+
const block = event => { event.preventDefault(); event.stopImmediatePropagation() }
|
|
141
|
+
const docPoint = event => ({ x: event.clientX + scrollX, y: event.clientY + scrollY })
|
|
142
|
+
function adjustRect({ marker, side, start, end }) {
|
|
143
|
+
const { x, y, width, height } = marker.anchor.rect
|
|
144
|
+
const dx = Math.round(end.x + scrollX - start.x), dy = Math.round(end.y + scrollY - start.y)
|
|
145
|
+
if (!side) return { x: x + dx, y: y + dy, width, height }
|
|
146
|
+
const left = side.includes("w") ? Math.min(x + dx, x + width - MIN_AREA) : x
|
|
147
|
+
const right = side.includes("e") ? Math.max(left + MIN_AREA, x + width + dx) : x + width
|
|
148
|
+
const top = side.includes("n") ? Math.min(y + dy, y + height - MIN_AREA) : y
|
|
149
|
+
const bottom = side.includes("s") ? Math.max(top + MIN_AREA, y + height + dy) : y + height
|
|
150
|
+
return { x: left, y: top, width: right - left, height: bottom - top }
|
|
151
|
+
}
|
|
152
|
+
function cancelAdjust(repaint = true) {
|
|
153
|
+
if (!areaDrag) return
|
|
154
|
+
const { id } = areaDrag
|
|
155
|
+
areaDrag = null
|
|
156
|
+
if (areaLayer.hasPointerCapture(id)) areaLayer.releasePointerCapture(id)
|
|
157
|
+
if (repaint) drawAreaMarkers()
|
|
158
|
+
}
|
|
159
|
+
async function areaGesture(action, marker, anchor) {
|
|
160
|
+
try {
|
|
161
|
+
const result = await chrome.runtime.sendMessage({ action, page: { url: location.href }, frame: AnnotateInspector.frame(),
|
|
162
|
+
id: marker.id, revision: marker.revision, baseRect: marker.anchor.rect, anchor })
|
|
163
|
+
if (!result.ok) throw new Error(result.error)
|
|
164
|
+
} catch (error) {
|
|
165
|
+
send(null, error.message, true)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
on(areaLayer, "pointerdown", event => {
|
|
169
|
+
const id = event.target.closest(".area-mark")?.dataset.markerId
|
|
170
|
+
if (mode || !id) return
|
|
171
|
+
block(event)
|
|
172
|
+
if (event.button !== 0 || areaDrag) return
|
|
173
|
+
const marker = id === draftMarker?.id ? draftMarker : markers.find(note => note.id === id)
|
|
174
|
+
if (!marker) return
|
|
175
|
+
const adjustable = event.target.closest(".area-mark").classList.contains("is-active")
|
|
176
|
+
areaDrag = { id: event.pointerId, marker, adjustable, side: event.target.dataset.handle,
|
|
177
|
+
start: docPoint(event), end: point(event) }
|
|
178
|
+
areaLayer.setPointerCapture(event.pointerId)
|
|
179
|
+
})
|
|
180
|
+
on(window, "pointermove", event => {
|
|
181
|
+
if (!areaDrag || areaDrag.id !== event.pointerId) return
|
|
182
|
+
block(event)
|
|
183
|
+
areaDrag.end = point(event)
|
|
184
|
+
if (areaDrag.adjustable) drawAreaMarkers()
|
|
185
|
+
}, { capture: true })
|
|
186
|
+
on(window, "pointerup", event => {
|
|
187
|
+
if (!areaDrag || areaDrag.id !== event.pointerId) return
|
|
188
|
+
block(event)
|
|
189
|
+
const { adjustable, marker } = areaDrag
|
|
190
|
+
areaDrag.end = point(event)
|
|
191
|
+
const rect = adjustRect(areaDrag)
|
|
192
|
+
cancelAdjust()
|
|
193
|
+
if (adjustable && Object.keys(rect).some(key => rect[key] !== marker.anchor.rect[key])) {
|
|
194
|
+
try { void areaGesture("area-adjust", marker, captureArea(rect)) }
|
|
195
|
+
catch (error) { send(null, error.message, true) }
|
|
196
|
+
} else void areaGesture("area-focus", marker)
|
|
197
|
+
}, { capture: true })
|
|
198
|
+
on(window, "click", event => { if (event.target === host && !mode) block(event) }, { capture: true })
|
|
199
|
+
on(window, "keydown", event => {
|
|
200
|
+
if (event.key === "Escape" && areaDrag) { block(event); cancelAdjust() }
|
|
201
|
+
}, { capture: true })
|
|
202
|
+
for (const name of ["pointercancel", "lostpointercapture"]) on(window, name, event => {
|
|
203
|
+
if (areaDrag?.id === event.pointerId) cancelAdjust()
|
|
204
|
+
}, { capture: true })
|
|
45
205
|
function selection() {
|
|
46
|
-
if (
|
|
206
|
+
if (mode || !active) return
|
|
47
207
|
const selected = getSelection()
|
|
48
208
|
if (!selected?.rangeCount || selected.isCollapsed || selected.anchorNode?.getRootNode() !== document) return
|
|
49
209
|
const range = selected.getRangeAt(0).cloneRange()
|
|
@@ -54,7 +214,7 @@
|
|
|
54
214
|
on(document, "selectionchange", () => { clearTimeout(timer); timer = setTimeout(selection, 160) })
|
|
55
215
|
on(document, "pointerup", selection)
|
|
56
216
|
const hover = event => {
|
|
57
|
-
if (
|
|
217
|
+
if (mode !== "element") return
|
|
58
218
|
syncLayer()
|
|
59
219
|
if (["iframe", "frame", "frameset"].includes(event.target.localName)) {
|
|
60
220
|
box.remove()
|
|
@@ -66,37 +226,51 @@
|
|
|
66
226
|
}
|
|
67
227
|
root.append(box)
|
|
68
228
|
const rect = event.target.getBoundingClientRect()
|
|
69
|
-
box
|
|
229
|
+
paint(box, rect)
|
|
70
230
|
}
|
|
71
231
|
on(document, "mousemove", hover, { capture: true })
|
|
72
232
|
on(document, "pointerover", hover, { capture: true })
|
|
73
|
-
on(document, "pointerdown", event => { if (
|
|
233
|
+
on(document, "pointerdown", event => { if (mode === "element") { event.preventDefault(); event.stopImmediatePropagation() } }, { capture: true })
|
|
74
234
|
on(document, "click", event => {
|
|
75
|
-
if (
|
|
235
|
+
if (mode !== "element") return
|
|
76
236
|
if (event.target.localName === "frameset") return
|
|
77
237
|
if (["iframe", "frame"].includes(event.target.localName)) {
|
|
78
238
|
try { if (event.target.contentDocument) { box.remove(); return } } catch { /* inaccessible frame: explain below */ }
|
|
79
239
|
}
|
|
80
240
|
event.preventDefault(); event.stopImmediatePropagation()
|
|
81
241
|
// A failed pick must never leave the page trapped in interception mode.
|
|
82
|
-
|
|
242
|
+
setMode(null, false)
|
|
83
243
|
try { send(AnnotateInspector.capture(event.target)) } catch (error) { send(null, error.message) }
|
|
84
244
|
}, { capture: true })
|
|
85
|
-
on(document, "keydown", event => { if (
|
|
245
|
+
on(document, "keydown", event => { if (mode === "element" && event.key === "Escape") setMode(null) })
|
|
86
246
|
const onMessage = (message, _sender, respond) => {
|
|
87
247
|
if (message.action === "annotate-ping") { respond({ ok: true }); return }
|
|
88
|
-
if (message.action === "pick") {
|
|
89
|
-
if (message.action === "markers") {
|
|
248
|
+
if (message.action === "pick") { setMode(message.mode, false); respond({ ok: true, mode }) }
|
|
249
|
+
if (message.action === "markers") {
|
|
250
|
+
const key = JSON.stringify([message.notes, message.draft, message.focus])
|
|
251
|
+
if (key !== markerKey) {
|
|
252
|
+
markerKey = key; markers = message.notes || []; draftMarker = message.draft; markerFocus = message.focus
|
|
253
|
+
draw()
|
|
254
|
+
}
|
|
255
|
+
respond({ ok: true })
|
|
256
|
+
}
|
|
90
257
|
if (message.action === "locate") respond({ states: message.anchors.map(locate) })
|
|
91
258
|
if (message.action === "reveal") {
|
|
92
259
|
const state = locate(message.anchor)
|
|
93
260
|
if (state !== "located") {
|
|
94
|
-
respond({ ok: false, error: `This
|
|
261
|
+
respond({ ok: false, error: `This target is ${state}. Your feedback is kept.` })
|
|
95
262
|
return
|
|
96
263
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
264
|
+
setMode(null, false)
|
|
265
|
+
const behavior = matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth"
|
|
266
|
+
if (message.anchor.type === "area") {
|
|
267
|
+
const { x, y, width, height } = message.anchor.rect
|
|
268
|
+
window.scrollTo({ left: x + (width - innerWidth) / 2, top: y + (height - innerHeight) / 2, behavior })
|
|
269
|
+
respond({ ok: true }); return
|
|
270
|
+
} else {
|
|
271
|
+
highlighted = document.querySelector(message.anchor.selector)
|
|
272
|
+
highlighted.scrollIntoView({ block: "center", inline: "nearest", behavior })
|
|
273
|
+
}
|
|
100
274
|
root.append(highlight); draw()
|
|
101
275
|
clearTimeout(highlightTimer)
|
|
102
276
|
highlightTimer = setTimeout(() => { highlighted = null; highlight.remove() }, 1600)
|
|
@@ -105,6 +279,7 @@
|
|
|
105
279
|
}
|
|
106
280
|
chrome.runtime.onMessage.addListener(onMessage)
|
|
107
281
|
function locate(anchor) {
|
|
282
|
+
if (anchor.type === "area") return "located"
|
|
108
283
|
try {
|
|
109
284
|
const matches = document.querySelectorAll(anchor.selector)
|
|
110
285
|
if (matches.length !== 1) return matches.length ? "ambiguous" : "missing"
|
|
@@ -116,22 +291,50 @@
|
|
|
116
291
|
return "located"
|
|
117
292
|
} catch { return "invalid selector" }
|
|
118
293
|
}
|
|
294
|
+
function drawAreaMarkers() {
|
|
295
|
+
const draws = []
|
|
296
|
+
for (const [index, marker] of [...markers, ...(draftMarker ? [draftMarker] : [])].entries()) {
|
|
297
|
+
if (marker.anchor?.type !== "area") continue
|
|
298
|
+
const isDraft = marker === draftMarker
|
|
299
|
+
const selected = marker.id && (markerFocus ? marker.id === markerFocus : isDraft)
|
|
300
|
+
const rect = areaDrag?.adjustable && areaDrag.marker.id === marker.id ? adjustRect(areaDrag) : marker.anchor.rect
|
|
301
|
+
const mark = document.createElement("div")
|
|
302
|
+
mark.className = `box area area-mark${selected ? " is-active" : ""}`
|
|
303
|
+
if (marker.id) mark.dataset.markerId = marker.id
|
|
304
|
+
paint(mark, areaRect({ rect }))
|
|
305
|
+
if (selected) {
|
|
306
|
+
for (const side of directions) {
|
|
307
|
+
const handle = document.createElement("span"); handle.className = "handle"; handle.dataset.handle = side
|
|
308
|
+
handle.style.cssText = `left:${side.includes("w") ? "0" : side.includes("e") ? "100%" : "50%"};top:${side.includes("n") ? "0" : side.includes("s") ? "100%" : "50%"};cursor:${side}-resize`
|
|
309
|
+
mark.append(handle)
|
|
310
|
+
}
|
|
311
|
+
} else if (marker.id) {
|
|
312
|
+
for (const side of ["n", "e", "s", "w"]) {
|
|
313
|
+
const edge = document.createElement("span"); edge.className = "edge"; edge.dataset.side = side; mark.append(edge)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (!isDraft) {
|
|
317
|
+
const pin = document.createElement("span"); pin.className = "pin"; pin.textContent = String(marker.number ?? index + 1)
|
|
318
|
+
mark.append(pin)
|
|
319
|
+
}
|
|
320
|
+
draws.push(mark)
|
|
321
|
+
}
|
|
322
|
+
areaLayer.replaceChildren(...draws)
|
|
323
|
+
}
|
|
119
324
|
function draw() {
|
|
120
325
|
syncLayer()
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
root.
|
|
326
|
+
drawArea()
|
|
327
|
+
drawAreaMarkers()
|
|
328
|
+
if (highlighted?.isConnected) paint(highlight, highlighted.getBoundingClientRect())
|
|
329
|
+
else highlight.remove()
|
|
330
|
+
for (const child of [...root.children]) if (child.classList.contains("pin")) child.remove()
|
|
126
331
|
for (const [index, note] of markers.entries()) {
|
|
332
|
+
if (!note.anchor || note.anchor.type === "area") continue
|
|
127
333
|
let matches
|
|
128
334
|
try { matches = document.querySelectorAll(note.anchor.selector) } catch { continue }
|
|
129
|
-
if (matches.length !== 1) continue
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
if (!AnnotateInspector.text(element).includes(note.anchor.quote)) continue
|
|
133
|
-
const rect = element.getBoundingClientRect()
|
|
134
|
-
const pin = document.createElement("span"); pin.className = "pin"; pin.textContent = String(index + 1)
|
|
335
|
+
if (matches.length !== 1 || !AnnotateInspector.text(matches[0]).includes(note.anchor.quote)) continue
|
|
336
|
+
const rect = matches[0].getBoundingClientRect()
|
|
337
|
+
const pin = document.createElement("span"); pin.className = "pin"; pin.textContent = String(note.number ?? index + 1)
|
|
135
338
|
pin.style.cssText = `left:${rect.left - 10}px;top:${rect.top - 10}px`; root.append(pin)
|
|
136
339
|
}
|
|
137
340
|
}
|
|
@@ -146,13 +349,18 @@
|
|
|
146
349
|
on(document, "load", event => {
|
|
147
350
|
if (["iframe", "frame"].includes(event.target.localName)) chrome.runtime.sendMessage({ action: "frames-changed" }).catch(() => {})
|
|
148
351
|
}, { capture: true })
|
|
149
|
-
const routeTimer = setInterval(() => {
|
|
352
|
+
const routeTimer = setInterval(() => {
|
|
353
|
+
if (!active) { observer.disconnect(); return }
|
|
354
|
+
if (url !== location.href) {
|
|
355
|
+
url = location.href; setMode(null, false); cancelAdjust(false); markers = []; draftMarker = markerFocus = markerKey = null; draw(); send()
|
|
356
|
+
}
|
|
357
|
+
}, 700)
|
|
150
358
|
function dispose() {
|
|
151
359
|
if (!active) return
|
|
152
|
-
active = false; listeners.abort(); clearInterval(routeTimer); clearTimeout(timer); clearTimeout(highlightTimer); observer.disconnect(); host.remove()
|
|
360
|
+
active = false; setMode(null, false); cancelAdjust(false); listeners.abort(); clearInterval(routeTimer); clearTimeout(timer); clearTimeout(highlightTimer); observer.disconnect(); host.remove()
|
|
153
361
|
try { chrome.runtime.onMessage.removeListener(onMessage) } catch { /* previous extension context may already be invalidated */ }
|
|
154
362
|
delete globalThis.__opencodeAnnotate
|
|
155
363
|
}
|
|
156
|
-
globalThis.__opencodeAnnotate = { dispose, version:
|
|
364
|
+
globalThis.__opencodeAnnotate = { dispose, version: 10 }
|
|
157
365
|
send(null, null, true, true)
|
|
158
366
|
})();
|
package/browser/inspector.js
CHANGED
|
@@ -123,6 +123,71 @@
|
|
|
123
123
|
rect: Object.fromEntries(["x", "y", "width", "height"].map(key => [key, Math.round(rect[key])])),
|
|
124
124
|
viewport: { width: innerWidth, height: innerHeight, scrollX, scrollY } }
|
|
125
125
|
}
|
|
126
|
+
const intersection = (a, b) => {
|
|
127
|
+
const left = Math.max(a.left, b.left), top = Math.max(a.top, b.top)
|
|
128
|
+
const right = Math.min(a.right, b.right), bottom = Math.min(a.bottom, b.bottom)
|
|
129
|
+
return right > left && bottom > top ? { left, top, right, bottom } : null
|
|
130
|
+
}
|
|
131
|
+
const size = rect => (rect.right - rect.left) * (rect.bottom - rect.top)
|
|
132
|
+
const contains = (outer, inner) => outer.left <= inner.left && outer.top <= inner.top && outer.right >= inner.right && outer.bottom >= inner.bottom
|
|
133
|
+
function captureArea(rect, container) {
|
|
134
|
+
const viewport = { width: innerWidth, height: innerHeight, scrollX, scrollY }
|
|
135
|
+
const region = intersection(new DOMRect(rect.x - scrollX, rect.y - scrollY, rect.width, rect.height), new DOMRect(0, 0, innerWidth, innerHeight))
|
|
136
|
+
if (!region || !container) return { type: "area", rect, viewport, quote: "", selectors: [] }
|
|
137
|
+
const omitted = textFilter(), clips = new WeakMap(), range = document.createRange(), candidates = []
|
|
138
|
+
function clip(element) {
|
|
139
|
+
if (!element) return region
|
|
140
|
+
if (clips.has(element)) return clips.get(element)
|
|
141
|
+
let bounds = clip(element.parentElement)
|
|
142
|
+
const style = getComputedStyle(element)
|
|
143
|
+
if (bounds && element.clientWidth && element.clientHeight && (style.overflowX !== "visible" || style.overflowY !== "visible")) {
|
|
144
|
+
const box = element.getBoundingClientRect()
|
|
145
|
+
bounds = intersection(bounds, {
|
|
146
|
+
left: style.overflowX === "visible" ? bounds.left : box.left,
|
|
147
|
+
right: style.overflowX === "visible" ? bounds.right : box.right,
|
|
148
|
+
top: style.overflowY === "visible" ? bounds.top : box.top,
|
|
149
|
+
bottom: style.overflowY === "visible" ? bounds.bottom : box.bottom,
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
clips.set(element, bounds)
|
|
153
|
+
return bounds
|
|
154
|
+
}
|
|
155
|
+
function textIn(node, bounds, start, end) {
|
|
156
|
+
range.setStart(node, start); range.setEnd(node, end)
|
|
157
|
+
const boxes = [...range.getClientRects()].filter(box => size(box) > 0)
|
|
158
|
+
if (!boxes.some(box => intersection(bounds, box))) return ""
|
|
159
|
+
if (end - start <= 1 || boxes.every(box => contains(bounds, box))) return node.data.slice(start, end)
|
|
160
|
+
const middle = Math.floor((start + end) / 2)
|
|
161
|
+
return textIn(node, bounds, start, middle) + textIn(node, bounds, middle, end)
|
|
162
|
+
}
|
|
163
|
+
let quote = ""
|
|
164
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT)
|
|
165
|
+
for (let node; (node = walker.nextNode());) {
|
|
166
|
+
const element = node.nodeType === Node.TEXT_NODE ? node.parentElement : node
|
|
167
|
+
if (omitted(element)) continue
|
|
168
|
+
const bounds = clip(element.parentElement)
|
|
169
|
+
if (!bounds) continue
|
|
170
|
+
if (node === element) {
|
|
171
|
+
const box = element.getBoundingClientRect()
|
|
172
|
+
const overlap = intersection(bounds, box)
|
|
173
|
+
if (overlap) candidates.push({ element, score: size(overlap) / (size(region) + size(box) - size(overlap)) })
|
|
174
|
+
} else if (quote.length < 4000 && node.data.trim()) {
|
|
175
|
+
const clipped = clip(element)
|
|
176
|
+
if (!clipped) continue
|
|
177
|
+
const text = textIn(node, clipped, 0, node.length).replace(/\s+/g, " ").trim()
|
|
178
|
+
if (text) quote = `${quote}${quote ? " " : ""}${text}`.slice(0, 4000)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const selectors = []
|
|
182
|
+
for (const { element } of candidates.sort((a, b) => b.score - a.score)) {
|
|
183
|
+
try {
|
|
184
|
+
const hint = selector(element)
|
|
185
|
+
if (hint.length <= 1000) selectors.push(hint)
|
|
186
|
+
} catch { /* A selector is evidence, not the area anchor. */ }
|
|
187
|
+
if (selectors.length === 5) break
|
|
188
|
+
}
|
|
189
|
+
return { type: "area", rect, viewport, quote, selectors }
|
|
190
|
+
}
|
|
126
191
|
function frame() {
|
|
127
192
|
const selectors = []
|
|
128
193
|
for (let current = window; current !== current.top; current = current.parent) {
|
|
@@ -131,5 +196,5 @@
|
|
|
131
196
|
}
|
|
132
197
|
return selectors.length ? { selectors, url: location.href } : null
|
|
133
198
|
}
|
|
134
|
-
globalThis.AnnotateInspector = { capture, text: elementText, frame }
|
|
199
|
+
globalThis.AnnotateInspector = { capture, captureArea, text: elementText, frame }
|
|
135
200
|
})();
|
package/browser/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "OpenCode Annotate",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"description": "Annotate HTML-based page feedback, private drafts, and paired OpenCode delivery.",
|
|
6
6
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp7TG2yzekNKpQvHBtj4jqkOxtoeDIBhNIjPi37Os/ksuhzPp1pHnrJPV4WV2ToatUaD5x5/SpLP8qZKLBD+wuraEE/TeclEZ8HvEs1yhlnx/S7piTG/s0eV5umuTEx2w66Hi0w3dhTC7ZZfJXCLyqs1feBtWzQx6ClgaHNYly4iJ03pV7RfguqpIaG9LV8Oa8ELA+7Ubr0BAujXrSlvqLF5oAKGoXXcpvTL5rgMRIH4Q/85tnvrk0pRVg+1z9IGNzSfjN82iveC/JAriyWABp8YuswtvKfI2Wb+KspaisBh39Y3BRqlyo8I2Cr+01uE6G5pWiJIWMLhe0glrMr5I2wIDAQAB",
|
|
7
7
|
"permissions": ["activeTab", "scripting", "storage", "sidePanel", "nativeMessaging", "clipboardWrite"],
|
package/browser/panel.css
CHANGED
|
@@ -37,9 +37,9 @@ textarea { caret-color: var(--accent); }
|
|
|
37
37
|
#page-url { min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
38
38
|
main { min-height: 0; min-width: 0; overflow: auto; padding: 14px 16px 20px; scrollbar-width: thin; scrollbar-color: var(--input) transparent; scroll-padding: 16px; }
|
|
39
39
|
.picker-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
|
40
|
-
#pick { flex: none; }
|
|
40
|
+
#pick, #area { flex: none; }
|
|
41
41
|
#pick-hint { font-size: 13px; color: var(--muted); }
|
|
42
|
-
|
|
42
|
+
.picker-row button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
|
|
43
43
|
.composer { margin-top: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
|
|
44
44
|
.section-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
|
|
45
45
|
.section-heading h2 { font-size: 14px; font-weight: 650; }
|
package/browser/panel.html
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
</section>
|
|
28
28
|
<div id="update-notice" class="update-notice" role="status" hidden><strong>Annotate was updated</strong><p>Reload once to finish. Notes and drafts are kept; reopen the panel with the icon or Alt+Shift+A afterwards.</p><button id="reload-extension" class="primary">Reload Annotate</button></div>
|
|
29
29
|
<p id="page-error" class="error" role="alert" hidden></p>
|
|
30
|
-
<div class="picker-row"><button id="pick" aria-pressed="false"><svg class="icon" aria-hidden="true"><use href="#icon-pick"/></svg><span id="pick-label">Pick element</span></button><span id="pick-hint">or select text</span></div>
|
|
30
|
+
<div class="picker-row"><button id="pick" aria-pressed="false"><svg class="icon" aria-hidden="true"><use href="#icon-pick"/></svg><span id="pick-label">Pick element</span></button><button id="area" aria-pressed="false">Select area</button><span id="pick-hint">or select text</span></div>
|
|
31
31
|
<section id="composer" class="composer" aria-label="Current annotation" hidden>
|
|
32
32
|
<div class="section-heading"><h2 id="composer-title">New note</h2><span id="draft-state" aria-live="polite"></span></div>
|
|
33
33
|
<blockquote class="selected-quote"><svg class="icon" aria-hidden="true"><use href="#icon-pick"/></svg><p id="quote"></p></blockquote>
|