@docusaurus/plugin-ideal-image 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +6 -0
- package/lib/theme/IdealImage/index.js +1 -2
- package/lib/theme/IdealImageLegacy/LICENSE +20 -0
- package/lib/theme/IdealImageLegacy/README.md +13 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Download.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Download.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Loading.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Loading.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Offline.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Offline.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Warning.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Warning.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/index.d.ts +8 -0
- package/lib/theme/IdealImageLegacy/components/Icon/index.js +25 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/index.d.ts +42 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/index.js +352 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/waypoint.d.ts +10 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/waypoint.js +188 -0
- package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.d.ts +33 -0
- package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +12 -0
- package/lib/theme/IdealImageLegacy/components/Media/index.d.ts +20 -0
- package/lib/theme/IdealImageLegacy/components/Media/index.js +169 -0
- package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
- package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.d.ts +33 -0
- package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +12 -0
- package/lib/theme/IdealImageLegacy/components/composeStyle.d.ts +5 -0
- package/lib/theme/IdealImageLegacy/components/composeStyle.js +37 -0
- package/lib/theme/IdealImageLegacy/components/constants.d.ts +22 -0
- package/lib/theme/IdealImageLegacy/components/constants.js +24 -0
- package/lib/theme/IdealImageLegacy/components/helpers.d.ts +22 -0
- package/lib/theme/IdealImageLegacy/components/helpers.js +142 -0
- package/lib/theme/IdealImageLegacy/components/icons.d.ts +15 -0
- package/lib/theme/IdealImageLegacy/components/icons.js +16 -0
- package/lib/theme/IdealImageLegacy/components/loaders.d.ts +4 -0
- package/lib/theme/IdealImageLegacy/components/loaders.js +112 -0
- package/lib/theme/IdealImageLegacy/components/theme.d.ts +30 -0
- package/lib/theme/IdealImageLegacy/components/theme.js +26 -0
- package/lib/theme/IdealImageLegacy/components/theme.module.css +35 -0
- package/lib/theme/IdealImageLegacy/components/unfetch.d.ts +7 -0
- package/lib/theme/IdealImageLegacy/components/unfetch.js +74 -0
- package/lib/theme/IdealImageLegacy/index.d.ts +2 -0
- package/lib/theme/IdealImageLegacy/index.js +2 -0
- package/package.json +8 -10
- package/src/index.ts +6 -0
- package/src/plugin-ideal-image.d.ts +121 -0
- package/src/theme/IdealImage/index.tsx +2 -3
- package/src/theme/IdealImageLegacy/LICENSE +20 -0
- package/src/theme/IdealImageLegacy/README.md +13 -0
- package/src/theme/IdealImageLegacy/components/Icon/Download.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/Loading.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/Offline.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/Warning.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/index.js +25 -0
- package/src/theme/IdealImageLegacy/components/IdealImage/index.js +352 -0
- package/src/theme/IdealImageLegacy/components/IdealImage/waypoint.tsx +254 -0
- package/src/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +12 -0
- package/src/theme/IdealImageLegacy/components/Media/index.js +169 -0
- package/src/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
- package/src/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +12 -0
- package/src/theme/IdealImageLegacy/components/composeStyle.js +37 -0
- package/src/theme/IdealImageLegacy/components/constants.js +24 -0
- package/src/theme/IdealImageLegacy/components/helpers.js +142 -0
- package/src/theme/IdealImageLegacy/components/icons.js +16 -0
- package/src/theme/IdealImageLegacy/components/loaders.js +112 -0
- package/src/theme/IdealImageLegacy/components/theme.js +26 -0
- package/src/theme/IdealImageLegacy/components/theme.module.css +35 -0
- package/src/theme/IdealImageLegacy/components/unfetch.js +74 -0
- package/src/theme/IdealImageLegacy/index.tsx +3 -0
- package/src/deps.d.ts +0 -124
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
export const ssr =
|
|
2
|
+
typeof window === 'undefined' || window.navigator.userAgent === 'ReactSnap';
|
|
3
|
+
|
|
4
|
+
export const nativeConnection = !ssr && !!window.navigator.connection;
|
|
5
|
+
|
|
6
|
+
// export const getScreenWidth = () => {
|
|
7
|
+
// if (ssr) return 0
|
|
8
|
+
// const devicePixelRatio = window.devicePixelRatio || 1
|
|
9
|
+
// const {screen} = window
|
|
10
|
+
// const {width} = screen
|
|
11
|
+
// // const angle = (screen.orientation && screen.orientation.angle) || 0
|
|
12
|
+
// // return Math.max(width, height)
|
|
13
|
+
// // const rotated = Math.floor(angle / 90) % 2 !== 0
|
|
14
|
+
// // return (rotated ? height : width) * devicePixelRatio
|
|
15
|
+
// return width * devicePixelRatio
|
|
16
|
+
// }
|
|
17
|
+
// export const screenWidth = getScreenWidth()
|
|
18
|
+
|
|
19
|
+
export const guessMaxImageWidth = (dimensions, w) => {
|
|
20
|
+
if (ssr) return 0;
|
|
21
|
+
|
|
22
|
+
// Default to window object but don't use window as a default
|
|
23
|
+
// parameter so that this can be used on the server as well
|
|
24
|
+
if (!w) {
|
|
25
|
+
w = window;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const imgWidth = dimensions.width;
|
|
29
|
+
|
|
30
|
+
const {screen} = w;
|
|
31
|
+
const sWidth = screen.width;
|
|
32
|
+
const sHeight = screen.height;
|
|
33
|
+
|
|
34
|
+
const {documentElement} = document;
|
|
35
|
+
const windowWidth = w.innerWidth || documentElement.clientWidth;
|
|
36
|
+
const windowHeight = w.innerHeight || documentElement.clientHeight;
|
|
37
|
+
const devicePixelRatio = w.devicePixelRatio || 1;
|
|
38
|
+
|
|
39
|
+
const windowResized = sWidth > windowWidth;
|
|
40
|
+
|
|
41
|
+
let result;
|
|
42
|
+
if (windowResized) {
|
|
43
|
+
const body = document.getElementsByTagName('body')[0];
|
|
44
|
+
const scrollWidth = windowWidth - imgWidth;
|
|
45
|
+
const isScroll =
|
|
46
|
+
body.clientHeight > windowHeight || body.clientHeight > sHeight;
|
|
47
|
+
if (isScroll && scrollWidth <= 15) {
|
|
48
|
+
result = sWidth - scrollWidth;
|
|
49
|
+
} else {
|
|
50
|
+
result = (imgWidth / windowWidth) * sWidth;
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
result = imgWidth;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return result * devicePixelRatio;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const bytesToSize = (bytes) => {
|
|
60
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
61
|
+
if (bytes === 0) return 'n/a';
|
|
62
|
+
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
|
|
63
|
+
if (i === 0) return `${bytes} ${sizes[i]}`;
|
|
64
|
+
return `${(bytes / 1024 ** i).toFixed(1)} ${sizes[i]}`;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// async function supportsWebp() {
|
|
68
|
+
// if (typeof createImageBitmap === 'undefined' || typeof fetch === 'undefined')
|
|
69
|
+
// return false
|
|
70
|
+
// return fetch(
|
|
71
|
+
// 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=',
|
|
72
|
+
// )
|
|
73
|
+
// .then(response => response.blob())
|
|
74
|
+
// .then(blob => createImageBitmap(blob).then(() => true, () => false))
|
|
75
|
+
// }
|
|
76
|
+
// let webp = undefined
|
|
77
|
+
// const webpPromise = supportsWebp()
|
|
78
|
+
// webpPromise.then(x => (webp = x))
|
|
79
|
+
// export default () => {
|
|
80
|
+
// if (webp === undefined) return webpPromise
|
|
81
|
+
// return {
|
|
82
|
+
// then: callback => callback(webp),
|
|
83
|
+
// }
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
const detectWebpSupport = () => {
|
|
87
|
+
if (ssr) return false;
|
|
88
|
+
const elem = document.createElement('canvas');
|
|
89
|
+
if (elem.getContext && elem.getContext('2d')) {
|
|
90
|
+
// was able or not to get WebP representation
|
|
91
|
+
return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
|
|
92
|
+
} else {
|
|
93
|
+
// very old browser like IE 8, canvas not supported
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const supportsWebp = detectWebpSupport();
|
|
99
|
+
|
|
100
|
+
const isWebp = (x) =>
|
|
101
|
+
x.format === 'webp' || (x.src && x.src.match(/\.webp($|\?.*)/i));
|
|
102
|
+
|
|
103
|
+
// eslint-disable-next-line no-shadow
|
|
104
|
+
export const selectSrc = ({srcSet, maxImageWidth, supportsWebp}) => {
|
|
105
|
+
if (srcSet.length === 0) throw new Error('Need at least one item in srcSet');
|
|
106
|
+
let supportedFormat, width;
|
|
107
|
+
if (supportsWebp) {
|
|
108
|
+
supportedFormat = srcSet.filter(isWebp);
|
|
109
|
+
if (supportedFormat.length === 0) supportedFormat = srcSet;
|
|
110
|
+
} else {
|
|
111
|
+
supportedFormat = srcSet.filter((x) => !isWebp(x));
|
|
112
|
+
if (supportedFormat.length === 0)
|
|
113
|
+
throw new Error('Need at least one supported format item in srcSet');
|
|
114
|
+
}
|
|
115
|
+
let widths = supportedFormat.filter((x) => x.width >= maxImageWidth);
|
|
116
|
+
if (widths.length === 0) {
|
|
117
|
+
widths = supportedFormat;
|
|
118
|
+
width = Math.max.apply(
|
|
119
|
+
null,
|
|
120
|
+
widths.map((x) => x.width),
|
|
121
|
+
);
|
|
122
|
+
} else {
|
|
123
|
+
width = Math.min.apply(
|
|
124
|
+
null,
|
|
125
|
+
widths.map((x) => x.width),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return supportedFormat.filter((x) => x.width === width)[0];
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const fallbackParams = ({srcSet, getUrl}) => {
|
|
132
|
+
if (!ssr) return {};
|
|
133
|
+
const notWebp = srcSet.filter((x) => !isWebp(x));
|
|
134
|
+
const first = notWebp[0];
|
|
135
|
+
return {
|
|
136
|
+
nsSrcSet: notWebp
|
|
137
|
+
.map((x) => `${getUrl ? getUrl(x) : x.src} ${x.width}w`)
|
|
138
|
+
.join(','),
|
|
139
|
+
nsSrc: getUrl ? getUrl(first) : first.src,
|
|
140
|
+
ssr,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import DownloadIcon from './Icon/Download';
|
|
2
|
+
import OfflineIcon from './Icon/Offline';
|
|
3
|
+
import WarningIcon from './Icon/Warning';
|
|
4
|
+
import LoadingIcon from './Icon/Loading';
|
|
5
|
+
import {icons} from './constants';
|
|
6
|
+
|
|
7
|
+
const {load, loading, loaded, error, noicon, offline} = icons;
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
[load]: DownloadIcon,
|
|
11
|
+
[loading]: LoadingIcon,
|
|
12
|
+
[loaded]: null,
|
|
13
|
+
[error]: WarningIcon,
|
|
14
|
+
[noicon]: null,
|
|
15
|
+
[offline]: OfflineIcon,
|
|
16
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// There is an issue with cancelable interface
|
|
2
|
+
// It is not obvious that
|
|
3
|
+
// `image(src)` has `cancel` function
|
|
4
|
+
// but `image(src).then()` doesn't
|
|
5
|
+
|
|
6
|
+
import {unfetch, UnfetchAbortController} from './unfetch';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* returns new "promise" with cancel function combined
|
|
10
|
+
*
|
|
11
|
+
* @param {Promise} p1 - first "promise" with cancel
|
|
12
|
+
* @param {Promise} p2 - second "promise" with cancel
|
|
13
|
+
* @returns {Promise} - new "promise" with cancel
|
|
14
|
+
*/
|
|
15
|
+
export const combineCancel = (p1, p2) => {
|
|
16
|
+
if (!p2) return p1;
|
|
17
|
+
const result = p1.then(
|
|
18
|
+
(x) => x,
|
|
19
|
+
(x) => x,
|
|
20
|
+
);
|
|
21
|
+
result.cancel = () => {
|
|
22
|
+
p1.cancel();
|
|
23
|
+
p2.cancel();
|
|
24
|
+
};
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const timeout = (threshold) => {
|
|
29
|
+
let timerId;
|
|
30
|
+
const result = new Promise((resolve) => {
|
|
31
|
+
timerId = setTimeout(resolve, threshold);
|
|
32
|
+
});
|
|
33
|
+
result.cancel = () => {
|
|
34
|
+
// there is a bug with cancel somewhere in the code
|
|
35
|
+
// if (!timerId) throw new Error('Already canceled')
|
|
36
|
+
clearTimeout(timerId);
|
|
37
|
+
timerId = undefined;
|
|
38
|
+
};
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Caveat: image loader can not cancel download in some browsers
|
|
43
|
+
export const imageLoader = (src) => {
|
|
44
|
+
let img = new Image();
|
|
45
|
+
const result = new Promise((resolve, reject) => {
|
|
46
|
+
img.onload = resolve;
|
|
47
|
+
// eslint-disable-next-line no-multi-assign
|
|
48
|
+
img.onabort = img.onerror = () => reject({});
|
|
49
|
+
img.src = src;
|
|
50
|
+
});
|
|
51
|
+
result.cancel = () => {
|
|
52
|
+
if (!img) throw new Error('Already canceled');
|
|
53
|
+
// eslint-disable-next-line no-multi-assign
|
|
54
|
+
img.onload = img.onabort = img.onerror = undefined;
|
|
55
|
+
img.src = '';
|
|
56
|
+
img = undefined;
|
|
57
|
+
};
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Caveat: XHR loader can cause errors because of 'Access-Control-Allow-Origin'
|
|
62
|
+
// Caveat: we still need imageLoader to do actual decoding,
|
|
63
|
+
// but if images are uncachable this will lead to two requests
|
|
64
|
+
export const xhrLoader = (url, options) => {
|
|
65
|
+
let controller = new UnfetchAbortController();
|
|
66
|
+
const signal = controller.signal;
|
|
67
|
+
const result = new Promise((resolve, reject) =>
|
|
68
|
+
unfetch(url, {...options, signal}).then((response) => {
|
|
69
|
+
if (response.ok) {
|
|
70
|
+
response
|
|
71
|
+
.blob()
|
|
72
|
+
.then(() => imageLoader(url))
|
|
73
|
+
.then(resolve);
|
|
74
|
+
} else {
|
|
75
|
+
reject({status: response.status});
|
|
76
|
+
}
|
|
77
|
+
}, reject),
|
|
78
|
+
);
|
|
79
|
+
result.cancel = () => {
|
|
80
|
+
if (!controller) throw new Error('Already canceled');
|
|
81
|
+
controller.abort();
|
|
82
|
+
controller = undefined;
|
|
83
|
+
};
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Caveat: AbortController only supported in Chrome 66+
|
|
88
|
+
// Caveat: we still need imageLoader to do actual decoding,
|
|
89
|
+
// but if images are uncachable this will lead to two requests
|
|
90
|
+
// export const fetchLoader = (url, options) => {
|
|
91
|
+
// let controller = new AbortController()
|
|
92
|
+
// const signal = controller.signal
|
|
93
|
+
// const result = new Promise((resolve, reject) =>
|
|
94
|
+
// fetch(url, {...options, signal}).then(response => {
|
|
95
|
+
// if (response.ok) {
|
|
96
|
+
// options && options.onMeta && options.onMeta(response.headers)
|
|
97
|
+
// response
|
|
98
|
+
// .blob()
|
|
99
|
+
// .then(() => imageLoader(url))
|
|
100
|
+
// .then(resolve)
|
|
101
|
+
// } else {
|
|
102
|
+
// reject({status: response.status})
|
|
103
|
+
// }
|
|
104
|
+
// }, reject),
|
|
105
|
+
// )
|
|
106
|
+
// result.cancel = () => {
|
|
107
|
+
// if (!controller) throw new Error('Already canceled')
|
|
108
|
+
// controller.abort()
|
|
109
|
+
// controller = undefined
|
|
110
|
+
// }
|
|
111
|
+
// return result
|
|
112
|
+
// }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
placeholder: {
|
|
3
|
+
backgroundSize: 'cover',
|
|
4
|
+
backgroundRepeat: 'no-repeat',
|
|
5
|
+
position: 'relative',
|
|
6
|
+
},
|
|
7
|
+
img: {
|
|
8
|
+
width: '100%',
|
|
9
|
+
height: 'auto',
|
|
10
|
+
maxWidth: '100%',
|
|
11
|
+
/* TODO: fix bug in styles */
|
|
12
|
+
marginBottom: '-4px',
|
|
13
|
+
},
|
|
14
|
+
icon: {
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
top: '50%',
|
|
17
|
+
left: '50%',
|
|
18
|
+
transform: 'translate(-50%, -50%)',
|
|
19
|
+
textAlign: 'center',
|
|
20
|
+
},
|
|
21
|
+
noscript: {
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
top: 0,
|
|
24
|
+
left: 0,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.placeholder {
|
|
9
|
+
background-size: cover;
|
|
10
|
+
background-repeat: no-repeat;
|
|
11
|
+
position: relative;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.img {
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: auto;
|
|
17
|
+
max-width: 100%;
|
|
18
|
+
/* TODO: fix bug in styles */
|
|
19
|
+
margin-bottom: -4px;
|
|
20
|
+
transform: translate3d(0, 0, 0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.icon {
|
|
24
|
+
position: absolute;
|
|
25
|
+
top: 50%;
|
|
26
|
+
left: 50%;
|
|
27
|
+
transform: translate(-50%, -50%);
|
|
28
|
+
text-align: center;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.noscript {
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: 0;
|
|
34
|
+
left: 0;
|
|
35
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export class UnfetchAbortController {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.signal = {onabort: () => {}};
|
|
4
|
+
this.abort = () => this.signal.onabort();
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// modified version of https://github.com/developit/unfetch
|
|
9
|
+
// - ponyfill intead of polyfill
|
|
10
|
+
// - add support for AbortController
|
|
11
|
+
export const unfetch = (url, options) => {
|
|
12
|
+
options = options || {};
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const request = new XMLHttpRequest();
|
|
15
|
+
|
|
16
|
+
request.open(options.method || 'get', url, true);
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line guard-for-in
|
|
19
|
+
for (const i in options.headers) {
|
|
20
|
+
request.setRequestHeader(i, options.headers[i]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
request.withCredentials = options.credentials === 'include';
|
|
24
|
+
|
|
25
|
+
request.onload = () => {
|
|
26
|
+
resolve(response());
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
request.onerror = reject;
|
|
30
|
+
|
|
31
|
+
if (options.signal)
|
|
32
|
+
options.signal.onabort = () => {
|
|
33
|
+
// eslint-disable-next-line no-multi-assign
|
|
34
|
+
request.onerror = request.onload = undefined;
|
|
35
|
+
request.abort();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
request.send(options.body);
|
|
39
|
+
|
|
40
|
+
function response() {
|
|
41
|
+
const keys = [];
|
|
42
|
+
const all = [];
|
|
43
|
+
const headers = {};
|
|
44
|
+
let header;
|
|
45
|
+
|
|
46
|
+
request
|
|
47
|
+
.getAllResponseHeaders()
|
|
48
|
+
.replace(/^(.*?):\s*?([\s\S]*?)$/gm, (m, key, value) => {
|
|
49
|
+
keys.push((key = key.toLowerCase()));
|
|
50
|
+
all.push([key, value]);
|
|
51
|
+
header = headers[key];
|
|
52
|
+
headers[key] = header ? `${header},${value}` : value;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
// eslint-disable-next-line no-bitwise
|
|
57
|
+
ok: ((request.status / 100) | 0) === 2, // 200-299
|
|
58
|
+
status: request.status,
|
|
59
|
+
statusText: request.statusText,
|
|
60
|
+
url: request.responseURL,
|
|
61
|
+
clone: response,
|
|
62
|
+
text: () => Promise.resolve(request.responseText),
|
|
63
|
+
json: () => Promise.resolve(request.responseText).then(JSON.parse),
|
|
64
|
+
blob: () => Promise.resolve(new Blob([request.response])),
|
|
65
|
+
headers: {
|
|
66
|
+
keys: () => keys,
|
|
67
|
+
entries: () => all,
|
|
68
|
+
get: (n) => headers[n.toLowerCase()],
|
|
69
|
+
has: (n) => n.toLowerCase() in headers,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
package/src/deps.d.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/// <reference types="@docusaurus/module-type-aliases" />
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @see https://github.com/endiliey/react-ideal-image/blob/master/index.d.ts
|
|
12
|
-
* Note: the original type definition is WRONG. getIcon & getMessage receive
|
|
13
|
-
* full state object.
|
|
14
|
-
*/
|
|
15
|
-
declare module '@slorber/react-ideal-image' {
|
|
16
|
-
import type {
|
|
17
|
-
ComponentProps,
|
|
18
|
-
ComponentType,
|
|
19
|
-
CSSProperties,
|
|
20
|
-
ReactNode,
|
|
21
|
-
} from 'react';
|
|
22
|
-
|
|
23
|
-
export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error';
|
|
24
|
-
|
|
25
|
-
export type State = {
|
|
26
|
-
pickedSrc: {
|
|
27
|
-
size: number;
|
|
28
|
-
};
|
|
29
|
-
loadInfo: 404 | null;
|
|
30
|
-
loadState: LoadingState;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type IconKey =
|
|
34
|
-
| 'load'
|
|
35
|
-
| 'loading'
|
|
36
|
-
| 'loaded'
|
|
37
|
-
| 'error'
|
|
38
|
-
| 'noicon'
|
|
39
|
-
| 'offline';
|
|
40
|
-
|
|
41
|
-
export type SrcType = {
|
|
42
|
-
width: number;
|
|
43
|
-
src?: string;
|
|
44
|
-
size?: number;
|
|
45
|
-
format?: 'webp' | 'jpeg' | 'png' | 'gif';
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript';
|
|
49
|
-
|
|
50
|
-
export interface ImageProps
|
|
51
|
-
extends Omit<ComponentProps<'img'>, 'srcSet' | 'placeholder'> {
|
|
52
|
-
/**
|
|
53
|
-
* This function decides what icon to show based on the current state of the
|
|
54
|
-
* component.
|
|
55
|
-
*/
|
|
56
|
-
getIcon?: (state: State) => IconKey;
|
|
57
|
-
/**
|
|
58
|
-
* This function decides what message to show based on the icon (returned
|
|
59
|
-
* from `getIcon` prop) and the current state of the component.
|
|
60
|
-
*/
|
|
61
|
-
getMessage?: (icon: IconKey, state: State) => string | null;
|
|
62
|
-
/**
|
|
63
|
-
* This function is called as soon as the component enters the viewport and
|
|
64
|
-
* is used to generate urls based on width and format if `props.srcSet`
|
|
65
|
-
* doesn't provide `src` field.
|
|
66
|
-
*/
|
|
67
|
-
getUrl?: (srcType: SrcType) => string;
|
|
68
|
-
/**
|
|
69
|
-
* The Height of the image in px.
|
|
70
|
-
*/
|
|
71
|
-
height: number;
|
|
72
|
-
/**
|
|
73
|
-
* This provides a map of the icons. By default, the component uses icons
|
|
74
|
-
* from material design, Implemented as React components with the SVG
|
|
75
|
-
* element. You can customize icons
|
|
76
|
-
*/
|
|
77
|
-
icons?: Partial<{[icon in IconKey]: ComponentType}>;
|
|
78
|
-
/**
|
|
79
|
-
* This prop takes one of the 2 options, xhr and image.
|
|
80
|
-
* Read more about it:
|
|
81
|
-
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#cancel-download
|
|
82
|
-
*/
|
|
83
|
-
loader?: 'xhr' | 'image';
|
|
84
|
-
/**
|
|
85
|
-
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#lqip
|
|
86
|
-
*/
|
|
87
|
-
placeholder: {color: string} | {lqip: string};
|
|
88
|
-
/**
|
|
89
|
-
* This function decides if image should be downloaded automatically. The
|
|
90
|
-
* default function returns false for a 2g network, for a 3g network it
|
|
91
|
-
* decides based on `props.threshold` and for a 4g network it returns true
|
|
92
|
-
* by default.
|
|
93
|
-
*/
|
|
94
|
-
shouldAutoDownload?: (options: {
|
|
95
|
-
connection?: 'slow-2g' | '2g' | '3g' | '4g';
|
|
96
|
-
size?: number;
|
|
97
|
-
threshold?: number;
|
|
98
|
-
possiblySlowNetwork?: boolean;
|
|
99
|
-
}) => boolean;
|
|
100
|
-
/**
|
|
101
|
-
* This provides an array of sources of different format and size of the
|
|
102
|
-
* image. Read more about it:
|
|
103
|
-
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#srcset
|
|
104
|
-
*/
|
|
105
|
-
srcSet: SrcType[];
|
|
106
|
-
/**
|
|
107
|
-
* This provides a theme to the component. By default, the component uses
|
|
108
|
-
* inline styles, but it is also possible to use CSS modules and override
|
|
109
|
-
* all styles.
|
|
110
|
-
*/
|
|
111
|
-
theme?: Partial<{[key in ThemeKey]: string | CSSProperties}>;
|
|
112
|
-
/**
|
|
113
|
-
* Tells how much to wait in milliseconds until consider the download to be
|
|
114
|
-
* slow.
|
|
115
|
-
*/
|
|
116
|
-
threshold?: number;
|
|
117
|
-
/**
|
|
118
|
-
* Width of the image in px.
|
|
119
|
-
*/
|
|
120
|
-
width: number;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export default function IdealImage(props: ImageProps): ReactNode;
|
|
124
|
-
}
|