import { V as useContext, e as Text$1, X as use, Q as Symbols, p as m0, Y as ALPHANUMERIC_KEYS, Z as ALPHANUMERIC_KEYS_SET, _ as KEYS, $ as MOUSE_KEYS, a0 as Provider, a1 as compareModeConfigs, a2 as determineMode, a3 as diff, a4 as eventKey, a5 as filter, a6 as flattenConfig, a7 as keyZ, a8 as keyboardKey, a9 as match, aa as mouseKey, ab as mouseKeyZ, ac as purge, ad as purgeMouse, ae as triggerZ, af as useFlattenedMemoConfig, ag as useHeld, y as useHeldRef } from "./Toggle-DcOiWiHG.js";
import { j as jsxRuntimeExports } from "./jsx-runtime-mMz73N64.js";
import { useState, useEffect, useRef, useCallback } from "react";
import "./aggregator-Dl2jHye5.js";
import { q, T as To } from "./css-DoalWJF6.js";
import { S as Space } from "./Center-hbwH7rg9.js";
import { K as Keyboard } from "./Keyboard-BqO4SYSr.js";
const Status = (props) => {
  const { listen } = useContext();
  const [trigger, setTrigger] = useState([]);
  useEffect(
    () => listen(({ next: [trigger2] }) => setTrigger(trigger2 ?? [])),
    [listen, setTrigger]
  );
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Text$1, { ...props, children: trigger.join(" ") });
};
const useDrag = ({
  onDrag,
  triggers = [["MouseLeft"], ["MouseRight"]],
  bound,
  loose = false
}) => {
  const triggerRef = useRef(null);
  const startLoc = useRef(q.ZERO);
  const onMove = useCallback(
    (e) => {
      const cursor = q.construct(e);
      if (triggerRef.current === null)
        return;
      const { triggers: triggers2 } = triggerRef.current;
      onDrag({
        box: To.construct(startLoc.current, cursor),
        cursor,
        triggers: triggers2,
        stage: "during"
      });
    },
    [onDrag]
  );
  const handleTrigger = useCallback(
    (event) => {
      const { stage, cursor } = event;
      if (stage === "start") {
        onDrag({ box: To.construct(cursor), ...event });
        window.addEventListener("mousemove", onMove);
        triggerRef.current = event;
        startLoc.current = cursor;
      } else if (stage === "end" && triggerRef.current != null) {
        onDrag({ box: To.construct(startLoc.current, cursor), ...event });
        window.removeEventListener("mousemove", onMove);
        triggerRef.current = null;
        startLoc.current = q.ZERO;
      }
    },
    [onDrag]
  );
  use({ triggers, callback: handleTrigger, region: bound, loose });
};
const CUSTOM_TEXT = {
  Control: () => /* @__PURE__ */ jsxRuntimeExports.jsx(Symbols.Meta, {}),
  Alt: () => /* @__PURE__ */ jsxRuntimeExports.jsx(Symbols.Alt, {}),
  Shift: () => /* @__PURE__ */ jsxRuntimeExports.jsx(m0.Keyboard.Shift, {}),
  MouseLeft: "Left Click",
  MouseRight: "Right Click",
  MouseMiddle: "Middle Click",
  Enter: () => /* @__PURE__ */ jsxRuntimeExports.jsx(m0.Keyboard.Return, {})
};
const getCustomText = (trigger) => {
  const t = CUSTOM_TEXT[trigger];
  if (t != null)
    return typeof t === "function" ? t() : t;
  return trigger;
};
const toSymbols = (trigger) => trigger.map((t) => getCustomText(t));
const Text = ({
  className,
  style,
  trigger,
  ...props
}) => {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Space, { className, style, direction: "x", children: trigger.map((t) => (
    // @ts-expect-error - issues with generic element types
    /* @__PURE__ */ jsxRuntimeExports.jsx(Keyboard, { ...props, children: getCustomText(t) }, t)
  )) });
};
const external = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  ALPHANUMERIC_KEYS,
  ALPHANUMERIC_KEYS_SET,
  KEYS,
  MOUSE_KEYS,
  Provider,
  Status,
  Text,
  compareModeConfigs,
  determineMode,
  diff,
  eventKey,
  filter,
  flattenConfig,
  keyZ,
  keyboardKey,
  match,
  mouseKey,
  mouseKeyZ,
  purge,
  purgeMouse,
  toSymbols,
  triggerZ,
  use,
  useContext,
  useDrag,
  useFlattenedMemoConfig,
  useHeld,
  useHeldRef
}, Symbol.toStringTag, { value: "Module" }));
export {
  Text as T,
  external as e,
  useDrag as u
};
//# sourceMappingURL=external-D8uwkCSk.js.map
