Socket
Socket
Sign inDemoInstall

gradient-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 1.0.0

lib/stringify.js

6

bower.json
{
"name": "gradient-parser",
"version": "0.1.5",
"version": "1.0.0",
"main": "build/web.js",

@@ -13,4 +13,2 @@ "ignore": [

".umd",
"gulpfile.js",
"npm-shrinkwrap.json",
"package.json",

@@ -21,3 +19,3 @@ "index.html",

"README.md",
"gruntfile.js",
"*.js",
"lib/*",

@@ -24,0 +22,0 @@ "spec/*",

@@ -5,4 +5,170 @@ // Copyright (c) 2014 Rafael Caricio. All rights reserved.

var GradientParser = {};
var GradientParser = (GradientParser || {});
GradientParser.stringify = (function() {
var visitor = {
'visit_linear-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_repeating-linear-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_radial-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_repeating-radial-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_gradient': function(node) {
var orientation = visitor.visit(node.orientation);
if (orientation) {
orientation += ', ';
}
return node.type + '(' + orientation + visitor.visit(node.colorStops) + ')';
},
'visit_shape': function(node) {
var result = node.value,
at = visitor.visit(node.at),
style = visitor.visit(node.style);
if (style) {
result += ' ' + style;
}
if (at) {
result += ' at ' + at;
}
return result;
},
'visit_default-radial': function(node) {
var result = '',
at = visitor.visit(node.at);
if (at) {
result += at;
}
return result;
},
'visit_extent-keyword': function(node) {
var result = node.value,
at = visitor.visit(node.at);
if (at) {
result += ' at ' + at;
}
return result;
},
'visit_position-keyword': function(node) {
return node.value;
},
'visit_position': function(node) {
return visitor.visit(node.value.x) + ' ' + visitor.visit(node.value.y);
},
'visit_%': function(node) {
return node.value + '%';
},
'visit_em': function(node) {
return node.value + 'em';
},
'visit_px': function(node) {
return node.value + 'px';
},
'visit_literal': function(node) {
return visitor.visit_color(node.value, node);
},
'visit_hex': function(node) {
return visitor.visit_color('#' + node.value, node);
},
'visit_rgb': function(node) {
return visitor.visit_color('rgb(' + node.value.join(', ') + ')', node);
},
'visit_rgba': function(node) {
return visitor.visit_color('rgba(' + node.value.join(', ') + ')', node);
},
'visit_color': function(resultColor, node) {
var result = resultColor,
length = visitor.visit(node.length);
if (length) {
result += ' ' + length;
}
return result;
},
'visit_angular': function(node) {
return node.value + 'deg';
},
'visit_directional': function(node) {
return 'to ' + node.value;
},
'visit_array': function(elements) {
var result = '',
size = elements.length;
elements.forEach(function(element, i) {
result += visitor.visit(element);
if (i < size - 1) {
result += ', ';
}
});
return result;
},
'visit': function(element) {
if (!element) {
return '';
}
if (element instanceof Array) {
return visitor.visit_array(element, result);
} else if (element.type) {
var nodeVisitor = visitor['visit_' + element.type];
if (nodeVisitor) {
return nodeVisitor(element);
} else {
throw Error('Missing visitor visit_' + element.type);
}
} else {
throw Error('Invalid node.');
}
}
};
return function(root) {
return visitor.visit(root);
};
})();
// Copyright (c) 2014 Rafael Caricio. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var GradientParser = (GradientParser || {});
GradientParser.parse = (function() {

@@ -155,8 +321,17 @@

} 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
};
}
}

@@ -341,2 +516,3 @@ }

exports.parse = (GradientParser || {}).parse;
exports.parse = GradientParser.parse;
exports.stringify = GradientParser.stringify;

@@ -0,1 +1,3 @@

var GradientParser = (window.GradientParser || {});
// Copyright (c) 2014 Rafael Caricio. All rights reserved.

@@ -5,3 +7,3 @@ // Use of this source code is governed by a BSD-style license that can be

var GradientParser = {};
var GradientParser = (GradientParser || {});

@@ -155,8 +157,17 @@ GradientParser.parse = (function() {

} 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
};
}
}

@@ -340,1 +351,167 @@ }

})();
// Copyright (c) 2014 Rafael Caricio. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var GradientParser = (GradientParser || {});
GradientParser.stringify = (function() {
var visitor = {
'visit_linear-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_repeating-linear-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_radial-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_repeating-radial-gradient': function(node) {
return visitor.visit_gradient(node);
},
'visit_gradient': function(node) {
var orientation = visitor.visit(node.orientation);
if (orientation) {
orientation += ', ';
}
return node.type + '(' + orientation + visitor.visit(node.colorStops) + ')';
},
'visit_shape': function(node) {
var result = node.value,
at = visitor.visit(node.at),
style = visitor.visit(node.style);
if (style) {
result += ' ' + style;
}
if (at) {
result += ' at ' + at;
}
return result;
},
'visit_default-radial': function(node) {
var result = '',
at = visitor.visit(node.at);
if (at) {
result += at;
}
return result;
},
'visit_extent-keyword': function(node) {
var result = node.value,
at = visitor.visit(node.at);
if (at) {
result += ' at ' + at;
}
return result;
},
'visit_position-keyword': function(node) {
return node.value;
},
'visit_position': function(node) {
return visitor.visit(node.value.x) + ' ' + visitor.visit(node.value.y);
},
'visit_%': function(node) {
return node.value + '%';
},
'visit_em': function(node) {
return node.value + 'em';
},
'visit_px': function(node) {
return node.value + 'px';
},
'visit_literal': function(node) {
return visitor.visit_color(node.value, node);
},
'visit_hex': function(node) {
return visitor.visit_color('#' + node.value, node);
},
'visit_rgb': function(node) {
return visitor.visit_color('rgb(' + node.value.join(', ') + ')', node);
},
'visit_rgba': function(node) {
return visitor.visit_color('rgba(' + node.value.join(', ') + ')', node);
},
'visit_color': function(resultColor, node) {
var result = resultColor,
length = visitor.visit(node.length);
if (length) {
result += ' ' + length;
}
return result;
},
'visit_angular': function(node) {
return node.value + 'deg';
},
'visit_directional': function(node) {
return 'to ' + node.value;
},
'visit_array': function(elements) {
var result = '',
size = elements.length;
elements.forEach(function(element, i) {
result += visitor.visit(element);
if (i < size - 1) {
result += ', ';
}
});
return result;
},
'visit': function(element) {
if (!element) {
return '';
}
if (element instanceof Array) {
return visitor.visit_array(element, result);
} else if (element.type) {
var nodeVisitor = visitor['visit_' + element.type];
if (nodeVisitor) {
return nodeVisitor(element);
} else {
throw Error('Missing visitor visit_' + element.type);
}
} else {
throw Error('Invalid node.');
}
}
};
return function(root) {
return visitor.visit(root);
};
})();

@@ -22,4 +22,4 @@ 'use strict';

files: {
'build/node.js': ['lib/parser.js', 'index.js'],
'build/web.js': ['lib/parser.js']
'build/node.js': ['lib/stringify.js', 'lib/parser.js', 'index.js'],
'build/web.js': ['webify.js', 'lib/parser.js', 'lib/stringify.js']
}

@@ -26,0 +26,0 @@ }

@@ -1,1 +0,2 @@

exports.parse = (GradientParser || {}).parse;
exports.parse = GradientParser.parse;
exports.stringify = GradientParser.stringify;

@@ -5,3 +5,3 @@ // Copyright (c) 2014 Rafael Caricio. All rights reserved.

var GradientParser = {};
var GradientParser = (GradientParser || {});

@@ -102,3 +102,3 @@ GradientParser.parse = (function() {

result = callback(captures);
var result = callback(captures);

@@ -156,8 +156,17 @@ if (!scan(tokens.endCall)) {

} 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
};
}
}

@@ -164,0 +173,0 @@ }

{
"name": "gradient-parser",
"version": "0.1.5",
"version": "1.0.0",
"description": "Parse CSS3 gradient definitions and return an AST.",

@@ -5,0 +5,0 @@ "author": {

@@ -7,3 +7,3 @@ 'use strict';

describe('gradient-parser.js', function () {
describe('lib/parser.js', function () {
var ast,

@@ -117,3 +117,3 @@ subject;

beforeEach(function() {
ast = gradients.parse('linear-gradient(blue 10' + metric + ', transparent)');
ast = gradients.parse('linear-gradient(blue 10.3' + metric + ', transparent)');
subject = ast[0];

@@ -129,3 +129,3 @@ });

expect(subject.length.type).to.equal(metric);
expect(subject.length.value).to.equal('10');
expect(subject.length.value).to.equal('10.3');
});

@@ -139,3 +139,3 @@ });

[
{type: 'angular', unparsedValue: '145deg', value: '145'},
{type: 'angular', unparsedValue: '-145deg', value: '-145'},
{type: 'directional', unparsedValue: 'to left top', value: 'left top'}

@@ -204,3 +204,6 @@ ].forEach(function(orientation) {

'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) {

@@ -207,0 +210,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc