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