import { C as r } from "./base-PQGakkrl.js";
import { C as M } from "./promise-CPiVqqqL.js";
class K {
  _elCanvasTextWidth;
  constructor() {
    this._elCanvasTextWidth = null;
  }
  _getArrClassBySplit(t) {
    return t.split(" ").filter((e) => !r.isEmpty(e));
  }
  _getClasssByReal(t, e) {
    return t.filter((i) => !r.isExistValue(e, i) && !r.isEmpty(i));
  }
  onListener(t, e, i, n = !1) {
    t && e && i && t.addEventListener(e, i, n);
  }
  offListener(t, e, i, n = !1) {
    t && e && i && t.removeEventListener(e, i, n);
  }
  getTextWidth(t, e = "normal 12px Microsoft YaHei") {
    this._elCanvasTextWidth || (this._elCanvasTextWidth = document.createElement("canvas"));
    const i = this._elCanvasTextWidth.getContext("2d");
    return i.font = e, i.measureText(t).width;
  }
  /** 添加class */
  getAddClass(...t) {
    let e = [];
    return t.forEach((i) => {
      if (r.isString(i)) {
        const n = this._getArrClassBySplit(i);
        e = e.concat(this._getClasssByReal(n, e));
      } else if (r.isArray(i))
        e = e.concat(this._getClasssByReal(i, e));
      else if (r.isObject(i))
        for (const [n, o] of Object.entries(i))
          r.isExistJsonKey(i, n) && o ? e.push(n) : e = e.filter((s) => s !== n || s === n && o);
    }), e.join(" ");
  }
  /** 移除class */
  getRemoveClass(t, e) {
    const i = this._getArrClassBySplit(e);
    return this._getArrClassBySplit(t).filter((o) => !r.isExistValue(i, o)).join(" ");
  }
  checkHasClass(t, e) {
    const i = this._getArrClassBySplit(t), n = this._getArrClassBySplit(e);
    return r.isContainArr(i, n);
  }
  /** 指定元素距离窗口信息 */
  _getBoundingClientRect(t) {
    const e = r.isUndefined(t.getBoundingClientRect) ? {} : t.getBoundingClientRect(), i = {
      width: e.width || 0,
      height: e.height || 0,
      top: e.top || 0,
      right: 0,
      bottom: 0,
      left: e.left || 0,
      x: e.left || 0,
      y: e.top || 0
    }, n = this.getWinHeight(), o = this.getWinWidth();
    return i.right = o - e.right || 0, i.bottom = n - e.bottom || 0, i;
  }
  /* _getWindow(el: any) {
      if (CommonBase.isWindow(el)) {
          return el;
      }
      return el.nodeType === 9 ? (el.defaultView || el.parentWindow) : false;
  } */
  _getWindow(t) {
    if (t && t.toString() !== "[object Window]") {
      const e = t.ownerDocument;
      return e && e.defaultView || window;
    }
    return t;
  }
  isElementHtml(t) {
    const e = this._getWindow(t).HTMLElement;
    return t instanceof e || t instanceof HTMLElement;
  }
  isElementBody(t) {
    return r.isUndefined(t) ? !1 : this.isElementHtml(t) && t.tagName.toLocaleLowerCase() === "body";
  }
  getWinScrollTop() {
    return document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
  }
  getWinWidth() {
    return document.documentElement.clientWidth || document.body.clientWidth || window.innerWidth;
  }
  getWinHeight() {
    return document.documentElement.clientHeight || document.body.clientHeight || window.innerHeight;
  }
  /**
   * 获取元素的css
   * @param el
   * @returns
   */
  getStyle(t) {
    return window.getComputedStyle ? window.getComputedStyle(t, null) : t.currentStyle;
  }
  _isElementScroll(t) {
    const e = this.getStyle(t), i = e.overflow, n = e.overflowX, o = e.overflowY;
    return /auto|scroll|overlay|hidden/.test(i + o + n);
  }
  isHidden(t) {
    return this.getStyle(t).display === "none";
  }
  isHiddenParent(t) {
    let e = !1, i = t, n = !1;
    for (; i && i.nodeType !== 9 && !n; )
      i.nodeType === 1 && (n = this.isHidden(i), n && (e = !0)), i = i.parentNode;
    return e;
  }
  /**
   * 获取上级元素,并检查parent包含el且parent非body
   * @param el 指定元素
   * @param parent 指定上级,可为string[#(id),.(class),tagName] || element; 为空时默认el.parentNode
   * @returns parentElement。当检查parentElement为body或者parent不包含el时,返回null
   */
  getParentCheckBody(t, e, i = !0) {
    let n = null;
    return e ? r.isString(e) ? e.toLocaleLowerCase() !== "body" && (n = this.getParent(t, e)) : this.isElementBody(e) || (i ? e.contains(t) && (n = e) : n = e) : this.isElementBody(t.parentNode) || (n = t.parentNode), n;
  }
  /**
  * 获取上级元素
   * @param el 指定元素
   * @param parentAttr 指定上级,可为string[#(id),.(class),tagName]; 为空时默认el.parentNode
   * @param elUpperLimit 非必传，设置该参数时，如果在parentAttr参数之前匹配上设置值 则直接返回
   * @param isLimitReturnSelf 截止到elUpperLimit时 未匹配上parentAttr 是否返回 elUpperLimit
   * @returns parentElement
   */
  getParent(t, e, i, n = !0) {
    if (r.isEmpty(e))
      return t.parentNode;
    let s = null;
    const f = !r.isUndefined(i);
    if (this._checkElementByAttr(t, e))
      s = t;
    else {
      let l = t.parentNode, h = !1;
      for (; l && l.nodeType !== 9 && !h; )
        l.nodeType === 1 && (h = this._checkElementByAttr(l, e), h ? s = l : f && (h = l === i, h && n && (s = l))), l = l.parentNode;
    }
    return s;
  }
  /**
   * 获取所有上级元素
   * @param el 指定元素
   * @param parentAttr 指定上级,可为string[#(id),.(class),tagName]; 为空时默认el.parentNode
   * @returns list[parentElement]
   */
  getParentList(t, e) {
    const i = r.isEmpty(e) ? "body" : e;
    return this._recursionParents(t, i);
  }
  _recursionParents(t, e) {
    const i = [];
    if (this._checkElementByAttr(t, e))
      i.push(t);
    else if (t.parentNode && t.parentElement && !this.isElementBody(t.parentElement)) {
      i.push(t.parentNode);
      const n = this._recursionParents(t.parentNode, e);
      i.push(...n);
    }
    return i;
  }
  getParentScrollList(t, e, i = !0) {
    const n = [];
    return this.getParentList(t, e).forEach((s) => {
      this._isElementScroll(s) && (i ? n.push(s) : this._checkElementByAttr(s, e) || n.push(s));
    }), n;
  }
  /**
   * 根据attr检查元素信息
   * @param el
   * @param attr
   * @returns true/false
   */
  _checkElementByAttr(t, e) {
    let i = !1;
    if (!r.isEmpty(e))
      if (r.isString(e)) {
        const n = e.substr(0, 1), o = e.substring(1);
        switch (n) {
          case "#":
            i = t.id === o;
            break;
          case ".":
            i = r.isString(t.className) ? r.isExistValue(t.className.split(" "), o) : !1;
            break;
          default:
            i = t.tagName.toLocaleLowerCase() === e;
        }
      } else
        this.isElementHtml(e) && (i = t === e);
    return i;
  }
  /**
   * 获取元素到窗体 偏移量
   * @param el 指定元素
   * @param viewEl 指定窗体,为空时默认window
   * @returns json { top，left }
   */
  getOffset(t, e = null) {
    const i = this.getPositionView(t, e);
    if (i.viewEl)
      return {
        top: i.top + i.viewEl.scrollTop - i.viewEl.clientTop,
        left: i.left + i.viewEl.scrollLeft - i.viewEl.clientLeft
      };
    {
      const o = (t && t.ownerDocument).documentElement, s = this._getWindow(o);
      return {
        top: i.top + (s.pageYOffset || o.scrollTop) - (o.clientTop || 0),
        left: i.left + (s.pageXOffset || o.scrollLeft) - (o.clientLeft || 0)
      };
    }
  }
  /**
   * 获取元素相对指定容器的相对偏移
   * @param el 指定元素
   * @param viewEl 指定容器,为空时默认window
   * @returns json {top,left,viewEl}
   */
  getPositionView(t, e = null) {
    const i = { top: 0, left: 0, viewEl: null };
    if (!this.isElementHtml(t))
      return i;
    const n = this._getBoundingClientRect(t);
    i.top = n.top, i.right = n.right, i.bottom = n.bottom, i.left = n.left, i.width = n.width, i.height = n.height;
    const o = { top: 0, right: 0, bottom: 0, left: 0 }, s = r.isUndefined(e) ? null : this.getParentCheckBody(t, e, !0);
    if (s) {
      const f = this._getBoundingClientRect(s);
      o.top = f.top, o.right = f.right, o.bottom = f.bottom, o.left = f.left, i.viewWidth = f.width, i.viewHeight = f.height, i.top = n.top - (o.top < 0 ? 0 : o.top), i.right = n.right - (o.right < 0 ? 0 : o.right), i.bottom = n.bottom - (o.bottom < 0 ? 0 : o.bottom), i.left = n.left - (o.left < 0 ? 0 : o.left), i.elViewBox = {
        top: n.top - o.top,
        right: n.right - o.right,
        bottom: n.bottom - o.bottom,
        left: n.left - o.left
      };
    }
    return i.viewEl = s, i;
  }
  /**
   * 获取元素相对指定容器的相对偏移
   * @param el 指定元素
   * @param parentAttr 指定窗体,为空时默认parentNode
   * @returns json
   */
  getPosition(t, e = null) {
    const i = r.isUndefined(e) ? t.parentNode : e;
    return this.getPositionView(t, i);
  }
  getElementIndex(t) {
    return this.getPrevAll(t).length;
  }
  getPrev(t) {
    if (r.isUndefined(t.previousElementSibling)) {
      let e = t.previousSibling;
      for (; e && e.nodeType !== 1; )
        e = e.previousSibling;
      return e;
    } else
      return t.previousElementSibling;
  }
  getPrevAll(t) {
    const e = [];
    let i = this.getPrev(t);
    for (; i; )
      e.push(i), i = this.getPrev(i);
    return e.reverse();
  }
  getNext(t) {
    if (r.isUndefined(t.nextElementSibling)) {
      let e = t.nextSibling;
      for (; e && e.nodeType !== 1; )
        e = e.nextSibling;
      return e;
    } else
      return t.nextElementSibling;
  }
  insertAfter(t, e) {
    const i = t.parentNode;
    i.lastChild == t ? i.appendChild(e) : i.insertBefore(e, t.nextSibling);
  }
  getFocusSelection(t) {
    const e = {};
    if (r.isUndefined(t.selectionStart)) {
      t.focus();
      const i = document.selection.createRange();
      e.length = i.text.length, i.moveStart("character", -t.value.length), e.end = i.text.length, e.start = e.end - e.length;
    } else
      e.start = t.selectionStart, e.end = t.selectionEnd, e.length = e.end - e.start;
    return e;
  }
  setFocusSelection(t, e, i) {
    if (r.isUndefined(t.selectionStart)) {
      t.focus();
      const n = t.createTextRange();
      n.collapse(!0), n.moveEnd("character", i), n.moveStart("character", e), n.select();
    } else
      t.selectionStart = e, t.selectionEnd = i;
  }
  /* checkHoverInControl(controlEl, hoverInfo) {
  
      } */
  calculationDropdownPosition(t, e, i, n, o) {
    const s = o ? this.getParentCheckBody(t, o) : null, f = r.isUndefined(s), g = e.offsetWidth, l = e.offsetHeight, h = i.offsetWidth, R = i.offsetHeight;
    let _ = 0, C = 0;
    r.isUndefined(n) || (_ = n.offsetWidth, C = n.offsetHeight);
    const v = _ / 2, T = this.getWinHeight(), B = this.getWinWidth();
    let u = 0, y = 0, S = 0, a = { top: 0, left: 0 }, m = { top: 0, left: 0 };
    f ? (u = B, y = T, S = u - document.body.clientWidth, a = this.getOffset(t), m = this.getPositionView(t)) : (u = s.clientWidth, y = s.clientHeight, S = s.offsetWidth - u, a = this.getOffset(t, s), m = this.getPositionView(t, s));
    const x = m.top, H = h + _, p = R + C, V = l + p, d = {
      winWidth: B,
      winHeight: T,
      containerWidth: u,
      containerHeight: y,
      controlOffset: a,
      controlPosView: m,
      textWidth: g,
      textHeight: l,
      dropDownWidth: h,
      dropDownHeight: R,
      arrowWidth: _,
      arrowHeight: C
    };
    let P = "down";
    x + V > y && (x > p || a.top > p) && (P = "up"), d.dropDownPosDown = P;
    let O = "up";
    x < p && a.top < p && (O = "down"), d.dropDownPosUp = O;
    let W = "left";
    m.left < H && a.right >= p && (W = "right"), d.dropDownPosLeft = W;
    const X = "right";
    m.right < H && a.left >= p && (W = "left"), d.dropDownPosRight = X;
    let k = "left";
    u - a.left < h && (k = a.left + g >= h ? "right" : "left"), d.arrowPosLeft = k;
    let A = "right";
    a.left + g < h && (A = u - a.left >= h ? "left" : "right"), d.arrowPosRight = A;
    let Y = "center";
    a.left + g < h / 2 - g / 2 && (Y = a.left > h / 2 - g / 2 ? "right" : "left"), d.arrowPosCenterLR = Y;
    const w = {
      dropDownLeft: 0,
      arrowLeft: 0
    }, U = this.getOffset(e), j = this.getOffset(e, t), b = g / 2, E = U.left - 5, F = u - E - g - 10 - S, D = i.clientWidth / 2 - b, I = D - E, L = D - F;
    return I <= 0 && L <= 0 ? (w.dropDownLeft = (D - j.left) * -1, w.arrowLeft = D + b - v - 1) : I > 0 ? (w.dropDownLeft = E * -1, w.arrowLeft = E + b - v) : L > 0 && (w.dropDownLeft = (D + L) * -1, w.arrowLeft = D + L + b - v), d.arrowPosCenterLRInfo = w, d.arrowPosTop = "top", d.arrowPosBottom = "bottom", d.arrowPosCenterTB = "center", d;
  }
  getElementData(t) {
    const e = {};
    if (!r.isEmpty(t))
      for (const [i, n] of Object.entries(t)) {
        const o = i.split("-"), s = [];
        o.forEach((f, g) => {
          if (g > 0) {
            const l = f.toLowerCase();
            g === 1 ? s.push(l) : s.push(l.replace(l[0], l[0].toUpperCase()));
          }
        }), s.length > 0 && (e[s.join("")] = n);
      }
    return e;
  }
  async getTextDataByFile(t) {
    const e = [];
    if (!r.isEmpty(t))
      for (let i = 0; i < t.length; i++) {
        const n = await this._getTextDataFileOne(t[i]);
        e.push(...n);
      }
    return e;
  }
  _getTextDataFileOne(t) {
    return M.promiseFun((e) => {
      const i = new FileReader();
      i.readAsText(t, "utf-8"), i.onload = (n) => {
        const o = [];
        n.target.result.split(`
`).forEach((s) => {
          const f = r.trim(s);
          r.isEmpty(f) || o.push(f);
        }), e(o);
      };
    });
  }
  getClientXY(t) {
    let e, i;
    return t.type === "touchend" ? (i = t.changedTouches[0].clientY, e = t.changedTouches[0].clientX) : t.type.startsWith("touch") ? (i = t.touches[0].clientY, e = t.touches[0].clientX) : (i = t.clientY, e = t.clientX), {
      clientX: e,
      clientY: i
    };
  }
}
const c = new K();
class z {
  optionsDrag;
  _isDragging;
  _bindRunDragStart;
  _bindRunDragIng;
  _bindRunDragEnd;
  constructor(t, e) {
    this.optionsDrag = e, this._isDragging = !1, this._init(t);
  }
  _init(t) {
    this._bindRunDragStart = this._runDragStart.bind(this), this._bindRunDragIng = this._runDraggIng.bind(this), this._bindRunDragEnd = this._runDragEnd.bind(this), c.onListener(t, "mousedown", this._bindRunDragStart), c.onListener(t, "touchstart", this._bindRunDragStart);
  }
  _runDragStart(t) {
    if (this._isDragging) return;
    const e = c.getClientXY(t);
    let i = !0;
    this.optionsDrag.start && (i = this.optionsDrag.start(t, e)), i = r.isBoolean(i) ? i : !0, i ? (t.preventDefault(), t.stopPropagation(), document.onselectstart = () => !1, document.ondragstart = () => !1, this._isDragging = !0, c.onListener(window, "mousemove", this._bindRunDragIng), c.onListener(window, "touchmove", this._bindRunDragIng), c.onListener(window, "mouseup", this._bindRunDragEnd), c.onListener(window, "touchend", this._bindRunDragEnd), c.onListener(window, "contextmenu", this._bindRunDragEnd)) : this._isDragging = !1;
  }
  _runDraggIng(t) {
    if (!this._isDragging) return;
    const e = c.getClientXY(t);
    this.optionsDrag.ing && this.optionsDrag.ing(t, e);
  }
  _runDragEnd(t) {
    if (!this._isDragging) return;
    this._isDragging = !1;
    const e = c.getClientXY(t);
    this.optionsDrag.end && this.optionsDrag.end(t, e), this._offListener();
  }
  _offListener() {
    c.offListener(window, "mousemove", this._bindRunDragIng), c.offListener(window, "touchmove", this._bindRunDragIng), c.offListener(window, "mouseup", this._bindRunDragEnd), c.offListener(window, "touchend", this._bindRunDragEnd), c.offListener(window, "contextmenu", this._bindRunDragEnd);
  }
  end() {
    this._isDragging = !1, this._offListener();
  }
}
export {
  c as C,
  z as D
};
//# sourceMappingURL=Element_Event_drag-DeZYlveu.js.map
