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.
56 lines
1.3 KiB
56 lines
1.3 KiB
var packNumber = require('./Number').pack;
|
|
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 && this.function.name === 'calc') {
|
|
return;
|
|
}
|
|
|
|
item.data = {
|
|
type: 'Number',
|
|
loc: node.loc,
|
|
value: value
|
|
};
|
|
}
|
|
};
|
|
|