Files
brk/websites/bitview/packages/modern-screenshot/wrapper.js
2025-08-31 17:05:28 +02:00

39 lines
840 B
JavaScript

import { domToBlob } from "./4.6.6/dist/index.mjs";
/**
* @param {Object} args
* @param {Element} args.element
* @param {string} args.name
* @param {string} args.title
* @param {Env} args.env
*/
export async function screenshot({ element, name, title, env }) {
const blob = await domToBlob(element, {
scale: 2,
});
if (env.ios) {
const file = new File(
[blob],
`bitview-${name}-${new Date().toJSON().split(".")[0]}.png`,
{
type: "image/png",
},
);
try {
await navigator.share({
files: [file],
title: `${title} on ${window.document.location.hostname}`,
});
return;
} catch (err) {
console.log(err);
}
}
const url = URL.createObjectURL(blob);
window.open(url, "_blank");
setTimeout(() => URL.revokeObjectURL(url), 100);
}