46 lines
1.2 KiB
JavaScript
Executable File
46 lines
1.2 KiB
JavaScript
Executable File
module.exports = function compressFont(node) {
|
|
var list = node.sequence;
|
|
|
|
list.eachRight(function(node, item) {
|
|
if (node.type === 'Identifier') {
|
|
if (node.name === 'bold') {
|
|
item.data = {
|
|
type: 'Number',
|
|
info: node.info,
|
|
value: '700'
|
|
};
|
|
} else if (node.name === 'normal') {
|
|
var prev = item.prev;
|
|
|
|
if (prev && prev.data.type === 'Operator' && prev.data.value === '/') {
|
|
this.remove(prev);
|
|
}
|
|
|
|
this.remove(item);
|
|
} else if (node.name === 'medium') {
|
|
var next = item.next;
|
|
|
|
if (!next || next.data.type !== 'Operator') {
|
|
this.remove(item);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// remove redundant spaces
|
|
list.each(function(node, item) {
|
|
if (node.type === 'Space') {
|
|
if (!item.prev || !item.next || item.next.data.type === 'Space') {
|
|
this.remove(item);
|
|
}
|
|
}
|
|
});
|
|
|
|
if (list.isEmpty()) {
|
|
list.insert(list.createItem({
|
|
type: 'Identifier',
|
|
name: 'normal'
|
|
}));
|
|
}
|
|
};
|