import {dataUrl} from './images.mjs';
const escape = (value) => String(value).replace(/[&<>"']/gu, (c) => ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''}[c]));
export function annotatedSvg(image, parts) {
const {width: w, height: h} = image;
const stroke = Math.max(w, h) / 400;
const font = Math.max(w, h) / 65;
const byId = new Map(parts.map((part) => [part.id, part]));
const overlays = parts.map((part, index) => {
const color = `hsl(${(index * 137.5) % 360} 85% 55%)`;
const [px, py] = [part.pivot_norm[0] * w, part.pivot_norm[1] * h];
const parent = byId.get(part.parent);
const line = parent ? ``;
const rows = data && validation.valid ? data.parts.map((part) => `
此图仅包含模型预测的粗框、关节点(空心圆)和正点(实心圆),尚未执行 SAM 分割或补全。结构校验通过不代表语义正确。
状态:${validation.valid ? 'needs_review(待检查)' : 'failed'}
${svg}${escape(JSON.stringify(validation, null, 2))}| ID | 父部件 | 可见性 | 遮挡物 | 自报置信度 |
|---|
${escape(JSON.stringify(data?.notes || [], null, 2))}${escape(JSON.stringify(metadata, null, 2))}`;
}