feat(domain): archive contracts — sheet snapshot (lean document, caps, integrity), envelope v1 layered reader, branding and label schemas, report rebase, sheet index moved from the app; bundle carries asset hashes

This commit is contained in:
bchanot committed 2026-10-11 12:30:57 +02:00
1 parent 8b86b926c8
commit cdc0943f35
25 files changed
+2253 -116

No files matched your search

+7 -109
View File
@@ -1,113 +1,11 @@
import type {
Annotation,
FindingCategory,
FindingNode,
FindingZone,
LocalizedText,
SheetView,
VertebralRegion,
} from '@faunosteo/domain'
import type { Locale } from '@/i18n/types'
import type { SheetIndex as DomainSheetIndex } from '@faunosteo/domain'
import type { LoadedSheet } from '@/sheets/provider'
/**
* Read-only lookups over a loaded sheet. Everything the editor used to derive
* from SVG attributes, label matching or the species manifest comes from the
* document here, by stable id: no label drives logic.
* The sheet index lives in @faunosteo/domain since Step 6 (shared with the
* PDF engine). This shim keeps the app's import path and binds the index to
* the sheet the app loads, so `index.sheet` still carries the migration map.
*/
export type ObservableAnnotation = Extract<
Annotation,
{ kind: 'point' | 'zone' }
>
export interface SheetIndex {
sheet: LoadedSheet
mainView: SheetView
view(id: string): SheetView | undefined
annotation(id: string): Annotation | undefined
annotationsOfView(viewId: string): Annotation[]
findingZone(id: string): FindingZone | undefined
/** The category or node at a path, undefined when absent from the sheet. */
nodeAt(
zoneId: string,
path: readonly string[],
): FindingCategory | FindingNode | undefined
regions(): VertebralRegion[]
region(code: string): VertebralRegion | undefined
/** The annotation that opens the vertebra picker for a region on a view. */
spineAnnotation(
regionCode: string,
viewId: string,
): ObservableAnnotation | undefined
/** Whether an annotation opens the vertebra picker. */
isSpine(annotationId: string): boolean
name(annotation: Annotation): LocalizedText
}
export function pickLabel(
text: LocalizedText | null | undefined,
locale: Locale,
): string {
if (!text) return ''
return locale === 'en' ? text.en || text.fr : text.fr || text.en
}
export function isObservable(
a: Annotation | undefined,
): a is ObservableAnnotation {
return a !== undefined && a.kind !== 'detail_trigger'
}
export function buildSheetIndex(sheet: LoadedSheet): SheetIndex {
const { document } = sheet
const views = new Map(document.views.map((v) => [v.id, v]))
const annotations = new Map(document.annotations.map((a) => [a.id, a]))
const zones = new Map(document.finding_zones.map((z) => [z.id, z]))
const regions = new Map(
document.vertebral_config.regions.map((r) => [r.code, r]),
)
const mainView = document.views.find((v) => v.kind === 'main')
if (!mainView) throw new Error('sheet has no main view')
const nodeAt: SheetIndex['nodeAt'] = (zoneId, path) => {
const zone = zones.get(zoneId)
if (!zone || path.length === 0) return undefined
let node: FindingCategory | FindingNode | undefined = zone.categories.find(
(c) => c.id === path[0],
)
for (const segment of path.slice(1)) {
if (!node) return undefined
node = node.children.find((n) => n.id === segment)
}
return node
}
return {
sheet,
mainView,
view: (id) => views.get(id),
annotation: (id) => annotations.get(id),
annotationsOfView: (viewId) =>
document.annotations.filter((a) => a.view_id === viewId),
findingZone: (id) => zones.get(id),
nodeAt,
regions: () => document.vertebral_config.regions,
region: (code) => regions.get(code),
spineAnnotation: (code, viewId) =>
document.annotations.find(
(a): a is ObservableAnnotation =>
isObservable(a) &&
a.view_id === viewId &&
a.vertebral_region_code === code,
),
isSpine: (id) => {
const a = annotations.get(id)
return isObservable(a) && a.vertebral_region_code !== null
},
name: (a) =>
a.kind === 'detail_trigger'
? (a.name ?? views.get(a.opens_view_id)?.name ?? { fr: '', en: '' })
: a.name,
}
}
export { buildSheetIndex, isObservable, pickLabel } from '@faunosteo/domain'
export type { ObservableAnnotation } from '@faunosteo/domain'
export type SheetIndex = DomainSheetIndex<LoadedSheet>