@vuepress/theme-default 2.0.0-rc.20 → 2.0.0-rc.22

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.
@@ -90,9 +90,11 @@ const isActive = computed(() => {
90
90
  :aria-label="linkAriaLabel"
91
91
  v-bind="$attrs"
92
92
  >
93
- <slot name="before" />
94
- {{ item.text }}
95
- <slot name="after" />
93
+ <slot>
94
+ <slot name="before" />
95
+ {{ item.text }}
96
+ <slot name="after" />
97
+ </slot>
96
98
  </RouteLink>
97
99
  <a
98
100
  v-else
@@ -103,9 +105,11 @@ const isActive = computed(() => {
103
105
  :aria-label="linkAriaLabel"
104
106
  v-bind="$attrs"
105
107
  >
106
- <slot name="before" />
107
- {{ item.text }}
108
- <AutoLinkExternalIcon v-if="isBlankTarget" />
109
- <slot name="after" />
108
+ <slot>
109
+ <slot name="before" />
110
+ {{ item.text }}
111
+ <AutoLinkExternalIcon v-if="isBlankTarget" />
112
+ <slot name="after" />
113
+ </slot>
110
114
  </a>
111
115
  </template>
@@ -32,6 +32,16 @@ const linksWrapperStyle = computed(() => {
32
32
  }
33
33
  })
34
34
 
35
+ const getCssValue = (el: HTMLElement | null, property: string): number => {
36
+ // NOTE: Known bug, will return 'auto' if style value is 'auto'
37
+ const val = el?.ownerDocument?.defaultView?.getComputedStyle(el, null)?.[
38
+ property
39
+ ]
40
+ const num = Number.parseInt(val, 10)
41
+
42
+ return Number.isNaN(num) ? 0 : num
43
+ }
44
+
35
45
  useUpdateDeviceStatus(
36
46
  DeviceType.MOBILE,
37
47
  (mobileDesktopBreakpoint: number): void => {
@@ -49,15 +59,6 @@ useUpdateDeviceStatus(
49
59
  }
50
60
  },
51
61
  )
52
-
53
- function getCssValue(el: HTMLElement | null, property: string): number {
54
- // NOTE: Known bug, will return 'auto' if style value is 'auto'
55
- const val = el?.ownerDocument?.defaultView?.getComputedStyle(el, null)?.[
56
- property
57
- ]
58
- const num = Number.parseInt(val, 10)
59
- return Number.isNaN(num) ? 0 : num
60
- }
61
62
  </script>
62
63
 
63
64
  <template>
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import AutoLink from '@theme/AutoLink.vue'
3
+ import { useEventListener } from '@vueuse/core'
3
4
  import { computed } from 'vue'
4
5
  import type { Router } from 'vuepress/client'
5
6
  import { usePageFrontmatter, useRoute, useRouter } from 'vuepress/client'
@@ -9,7 +10,11 @@ import type {
9
10
  NavLink,
10
11
  ResolvedSidebarItem,
11
12
  } from '../../shared/index.js'
12
- import { useSidebarItems, useThemeLocaleData } from '../composables/index.js'
13
+ import {
14
+ useNavigate,
15
+ useSidebarItems,
16
+ useThemeLocaleData,
17
+ } from '../composables/index.js'
13
18
  import { getNavLink } from '../utils/index.js'
14
19
 
15
20
  /**
@@ -69,8 +74,10 @@ const resolveFromSidebarItems = (
69
74
 
70
75
  const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
71
76
  const sidebarItems = useSidebarItems()
77
+ const themeLocale = useThemeLocaleData()
72
78
  const route = useRoute()
73
79
  const router = useRouter()
80
+ const navigate = useNavigate()
74
81
 
75
82
  const prevNavLink = computed(() => {
76
83
  const prevConfig = resolveFromFrontmatterConfig(
@@ -100,22 +107,109 @@ const navbarLabel = computed(() => {
100
107
  const themeLocale = useThemeLocaleData()
101
108
  return themeLocale.value.pageNavbarLabel ?? 'page navigation'
102
109
  })
110
+
111
+ useEventListener('keydown', (event): void => {
112
+ if (event.altKey)
113
+ if (event.key === 'ArrowRight') {
114
+ if (nextNavLink.value) {
115
+ navigate(nextNavLink.value.link)
116
+ event.preventDefault()
117
+ }
118
+ } else if (event.key === 'ArrowLeft') {
119
+ if (prevNavLink.value) {
120
+ navigate(prevNavLink.value.link)
121
+ event.preventDefault()
122
+ }
123
+ }
124
+ })
103
125
  </script>
104
126
 
105
127
  <template>
106
128
  <nav
107
129
  v-if="prevNavLink || nextNavLink"
108
- class="page-nav"
130
+ class="vp-page-nav"
109
131
  :aria-label="navbarLabel"
110
132
  >
111
- <p class="inner">
112
- <span v-if="prevNavLink" class="prev">
113
- <AutoLink :item="prevNavLink" />
114
- </span>
115
-
116
- <span v-if="nextNavLink" class="next">
117
- <AutoLink :item="nextNavLink" />
118
- </span>
119
- </p>
133
+ <AutoLink v-if="prevNavLink" class="prev" :item="prevNavLink">
134
+ <div class="hint">
135
+ <span class="arrow left" />
136
+ {{ themeLocale.prev ?? 'Prev' }}
137
+ </div>
138
+ <div class="link">
139
+ <span>{{ prevNavLink.text }}</span>
140
+ </div>
141
+ </AutoLink>
142
+
143
+ <AutoLink v-if="nextNavLink" class="next" :item="nextNavLink">
144
+ <div class="hint">
145
+ {{ themeLocale.next ?? 'Next' }}
146
+ <span class="arrow right" />
147
+ </div>
148
+ <div class="link">
149
+ <span>{{ nextNavLink.text }}</span>
150
+ </div>
151
+ </AutoLink>
120
152
  </nav>
121
153
  </template>
154
+
155
+ <style lang="scss">
156
+ @import '../styles/_variables';
157
+
158
+ .vp-page-nav {
159
+ display: flex;
160
+ flex-wrap: wrap;
161
+
162
+ max-width: var(--content-width, 740px);
163
+ min-height: 2rem;
164
+ margin-inline: auto;
165
+ margin-top: 0;
166
+ padding-block: 0.5rem;
167
+ padding-inline: 2rem;
168
+ border-top: 1px solid var(--c-border);
169
+
170
+ transition: border-top var(--t-color);
171
+
172
+ @media (max-width: $MQNarrow) {
173
+ padding-inline: 1rem;
174
+ }
175
+
176
+ @media print {
177
+ display: none;
178
+ }
179
+
180
+ padding-top: 1rem;
181
+ padding-bottom: 0;
182
+
183
+ @media print {
184
+ display: none;
185
+ }
186
+
187
+ .route-link {
188
+ display: inline-block;
189
+ flex-grow: 1;
190
+
191
+ margin: 0.25rem;
192
+ padding: 0.25rem 0.5rem;
193
+ border: 1px solid var(--c-border);
194
+ border-radius: 0.25rem;
195
+
196
+ &:hover {
197
+ background: var(--c-bg-light);
198
+ }
199
+
200
+ .hint {
201
+ color: var(--c-text-quote);
202
+ font-size: 0.875rem;
203
+ line-height: 2;
204
+ }
205
+ }
206
+
207
+ .prev {
208
+ text-align: start;
209
+ }
210
+
211
+ .next {
212
+ text-align: end;
213
+ }
214
+ }
215
+ </style>
@@ -1,4 +1,5 @@
1
1
  export * from './useDarkMode.js';
2
+ export * from './useNavigate.js';
2
3
  export * from './useScrollPromise.js';
3
4
  export * from './useSidebarItems.js';
4
5
  export * from './useThemeData.js';
@@ -1,4 +1,5 @@
1
1
  export * from './useDarkMode.js';
2
+ export * from './useNavigate.js';
2
3
  export * from './useScrollPromise.js';
3
4
  export * from './useSidebarItems.js';
4
5
  export * from './useThemeData.js';
@@ -0,0 +1 @@
1
+ export declare const useNavigate: () => (url: string) => void;
@@ -0,0 +1,25 @@
1
+ import { isLinkAbsolute, isLinkWithProtocol } from '@vuepress/helper/client';
2
+ import { useRoute, useRouter } from 'vuepress/client';
3
+ const FAKE_HOST = 'http://.';
4
+ export const useNavigate = () => {
5
+ const router = useRouter();
6
+ const route = useRoute();
7
+ return (url) => {
8
+ if (url)
9
+ if (isLinkAbsolute(url)) {
10
+ // Inner absolute path
11
+ if (route.path !== url)
12
+ router.push(url);
13
+ }
14
+ else if (isLinkWithProtocol(url)) {
15
+ // Outer url
16
+ if (window)
17
+ window.open(url);
18
+ }
19
+ else {
20
+ // Inner relative path
21
+ const loc = route.path.slice(0, route.path.lastIndexOf('/'));
22
+ router.push(new URL(`${loc}/${encodeURI(url)}`, FAKE_HOST).pathname);
23
+ }
24
+ };
25
+ };
@@ -1,3 +1,4 @@
1
+ import { useEventListener } from '@vueuse/core';
1
2
  import { onMounted } from 'vue';
2
3
  import cssVars from '../styles/_variables.module.scss?module';
3
4
  export var DeviceType;
@@ -17,9 +18,9 @@ export const useUpdateDeviceStatus = (deviceType, callback) => {
17
18
  throw new Error('device width must be a integer');
18
19
  return;
19
20
  }
21
+ useEventListener('orientationchange', () => callback(width), false);
22
+ useEventListener('resize', () => callback(width), false);
20
23
  onMounted(() => {
21
24
  callback(width);
22
- window.addEventListener('resize', () => callback(width), false);
23
- window.addEventListener('orientationchange', () => callback(width), false);
24
25
  });
25
26
  };
@@ -1,37 +1,31 @@
1
1
  .arrow {
2
2
  display: inline-block;
3
- width: 0;
4
- height: 0;
5
-
6
- &.up {
7
- border: {
8
- left: 4px solid transparent;
9
- right: 4px solid transparent;
10
- bottom: 6px solid var(--c-bg-arrow);
11
- }
3
+ vertical-align: middle;
4
+
5
+ width: 1em;
6
+ height: 1em;
7
+
8
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='rgba(0,0,0,0.5)' d='M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z'/%3E%3C/svg%3E");
9
+ background-position: center;
10
+ background-repeat: no-repeat;
11
+
12
+ line-height: normal;
13
+
14
+ transition: all 0.3s;
15
+
16
+ html.dark & {
17
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='rgba(255,255,255,0.5)' d='M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z'/%3E%3C/svg%3E");
12
18
  }
13
19
 
14
20
  &.down {
15
- border: {
16
- left: 4px solid transparent;
17
- right: 4px solid transparent;
18
- top: 6px solid var(--c-bg-arrow);
19
- }
21
+ transform: rotate(180deg);
20
22
  }
21
23
 
22
24
  &.right {
23
- border: {
24
- top: 4px solid transparent;
25
- bottom: 4px solid transparent;
26
- left: 6px solid var(--c-bg-arrow);
27
- }
25
+ transform: rotate(90deg);
28
26
  }
29
27
 
30
28
  &.left {
31
- border: {
32
- top: 4px solid transparent;
33
- bottom: 4px solid transparent;
34
- right: 6px solid var(--c-bg-arrow);
35
- }
29
+ transform: rotate(-90deg);
36
30
  }
37
31
  }
@@ -58,30 +58,3 @@
58
58
  }
59
59
  }
60
60
  }
61
-
62
- .page-nav {
63
- @include content_wrapper;
64
- padding-top: 1rem;
65
- padding-bottom: 0;
66
-
67
- .inner {
68
- min-height: 2rem;
69
- margin-top: 0;
70
- border-top: 1px solid var(--c-border);
71
- transition: border-color var(--t-color);
72
- padding-top: 1rem;
73
- overflow: auto;
74
- }
75
-
76
- .prev {
77
- a:before {
78
- content: '←';
79
- }
80
- }
81
- .next {
82
- float: right;
83
- a:after {
84
- content: '→';
85
- }
86
- }
87
- }
@@ -276,4 +276,12 @@ export interface DefaultThemeLocaleData extends LocaleData {
276
276
  * A11y text for sidebar toggle button
277
277
  */
278
278
  toggleSidebar?: string;
279
+ /**
280
+ * text for prev link
281
+ */
282
+ prev?: string;
283
+ /**
284
+ * text for next link
285
+ */
286
+ next?: string;
279
287
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/theme-default",
3
- "version": "2.0.0-rc.20",
3
+ "version": "2.0.0-rc.22",
4
4
  "description": "Default theme of VuePress",
5
5
  "keywords": [
6
6
  "vuepress-theme",
@@ -42,28 +42,28 @@
42
42
  "copy": "cpx \"src/**/*.{d.ts,vue,scss}\" lib"
43
43
  },
44
44
  "dependencies": {
45
- "@vuepress/helper": "~2.0.0-rc.19",
46
- "@vuepress/plugin-active-header-links": "~2.0.0-rc.18",
47
- "@vuepress/plugin-back-to-top": "~2.0.0-rc.19",
48
- "@vuepress/plugin-container": "~2.0.0-rc.15",
49
- "@vuepress/plugin-copy-code": "~2.0.0-rc.19",
50
- "@vuepress/plugin-external-link-icon": "~2.0.0-rc.18",
51
- "@vuepress/plugin-git": "~2.0.0-rc.15",
52
- "@vuepress/plugin-links-check": "~2.0.0-rc.19",
53
- "@vuepress/plugin-medium-zoom": "~2.0.0-rc.19",
54
- "@vuepress/plugin-nprogress": "~2.0.0-rc.18",
55
- "@vuepress/plugin-palette": "~2.0.0-rc.15",
56
- "@vuepress/plugin-prismjs": "~2.0.0-rc.15",
57
- "@vuepress/plugin-seo": "~2.0.0-rc.19",
58
- "@vuepress/plugin-sitemap": "~2.0.0-rc.19",
59
- "@vuepress/plugin-theme-data": "~2.0.0-rc.18",
45
+ "@vuepress/helper": "~2.0.0-rc.22",
46
+ "@vuepress/plugin-active-header-links": "~2.0.0-rc.21",
47
+ "@vuepress/plugin-back-to-top": "~2.0.0-rc.22",
48
+ "@vuepress/plugin-container": "~2.0.0-rc.21",
49
+ "@vuepress/plugin-copy-code": "~2.0.0-rc.22",
50
+ "@vuepress/plugin-external-link-icon": "~2.0.0-rc.21",
51
+ "@vuepress/plugin-git": "~2.0.0-rc.22",
52
+ "@vuepress/plugin-links-check": "~2.0.0-rc.22",
53
+ "@vuepress/plugin-medium-zoom": "~2.0.0-rc.22",
54
+ "@vuepress/plugin-nprogress": "~2.0.0-rc.21",
55
+ "@vuepress/plugin-palette": "~2.0.0-rc.21",
56
+ "@vuepress/plugin-prismjs": "~2.0.0-rc.21",
57
+ "@vuepress/plugin-seo": "~2.0.0-rc.22",
58
+ "@vuepress/plugin-sitemap": "~2.0.0-rc.22",
59
+ "@vuepress/plugin-theme-data": "~2.0.0-rc.21",
60
60
  "@vueuse/core": "^10.9.0",
61
- "sass": "^1.71.1",
61
+ "sass": "^1.72.0",
62
62
  "vue": "^3.4.21"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "sass-loader": "^14.0.0",
66
- "vuepress": "2.0.0-rc.8"
66
+ "vuepress": "2.0.0-rc.9"
67
67
  },
68
68
  "peerDependenciesMeta": {
69
69
  "sass-loader": {
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "access": "public"
75
75
  },
76
- "gitHead": "7042b2665c01b45c39a511efe059aed11b77c6f3"
76
+ "gitHead": "088ab15335527cc0c644d7ec83e7588be675477e"
77
77
  }