aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index b280badd7..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);
@@ -603,6 +609,8 @@ 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();