@kelvininc/ui-components
Version:
Kelvin UI Components
35 lines (31 loc) • 1.1 kB
JavaScript
import { i as isNil } from './p-BEvgYojK.js';
function fallbackCopyTextToClipboard(text) {
const textArea = document.createElement('textarea');
let isCopySuccessful = true;
textArea.value = text;
textArea.style.position = 'fixed';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
isCopySuccessful = document.execCommand('copy');
}
catch (err) {
isCopySuccessful = false;
}
document.body.removeChild(textArea);
return isCopySuccessful;
}
async function copyTextToClipboard(text) {
const sanitizedText = !isNil(text) ? text.replace(/^\s+|\s+$/gm, '') : '';
if (isNil(navigator.clipboard)) {
return fallbackCopyTextToClipboard(sanitizedText);
}
return await navigator.clipboard.writeText(sanitizedText).then(() => true, _ => false);
}
var clipboard_helper = /*#__PURE__*/Object.freeze({
__proto__: null,
copyTextToClipboard: copyTextToClipboard,
fallbackCopyTextToClipboard: fallbackCopyTextToClipboard
});
export { copyTextToClipboard as a, clipboard_helper as c };