"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _warning = _interopRequireDefault(require("./warning"));
function copy(text, config) {
  const format = config === null || config === void 0 ? void 0 : config.format;
  if (typeof text !== 'string') {
    (0, _warning.default)(false, 'The clipboard content must be of string type', '');
    return false;
  }
  try {
    if (format === 'text/html') {
      const item = new ClipboardItem({
        [format]: new Blob([text], {
          type: format
        }),
        'text/plain': new Blob([text], {
          type: 'text/plain'
        })
      });
      navigator.clipboard.write([item]);
    } else {
      navigator.clipboard.writeText(text);
    }
    return true;
  } catch (err) {
    (0, _warning.default)(false, 'Clipboard API failed:', String(err));
  }
}
var _default = exports.default = copy;