import { onBeforeUnmount, readonly, ref, watch } from "vue";
import { SUPPORTS_RESIZE_OBSERVER } from "@veno-ui/utils";
function useResizeObserver(callback) {
  const resizeRef = ref();
  const contentRect = ref();
  const contentBoxSize = ref();
  const borderBoxSize = ref();
  if (SUPPORTS_RESIZE_OBSERVER) {
    const observer = new ResizeObserver((entries) => {
      callback?.(entries, observer);
      if (!entries.length)
        return;
      contentRect.value = entries[0].contentRect;
      contentBoxSize.value = entries[0].contentBoxSize[0];
      borderBoxSize.value = entries[0].borderBoxSize[0];
    });
    onBeforeUnmount(() => {
      observer.disconnect();
    });
    watch(resizeRef, (newValue, oldValue) => {
      if (oldValue) {
        observer.unobserve(oldValue);
        contentRect.value = void 0;
        contentBoxSize.value = void 0;
        borderBoxSize.value = void 0;
      }
      if (newValue)
        observer.observe(newValue);
    }, {
      flush: "post"
    });
  }
  return {
    resizeRef,
    contentRect: readonly(contentRect),
    contentBoxSize: readonly(contentBoxSize),
    borderBoxSize: readonly(borderBoxSize)
  };
}
export {
  useResizeObserver
};
//# sourceMappingURL=index.mjs.map
