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

  var nodes, pt, __SystemJSRewritingHack, offset;
  function globalPosition(e) {
    return pt(e.clientX, e.clientY);
  }
  function elementsUnder(e) {
    var pos = 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;
  }
  function distanceTo(e, pos) {
    var yDist = Math.abs(pos.y - globalPosition(e).y);
    var xDist = Math.abs(pos.x - globalPosition(e).x);
    return Math.sqrt(xDist * xDist + yDist * yDist);
  }
  function getTargetNode(e) {
    var target = elementsUnder(e)[0];
    return document.body === target ? null : target;
  }
  function noticableDistanceTo(e, pos) {
    return distanceTo(e, pos) > offset;
  }
  _export({
    globalPosition: globalPosition,
    elementsUnder: elementsUnder,
    distanceTo: distanceTo,
    getTargetNode: getTargetNode,
    noticableDistanceTo: noticableDistanceTo
  });
  return {
    setters: [function (_nodeHelpersJs) {
      nodes = _nodeHelpersJs;
    }, function (_graphicsJs) {
      pt = _graphicsJs.pt;
    }],
    execute: function () {
      __SystemJSRewritingHack = {};
      _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js = _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js || {};
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "noticableDistanceTo", {
        get() {
          return noticableDistanceTo;
        },
        set(thisIsVererySecretVariableName) {
          _export("noticableDistanceTo", noticableDistanceTo = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "getTargetNode", {
        get() {
          return getTargetNode;
        },
        set(thisIsVererySecretVariableName) {
          _export("getTargetNode", getTargetNode = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "distanceTo", {
        get() {
          return distanceTo;
        },
        set(thisIsVererySecretVariableName) {
          _export("distanceTo", distanceTo = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "elementsUnder", {
        get() {
          return elementsUnder;
        },
        set(thisIsVererySecretVariableName) {
          _export("elementsUnder", elementsUnder = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "globalPosition", {
        get() {
          return globalPosition;
        },
        set(thisIsVererySecretVariableName) {
          _export("globalPosition", globalPosition = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "nodes", {
        get() {
          return nodes;
        },
        set(thisIsVererySecretVariableName) {
          nodes = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "pt", {
        get() {
          return pt;
        },
        set(thisIsVererySecretVariableName) {
          pt = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      // todo: export class wrappers
      /**
      Event(e).globalPosition();
      */
      offset = 30;
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_morphic_event_helpers_js, "offset", {
        get() {
          return offset;
        },
        set(thisIsVererySecretVariableName) {
          offset = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
    }
  };
});