17 lines
576 B
TypeScript
17 lines
576 B
TypeScript
import { readFile } from 'node:fs/promises'
|
|
|
|
import { BUILTIN_IO_FORMATS, IORegistry, initCanvasKit } from '@open-pencil/core/io'
|
|
import { computeAllLayouts } from '@open-pencil/core/layout'
|
|
import type { SceneGraph } from '@open-pencil/scene-graph'
|
|
|
|
export { initCanvasKit }
|
|
|
|
const io = new IORegistry(BUILTIN_IO_FORMATS)
|
|
|
|
export async function loadDocument(filePath: string): Promise<SceneGraph> {
|
|
const bytes = new Uint8Array(await readFile(filePath))
|
|
const { graph } = await io.readDocument({ name: filePath, data: bytes })
|
|
computeAllLayouts(graph)
|
|
return graph
|
|
}
|