source: frontend/node_modules/stylehacks/src/index.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2const browserslist = require('browserslist');
3const plugins = require('./plugins');
4
5/** @typedef {{lint?: boolean}} Options */
6
7/**
8 * @type {import('postcss').PluginCreator<Options>}
9 * @param {Options} opts
10 * @return {import('postcss').Plugin}
11 */
12function pluginCreator(opts = {}) {
13 return {
14 postcssPlugin: 'stylehacks',
15
16 OnceExit(css, { result }) {
17 /** @type {typeof result.opts & browserslist.Options} */
18 const resultOpts = result.opts || {};
19 const browsers = browserslist(null, {
20 stats: resultOpts.stats,
21 path: __dirname,
22 env: resultOpts.env,
23 });
24
25 /** @type {import('./plugin').Plugin[]} */
26 const processors = [];
27 for (const Plugin of plugins) {
28 const hack = new Plugin(result);
29 if (!browsers.some((browser) => hack.targets.has(browser))) {
30 processors.push(hack);
31 }
32 }
33 css.walk((node) => {
34 processors.forEach((proc) => {
35 if (!proc.nodeTypes.has(node.type)) {
36 return;
37 }
38
39 if (opts.lint) {
40 return proc.detectAndWarn(node);
41 }
42
43 return proc.detectAndResolve(node);
44 });
45 });
46 },
47 };
48}
49
50/** @type {(node: import('postcss').Node) => boolean} */
51pluginCreator.detect = (node) => {
52 return plugins.some((Plugin) => {
53 const hack = new Plugin();
54
55 return hack.any(node);
56 });
57};
58
59pluginCreator.postcss = true;
60module.exports = pluginCreator;
Note: See TracBrowser for help on using the repository browser.