@aplus-frontend/ui
Version:
32 lines (31 loc) • 748 B
JavaScript
function a(t, e) {
const o = e?.format;
if (typeof t != "string")
return !1;
try {
if (o === "text/html") {
const n = new ClipboardItem({
[o]: new Blob([t], { type: o }),
"text/plain": new Blob([t], { type: "text/plain" })
});
navigator.clipboard.write([n]);
} else
navigator.clipboard.writeText(t);
return !0;
} catch {
return r(t);
}
}
function r(t) {
try {
const e = document.createElement("textarea");
e.value = t, e.style.position = "fixed", e.style.opacity = "0", document.body.appendChild(e), e.focus(), e.select();
const o = document.execCommand("copy");
return document.body.removeChild(e), o;
} catch {
return !1;
}
}
export {
a as copy
};