Comparing version 0.1.3 to 0.2.0
@@ -10,2 +10,13 @@ # Changelog | ||
## [0.2.0] - 2018-05-16 | ||
### Changed | ||
- Now available give color argument as `ColorData` in MooColor constructor. #7 | ||
- Changes `random()` to static method. #6 | ||
### Removed | ||
- Removed `random()` method. use static [`random()`](https://github.com/archco/moo-color/blob/master/docs/static.md#random) method instead. | ||
## [0.1.3] - 2018-03-30 | ||
@@ -35,5 +46,6 @@ | ||
[Unreleased]: https://github.com/archco/moo-color/compare/v0.1.3...HEAD | ||
[Unreleased]: https://github.com/archco/moo-color/compare/v0.2.0...HEAD | ||
[0.2.0]: https://github.com/archco/moo-color/compare/v0.1.3...v0.2.0 | ||
[0.1.3]: https://github.com/archco/moo-color/compare/v0.1.1...v0.1.3 | ||
[0.1.1]: https://github.com/archco/moo-color/compare/v0.1.0...v0.1.1 | ||
[0.1.0]: https://github.com/archco/moo-color/compare/a4dfebd...v0.1.0 |
@@ -858,30 +858,28 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function inputParser(input) { | ||
if (typeof input === 'string') { | ||
if (input in _color_names__WEBPACK_IMPORTED_MODULE_1__["default"]) { | ||
// Named colors. | ||
return { | ||
model: 'rgb', | ||
values: _color_names__WEBPACK_IMPORTED_MODULE_1__["default"][input], | ||
alpha: 1, | ||
}; | ||
if (input in _color_names__WEBPACK_IMPORTED_MODULE_1__["default"]) { | ||
// Named colors. | ||
return { | ||
model: 'rgb', | ||
values: _color_names__WEBPACK_IMPORTED_MODULE_1__["default"][input], | ||
alpha: 1, | ||
}; | ||
} | ||
else if (input === 'transparent') { | ||
// 'transparent'. | ||
return { | ||
model: 'rgb', | ||
values: [0, 0, 0], | ||
alpha: 0, | ||
}; | ||
} | ||
else { | ||
// parse string. | ||
var prefix = input.substr(0, 3).toLowerCase(); | ||
switch (prefix) { | ||
case 'hwb': return parseHwb(input); | ||
case 'hsl': return parseHsl(input); | ||
case 'hsv': return parseHsv(input); | ||
case 'cmy': return parseCmyk(input); | ||
default: return parseRgb(input); | ||
} | ||
else if (input === 'transparent') { | ||
// 'transparent'. | ||
return { | ||
model: 'rgb', | ||
values: [0, 0, 0], | ||
alpha: 0, | ||
}; | ||
} | ||
else { | ||
// parse string. | ||
var prefix = input.substr(0, 3).toLowerCase(); | ||
switch (prefix) { | ||
case 'hwb': return parseHwb(input); | ||
case 'hsl': return parseHsl(input); | ||
case 'hsv': return parseHsv(input); | ||
case 'cmy': return parseCmyk(input); | ||
default: return parseRgb(input); | ||
} | ||
} | ||
} | ||
@@ -1014,7 +1012,8 @@ } | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MooColor", function() { return MooColor; }); | ||
/* harmony import */ var _color_formatter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./color-formatter */ "./src/color-formatter.ts"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ColorFormatter", function() { return _color_formatter__WEBPACK_IMPORTED_MODULE_0__["default"]; }); | ||
/* harmony import */ var _color_converter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./color-converter */ "./src/color-converter.ts"); | ||
/* harmony import */ var _color_formatter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./color-formatter */ "./src/color-formatter.ts"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ColorFormatter", function() { return _color_formatter__WEBPACK_IMPORTED_MODULE_1__["default"]; }); | ||
/* harmony import */ var _input_parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./input-parser */ "./src/input-parser.ts"); | ||
/* harmony import */ var _util_util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./util/util */ "./src/util/util.ts"); | ||
/* harmony import */ var _input_parser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./input-parser */ "./src/input-parser.ts"); | ||
/* harmony import */ var _util_util__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./util/util */ "./src/util/util.ts"); | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
@@ -1034,2 +1033,3 @@ var extendStatics = Object.setPrototypeOf || | ||
var MooColor = /** @class */ (function (_super) { | ||
@@ -1039,8 +1039,14 @@ __extends(MooColor, _super); | ||
* Creates an instance of MooColor. | ||
* @param {*} [color] color string. e.g. '#ff0000' 'rgba(255, 0, 0, .5)' 'hsl(120, 50%, 100%)' | ||
* @param {(string|Color)} [color] color value. e.g. '#ff0000' 'rgba(255, 0, 0, .5)' 'hsl(120, 50%, 100%)' | ||
* @memberof MooColor | ||
*/ | ||
function MooColor(color) { | ||
var _this = _super.call(this) || this; | ||
color = color ? color : '#000'; | ||
_this.setColorByParser(color); | ||
if (typeof color === 'object' && color !== null) { | ||
_this.setColor(color); | ||
} | ||
else if (typeof color === 'string' || typeof color === 'undefined') { | ||
color = color ? color : '#000'; | ||
_this.setColorByParser(color); | ||
} | ||
return _this; | ||
@@ -1050,8 +1056,37 @@ } | ||
if (percentOf1 === void 0) { percentOf1 = 50; } | ||
var c1 = (typeof color1 === 'string') ? new MooColor(color1) : color1; | ||
var c2 = (typeof color2 === 'string') ? new MooColor(color2) : color2; | ||
var c1 = (color1 instanceof MooColor) ? color1 : new MooColor(color1); | ||
var c2 = (color2 instanceof MooColor) ? color2 : new MooColor(color2); | ||
return c2.mix(c1, percentOf1); | ||
}; | ||
/** | ||
* Create random color as HWB color model. | ||
* | ||
* @static | ||
* @param {RandomArguments} [{hue, white, black}={}] | ||
* @returns {MooColor} | ||
* @memberof MooColor | ||
*/ | ||
MooColor.random = function (_a) { | ||
var _b = _a === void 0 ? {} : _a, hue = _b.hue, white = _b.white, black = _b.black; | ||
_c = [hue, white, black].map(function (x, i) { | ||
if (typeof x === 'number') { | ||
return x; | ||
} | ||
else if (Array.isArray(x)) { | ||
var precision = i === 0 ? 0 : 2; | ||
return Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["getRandom"])(Math.min.apply(Math, x), Math.max.apply(Math, x), precision); | ||
} | ||
else { | ||
return i === 0 ? Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["getRandom"])(0, 360) : Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["getRandom"])(0, 100, 2); | ||
} | ||
}), hue = _c[0], white = _c[1], black = _c[2]; | ||
return new MooColor({ | ||
model: 'hwb', | ||
values: Object(_color_converter__WEBPACK_IMPORTED_MODULE_0__["resolveHwb"])(Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["degree"])(hue), Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(white, 0, 100), Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(black, 0, 100)), | ||
alpha: 1, | ||
}); | ||
var _c; | ||
}; | ||
MooColor.prototype.setColorByParser = function (str) { | ||
var color = Object(_input_parser__WEBPACK_IMPORTED_MODULE_1__["default"])(str); | ||
var color = Object(_input_parser__WEBPACK_IMPORTED_MODULE_2__["default"])(str); | ||
if (!color) { | ||
@@ -1063,3 +1098,3 @@ throw new Error('parsing error!'); | ||
MooColor.prototype.clone = function () { | ||
return new MooColor().setColor(this.color); | ||
return new MooColor(this.color); | ||
}; | ||
@@ -1145,3 +1180,3 @@ Object.defineProperty(MooColor.prototype, "brightness", { | ||
return this.manipulate('hsl', function (h, s, l) { | ||
l = Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(l + amount, 0, 100); | ||
l = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(l + amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1157,3 +1192,3 @@ }); | ||
return this.manipulate('hsl', function (h, s, l) { | ||
l = Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(l - amount, 0, 100); | ||
l = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(l - amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1169,3 +1204,3 @@ }); | ||
return this.manipulate('hsl', function (h, s, l) { | ||
s = Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(s + amount, 0, 100); | ||
s = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(s + amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1181,3 +1216,3 @@ }); | ||
return this.manipulate('hsl', function (h, s, l) { | ||
s = Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(s - amount, 0, 100); | ||
s = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(s - amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1200,3 +1235,3 @@ }); | ||
var _this = this; | ||
return this.manipulate('hwb', function (h, w, b) { return _this.resolveHwb(h, Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(w + amount, 0, 100), b); }); | ||
return this.manipulate('hwb', function (h, w, b) { return _this.resolveHwb(h, Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(w + amount, 0, 100), b); }); | ||
}; | ||
@@ -1210,3 +1245,3 @@ /** | ||
var _this = this; | ||
return this.manipulate('hwb', function (h, w, b) { return _this.resolveHwb(h, w, Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(b + amount, 0, 100)); }); | ||
return this.manipulate('hwb', function (h, w, b) { return _this.resolveHwb(h, w, Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(b + amount, 0, 100)); }); | ||
}; | ||
@@ -1219,3 +1254,3 @@ /** | ||
MooColor.prototype.rotate = function (d) { | ||
return this.manipulate('hsl', function (h, s, l) { return [Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["degree"])(h + d), s, l]; }); | ||
return this.manipulate('hsl', function (h, s, l) { return [Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["degree"])(h + d), s, l]; }); | ||
}; | ||
@@ -1234,3 +1269,3 @@ /** | ||
var c2 = color.getColorAs('rgb'); | ||
return new MooColor().setColor({ | ||
return new MooColor({ | ||
model: 'rgb', | ||
@@ -1247,3 +1282,3 @@ values: c1.values.map(function (v, i) { return v + (c2.values[i] - v) * percent; }), | ||
MooColor.prototype.complement = function () { | ||
return this.manipulate('hsl', function (h, s, l) { return [Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["degree"])(h + 180), s, l]; }); | ||
return this.manipulate('hsl', function (h, s, l) { return [Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["degree"])(h + 180), s, l]; }); | ||
}; | ||
@@ -1262,29 +1297,2 @@ /** | ||
}; | ||
/** | ||
* Sets random color values as HWB color model. | ||
* | ||
* @param {RandomArguments} [{hue, white, black}={}] | ||
* @returns {this} | ||
*/ | ||
MooColor.prototype.random = function (_a) { | ||
var _b = _a === void 0 ? {} : _a, hue = _b.hue, white = _b.white, black = _b.black; | ||
_c = [hue, white, black].map(function (x, i) { | ||
if (typeof x === 'number') { | ||
return x; | ||
} | ||
else if (Array.isArray(x)) { | ||
var precision = i === 0 ? 0 : 2; | ||
return Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["getRandom"])(Math.min.apply(Math, x), Math.max.apply(Math, x), precision); | ||
} | ||
else { | ||
return i === 0 ? Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["getRandom"])(0, 360) : Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["getRandom"])(0, 100, 2); | ||
} | ||
}), hue = _c[0], white = _c[1], black = _c[2]; | ||
return this.setColor({ | ||
model: 'hwb', | ||
values: this.resolveHwb(Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["degree"])(hue), Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(white, 0, 100), Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(black, 0, 100)), | ||
alpha: 1, | ||
}); | ||
var _c; | ||
}; | ||
MooColor.prototype.manipulate = function (asModel, callback) { | ||
@@ -1297,3 +1305,3 @@ var m = this.color.model; | ||
return MooColor; | ||
}(_color_formatter__WEBPACK_IMPORTED_MODULE_0__["default"])); | ||
}(_color_formatter__WEBPACK_IMPORTED_MODULE_1__["default"])); | ||
@@ -1300,0 +1308,0 @@ /* harmony default export */ __webpack_exports__["default"] = (MooColor); |
@@ -9,7 +9,7 @@ !function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.MooColor=r():t.MooColor=r()}(this,function(){return function(t){var r={};function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s="./src/moo-color.ts")}({"./node_modules/color-name/index.js": | ||
\********************************/ | ||
/*! exports provided: hslToRgb, rgbToHsl, hwbToRgb, rgbToHwb, cmykToRgb, rgbToCmyk, hsvToRgb, rgbToHsv, hsvToHwb, hwbToHsv, rgbToHex, hexToRgb, resolveHwb */function(t,r,e){"use strict";e.r(r),e.d(r,"hslToRgb",function(){return o}),e.d(r,"rgbToHsl",function(){return a}),e.d(r,"hwbToRgb",function(){return u}),e.d(r,"rgbToHwb",function(){return s}),e.d(r,"cmykToRgb",function(){return i}),e.d(r,"rgbToCmyk",function(){return c}),e.d(r,"hsvToRgb",function(){return l}),e.d(r,"rgbToHsv",function(){return h}),e.d(r,"hsvToHwb",function(){return p}),e.d(r,"hwbToHsv",function(){return f}),e.d(r,"rgbToHex",function(){return d}),e.d(r,"hexToRgb",function(){return b}),e.d(r,"resolveHwb",function(){return m});var n=e(/*! ./util/util */"./src/util/util.ts");function o(t,r,e){t/=60,r/=100,e/=100;var n,o,a,u=(1-Math.abs(2*e-1))*r,s=u*(1-Math.abs(t%2-1)),i=e-u/2;switch(Math.floor(t)){case 0:n=u,o=s,a=0;break;case 1:n=s,o=u,a=0;break;case 2:n=0,o=u,a=s;break;case 3:n=0,o=s,a=u;break;case 4:n=s,o=0,a=u;break;case 5:n=u,o=0,a=s}return[n,o,a].map(function(t){return 255*(t+i)})}function a(t,r,e){t/=255,r/=255,e/=255;var n,o=Math.max(t,r,e),a=Math.min(t,r,e),u=o-a;return n=(o+a)/2,[0===u?0:o===t?(r-e)/u%6*60:o===r?60*((e-t)/u+2):60*((t-r)/u+4),100*(0===u?0:u/(1-Math.abs(2*n-1))),100*n]}function u(t,r,e){var n=f(t,r,e);return l(n[0],n[1],n[2])}function s(t,r,e){var n=h(t,r,e);return p(n[0],n[1],n[2])}function i(t,r,e,n){return[255*(1-(t/=100))*(1-(n/=100)),255*(1-(r/=100))*(1-n),255*(1-(e/=100))*(1-n)]}function c(t,r,e){t/=255,r/=255,e/=255;var n=1-Math.max(t,r,e);return[(1-t-n)/(1-n),(1-r-n)/(1-n),(1-e-n)/(1-n),n].map(function(t){return 100*t})}function l(t,r,e){var n,o,a,u=t/60,s=(e/=100)*(r/=100),i=s*(1-Math.abs(u%2-1)),c=e-s;switch(Math.floor(u)){case 0:n=s,o=i,a=0;break;case 1:n=i,o=s,a=0;break;case 2:n=0,o=s,a=i;break;case 3:n=0,o=i,a=s;break;case 4:n=i,o=0,a=s;break;case 5:n=s,o=0,a=i}return[n,o,a].map(function(t){return 255*(t+c)})}function h(t,r,e){t/=255,r/=255,e/=255;var n=Math.max(t,r,e),o=n-Math.min(t,r,e);return[0===o?0:n===t?(r-e)/o%6*60:n===r?60*((e-t)/o+2):60*((t-r)/o+4),100*(0===n?0:o/n),100*n]}function p(t,r,e){return[t,100*((1-(r/=100))*(e/=100)),100*(1-e)]}function f(t,r,e){var n;return t=(n=m(t,r,e))[0],r=n[1],e=n[2],[t,100*(1-(r/=100)/(1-(e/=100))),100*(1-e)]}function d(t,r,e,o,a){var u=[t,r,e];"number"==typeof o&&u.push(Math.round(255*o));var s=u.map(function(t){return Object(n.padStart)(t.toString(16),2,"0")}).join("");return a?function(t){var r=!0,e=t.match(/.{2}/g);return e.forEach(function(t){t.match(/(.)\1+/)||(r=!1)}),r?e.map(function(t){return t.substring(1)}).join(""):t}(s):s}function b(t){return t.replace(/^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i,function(t,r,e,n,o){return r+r+e+e+n+n+(o=void 0===o?"":o)+o}).match(/.{2}/g).map(function(t,r){return 3!==r?parseInt(t,16):parseInt(t,16)/255})}function m(t,r,e){var n=r+e;return n>100&&(r=100*Number((r/n).toFixed(4)),e=100*Number((e/n).toFixed(4))),[t,r,e]}},"./src/color-formatter.ts": | ||
/*! exports provided: hslToRgb, rgbToHsl, hwbToRgb, rgbToHwb, cmykToRgb, rgbToCmyk, hsvToRgb, rgbToHsv, hsvToHwb, hwbToHsv, rgbToHex, hexToRgb, resolveHwb */function(t,r,e){"use strict";e.r(r),e.d(r,"hslToRgb",function(){return o}),e.d(r,"rgbToHsl",function(){return a}),e.d(r,"hwbToRgb",function(){return u}),e.d(r,"rgbToHwb",function(){return s}),e.d(r,"cmykToRgb",function(){return c}),e.d(r,"rgbToCmyk",function(){return i}),e.d(r,"hsvToRgb",function(){return l}),e.d(r,"rgbToHsv",function(){return h}),e.d(r,"hsvToHwb",function(){return p}),e.d(r,"hwbToHsv",function(){return f}),e.d(r,"rgbToHex",function(){return d}),e.d(r,"hexToRgb",function(){return b}),e.d(r,"resolveHwb",function(){return m});var n=e(/*! ./util/util */"./src/util/util.ts");function o(t,r,e){t/=60,r/=100,e/=100;var n,o,a,u=(1-Math.abs(2*e-1))*r,s=u*(1-Math.abs(t%2-1)),c=e-u/2;switch(Math.floor(t)){case 0:n=u,o=s,a=0;break;case 1:n=s,o=u,a=0;break;case 2:n=0,o=u,a=s;break;case 3:n=0,o=s,a=u;break;case 4:n=s,o=0,a=u;break;case 5:n=u,o=0,a=s}return[n,o,a].map(function(t){return 255*(t+c)})}function a(t,r,e){t/=255,r/=255,e/=255;var n,o=Math.max(t,r,e),a=Math.min(t,r,e),u=o-a;return n=(o+a)/2,[0===u?0:o===t?(r-e)/u%6*60:o===r?60*((e-t)/u+2):60*((t-r)/u+4),100*(0===u?0:u/(1-Math.abs(2*n-1))),100*n]}function u(t,r,e){var n=f(t,r,e);return l(n[0],n[1],n[2])}function s(t,r,e){var n=h(t,r,e);return p(n[0],n[1],n[2])}function c(t,r,e,n){return[255*(1-(t/=100))*(1-(n/=100)),255*(1-(r/=100))*(1-n),255*(1-(e/=100))*(1-n)]}function i(t,r,e){t/=255,r/=255,e/=255;var n=1-Math.max(t,r,e);return[(1-t-n)/(1-n),(1-r-n)/(1-n),(1-e-n)/(1-n),n].map(function(t){return 100*t})}function l(t,r,e){var n,o,a,u=t/60,s=(e/=100)*(r/=100),c=s*(1-Math.abs(u%2-1)),i=e-s;switch(Math.floor(u)){case 0:n=s,o=c,a=0;break;case 1:n=c,o=s,a=0;break;case 2:n=0,o=s,a=c;break;case 3:n=0,o=c,a=s;break;case 4:n=c,o=0,a=s;break;case 5:n=s,o=0,a=c}return[n,o,a].map(function(t){return 255*(t+i)})}function h(t,r,e){t/=255,r/=255,e/=255;var n=Math.max(t,r,e),o=n-Math.min(t,r,e);return[0===o?0:n===t?(r-e)/o%6*60:n===r?60*((e-t)/o+2):60*((t-r)/o+4),100*(0===n?0:o/n),100*n]}function p(t,r,e){return[t,100*((1-(r/=100))*(e/=100)),100*(1-e)]}function f(t,r,e){var n;return t=(n=m(t,r,e))[0],r=n[1],e=n[2],[t,100*(1-(r/=100)/(1-(e/=100))),100*(1-e)]}function d(t,r,e,o,a){var u=[t,r,e];"number"==typeof o&&u.push(Math.round(255*o));var s=u.map(function(t){return Object(n.padStart)(t.toString(16),2,"0")}).join("");return a?function(t){var r=!0,e=t.match(/.{2}/g);return e.forEach(function(t){t.match(/(.)\1+/)||(r=!1)}),r?e.map(function(t){return t.substring(1)}).join(""):t}(s):s}function b(t){return t.replace(/^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i,function(t,r,e,n,o){return r+r+e+e+n+n+(o=void 0===o?"":o)+o}).match(/.{2}/g).map(function(t,r){return 3!==r?parseInt(t,16):parseInt(t,16)/255})}function m(t,r,e){var n=r+e;return n>100&&(r=100*Number((r/n).toFixed(4)),e=100*Number((e/n).toFixed(4))),[t,r,e]}},"./src/color-formatter.ts": | ||
/*!********************************!*\ | ||
!*** ./src/color-formatter.ts ***! | ||
\********************************/ | ||
/*! exports provided: ColorFormatter, default */function(t,r,e){"use strict";e.r(r),e.d(r,"ColorFormatter",function(){return u});var n=e(/*! ./color-converter */"./src/color-converter.ts"),o=e(/*! ./color-names */"./src/color-names.ts"),a=e(/*! ./util/util */"./src/util/util.ts"),u=function(){function t(){this.resolveHwb=n.resolveHwb}return t.prototype.setColor=function(t){return t.alpha=Object(a.resolveAlpha)(t.alpha),this.color=t,this},t.prototype.getColor=function(){return this.color},t.prototype.getColorAs=function(t){return this.color.model===t?this.color:this.convert(this.color,t)},t.prototype.getModel=function(){return this.color?this.color.model:void 0},t.prototype.changeModel=function(t){return this.color.model===t?this:this.setColor(this.convert(this.color,t))},t.prototype.getAlpha=function(){return this.color.alpha},t.prototype.setAlpha=function(t){return this.color.alpha=t,this},t.prototype.convert=function(t,r){var e;switch(t.model){case"rgb":e=this.convertFromRgb(t.values,r);break;case"hwb":e=this.convertFromHwb(t.values,r);break;case"hsl":e=this.convertFromHsl(t.values,r);break;case"hsv":e=this.convertFromHsv(t.values,r);break;case"cmyk":e=this.convertFromCmyk(t.values,r)}if(!e.length)throw new Error("Converting Error!");return{model:r,values:e,alpha:t.alpha}},t.prototype.toString=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];switch(t=t||this.color.model){case"hex":return this.toHex.apply(this,r);case"hwb":return this.toHwb();case"hsl":return this.toHsl();case"hsv":return this.toHsv();case"cmyk":return this.toCmyk();default:return this.toRgb.apply(this,r)}},t.prototype.toHex=function(t){void 0===t&&(t="full");var r=this.getColorAs("rgb"),e=r.values.map(function(t){return Math.round(t)}),u=e[0],s=e[1],i=e[2],c=1===r.alpha?null:r.alpha;switch(t){case"name":return function(){for(var t="",r=0,e=Object.keys(o.default);r<e.length;r++){var l=e[r];if(Object(a.arrayIsEqual)(o.default[l],[u,s,i])){t=l;break}}return null===c&&""!==t?t:"#"+n.rgbToHex(u,s,i,c,!0)}();case"short":return"#"+n.rgbToHex(u,s,i,c,!0);case"full":default:return"#"+n.rgbToHex(u,s,i,c)}},t.prototype.toRgb=function(t){void 0===t&&(t="default");var r,e=this.getColorAs("rgb"),n=e.values.map(function(t){return Math.round(t)}),o=n[0],a=n[1],u=n[2];return"percent"===t&&(o=(r=[o,a,u].map(function(t){return t/255*100+"%"}))[0],a=r[1],u=r[2]),1===e.alpha?"rgb("+o+", "+a+", "+u+")":"rgba("+o+", "+a+", "+u+", "+e.alpha+")"},t.prototype.toHwb=function(){var t=this.getColorAs("hwb"),r=t.values.map(function(t){return Object(a.decimal)(t,2)});return"hwb("+r[0]+", "+r[1]+"%, "+r[2]+"%"+(1===t.alpha?"":", "+t.alpha)+")"},t.prototype.toHsl=function(){var t=this.getColorAs("hsl"),r=t.values.map(function(t){return Object(a.decimal)(t,2)}),e=r[0],n=r[1],o=r[2];return 1===t.alpha?"hsl("+e+", "+n+"%, "+o+"%)":"hsla("+e+", "+n+"%, "+o+"%, "+t.alpha+")"},t.prototype.toHsv=function(){var t=this.getColorAs("hsv"),r=t.values.map(function(t){return Object(a.decimal)(t,2)}),e=r[0],n=r[1],o=r[2];return 1===t.alpha?"hsv("+e+", "+n+"%, "+o+"%)":"hsva("+e+", "+n+"%, "+o+"%, "+t.alpha+")"},t.prototype.toCmyk=function(){var t=this.getColorAs("cmyk"),r=t.values.map(function(t){return Object(a.decimal)(t,2)});return"cmyk("+r[0]+"%, "+r[1]+"%, "+r[2]+"%, "+r[3]+"%"+(1===t.alpha?"":", "+t.alpha)+")"},t.prototype.convertFromRgb=function(t,r){var e=t[0],o=t[1],a=t[2];switch(r){case"rgb":return[e,o,a];case"hwb":return n.rgbToHwb(e,o,a);case"hsl":return n.rgbToHsl(e,o,a);case"hsv":return n.rgbToHsv(e,o,a);case"cmyk":return n.rgbToCmyk(e,o,a)}},t.prototype.convertFromHwb=function(t,r){var e=t[0],o=t[1],a=t[2],u=n.hwbToRgb(e,o,a),s=u[0],i=u[1],c=u[2];switch(r){case"rgb":return[s,i,c];case"hwb":return[e,o,a];case"hsl":return n.rgbToHsl(s,i,c);case"hsv":return n.hwbToHsv(e,o,a);case"cmyk":return n.rgbToCmyk(s,i,c)}},t.prototype.convertFromHsl=function(t,r){var e=t[0],o=t[1],a=t[2],u=n.hslToRgb(e,o,a),s=u[0],i=u[1],c=u[2];switch(r){case"rgb":return[s,i,c];case"hwb":return n.rgbToHwb(s,i,c);case"hsl":return[e,o,a];case"hsv":return n.rgbToHsv(s,i,c);case"cmyk":return n.rgbToCmyk(s,i,c)}},t.prototype.convertFromHsv=function(t,r){var e=t[0],o=t[1],a=t[2],u=n.hsvToRgb(e,o,a),s=u[0],i=u[1],c=u[2];switch(r){case"rgb":return[s,i,c];case"hwb":return n.hsvToHwb(e,o,a);case"hsl":return n.rgbToHsl(s,i,c);case"hsv":return[e,o,a];case"cmyk":return n.rgbToCmyk(s,i,c)}},t.prototype.convertFromCmyk=function(t,r){var e=t[0],o=t[1],a=t[2],u=t[3],s=n.cmykToRgb(e,o,a,u),i=s[0],c=s[1],l=s[2];switch(r){case"rgb":return[i,c,l];case"hwb":return n.rgbToHwb(i,c,l);case"hsl":return n.rgbToHsl(i,c,l);case"hsv":return n.rgbToHsv(i,c,l);case"cmyk":return[e,o,a,u]}},t}();r.default=u},"./src/color-names.ts": | ||
/*! exports provided: ColorFormatter, default */function(t,r,e){"use strict";e.r(r),e.d(r,"ColorFormatter",function(){return u});var n=e(/*! ./color-converter */"./src/color-converter.ts"),o=e(/*! ./color-names */"./src/color-names.ts"),a=e(/*! ./util/util */"./src/util/util.ts"),u=function(){function t(){this.resolveHwb=n.resolveHwb}return t.prototype.setColor=function(t){return t.alpha=Object(a.resolveAlpha)(t.alpha),this.color=t,this},t.prototype.getColor=function(){return this.color},t.prototype.getColorAs=function(t){return this.color.model===t?this.color:this.convert(this.color,t)},t.prototype.getModel=function(){return this.color?this.color.model:void 0},t.prototype.changeModel=function(t){return this.color.model===t?this:this.setColor(this.convert(this.color,t))},t.prototype.getAlpha=function(){return this.color.alpha},t.prototype.setAlpha=function(t){return this.color.alpha=t,this},t.prototype.convert=function(t,r){var e;switch(t.model){case"rgb":e=this.convertFromRgb(t.values,r);break;case"hwb":e=this.convertFromHwb(t.values,r);break;case"hsl":e=this.convertFromHsl(t.values,r);break;case"hsv":e=this.convertFromHsv(t.values,r);break;case"cmyk":e=this.convertFromCmyk(t.values,r)}if(!e.length)throw new Error("Converting Error!");return{model:r,values:e,alpha:t.alpha}},t.prototype.toString=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];switch(t=t||this.color.model){case"hex":return this.toHex.apply(this,r);case"hwb":return this.toHwb();case"hsl":return this.toHsl();case"hsv":return this.toHsv();case"cmyk":return this.toCmyk();default:return this.toRgb.apply(this,r)}},t.prototype.toHex=function(t){void 0===t&&(t="full");var r=this.getColorAs("rgb"),e=r.values.map(function(t){return Math.round(t)}),u=e[0],s=e[1],c=e[2],i=1===r.alpha?null:r.alpha;switch(t){case"name":return function(){for(var t="",r=0,e=Object.keys(o.default);r<e.length;r++){var l=e[r];if(Object(a.arrayIsEqual)(o.default[l],[u,s,c])){t=l;break}}return null===i&&""!==t?t:"#"+n.rgbToHex(u,s,c,i,!0)}();case"short":return"#"+n.rgbToHex(u,s,c,i,!0);case"full":default:return"#"+n.rgbToHex(u,s,c,i)}},t.prototype.toRgb=function(t){void 0===t&&(t="default");var r,e=this.getColorAs("rgb"),n=e.values.map(function(t){return Math.round(t)}),o=n[0],a=n[1],u=n[2];return"percent"===t&&(o=(r=[o,a,u].map(function(t){return t/255*100+"%"}))[0],a=r[1],u=r[2]),1===e.alpha?"rgb("+o+", "+a+", "+u+")":"rgba("+o+", "+a+", "+u+", "+e.alpha+")"},t.prototype.toHwb=function(){var t=this.getColorAs("hwb"),r=t.values.map(function(t){return Object(a.decimal)(t,2)});return"hwb("+r[0]+", "+r[1]+"%, "+r[2]+"%"+(1===t.alpha?"":", "+t.alpha)+")"},t.prototype.toHsl=function(){var t=this.getColorAs("hsl"),r=t.values.map(function(t){return Object(a.decimal)(t,2)}),e=r[0],n=r[1],o=r[2];return 1===t.alpha?"hsl("+e+", "+n+"%, "+o+"%)":"hsla("+e+", "+n+"%, "+o+"%, "+t.alpha+")"},t.prototype.toHsv=function(){var t=this.getColorAs("hsv"),r=t.values.map(function(t){return Object(a.decimal)(t,2)}),e=r[0],n=r[1],o=r[2];return 1===t.alpha?"hsv("+e+", "+n+"%, "+o+"%)":"hsva("+e+", "+n+"%, "+o+"%, "+t.alpha+")"},t.prototype.toCmyk=function(){var t=this.getColorAs("cmyk"),r=t.values.map(function(t){return Object(a.decimal)(t,2)});return"cmyk("+r[0]+"%, "+r[1]+"%, "+r[2]+"%, "+r[3]+"%"+(1===t.alpha?"":", "+t.alpha)+")"},t.prototype.convertFromRgb=function(t,r){var e=t[0],o=t[1],a=t[2];switch(r){case"rgb":return[e,o,a];case"hwb":return n.rgbToHwb(e,o,a);case"hsl":return n.rgbToHsl(e,o,a);case"hsv":return n.rgbToHsv(e,o,a);case"cmyk":return n.rgbToCmyk(e,o,a)}},t.prototype.convertFromHwb=function(t,r){var e=t[0],o=t[1],a=t[2],u=n.hwbToRgb(e,o,a),s=u[0],c=u[1],i=u[2];switch(r){case"rgb":return[s,c,i];case"hwb":return[e,o,a];case"hsl":return n.rgbToHsl(s,c,i);case"hsv":return n.hwbToHsv(e,o,a);case"cmyk":return n.rgbToCmyk(s,c,i)}},t.prototype.convertFromHsl=function(t,r){var e=t[0],o=t[1],a=t[2],u=n.hslToRgb(e,o,a),s=u[0],c=u[1],i=u[2];switch(r){case"rgb":return[s,c,i];case"hwb":return n.rgbToHwb(s,c,i);case"hsl":return[e,o,a];case"hsv":return n.rgbToHsv(s,c,i);case"cmyk":return n.rgbToCmyk(s,c,i)}},t.prototype.convertFromHsv=function(t,r){var e=t[0],o=t[1],a=t[2],u=n.hsvToRgb(e,o,a),s=u[0],c=u[1],i=u[2];switch(r){case"rgb":return[s,c,i];case"hwb":return n.hsvToHwb(e,o,a);case"hsl":return n.rgbToHsl(s,c,i);case"hsv":return[e,o,a];case"cmyk":return n.rgbToCmyk(s,c,i)}},t.prototype.convertFromCmyk=function(t,r){var e=t[0],o=t[1],a=t[2],u=t[3],s=n.cmykToRgb(e,o,a,u),c=s[0],i=s[1],l=s[2];switch(r){case"rgb":return[c,i,l];case"hwb":return n.rgbToHwb(c,i,l);case"hsl":return n.rgbToHsl(c,i,l);case"hsv":return n.rgbToHsv(c,i,l);case"cmyk":return[e,o,a,u]}},t}();r.default=u},"./src/color-names.ts": | ||
/*!****************************!*\ | ||
@@ -22,10 +22,10 @@ !*** ./src/color-names.ts ***! | ||
\*****************************/ | ||
/*! exports provided: default */function(t,r,e){"use strict";e.r(r),e.d(r,"default",function(){return u});var n=e(/*! ./color-converter */"./src/color-converter.ts"),o=e(/*! ./color-names */"./src/color-names.ts"),a=e(/*! ./util/util */"./src/util/util.ts");function u(t){if("string"==typeof t){if(t in o.default)return{model:"rgb",values:o.default[t],alpha:1};if("transparent"===t)return{model:"rgb",values:[0,0,0],alpha:0};switch(t.substr(0,3).toLowerCase()){case"hwb":return function(t){var r=/^hwba?\s*\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),o=e[1],u=e[2],s=e[3],i=e[4];return{model:"hwb",values:Object(n.resolveHwb)(Object(a.degree)(o),Object(a.clamp)(parseFloat(u),0,100),Object(a.clamp)(parseFloat(s),0,100)),alpha:Object(a.resolveAlpha)(i)}}return null}(t);case"hsl":return function(t){var r=/^hsla?\s*\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),n=e[1],o=e[2],u=e[3],s=e[4];return{model:"hsl",values:[Object(a.degree)(n),Object(a.clamp)(parseFloat(o),0,100),Object(a.clamp)(parseFloat(u),0,100)],alpha:Object(a.resolveAlpha)(s)}}return null}(t);case"hsv":return function(t){var r=/^hsva?\s*\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),n=e[1],o=e[2],u=e[3],s=e[4];return{model:"hsv",values:[Object(a.degree)(n),Object(a.clamp)(parseFloat(o),0,100),Object(a.clamp)(parseFloat(u),0,100)],alpha:Object(a.resolveAlpha)(s)}}return null}(t);case"cmy":return function(t){var r=/^cmyk\s*\(\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),n=e[1],o=e[2],u=e[3],s=e[4],i=e[5];return{model:"cmyk",values:[Object(a.clamp)(parseFloat(n),0,100),Object(a.clamp)(parseFloat(o),0,100),Object(a.clamp)(parseFloat(u),0,100),Object(a.clamp)(parseFloat(s),0,100)],alpha:Object(a.resolveAlpha)(i)}}return null}(t);default:return function(t){var r,e,n=/^#?([a-f0-9]{6})([a-f0-9]{2})?$/i,o=/^#?([a-f0-9]{3})([a-f0-9]{1})?$/i,u=/^rgba?\s*\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,s=/^rgba?\s*\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,i=function(t){return Math.round(parseInt(t,16)/255*100)/100};if(n.test(t)){var c=t.match(n),l=c[1],h=c[2];r=l.match(/.{2}/g).map(function(t){return parseInt(t,16)}),e=h?i(h):1}else if(o.test(t)){var p=t.match(o),l=p[1],h=p[2];r=l.match(/.{1}/g).map(function(t){return parseInt(t+t,16)}),e=h?i(h):1}else if(u.test(t)){var f=t.match(u),d=f[1],b=f[2],m=f[3],h=f[4];r=[d,b,m].map(function(t){return parseInt(t,0)}),e=Object(a.resolveAlpha)(h)}else{if(!s.test(t))return null;var g=t.match(s),d=g[1],b=g[2],m=g[3],h=g[4];r=[d,b,m].map(function(t){return Math.round(2.55*parseFloat(t))}),e=Object(a.resolveAlpha)(h)}return{model:"rgb",values:r.map(function(t){return Object(a.clamp)(t,0,255)}),alpha:Object(a.clamp)(e,0,1)}}(t)}}}},"./src/moo-color.ts": | ||
/*! exports provided: default */function(t,r,e){"use strict";e.r(r),e.d(r,"default",function(){return u});var n=e(/*! ./color-converter */"./src/color-converter.ts"),o=e(/*! ./color-names */"./src/color-names.ts"),a=e(/*! ./util/util */"./src/util/util.ts");function u(t){if(t in o.default)return{model:"rgb",values:o.default[t],alpha:1};if("transparent"===t)return{model:"rgb",values:[0,0,0],alpha:0};switch(t.substr(0,3).toLowerCase()){case"hwb":return function(t){var r=/^hwba?\s*\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),o=e[1],u=e[2],s=e[3],c=e[4];return{model:"hwb",values:Object(n.resolveHwb)(Object(a.degree)(o),Object(a.clamp)(parseFloat(u),0,100),Object(a.clamp)(parseFloat(s),0,100)),alpha:Object(a.resolveAlpha)(c)}}return null}(t);case"hsl":return function(t){var r=/^hsla?\s*\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),n=e[1],o=e[2],u=e[3],s=e[4];return{model:"hsl",values:[Object(a.degree)(n),Object(a.clamp)(parseFloat(o),0,100),Object(a.clamp)(parseFloat(u),0,100)],alpha:Object(a.resolveAlpha)(s)}}return null}(t);case"hsv":return function(t){var r=/^hsva?\s*\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),n=e[1],o=e[2],u=e[3],s=e[4];return{model:"hsv",values:[Object(a.degree)(n),Object(a.clamp)(parseFloat(o),0,100),Object(a.clamp)(parseFloat(u),0,100)],alpha:Object(a.resolveAlpha)(s)}}return null}(t);case"cmy":return function(t){var r=/^cmyk\s*\(\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i;if(r.test(t)){var e=t.match(r),n=e[1],o=e[2],u=e[3],s=e[4],c=e[5];return{model:"cmyk",values:[Object(a.clamp)(parseFloat(n),0,100),Object(a.clamp)(parseFloat(o),0,100),Object(a.clamp)(parseFloat(u),0,100),Object(a.clamp)(parseFloat(s),0,100)],alpha:Object(a.resolveAlpha)(c)}}return null}(t);default:return function(t){var r,e,n=/^#?([a-f0-9]{6})([a-f0-9]{2})?$/i,o=/^#?([a-f0-9]{3})([a-f0-9]{1})?$/i,u=/^rgba?\s*\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,s=/^rgba?\s*\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,c=function(t){return Math.round(parseInt(t,16)/255*100)/100};if(n.test(t)){var i=t.match(n),l=i[1],h=i[2];r=l.match(/.{2}/g).map(function(t){return parseInt(t,16)}),e=h?c(h):1}else if(o.test(t)){var p=t.match(o),l=p[1],h=p[2];r=l.match(/.{1}/g).map(function(t){return parseInt(t+t,16)}),e=h?c(h):1}else if(u.test(t)){var f=t.match(u),d=f[1],b=f[2],m=f[3],h=f[4];r=[d,b,m].map(function(t){return parseInt(t,0)}),e=Object(a.resolveAlpha)(h)}else{if(!s.test(t))return null;var g=t.match(s),d=g[1],b=g[2],m=g[3],h=g[4];r=[d,b,m].map(function(t){return Math.round(2.55*parseFloat(t))}),e=Object(a.resolveAlpha)(h)}return{model:"rgb",values:r.map(function(t){return Object(a.clamp)(t,0,255)}),alpha:Object(a.clamp)(e,0,1)}}(t)}}},"./src/moo-color.ts": | ||
/*!**************************!*\ | ||
!*** ./src/moo-color.ts ***! | ||
\**************************/ | ||
/*! exports provided: ColorFormatter, MooColor, default */function(t,r,e){"use strict";e.r(r),e.d(r,"MooColor",function(){return i});var n=e(/*! ./color-formatter */"./src/color-formatter.ts");e.d(r,"ColorFormatter",function(){return n.default});var o,a=e(/*! ./input-parser */"./src/input-parser.ts"),u=e(/*! ./util/util */"./src/util/util.ts"),s=(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])},function(t,r){function e(){this.constructor=t}o(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),i=function(t){function r(r){var e=t.call(this)||this;return r=r||"#000",e.setColorByParser(r),e}return s(r,t),r.mix=function(t,e,n){void 0===n&&(n=50);var o="string"==typeof t?new r(t):t;return("string"==typeof e?new r(e):e).mix(o,n)},r.prototype.setColorByParser=function(t){var r=Object(a.default)(t);if(!r)throw new Error("parsing error!");return this.setColor(r)},r.prototype.clone=function(){return(new r).setColor(this.color)},Object.defineProperty(r.prototype,"brightness",{get:function(){var t=this.getColorAs("rgb").values;return(299*t[0]+587*t[1]+114*t[2])/1e3},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isLight",{get:function(){return this.brightness>=128},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isDark",{get:function(){return this.brightness<128},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"luminance",{get:function(){var t=this.getColorAs("rgb").values.map(function(t){return t/255});return.2126*t[0]+.7152*t[1]+.0722*t[2]},enumerable:!0,configurable:!0}),r.prototype.contrastRatioWith=function(t){return(Math.max(this.luminance,t.luminance)+.05)/(Math.min(this.luminance,t.luminance)+.05)},r.prototype.isContrastEnough=function(t){return this.contrastRatioWith(t)>=4.5},r.prototype.lighten=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e,n=Object(u.clamp)(n+t,0,100)]})},r.prototype.darken=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e,n=Object(u.clamp)(n-t,0,100)]})},r.prototype.saturate=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e=Object(u.clamp)(e+t,0,100),n]})},r.prototype.desaturate=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e=Object(u.clamp)(e-t,0,100),n]})},r.prototype.grayscale=function(){return this.manipulate("hsl",function(t,r,e){return[t,0,e]})},r.prototype.whiten=function(t){var r=this;return this.manipulate("hwb",function(e,n,o){return r.resolveHwb(e,Object(u.clamp)(n+t,0,100),o)})},r.prototype.blacken=function(t){var r=this;return this.manipulate("hwb",function(e,n,o){return r.resolveHwb(e,n,Object(u.clamp)(o+t,0,100))})},r.prototype.rotate=function(t){return this.manipulate("hsl",function(r,e,n){return[Object(u.degree)(r+t),e,n]})},r.prototype.mix=function(t,e){void 0===e&&(e=50),e/=100;var n=this.getModel(),o=this.getColorAs("rgb"),a=t.getColorAs("rgb");return(new r).setColor({model:"rgb",values:o.values.map(function(t,r){return t+(a.values[r]-t)*e}),alpha:o.alpha+(a.alpha-o.alpha)*e}).changeModel(n)},r.prototype.complement=function(){return this.manipulate("hsl",function(t,r,e){return[Object(u.degree)(t+180),r,e]})},r.prototype.invert=function(t){void 0===t&&(t=100),t/=100;return this.manipulate("rgb",function(r,e,n){return[r,e,n].map(function(r){return function(t){return Math.round(Math.abs(t))}(255*t-r)})})},r.prototype.random=function(t){var r,e=void 0===t?{}:t,n=e.hue,o=e.white,a=e.black;return n=(r=[n,o,a].map(function(t,r){if("number"==typeof t)return t;if(Array.isArray(t)){var e=0===r?0:2;return Object(u.getRandom)(Math.min.apply(Math,t),Math.max.apply(Math,t),e)}return 0===r?Object(u.getRandom)(0,360):Object(u.getRandom)(0,100,2)}))[0],o=r[1],a=r[2],this.setColor({model:"hwb",values:this.resolveHwb(Object(u.degree)(n),Object(u.clamp)(o,0,100),Object(u.clamp)(a,0,100)),alpha:1})},r.prototype.manipulate=function(t,r){var e=this.color.model,n=this.getColorAs(t);return n.values=r.apply(void 0,n.values),this.setColor(n).changeModel(e)},r}(n.default);r.default=i},"./src/util/util.ts": | ||
/*! exports provided: ColorFormatter, MooColor, default */function(t,r,e){"use strict";e.r(r),e.d(r,"MooColor",function(){return i});var n=e(/*! ./color-converter */"./src/color-converter.ts"),o=e(/*! ./color-formatter */"./src/color-formatter.ts");e.d(r,"ColorFormatter",function(){return o.default});var a,u=e(/*! ./input-parser */"./src/input-parser.ts"),s=e(/*! ./util/util */"./src/util/util.ts"),c=(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])},function(t,r){function e(){this.constructor=t}a(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),i=function(t){function r(r){var e=t.call(this)||this;return"object"==typeof r&&null!==r?e.setColor(r):"string"!=typeof r&&void 0!==r||(r=r||"#000",e.setColorByParser(r)),e}return c(r,t),r.mix=function(t,e,n){void 0===n&&(n=50);var o=t instanceof r?t:new r(t);return(e instanceof r?e:new r(e)).mix(o,n)},r.random=function(t){var e,o=void 0===t?{}:t,a=o.hue,u=o.white,c=o.black;return a=(e=[a,u,c].map(function(t,r){if("number"==typeof t)return t;if(Array.isArray(t)){var e=0===r?0:2;return Object(s.getRandom)(Math.min.apply(Math,t),Math.max.apply(Math,t),e)}return 0===r?Object(s.getRandom)(0,360):Object(s.getRandom)(0,100,2)}))[0],u=e[1],c=e[2],new r({model:"hwb",values:Object(n.resolveHwb)(Object(s.degree)(a),Object(s.clamp)(u,0,100),Object(s.clamp)(c,0,100)),alpha:1})},r.prototype.setColorByParser=function(t){var r=Object(u.default)(t);if(!r)throw new Error("parsing error!");return this.setColor(r)},r.prototype.clone=function(){return new r(this.color)},Object.defineProperty(r.prototype,"brightness",{get:function(){var t=this.getColorAs("rgb").values;return(299*t[0]+587*t[1]+114*t[2])/1e3},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isLight",{get:function(){return this.brightness>=128},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isDark",{get:function(){return this.brightness<128},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"luminance",{get:function(){var t=this.getColorAs("rgb").values.map(function(t){return t/255});return.2126*t[0]+.7152*t[1]+.0722*t[2]},enumerable:!0,configurable:!0}),r.prototype.contrastRatioWith=function(t){return(Math.max(this.luminance,t.luminance)+.05)/(Math.min(this.luminance,t.luminance)+.05)},r.prototype.isContrastEnough=function(t){return this.contrastRatioWith(t)>=4.5},r.prototype.lighten=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e,n=Object(s.clamp)(n+t,0,100)]})},r.prototype.darken=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e,n=Object(s.clamp)(n-t,0,100)]})},r.prototype.saturate=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e=Object(s.clamp)(e+t,0,100),n]})},r.prototype.desaturate=function(t){return this.manipulate("hsl",function(r,e,n){return[r,e=Object(s.clamp)(e-t,0,100),n]})},r.prototype.grayscale=function(){return this.manipulate("hsl",function(t,r,e){return[t,0,e]})},r.prototype.whiten=function(t){var r=this;return this.manipulate("hwb",function(e,n,o){return r.resolveHwb(e,Object(s.clamp)(n+t,0,100),o)})},r.prototype.blacken=function(t){var r=this;return this.manipulate("hwb",function(e,n,o){return r.resolveHwb(e,n,Object(s.clamp)(o+t,0,100))})},r.prototype.rotate=function(t){return this.manipulate("hsl",function(r,e,n){return[Object(s.degree)(r+t),e,n]})},r.prototype.mix=function(t,e){void 0===e&&(e=50),e/=100;var n=this.getModel(),o=this.getColorAs("rgb"),a=t.getColorAs("rgb");return new r({model:"rgb",values:o.values.map(function(t,r){return t+(a.values[r]-t)*e}),alpha:o.alpha+(a.alpha-o.alpha)*e}).changeModel(n)},r.prototype.complement=function(){return this.manipulate("hsl",function(t,r,e){return[Object(s.degree)(t+180),r,e]})},r.prototype.invert=function(t){void 0===t&&(t=100),t/=100;return this.manipulate("rgb",function(r,e,n){return[r,e,n].map(function(r){return function(t){return Math.round(Math.abs(t))}(255*t-r)})})},r.prototype.manipulate=function(t,r){var e=this.color.model,n=this.getColorAs(t);return n.values=r.apply(void 0,n.values),this.setColor(n).changeModel(e)},r}(o.default);r.default=i},"./src/util/util.ts": | ||
/*!**************************!*\ | ||
!*** ./src/util/util.ts ***! | ||
\**************************/ | ||
/*! exports provided: padStart, padEnd, clamp, degree, resolveAlpha, decimal, getRandom, arrayIsEqual */function(t,r,e){"use strict";function n(t,r,e){var n=r-t.length;return n>0?""+a(e,n)+t:t}function o(t,r,e){var n=r-t.length;return n>0?""+t+a(e,n):t}function a(t,r){for(;t.length<r;)t+=t;return t.length>r?t.substring(t.length-r):t}function u(t,r,e){return Math.min(Math.max(r,t),e)}function s(t){return((t="string"==typeof t?parseFloat(t):t)%360+360)%360}function i(t){return t="string"==typeof t?parseFloat(t):t,u(isNaN(t)?1:t,0,1)}function c(t,r){var e=Math.pow(10,r);return Math.round(t*e)/e}function l(t,r,e){return void 0===e&&(e=0),c(Math.random()*(r-t)+t,e)}function h(t,r){return t.length===r.length&&t.every(function(t,e){return Array.isArray(t)?h(t,r[e]):t===r[e]})}e.r(r),e.d(r,"padStart",function(){return n}),e.d(r,"padEnd",function(){return o}),e.d(r,"clamp",function(){return u}),e.d(r,"degree",function(){return s}),e.d(r,"resolveAlpha",function(){return i}),e.d(r,"decimal",function(){return c}),e.d(r,"getRandom",function(){return l}),e.d(r,"arrayIsEqual",function(){return h})}})}); | ||
/*! exports provided: padStart, padEnd, clamp, degree, resolveAlpha, decimal, getRandom, arrayIsEqual */function(t,r,e){"use strict";function n(t,r,e){var n=r-t.length;return n>0?""+a(e,n)+t:t}function o(t,r,e){var n=r-t.length;return n>0?""+t+a(e,n):t}function a(t,r){for(;t.length<r;)t+=t;return t.length>r?t.substring(t.length-r):t}function u(t,r,e){return Math.min(Math.max(r,t),e)}function s(t){return((t="string"==typeof t?parseFloat(t):t)%360+360)%360}function c(t){return t="string"==typeof t?parseFloat(t):t,u(isNaN(t)?1:t,0,1)}function i(t,r){var e=Math.pow(10,r);return Math.round(t*e)/e}function l(t,r,e){return void 0===e&&(e=0),i(Math.random()*(r-t)+t,e)}function h(t,r){return t.length===r.length&&t.every(function(t,e){return Array.isArray(t)?h(t,r[e]):t===r[e]})}e.r(r),e.d(r,"padStart",function(){return n}),e.d(r,"padEnd",function(){return o}),e.d(r,"clamp",function(){return u}),e.d(r,"degree",function(){return s}),e.d(r,"resolveAlpha",function(){return c}),e.d(r,"decimal",function(){return i}),e.d(r,"getRandom",function(){return l}),e.d(r,"arrayIsEqual",function(){return h})}})}); |
# MooColor API | ||
## Base | ||
### Table of contents | ||
- [Basic](#basic) | ||
- [Constructor](#constructor) | ||
- [Parsable color string](#parsable-color-string) | ||
- [Static](#static) | ||
- [Setter](#setter) | ||
- [Formatter](#formatter) | ||
- [State Access](#state-access) | ||
- [Modification](#modification) | ||
## Basic | ||
### Constructor | ||
@@ -38,2 +49,7 @@ | ||
## [Static](static.md) | ||
- [mix](static.md#mix): Helper method for [`mix()`](modifier.md#mix) method. | ||
- [random](static.md#random): Create random color as HWB model. | ||
## [Setter](setter.md) | ||
@@ -68,3 +84,3 @@ | ||
## [Modifier](modifier.md) | ||
## [Modification](modification.md) | ||
@@ -82,2 +98,1 @@ - [lighten](modifier.md#lighten): Increase lightness. | ||
- [invert](modifier.md#invert): Sets color to the inverse (negative) of a color. | ||
- [random](modifier.md#random): Sets random color values as HWB color model. |
{ | ||
"name": "moo-color", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "A simple color library.", | ||
@@ -34,10 +34,10 @@ "main": "dist/moo-color.js", | ||
"@types/color-name": "^1.1.0", | ||
"@types/jest": "^22.2.2", | ||
"@types/jest": "^22.2.3", | ||
"jest": "^22.4.3", | ||
"source-map-loader": "^0.2.3", | ||
"ts-jest": "^22.4.2", | ||
"ts-loader": "^4.1.0", | ||
"typescript": "^2.8.1", | ||
"webpack": "^4.4.1", | ||
"webpack-cli": "^2.0.13", | ||
"ts-jest": "^22.4.6", | ||
"ts-loader": "^4.3.0", | ||
"typescript": "^2.8.3", | ||
"webpack": "^4.8.3", | ||
"webpack-cli": "^2.1.3", | ||
"webpack-merge": "^4.1.2", | ||
@@ -44,0 +44,0 @@ "webpack-notifier": "^1.6.0" |
@@ -90,3 +90,2 @@ export type Color = ColorData; | ||
invert(percent?: number): this; | ||
random(arg?: RandomArguments): this; | ||
} |
@@ -6,30 +6,26 @@ import { Color } from './color'; | ||
type AcceptedInput = string|string[]|number[]|object; | ||
export default function inputParser(input: AcceptedInput): Color|null { | ||
if (typeof input === 'string') { | ||
if (input in Names) { | ||
// Named colors. | ||
return { | ||
model: 'rgb', | ||
values: Names[input], | ||
alpha: 1, | ||
}; | ||
} else if (input === 'transparent') { | ||
// 'transparent'. | ||
return { | ||
model: 'rgb', | ||
values: [0, 0, 0], | ||
alpha: 0, | ||
}; | ||
} else { | ||
// parse string. | ||
const prefix = input.substr(0, 3).toLowerCase(); | ||
switch (prefix) { | ||
case 'hwb': return parseHwb(input); | ||
case 'hsl': return parseHsl(input); | ||
case 'hsv': return parseHsv(input); | ||
case 'cmy': return parseCmyk(input); | ||
default: return parseRgb(input); | ||
} | ||
export default function inputParser(input: string): Color|null { | ||
if (input in Names) { | ||
// Named colors. | ||
return { | ||
model: 'rgb', | ||
values: Names[input], | ||
alpha: 1, | ||
}; | ||
} else if (input === 'transparent') { | ||
// 'transparent'. | ||
return { | ||
model: 'rgb', | ||
values: [0, 0, 0], | ||
alpha: 0, | ||
}; | ||
} else { | ||
// parse string. | ||
const prefix = input.substr(0, 3).toLowerCase(); | ||
switch (prefix) { | ||
case 'hwb': return parseHwb(input); | ||
case 'hsl': return parseHsl(input); | ||
case 'hsv': return parseHsv(input); | ||
case 'cmy': return parseCmyk(input); | ||
default: return parseRgb(input); | ||
} | ||
@@ -36,0 +32,0 @@ } |
@@ -8,5 +8,11 @@ import { | ||
} from './color'; | ||
import { resolveHwb } from './color-converter'; | ||
import ColorFormatter from './color-formatter'; | ||
import parser from './input-parser'; | ||
import { clamp, decimal, degree, getRandom } from './util/util'; | ||
import { | ||
clamp, | ||
decimal, | ||
degree, | ||
getRandom, | ||
} from './util/util'; | ||
@@ -20,5 +26,6 @@ export * from './color'; | ||
export class MooColor extends ColorFormatter implements ColorModifiable<MooColor>, ColorStateAccessible { | ||
static mix(color1: string|MooColor, color2: string|MooColor, percentOf1: number = 50): MooColor { | ||
const c1 = (typeof color1 === 'string') ? new MooColor(color1) : color1; | ||
const c2 = (typeof color2 === 'string') ? new MooColor(color2) : color2; | ||
static mix(color1: MooColor|string|Color, color2: MooColor|string|Color, percentOf1: number = 50): MooColor { | ||
const c1 = (color1 instanceof MooColor) ? color1 : new MooColor(color1); | ||
const c2 = (color2 instanceof MooColor) ? color2 : new MooColor(color2); | ||
return c2.mix(c1, percentOf1); | ||
@@ -28,9 +35,40 @@ } | ||
/** | ||
* Create random color as HWB color model. | ||
* | ||
* @static | ||
* @param {RandomArguments} [{hue, white, black}={}] | ||
* @returns {MooColor} | ||
* @memberof MooColor | ||
*/ | ||
static random({hue, white, black}: RandomArguments = {}): MooColor { | ||
[hue, white, black] = [hue, white, black].map((x, i) => { | ||
if (typeof x === 'number') { | ||
return x; | ||
} else if (Array.isArray(x)) { | ||
const precision = i === 0 ? 0 : 2; | ||
return getRandom(Math.min(...x), Math.max(...x), precision); | ||
} else { | ||
return i === 0 ? getRandom(0, 360) : getRandom(0, 100, 2); | ||
} | ||
}); | ||
return new MooColor({ | ||
model: 'hwb', | ||
values: resolveHwb(degree(hue), clamp(white, 0, 100), clamp(black, 0, 100)), | ||
alpha: 1, | ||
}); | ||
} | ||
/** | ||
* Creates an instance of MooColor. | ||
* @param {*} [color] color string. e.g. '#ff0000' 'rgba(255, 0, 0, .5)' 'hsl(120, 50%, 100%)' | ||
* @param {(string|Color)} [color] color value. e.g. '#ff0000' 'rgba(255, 0, 0, .5)' 'hsl(120, 50%, 100%)' | ||
* @memberof MooColor | ||
*/ | ||
constructor(color?: any) { | ||
constructor(color?: string|Color) { | ||
super(); | ||
color = color ? color : '#000'; | ||
this.setColorByParser(color); | ||
if (typeof color === 'object' && color !== null) { | ||
this.setColor(color as Color); | ||
} else if (typeof color === 'string' || typeof color === 'undefined') { | ||
color = color ? color : '#000'; | ||
this.setColorByParser(color as string); | ||
} | ||
} | ||
@@ -47,3 +85,3 @@ | ||
clone(): MooColor { | ||
return new MooColor().setColor(this.color); | ||
return new MooColor(this.color); | ||
} | ||
@@ -213,3 +251,3 @@ | ||
const c2 = color.getColorAs('rgb'); | ||
return new MooColor().setColor({ | ||
return new MooColor({ | ||
model: 'rgb', | ||
@@ -242,26 +280,2 @@ values: c1.values.map((v, i) => v + (c2.values[i] - v) * percent), | ||
/** | ||
* Sets random color values as HWB color model. | ||
* | ||
* @param {RandomArguments} [{hue, white, black}={}] | ||
* @returns {this} | ||
*/ | ||
random({hue, white, black}: RandomArguments = {}): this { | ||
[hue, white, black] = [hue, white, black].map((x, i) => { | ||
if (typeof x === 'number') { | ||
return x; | ||
} else if (Array.isArray(x)) { | ||
const precision = i === 0 ? 0 : 2; | ||
return getRandom(Math.min(...x), Math.max(...x), precision); | ||
} else { | ||
return i === 0 ? getRandom(0, 360) : getRandom(0, 100, 2); | ||
} | ||
}); | ||
return this.setColor({ | ||
model: 'hwb', | ||
values: this.resolveHwb(degree(hue), clamp(white, 0, 100), clamp(black, 0, 100)), | ||
alpha: 1, | ||
}); | ||
} | ||
protected manipulate(asModel: AcceptedModel, callback: manipulateFn): this { | ||
@@ -268,0 +282,0 @@ const m = this.color.model; |
@@ -11,2 +11,45 @@ import { MooColor } from '../src/moo-color'; | ||
describe('static #random', () => { | ||
it('sets random color.', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const c = MooColor.random(); | ||
const [h, w, b] = c.getColorAs('hwb').values; | ||
expect(h).toBeGreaterThanOrEqual(0); | ||
expect(h).toBeLessThanOrEqual(360); | ||
expect(w).toBeGreaterThanOrEqual(0); | ||
expect(w).toBeLessThanOrEqual(100); | ||
expect(b).toBeGreaterThanOrEqual(0); | ||
expect(b).toBeLessThanOrEqual(100); | ||
} | ||
}); | ||
it('specifying whiteness.', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const c = MooColor.random({white: 50, black: [0, 50]}); | ||
const [h, w, b] = c.getColorAs('hwb').values; | ||
expect(h).toBeGreaterThanOrEqual(0); | ||
expect(h).toBeLessThanOrEqual(360); | ||
expect(w).toEqual(50); | ||
expect(b).toBeGreaterThanOrEqual(0); | ||
expect(b).toBeLessThanOrEqual(100); | ||
} | ||
}); | ||
it('range setting: hue', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const c = MooColor.random({ hue: [0, 60] }); | ||
const [h, w, b] = c.getColorAs('hwb').values; | ||
expect(h).toBeGreaterThanOrEqual(0); | ||
expect(h).toBeLessThanOrEqual(60); | ||
expect(w).toBeGreaterThanOrEqual(0); | ||
expect(w).toBeLessThanOrEqual(100); | ||
expect(b).toBeGreaterThanOrEqual(0); | ||
expect(b).toBeLessThanOrEqual(100); | ||
} | ||
}); | ||
}); | ||
describe('#constructor', () => { | ||
@@ -18,2 +61,7 @@ it('color argument.', () => { | ||
it('can set color as a color data.', () => { | ||
const color = new MooColor({ model: 'rgb', values: [255, 0, 0] }); | ||
expect(color.toHex('short')).toEqual('#f00'); | ||
}); | ||
it('if no argument, color is black.', () => { | ||
@@ -24,5 +72,3 @@ expect(new MooColor().toHex('short')).toEqual('#000'); | ||
it('if parsing failed, occurs error.', () => { | ||
expect(() => { | ||
const color = new MooColor([]); | ||
}).toThrowError(); | ||
expect(() => new MooColor('wrong string')).toThrow(Error); | ||
}); | ||
@@ -198,45 +244,2 @@ }); | ||
}); | ||
describe('#random', () => { | ||
it('sets random color.', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const c = new MooColor().random(); | ||
const [h, w, b] = c.getColorAs('hwb').values; | ||
expect(h).toBeGreaterThanOrEqual(0); | ||
expect(h).toBeLessThanOrEqual(360); | ||
expect(w).toBeGreaterThanOrEqual(0); | ||
expect(w).toBeLessThanOrEqual(100); | ||
expect(b).toBeGreaterThanOrEqual(0); | ||
expect(b).toBeLessThanOrEqual(100); | ||
} | ||
}); | ||
it('specifying whiteness.', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const c = new MooColor().random({white: 50, black: [0, 50]}); | ||
const [h, w, b] = c.getColorAs('hwb').values; | ||
expect(h).toBeGreaterThanOrEqual(0); | ||
expect(h).toBeLessThanOrEqual(360); | ||
expect(w).toEqual(50); | ||
expect(b).toBeGreaterThanOrEqual(0); | ||
expect(b).toBeLessThanOrEqual(100); | ||
} | ||
}); | ||
it('range setting: hue', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const c = new MooColor().random({ hue: [0, 60] }); | ||
const [h, w, b] = c.getColorAs('hwb').values; | ||
expect(h).toBeGreaterThanOrEqual(0); | ||
expect(h).toBeLessThanOrEqual(60); | ||
expect(w).toBeGreaterThanOrEqual(0); | ||
expect(w).toBeLessThanOrEqual(100); | ||
expect(b).toBeGreaterThanOrEqual(0); | ||
expect(b).toBeLessThanOrEqual(100); | ||
} | ||
}); | ||
}); | ||
}); |
@@ -1,59 +0,63 @@ | ||
import * as Util from '../src/util/util'; | ||
import { | ||
arrayIsEqual, | ||
degree, | ||
getRandom, | ||
padEnd, | ||
padStart, | ||
} from '../src/util/util'; | ||
describe('#Util', () => { | ||
describe('#padStart', () => { | ||
it('padStart', () => { | ||
let res = Util.padStart('xx', 4, 'O'); | ||
expect(res).toEqual('OOxx'); | ||
res = Util.padStart('xx', 8, '12'); | ||
expect(res).toEqual('121212xx'); | ||
}); | ||
describe('#padStart', () => { | ||
it('padStart', () => { | ||
let res = padStart('xx', 4, 'O'); | ||
expect(res).toEqual('OOxx'); | ||
res = padStart('xx', 8, '12'); | ||
expect(res).toEqual('121212xx'); | ||
}); | ||
}); | ||
describe('#padEnd', () => { | ||
it('padEnd', () => { | ||
let res = Util.padEnd('4', 4, '-'); | ||
expect(res).toEqual('4---'); | ||
res = Util.padEnd('xx', 8, '123'); | ||
expect(res).toEqual('xx123123'); | ||
}); | ||
describe('#padEnd', () => { | ||
it('padEnd', () => { | ||
let res = padEnd('4', 4, '-'); | ||
expect(res).toEqual('4---'); | ||
res = padEnd('xx', 8, '123'); | ||
expect(res).toEqual('xx123123'); | ||
}); | ||
it('no space, no change.', () => { | ||
const str = Util.padEnd('1234', 4, '_'); | ||
expect(str).toEqual('1234'); | ||
}); | ||
it('no space, no change.', () => { | ||
const str = padEnd('1234', 4, '_'); | ||
expect(str).toEqual('1234'); | ||
}); | ||
}); | ||
describe('#getRandom', () => { | ||
it('works.', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const num = Util.getRandom(0, 255, 2); | ||
expect(num).toBeGreaterThanOrEqual(0); | ||
expect(num).toBeLessThanOrEqual(255); | ||
} | ||
}); | ||
describe('#getRandom', () => { | ||
it('works.', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const num = getRandom(0, 255, 2); | ||
expect(num).toBeGreaterThanOrEqual(0); | ||
expect(num).toBeLessThanOrEqual(255); | ||
} | ||
}); | ||
it('0-360', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const num = Util.getRandom(0, 360); | ||
expect(num).toBeGreaterThanOrEqual(0); | ||
expect(num).toBeLessThanOrEqual(360); | ||
} | ||
}); | ||
it('0-360', () => { | ||
for (let i = 0; i < 10; i++) { | ||
const num = getRandom(0, 360); | ||
expect(num).toBeGreaterThanOrEqual(0); | ||
expect(num).toBeLessThanOrEqual(360); | ||
} | ||
}); | ||
}); | ||
describe('#degree', () => { | ||
it('converts minus to plus degree.', () => { | ||
const d = Util.degree(-45); | ||
expect(d).toEqual(315); | ||
}); | ||
describe('#degree', () => { | ||
it('converts minus to plus degree.', () => { | ||
const d = degree(-45); | ||
expect(d).toEqual(315); | ||
}); | ||
}); | ||
describe('#arrayIsEqual', () => { | ||
it('works.', () => { | ||
expect(Util.arrayIsEqual([1, 2, 3], [1, 2, 3])).toBe(true); | ||
expect(Util.arrayIsEqual([1, 2, 3], [2, 2, 3])).toBe(false); | ||
expect(Util.arrayIsEqual([1, [2, 3], 4], [1, [2, 3], 4])).toBe(true); | ||
}); | ||
describe('#arrayIsEqual', () => { | ||
it('works.', () => { | ||
expect(arrayIsEqual([1, 2, 3], [1, 2, 3])).toBe(true); | ||
expect(arrayIsEqual([1, 2, 3], [2, 2, 3])).toBe(false); | ||
expect(arrayIsEqual([1, [2, 3], 4], [1, [2, 3], 4])).toBe(true); | ||
}); | ||
}); |
@@ -90,3 +90,2 @@ export type Color = ColorData; | ||
invert(percent?: number): this; | ||
random(arg?: RandomArguments): this; | ||
} |
@@ -19,5 +19,26 @@ import { | ||
export class MooColor extends ColorFormatter implements ColorModifiable<MooColor>, ColorStateAccessible { | ||
/** | ||
* Helper method for `mix()`. | ||
* | ||
* @static | ||
* @param {(string|MooColor)} color1 | ||
* @param {(string|MooColor)} color2 | ||
* @param {number} [percentOf1] | ||
* @returns {MooColor} | ||
* @memberof MooColor | ||
*/ | ||
static mix(color1: string|MooColor, color2: string|MooColor, percentOf1?: number): MooColor; | ||
/** | ||
* Create random color as HWB color model. | ||
* | ||
* @static | ||
* @param {RandomArguments} [arg] | ||
* @returns {MooColor} | ||
* @memberof MooColor | ||
*/ | ||
static random(arg?: RandomArguments): MooColor; | ||
/** | ||
* Returns color brightness from 0 to 255. (It based RGB) | ||
@@ -54,5 +75,6 @@ * @see https://www.w3.org/TR/AERT/#color-contrast | ||
* Creates an instance of MooColor. | ||
* @param {*} [color] color string. e.g. '#ff0000' 'rgba(255, 0, 0, .5)' 'hsl(120, 50%, 100%)' | ||
* @param {(string|Color)} [color] color value. e.g. '#ff0000' 'rgba(255, 0, 0, .5)' 'hsl(120, 50%, 100%)' | ||
* @memberof MooColor | ||
*/ | ||
constructor(color?: any); | ||
constructor(color?: string|Color); | ||
@@ -155,12 +177,4 @@ setColorByParser(str: string): this; | ||
invert(percent?: number): this; | ||
/** | ||
* Sets random color values as HWB color model. | ||
* | ||
* @param {RandomArguments} [{hue, white, black}={}] | ||
* @returns {this} | ||
*/ | ||
random(arg?: RandomArguments): this; | ||
} | ||
export default MooColor; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
224388
36
3352