feat(app): application on the canonical sheet — report v3 store with v2 draft migration, bundled SheetProvider (SHEET_BUNDLE), annotation layer rendered from the document, zone interaction service, pickers and cards on the sheet index, PDF v3 export with v2 archive import; legacy registry, matchers, editors and assets removed
This commit is contained in:
1 parent
0a17e390cf
commit
ce2ec26112
114 files changed
+3560
-14637
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
/**
|
||||
* Bundles the reference anatomical sheet (the generated seed draft) into the
|
||||
* application as the virtual module `virtual:faunosteo-sheet`.
|
||||
*
|
||||
* Mode `draft` embeds `document.json`, `sheet-ref.json`,
|
||||
* `report-migration-map.json` and the SVG assets of the seed folder; mode
|
||||
* `none` exports null and the app shows "no sheet configured". The default is
|
||||
* `draft` for the dev server and `none` for a build: a production bundle never
|
||||
* carries the medically unvalidated draft unless `SHEET_BUNDLE=draft` is set
|
||||
* on purpose (BDR-037, D2).
|
||||
*/
|
||||
|
||||
export const SHEET_VIRTUAL_ID = 'virtual:faunosteo-sheet'
|
||||
const RESOLVED_ID = `\0${SHEET_VIRTUAL_ID}`
|
||||
|
||||
export type SheetBundleMode = 'draft' | 'none'
|
||||
|
||||
export function resolveSheetBundleMode(
|
||||
env: Record<string, string | undefined>,
|
||||
command: 'build' | 'serve',
|
||||
): SheetBundleMode {
|
||||
const raw = env.SHEET_BUNDLE
|
||||
if (raw === 'draft' || raw === 'none') return raw
|
||||
if (raw !== undefined && raw !== '') {
|
||||
throw new Error(`SHEET_BUNDLE must be "draft" or "none", got "${raw}"`)
|
||||
}
|
||||
return command === 'serve' ? 'draft' : 'none'
|
||||
}
|
||||
|
||||
interface SeedFiles {
|
||||
ref: unknown
|
||||
document: unknown
|
||||
migrationMap: unknown
|
||||
assets: Record<string, string>
|
||||
watched: string[]
|
||||
}
|
||||
|
||||
function readSeed(seedDir: string): SeedFiles {
|
||||
const json = (name: string) =>
|
||||
JSON.parse(readFileSync(join(seedDir, name), 'utf8')) as unknown
|
||||
const manifest = json('assets.json') as {
|
||||
file: string
|
||||
svg_asset_id: string
|
||||
}[]
|
||||
const assets: Record<string, string> = {}
|
||||
for (const asset of manifest) {
|
||||
assets[asset.svg_asset_id] = readFileSync(
|
||||
join(seedDir, 'assets', asset.file),
|
||||
'utf8',
|
||||
)
|
||||
}
|
||||
return {
|
||||
ref: json('sheet-ref.json'),
|
||||
document: json('document.json'),
|
||||
migrationMap: json('report-migration-map.json'),
|
||||
assets,
|
||||
watched: [
|
||||
'sheet-ref.json',
|
||||
'document.json',
|
||||
'report-migration-map.json',
|
||||
'assets.json',
|
||||
...manifest.map((a) => `assets/${a.file}`),
|
||||
].map((name) => join(seedDir, name)),
|
||||
}
|
||||
}
|
||||
|
||||
export function faunosteoSheetBundle(options: {
|
||||
mode: SheetBundleMode
|
||||
seedDir: string
|
||||
}): Plugin {
|
||||
return {
|
||||
name: 'faunosteo-sheet-bundle',
|
||||
resolveId(id) {
|
||||
return id === SHEET_VIRTUAL_ID ? RESOLVED_ID : null
|
||||
},
|
||||
load(id) {
|
||||
if (id !== RESOLVED_ID) return null
|
||||
if (options.mode === 'none') return 'export const bundledSheet = null\n'
|
||||
const seed = readSeed(options.seedDir)
|
||||
for (const file of seed.watched) this.addWatchFile(file)
|
||||
const payload = {
|
||||
status: 'draft',
|
||||
ref: seed.ref,
|
||||
document: seed.document,
|
||||
migrationMap: seed.migrationMap,
|
||||
assets: seed.assets,
|
||||
}
|
||||
return `export const bundledSheet = ${JSON.stringify(payload)}\n`
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user