aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Utility/html.ts
blob: 3371a7d3ef8da6cc5a711e2d3f6d2dedbbc1ad14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import settings from '$stores/settings';
import { get } from 'svelte/store';

export const nbsp = (str: string) => str.replace(/ /g, ' ');

export const limitListHeight = () => {
	if (get(settings).displayLimitListHeight) {
		document.querySelectorAll('.list').forEach((list) => {
			const listContainerBottom =
				document.querySelector('#list-container')?.getBoundingClientRect().bottom || 0;
			const headerBottom =
				(document.querySelector('#header')?.getBoundingClientRect().bottom || 0) * 1.5;
			const offset = 1.25;
			const offsetInPixels =
				offset * parseFloat(getComputedStyle(document.documentElement).fontSize);

			(
				list as HTMLElement
			).style.maxHeight = `calc(100vh - ${listContainerBottom}px + ${headerBottom}px - ${
				offsetInPixels * 2
			}px)`;
		});
	}
};