SAnchor.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. import { defineComponent as q, shallowRef as Y, reactive as le, getCurrentInstance as ge, computed as F, watch as V, onMounted as G, onUpdated as se, onUnmounted as me, createVNode as w, provide as ve, inject as xe, nextTick as ae, onBeforeUnmount as ce, ref as U, openBlock as ke, createBlock as ye } from "vue";
  2. import { w as J, a as W, s as Ce, g as fe, m as ue, b as Se, u as X, c as D, o as Te, R as we, _ as z, d as N, r as $e, t as Ae, i as be, e as Be, f as Ie, h as Q, j as Pe, P as Ee, k as Le, l as _e } from "./index2.js";
  3. import { g as Ne, s as ze } from "./scrollTo.js";
  4. function Z(e) {
  5. let t;
  6. const o = (i) => () => {
  7. t = null, e(...i);
  8. }, r = function() {
  9. if (t == null) {
  10. for (var i = arguments.length, u = new Array(i), f = 0; f < i; f++)
  11. u[f] = arguments[f];
  12. t = J(o(u));
  13. }
  14. };
  15. return r.cancel = () => {
  16. J.cancel(t), t = null;
  17. }, r;
  18. }
  19. function M(e) {
  20. return e !== window ? e.getBoundingClientRect() : {
  21. top: 0,
  22. bottom: window.innerHeight
  23. };
  24. }
  25. function ee(e, t, o) {
  26. if (o !== void 0 && t.top > e.top - o)
  27. return `${o + t.top}px`;
  28. }
  29. function te(e, t, o) {
  30. if (o !== void 0 && t.bottom < e.bottom + o) {
  31. const r = window.innerHeight - t.bottom;
  32. return `${o + r}px`;
  33. }
  34. }
  35. const de = ["resize", "scroll", "touchstart", "touchmove", "touchend", "pageshow", "load"];
  36. let H = [];
  37. function ne(e, t) {
  38. if (!e) return;
  39. let o = H.find((r) => r.target === e);
  40. o ? o.affixList.push(t) : (o = {
  41. target: e,
  42. affixList: [t],
  43. eventHandlers: {}
  44. }, H.push(o), de.forEach((r) => {
  45. o.eventHandlers[r] = W(e, r, () => {
  46. o.affixList.forEach((i) => {
  47. const {
  48. lazyUpdatePosition: u
  49. } = i.exposed;
  50. u();
  51. }, (r === "touchstart" || r === "touchmove") && Ce ? {
  52. passive: !0
  53. } : !1);
  54. });
  55. }));
  56. }
  57. function oe(e) {
  58. const t = H.find((o) => {
  59. const r = o.affixList.some((i) => i === e);
  60. return r && (o.affixList = o.affixList.filter((i) => i !== e)), r;
  61. });
  62. t && t.affixList.length === 0 && (H = H.filter((o) => o !== t), de.forEach((o) => {
  63. const r = t.eventHandlers[o];
  64. r && r.remove && r.remove();
  65. }));
  66. }
  67. const Oe = (e) => {
  68. const {
  69. componentCls: t
  70. } = e;
  71. return {
  72. [t]: {
  73. position: "fixed",
  74. zIndex: e.zIndexPopup
  75. }
  76. };
  77. }, Re = fe("Affix", (e) => {
  78. const t = ue(e, {
  79. zIndexPopup: e.zIndexBase + 10
  80. });
  81. return [Oe(t)];
  82. });
  83. function De() {
  84. return typeof window != "undefined" ? window : null;
  85. }
  86. var R;
  87. (function(e) {
  88. e[e.None = 0] = "None", e[e.Prepare = 1] = "Prepare";
  89. })(R || (R = {}));
  90. const Fe = () => ({
  91. /**
  92. * 距离窗口顶部达到指定偏移量后触发
  93. */
  94. offsetTop: Number,
  95. /** 距离窗口底部达到指定偏移量后触发 */
  96. offsetBottom: Number,
  97. /** 设置 Affix 需要监听其滚动事件的元素,值为一个返回对应 DOM 元素的函数 */
  98. target: {
  99. type: Function,
  100. default: De
  101. },
  102. prefixCls: String,
  103. /** 固定状态改变时触发的回调函数 */
  104. onChange: Function,
  105. onTestUpdatePosition: Function
  106. }), He = q({
  107. compatConfig: {
  108. MODE: 3
  109. },
  110. name: "AAffix",
  111. inheritAttrs: !1,
  112. props: Fe(),
  113. setup(e, t) {
  114. let {
  115. slots: o,
  116. emit: r,
  117. expose: i,
  118. attrs: u
  119. } = t;
  120. const f = Y(), C = Y(), g = le({
  121. affixStyle: void 0,
  122. placeholderStyle: void 0,
  123. status: R.None,
  124. lastAffix: !1,
  125. prevTarget: null,
  126. timeout: null
  127. }), I = ge(), $ = F(() => e.offsetBottom === void 0 && e.offsetTop === void 0 ? 0 : e.offsetTop), S = F(() => e.offsetBottom), y = () => {
  128. const {
  129. status: a,
  130. lastAffix: d
  131. } = g, {
  132. target: A
  133. } = e;
  134. if (a !== R.Prepare || !C.value || !f.value || !A)
  135. return;
  136. const B = A();
  137. if (!B)
  138. return;
  139. const m = {
  140. status: R.None
  141. }, n = M(f.value);
  142. if (n.top === 0 && n.left === 0 && n.width === 0 && n.height === 0)
  143. return;
  144. const l = M(B), p = ee(n, l, $.value), k = te(n, l, S.value);
  145. if (!(n.top === 0 && n.left === 0 && n.width === 0 && n.height === 0)) {
  146. if (p !== void 0) {
  147. const c = `${n.width}px`, h = `${n.height}px`;
  148. m.affixStyle = {
  149. position: "fixed",
  150. top: p,
  151. width: c,
  152. height: h
  153. }, m.placeholderStyle = {
  154. width: c,
  155. height: h
  156. };
  157. } else if (k !== void 0) {
  158. const c = `${n.width}px`, h = `${n.height}px`;
  159. m.affixStyle = {
  160. position: "fixed",
  161. bottom: k,
  162. width: c,
  163. height: h
  164. }, m.placeholderStyle = {
  165. width: c,
  166. height: h
  167. };
  168. }
  169. m.lastAffix = !!m.affixStyle, d !== m.lastAffix && r("change", m.lastAffix), N(g, m);
  170. }
  171. }, s = () => {
  172. N(g, {
  173. status: R.Prepare,
  174. affixStyle: void 0,
  175. placeholderStyle: void 0
  176. }), process.env.NODE_ENV === "test" && r("testUpdatePosition");
  177. }, v = Z(() => {
  178. s();
  179. }), x = Z(() => {
  180. const {
  181. target: a
  182. } = e, {
  183. affixStyle: d
  184. } = g;
  185. if (a && d) {
  186. const A = a();
  187. if (A && f.value) {
  188. const B = M(A), m = M(f.value), n = ee(m, B, $.value), l = te(m, B, S.value);
  189. if (n !== void 0 && d.top === n || l !== void 0 && d.bottom === l)
  190. return;
  191. }
  192. }
  193. s();
  194. });
  195. i({
  196. updatePosition: v,
  197. lazyUpdatePosition: x
  198. }), V(() => e.target, (a) => {
  199. const d = (a == null ? void 0 : a()) || null;
  200. g.prevTarget !== d && (oe(I), d && (ne(d, I), v()), g.prevTarget = d);
  201. }), V(() => [e.offsetTop, e.offsetBottom], v), G(() => {
  202. const {
  203. target: a
  204. } = e;
  205. a && (g.timeout = setTimeout(() => {
  206. ne(a(), I), v();
  207. }));
  208. }), se(() => {
  209. y();
  210. }), me(() => {
  211. clearTimeout(g.timeout), oe(I), v.cancel(), x.cancel();
  212. });
  213. const {
  214. prefixCls: E
  215. } = X("affix", e), [b, L] = Re(E);
  216. return () => {
  217. var a;
  218. const {
  219. affixStyle: d,
  220. placeholderStyle: A,
  221. status: B
  222. } = g, m = D({
  223. [E.value]: d,
  224. [L.value]: !0
  225. }), n = Te(e, ["prefixCls", "offsetTop", "offsetBottom", "target", "onChange", "onTestUpdatePosition"]);
  226. return b(w(we, {
  227. onResize: v
  228. }, {
  229. default: () => [w("div", z(z(z({}, n), u), {}, {
  230. ref: f,
  231. "data-measure-status": B
  232. }), [d && w("div", {
  233. style: A,
  234. "aria-hidden": "true"
  235. }, null), w("div", {
  236. class: m,
  237. ref: C,
  238. style: d
  239. }, [(a = o.default) === null || a === void 0 ? void 0 : a.call(o)])])]
  240. }));
  241. };
  242. }
  243. }), Me = Se(He);
  244. function j() {
  245. }
  246. const he = Symbol("anchorContextKey"), je = (e) => {
  247. ve(he, e);
  248. }, Ue = () => xe(he, {
  249. registerLink: j,
  250. unregisterLink: j,
  251. scrollTo: j,
  252. activeLink: F(() => ""),
  253. handleClick: j,
  254. direction: F(() => "vertical")
  255. }), Ve = (e) => {
  256. const {
  257. componentCls: t,
  258. holderOffsetBlock: o,
  259. motionDurationSlow: r,
  260. lineWidthBold: i,
  261. colorPrimary: u,
  262. lineType: f,
  263. colorSplit: C
  264. } = e;
  265. return {
  266. [`${t}-wrapper`]: {
  267. marginBlockStart: -o,
  268. paddingBlockStart: o,
  269. // delete overflow: auto
  270. // overflow: 'auto',
  271. backgroundColor: "transparent",
  272. [t]: N(N({}, $e(e)), {
  273. position: "relative",
  274. paddingInlineStart: i,
  275. [`${t}-link`]: {
  276. paddingBlock: e.anchorPaddingBlock,
  277. paddingInline: `${e.anchorPaddingInline}px 0`,
  278. "&-title": N(N({}, Ae), {
  279. position: "relative",
  280. display: "block",
  281. marginBlockEnd: e.anchorTitleBlock,
  282. color: e.colorText,
  283. transition: `all ${e.motionDurationSlow}`,
  284. "&:only-child": {
  285. marginBlockEnd: 0
  286. }
  287. }),
  288. [`&-active > ${t}-link-title`]: {
  289. color: e.colorPrimary
  290. },
  291. // link link
  292. [`${t}-link`]: {
  293. paddingBlock: e.anchorPaddingBlockSecondary
  294. }
  295. }
  296. }),
  297. [`&:not(${t}-wrapper-horizontal)`]: {
  298. [t]: {
  299. "&::before": {
  300. position: "absolute",
  301. left: {
  302. _skip_check_: !0,
  303. value: 0
  304. },
  305. top: 0,
  306. height: "100%",
  307. borderInlineStart: `${i}px ${f} ${C}`,
  308. content: '" "'
  309. },
  310. [`${t}-ink`]: {
  311. position: "absolute",
  312. left: {
  313. _skip_check_: !0,
  314. value: 0
  315. },
  316. display: "none",
  317. transform: "translateY(-50%)",
  318. transition: `top ${r} ease-in-out`,
  319. width: i,
  320. backgroundColor: u,
  321. [`&${t}-ink-visible`]: {
  322. display: "inline-block"
  323. }
  324. }
  325. }
  326. },
  327. [`${t}-fixed ${t}-ink ${t}-ink`]: {
  328. display: "none"
  329. }
  330. }
  331. };
  332. }, We = (e) => {
  333. const {
  334. componentCls: t,
  335. motionDurationSlow: o,
  336. lineWidthBold: r,
  337. colorPrimary: i
  338. } = e;
  339. return {
  340. [`${t}-wrapper-horizontal`]: {
  341. position: "relative",
  342. "&::before": {
  343. position: "absolute",
  344. left: {
  345. _skip_check_: !0,
  346. value: 0
  347. },
  348. right: {
  349. _skip_check_: !0,
  350. value: 0
  351. },
  352. bottom: 0,
  353. borderBottom: `1px ${e.lineType} ${e.colorSplit}`,
  354. content: '" "'
  355. },
  356. [t]: {
  357. overflowX: "scroll",
  358. position: "relative",
  359. display: "flex",
  360. scrollbarWidth: "none",
  361. "&::-webkit-scrollbar": {
  362. display: "none"
  363. /* Safari and Chrome */
  364. },
  365. [`${t}-link:first-of-type`]: {
  366. paddingInline: 0
  367. },
  368. [`${t}-ink`]: {
  369. position: "absolute",
  370. bottom: 0,
  371. transition: `left ${o} ease-in-out, width ${o} ease-in-out`,
  372. height: r,
  373. backgroundColor: i
  374. }
  375. }
  376. }
  377. };
  378. }, qe = fe("Anchor", (e) => {
  379. const {
  380. fontSize: t,
  381. fontSizeLG: o,
  382. padding: r,
  383. paddingXXS: i
  384. } = e, u = ue(e, {
  385. holderOffsetBlock: i,
  386. anchorPaddingBlock: i,
  387. anchorPaddingBlockSecondary: i / 2,
  388. anchorPaddingInline: r,
  389. anchorTitleBlock: t / 14 * 3,
  390. anchorBallSize: o / 2
  391. });
  392. return [Ve(u), We(u)];
  393. }), Ge = () => ({
  394. prefixCls: String,
  395. href: String,
  396. title: Be(),
  397. target: String,
  398. /* private use */
  399. customTitleProps: Ie()
  400. }), pe = q({
  401. compatConfig: {
  402. MODE: 3
  403. },
  404. name: "AAnchorLink",
  405. inheritAttrs: !1,
  406. props: be(Ge(), {
  407. href: "#"
  408. }),
  409. slots: Object,
  410. setup(e, t) {
  411. let {
  412. slots: o,
  413. attrs: r
  414. } = t, i = null;
  415. const {
  416. handleClick: u,
  417. scrollTo: f,
  418. unregisterLink: C,
  419. registerLink: g,
  420. activeLink: I
  421. } = Ue(), {
  422. prefixCls: $
  423. } = X("anchor", e), S = (y) => {
  424. const {
  425. href: s
  426. } = e;
  427. u(y, {
  428. title: i,
  429. href: s
  430. }), f(s);
  431. };
  432. return V(() => e.href, (y, s) => {
  433. ae(() => {
  434. C(s), g(y);
  435. });
  436. }), G(() => {
  437. g(e.href);
  438. }), ce(() => {
  439. C(e.href);
  440. }), () => {
  441. var y;
  442. const {
  443. href: s,
  444. target: v,
  445. title: x = o.title,
  446. customTitleProps: E = {}
  447. } = e, b = $.value;
  448. i = typeof x == "function" ? x(E) : x;
  449. const L = I.value === s, a = D(`${b}-link`, {
  450. [`${b}-link-active`]: L
  451. }, r.class), d = D(`${b}-link-title`, {
  452. [`${b}-link-title-active`]: L
  453. });
  454. return w("div", z(z({}, r), {}, {
  455. class: a
  456. }), [w("a", {
  457. class: d,
  458. href: s,
  459. title: typeof i == "string" ? i : "",
  460. target: v,
  461. onClick: S
  462. }, [o.customTitle ? o.customTitle(E) : i]), (y = o.default) === null || y === void 0 ? void 0 : y.call(o)]);
  463. };
  464. }
  465. });
  466. function Xe() {
  467. return window;
  468. }
  469. function ie(e, t) {
  470. if (!e.getClientRects().length)
  471. return 0;
  472. const o = e.getBoundingClientRect();
  473. return o.width || o.height ? t === window ? (t = e.ownerDocument.documentElement, o.top - t.clientTop) : o.top - t.getBoundingClientRect().top : o.top;
  474. }
  475. const re = /#([\S ]+)$/, Ke = () => ({
  476. prefixCls: String,
  477. offsetTop: Number,
  478. bounds: Number,
  479. affix: {
  480. type: Boolean,
  481. default: !0
  482. },
  483. showInkInFixed: {
  484. type: Boolean,
  485. default: !1
  486. },
  487. getContainer: Function,
  488. wrapperClass: String,
  489. wrapperStyle: {
  490. type: Object,
  491. default: void 0
  492. },
  493. getCurrentAnchor: Function,
  494. targetOffset: Number,
  495. items: Pe(),
  496. direction: Ee.oneOf(["vertical", "horizontal"]).def("vertical"),
  497. onChange: Function,
  498. onClick: Function
  499. }), _ = q({
  500. compatConfig: {
  501. MODE: 3
  502. },
  503. name: "AAnchor",
  504. inheritAttrs: !1,
  505. props: Ke(),
  506. setup(e, t) {
  507. let {
  508. emit: o,
  509. attrs: r,
  510. slots: i,
  511. expose: u
  512. } = t;
  513. var f;
  514. const {
  515. prefixCls: C,
  516. getTargetContainer: g,
  517. direction: I
  518. } = X("anchor", e), $ = F(() => {
  519. var n;
  520. return (n = e.direction) !== null && n !== void 0 ? n : "vertical";
  521. });
  522. process.env.NODE_ENV !== "production" && Q(e.items && typeof i.default != "function", "Anchor", "`Anchor children` is deprecated. Please use `items` instead."), process.env.NODE_ENV !== "production" && Q(!($.value === "horizontal" && (!((f = e.items) === null || f === void 0) && f.some((n) => "children" in n))), "Anchor", "`Anchor items#children` is not supported when `Anchor` direction is horizontal.");
  523. const S = U(null), y = U(), s = le({
  524. links: [],
  525. scrollContainer: null,
  526. scrollEvent: null,
  527. animating: !1
  528. }), v = U(null), x = F(() => {
  529. const {
  530. getContainer: n
  531. } = e;
  532. return n || (g == null ? void 0 : g.value) || Xe;
  533. }), E = function() {
  534. let n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, l = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 5;
  535. const p = [], k = x.value();
  536. return s.links.forEach((c) => {
  537. const h = re.exec(c.toString());
  538. if (!h)
  539. return;
  540. const T = document.getElementById(h[1]);
  541. if (T) {
  542. const P = ie(T, k);
  543. P < n + l && p.push({
  544. link: c,
  545. top: P
  546. });
  547. }
  548. }), p.length ? p.reduce((h, T) => T.top > h.top ? T : h).link : "";
  549. }, b = (n) => {
  550. const {
  551. getCurrentAnchor: l
  552. } = e;
  553. v.value !== n && (v.value = typeof l == "function" ? l(n) : n, o("change", n));
  554. }, L = (n) => {
  555. const {
  556. offsetTop: l,
  557. targetOffset: p
  558. } = e;
  559. b(n);
  560. const k = re.exec(n);
  561. if (!k)
  562. return;
  563. const c = document.getElementById(k[1]);
  564. if (!c)
  565. return;
  566. const h = x.value(), T = Ne(h), P = ie(c, h);
  567. let O = T + P;
  568. O -= p !== void 0 ? p : l || 0, s.animating = !0, ze(O, {
  569. callback: () => {
  570. s.animating = !1;
  571. },
  572. getContainer: x.value
  573. });
  574. };
  575. u({
  576. scrollTo: L
  577. });
  578. const a = () => {
  579. if (s.animating)
  580. return;
  581. const {
  582. offsetTop: n,
  583. bounds: l,
  584. targetOffset: p
  585. } = e, k = E(p !== void 0 ? p : n || 0, l);
  586. b(k);
  587. }, d = () => {
  588. const n = y.value.querySelector(`.${C.value}-link-title-active`);
  589. if (n && S.value) {
  590. const l = $.value === "horizontal";
  591. S.value.style.top = l ? "" : `${n.offsetTop + n.clientHeight / 2}px`, S.value.style.height = l ? "" : `${n.clientHeight}px`, S.value.style.left = l ? `${n.offsetLeft}px` : "", S.value.style.width = l ? `${n.clientWidth}px` : "", l && Le(n, {
  592. scrollMode: "if-needed",
  593. block: "nearest"
  594. });
  595. }
  596. };
  597. je({
  598. registerLink: (n) => {
  599. s.links.includes(n) || s.links.push(n);
  600. },
  601. unregisterLink: (n) => {
  602. const l = s.links.indexOf(n);
  603. l !== -1 && s.links.splice(l, 1);
  604. },
  605. activeLink: v,
  606. scrollTo: L,
  607. handleClick: (n, l) => {
  608. o("click", n, l);
  609. },
  610. direction: $
  611. }), G(() => {
  612. ae(() => {
  613. const n = x.value();
  614. s.scrollContainer = n, s.scrollEvent = W(s.scrollContainer, "scroll", a), a();
  615. });
  616. }), ce(() => {
  617. s.scrollEvent && s.scrollEvent.remove();
  618. }), se(() => {
  619. if (s.scrollEvent) {
  620. const n = x.value();
  621. s.scrollContainer !== n && (s.scrollContainer = n, s.scrollEvent.remove(), s.scrollEvent = W(s.scrollContainer, "scroll", a), a());
  622. }
  623. d();
  624. });
  625. const A = (n) => Array.isArray(n) ? n.map((l) => {
  626. const {
  627. children: p,
  628. key: k,
  629. href: c,
  630. target: h,
  631. class: T,
  632. style: P,
  633. title: O
  634. } = l;
  635. return w(pe, {
  636. key: k,
  637. href: c,
  638. target: h,
  639. class: T,
  640. style: P,
  641. title: O,
  642. customTitleProps: l
  643. }, {
  644. default: () => [$.value === "vertical" ? A(p) : null],
  645. customTitle: i.customTitle
  646. });
  647. }) : null, [B, m] = qe(C);
  648. return () => {
  649. var n;
  650. const {
  651. offsetTop: l,
  652. affix: p,
  653. showInkInFixed: k
  654. } = e, c = C.value, h = D(`${c}-ink`, {
  655. [`${c}-ink-visible`]: v.value
  656. }), T = D(m.value, e.wrapperClass, `${c}-wrapper`, {
  657. [`${c}-wrapper-horizontal`]: $.value === "horizontal",
  658. [`${c}-rtl`]: I.value === "rtl"
  659. }), P = D(c, {
  660. [`${c}-fixed`]: !p && !k
  661. }), O = N({
  662. maxHeight: l ? `calc(100vh - ${l}px)` : "100vh"
  663. }, e.wrapperStyle), K = w("div", {
  664. class: T,
  665. style: O,
  666. ref: y
  667. }, [w("div", {
  668. class: P
  669. }, [w("span", {
  670. class: h,
  671. ref: S
  672. }, null), Array.isArray(e.items) ? A(e.items) : (n = i.default) === null || n === void 0 ? void 0 : n.call(i)])]);
  673. return B(p ? w(Me, z(z({}, r), {}, {
  674. offsetTop: l,
  675. target: x.value
  676. }), {
  677. default: () => [K]
  678. }) : K);
  679. };
  680. }
  681. });
  682. _.Link = pe;
  683. _.install = function(e) {
  684. return e.component(_.name, _), e.component(_.Link.name, _.Link), e;
  685. };
  686. const Ye = {
  687. name: "SAnchor",
  688. data() {
  689. return {
  690. anchors: []
  691. };
  692. },
  693. methods: {
  694. /** 锚点 */
  695. getItemAnchor() {
  696. const e = document.querySelectorAll(
  697. ".s-collapses .s-collapses-item .s-collapses-item-title"
  698. );
  699. e.length > 0 && e.forEach((t) => {
  700. this.anchors.push({
  701. el: t,
  702. key: t.id,
  703. href: `#${t.id}`,
  704. title: t.firstChild.innerText
  705. });
  706. });
  707. },
  708. initRightNav() {
  709. this.getItemAnchor();
  710. let e = setTimeout(() => {
  711. this.anchors = [], this.getItemAnchor(), clearTimeout(e), e = null;
  712. }, 500);
  713. },
  714. handleAnchorClick(e, t) {
  715. var r;
  716. e.preventDefault();
  717. const o = this.anchors.find((i) => i.href === t.href);
  718. this.anchorId = o.href, (r = o == null ? void 0 : o.el) == null || r.scrollIntoView({ block: "start", behavior: "smooth" });
  719. },
  720. formatName(e) {
  721. const t = (e + "").trim();
  722. return t && t.length > 8 ? t.slice(0, 8) + "..." : t;
  723. },
  724. getContainer() {
  725. return document.getElementById("form-container");
  726. }
  727. },
  728. mounted() {
  729. this.$nextTick(() => {
  730. this.initRightNav();
  731. });
  732. }
  733. };
  734. function Je(e, t, o, r, i, u) {
  735. const f = _;
  736. return ke(), ye(f, {
  737. affix: !1,
  738. showInkInFixed: "",
  739. targetOffset: 10,
  740. getContainer: u.getContainer,
  741. onClick: u.handleAnchorClick,
  742. items: i.anchors
  743. }, null, 8, ["getContainer", "onClick", "items"]);
  744. }
  745. const tt = /* @__PURE__ */ _e(Ye, [["render", Je]]);
  746. export {
  747. tt as default
  748. };