From 616616819926412a26d35dc07414b0006665e973 Mon Sep 17 00:00:00 2001 From: Tyler Gaw Date: Sat, 7 Oct 2017 12:45:31 -0400 Subject: [PATCH 1/3] Re-adds changes from #19 that we reverted in #33 --- lib/parse.js | 2 +- test/convert.js | 32 +++++++++++------ test/parse.js | 93 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 114 insertions(+), 13 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index efb0c35..10b2903 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -61,7 +61,7 @@ function parse (string) { */ function modifier () { - var m = match(/^([\+\-\*])/); + var m = match(/^([\+\-](?= )|\*)/); if (!m) return; var ret = {}; ret.type = 'modifier'; diff --git a/test/convert.js b/test/convert.js index 533f21d..5a5913f 100644 --- a/test/convert.js +++ b/test/convert.js @@ -150,12 +150,16 @@ describe('#convert', function () { convert('hsl(34, 50%, 50%) hue(25)', 'rgb(191, 117, 64)'); }); + it('should set hue with explicit positive', function () { + convert('hsl(34, 50%, 50%) hue(+25)', 'rgb(191, 117, 64)'); + }); + it('should set hue greater than 360', function () { convert('hsl(34, 50%, 50%) hue(385)', 'rgb(191, 117, 64)'); }); it('should set hue less than 360', function () { - convert('hsl(34, 50%, 50%) hue(-369)', 'rgb(191, 117, 64)'); + convert('hsl(34, 50%, 50%) hue(- 369)', 'rgb(191, 117, 64)'); }); it('should add hue', function () { @@ -188,7 +192,7 @@ describe('#convert', function () { convert('hsl(25, 25%, 50%) saturation(+ 25%)', 'rgb(191, 117, 64)'); }); - it('should substract saturation', function () { + it('should subtract saturation', function () { convert('hsl(25, 60%, 50%) saturation(- 10%)', 'rgb(191, 117, 64)'); }); @@ -206,7 +210,7 @@ describe('#convert', function () { convert('hsl(25, 50%, 25%) lightness(+ 25%)', 'rgb(191, 117, 64)'); }); - it('should substract lightness', function () { + it('should subtract lightness', function () { convert('hsl(25, 50%, 60%) lightness(- 10%)', 'rgb(191, 117, 64)'); }); @@ -220,12 +224,16 @@ describe('#convert', function () { convert('hwb(0, 0%, 0%) whiteness(20%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%) }); + it('should set whiteness with explicit positive', function () { + convert('hwb(0, 0%, 0%) whiteness(+20%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%) + }); + it('should add whiteness', function () { - convert('hwb(0, 75%, 0%) whiteness(+25%)', 'rgb(255, 255, 255)'); // hwb(0, 100%, 0%) + convert('hwb(0, 75%, 0%) whiteness(+ 25%)', 'rgb(255, 255, 255)'); // hwb(0, 100%, 0%) }); - it('should substract whiteness', function () { - convert('hwb(0, 30%, 0%) whiteness(-10%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%) + it('should subtract whiteness', function () { + convert('hwb(0, 30%, 0%) whiteness(- 10%)', 'rgb(255, 51, 51)'); // hwb(0, 20%, 0%) }); it('should multiply whiteness', function () { @@ -238,12 +246,16 @@ describe('#convert', function () { convert('hwb(0, 0%, 0%) blackness(20%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%) }); + it('should set blackness with explicit positive', function () { + convert('hwb(0, 0%, 0%) blackness(+20%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%) + }); + it('should add blackness', function () { - convert('hwb(0, 0%, 75%) blackness(+25%)', 'rgb(0, 0, 0)'); // hwb(0, 0%, 100%) + convert('hwb(0, 0%, 75%) blackness(+ 25%)', 'rgb(0, 0, 0)'); // hwb(0, 0%, 100%) }); - it('should substract blackness', function () { - convert('hwb(0, 0%, 30%) blackness(-10%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%) + it('should subtract blackness', function () { + convert('hwb(0, 0%, 30%) blackness(- 10%)', 'rgb(204, 0, 0)'); // hwb(0, 0%, 20%) }); it('should multiply blackness', function () { @@ -319,7 +331,7 @@ describe('#convert', function () { describe('nested color functions', function () { it('should convert nested color functions', function () { - convert('color(rebeccapurple a(-10%)) a(-10%)', 'rgba(102, 51, 153, 0.81)'); + convert('color(rebeccapurple a(- 10%)) a(- 10%)', 'rgba(102, 51, 153, 0.81)'); convert('color(#4C5859 shade(25%)) blend(color(#4C5859 shade(40%)) 20%)', 'rgb(55, 63, 64)'); }); }); diff --git a/test/parse.js b/test/parse.js index 097d6c2..5ddd9f4 100644 --- a/test/parse.js +++ b/test/parse.js @@ -191,7 +191,7 @@ describe('#parse', function () { }); it('should parse nested color functions', function () { - parse('color(hsl(0, 0%, 93%) l(-5%)) l(+10%)', { + parse('color(hsl(0, 0%, 93%) l(- 5%)) l(+ 10%)', { type: 'function', name: 'color', arguments: [ @@ -237,6 +237,95 @@ describe('#parse', function () { }); }); + it('should properly parse modifiers', function () { + parse('red a(+ 5%) a(+5%) a(- 5%) a(-5%) a(* 50%) a(*50%)', { + type: 'function', + name: 'color', + arguments: [ + { + type: 'color', + value: 'red', + }, + { + type: 'function', + name: 'a', + arguments: [ + { + type: 'modifier', + value: '+' + }, + { + type: 'number', + value: '5%' + } + ] + }, + { + type: 'function', + name: 'a', + arguments: [ + { + type: 'number', + value: '+5%' + } + ] + }, + { + type: 'function', + name: 'a', + arguments: [ + { + type: 'modifier', + value: '-' + }, + { + type: 'number', + value: '5%' + } + ] + }, + { + type: 'function', + name: 'a', + arguments: [ + { + type: 'number', + value: '-5%' + } + ] + }, + { + type: 'function', + name: 'a', + arguments: [ + { + type: 'modifier', + value: '*' + }, + { + type: 'number', + value: '50%' + } + ] + }, + { + type: 'function', + name: 'a', + arguments: [ + { + type: 'modifier', + value: '*' + }, + { + type: 'number', + value: '50%' + } + ] + } + ] + }); + }) + it('should throw on syntax error', function () { assert.throws(function () { @@ -246,7 +335,7 @@ describe('#parse', function () { it('should throw on syntax error for adjuster', function () { assert.throws(function () { - color.parse('color(red l(+5%)'); + color.parse('color(red l(+ 5%)'); }, /Missing closing parenthese for/); }); From 7c58cfd487f5426a65accc18a0b631600a531e5e Mon Sep 17 00:00:00 2001 From: Tyler Gaw Date: Sat, 7 Oct 2017 12:46:18 -0400 Subject: [PATCH 2/3] Bumps major version, updates History. --- History.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 0623d25..2e44308 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,7 @@ +2.0.0 - October 7, 2017 +----------------------- +* Require space after + and - in modifiers. See #19. + 1.3.3 - October 7, 2017 ----------------------- * REVERT RELEASE: This removes the changes made in `#19` only for this release. Those changes will be added back and released in a 2.0 because they are breaking changes. diff --git a/package.json b/package.json index c369285..96fba9a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "css-color-function", "repository": "git://github.com/ianstormtaylor/css-color-function.git", - "version": "1.3.3", + "version": "2.0.0", "license": "MIT", "description": "A parser and converter for Tab Atkins's proposed color function in CSS.", "keywords": [ From ccba7e8608a868ec5a804ddc0ef5c75dad8160dd Mon Sep 17 00:00:00 2001 From: Tyler Gaw Date: Wed, 11 Oct 2017 20:14:33 -0400 Subject: [PATCH 3/3] Removes history and version bump, do that elsewhere --- History.md | 4 ---- package.json | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/History.md b/History.md index 2e44308..0623d25 100644 --- a/History.md +++ b/History.md @@ -1,7 +1,3 @@ -2.0.0 - October 7, 2017 ------------------------ -* Require space after + and - in modifiers. See #19. - 1.3.3 - October 7, 2017 ----------------------- * REVERT RELEASE: This removes the changes made in `#19` only for this release. Those changes will be added back and released in a 2.0 because they are breaking changes. diff --git a/package.json b/package.json index 96fba9a..c369285 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "css-color-function", "repository": "git://github.com/ianstormtaylor/css-color-function.git", - "version": "2.0.0", + "version": "1.3.3", "license": "MIT", "description": "A parser and converter for Tab Atkins's proposed color function in CSS.", "keywords": [