"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _jquery = _interopRequireDefault(require("jquery"));

var _svgprocessing = _interopRequireDefault(require("./svgprocessing"));

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

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var extend_vrv = function extend_vrv(svg) {
  // Make extensions to Verovio's SVG to facilitate user interaction
  var $svg = (0, _jquery["default"])(svg);

  var _iterator = _createForOfIteratorHelper($svg.find("g.note, g.chord, g.rest, g.mRest")),
      _step;

  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var el = _step.value;

      // skip events within chords
      if ((0, _jquery["default"])(el).parent().closest('g.chord').get(0)) {
        continue;
      }

      var $el = (0, _jquery["default"])(el);
      var g1_attrs = {
        "class": "cnt-selectable"
      };

      var g1 = _svgprocessing["default"].makeSVGEl("g", g1_attrs);

      var g2 = _svgprocessing["default"].makeSVGEl("g");

      var _iterator3 = _createForOfIteratorHelper($el.children()),
          _step3;

      try {
        for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
          var child = _step3.value;

          if ((0, _jquery["default"])(child).attr('class') == 'verse') {
            (0, _jquery["default"])(g2).append(child);
          } else {
            (0, _jquery["default"])(g1).append(child);
          }
        }
      } catch (err) {
        _iterator3.e(err);
      } finally {
        _iterator3.f();
      }

      $el.empty();
      $el.append(g1);
      $el.append(g2);
    } // Add some useful content to g.space

  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }

  var _iterator2 = _createForOfIteratorHelper($svg.find("g.space")),
      _step2;

  try {
    for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {// console.log($(el).prevAll("*[x]"));
      // console.log($(el).prevAll("g"));
      // <text x="887" y="2390" dx="0" dy="0" text-anchor="end" font-size="0px">
      //             <tspan font-family="Garamond" font-size="405px">Altus</tspan>
      //         </text>

      var _el = _step2.value;
    }
  } catch (err) {
    _iterator2.e(err);
  } finally {
    _iterator2.f();
  }

  return $svg.get(0);
};

var _default = extend_vrv;
exports["default"] = _default;