refactor(anatomy): rename SVG data attrs (bone → anno) per new convention

User updated the clickable-zone convention in the source SVGs:

  data-bone-id        → data-anno-id
  data-bone-fr        → data-anno-name-fr
  data-bone-en        → data-anno-name-en
  data-category       → data-anno-category
  data-opens-detail   → data-anno-opens-detail

Bulk-renamed across:
- public/species/equine/Horse.svg + Horse_head.svg (86 anno-attrs each)
- src/anatomy/svgConvention.ts (parser + getBoneIdFromEvent)
- src/anatomy/types.ts (doc strings)
- src/components/canvas/AnatomyCanvas.tsx (querySelector + delegated click)
- src/styles/index.css (`[data-bone-id]` selectors → `[data-anno-id]`)
- src/domain/species/types.ts + schema/observation.ts (doc strings)
- docs/{ANATOMY-SVG-CONVENTION,ADDING-A-SPECIES,superpowers/specs,plans}.md
- CLAUDE.md + .claude/{memory/learnings,tasks/TODO}.md
- tests/unit/{anatomy.svgConvention,anatomy.svgLoader,components.AnatomyCanvas}.test.tsx

Internal TS type names and field names (Bone, boneId, parseSvgBones,
getBoneIdFromEvent) are kept intentionally — they're the application's
logical shape and the persisted JSON contract. ObservationZone.boneId is
the identifier seen in already-exported PDFs; renaming it would break
re-import of those PDFs. Only the SVG-side attribute names change.

90/90 tests pass, lint clean, build clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-19 03:10:06 +02:00
1 parent e8c29c1fdf
commit 1109e33383
18 files changed
+308 -308

No files matched your search

+14 -14
View File
@@ -20,22 +20,22 @@ function classList(el: Element): string[] {
}
export function validateBoneElement(el: Element): void {
const boneId = el.getAttribute('data-bone-id') ?? ''
for (const attr of ['data-bone-fr', 'data-bone-en', 'data-category']) {
const boneId = el.getAttribute('data-anno-id') ?? ''
for (const attr of ['data-anno-name-fr', 'data-anno-name-en', 'data-anno-category']) {
if (!el.getAttribute(attr)) {
throw new SvgConventionError(
`Element data-bone-id="${boneId}" missing attribute ${attr}`,
`Element data-anno-id="${boneId}" missing attribute ${attr}`,
boneId,
attr,
)
}
}
const cat = el.getAttribute('data-category') ?? ''
const cat = el.getAttribute('data-anno-category') ?? ''
if (!isValidCategory(cat)) {
throw new SvgConventionError(
`Element data-bone-id="${boneId}" has unknown data-category="${cat}"`,
`Element data-anno-id="${boneId}" has unknown data-anno-category="${cat}"`,
boneId,
'data-category',
'data-anno-category',
)
}
}
@@ -47,7 +47,7 @@ export function validateBoneElement(el: Element): void {
* - its category is `head` (single entry-point polygon for a detail SVG).
*
* Decorative elements (e.g. individual vertebrae paths, teeth, malar bone)
* carry `data-bone-id` so their colorization can be controlled by JS, but
* carry `data-anno-id` so their colorization can be controlled by JS, but
* must NOT intercept clicks. We mark them with `pointer-events: none` and
* exclude them from the returned Bone map so the click handler ignores
* them naturally.
@@ -60,14 +60,14 @@ function isInteractiveBone(bone: Bone): boolean {
export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
const raw = new Map<string, Bone>()
const all = svgRoot.querySelectorAll<Element>('[data-bone-id]')
const all = svgRoot.querySelectorAll<Element>('[data-anno-id]')
all.forEach((el) => {
validateBoneElement(el)
const id = el.getAttribute('data-bone-id') as string
const fr = el.getAttribute('data-bone-fr') as string
const en = el.getAttribute('data-bone-en') as string
const category = el.getAttribute('data-category') as BoneCategory
const opensDetail = el.getAttribute('data-opens-detail') ?? undefined
const id = el.getAttribute('data-anno-id') as string
const fr = el.getAttribute('data-anno-name-fr') as string
const en = el.getAttribute('data-anno-name-en') as string
const category = el.getAttribute('data-anno-category') as BoneCategory
const opensDetail = el.getAttribute('data-anno-opens-detail') ?? undefined
const classes = classList(el)
const isHitbox = classes.includes('hitbox')
@@ -110,7 +110,7 @@ export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
export function getBoneIdFromEvent(event: Event): string | null {
let node = event.target as Element | null
while (node && node.nodeType === 1) {
const id = node.getAttribute?.('data-bone-id')
const id = node.getAttribute?.('data-anno-id')
if (id) return id
node = node.parentElement
}
+4 -4
View File
@@ -1,4 +1,4 @@
/** Valid data-category values per the SVG convention. */
/** Valid data-anno-category values per the SVG convention. */
export type BoneCategory =
| 'articulation'
| 'charniere'
@@ -11,12 +11,12 @@ export type BoneCategory =
/** A logical bone as parsed from an SVG — groups hitbox + visible elements. */
export interface Bone {
id: string
/** French label from data-bone-fr */
/** French label from data-anno-name-fr */
fr: string
/** English label from data-bone-en */
/** English label from data-anno-name-en */
en: string
category: BoneCategory
/** Detail popup id from data-opens-detail, if present */
/** Detail popup id from data-anno-opens-detail, if present */
opensDetail?: string
/** Elements with class containing "hitbox" */
hitboxEls: Element[]
+2 -2
View File
@@ -44,9 +44,9 @@ export default function AnatomyCanvas({
useEffect(() => {
const c = containerRef.current
if (!c) return
const all = c.querySelectorAll<Element>('[data-bone-id]')
const all = c.querySelectorAll<Element>('[data-anno-id]')
all.forEach((el) => {
const id = el.getAttribute('data-bone-id') as string
const id = el.getAttribute('data-anno-id') as string
const state = boneStates.get(id)
if (state && state !== 'default') el.setAttribute('data-state', state)
else el.removeAttribute('data-state')
+1 -1
View File
@@ -16,7 +16,7 @@ export const VertebraSchema = z.object({
export type Vertebra = z.infer<typeof VertebraSchema>
export const ObservationZoneSchema = z.object({
/** Must match data-bone-id attribute on the SVG element */
/** Must match data-anno-id attribute on the SVG element */
boneId: z.string().min(1),
/** Set when zone originates from a detail popup SVG */
detailSourceId: z.string().optional(),
+1 -1
View File
@@ -21,7 +21,7 @@ export interface SpeciesManifest {
mainSvg: string
/**
* Map of detail popup id → absolute public path to detail SVG.
* Keys match data-opens-detail attribute values in the main SVG.
* Keys match data-anno-opens-detail attribute values in the main SVG.
*/
details: Record<string, string>
vertebralFormula: VertebralFormula
+2 -2
View File
@@ -12,5 +12,5 @@ body {
.svg-canvas [data-state='current'] { fill: var(--color-accent) !important; fill-opacity: 0.85 !important; }
.svg-canvas [data-state='linked'] { stroke-dasharray: 4 3; stroke: var(--color-accent); fill-opacity: 0.35 !important; }
.svg-canvas [data-state='multi'] { fill: var(--color-accent) !important; fill-opacity: 0.65 !important; stroke: var(--color-ink); stroke-width: 1.5; }
.svg-canvas [data-bone-id] { cursor: pointer; }
.svg-canvas [data-bone-id]:hover { filter: brightness(1.05); }
.svg-canvas [data-anno-id] { cursor: pointer; }
.svg-canvas [data-anno-id]:hover { filter: brightness(1.05); }