@docusaurus/plugin-ideal-image 2.0.0-beta.15 → 2.0.0-beta.16
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 +1 -1
- package/lib/theme/IdealImage/index.d.ts +1 -2
- package/lib/theme/IdealImage/index.js +6 -8
- package/package.json +12 -12
- package/src/deps.d.ts +29 -23
- package/src/index.ts +2 -3
- package/src/plugin-ideal-image.d.ts +12 -6
- package/src/theme/IdealImage/index.tsx +6 -9
package/lib/index.js
CHANGED
|
@@ -60,19 +60,18 @@ const getMessage = (icon, state) => {
|
|
|
60
60
|
message: '404. Image not found',
|
|
61
61
|
description: 'When the image is not found',
|
|
62
62
|
});
|
|
63
|
-
} else {
|
|
64
|
-
return translate({
|
|
65
|
-
id: 'theme.IdealImageMessage.error',
|
|
66
|
-
message: 'Error. Click to reload',
|
|
67
|
-
description: 'When the image fails to load for unknown error',
|
|
68
|
-
});
|
|
69
63
|
}
|
|
64
|
+
return translate({
|
|
65
|
+
id: 'theme.IdealImageMessage.error',
|
|
66
|
+
message: 'Error. Click to reload',
|
|
67
|
+
description: 'When the image fails to load for unknown error',
|
|
68
|
+
});
|
|
70
69
|
}
|
|
71
70
|
default:
|
|
72
71
|
throw new Error(`Wrong icon: ${icon}`);
|
|
73
72
|
}
|
|
74
73
|
};
|
|
75
|
-
function IdealImage(props) {
|
|
74
|
+
export default function IdealImage(props) {
|
|
76
75
|
const {alt, className, img} = props;
|
|
77
76
|
// In dev env just use regular img with original file
|
|
78
77
|
if (typeof img === 'string' || 'default' in img) {
|
|
@@ -102,4 +101,3 @@ function IdealImage(props) {
|
|
|
102
101
|
/>
|
|
103
102
|
);
|
|
104
103
|
}
|
|
105
|
-
export default IdealImage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-ideal-image",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.16",
|
|
4
4
|
"description": "Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder).",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-ideal-image.d.ts",
|
|
@@ -21,21 +21,21 @@
|
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
25
|
-
"@docusaurus/lqip-loader": "2.0.0-beta.
|
|
26
|
-
"@docusaurus/responsive-loader": "1.
|
|
27
|
-
"@docusaurus/theme-translations": "2.0.0-beta.
|
|
28
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
24
|
+
"@docusaurus/core": "2.0.0-beta.16",
|
|
25
|
+
"@docusaurus/lqip-loader": "2.0.0-beta.16",
|
|
26
|
+
"@docusaurus/responsive-loader": "^1.7.0",
|
|
27
|
+
"@docusaurus/theme-translations": "2.0.0-beta.16",
|
|
28
|
+
"@docusaurus/utils-validation": "2.0.0-beta.16",
|
|
29
29
|
"@endiliey/react-ideal-image": "^0.0.11",
|
|
30
30
|
"react-waypoint": "^10.1.0",
|
|
31
|
-
"sharp": "^0.
|
|
31
|
+
"sharp": "^0.30.1",
|
|
32
32
|
"tslib": "^2.3.1",
|
|
33
|
-
"webpack": "^5.
|
|
33
|
+
"webpack": "^5.69.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
37
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
38
|
-
"fs-extra": "^10.0.
|
|
36
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.16",
|
|
37
|
+
"@docusaurus/types": "2.0.0-beta.16",
|
|
38
|
+
"fs-extra": "^10.0.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"jimp": "*",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=14"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
|
|
54
54
|
}
|
package/src/deps.d.ts
CHANGED
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
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
|
|
12
|
+
* Note: the original type definition is WRONG. getIcon & getMessage receive
|
|
13
|
+
* full state object.
|
|
13
14
|
*/
|
|
14
15
|
declare module '@endiliey/react-ideal-image' {
|
|
16
|
+
import type {ComponentProps, ComponentType, CSSProperties} from 'react';
|
|
17
|
+
|
|
15
18
|
export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error';
|
|
16
19
|
|
|
17
20
|
export type State = {
|
|
@@ -39,19 +42,21 @@ declare module '@endiliey/react-ideal-image' {
|
|
|
39
42
|
|
|
40
43
|
type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript';
|
|
41
44
|
|
|
42
|
-
export interface ImageProps {
|
|
45
|
+
export interface ImageProps extends ComponentProps<'img'> {
|
|
43
46
|
/**
|
|
44
|
-
* This function decides what icon to show based on the current state of the
|
|
47
|
+
* This function decides what icon to show based on the current state of the
|
|
48
|
+
* component.
|
|
45
49
|
*/
|
|
46
50
|
getIcon?: (state: State) => IconKey;
|
|
47
51
|
/**
|
|
48
|
-
* This function decides what message to show based on the icon (returned
|
|
49
|
-
* the current state of the component.
|
|
52
|
+
* This function decides what message to show based on the icon (returned
|
|
53
|
+
* from `getIcon` prop) and the current state of the component.
|
|
50
54
|
*/
|
|
51
|
-
getMessage?: (icon: IconKey, state: State) => string;
|
|
55
|
+
getMessage?: (icon: IconKey, state: State) => string | null;
|
|
52
56
|
/**
|
|
53
|
-
* This function is called as soon as the component enters the viewport and
|
|
54
|
-
* based on width and format if props.srcSet
|
|
57
|
+
* This function is called as soon as the component enters the viewport and
|
|
58
|
+
* is used to generate urls based on width and format if `props.srcSet`
|
|
59
|
+
* doesn't provide `src` field.
|
|
55
60
|
*/
|
|
56
61
|
getUrl?: (srcType: SrcType) => string;
|
|
57
62
|
/**
|
|
@@ -59,10 +64,11 @@ declare module '@endiliey/react-ideal-image' {
|
|
|
59
64
|
*/
|
|
60
65
|
height: number;
|
|
61
66
|
/**
|
|
62
|
-
* This provides a map of the icons. By default, the component uses icons
|
|
63
|
-
*
|
|
67
|
+
* This provides a map of the icons. By default, the component uses icons
|
|
68
|
+
* from material design, Implemented as React components with the SVG
|
|
69
|
+
* element. You can customize icons
|
|
64
70
|
*/
|
|
65
|
-
icons
|
|
71
|
+
icons?: Partial<Record<IconKey, ComponentType>>;
|
|
66
72
|
/**
|
|
67
73
|
* This prop takes one of the 2 options, xhr and image.
|
|
68
74
|
* Read more about it:
|
|
@@ -74,9 +80,10 @@ declare module '@endiliey/react-ideal-image' {
|
|
|
74
80
|
*/
|
|
75
81
|
placeholder: {color: string} | {lqip: string};
|
|
76
82
|
/**
|
|
77
|
-
* This function decides if image should be downloaded automatically. The
|
|
78
|
-
* returns false for a 2g network, for a 3g network it
|
|
79
|
-
* and for a 4g network it returns true
|
|
83
|
+
* This function decides if image should be downloaded automatically. The
|
|
84
|
+
* default function returns false for a 2g network, for a 3g network it
|
|
85
|
+
* decides based on `props.threshold` and for a 4g network it returns true
|
|
86
|
+
* by default.
|
|
80
87
|
*/
|
|
81
88
|
shouldAutoDownload?: (options: {
|
|
82
89
|
connection?: 'slow-2g' | '2g' | '3g' | '4g';
|
|
@@ -85,18 +92,20 @@ declare module '@endiliey/react-ideal-image' {
|
|
|
85
92
|
possiblySlowNetwork?: boolean;
|
|
86
93
|
}) => boolean;
|
|
87
94
|
/**
|
|
88
|
-
* This provides an array of sources of different format and size of the
|
|
89
|
-
* Read more about it:
|
|
95
|
+
* This provides an array of sources of different format and size of the
|
|
96
|
+
* image. Read more about it:
|
|
90
97
|
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#srcset
|
|
91
98
|
*/
|
|
92
99
|
srcSet: SrcType[];
|
|
93
100
|
/**
|
|
94
|
-
* This provides a theme to the component. By default, the component uses
|
|
95
|
-
* but it is also possible to use CSS modules and override
|
|
101
|
+
* This provides a theme to the component. By default, the component uses
|
|
102
|
+
* inline styles, but it is also possible to use CSS modules and override
|
|
103
|
+
* all styles.
|
|
96
104
|
*/
|
|
97
105
|
theme?: Partial<Record<ThemeKey, string | CSSProperties>>;
|
|
98
106
|
/**
|
|
99
|
-
* Tells how much to wait in milliseconds until consider the download to be
|
|
107
|
+
* Tells how much to wait in milliseconds until consider the download to be
|
|
108
|
+
* slow.
|
|
100
109
|
*/
|
|
101
110
|
threshold?: number;
|
|
102
111
|
/**
|
|
@@ -105,8 +114,5 @@ declare module '@endiliey/react-ideal-image' {
|
|
|
105
114
|
width: number;
|
|
106
115
|
}
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
declare const IdealImage: IdealImageComponent;
|
|
111
|
-
export default IdealImage;
|
|
117
|
+
export default function IdealImage(props: ImageProps): JSX.Element;
|
|
112
118
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
ValidationResult,
|
|
13
13
|
} from '@docusaurus/types';
|
|
14
14
|
import type {PluginOptions} from '@docusaurus/plugin-ideal-image';
|
|
15
|
-
import type {Configuration} from 'webpack';
|
|
16
15
|
import {Joi} from '@docusaurus/utils-validation';
|
|
17
16
|
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
|
|
18
17
|
|
|
@@ -44,7 +43,7 @@ export default function pluginIdealImage(
|
|
|
44
43
|
});
|
|
45
44
|
},
|
|
46
45
|
|
|
47
|
-
configureWebpack(_config
|
|
46
|
+
configureWebpack(_config, isServer) {
|
|
48
47
|
const {disableInDev, ...loaderOptions} = options;
|
|
49
48
|
if (disableInDev && process.env.NODE_ENV !== 'production') {
|
|
50
49
|
return {};
|
|
@@ -57,7 +56,7 @@ export default function pluginIdealImage(
|
|
|
57
56
|
module: {
|
|
58
57
|
rules: [
|
|
59
58
|
{
|
|
60
|
-
test: /\.(png|jpe?g|gif)$/i,
|
|
59
|
+
test: /\.(?:png|jpe?g|gif)$/i,
|
|
61
60
|
use: [
|
|
62
61
|
require.resolve('@docusaurus/lqip-loader'),
|
|
63
62
|
{
|
|
@@ -12,15 +12,21 @@ declare module '@docusaurus/plugin-ideal-image' {
|
|
|
12
12
|
*/
|
|
13
13
|
name?: string;
|
|
14
14
|
/**
|
|
15
|
-
* Specify all widths you want to use; if a specified size exceeds the
|
|
15
|
+
* Specify all widths you want to use; if a specified size exceeds the
|
|
16
|
+
* original image's width, the latter will be used (i.e. images won't be
|
|
17
|
+
* scaled up). You may also declare a default sizes array in the loader
|
|
18
|
+
* options in your webpack.config.js.
|
|
16
19
|
*/
|
|
17
20
|
sizes?: number[];
|
|
18
21
|
/**
|
|
19
|
-
* Specify one width you want to use; if the specified size exceeds the
|
|
22
|
+
* Specify one width you want to use; if the specified size exceeds the
|
|
23
|
+
* original image's width, the latter will be used (i.e. images won't be
|
|
24
|
+
* scaled up)
|
|
20
25
|
*/
|
|
21
26
|
size?: number;
|
|
22
27
|
/**
|
|
23
|
-
* As an alternative to manually specifying sizes, you can specify min, max
|
|
28
|
+
* As an alternative to manually specifying sizes, you can specify min, max
|
|
29
|
+
* and steps, and the sizes will be generated for you.
|
|
24
30
|
*/
|
|
25
31
|
min?: number;
|
|
26
32
|
/**
|
|
@@ -60,8 +66,8 @@ declare module '@theme/IdealImage' {
|
|
|
60
66
|
images: SrcType[];
|
|
61
67
|
};
|
|
62
68
|
|
|
63
|
-
export
|
|
64
|
-
img: {default: string} | {src: SrcImage; preSrc: string} | string;
|
|
65
|
-
}
|
|
69
|
+
export interface Props extends ComponentProps<'img'> {
|
|
70
|
+
readonly img: {default: string} | {src: SrcImage; preSrc: string} | string;
|
|
71
|
+
}
|
|
66
72
|
export default function IdealImage(props: Props): JSX.Element;
|
|
67
73
|
}
|
|
@@ -68,20 +68,19 @@ const getMessage = (icon: IconKey, state: State) => {
|
|
|
68
68
|
message: '404. Image not found',
|
|
69
69
|
description: 'When the image is not found',
|
|
70
70
|
});
|
|
71
|
-
} else {
|
|
72
|
-
return translate({
|
|
73
|
-
id: 'theme.IdealImageMessage.error',
|
|
74
|
-
message: 'Error. Click to reload',
|
|
75
|
-
description: 'When the image fails to load for unknown error',
|
|
76
|
-
});
|
|
77
71
|
}
|
|
72
|
+
return translate({
|
|
73
|
+
id: 'theme.IdealImageMessage.error',
|
|
74
|
+
message: 'Error. Click to reload',
|
|
75
|
+
description: 'When the image fails to load for unknown error',
|
|
76
|
+
});
|
|
78
77
|
}
|
|
79
78
|
default:
|
|
80
79
|
throw new Error(`Wrong icon: ${icon}`);
|
|
81
80
|
}
|
|
82
81
|
};
|
|
83
82
|
|
|
84
|
-
function IdealImage(props: Props): JSX.Element {
|
|
83
|
+
export default function IdealImage(props: Props): JSX.Element {
|
|
85
84
|
const {alt, className, img} = props;
|
|
86
85
|
|
|
87
86
|
// In dev env just use regular img with original file
|
|
@@ -113,5 +112,3 @@ function IdealImage(props: Props): JSX.Element {
|
|
|
113
112
|
/>
|
|
114
113
|
);
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
export default IdealImage;
|