# zumerlab/snapdom architecture

> Architecture diagram of the GitHub repository zumerlab/snapdom, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zumerlab/snapdom
- Repository: https://github.com/zumerlab/snapdom

## Overview

SnapDOM captures a rendered DOM subtree into a reusable frozen result, then exposes image, canvas, Blob, and download outputs. Its plugin package extends that result with HTML/context/agent-map exports, document formats, and live recordings; vector export also produces editable artwork and Figma payloads. The core capture stages and major plugin branches are represented, but several plugin internals were not sampled, so their links rely on README capability statements rather than inferred call chains.

Main entry points: [`src/api/snapdom.js`](https://github.com/zumerlab/snapdom/blob/main/src/api/snapdom.js) (Capture API), [`packages/plugins/vector/src/index.js`](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/index.js) (Vector export), [`packages/plugins/pdf/src/index.js`](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/pdf/src/index.js) (PDF export), [`src/modules/styles.js`](https://github.com/zumerlab/snapdom/blob/main/src/modules/styles.js) (Style snapshots)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Capture core"]
  node_api["Capture API<br/>[snapdom.js]"]
  node_context["Option context<br/>[context.js]"]
  node_capture["DOM capture<br/>[capture.js]"]
end

subgraph group_prep["Capture preparation"]
  node_clone["DOM cloning<br/>[clone.js]"]
  node_styles["Style snapshots<br/>[styles.js]"]
  node_fonts["Font embedding<br/>[fonts.js]"]
  node_cache[("Capture caches<br/>[cache.js]")]
end

subgraph group_output["Core outputs"]
  node_svg["SVG rendering<br/>[svg.js]"]
  node_canvas["Canvas export<br/>[toCanvas.js]"]
  node_download["File download<br/>[download.js]"]
end

subgraph group_plugins["Capture plugins"]
  node_html["HTML export<br/>[html-export.js]"]
  node_contextexport["Context export<br/>[context-export.js]"]
  node_agentmap["Agent map<br/>[agent-map.js]"]
  node_gif["GIF recording<br/>[gif-export.js]"]
  node_video["Video recording<br/>[video-export.js]"]
end

subgraph group_advanced["Document and vector"]
  node_pdf["PDF export<br/>[index.js]"]
  node_pdftext["PDF text layer<br/>[text-layer.js]"]
  node_pdfwriter["PDF writer<br/>[index.js]"]
  node_vector["Vector export<br/>[index.js]"]
  node_vectorcollect["Vector collection<br/>[box.js]"]
  node_vectortext["Vector text<br/>[text.js]"]
  node_vectorsvg["Flat SVG output<br/>[svg-flat.js]"]
end

node_user(("Page caller"))

node_user -->|"captures element"| node_api
node_api -->|"normalizes options"| node_context
node_api -->|"captures DOM"| node_capture
node_api -->|"prepares clone"| node_clone
node_api -->|"embeds styles"| node_styles
node_api -->|"waits for fonts"| node_fonts
node_api -->|"renders capture"| node_svg
node_api -->|"exports canvas"| node_canvas
node_api -->|"downloads result"| node_download
node_styles -->|"uses shared cache"| node_cache
node_fonts -->|"uses shared cache"| node_cache
node_canvas -->|"provides raster output"| node_download
node_api -.->|"offers plugin export"| node_html
node_api -.->|"offers plugin export"| node_contextexport
node_api -.->|"offers plugin export"| node_agentmap
node_api -.->|"records live element"| node_gif
node_api -.->|"records live element"| node_video
node_api -.->|"offers plugin export"| node_pdf
node_pdf -->|"builds text layer"| node_pdftext
node_pdf -->|"writes PDF"| node_pdfwriter
node_api -.->|"offers plugin export"| node_vector
node_vector -->|"collects geometry"| node_vectorcollect
node_vector -->|"collects text"| node_vectortext
node_vector -->|"emits SVG"| node_vectorsvg

click node_api "https://github.com/zumerlab/snapdom/blob/main/src/api/snapdom.js"
click node_context "https://github.com/zumerlab/snapdom/blob/main/src/core/context.js"
click node_capture "https://github.com/zumerlab/snapdom/blob/main/src/core/capture.js"
click node_clone "https://github.com/zumerlab/snapdom/blob/main/src/core/clone.js"
click node_styles "https://github.com/zumerlab/snapdom/blob/main/src/modules/styles.js"
click node_fonts "https://github.com/zumerlab/snapdom/blob/main/src/modules/fonts.js"
click node_cache "https://github.com/zumerlab/snapdom/blob/main/src/core/cache.js"
click node_svg "https://github.com/zumerlab/snapdom/blob/main/src/engines/svg.js"
click node_canvas "https://github.com/zumerlab/snapdom/blob/main/src/exporters/toCanvas.js"
click node_download "https://github.com/zumerlab/snapdom/blob/main/src/exporters/download.js"
click node_html "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/html-export.js"
click node_contextexport "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/context-export.js"
click node_agentmap "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/agent-map.js"
click node_gif "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/gif-export.js"
click node_video "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/video-export.js"
click node_pdf "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/pdf/src/index.js"
click node_pdftext "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/pdf/src/text-layer.js"
click node_pdfwriter "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/pdf/src/writer/index.js"
click node_vector "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/index.js"
click node_vectorcollect "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/collect/box.js"
click node_vectortext "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/collect/text.js"
click node_vectorsvg "https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/emit/svg-flat.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_context,node_capture toneBlue
class node_clone,node_styles,node_fonts,node_cache toneAmber
class node_svg,node_canvas,node_download toneMint
class node_html,node_contextexport,node_agentmap,node_gif,node_video toneRose
class node_pdf,node_pdftext,node_pdfwriter,node_vector,node_vectorcollect,node_vectortext,node_vectorsvg,node_user toneIndigo
```

## Components

### Capture core

- [Capture API](https://github.com/zumerlab/snapdom/blob/main/src/api/snapdom.js): `src/api/snapdom.js`
- [Option context](https://github.com/zumerlab/snapdom/blob/main/src/core/context.js): `src/core/context.js`
- [DOM capture](https://github.com/zumerlab/snapdom/blob/main/src/core/capture.js): `src/core/capture.js`

### Capture preparation

- [DOM cloning](https://github.com/zumerlab/snapdom/blob/main/src/core/clone.js): `src/core/clone.js`
- [Style snapshots](https://github.com/zumerlab/snapdom/blob/main/src/modules/styles.js): `src/modules/styles.js`
- [Font embedding](https://github.com/zumerlab/snapdom/blob/main/src/modules/fonts.js): `src/modules/fonts.js`
- [Capture caches](https://github.com/zumerlab/snapdom/blob/main/src/core/cache.js): `src/core/cache.js`

### Core outputs

- [SVG rendering](https://github.com/zumerlab/snapdom/blob/main/src/engines/svg.js): `src/engines/svg.js`
- [Canvas export](https://github.com/zumerlab/snapdom/blob/main/src/exporters/toCanvas.js): `src/exporters/toCanvas.js`
- [File download](https://github.com/zumerlab/snapdom/blob/main/src/exporters/download.js): `src/exporters/download.js`

### Capture plugins

- [HTML export](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/html-export.js): `packages/plugins/html-export.js`
- [Context export](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/context-export.js): `packages/plugins/context-export.js`
- [Agent map](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/agent-map.js): `packages/plugins/agent-map.js`
- [GIF recording](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/gif-export.js): `packages/plugins/gif-export.js`
- [Video recording](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/video-export.js): `packages/plugins/video-export.js`

### Document and vector

- [PDF export](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/pdf/src/index.js): `packages/plugins/pdf/src/index.js`
- [PDF text layer](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/pdf/src/text-layer.js): `packages/plugins/pdf/src/text-layer.js`
- [PDF writer](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/pdf/src/writer/index.js): `packages/plugins/pdf/src/writer/index.js`
- [Vector export](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/index.js): `packages/plugins/vector/src/index.js`
- [Vector collection](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/collect/box.js): `packages/plugins/vector/src/collect/box.js`
- [Vector text](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/collect/text.js): `packages/plugins/vector/src/collect/text.js`
- [Flat SVG output](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/vector/src/emit/svg-flat.js): `packages/plugins/vector/src/emit/svg-flat.js`

### Other components

- **Page caller**

## Connections

- Page caller → Capture API: captures element (evidence: `README.md`)
- Capture API → Option context: normalizes options (evidence: `src/api/snapdom.js`)
- Capture API → DOM capture: captures DOM (evidence: `src/api/snapdom.js`)
- Capture API → DOM cloning: prepares clone (evidence: `src/api/snapdom.js`)
- Capture API → Style snapshots: embeds styles (evidence: `src/api/snapdom.js`)
- Capture API → Font embedding: waits for fonts (evidence: `src/api/snapdom.js`)
- Capture API → SVG rendering: renders capture (evidence: `src/engines/svg.js`)
- Capture API → Canvas export: exports canvas (evidence: `src/api/snapdom.js`)
- Capture API → File download: downloads result (evidence: `src/exporters/download.js`)
- Style snapshots → Capture caches: uses shared cache (evidence: `src/modules/styles.js`)
- Font embedding → Capture caches: uses shared cache (evidence: `src/modules/fonts.js`)
- Canvas export → File download: provides raster output (evidence: `src/exporters/download.js`)
- Capture API → HTML export: offers plugin export (evidence: `README.md`)
- Capture API → Context export: offers plugin export (evidence: `README.md`)
- Capture API → Agent map: offers plugin export (evidence: `README.md`)
- Capture API → GIF recording: records live element (evidence: `README.md`)
- Capture API → Video recording: records live element (evidence: `README.md`)
- Capture API → PDF export: offers plugin export (evidence: `README.md`)
- PDF export → PDF text layer: builds text layer (evidence: `packages/plugins/pdf/src/index.js`)
- PDF export → PDF writer: writes PDF (evidence: `packages/plugins/pdf/src/index.js`)
- Capture API → Vector export: offers plugin export (evidence: `README.md`)
- Vector export → Vector collection: collects geometry (evidence: `packages/plugins/vector/src/index.js`)
- Vector export → Vector text: collects text (evidence: `packages/plugins/vector/src/index.js`)
- Vector export → Flat SVG output: emits SVG (evidence: `packages/plugins/vector/src/index.js`)
