import { effects as tt, ValueHistory as Ee, snapshot as it, reactive as _, derived as b } from "../../../../@dnd-kit_state@0.1.21/node_modules/@dnd-kit/state/dist/index.js";
import { Position as Ie } from "../../../../@dnd-kit_geometry@0.1.21/node_modules/@dnd-kit/geometry/dist/index.js";
import { untracked as O, effect as Ct, batch as At, signal as Lt } from "../../../../@preact_signals-core@1.12.0/node_modules/@preact/signals-core/dist/signals-core.module.js";
var Pe = Object.create, lt = Object.defineProperty, Se = Object.defineProperties, We = Object.getOwnPropertyDescriptor, xe = Object.getOwnPropertyDescriptors, Z = Object.getOwnPropertySymbols, Rt = Object.prototype.hasOwnProperty, jt = Object.prototype.propertyIsEnumerable, Ht = (t, e) => (e = Symbol[t]) ? e : Symbol.for("Symbol." + t), q = (t) => {
  throw TypeError(t);
}, at = (t, e, s) => e in t ? lt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s, Vt = (t, e) => {
  for (var s in e || (e = {}))
    Rt.call(e, s) && at(t, s, e[s]);
  if (Z)
    for (var s of Z(e))
      jt.call(e, s) && at(t, s, e[s]);
  return t;
}, qt = (t, e) => Se(t, xe(e)), Wt = (t, e) => lt(t, "name", { value: e, configurable: !0 }), Nt = (t, e) => {
  var s = {};
  for (var r in t)
    Rt.call(t, r) && e.indexOf(r) < 0 && (s[r] = t[r]);
  if (t != null && Z)
    for (var r of Z(t))
      e.indexOf(r) < 0 && jt.call(t, r) && (s[r] = t[r]);
  return s;
}, N = (t) => {
  var e;
  return [, , , Pe((e = t?.[Ht("metadata")]) != null ? e : null)];
}, Ut = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], U = (t) => t !== void 0 && typeof t != "function" ? q("Function expected") : t, ze = (t, e, s, r, i) => ({ kind: Ut[t], name: e, metadata: r, addInitializer: (n) => s._ ? q("Already initialized") : i.push(U(n || null)) }), A = (t, e) => at(e, Ht("metadata"), t[3]), a = (t, e, s, r) => {
  for (var i = 0, n = t[e >> 1], d = n && n.length; i < d; i++) e & 1 ? n[i].call(s) : r = n[i].call(s, r);
  return r;
}, l = (t, e, s, r, i, n) => {
  var d, o, g, p, u, c = e & 7, z = !!(e & 8), D = !!(e & 16), L = c > 3 ? t.length + 1 : c ? z ? 1 : 2 : 0, R = Ut[c + 5], B = c > 3 && (t[L - 1] = []), et = t[L] || (t[L] = []), E = c && (!D && !z && (i = i.prototype), c < 5 && (c > 3 || !D) && We(c < 4 ? i : { get [s]() {
    return y(this, n);
  }, set [s](M) {
    return I(this, n, M);
  } }, s));
  c ? D && c < 4 && Wt(n, (c > 2 ? "set " : c > 1 ? "get " : "") + s) : Wt(i, s);
  for (var st = r.length - 1; st >= 0; st--)
    p = ze(c, s, g = {}, t[3], et), c && (p.static = z, p.private = D, u = p.access = { has: D ? (M) => Fe(i, M) : (M) => s in M }, c ^ 3 && (u.get = D ? (M) => (c ^ 1 ? y : Ce)(M, i, c ^ 4 ? n : E.get) : (M) => M[s]), c > 2 && (u.set = D ? (M, rt) => I(M, i, rt, c ^ 4 ? n : E.set) : (M, rt) => M[s] = rt)), o = (0, r[st])(c ? c < 4 ? D ? n : E[R] : c > 4 ? void 0 : { get: E.get, set: E.set } : i, p), g._ = 1, c ^ 4 || o === void 0 ? U(o) && (c > 4 ? B.unshift(o) : c ? D ? n = o : E[R] = o : i = o) : typeof o != "object" || o === null ? q("Object expected") : (U(d = o.get) && (E.get = d), U(d = o.set) && (E.set = d), U(d = o.init) && B.unshift(d));
  return c || A(t, i), E && lt(i, s, E), D ? c ^ 4 ? n : E : i;
}, dt = (t, e, s) => e.has(t) || q("Cannot " + s), Fe = (t, e) => Object(e) !== e ? q('Cannot use the "in" operator on this value') : t.has(e), y = (t, e, s) => (dt(t, e, "read from private field"), s ? s.call(t) : e.get(t)), h = (t, e, s) => e.has(t) ? q("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), I = (t, e, s, r) => (dt(t, e, "write to private field"), r ? r.call(t, s) : e.set(t, s), s), Ce = (t, e, s) => (dt(t, e, "access private method"), s);
function Tt(t, e) {
  return {
    plugin: t,
    options: e
  };
}
function Je(t) {
  return (e) => Tt(t, e);
}
function $t(t) {
  return typeof t == "function" ? {
    plugin: t,
    options: void 0
  } : t;
}
var Gt, G, ut, K;
Gt = [_];
var F = class {
  /**
   * Creates a new plugin instance.
   *
   * @param manager - The drag and drop manager that owns this plugin
   * @param options - Optional configuration for the plugin
   */
  constructor(t, e) {
    this.manager = t, this.options = e, h(this, ut, a(G, 8, this, !1)), a(G, 11, this), h(this, K, /* @__PURE__ */ new Set());
  }
  /**
   * Enables a disabled plugin instance.
   *
   * @remarks
   * This method triggers effects when called.
   */
  enable() {
    this.disabled = !1;
  }
  /**
   * Disables an enabled plugin instance.
   *
   * @remarks
   * This method triggers effects when called.
   */
  disable() {
    this.disabled = !0;
  }
  /**
   * Checks if the plugin instance is disabled.
   *
   * @returns true if the plugin is disabled
   * @remarks
   * This method does not trigger effects when accessed.
   */
  isDisabled() {
    return O(() => this.disabled);
  }
  /**
   * Configures a plugin instance with new options.
   *
   * @param options - The new options to apply
   */
  configure(t) {
    this.options = t;
  }
  /**
   * Registers an effect that will be cleaned up when the plugin is destroyed.
   *
   * @param callback - The effect callback to register
   * @returns A function to dispose of the effect
   */
  registerEffect(t) {
    const e = Ct(t.bind(this));
    return y(this, K).add(e), e;
  }
  /**
   * Destroys a plugin instance and cleans up its resources.
   *
   * @remarks
   * This method:
   * - Calls all registered cleanup functions
   * - Should be overridden by subclasses to clean up additional resources
   */
  destroy() {
    y(this, K).forEach((t) => t());
  }
  /**
   * Configures a plugin constructor with options.
   *
   * @param options - The options to configure the constructor with
   * @returns The configured plugin constructor
   *
   * @remarks
   * This method is used to configure the options that the
   * plugin constructor will use to create plugin instances.
   */
  static configure(t) {
    return Tt(this, t);
  }
};
G = N(null);
ut = /* @__PURE__ */ new WeakMap();
K = /* @__PURE__ */ new WeakMap();
l(G, 4, "disabled", Gt, F, ut);
A(G, F);
var Bt = class extends F {
}, Q, nt = class {
  /**
   * Creates a new plugin registry.
   *
   * @param manager - The drag and drop manager that owns this registry
   */
  constructor(t) {
    this.manager = t, this.instances = /* @__PURE__ */ new Map(), h(this, Q, []);
  }
  /**
   * Gets all registered plugin instances.
   *
   * @returns An array of all active plugin instances
   */
  get values() {
    return Array.from(this.instances.values());
  }
  /**
   * Sets the list of plugins to be used by the registry.
   *
   * @param entries - Array of plugin constructors or descriptors
   * @remarks
   * This method:
   * - Filters out duplicate plugins
   * - Unregisters plugins that are no longer in use
   * - Registers new plugins with their options
   */
  set values(t) {
    const e = t.map($t).reduceRight((r, i) => r.some(({ plugin: n }) => n === i.plugin) ? r : [i, ...r], []), s = e.map(({ plugin: r }) => r);
    for (const r of y(this, Q))
      if (!s.includes(r)) {
        if (r.prototype instanceof Bt)
          continue;
        this.unregister(r);
      }
    for (const { plugin: r, options: i } of e)
      this.register(r, i);
    I(this, Q, s);
  }
  /**
   * Gets a plugin instance by its constructor.
   *
   * @param plugin - The plugin constructor to look up
   * @returns The plugin instance or undefined if not found
   */
  get(t) {
    return this.instances.get(t);
  }
  /**
   * Registers a new plugin instance.
   *
   * @param plugin - The plugin constructor to register
   * @param options - Optional configuration for the plugin
   * @returns The registered plugin instance
   * @remarks
   * If the plugin is already registered, its options will be updated
   * and the existing instance will be returned.
   */
  register(t, e) {
    const s = this.instances.get(t);
    if (s)
      return s.options !== e && (s.options = e), s;
    const r = new t(this.manager, e);
    return this.instances.set(t, r), r;
  }
  /**
   * Unregisters a plugin instance.
   *
   * @param plugin - The plugin constructor to unregister
   * @remarks
   * This method:
   * - Destroys the plugin instance
   * - Removes it from the registry
   */
  unregister(t) {
    const e = this.instances.get(t);
    e && (e.destroy(), this.instances.delete(t));
  }
  /**
   * Destroys all registered plugin instances.
   *
   * @remarks
   * This method:
   * - Calls destroy() on all plugin instances
   * - Clears the registry
   */
  destroy() {
    for (const t of this.instances.values())
      t.destroy();
    this.instances.clear();
  }
};
Q = /* @__PURE__ */ new WeakMap();
function Ae(t, e) {
  return t.priority === e.priority ? t.type === e.type ? e.value - t.value : e.type - t.type : e.priority - t.priority;
}
var J = [], j, H, Le = class extends F {
  /**
   * Creates a new CollisionObserver instance.
   *
   * @param manager - The drag drop manager instance
   */
  constructor(t) {
    super(t), h(this, j), h(this, H), this.computeCollisions = this.computeCollisions.bind(this), I(this, H, Lt(J)), this.destroy = tt(
      () => {
        const e = this.computeCollisions(), s = O(
          () => this.manager.dragOperation.position.current
        );
        if (e !== J) {
          const r = y(this, j);
          if (I(this, j, s), r && s.x == r.x && s.y == r.y)
            return;
        } else
          I(this, j, void 0);
        y(this, H).value = e;
      },
      () => {
        const { dragOperation: e } = this.manager;
        e.status.initialized && this.forceUpdate();
      }
    );
  }
  /**
   * Forces an immediate update of collision detection.
   *
   * @param immediate - If true, updates collisions immediately. If false, resets previous coordinates.
   */
  forceUpdate(t = !0) {
    O(() => {
      t ? y(this, H).value = this.computeCollisions() : I(this, j, void 0);
    });
  }
  /**
   * Computes collisions between draggable and droppable elements.
   *
   * @param entries - Optional array of droppable elements to check. If not provided, uses all registered droppables.
   * @param collisionDetector - Optional custom collision detector function
   * @returns Array of detected collisions, sorted by priority
   */
  computeCollisions(t, e) {
    const { registry: s, dragOperation: r } = this.manager, { source: i, shape: n, status: d } = r;
    if (!d.initialized || !n)
      return J;
    const o = [], g = [];
    for (const p of t ?? s.droppables) {
      if (p.disabled || i && !p.accepts(i))
        continue;
      const u = e ?? p.collisionDetector;
      if (!u)
        continue;
      g.push(p), p.shape;
      const c = O(
        () => u({
          droppable: p,
          dragOperation: r
        })
      );
      c && (p.collisionPriority != null && (c.priority = p.collisionPriority), o.push(c));
    }
    return g.length === 0 ? J : (o.sort(Ae), o);
  }
  /**
   * Gets the current collisions signal value.
   */
  get collisions() {
    return y(this, H).value;
  }
};
j = /* @__PURE__ */ new WeakMap();
H = /* @__PURE__ */ new WeakMap();
var Re = class {
  constructor() {
    this.registry = /* @__PURE__ */ new Map();
  }
  /**
   * Adds an event listener for the specified event type.
   *
   * @param name - The name of the event to listen for
   * @param handler - The function to call when the event occurs
   * @returns A function to remove the event listener
   */
  addEventListener(t, e) {
    const { registry: s } = this, r = new Set(s.get(t));
    return r.add(e), s.set(t, r), () => this.removeEventListener(t, e);
  }
  /**
   * Removes an event listener for the specified event type.
   *
   * @param name - The name of the event
   * @param handler - The function to remove
   */
  removeEventListener(t, e) {
    const { registry: s } = this, r = new Set(s.get(t));
    r.delete(e), s.set(t, r);
  }
  /**
   * Dispatches an event to all registered listeners.
   *
   * @param name - The name of the event to dispatch
   * @param args - Arguments to pass to the event handlers
   */
  dispatch(t, ...e) {
    const { registry: s } = this, r = s.get(t);
    if (r)
      for (const i of r)
        i(...e);
  }
}, je = class extends Re {
  /**
   * Creates a new drag and drop monitor.
   *
   * @param manager - The drag and drop manager to monitor
   */
  constructor(t) {
    super(), this.manager = t;
  }
  /**
   * Dispatches a drag and drop event.
   *
   * @param type - The type of event to dispatch
   * @param event - The event data to dispatch
   */
  dispatch(t, e) {
    const s = [e, this.manager];
    super.dispatch(t, ...s);
  }
};
function X(t, e = !0) {
  let s = !1;
  return qt(Vt({}, t), {
    cancelable: e,
    get defaultPrevented() {
      return s;
    },
    preventDefault() {
      e && (s = !0);
    }
  });
}
var He = class extends Bt {
  constructor(t) {
    super(t);
    const e = (r, i) => r.map(({ id: n }) => n).join("") === i.map(({ id: n }) => n).join("");
    let s = [];
    this.destroy = tt(
      () => {
        const { dragOperation: r, collisionObserver: i } = t;
        r.status.initializing && (s = [], i.enable());
      },
      () => {
        const { collisionObserver: r, monitor: i } = t, { collisions: n } = r;
        if (r.isDisabled())
          return;
        const d = X({
          collisions: n
        });
        if (i.dispatch("collision", d), d.defaultPrevented || e(n, s))
          return;
        s = n;
        const [o] = n;
        O(() => {
          var g;
          o?.id !== ((g = t.dragOperation.target) == null ? void 0 : g.id) && (r.disable(), t.actions.setDropTarget(o?.id).then(() => {
            r.enable();
          }));
        });
      }
    );
  }
}, Ve = /* @__PURE__ */ ((t) => (t[t.Lowest = 0] = "Lowest", t[t.Low = 1] = "Low", t[t.Normal = 2] = "Normal", t[t.High = 3] = "High", t[t.Highest = 4] = "Highest", t))(Ve || {}), qe = /* @__PURE__ */ ((t) => (t[t.Collision = 0] = "Collision", t[t.ShapeIntersection = 1] = "ShapeIntersection", t[t.PointerIntersection = 2] = "PointerIntersection", t))(qe || {}), Jt, Kt, Qt, Xt, Yt, Zt, te, k, ht;
te = [_], Zt = [b], Yt = [b], Xt = [b], Qt = [b], Kt = [b], Jt = [b];
var x = class {
  constructor() {
    a(k, 5, this), h(this, ht, a(
      k,
      8,
      this,
      "idle"
      /* Idle */
    )), a(k, 11, this);
  }
  get current() {
    return this.value;
  }
  get idle() {
    return this.value === "idle";
  }
  get initializing() {
    return this.value === "initializing";
  }
  get initialized() {
    const { value: t } = this;
    return t !== "idle" && t !== "initialization-pending";
  }
  get dragging() {
    return this.value === "dragging";
  }
  get dropped() {
    return this.value === "dropped";
  }
  /**
   * Sets the current status value.
   *
   * @param value - The new status value
   */
  set(t) {
    this.value = t;
  }
};
k = N(null);
ht = /* @__PURE__ */ new WeakMap();
l(k, 4, "value", te, x, ht);
l(k, 2, "current", Zt, x);
l(k, 2, "idle", Yt, x);
l(k, 2, "initializing", Xt, x);
l(k, 2, "initialized", Qt, x);
l(k, 2, "dragging", Kt, x);
l(k, 2, "dropped", Jt, x);
A(k, x);
var Ne = class {
  /**
   * Creates a new instance of drag actions.
   *
   * @param manager - The drag and drop manager instance
   */
  constructor(t) {
    this.manager = t;
  }
  /**
   * Sets the source of the drag operation.
   *
   * @param source - The draggable entity or its unique identifier
   */
  setDragSource(t) {
    const { dragOperation: e } = this.manager;
    e.sourceIdentifier = typeof t == "string" || typeof t == "number" ? t : t.id;
  }
  /**
   * Sets the target of the drop operation.
   *
   * @param identifier - The unique identifier of the droppable entity or null/undefined
   * @returns A promise that resolves to true if the drop was prevented
   */
  setDropTarget(t) {
    return O(() => {
      const { dragOperation: e } = this.manager, s = t ?? null;
      if (e.targetIdentifier === s)
        return Promise.resolve(!1);
      e.targetIdentifier = s;
      const r = X({
        operation: e.snapshot()
      });
      return e.status.dragging && this.manager.monitor.dispatch("dragover", r), this.manager.renderer.rendering.then(() => r.defaultPrevented);
    });
  }
  /**
   * Starts a new drag operation.
   *
   * @param args - Configuration for the drag operation
   * @param args.event - The event that initiated the drag
   * @param args.source - The source draggable entity or its identifier
   * @param args.coordinates - The initial coordinates of the drag
   * @returns true if the drag operation started successfully
   * @throws {Error} If there is no drag source or another operation is active
   */
  start(t) {
    return O(() => {
      const { dragOperation: e } = this.manager;
      if (t.source != null && this.setDragSource(t.source), !e.source)
        throw new Error("Cannot start a drag operation without a drag source");
      if (!e.status.idle)
        throw new Error(
          "Cannot start a drag operation while another is active"
        );
      const r = new AbortController(), { event: i, coordinates: n } = t;
      At(() => {
        e.status.set(
          "initialization-pending"
          /* InitializationPending */
        ), e.shape = null, e.canceled = !1, e.activatorEvent = i ?? null, e.position.reset(n);
      });
      const d = X({
        operation: e.snapshot()
      });
      return this.manager.monitor.dispatch("beforedragstart", d), d.defaultPrevented ? (e.reset(), r.abort(), r) : (e.status.set(
        "initializing"
        /* Initializing */
      ), e.controller = r, this.manager.renderer.rendering.then(() => {
        if (r.signal.aborted) return;
        const { status: o } = e;
        o.current === "initializing" && (e.status.set(
          "dragging"
          /* Dragging */
        ), this.manager.monitor.dispatch("dragstart", {
          nativeEvent: i,
          operation: e.snapshot(),
          cancelable: !1
        }));
      }), r);
    });
  }
  /**
   * Moves the dragged entity to a new position.
   *
   * @param args - Configuration for the move operation
   * @param args.by - Relative coordinates to move by
   * @param args.to - Absolute coordinates to move to
   * @param args.event - The event that triggered the move
   * @param args.cancelable - Whether the move can be canceled
   * @param args.propagate - Whether to dispatch dragmove events
   */
  move(t) {
    return O(() => {
      var e, s;
      const { dragOperation: r } = this.manager, { status: i, controller: n } = r;
      if (!i.dragging || !n || n.signal.aborted)
        return;
      const d = X(
        {
          nativeEvent: t.event,
          operation: r.snapshot(),
          by: t.by,
          to: t.to
        },
        (e = t.cancelable) != null ? e : !0
      );
      ((s = t.propagate) == null || s) && this.manager.monitor.dispatch("dragmove", d), queueMicrotask(() => {
        var o, g, p, u, c;
        if (d.defaultPrevented)
          return;
        const z = (c = t.to) != null ? c : {
          x: r.position.current.x + ((g = (o = t.by) == null ? void 0 : o.x) != null ? g : 0),
          y: r.position.current.y + ((u = (p = t.by) == null ? void 0 : p.y) != null ? u : 0)
        };
        r.position.current = z;
      });
    });
  }
  /**
   * Stops the current drag operation.
   *
   * @param args - Configuration for stopping the operation
   * @param args.event - The event that triggered the stop
   * @param args.canceled - Whether the operation was canceled
   * @remarks
   * This method:
   * - Dispatches a dragend event
   * - Allows suspension of the operation
   * - Handles cleanup of the operation state
   */
  stop(t = {}) {
    return O(() => {
      var e, s;
      const { dragOperation: r } = this.manager, { controller: i } = r;
      if (!i || i.signal.aborted) return;
      let n;
      const d = () => {
        const g = {
          resume: () => {
          },
          abort: () => {
          }
        };
        return n = new Promise((p, u) => {
          g.resume = p, g.abort = u;
        }), g;
      };
      i.abort();
      const o = () => {
        this.manager.renderer.rendering.then(() => {
          r.status.set(
            "dropped"
            /* Dropped */
          );
          const g = O(
            () => {
              var u;
              return ((u = r.source) == null ? void 0 : u.status) === "dropping";
            }
          ), p = () => {
            r.controller === i && (r.controller = void 0), r.reset();
          };
          if (g) {
            const { source: u } = r, c = Ct(() => {
              u?.status === "idle" && (c(), p());
            });
          } else
            this.manager.renderer.rendering.then(p);
        });
      };
      r.canceled = (e = t.canceled) != null ? e : !1, this.manager.monitor.dispatch("dragend", {
        nativeEvent: t.event,
        operation: r.snapshot(),
        canceled: (s = t.canceled) != null ? s : !1,
        suspend: d
      }), n ? n.then(o).catch(() => r.reset()) : o();
    });
  }
}, ee, se, re, ie, w, pt, gt, ft, vt;
ie = [_], re = [_], se = [_], ee = [_];
var C = class {
  /**
   * Creates a new instance of the `Entity` class.
   *
   * @param input - An object containing the initial properties of the entity.
   * @param manager - The manager that controls the drag and drop operations.
   */
  constructor(t, e) {
    h(this, pt, a(w, 8, this)), a(w, 11, this), h(this, gt, a(w, 12, this)), a(w, 15, this), h(this, ft, a(w, 16, this)), a(w, 19, this), h(this, vt, a(w, 20, this)), a(w, 23, this);
    const { effects: s, id: r, data: i = {}, disabled: n = !1, register: d = !0 } = t;
    let o = r;
    this.manager = e, this.id = r, this.data = i, this.disabled = n, this.effects = () => {
      var g;
      return [
        () => {
          const { id: p, manager: u } = this;
          if (p !== o)
            return u?.registry.register(this), () => u?.registry.unregister(this);
        },
        ...(g = s?.()) != null ? g : []
      ];
    }, this.register = this.register.bind(this), this.unregister = this.unregister.bind(this), this.destroy = this.destroy.bind(this), e && d && queueMicrotask(this.register);
  }
  /**
   * A method that registers the entity with the manager.
   * @returns CleanupFunction | void
   */
  register() {
    var t;
    return (t = this.manager) == null ? void 0 : t.registry.register(this);
  }
  /**
   * A method that unregisters the entity from the manager.
   * @returns void
   */
  unregister() {
    var t;
    (t = this.manager) == null || t.registry.unregister(this);
  }
  /**
   * A method that cleans up the entity when it is no longer needed.
   * @returns void
   */
  destroy() {
    var t;
    (t = this.manager) == null || t.registry.unregister(this);
  }
};
w = N(null);
pt = /* @__PURE__ */ new WeakMap();
gt = /* @__PURE__ */ new WeakMap();
ft = /* @__PURE__ */ new WeakMap();
vt = /* @__PURE__ */ new WeakMap();
l(w, 4, "manager", ie, C, pt);
l(w, 4, "id", re, C, gt);
l(w, 4, "data", se, C, ft);
l(w, 4, "disabled", ee, C, vt);
A(w, C);
var xt = class {
  constructor() {
    this.map = Lt(/* @__PURE__ */ new Map()), this.cleanupFunctions = /* @__PURE__ */ new WeakMap(), this.register = (t, e) => {
      const s = this.map.peek(), r = s.get(t), i = () => this.unregister(t, e);
      if (r === e) return i;
      if (r) {
        const o = this.cleanupFunctions.get(r);
        o?.(), this.cleanupFunctions.delete(r);
      }
      const n = new Map(s);
      n.set(t, e), this.map.value = n;
      const d = tt(...e.effects());
      return this.cleanupFunctions.set(e, d), i;
    }, this.unregister = (t, e) => {
      const s = this.map.peek();
      if (s.get(t) !== e)
        return;
      const r = this.cleanupFunctions.get(e);
      r?.(), this.cleanupFunctions.delete(e);
      const i = new Map(s);
      i.delete(t), this.map.value = i;
    };
  }
  /**
   * Iterator for the EntityRegistry class.
   * @returns An iterator for the values in the map.
   */
  [Symbol.iterator]() {
    return this.map.peek().values();
  }
  get value() {
    return this.map.value.values();
  }
  /**
   * Checks if a entity with the given identifier exists in the registry.
   * @param identifier - The unique identifier of the entity.
   * @returns True if the entity exists, false otherwise.
   */
  has(t) {
    return this.map.value.has(t);
  }
  /**
   * Retrieves a entity from the registry using its identifier.
   * @param identifier - The unique identifier of the entity.
   * @returns The entity if it exists, undefined otherwise.
   */
  get(t) {
    return this.map.value.get(t);
  }
  /**
   * Destroys all entries in the registry and clears the registry.
   */
  destroy() {
    for (const t of this) {
      const e = this.cleanupFunctions.get(t);
      e?.(), t.destroy();
    }
    this.map.value = /* @__PURE__ */ new Map();
  }
}, ne, ae, oe, ce, le, de, ot, m, _t, yt, mt, S = class extends (ot = C, de = [_], le = [_], ce = [_], oe = [b], ae = [b], ne = [b], ot) {
  constructor(e, s) {
    var r = e, { modifiers: i, type: n, sensors: d } = r, o = Nt(r, ["modifiers", "type", "sensors"]);
    super(o, s), a(m, 5, this), h(this, _t, a(m, 8, this)), a(m, 11, this), h(this, yt, a(m, 12, this)), a(m, 15, this), h(this, mt, a(m, 16, this, this.isDragSource ? "dragging" : "idle")), a(m, 19, this), this.type = n, this.sensors = d, this.modifiers = i, this.alignment = o.alignment;
  }
  get isDropping() {
    return this.status === "dropping" && this.isDragSource;
  }
  get isDragging() {
    return this.status === "dragging" && this.isDragSource;
  }
  get isDragSource() {
    var e, s;
    return ((s = (e = this.manager) == null ? void 0 : e.dragOperation.source) == null ? void 0 : s.id) === this.id;
  }
};
m = N(ot);
_t = /* @__PURE__ */ new WeakMap();
yt = /* @__PURE__ */ new WeakMap();
mt = /* @__PURE__ */ new WeakMap();
l(m, 4, "type", de, S, _t);
l(m, 4, "modifiers", le, S, yt);
l(m, 4, "status", ce, S, mt);
l(m, 2, "isDropping", oe, S);
l(m, 2, "isDragging", ae, S);
l(m, 2, "isDragSource", ne, S);
A(m, S);
var ue, he, pe, ge, fe, ve, ct, v, wt, bt, Dt, Mt, Ot, W = class extends (ct = C, ve = [_], fe = [_], ge = [_], pe = [_], he = [_], ue = [b], ct) {
  constructor(e, s) {
    var r = e, { accept: i, collisionDetector: n, collisionPriority: d, type: o } = r, g = Nt(r, ["accept", "collisionDetector", "collisionPriority", "type"]);
    super(g, s), a(v, 5, this), h(this, wt, a(v, 8, this)), a(v, 11, this), h(this, bt, a(v, 12, this)), a(v, 15, this), h(this, Dt, a(v, 16, this)), a(v, 19, this), h(this, Mt, a(v, 20, this)), a(v, 23, this), h(this, Ot, a(v, 24, this)), a(v, 27, this), this.accept = i, this.collisionDetector = n, this.collisionPriority = d, this.type = o;
  }
  /**
   * Checks whether or not the droppable accepts a given draggable.
   *
   * @param draggable - The draggable to check
   * @returns true if the draggable can be dropped here
   */
  accepts(e) {
    const { accept: s } = this;
    return s ? typeof s == "function" ? s(e) : e.type ? Array.isArray(s) ? s.includes(e.type) : e.type === s : !1 : !0;
  }
  get isDropTarget() {
    var e, s;
    return ((s = (e = this.manager) == null ? void 0 : e.dragOperation.target) == null ? void 0 : s.id) === this.id;
  }
};
v = N(ct);
wt = /* @__PURE__ */ new WeakMap();
bt = /* @__PURE__ */ new WeakMap();
Dt = /* @__PURE__ */ new WeakMap();
Mt = /* @__PURE__ */ new WeakMap();
Ot = /* @__PURE__ */ new WeakMap();
l(v, 4, "accept", ve, W, wt);
l(v, 4, "type", fe, W, bt);
l(v, 4, "collisionDetector", ge, W, Dt);
l(v, 4, "collisionPriority", pe, W, Mt);
l(v, 4, "shape", he, W, Ot);
l(v, 2, "isDropTarget", ue, W);
A(v, W);
var zt = class extends F {
  /**
   * Creates a new sensor instance.
   *
   * @param manager - The drag drop manager instance
   * @param options - Optional sensor configuration
   */
  constructor(t, e) {
    super(t, e), this.manager = t, this.options = e;
  }
}, Ft = class extends F {
  /**
   * Creates a new modifier instance.
   *
   * @param manager - The drag and drop manager that owns this modifier
   * @param options - Optional configuration for the modifier
   */
  constructor(t, e) {
    super(t, e), this.manager = t, this.options = e;
  }
  /**
   * Applies the modifier to the current drag operation.
   *
   * @param operation - The current state of the drag operation
   * @returns The transformed coordinates
   *
   * @remarks
   * Override this method to implement custom transformation logic.
   * The default implementation returns the original transform unchanged.
   */
  apply(t) {
    return t.transform;
  }
}, Ue = class {
  /**
   * Creates a new registry instance.
   *
   * @param manager - The drag and drop manager that owns this registry
   */
  constructor(t) {
    this.draggables = new xt(), this.droppables = new xt(), this.plugins = new nt(t), this.sensors = new nt(t), this.modifiers = new nt(t);
  }
  register(t, e) {
    if (t instanceof S)
      return this.draggables.register(t.id, t);
    if (t instanceof W)
      return this.droppables.register(t.id, t);
    if (t.prototype instanceof Ft)
      return this.modifiers.register(t, e);
    if (t.prototype instanceof zt)
      return this.sensors.register(t, e);
    if (t.prototype instanceof F)
      return this.plugins.register(t, e);
    throw new Error("Invalid instance type");
  }
  unregister(t) {
    if (t instanceof C)
      return t instanceof S ? this.draggables.unregister(t.id, t) : t instanceof W ? this.droppables.unregister(t.id, t) : () => {
      };
    if (t.prototype instanceof Ft)
      return this.modifiers.unregister(t);
    if (t.prototype instanceof zt)
      return this.sensors.unregister(t);
    if (t.prototype instanceof F)
      return this.plugins.unregister(t);
    throw new Error("Invalid instance type");
  }
  /**
   * Destroys all registered entities and cleans up resources.
   *
   * @remarks
   * This method:
   * - Destroys all draggable and droppable entities
   * - Destroys all plugins, sensors, and modifiers
   * - Cleans up any associated resources
   */
  destroy() {
    this.draggables.destroy(), this.droppables.destroy(), this.plugins.destroy(), this.sensors.destroy(), this.modifiers.destroy();
  }
}, _e, ye, me, we, be, De, Me, Oe, ke, T, Y, V, f, kt, Et, It, Pt, St, $;
ke = [b], Oe = [_], Me = [_], De = [_], be = [_], we = [_], me = [b], ye = [b], _e = [b];
var P = class {
  /**
   * Creates a new drag operation instance.
   *
   * @param manager - The drag and drop manager that owns this operation
   */
  constructor(t) {
    a(f, 5, this), h(this, T), h(this, Y), h(this, V, new Ee(
      void 0,
      (e, s) => e && s ? e.equals(s) : e === s
    )), this.status = new x(), h(this, kt, a(f, 8, this, !1)), a(f, 11, this), h(this, Et, a(f, 12, this, null)), a(f, 15, this), h(this, It, a(f, 16, this, null)), a(f, 19, this), h(this, Pt, a(f, 20, this, null)), a(f, 23, this), h(this, St, a(f, 24, this, [])), a(f, 27, this), this.position = new Ie({ x: 0, y: 0 }), h(this, $, { x: 0, y: 0 }), I(this, T, t);
  }
  get shape() {
    const { current: t, initial: e, previous: s } = y(this, V);
    return !t || !e ? null : { current: t, initial: e, previous: s };
  }
  /**
   * Sets the shape of the dragged entity.
   *
   * @param value - The new shape or null to reset
   */
  set shape(t) {
    t ? y(this, V).current = t : y(this, V).reset();
  }
  get source() {
    var t;
    const e = this.sourceIdentifier;
    if (e == null) return null;
    const s = y(this, T).registry.draggables.get(e);
    return s && I(this, Y, s), (t = s ?? y(this, Y)) != null ? t : null;
  }
  get target() {
    var t;
    const e = this.targetIdentifier;
    return e != null && (t = y(this, T).registry.droppables.get(e)) != null ? t : null;
  }
  get transform() {
    const { x: t, y: e } = this.position.delta;
    let s = { x: t, y: e };
    for (const r of this.modifiers)
      s = r.apply(qt(Vt({}, this.snapshot()), {
        transform: s
      }));
    return I(this, $, s), s;
  }
  /**
   * Creates a snapshot of the current drag operation state.
   *
   * @returns An immutable snapshot of the current operation state
   */
  snapshot() {
    return O(() => ({
      source: this.source,
      target: this.target,
      activatorEvent: this.activatorEvent,
      transform: y(this, $),
      shape: this.shape ? it(this.shape) : null,
      position: it(this.position),
      status: it(this.status),
      canceled: this.canceled
    }));
  }
  /**
   * Resets the drag operation to its initial state.
   *
   * @remarks
   * This method:
   * - Sets status to idle
   * - Clears source and target identifiers
   * - Resets shape history
   * - Resets position and transform
   * - Clears modifiers
   */
  reset() {
    At(() => {
      this.status.set(
        "idle"
        /* Idle */
      ), this.sourceIdentifier = null, this.targetIdentifier = null, y(this, V).reset(), this.position.reset({ x: 0, y: 0 }), I(this, $, { x: 0, y: 0 }), this.modifiers = [];
    });
  }
};
f = N(null);
T = /* @__PURE__ */ new WeakMap();
Y = /* @__PURE__ */ new WeakMap();
V = /* @__PURE__ */ new WeakMap();
kt = /* @__PURE__ */ new WeakMap();
Et = /* @__PURE__ */ new WeakMap();
It = /* @__PURE__ */ new WeakMap();
Pt = /* @__PURE__ */ new WeakMap();
St = /* @__PURE__ */ new WeakMap();
$ = /* @__PURE__ */ new WeakMap();
l(f, 2, "shape", ke, P);
l(f, 4, "canceled", Oe, P, kt);
l(f, 4, "activatorEvent", Me, P, Et);
l(f, 4, "sourceIdentifier", De, P, It);
l(f, 4, "targetIdentifier", be, P, Pt);
l(f, 4, "modifiers", we, P, St);
l(f, 2, "source", me, P);
l(f, 2, "target", ye, P);
l(f, 2, "transform", _e, P);
A(f, P);
var Te = {
  get rendering() {
    return Promise.resolve();
  }
}, Xe = class {
  /**
   * Creates a new drag and drop manager instance.
   *
   * @param config - Optional configuration for plugins, sensors, modifiers, and renderer
   */
  constructor(e) {
    this.destroy = () => {
      this.dragOperation.status.idle || this.actions.stop({ canceled: !0 }), this.dragOperation.modifiers.forEach((u) => u.destroy()), this.registry.destroy(), this.collisionObserver.destroy();
    };
    const {
      plugins: s = [],
      sensors: r = [],
      modifiers: i = [],
      renderer: n = Te
    } = e ?? {}, d = new je(this), o = new Ue(this);
    this.registry = o, this.monitor = d, this.renderer = n, this.actions = new Ne(this), this.dragOperation = new P(this), this.collisionObserver = new Le(this), this.plugins = [He, ...s], this.modifiers = i, this.sensors = r;
    const { destroy: g } = this, p = tt(() => {
      var u, c, z;
      const D = O(() => this.dragOperation.modifiers), L = this.modifiers;
      D !== L && D.forEach((R) => R.destroy()), this.dragOperation.modifiers = (z = (c = (u = this.dragOperation.source) == null ? void 0 : u.modifiers) == null ? void 0 : c.map((R) => {
        const { plugin: B, options: et } = $t(R);
        return new B(this, et);
      })) != null ? z : L;
    });
    this.destroy = () => {
      p(), g();
    };
  }
  /**
   * Gets the list of active plugins.
   *
   * @returns Array of active plugin instances
   */
  get plugins() {
    return this.registry.plugins.values;
  }
  /**
   * Sets the list of plugins to be used by the manager.
   *
   * @param plugins - Array of plugin constructors or instances
   */
  set plugins(e) {
    this.registry.plugins.values = e;
  }
  /**
   * Gets the list of active modifiers.
   *
   * @returns Array of active modifier instances
   */
  get modifiers() {
    return this.registry.modifiers.values;
  }
  /**
   * Sets the list of modifiers to be used by the manager.
   *
   * @param modifiers - Array of modifier constructors or instances
   */
  set modifiers(e) {
    this.registry.modifiers.values = e;
  }
  /**
   * Gets the list of active sensors.
   *
   * @returns Array of active sensor instances
   */
  get sensors() {
    return this.registry.sensors.values;
  }
  /**
   * Sets the list of sensors to be used by the manager.
   *
   * @param sensors - Array of sensor constructors or instances
   */
  set sensors(e) {
    this.registry.sensors.values = e;
  }
};
export {
  Ve as CollisionPriority,
  qe as CollisionType,
  Bt as CorePlugin,
  Xe as DragDropManager,
  x as DragOperationStatus,
  S as Draggable,
  W as Droppable,
  Ft as Modifier,
  F as Plugin,
  nt as PluginRegistry,
  zt as Sensor,
  Je as configurator,
  Tt as configure,
  $t as descriptor,
  Ae as sortCollisions
};
//# sourceMappingURL=index.js.map
