diff options
Diffstat (limited to 'node_modules/colormin/dist')
| -rw-r--r-- | node_modules/colormin/dist/index.js | 80 | ||||
| -rw-r--r-- | node_modules/colormin/dist/lib/colourNames.js | 19 | ||||
| -rw-r--r-- | node_modules/colormin/dist/lib/colourType.js | 35 | ||||
| -rw-r--r-- | node_modules/colormin/dist/lib/stripWhitespace.js | 9 | ||||
| -rw-r--r-- | node_modules/colormin/dist/lib/toLonghand.js | 16 | ||||
| -rw-r--r-- | node_modules/colormin/dist/lib/toShorthand.js | 12 | ||||
| -rw-r--r-- | node_modules/colormin/dist/lib/trimLeadingZero.js | 9 |
7 files changed, 180 insertions, 0 deletions
diff --git a/node_modules/colormin/dist/index.js b/node_modules/colormin/dist/index.js new file mode 100644 index 00000000..6ee5fc37 --- /dev/null +++ b/node_modules/colormin/dist/index.js @@ -0,0 +1,80 @@ +'use strict'; + +exports.__esModule = true; + +var _color = require('color'); + +var _color2 = _interopRequireDefault(_color); + +var _colourNames = require('./lib/colourNames'); + +var _colourNames2 = _interopRequireDefault(_colourNames); + +var _toShorthand = require('./lib/toShorthand'); + +var _toShorthand2 = _interopRequireDefault(_toShorthand); + +var _colourType = require('./lib/colourType'); + +var ctype = _interopRequireWildcard(_colourType); + +var _stripWhitespace = require('./lib/stripWhitespace'); + +var _stripWhitespace2 = _interopRequireDefault(_stripWhitespace); + +var _trimLeadingZero = require('./lib/trimLeadingZero'); + +var _trimLeadingZero2 = _interopRequireDefault(_trimLeadingZero); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var filterColor = function filterColor(callback) { + return Object.keys(_colourNames2.default).filter(callback); +}; +var shorter = function shorter(a, b) { + return (a && a.length < b.length ? a : b).toLowerCase(); +}; + +exports.default = function (colour) { + var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + + if (ctype.isRGBorHSL(colour)) { + var c = void 0; + // Pass through invalid rgb/hsl functions + try { + c = (0, _color2.default)(colour); + } catch (err) { + return colour; + } + if (c.alpha() === 1) { + // At full alpha, just use hex + colour = c.hexString(); + } else { + var rgb = c.rgb(); + if (!opts.legacy && !rgb.r && !rgb.g && !rgb.b && !rgb.a) { + return 'transparent'; + } + var hsla = c.hslaString(); + var rgba = c.rgbString(); + return (0, _trimLeadingZero2.default)((0, _stripWhitespace2.default)(hsla.length < rgba.length ? hsla : rgba)); + } + } + if (ctype.isHex(colour)) { + colour = (0, _toShorthand2.default)(colour.toLowerCase()); + var keyword = filterColor(function (key) { + return _colourNames2.default[key] === colour; + })[0]; + return shorter(keyword, colour); + } else if (ctype.isKeyword(colour)) { + var hex = _colourNames2.default[filterColor(function (k) { + return k === colour.toLowerCase(); + })[0]]; + return shorter(hex, colour); + } + // Possibly malformed, just pass through + return colour; +}; + +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/colormin/dist/lib/colourNames.js b/node_modules/colormin/dist/lib/colourNames.js new file mode 100644 index 00000000..6948271f --- /dev/null +++ b/node_modules/colormin/dist/lib/colourNames.js @@ -0,0 +1,19 @@ +'use strict'; + +exports.__esModule = true; + +var _cssColorNames = require('css-color-names'); + +var _cssColorNames2 = _interopRequireDefault(_cssColorNames); + +var _toShorthand = require('./toShorthand'); + +var _toShorthand2 = _interopRequireDefault(_toShorthand); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +Object.keys(_cssColorNames2.default).forEach(function (c) { + return _cssColorNames2.default[c] = (0, _toShorthand2.default)(_cssColorNames2.default[c]); +}); +exports.default = _cssColorNames2.default; +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/colormin/dist/lib/colourType.js b/node_modules/colormin/dist/lib/colourType.js new file mode 100644 index 00000000..f2ea803b --- /dev/null +++ b/node_modules/colormin/dist/lib/colourType.js @@ -0,0 +1,35 @@ +'use strict'; + +exports.__esModule = true; +exports.isKeyword = exports.isRGBorHSL = exports.isHex = undefined; + +var _has = require('has'); + +var _has2 = _interopRequireDefault(_has); + +var _colourNames = require('./colourNames'); + +var _colourNames2 = _interopRequireDefault(_colourNames); + +var _toLonghand = require('./toLonghand'); + +var _toLonghand2 = _interopRequireDefault(_toLonghand); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var isHex = exports.isHex = function isHex(colour) { + if (colour[0] === '#') { + var c = (0, _toLonghand2.default)(colour).substring(1); + return c.length === 6 && !isNaN(parseInt(c, 16)); + } + return false; +}; + +var isRGBorHSL = exports.isRGBorHSL = function isRGBorHSL(colour) { + return (/^(rgb|hsl)a?\(.*?\)/.test(colour) + ); +}; + +var isKeyword = exports.isKeyword = function isKeyword(colour) { + return (0, _has2.default)(_colourNames2.default, colour.toLowerCase()); +};
\ No newline at end of file diff --git a/node_modules/colormin/dist/lib/stripWhitespace.js b/node_modules/colormin/dist/lib/stripWhitespace.js new file mode 100644 index 00000000..e279c8db --- /dev/null +++ b/node_modules/colormin/dist/lib/stripWhitespace.js @@ -0,0 +1,9 @@ +'use strict'; + +exports.__esModule = true; + +exports.default = function (str) { + return str.replace(/\s/g, ''); +}; + +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/colormin/dist/lib/toLonghand.js b/node_modules/colormin/dist/lib/toLonghand.js new file mode 100644 index 00000000..94377f43 --- /dev/null +++ b/node_modules/colormin/dist/lib/toLonghand.js @@ -0,0 +1,16 @@ +'use strict'; + +exports.__esModule = true; + +exports.default = function (hex) { + if (hex.length !== 4) { + return hex; + } + + var r = hex[1]; + var g = hex[2]; + var b = hex[3]; + return '#' + r + r + g + g + b + b; +}; + +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/colormin/dist/lib/toShorthand.js b/node_modules/colormin/dist/lib/toShorthand.js new file mode 100644 index 00000000..dd305707 --- /dev/null +++ b/node_modules/colormin/dist/lib/toShorthand.js @@ -0,0 +1,12 @@ +'use strict'; + +exports.__esModule = true; + +exports.default = function (hex) { + if (hex.length === 7 && hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) { + return '#' + hex[2] + hex[4] + hex[6]; + } + return hex; +}; + +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/colormin/dist/lib/trimLeadingZero.js b/node_modules/colormin/dist/lib/trimLeadingZero.js new file mode 100644 index 00000000..65d8508a --- /dev/null +++ b/node_modules/colormin/dist/lib/trimLeadingZero.js @@ -0,0 +1,9 @@ +'use strict'; + +exports.__esModule = true; + +exports.default = function (str) { + return str.replace(/([^\d])0(\.\d*)/g, '$1$2'); +}; + +module.exports = exports['default'];
\ No newline at end of file |
