/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');

const defaultWindow = typeof window !== "undefined" ? window : void 0;
function unrefElement(elRef) {
  const plain = VueCompositionAPI.unref(elRef);
  return (plain === null || plain === void 0 ? void 0 : plain.$el) ?? plain;
}
function tryOnScopeDispose(fn) {
  if (VueCompositionAPI.getCurrentScope()) {
    VueCompositionAPI.onScopeDispose(fn);
    return true;
  }
  return false;
}
function useMutationObserver(target, callback) {
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  const {
    window: window2 = defaultWindow,
    ...mutationOptions
  } = options;
  let observer;
  const isSupported = window2 && "MutationObserver" in window2;
  const cleanup = () => {
    if (observer) {
      observer.disconnect();
      observer = void 0;
    }
  };
  const stopWatch = VueCompositionAPI.watch(() => unrefElement(target), el => {
    cleanup();
    if (isSupported && window2 && el) {
      observer = new MutationObserver(callback);
      observer.observe(el, mutationOptions);
    }
  }, {
    immediate: true
  });
  const stop = () => {
    cleanup();
    stopWatch();
  };
  tryOnScopeDispose(stop);
  return {
    isSupported,
    stop
  };
}

exports.defaultWindow = defaultWindow;
exports.tryOnScopeDispose = tryOnScopeDispose;
exports.unrefElement = unrefElement;
exports.useMutationObserver = useMutationObserver;
//# sourceMappingURL=hooks.js.map
