Compare commits
13 commits
Author | SHA1 | Date | |
---|---|---|---|
Rafael Caricio | 92b6e8011e | ||
a3494b3421 | |||
330ffa92cd | |||
Rafael Caricio | cce801d1df | ||
Rafael Caricio | eff630c873 | ||
Rafael Caricio | c4ba2836b6 | ||
Rafael Caricio | 015088b929 | ||
4bfe95a98f | |||
Rafael Caricio | 04708dcb45 | ||
Rafael Caricio | 2720da021f | ||
12648a2a28 | |||
Rafael Caricio | 4b49f43244 | ||
d0e6c24616 |
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "gradient-parser",
|
||||
"version": "0.2.0",
|
||||
"version": "1.0.0",
|
||||
"main": "build/web.js",
|
||||
"ignore": [
|
||||
".editorconfig",
|
||||
|
|
|
@ -60,7 +60,14 @@ GradientParser.stringify = (function() {
|
|||
},
|
||||
|
||||
'visit_extent-keyword': function(node) {
|
||||
return node.value;
|
||||
var result = node.value,
|
||||
at = visitor.visit(node.at);
|
||||
|
||||
if (at) {
|
||||
result += ' at ' + at;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
'visit_position-keyword': function(node) {
|
||||
|
@ -135,6 +142,7 @@ GradientParser.stringify = (function() {
|
|||
if (!element) {
|
||||
return '';
|
||||
}
|
||||
var result = '';
|
||||
|
||||
if (element instanceof Array) {
|
||||
return visitor.visit_array(element, result);
|
||||
|
@ -257,7 +265,7 @@ GradientParser.parse = (function() {
|
|||
error('Missing (');
|
||||
}
|
||||
|
||||
result = callback(captures);
|
||||
var result = callback(captures);
|
||||
|
||||
if (!scan(tokens.endCall)) {
|
||||
error('Missing )');
|
||||
|
@ -310,12 +318,21 @@ GradientParser.parse = (function() {
|
|||
if (radialType) {
|
||||
radialType.at = matchAtPosition();
|
||||
} else {
|
||||
var defaultPosition = matchPositioning();
|
||||
if (defaultPosition) {
|
||||
radialType = {
|
||||
type: 'default-radial',
|
||||
at: defaultPosition
|
||||
};
|
||||
var extent = matchExtentKeyword();
|
||||
if (extent) {
|
||||
radialType = extent;
|
||||
var positionAt = matchAtPosition();
|
||||
if (positionAt) {
|
||||
radialType.at = positionAt;
|
||||
}
|
||||
} else {
|
||||
var defaultPosition = matchPositioning();
|
||||
if (defaultPosition) {
|
||||
radialType = {
|
||||
type: 'default-radial',
|
||||
at: defaultPosition
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
33
build/web.js
33
build/web.js
|
@ -100,7 +100,7 @@ GradientParser.parse = (function() {
|
|||
error('Missing (');
|
||||
}
|
||||
|
||||
result = callback(captures);
|
||||
var result = callback(captures);
|
||||
|
||||
if (!scan(tokens.endCall)) {
|
||||
error('Missing )');
|
||||
|
@ -153,12 +153,21 @@ GradientParser.parse = (function() {
|
|||
if (radialType) {
|
||||
radialType.at = matchAtPosition();
|
||||
} else {
|
||||
var defaultPosition = matchPositioning();
|
||||
if (defaultPosition) {
|
||||
radialType = {
|
||||
type: 'default-radial',
|
||||
at: defaultPosition
|
||||
};
|
||||
var extent = matchExtentKeyword();
|
||||
if (extent) {
|
||||
radialType = extent;
|
||||
var positionAt = matchAtPosition();
|
||||
if (positionAt) {
|
||||
radialType.at = positionAt;
|
||||
}
|
||||
} else {
|
||||
var defaultPosition = matchPositioning();
|
||||
if (defaultPosition) {
|
||||
radialType = {
|
||||
type: 'default-radial',
|
||||
at: defaultPosition
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,7 +409,14 @@ GradientParser.stringify = (function() {
|
|||
},
|
||||
|
||||
'visit_extent-keyword': function(node) {
|
||||
return node.value;
|
||||
var result = node.value,
|
||||
at = visitor.visit(node.at);
|
||||
|
||||
if (at) {
|
||||
result += ' at ' + at;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
'visit_position-keyword': function(node) {
|
||||
|
@ -475,6 +491,7 @@ GradientParser.stringify = (function() {
|
|||
if (!element) {
|
||||
return '';
|
||||
}
|
||||
var result = '';
|
||||
|
||||
if (element instanceof Array) {
|
||||
return visitor.visit_array(element, result);
|
||||
|
|
|
@ -11,7 +11,7 @@ GradientParser.parse = (function() {
|
|||
repeatingLinearGradient: /^(\-(webkit|o|ms|moz)\-)?(repeating\-linear\-gradient)/i,
|
||||
radialGradient: /^(\-(webkit|o|ms|moz)\-)?(radial\-gradient)/i,
|
||||
repeatingRadialGradient: /^(\-(webkit|o|ms|moz)\-)?(repeating\-radial\-gradient)/i,
|
||||
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|left|right|top|bottom)/i,
|
||||
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
||||
extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
|
||||
positionKeywords: /^(left|center|right|top|bottom)/i,
|
||||
pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
|
||||
|
@ -98,7 +98,7 @@ GradientParser.parse = (function() {
|
|||
error('Missing (');
|
||||
}
|
||||
|
||||
result = callback(captures);
|
||||
var result = callback(captures);
|
||||
|
||||
if (!scan(tokens.endCall)) {
|
||||
error('Missing )');
|
||||
|
@ -151,12 +151,21 @@ GradientParser.parse = (function() {
|
|||
if (radialType) {
|
||||
radialType.at = matchAtPosition();
|
||||
} else {
|
||||
var defaultPosition = matchPositioning();
|
||||
if (defaultPosition) {
|
||||
radialType = {
|
||||
type: 'default-radial',
|
||||
at: defaultPosition
|
||||
};
|
||||
var extent = matchExtentKeyword();
|
||||
if (extent) {
|
||||
radialType = extent;
|
||||
var positionAt = matchAtPosition();
|
||||
if (positionAt) {
|
||||
radialType.at = positionAt;
|
||||
}
|
||||
} else {
|
||||
var defaultPosition = matchPositioning();
|
||||
if (defaultPosition) {
|
||||
radialType = {
|
||||
type: 'default-radial',
|
||||
at: defaultPosition
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,14 @@ GradientParser.stringify = (function() {
|
|||
},
|
||||
|
||||
'visit_extent-keyword': function(node) {
|
||||
return node.value;
|
||||
var result = node.value,
|
||||
at = visitor.visit(node.at);
|
||||
|
||||
if (at) {
|
||||
result += ' at ' + at;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
'visit_position-keyword': function(node) {
|
||||
|
@ -135,6 +142,7 @@ GradientParser.stringify = (function() {
|
|||
if (!element) {
|
||||
return '';
|
||||
}
|
||||
var result = '';
|
||||
|
||||
if (element instanceof Array) {
|
||||
return visitor.visit_array(element, result);
|
||||
|
|
10999
package-lock.json
generated
Normal file
10999
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "gradient-parser",
|
||||
"version": "0.2.0",
|
||||
"version": "1.0.2",
|
||||
"description": "Parse CSS3 gradient definitions and return an AST.",
|
||||
"author": {
|
||||
"name": "Rafael Carcicio",
|
||||
|
@ -32,8 +32,8 @@
|
|||
"css3",
|
||||
"parser"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"expect.js": "*",
|
||||
"grunt": "*",
|
||||
"grunt-browserify": "^3.0.1",
|
||||
"grunt-complexity": "*",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var gradients = require('build/node');
|
||||
var gradients = require('../build/node');
|
||||
|
||||
|
||||
describe('lib/parser.js', function () {
|
||||
|
@ -134,7 +134,11 @@ describe('lib/parser.js', function () {
|
|||
describe('parse all linear directional', function() {
|
||||
[
|
||||
{type: 'angular', unparsedValue: '-145deg', value: '-145'},
|
||||
{type: 'directional', unparsedValue: 'to left top', value: 'left top'}
|
||||
{type: 'directional', unparsedValue: 'to left top', value: 'left top'},
|
||||
{type: 'directional', unparsedValue: 'to top left', value: 'top left'},
|
||||
{type: 'directional', unparsedValue: 'to top right', value: 'top right'},
|
||||
{type: 'directional', unparsedValue: 'to bottom left', value: 'bottom left'},
|
||||
{type: 'directional', unparsedValue: 'to bottom right', value: 'bottom right'}
|
||||
].forEach(function(orientation) {
|
||||
describe('parse orientation ' + orientation.type, function() {
|
||||
beforeEach(function() {
|
||||
|
@ -197,7 +201,10 @@ describe('lib/parser.js', function () {
|
|||
'ellipse cover',
|
||||
'circle cover',
|
||||
'center bottom, ellipse cover',
|
||||
'circle at 87.23px -58.3px'
|
||||
'circle at 87.23px -58.3px',
|
||||
'farthest-side, red, blue',
|
||||
'farthest-corner, red, blue',
|
||||
'farthest-corner at 87.23px -58.3px, red, blue'
|
||||
].forEach(function(declaration) {
|
||||
|
||||
it('should parse ' + declaration + ' declaration', function() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var gradients = require('build/node');
|
||||
var gradients = require('../build/node');
|
||||
|
||||
function pprint(ast) {
|
||||
console.log(JSON.stringify(ast, true, 2));
|
||||
|
@ -79,7 +79,9 @@ describe('lib/stringify.js', function () {
|
|||
'ellipse cover',
|
||||
'circle cover',
|
||||
'center bottom, ellipse cover',
|
||||
'circle at 87.23px -58.3px'
|
||||
'circle at 87.23px -58.3px',
|
||||
'farthest-corner, red, blue',
|
||||
'farthest-corner at 87.23px -58.3px, red, blue'
|
||||
].forEach(function(declaration) {
|
||||
|
||||
it('should parse ' + declaration + ' declaration', function() {
|
||||
|
|
Loading…
Reference in a new issue