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.
@@ -1,3 +1,9 @@
1
+ .katex-display {
2
+ overflow-x: auto;
3
+ overflow-y: visible;
4
+ padding: 8px 0;
5
+ }
6
+
1
7
  .katex-display > .katex > .katex-html > .tag {
2
8
  right: 2px;
3
9
  }
@@ -4,3 +4,4 @@ export * from './time'
4
4
  export * from './wrap'
5
5
  export * from './types'
6
6
  export * from './content'
7
+ export * from './router'
@@ -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
+ }