Documentation
¶
Overview ¶
Package contract defines waffle-tree/v1: the versioned JSON boundary between the React authoring layer (@waffle/react) and the Go rendering engine. It parses the wire format into a lightly-typed node tree, leaving interpretation of styles, units, and props to downstream subsystems (the stylesheet and layout engines), exactly as react-pdf keeps its node tree uninterpreted until layout.
Index ¶
Constants ¶
const ( TypeDocument = "DOCUMENT" TypePage = "PAGE" TypeView = "VIEW" TypeText = "TEXT" TypeTextInstance = "TEXT_INSTANCE" TypeImage = "IMAGE" TypeImageBackground = "IMAGE_BACKGROUND" TypeLink = "LINK" TypeNote = "NOTE" TypeCanvas = "CANVAS" TypeSvg = "SVG" TypeG = "G" TypePath = "PATH" TypeRect = "RECT" TypeCircle = "CIRCLE" TypeEllipse = "ELLIPSE" TypeLine = "LINE" TypePolyline = "POLYLINE" TypePolygon = "POLYGON" TypeTspan = "TSPAN" TypeDefs = "DEFS" TypeClipPath = "CLIP_PATH" TypeLinearGradient = "LINEAR_GRADIENT" TypeRadialGradient = "RADIAL_GRADIENT" TypeStop = "STOP" TypeMarker = "MARKER" TypeTextInput = "TEXT_INPUT" TypeCheckbox = "CHECKBOX" TypeSelect = "SELECT" TypeList = "LIST" TypeFieldSet = "FIELD_SET" )
Node type strings mirror react-pdf's primitive constants so the reconciler is a near pass-through and react-pdf's component docs describe this contract.
const Version = "waffle-tree/v1"
Version is the contract version this build implements.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CallbackRef ¶
type CallbackRef struct {
ID string
}
CallbackRef is a serialized function-valued prop, wire form {"$cb":"cb_1"}. Function props (render, paint, hyphenationCallback, image src callbacks) can only be evaluated in a VM execution mode; the layout pipeline resolves them through a CallbackEvaluator.
type Document ¶
type Document struct {
Props map[string]any
Fonts []FontRegistration
EmojiSource *EmojiSource
HyphenationCallback *CallbackRef
Children []*Node
}
Document is the root of the tree: document-level props and metadata plus the page children.
type EmojiSource ¶
EmojiSource mirrors Font.registerEmojiSource (URL-template form).
type FontFace ¶
type FontFace struct {
Src any // string URL/path, InlineAsset, or map with fetch options
FontWeight any // json.Number or keyword string; resolved by the font store
FontStyle string
}
FontFace is one registered face of a font family.
type FontRegistration ¶
FontRegistration mirrors a Font.register call from @waffle/react.
type InlineAsset ¶
type InlineAsset struct {
Base64 string
}
InlineAsset is an inlined binary asset, wire form {"$inline":"<base64>"}. The CLI's --inline-assets flag converts local font/image references into this form so the engine needs no filesystem access to them.
type Node ¶
Node is one element of the tree. Prop values are decoded JSON scalars (json.Number, string, bool, nil), maps, and slices, with $cb/$inline sentinels replaced by CallbackRef/InlineAsset. TEXT_INSTANCE nodes carry Value and have no children.
type Tree ¶
type Tree struct {
Version string
Document *Document
Callbacks []string // callback ids declared by the producer
Warnings []string // non-fatal issues (unknown types, callback mismatches)
}
Tree is a parsed waffle-tree document.
func Parse ¶
Parse decodes a waffle-tree/v1 document. Numbers are preserved as json.Number so downstream style parsing sees exact values. Unknown node types and props are tolerated and surfaced as warnings rather than errors, so a newer producer degrades gracefully against an older engine.
func (*Tree) RequiresEvaluator ¶
RequiresEvaluator reports whether the tree contains function-valued props that need a VM execution mode (embedded runtime or sidecar) to resolve. A tree with none can be rendered from the static-tree path alone.