导出器 SDK
导出器是一组针对 DrawtonomySnapshot 的纯函数。
新增一个目标格式是自包含的:一个新模块、几个测试,
以及一个可选的 UI 钩子。
本页是一份快速指南。完整说明——架构、API、测试模式、 基于 esmini 的可视化校验——位于公开仓库:
➡ Exporter Developer Guide (日本語)
git clone https://github.com/kosuke55/drawtonomy.gitcd drawtonomypnpm installcd packages/drawtonomy-sdkpnpm exec vitest exporter # watch 模式一个最小的新导出器
Section titled “一个最小的新导出器”import type { DrawtonomySnapshot } from '../types'
export function exportToMyFormat(snapshot: DrawtonomySnapshot): string { // 遍历图形,输出你的格式。 return ''}import { describe, it, expect } from 'vitest'import { exportToMyFormat } from '../../src/exporter/my-format'import { createSnapshot, createLane } from '../../src/index'
describe('my-format exporter', () => { it('emits expected payload for a single lane', () => { const snapshot = createSnapshot([createLane(/* ... */)]) expect(exportToMyFormat(snapshot)).toContain('<expected/>') })})用真实场景作为 fixture
Section titled “用真实场景作为 fixture”drawtonomy.svg 文件可以通过 SDK 双向往返,
所以你可以在编辑器里制作一个场景,作为回归测试输入:
import { readFileSync } from 'node:fs'import { parseDrawtonomySvg } from '@drawtonomy/sdk'
const svg = readFileSync('./fixtures/my-scene.drawtonomy.svg', 'utf-8')const snapshot = parseDrawtonomySvg(svg)!- 导出器架构 — 导出管线及它为何是纯函数。
@drawtonomy/sdk概览