md2ui 1.0.0
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/README.md +230 -0
- package/bin/md2ui.js +168 -0
- package/index.html +14 -0
- package/package.json +46 -0
- package/public/README.md +106 -0
- package/public/docs/00-/345/277/253/351/200/237/345/274/200/345/247/213.md +51 -0
- package/public/docs/01-/345/212/237/350/203/275/347/211/271/346/200/247.md +57 -0
- package/public/docs/02-Mermaid/345/233/276/350/241/250.md +102 -0
- package/public/docs/03-/350/277/233/351/230/266/346/214/207/345/215/227/01-/347/233/256/345/275/225/347/273/223/346/236/204.md +55 -0
- package/public/docs/03-/350/277/233/351/230/266/346/214/207/345/215/227/02-/350/207/252/345/256/232/344/271/211/351/205/215/347/275/256.md +63 -0
- package/public/docs/03-/350/277/233/351/230/266/346/214/207/345/215/227/03-/351/203/250/347/275/262/346/226/271/346/241/210.md +73 -0
- package/public/docs/04-API/345/217/202/350/200/203/01-/347/273/204/344/273/266API.md +80 -0
- package/public/docs/04-API/345/217/202/350/200/203/02-Composables.md +92 -0
- package/public/logo.svg +6 -0
- package/src/App.vue +171 -0
- package/src/api/docs.js +103 -0
- package/src/components/ImageZoom.vue +285 -0
- package/src/components/Logo.vue +44 -0
- package/src/components/TableOfContents.vue +44 -0
- package/src/components/TreeNode.vue +61 -0
- package/src/composables/useMarkdown.js +128 -0
- package/src/composables/useResize.js +50 -0
- package/src/composables/useScroll.js +77 -0
- package/src/main.js +5 -0
- package/src/style.css +784 -0
- package/vite.config.js +9 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export function useScroll() {
|
|
4
|
+
const scrollProgress = ref(0)
|
|
5
|
+
const showBackToTop = ref(false)
|
|
6
|
+
const activeHeading = ref('')
|
|
7
|
+
|
|
8
|
+
// 监听滚动
|
|
9
|
+
function handleScroll(e) {
|
|
10
|
+
const element = e.target
|
|
11
|
+
const scrollTop = element.scrollTop
|
|
12
|
+
const scrollHeight = element.scrollHeight - element.clientHeight
|
|
13
|
+
|
|
14
|
+
if (scrollHeight > 0) {
|
|
15
|
+
scrollProgress.value = Math.round((scrollTop / scrollHeight) * 100)
|
|
16
|
+
showBackToTop.value = scrollTop > 300
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
updateActiveHeading()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 更新当前激活的标题
|
|
23
|
+
function updateActiveHeading() {
|
|
24
|
+
const content = document.querySelector('.content')
|
|
25
|
+
if (!content) return
|
|
26
|
+
|
|
27
|
+
const headings = document.querySelectorAll('.markdown-content h1, .markdown-content h2, .markdown-content h3, .markdown-content h4, .markdown-content h5, .markdown-content h6')
|
|
28
|
+
const scrollTop = content.scrollTop
|
|
29
|
+
|
|
30
|
+
let currentId = ''
|
|
31
|
+
headings.forEach(heading => {
|
|
32
|
+
const rect = heading.getBoundingClientRect()
|
|
33
|
+
const contentRect = content.getBoundingClientRect()
|
|
34
|
+
const offsetTop = rect.top - contentRect.top + scrollTop
|
|
35
|
+
|
|
36
|
+
if (offsetTop <= scrollTop + 100) {
|
|
37
|
+
currentId = heading.id
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
activeHeading.value = currentId
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 滚动到指定标题
|
|
45
|
+
function scrollToHeading(id) {
|
|
46
|
+
const element = document.getElementById(id)
|
|
47
|
+
const content = document.querySelector('.content')
|
|
48
|
+
|
|
49
|
+
if (element && content) {
|
|
50
|
+
const contentRect = content.getBoundingClientRect()
|
|
51
|
+
const elementRect = element.getBoundingClientRect()
|
|
52
|
+
const offsetTop = elementRect.top - contentRect.top + content.scrollTop
|
|
53
|
+
|
|
54
|
+
content.scrollTo({
|
|
55
|
+
top: offsetTop - 20,
|
|
56
|
+
behavior: 'smooth'
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 返回顶部
|
|
62
|
+
function scrollToTop() {
|
|
63
|
+
const content = document.querySelector('.content')
|
|
64
|
+
if (content) {
|
|
65
|
+
content.scrollTo({ top: 0, behavior: 'smooth' })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
scrollProgress,
|
|
71
|
+
showBackToTop,
|
|
72
|
+
activeHeading,
|
|
73
|
+
handleScroll,
|
|
74
|
+
scrollToHeading,
|
|
75
|
+
scrollToTop
|
|
76
|
+
}
|
|
77
|
+
}
|