System.register(['./node-helpers.js', '../graphics.js'], function (_export, _context) {
  "use strict";

  var nodes, pt, offset;
  function globalPosition(e) {
    return _recorder_._src_client_morphic_event_helpers_js.pt(e.clientX, e.clientY);
  }

  _export('globalPosition', globalPosition);

  function elementsUnder(e) {

    var pos = _recorder_._src_client_morphic_event_helpers_js.globalPosition(e);
    var elements = Array.from(document.elementsFromPoint(e.clientX, e.clientY));

    var result = Array.from(elements).filter(ea => !ea.isMetaNode
    // go deep one level #ContinueHere
    );for (var ea of elements.reverse()) {
      if (ea.shadowRoot && ea.shadowRoot.elementsFromPoint) {
        result.unshift(...Array.from(ea.shadowRoot.elementsFromPoint(e.clientX, e.clientY)).filter(ea => !ea.isMetaNode));
      }
    }
    if (result.find(ea => ea.tagName && ea.tagName.match("HALO"))) {
      debugger;
    }

    return result;
  }

  _export('elementsUnder', elementsUnder);

  function distanceTo(e, pos) {
    var yDist = Math.abs(pos.y - _recorder_._src_client_morphic_event_helpers_js.globalPosition(e).y);
    var xDist = Math.abs(pos.x - _recorder_._src_client_morphic_event_helpers_js.globalPosition(e).x);
    return Math.sqrt(xDist * xDist + yDist * yDist);
  }

  _export('distanceTo', distanceTo);

  function getTargetNode(e) {
    var target = _recorder_._src_client_morphic_event_helpers_js.elementsUnder(e)[0];
    return document.body === target ? null : target;
  }

  _export('getTargetNode', getTargetNode);

  function noticableDistanceTo(e, pos) {
    return _recorder_._src_client_morphic_event_helpers_js.distanceTo(e, pos) > _recorder_._src_client_morphic_event_helpers_js.offset;
  }

  _export('noticableDistanceTo', noticableDistanceTo);

  return {
    setters: [function (_nodeHelpersJs) {
      nodes = _nodeHelpersJs;
    }, function (_graphicsJs) {
      pt = _graphicsJs.pt;
    }],
    execute: function () {
      _recorder_._src_client_morphic_event_helpers_js = _recorder_._src_client_morphic_event_helpers_js || {};
      _recorder_._src_client_morphic_event_helpers_js.noticableDistanceTo = noticableDistanceTo;
      _recorder_._src_client_morphic_event_helpers_js.getTargetNode = getTargetNode;
      _recorder_._src_client_morphic_event_helpers_js.distanceTo = distanceTo;
      _recorder_._src_client_morphic_event_helpers_js.elementsUnder = elementsUnder;
      _recorder_._src_client_morphic_event_helpers_js.globalPosition = globalPosition;
      _recorder_._src_client_morphic_event_helpers_js.nodes = nodes;
      _recorder_._src_client_morphic_event_helpers_js.pt = pt;
      offset = 30;
      _recorder_._src_client_morphic_event_helpers_js.offset = offset;
    }
  };
});