This commit is contained in:
talorr
2026-03-27 03:36:08 +03:00
parent 8a97ce6d54
commit cda36918e8
225 changed files with 35641 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
export const useClipboard = () => {
const fallbackCopy = (value: string) => {
const textarea = document.createElement("textarea");
textarea.value = value;
textarea.setAttribute("readonly", "true");
textarea.style.position = "fixed";
textarea.style.top = "-9999px";
textarea.style.left = "-9999px";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
return document.execCommand("copy");
} finally {
document.body.removeChild(textarea);
}
};
const copyText = async (value: string) => {
if (!process.client) {
return false;
}
const normalized = value.trim();
if (!normalized) {
return false;
}
try {
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(normalized);
return true;
}
} catch {
// Fall through to legacy copy API for embedded webviews.
}
return fallbackCopy(normalized);
};
return { copyText };
};