-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
29 lines (25 loc) · 787 Bytes
/
index.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
import { blurhash_to_css, blurhashes_to_css } from './pkg/blurhash_to_css';
export interface BlurhashCss {
backgroundImage: string;
backgroundPosition: string;
backgroundSize: string;
backgroundRepeat: string;
filter: string;
transform: string;
}
export interface Options {
width: number;
height: number;
}
export type BlurhashToCss = {
(blurhash: string, options?: Options): BlurhashCss;
(blurhashes: string[], options?: Options): BlurhashCss[];
};
export const blurhashToCss: BlurhashToCss = (blurhash, options) => {
const height = options?.height || 10;
const width = options?.width || 10;
const json = Array.isArray(blurhash)
? blurhashes_to_css(blurhash, width, height)
: blurhash_to_css(blurhash, width, height);
return JSON.parse(json);
};