2021-11-16 18:01:06 +01:00
|
|
|
import { normalizeScreens } from '../util/normalizeScreens'
|
2017-10-06 10:09:37 -04:00
|
|
|
import buildMediaQuery from '../util/buildMediaQuery'
|
2017-10-05 20:20:43 -04:00
|
|
|
|
2021-05-19 11:46:50 -04:00
|
|
|
export default function ({ tailwindConfig: { theme } }) {
|
2020-10-16 13:30:06 -04:00
|
|
|
return function (css) {
|
2020-10-16 15:39:44 -04:00
|
|
|
css.walkAtRules('screen', (atRule) => {
|
2021-11-16 18:01:06 +01:00
|
|
|
let screen = atRule.params
|
|
|
|
|
let screens = normalizeScreens(theme.screens)
|
|
|
|
|
let screenDefinition = screens.find(({ name }) => name === screen)
|
2017-10-05 20:20:43 -04:00
|
|
|
|
2021-11-16 18:01:06 +01:00
|
|
|
if (!screenDefinition) {
|
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'
|
2021-11-16 18:01:06 +01:00
|
|
|
atRule.params = buildMediaQuery(screenDefinition)
|
2017-10-05 20:20:43 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|