You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
935 B
34 lines
935 B
4 years ago
|
import postcss from 'postcss';
|
||
|
|
||
|
const mediaRegExp = /^media$/i;
|
||
|
const prefersInterfaceRegExp = /\(\s*prefers-color-scheme\s*:\s*(dark|light|no-preference)\s*\)/i;
|
||
|
const colorIndexByStyle = {
|
||
|
dark: 48,
|
||
|
light: 70,
|
||
|
'no-preference': 22
|
||
|
};
|
||
|
|
||
|
const prefersInterfaceReplacer = ($0, style) => `(color-index: ${colorIndexByStyle[style.toLowerCase()]})`;
|
||
|
|
||
|
var postcss$1 = postcss.plugin('postcss-prefers-color-scheme', opts => {
|
||
|
const preserve = 'preserve' in Object(opts) ? opts.preserve : true;
|
||
|
return root => {
|
||
|
root.walkAtRules(mediaRegExp, atRule => {
|
||
|
const params = atRule.params;
|
||
|
const altParams = params.replace(prefersInterfaceRegExp, prefersInterfaceReplacer);
|
||
|
|
||
|
if (params !== altParams) {
|
||
|
if (preserve) {
|
||
|
atRule.cloneBefore({
|
||
|
params: altParams
|
||
|
});
|
||
|
} else {
|
||
|
atRule.params = altParams;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
});
|
||
|
|
||
|
export default postcss$1;
|