import "../../../../@dnd-kit_state@0.1.21/node_modules/@dnd-kit/state/dist/index.js";
import { Modifier as d, configurator as g } from "../../../../@dnd-kit_abstract@0.1.21/node_modules/@dnd-kit/abstract/index.js";
import { restrictShapeToBoundingRectangle as f } from "../../../../@dnd-kit_abstract@0.1.21/node_modules/@dnd-kit/abstract/modifiers.js";
import { Rectangle as m } from "../../../../@dnd-kit_geometry@0.1.21/node_modules/@dnd-kit/geometry/dist/index.js";
import { getBoundingRectangle as p } from "./utilities.js";
import { signal as R, effect as h } from "../../../../@preact_signals-core@1.12.0/node_modules/@preact/signals-core/dist/signals-core.module.js";
var l = class extends d {
  constructor(i, s) {
    super(i, s), this.boundingRectangle = R(null), this.destroy = h(() => {
      if (!this.options)
        return;
      const { dragOperation: t } = i, { status: c } = t;
      if (c.initialized) {
        const { element: e } = this.options, r = typeof e == "function" ? e(t) : e;
        if (!r)
          return;
        let n;
        const o = () => {
          this.boundingRectangle.value = p(r);
        }, u = () => {
          n || (n = setTimeout(() => {
            o(), n = void 0;
          }, 25));
        }, a = new ResizeObserver(o);
        return a.observe(r), document.addEventListener("scroll", u, {
          passive: !0,
          capture: !0
        }), () => {
          document.removeEventListener("scroll", u, {
            capture: !0
          }), a.disconnect(), this.boundingRectangle.value = null;
        };
      }
    });
  }
  apply(i) {
    const { shape: s, transform: t } = i;
    if (!s)
      return t;
    const c = this.boundingRectangle.value;
    if (!c)
      return t;
    const { initial: e, current: r } = s, { height: n, width: o } = r.boundingRectangle, u = e.center.x - o / 2, a = e.center.y - n / 2;
    return f(
      new m(u, a, o, n),
      t,
      c
    );
  }
};
l.configure = g(l);
var O = l;
export {
  O as RestrictToElement
};
//# sourceMappingURL=modifiers.js.map
