listpage-next 0.0.279 → 0.0.280
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies text to the clipboard using the Clipboard API or a fallback method.
|
|
3
|
+
* Compatible with Google Chrome and other modern browsers.
|
|
4
|
+
*
|
|
5
|
+
* @param text The text to copy.
|
|
6
|
+
* @returns A promise that resolves to true if the copy was successful, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function copyToClipboard(text: string): Promise<boolean>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
async function copyToClipboard(text) {
|
|
2
|
+
if (!text) return false;
|
|
3
|
+
try {
|
|
4
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
5
|
+
await navigator.clipboard.writeText(text);
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
} catch (err) {
|
|
9
|
+
console.warn('Clipboard API failed, attempting fallback...', err);
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const textArea = document.createElement('textarea');
|
|
13
|
+
textArea.value = text;
|
|
14
|
+
textArea.style.position = 'fixed';
|
|
15
|
+
textArea.style.left = '-9999px';
|
|
16
|
+
textArea.style.top = '0';
|
|
17
|
+
textArea.setAttribute('readonly', '');
|
|
18
|
+
document.body.appendChild(textArea);
|
|
19
|
+
textArea.focus();
|
|
20
|
+
textArea.select();
|
|
21
|
+
const successful = document.execCommand('copy');
|
|
22
|
+
document.body.removeChild(textArea);
|
|
23
|
+
return successful;
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error('Fallback copy failed', err);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export { copyToClipboard };
|