Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scroll-snap prefix support #286

Merged
merged 3 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Prefixer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {MS, MOZ, WEBKIT} from './Enum.js'
import {hash, charat, strlen, indexof, replace} from './Utility.js'
import { MS, MOZ, WEBKIT } from './Enum.js'
renbaoshuo marked this conversation as resolved.
Show resolved Hide resolved
import { hash, charat, strlen, indexof, replace } from './Utility.js'

/**
* @param {string} value
* @param {number} length
* @return {string}
*/
export function prefix (value, length) {
renbaoshuo marked this conversation as resolved.
Show resolved Hide resolved
export function prefix(value, length) {
switch (hash(value, length)) {
// color-adjust
case 5103:
Expand Down Expand Up @@ -113,6 +113,12 @@ export function prefix (value, length) {
}

return WEBKIT + value + MS + value + value
// scroll-snap-type
case 2903:
thysultan marked this conversation as resolved.
Show resolved Hide resolved
return WEBKIT + value + MS + value + value
// scroll-margin, scroll-margin-(top|right|bottom|left)
case 5719: case 2647: case 2135: case 3927: case 2391:
return replace(value, 'scroll-', 'scroll-snap-') + value
}

return value
Expand Down
9 changes: 9 additions & 0 deletions test/Prefixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,13 @@ describe('Prefixer', () => {
`animation-timing-function:cubic-bezier(0.1,0.7,1.0,0.1);`
].join(''))
})

test('scroll-snap', () => {
thysultan marked this conversation as resolved.
Show resolved Hide resolved
expect(prefix(`scroll-snap-type:none;`, 16)).to.equal([`-webkit-scroll-snap-type:none;`, `-ms-scroll-snap-type:none;`, `scroll-snap-type:none;`].join(''))
expect(prefix(`scroll-margin:0;`, 13)).to.equal([`scroll-snap-margin:0;`, `scroll-margin:0;`].join(''))
expect(prefix(`scroll-margin-top:0;`, 17)).to.equal([`scroll-snap-margin-top:0;`, `scroll-margin-top:0;`].join(''))
expect(prefix(`scroll-margin-right:0;`, 19)).to.equal([`scroll-snap-margin-right:0;`, `scroll-margin-right:0;`].join(''))
expect(prefix(`scroll-margin-bottom:0;`, 20)).to.equal([`scroll-snap-margin-bottom:0;`, `scroll-margin-bottom:0;`].join(''))
expect(prefix(`scroll-margin-left:0;`, 18)).to.equal([`scroll-snap-margin-left:0;`, `scroll-margin-left:0;`].join(''))
})
})