@docusaurus/plugin-ideal-image 3.7.0-canary-6263 → 3.7.0-canary-6264

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.
Files changed (64) hide show
  1. package/lib/theme/IdealImage/index.js +1 -2
  2. package/lib/theme/IdealImageLegacy/LICENSE +20 -0
  3. package/lib/theme/IdealImageLegacy/README.md +13 -0
  4. package/lib/theme/IdealImageLegacy/components/Icon/Download.d.ts +3 -0
  5. package/lib/theme/IdealImageLegacy/components/Icon/Download.js +15 -0
  6. package/lib/theme/IdealImageLegacy/components/Icon/Loading.d.ts +3 -0
  7. package/lib/theme/IdealImageLegacy/components/Icon/Loading.js +15 -0
  8. package/lib/theme/IdealImageLegacy/components/Icon/Offline.d.ts +3 -0
  9. package/lib/theme/IdealImageLegacy/components/Icon/Offline.js +15 -0
  10. package/lib/theme/IdealImageLegacy/components/Icon/Warning.d.ts +3 -0
  11. package/lib/theme/IdealImageLegacy/components/Icon/Warning.js +15 -0
  12. package/lib/theme/IdealImageLegacy/components/Icon/index.d.ts +8 -0
  13. package/lib/theme/IdealImageLegacy/components/Icon/index.js +25 -0
  14. package/lib/theme/IdealImageLegacy/components/IdealImage/index.d.ts +42 -0
  15. package/lib/theme/IdealImageLegacy/components/IdealImage/index.js +353 -0
  16. package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.d.ts +33 -0
  17. package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +12 -0
  18. package/lib/theme/IdealImageLegacy/components/Media/index.d.ts +20 -0
  19. package/lib/theme/IdealImageLegacy/components/Media/index.js +169 -0
  20. package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
  21. package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.d.ts +33 -0
  22. package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +12 -0
  23. package/lib/theme/IdealImageLegacy/components/composeStyle.d.ts +5 -0
  24. package/lib/theme/IdealImageLegacy/components/composeStyle.js +37 -0
  25. package/lib/theme/IdealImageLegacy/components/constants.d.ts +22 -0
  26. package/lib/theme/IdealImageLegacy/components/constants.js +24 -0
  27. package/lib/theme/IdealImageLegacy/components/helpers.d.ts +22 -0
  28. package/lib/theme/IdealImageLegacy/components/helpers.js +142 -0
  29. package/lib/theme/IdealImageLegacy/components/icons.d.ts +15 -0
  30. package/lib/theme/IdealImageLegacy/components/icons.js +16 -0
  31. package/lib/theme/IdealImageLegacy/components/loaders.d.ts +4 -0
  32. package/lib/theme/IdealImageLegacy/components/loaders.js +112 -0
  33. package/lib/theme/IdealImageLegacy/components/theme.d.ts +30 -0
  34. package/lib/theme/IdealImageLegacy/components/theme.js +26 -0
  35. package/lib/theme/IdealImageLegacy/components/theme.module.css +35 -0
  36. package/lib/theme/IdealImageLegacy/components/unfetch.d.ts +7 -0
  37. package/lib/theme/IdealImageLegacy/components/unfetch.js +74 -0
  38. package/lib/theme/IdealImageLegacy/index.d.ts +2 -0
  39. package/lib/theme/IdealImageLegacy/index.js +2 -0
  40. package/package.json +8 -9
  41. package/src/plugin-ideal-image.d.ts +121 -0
  42. package/src/theme/IdealImage/index.tsx +2 -3
  43. package/src/theme/IdealImageLegacy/LICENSE +20 -0
  44. package/src/theme/IdealImageLegacy/README.md +13 -0
  45. package/src/theme/IdealImageLegacy/components/Icon/Download.js +15 -0
  46. package/src/theme/IdealImageLegacy/components/Icon/Loading.js +15 -0
  47. package/src/theme/IdealImageLegacy/components/Icon/Offline.js +15 -0
  48. package/src/theme/IdealImageLegacy/components/Icon/Warning.js +15 -0
  49. package/src/theme/IdealImageLegacy/components/Icon/index.js +25 -0
  50. package/src/theme/IdealImageLegacy/components/IdealImage/index.js +353 -0
  51. package/src/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +12 -0
  52. package/src/theme/IdealImageLegacy/components/Media/index.js +169 -0
  53. package/src/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
  54. package/src/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +12 -0
  55. package/src/theme/IdealImageLegacy/components/composeStyle.js +37 -0
  56. package/src/theme/IdealImageLegacy/components/constants.js +24 -0
  57. package/src/theme/IdealImageLegacy/components/helpers.js +142 -0
  58. package/src/theme/IdealImageLegacy/components/icons.js +16 -0
  59. package/src/theme/IdealImageLegacy/components/loaders.js +112 -0
  60. package/src/theme/IdealImageLegacy/components/theme.js +26 -0
  61. package/src/theme/IdealImageLegacy/components/theme.module.css +35 -0
  62. package/src/theme/IdealImageLegacy/components/unfetch.js +74 -0
  63. package/src/theme/IdealImageLegacy/index.tsx +3 -0
  64. package/src/deps.d.ts +0 -124
@@ -0,0 +1,169 @@
1
+ import React, {PureComponent} from 'react';
2
+ // import PropTypes from 'prop-types'
3
+ import compose from '../composeStyle';
4
+ import {icons as defaultIcons} from '../constants';
5
+
6
+ const {load, loading, loaded, error, noicon, offline} = defaultIcons;
7
+
8
+ export default class Media extends PureComponent {
9
+ /*static propTypes = {
10
+ /!** URL of the image *!/
11
+ src: PropTypes.string.isRequired,
12
+ /!** Width of the image in px *!/
13
+ width: PropTypes.number.isRequired,
14
+ /!** Height of the image in px *!/
15
+ height: PropTypes.number.isRequired,
16
+ placeholder: PropTypes.oneOfType([
17
+ PropTypes.shape({
18
+ /!** Solid color placeholder *!/
19
+ color: PropTypes.string.isRequired,
20
+ }),
21
+ PropTypes.shape({
22
+ /!**
23
+ * [Low Quality Image Placeholder](https://github.com/zouhir/lqip)
24
+ * [SVG-Based Image Placeholder](https://github.com/technopagan/sqip)
25
+ * base64 encoded image of low quality
26
+ *!/
27
+ lqip: PropTypes.string.isRequired,
28
+ }),
29
+ ]).isRequired,
30
+ /!** display icon *!/
31
+ icon: PropTypes.oneOf([load, loading, loaded, error, noicon, offline])
32
+ .isRequired,
33
+ /!** Map of icons *!/
34
+ icons: PropTypes.object.isRequired,
35
+ /!** theme object - CSS Modules or React styles *!/
36
+ theme: PropTypes.object.isRequired,
37
+ /!** Alternative text *!/
38
+ alt: PropTypes.string,
39
+ /!** Color of the icon *!/
40
+ iconColor: PropTypes.string,
41
+ /!** Size of the icon in px *!/
42
+ iconSize: PropTypes.number,
43
+ /!** React's style attribute for root element of the component *!/
44
+ style: PropTypes.object,
45
+ /!** React's className attribute for root element of the component *!/
46
+ className: PropTypes.string,
47
+ /!** On click handler *!/
48
+ onClick: PropTypes.func,
49
+ /!** callback to get dimensions of the placeholder *!/
50
+ onDimensions: PropTypes.func,
51
+ /!** message to show below the icon *!/
52
+ message: PropTypes.node,
53
+ /!** reference for Waypoint *!/
54
+ innerRef: PropTypes.func,
55
+ /!** noscript image src *!/
56
+ nsSrc: PropTypes.string,
57
+ /!** noscript image srcSet *!/
58
+ nsSrcSet: PropTypes.string,
59
+ }*/
60
+
61
+ static defaultProps = {
62
+ iconColor: '#fff',
63
+ iconSize: 64,
64
+ };
65
+
66
+ constructor(props) {
67
+ super(props);
68
+ this.state = {isMounted: false};
69
+ }
70
+
71
+ componentDidMount() {
72
+ this.setState({isMounted: true});
73
+
74
+ if (this.props.onDimensions && this.dimensionElement)
75
+ /* Firefox returns 0 for both clientWidth and clientHeight.
76
+ To fix this we can check the parentNode's clientWidth and clientHeight as a fallback. */
77
+ this.props.onDimensions({
78
+ width:
79
+ this.dimensionElement.clientWidth ||
80
+ this.dimensionElement.parentNode.clientWidth,
81
+ height:
82
+ this.dimensionElement.clientHeight ||
83
+ this.dimensionElement.parentNode.clientHeight,
84
+ });
85
+ }
86
+
87
+ renderIcon(props) {
88
+ const {icon, icons, iconColor: fill, iconSize: size, theme} = props;
89
+ const iconToRender = icons[icon];
90
+ if (!iconToRender) return null;
91
+ const styleOrClass = compose(
92
+ {width: size + 100, height: size, color: fill},
93
+ theme.icon,
94
+ );
95
+ return React.createElement('div', styleOrClass, [
96
+ React.createElement(iconToRender, {fill, size, key: 'icon'}),
97
+ React.createElement('br', {key: 'br'}),
98
+ this.props.message,
99
+ ]);
100
+ }
101
+
102
+ renderImage(props) {
103
+ return props.icon === loaded ? (
104
+ <img
105
+ {...compose(props.theme.img)}
106
+ src={props.src}
107
+ alt={props.alt}
108
+ width={props.width}
109
+ height={props.height}
110
+ />
111
+ ) : (
112
+ <svg
113
+ {...compose(props.theme.img)}
114
+ width={props.width}
115
+ height={props.height}
116
+ ref={(ref) => (this.dimensionElement = ref)}
117
+ />
118
+ );
119
+ }
120
+
121
+ renderNoscript(props) {
122
+ // render noscript in ssr + hydration to avoid hydration mismatch error
123
+ return this.state.isMounted ? null : (
124
+ <noscript>
125
+ <img
126
+ {...compose(props.theme.img, props.theme.noscript)}
127
+ src={props.nsSrc}
128
+ srcSet={props.nsSrcSet}
129
+ alt={props.alt}
130
+ width={props.width}
131
+ height={props.height}
132
+ />
133
+ </noscript>
134
+ );
135
+ }
136
+
137
+ render() {
138
+ const props = this.props;
139
+ const {placeholder, theme} = props;
140
+ let background;
141
+ if (props.icon === loaded) {
142
+ background = {};
143
+ } else if (placeholder.lqip) {
144
+ background = {
145
+ backgroundImage: `url("${placeholder.lqip}")`,
146
+ };
147
+ } else {
148
+ background = {
149
+ backgroundColor: placeholder.color,
150
+ };
151
+ }
152
+ return (
153
+ <div
154
+ {...compose(
155
+ theme.placeholder,
156
+ background,
157
+ props.style,
158
+ props.className,
159
+ )}
160
+ onClick={this.props.onClick}
161
+ onKeyPress={this.props.onClick}
162
+ ref={this.props.innerRef}>
163
+ {this.renderImage(props)}
164
+ {this.renderNoscript(props)}
165
+ {this.renderIcon(props)}
166
+ </div>
167
+ );
168
+ }
169
+ }
@@ -0,0 +1,89 @@
1
+ All possible states of the component
2
+
3
+ ```js
4
+ const lqip =
5
+ 'data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAA4DASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAUG/8QAIRAAAQQDAAEFAAAAAAAAAAAAAQIDBREABAYhEjEyQVH/xAAUAQEAAAAAAAAAAAAAAAAAAAAE/8QAGBEBAAMBAAAAAAAAAAAAAAAAAQACIRH/2gAMAwEAAhEDEQA/AMJ2DG+7Dw0nz8gsx+uyhlxnWdLakOlfzpIF3aRf1WT5t96P5+N1ug9Tu7ZWS8q1gG6B8H2FDz+YxhjUrEOdZ//Z';
6
+
7
+ const sqip =
8
+ "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4774 3024'%3e%3cfilter id='b'%3e%3cfeGaussianBlur stdDeviation='12' /%3e%3c/filter%3e%3cpath fill='%23515a57' d='M0 0h4774v3021H0z'/%3e%3cg filter='url(%23b)' transform='translate(9.3 9.3) scale(18.64844)' fill-opacity='.5'%3e%3cellipse fill='whitefef' rx='1' ry='1' transform='matrix(74.55002 60.89891 -21.7939 26.67923 151.8 104.4)'/%3e%3cellipse fill='black80c' cx='216' cy='49' rx='59' ry='59'/%3e%3cellipse fill='black60e' cx='22' cy='60' rx='46' ry='89'/%3e%3cellipse fill='%23ffebd5' cx='110' cy='66' rx='42' ry='28'/%3e%3cellipse fill='whiteff9' rx='1' ry='1' transform='rotate(33.3 -113.2 392.6) scale(42.337 17.49703)'/%3e%3cellipse fill='%23031f1e' rx='1' ry='1' transform='matrix(163.4651 -64.93326 6.77862 17.06471 111 16.4)'/%3e%3cpath fill='whitefea' d='M66 74l9 39 16-44z'/%3e%3cellipse fill='%23a28364' rx='1' ry='1' transform='rotate(-32.4 253.2 -179) scale(30.79511 43.65381)'/%3e%3cpath fill='%231a232c' d='M40 139l61-57 33 95z'/%3e%3cpath fill='%230a222b' d='M249.8 153.3l-48.1-48 32.5-32.6 48.1 48z'/%3e%3c/g%3e%3c/svg%3e";
9
+ <table>
10
+ <tbody>
11
+ <tr>
12
+ <th align="left" width="100">
13
+ load
14
+ </th>
15
+ <td>
16
+ <MediaWithDefaults
17
+ width={3500}
18
+ height={2095}
19
+ placeholder={{lqip: lqip}}
20
+ src="andre-spieker-238-unsplash.jpg"
21
+ style={{maxWidth: 200}}
22
+ icon={'load'}
23
+ />
24
+ </td>
25
+ <th align="left" width="100">
26
+ noicon
27
+ </th>
28
+ <td>
29
+ <MediaWithDefaults
30
+ width={3500}
31
+ height={2095}
32
+ placeholder={{lqip: lqip}}
33
+ src="andre-spieker-238-unsplash.jpg"
34
+ style={{maxWidth: 200}}
35
+ icon={'noicon'}
36
+ />
37
+ </td>
38
+ </tr>
39
+ <tr>
40
+ <th align="left">loading</th>
41
+ <td>
42
+ <MediaWithDefaults
43
+ width={3500}
44
+ height={2095}
45
+ placeholder={{lqip: lqip}}
46
+ src="andre-spieker-238-unsplash.jpg"
47
+ style={{maxWidth: 200}}
48
+ icon={'loading'}
49
+ />
50
+ </td>
51
+ <th align="left">offline</th>
52
+ <td>
53
+ <MediaWithDefaults
54
+ width={3500}
55
+ height={2095}
56
+ placeholder={{lqip: lqip}}
57
+ src="andre-spieker-238-unsplash.jpg"
58
+ style={{maxWidth: 200}}
59
+ icon={'offline'}
60
+ />
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <th align="left">loaded</th>
65
+ <td>
66
+ <MediaWithDefaults
67
+ width={3500}
68
+ height={2095}
69
+ placeholder={{lqip: lqip}}
70
+ src="andre-spieker-238-unsplash.jpg"
71
+ style={{maxWidth: 200}}
72
+ icon={'loaded'}
73
+ />
74
+ </td>
75
+ <th align="left">error</th>
76
+ <td>
77
+ <MediaWithDefaults
78
+ width={3500}
79
+ height={2095}
80
+ placeholder={{lqip: lqip}}
81
+ src="andre-spieker-238-unsplash.jpg"
82
+ style={{maxWidth: 200}}
83
+ icon={'error'}
84
+ />
85
+ </td>
86
+ </tr>
87
+ </tbody>
88
+ </table>;
89
+ ```
@@ -0,0 +1,33 @@
1
+ export default MediaWithDefaults;
2
+ declare function MediaWithDefaults({ icons: iconsProp, theme: themeProp, ...props }: {
3
+ [x: string]: any;
4
+ icons?: {
5
+ [x: string]: ((props: any) => React.JSX.Element) | null;
6
+ } | undefined;
7
+ theme?: {
8
+ placeholder: {
9
+ backgroundSize: string;
10
+ backgroundRepeat: string;
11
+ position: string;
12
+ };
13
+ img: {
14
+ width: string;
15
+ height: string;
16
+ maxWidth: string;
17
+ marginBottom: string;
18
+ };
19
+ icon: {
20
+ position: string;
21
+ top: string;
22
+ left: string;
23
+ transform: string;
24
+ textAlign: string;
25
+ };
26
+ noscript: {
27
+ position: string;
28
+ top: number;
29
+ left: number;
30
+ };
31
+ } | undefined;
32
+ }): React.JSX.Element;
33
+ import React from 'react';
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import Media from '../Media';
3
+ import icons from '../icons';
4
+ import theme from '../theme';
5
+
6
+ const MediaWithDefaults = ({
7
+ icons: iconsProp = icons,
8
+ theme: themeProp = theme,
9
+ ...props
10
+ }) => <Media {...props} icons={iconsProp} theme={themeProp} />;
11
+
12
+ export default MediaWithDefaults;
@@ -0,0 +1,5 @@
1
+ declare function _default(...stylesOrClasses: any[]): {
2
+ className: string;
3
+ style: object;
4
+ };
5
+ export default _default;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Composes styles and/or classes
3
+ *
4
+ * For classes it will concat them in in one string
5
+ * and return as `className` property.
6
+ * Alternative is https://github.com/JedWatson/classnames
7
+ *
8
+ * For objects it will merge them in one object
9
+ * and return as `style` property.
10
+ *
11
+ * Usage:
12
+ * Asume you have `theme` object, which can be css-module
13
+ * or object or other css-in-js compatible with css-module
14
+ *
15
+ * <a {...compose(theme.link, theme.active, {color: "#000"})}>link</a>
16
+ *
17
+ * @returns {{className: string, style: object}} - params for React component
18
+ */
19
+ export default (...stylesOrClasses) => {
20
+ const classes = [];
21
+ let style;
22
+ for (const obj of stylesOrClasses) {
23
+ if (obj instanceof Object) {
24
+ Object.assign(style || (style = {}), obj);
25
+ } else if (obj === undefined || obj === false) {
26
+ // ignore
27
+ } else if (typeof obj === 'string') {
28
+ classes.push(obj);
29
+ } else {
30
+ throw new Error(`Unexpected value ${obj}`);
31
+ }
32
+ }
33
+ return {
34
+ className: classes.length > 1 ? classes.join(' ') : classes[0],
35
+ style,
36
+ };
37
+ };
@@ -0,0 +1,22 @@
1
+ export namespace icons {
2
+ export { load };
3
+ export { loading };
4
+ export { loaded };
5
+ export { error };
6
+ export { noicon };
7
+ export { offline };
8
+ }
9
+ export namespace loadStates {
10
+ export { initial };
11
+ export { loading };
12
+ export { loaded };
13
+ export { error };
14
+ }
15
+ declare const load: "load";
16
+ declare const loading: "loading";
17
+ declare const loaded: "loaded";
18
+ declare const error: "error";
19
+ declare const noicon: "noicon";
20
+ declare const offline: "offline";
21
+ declare const initial: "initial";
22
+ export {};
@@ -0,0 +1,24 @@
1
+ const load = 'load';
2
+ const loading = 'loading';
3
+ const loaded = 'loaded';
4
+ const error = 'error';
5
+ const noicon = 'noicon';
6
+ const offline = 'offline';
7
+
8
+ export const icons = {
9
+ load,
10
+ loading,
11
+ loaded,
12
+ error,
13
+ noicon,
14
+ offline,
15
+ };
16
+
17
+ const initial = 'initial';
18
+
19
+ export const loadStates = {
20
+ initial,
21
+ loading,
22
+ loaded,
23
+ error,
24
+ };
@@ -0,0 +1,22 @@
1
+ export const ssr: boolean;
2
+ export const nativeConnection: boolean;
3
+ export function guessMaxImageWidth(dimensions: any, w: any): number;
4
+ export function bytesToSize(bytes: any): string;
5
+ export const supportsWebp: boolean;
6
+ export function selectSrc({ srcSet, maxImageWidth, supportsWebp }: {
7
+ srcSet: any;
8
+ maxImageWidth: any;
9
+ supportsWebp: any;
10
+ }): any;
11
+ export function fallbackParams({ srcSet, getUrl }: {
12
+ srcSet: any;
13
+ getUrl: any;
14
+ }): {
15
+ nsSrcSet?: undefined;
16
+ nsSrc?: undefined;
17
+ ssr?: undefined;
18
+ } | {
19
+ nsSrcSet: any;
20
+ nsSrc: any;
21
+ ssr: true;
22
+ };
@@ -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,15 @@
1
+ declare const _default: {
2
+ [load]: (props: any) => import("react").JSX.Element;
3
+ [loading]: (props: any) => import("react").JSX.Element;
4
+ [loaded]: null;
5
+ [error]: (props: any) => import("react").JSX.Element;
6
+ [noicon]: null;
7
+ [offline]: (props: any) => import("react").JSX.Element;
8
+ };
9
+ export default _default;
10
+ declare const load: string;
11
+ declare const loading: string;
12
+ declare const loaded: string;
13
+ declare const error: string;
14
+ declare const noicon: string;
15
+ declare const offline: string;
@@ -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,4 @@
1
+ export function combineCancel(p1: Promise<any>, p2: Promise<any>): Promise<any>;
2
+ export function timeout(threshold: any): Promise<any>;
3
+ export function imageLoader(src: any): Promise<any>;
4
+ export function xhrLoader(url: any, options: any): Promise<any>;