33 lines
864 B
JavaScript
33 lines
864 B
JavaScript
/**
|
|
* TT-Core Clipboard Utilities
|
|
* Modern clipboard operations with fallback support
|
|
*/
|
|
|
|
/**
|
|
* Copy text to clipboard
|
|
* @param {string} text - Text to copy
|
|
* @returns {Promise<boolean>} - Success status
|
|
*/
|
|
export async function copyToClipboard(text) {
|
|
try {
|
|
await navigator.clipboard.writeText(text || '');
|
|
return true;
|
|
} catch {
|
|
// Fallback for older browsers
|
|
const textarea = document.createElement('textarea');
|
|
textarea.value = text || '';
|
|
textarea.style.position = 'fixed';
|
|
textarea.style.opacity = '0';
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
try {
|
|
document.execCommand('copy');
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
} finally {
|
|
document.body.removeChild(textarea);
|
|
}
|
|
}
|
|
}
|