valaxy 0.15.5 → 0.15.6
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/styles/third/katex.scss +6 -0
- package/client/utils/index.ts +1 -0
- package/client/utils/router.ts +39 -0
- package/dist/{chunk-APBMT6DR.cjs → chunk-43XYAG2L.cjs} +32 -31
- package/dist/{chunk-URU76UTL.mjs → chunk-4TR5DCV6.mjs} +33 -32
- package/dist/node/cli.cjs +1 -1
- package/dist/node/cli.mjs +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.mjs +1 -1
- package/package.json +1 -1
package/client/utils/index.ts
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface ScrollToOptions {
|
|
2
|
+
smooth: boolean
|
|
3
|
+
targetPadding: number
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function scrollTo(el: HTMLElement, hash: string, options: Partial<ScrollToOptions> = {
|
|
7
|
+
smooth: true,
|
|
8
|
+
targetPadding: -64,
|
|
9
|
+
}) {
|
|
10
|
+
let target: Element | null = null
|
|
11
|
+
try {
|
|
12
|
+
target = el.classList.contains('header-anchor')
|
|
13
|
+
? el
|
|
14
|
+
: ((decodeURIComponent(hash) && document.querySelector(decodeURIComponent(hash))) || null)
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.warn(e)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (target) {
|
|
21
|
+
const targetPadding = options?.targetPadding || -64
|
|
22
|
+
const targetTop
|
|
23
|
+
= window.scrollY
|
|
24
|
+
+ (target as HTMLElement).getBoundingClientRect().top
|
|
25
|
+
+ targetPadding
|
|
26
|
+
|
|
27
|
+
// only smooth scroll if distance is smaller than screen height.
|
|
28
|
+
if (!options.smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) {
|
|
29
|
+
window.scrollTo(0, targetTop)
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
window.scrollTo({
|
|
33
|
+
// left: 0,
|
|
34
|
+
top: targetTop,
|
|
35
|
+
behavior: 'smooth',
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|