mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 02:08:24 +08:00
These packages will be used to dynamically optimize SVG images during the build. R=jacktfranklin@chromium.org Bug: 1216402 Change-Id: I04e95aa7d79c9d67beaf8a7861182c52b16b7d0f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2939992 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
module.exports = function compressFont(node) {
|
|
var list = node.children;
|
|
|
|
list.eachRight(function(node, item) {
|
|
if (node.type === 'Identifier') {
|
|
if (node.name === 'bold') {
|
|
item.data = {
|
|
type: 'Number',
|
|
loc: node.loc,
|
|
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 === 'WhiteSpace') {
|
|
if (!item.prev || !item.next || item.next.data.type === 'WhiteSpace') {
|
|
this.remove(item);
|
|
}
|
|
}
|
|
});
|
|
|
|
if (list.isEmpty()) {
|
|
list.insert(list.createItem({
|
|
type: 'Identifier',
|
|
name: 'normal'
|
|
}));
|
|
}
|
|
};
|