diff options
author | bobzel <zzzman@gmail.com> | 2024-10-10 20:06:17 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-10-10 20:06:17 -0400 |
commit | 962302d41ba5b086818f5db9ea5103c1e754b66f (patch) | |
tree | fe7b36ce2ac3c8276e4175e4dd8d5e223e1373a7 /src/ClientUtils.ts | |
parent | 3a35e2687e3c7b0c864dd4f00b1002ff088b56d3 (diff) | |
parent | 040a1c5fd3e80606793e65be3ae821104460511b (diff) |
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/ClientUtils.ts')
-rw-r--r-- | src/ClientUtils.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ClientUtils.ts b/src/ClientUtils.ts index e8165d5ab..e7aee1c2a 100644 --- a/src/ClientUtils.ts +++ b/src/ClientUtils.ts @@ -316,6 +316,26 @@ export namespace ClientUtils { return { h: h, s: s, l: l }; } + export function lightenRGB(rVal: number, gVal: number, bVal: number, percent: number): [number, number, number] { + const amount = 1 + percent / 100; + const r = rVal * amount; + const g = gVal * amount; + const b = bVal * amount; + + const threshold = 255.999; + const maxVal = Math.max(r, g, b); + if (maxVal <= threshold) { + return [Math.round(r), Math.round(g), Math.round(b)]; + } + const total = r + g + b; + if (total >= 3 * threshold) { + return [Math.round(threshold), Math.round(threshold), Math.round(threshold)]; + } + const x = (3 * threshold - total) / (3 * maxVal - total); + const gray = threshold - x * maxVal; + return [Math.round(gray + x * r), Math.round(gray + x * g), Math.round(gray + x * b)]; + } + export function scrollIntoView(targetY: number, targetHgt: number, scrollTop: number, contextHgt: number, minSpacing: number, scrollHeight: number) { if (!targetHgt) return targetY; // if there's no height, then assume that if (scrollTop + contextHgt < Math.min(scrollHeight, targetY + minSpacing + targetHgt)) { |