mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 17:27:22 +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>
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
var packNumber = require('./Number').pack;
|
|
var MATH_FUNCTIONS = {
|
|
'calc': true,
|
|
'min': true,
|
|
'max': true,
|
|
'clamp': true
|
|
};
|
|
var LENGTH_UNIT = {
|
|
// absolute length units
|
|
'px': true,
|
|
'mm': true,
|
|
'cm': true,
|
|
'in': true,
|
|
'pt': true,
|
|
'pc': true,
|
|
|
|
// relative length units
|
|
'em': true,
|
|
'ex': true,
|
|
'ch': true,
|
|
'rem': true,
|
|
|
|
// viewport-percentage lengths
|
|
'vh': true,
|
|
'vw': true,
|
|
'vmin': true,
|
|
'vmax': true,
|
|
'vm': true
|
|
};
|
|
|
|
module.exports = function compressDimension(node, item) {
|
|
var value = packNumber(node.value, item);
|
|
|
|
node.value = value;
|
|
|
|
if (value === '0' && this.declaration !== null && this.atrulePrelude === null) {
|
|
var unit = node.unit.toLowerCase();
|
|
|
|
// only length values can be compressed
|
|
if (!LENGTH_UNIT.hasOwnProperty(unit)) {
|
|
return;
|
|
}
|
|
|
|
// issue #362: shouldn't remove unit in -ms-flex since it breaks flex in IE10/11
|
|
// issue #200: shouldn't remove unit in flex since it breaks flex in IE10/11
|
|
if (this.declaration.property === '-ms-flex' ||
|
|
this.declaration.property === 'flex') {
|
|
return;
|
|
}
|
|
|
|
// issue #222: don't remove units inside calc
|
|
if (this.function && MATH_FUNCTIONS.hasOwnProperty(this.function.name)) {
|
|
return;
|
|
}
|
|
|
|
item.data = {
|
|
type: 'Number',
|
|
loc: node.loc,
|
|
value: value
|
|
};
|
|
}
|
|
};
|