define(["exports", "deps/text!core/images/clipboard.svg", "deps/clipboard", "deps/regenerator"], function (exports, _clipboard, _clipboard3) {
  "use strict";

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.run = exports.name = undefined;

  var _clipboard2 = _interopRequireDefault(_clipboard);

  var _clipboard4 = _interopRequireDefault(_clipboard3);

  function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
      default: obj
    };
  }

  function _asyncToGenerator(fn) {
    return function () {
      var gen = fn.apply(this, arguments);
      return new Promise(function (resolve, reject) {
        function step(key, arg) {
          try {
            var info = gen[key](arg);
            var value = info.value;
          } catch (error) {
            reject(error);
            return;
          }

          if (info.done) {
            resolve(value);
          } else {
            return Promise.resolve(value).then(function (value) {
              step("next", value);
            }, function (err) {
              step("throw", err);
            });
          }
        }

        return step("next");
      });
    };
  }

  var name = exports.name = "core/webidl-clipboard";

  // This button serves a prototype that we clone as needed.
  var copyButton = document.createElement("button");
  copyButton.innerHTML = _clipboard2.default;
  copyButton.title = "Copy IDL to clipboard";
  copyButton.classList.add("respec-button-copy-paste", "removeOnSave");

  var clipboardOps = {
    text: function text(trigger) {
      return document.querySelector(trigger.dataset.clipboardTarget).textContent.replace(/\ +/gm, " ").replace(/^\ /gm, "  ").replace(/^};\n/gm, "};\n").trim();
    }
  };

  var run = exports.run = function () {
    var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(conf, doc, cb) {
      var clipboard;
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              Array.from(doc.querySelectorAll("pre.idl")).map(function (elem) {
                var button = copyButton.cloneNode(true);
                var definition = elem.querySelector("span[id^=\"idl-def-\"], span[id^=\"dom-\"]");
                var target = "#";
                if (definition === null && elem.id === "") {
                  if (elem.parentElement.id === "idl-index") {
                    target += "actual-idl-index";
                  } else {
                    elem.id = "idl-" + String(Math.random()).substr(2);
                    target += elem.id;
                  }
                } else {
                  target += elem.id || definition.id;
                }
                return { button: button, elem: elem, target: target };
              }).forEach(function (_ref2) {
                var elem = _ref2.elem,
                    button = _ref2.button,
                    target = _ref2.target;

                var wrapper = doc.createElement("div");
                button.dataset.clipboardTarget = target;
                elem.parentElement.replaceChild(wrapper, elem);
                wrapper.appendChild(button);
                wrapper.appendChild(elem);
              });
              clipboard = new _clipboard4.default(".respec-button-copy-paste", clipboardOps);

              clipboard.on("success", function (e) {
                return e.clearSelection();
              });
              cb();

            case 4:
            case "end":
              return _context.stop();
          }
        }
      }, _callee, this);
    }));

    return function run(_x, _x2, _x3) {
      return _ref.apply(this, arguments);
    };
  }();
});
//# sourceMappingURL=webidl-clipboard.js.map