chore(workspace): move the app to apps/app under a pnpm workspace (step 2)
144 files moved with git mv (pure renames). Root package.json delegates dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager, root devDependency, engine-strict). Dockerfile builds @faunosteo/app on node:24-alpine and copies apps/app/dist; nginx and runtime config unchanged. CI workflow for Gitea Actions. packages/ reserved (README only). Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan. 271/271 tests, typecheck, lint, build green from the root.
This commit is contained in:
1 parent
c8d48ab4cc
commit
8673475293
164 files changed
+348
-128
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import type { Locale } from '@/i18n/types'
|
||||
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
import type { Bone } from './types'
|
||||
|
||||
/**
|
||||
* Resolves the user-facing label for an anatomical zone given the active
|
||||
* locale. Falls back to the opposite language when the requested one is
|
||||
* missing (some SVG hitboxes carry only `data-anno-name-fr`), then to the
|
||||
* provided fallback (typically the raw boneId) so the UI never renders
|
||||
* an empty label.
|
||||
*/
|
||||
export function boneLabel(
|
||||
bone: Bone | undefined,
|
||||
locale: Locale,
|
||||
fallback: string,
|
||||
): string {
|
||||
if (!bone) return fallback
|
||||
return pickLocaleLabel(bone.fr, bone.en, locale, fallback)
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import { SvgConventionError } from './types'
|
||||
import type { Bone, BoneCategory } from './types'
|
||||
|
||||
/**
|
||||
* Validates that an annotated SVG element carries the two attributes the
|
||||
* application needs to wire it up: a stable id (`data-anno-id`) and a
|
||||
* category bucket (`data-anno-category`). Labels (`data-anno-name-fr/en`)
|
||||
* and the popup trigger (`data-anno-opens-detail`) are optional and
|
||||
* checked only at use-site.
|
||||
*
|
||||
* The category value itself is opaque to the application — any non-empty
|
||||
* string is accepted. New SVGs are free to introduce new categories
|
||||
* without touching this parser.
|
||||
*/
|
||||
function validateBoneElement(el: Element): void {
|
||||
const boneId = el.getAttribute('data-anno-id') ?? ''
|
||||
if (!boneId) {
|
||||
throw new SvgConventionError(
|
||||
'Element with missing data-anno-id',
|
||||
boneId,
|
||||
'data-anno-id',
|
||||
)
|
||||
}
|
||||
const cat = el.getAttribute('data-anno-category') ?? ''
|
||||
if (!cat) {
|
||||
throw new SvgConventionError(
|
||||
`Element data-anno-id="${boneId}" missing attribute data-anno-category`,
|
||||
boneId,
|
||||
'data-anno-category',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an SVG document and returns a map of `data-anno-id` → Bone.
|
||||
*
|
||||
* Every element carrying `data-anno-id` is collected. Multiple elements
|
||||
* may share the same id (e.g. hitbox + visible layer); they all end up
|
||||
* grouped under the same Bone with all elements in `els`.
|
||||
*
|
||||
* Throws `SvgConventionError` only on the two required attributes
|
||||
* (`data-anno-id`, `data-anno-category`). Labels are optional.
|
||||
*/
|
||||
export function parseSvgBones(svgRoot: SVGSVGElement): Map<string, Bone> {
|
||||
const map = new Map<string, Bone>()
|
||||
const all = svgRoot.querySelectorAll<Element>('[data-anno-id]')
|
||||
all.forEach((el) => {
|
||||
validateBoneElement(el)
|
||||
const id = el.getAttribute('data-anno-id') as string
|
||||
const fr = el.getAttribute('data-anno-name-fr') ?? ''
|
||||
const en = el.getAttribute('data-anno-name-en') ?? ''
|
||||
const category = el.getAttribute('data-anno-category') as BoneCategory
|
||||
const opensDetail =
|
||||
el.getAttribute('data-anno-opens-detail') ?? undefined
|
||||
const special = el.getAttribute('data-anno-special') ?? undefined
|
||||
const lateral = (el.getAttribute('data-anno-lateral') ?? undefined) as
|
||||
| 'bilateral'
|
||||
| 'unpaired'
|
||||
| undefined
|
||||
|
||||
const existing = map.get(id)
|
||||
if (existing) {
|
||||
existing.els.push(el)
|
||||
if (opensDetail && !existing.opensDetail) {
|
||||
existing.opensDetail = opensDetail
|
||||
}
|
||||
if (special && !existing.special) {
|
||||
existing.special = special
|
||||
}
|
||||
if (lateral && !existing.lateral) {
|
||||
existing.lateral = lateral
|
||||
}
|
||||
if (!existing.fr && fr) existing.fr = fr
|
||||
if (!existing.en && en) existing.en = en
|
||||
} else {
|
||||
map.set(id, {
|
||||
id,
|
||||
fr,
|
||||
en,
|
||||
category,
|
||||
opensDetail,
|
||||
special,
|
||||
lateral,
|
||||
els: [el],
|
||||
})
|
||||
}
|
||||
})
|
||||
return map
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks up from `event.target` to find the nearest element carrying
|
||||
* `data-anno-id`. Returns null when the click did not land on an
|
||||
* annotated element.
|
||||
*/
|
||||
export function getBoneIdFromEvent(event: Event): string | null {
|
||||
return getAnnotatedElement(event)?.getAttribute('data-anno-id') || null
|
||||
}
|
||||
|
||||
export function getAnnotatedElement(event: Event): Element | null {
|
||||
let node = event.target as Element | null
|
||||
while (node && node.nodeType === 1) {
|
||||
if (node.hasAttribute('data-anno-id')) return node
|
||||
node = node.parentElement
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
export async function loadSvg(publicPath: string): Promise<SVGSVGElement> {
|
||||
const resp = await fetch(publicPath)
|
||||
if (!resp.ok) {
|
||||
throw new Error(`Failed to load SVG ${publicPath}: HTTP ${resp.status}`)
|
||||
}
|
||||
const text = await resp.text()
|
||||
const doc = new DOMParser().parseFromString(text, 'image/svg+xml')
|
||||
const parseErr = doc.querySelector('parsererror')
|
||||
if (parseErr) {
|
||||
throw new Error(`Invalid SVG at ${publicPath}: ${parseErr.textContent}`)
|
||||
}
|
||||
const root = doc.documentElement
|
||||
if (root.tagName.toLowerCase() !== 'svg') {
|
||||
throw new Error(`Root element of ${publicPath} is not <svg>`)
|
||||
}
|
||||
return root as unknown as SVGSVGElement
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* `data-anno-category` is a free-form string supplied by the SVG.
|
||||
*
|
||||
* The application never branches on category values — it treats every
|
||||
* annotation the same way. Categories are kept around because they're
|
||||
* useful for grouping and future filtering, but no code path here may
|
||||
* rely on a closed set.
|
||||
*/
|
||||
export type BoneCategory = string
|
||||
|
||||
/**
|
||||
* Logical annotation as parsed from an SVG. All DOM elements sharing the
|
||||
* same `data-anno-id` are grouped into one Bone. `id` is the persisted
|
||||
* identifier surfaced in the report JSON contract
|
||||
* (`ObservationZone.boneId`); keep it stable across SVG renames.
|
||||
*/
|
||||
export interface Bone {
|
||||
id: string
|
||||
/** French label from data-anno-name-fr — may be empty for opens-detail-only triggers */
|
||||
fr: string
|
||||
/** English label from data-anno-name-en — may be empty */
|
||||
en: string
|
||||
/** Raw value from data-anno-category — opaque to the application */
|
||||
category: BoneCategory
|
||||
/** Detail popup id from data-anno-opens-detail, if present */
|
||||
opensDetail?: string
|
||||
/**
|
||||
* Free-form behavior hint from `data-anno-special`.
|
||||
*
|
||||
* Known values consumed by the application:
|
||||
* - `vertebral-precision`: clicking the zone opens VertebraPicker.
|
||||
*
|
||||
* Opaque to the parser; new values are accepted without code changes.
|
||||
*/
|
||||
special?: string
|
||||
/** Laterality hint from data-anno-lateral — bilateral or unpaired */
|
||||
lateral?: 'bilateral' | 'unpaired'
|
||||
/** All DOM elements carrying this annotation (used for colorization) */
|
||||
els: Element[]
|
||||
}
|
||||
|
||||
/** Visual state applied to SVG elements (active-observation highlight). */
|
||||
export type BoneState = 'current' | 'default'
|
||||
|
||||
/** Error thrown when SVG violates the convention. */
|
||||
export class SvgConventionError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly boneId: string,
|
||||
public readonly missingAttribute: string,
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'SvgConventionError'
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user