forked from enviPath/enviPy
Current Dev State
This commit is contained in:
21
static/js/ketcher2/node_modules/rgb2hex/LICENSE
generated
vendored
Normal file
21
static/js/ketcher2/node_modules/rgb2hex/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Christian Bromann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
68
static/js/ketcher2/node_modules/rgb2hex/README.md
generated
vendored
Normal file
68
static/js/ketcher2/node_modules/rgb2hex/README.md
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
rgb2hex [](https://travis-ci.org/christian-bromann/rgb2hex) [](https://coveralls.io/r/christian-bromann/rgb2hex)
|
||||
=======
|
||||
|
||||
[](https://saucelabs.com/u/rgb2hex)
|
||||
|
||||
Parse any rgb or rgba string into a hex color. Lightweight library, no dependencies!
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
via NPM:
|
||||
```
|
||||
$ npm install rgb2hex
|
||||
```
|
||||
|
||||
via Bower
|
||||
```
|
||||
$ bower install rgb2hex
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Include `rgb2hex.js` in your web app, by loading it as usual:
|
||||
|
||||
```html
|
||||
<script src="rgb2hex.js"></script>
|
||||
```
|
||||
|
||||
### Using NodeJS
|
||||
|
||||
```js
|
||||
var rgb2hex = require('rgb2hex');
|
||||
|
||||
console.log(rgb2hex('rgb(210,43,2525)'));
|
||||
/**
|
||||
* returns:
|
||||
* {
|
||||
* hex: '#d22bff',
|
||||
* alpha: 1
|
||||
* }
|
||||
*/
|
||||
|
||||
console.log(rgb2hex('rgba(12,173,22,.67)'));
|
||||
/**
|
||||
* returns:
|
||||
* {
|
||||
* hex: '#d22bff',
|
||||
* alpha: 0.67
|
||||
* }
|
||||
*/
|
||||
```
|
||||
|
||||
### Using RequireJS
|
||||
|
||||
rgb2hex can be also loaded with AMD:
|
||||
|
||||
```js
|
||||
require(['rgb2hex'], function (rgb2hex) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
## Contributing
|
||||
Please fork, add specs, and send pull requests! In lieu of a formal styleguide, take care to
|
||||
maintain the existing coding style.
|
||||
|
||||
## Release History
|
||||
* 2013-04-22 v0.1.0 first working version
|
||||
26
static/js/ketcher2/node_modules/rgb2hex/bower.json
generated
vendored
Normal file
26
static/js/ketcher2/node_modules/rgb2hex/bower.json
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "rgb2hex",
|
||||
"main": "rgb2hex.js",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://github.com/christian-bromann/rgb2hex",
|
||||
"authors": [
|
||||
"Christian Bromann <mail@christian-bromann.com>"
|
||||
],
|
||||
"description": "lightweight rgb/rgba to hex parser",
|
||||
"keywords": [
|
||||
"rgb",
|
||||
"rgba",
|
||||
"hex",
|
||||
"color",
|
||||
"parse",
|
||||
"parser"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
56
static/js/ketcher2/node_modules/rgb2hex/index.js
generated
vendored
Normal file
56
static/js/ketcher2/node_modules/rgb2hex/index.js
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* rgb2hex
|
||||
*
|
||||
* @author Christian Bromann <mail@christian-bromann.com>
|
||||
* @description converts rgba color to HEX
|
||||
*
|
||||
* @param {String} color rgb or rgba color
|
||||
* @return {Object} object with hex and alpha value
|
||||
*/
|
||||
|
||||
var rgb2hex = module.exports = function rgb2hex(color) {
|
||||
|
||||
if(typeof color !== 'string') {
|
||||
// throw error of input isn't typeof string
|
||||
throw new Error('color has to be type of `string`');
|
||||
} else if (color.substr(0, 1) === '#') {
|
||||
// or return if already rgb color
|
||||
return {
|
||||
hex: color,
|
||||
alpha: 1
|
||||
};
|
||||
}
|
||||
|
||||
// parse input
|
||||
var digits = /(.*?)rgb(a)*\((\d+),(\d+),(\d+)(,[0-9]*\.*[0-9]+)*\)/.exec(color.replace(/\s+/g,''));
|
||||
|
||||
if(!digits) {
|
||||
// or throw error if input isn't a valid rgb(a) color
|
||||
throw new Error('given color (' + color + ') isn\'t a valid rgb or rgba color');
|
||||
}
|
||||
|
||||
var red = parseInt(digits[3]);
|
||||
var green = parseInt(digits[4]);
|
||||
var blue = parseInt(digits[5]);
|
||||
var alpha = digits[6] ? /([0-9\.]+)/.exec(digits[6])[0] : '1';
|
||||
var rgb = ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1);
|
||||
|
||||
// parse alpha value into float
|
||||
if(alpha.substr(0,1) === '.') {
|
||||
alpha = parseFloat('0' + alpha, 10);
|
||||
}
|
||||
|
||||
// limit alpha value to 1
|
||||
if(alpha > 1) {
|
||||
alpha = 1;
|
||||
}
|
||||
|
||||
// cut alpha value after 2 digits after comma
|
||||
alpha = parseFloat(Math.round(alpha * 100), 10) / 100;
|
||||
|
||||
return {
|
||||
hex: digits[1] + '#' + rgb.toString(16),
|
||||
alpha: alpha
|
||||
}
|
||||
|
||||
};
|
||||
67
static/js/ketcher2/node_modules/rgb2hex/package.json
generated
vendored
Normal file
67
static/js/ketcher2/node_modules/rgb2hex/package.json
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
{
|
||||
"_from": "rgb2hex@~0.1.0",
|
||||
"_id": "rgb2hex@0.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-zNVfhgrgxcTqN1BLlY5ELY0SMls=",
|
||||
"_location": "/rgb2hex",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "rgb2hex@~0.1.0",
|
||||
"name": "rgb2hex",
|
||||
"escapedName": "rgb2hex",
|
||||
"rawSpec": "~0.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~0.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webdriverio"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/rgb2hex/-/rgb2hex-0.1.0.tgz",
|
||||
"_shasum": "ccd55f860ae0c5c4ea37504b958e442d8d12325b",
|
||||
"_spec": "rgb2hex@~0.1.0",
|
||||
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/webdriverio",
|
||||
"author": {
|
||||
"name": "Christian Bromann",
|
||||
"email": "mail@christian-bromann.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/christian-bromann/rgb2hex/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "lightweight rgb/rgba to hex parser",
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.10.0",
|
||||
"istanbul": "^0.2.7",
|
||||
"mocha": "^1.18.2",
|
||||
"should": "^3.3.1",
|
||||
"zuul": "^1.6.3"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"homepage": "https://github.com/christian-bromann/rgb2hex",
|
||||
"keywords": [
|
||||
"rgb",
|
||||
"rgba",
|
||||
"hex",
|
||||
"color",
|
||||
"parse",
|
||||
"parser"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "rgb2hex",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/christian-bromann/rgb2hex.git"
|
||||
},
|
||||
"scripts": {
|
||||
"cover": "istanbul cover ./node_modules/.bin/_mocha --print -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
|
||||
"test": "./node_modules/mocha/bin/_mocha",
|
||||
"travis": "zuul test/rgb2hex.spec.js"
|
||||
},
|
||||
"version": "0.1.0"
|
||||
}
|
||||
58
static/js/ketcher2/node_modules/rgb2hex/rgb2hex.js
generated
vendored
Normal file
58
static/js/ketcher2/node_modules/rgb2hex/rgb2hex.js
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
;(function(window) {
|
||||
|
||||
var rgb2hex = function(color) {
|
||||
|
||||
if(typeof color !== 'string') {
|
||||
// throw error of input isn't typeof string
|
||||
throw new Error('color has to be type of `string`');
|
||||
} else if (color.substr(0, 1) === '#') {
|
||||
// or return if already rgb color
|
||||
return {
|
||||
hex: color,
|
||||
alpha: 1
|
||||
};
|
||||
}
|
||||
|
||||
// parse input
|
||||
var digits = /(.*?)rgb(a)*\((\d+),(\d+),(\d+)(,[0-9]*\.*[0-9]+)*\)/.exec(color.replace(/\s+/g,''));
|
||||
|
||||
if(!digits) {
|
||||
// or throw error if input isn't a valid rgb(a) color
|
||||
throw new Error('given color (' + color + ') isn\'t a valid rgb or rgba color');
|
||||
}
|
||||
|
||||
var red = parseInt(digits[3]);
|
||||
var green = parseInt(digits[4]);
|
||||
var blue = parseInt(digits[5]);
|
||||
var alpha = digits[6] ? /([0-9\.]+)/.exec(digits[6])[0] : '1';
|
||||
var rgb = ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1);
|
||||
|
||||
// parse alpha value into float
|
||||
if(alpha.substr(0,1) === '.') {
|
||||
alpha = parseFloat('0' + alpha, 10);
|
||||
}
|
||||
|
||||
// limit alpha value to 1
|
||||
if(alpha > 1) {
|
||||
alpha = 1;
|
||||
}
|
||||
|
||||
// cut alpha value after 2 digits after comma
|
||||
alpha = parseFloat(Math.round(alpha * 100), 10) / 100;
|
||||
|
||||
return {
|
||||
hex: digits[1] + '#' + rgb.toString(16),
|
||||
alpha: alpha
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
if(typeof define === 'function' && define.amd) {
|
||||
define('rgb2hex', function () {
|
||||
return rgb2hex;
|
||||
});
|
||||
} else {
|
||||
window.rgb2hex = rgb2hex;
|
||||
}
|
||||
|
||||
}(window));
|
||||
1
static/js/ketcher2/node_modules/rgb2hex/rgb2hex.min.js
generated
vendored
Normal file
1
static/js/ketcher2/node_modules/rgb2hex/rgb2hex.min.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
(function(b){var a=function(d){if(typeof d!=="string"){throw new Error("color has to be type of `string`")}else{if(d.substr(0,1)==="#"){return{hex:d,alpha:1}}}var g=/(.*?)rgb(a)*\((\d+),(\d+),(\d+)(,[0-9]*\.*[0-9]+)*\)/.exec(d.replace(/\s+/g,""));if(!g){throw new Error("given color ("+d+") isn't a valid rgb or rgba color")}var i=parseInt(g[3]);var f=parseInt(g[4]);var c=parseInt(g[5]);var h=g[6]?/([0-9\.]+)/.exec(g[6])[0]:"1";var e=((c|f<<8|i<<16)|1<<24).toString(16).slice(1);if(h.substr(0,1)==="."){h=parseFloat("0"+h,10)}if(h>1){h=1}h=parseFloat(Math.round(h*100),10)/100;return{hex:g[1]+"#"+e.toString(16),alpha:h}};if(typeof define==="function"&&define.amd){define("rgb2hex",function(){return a})}else{b.rgb2hex=a}}(window));
|
||||
121
static/js/ketcher2/node_modules/rgb2hex/test/rgb2hex.spec.js
generated
vendored
Normal file
121
static/js/ketcher2/node_modules/rgb2hex/test/rgb2hex.spec.js
generated
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
var rgb2hex = require('../index'),
|
||||
should = require('should'),
|
||||
typeofErrorMessage = 'color has to be type of `string`',
|
||||
invalidErrorMessage = function(input) { return 'given color (' + input + ') isn\'t a valid rgb or rgba color'; };
|
||||
|
||||
describe('rgb2hex should', function() {
|
||||
|
||||
describe('throw an error if input is not typeof string', function() {
|
||||
|
||||
it('[Object] {color: \'something\'}', function() {
|
||||
var input = {color: 'something'};
|
||||
rgb2hex.bind(null,input).should.throw(typeofErrorMessage);
|
||||
});
|
||||
|
||||
it('[Function] function(){}', function() {
|
||||
var input = function(){};
|
||||
rgb2hex.bind(null,input).should.throw(typeofErrorMessage);
|
||||
});
|
||||
|
||||
it('[Number] 231', function() {
|
||||
var input = 231;
|
||||
rgb2hex.bind(null,input).should.throw(typeofErrorMessage);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('throw an error if input is invalid', function() {
|
||||
|
||||
it('notacolor', function() {
|
||||
var input = 'notacolor';
|
||||
rgb2hex.bind(null,input).should.throw(invalidErrorMessage(input));
|
||||
});
|
||||
|
||||
it('rgba(100, 100)', function() {
|
||||
var input = 'rgb(100, 100)';
|
||||
rgb2hex.bind(null,input).should.throw(invalidErrorMessage(input));
|
||||
});
|
||||
|
||||
it('rgba(100, 10a0, 200, 300)', function() {
|
||||
var input = 'rgba(100, 10a0, 200, 300)';
|
||||
rgb2hex.bind(null,input).should.throw(invalidErrorMessage(input));
|
||||
});
|
||||
|
||||
it('rgba(23, 54, 4, -.33)', function() {
|
||||
var input = 'rgba(23, 54, 4, -.33)';
|
||||
rgb2hex.bind(null,input).should.throw(invalidErrorMessage(input));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('return input if it is already a hex color', function() {
|
||||
var input = '#ffffff',
|
||||
parsedValue = rgb2hex(input);
|
||||
|
||||
parsedValue.should.have.property('hex');
|
||||
parsedValue.should.have.property('alpha');
|
||||
parsedValue.hex.should.be.type('string');
|
||||
parsedValue.hex.should.eql('#ffffff');
|
||||
parsedValue.alpha.should.be.type('number');
|
||||
parsedValue.alpha.should.eql(1);
|
||||
});
|
||||
|
||||
describe('parse input properly', function() {
|
||||
|
||||
it('converting rgb(210,43,2525)', function() {
|
||||
var input = 'rgb(210,43,255)',
|
||||
parsedValue = rgb2hex(input);
|
||||
|
||||
parsedValue.should.have.property('hex');
|
||||
parsedValue.should.have.property('alpha');
|
||||
parsedValue.hex.should.be.type('string');
|
||||
parsedValue.hex.should.eql('#d22bff');
|
||||
parsedValue.alpha.should.be.type('number');
|
||||
parsedValue.alpha.should.eql(1);
|
||||
});
|
||||
|
||||
it('converting rgba(12,173,22,.67)', function() {
|
||||
var input = 'rgba(12,173,22,.67)',
|
||||
parsedValue = rgb2hex(input);
|
||||
|
||||
parsedValue.should.have.property('hex');
|
||||
parsedValue.should.have.property('alpha');
|
||||
parsedValue.hex.should.be.type('string');
|
||||
parsedValue.hex.should.eql('#0cad16');
|
||||
parsedValue.alpha.should.be.type('number');
|
||||
parsedValue.alpha.should.eql(0.67);
|
||||
});
|
||||
|
||||
it('by limiting alpha value to 1', function() {
|
||||
var input = 'rgba(12,173,22,12312.67)';
|
||||
rgb2hex(input).alpha.should.not.be.above(1);
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('not care about', function() {
|
||||
|
||||
it('rgb or rgba prefix', function() {
|
||||
var rgb = 'rgb(0, 0, 0)',
|
||||
rgba = 'rgba(0, 0, 0)';
|
||||
|
||||
rgb2hex(rgb).hex.should.be.equal(rgb2hex(rgba).hex);
|
||||
});
|
||||
|
||||
it('spaces between color numbers', function() {
|
||||
var rgbWithSpaces = 'rgb(0, 0, 0)',
|
||||
rgbWithoutSpaces = 'rgba(0,0,0)';
|
||||
|
||||
rgb2hex(rgbWithSpaces).hex.should.be.equal(rgb2hex(rgbWithoutSpaces).hex);
|
||||
});
|
||||
|
||||
it('if alpha value starts with `.` or with `0`', function() {
|
||||
var rgbaWithDot = 'rgba(213,12,4,.45)',
|
||||
rgbWitahoutDot = 'rgba(213,12,4,0.45)';
|
||||
|
||||
rgb2hex(rgbaWithDot).alpha.should.be.equal(rgb2hex(rgbWitahoutDot).alpha);
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user