1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createInterpolateRound = exports.createInterpolateValue = exports.createInterpolateColor = exports.createInterpolateNumber = void 0;
|
4 | const color_1 = require("./color");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const createInterpolateNumber = (a, b) => {
|
12 | return (t) => a * (1 - t) + b * t;
|
13 | };
|
14 | exports.createInterpolateNumber = createInterpolateNumber;
|
15 | const createInterpolateColor = (a, b) => {
|
16 | const c1 = (0, color_1.string2rbg)(a);
|
17 | const c2 = (0, color_1.string2rbg)(b);
|
18 | if (c1 === null || c2 === null)
|
19 | return c1 ? () => a : () => b;
|
20 | return (t) => {
|
21 | const values = new Array(4);
|
22 | for (let i = 0; i < 4; i += 1) {
|
23 | const from = c1[i];
|
24 | const to = c2[i];
|
25 | values[i] = from * (1 - t) + to * t;
|
26 | }
|
27 | const [r, g, b, a] = values;
|
28 | return `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${a})`;
|
29 | };
|
30 | };
|
31 | exports.createInterpolateColor = createInterpolateColor;
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | const createInterpolateValue = (a, b) => {
|
39 | if (typeof a === 'number' && typeof b === 'number')
|
40 | return (0, exports.createInterpolateNumber)(a, b);
|
41 | if (typeof a === 'string' && typeof b === 'string')
|
42 | return (0, exports.createInterpolateColor)(a, b);
|
43 | return () => a;
|
44 | };
|
45 | exports.createInterpolateValue = createInterpolateValue;
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | const createInterpolateRound = (a, b) => {
|
53 | const interpolateNumber = (0, exports.createInterpolateNumber)(a, b);
|
54 | return (t) => Math.round(interpolateNumber(t));
|
55 | };
|
56 | exports.createInterpolateRound = createInterpolateRound;
|
57 |
|
\ | No newline at end of file |