SAnchor.js 19 KB

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