You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
import { List } from 'css-tree'; |
|
|
|
export default function compressBackground(node) { |
|
function flush() { |
|
if (!buffer.length) { |
|
buffer.unshift( |
|
{ |
|
type: 'Number', |
|
loc: null, |
|
value: '0' |
|
}, |
|
{ |
|
type: 'Number', |
|
loc: null, |
|
value: '0' |
|
} |
|
); |
|
} |
|
|
|
newValue.push.apply(newValue, buffer); |
|
|
|
buffer = []; |
|
} |
|
|
|
let newValue = []; |
|
let buffer = []; |
|
|
|
node.children.forEach((node) => { |
|
if (node.type === 'Operator' && node.value === ',') { |
|
flush(); |
|
newValue.push(node); |
|
return; |
|
} |
|
|
|
// remove defaults |
|
if (node.type === 'Identifier') { |
|
if (node.name === 'transparent' || |
|
node.name === 'none' || |
|
node.name === 'repeat' || |
|
node.name === 'scroll') { |
|
return; |
|
} |
|
} |
|
|
|
buffer.push(node); |
|
}); |
|
|
|
flush(); |
|
node.children = new List().fromArray(newValue); |
|
};
|
|
|