System.register(["src/components/widgets/lively-morph.js", "src/client/graphics.js", "src/client/morphic/selecting.js", "src/components/halo/lively-halo-grab-item.js"], function (_export, _context) {
  "use strict";

  var Morph, pt, Selecting, GrabItem, LivelyHand, __SystemJSRewritingHack;
  _export("default", void 0);
  return {
    setters: [function (_srcComponentsWidgetsLivelyMorphJs) {
      Morph = _srcComponentsWidgetsLivelyMorphJs.default;
    }, function (_srcClientGraphicsJs) {
      pt = _srcClientGraphicsJs.pt;
    }, function (_srcClientMorphicSelectingJs) {
      Selecting = _srcClientMorphicSelectingJs.default;
    }, function (_srcComponentsHaloLivelyHaloGrabItemJs) {
      GrabItem = _srcComponentsHaloLivelyHaloGrabItemJs.default;
    }],
    execute: function () {
      __SystemJSRewritingHack = {};
      _recorder_._src_components_halo_lively_hand_js = _recorder_._src_components_halo_lively_hand_js || {};
      Object.defineProperty(_recorder_._src_components_halo_lively_hand_js, "Morph", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return Morph;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          Morph = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_halo_lively_hand_js, "pt", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return pt;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          pt = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_halo_lively_hand_js, "Selecting", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return Selecting;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          Selecting = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      /*
       * Classic old Morphic-like drag and drop of graphical elements
       */
      Object.defineProperty(_recorder_._src_components_halo_lively_hand_js, "GrabItem", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return GrabItem;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          GrabItem = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      _export("default", LivelyHand = class LivelyHand extends Morph {
        initialize() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          this.setAttribute("data-lively4-donotpersist", "all");
          lively.removeEventListener("Hand", this.outerWorldContext());
          lively.addEventListener("Hand", this.outerWorldContext(), "pointerdown", e => this.onPointerDown(e));
        }
        get info() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return this.get("#info");
        }
        get isMetaNode() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return true;
        }
        outerWorldContext() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          var world = this.worldContext();
          return world.isWorld ? world : document.body.parentElement;
        }
        worldContext() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return this.parentNode || document.body;
        }
        grab(element) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          this.drop();
          var pos = lively.getClientPosition(element);
          this.appendChild(element);
          lively.setClientPosition(element, pos);
        }
        drop() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          this.childNodes.forEach(element => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
            var pos = lively.getClientPosition(element);
            var droptarget = this.dropTarget || this.worldContext();
            droptarget.appendChild(element);
            lively.setClientPosition(element, pos);
          });
        }
        elementUnderHand(evt) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          var path = evt.composedPath().slice(evt.composedPath().indexOf(evt.srcElement)).filter(ea => !Selecting.isIgnoredOnMagnify(ea) && GrabItem.canDropInto(this, ea));
          return path[0];
        }
        startGrabbing(target, evt) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          // this.style.display = "block"
          this.style.visibility = "visible";
          if (evt) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
            lively.setClientPosition(this, pt(evt.clientX, evt.clientY));
          }
          lively.addEventListener("Hand", document.body.parentElement, "pointermove", e => this.onPointerMove(e));
          lively.addEventListener("Hand", document.body.parentElement, "pointerup", e => this.onPointerUp(e));
          this.grab(target);
        }
        onPointerDown(evt) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          // document.body.parentElement.setPointerCapture(evt.pointerId)
          if (evt.altKey && !lively.preferences.get("DisableAltGrab")) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
            window.LastEvent2 = evt;
            var target = this.elementUnderHand(evt);
            if (!target) return;
            // lively.notify("grab this" + target)
            evt.preventDefault();
            this.startGrabbing(target, evt);
          }
          // this.offset = lively.globalPosition(this)
        }

        onPointerMove(evt) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          if (this.dropIndicator) this.dropIndicator.remove();
          this.dropTarget = this.elementUnderHand(evt);
          if (this.dropTarget) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
            this.dropIndicator = lively.showElement(this.dropTarget);
            this.dropIndicator.style.border = "3px dashed rgba(0,100,0,0.5)";
            this.dropIndicator.innerHTML = "";
          }
          lively.setClientPosition(this, pt(evt.clientX, evt.clientY));
        }
        onPointerUp(evt) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          if (this.dropIndicator) this.dropIndicator.remove();

          // document.body.parentElement.releasePointerCapture(evt.pointerId)
          lively.removeEventListener("Hand", document.body.parentElement, "pointermove");
          lively.removeEventListener("Hand", document.body.parentElement, "pointerup");
          this.drop();
          this.style.visibility = "hidden";
        }
        static migrate() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          var hand = document.body.querySelector(":scope > lively-hand");
          if (hand) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
            hand.remove();
            lively.ensureHand(); // lazy... reinitialize
          }
        }
      }); // does not work for booting .... 
      // LivelyHand.migrate()
      Object.defineProperty(_recorder_._src_components_halo_lively_hand_js, "LivelyHand", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          return LivelyHand;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/halo/lively-hand.js"]++;
          _export("default", LivelyHand = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
    }
  };
});