UNPKG

ami-cjs.js

Version:

<p align="center"> <img src="https://cloud.githubusercontent.com/assets/214063/23213764/78ade038-f90c-11e6-8208-4fcade5f3832.png" width="60%"> </p>

106 lines (84 loc) 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Colors = function () { function Colors() { _classCallCheck(this, Colors); } _createClass(Colors, null, [{ key: "cielab2XYZ", // http://www.easyrgb.com/index.php?X=MATH&H=08#text8 value: function cielab2XYZ(l, a, b) { var refX = 95.047; var refY = 100.00; var refZ = 108.883; var y = (l + 16) / 116; var x = a / 500 + y; var z = y - b / 200; if (Math.pow(y, 3) > 0.008856) { y = Math.pow(y, 3); } else { y = (y - 16 / 116) / 7.787; } if (Math.pow(x, 3) > 0.008856) { x = Math.pow(x, 3); } else { x = (x - 16 / 116) / 7.787; } if (Math.pow(z, 3) > 0.008856) { z = Math.pow(z, 3); } else { z = (z - 16 / 116) / 7.787; } return [refX * x, refY * y, refZ * z]; } }, { key: "xyz2RGB", value: function xyz2RGB(x, y, z) { x /= 100; y /= 100; z /= 100; var r = x * 3.2406 + y * -1.5372 + z * -0.4986; var g = x * -0.9689 + y * 1.8758 + z * 0.0415; var b = x * 0.0557 + y * -0.2040 + z * 1.0570; if (r > 0.0031308) { r = 1.055 * Math.pow(r, 1 / 2.4) - 0.055; } else { r = 12.92 * r; } if (g > 0.0031308) { g = 1.055 * Math.pow(g, 1 / 2.4) - 0.055; } else { g = 12.92 * g; } if (b > 0.0031308) { b = 1.055 * Math.pow(b, 1 / 2.4) - 0.055; } else { b = 12.92 * b; } r = r * 255; g = g * 255; b = b * 255; return [r, g, b]; } }, { key: "cielab2RGB", value: function cielab2RGB() { var l = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 50; var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; var b = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; if (!(l >= 0 && l <= 100)) { return null; } var xyz = this.cielab2XYZ(l, a, b); return this.xyz2RGB.apply(this, _toConsumableArray(xyz)); } }]); return Colors; }(); exports.default = Colors; module.exports = exports["default"];