Sha256: 38c7fbbd3692fce85149f83a47df5a8555a4e6974569fc7d6da4212c4f2a6061

Contents?: true

Size: 766 Bytes

Versions: 2

Compression:

Stored size: 766 Bytes

Contents

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 };

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
coveragebook_components-0.5.1 app/assets/js/helpers/screenshot.js
coveragebook_components-0.5.0 app/assets/js/helpers/screenshot.js