import { defineComponent as v, ref as d, onMounted as f, onUnmounted as w, openBlock as r, createElementBlock as s, normalizeClass as m, Fragment as g, renderList as k, createElementVNode as u, toDisplayString as y } from "vue";
const E = ["onClick"], C = { class: "anchor-label" }, B = /* @__PURE__ */ v({
  name: "ClAnchorNav",
  __name: "Index",
  props: {
    className: {
      type: String,
      default: ""
      // desc: 自定义CSS类名
    },
    list: {
      type: Array,
      required: !0
      // desc: 锚点列表配置，每个锚点包含id和label属性
    }
  },
  setup(c) {
    const h = c, i = d(""), a = d(!1), p = (o) => {
      const t = document.getElementById(o);
      t && t.scrollIntoView({ behavior: "smooth", block: "start" });
    }, l = () => {
      const o = window.scrollY, t = window.innerHeight;
      a.value = o > 100;
      const n = h.list.map((e) => ({
        id: e.id,
        element: document.getElementById(e.id)
      })).filter((e) => e.element !== null);
      for (let e = n.length - 1; e >= 0; e--)
        if (n[e].element.getBoundingClientRect().top <= t / 2) {
          i.value = n[e].id;
          break;
        }
    };
    return f(() => {
      window.addEventListener("scroll", l), l();
    }), w(() => {
      window.removeEventListener("scroll", l);
    }), (o, t) => (r(), s("div", {
      class: m(["anchor-nav", { "is-fixed": a.value }])
    }, [
      (r(!0), s(g, null, k(c.list, (n) => (r(), s("div", {
        key: n.id,
        class: m(["anchor-item", { active: i.value === n.id }]),
        onClick: (e) => p(n.id)
      }, [
        t[0] || (t[0] = u("span", { class: "anchor-dot" }, null, -1)),
        u("span", C, y(n.label), 1)
      ], 10, E))), 128))
    ], 2));
  }
});
export {
  B as default
};
//# sourceMappingURL=ClAnchorNav.js.map
