katoikia-app/web-ui/web-react/node_modules/postcss-flexbugs-fixes/bugs/bug4.js

45 lines
1021 B
JavaScript
Raw Normal View History

2022-07-06 04:15:11 +00:00
var postcss = require('postcss');
function shouldSetZeroBasis(basisValue) {
if (!basisValue) {
return false;
}
return basisValue === '0' || basisValue.replace(/\s/g, '') === '0px';
}
function properBasis(basis) {
if (shouldSetZeroBasis(basis)) {
return '0%';
}
return basis;
}
module.exports = function(decl) {
if (decl.prop === 'flex') {
var values = postcss.list.space(decl.value);
// set default values
var flexGrow = '0';
var flexShrink = '1';
var flexBasis = '0%';
if (values[0]) {
flexGrow = values[0];
}
if (values[1]) {
if (!isNaN(values[1])) {
flexShrink = values[1];
} else {
flexBasis = values[1];
}
}
if (values[2]) {
flexBasis = values[2];
}
decl.value = flexGrow + ' ' + flexShrink + ' ' + properBasis(flexBasis);
}
};