Skip to content

Commit

Permalink
Merge pull request #332 from peterramsing/99-percent
Browse files Browse the repository at this point in the history
Adds rounder feature
  • Loading branch information
peterramsing authored Nov 6, 2016
2 parents 6bcee6f + ad96d41 commit 2097644
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 24 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Change Log
All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

## [v8.0.0-beta.1] - 2016-11-05
### Added
- Global and local configuration for setting the "rounder". The default is 99.9% but this can be adapted with a global `@ rounder [insert percent here]` or you can do it on the local level with `lost-column-rounder: 100` rule.

### Fixed
- Issue where 99.9 pixels could cause issues. You can now use the custom rounder to fine-tune your width to remove pixel rounding issues.


## [v8.0.0-beta.0] - 2016-10-18
### Changed
- ([#184](https://github.com/peterramsing/lost/issues/184))[API Change] Changes the lost-offset to be more intuitive.
This reverses the current api from moving left to right based on negative fractions which didn’t make much sense. This breaks that api’s current functionality and makes it more intuitive.
3 changes: 3 additions & 0 deletions lib/lost-at-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module.exports = function lostAtRule(css, Settings) {
if (rule.params[0] === 'flexbox') {
settings.flexbox = rule.params[1];
}
if (rule.params[0] === 'rounder') {
settings.rounder = rule.params[1];
}
if (rule.params[0] === 'cycle') {
if (rule.params[1] !== 'auto') {
if (rule.params[1] === 'none' || rule.params[1] === '0') {
Expand Down
13 changes: 11 additions & 2 deletions lib/lost-column.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = function lostColumnDecl(css, settings) {
var declArr = [];
var lostColumn;
var lostColumnCycle;
var lostColumnRounder = settings.rounder;
var lostColumnGutter = settings.gutter;
var lostColumnFlexbox = settings.flexbox;

Expand Down Expand Up @@ -78,6 +79,14 @@ module.exports = function lostColumnDecl(css, settings) {
}
});

decl.parent.nodes.forEach(function lostColumnRounderFunction(declaration) {
if (declaration.prop === 'lost-column-rounder') {
lostColumnRounder = declaration.value;

declaration.remove();
}
});

decl.parent.nodes.forEach(function lostColumnGutterFunction(declaration) {
if (declaration.prop === 'lost-column-gutter') {
lostColumnGutter = declaration.value;
Expand Down Expand Up @@ -175,14 +184,14 @@ module.exports = function lostColumnDecl(css, settings) {
if (lostColumnGutter !== '0') {
decl.cloneBefore({
prop: 'width',
value: 'calc(99.9% * '
value: 'calc(' + lostColumnRounder + '% * '
+ lostColumn + ' - (' + lostColumnGutter + ' - '
+ lostColumnGutter + ' * ' + lostColumn + '))'
});
} else {
decl.cloneBefore({
prop: 'width',
value: 'calc(99.9% * ' + lostColumn + ')'
value: 'calc(' + lostColumnRounder + '% * ' + lostColumn + ')'
});
}
} else {
Expand Down
20 changes: 18 additions & 2 deletions lib/lost-masonry-column.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function lostMasonryColumnDecl(css, settings) {
css.walkDecls('lost-masonry-column', function lostMasonryColumnFunction(decl) {
var declArr = [];
var lostMasonryColumn;
var lostMasonryColumnRounder = settings.rounder;
var lostMasonryColumnFlexbox = settings.flexbox;
var lostMasonryColumnGutter = settings.gutter;
var lostMasonryColumnGutterUnit;
Expand Down Expand Up @@ -54,14 +55,28 @@ module.exports = function lostMasonryColumnDecl(css, settings) {
lostMasonryColumnFlexbox = 'no-flex';
}

decl.parent.nodes.forEach(function lostMasonryColumnRounderFunction(declaration) {
if (declaration.prop === 'lost-masonry-column-rounder') {
lostMasonryColumnRounder = declaration.value;

declaration.remove();
}
});

decl.parent.nodes.forEach(function lostMasonryColumnGutterFunction(declaration) {
if (declaration.prop === 'lost-masonry-column-gutter') {
lostMasonryColumnGutter = declaration.value;

declaration.remove();
}
});
decl.parent.nodes.forEach(function lostMasonryColumnRounderFunction(declaration) {
if (declaration.prop === 'lost-rounder') {
lostMasonryColumnRounder = declaration.value;

declaration.remove();
}
});
decl.parent.nodes.forEach(function lostMasonryColumnFlexboxFunction(declaration) {
if (declaration.prop === 'lost-masonry-column-flexbox') {
if (declaration.value === 'flex') {
Expand All @@ -88,13 +103,14 @@ module.exports = function lostMasonryColumnDecl(css, settings) {

if (lostMasonryColumnGutter !== '0') {
cloneAllBefore({
width: 'calc(99.9% * ' + lostMasonryColumn + ' - ' + lostMasonryColumnGutter + ')',
width: 'calc(' + lostMasonryColumnRounder + '% * ' + lostMasonryColumn +
' - ' + lostMasonryColumnGutter + ')',
'margin-left': (parseInt(lostMasonryColumnGutter, 10) / 2) + lostMasonryColumnGutterUnit,
'margin-right': (parseInt(lostMasonryColumnGutter, 10) / 2) + lostMasonryColumnGutterUnit
});
} else {
cloneAllBefore({
width: 'calc(99.9% * ' + lostMasonryColumn + ')',
width: 'calc(' + lostMasonryColumnRounder + '% * ' + lostMasonryColumn + ')',
'margin-left': (parseInt(lostMasonryColumnGutter, 10) / 2) + lostMasonryColumnGutterUnit,
'margin-right': (parseInt(lostMasonryColumnGutter, 10) / 2) + lostMasonryColumnGutterUnit
});
Expand Down
17 changes: 13 additions & 4 deletions lib/lost-move.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = function lostMoveDecl(css, settings) {
var declArr = [];
var lostMove;
var lostMoveDirection;
var lostMoveRounder = settings.rounder;
var lostMoveGutter = settings.gutter;

declArr = decl.value.split(' ');
Expand All @@ -39,6 +40,14 @@ module.exports = function lostMoveDecl(css, settings) {
lostMoveGutter = declArr[2];
}

decl.parent.nodes.forEach(function lostMoveRounderFunction(declaration) {
if (declaration.prop === 'lost-move-rounder') {
lostMoveRounder = declaration.value;

declaration.remove();
}
});

decl.parent.nodes.forEach(function lostMoveDirectionFunction(declaration) {
if (declaration.prop === 'lost-move-direction') {
lostMoveDirection = declaration.value;
Expand All @@ -64,27 +73,27 @@ module.exports = function lostMoveDecl(css, settings) {
if (lostMoveGutter !== '0') {
decl.cloneBefore({
prop: 'top',
value: 'calc(99.9% * '
value: 'calc(' + lostMoveRounder + '% * '
+ lostMove + ' - (' + lostMoveGutter + ' - '
+ lostMoveGutter + ' * ' + lostMove + ') + ' + lostMoveGutter + ')'
});
} else {
decl.cloneBefore({
prop: 'top',
value: 'calc(99.999999% * ' + lostMove + ')'
value: 'calc(' + lostMoveRounder + '% * ' + lostMove + ')'
});
}
} else if (lostMoveGutter !== '0') {
decl.cloneBefore({
prop: 'left',
value: 'calc(99.9% * '
value: 'calc(' + lostMoveRounder + '% * '
+ lostMove + ' - (' + lostMoveGutter + ' - '
+ lostMoveGutter + ' * ' + lostMove + ') + ' + lostMoveGutter + ')'
});
} else {
decl.cloneBefore({
prop: 'left',
value: 'calc(99.999999% * ' + lostMove + ')'
value: 'calc(' + lostMoveRounder + '% * ' + lostMove + ')'
});
}

Expand Down
25 changes: 17 additions & 8 deletions lib/lost-offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function lostOffsetDecl(css, settings) {
var lostOffset;
var lostOffsetNumerator;
var lostOffsetDirection;
var lostOffsetRounder = settings.rounder;
var lostOffsetGutter = settings.gutter;

function cloneAllBefore(props) {
Expand All @@ -50,6 +51,14 @@ module.exports = function lostOffsetDecl(css, settings) {
lostOffsetGutter = declArr[2];
}

decl.parent.nodes.forEach(function lostOffsetRounderFunction(declaration) {
if (declaration.prop === 'lost-offset-rounder') {
lostOffsetRounder = declaration.value;

declaration.remove();
}
});

decl.parent.nodes.forEach(function lostOffsetDirectionFunction(declaration) {
if (declaration.prop === 'lost-offset-direction') {
lostOffsetDirection = declaration.value;
Expand All @@ -71,30 +80,30 @@ module.exports = function lostOffsetDecl(css, settings) {
if (lostOffsetGutter !== '0') {
decl.cloneBefore({
prop: 'margin-bottom',
value: 'calc(99.9% * '
value: 'calc(' + lostOffsetRounder + '% * '
+ lostOffset + ' - (' + lostOffsetGutter + ' - '
+ lostOffsetGutter + ' * ' + lostOffset + ') + ('
+ lostOffsetGutter + ' * 2)) !important'
});
} else {
decl.cloneBefore({
prop: 'margin-bottom',
value: 'calc(99.999999% * ' + lostOffset + ') !important'
value: 'calc(' + lostOffsetRounder + '% * ' + lostOffset + ') !important'
});
}
} else if (lostOffsetNumerator < 0) {
if (lostOffsetGutter !== '0') {
decl.cloneBefore({
prop: 'margin-top',
value: 'calc(99.9% * ('
value: 'calc(' + lostOffsetRounder + '% * ('
+ lostOffset + ' * -1) - (' + lostOffsetGutter + ' - '
+ lostOffsetGutter + ' * (' + lostOffset + ' * -1)) + '
+ lostOffsetGutter + ') !important'
});
} else {
decl.cloneBefore({
prop: 'margin-top',
value: 'calc(99.999999% * ' + lostOffset + ') !important'
value: 'calc(' + lostOffsetRounder + '% * ' + lostOffset + ') !important'
});
}
} else {
Expand All @@ -112,30 +121,30 @@ module.exports = function lostOffsetDecl(css, settings) {
if (lostOffsetGutter !== '0') {
decl.cloneBefore({
prop: 'margin-left',
value: 'calc(99.9% * (-'
value: 'calc(' + lostOffsetRounder + '% * (-'
+ lostOffset + ' * -1) - (' + lostOffsetGutter + ' - '
+ lostOffsetGutter + ' * (-' + lostOffset + ' * -1)) + '
+ lostOffsetGutter + ') !important'
});
} else {
decl.cloneBefore({
prop: 'margin-left',
value: 'calc(99.999999% * ' + lostOffset + ') !important'
value: 'calc(' + lostOffsetRounder + '% * ' + lostOffset + ') !important'
});
}
} else if (lostOffsetNumerator < 0) {
if (lostOffsetGutter !== '0') {
decl.cloneBefore({
prop: 'margin-left',
value: 'calc(99.9% * '
value: 'calc(' + lostOffsetRounder + '% * '
+ lostOffset + ' - (' + lostOffsetGutter + ' - '
+ lostOffsetGutter + ' * ' + lostOffset + ') + '
+ lostOffsetGutter + ') !important'
});
} else {
decl.cloneBefore({
prop: 'margin-left',
value: 'calc(99.999999% * ' + lostOffset + ') !important'
value: 'calc(' + lostOffsetRounder + '% * ' + lostOffset + ') !important'
});
}
} else {
Expand Down
13 changes: 11 additions & 2 deletions lib/lost-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function lostRowDecl(css, settings) {
css.walkDecls('lost-row', function lostRowDeclFunction(decl) {
var declArr = [];
var lostRow;
var lostRowRounder = settings.rounder;
var lostRowGutter = settings.gutter;
var lostRowFlexbox = settings.flexbox;

Expand All @@ -49,6 +50,14 @@ module.exports = function lostRowDecl(css, settings) {
lostRowFlexbox = 'no-flex';
}

decl.parent.nodes.forEach(function lostRowRounderFunction(declaration) {
if (declaration.prop === 'lost-row-rounder') {
lostRowRounder = declaration.value;

declaration.remove();
}
});

decl.parent.nodes.forEach(function lostRowGutterFunction(declaration) {
if (declaration.prop === 'lost-row-gutter') {
lostRowGutter = declaration.value;
Expand Down Expand Up @@ -82,14 +91,14 @@ module.exports = function lostRowDecl(css, settings) {
if (lostRowGutter !== '0') {
decl.cloneBefore({
prop: 'height',
value: 'calc(99.9% * '
value: 'calc(' + lostRowRounder + '% * '
+ lostRow + ' - (' + lostRowGutter + ' - '
+ lostRowGutter + ' * ' + lostRow + '))'
});
} else {
decl.cloneBefore({
prop: 'height',
value: 'calc(99.9% * ' + lostRow + ')'
value: 'calc(' + lostRowRounder + '% * ' + lostRow + ')'
});
}

Expand Down
16 changes: 12 additions & 4 deletions lib/lost-waffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = function lostWaffleDecl(css, settings) {
var declArr = [];
var lostWaffle;
var lostWaffleCycle;
var lostWaffleRounder = settings.rounder;
var lostWaffleGutter = settings.gutter;
var lostWaffleFlexbox = settings.flexbox;

Expand Down Expand Up @@ -77,6 +78,13 @@ module.exports = function lostWaffleDecl(css, settings) {
lostWaffleFlexbox = 'no-flex';
}

decl.parent.nodes.forEach(function lostWaffleRounderFunction(declaration) {
if (declaration.prop === 'lost-waffle-rounder') {
lostWaffleRounder = declaration.value;
declaration.remove();
}
});

decl.parent.nodes.forEach(function lostWaffleCycleFunction(declaration) {
if (declaration.prop === 'lost-waffle-cycle') {
lostWaffleCycle = declaration.value;
Expand Down Expand Up @@ -188,17 +196,17 @@ module.exports = function lostWaffleDecl(css, settings) {

if (lostWaffleGutter !== '0') {
cloneAllBefore({
width: 'calc(99.9% * '
width: 'calc(' + lostWaffleRounder + '% * '
+ lostWaffle + ' - (' + lostWaffleGutter + ' - '
+ lostWaffleGutter + ' * ' + lostWaffle + '))',
height: 'calc(99.9% * ' + lostWaffle + ' - ('
height: 'calc(' + lostWaffleRounder + '% * ' + lostWaffle + ' - ('
+ lostWaffleGutter + ' - ' + lostWaffleGutter + ' * '
+ lostWaffle + '))'
});
} else {
cloneAllBefore({
width: 'calc(99.9% * ' + lostWaffle + ')',
height: 'calc(99.9% * ' + lostWaffle + ')'
width: 'calc(' + lostWaffleRounder + '% * ' + lostWaffle + ')',
height: 'calc(' + lostWaffleRounder + '% * ' + lostWaffle + ')'
});
}

Expand Down
3 changes: 2 additions & 1 deletion lost.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var defaultSettings = {
gutter: '30px',
flexbox: 'no-flex',
cycle: 'auto',
clearing: 'both'
clearing: 'both',
rounder: 99.9
};

module.exports = postcss.plugin('lost', function lost(settings) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lost",
"version": "8.0.0-beta.0",
"version": "8.0.0-beta.1",
"description": "LostGrid is a powerful grid system built in PostCSS that works with any preprocessor and even vanilla CSS.",
"main": "lost.js",
"repository": {
Expand Down
Loading

0 comments on commit 2097644

Please sign in to comment.