tdesign-react
Version:
TDesign Component for React
34 lines (30 loc) • 998 B
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { c as canUseDocument } from '../_chunks/dep-3a09424a.js';
import 'lodash-es';
function copyText(text) {
var _document$execCommand, _document;
if (!canUseDocument) return;
if ("clipboard" in navigator) {
navigator.clipboard.writeText(text);
return;
}
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.width = "0px";
textarea.style.height = "0px";
document.body.appendChild(textarea);
var selection = document.getSelection();
var range = document.createRange();
range.selectNode(textarea);
selection.removeAllRanges();
selection.addRange(range);
(_document$execCommand = (_document = document).execCommand) === null || _document$execCommand === void 0 || _document$execCommand.call(_document, "copy");
selection.removeAllRanges();
document.body.removeChild(textarea);
}
export { copyText as default };
//# sourceMappingURL=copyText.js.map