@kelvininc/ui-components
Version:
Kelvin UI Components
38 lines (33 loc) • 1.16 kB
JavaScript
;
var isNil = require('./isNil-B-fGcnNC.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.isNil(text) ? text.replace(/^\s+|\s+$/gm, '') : '';
if (isNil.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
});
exports.clipboard_helper = clipboard_helper;
exports.copyTextToClipboard = copyTextToClipboard;