define(["exports", "core/pubsubhub", "deps/regenerator"], function (exports, _pubsubhub) {
  "use strict";

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

  function _toConsumableArray(arr) {
    if (Array.isArray(arr)) {
      for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
        arr2[i] = arr[i];
      }

      return arr2;
    } else {
      return Array.from(arr);
    }
  }

  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 doneResolver = void 0;
  var done = exports.done = new Promise(function (resolve) {
    doneResolver = resolve;
  });

  (0, _pubsubhub.sub)("plugins-done", function () {
    var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(config) {
      var result, values;
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              result = [];

              if (!Array.isArray(config.postProcess)) {
                _context.next = 6;
                break;
              }

              _context.next = 4;
              return Promise.all(config.postProcess.filter(function (f) {
                return typeof f === "function";
              }).map(function (f) {
                return Promise.resolve(f(config, document));
              }));

            case 4:
              values = _context.sent;

              result.push.apply(result, _toConsumableArray(values));

            case 6:
              if (!(typeof config.afterEnd === "function")) {
                _context.next = 12;
                break;
              }

              _context.t0 = result;
              _context.next = 10;
              return Promise.resolve(config.afterEnd(config, document));

            case 10:
              _context.t1 = _context.sent;

              _context.t0.push.call(_context.t0, _context.t1);

            case 12:
              doneResolver(result);

            case 13:
            case "end":
              return _context.stop();
          }
        }
      }, _callee, undefined);
    }));

    return function (_x) {
      return _ref.apply(this, arguments);
    };
  }(), { once: true });
});
//# sourceMappingURL=post-process.js.map