valaxy-theme-yun 0.14.57 → 0.14.58
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.
- package/components/ValaxyMain.vue +57 -2
- package/components/YunFireworks.vue +2 -1
- package/package.json +2 -2
- package/utils/index.ts +32 -0
@@ -1,8 +1,10 @@
|
|
1
1
|
<script lang="ts" setup>
|
2
|
+
import { computed, nextTick } from 'vue'
|
2
3
|
import type { PageData, Post } from 'valaxy'
|
3
|
-
import { usePostTitle, useSiteConfig } from 'valaxy'
|
4
|
+
import { onContentUpdated, usePostTitle, useSiteConfig } from 'valaxy'
|
4
5
|
import type { StyleValue } from 'vue'
|
5
|
-
import {
|
6
|
+
import { useRoute, useRouter } from 'vue-router'
|
7
|
+
import { scrollTo } from '../utils'
|
6
8
|
import { usePostProperty } from '../composables'
|
7
9
|
|
8
10
|
const props = defineProps<{
|
@@ -16,6 +18,59 @@ const { styles, icon, color } = usePostProperty(props.frontmatter.type)
|
|
16
18
|
const title = usePostTitle(computed(() => props.frontmatter))
|
17
19
|
|
18
20
|
const aside = computed(() => props.frontmatter.aside !== false)
|
21
|
+
|
22
|
+
const route = useRoute()
|
23
|
+
const router = useRouter()
|
24
|
+
|
25
|
+
nextTick(() => {
|
26
|
+
if (route.hash) {
|
27
|
+
setTimeout(() => {
|
28
|
+
scrollTo(document.body, route.hash, true)
|
29
|
+
}, 0)
|
30
|
+
}
|
31
|
+
})
|
32
|
+
|
33
|
+
onContentUpdated(() => {
|
34
|
+
// to extract
|
35
|
+
// click title scroll
|
36
|
+
window.addEventListener(
|
37
|
+
'click',
|
38
|
+
async (e) => {
|
39
|
+
const link = (e.target as Element).closest('a')
|
40
|
+
if (link) {
|
41
|
+
const { protocol, hostname, pathname, hash, target } = link
|
42
|
+
const currentUrl = window.location
|
43
|
+
const extMatch = pathname.match(/\.\w+$/)
|
44
|
+
// only intercept inbound links
|
45
|
+
if (
|
46
|
+
!e.ctrlKey
|
47
|
+
&& !e.shiftKey
|
48
|
+
&& !e.altKey
|
49
|
+
&& !e.metaKey
|
50
|
+
&& target !== '_blank'
|
51
|
+
&& protocol === currentUrl.protocol
|
52
|
+
&& hostname === currentUrl.hostname
|
53
|
+
&& !(extMatch && extMatch[0] !== '.html')
|
54
|
+
) {
|
55
|
+
if (pathname === currentUrl.pathname) {
|
56
|
+
e.preventDefault()
|
57
|
+
// scroll between hash anchors in the same page
|
58
|
+
if (hash && hash !== currentUrl.hash) {
|
59
|
+
await router.push({ hash })
|
60
|
+
history.replaceState({ ...history.state }, '')
|
61
|
+
|
62
|
+
// still emit the event so we can listen to it in themes
|
63
|
+
window.dispatchEvent(new Event('hashchange'))
|
64
|
+
// use smooth scroll when clicking on header anchor links
|
65
|
+
scrollTo(link, hash, link.classList.contains('header-anchor'))
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
},
|
71
|
+
{ capture: true },
|
72
|
+
)
|
73
|
+
})
|
19
74
|
</script>
|
20
75
|
|
21
76
|
<template>
|
@@ -2,8 +2,9 @@
|
|
2
2
|
import { useThemeConfig } from 'valaxy'
|
3
3
|
import { onMounted } from 'vue'
|
4
4
|
import { createFireworks } from '@explosions/fireworks'
|
5
|
+
import type { YunTheme } from '../types'
|
5
6
|
|
6
|
-
const themeConfig = useThemeConfig()
|
7
|
+
const themeConfig = useThemeConfig<YunTheme.Config>()
|
7
8
|
|
8
9
|
onMounted(() => {
|
9
10
|
createFireworks({
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "valaxy-theme-yun",
|
3
|
-
"version": "0.14.
|
3
|
+
"version": "0.14.58",
|
4
4
|
"author": {
|
5
5
|
"email": "me@yunyoujun.cn",
|
6
6
|
"name": "YunYouJun",
|
@@ -24,7 +24,7 @@
|
|
24
24
|
},
|
25
25
|
"devDependencies": {
|
26
26
|
"@types/animejs": "^3.1.7",
|
27
|
-
"valaxy": "0.14.
|
27
|
+
"valaxy": "0.14.58",
|
28
28
|
"valaxy-addon-waline": "0.1.0"
|
29
29
|
}
|
30
30
|
}
|
package/utils/index.ts
CHANGED
@@ -9,3 +9,35 @@ export function onImgError(e: Event, defaultImg = anonymousImage) {
|
|
9
9
|
targetEl.setAttribute('data-src', targetEl.src)
|
10
10
|
targetEl.src = defaultImg
|
11
11
|
}
|
12
|
+
|
13
|
+
export function scrollTo(el: HTMLElement, hash: string, smooth = false) {
|
14
|
+
let target: Element | null = null
|
15
|
+
try {
|
16
|
+
target = el.classList.contains('header-anchor')
|
17
|
+
? el
|
18
|
+
: ((decodeURIComponent(hash) && document.querySelector(decodeURIComponent(hash))) || null)
|
19
|
+
}
|
20
|
+
catch (e) {
|
21
|
+
console.warn(e)
|
22
|
+
}
|
23
|
+
|
24
|
+
if (target) {
|
25
|
+
const targetPadding = -64
|
26
|
+
const targetTop
|
27
|
+
= window.scrollY
|
28
|
+
+ (target as HTMLElement).getBoundingClientRect().top
|
29
|
+
+ targetPadding
|
30
|
+
|
31
|
+
// only smooth scroll if distance is smaller than screen height.
|
32
|
+
if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) {
|
33
|
+
window.scrollTo(0, targetTop)
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
window.scrollTo({
|
37
|
+
// left: 0,
|
38
|
+
top: targetTop,
|
39
|
+
behavior: 'smooth',
|
40
|
+
})
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|