Domotion

API overview

Every export from `domotion`, with one-line summaries.

Domotion's public surface is intentionally small — five functions, one class, and a handful of types. Everything is imported from the package root:

import {
  captureElementTree,
  elementTreeToSvg,
  wrapSvg,
  generateAnimatedSvg,
  DemoRecorder,
  optimizeSvg,
  getLastCaptureWarnings,
  logCaptureWarnings,
  type CapturedElement,
  type CaptureWarning,
  type AnimationConfig,
  type AnimationFrame,
  type Overlay,
  type TypingOverlay,
  type TapOverlay,
  type CaptureOptions,
} from "domotion";

The two-step API

The core capture pipeline is two functions:

FunctionWhat it does
captureElementTree(page, selector?, viewport) Walks the DOM under selector in a Playwright page and returns a serialisable CapturedElement[] tree.
elementTreeToSvg(tree, w, h, idPrefix?, includeGlyphDefs?) Pure function: converts the captured tree into an SVG fragment (defs + groups).
wrapSvg(inner, w, h) Wraps a fragment in the standard <svg xmlns="..."> shell so the result is a standalone, browser-loadable document.

Animation

FunctionWhat it does
generateAnimatedSvg(config) Composes multiple captured frames into one animated SVG with CSS keyframes.

The shape passed to generateAnimatedSvg is documented under AnimationConfig; overlay types under Overlay types.

The convenience class

ClassWhat it does
DemoRecorder Wraps Playwright bring-up + the two-step capture API. Best when capturing several pages from a running server.

Optimisation

FunctionWhat it does
optimizeSvg(svg) Runs SVGO with a structure-preserving plugin set — typically 30–50% size reduction without changing semantics.

Types

TypeUsed with
CapturedElementReturned by captureElementTree; consumed by elementTreeToSvg.
AnimationConfigArgument to generateAnimatedSvg.
AnimationFrameElement of AnimationConfig.frames.
Overlay / TypingOverlay / TapOverlayPer-frame overlays.
CaptureOptionsOptions to DemoRecorder.

Stability

Domotion is at 0.x. Patch and minor releases may change return shapes (especially CapturedElement's style fields, which track new CSS support) and tighten warning behavior. The functions and class listed above are stable; the function signatures aren't expected to change before 1.0 without a deprecation notice.