vitepress-theme-element-plus 1.3.1 → 1.3.2

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.
Files changed (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +3 -3
  3. package/client/components/A11yTag.vue +29 -29
  4. package/client/components/ApiTyping.vue +54 -54
  5. package/client/components/Backdrop.vue +41 -41
  6. package/client/components/Bili.vue +94 -94
  7. package/client/components/Content.vue +148 -148
  8. package/client/components/DeprecatedTag.vue +19 -19
  9. package/client/components/Doc.vue +185 -185
  10. package/client/components/DocAside.vue +46 -46
  11. package/client/components/DocAsideOutline.vue +145 -145
  12. package/client/components/DocFooter.vue +162 -162
  13. package/client/components/Footer.vue +100 -100
  14. package/client/components/FooterCopyright.vue +27 -27
  15. package/client/components/Layout.vue +156 -156
  16. package/client/components/Link.vue +41 -41
  17. package/client/components/LocalNav.vue +160 -160
  18. package/client/components/Nav.vue +69 -69
  19. package/client/components/NavBar.vue +203 -203
  20. package/client/components/NavBarTitle.vue +89 -89
  21. package/client/components/Sidebar.vue +129 -129
  22. package/client/components/SidebarGroup.vue +51 -51
  23. package/client/components/SidebarItem.vue +304 -304
  24. package/client/components/ThemeToggler.vue +129 -129
  25. package/client/components/VPNavBarSearch.vue +23 -23
  26. package/client/hooks/useBackTop.ts +71 -71
  27. package/client/hooks/useLangs.ts +50 -50
  28. package/client/hooks/useSidebarControl.ts +78 -78
  29. package/client/hooks/useSize.ts +69 -69
  30. package/client/icons/dark.vue +8 -8
  31. package/client/icons/light.vue +8 -8
  32. package/client/utils/client/common.ts +49 -49
  33. package/client/utils/client/outline.ts +116 -116
  34. package/client/utils/common.ts +90 -90
  35. package/index.ts +45 -45
  36. package/package.json +2 -2
  37. package/shared/constants.ts +3 -3
  38. package/styles/base.scss +105 -105
  39. package/styles/code.scss +290 -290
  40. package/styles/doc-content.scss +363 -363
  41. package/styles/index.scss +71 -71
  42. package/styles/tag-content.scss +30 -30
@@ -1,129 +1,129 @@
1
- <script setup lang="ts">
2
- import type { SwitchInstance } from 'element-plus'
3
- import { ElSwitch } from 'element-plus'
4
- import { useData } from 'vitepress/client'
5
- import { nextTick, ref } from 'vue'
6
- import DarkIcon from '../icons/dark.vue'
7
- import LightIcon from '../icons/light.vue'
8
-
9
- const { site, isDark } = useData()
10
- const switchRef = ref<SwitchInstance>()
11
-
12
- function handleChange(value: boolean) {
13
- if (isDark.value !== value)
14
- isDark.value = value
15
- }
16
-
17
- function beforeChange() {
18
- return new Promise<boolean>((resolve) => {
19
- const isAppearanceTransition = document.startViewTransition && !window.matchMedia('(prefers-reduced-motion: reduce)').matches
20
- if (!isAppearanceTransition) {
21
- resolve(true)
22
- return
23
- }
24
-
25
- const switchElement = switchRef.value?.$el
26
- const rect = switchElement.getBoundingClientRect()
27
- const x = rect.left + rect.width / 2
28
- const y = rect.top + rect.height / 2
29
-
30
- const endRadius = Math.hypot(
31
- Math.max(x, innerWidth - x),
32
- Math.max(y, innerHeight - y),
33
- )
34
-
35
- const ratioX = (100 * x) / innerWidth
36
- const ratioY = (100 * y) / innerHeight
37
- const referR = Math.hypot(innerWidth, innerHeight) / Math.SQRT2
38
- const ratioR = (100 * endRadius) / referR
39
-
40
- const transition = document.startViewTransition(async () => {
41
- resolve(true)
42
- await nextTick()
43
- })
44
- transition.ready.then(() => {
45
- const clipPath = [
46
- `circle(0% at ${ratioX}% ${ratioY}%)`,
47
- `circle(${ratioR}% at ${ratioX}% ${ratioY}%)`,
48
- ]
49
- document.documentElement.animate(
50
- {
51
- clipPath: isDark.value ? [...clipPath].reverse() : clipPath,
52
- },
53
- {
54
- duration: 400,
55
- easing: 'ease-in',
56
- fill: 'both',
57
- pseudoElement: isDark.value
58
- ? '::view-transition-old(root)'
59
- : '::view-transition-new(root)',
60
- },
61
- )
62
- })
63
- })
64
- }
65
- </script>
66
-
67
- <template>
68
- <div class="VPNavBarAppearance">
69
- <ClientOnly>
70
- <ElSwitch
71
- v-if="
72
- site.appearance
73
- && site.appearance !== 'force-dark'
74
- && site.appearance !== 'force-auto'
75
- "
76
- ref="switchRef"
77
- :model-value="isDark"
78
- v-bind="$attrs"
79
- :before-change="beforeChange"
80
- :active-action-icon="DarkIcon"
81
- :inactive-action-icon="LightIcon"
82
- @change="handleChange"
83
- />
84
- </ClientOnly>
85
- </div>
86
- </template>
87
-
88
- <style lang="scss" scoped>
89
- .button {
90
- display: flex;
91
- align-items: center;
92
- padding: 0 12px;
93
- height: var(--vp-nav-height);
94
- color: var(--vp-c-text-1);
95
- transition: color 0.5s;
96
- }
97
-
98
- :deep(.el-switch__core) {
99
- --el-switch-on-color: var(--bg-color-mute);
100
- --el-switch-off-color: var(--bg-color-mute);
101
- --el-switch-border-color: var(--border-color);
102
-
103
- .el-switch__action {
104
- width: 14px;
105
- height: 14px;
106
- }
107
- }
108
-
109
- :deep(.dark-icon) {
110
- border-radius: 50%;
111
- color: #cfd3dc;
112
- background-color: #141414;
113
- }
114
-
115
- :deep(.light-icon) {
116
- color: #606266;
117
- }
118
-
119
- .VPNavBarAppearance {
120
- display: none;
121
- }
122
-
123
- @media (min-width: 1280px) {
124
- .VPNavBarAppearance {
125
- display: flex;
126
- align-items: center;
127
- }
128
- }
129
- </style>
1
+ <script setup lang="ts">
2
+ import type { SwitchInstance } from 'element-plus'
3
+ import { ElSwitch } from 'element-plus'
4
+ import { useData } from 'vitepress/client'
5
+ import { nextTick, ref } from 'vue'
6
+ import DarkIcon from '../icons/dark.vue'
7
+ import LightIcon from '../icons/light.vue'
8
+
9
+ const { site, isDark } = useData()
10
+ const switchRef = ref<SwitchInstance>()
11
+
12
+ function handleChange(value: boolean) {
13
+ if (isDark.value !== value)
14
+ isDark.value = value
15
+ }
16
+
17
+ function beforeChange() {
18
+ return new Promise<boolean>((resolve) => {
19
+ const isAppearanceTransition = document.startViewTransition && !window.matchMedia('(prefers-reduced-motion: reduce)').matches
20
+ if (!isAppearanceTransition) {
21
+ resolve(true)
22
+ return
23
+ }
24
+
25
+ const switchElement = switchRef.value?.$el
26
+ const rect = switchElement.getBoundingClientRect()
27
+ const x = rect.left + rect.width / 2
28
+ const y = rect.top + rect.height / 2
29
+
30
+ const endRadius = Math.hypot(
31
+ Math.max(x, innerWidth - x),
32
+ Math.max(y, innerHeight - y),
33
+ )
34
+
35
+ const ratioX = (100 * x) / innerWidth
36
+ const ratioY = (100 * y) / innerHeight
37
+ const referR = Math.hypot(innerWidth, innerHeight) / Math.SQRT2
38
+ const ratioR = (100 * endRadius) / referR
39
+
40
+ const transition = document.startViewTransition(async () => {
41
+ resolve(true)
42
+ await nextTick()
43
+ })
44
+ transition.ready.then(() => {
45
+ const clipPath = [
46
+ `circle(0% at ${ratioX}% ${ratioY}%)`,
47
+ `circle(${ratioR}% at ${ratioX}% ${ratioY}%)`,
48
+ ]
49
+ document.documentElement.animate(
50
+ {
51
+ clipPath: isDark.value ? [...clipPath].reverse() : clipPath,
52
+ },
53
+ {
54
+ duration: 400,
55
+ easing: 'ease-in',
56
+ fill: 'both',
57
+ pseudoElement: isDark.value
58
+ ? '::view-transition-old(root)'
59
+ : '::view-transition-new(root)',
60
+ },
61
+ )
62
+ })
63
+ })
64
+ }
65
+ </script>
66
+
67
+ <template>
68
+ <div class="VPNavBarAppearance">
69
+ <ClientOnly>
70
+ <ElSwitch
71
+ v-if="
72
+ site.appearance
73
+ && site.appearance !== 'force-dark'
74
+ && site.appearance !== 'force-auto'
75
+ "
76
+ ref="switchRef"
77
+ :model-value="isDark"
78
+ v-bind="$attrs"
79
+ :before-change="beforeChange"
80
+ :active-action-icon="DarkIcon"
81
+ :inactive-action-icon="LightIcon"
82
+ @change="handleChange"
83
+ />
84
+ </ClientOnly>
85
+ </div>
86
+ </template>
87
+
88
+ <style lang="scss" scoped>
89
+ .button {
90
+ display: flex;
91
+ align-items: center;
92
+ padding: 0 12px;
93
+ height: var(--vp-nav-height);
94
+ color: var(--vp-c-text-1);
95
+ transition: color 0.5s;
96
+ }
97
+
98
+ :deep(.el-switch__core) {
99
+ --el-switch-on-color: var(--bg-color-mute);
100
+ --el-switch-off-color: var(--bg-color-mute);
101
+ --el-switch-border-color: var(--border-color);
102
+
103
+ .el-switch__action {
104
+ width: 14px;
105
+ height: 14px;
106
+ }
107
+ }
108
+
109
+ :deep(.dark-icon) {
110
+ border-radius: 50%;
111
+ color: #cfd3dc;
112
+ background-color: #141414;
113
+ }
114
+
115
+ :deep(.light-icon) {
116
+ color: #606266;
117
+ }
118
+
119
+ .VPNavBarAppearance {
120
+ display: none;
121
+ }
122
+
123
+ @media (min-width: 1280px) {
124
+ .VPNavBarAppearance {
125
+ display: flex;
126
+ align-items: center;
127
+ }
128
+ }
129
+ </style>
@@ -1,23 +1,23 @@
1
- <script lang="ts" setup>
2
- import VPNavBarSearch from 'vitepress/dist/client/theme-default/components/VPNavBarSearch.vue'
3
- // compatible with vitepress-plugin-pagefind
4
- </script>
5
-
6
- <template>
7
- <VPNavBarSearch />
8
- </template>
9
-
10
- <style>
11
- @media (min-width: 768px) {
12
- .VPNavBarSearch.VPNavBarSearch {
13
- flex-grow: unset;
14
- padding-right: 24px;
15
- }
16
- }
17
-
18
- @media (min-width: 960px) {
19
- .VPNavBarSearch.VPNavBarSearch {
20
- padding-right: 32px;
21
- }
22
- }
23
- </style>
1
+ <script lang="ts" setup>
2
+ import VPNavBarSearch from 'vitepress/dist/client/theme-default/components/VPNavBarSearch.vue'
3
+ // compatible with vitepress-plugin-pagefind
4
+ </script>
5
+
6
+ <template>
7
+ <VPNavBarSearch />
8
+ </template>
9
+
10
+ <style>
11
+ @media (min-width: 768px) {
12
+ .VPNavBarSearch.VPNavBarSearch {
13
+ flex-grow: unset;
14
+ padding-right: 24px;
15
+ }
16
+ }
17
+
18
+ @media (min-width: 960px) {
19
+ .VPNavBarSearch.VPNavBarSearch {
20
+ padding-right: 32px;
21
+ }
22
+ }
23
+ </style>
@@ -1,74 +1,74 @@
1
1
  import { isClient } from '@vueuse/core'
2
2
  import { onBeforeUnmount, onMounted, ref } from 'vue'
3
3
  import { throttle } from '../utils/throttle'
4
-
5
- const threshold = 960
6
-
7
- const cubic = (value: number): number => value ** 3
8
- function easeInOutCubic(value: number): number {
9
- return value < 0.5 ? cubic(value * 2) / 2 : 1 - cubic((1 - value) * 2) / 2
10
- }
11
-
12
- export function useBackTop(offset = 200) {
13
- const shouldShow = ref(false)
14
- const throttleResize = throttle(onResize, 300)
15
- const throttleScroll = throttle(onScroll, 160)
16
-
17
- onMounted(() => {
18
- if (!isClient)
19
- return
20
- onResize()
21
- onScroll()
22
- window.addEventListener('resize', throttleResize)
23
- })
24
-
25
- onBeforeUnmount(() => {
26
- if (!isClient)
27
- return
28
- window.removeEventListener('resize', throttleResize)
29
- window.removeEventListener('scroll', throttleScroll)
30
- })
31
-
32
- const scrollToTop = () => {
33
- const beginTime = Date.now()
34
- const beginValue = document.documentElement.scrollTop
35
- const rAF = window.requestAnimationFrame
36
- const frameFunc = () => {
37
- const progress = (Date.now() - beginTime) / 500
38
- if (progress < 1) {
39
- document.documentElement.scrollTop
40
- = beginValue * (1 - easeInOutCubic(progress))
41
- rAF(frameFunc)
42
- }
43
- else {
44
- document.documentElement.scrollTop = 0
45
- }
46
- }
47
- rAF(frameFunc)
48
- }
49
-
50
- function onResize() {
51
- if (!isClient)
52
- return
53
-
54
- const { clientWidth } = document.body
55
-
56
- if (clientWidth < threshold) {
57
- window.addEventListener('scroll', throttleScroll)
58
- }
59
- else {
60
- window.removeEventListener('scroll', throttleScroll)
61
- }
62
- }
63
-
64
- function onScroll() {
65
- if (!isClient)
66
- return
67
- shouldShow.value = document.documentElement.scrollTop > offset
68
- }
69
-
70
- return {
71
- shouldShow,
72
- scrollToTop,
73
- }
74
- }
4
+
5
+ const threshold = 960
6
+
7
+ const cubic = (value: number): number => value ** 3
8
+ function easeInOutCubic(value: number): number {
9
+ return value < 0.5 ? cubic(value * 2) / 2 : 1 - cubic((1 - value) * 2) / 2
10
+ }
11
+
12
+ export function useBackTop(offset = 200) {
13
+ const shouldShow = ref(false)
14
+ const throttleResize = throttle(onResize, 300)
15
+ const throttleScroll = throttle(onScroll, 160)
16
+
17
+ onMounted(() => {
18
+ if (!isClient)
19
+ return
20
+ onResize()
21
+ onScroll()
22
+ window.addEventListener('resize', throttleResize)
23
+ })
24
+
25
+ onBeforeUnmount(() => {
26
+ if (!isClient)
27
+ return
28
+ window.removeEventListener('resize', throttleResize)
29
+ window.removeEventListener('scroll', throttleScroll)
30
+ })
31
+
32
+ const scrollToTop = () => {
33
+ const beginTime = Date.now()
34
+ const beginValue = document.documentElement.scrollTop
35
+ const rAF = window.requestAnimationFrame
36
+ const frameFunc = () => {
37
+ const progress = (Date.now() - beginTime) / 500
38
+ if (progress < 1) {
39
+ document.documentElement.scrollTop
40
+ = beginValue * (1 - easeInOutCubic(progress))
41
+ rAF(frameFunc)
42
+ }
43
+ else {
44
+ document.documentElement.scrollTop = 0
45
+ }
46
+ }
47
+ rAF(frameFunc)
48
+ }
49
+
50
+ function onResize() {
51
+ if (!isClient)
52
+ return
53
+
54
+ const { clientWidth } = document.body
55
+
56
+ if (clientWidth < threshold) {
57
+ window.addEventListener('scroll', throttleScroll)
58
+ }
59
+ else {
60
+ window.removeEventListener('scroll', throttleScroll)
61
+ }
62
+ }
63
+
64
+ function onScroll() {
65
+ if (!isClient)
66
+ return
67
+ shouldShow.value = document.documentElement.scrollTop > offset
68
+ }
69
+
70
+ return {
71
+ shouldShow,
72
+ scrollToTop,
73
+ }
74
+ }
@@ -1,50 +1,50 @@
1
- import { useData } from 'vitepress'
2
- import { computed } from 'vue'
3
- import { ensureStartingSlash } from '../utils/common'
4
-
5
- export function useLangs({ correspondingLink = false } = {}) {
6
- const { site, localeIndex, page, theme, hash } = useData()
7
- const currentLang = computed(() => ({
8
- label: site.value.locales[localeIndex.value]?.label,
9
- link:
10
- site.value.locales[localeIndex.value]?.link
11
- || (localeIndex.value === 'root' ? '/' : `/${localeIndex.value}/`),
12
- }))
13
-
14
- const localeLinks = computed(() =>
15
- Object.entries(site.value.locales).flatMap(([key, value]) =>
16
- currentLang.value.label === value.label
17
- ? []
18
- : {
19
- text: value.label,
20
- link:
21
- normalizeLink(
22
- value.link || (key === 'root' ? '/' : `/${key}/`),
23
- theme.value.i18nRouting !== false && correspondingLink,
24
- page.value.relativePath.slice(
25
- currentLang.value.link.length - 1,
26
- ),
27
- !site.value.cleanUrls,
28
- ) + hash.value,
29
- },
30
- ),
31
- )
32
-
33
- return { localeLinks, currentLang }
34
- }
35
-
36
- function normalizeLink(
37
- link: string,
38
- addPath: boolean,
39
- path: string,
40
- addExt: boolean,
41
- ) {
42
- return addPath
43
- ? link.replace(/\/$/, '')
44
- + ensureStartingSlash(
45
- path
46
- .replace(/(^|\/)index\.md$/, '$1')
47
- .replace(/\.md$/, addExt ? '.html' : ''),
48
- )
49
- : link
50
- }
1
+ import { useData } from 'vitepress'
2
+ import { computed } from 'vue'
3
+ import { ensureStartingSlash } from '../utils/common'
4
+
5
+ export function useLangs({ correspondingLink = false } = {}) {
6
+ const { site, localeIndex, page, theme, hash } = useData()
7
+ const currentLang = computed(() => ({
8
+ label: site.value.locales[localeIndex.value]?.label,
9
+ link:
10
+ site.value.locales[localeIndex.value]?.link
11
+ || (localeIndex.value === 'root' ? '/' : `/${localeIndex.value}/`),
12
+ }))
13
+
14
+ const localeLinks = computed(() =>
15
+ Object.entries(site.value.locales).flatMap(([key, value]) =>
16
+ currentLang.value.label === value.label
17
+ ? []
18
+ : {
19
+ text: value.label,
20
+ link:
21
+ normalizeLink(
22
+ value.link || (key === 'root' ? '/' : `/${key}/`),
23
+ theme.value.i18nRouting !== false && correspondingLink,
24
+ page.value.relativePath.slice(
25
+ currentLang.value.link.length - 1,
26
+ ),
27
+ !site.value.cleanUrls,
28
+ ) + hash.value,
29
+ },
30
+ ),
31
+ )
32
+
33
+ return { localeLinks, currentLang }
34
+ }
35
+
36
+ function normalizeLink(
37
+ link: string,
38
+ addPath: boolean,
39
+ path: string,
40
+ addExt: boolean,
41
+ ) {
42
+ return addPath
43
+ ? link.replace(/\/$/, '')
44
+ + ensureStartingSlash(
45
+ path
46
+ .replace(/(^|\/)index\.md$/, '$1')
47
+ .replace(/\.md$/, addExt ? '.html' : ''),
48
+ )
49
+ : link
50
+ }