colormangle
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,854 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.ColorMangle = void 0; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
// To test on local browser, remove export | ||
var ColorMangle = /*#__PURE__*/function () { | ||
/** | ||
* An user-friendly text and background color selector for UI design. ColorMangle converts color strings to various format. | ||
* @param {string} [color='teal'] - Argument string can be either color name string or any type of HTML color codes (hex, rgb, hsl). | ||
*/ | ||
function ColorMangle() { | ||
var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'teal'; | ||
_classCallCheck(this, ColorMangle); | ||
this.colorName = { | ||
"aliceblue": "#f0f8ff", | ||
"antiquewhite": "#faebd7", | ||
"aqua": "#00ffff", | ||
"aquamarine": "#7fffd4", | ||
"azure": "#f0ffff", | ||
"beige": "#f5f5dc", | ||
"bisque": "#ffe4c4", | ||
"black": "#000000", | ||
"blanchedalmond": "#ffebcd", | ||
"blue": "#0000ff", | ||
"blueviolet": "#8a2be2", | ||
"brown": "#a52a2a", | ||
"burlywood": "#deb887", | ||
"cadetblue": "#5f9ea0", | ||
"chartreuse": "#7fff00", | ||
"chocolate": "#d2691e", | ||
"coral": "#ff7f50", | ||
"cornflowerblue": "#6495ed", | ||
"cornsilk": "#fff8dc", | ||
"crimson": "#dc143c", | ||
"cyan": "#00ffff", | ||
"darkblue": "#00008b", | ||
"darkcyan": "#008b8b", | ||
"darkgoldenrod": "#b8860b", | ||
"darkgray": "#a9a9a9", | ||
"darkgreen": "#006400", | ||
"darkgrey": "#a9a9a9", | ||
"darkkhaki": "#bdb76b", | ||
"darkmagenta": "#8b008b", | ||
"darkolivegreen": "#556b2f", | ||
"darkorange": "#ff8c00", | ||
"darkorchid": "#9932cc", | ||
"darkred": "#8b0000", | ||
"darksalmon": "#e9967a", | ||
"darkseagreen": "#8fbc8f", | ||
"darkslateblue": "#483d8b", | ||
"darkslategray": "#2f4f4f", | ||
"darkslategrey": "#2f4f4f", | ||
"darkturquoise": "#00ced1", | ||
"darkviolet": "#9400d3", | ||
"deeppink": "#ff1493", | ||
"deepskyblue": "#00bfff", | ||
"dimgray": "#696969", | ||
"dimgrey": "#696969", | ||
"dodgerblue": "#1e90ff", | ||
"firebrick": "#b22222", | ||
"floralwhite": "#fffaf0", | ||
"forestgreen": "#228b22", | ||
"fuchsia": "#ff00ff", | ||
"gainsboro": "#dcdcdc", | ||
"ghostwhite": "#f8f8ff", | ||
"goldenrod": "#daa520", | ||
"gold": "#ffd700", | ||
"gray": "#808080", | ||
"green": "#008000", | ||
"greenyellow": "#adff2f", | ||
"grey": "#808080", | ||
"honeydew": "#f0fff0", | ||
"hotpink": "#ff69b4", | ||
"indianred": "#cd5c5c", | ||
"indigo": "#4b0082", | ||
"ivory": "#fffff0", | ||
"khaki": "#f0e68c", | ||
"lavenderblush": "#fff0f5", | ||
"lavender": "#e6e6fa", | ||
"lawngreen": "#7cfc00", | ||
"lemonchiffon": "#fffacd", | ||
"lightblue": "#add8e6", | ||
"lightcoral": "#f08080", | ||
"lightcyan": "#e0ffff", | ||
"lightgoldenrodyellow": "#fafad2", | ||
"lightgray": "#d3d3d3", | ||
"lightgreen": "#90ee90", | ||
"lightgrey": "#d3d3d3", | ||
"lightpink": "#ffb6c1", | ||
"lightsalmon": "#ffa07a", | ||
"lightseagreen": "#20b2aa", | ||
"lightskyblue": "#87cefa", | ||
"lightslategray": "#778899", | ||
"lightslategrey": "#778899", | ||
"lightsteelblue": "#b0c4de", | ||
"lightyellow": "#ffffe0", | ||
"lime": "#00ff00", | ||
"limegreen": "#32cd32", | ||
"linen": "#faf0e6", | ||
"magenta": "#ff00ff", | ||
"maroon": "#800000", | ||
"mediumaquamarine": "#66cdaa", | ||
"mediumblue": "#0000cd", | ||
"mediumorchid": "#ba55d3", | ||
"mediumpurple": "#9370db", | ||
"mediumseagreen": "#3cb371", | ||
"mediumslateblue": "#7b68ee", | ||
"mediumspringgreen": "#00fa9a", | ||
"mediumturquoise": "#48d1cc", | ||
"mediumvioletred": "#c71585", | ||
"midnightblue": "#191970", | ||
"mintcream": "#f5fffa", | ||
"mistyrose": "#ffe4e1", | ||
"moccasin": "#ffe4b5", | ||
"navajowhite": "#ffdead", | ||
"navy": "#000080", | ||
"oldlace": "#fdf5e6", | ||
"olive": "#808000", | ||
"olivedrab": "#6b8e23", | ||
"orange": "#ffa500", | ||
"orangered": "#ff4500", | ||
"orchid": "#da70d6", | ||
"palegoldenrod": "#eee8aa", | ||
"palegreen": "#98fb98", | ||
"paleturquoise": "#afeeee", | ||
"palevioletred": "#db7093", | ||
"papayawhip": "#ffefd5", | ||
"peachpuff": "#ffdab9", | ||
"peru": "#cd853f", | ||
"pink": "#ffc0cb", | ||
"plum": "#dda0dd", | ||
"powderblue": "#b0e0e6", | ||
"purple": "#800080", | ||
"rebeccapurple": "#663399", | ||
"red": "#ff0000", | ||
"rosybrown": "#bc8f8f", | ||
"royalblue": "#4169e1", | ||
"saddlebrown": "#8b4513", | ||
"salmon": "#fa8072", | ||
"sandybrown": "#f4a460", | ||
"seagreen": "#2e8b57", | ||
"seashell": "#fff5ee", | ||
"sienna": "#a0522d", | ||
"silver": "#c0c0c0", | ||
"skyblue": "#87ceeb", | ||
"slateblue": "#6a5acd", | ||
"slategray": "#708090", | ||
"slategrey": "#708090", | ||
"snow": "#fffafa", | ||
"springgreen": "#00ff7f", | ||
"steelblue": "#4682b4", | ||
"tan": "#d2b48c", | ||
"teal": "#008080", | ||
"thistle": "#d8bfd8", | ||
"tomato": "#ff6347", | ||
"turquoise": "#40e0d0", | ||
"violet": "#ee82ee", | ||
"wheat": "#f5deb3", | ||
"white": "#ffffff", | ||
"whitesmoke": "#f5f5f5", | ||
"yellow": "#ffff00", | ||
"yellowgreen": "#9acd32" | ||
}; | ||
var format = this._colorType(color); | ||
this.type = format.type; | ||
this.color = format.color; | ||
} | ||
_createClass(ColorMangle, [{ | ||
key: "_extractRGBAHSLADigit", | ||
value: function _extractRGBAHSLADigit() { | ||
var color_arg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.color; | ||
var _this$_colorType = this._colorType(color_arg), | ||
_this$_colorType$type = _this$_colorType.type, | ||
type = _this$_colorType$type === void 0 ? this.type : _this$_colorType$type, | ||
_this$_colorType$colo = _this$_colorType.color, | ||
color = _this$_colorType$colo === void 0 ? this.color : _this$_colorType$colo; | ||
if (type === 'hex') return null; | ||
var value = []; | ||
var _iterator = _createForOfIteratorHelper(color.match(/\d+(\.\d+)?/g)), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var i = _step.value; | ||
value.push(parseFloat(i)); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
if (value.length < 4) value.push(1); | ||
return value; | ||
} | ||
}, { | ||
key: "_colorType", | ||
value: function _colorType() { | ||
var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.color; | ||
var throwErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var chkType, type; | ||
try { | ||
if (!color) throw 'invalid color'; | ||
if (_typeof(color) === 'object' && color.string) color = color.string; | ||
if (typeof color === 'string') color = color.toLowerCase();else throw 'invalid color'; | ||
if (color === this.color) return { | ||
type: this.type, | ||
color: this.color | ||
}; | ||
if (this.colorName[color]) return { | ||
type: 'hex', | ||
color: this.colorName[color] | ||
}; | ||
chkType = color.match(/^(rgba?|rgb?|hsla?|#)/g); | ||
if (Array.isArray(chkType)) { | ||
if (chkType[0] === '#') { | ||
if (color.length === 4) // convert shorthand hex | ||
color = color[0] + color[1] + color[1] + color[2] + color[2] + color[3] + color[3]; | ||
if (/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color)) // is valid hex | ||
type = 'hex';else throw 'invalid hex'; | ||
} else if (color[color.length - 1] === ')') // hex, rgb, rgba, hsl, hsla | ||
type = chkType[0]; | ||
return { | ||
type: type, | ||
color: color | ||
}; | ||
} | ||
} catch (err) { | ||
if (throwErr) throw err; | ||
} | ||
return {}; | ||
} | ||
/** | ||
* @typedef {Object} colorScheme | ||
* @property {string} --shadow - rgba(0, 0, 0, 0.05) | ||
* @property {string} --light - rgba(255, 255, 255, 0.05) | ||
* @property {string} --overlay - rgba(0, 0, 0, 0.25) | ||
* @property {string} --alert - #ff6347 | ||
* @property {string} --background | ||
* @property {string} --background-focus | ||
* @property {string} --background-focus_faded | ||
* @property {string} --background-focus_transparent | ||
* @property {string} --background-focus-text | ||
* @property {string} --background-text | ||
* @property {string} --background-text_transparent | ||
* @property {string} --background-placeholder | ||
* @property {string} --content | ||
* @property {string} --content-focus | ||
* @property {string} --content-focus_faded | ||
* @property {string} --content-focus_transparent | ||
* @property {string} --content-focus-text | ||
* @property {string} --content-text | ||
* @property {string} --content-text_transparent | ||
* @property {string} --content-placeholder | ||
* @property {string} --toolbar | ||
* @property {string} --toolbar-focus | ||
* @property {string} --toolbar-focus_faded | ||
* @property {string} --toolbar-focus_transparent | ||
* @property {string} --toolbar-focus-text | ||
* @property {string} --toolbar-text | ||
* @property {string} --toolbar-text_transparent | ||
* @property {string} --toolbar-placeholder | ||
* @property {string} --button | ||
* @property {string} --button-focus | ||
* @property {string} --button-focus_faded | ||
* @property {string} --button-focus_transparent | ||
* @property {string} --button-focus-text | ||
* @property {string} --button-text | ||
* @property {string} --button-text_transparent | ||
* @property {string} --button-placeholder | ||
*/ | ||
/** | ||
* Generates color scheme object. | ||
* @return {colorScheme} | ||
*/ | ||
}, { | ||
key: "colorScheme", | ||
value: function colorScheme() { | ||
var _this = this; | ||
var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.color; | ||
var opacity = { | ||
text: { | ||
black: 0.88, | ||
white: 1 | ||
}, | ||
faded: { | ||
black: 14, | ||
white: 14 | ||
}, | ||
soft: { | ||
black: 0.66, | ||
white: 0.88 | ||
}, | ||
placeholder: { | ||
black: 0.33, | ||
white: 0.66 | ||
}, | ||
transparent: { | ||
black: 0.11, | ||
white: 0.33 | ||
}, | ||
shadow: { | ||
black: 0.066, | ||
white: 0.11 | ||
}, | ||
screen: { | ||
black: 0.033, | ||
white: 0.066 | ||
} | ||
}; | ||
var background = ['--background', '--content', '--toolbar', '--button']; | ||
var attribute = ['', '-focus', '-focus_faded', '-focus_soft', '-focus_shadow', '-focus_transparent', '-focus_screen', '-focus-text', '-text', '-text_soft', '-text_shadow', '-text_transparent', '-text_screen', '-placeholder']; | ||
var fixedValue = { | ||
'--shadow': 'rgba(0, 0, 0, 0.05)', | ||
'--shade': 'rgba(0, 0, 0, 0.15)', | ||
'--light': 'rgba(255, 255, 255, 0.15)', | ||
'--alert': this.colorName.tomato, | ||
'--overlay': 'rgba(0, 0, 0, 0.25)' | ||
}; | ||
for (var _i = 0, _arr = ['transparent', 'soft', 'shadow', 'screen']; _i < _arr.length; _i++) { | ||
var l = _arr[_i]; | ||
fixedValue['--alert-' + l] = this.rgba(opacity[l].black, fixedValue['--alert']).string; | ||
} | ||
var focusDefault = this._colorType(color).color; | ||
var variableList = function () { | ||
var list = []; | ||
var _iterator2 = _createForOfIteratorHelper(background), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var bk = _step2.value; | ||
// --{background}-{background(_attribute)}-{target(_attribute)} | ||
var _iterator3 = _createForOfIteratorHelper(attribute), | ||
_step3; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var att = _step3.value; | ||
list.push(bk + att); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
return list; | ||
}(); | ||
var scheme = {}; | ||
var missingList = []; | ||
var focusColorKey = []; | ||
var fillMissing = function fillMissing(missing) { | ||
var _iterator4 = _createForOfIteratorHelper(missing), | ||
_step4; | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var m = _step4.value; | ||
var splitKey = m.split('-'); | ||
var target = splitKey[splitKey.length - 1]; | ||
if (splitKey.length === 3) { | ||
// '--background', | ||
// '--content', | ||
// '--toolbar', | ||
// '--button' | ||
if (target === 'button') { | ||
if (focusColorKey.length) scheme[m] = scheme[focusColorKey[focusColorKey.length - 1]];else scheme[m] = focusDefault; | ||
} else { | ||
if (scheme[m + '-text']) scheme[m] = _this.textColor(opacity.text, scheme[m + '-text']);else { | ||
var t = _this.textColor(); | ||
if (target === 'background' && t === '#ffffff') t = _this.adjustBrightness(-4, t);else if (target === 'content' && scheme['--background'] && !_this.isHighLuminance(scheme['--background'])) t = _this.adjustBrightness(14, scheme['--background']); | ||
scheme[m] = t; | ||
} | ||
} | ||
} else { | ||
if (target === 'focus') { | ||
if (focusColorKey.length) scheme[m] = scheme[focusColorKey[focusColorKey.length - 1]];else if (scheme['--button']) scheme[m] = scheme['--button'];else scheme[m] = focusDefault; | ||
} else if (target === 'text' || target === 'placeholder') { | ||
var bk_key = m.replace('-' + target, ''); | ||
if (scheme[bk_key]) scheme[m] = _this.textColor(opacity[target], scheme[bk_key]);else scheme[m] = "#808080"; | ||
} else if (target.includes('faded')) { | ||
var t_key = m.replace('_faded', ''); | ||
if (scheme[t_key]) scheme[m] = _this.adjustBrightness(_this.isHighLuminance(scheme[t_key]) ? opacity.faded.black : opacity.faded.white, scheme[t_key]);else scheme[m] = "#808080"; | ||
} else { | ||
for (var _i2 = 0, _arr2 = ['transparent', 'soft', 'shadow', 'screen']; _i2 < _arr2.length; _i2++) { | ||
var _l = _arr2[_i2]; | ||
if (target.includes(_l)) { | ||
var _t_key = m.replace('_' + _l, ''); | ||
if (scheme[_t_key]) scheme[m] = _this.rgba(_this.isHighLuminance(scheme[_t_key]) ? opacity[_l].white : opacity[_l].black, scheme[_t_key]).string;else scheme[m] = "#808080"; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
}; | ||
if (_typeof(color) === 'object' && Object.keys(color).length && !Array.isArray(color)) { | ||
var _iterator5 = _createForOfIteratorHelper(variableList), | ||
_step5; | ||
try { | ||
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { | ||
var k = _step5.value; | ||
if (color[k]) { | ||
var splitKey = k.split('-'); | ||
var target = splitKey[splitKey.length - 1]; | ||
if (target === 'button' || target === 'focus') focusColorKey.push(k); | ||
scheme[k] = color[k]; | ||
} else missingList.push(k); | ||
} | ||
} catch (err) { | ||
_iterator5.e(err); | ||
} finally { | ||
_iterator5.f(); | ||
} | ||
if (missingList.length) fillMissing(missingList); | ||
} else if (typeof color === 'string') { | ||
fillMissing(variableList); | ||
} | ||
return Object.assign(fixedValue, scheme); | ||
} | ||
/** | ||
* Check if the color has high luminance. | ||
* @return {boolean} | ||
*/ | ||
}, { | ||
key: "isHighLuminance", | ||
value: function isHighLuminance() { | ||
var color_arg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.color; | ||
var fineTuned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var _this$rgba = this.rgba(1, this._colorType(color_arg).color), | ||
r = _this$rgba.r, | ||
g = _this$rgba.g, | ||
b = _this$rgba.b; | ||
var yiq = fineTuned ? (r * (299 - 128) + g * (587 + 64) + b * (114 + 64)) / 1000 : // Fine tuned | ||
(r * 299 + g * 587 + b * 114) / 1000; // Standard color space formula | ||
// Web standard of color space threshold is 128 | ||
return yiq >= (fineTuned ? 142 : 128); | ||
} | ||
/** | ||
* Returns contrast ratio between the given color. | ||
* Useful to determine if the given color is suitable for text with the constructed color as a background. | ||
* @param {string} color_arg - Color string you want to compare luminance ratio. | ||
* @return {number} | ||
*/ | ||
}, { | ||
key: "contrastRatio", | ||
value: function contrastRatio(color_arg) { | ||
var _this2 = this; | ||
var luminance = function luminance(c) { | ||
var rgb = _this2.rgba(1, c); | ||
var a = [rgb.r, rgb.g, rgb.b].map(function (v) { | ||
v /= 255; | ||
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); | ||
}); | ||
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722; | ||
}; | ||
var lum1 = luminance(this.color) + 0.05; | ||
var lum2 = luminance(color_arg) + 0.05; | ||
return lum1 > lum2 ? lum1 / lum2 : lum2 / lum1; | ||
} | ||
/** | ||
* Returns suitable text color (Black / White). | ||
* @param {number | {}} opacity - Can set returning color values opacity. | ||
* @param {number} opacity.black - Set returning color values opacity when the result color is black. | ||
* @param {number} opacity.white - Set returning color values opacity when the result color is white. | ||
* @return {number} | ||
*/ | ||
}, { | ||
key: "textColor", | ||
value: function textColor() { | ||
var opacity = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var color_arg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.color; | ||
var blackOpacity, whiteOpacity; | ||
if (typeof opacity === 'number' && opacity < 1) { | ||
blackOpacity = opacity; | ||
whiteOpacity = opacity; | ||
} else if (opacity && _typeof(opacity) === 'object') { | ||
for (var _i3 = 0, _arr3 = ['black', 'white']; _i3 < _arr3.length; _i3++) { | ||
var k = _arr3[_i3]; | ||
var _opa = opacity[k]; | ||
if (typeof _opa === 'number' && _opa < 1) { | ||
if (k === 'black') blackOpacity = _opa;else if (k === 'white') whiteOpacity = _opa; | ||
} | ||
} | ||
} | ||
var opa = function opa(v) { | ||
if (typeof v === 'number') { | ||
if (v < 1 && v > 0) return v;else if (v > 1) return 1;else return 0; | ||
} else return 1; | ||
}; | ||
if (this.isHighLuminance(this._colorType(color_arg).color)) return blackOpacity ? "rgba(0, 0, 0, ".concat(opa(blackOpacity), ")") : '#000000'; | ||
return whiteOpacity ? "rgba(255, 255, 255, ".concat(opa(whiteOpacity), ")") : '#ffffff'; | ||
} | ||
/** | ||
* Returns hsla color | ||
* @param {number} opacity - Set opacity for returning color value. | ||
* @return {object} | ||
*/ | ||
}, { | ||
key: "hsla", | ||
value: function hsla() { | ||
var opacity = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var color_arg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.color; | ||
var _this$_colorType2 = this._colorType(color_arg), | ||
_this$_colorType2$typ = _this$_colorType2.type, | ||
type = _this$_colorType2$typ === void 0 ? this.type : _this$_colorType2$typ, | ||
_this$_colorType2$col = _this$_colorType2.color, | ||
color = _this$_colorType2$col === void 0 ? this.color : _this$_colorType2$col; | ||
var hsl = function hsl(r, g, b) { | ||
r /= 255; | ||
g /= 255; | ||
b /= 255; | ||
var c_min = Math.min(r, g, b), | ||
c_max = Math.max(r, g, b), | ||
delta = c_max - c_min, | ||
h = 0, | ||
s = 0, | ||
l = 0; | ||
if (delta === 0) h = 0;else if (c_max === r) h = (g - b) / delta % 6;else if (c_max === g) h = (b - r) / delta + 2;else h = (r - g) / delta + 4; | ||
h = Math.round(h * 60); | ||
if (h < 0) h += 360; | ||
l = (c_max + c_min) / 2; | ||
s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)); | ||
s = +(s * 100).toFixed(1); | ||
l = +(l * 100).toFixed(1); | ||
return { | ||
h: h, | ||
s: s, | ||
l: l | ||
}; | ||
}; | ||
if (type === 'hex') { | ||
opacity = typeof opacity === 'number' ? opacity : 1; | ||
var rgba = this.rgba(opacity, color); | ||
var r = rgba.r, | ||
g = rgba.g, | ||
b = rgba.b, | ||
a = rgba.a; | ||
var _hsl = hsl(r, g, b), | ||
h = _hsl.h, | ||
s = _hsl.s, | ||
l = _hsl.l; | ||
return { | ||
r: r, | ||
g: g, | ||
b: b, | ||
a: a, | ||
h: h, | ||
s: s, | ||
l: l, | ||
string: 'hsla(' + h + ', ' + s + '%, ' + l + '%, ' + opacity + ')' | ||
}; | ||
} else { | ||
var digit = this._extractRGBAHSLADigit(color); | ||
opacity = typeof opacity === 'number' ? opacity : digit[3] || 1; | ||
if (type.includes('hsl')) { | ||
var _this$rgba2 = this.rgba(opacity, color), | ||
_r = _this$rgba2.r, | ||
_g = _this$rgba2.g, | ||
_b = _this$rgba2.b, | ||
_a = _this$rgba2.a; | ||
return { | ||
r: _r, | ||
g: _g, | ||
b: _b, | ||
a: _a, | ||
h: digit[0], | ||
s: digit[1], | ||
l: digit[2], | ||
string: 'hsla(' + digit[0] + ', ' + digit[1] + '%, ' + digit[2] + '%, ' + _a + ')' | ||
}; | ||
} else if (type.includes('rgb')) { | ||
var value = { | ||
r: digit[0], | ||
g: digit[1], | ||
b: digit[2], | ||
a: opacity | ||
}; | ||
var _hsl2 = hsl(value.r, value.g, value.b), | ||
_h = _hsl2.h, | ||
_s = _hsl2.s, | ||
_l2 = _hsl2.l; | ||
return Object.assign(value, { | ||
r: value.r, | ||
g: value.g, | ||
b: value.b, | ||
h: _h, | ||
s: _s, | ||
l: _l2, | ||
a: value.a, | ||
string: 'hsla(' + _h + ', ' + _s + '%, ' + _l2 + '%, ' + value.a + ')' | ||
}); | ||
} | ||
} | ||
} | ||
/** | ||
* Returns hex color string | ||
* @return {string} | ||
*/ | ||
}, { | ||
key: "hex", | ||
value: function hex() { | ||
var color_arg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.color; | ||
var _this$_colorType3 = this._colorType(color_arg), | ||
_this$_colorType3$typ = _this$_colorType3.type, | ||
type = _this$_colorType3$typ === void 0 ? this.type : _this$_colorType3$typ, | ||
_this$_colorType3$col = _this$_colorType3.color, | ||
color = _this$_colorType3$col === void 0 ? this.color : _this$_colorType3$col; | ||
if (type.includes('rgb') || type.includes('hsl')) { | ||
var opacity = this._extractRGBAHSLADigit(color)[3] || 1; | ||
var rgba = this.rgba(opacity, color); | ||
return '#' + ((1 << 24) + (rgba.r << 16) + (rgba.g << 8) + rgba.b).toString(16).slice(1); | ||
} | ||
return color; | ||
} | ||
/** | ||
* Returns rgba color | ||
* @param {number} opacity - Set opacity of returning color | ||
* @return {object} | ||
*/ | ||
}, { | ||
key: "rgba", | ||
value: function rgba() { | ||
var opacity = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var color_arg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.color; | ||
var _this$_colorType4 = this._colorType(color_arg), | ||
_this$_colorType4$typ = _this$_colorType4.type, | ||
type = _this$_colorType4$typ === void 0 ? this.type : _this$_colorType4$typ, | ||
_this$_colorType4$col = _this$_colorType4.color, | ||
color = _this$_colorType4$col === void 0 ? this.color : _this$_colorType4$col; | ||
if (type === 'hex') { | ||
var hex = color; | ||
var r, g, b; | ||
if (hex.length === 4) { | ||
r = '0x' + hex[1] + hex[1]; | ||
g = '0x' + hex[2] + hex[2]; | ||
b = '0x' + hex[3] + hex[3]; | ||
} else if (hex.length === 7) { | ||
r = '0x' + hex[1] + hex[2]; | ||
g = '0x' + hex[3] + hex[4]; | ||
b = '0x' + hex[5] + hex[6]; | ||
} | ||
var opacity_value = typeof opacity === 'number' ? opacity : 1; | ||
return { | ||
r: +r, | ||
g: +g, | ||
b: +b, | ||
a: opacity_value, | ||
string: "rgba(".concat(+r, ", ").concat(+g, ", ").concat(+b, ", ").concat(opacity_value, ")") | ||
}; | ||
} else { | ||
var digit = this._extractRGBAHSLADigit(color); | ||
var a = typeof opacity === 'number' ? opacity : digit[3] || 1; | ||
if (type.includes('rgb')) { | ||
var value = { | ||
r: digit[0], | ||
g: digit[1], | ||
b: digit[2], | ||
a: a | ||
}; | ||
return Object.assign({ | ||
string: "rgba(".concat(value.r, ", ").concat(value.g, ", ").concat(value.b, ", ").concat(value.a, ")") | ||
}, value); | ||
} else if (type.includes('hsl')) { | ||
var h = digit[0]; | ||
var s = digit[1]; | ||
var l = digit[2]; | ||
s /= 100; | ||
l /= 100; | ||
var c = (1 - Math.abs(2 * l - 1)) * s, | ||
x = c * (1 - Math.abs(h / 60 % 2 - 1)), | ||
m = l - c / 2, | ||
_r2 = 0, | ||
_g2 = 0, | ||
_b2 = 0; | ||
if (0 <= h && h < 60) { | ||
_r2 = c; | ||
_g2 = x; | ||
_b2 = 0; | ||
} else if (60 <= h && h < 120) { | ||
_r2 = x; | ||
_g2 = c; | ||
_b2 = 0; | ||
} else if (120 <= h && h < 180) { | ||
_r2 = 0; | ||
_g2 = c; | ||
_b2 = x; | ||
} else if (180 <= h && h < 240) { | ||
_r2 = 0; | ||
_g2 = x; | ||
_b2 = c; | ||
} else if (240 <= h && h < 300) { | ||
_r2 = x; | ||
_g2 = 0; | ||
_b2 = c; | ||
} else if (300 <= h && h < 360) { | ||
_r2 = c; | ||
_g2 = 0; | ||
_b2 = x; | ||
} | ||
_r2 = Math.round((_r2 + m) * 255); | ||
_g2 = Math.round((_g2 + m) * 255); | ||
_b2 = Math.round((_b2 + m) * 255); | ||
return { | ||
r: _r2, | ||
g: _g2, | ||
b: _b2, | ||
a: a, | ||
string: 'rgba(' + _r2 + ', ' + _g2 + ', ' + _b2 + ', ' + a + ')' | ||
}; | ||
} | ||
} | ||
} | ||
/** | ||
* Returns brightness adjusted color string | ||
* @param {number} light - Adjust value. Darker when minus. | ||
* @return {string} | ||
*/ | ||
}, { | ||
key: "adjustBrightness", | ||
value: function adjustBrightness() { | ||
var light = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var color_arg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.color; | ||
var _this$_colorType5 = this._colorType(color_arg), | ||
_this$_colorType5$typ = _this$_colorType5.type, | ||
type = _this$_colorType5$typ === void 0 ? this.type : _this$_colorType5$typ, | ||
_this$_colorType5$col = _this$_colorType5.color, | ||
color = _this$_colorType5$col === void 0 ? this.color : _this$_colorType5$col; | ||
if (light === 0) return color; | ||
var opacity = type === 'hex' ? 1 : this._extractRGBAHSLADigit(color)[3] || 1; | ||
var rgb = this.rgba(opacity, color); | ||
var rgbRange = { | ||
r: 0 - rgb['r'], | ||
g: 0 - rgb['g'], | ||
b: 0 - rgb['b'] | ||
}; | ||
if (light > 0) { | ||
Object.keys(rgbRange).map(function (key) { | ||
rgbRange[key] = 255 - rgb[key]; | ||
}); | ||
} | ||
['r', 'g', 'b'].map(function (key) { | ||
rgb[key] += parseInt(rgbRange[key] / 100 * Math.abs(light)); | ||
}); | ||
var result = 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')'; | ||
if (type === 'hex') return this.hex(result);else if (type.includes('rgb')) return this.rgba(rgb.a, result).string;else if (type.includes('hsl')) return this.hsla(rgb.a, result).string; | ||
} | ||
}]); | ||
return ColorMangle; | ||
}(); | ||
exports.ColorMangle = ColorMangle; | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _createForOfIteratorHelper(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=_unsupportedIterableToArray(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var a=0,o=function(){};return{s:o,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var n,i=!0,l=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return i=e.done,e},e:function(e){l=!0,n=e},f:function(){try{i||null==t.return||t.return()}finally{if(l)throw n}}}}function _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,a=new Array(r);t<r;t++)a[t]=e[t];return a}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var a=r[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.ColorMangle=void 0;var ColorMangle=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"teal";_classCallCheck(this,e),this.colorName={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",goldenrod:"#daa520",gold:"#ffd700",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavenderblush:"#fff0f5",lavender:"#e6e6fa",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};var t=this._colorType(r);this.type=t.type,this.color=t.color}return _createClass(e,[{key:"_extractRGBAHSLADigit",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.color,r=this._colorType(e),t=r.type,a=void 0===t?this.type:t,o=r.color,n=void 0===o?this.color:o;if("hex"===a)return null;var i,l=[],f=_createForOfIteratorHelper(n.match(/\d+(\.\d+)?/g));try{for(f.s();!(i=f.n()).done;){var c=i.value;l.push(parseFloat(c))}}catch(e){f.e(e)}finally{f.f()}return l.length<4&&l.push(1),l}},{key:"_colorType",value:function(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.color,a=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];try{if(!t)throw"invalid color";if("object"===_typeof(t)&&t.string&&(t=t.string),"string"!=typeof t)throw"invalid color";if((t=t.toLowerCase())===this.color)return{type:this.type,color:this.color};if(this.colorName[t])return{type:"hex",color:this.colorName[t]};if(e=t.match(/^(rgba?|rgb?|hsla?|#)/g),Array.isArray(e)){if("#"===e[0]){if(4===t.length&&(t=t[0]+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]),!/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))throw"invalid hex";r="hex"}else")"===t[t.length-1]&&(r=e[0]);return{type:r,color:t}}}catch(e){if(a)throw e}return{}}},{key:"colorScheme",value:function(){for(var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.color,t={text:{black:.88,white:1},faded:{black:14,white:14},soft:{black:.66,white:.88},placeholder:{black:.33,white:.66},transparent:{black:.11,white:.33},shadow:{black:.066,white:.11},screen:{black:.033,white:.066}},a=["--background","--content","--toolbar","--button"],o=["","-focus","-focus_faded","-focus_soft","-focus_shadow","-focus_transparent","-focus_screen","-focus-text","-text","-text_soft","-text_shadow","-text_transparent","-text_screen","-placeholder"],n={"--shadow":"rgba(0, 0, 0, 0.05)","--shade":"rgba(0, 0, 0, 0.15)","--light":"rgba(255, 255, 255, 0.15)","--alert":this.colorName.tomato,"--overlay":"rgba(0, 0, 0, 0.25)"},i=0,l=["transparent","soft","shadow","screen"];i<l.length;i++){var f=l[i];n["--alert-"+f]=this.rgba(t[f].black,n["--alert"]).string}var c=this._colorType(r).color,s=function(){var e,r=[],t=_createForOfIteratorHelper(a);try{for(t.s();!(e=t.n()).done;){var n,i=e.value,l=_createForOfIteratorHelper(o);try{for(l.s();!(n=l.n()).done;){var f=n.value;r.push(i+f)}}catch(e){l.e(e)}finally{l.f()}}}catch(e){t.e(e)}finally{t.f()}return r}(),d={},h=[],u=[],g=function(r){var a,o=_createForOfIteratorHelper(r);try{for(o.s();!(a=o.n()).done;){var n=a.value,i=n.split("-"),l=i[i.length-1];if(3===i.length)if("button"===l)u.length?d[n]=d[u[u.length-1]]:d[n]=c;else if(d[n+"-text"])d[n]=e.textColor(t.text,d[n+"-text"]);else{var f=e.textColor();"background"===l&&"#ffffff"===f?f=e.adjustBrightness(-4,f):"content"===l&&d["--background"]&&!e.isHighLuminance(d["--background"])&&(f=e.adjustBrightness(14,d["--background"])),d[n]=f}else if("focus"===l)u.length?d[n]=d[u[u.length-1]]:d["--button"]?d[n]=d["--button"]:d[n]=c;else if("text"===l||"placeholder"===l){var s=n.replace("-"+l,"");d[s]?d[n]=e.textColor(t[l],d[s]):d[n]="#808080"}else if(l.includes("faded")){var h=n.replace("_faded","");d[h]?d[n]=e.adjustBrightness(e.isHighLuminance(d[h])?t.faded.black:t.faded.white,d[h]):d[n]="#808080"}else for(var g=0,b=["transparent","soft","shadow","screen"];g<b.length;g++){var y=b[g];if(l.includes(y)){var p=n.replace("_"+y,"");d[p]?d[n]=e.rgba(e.isHighLuminance(d[p])?t[y].white:t[y].black,d[p]).string:d[n]="#808080"}}}}catch(e){o.e(e)}finally{o.f()}};if("object"===_typeof(r)&&Object.keys(r).length&&!Array.isArray(r)){var b,y=_createForOfIteratorHelper(s);try{for(y.s();!(b=y.n()).done;){var p=b.value;if(r[p]){var v=p.split("-"),m=v[v.length-1];"button"!==m&&"focus"!==m||u.push(p),d[p]=r[p]}else h.push(p)}}catch(e){y.e(e)}finally{y.f()}h.length&&g(h)}else"string"==typeof r&&g(s);return Object.assign(n,d)}},{key:"isHighLuminance",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.color,r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],t=this.rgba(1,this._colorType(e).color),a=t.r,o=t.g,n=t.b,i=r?(171*a+651*o+178*n)/1e3:(299*a+587*o+114*n)/1e3;return i>=(r?142:128)}},{key:"contrastRatio",value:function(e){var r=this,t=function(e){var t=r.rgba(1,e),a=[t.r,t.g,t.b].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*a[0]+.7152*a[1]+.0722*a[2]},a=t(this.color)+.05,o=t(e)+.05;return a>o?a/o:o/a}},{key:"textColor",value:function(){var e,r,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.color;if("number"==typeof t&&t<1)e=t,r=t;else if(t&&"object"===_typeof(t))for(var o=0,n=["black","white"];o<n.length;o++){var i=n[o],l=t[i];"number"==typeof l&&l<1&&("black"===i?e=l:"white"===i&&(r=l))}var f=function(e){return"number"==typeof e?e<1&&e>0?e:e>1?1:0:1};return this.isHighLuminance(this._colorType(a).color)?e?"rgba(0, 0, 0, ".concat(f(e),")"):"#000000":r?"rgba(255, 255, 255, ".concat(f(r),")"):"#ffffff"}},{key:"hsla",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.color,t=this._colorType(r),a=t.type,o=void 0===a?this.type:a,n=t.color,i=void 0===n?this.color:n,l=function(e,r,t){e/=255,r/=255,t/=255;var a=Math.min(e,r,t),o=Math.max(e,r,t),n=o-a,i=0,l=0;return i=0===n?0:o===e?(r-t)/n%6:o===r?(t-e)/n+2:(e-r)/n+4,(i=Math.round(60*i))<0&&(i+=360),l=(o+a)/2,{h:i,s:+(100*(0===n?0:n/(1-Math.abs(2*l-1)))).toFixed(1),l:l=+(100*l).toFixed(1)}};if("hex"===o){e="number"==typeof e?e:1;var f=this.rgba(e,i),c=f.r,s=f.g,d=f.b,h=f.a,u=l(c,s,d),g=u.h,b=u.s,y=u.l;return{r:c,g:s,b:d,a:h,h:g,s:b,l:y,string:"hsla("+g+", "+b+"%, "+y+"%, "+e+")"}}var p=this._extractRGBAHSLADigit(i);if(e="number"==typeof e?e:p[3]||1,o.includes("hsl")){var v=this.rgba(e,i),m=v.r,k=v.g,w=v.b,_=v.a;return{r:m,g:k,b:w,a:_,h:p[0],s:p[1],l:p[2],string:"hsla("+p[0]+", "+p[1]+"%, "+p[2]+"%, "+_+")"}}if(o.includes("rgb")){var x={r:p[0],g:p[1],b:p[2],a:e},A=l(x.r,x.g,x.b),j=A.h,S=A.s,C=A.l;return Object.assign(x,{r:x.r,g:x.g,b:x.b,h:j,s:S,l:C,a:x.a,string:"hsla("+j+", "+S+"%, "+C+"%, "+x.a+")"})}}},{key:"hex",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.color,r=this._colorType(e),t=r.type,a=void 0===t?this.type:t,o=r.color,n=void 0===o?this.color:o;if(a.includes("rgb")||a.includes("hsl")){var i=this._extractRGBAHSLADigit(n)[3]||1,l=this.rgba(i,n);return"#"+((1<<24)+(l.r<<16)+(l.g<<8)+l.b).toString(16).slice(1)}return n}},{key:"rgba",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.color,t=this._colorType(r),a=t.type,o=void 0===a?this.type:a,n=t.color,i=void 0===n?this.color:n;if("hex"===o){var l,f,c,s=i;4===s.length?(l="0x"+s[1]+s[1],f="0x"+s[2]+s[2],c="0x"+s[3]+s[3]):7===s.length&&(l="0x"+s[1]+s[2],f="0x"+s[3]+s[4],c="0x"+s[5]+s[6]);var d="number"==typeof e?e:1;return{r:+l,g:+f,b:+c,a:d,string:"rgba(".concat(+l,", ").concat(+f,", ").concat(+c,", ").concat(d,")")}}var h=this._extractRGBAHSLADigit(i),u="number"==typeof e?e:h[3]||1;if(o.includes("rgb")){var g={r:h[0],g:h[1],b:h[2],a:u};return Object.assign({string:"rgba(".concat(g.r,", ").concat(g.g,", ").concat(g.b,", ").concat(g.a,")")},g)}if(o.includes("hsl")){var b=h[0],y=h[1],p=h[2];y/=100,p/=100;var v=(1-Math.abs(2*p-1))*y,m=v*(1-Math.abs(b/60%2-1)),k=p-v/2,w=0,_=0,x=0;return 0<=b&&b<60?(w=v,_=m,x=0):60<=b&&b<120?(w=m,_=v,x=0):120<=b&&b<180?(w=0,_=v,x=m):180<=b&&b<240?(w=0,_=m,x=v):240<=b&&b<300?(w=m,_=0,x=v):300<=b&&b<360&&(w=v,_=0,x=m),{r:w=Math.round(255*(w+k)),g:_=Math.round(255*(_+k)),b:x=Math.round(255*(x+k)),a:u,string:"rgba("+w+", "+_+", "+x+", "+u+")"}}}},{key:"adjustBrightness",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.color,t=this._colorType(r),a=t.type,o=void 0===a?this.type:a,n=t.color,i=void 0===n?this.color:n;if(0===e)return i;var l="hex"===o?1:this._extractRGBAHSLADigit(i)[3]||1,f=this.rgba(l,i),c={r:0-f.r,g:0-f.g,b:0-f.b};e>0&&Object.keys(c).map((function(e){c[e]=255-f[e]})),["r","g","b"].map((function(r){f[r]+=parseInt(c[r]/100*Math.abs(e))}));var s="rgb("+f.r+", "+f.g+", "+f.b+")";return"hex"===o?this.hex(s):o.includes("rgb")?this.rgba(f.a,s).string:o.includes("hsl")?this.hsla(f.a,s).string:void 0}}]),e}();exports.ColorMangle=ColorMangle; |
{ | ||
"name": "colormangle", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "converts html color strings to various format", | ||
"main": "colormangle.min.js", | ||
"main": "colormangle.js", | ||
"scripts": { | ||
@@ -14,6 +14,3 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
"keywords": [ | ||
"rgb", | ||
"hex", | ||
"hsl", | ||
"color" | ||
"colormangle" | ||
], | ||
@@ -20,0 +17,0 @@ "author": "Baksa Gimm", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14040
2
52
1