Bỏ qua để đến nội dung

SDK Trình xuất

Trình xuất là một tập hợp các hàm thuần trên DrawtonomySnapshot. Thêm một định dạng đích mới là tự chứa: một module mới, vài bài kiểm thử, và một móc UI tùy chọn.

Trang này là một định hướng nhanh. Hướng dẫn đầy đủ — kiến trúc, API, các mẫu kiểm thử, các kiểm tra trực quan esmini — nằm trong repo công khai:

Hướng dẫn Nhà phát triển Trình xuất (日本語)

Terminal window
git clone https://github.com/kosuke55/drawtonomy.git
cd drawtonomy
pnpm install
cd packages/drawtonomy-sdk
pnpm exec vitest exporter # watch mode
packages/drawtonomy-sdk/src/exporter/my-format.ts
import type { DrawtonomySnapshot } from '../types'
export function exportToMyFormat(snapshot: DrawtonomySnapshot): string {
// Walk shapes, emit your format.
return ''
}
packages/drawtonomy-sdk/__tests__/exporter/my-format.test.ts
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/>')
})
})

Các tệp drawtonomy.svg được đọc/ghi qua lại qua SDK, vì vậy bạn có thể tạo một cảnh trong trình chỉnh sửa và sử dụng nó làm đầu vào kiểm thử hồi quy:

import { readFileSync } from 'node:fs'
import { parseDrawtonomySvg } from '@drawtonomy/sdk'
const svg = readFileSync('./fixtures/my-scene.drawtonomy.svg', 'utf-8')
const snapshot = parseDrawtonomySvg(svg)!