/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var utils_dom = require('../utils/dom.js');
require('vue');
require('raf');
require('lodash/isString');
require('../utils/easing.js');

var triggers = ["click", "hover", "focus", "context-menu"];
function getPopperPlacement(placement) {
  return placement.replace(/-(left|top)$/, "-start").replace(/-(right|bottom)$/, "-end");
}
function attachListeners(elm) {
  var offs = [];
  return {
    add: function add(type, listener) {
      utils_dom.on(elm, type, listener);
      offs.push(function () {
        utils_dom.off(elm, type, listener);
      });
    },
    clean: function clean() {
      offs.forEach(function (handler) {
        return handler === null || handler === void 0 ? void 0 : handler();
      });
      offs.length = 0;
    }
  };
}
function isContentRectChanged(rect1, rect2) {
  if (!rect1 || !rect2) return;
  if (["width", "height", "x", "y"].some(function (k) {
    return rect1[k] !== rect2[k];
  })) return true;
  return false;
}
function observeResize(elm, cb) {
  var _window;
  if (!((_window = window) !== null && _window !== void 0 && _window.ResizeObserver) || !elm) return;
  var prevContentRect = null;
  var ro = new ResizeObserver(function () {
    var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var _ref = entries[0] || {},
      contentRect = _ref.contentRect;
    if (isContentRectChanged(contentRect, prevContentRect)) {
      prevContentRect = contentRect;
      cb(contentRect);
      return;
    }
    if (!prevContentRect) prevContentRect = contentRect;
  });
  ro.observe(elm);
  return function () {
    ro.unobserve(elm);
  };
}

exports.attachListeners = attachListeners;
exports.getPopperPlacement = getPopperPlacement;
exports.observeResize = observeResize;
exports.triggers = triggers;
//# sourceMappingURL=utils.js.map
