Documentation
¶
Overview ¶
Package waffle renders PDF documents from a React-authored element tree.
Documents are written in ReactJS exactly as react-pdf users write them today. waffle can consume them two ways:
- In-process (recommended): LoadTemplate/RenderReact transpile a JSX/TSX source with esbuild and execute it with the goja JavaScript engine — real React runs inside the Go process, with no Node.js at render time. goja is waffle's single JS engine; there is no sidecar.
- Static tree: RenderTree ingests a waffle-tree/v1 JSON document (the serialized element tree), for setups that prefer to produce the tree in a separate step. This is the same contract the in-process path emits.
Both paths feed the same Go pipeline: parse the contract, build and validate the element tree, lay it out (flexbox + text + pagination), and paint the PDF. See the README's Architecture section and docs/architecture.excalidraw.
Index ¶
Constants ¶
const Version = "0.0.0-dev"
Version is the current waffle library version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RenderInfo ¶
RenderInfo reports the outcome of a render.
func RenderReact ¶
RenderReact is a one-shot convenience: compile source and render it with props to a PDF in a single call. Prefer LoadTemplate when rendering the same document repeatedly, so compilation happens once.
func RenderTree ¶
RenderTree renders a waffle-tree/v1 document (as produced by @waffle/react) to a PDF written to w. It runs the full pipeline: parse the contract, build and validate the element tree, lay it out, and paint it.
This is the static-tree entry point (execution mode 2). It does not evaluate function-valued props (render callbacks, canvas paint, hyphenation); documents that require them need a VM execution mode, added in a later phase.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a compiled React document that renders to PDF with varying props.
The source is a JSX/TSX module whose default export is either a <Document> element or a function of props returning one, exactly as react-pdf documents are authored. It is transpiled (esbuild) and executed (goja) entirely inside the Go process — waffle needs no Node.js at render time. A Template is safe to Render repeatedly, including concurrently: each Render runs on its own VM.
A Template caches its decoded assets: images are decoded (and their pixels compressed) and registered fonts fetched and parsed once, on first use, then reused by every subsequent Render. File and URL sources are therefore read once per Template — a change to the underlying file is picked up by loading a new Template, not by re-rendering an existing one.
func LoadTemplate ¶
func LoadTemplate(source []byte, opts TemplateOptions) (*Template, error)
LoadTemplate compiles a React source into a reusable Template.
type TemplateOptions ¶
type TemplateOptions struct {
// TypeScript parses the source as TSX instead of JSX.
TypeScript bool
// Filename labels the source in compile/runtime error messages.
Filename string
}
TemplateOptions configures how a React source is compiled into a Template.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
waffle
command
Command waffle renders a React document to a PDF.
|
Command waffle renders a React document to a PDF. |
|
examples
|
|
|
appointment
command
Command appointment renders the offer/appointment-letter example to a PDF.
|
Command appointment renders the offer/appointment-letter example to a PDF. |
|
appointment/bench
command
Command bench load-tests the in-process JSX->PDF render.
|
Command bench load-tests the in-process JSX->PDF render. |
|
boxes
command
Command boxes renders a small styled View tree (a waffle-tree/v1 document) to boxes.pdf, demonstrating the end-to-end pipeline: contract → tree → layout → PDF.
|
Command boxes renders a small styled View tree (a waffle-tree/v1 document) to boxes.pdf, demonstrating the end-to-end pipeline: contract → tree → layout → PDF. |
|
hello
command
Command hello renders a minimal single-page PDF using the Phase 1 writer core.
|
Command hello renders a minimal single-page PDF using the Phase 1 writer core. |
|
multipage
command
Command multipage builds a data-driven document (24 rows) that overflows a small page, demonstrating automatic pagination.
|
Command multipage builds a data-driven document (24 rows) that overflows a small page, demonstrating automatic pagination. |
|
react
command
This example renders a React-authored invoice to a PDF with data supplied from Go — the whole point of waffle: author in React, drive it with Go data, render in-process on goja with no Node.js.
|
This example renders a React-authored invoice to a PDF with data supplied from Go — the whole point of waffle: author in React, drive it with Go data, render in-process on goja with no Node.js. |
|
text
command
Command text renders a small typographic document to text.pdf, exercising the standard-14 font path (Helvetica/Times/Courier, weights and italics) end to end.
|
Command text renders a small typographic document to text.pdf, exercising the standard-14 font path (Helvetica/Times/Courier, weights and italics) end to end. |
|
internal
|
|
|
contract
Package contract defines waffle-tree/v1: the versioned JSON boundary between the React authoring layer (@waffle/react) and the Go rendering engine.
|
Package contract defines waffle-tree/v1: the versioned JSON boundary between the React authoring layer (@waffle/react) and the Go rendering engine. |
|
fetch
Package fetch resolves a resource reference — a data: URI, an http(s) URL, or a local file path — to raw bytes, with a size cap and a scheme allowlist.
|
Package fetch resolves a resource reference — a data: URI, an http(s) URL, or a local file path — to raw bytes, with a size cap and a scheme allowlist. |
|
flexbox
Package flexbox is waffle's own flexbox layout engine — the replacement for react-pdf's Yoga binding.
|
Package flexbox is waffle's own flexbox layout engine — the replacement for react-pdf's Yoga binding. |
|
fontstore
Package fontstore registers and resolves fonts and measures text.
|
Package fontstore registers and resolves fonts and measures text. |
|
imaging
Package imaging decodes images for PDF embedding.
|
Package imaging decodes images for PDF embedding. |
|
jsruntime
Package jsruntime is waffle's in-process JavaScript engine: it transpiles a user's JSX/TSX React document and runs it entirely inside the Go process to produce a waffle-tree/v1 JSON document — no Node.js at render time.
|
Package jsruntime is waffle's in-process JavaScript engine: it transpiles a user's JSX/TSX React document and runs it entirely inside the Go process to produce a waffle-tree/v1 JSON document — no Node.js at render time. |
|
layout
Package layout is the layout pipeline: it resolves styles and page sizes, drives the flexbox engine, and produces a tree of positioned boxes ready for painting.
|
Package layout is the layout pipeline: it resolves styles and page sizes, drives the flexbox engine, and produces a tree of positioned boxes ready for painting. |
|
pdf
Package pdf is a write-only PDF 1.3–1.7 serializer: the low-level object model, document/xref writer, content-stream operator builder, and standard-14 font support.
|
Package pdf is a write-only PDF 1.3–1.7 serializer: the low-level object model, document/xref writer, content-stream operator builder, and standard-14 font support. |
|
pdf/afm
Package afm parses Adobe Font Metrics for the 14 standard PDF fonts and exposes glyph widths and font metrics used for text measurement.
|
Package afm parses Adobe Font Metrics for the 14 standard PDF fonts and exposes glyph widths and font metrics used for text measurement. |
|
render
Package render paints a laid-out document (layout.Result) onto the PDF writer, producing the final bytes.
|
Package render paints a laid-out document (layout.Result) onto the PDF writer, producing the final bytes. |
|
stylesheet
Package stylesheet parses react-pdf-shaped style values into typed, resolved forms for the layout engine: dimensioned values and their unit conversions, colors, font weights, and style flattening.
|
Package stylesheet parses react-pdf-shaped style values into typed, resolved forms for the layout engine: dimensioned values and their unit conversions, colors, font weights, and style flattening. |
|
svgparse
Package svgparse parses SVG path data and basic shapes into a vector IR of move/line/cubic/close segments, ready to emit as PDF path operators.
|
Package svgparse parses SVG path data and basic shapes into a vector IR of move/line/cubic/close segments, ready to emit as PDF path operators. |
|
transform
Package transform parses CSS transform strings (translate, scale, rotate, skew, matrix) and composes them into a single 2D affine matrix expressed in PDF operand order [A B C D E F].
|
Package transform parses CSS transform strings (translate, scale, rotate, skew, matrix) and composes them into a single 2D affine matrix expressed in PDF operand order [A B C D E F]. |
|
tree
Package tree is the internal, validated element model the layout pipeline walks.
|
Package tree is the internal, validated element model the layout pipeline walks. |