source: trip-planner-front/node_modules/csso/lib/replace/property/background.js@ 188ee53

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

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1var List = require('css-tree').List;
2
3module.exports = function compressBackground(node) {
4 function lastType() {
5 if (buffer.length) {
6 return buffer[buffer.length - 1].type;
7 }
8 }
9
10 function flush() {
11 if (lastType() === 'WhiteSpace') {
12 buffer.pop();
13 }
14
15 if (!buffer.length) {
16 buffer.unshift(
17 {
18 type: 'Number',
19 loc: null,
20 value: '0'
21 },
22 {
23 type: 'WhiteSpace',
24 value: ' '
25 },
26 {
27 type: 'Number',
28 loc: null,
29 value: '0'
30 }
31 );
32 }
33
34 newValue.push.apply(newValue, buffer);
35
36 buffer = [];
37 }
38
39 var newValue = [];
40 var buffer = [];
41
42 node.children.each(function(node) {
43 if (node.type === 'Operator' && node.value === ',') {
44 flush();
45 newValue.push(node);
46 return;
47 }
48
49 // remove defaults
50 if (node.type === 'Identifier') {
51 if (node.name === 'transparent' ||
52 node.name === 'none' ||
53 node.name === 'repeat' ||
54 node.name === 'scroll') {
55 return;
56 }
57 }
58
59 // don't add redundant spaces
60 if (node.type === 'WhiteSpace' && (!buffer.length || lastType() === 'WhiteSpace')) {
61 return;
62 }
63
64 buffer.push(node);
65 });
66
67 flush();
68 node.children = new List().fromArray(newValue);
69};
Note: See TracBrowser for help on using the repository browser.