Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
935 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | import postcss from 'postcss';
|
---|
| 2 |
|
---|
| 3 | const mediaRegExp = /^media$/i;
|
---|
| 4 | const prefersInterfaceRegExp = /\(\s*prefers-color-scheme\s*:\s*(dark|light|no-preference)\s*\)/i;
|
---|
| 5 | const colorIndexByStyle = {
|
---|
| 6 | dark: 48,
|
---|
| 7 | light: 70,
|
---|
| 8 | 'no-preference': 22
|
---|
| 9 | };
|
---|
| 10 |
|
---|
| 11 | const prefersInterfaceReplacer = ($0, style) => `(color-index: ${colorIndexByStyle[style.toLowerCase()]})`;
|
---|
| 12 |
|
---|
| 13 | var postcss$1 = postcss.plugin('postcss-prefers-color-scheme', opts => {
|
---|
| 14 | const preserve = 'preserve' in Object(opts) ? opts.preserve : true;
|
---|
| 15 | return root => {
|
---|
| 16 | root.walkAtRules(mediaRegExp, atRule => {
|
---|
| 17 | const params = atRule.params;
|
---|
| 18 | const altParams = params.replace(prefersInterfaceRegExp, prefersInterfaceReplacer);
|
---|
| 19 |
|
---|
| 20 | if (params !== altParams) {
|
---|
| 21 | if (preserve) {
|
---|
| 22 | atRule.cloneBefore({
|
---|
| 23 | params: altParams
|
---|
| 24 | });
|
---|
| 25 | } else {
|
---|
| 26 | atRule.params = altParams;
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 | });
|
---|
| 30 | };
|
---|
| 31 | });
|
---|
| 32 |
|
---|
| 33 | export default postcss$1;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.