-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayout-helper.ts
37 lines (32 loc) · 1.08 KB
/
layout-helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { CSSProperties } from 'vue';
export function resolveAssetUrl(url: string) {
if(url.startsWith('/')) {
const baseUrl = import.meta.env.BASE_URL;
if(baseUrl.endsWith('/')) return baseUrl + url.slice(1);
else return baseUrl + url;
} else if(url.startsWith('http')) {
return url;
} else {
const baseUrl = import.meta.env.BASE_URL;
if(baseUrl.endsWith('/')) return baseUrl + url;
else return `${baseUrl}/${url}`;
}
}
export function handleBackground(background?: string, dim = false): CSSProperties {
const isColor = background && ['#', 'rgb', 'hsl'].some((v) => background.indexOf(v) === 0);
const style = {
background: isColor ? background : undefined,
backgroundImage: isColor
? undefined
: background
? dim
? `linear-gradient(#0009, #0009), url(${resolveAssetUrl(background)})`
: `url("${resolveAssetUrl(background)}")`
: undefined,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'cover',
};
if (!style.background) delete style.background;
return style;
}