From 42da015abd87a1fb6e7609ffcfad1f7db892c2a7 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 17:03:48 +0500 Subject: [PATCH 01/11] 2-nd argument's adding feature ```
1
2
3
4
``` ``` /* CSS */ .child { lost-column: 1/3 3n+1; } .child:first-child { lost-offset: 1/3; } ``` Bad implementation but it's work. --- lib/lost-waffle.js | 88 +++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index 58784688..0ea65fd1 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -15,6 +15,9 @@ module.exports = function lostWaffleDecl(css, settings) { var lostWaffleFlexbox = settings.flexbox; var validUnits = ['%', 'vh', 'vw']; + var reg = /[+-]?(\d+)(n([+-]\d+)?)?/; + var start = ''; + function cloneAllBefore(props) { Object.keys(props).forEach(function traverseProps(prop) { decl.cloneBefore({ @@ -37,11 +40,7 @@ module.exports = function lostWaffleDecl(css, settings) { lostWaffleCycle = declArr[1]; } - if ( - declArr[1] === 'flex' || - declArr[1] === 'no-flex' || - declArr[1] === 'auto' - ) { + if (declArr[1] === 'flex' || declArr[1] === 'no-flex' || declArr[1] === 'auto') { lostWaffleCycle = declArr[0].split('/')[1]; } @@ -49,6 +48,16 @@ module.exports = function lostWaffleDecl(css, settings) { lostWaffleGutter = declArr[2]; } + if (reg.test(declArr[1])) { + var parse = reg.exec(declArr[1]) + var lostWaffleCycle = parse[1]; + start = parse[3]; + + if (start == null) { + start = ''; + } + } + if (declArr.indexOf('flex') !== -1) { lostWaffleFlexbox = 'flex'; } @@ -92,11 +101,7 @@ module.exports = function lostWaffleDecl(css, settings) { if (lgLogic.validateUnit(declaration.value, validUnits)) { unit = declaration.value; } else { - throw declaration.error( - `lost-unit: property ${ - declaration.value - } is not a valid unit for lost-waffle.` - ); + throw declaration.error(`lost-unit: property ${declaration.value} is not a valid unit for lost-waffle.`); } declaration.remove(); } @@ -107,9 +112,7 @@ module.exports = function lostWaffleDecl(css, settings) { if (declaration.value === 'flex') { lostWaffleFlexbox = 'flex'; } else { - throw declaration.error( - `lost-waffle-flexbox: property '${declaration.value}' is unknown.` - ); + throw declaration.error(`lost-waffle-flexbox: property '${declaration.value}' is unknown.`); } declaration.remove(); @@ -137,14 +140,14 @@ module.exports = function lostWaffleDecl(css, settings) { if (gridDirection === 'rtl') { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n)', + ':nth-child(' + lostWaffleCycle + 'n' + start + ')', ['margin-left', 'margin-right'], [0, 'auto'] ); } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n)', + ':nth-child(' + lostWaffleCycle + 'n' + start + ')', ['margin-right', 'margin-left'], [0, 'auto'] ); @@ -153,15 +156,16 @@ module.exports = function lostWaffleDecl(css, settings) { decl.cloneBefore({ prop: 'flex-basis', - value: lgLogic.calcValue( - lostWaffle, - lostWaffleGutter, - lostWaffleRounder - ) + value: lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder) }); if (gridDirection === 'rtl') { - newBlock(decl, ':last-child', ['margin-left', 'margin-bottom'], [0, 0]); + newBlock( + decl, + ':last-child', + ['margin-left', 'margin-bottom'], + [0, 0] + ); newBlock( decl, @@ -199,14 +203,14 @@ module.exports = function lostWaffleDecl(css, settings) { if (gridDirection === 'rtl') { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n + 1)', + ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')', ['clear'], ['right'] ); } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n + 1)', + ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')', ['clear'], ['left'] ); @@ -214,7 +218,7 @@ module.exports = function lostWaffleDecl(css, settings) { } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n + 1)', + ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')', ['clear'], ['both'] ); @@ -225,14 +229,14 @@ module.exports = function lostWaffleDecl(css, settings) { if (floatRight === true) { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n)', + ':nth-child(' + lostWaffleCycle + 'n' + start + ')', ['margin-left', 'float'], [0, 'left'] ); } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n)', + ':nth-child(' + lostWaffleCycle + 'n' + start + ')', ['margin-left'], [0] ); @@ -241,14 +245,14 @@ module.exports = function lostWaffleDecl(css, settings) { if (floatRight === true) { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n)', + ':nth-child(' + lostWaffleCycle + 'n' + start + ')', ['margin-right', 'float'], [0, 'right'] ); } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n)', + ':nth-child(' + lostWaffleCycle + 'n' + start + ')', ['margin-right'], [0] ); @@ -257,7 +261,12 @@ module.exports = function lostWaffleDecl(css, settings) { } if (gridDirection === 'rtl') { - newBlock(decl, ':last-child', ['margin-left', 'margin-bottom'], [0, 0]); + newBlock( + decl, + ':last-child', + ['margin-left', 'margin-bottom'], + [0, 0] + ); newBlock( decl, @@ -283,24 +292,9 @@ module.exports = function lostWaffleDecl(css, settings) { } cloneAllBefore({ - width: lgLogic.calcValue( - lostWaffle, - lostWaffleGutter, - lostWaffleRounder, - unit - ), - 'max-width': lgLogic.calcValue( - lostWaffle, - lostWaffleGutter, - lostWaffleRounder, - unit - ), - height: lgLogic.calcValue( - lostWaffle, - lostWaffleGutter, - lostWaffleRounder, - unit - ) + width: lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder, unit), + 'max-width': lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder, unit), + height: lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder, unit) }); decl.remove(); From a1fc3fbc2d34e48450baf31684d867c4a7730988 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 17:44:14 +0500 Subject: [PATCH 02/11] Update lost-waffle.js --- lib/lost-waffle.js | 70 ++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index 0ea65fd1..4a45b84a 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -40,7 +40,11 @@ module.exports = function lostWaffleDecl(css, settings) { lostWaffleCycle = declArr[1]; } - if (declArr[1] === 'flex' || declArr[1] === 'no-flex' || declArr[1] === 'auto') { + if ( + declArr[1] === 'flex' || + declArr[1] === 'no-flex' || + declArr[1] === 'auto' + ) { lostWaffleCycle = declArr[0].split('/')[1]; } @@ -49,8 +53,8 @@ module.exports = function lostWaffleDecl(css, settings) { } if (reg.test(declArr[1])) { - var parse = reg.exec(declArr[1]) - var lostWaffleCycle = parse[1]; + var parse = reg.exec(declArr[1]); + lostWaffleCycle = parse[1]; start = parse[3]; if (start == null) { @@ -101,7 +105,11 @@ module.exports = function lostWaffleDecl(css, settings) { if (lgLogic.validateUnit(declaration.value, validUnits)) { unit = declaration.value; } else { - throw declaration.error(`lost-unit: property ${declaration.value} is not a valid unit for lost-waffle.`); + throw declaration.error( + `lost-unit: property ${ + declaration.value + } is not a valid unit for lost-waffle.` + ); } declaration.remove(); } @@ -112,7 +120,9 @@ module.exports = function lostWaffleDecl(css, settings) { if (declaration.value === 'flex') { lostWaffleFlexbox = 'flex'; } else { - throw declaration.error(`lost-waffle-flexbox: property '${declaration.value}' is unknown.`); + throw declaration.error( + `lost-waffle-flexbox: property '${declaration.value}' is unknown.` + ); } declaration.remove(); @@ -156,16 +166,15 @@ module.exports = function lostWaffleDecl(css, settings) { decl.cloneBefore({ prop: 'flex-basis', - value: lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder) + value: lgLogic.calcValue( + lostWaffle, + lostWaffleGutter, + lostWaffleRounder + ) }); if (gridDirection === 'rtl') { - newBlock( - decl, - ':last-child', - ['margin-left', 'margin-bottom'], - [0, 0] - ); + newBlock(decl, ':last-child', ['margin-left', 'margin-bottom'], [0, 0]); newBlock( decl, @@ -200,17 +209,19 @@ module.exports = function lostWaffleDecl(css, settings) { if (settings.clearing === 'left') { // FIXME: this doesn't make sense w/ rtl /* istanbul ignore if */ + var selector = ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')'; + if (gridDirection === 'rtl') { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')', + selector, ['clear'], ['right'] ); } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')', + selector, ['clear'], ['left'] ); @@ -218,7 +229,7 @@ module.exports = function lostWaffleDecl(css, settings) { } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')', + selector, ['clear'], ['both'] ); @@ -261,12 +272,8 @@ module.exports = function lostWaffleDecl(css, settings) { } if (gridDirection === 'rtl') { - newBlock( - decl, - ':last-child', - ['margin-left', 'margin-bottom'], - [0, 0] - ); + + newBlock(decl, ':last-child', ['margin-left', 'margin-bottom'], [0, 0]); newBlock( decl, @@ -292,9 +299,24 @@ module.exports = function lostWaffleDecl(css, settings) { } cloneAllBefore({ - width: lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder, unit), - 'max-width': lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder, unit), - height: lgLogic.calcValue(lostWaffle, lostWaffleGutter, lostWaffleRounder, unit) + width: lgLogic.calcValue( + lostWaffle, + lostWaffleGutter, + lostWaffleRounder, + unit + ), + 'max-width': lgLogic.calcValue( + lostWaffle, + lostWaffleGutter, + lostWaffleRounder, + unit + ), + height: lgLogic.calcValue( + lostWaffle, + lostWaffleGutter, + lostWaffleRounder, + unit + ) }); decl.remove(); From c170fd0d3fb1cf10a727060d870b3c9054348b67 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 21:30:46 +0500 Subject: [PATCH 03/11] Update lost-waffle.js --- lib/lost-waffle.js | 93 ++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 62 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index 4a45b84a..b4a8dd78 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -9,15 +9,13 @@ module.exports = function lostWaffleDecl(css, settings) { var lostWaffle; var floatRight; var lostWaffleCycle; + var lostWaffleStart = ''; var unit = settings.gridUnit; var lostWaffleRounder = settings.rounder; var lostWaffleGutter = settings.gutter; var lostWaffleFlexbox = settings.flexbox; var validUnits = ['%', 'vh', 'vw']; - var reg = /[+-]?(\d+)(n([+-]\d+)?)?/; - var start = ''; - function cloneAllBefore(props) { Object.keys(props).forEach(function traverseProps(prop) { decl.cloneBefore({ @@ -36,6 +34,10 @@ module.exports = function lostWaffleDecl(css, settings) { declArr = decl.value.split(' '); lostWaffle = declArr[0]; + if (declArr[1] !== undefined && declArr[1].indexOf('/') !== -1) { + lostWaffleStart = declArr[1].split('/')[1]; + } + if (declArr[1] !== undefined && declArr[1].search(/^\d/) !== -1) { lostWaffleCycle = declArr[1]; } @@ -52,16 +54,6 @@ module.exports = function lostWaffleDecl(css, settings) { lostWaffleGutter = declArr[2]; } - if (reg.test(declArr[1])) { - var parse = reg.exec(declArr[1]); - lostWaffleCycle = parse[1]; - start = parse[3]; - - if (start == null) { - start = ''; - } - } - if (declArr.indexOf('flex') !== -1) { lostWaffleFlexbox = 'flex'; } @@ -129,6 +121,21 @@ module.exports = function lostWaffleDecl(css, settings) { } }); + var selectors = { + lastRow: ':nth-last-child(-n + ' + lostWaffleCycle + ')' + }; + + if (lostWaffleStart === '') { + selectors.lastChild = ':nth-child(' + lostWaffleCycle + 'n)'; + selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n + 1)'; + } else { + selectors.lastChild = ` + :nth-child(${lostWaffleCycle}n + ${lostWaffleStart})`; + selectors.firstChild = ` + :nth-child(${lostWaffleCycle}n + + ${(1 + lostWaffleStart) % lostWaffleCycle})`; + } + if (lostWaffleFlexbox === 'flex') { decl.cloneBefore({ prop: 'flex-grow', @@ -140,24 +147,19 @@ module.exports = function lostWaffleDecl(css, settings) { }); if (lostWaffleCycle !== 0) { - newBlock( - decl, - ':nth-last-child(-n + ' + lostWaffleCycle + ')', - ['margin-bottom'], - [0] - ); + newBlock(decl, selectors.lastRow, ['margin-bottom'], [0]); if (gridDirection === 'rtl') { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n' + start + ')', + selectors.lastChild, ['margin-left', 'margin-right'], [0, 'auto'] ); } else { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n' + start + ')', + selectors.lastChild, ['margin-right', 'margin-left'], [0, 'auto'] ); @@ -199,40 +201,18 @@ module.exports = function lostWaffleDecl(css, settings) { } } else { if (lostWaffleCycle !== 0) { - newBlock( - decl, - ':nth-last-child(-n + ' + lostWaffleCycle + ')', - ['margin-bottom'], - [0] - ); + newBlock(decl, selectors.lastRow, ['margin-bottom'], [0]); if (settings.clearing === 'left') { // FIXME: this doesn't make sense w/ rtl /* istanbul ignore if */ - var selector = ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + (start == null ? 0 : +start)) % lostWaffleCycle + ')'; - if (gridDirection === 'rtl') { - newBlock( - decl, - selector, - ['clear'], - ['right'] - ); + newBlock(decl, selectors.firstChild, ['clear'], ['right']); } else { - newBlock( - decl, - selector, - ['clear'], - ['left'] - ); + newBlock(decl, selectors.firstChild, ['clear'], ['left']); } } else { - newBlock( - decl, - selector, - ['clear'], - ['both'] - ); + newBlock(decl, selectors.firstChild, ['clear'], ['both']); } /* istanbul ignore if */ if (gridDirection === 'rtl') { @@ -240,39 +220,28 @@ module.exports = function lostWaffleDecl(css, settings) { if (floatRight === true) { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n' + start + ')', + selectors.lastChild, ['margin-left', 'float'], [0, 'left'] ); } else { - newBlock( - decl, - ':nth-child(' + lostWaffleCycle + 'n' + start + ')', - ['margin-left'], - [0] - ); + newBlock(decl, selectors.lastChild, ['margin-left'], [0]); } } else { if (floatRight === true) { newBlock( decl, - ':nth-child(' + lostWaffleCycle + 'n' + start + ')', + selectors.lastChild, ['margin-right', 'float'], [0, 'right'] ); } else { - newBlock( - decl, - ':nth-child(' + lostWaffleCycle + 'n' + start + ')', - ['margin-right'], - [0] - ); + newBlock(decl, selectors.lastChild, ['margin-right'], [0]); } } } if (gridDirection === 'rtl') { - newBlock(decl, ':last-child', ['margin-left', 'margin-bottom'], [0, 0]); newBlock( From 91aa594bff92569a3092f8e4795171025e5f583b Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 22:18:24 +0500 Subject: [PATCH 04/11] Update lost-waffle.js --- test/lost-waffle.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/lost-waffle.js b/test/lost-waffle.js index 5a80af12..226ddcce 100644 --- a/test/lost-waffle.js +++ b/test/lost-waffle.js @@ -236,4 +236,24 @@ describe('lost-waffle', function() { ); }); }); + + describe('supports start-indication', () => { + it('supports start-indication', () => { + check( + 'div { lost-waffle: 1/3 3/1 }', + 'div { width: calc(99.9% * 1/3 - (30px - 30px * 1/3));\n' + + 'max-width: calc(99.9% * 1/3 - (30px - 30px * 1/3));\n' + + 'height: calc(99.9% * 1/3 - (30px - 30px * 1/3)) }' + + 'div:nth-child(1n) { float:left;\n' + + 'margin-right: 30px;\n' + + 'margin-bottom: 30px;\n' + + 'clear:none }\n' + + 'div:last-child { margin-right: 0;\n' + + 'margin-bottom: 0 }\n' + + 'div:nth-child(3n+1) { margin-right: 0 }\n' + + 'div:nth-child(3n+2) { clear:both }\n' + + 'div:nth-last-child(-n+3){ margin-bottom:0 }' + ); + }); + }); }); From a6ff620e62d4046db135ab67acea7ec220fc15ac Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 22:34:41 +0500 Subject: [PATCH 05/11] Update lost-waffle.js --- lib/lost-waffle.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index b4a8dd78..2fac236b 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -122,6 +122,8 @@ module.exports = function lostWaffleDecl(css, settings) { }); var selectors = { + lastChild: '', + firstChild: '', lastRow: ':nth-last-child(-n + ' + lostWaffleCycle + ')' }; @@ -129,11 +131,11 @@ module.exports = function lostWaffleDecl(css, settings) { selectors.lastChild = ':nth-child(' + lostWaffleCycle + 'n)'; selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n + 1)'; } else { - selectors.lastChild = ` - :nth-child(${lostWaffleCycle}n + ${lostWaffleStart})`; - selectors.firstChild = ` - :nth-child(${lostWaffleCycle}n + - ${(1 + lostWaffleStart) % lostWaffleCycle})`; + selectors.lastChild = + ':nth-child(' + lostWaffleCycle + 'n + ' + lostWaffleStart + ')'; + selectors.firstChild = + ':nth-child(' + lostWaffleCycle + 'n + ' + + (1 + lostWaffleStart) % lostWaffleCycle +')'; } if (lostWaffleFlexbox === 'flex') { From a40577cdf6161b18d9c3792737d33a9643069724 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 22:35:25 +0500 Subject: [PATCH 06/11] Update lost-waffle.js --- lib/lost-waffle.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index 2fac236b..daf283da 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -122,8 +122,6 @@ module.exports = function lostWaffleDecl(css, settings) { }); var selectors = { - lastChild: '', - firstChild: '', lastRow: ':nth-last-child(-n + ' + lostWaffleCycle + ')' }; From 4e266a2cddc49ca5a27a56f45a3ef123a43720d9 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 22:58:58 +0500 Subject: [PATCH 07/11] Update lost-waffle.js --- lib/lost-waffle.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index daf283da..1e6556f0 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -9,7 +9,7 @@ module.exports = function lostWaffleDecl(css, settings) { var lostWaffle; var floatRight; var lostWaffleCycle; - var lostWaffleStart = ''; + var lostWaffleStart = 0; var unit = settings.gridUnit; var lostWaffleRounder = settings.rounder; var lostWaffleGutter = settings.gutter; @@ -35,7 +35,7 @@ module.exports = function lostWaffleDecl(css, settings) { lostWaffle = declArr[0]; if (declArr[1] !== undefined && declArr[1].indexOf('/') !== -1) { - lostWaffleStart = declArr[1].split('/')[1]; + lostWaffleStart = +declArr[1].split('/')[1]; } if (declArr[1] !== undefined && declArr[1].search(/^\d/) !== -1) { @@ -125,7 +125,7 @@ module.exports = function lostWaffleDecl(css, settings) { lastRow: ':nth-last-child(-n + ' + lostWaffleCycle + ')' }; - if (lostWaffleStart === '') { + if (lostWaffleStart === 0) { selectors.lastChild = ':nth-child(' + lostWaffleCycle + 'n)'; selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n + 1)'; } else { @@ -133,9 +133,14 @@ module.exports = function lostWaffleDecl(css, settings) { ':nth-child(' + lostWaffleCycle + 'n + ' + lostWaffleStart + ')'; selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n + ' + - (1 + lostWaffleStart) % lostWaffleCycle +')'; + (1 + lostWaffleStart) +')'; + + if (lostWaffleStart + 1 === lostWaffleCycle) { + selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n)'; + } } + if (lostWaffleFlexbox === 'flex') { decl.cloneBefore({ prop: 'flex-grow', From efcba5e0af319b344fa36faa196e69f5729ec871 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 23:05:39 +0500 Subject: [PATCH 08/11] Update lost-waffle.js --- test/lost-waffle.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/lost-waffle.js b/test/lost-waffle.js index 226ddcce..79da05b9 100644 --- a/test/lost-waffle.js +++ b/test/lost-waffle.js @@ -247,13 +247,28 @@ describe('lost-waffle', function() { 'div:nth-child(1n) { float:left;\n' + 'margin-right: 30px;\n' + 'margin-bottom: 30px;\n' + - 'clear:none }\n' + + 'clear: none }\n' + 'div:last-child { margin-right: 0;\n' + 'margin-bottom: 0 }\n' + 'div:nth-child(3n+1) { margin-right: 0 }\n' + 'div:nth-child(3n+2) { clear:both }\n' + 'div:nth-last-child(-n+3){ margin-bottom:0 }' ); + check( + 'div { lost-waffle: 1/3 3/2 }', + 'div { width: calc(99.9% * 1/3 - (30px - 30px * 1/3));\n' + + 'max-width: calc(99.9% * 1/3 - (30px - 30px * 1/3));\n' + + 'height: calc(99.9% * 1/3 - (30px - 30px * 1/3)) }' + + 'div:nth-child(1n) { float:left;\n' + + 'margin-right: 30px;\n' + + 'margin-bottom: 30px;\n' + + 'clear: none }\n' + + 'div:last-child { margin-right: 0;\n' + + 'margin-bottom: 0 }\n' + + 'div:nth-child(3n+2) { margin-right: 0 }\n' + + 'div:nth-child(3n) { clear:both }\n' + + 'div:nth-last-child(-n+3){ margin-bottom:0 }' + ); }); }); }); From 5f71f25eb96e5bbbf0e07cccb32774ccbde9ac33 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Sun, 14 Oct 2018 23:09:52 +0500 Subject: [PATCH 09/11] Update lost-waffle.js --- lib/lost-waffle.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index 1e6556f0..1d97a62a 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -132,15 +132,13 @@ module.exports = function lostWaffleDecl(css, settings) { selectors.lastChild = ':nth-child(' + lostWaffleCycle + 'n + ' + lostWaffleStart + ')'; selectors.firstChild = - ':nth-child(' + lostWaffleCycle + 'n + ' + - (1 + lostWaffleStart) +')'; + ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + lostWaffleStart) +')'; if (lostWaffleStart + 1 === lostWaffleCycle) { selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n)'; } } - if (lostWaffleFlexbox === 'flex') { decl.cloneBefore({ prop: 'flex-grow', From 701f9d6ad1f80a01a032c926ad1d28409c37918e Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Mon, 15 Oct 2018 15:45:42 +0500 Subject: [PATCH 10/11] Update lost-waffle.js --- lib/lost-waffle.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index 1d97a62a..60d87a9a 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -35,7 +35,7 @@ module.exports = function lostWaffleDecl(css, settings) { lostWaffle = declArr[0]; if (declArr[1] !== undefined && declArr[1].indexOf('/') !== -1) { - lostWaffleStart = +declArr[1].split('/')[1]; + lostWaffleStart = declArr[1].split('/')[1]; } if (declArr[1] !== undefined && declArr[1].search(/^\d/) !== -1) { @@ -122,6 +122,8 @@ module.exports = function lostWaffleDecl(css, settings) { }); var selectors = { + lastChild: '', + firstChild: '', lastRow: ':nth-last-child(-n + ' + lostWaffleCycle + ')' }; @@ -132,11 +134,15 @@ module.exports = function lostWaffleDecl(css, settings) { selectors.lastChild = ':nth-child(' + lostWaffleCycle + 'n + ' + lostWaffleStart + ')'; selectors.firstChild = - ':nth-child(' + lostWaffleCycle + 'n + ' + (1 + lostWaffleStart) +')'; + ':nth-child(' + + lostWaffleCycle + + 'n + ' + + ((1 + lostWaffleStart) % lostWaffleCycle) + + ')'; + } - if (lostWaffleStart + 1 === lostWaffleCycle) { - selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n)'; - } + if ((lostWaffleStart + 1) % lostWaffleCycle === 0) { + selectors.firstChild = ':nth-child(' + lostWaffleCycle + 'n)'; } if (lostWaffleFlexbox === 'flex') { From 046094c03677356fc6a9c078e0b8e569569cb7f3 Mon Sep 17 00:00:00 2001 From: Kan-Artem <39461306+Kan-Artem@users.noreply.github.com> Date: Mon, 15 Oct 2018 16:10:26 +0500 Subject: [PATCH 11/11] Update lost-waffle.js --- lib/lost-waffle.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/lost-waffle.js b/lib/lost-waffle.js index 60d87a9a..34688814 100644 --- a/lib/lost-waffle.js +++ b/lib/lost-waffle.js @@ -1,5 +1,4 @@ var newBlock = require('./new-block.js'); - var lgLogic = require('./_lg-logic'); module.exports = function lostWaffleDecl(css, settings) {