valaxy 0.18.8 → 0.18.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,7 +44,7 @@ useVanillaLazyLoad()
44
44
  </script>
45
45
 
46
46
  <template>
47
- <article v-if="$slots.default" :class="frontmatter.markdown !== false && 'markdown-body'">
47
+ <article v-if="$slots.default" :class="frontmatter.markdownClass || 'markdown-body'">
48
48
  <slot ref="contentRef" @vue:updated="runContentUpdated" />
49
49
 
50
50
  <div v-if="frontmatter.url" text="center">
@@ -1,3 +1,5 @@
1
+ import type { Router } from 'vue-router'
2
+
1
3
  export interface ScrollToOptions {
2
4
  /**
3
5
  * 平滑滚动
@@ -43,3 +45,49 @@ export function scrollTo(el: HTMLElement, hash: string, options: Partial<ScrollT
43
45
  }
44
46
  }
45
47
  }
48
+
49
+ /**
50
+ * @description Intercept click events and handle offset positions for jump links on the same page
51
+ * @description:zh-CN 拦截点击事件,处理同一页面下跳转链接的偏移位置
52
+ * @param router Vue Router
53
+ */
54
+ export function onClickHref(router: Router) {
55
+ // to extract
56
+ // click title scroll
57
+ window.addEventListener(
58
+ 'click',
59
+ async (e) => {
60
+ const link = (e.target as Element).closest('a')
61
+ if (link) {
62
+ const { protocol, hostname, pathname, hash, target } = link
63
+ const currentUrl = window.location
64
+ const extMatch = pathname.match(/\.\w+$/)
65
+ // only intercept inbound links
66
+ if (
67
+ !e.ctrlKey
68
+ && !e.shiftKey
69
+ && !e.altKey
70
+ && !e.metaKey
71
+ && target !== '_blank'
72
+ && protocol === currentUrl.protocol
73
+ && hostname === currentUrl.hostname
74
+ && !(extMatch && extMatch[0] !== '.html')
75
+ ) {
76
+ if (pathname === currentUrl.pathname) {
77
+ e.preventDefault()
78
+ // scroll between hash anchors in the same page
79
+ if (hash && hash !== currentUrl.hash) {
80
+ await router.push({ hash: decodeURIComponent(hash) })
81
+
82
+ // use smooth scroll when clicking on header anchor links
83
+ scrollTo(link, hash, {
84
+ smooth: link.classList.contains('header-anchor'),
85
+ })
86
+ }
87
+ }
88
+ }
89
+ }
90
+ },
91
+ { capture: true },
92
+ )
93
+ }