OCIF (Open Canvas Interchange Format) plugin for tldraw — import and export canvases using the OCWG specification.
Status: Implements OCIF v0.7.0
npm install tldraw-ocif tldrawtldraw is a peer dependency — make sure it's installed in your project.
import { serializeTldrawToOcif } from 'tldraw-ocif'
// `editor` is a tldraw Editor instance
const ocifJson = await serializeTldrawToOcif(editor)
// Download as file
const blob = new Blob([ocifJson], { type: 'application/vnd.ocif+json' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = 'canvas.ocif.json'
a.click()import { parseAndLoadOcifFile } from 'tldraw-ocif'
const ocifContent = await file.text()
await parseAndLoadOcifFile(editor, ocifContent, msg, addToast)import { parseOcifFile } from 'tldraw-ocif'
import { createTLSchema } from 'tldraw'
const schema = createTLSchema()
const result = parseOcifFile({ json: ocifContent, schema })
if (result.ok) {
const store = result.value
const records = store.allRecords()
// work with records...
}| Export | Description |
|---|---|
serializeTldrawToOcif(editor) |
Export the current page to an OCIF v0.7.0 JSON string |
serializeTldrawToOcifBlob(editor) |
Export to a Blob with the correct MIME type |
parseOcifFile({ json, schema }) |
Parse OCIF JSON → Result<TLStore, OcifFileParseError> |
parseAndLoadOcifFile(editor, json, msg, addToast) |
Parse and load OCIF directly into a tldraw editor |
OCIF_FILE_MIMETYPE |
'application/vnd.ocif+json' |
OCIF_FILE_EXTENSION |
'.ocif.json' |
OcifFile
OcifNode
OcifResource
OcifRepresentation
OcifSchema
OcifFileParseError@ocif/rect— rectangles (and geo variants like diamond, star, triangle, etc.)@ocif/oval— ellipses / circles@ocif/path— SVG paths / freehand drawing@ocif/arrow— arrows with markers
@ocif/edge— directed/undirected edges between nodes@ocif/group— grouping nodes together@ocif/hyperedge— many-to-many relationships- Node
parentproperty — frame containment / nesting
@ocif/textstyle— font size, family, color, alignment
@ocif/ports— precise anchor points for arrow bindings- Node
scaleproperty — scale factor (v0.7.0 core property)
- Image, video, and bookmark assets with representations
@tldraw/node/note— sticky notes@tldraw/node/embed— embedded content (YouTube, etc.)@tldraw/node/bookmark— bookmarks with metadata@tldraw/node/highlight— highlighter strokes
npm install
npm run build # Build with tsup
npm test # Run tests with vitest
npm run dev # Watch modeMIT