Skip to content

Commit c8cb639

Browse files
janvennemannsgtcoolguy
authored andcommitted
fix: scroll behavior and css adjustments
1 parent b73996a commit c8cb639

File tree

18 files changed

+390
-139
lines changed

18 files changed

+390
-139
lines changed

packages/docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"@fortawesome/free-solid-svg-icons": "^5.13.1",
1717
"@vuepress/plugin-back-to-top": "1.5.2",
1818
"fs-extra": "^8.1.0",
19-
"vuepress": "^1.5.2",
19+
"vuepress": "^1.6.0",
2020
"vuepress-plugin-apidocs": "^4.8.1",
2121
"vuepress-plugin-versioning": "^4.5.0",
2222
"vuepress-theme-titanium": "^4.8.0",
23-
"vuex": "^3.1.1",
23+
"vuex": "^3.5.1",
2424
"vuex-router-sync": "^5.0.0"
2525
}
2626
}

packages/vuepress/vuepress-plugin-apidocs/components/AvailabilityInfo.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ export default {
7070
margin-left: 0.8rem
7171
display flex
7272
flex-shrink 0
73+
align-items center
7374
7475
&>.platform-logo
7576
height 1rem
7677
width 1rem
77-
vertical-align top
7878
7979
&>span
80-
margin-left: 0.4rem
80+
margin-left: 0.25rem
8181
8282
@media (max-width: $MQMobile)
8383
.availability

packages/vuepress/vuepress-plugin-apidocs/global-components/ApiDocs.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ export default {
4646

4747
<style lang="stylus">
4848
.member-list
49-
& h2, h3, h4
50-
margin-top: -3.1rem;
51-
padding-top: 4.6rem;
52-
margin-bottom: 0;
53-
5449
.member-header
5550
display flex
51+
align-items center
5652
57-
&>h3, h4
53+
& > h3, h4
5854
flex-grow 1
59-
</style>
55+
margin-top 0
6056
57+
h1, h2, h3
58+
&:hover
59+
a
60+
opacity 1
61+
</style>

packages/vuepress/vuepress-plugin-apidocs/styles/main.styl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.type-meta
2-
margin-top 10px
32
>.type-meta-name
4-
font-size: 14px
3+
font-size: 0.75rem
54
color: #7f8c8d;
65
text-align right
76
>.type-meta-value
8-
margin: 0.5rem 0 0.9rem;
7+
font-size: 0.875rem
8+
margin: 0.5rem 0 0.875rem;
99
text-align right
1010
.type-metas
1111
&>:last-child
@@ -14,8 +14,8 @@
1414

1515
.type-signature
1616
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
17-
font-size: 0.85rem
18-
padding: 0.8rem 0.6rem
17+
font-size: 0.875rem
18+
padding: 0.875rem 0.75rem
1919
border-left 5px solid #eaecef
2020

2121
.content-loading

packages/vuepress/vuepress-theme-titanium/components/PageEdit.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ export default {
137137
.edit-link
138138
display inline-block
139139
a
140-
color lighten($textColor, 25%)
140+
color #006580
141141
margin-right 0.25rem
142142
.last-updated
143143
float right
144144
font-size 0.9em
145145
.prefix
146146
font-weight 500
147-
color lighten($textColor, 25%)
147+
color #006580
148148
.time
149149
font-weight 400
150150
color #aaa
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<template>
2+
<component
3+
:is="`h${level}`"
4+
>
5+
<a
6+
v-if="href"
7+
:href="href"
8+
class="header-anchor"
9+
@click="onClick"
10+
>
11+
#
12+
</a>
13+
14+
<slot />
15+
</component>
16+
</template>
17+
18+
<script>
19+
export default {
20+
props: {
21+
href: String,
22+
level: String
23+
},
24+
25+
methods: {
26+
onClick (e) {
27+
e.preventDefault()
28+
29+
const hash = this.href
30+
31+
if (this.hash === hash) return
32+
33+
this.$router.push({ hash })
34+
}
35+
}
36+
}
37+
</script>
38+
39+
<style lang="stylus">
40+
h1, h2, h3, h4, h5, h6
41+
> .header-anchor
42+
font-size 0.85em
43+
float left
44+
margin-left -0.87em
45+
padding-right 0.23em
46+
margin-top 0.125em
47+
opacity 0
48+
49+
&:hover
50+
text-decoration none
51+
52+
&:not(:hover):not(:focus)
53+
opacity: 0
54+
55+
.content:not(.custom) > &
56+
&:hover .header-anchor
57+
opacity: 1
58+
</style>

packages/vuepress/vuepress-theme-titanium/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = (options, ctx) => ({
2222
'@vuepress/nprogress',
2323
['container', { type: 'tip' }],
2424
['container', { type: 'warning' }],
25-
['container', { type: 'danger' }]
25+
['container', { type: 'danger' }],
26+
require('./plugins/smoothScroll')
2627
]
2728
})

packages/vuepress/vuepress-theme-titanium/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"lodash": "^4.17.15",
2121
"stylus": "^0.54.5",
2222
"stylus-loader": "^3.0.2",
23-
"vuepress-plugin-container": "^2.0.2",
24-
"vuepress-plugin-smooth-scroll": "^0.0.9"
23+
"vuepress-plugin-container": "^2.0.2"
2524
}
2625
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = function appHeading (md, options) {
2+
md.core.ruler.push('app-heading', state => {
3+
const slugs = {}
4+
const tokens = state.tokens
5+
tokens
6+
.filter(token => token.type === 'heading_open' || token.type === 'heading_close')
7+
.forEach(token => {
8+
token.tag = 'app-heading'
9+
if (token.type === 'heading_open') {
10+
const title = tokens[tokens.indexOf(token) + 1]
11+
.children
12+
.filter(token => token.type === 'text' || token.type === 'code_inline')
13+
.reduce((acc, t) => acc + t.content, '')
14+
let slug = token.attrGet('id')
15+
if (slug == null) {
16+
slug = uniqueSlug(slugify(title), slugs, false)
17+
} else {
18+
slug = uniqueSlug(slug, slugs, true)
19+
}
20+
token.attrSet('id', slug)
21+
token.attrSet('level', token.markup.split('').length)
22+
token.attrSet('href', `#${slug}`)
23+
}
24+
})
25+
})
26+
}
27+
28+
const slugify = (s) => encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'))
29+
const hasProp = Object.prototype.hasOwnProperty
30+
const uniqueSlug = (slug, slugs, failOnNonUnique) => {
31+
let uniq = slug
32+
let i = 1
33+
if (failOnNonUnique && hasProp.call(slugs, uniq)) {
34+
throw Error(`User defined id attribute '${slug}' is NOT unique. Please fix it in your markdown to continue.`)
35+
} else {
36+
while (hasProp.call(slugs, uniq)) uniq = `${slug}-${i++}`
37+
}
38+
slugs[uniq] = true
39+
return uniq
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const SCROLL_OFFSET = 75
2+
3+
// fork from vue-router@3.0.2
4+
// src/util/scroll.js
5+
function getElementPosition (el) {
6+
const docEl = document.documentElement
7+
const docRect = docEl.getBoundingClientRect()
8+
const elRect = el.getBoundingClientRect()
9+
return {
10+
x: elRect.left - docRect.left,
11+
y: elRect.top - docRect.top
12+
}
13+
}
14+
15+
module.exports = ({ Vue, options, router }) => {
16+
router.options.scrollBehavior = (to, from, savedPosition) => {
17+
if (savedPosition) {
18+
return window.scrollTo({
19+
top: savedPosition.y - SCROLL_OFFSET,
20+
behavior: 'smooth'
21+
})
22+
} else if (from.path === to.path && to.hash) {
23+
if (Vue.$vuepress.$get('disableScrollBehavior')) {
24+
return
25+
}
26+
const targetAnchor = to.hash
27+
const targetName = targetAnchor.slice(1)
28+
const targetElement =
29+
document.getElementById(targetName) ||
30+
document.querySelector(`[name=${targetName}]`)
31+
if (targetElement) {
32+
return window.scrollTo({
33+
top: getElementPosition(targetElement).y - SCROLL_OFFSET,
34+
behavior: 'smooth'
35+
})
36+
}
37+
} else {
38+
const html = document.querySelector('html')
39+
html.style.scrollBehavior = 'auto'
40+
window.scrollTo({ top: 0 })
41+
html.style.scrollBehavior = ''
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)