* Select annotation(s). Pass null to deselect all. * If additive is true, toggle the given id without clearing existing selection.
(id: string | null, additive = false)
| 1257 | * If additive is true, toggle the given id without clearing existing selection. |
| 1258 | */ |
| 1259 | function selectAnnotation(id: string | null, additive = false): void { |
| 1260 | if (!additive) { |
| 1261 | // Clear all existing selection visuals |
| 1262 | for (const prevId of selectedAnnotationIds) { |
| 1263 | const tracked = annotationMap.get(prevId); |
| 1264 | if (tracked) { |
| 1265 | for (const el of tracked.elements) { |
| 1266 | el.classList.remove("annotation-selected"); |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | // Remove handles |
| 1271 | for (const h of annotationLayerEl.querySelectorAll( |
| 1272 | ".annotation-handle, .annotation-handle-rotate", |
| 1273 | )) { |
| 1274 | h.remove(); |
| 1275 | } |
| 1276 | selectedAnnotationIds.clear(); |
| 1277 | } |
| 1278 | |
| 1279 | if (id) { |
| 1280 | if (additive && selectedAnnotationIds.has(id)) { |
| 1281 | // Toggle off |
| 1282 | selectedAnnotationIds.delete(id); |
| 1283 | const tracked = annotationMap.get(id); |
| 1284 | if (tracked) { |
| 1285 | for (const el of tracked.elements) { |
| 1286 | el.classList.remove("annotation-selected"); |
| 1287 | } |
| 1288 | } |
| 1289 | } else { |
| 1290 | selectedAnnotationIds.add(id); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | // Apply selection visuals + handles on all selected |
| 1295 | // Only show handles when exactly one annotation is selected |
| 1296 | for (const selId of selectedAnnotationIds) { |
| 1297 | const tracked = annotationMap.get(selId); |
| 1298 | if (tracked) { |
| 1299 | for (const el of tracked.elements) { |
| 1300 | el.classList.add("annotation-selected"); |
| 1301 | } |
| 1302 | if (selectedAnnotationIds.size === 1) { |
| 1303 | showHandles(tracked); |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | // Auto-expand the accordion section for the selected annotation's page |
| 1309 | if (id) { |
| 1310 | const tracked = annotationMap.get(id); |
| 1311 | if (tracked) { |
| 1312 | panelState.openAccordionSection = `page-${tracked.def.page}`; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | // Re-render the panel so accordion sections open/close to match selection |
no test coverage detected
searching dependent graphs…