2017-10-05 20:20:43 -04:00
|
|
|
import _ from 'lodash'
|
2017-10-06 10:09:37 -04:00
|
|
|
import buildMediaQuery from '../util/buildMediaQuery'
|
2017-10-05 20:20:43 -04:00
|
|
|
|
2017-11-03 09:54:15 -04:00
|
|
|
export default function(config) {
|
2017-10-05 20:20:43 -04:00
|
|
|
return function(css) {
|
2017-11-03 09:54:15 -04:00
|
|
|
const options = config()
|
2017-10-05 20:20:43 -04:00
|
|
|
|
2017-10-13 11:39:55 -04:00
|
|
|
css.walkAtRules('screen', atRule => {
|
|
|
|
|
const screen = atRule.params
|
2017-10-05 20:20:43 -04:00
|
|
|
|
2017-11-04 00:35:59 -05:00
|
|
|
if (!_.has(options.screens, screen)) {
|
2017-10-13 11:39:55 -04:00
|
|
|
throw atRule.error(`No \`${screen}\` screen found.`)
|
2017-10-05 20:20:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
atRule.name = 'media'
|
2017-10-13 11:39:55 -04:00
|
|
|
atRule.params = buildMediaQuery(options.screens[screen])
|
2017-10-05 20:20:43 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|