-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathpostcss.config.js
More file actions
37 lines (34 loc) · 1.44 KB
/
Copy pathpostcss.config.js
File metadata and controls
37 lines (34 loc) · 1.44 KB
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
31
32
33
34
35
36
37
// This is used to auto-prefix CSS, see: https://github.com/postcss/postcss-loader
const autoprefixer = require('autoprefixer');
const SCOPE_CLASS = '.bp-doc';
// Files whose selectors must be confined to the doc viewer DOM. Without this
// scoping, upstream selectors like `.sidebar` and `.toggleButton` collide with
// host-app selectors when the npm pdfjs path is used.
const SCOPE_FILE_RE = /pdfjs-dist[\\/]web[\\/]pdf_viewer\.css$/;
const scopePdfjsViewerCss = () => ({
postcssPlugin: 'scope-pdfjs-viewer-css',
Once(root, { result }) {
if (!SCOPE_FILE_RE.test(result.opts.from || '')) {
return;
}
root.walkRules(rule => {
// Skip rules nested in @keyframes — `from`/`to`/`50%` are not selectors.
if (rule.parent && rule.parent.type === 'atrule' && rule.parent.name === 'keyframes') {
return;
}
rule.selectors = rule.selectors.map(selector => {
const trimmed = selector.trim();
// `:root` is the document root; rewrite to our scope so custom
// properties declared there only apply inside the viewer.
if (trimmed === ':root') {
return SCOPE_CLASS;
}
return `${SCOPE_CLASS} ${trimmed}`;
});
});
},
});
scopePdfjsViewerCss.postcss = true;
module.exports = {
plugins: [scopePdfjsViewerCss(), autoprefixer()],
};