forked from csstools/postcss-custom-media
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·30 lines (23 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import postcss from 'postcss';
import getCustomMedia from './lib/custom-media-from-root';
import transformAtrules from './lib/transform-atrules';
import importCustomMediaFromSources from './lib/import-from';
import exportCustomMediaToDestinations from './lib/export-to';
export default postcss.plugin('postcss-custom-media', opts => {
// whether to preserve custom selectors and rules using them
const preserve = Boolean(Object(opts).preserve);
// sources to import custom selectors from
const importFrom = [].concat(Object(opts).importFrom || []);
// destinations to export custom selectors to
const exportTo = [].concat(Object(opts).exportTo || []);
// promise any custom selectors are imported
const customMediaPromise = importCustomMediaFromSources(importFrom);
return async root => {
const customMedia = Object.assign(
await customMediaPromise,
getCustomMedia(root, { preserve })
);
await exportCustomMediaToDestinations(customMedia, exportTo);
transformAtrules(root, customMedia, { preserve });
};
});