bitview: fix screenshot in ios

This commit is contained in:
nym21
2025-08-31 16:17:50 +02:00
parent cc6913c854
commit f6d9332c48
3 changed files with 64 additions and 28 deletions

View File

@@ -1,12 +1,37 @@
import { domToBlob } from "./4.6.6/dist/index.mjs";
/**
* @param {Element} element
* @param {Object} args
* @param {Element} args.element
* @param {string} args.name
* @param {string} args.title
* @param {Env} args.env
*/
export async function screenshot(element) {
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: `Bitview screenshot: ${title}`,
});
return;
} catch (err) {
console.log(err);
}
}
const url = URL.createObjectURL(blob);
window.open(url, "_blank");
setTimeout(() => URL.revokeObjectURL(url), 100);