'use strict';

var vue = require('vue');
var index$2 = require('../try-on-scope-dispose/index.cjs');
var index$1 = require('../unref-element/index.cjs');
var index = require('../use-supported/index.cjs');
var _configurable = require('../_configurable.cjs');

function useMutationObserver(target, callback, options = {}) {
  const { window = _configurable.defaultWindow, ...mutationOptions } = options;
  let observer;
  const isSupported = index.useSupported(() => window && "MutationObserver" in window);
  const cleanup = () => {
    if (observer) {
      observer.disconnect();
      observer = void 0;
    }
  };
  const stopWatch = vue.watch(
    () => index$1.unrefElement(target),
    (el) => {
      cleanup();
      if (isSupported.value && window && el) {
        observer = new MutationObserver(callback);
        observer.observe(el, mutationOptions);
      }
    },
    { immediate: true }
  );
  const stop = () => {
    cleanup();
    stopWatch();
  };
  index$2.tryOnScopeDispose(stop);
  return {
    isSupported,
    stop
  };
}

exports.useMutationObserver = useMutationObserver;
//# sourceMappingURL=index.cjs.map
