@reactsnap/core is the package you reach for when you want low-level control over browser-side rendering and export behavior.
Main exports#
renderToPng(input, options?)#
Render a DOM node to a PNG Blob.
import { renderToPng } from '@reactsnap/core';
const blob = await renderToPng(document.getElementById('card')!, {
width: 1200,
height: 630,
scale: 2,
background: '#ffffff',
});
renderToJpeg(input, options?)#
Render a DOM node to a JPEG Blob.
renderToWebp(input, options?)#
Render a DOM node to a WebP Blob.
renderToCanvas(input, options?)#
Render a DOM node to an HTMLCanvasElement for post-processing inside the browser.
supportsHtmlInCanvas()#
Check whether the current browser exposes the experimental WICG APIs ReactSnap uses today.
import { renderToPng, supportsHtmlInCanvas } from '@reactsnap/core';
const blob = await renderToPng(node, {
strategy: supportsHtmlInCanvas() ? 'html-in-canvas' : 'foreign-object',
debug: true,
});
Render options#
The published package exposes these important options:
widthheightscalebackgroundpixelRatiostrategywaitUntilfontEmbedimageEmbedallowTainttimeoutdebugonStrategyResolved
Strategy usage guidance#
- Use
autofor most in-browser preview flows. - Use
html-in-canvasonly when you explicitly want the experimental route and can handle unsupported browsers. - Use
foreign-objectwhen a deterministic baseline matters.
Related exports#
@reactsnap/core also exposes nodeToCanvas, nodeToSvgString, nodeToSvgDataUrl, and downloadBlob for lower-level browser workflows.