forked from react-component/image
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
35 lines (30 loc) · 881 Bytes
/
util.ts
File metadata and controls
35 lines (30 loc) · 881 Bytes
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
import * as React from 'react';
import type { FetchPriority } from './interface';
export function isImageValid(src: string) {
return new Promise(resolve => {
if (!src) {
resolve(false);
return;
}
const img = document.createElement('img');
img.onerror = () => resolve(false);
img.onload = () => resolve(true);
img.src = src;
});
}
export function getFetchPriorityProps(value?: FetchPriority) {
if (!value) {
return {};
}
const major = Number(React.version.split('.')[0]);
return major >= 19 ? { fetchPriority: value } : { fetchpriority: value };
}
// ============================= Legacy =============================
export function getClientSize() {
const width = document.documentElement.clientWidth;
const height = window.innerHeight || document.documentElement.clientHeight;
return {
width,
height,
};
}