// packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js
import { useReducedMotion, useRefEffect } from "@wordpress/compose";
function useScrollIntoView({ isSelected }) {
  const prefersReducedMotion = useReducedMotion();
  return useRefEffect(
    (node) => {
      if (isSelected) {
        const { ownerDocument } = node;
        const { defaultView } = ownerDocument;
        if (!defaultView.IntersectionObserver) {
          return;
        }
        const observer = new defaultView.IntersectionObserver(
          (entries) => {
            if (!entries[0].isIntersecting) {
              node.scrollIntoView({
                behavior: prefersReducedMotion ? "instant" : "smooth"
              });
            }
            observer.disconnect();
          }
        );
        observer.observe(node);
        return () => {
          observer.disconnect();
        };
      }
    },
    [isSelected]
  );
}
export {
  useScrollIntoView
};
//# sourceMappingURL=use-scroll-into-view.js.map
