valaxy 1.4.0 → 1.5.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/client/components/ValaxyCopyright.vue +20 -7
- package/client/components/ValaxyFootnoteTooltip.vue +35 -2
- package/client/composables/features/copy-code.ts +4 -46
- package/client/composables/outline/anchor.ts +117 -26
- package/client/locales/en.yml +2 -0
- package/client/locales/zh-CN.yml +2 -0
- package/client/styles/common/markdown.scss +122 -21
- package/client/styles/css-vars.scss +10 -0
- package/client/utils/clipboard.ts +65 -0
- package/client/utils/index.ts +1 -0
- package/client/utils/router.ts +39 -3
- package/dist/node/cli/index.mjs +1 -1
- package/dist/node/index.mjs +1 -1
- package/dist/shared/{valaxy.i_3nqqSt.mjs → valaxy.BvJ4MbYz.mjs} +42 -20
- package/package.json +3 -3
|
@@ -40,7 +40,7 @@ const licenseHtml = computed(() => {
|
|
|
40
40
|
<strong>
|
|
41
41
|
{{ t('post.copyright.link') + t('symbol.colon') }}
|
|
42
42
|
</strong>
|
|
43
|
-
<a :href="url" target="_blank" :title="t('post.copyright.link')">
|
|
43
|
+
<a :href="url" target="_blank" rel="noopener noreferrer" :title="t('post.copyright.link')">
|
|
44
44
|
{{ decodePath(url) }}
|
|
45
45
|
</a>
|
|
46
46
|
</li>
|
|
@@ -55,14 +55,27 @@ const licenseHtml = computed(() => {
|
|
|
55
55
|
|
|
56
56
|
<style lang="scss">
|
|
57
57
|
.post-copyright {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
position: relative;
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
padding: 0.75rem 1.125rem;
|
|
61
|
+
border: 1px solid var(--yun-surface-line, var(--va-c-divider));
|
|
62
|
+
border-left: 3px solid var(--va-c-link);
|
|
63
|
+
border-radius: var(--va-card-border-radius, 0.5rem);
|
|
61
64
|
background-color: var(--va-c-bg-dark);
|
|
65
|
+
color: var(--va-c-text-2);
|
|
66
|
+
font-size: 0.9rem;
|
|
67
|
+
line-height: 1.7;
|
|
62
68
|
list-style: none;
|
|
63
69
|
word-break: break-all;
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
|
|
71
|
+
strong {
|
|
72
|
+
color: var(--va-c-text);
|
|
73
|
+
font-weight: 600;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
a {
|
|
77
|
+
color: var(--va-c-link);
|
|
78
|
+
}
|
|
66
79
|
|
|
67
80
|
&::after {
|
|
68
81
|
pointer-events: none;
|
|
@@ -74,7 +87,7 @@ const licenseHtml = computed(() => {
|
|
|
74
87
|
width: 10rem;
|
|
75
88
|
right: -2rem;
|
|
76
89
|
top: -2rem;
|
|
77
|
-
opacity: 0.
|
|
90
|
+
opacity: 0.06;
|
|
78
91
|
}
|
|
79
92
|
}
|
|
80
93
|
</style>
|
|
@@ -3,6 +3,11 @@ import { PopoverArrow, PopoverClose, PopoverContent, PopoverPortal, PopoverRoot,
|
|
|
3
3
|
import { onBeforeUnmount, shallowRef } from 'vue'
|
|
4
4
|
import { useI18n } from 'vue-i18n'
|
|
5
5
|
|
|
6
|
+
defineProps<{
|
|
7
|
+
/** Semantic kind supplied by the Markdown renderer for an author note. */
|
|
8
|
+
kind?: 'author'
|
|
9
|
+
}>()
|
|
10
|
+
|
|
6
11
|
const { t } = useI18n()
|
|
7
12
|
const open = shallowRef(false)
|
|
8
13
|
// Hover previews must neither steal focus nor return it when dismissed.
|
|
@@ -55,13 +60,13 @@ onBeforeUnmount(cancelClose)
|
|
|
55
60
|
|
|
56
61
|
<template>
|
|
57
62
|
<PopoverRoot :open="open" :modal="false" @update:open="updateOpen">
|
|
58
|
-
<span class="va-footnote">
|
|
63
|
+
<span class="va-footnote" :data-footnote-kind="kind">
|
|
59
64
|
<span @pointerenter="preview" @pointerleave="scheduleClose" @click="followFootnote">
|
|
60
65
|
<slot />
|
|
61
66
|
</span>
|
|
62
67
|
<PopoverTrigger
|
|
63
68
|
class="va-footnote-preview"
|
|
64
|
-
:aria-label="t('post.footnote_preview')"
|
|
69
|
+
:aria-label="t(kind === 'author' ? 'post.author_note_preview' : 'post.footnote_preview')"
|
|
65
70
|
@pointerenter="cancelClose"
|
|
66
71
|
@pointerleave="scheduleClose"
|
|
67
72
|
>
|
|
@@ -70,6 +75,8 @@ onBeforeUnmount(cancelClose)
|
|
|
70
75
|
<PopoverPortal to="#valaxy-teleports">
|
|
71
76
|
<PopoverContent
|
|
72
77
|
class="va-footnote-popover markdown-body"
|
|
78
|
+
:data-footnote-kind="kind"
|
|
79
|
+
:aria-label="kind === 'author' ? t('post.author_note') : undefined"
|
|
73
80
|
side="top"
|
|
74
81
|
:side-offset="8"
|
|
75
82
|
:collision-padding="12"
|
|
@@ -83,6 +90,7 @@ onBeforeUnmount(cancelClose)
|
|
|
83
90
|
<PopoverClose class="va-footnote-close" :aria-label="t('post.footnote_close')">
|
|
84
91
|
<span aria-hidden="true">×</span>
|
|
85
92
|
</PopoverClose>
|
|
93
|
+
<span v-if="kind === 'author'" class="va-footnote-label">{{ t('post.author_note') }}</span>
|
|
86
94
|
<slot name="popper" />
|
|
87
95
|
<PopoverArrow class="va-footnote-arrow" />
|
|
88
96
|
</PopoverContent>
|
|
@@ -121,12 +129,19 @@ onBeforeUnmount(cancelClose)
|
|
|
121
129
|
font-size: 0.875rem;
|
|
122
130
|
line-height: 1.6;
|
|
123
131
|
overflow-wrap: anywhere;
|
|
132
|
+
animation: va-footnote-popover-in var(--va-transition-duration-fast, 150ms) ease-out;
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
.va-footnote-popover > p:last-of-type {
|
|
127
136
|
margin-bottom: 0;
|
|
128
137
|
}
|
|
129
138
|
|
|
139
|
+
.va-footnote-label {
|
|
140
|
+
display: block;
|
|
141
|
+
margin-bottom: 0.5em;
|
|
142
|
+
font-weight: 600;
|
|
143
|
+
}
|
|
144
|
+
|
|
130
145
|
.va-footnote-close {
|
|
131
146
|
float: right;
|
|
132
147
|
margin-inline-start: 0.5rem;
|
|
@@ -143,4 +158,22 @@ onBeforeUnmount(cancelClose)
|
|
|
143
158
|
.va-footnote-arrow {
|
|
144
159
|
fill: var(--va-c-bg);
|
|
145
160
|
}
|
|
161
|
+
|
|
162
|
+
@media (prefers-reduced-motion: reduce) {
|
|
163
|
+
.va-footnote-popover {
|
|
164
|
+
animation: none;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@keyframes va-footnote-popover-in {
|
|
169
|
+
from {
|
|
170
|
+
opacity: 0;
|
|
171
|
+
transform: translateY(4px);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
to {
|
|
175
|
+
opacity: 1;
|
|
176
|
+
transform: translateY(0);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
146
179
|
</style>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// ref vitepress copyCode.ts
|
|
2
2
|
import { isClient } from '@vueuse/core'
|
|
3
3
|
import { getCurrentScope, onScopeDispose } from 'vue'
|
|
4
|
+
import { copyToClipboard } from '../../utils/clipboard'
|
|
4
5
|
|
|
5
6
|
const timeoutIdMap: WeakMap<HTMLElement, ReturnType<typeof setTimeout>> = new WeakMap()
|
|
6
7
|
let activeCopyCodeListeners = 0
|
|
@@ -31,7 +32,9 @@ function handleCopyClick(e: MouseEvent) {
|
|
|
31
32
|
text = text.replace(/^ *(\$|>) /gm, '').trim()
|
|
32
33
|
|
|
33
34
|
copyToClipboard(text)
|
|
34
|
-
.then(() => {
|
|
35
|
+
.then((copied) => {
|
|
36
|
+
if (!copied)
|
|
37
|
+
return
|
|
35
38
|
el.classList.add('copied')
|
|
36
39
|
clearTimeout(timeoutIdMap.get(el as HTMLElement))
|
|
37
40
|
const timeoutId = setTimeout(() => {
|
|
@@ -67,48 +70,3 @@ export function useCopyCode() {
|
|
|
67
70
|
|
|
68
71
|
return cleanup
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
async function copyToClipboard(text: string) {
|
|
72
|
-
try {
|
|
73
|
-
return await navigator.clipboard.writeText(text)
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
const element = document.createElement('textarea')
|
|
77
|
-
const previouslyFocusedElement = document.activeElement
|
|
78
|
-
|
|
79
|
-
element.value = text
|
|
80
|
-
|
|
81
|
-
// Prevent keyboard from showing on mobile
|
|
82
|
-
element.setAttribute('readonly', '')
|
|
83
|
-
|
|
84
|
-
element.style.contain = 'strict'
|
|
85
|
-
element.style.position = 'absolute'
|
|
86
|
-
element.style.left = '-9999px'
|
|
87
|
-
element.style.fontSize = '12pt' // Prevent zooming on iOS
|
|
88
|
-
|
|
89
|
-
const selection = document.getSelection()
|
|
90
|
-
const originalRange = selection
|
|
91
|
-
? selection.rangeCount > 0 && selection.getRangeAt(0)
|
|
92
|
-
: null
|
|
93
|
-
|
|
94
|
-
document.body.appendChild(element)
|
|
95
|
-
element.select()
|
|
96
|
-
|
|
97
|
-
// Explicit selection workaround for iOS
|
|
98
|
-
element.selectionStart = 0
|
|
99
|
-
element.selectionEnd = text.length
|
|
100
|
-
|
|
101
|
-
document.execCommand('copy')
|
|
102
|
-
document.body.removeChild(element)
|
|
103
|
-
|
|
104
|
-
if (originalRange) {
|
|
105
|
-
selection!.removeAllRanges() // originalRange can't be truthy when selection is falsy
|
|
106
|
-
selection!.addRange(originalRange)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Get the focus back on the previously focused element, if any
|
|
110
|
-
if (previouslyFocusedElement) {
|
|
111
|
-
;(previouslyFocusedElement as HTMLElement).focus()
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Ref } from 'vue'
|
|
2
2
|
import { resolvedHeaders } from '@valaxyjs/utils'
|
|
3
|
-
import { onMounted, onUnmounted,
|
|
4
|
-
import { throttleAndDebounce } from '../../utils'
|
|
3
|
+
import { nextTick, onMounted, onUnmounted, shallowRef } from 'vue'
|
|
4
|
+
import { onContentUpdated, throttleAndDebounce } from '../../utils'
|
|
5
5
|
import { useAside } from '../aside'
|
|
6
6
|
|
|
7
7
|
// magic number to avoid repeated retrieval
|
|
@@ -43,27 +43,99 @@ function findLinkByHash(container: HTMLElement, hash: string): HTMLAnchorElement
|
|
|
43
43
|
.find(link => safeDecode(link.hash) === target) ?? null
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* When the active outline link sits inside a collapsed branch, walk up to
|
|
48
|
+
* the nearest expanded ancestor item so the indicator tracks a visible row.
|
|
49
|
+
*/
|
|
50
|
+
function resolveVisibleLink(link: HTMLAnchorElement): HTMLAnchorElement {
|
|
51
|
+
let cur: HTMLAnchorElement = link
|
|
52
|
+
while (true) {
|
|
53
|
+
const collapsedBranch = cur.closest('[data-outline-collapsed="true"]')
|
|
54
|
+
if (!collapsedBranch)
|
|
55
|
+
return cur
|
|
56
|
+
|
|
57
|
+
const parentItem = collapsedBranch.closest('.va-toc-item')
|
|
58
|
+
const parentLink = parentItem?.querySelector<HTMLAnchorElement>(
|
|
59
|
+
':scope > a[href*="#"]',
|
|
60
|
+
)
|
|
61
|
+
if (!parentLink || parentLink === cur)
|
|
62
|
+
return cur
|
|
63
|
+
|
|
64
|
+
cur = parentLink
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getRelativeTop(element: HTMLElement, ancestor: HTMLElement): number | null {
|
|
69
|
+
let top = 0
|
|
70
|
+
let cur: HTMLElement | null = element
|
|
71
|
+
while (cur && cur !== ancestor) {
|
|
72
|
+
top += cur.offsetTop
|
|
73
|
+
cur = cur.offsetParent as HTMLElement | null
|
|
74
|
+
}
|
|
75
|
+
return cur === ancestor ? top : null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Compute the marker's `top` offset relative to its containing block so
|
|
80
|
+
* alignment stays accurate whether the outline header is visible, taller, or hidden.
|
|
81
|
+
*/
|
|
82
|
+
export function resolveOutlineMarkerTop(
|
|
83
|
+
visibleLink: HTMLElement,
|
|
84
|
+
markerEl: HTMLElement,
|
|
85
|
+
fallbackOffset = topOffset,
|
|
86
|
+
): number {
|
|
87
|
+
const markerParent = markerEl.offsetParent as HTMLElement | null
|
|
88
|
+
if (markerParent) {
|
|
89
|
+
const relativeTop = getRelativeTop(visibleLink, markerParent)
|
|
90
|
+
if (relativeTop !== null) {
|
|
91
|
+
const centerOffset = visibleLink.offsetHeight && markerEl.offsetHeight
|
|
92
|
+
? Math.round((visibleLink.offsetHeight - markerEl.offsetHeight) / 2)
|
|
93
|
+
: 5
|
|
94
|
+
return relativeTop + centerOffset
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return visibleLink.offsetTop + fallbackOffset
|
|
98
|
+
}
|
|
99
|
+
|
|
46
100
|
export function useActiveAnchor(
|
|
47
101
|
container: Ref<HTMLElement>,
|
|
48
102
|
marker: Ref<HTMLElement>,
|
|
49
103
|
) {
|
|
50
104
|
const { isAsideEnabled } = useAside()
|
|
51
105
|
const onScroll = throttleAndDebounce(setActiveLink, 100)
|
|
106
|
+
const activeLink = shallowRef<string | null>(null)
|
|
52
107
|
|
|
53
108
|
let prevActiveLink: HTMLAnchorElement | null = null
|
|
109
|
+
let resizeObserver: ResizeObserver | undefined
|
|
110
|
+
|
|
111
|
+
const onHashChange = () => {
|
|
112
|
+
activateLink(location.hash || null)
|
|
113
|
+
}
|
|
54
114
|
|
|
55
115
|
onMounted(() => {
|
|
56
116
|
requestAnimationFrame(setActiveLink)
|
|
57
117
|
window.addEventListener('scroll', onScroll)
|
|
118
|
+
window.addEventListener('hashchange', onHashChange)
|
|
119
|
+
if (typeof ResizeObserver !== 'undefined' && container.value) {
|
|
120
|
+
resizeObserver = new ResizeObserver(() => refreshMarker())
|
|
121
|
+
resizeObserver.observe(container.value)
|
|
122
|
+
}
|
|
58
123
|
})
|
|
59
124
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
125
|
+
onContentUpdated(() => {
|
|
126
|
+
void nextTick(() => {
|
|
127
|
+
if (location.hash)
|
|
128
|
+
activateLink(location.hash)
|
|
129
|
+
else
|
|
130
|
+
setActiveLink()
|
|
131
|
+
})
|
|
63
132
|
})
|
|
64
133
|
|
|
65
134
|
onUnmounted(() => {
|
|
66
135
|
window.removeEventListener('scroll', onScroll)
|
|
136
|
+
window.removeEventListener('hashchange', onHashChange)
|
|
137
|
+
resizeObserver?.disconnect()
|
|
138
|
+
resizeObserver = undefined
|
|
67
139
|
})
|
|
68
140
|
|
|
69
141
|
/**
|
|
@@ -71,16 +143,14 @@ export function useActiveAnchor(
|
|
|
71
143
|
* @see e2e/theme-yun/outline.spec.ts
|
|
72
144
|
*/
|
|
73
145
|
const checkActiveLinkInViewport = () => {
|
|
74
|
-
const
|
|
75
|
-
if (!
|
|
76
|
-
// container.value.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
146
|
+
const visibleLink = prevActiveLink ? resolveVisibleLink(prevActiveLink) : null
|
|
147
|
+
if (!visibleLink)
|
|
77
148
|
return
|
|
78
|
-
}
|
|
79
149
|
|
|
80
150
|
const parentEl = document.querySelector('.yun-aside') as HTMLElement
|
|
81
151
|
if (parentEl) {
|
|
82
152
|
// 超出
|
|
83
|
-
const top =
|
|
153
|
+
const top = (marker.value ? resolveOutlineMarkerTop(visibleLink, marker.value) : visibleLink.offsetTop + topOffset) + 60
|
|
84
154
|
if (top < parentEl.scrollTop || (top > parentEl.offsetHeight + parentEl.scrollTop))
|
|
85
155
|
parentEl.scrollTo({ top, behavior: 'smooth' })
|
|
86
156
|
}
|
|
@@ -123,35 +193,56 @@ export function useActiveAnchor(
|
|
|
123
193
|
}
|
|
124
194
|
|
|
125
195
|
// find the last header above the top of viewport
|
|
126
|
-
let
|
|
196
|
+
let currentHash: string | null = null
|
|
127
197
|
for (const { link, top } of headers) {
|
|
128
198
|
if (top > scrollY + 4 + PAGE_OFFSET)
|
|
129
199
|
break
|
|
130
200
|
|
|
131
|
-
|
|
201
|
+
currentHash = link
|
|
132
202
|
}
|
|
133
|
-
activateLink(
|
|
203
|
+
activateLink(currentHash)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function updateMarkerPosition(targetLink: HTMLAnchorElement | null) {
|
|
207
|
+
if (!marker.value)
|
|
208
|
+
return
|
|
209
|
+
|
|
210
|
+
const visibleLink = targetLink ? resolveVisibleLink(targetLink) : null
|
|
211
|
+
if (visibleLink) {
|
|
212
|
+
marker.value.style.top = `${resolveOutlineMarkerTop(visibleLink, marker.value)}px`
|
|
213
|
+
marker.value.style.opacity = '1'
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
marker.value.style.top = `${topOffset}px`
|
|
217
|
+
marker.value.style.opacity = '0'
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function refreshMarker() {
|
|
222
|
+
if (!container.value)
|
|
223
|
+
return
|
|
224
|
+
updateMarkerPosition(prevActiveLink)
|
|
134
225
|
}
|
|
135
226
|
|
|
136
227
|
function activateLink(hash: string | null) {
|
|
228
|
+
activeLink.value = hash || null
|
|
229
|
+
|
|
137
230
|
if (prevActiveLink)
|
|
138
231
|
prevActiveLink.classList.remove('active')
|
|
139
232
|
|
|
140
|
-
prevActiveLink = hash ? findLinkByHash(container.value, hash) : null
|
|
233
|
+
prevActiveLink = hash && container.value ? findLinkByHash(container.value, hash) : null
|
|
141
234
|
|
|
142
|
-
const
|
|
235
|
+
const currentLink = prevActiveLink
|
|
143
236
|
checkActiveLinkInViewport()
|
|
144
237
|
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}
|
|
238
|
+
if (currentLink)
|
|
239
|
+
currentLink.classList.add('active')
|
|
240
|
+
|
|
241
|
+
updateMarkerPosition(currentLink)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
activeLink,
|
|
246
|
+
refreshMarker,
|
|
156
247
|
}
|
|
157
248
|
}
|
package/client/locales/en.yml
CHANGED
package/client/locales/zh-CN.yml
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
@use "sass:map";
|
|
2
2
|
|
|
3
|
+
@mixin header-anchor-inline {
|
|
4
|
+
--va-header-anchor-shift: -4px;
|
|
5
|
+
|
|
6
|
+
position: relative;
|
|
7
|
+
top: auto;
|
|
8
|
+
inset-inline-end: auto;
|
|
9
|
+
height: auto;
|
|
10
|
+
margin-inline: 0.1em 0;
|
|
11
|
+
padding-inline: 0.2em;
|
|
12
|
+
line-height: 1;
|
|
13
|
+
vertical-align: middle;
|
|
14
|
+
|
|
15
|
+
&::after {
|
|
16
|
+
inset: -0.35rem -0.45rem -0.35rem -0.15rem;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
3
20
|
.markdown-body {
|
|
4
21
|
h1,
|
|
5
22
|
h2,
|
|
@@ -60,39 +77,123 @@
|
|
|
60
77
|
// header-anchor
|
|
61
78
|
.header-anchor {
|
|
62
79
|
position: absolute;
|
|
63
|
-
top: 0;
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
top: var(--va-header-anchor-top, 0);
|
|
81
|
+
inset-inline-end: 100%;
|
|
82
|
+
display: inline-flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
justify-content: center;
|
|
85
|
+
height: 1.5em;
|
|
86
|
+
margin-inline-end: var(--va-header-anchor-gutter-gap, 0.35rem);
|
|
87
|
+
padding-inline: 0.15rem;
|
|
88
|
+
border-bottom: 0;
|
|
89
|
+
border-radius: 0.25rem;
|
|
90
|
+
color: var(--va-header-anchor-color, var(--va-c-text-3));
|
|
91
|
+
font-family: var(--va-header-anchor-font-family, var(--va-font-sans));
|
|
66
92
|
font-weight: 500;
|
|
93
|
+
line-height: inherit;
|
|
94
|
+
text-decoration: none;
|
|
67
95
|
user-select: none;
|
|
68
96
|
opacity: 0;
|
|
69
|
-
|
|
97
|
+
transform: translateX(var(--va-header-anchor-shift, 4px));
|
|
70
98
|
transition:
|
|
71
|
-
color var(--va-transition-duration),
|
|
72
|
-
opacity var(--va-
|
|
99
|
+
color var(--va-transition-duration-fast, 0.15s) ease,
|
|
100
|
+
opacity 0.2s var(--va-header-anchor-ease, cubic-bezier(0.22, 1, 0.36, 1)),
|
|
101
|
+
transform 0.22s var(--va-header-anchor-ease, cubic-bezier(0.22, 1, 0.36, 1));
|
|
102
|
+
|
|
103
|
+
@supports (height: 1lh) {
|
|
104
|
+
height: 1lh;
|
|
105
|
+
}
|
|
73
106
|
}
|
|
74
107
|
|
|
75
108
|
.header-anchor::before {
|
|
76
109
|
content: var(--va-header-anchor-symbol, '#');
|
|
110
|
+
display: inline-block;
|
|
111
|
+
font-size: var(--va-header-anchor-font-size, clamp(0.875rem, 0.65em, 1.35rem));
|
|
112
|
+
line-height: 1;
|
|
113
|
+
}
|
|
77
114
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
115
|
+
.header-anchor::after {
|
|
116
|
+
content: '';
|
|
117
|
+
position: absolute;
|
|
118
|
+
inset: -0.25rem -0.5rem -0.25rem -0.35rem;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
:where(h1, h2, h3, h4, h5, h6):hover > .header-anchor {
|
|
122
|
+
opacity: var(--va-header-anchor-hover-opacity, 0.85);
|
|
123
|
+
transform: translateX(0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.header-anchor:hover,
|
|
127
|
+
.header-anchor:focus-visible {
|
|
128
|
+
border-bottom: 0;
|
|
129
|
+
color: var(--va-header-anchor-hover-color, var(--va-c-link, var(--va-c-primary)));
|
|
130
|
+
text-decoration: none;
|
|
131
|
+
opacity: 1;
|
|
132
|
+
transform: translateX(0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.header-anchor.is-copied,
|
|
136
|
+
.header-anchor.is-copied:hover,
|
|
137
|
+
.header-anchor.is-copied:focus-visible {
|
|
138
|
+
border-bottom: 0;
|
|
139
|
+
color: var(--va-header-anchor-copied-color, var(--va-c-green-1, #18794e));
|
|
140
|
+
text-decoration: none;
|
|
141
|
+
opacity: 1;
|
|
142
|
+
transform: translateX(0);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.header-anchor.is-copied::before {
|
|
146
|
+
content: var(--va-header-anchor-copied-symbol, '✓');
|
|
147
|
+
animation: va-header-anchor-pop 0.32s var(--va-header-anchor-ease, cubic-bezier(0.22, 1, 0.36, 1));
|
|
81
148
|
}
|
|
82
149
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
150
|
+
:is(blockquote, .custom-block, details, li, td, th) :is(h1, h2, h3, h4, h5, h6) > .header-anchor {
|
|
151
|
+
@include header-anchor-inline;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@keyframes va-header-anchor-pop {
|
|
156
|
+
0% {
|
|
157
|
+
opacity: 0;
|
|
158
|
+
transform: scale(0.6);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
60% {
|
|
95
162
|
opacity: 1;
|
|
163
|
+
transform: scale(1.16);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
100% {
|
|
167
|
+
opacity: 1;
|
|
168
|
+
transform: scale(1);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@media (width < 1024px) {
|
|
173
|
+
.markdown-body .header-anchor {
|
|
174
|
+
@include header-anchor-inline;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@media (hover: none) {
|
|
179
|
+
.markdown-body .header-anchor {
|
|
180
|
+
@include header-anchor-inline;
|
|
181
|
+
|
|
182
|
+
opacity: var(--va-header-anchor-touch-opacity, 0.55);
|
|
183
|
+
transform: none;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@media (prefers-reduced-motion: reduce) {
|
|
188
|
+
.markdown-body .header-anchor {
|
|
189
|
+
transform: none;
|
|
190
|
+
transition:
|
|
191
|
+
color var(--va-transition-duration-fast, 0.15s) ease,
|
|
192
|
+
opacity var(--va-transition-duration-fast, 0.15s) ease;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.markdown-body .header-anchor.is-copied::before {
|
|
196
|
+
animation: none;
|
|
96
197
|
}
|
|
97
198
|
}
|
|
98
199
|
|
|
@@ -143,4 +143,14 @@ html.dark {
|
|
|
143
143
|
|
|
144
144
|
:root {
|
|
145
145
|
--va-header-anchor-symbol: '#';
|
|
146
|
+
--va-header-anchor-copied-symbol: '✓';
|
|
147
|
+
--va-header-anchor-font-family: var(--va-font-sans);
|
|
148
|
+
--va-header-anchor-font-size: clamp(0.875rem, 0.65em, 1.35rem);
|
|
149
|
+
--va-header-anchor-color: var(--va-c-text-3);
|
|
150
|
+
--va-header-anchor-hover-color: var(--va-c-link, var(--va-c-primary));
|
|
151
|
+
--va-header-anchor-copied-color: var(--va-c-green-1, #18794e);
|
|
152
|
+
--va-header-anchor-hover-opacity: 0.85;
|
|
153
|
+
--va-header-anchor-touch-opacity: 0.55;
|
|
154
|
+
--va-header-anchor-ease: cubic-bezier(0.22, 1, 0.36, 1);
|
|
155
|
+
--va-header-anchor-gutter-gap: 0.35rem;
|
|
146
156
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy text to the system clipboard using the async Clipboard API with a
|
|
3
|
+
* DOM `execCommand('copy')` fallback for restricted contexts.
|
|
4
|
+
*/
|
|
5
|
+
export async function copyToClipboard(text: string): Promise<boolean> {
|
|
6
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
|
7
|
+
try {
|
|
8
|
+
await navigator.clipboard.writeText(text)
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// Fall through to execCommand fallback
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof document === 'undefined' || !document.body)
|
|
17
|
+
return false
|
|
18
|
+
|
|
19
|
+
const element = document.createElement('textarea')
|
|
20
|
+
const previouslyFocusedElement = document.activeElement
|
|
21
|
+
|
|
22
|
+
element.value = text
|
|
23
|
+
|
|
24
|
+
// Prevent keyboard from showing on mobile
|
|
25
|
+
element.setAttribute('readonly', '')
|
|
26
|
+
|
|
27
|
+
element.style.contain = 'strict'
|
|
28
|
+
element.style.position = 'absolute'
|
|
29
|
+
element.style.left = '-9999px'
|
|
30
|
+
element.style.fontSize = '12pt' // Prevent zooming on iOS
|
|
31
|
+
|
|
32
|
+
const selection = document.getSelection()
|
|
33
|
+
const originalRange = selection && selection.rangeCount > 0
|
|
34
|
+
? selection.getRangeAt(0)
|
|
35
|
+
: null
|
|
36
|
+
|
|
37
|
+
document.body.appendChild(element)
|
|
38
|
+
element.select()
|
|
39
|
+
|
|
40
|
+
// Explicit selection workaround for iOS
|
|
41
|
+
element.selectionStart = 0
|
|
42
|
+
element.selectionEnd = text.length
|
|
43
|
+
|
|
44
|
+
let copied = false
|
|
45
|
+
try {
|
|
46
|
+
copied = document.execCommand('copy')
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
copied = false
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
document.body.removeChild(element)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (originalRange && selection) {
|
|
56
|
+
selection.removeAllRanges()
|
|
57
|
+
selection.addRange(originalRange)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Get the focus back on the previously focused element, if any
|
|
61
|
+
if (previouslyFocusedElement instanceof HTMLElement)
|
|
62
|
+
previouslyFocusedElement.focus({ preventScroll: true })
|
|
63
|
+
|
|
64
|
+
return copied
|
|
65
|
+
}
|
package/client/utils/index.ts
CHANGED
package/client/utils/router.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Router } from 'vue-router'
|
|
2
|
+
import { copyToClipboard } from './clipboard'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @en
|
|
@@ -36,7 +37,7 @@ export function scrollTo(el: HTMLElement, hash: string, options: Partial<ScrollT
|
|
|
36
37
|
let target: Element | null = null
|
|
37
38
|
try {
|
|
38
39
|
target = el.classList.contains('header-anchor')
|
|
39
|
-
? el
|
|
40
|
+
? (el.closest('h1, h2, h3, h4, h5, h6') || el)
|
|
40
41
|
: ((decodeURIComponent(hash) && document.querySelector(decodeURIComponent(hash))) || null)
|
|
41
42
|
}
|
|
42
43
|
catch (e) {
|
|
@@ -71,6 +72,33 @@ interface ClickHandlerEntry {
|
|
|
71
72
|
|
|
72
73
|
const activeClickHandlers = new WeakMap<Router, ClickHandlerEntry>()
|
|
73
74
|
|
|
75
|
+
const HEADER_ANCHOR_COPIED_DURATION = 1600
|
|
76
|
+
const copiedAnchorTimers = new WeakMap<HTMLElement, ReturnType<typeof setTimeout>>()
|
|
77
|
+
|
|
78
|
+
function copyHeaderAnchorLink(link: HTMLAnchorElement) {
|
|
79
|
+
const url = link.href || window.location.href
|
|
80
|
+
void copyToClipboard(url).then((copied) => {
|
|
81
|
+
if (!copied)
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
const prevTimer = copiedAnchorTimers.get(link)
|
|
85
|
+
if (prevTimer)
|
|
86
|
+
clearTimeout(prevTimer)
|
|
87
|
+
|
|
88
|
+
if (link.classList.contains('is-copied')) {
|
|
89
|
+
link.classList.remove('is-copied')
|
|
90
|
+
void link.offsetWidth
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
link.classList.add('is-copied')
|
|
94
|
+
const timer = setTimeout(() => {
|
|
95
|
+
link.classList.remove('is-copied')
|
|
96
|
+
copiedAnchorTimers.delete(link)
|
|
97
|
+
}, HEADER_ANCHOR_COPIED_DURATION)
|
|
98
|
+
copiedAnchorTimers.set(link, timer)
|
|
99
|
+
}).catch(() => {})
|
|
100
|
+
}
|
|
101
|
+
|
|
74
102
|
function safeDecodeHash(hash: string): string {
|
|
75
103
|
try {
|
|
76
104
|
return decodeURIComponent(hash)
|
|
@@ -96,7 +124,8 @@ export function onClickHref(router: Router): () => void {
|
|
|
96
124
|
? e.target
|
|
97
125
|
: (e.target as Node | null)?.parentElement
|
|
98
126
|
const link = targetEl?.closest('a')
|
|
99
|
-
|
|
127
|
+
// Let controls that own their anchor navigation handle it themselves.
|
|
128
|
+
if (!link || link.hasAttribute('data-valaxy-native-link'))
|
|
100
129
|
return
|
|
101
130
|
|
|
102
131
|
const { protocol, hostname, pathname, hash, target } = link
|
|
@@ -115,15 +144,22 @@ export function onClickHref(router: Router): () => void {
|
|
|
115
144
|
) {
|
|
116
145
|
if (pathname === currentUrl.pathname) {
|
|
117
146
|
e.preventDefault()
|
|
147
|
+
const isHeaderAnchor = link.classList.contains('header-anchor')
|
|
148
|
+
if (hash && isHeaderAnchor)
|
|
149
|
+
copyHeaderAnchorLink(link)
|
|
150
|
+
|
|
118
151
|
// scroll between hash anchors in the same page
|
|
119
152
|
if (hash && hash !== currentUrl.hash) {
|
|
120
153
|
await router.push({ hash: safeDecodeHash(hash) })
|
|
121
154
|
|
|
122
155
|
// use smooth scroll when clicking on header anchor links
|
|
123
156
|
scrollTo(link, hash, {
|
|
124
|
-
smooth:
|
|
157
|
+
smooth: isHeaderAnchor,
|
|
125
158
|
})
|
|
126
159
|
}
|
|
160
|
+
else if (hash && isHeaderAnchor) {
|
|
161
|
+
scrollTo(link, hash, { smooth: true })
|
|
162
|
+
}
|
|
127
163
|
}
|
|
128
164
|
}
|
|
129
165
|
}
|
package/dist/node/cli/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import 'node:path';
|
|
|
2
2
|
import 'node:process';
|
|
3
3
|
import 'yargs';
|
|
4
4
|
import 'yargs/helpers';
|
|
5
|
-
export { a as createCli, t as desktopRuntimeVersion, v as execBuild, R as registerDevCommand, a3 as run, a5 as startValaxyDev } from '../../shared/valaxy.
|
|
5
|
+
export { a as createCli, t as desktopRuntimeVersion, v as execBuild, R as registerDevCommand, a3 as run, a5 as startValaxyDev } from '../../shared/valaxy.BvJ4MbYz.mjs';
|
|
6
6
|
import 'node:os';
|
|
7
7
|
import '@11ty/gray-matter';
|
|
8
8
|
import 'consola';
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as ALL_ROUTE, E as EXCERPT_SEPARATOR, G as GLOBAL_STATE, P as PATHNAME_PROTOCOL_RE, S as StateManager, V as ViteValaxyPlugins, b as build, c as clearGitTimestampCache, a as createCli, d as createContentService, e as createMemoryReleasePlugin, f as createServer, g as createValaxyNode, h as createValaxyPlugin, i as customElements, j as defaultSiteConfig, k as defaultValaxyConfig, l as defaultViteConfig, m as defineAddon, n as defineConfig, o as defineSiteConfig, p as defineTheme, q as defineValaxyAddon, r as defineValaxyConfig, s as defineValaxyTheme, t as desktopRuntimeVersion, u as encryptContent, v as execBuild, w as generateClientRedirects, x as getGitTimestamp, y as getGitTimestampCache, z as getIndexHtml, B as getServerInfoText, C as isExternal, D as isInstalledGlobally, F as isKatexEnabled, H as isKatexPluginNeeded, I as isMathJaxEnabled, J as isPath, K as loadAllContent, L as loadConfigFromFile, M as mergeValaxyConfig, N as mergeViteConfigs, O as postProcessForSSG, Q as processValaxyOptions, R as registerDevCommand, T as resolveAddonsConfig, U as resolveImportPath, W as resolveImportUrl, X as resolveOptions, Y as resolveSiteConfig, Z as resolveSiteConfigFromRoot, _ as resolveThemeConfigFromRoot, $ as resolveThemeValaxyConfig, a0 as resolveUserThemeConfig, a1 as resolveValaxyConfig, a2 as resolveValaxyConfigFromRoot, a3 as run, a4 as ssgBuild, a5 as startValaxyDev, a6 as toAtFS, a7 as transformObject, a8 as version } from '../shared/valaxy.
|
|
1
|
+
export { A as ALL_ROUTE, E as EXCERPT_SEPARATOR, G as GLOBAL_STATE, P as PATHNAME_PROTOCOL_RE, S as StateManager, V as ViteValaxyPlugins, b as build, c as clearGitTimestampCache, a as createCli, d as createContentService, e as createMemoryReleasePlugin, f as createServer, g as createValaxyNode, h as createValaxyPlugin, i as customElements, j as defaultSiteConfig, k as defaultValaxyConfig, l as defaultViteConfig, m as defineAddon, n as defineConfig, o as defineSiteConfig, p as defineTheme, q as defineValaxyAddon, r as defineValaxyConfig, s as defineValaxyTheme, t as desktopRuntimeVersion, u as encryptContent, v as execBuild, w as generateClientRedirects, x as getGitTimestamp, y as getGitTimestampCache, z as getIndexHtml, B as getServerInfoText, C as isExternal, D as isInstalledGlobally, F as isKatexEnabled, H as isKatexPluginNeeded, I as isMathJaxEnabled, J as isPath, K as loadAllContent, L as loadConfigFromFile, M as mergeValaxyConfig, N as mergeViteConfigs, O as postProcessForSSG, Q as processValaxyOptions, R as registerDevCommand, T as resolveAddonsConfig, U as resolveImportPath, W as resolveImportUrl, X as resolveOptions, Y as resolveSiteConfig, Z as resolveSiteConfigFromRoot, _ as resolveThemeConfigFromRoot, $ as resolveThemeValaxyConfig, a0 as resolveUserThemeConfig, a1 as resolveValaxyConfig, a2 as resolveValaxyConfigFromRoot, a3 as run, a4 as ssgBuild, a5 as startValaxyDev, a6 as toAtFS, a7 as transformObject, a8 as version } from '../shared/valaxy.BvJ4MbYz.mjs';
|
|
2
2
|
import 'node:path';
|
|
3
3
|
import 'consola';
|
|
4
4
|
import 'fs-extra';
|
|
@@ -73,7 +73,7 @@ import * as readline from 'node:readline';
|
|
|
73
73
|
import qrcode from 'qrcode';
|
|
74
74
|
import ejs from 'ejs';
|
|
75
75
|
|
|
76
|
-
const version = "1.
|
|
76
|
+
const version = "1.5.0";
|
|
77
77
|
|
|
78
78
|
const GLOBAL_STATE = {
|
|
79
79
|
valaxyApp: void 0,
|
|
@@ -5595,7 +5595,9 @@ function footnoteTooltipPlugin(md) {
|
|
|
5595
5595
|
return mapRenderResult(originalFootnoteRef(tokens, idx, options, env, self), (originalCode) => {
|
|
5596
5596
|
const href = originalCode.match(/href="(.*?)"/)[0];
|
|
5597
5597
|
const id = originalCode.match(/id="(.*?)"/)[0];
|
|
5598
|
-
|
|
5598
|
+
const label = tokens[idx]?.meta?.label;
|
|
5599
|
+
const kind = typeof label === "string" && label.startsWith("author-") && label.length > "author-".length ? ' kind="author"' : "";
|
|
5600
|
+
return `<ValaxyFootnoteRef ${href} ${id}${kind}>${originalCode}</ValaxyFootnoteRef>`;
|
|
5599
5601
|
});
|
|
5600
5602
|
};
|
|
5601
5603
|
md.renderer.rules.footnote_open = function(tokens, idx, options, env, self) {
|
|
@@ -7581,8 +7583,8 @@ function transformFootnoteTooltip(code, _id) {
|
|
|
7581
7583
|
const itemContent = content.replace(/<ValaxyFootnoteContent>(.*?)<\/ValaxyFootnoteContent>/gs, (_2, content2) => content2).replace(/<ValaxyFootnoteAnchor.*?>(.*?)<\/ValaxyFootnoteAnchor>/gs, (_2, anchor) => anchor);
|
|
7582
7584
|
footnoteContentMap.set(id, tooltipContent);
|
|
7583
7585
|
return itemContent;
|
|
7584
|
-
}).replace(/<ValaxyFootnoteRef href="#(
|
|
7585
|
-
return `<ValaxyFootnoteTooltip>${content}<template #popper>${footnoteContentMap.get(href)}</template></ValaxyFootnoteTooltip>`;
|
|
7586
|
+
}).replace(/<ValaxyFootnoteRef href="#([^"]+)" id="[^"]+"( kind="author")?>(.*?)<\/ValaxyFootnoteRef>/gs, (_, href, kind, content) => {
|
|
7587
|
+
return `<ValaxyFootnoteTooltip${kind ?? ""}>${content}<template #popper>${footnoteContentMap.get(href)}</template></ValaxyFootnoteTooltip>`;
|
|
7586
7588
|
});
|
|
7587
7589
|
}
|
|
7588
7590
|
|
|
@@ -8926,7 +8928,7 @@ async function renderPage(opts) {
|
|
|
8926
8928
|
}
|
|
8927
8929
|
const result = await opts.render(opts.route);
|
|
8928
8930
|
const headPayload = result.head ? await renderSSRHead(result.head) : { headTags: "", bodyTags: "", bodyTagsOpen: "", htmlAttrs: "", bodyAttrs: "" };
|
|
8929
|
-
const preloadLinks = renderPreloadLinks(result.modules, opts.ssrManifest);
|
|
8931
|
+
const preloadLinks = renderPreloadLinks(result.modules, opts.ssrManifest, template);
|
|
8930
8932
|
const stateScript = serializeState(result.initialState);
|
|
8931
8933
|
let html = template;
|
|
8932
8934
|
if (headPayload.htmlAttrs)
|
|
@@ -8965,11 +8967,9 @@ async function renderPage(opts) {
|
|
|
8965
8967
|
await writeFile(filePath, html, "utf-8");
|
|
8966
8968
|
return { route: opts.route, ...readCanonicalLink(html) };
|
|
8967
8969
|
}
|
|
8968
|
-
function
|
|
8969
|
-
let canonical;
|
|
8970
|
-
let baseHref;
|
|
8970
|
+
function visitHeadTags(html, visit) {
|
|
8971
8971
|
let inHead = false;
|
|
8972
|
-
let
|
|
8972
|
+
let inertDepth = 0;
|
|
8973
8973
|
const parser = new Parser({
|
|
8974
8974
|
onopentag(tag, attrs) {
|
|
8975
8975
|
if (tag === "body") {
|
|
@@ -8980,30 +8980,50 @@ function readCanonicalLink(html) {
|
|
|
8980
8980
|
inHead = true;
|
|
8981
8981
|
if (!inHead)
|
|
8982
8982
|
return;
|
|
8983
|
-
if (tag === "template")
|
|
8984
|
-
|
|
8985
|
-
if (
|
|
8983
|
+
if (tag === "template" || tag === "noscript")
|
|
8984
|
+
inertDepth++;
|
|
8985
|
+
if (inertDepth)
|
|
8986
8986
|
return;
|
|
8987
|
-
|
|
8988
|
-
baseHref ??= attrs.href;
|
|
8989
|
-
if (tag === "link" && attrs.rel?.toLowerCase().split(/\s+/).includes("canonical"))
|
|
8990
|
-
canonical ??= attrs.href;
|
|
8987
|
+
visit(tag, attrs);
|
|
8991
8988
|
},
|
|
8992
8989
|
onclosetag(tag) {
|
|
8993
|
-
if (tag === "template" &&
|
|
8994
|
-
|
|
8990
|
+
if ((tag === "template" || tag === "noscript") && inertDepth)
|
|
8991
|
+
inertDepth--;
|
|
8995
8992
|
if (tag === "head")
|
|
8996
8993
|
parser.pause();
|
|
8997
8994
|
}
|
|
8998
8995
|
});
|
|
8999
8996
|
parser.end(html);
|
|
8997
|
+
}
|
|
8998
|
+
function readCanonicalLink(html) {
|
|
8999
|
+
let canonical;
|
|
9000
|
+
let baseHref;
|
|
9001
|
+
visitHeadTags(html, (tag, attrs) => {
|
|
9002
|
+
if (tag === "base")
|
|
9003
|
+
baseHref ??= attrs.href;
|
|
9004
|
+
if (tag === "link" && attrs.rel?.toLowerCase().split(/\s+/).includes("canonical"))
|
|
9005
|
+
canonical ??= attrs.href;
|
|
9006
|
+
});
|
|
9000
9007
|
return { canonical, baseHref };
|
|
9001
9008
|
}
|
|
9002
|
-
function
|
|
9009
|
+
function readStylesheetHrefs(html) {
|
|
9010
|
+
const stylesheets = /* @__PURE__ */ new Set();
|
|
9011
|
+
visitHeadTags(html, (tag, attrs) => {
|
|
9012
|
+
if (tag !== "link" || attrs.rel?.trim().toLowerCase() !== "stylesheet" || !attrs.href)
|
|
9013
|
+
return;
|
|
9014
|
+
const media = attrs.media?.trim().toLowerCase();
|
|
9015
|
+
const type = attrs.type?.trim().toLowerCase();
|
|
9016
|
+
if (attrs.disabled === void 0 && !attrs.title && (!media || media === "all") && (!type || type === "text/css"))
|
|
9017
|
+
stylesheets.add(attrs.href);
|
|
9018
|
+
});
|
|
9019
|
+
return stylesheets;
|
|
9020
|
+
}
|
|
9021
|
+
function renderPreloadLinks(modules, manifest, template) {
|
|
9003
9022
|
if (!modules || modules.size === 0)
|
|
9004
9023
|
return "";
|
|
9005
9024
|
const seen = /* @__PURE__ */ new Set();
|
|
9006
9025
|
const links = [];
|
|
9026
|
+
let templateStylesheets;
|
|
9007
9027
|
for (const id of modules) {
|
|
9008
9028
|
const files = manifest[id];
|
|
9009
9029
|
if (!files)
|
|
@@ -9015,7 +9035,9 @@ function renderPreloadLinks(modules, manifest) {
|
|
|
9015
9035
|
if (file.endsWith(".js") || file.endsWith(".mjs")) {
|
|
9016
9036
|
links.push(`<link rel="modulepreload" crossorigin href="${file}">`);
|
|
9017
9037
|
} else if (file.endsWith(".css")) {
|
|
9018
|
-
|
|
9038
|
+
templateStylesheets ??= readStylesheetHrefs(template ?? "");
|
|
9039
|
+
if (!templateStylesheets.has(file))
|
|
9040
|
+
links.push(`<link rel="stylesheet" href="${file}">`);
|
|
9019
9041
|
} else if (file.endsWith(".woff") || file.endsWith(".woff2")) {
|
|
9020
9042
|
if (/(?:^|\/)KaTeX_[^/]+$/.test(file))
|
|
9021
9043
|
continue;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valaxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"description": "📄 Vite & Vue powered static blog generator.",
|
|
6
6
|
"author": {
|
|
7
7
|
"email": "me@yunyoujun.cn",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"@unhead/bundler": "^3.4.1",
|
|
80
80
|
"@unhead/schema-org": "^3.4.1",
|
|
81
81
|
"@unhead/vue": "^3.4.1",
|
|
82
|
-
"@valaxyjs/devtools": "1.
|
|
83
|
-
"@valaxyjs/utils": "1.
|
|
82
|
+
"@valaxyjs/devtools": "1.5.0",
|
|
83
|
+
"@valaxyjs/utils": "1.5.0",
|
|
84
84
|
"@vitejs/devtools": "0.8.0",
|
|
85
85
|
"@vitejs/plugin-vue": "^6.0.9",
|
|
86
86
|
"@vueuse/core": "^15.0.0",
|