Comparing version 1.0.2 to 1.0.3
@@ -10,2 +10,8 @@ # Changelog | ||
## 1.0.3 - 2022-04-04 | ||
- Lint codes. | ||
- Fix docs. | ||
- Update dependencies. | ||
## [1.0.2] - 2019-12-31 | ||
@@ -12,0 +18,0 @@ |
@@ -10,90 +10,6 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["MooColor"] = factory(); | ||
})(this, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // create a fake namespace object | ||
/******/ // mode & 1: value is a module id, require it | ||
/******/ // mode & 2: merge all properties of value into the ns | ||
/******/ // mode & 4: return value when already ns object | ||
/******/ // mode & 8|1: behave like require | ||
/******/ __webpack_require__.t = function(value, mode) { | ||
/******/ if(mode & 1) value = __webpack_require__(value); | ||
/******/ if(mode & 8) return value; | ||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||
/******/ var ns = Object.create(null); | ||
/******/ __webpack_require__.r(ns); | ||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||
/******/ return ns; | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = "./src/moo-color.ts"); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ({ | ||
})(this, () => { | ||
return /******/ (() => { // webpackBootstrap | ||
/******/ "use strict"; | ||
/******/ var __webpack_modules__ = ({ | ||
@@ -104,6 +20,4 @@ /***/ "./node_modules/color-name/index.js": | ||
\******************************************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ ((module) => { | ||
"use strict"; | ||
@@ -269,20 +183,20 @@ | ||
\********************************/ | ||
/*! exports provided: hslToRgb, rgbToHsl, hwbToRgb, rgbToHwb, cmykToRgb, rgbToCmyk, hsvToRgb, rgbToHsv, hsvToHwb, hwbToHsv, rgbToHex, hexToRgb, resolveHwb */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hslToRgb", function() { return hslToRgb; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rgbToHsl", function() { return rgbToHsl; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hwbToRgb", function() { return hwbToRgb; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rgbToHwb", function() { return rgbToHwb; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cmykToRgb", function() { return cmykToRgb; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rgbToCmyk", function() { return rgbToCmyk; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hsvToRgb", function() { return hsvToRgb; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rgbToHsv", function() { return rgbToHsv; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hsvToHwb", function() { return hsvToHwb; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hwbToHsv", function() { return hwbToHsv; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "rgbToHex", function() { return rgbToHex; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hexToRgb", function() { return hexToRgb; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "resolveHwb", function() { return resolveHwb; }); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "cmykToRgb": () => (/* binding */ cmykToRgb), | ||
/* harmony export */ "hexToRgb": () => (/* binding */ hexToRgb), | ||
/* harmony export */ "hslToRgb": () => (/* binding */ hslToRgb), | ||
/* harmony export */ "hsvToHwb": () => (/* binding */ hsvToHwb), | ||
/* harmony export */ "hsvToRgb": () => (/* binding */ hsvToRgb), | ||
/* harmony export */ "hwbToHsv": () => (/* binding */ hwbToHsv), | ||
/* harmony export */ "hwbToRgb": () => (/* binding */ hwbToRgb), | ||
/* harmony export */ "resolveHwb": () => (/* binding */ resolveHwb), | ||
/* harmony export */ "rgbToCmyk": () => (/* binding */ rgbToCmyk), | ||
/* harmony export */ "rgbToHex": () => (/* binding */ rgbToHex), | ||
/* harmony export */ "rgbToHsl": () => (/* binding */ rgbToHsl), | ||
/* harmony export */ "rgbToHsv": () => (/* binding */ rgbToHsv), | ||
/* harmony export */ "rgbToHwb": () => (/* binding */ rgbToHwb) | ||
/* harmony export */ }); | ||
/* harmony import */ var _util_util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util/util */ "./src/util/util.ts"); | ||
@@ -344,4 +258,2 @@ | ||
var h; | ||
var s; | ||
var l; | ||
if (delta === 0) { | ||
@@ -359,4 +271,4 @@ h = 0; | ||
} | ||
l = (max + min) / 2; | ||
s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)); | ||
var l = (max + min) / 2; | ||
var s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)); | ||
return [h, s * 100, l * 100]; | ||
@@ -475,4 +387,2 @@ } | ||
var h; | ||
var s; | ||
var v; | ||
var max = Math.max(r, g, b); | ||
@@ -493,4 +403,4 @@ var min = Math.min(r, g, b); | ||
} | ||
s = max === 0 ? 0 : delta / max; | ||
v = max; | ||
var s = max === 0 ? 0 : delta / max; | ||
var v = max; | ||
return [h, s * 100, v * 100]; | ||
@@ -545,3 +455,3 @@ } | ||
} | ||
var hex = arr.map(function (x) { return Object(_util_util__WEBPACK_IMPORTED_MODULE_0__["padStart"])(x.toString(16), 2, '0'); }).join(''); | ||
var hex = arr.map(function (x) { return (0,_util_util__WEBPACK_IMPORTED_MODULE_0__.padStart)(x.toString(16), 2, '0'); }).join(''); | ||
return enableShort ? hexToShorthand(hex) : hex; | ||
@@ -599,8 +509,9 @@ } | ||
\********************************/ | ||
/*! exports provided: ColorFormatter, default */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ColorFormatter", function() { return ColorFormatter; }); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "ColorFormatter": () => (/* binding */ ColorFormatter), | ||
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | ||
/* harmony export */ }); | ||
/* harmony import */ var _color_converter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./color-converter */ "./src/color-converter.ts"); | ||
@@ -615,6 +526,6 @@ /* harmony import */ var _color_names__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./color-names */ "./src/color-names.ts"); | ||
// In hwb model, whiteness and blackness value's adjust will required. | ||
this.resolveHwb = _color_converter__WEBPACK_IMPORTED_MODULE_0__["resolveHwb"]; | ||
this.resolveHwb = _color_converter__WEBPACK_IMPORTED_MODULE_0__.resolveHwb; | ||
} | ||
ColorFormatter.prototype.setColor = function (color) { | ||
color.alpha = Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["resolveAlpha"])(color.alpha); | ||
color.alpha = (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.resolveAlpha)(color.alpha); | ||
this.color = color; | ||
@@ -709,3 +620,3 @@ return this; | ||
var key = _a[_i]; | ||
if (Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["arrayIsEqual"])(_color_names__WEBPACK_IMPORTED_MODULE_1__["default"][key], [r, g, b])) { | ||
if ((0,_util_util__WEBPACK_IMPORTED_MODULE_2__.arrayIsEqual)(_color_names__WEBPACK_IMPORTED_MODULE_1__["default"][key], [r, g, b])) { | ||
name = key; | ||
@@ -715,9 +626,9 @@ break; | ||
} | ||
return a === null && name !== '' ? name : "#" + _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHex"](r, g, b, a, true); | ||
return a === null && name !== '' ? name : "#".concat(_color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHex(r, g, b, a, true)); | ||
}; | ||
switch (mode) { | ||
case 'name': return nameOrShort(); | ||
case 'short': return "#" + _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHex"](r, g, b, a, true); | ||
case 'short': return "#".concat(_color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHex(r, g, b, a, true)); | ||
case 'full': | ||
default: return "#" + _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHex"](r, g, b, a); | ||
default: return "#".concat(_color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHex(r, g, b, a)); | ||
} | ||
@@ -738,7 +649,7 @@ }; | ||
if (mode === 'percent') { | ||
_a = [r, g, b].map(function (x) { return x / 255 * 100 + "%"; }), r = _a[0], g = _a[1], b = _a[2]; | ||
_a = [r, g, b].map(function (x) { return "".concat(x / 255 * 100, "%"); }), r = _a[0], g = _a[1], b = _a[2]; | ||
} | ||
return color.alpha === 1 | ||
? "rgb(" + r + ", " + g + ", " + b + ")" | ||
: "rgba(" + r + ", " + g + ", " + b + ", " + color.alpha + ")"; | ||
? "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")") | ||
: "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(color.alpha, ")"); | ||
}; | ||
@@ -752,5 +663,5 @@ /** | ||
var color = this.getColorAs('hwb'); | ||
var _a = color.values.map(function (x) { return Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["decimal"])(x, 2); }), h = _a[0], w = _a[1], b = _a[2]; | ||
var a = color.alpha === 1 ? '' : ", " + color.alpha; | ||
return "hwb(" + h + ", " + w + "%, " + b + "%" + a + ")"; | ||
var _a = color.values.map(function (x) { return (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.decimal)(x, 2); }), h = _a[0], w = _a[1], b = _a[2]; | ||
var a = color.alpha === 1 ? '' : ", ".concat(color.alpha); | ||
return "hwb(".concat(h, ", ").concat(w, "%, ").concat(b, "%").concat(a, ")"); | ||
}; | ||
@@ -764,6 +675,6 @@ /** | ||
var color = this.getColorAs('hsl'); | ||
var _a = color.values.map(function (x) { return Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["decimal"])(x, 2); }), h = _a[0], s = _a[1], l = _a[2]; | ||
var _a = color.values.map(function (x) { return (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.decimal)(x, 2); }), h = _a[0], s = _a[1], l = _a[2]; | ||
return color.alpha === 1 | ||
? "hsl(" + h + ", " + s + "%, " + l + "%)" | ||
: "hsla(" + h + ", " + s + "%, " + l + "%, " + color.alpha + ")"; | ||
? "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)") | ||
: "hsla(".concat(h, ", ").concat(s, "%, ").concat(l, "%, ").concat(color.alpha, ")"); | ||
}; | ||
@@ -776,6 +687,6 @@ /** | ||
var color = this.getColorAs('hsv'); | ||
var _a = color.values.map(function (x) { return Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["decimal"])(x, 2); }), h = _a[0], s = _a[1], v = _a[2]; | ||
var _a = color.values.map(function (x) { return (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.decimal)(x, 2); }), h = _a[0], s = _a[1], v = _a[2]; | ||
return color.alpha === 1 | ||
? "hsv(" + h + ", " + s + "%, " + v + "%)" | ||
: "hsva(" + h + ", " + s + "%, " + v + "%, " + color.alpha + ")"; | ||
? "hsv(".concat(h, ", ").concat(s, "%, ").concat(v, "%)") | ||
: "hsva(".concat(h, ", ").concat(s, "%, ").concat(v, "%, ").concat(color.alpha, ")"); | ||
}; | ||
@@ -789,5 +700,5 @@ /** | ||
var color = this.getColorAs('cmyk'); | ||
var _a = color.values.map(function (x) { return Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["decimal"])(x, 2); }), c = _a[0], m = _a[1], y = _a[2], k = _a[3]; | ||
var a = color.alpha === 1 ? '' : ", " + color.alpha; | ||
return "cmyk(" + c + "%, " + m + "%, " + y + "%, " + k + "%" + a + ")"; | ||
var _a = color.values.map(function (x) { return (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.decimal)(x, 2); }), c = _a[0], m = _a[1], y = _a[2], k = _a[3]; | ||
var a = color.alpha === 1 ? '' : ", ".concat(color.alpha); | ||
return "cmyk(".concat(c, "%, ").concat(m, "%, ").concat(y, "%, ").concat(k, "%").concat(a, ")"); | ||
}; | ||
@@ -798,6 +709,6 @@ ColorFormatter.prototype.convertFromRgb = function (_a, model) { | ||
case 'rgb': return [r, g, b]; | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHwb"](r, g, b); | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHsl"](r, g, b); | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHsv"](r, g, b); | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToCmyk"](r, g, b); | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHwb(r, g, b); | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHsl(r, g, b); | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHsv(r, g, b); | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToCmyk(r, g, b); | ||
} | ||
@@ -807,9 +718,9 @@ }; | ||
var h = _a[0], w = _a[1], b = _a[2]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__["hwbToRgb"](h, w, b), red = _b[0], green = _b[1], blue = _b[2]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__.hwbToRgb(h, w, b), red = _b[0], green = _b[1], blue = _b[2]; | ||
switch (model) { | ||
case 'rgb': return [red, green, blue]; | ||
case 'hwb': return [h, w, b]; | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHsl"](red, green, blue); | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["hwbToHsv"](h, w, b); | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToCmyk"](red, green, blue); | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHsl(red, green, blue); | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.hwbToHsv(h, w, b); | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToCmyk(red, green, blue); | ||
} | ||
@@ -819,9 +730,9 @@ }; | ||
var h = _a[0], s = _a[1], l = _a[2]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__["hslToRgb"](h, s, l), red = _b[0], green = _b[1], blue = _b[2]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__.hslToRgb(h, s, l), red = _b[0], green = _b[1], blue = _b[2]; | ||
switch (model) { | ||
case 'rgb': return [red, green, blue]; | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHwb"](red, green, blue); | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHwb(red, green, blue); | ||
case 'hsl': return [h, s, l]; | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHsv"](red, green, blue); | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToCmyk"](red, green, blue); | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHsv(red, green, blue); | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToCmyk(red, green, blue); | ||
} | ||
@@ -831,9 +742,9 @@ }; | ||
var h = _a[0], s = _a[1], v = _a[2]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__["hsvToRgb"](h, s, v), red = _b[0], green = _b[1], blue = _b[2]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__.hsvToRgb(h, s, v), red = _b[0], green = _b[1], blue = _b[2]; | ||
switch (model) { | ||
case 'rgb': return [red, green, blue]; | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["hsvToHwb"](h, s, v); | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHsl"](red, green, blue); | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.hsvToHwb(h, s, v); | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHsl(red, green, blue); | ||
case 'hsv': return [h, s, v]; | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToCmyk"](red, green, blue); | ||
case 'cmyk': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToCmyk(red, green, blue); | ||
} | ||
@@ -843,8 +754,8 @@ }; | ||
var c = _a[0], m = _a[1], y = _a[2], k = _a[3]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__["cmykToRgb"](c, m, y, k), red = _b[0], green = _b[1], blue = _b[2]; | ||
var _b = _color_converter__WEBPACK_IMPORTED_MODULE_0__.cmykToRgb(c, m, y, k), red = _b[0], green = _b[1], blue = _b[2]; | ||
switch (model) { | ||
case 'rgb': return [red, green, blue]; | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHwb"](red, green, blue); | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHsl"](red, green, blue); | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__["rgbToHsv"](red, green, blue); | ||
case 'hwb': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHwb(red, green, blue); | ||
case 'hsl': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHsl(red, green, blue); | ||
case 'hsv': return _color_converter__WEBPACK_IMPORTED_MODULE_0__.rgbToHsv(red, green, blue); | ||
case 'cmyk': return [c, m, y, k]; | ||
@@ -856,3 +767,3 @@ } | ||
/* harmony default export */ __webpack_exports__["default"] = (ColorFormatter); | ||
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ColorFormatter); | ||
@@ -866,11 +777,12 @@ | ||
\****************************/ | ||
/*! exports provided: default */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | ||
/* harmony export */ }); | ||
/* harmony import */ var color_name__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! color-name */ "./node_modules/color-name/index.js"); | ||
/* harmony import */ var color_name__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(color_name__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony default export */ __webpack_exports__["default"] = (color_name__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (color_name__WEBPACK_IMPORTED_MODULE_0__); | ||
@@ -880,2 +792,14 @@ | ||
/***/ "./src/color.ts": | ||
/*!**********************!*\ | ||
!*** ./src/color.ts ***! | ||
\**********************/ | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
__webpack_require__.r(__webpack_exports__); | ||
/***/ }), | ||
/***/ "./src/input-parser.ts": | ||
@@ -885,8 +809,8 @@ /*!*****************************!*\ | ||
\*****************************/ | ||
/*! exports provided: default */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return inputParser; }); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "default": () => (/* binding */ inputParser) | ||
/* harmony export */ }); | ||
/* harmony import */ var _color_converter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./color-converter */ "./src/color-converter.ts"); | ||
@@ -949,3 +873,3 @@ /* harmony import */ var _color_names__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./color-names */ "./src/color-names.ts"); | ||
values = [r, g, b].map(function (x) { return parseInt(x, 0); }); | ||
alpha = Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["resolveAlpha"])(a); | ||
alpha = (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.resolveAlpha)(a); | ||
} | ||
@@ -955,3 +879,3 @@ else if (percent.test(input)) { | ||
values = [r, g, b].map(function (x) { return Math.round(parseFloat(x) * 2.55); }); | ||
alpha = Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["resolveAlpha"])(a); | ||
alpha = (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.resolveAlpha)(a); | ||
} | ||
@@ -963,4 +887,4 @@ else { | ||
model: 'rgb', | ||
values: values.map(function (x) { return Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(x, 0, 255); }), | ||
alpha: Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(alpha, 0, 1), | ||
values: values.map(function (x) { return (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(x, 0, 255); }), | ||
alpha: (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(alpha, 0, 1), | ||
}; | ||
@@ -976,7 +900,7 @@ } | ||
values: [ | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["degree"])(h), | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(s), 0, 100), | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(l), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.degree)(h), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(s), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(l), 0, 100), | ||
], | ||
alpha: Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["resolveAlpha"])(a), | ||
alpha: (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.resolveAlpha)(a), | ||
}; | ||
@@ -995,4 +919,4 @@ } | ||
model: 'hwb', | ||
values: Object(_color_converter__WEBPACK_IMPORTED_MODULE_0__["resolveHwb"])(Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["degree"])(h), Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(w), 0, 100), Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(b), 0, 100)), | ||
alpha: Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["resolveAlpha"])(a), | ||
values: (0,_color_converter__WEBPACK_IMPORTED_MODULE_0__.resolveHwb)((0,_util_util__WEBPACK_IMPORTED_MODULE_2__.degree)(h), (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(w), 0, 100), (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(b), 0, 100)), | ||
alpha: (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.resolveAlpha)(a), | ||
}; | ||
@@ -1012,7 +936,7 @@ } | ||
values: [ | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["degree"])(h), | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(s), 0, 100), | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(v), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.degree)(h), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(s), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(v), 0, 100), | ||
], | ||
alpha: Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["resolveAlpha"])(a), | ||
alpha: (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.resolveAlpha)(a), | ||
}; | ||
@@ -1032,8 +956,8 @@ } | ||
values: [ | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(c), 0, 100), | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(m), 0, 100), | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(y), 0, 100), | ||
Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["clamp"])(parseFloat(k), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(c), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(m), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(y), 0, 100), | ||
(0,_util_util__WEBPACK_IMPORTED_MODULE_2__.clamp)(parseFloat(k), 0, 100), | ||
], | ||
alpha: Object(_util_util__WEBPACK_IMPORTED_MODULE_2__["resolveAlpha"])(a), | ||
alpha: (0,_util_util__WEBPACK_IMPORTED_MODULE_2__.resolveAlpha)(a), | ||
}; | ||
@@ -1049,18 +973,149 @@ } | ||
/***/ "./src/moo-color.ts": | ||
/***/ "./src/util/util.ts": | ||
/*!**************************!*\ | ||
!*** ./src/moo-color.ts ***! | ||
!*** ./src/util/util.ts ***! | ||
\**************************/ | ||
/*! exports provided: ColorFormatter, MooColor, default */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MooColor", function() { return MooColor; }); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "arrayIsEqual": () => (/* binding */ arrayIsEqual), | ||
/* harmony export */ "clamp": () => (/* binding */ clamp), | ||
/* harmony export */ "decimal": () => (/* binding */ decimal), | ||
/* harmony export */ "degree": () => (/* binding */ degree), | ||
/* harmony export */ "getRandom": () => (/* binding */ getRandom), | ||
/* harmony export */ "padEnd": () => (/* binding */ padEnd), | ||
/* harmony export */ "padStart": () => (/* binding */ padStart), | ||
/* harmony export */ "resolveAlpha": () => (/* binding */ resolveAlpha) | ||
/* harmony export */ }); | ||
function padStart(str, length, chars) { | ||
var space = length - str.length; | ||
return space > 0 ? "".concat(makePad(chars, space)).concat(str) : str; | ||
} | ||
function padEnd(str, length, chars) { | ||
var space = length - str.length; | ||
return space > 0 ? "".concat(str).concat(makePad(chars, space)) : str; | ||
} | ||
function makePad(chars, limit) { | ||
while (chars.length < limit) { | ||
chars += chars; | ||
} | ||
return chars.substring(0, limit); | ||
} | ||
function clamp(num, min, max) { | ||
return Math.min(Math.max(min, num), max); | ||
} | ||
function degree(num) { | ||
num = typeof num === 'string' ? parseFloat(num) : num; | ||
return (num % 360 + 360) % 360; | ||
} | ||
function resolveAlpha(a) { | ||
a = typeof a === 'string' ? parseFloat(a) : a; | ||
return clamp(isNaN(a) ? 1 : a, 0, 1); | ||
} | ||
// @see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round | ||
function decimal(num, precision) { | ||
var factor = Math.pow(10, precision); | ||
return Math.round(num * factor) / factor; | ||
} | ||
function getRandom(min, max, precision) { | ||
if (precision === void 0) { precision = 0; } | ||
var num = Math.random() * (max - min) + min; | ||
return decimal(num, precision); | ||
} | ||
// https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript#answer-19746771 | ||
function arrayIsEqual(arr1, arr2) { | ||
return arr1.length === arr2.length && arr1.every(function (v, i) { | ||
return Array.isArray(v) ? arrayIsEqual(v, arr2[i]) : v === arr2[i]; | ||
}); | ||
} | ||
/***/ }) | ||
/******/ }); | ||
/************************************************************************/ | ||
/******/ // The module cache | ||
/******/ var __webpack_module_cache__ = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ // Check if module is in cache | ||
/******/ var cachedModule = __webpack_module_cache__[moduleId]; | ||
/******/ if (cachedModule !== undefined) { | ||
/******/ return cachedModule.exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = __webpack_module_cache__[moduleId] = { | ||
/******/ // no module.id needed | ||
/******/ // no module.loaded needed | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/compat get default export */ | ||
/******/ (() => { | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = (module) => { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ () => (module['default']) : | ||
/******/ () => (module); | ||
/******/ __webpack_require__.d(getter, { a: getter }); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
/******/ (() => { | ||
/******/ // define getter functions for harmony exports | ||
/******/ __webpack_require__.d = (exports, definition) => { | ||
/******/ for(var key in definition) { | ||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
(() => { | ||
/*!**************************!*\ | ||
!*** ./src/moo-color.ts ***! | ||
\**************************/ | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "ColorFormatter": () => (/* reexport safe */ _color_formatter__WEBPACK_IMPORTED_MODULE_1__["default"]), | ||
/* harmony export */ "MooColor": () => (/* binding */ MooColor), | ||
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | ||
/* harmony export */ }); | ||
/* 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_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"); | ||
/* harmony import */ var _color__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./color */ "./src/color.ts"); | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
@@ -1070,6 +1125,8 @@ var extendStatics = function (d, b) { | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
@@ -1085,2 +1142,3 @@ function __() { this.constructor = d; } | ||
var MooColor = /** @class */ (function (_super) { | ||
@@ -1127,6 +1185,6 @@ __extends(MooColor, _super); | ||
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); | ||
return (0,_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); | ||
return i === 0 ? (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.getRandom)(0, 360) : (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.getRandom)(0, 100, 2); | ||
} | ||
@@ -1136,3 +1194,3 @@ }), hue = _b[0], white = _b[1], black = _b[2]; | ||
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)), | ||
values: (0,_color_converter__WEBPACK_IMPORTED_MODULE_0__.resolveHwb)((0,_util_util__WEBPACK_IMPORTED_MODULE_3__.degree)(hue), (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(white, 0, 100), (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(black, 0, 100)), | ||
alpha: 1, | ||
@@ -1142,3 +1200,3 @@ }); | ||
MooColor.prototype.setColorByParser = function (str) { | ||
var color = Object(_input_parser__WEBPACK_IMPORTED_MODULE_2__["default"])(str); | ||
var color = (0,_input_parser__WEBPACK_IMPORTED_MODULE_2__["default"])(str); | ||
if (!color) { | ||
@@ -1163,3 +1221,3 @@ throw new Error('parsing error!'); | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -1176,3 +1234,3 @@ }); | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -1189,3 +1247,3 @@ }); | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -1204,3 +1262,3 @@ }); | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -1235,3 +1293,3 @@ }); | ||
return this.manipulate('hsl', function (h, s, l) { | ||
l = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(l + amount, 0, 100); | ||
l = (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(l + amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1247,3 +1305,3 @@ }); | ||
return this.manipulate('hsl', function (h, s, l) { | ||
l = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(l - amount, 0, 100); | ||
l = (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(l - amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1259,3 +1317,3 @@ }); | ||
return this.manipulate('hsl', function (h, s, l) { | ||
s = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(s + amount, 0, 100); | ||
s = (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(s + amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1271,3 +1329,3 @@ }); | ||
return this.manipulate('hsl', function (h, s, l) { | ||
s = Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["clamp"])(s - amount, 0, 100); | ||
s = (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(s - amount, 0, 100); | ||
return [h, s, l]; | ||
@@ -1290,3 +1348,3 @@ }); | ||
var _this = this; | ||
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); }); | ||
return this.manipulate('hwb', function (h, w, b) { return _this.resolveHwb(h, (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(w + amount, 0, 100), b); }); | ||
}; | ||
@@ -1300,3 +1358,3 @@ /** | ||
var _this = this; | ||
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)); }); | ||
return this.manipulate('hwb', function (h, w, b) { return _this.resolveHwb(h, w, (0,_util_util__WEBPACK_IMPORTED_MODULE_3__.clamp)(b + amount, 0, 100)); }); | ||
}; | ||
@@ -1309,3 +1367,3 @@ /** | ||
MooColor.prototype.rotate = function (d) { | ||
return this.manipulate('hsl', function (h, s, l) { return [Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["degree"])(h + d), s, l]; }); | ||
return this.manipulate('hsl', function (h, s, l) { return [(0,_util_util__WEBPACK_IMPORTED_MODULE_3__.degree)(h + d), s, l]; }); | ||
}; | ||
@@ -1336,3 +1394,3 @@ /** | ||
MooColor.prototype.complement = function () { | ||
return this.manipulate('hsl', function (h, s, l) { return [Object(_util_util__WEBPACK_IMPORTED_MODULE_3__["degree"])(h + 180), s, l]; }); | ||
return this.manipulate('hsl', function (h, s, l) { return [(0,_util_util__WEBPACK_IMPORTED_MODULE_3__.degree)(h + 180), s, l]; }); | ||
}; | ||
@@ -1360,71 +1418,10 @@ /** | ||
/* harmony default export */ __webpack_exports__["default"] = (MooColor); | ||
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MooColor); | ||
})(); | ||
/***/ }), | ||
/***/ "./src/util/util.ts": | ||
/*!**************************!*\ | ||
!*** ./src/util/util.ts ***! | ||
\**************************/ | ||
/*! exports provided: padStart, padEnd, clamp, degree, resolveAlpha, decimal, getRandom, arrayIsEqual */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "padStart", function() { return padStart; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "padEnd", function() { return padEnd; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "clamp", function() { return clamp; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "degree", function() { return degree; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "resolveAlpha", function() { return resolveAlpha; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "decimal", function() { return decimal; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getRandom", function() { return getRandom; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "arrayIsEqual", function() { return arrayIsEqual; }); | ||
function padStart(str, length, chars) { | ||
var space = length - str.length; | ||
return space > 0 ? "" + makePad(chars, space) + str : str; | ||
} | ||
function padEnd(str, length, chars) { | ||
var space = length - str.length; | ||
return space > 0 ? "" + str + makePad(chars, space) : str; | ||
} | ||
function makePad(chars, limit) { | ||
while (chars.length < limit) { | ||
chars += chars; | ||
} | ||
return chars.substring(0, limit); | ||
} | ||
function clamp(num, min, max) { | ||
return Math.min(Math.max(min, num), max); | ||
} | ||
function degree(num) { | ||
num = typeof num === 'string' ? parseFloat(num) : num; | ||
return (num % 360 + 360) % 360; | ||
} | ||
function resolveAlpha(a) { | ||
a = typeof a === 'string' ? parseFloat(a) : a; | ||
return clamp(isNaN(a) ? 1 : a, 0, 1); | ||
} | ||
// @see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round | ||
function decimal(num, precision) { | ||
var factor = Math.pow(10, precision); | ||
return Math.round(num * factor) / factor; | ||
} | ||
function getRandom(min, max, precision) { | ||
if (precision === void 0) { precision = 0; } | ||
var num = Math.random() * (max - min) + min; | ||
return decimal(num, precision); | ||
} | ||
// https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript#answer-19746771 | ||
function arrayIsEqual(arr1, arr2) { | ||
return arr1.length === arr2.length && arr1.every(function (v, i) { | ||
return Array.isArray(v) ? arrayIsEqual(v, arr2[i]) : v === arr2[i]; | ||
}); | ||
} | ||
/***/ }) | ||
/******/ }); | ||
/******/ return __webpack_exports__; | ||
/******/ })() | ||
; | ||
}); | ||
//# sourceMappingURL=moo-color.js.map |
@@ -1,29 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.MooColor=e():t.MooColor=e()}(this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s="./src/moo-color.ts")}({"./node_modules/color-name/index.js": | ||
/*!******************************************!*\ | ||
!*** ./node_modules/color-name/index.js ***! | ||
\******************************************/ | ||
/*! no static exports found */function(t,e,r){"use strict";t.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}},"./src/color-converter.ts": | ||
/*!********************************!*\ | ||
!*** ./src/color-converter.ts ***! | ||
\********************************/ | ||
/*! exports provided: hslToRgb, rgbToHsl, hwbToRgb, rgbToHwb, cmykToRgb, rgbToCmyk, hsvToRgb, rgbToHsv, hsvToHwb, hwbToHsv, rgbToHex, hexToRgb, resolveHwb */function(t,e,r){"use strict";r.r(e),r.d(e,"hslToRgb",(function(){return o})),r.d(e,"rgbToHsl",(function(){return a})),r.d(e,"hwbToRgb",(function(){return u})),r.d(e,"rgbToHwb",(function(){return s})),r.d(e,"cmykToRgb",(function(){return c})),r.d(e,"rgbToCmyk",(function(){return i})),r.d(e,"hsvToRgb",(function(){return l})),r.d(e,"rgbToHsv",(function(){return h})),r.d(e,"hsvToHwb",(function(){return p})),r.d(e,"hwbToHsv",(function(){return f})),r.d(e,"rgbToHex",(function(){return d})),r.d(e,"hexToRgb",(function(){return b})),r.d(e,"resolveHwb",(function(){return m}));var n=r(/*! ./util/util */"./src/util/util.ts");function o(t,e,r){t/=60,e/=100,r/=100;var n,o,a,u=(1-Math.abs(2*r-1))*e,s=u*(1-Math.abs(t%2-1)),c=r-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,e,r){t/=255,e/=255,r/=255;var n,o=Math.max(t,e,r),a=Math.min(t,e,r),u=o-a;return n=(o+a)/2,[0===u?0:o===t?(e-r)/u%6*60:o===e?60*((r-t)/u+2):60*((t-e)/u+4),100*(0===u?0:u/(1-Math.abs(2*n-1))),100*n]}function u(t,e,r){var n=f(t,e,r);return l(n[0],n[1],n[2])}function s(t,e,r){var n=h(t,e,r);return p(n[0],n[1],n[2])}function c(t,e,r,n){return[255*(1-(t/=100))*(1-(n/=100)),255*(1-(e/=100))*(1-n),255*(1-(r/=100))*(1-n)]}function i(t,e,r){t/=255,e/=255,r/=255;var n=1-Math.max(t,e,r);return[(1-t-n)/(1-n),(1-e-n)/(1-n),(1-r-n)/(1-n),n].map((function(t){return 100*t}))}function l(t,e,r){var n,o,a,u=t/60,s=(r/=100)*(e/=100),c=s*(1-Math.abs(u%2-1)),i=r-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,e,r){t/=255,e/=255,r/=255;var n=Math.max(t,e,r),o=n-Math.min(t,e,r);return[0===o?0:n===t?(e-r)/o%6*60:n===e?60*((r-t)/o+2):60*((t-e)/o+4),100*(0===n?0:o/n),100*n]}function p(t,e,r){return[t,100*((1-(e/=100))*(r/=100)),100*(1-r)]}function f(t,e,r){var n;return t=(n=m(t,e,r))[0],e=n[1],r=n[2],[t,100*(1-(e/=100)/(1-(r/=100))),100*(1-r)]}function d(t,e,r,o,a){var u=[t,e,r];"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 e=!0,r=t.match(/.{2}/g);return r.forEach((function(t){t.match(/(.)\1+/)||(e=!1)})),e?r.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,e,r,n,o){return e+e+r+r+n+n+(o=void 0===o?"":o)+o})).match(/.{2}/g).map((function(t,e){return 3!==e?parseInt(t,16):parseInt(t,16)/255}))}function m(t,e,r){var n=e+r;return n>100&&(e=100*Number((e/n).toFixed(4)),r=100*Number((r/n).toFixed(4))),[t,e,r]}},"./src/color-formatter.ts": | ||
/*!********************************!*\ | ||
!*** ./src/color-formatter.ts ***! | ||
\********************************/ | ||
/*! exports provided: ColorFormatter, default */function(t,e,r){"use strict";r.r(e),r.d(e,"ColorFormatter",(function(){return u}));var n=r(/*! ./color-converter */"./src/color-converter.ts"),o=r(/*! ./color-names */"./src/color-names.ts"),a=r(/*! ./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,e){var r;switch(t.model){case"rgb":r=this.convertFromRgb(t.values,e);break;case"hwb":r=this.convertFromHwb(t.values,e);break;case"hsl":r=this.convertFromHsl(t.values,e);break;case"hsv":r=this.convertFromHsv(t.values,e);break;case"cmyk":r=this.convertFromCmyk(t.values,e)}if(!r.length)throw new Error("Converting Error!");return{model:e,values:r,alpha:t.alpha}},t.prototype.toString=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];switch(t=t||this.color.model){case"hex":return this.toHex.apply(this,e);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,e)}},t.prototype.toHex=function(t){void 0===t&&(t="full");var e=this.getColorAs("rgb"),r=e.values.map((function(t){return Math.round(t)})),u=r[0],s=r[1],c=r[2],i=1===e.alpha?null:e.alpha;switch(t){case"name":return function(){for(var t="",e=0,r=Object.keys(o.default);e<r.length;e++){var l=r[e];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){var e;void 0===t&&(t="default");var r=this.getColorAs("rgb"),n=r.values.map((function(t){return Math.round(t)})),o=n[0],a=n[1],u=n[2];return"percent"===t&&(e=[o,a,u].map((function(t){return t/255*100+"%"})),o=e[0],a=e[1],u=e[2]),1===r.alpha?"rgb("+o+", "+a+", "+u+")":"rgba("+o+", "+a+", "+u+", "+r.alpha+")"},t.prototype.toHwb=function(){var t=this.getColorAs("hwb"),e=t.values.map((function(t){return Object(a.decimal)(t,2)}));return"hwb("+e[0]+", "+e[1]+"%, "+e[2]+"%"+(1===t.alpha?"":", "+t.alpha)+")"},t.prototype.toHsl=function(){var t=this.getColorAs("hsl"),e=t.values.map((function(t){return Object(a.decimal)(t,2)})),r=e[0],n=e[1],o=e[2];return 1===t.alpha?"hsl("+r+", "+n+"%, "+o+"%)":"hsla("+r+", "+n+"%, "+o+"%, "+t.alpha+")"},t.prototype.toHsv=function(){var t=this.getColorAs("hsv"),e=t.values.map((function(t){return Object(a.decimal)(t,2)})),r=e[0],n=e[1],o=e[2];return 1===t.alpha?"hsv("+r+", "+n+"%, "+o+"%)":"hsva("+r+", "+n+"%, "+o+"%, "+t.alpha+")"},t.prototype.toCmyk=function(){var t=this.getColorAs("cmyk"),e=t.values.map((function(t){return Object(a.decimal)(t,2)}));return"cmyk("+e[0]+"%, "+e[1]+"%, "+e[2]+"%, "+e[3]+"%"+(1===t.alpha?"":", "+t.alpha)+")"},t.prototype.convertFromRgb=function(t,e){var r=t[0],o=t[1],a=t[2];switch(e){case"rgb":return[r,o,a];case"hwb":return n.rgbToHwb(r,o,a);case"hsl":return n.rgbToHsl(r,o,a);case"hsv":return n.rgbToHsv(r,o,a);case"cmyk":return n.rgbToCmyk(r,o,a)}},t.prototype.convertFromHwb=function(t,e){var r=t[0],o=t[1],a=t[2],u=n.hwbToRgb(r,o,a),s=u[0],c=u[1],i=u[2];switch(e){case"rgb":return[s,c,i];case"hwb":return[r,o,a];case"hsl":return n.rgbToHsl(s,c,i);case"hsv":return n.hwbToHsv(r,o,a);case"cmyk":return n.rgbToCmyk(s,c,i)}},t.prototype.convertFromHsl=function(t,e){var r=t[0],o=t[1],a=t[2],u=n.hslToRgb(r,o,a),s=u[0],c=u[1],i=u[2];switch(e){case"rgb":return[s,c,i];case"hwb":return n.rgbToHwb(s,c,i);case"hsl":return[r,o,a];case"hsv":return n.rgbToHsv(s,c,i);case"cmyk":return n.rgbToCmyk(s,c,i)}},t.prototype.convertFromHsv=function(t,e){var r=t[0],o=t[1],a=t[2],u=n.hsvToRgb(r,o,a),s=u[0],c=u[1],i=u[2];switch(e){case"rgb":return[s,c,i];case"hwb":return n.hsvToHwb(r,o,a);case"hsl":return n.rgbToHsl(s,c,i);case"hsv":return[r,o,a];case"cmyk":return n.rgbToCmyk(s,c,i)}},t.prototype.convertFromCmyk=function(t,e){var r=t[0],o=t[1],a=t[2],u=t[3],s=n.cmykToRgb(r,o,a,u),c=s[0],i=s[1],l=s[2];switch(e){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[r,o,a,u]}},t}();e.default=u},"./src/color-names.ts": | ||
/*!****************************!*\ | ||
!*** ./src/color-names.ts ***! | ||
\****************************/ | ||
/*! exports provided: default */function(t,e,r){"use strict";r.r(e);var n=r(/*! color-name */"./node_modules/color-name/index.js");e.default=n},"./src/input-parser.ts": | ||
/*!*****************************!*\ | ||
!*** ./src/input-parser.ts ***! | ||
\*****************************/ | ||
/*! exports provided: default */function(t,e,r){"use strict";r.r(e),r.d(e,"default",(function(){return u}));var n=r(/*! ./color-converter */"./src/color-converter.ts"),o=r(/*! ./color-names */"./src/color-names.ts"),a=r(/*! ./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 e=/^hwba?\s*\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(e.test(t)){var r=t.match(e),o=r[1],u=r[2],s=r[3],c=r[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 e=/^hsla?\s*\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(e.test(t)){var r=t.match(e),n=r[1],o=r[2],u=r[3],s=r[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 e=/^hsva?\s*\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(e.test(t)){var r=t.match(e),n=r[1],o=r[2],u=r[3],s=r[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 e=/^cmyk\s*\(\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(e.test(t)){var r=t.match(e),n=r[1],o=r[2],u=r[3],s=r[4],c=r[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 e,r,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];e=l.match(/.{2}/g).map((function(t){return parseInt(t,16)})),r=h?c(h):1}else if(o.test(t)){var p=t.match(o);l=p[1],h=p[2];e=l.match(/.{1}/g).map((function(t){return parseInt(t+t,16)})),r=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];e=[d,b,m].map((function(t){return parseInt(t,0)})),r=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];e=[d,b,m].map((function(t){return Math.round(2.55*parseFloat(t))})),r=Object(a.resolveAlpha)(h)}return{model:"rgb",values:e.map((function(t){return Object(a.clamp)(t,0,255)})),alpha:Object(a.clamp)(r,0,1)}}(t)}}},"./src/moo-color.ts": | ||
/*!**************************!*\ | ||
!*** ./src/moo-color.ts ***! | ||
\**************************/ | ||
/*! exports provided: ColorFormatter, MooColor, default */function(t,e,r){"use strict";r.r(e),r.d(e,"MooColor",(function(){return i}));var n=r(/*! ./color-converter */"./src/color-converter.ts"),o=r(/*! ./color-formatter */"./src/color-formatter.ts");r.d(e,"ColorFormatter",(function(){return o.default}));var a,u=r(/*! ./input-parser */"./src/input-parser.ts"),s=r(/*! ./util/util */"./src/util/util.ts"),c=(a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=function(t){function e(e){var r=t.call(this)||this;return"object"==typeof e&&null!==e?r.setColor(e):"string"!=typeof e&&void 0!==e||(e=e||"#000",r.setColorByParser(e)),r}return c(e,t),e.mix=function(t,r,n){void 0===n&&(n=50);var o=t instanceof e?t:new e(t);return(r instanceof e?r:new e(r)).mix(o,n)},e.random=function(t){var r,o=void 0===t?{}:t,a=o.hue,u=o.white,c=o.black;return r=[a,u,c].map((function(t,e){if("number"==typeof t)return t;if(Array.isArray(t)){var r=0===e?0:2;return Object(s.getRandom)(Math.min.apply(Math,t),Math.max.apply(Math,t),r)}return 0===e?Object(s.getRandom)(0,360):Object(s.getRandom)(0,100,2)})),a=r[0],u=r[1],c=r[2],new e({model:"hwb",values:Object(n.resolveHwb)(Object(s.degree)(a),Object(s.clamp)(u,0,100),Object(s.clamp)(c,0,100)),alpha:1})},e.prototype.setColorByParser=function(t){var e=Object(u.default)(t);if(!e)throw new Error("parsing error!");return this.setColor(e)},e.prototype.clone=function(){return new e(this.color)},Object.defineProperty(e.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(e.prototype,"isLight",{get:function(){return this.brightness>=128},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDark",{get:function(){return this.brightness<128},enumerable:!0,configurable:!0}),Object.defineProperty(e.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}),e.prototype.contrastRatioWith=function(t){return(Math.max(this.luminance,t.luminance)+.05)/(Math.min(this.luminance,t.luminance)+.05)},e.prototype.isContrastEnough=function(t){return this.contrastRatioWith(t)>=4.5},e.prototype.lighten=function(t){return this.manipulate("hsl",(function(e,r,n){return[e,r,n=Object(s.clamp)(n+t,0,100)]}))},e.prototype.darken=function(t){return this.manipulate("hsl",(function(e,r,n){return[e,r,n=Object(s.clamp)(n-t,0,100)]}))},e.prototype.saturate=function(t){return this.manipulate("hsl",(function(e,r,n){return[e,r=Object(s.clamp)(r+t,0,100),n]}))},e.prototype.desaturate=function(t){return this.manipulate("hsl",(function(e,r,n){return[e,r=Object(s.clamp)(r-t,0,100),n]}))},e.prototype.grayscale=function(){return this.manipulate("hsl",(function(t,e,r){return[t,0,r]}))},e.prototype.whiten=function(t){var e=this;return this.manipulate("hwb",(function(r,n,o){return e.resolveHwb(r,Object(s.clamp)(n+t,0,100),o)}))},e.prototype.blacken=function(t){var e=this;return this.manipulate("hwb",(function(r,n,o){return e.resolveHwb(r,n,Object(s.clamp)(o+t,0,100))}))},e.prototype.rotate=function(t){return this.manipulate("hsl",(function(e,r,n){return[Object(s.degree)(e+t),r,n]}))},e.prototype.mix=function(t,r){void 0===r&&(r=50),r/=100;var n=this.getModel(),o=this.getColorAs("rgb"),a=t.getColorAs("rgb");return new e({model:"rgb",values:o.values.map((function(t,e){return t+(a.values[e]-t)*r})),alpha:o.alpha+(a.alpha-o.alpha)*r}).changeModel(n)},e.prototype.complement=function(){return this.manipulate("hsl",(function(t,e,r){return[Object(s.degree)(t+180),e,r]}))},e.prototype.invert=function(t){void 0===t&&(t=100),t/=100;return this.manipulate("rgb",(function(e,r,n){return[e,r,n].map((function(e){return function(t){return Math.round(Math.abs(t))}(255*t-e)}))}))},e.prototype.manipulate=function(t,e){var r=this.color.model,n=this.getColorAs(t);return n.values=e.apply(void 0,n.values),this.setColor(n).changeModel(r)},e}(o.default);e.default=i},"./src/util/util.ts": | ||
/*!**************************!*\ | ||
!*** ./src/util/util.ts ***! | ||
\**************************/ | ||
/*! exports provided: padStart, padEnd, clamp, degree, resolveAlpha, decimal, getRandom, arrayIsEqual */function(t,e,r){"use strict";function n(t,e,r){var n=e-t.length;return n>0?""+a(r,n)+t:t}function o(t,e,r){var n=e-t.length;return n>0?""+t+a(r,n):t}function a(t,e){for(;t.length<e;)t+=t;return t.substring(0,e)}function u(t,e,r){return Math.min(Math.max(e,t),r)}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,e){var r=Math.pow(10,e);return Math.round(t*r)/r}function l(t,e,r){return void 0===r&&(r=0),i(Math.random()*(e-t)+t,r)}function h(t,e){return t.length===e.length&&t.every((function(t,r){return Array.isArray(t)?h(t,e[r]):t===e[r]}))}r.r(e),r.d(e,"padStart",(function(){return n})),r.d(e,"padEnd",(function(){return o})),r.d(e,"clamp",(function(){return u})),r.d(e,"degree",(function(){return s})),r.d(e,"resolveAlpha",(function(){return c})),r.d(e,"decimal",(function(){return i})),r.d(e,"getRandom",(function(){return l})),r.d(e,"arrayIsEqual",(function(){return h}))}})})); | ||
/*! For license information please see moo-color.min.js.LICENSE.txt */ | ||
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MooColor=t():r.MooColor=t()}(this,(()=>(()=>{"use strict";var r={"./node_modules/color-name/index.js":r=>{r.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}},"./src/color-converter.ts":(r,t,e)=>{e.r(t),e.d(t,{cmykToRgb:()=>u,hexToRgb:()=>f,hslToRgb:()=>n,hsvToHwb:()=>p,hsvToRgb:()=>i,hwbToHsv:()=>d,hwbToRgb:()=>s,resolveHwb:()=>g,rgbToCmyk:()=>l,rgbToHex:()=>m,rgbToHsl:()=>a,rgbToHsv:()=>h,rgbToHwb:()=>c});var o=e("./src/util/util.ts");function n(r,t,e){r/=60,t/=100,e/=100;var o,n,a,s=(1-Math.abs(2*e-1))*t,c=s*(1-Math.abs(r%2-1)),u=e-s/2;switch(Math.floor(r)){case 0:o=s,n=c,a=0;break;case 1:o=c,n=s,a=0;break;case 2:o=0,n=s,a=c;break;case 3:o=0,n=c,a=s;break;case 4:o=c,n=0,a=s;break;case 5:o=s,n=0,a=c}return[o,n,a].map((function(r){return 255*(r+u)}))}function a(r,t,e){r/=255,t/=255,e/=255;var o=Math.max(r,t,e),n=Math.min(r,t,e),a=o-n,s=(o+n)/2;return[0===a?0:o===r?(t-e)/a%6*60:o===t?60*((e-r)/a+2):60*((r-t)/a+4),100*(0===a?0:a/(1-Math.abs(2*s-1))),100*s]}function s(r,t,e){var o=d(r,t,e);return i(o[0],o[1],o[2])}function c(r,t,e){var o=h(r,t,e);return p(o[0],o[1],o[2])}function u(r,t,e,o){return[255*(1-(r/=100))*(1-(o/=100)),255*(1-(t/=100))*(1-o),255*(1-(e/=100))*(1-o)]}function l(r,t,e){r/=255,t/=255,e/=255;var o=1-Math.max(r,t,e);return[(1-r-o)/(1-o),(1-t-o)/(1-o),(1-e-o)/(1-o),o].map((function(r){return 100*r}))}function i(r,t,e){var o,n,a,s=r/60,c=(e/=100)*(t/=100),u=c*(1-Math.abs(s%2-1)),l=e-c;switch(Math.floor(s)){case 0:o=c,n=u,a=0;break;case 1:o=u,n=c,a=0;break;case 2:o=0,n=c,a=u;break;case 3:o=0,n=u,a=c;break;case 4:o=u,n=0,a=c;break;case 5:o=c,n=0,a=u}return[o,n,a].map((function(r){return 255*(r+l)}))}function h(r,t,e){r/=255,t/=255,e/=255;var o=Math.max(r,t,e),n=o-Math.min(r,t,e);return[0===n?0:o===r?(t-e)/n%6*60:o===t?60*((e-r)/n+2):60*((r-t)/n+4),100*(0===o?0:n/o),100*o]}function p(r,t,e){return[r,(1-(t/=100))*(e/=100)*100,100*(1-e)]}function d(r,t,e){var o;return r=(o=g(r,t,e))[0],t=o[1],e=o[2],[r,100*(1-(t/=100)/(1-(e/=100))),100*(1-e)]}function m(r,t,e,n,a){var s=[r,t,e];"number"==typeof n&&s.push(Math.round(255*n));var c=s.map((function(r){return(0,o.padStart)(r.toString(16),2,"0")})).join("");return a?function(r){var t=!0,e=r.match(/.{2}/g);return e.forEach((function(r){r.match(/(.)\1+/)||(t=!1)})),t?e.map((function(r){return r.substring(1)})).join(""):r}(c):c}function f(r){return r.replace(/^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i,(function(r,t,e,o,n){return t+t+e+e+o+o+(n=void 0===n?"":n)+n})).match(/.{2}/g).map((function(r,t){return 3!==t?parseInt(r,16):parseInt(r,16)/255}))}function g(r,t,e){var o=t+e;return o>100&&(t=100*Number((t/o).toFixed(4)),e=100*Number((e/o).toFixed(4))),[r,t,e]}},"./src/color-formatter.ts":(r,t,e)=>{e.r(t),e.d(t,{ColorFormatter:()=>s,default:()=>c});var o=e("./src/color-converter.ts"),n=e("./src/color-names.ts"),a=e("./src/util/util.ts"),s=function(){function r(){this.resolveHwb=o.resolveHwb}return r.prototype.setColor=function(r){return r.alpha=(0,a.resolveAlpha)(r.alpha),this.color=r,this},r.prototype.getColor=function(){return this.color},r.prototype.getColorAs=function(r){return this.color.model===r?this.color:this.convert(this.color,r)},r.prototype.getModel=function(){return this.color?this.color.model:void 0},r.prototype.changeModel=function(r){return this.color.model===r?this:this.setColor(this.convert(this.color,r))},r.prototype.getAlpha=function(){return this.color.alpha},r.prototype.setAlpha=function(r){return this.color.alpha=r,this},r.prototype.convert=function(r,t){var e;switch(r.model){case"rgb":e=this.convertFromRgb(r.values,t);break;case"hwb":e=this.convertFromHwb(r.values,t);break;case"hsl":e=this.convertFromHsl(r.values,t);break;case"hsv":e=this.convertFromHsv(r.values,t);break;case"cmyk":e=this.convertFromCmyk(r.values,t)}if(!e.length)throw new Error("Converting Error!");return{model:t,values:e,alpha:r.alpha}},r.prototype.toString=function(r){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];switch(r=r||this.color.model){case"hex":return this.toHex.apply(this,t);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,t)}},r.prototype.toHex=function(r){void 0===r&&(r="full");var t=this.getColorAs("rgb"),e=t.values.map((function(r){return Math.round(r)})),s=e[0],c=e[1],u=e[2],l=1===t.alpha?null:t.alpha;switch(r){case"name":return function(){for(var r="",t=0,e=Object.keys(n.default);t<e.length;t++){var i=e[t];if((0,a.arrayIsEqual)(n.default[i],[s,c,u])){r=i;break}}return null===l&&""!==r?r:"#".concat(o.rgbToHex(s,c,u,l,!0))}();case"short":return"#".concat(o.rgbToHex(s,c,u,l,!0));default:return"#".concat(o.rgbToHex(s,c,u,l))}},r.prototype.toRgb=function(r){var t;void 0===r&&(r="default");var e=this.getColorAs("rgb"),o=e.values.map((function(r){return Math.round(r)})),n=o[0],a=o[1],s=o[2];return"percent"===r&&(t=[n,a,s].map((function(r){return"".concat(r/255*100,"%")})),n=t[0],a=t[1],s=t[2]),1===e.alpha?"rgb(".concat(n,", ").concat(a,", ").concat(s,")"):"rgba(".concat(n,", ").concat(a,", ").concat(s,", ").concat(e.alpha,")")},r.prototype.toHwb=function(){var r=this.getColorAs("hwb"),t=r.values.map((function(r){return(0,a.decimal)(r,2)})),e=t[0],o=t[1],n=t[2],s=1===r.alpha?"":", ".concat(r.alpha);return"hwb(".concat(e,", ").concat(o,"%, ").concat(n,"%").concat(s,")")},r.prototype.toHsl=function(){var r=this.getColorAs("hsl"),t=r.values.map((function(r){return(0,a.decimal)(r,2)})),e=t[0],o=t[1],n=t[2];return 1===r.alpha?"hsl(".concat(e,", ").concat(o,"%, ").concat(n,"%)"):"hsla(".concat(e,", ").concat(o,"%, ").concat(n,"%, ").concat(r.alpha,")")},r.prototype.toHsv=function(){var r=this.getColorAs("hsv"),t=r.values.map((function(r){return(0,a.decimal)(r,2)})),e=t[0],o=t[1],n=t[2];return 1===r.alpha?"hsv(".concat(e,", ").concat(o,"%, ").concat(n,"%)"):"hsva(".concat(e,", ").concat(o,"%, ").concat(n,"%, ").concat(r.alpha,")")},r.prototype.toCmyk=function(){var r=this.getColorAs("cmyk"),t=r.values.map((function(r){return(0,a.decimal)(r,2)})),e=t[0],o=t[1],n=t[2],s=t[3],c=1===r.alpha?"":", ".concat(r.alpha);return"cmyk(".concat(e,"%, ").concat(o,"%, ").concat(n,"%, ").concat(s,"%").concat(c,")")},r.prototype.convertFromRgb=function(r,t){var e=r[0],n=r[1],a=r[2];switch(t){case"rgb":return[e,n,a];case"hwb":return o.rgbToHwb(e,n,a);case"hsl":return o.rgbToHsl(e,n,a);case"hsv":return o.rgbToHsv(e,n,a);case"cmyk":return o.rgbToCmyk(e,n,a)}},r.prototype.convertFromHwb=function(r,t){var e=r[0],n=r[1],a=r[2],s=o.hwbToRgb(e,n,a),c=s[0],u=s[1],l=s[2];switch(t){case"rgb":return[c,u,l];case"hwb":return[e,n,a];case"hsl":return o.rgbToHsl(c,u,l);case"hsv":return o.hwbToHsv(e,n,a);case"cmyk":return o.rgbToCmyk(c,u,l)}},r.prototype.convertFromHsl=function(r,t){var e=r[0],n=r[1],a=r[2],s=o.hslToRgb(e,n,a),c=s[0],u=s[1],l=s[2];switch(t){case"rgb":return[c,u,l];case"hwb":return o.rgbToHwb(c,u,l);case"hsl":return[e,n,a];case"hsv":return o.rgbToHsv(c,u,l);case"cmyk":return o.rgbToCmyk(c,u,l)}},r.prototype.convertFromHsv=function(r,t){var e=r[0],n=r[1],a=r[2],s=o.hsvToRgb(e,n,a),c=s[0],u=s[1],l=s[2];switch(t){case"rgb":return[c,u,l];case"hwb":return o.hsvToHwb(e,n,a);case"hsl":return o.rgbToHsl(c,u,l);case"hsv":return[e,n,a];case"cmyk":return o.rgbToCmyk(c,u,l)}},r.prototype.convertFromCmyk=function(r,t){var e=r[0],n=r[1],a=r[2],s=r[3],c=o.cmykToRgb(e,n,a,s),u=c[0],l=c[1],i=c[2];switch(t){case"rgb":return[u,l,i];case"hwb":return o.rgbToHwb(u,l,i);case"hsl":return o.rgbToHsl(u,l,i);case"hsv":return o.rgbToHsv(u,l,i);case"cmyk":return[e,n,a,s]}},r}();const c=s},"./src/color-names.ts":(r,t,e)=>{e.r(t),e.d(t,{default:()=>o});const o=e("./node_modules/color-name/index.js")},"./src/color.ts":(r,t,e)=>{e.r(t)},"./src/input-parser.ts":(r,t,e)=>{e.r(t),e.d(t,{default:()=>s});var o=e("./src/color-converter.ts"),n=e("./src/color-names.ts"),a=e("./src/util/util.ts");function s(r){if(r in n.default)return{model:"rgb",values:n.default[r],alpha:1};if("transparent"===r)return{model:"rgb",values:[0,0,0],alpha:0};switch(r.substr(0,3).toLowerCase()){case"hwb":return function(r){var t=/^hwba?\s*\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(t.test(r)){var e=r.match(t),n=e[1],s=e[2],c=e[3],u=e[4];return{model:"hwb",values:(0,o.resolveHwb)((0,a.degree)(n),(0,a.clamp)(parseFloat(s),0,100),(0,a.clamp)(parseFloat(c),0,100)),alpha:(0,a.resolveAlpha)(u)}}return null}(r);case"hsl":return function(r){var t=/^hsla?\s*\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(t.test(r)){var e=r.match(t),o=e[1],n=e[2],s=e[3],c=e[4];return{model:"hsl",values:[(0,a.degree)(o),(0,a.clamp)(parseFloat(n),0,100),(0,a.clamp)(parseFloat(s),0,100)],alpha:(0,a.resolveAlpha)(c)}}return null}(r);case"hsv":return function(r){var t=/^hsva?\s*\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(t.test(r)){var e=r.match(t),o=e[1],n=e[2],s=e[3],c=e[4];return{model:"hsv",values:[(0,a.degree)(o),(0,a.clamp)(parseFloat(n),0,100),(0,a.clamp)(parseFloat(s),0,100)],alpha:(0,a.resolveAlpha)(c)}}return null}(r);case"cmy":return function(r){var t=/^cmyk\s*\(\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/i;if(t.test(r)){var e=r.match(t),o=e[1],n=e[2],s=e[3],c=e[4],u=e[5];return{model:"cmyk",values:[(0,a.clamp)(parseFloat(o),0,100),(0,a.clamp)(parseFloat(n),0,100),(0,a.clamp)(parseFloat(s),0,100),(0,a.clamp)(parseFloat(c),0,100)],alpha:(0,a.resolveAlpha)(u)}}return null}(r);default:return function(r){var t,e,o=/^#?([a-f0-9]{6})([a-f0-9]{2})?$/i,n=/^#?([a-f0-9]{3})([a-f0-9]{1})?$/i,s=/^rgba?\s*\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/,c=/^rgba?\s*\(\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/,u=function(r){return Math.round(parseInt(r,16)/255*100)/100};if(o.test(r)){var l=r.match(o),i=l[1],h=l[2];t=i.match(/.{2}/g).map((function(r){return parseInt(r,16)})),e=h?u(h):1}else if(n.test(r)){var p=r.match(n);i=p[1],h=p[2],t=i.match(/.{1}/g).map((function(r){return parseInt(r+r,16)})),e=h?u(h):1}else if(s.test(r)){var d=r.match(s),m=d[1],f=d[2],g=d[3];h=d[4],t=[m,f,g].map((function(r){return parseInt(r,0)})),e=(0,a.resolveAlpha)(h)}else{if(!c.test(r))return null;var b=r.match(c);m=b[1],f=b[2],g=b[3],h=b[4],t=[m,f,g].map((function(r){return Math.round(2.55*parseFloat(r))})),e=(0,a.resolveAlpha)(h)}return{model:"rgb",values:t.map((function(r){return(0,a.clamp)(r,0,255)})),alpha:(0,a.clamp)(e,0,1)}}(r)}}},"./src/util/util.ts":(r,t,e)=>{function o(r,t,e){var o=t-r.length;return o>0?"".concat(a(e,o)).concat(r):r}function n(r,t,e){var o=t-r.length;return o>0?"".concat(r).concat(a(e,o)):r}function a(r,t){for(;r.length<t;)r+=r;return r.substring(0,t)}function s(r,t,e){return Math.min(Math.max(t,r),e)}function c(r){return((r="string"==typeof r?parseFloat(r):r)%360+360)%360}function u(r){return r="string"==typeof r?parseFloat(r):r,s(isNaN(r)?1:r,0,1)}function l(r,t){var e=Math.pow(10,t);return Math.round(r*e)/e}function i(r,t,e){return void 0===e&&(e=0),l(Math.random()*(t-r)+r,e)}function h(r,t){return r.length===t.length&&r.every((function(r,e){return Array.isArray(r)?h(r,t[e]):r===t[e]}))}e.r(t),e.d(t,{arrayIsEqual:()=>h,clamp:()=>s,decimal:()=>l,degree:()=>c,getRandom:()=>i,padEnd:()=>n,padStart:()=>o,resolveAlpha:()=>u})}},t={};function e(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return r[o](a,a.exports,e),a.exports}e.n=r=>{var t=r&&r.__esModule?()=>r.default:()=>r;return e.d(t,{a:t}),t},e.d=(r,t)=>{for(var o in t)e.o(t,o)&&!e.o(r,o)&&Object.defineProperty(r,o,{enumerable:!0,get:t[o]})},e.o=(r,t)=>Object.prototype.hasOwnProperty.call(r,t),e.r=r=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})};var o={};return(()=>{e.r(o),e.d(o,{ColorFormatter:()=>n.default,MooColor:()=>u,default:()=>l});var r,t=e("./src/color-converter.ts"),n=e("./src/color-formatter.ts"),a=e("./src/input-parser.ts"),s=e("./src/util/util.ts"),c=(e("./src/color.ts"),r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,t){r.__proto__=t}||function(r,t){for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}),u=function(r){function e(t){var e=r.call(this)||this;return"object"==typeof t&&null!==t?e.setColor(t):"string"!=typeof t&&void 0!==t||(t=t||"#000",e.setColorByParser(t)),e}return c(e,r),e.mix=function(r,t,o){void 0===o&&(o=50);var n=r instanceof e?r:new e(r);return(t instanceof e?t:new e(t)).mix(n,o)},e.random=function(r){var o,n=void 0===r?{}:r,a=n.hue,c=n.white,u=n.black;return o=[a,c,u].map((function(r,t){if("number"==typeof r)return r;if(Array.isArray(r)){var e=0===t?0:2;return(0,s.getRandom)(Math.min.apply(Math,r),Math.max.apply(Math,r),e)}return 0===t?(0,s.getRandom)(0,360):(0,s.getRandom)(0,100,2)})),a=o[0],c=o[1],u=o[2],new e({model:"hwb",values:(0,t.resolveHwb)((0,s.degree)(a),(0,s.clamp)(c,0,100),(0,s.clamp)(u,0,100)),alpha:1})},e.prototype.setColorByParser=function(r){var t=(0,a.default)(r);if(!t)throw new Error("parsing error!");return this.setColor(t)},e.prototype.clone=function(){return new e(this.color)},Object.defineProperty(e.prototype,"brightness",{get:function(){var r=this.getColorAs("rgb").values;return(299*r[0]+587*r[1]+114*r[2])/1e3},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isLight",{get:function(){return this.brightness>=128},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDark",{get:function(){return this.brightness<128},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"luminance",{get:function(){var r=this.getColorAs("rgb").values.map((function(r){return r/255}));return.2126*r[0]+.7152*r[1]+.0722*r[2]},enumerable:!1,configurable:!0}),e.prototype.contrastRatioWith=function(r){return(Math.max(this.luminance,r.luminance)+.05)/(Math.min(this.luminance,r.luminance)+.05)},e.prototype.isContrastEnough=function(r){return this.contrastRatioWith(r)>=4.5},e.prototype.lighten=function(r){return this.manipulate("hsl",(function(t,e,o){return[t,e,o=(0,s.clamp)(o+r,0,100)]}))},e.prototype.darken=function(r){return this.manipulate("hsl",(function(t,e,o){return[t,e,o=(0,s.clamp)(o-r,0,100)]}))},e.prototype.saturate=function(r){return this.manipulate("hsl",(function(t,e,o){return[t,e=(0,s.clamp)(e+r,0,100),o]}))},e.prototype.desaturate=function(r){return this.manipulate("hsl",(function(t,e,o){return[t,e=(0,s.clamp)(e-r,0,100),o]}))},e.prototype.grayscale=function(){return this.manipulate("hsl",(function(r,t,e){return[r,0,e]}))},e.prototype.whiten=function(r){var t=this;return this.manipulate("hwb",(function(e,o,n){return t.resolveHwb(e,(0,s.clamp)(o+r,0,100),n)}))},e.prototype.blacken=function(r){var t=this;return this.manipulate("hwb",(function(e,o,n){return t.resolveHwb(e,o,(0,s.clamp)(n+r,0,100))}))},e.prototype.rotate=function(r){return this.manipulate("hsl",(function(t,e,o){return[(0,s.degree)(t+r),e,o]}))},e.prototype.mix=function(r,t){void 0===t&&(t=50),t/=100;var o=this.getModel(),n=this.getColorAs("rgb"),a=r.getColorAs("rgb");return new e({model:"rgb",values:n.values.map((function(r,e){return r+(a.values[e]-r)*t})),alpha:n.alpha+(a.alpha-n.alpha)*t}).changeModel(o)},e.prototype.complement=function(){return this.manipulate("hsl",(function(r,t,e){return[(0,s.degree)(r+180),t,e]}))},e.prototype.invert=function(r){return void 0===r&&(r=100),r/=100,this.manipulate("rgb",(function(t,e,o){return[t,e,o].map((function(t){return function(r){return Math.round(Math.abs(r))}(255*r-t)}))}))},e.prototype.manipulate=function(r,t){var e=this.color.model,o=this.getColorAs(r);return o.values=t.apply(void 0,o.values),this.setColor(o).changeModel(e)},e}(n.default);const l=u})(),o})())); |
@@ -85,12 +85,12 @@ # MooColor API | ||
- [lighten](modifier.md#lighten): Increase lightness. | ||
- [darken](modifier.md#darken): Decrease darkness. | ||
- [saturate](modifier.md#saturate): Increase saturation. | ||
- [desaturate](modifier.md#desaturate): Decrease saturation. | ||
- [grayscale](modifier.md#grayscale): Sets saturation value to 0. | ||
- [whiten](modifier.md#whiten): Modify whiteness. | ||
- [blacken](modifier.md#blacken): Modify blackness. | ||
- [rotate](modifier.md#rotate): Rotate hue value. | ||
- [mix](modifier.md#mix): Mix two colors. | ||
- [complement](modifier.md#complement): Sets color to the complement of a color. | ||
- [invert](modifier.md#invert): Sets color to the inverse (negative) of a color. | ||
- [lighten](modification.md#lighten): Increase lightness. | ||
- [darken](modification.md#darken): Decrease darkness. | ||
- [saturate](modification.md#saturate): Increase saturation. | ||
- [desaturate](modification.md#desaturate): Decrease saturation. | ||
- [grayscale](modification.md#grayscale): Sets saturation value to 0. | ||
- [whiten](modification.md#whiten): Modify whiteness. | ||
- [blacken](modification.md#blacken): Modify blackness. | ||
- [rotate](modification.md#rotate): Rotate hue value. | ||
- [mix](modification.md#mix): Mix two colors. | ||
- [complement](modification.md#complement): Sets color to the complement of a color. | ||
- [invert](modification.md#invert): Sets color to the inverse (negative) of a color. |
{ | ||
"name": "moo-color", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A javascript class that provides convenience for color parsing and manipulating.", | ||
@@ -13,4 +13,4 @@ "main": "dist/moo-color.js", | ||
"test": "jest", | ||
"build": "webpack --hide-modules", | ||
"watch": "npm run build -- --watch" | ||
"build": "webpack", | ||
"watch": "webpack --watch" | ||
}, | ||
@@ -35,15 +35,15 @@ "keywords": [ | ||
"@types/color-name": "^1.1.1", | ||
"@types/jest": "^24.0.25", | ||
"@typescript-eslint/eslint-plugin": "^2.14.0", | ||
"@typescript-eslint/parser": "^2.14.0", | ||
"eslint": "^6.8.0", | ||
"jest": "^24.9.0", | ||
"source-map-loader": "^0.2.4", | ||
"ts-jest": "^24.2.0", | ||
"ts-loader": "^6.2.1", | ||
"typescript": "^3.7.4", | ||
"webpack": "^4.41.5", | ||
"webpack-cli": "^3.3.10", | ||
"webpack-merge": "^4.2.2", | ||
"webpack-notifier": "^1.8.0" | ||
"@types/jest": "^27.4.1", | ||
"@typescript-eslint/eslint-plugin": "^5.17.0", | ||
"@typescript-eslint/parser": "^5.17.0", | ||
"eslint": "^8.12.0", | ||
"jest": "^27.5.1", | ||
"source-map-loader": "^3.0.1", | ||
"ts-jest": "^27.1.4", | ||
"ts-loader": "^9.2.8", | ||
"typescript": "^4.6.3", | ||
"webpack": "^5.71.0", | ||
"webpack-cli": "^4.9.2", | ||
"webpack-merge": "^5.8.0", | ||
"webpack-notifier": "^1.15.0" | ||
}, | ||
@@ -50,0 +50,0 @@ "jest": { |
# MooColor | ||
[![Build Status](https://travis-ci.org/archco/moo-color.svg?branch=master)](https://travis-ci.org/archco/moo-color) | ||
[![Node.js CI](https://github.com/archco/moo-color/actions/workflows/node.js.yml/badge.svg)](https://github.com/archco/moo-color/actions/workflows/node.js.yml) | ||
[![npm version](https://badge.fury.io/js/moo-color.svg)](https://www.npmjs.com/package/moo-color) | ||
@@ -5,0 +5,0 @@ [![Downloads](https://img.shields.io/npm/dm/moo-color.svg)](https://www.npmjs.com/package/moo-color) |
@@ -46,4 +46,2 @@ import { padStart } from './util/util'; | ||
let h; | ||
let s; | ||
let l; | ||
if (delta === 0) { | ||
@@ -58,4 +56,4 @@ h = 0; | ||
} | ||
l = (max + min) / 2; | ||
s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)); | ||
const l = (max + min) / 2; | ||
const s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)); | ||
return [h, s * 100, l * 100]; | ||
@@ -167,4 +165,2 @@ } | ||
let h; | ||
let s; | ||
let v; | ||
const max = Math.max(r, g, b); | ||
@@ -182,4 +178,4 @@ const min = Math.min(r, g, b); | ||
} | ||
s = max === 0 ? 0 : delta / max; | ||
v = max; | ||
const s = max === 0 ? 0 : delta / max; | ||
const v = max; | ||
return [h, s * 100, v * 100]; | ||
@@ -186,0 +182,0 @@ } |
const path = require('path'); | ||
const merge = require('webpack-merge'); | ||
const { merge } = require('webpack-merge'); | ||
const WebpackNotifierPlugin = require('webpack-notifier'); | ||
@@ -4,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
230562
39
1
80
3305