(rgb: RGBA, theme: Theme, modifyHSL: HSLModifyFunction, poleColor?: string, anotherPoleColor?: string)
| 57 | } |
| 58 | |
| 59 | function modifyColorWithCache(rgb: RGBA, theme: Theme, modifyHSL: HSLModifyFunction, poleColor?: string, anotherPoleColor?: string): string { |
| 60 | let fnCache: Map<string, string>; |
| 61 | if (colorModificationCache.has(modifyHSL)) { |
| 62 | fnCache = colorModificationCache.get(modifyHSL)!; |
| 63 | } else { |
| 64 | fnCache = new Map(); |
| 65 | colorModificationCache.set(modifyHSL, fnCache); |
| 66 | } |
| 67 | const id = getCacheId(rgb, theme, poleColor, anotherPoleColor); |
| 68 | if (fnCache.has(id)) { |
| 69 | return fnCache.get(id)!; |
| 70 | } |
| 71 | |
| 72 | const hsl = rgbToHSL(rgb); |
| 73 | const pole = poleColor == null ? null : parseToHSLWithCache(poleColor); |
| 74 | const anotherPole = anotherPoleColor == null ? null : parseToHSLWithCache(anotherPoleColor); |
| 75 | const modified = modifyHSL(hsl, pole!, anotherPole!); |
| 76 | const {r, g, b, a} = hslToRGB(modified); |
| 77 | const matrix = createFilterMatrix({...theme, mode: 0}); |
| 78 | const [rf, gf, bf] = applyColorMatrix([r, g, b], matrix); |
| 79 | |
| 80 | const color = (a === 1 ? |
| 81 | rgbToHexString({r: rf, g: gf, b: bf}) : |
| 82 | rgbToString({r: rf, g: gf, b: bf, a})); |
| 83 | |
| 84 | fnCache.set(id, color); |
| 85 | return color; |
| 86 | } |
| 87 | |
| 88 | function noopHSL(hsl: HSLA): HSLA { |
| 89 | return hsl; |
no test coverage detected