Skip to main content

Building SVG in Lightpanda

How seven dependency-ordered contributions brought a typed SVG document model into Lightpanda.

Updated 3 min readMarkdown
Building SVG in Lightpanda

A capability is easier to review when each layer establishes the contract the next one needs.

A browser's graphics support is not just about whether an element exists on a page. Programs also need to identify its type, read and change its values, work with collections, ask geometry questions, and inspect text. Those behaviors form a platform contract that other software builds on.

For Lightpanda, I reworked a broad SVG prototype into seven dependency-ordered contributions. The stack moves from prototype inheritance through live values, collections, geometry, structural elements, resources, and text. All seven layers were merged. The useful story is how those layers made a substantial capability reviewable.

Make the foundation extensible.

The first layer derives SVG prototype chains at compile time. That foundation gives graphics and geometry elements the expected inheritance path without building another fixed-depth factory for every new interface. Identity matters because programs use inherited methods and type checks to decide how to interact with an element.

Live values and collections then build on that identity. Their behavior needs to remain connected to the element rather than becoming a detached copy of its current attributes. Treating those contracts as their own layers gave review and testing a smaller, more coherent unit of work.

A layer establishes a contract for the next.

  1. Element identity
  2. Live attribute behavior
  3. Higher-level geometry and text

The later APIs rely on the meaning established below them, not just on a shared file layout.

Keep geometry and text precise about what they provide.

The geometry work adds path parsing, length and point queries, and analytic fill bounds. Structural and resource elements extend the document model around that behavior. Each piece can be discussed in terms of a concrete API contract rather than a broad claim that graphics support is complete.

The text layer provides typed elements and isolated deterministic fallback metrics without introducing a new font-shaping dependency. That boundary is deliberate. Fallback measurements are useful within their documented role; they are not interchangeable with a complete shaping and rendering stack.

Use the delivery shape to improve the design.

Splitting a broad change is valuable when the split follows dependency meaning. A foundation can be reviewed and merged before the behavior that depends on it. Reviewers can ask whether a layer is internally sound and whether its contract is sufficient for the next layer, instead of holding the entire capability in their heads at once.

I use that approach when a system change spans several kinds of reasoning. It does not make the underlying work small. It makes the path through the work legible, and it gives a team useful checkpoints where they can refine the design without losing the overall direction.

What I take from it

Build and review SVG support in dependency order, keeping geometry, text metrics, and browser access as distinct responsibilities.

Code and further reading

Read the illustrated essay on mh0pe.github.io

About the author

  • Principal AI Architect. I help teams govern, ship, and scale AI, security, cloud, and developer systems. Illustrated essays and selected work at https://mh0pe.github.io/

No comments yet. Be the first to comment.