UNPKG

@kelvininc/ui-components

Version:
35 lines (31 loc) 1.14 kB
import { i as isNil } from './p-CRcRM80a.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, fallbackCopyTextToClipboard as f };