source: trip-planner-front/node_modules/icss-utils/src/createICSSRules.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1const createImports = (imports, postcss, mode = "rule") => {
2 return Object.keys(imports).map((path) => {
3 const aliases = imports[path];
4 const declarations = Object.keys(aliases).map((key) =>
5 postcss.decl({
6 prop: key,
7 value: aliases[key],
8 raws: { before: "\n " },
9 })
10 );
11
12 const hasDeclarations = declarations.length > 0;
13
14 const rule =
15 mode === "rule"
16 ? postcss.rule({
17 selector: `:import('${path}')`,
18 raws: { after: hasDeclarations ? "\n" : "" },
19 })
20 : postcss.atRule({
21 name: "icss-import",
22 params: `'${path}'`,
23 raws: { after: hasDeclarations ? "\n" : "" },
24 });
25
26 if (hasDeclarations) {
27 rule.append(declarations);
28 }
29
30 return rule;
31 });
32};
33
34const createExports = (exports, postcss, mode = "rule") => {
35 const declarations = Object.keys(exports).map((key) =>
36 postcss.decl({
37 prop: key,
38 value: exports[key],
39 raws: { before: "\n " },
40 })
41 );
42
43 if (declarations.length === 0) {
44 return [];
45 }
46 const rule =
47 mode === "rule"
48 ? postcss.rule({
49 selector: `:export`,
50 raws: { after: "\n" },
51 })
52 : postcss.atRule({
53 name: "icss-export",
54 raws: { after: "\n" },
55 });
56
57 rule.append(declarations);
58
59 return [rule];
60};
61
62const createICSSRules = (imports, exports, postcss, mode) => [
63 ...createImports(imports, postcss, mode),
64 ...createExports(exports, postcss, mode),
65];
66
67module.exports = createICSSRules;
Note: See TracBrowser for help on using the repository browser.