1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports["default"] = void 0;
|
5 | var _curry = _interopRequireDefault(require("../internalHelpers/_curry"));
|
6 | var _rgba = _interopRequireDefault(require("./rgba"));
|
7 | var _parseToRgb = _interopRequireDefault(require("./parseToRgb"));
|
8 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
9 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function mix(weight, color, otherColor) {
|
37 | if (color === 'transparent') return otherColor;
|
38 | if (otherColor === 'transparent') return color;
|
39 | if (weight === 0) return otherColor;
|
40 | var parsedColor1 = (0, _parseToRgb["default"])(color);
|
41 | var color1 = _extends({}, parsedColor1, {
|
42 | alpha: typeof parsedColor1.alpha === 'number' ? parsedColor1.alpha : 1
|
43 | });
|
44 | var parsedColor2 = (0, _parseToRgb["default"])(otherColor);
|
45 | var color2 = _extends({}, parsedColor2, {
|
46 | alpha: typeof parsedColor2.alpha === 'number' ? parsedColor2.alpha : 1
|
47 | });
|
48 |
|
49 |
|
50 |
|
51 | var alphaDelta = color1.alpha - color2.alpha;
|
52 | var x = parseFloat(weight) * 2 - 1;
|
53 | var y = x * alphaDelta === -1 ? x : x + alphaDelta;
|
54 | var z = 1 + x * alphaDelta;
|
55 | var weight1 = (y / z + 1) / 2.0;
|
56 | var weight2 = 1 - weight1;
|
57 | var mixedColor = {
|
58 | red: Math.floor(color1.red * weight1 + color2.red * weight2),
|
59 | green: Math.floor(color1.green * weight1 + color2.green * weight2),
|
60 | blue: Math.floor(color1.blue * weight1 + color2.blue * weight2),
|
61 | alpha: color1.alpha * parseFloat(weight) + color2.alpha * (1 - parseFloat(weight))
|
62 | };
|
63 | return (0, _rgba["default"])(mixedColor);
|
64 | }
|
65 |
|
66 |
|
67 | var curriedMix = (0, _curry["default"] )(mix);
|
68 | var _default = exports["default"] = curriedMix;
|
69 | module.exports = exports.default; |
\ | No newline at end of file |