Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,271 additions
and
867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
{ | ||
"rules": { | ||
"no-unused-expressions": [0], | ||
"no-underscore-dangle": [0], | ||
"no-reserved-keys": [2], | ||
"no-multi-spaces": [0], | ||
"no-extra-parens": [2], | ||
"no-unused-vars": [2], | ||
"no-loop-func": [0], | ||
"key-spacing": [0], | ||
"max-len": [2], | ||
"strict": [0], | ||
"indent": [2], | ||
"quotes": [2, "single", "avoid-escape"], | ||
"curly": [0] | ||
}, | ||
"env": { | ||
"mocha": true, | ||
"node": true | ||
} | ||
"rules": { | ||
"no-unused-expressions": [0], | ||
"no-underscore-dangle": [0], | ||
"no-multi-spaces": [0], | ||
"no-extra-parens": [2], | ||
"no-unused-vars": [2], | ||
"no-loop-func": [0], | ||
"key-spacing": [0], | ||
"strict": [0], | ||
"indent": [2], | ||
"quotes": [2, "single", "avoid-escape"], | ||
"curly": [0] | ||
}, | ||
"env": { | ||
"mocha": true, | ||
"node": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
var postcss = require('postcss'); | ||
|
||
function shouldSetZeroBasis(basisValue) { | ||
if (!basisValue) { | ||
return false; | ||
} | ||
return basisValue === '0' || basisValue.replace(/\s/g, '') === '0px'; | ||
if (!basisValue) { | ||
return false; | ||
} | ||
return basisValue === '0' || basisValue.replace(/\s/g, '') === '0px'; | ||
} | ||
|
||
function properBasis(basis) { | ||
if (shouldSetZeroBasis(basis)) { | ||
return '0%'; | ||
} | ||
return 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); | ||
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
var postcss = require('postcss'); | ||
|
||
module.exports = function(decl) { | ||
if (decl.prop === 'flex') { | ||
var values = postcss.list.space(decl.value); | ||
var flexGrow = values[0]; | ||
var flexShrink = values[1] || '1'; | ||
var flexBasis = values[2] || '0%'; | ||
// Safari seems to hate '0%' and the others seems to make do with a nice value when basis is missing, | ||
// so if we see a '0%', just remove it. This way it'll get adjusted for any other cases where '0%' is | ||
// already defined somewhere else. | ||
if(flexBasis === '0%') flexBasis = null; | ||
decl.value = flexGrow + ' ' + flexShrink + (flexBasis ? ' ' + flexBasis : ''); | ||
} | ||
if (decl.prop === 'flex') { | ||
var values = postcss.list.space(decl.value); | ||
var flexGrow = values[0]; | ||
var flexShrink = values[1] || '1'; | ||
var flexBasis = values[2] || '0%'; | ||
// Safari seems to hate '0%' and the others seems to make do with a nice value when basis is missing, | ||
// so if we see a '0%', just remove it. This way it'll get adjusted for any other cases where '0%' is | ||
// already defined somewhere else. | ||
if (flexBasis === '0%') flexBasis = null; | ||
decl.value = | ||
flexGrow + ' ' + flexShrink + (flexBasis ? ' ' + flexBasis : ''); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
var postcss = require('postcss'); | ||
|
||
module.exports = function(decl) { | ||
var regex = /(\d{1,}) (\d{1,}) (calc\(.*?\))/g; | ||
var matches = regex.exec(decl.value); | ||
if (decl.prop === 'flex' && matches) { | ||
var grow = postcss.decl({ | ||
prop: 'flex-grow', | ||
value: matches[1], | ||
source: decl.source | ||
}); | ||
var shrink = postcss.decl({ | ||
prop: 'flex-shrink', | ||
value: matches[2], | ||
source: decl.source | ||
}); | ||
var basis = postcss.decl({ | ||
prop: 'flex-basis', | ||
value: matches[3], | ||
source: decl.source | ||
}); | ||
decl.parent.insertBefore(decl, grow); | ||
decl.parent.insertBefore(decl, shrink); | ||
decl.parent.insertBefore(decl, basis); | ||
decl.remove(); | ||
} | ||
var regex = /(\d{1,}) (\d{1,}) (calc\(.*?\))/g; | ||
var matches = regex.exec(decl.value); | ||
if (decl.prop === 'flex' && matches) { | ||
var grow = postcss.decl({ | ||
prop: 'flex-grow', | ||
value: matches[1], | ||
source: decl.source | ||
}); | ||
var shrink = postcss.decl({ | ||
prop: 'flex-shrink', | ||
value: matches[2], | ||
source: decl.source | ||
}); | ||
var basis = postcss.decl({ | ||
prop: 'flex-basis', | ||
value: matches[3], | ||
source: decl.source | ||
}); | ||
decl.parent.insertBefore(decl, grow); | ||
decl.parent.insertBefore(decl, shrink); | ||
decl.parent.insertBefore(decl, basis); | ||
decl.remove(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
var gulp = require('gulp'); | ||
|
||
function lint() { | ||
var eslint = require('gulp-eslint'); | ||
return gulp.src(['index.js', 'bugs/*.js', 'specs/*.js', 'gulpfile.js']) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
var eslint = require('gulp-eslint'); | ||
return gulp | ||
.src(['index.js', 'bugs/*.js', 'specs/*.js', 'gulpfile.js']) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
} | ||
|
||
function test() { | ||
var mocha = require('gulp-mocha'); | ||
return gulp.src('specs/*.js', { read: false }).pipe(mocha()); | ||
var mocha = require('gulp-mocha'); | ||
return gulp.src('specs/*.js', { read: false }).pipe(mocha()); | ||
} | ||
|
||
exports.default = gulp.series(lint, test); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.