You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(plugins): expose capture geometry, exact export options and canvas cropping
Document exporters need to know where the content sits inside the serialized
SVG and to rasterize it a region at a time. Three additions, all read-only
surface:
- result.meta / context.meta: frozen render geometry (viewBox size, logical
capture box, contentX/contentY origin, resolved clip window). contentX/Y are
the exact origin rather than a centred guess, so they stay correct under
asymmetric shadows, transformed roots and clip windows. The property is
non-writable so a hook cannot desynchronise it from the canonical SVG, but it
stays configurable: options is caller-owned and toPng/toJpg/toWebp pass their
raw bag straight to captureDOM, so a reused object must be able to take a
second capture's geometry instead of throwing "Cannot redefine property".
- export.requestedOptions: a frozen shallow copy of exactly what the caller
passed, snapshotted when toXxx() is called rather than when the export
reaches the session queue. Callers commonly reuse an options object, and a
slow earlier export must not let later mutation rewrite an already-requested
one. Key presence is preserved, so a plugin can tell an explicit value from an
omitted one even when it equals the capture default.
- toCanvas({ crop }): windows the SVG in viewBox coordinates by rewriting the
header before decode, so a long capture can be rasterized page by page
instead of allocating one bitmap that exceeds the browser decode limits. The
crop clips to the intersection with the viewBox and never degrades silently:
an empty, non-finite or fully outside window, or a non-SVG payload, rejects
with a RangeError rather than returning the whole capture where one page was
asked for. The decoded bitmap becomes the aspect reference, otherwise a
width-only crop inherits the full document ratio and stretches.
**Priority.** When multiple sources define the same export key, resolution is **local plugin > global plugin > core**. So a plugin passed via `snapdom(el, { plugins: [...] })` can override `toPng`, `toJpg`, `toCanvas`, etc., and a per-capture plugin beats a globally-registered one with the same key. Use this to swap a core exporter for a plugin implementation (e.g. a plugin-provided `png` that reuses the existing SVG via `ctx.export.url`).
167
178
179
+
`defineExports(ctx)` also receives `ctx.exports`, a silent facade over the core
180
+
exporters. It reuses this capture without recursively firing export hooks. Its
181
+
`canvas()` method accepts `crop: { x, y, width, height }` in SVG viewBox
182
+
coordinates; SnapDOM windows the SVG before image decode, allowing document
183
+
plugins to rasterize page-sized regions instead of one browser-limited bitmap.
184
+
A crop is clipped to the intersection with the viewBox, and it never degrades
185
+
silently: a non-finite or empty window, a window fully outside the viewBox, or a
186
+
payload that is not a serialized SVG capture all reject with a `RangeError`
187
+
rather than returning the whole capture where one page was requested.
188
+
The returned capture object exposes the same immutable render geometry as
189
+
`result.meta`; both the metadata value and the result property that holds it are
190
+
non-writable/non-configurable. Auxiliary element captures can therefore measure
191
+
their own final SVG artifact without consulting the live source tree or risking
0 commit comments