-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (32 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module.exports = (opts = {}) => {
let defaults = ['hidden', 'scroll', 'auto', 'inherit']
let skipped = Symbol('isSkipped') // skipped flag
let counter = Symbol('skippedCounter') // counter for test "isSkipped" optimization
opts = Array.isArray(opts) ? opts : defaults
function makeRuleOverflowTouch(decl) {
let rule = decl.parent;
rule[counter] = Number.isInteger(rule[counter]) ? rule[counter] : 0;
if (!rule[skipped]) {
if (opts.includes(decl.value)) {
let hasTouch = rule.some(i => i.prop === '-webkit-overflow-scrolling' )
if (!hasTouch) {
rule.append({
prop: '-webkit-overflow-scrolling',
value: 'touch'
})
}
rule[skipped] = true
rule[counter]++
}
}
}
return {
postcssPlugin: 'postcss-momentum-scrolling',
Declaration: {
'overflow': decl => makeRuleOverflowTouch(decl),
'overflow-x': decl => makeRuleOverflowTouch(decl),
'overflow-y': decl => makeRuleOverflowTouch(decl),
}
}
}
module.exports.postcss = true