CanvasDocument version 1 is the only cross-product persistence envelope.
Required roots are schema, version, canvas, non-empty pages, and elements; resources, meta, and portable viewState are optional.
Known kinds are shape, path, text, richText, image, chart, connector, group, and frame.
Custom kinds require a namespace delimiter such as example.widget and extend through type, data, and meta.
History, callbacks, DOM nodes, render caches, measurements, decoded images, workers, and transient drag state are never serialized.
CanvasPage x/y positions the authored page in workspace coordinates.
CanvasElement transform is local to its owning page; moving a page does not rewrite child transforms.
Connector explicit points are page-local; anchor x/y values are local to the referenced element.
Cantext layout pages are derived runtime output, not additional authored Canvas pages.
Page and element IDs are unique non-empty strings; every element pageId resolves to an existing page.
Connector endpoints and group/frame children stay on the owning page.
Containment is acyclic and one child cannot have multiple container owners.
Canonical IDs, transforms, visibility, opacity, z-order, style, and connector endpoints override duplicate product payload data.
A product adapter must preserve foreign elements byte-for-byte at the semantic JSON level when it cannot edit them.
Parse unknown JSON; do not cast it to CanvasDocument.
Serialize canonical document state, not a product-native snapshot inside another root object.
Reject unsupported schema/version values instead of silently guessing a migration.
import { canvasDocumentCodec } from "@pixxl-tools/canvas";
export function openCanvasDocument(source: string) {
const document = canvasDocumentCodec.parse(JSON.parse(source));
return {
document,
prettyJson: canvasDocumentCodec.toPrettyJson(document),
};
}