diff options
| author | Jenny Yu <jennyyu212@outlook.com> | 2022-04-28 16:17:25 -0400 |
|---|---|---|
| committer | Jenny Yu <jennyyu212@outlook.com> | 2022-04-28 16:17:25 -0400 |
| commit | 83c615b1b9706818894ee74481afd4c2bf34fe61 (patch) | |
| tree | 6e6a242fdbe1d5c164fce9d0c1ae84b4423ed40c /src/Utils.ts | |
| parent | 9f62b6d1c9848439671065dac9ed79bc393c83fa (diff) | |
| parent | 15bc17cbbe3816ab78ce653105ddff06bce18c59 (diff) | |
Merge branch 'master' into recording-jenny
Diffstat (limited to 'src/Utils.ts')
| -rw-r--r-- | src/Utils.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index 77095005b..205f9379e 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -204,11 +204,11 @@ export namespace Utils { return { h: h, s: s, l: l }; } - export function scrollIntoView(targetY: number, targetHgt: number, scrollTop: number, contextHgt: number, minSpacing: number) { - if (scrollTop + contextHgt < targetY + minSpacing + targetHgt) { + export function scrollIntoView(targetY: number, targetHgt: number, scrollTop: number, contextHgt: number, minSpacing: number, scrollHeight: number) { + if (scrollTop + contextHgt < Math.min(scrollHeight, targetY + minSpacing + targetHgt)) { return Math.ceil(targetY + minSpacing + targetHgt - contextHgt); } - if (scrollTop > targetY - minSpacing - targetHgt) { + if (scrollTop > Math.max(0, targetY - minSpacing - targetHgt)) { return Math.max(0, Math.floor(targetY - minSpacing - targetHgt)); } } @@ -399,6 +399,12 @@ export function timenow() { return now.toLocaleDateString() + ' ' + h + ':' + m + ' ' + ampm; } +export function incrementTitleCopy(title: string) { + const numstr = title.match(/.*(\{([0-9]*)\})+/); + const copyNumStr = `{${1 + (numstr ? (+numstr[2]) : 0)}}`; + return (numstr ? title.replace(numstr[1], "") : title) + copyNumStr; +} + export function formatTime(time: number) { time = Math.round(time); const hours = Math.floor(time / 60 / 60); @@ -604,6 +610,7 @@ export function DashColor(color: string) { export function lightOrDark(color: any) { if (color === "transparent") return "gray"; + if (color.startsWith?.("linear")) return "black"; const nonAlphaColor = color.startsWith("#") ? (color as string).substring(0, 7) : color.startsWith("rgba") ? color.replace(/,.[^,]*\)/, ")").replace("rgba", "rgb") : color; const col = DashColor(nonAlphaColor).rgb(); |
