import { toBlob } from "html-to-image"; import { stripExtension } from "./path"; import { isObject } from "./lang"; import { blobToFile } from "./file"; function generateScreenshotFilename(name = null, ext = null) { name = [stripExtension(name || "screenshot"), new Date().getTime()].join("-"); return ext ? `${name}.${ext}` : name; } // Attempts to convert a DOM element into a static image. // Returns a File object. async function captureElementScreenshot(el, filename, opts = {}) { if (isObject(filename)) { filename = null; opts = filename; } filename = generateScreenshotFilename(filename, "jpg"); const imageBlob = await toBlob(el, opts); return blobToFile(imageBlob, filename, "image/jpg"); } export { captureElementScreenshot };