@docusaurus/plugin-ideal-image 2.0.0-beta.20 → 2.0.0-beta.21
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 +54 -56
- package/lib/theme/IdealImage/index.js +2 -2
- package/package.json +15 -16
- package/src/index.ts +3 -3
- package/src/theme/IdealImage/index.tsx +4 -4
package/lib/index.js
CHANGED
|
@@ -1,71 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
Object.defineProperty(exports,
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateOptions = void 0;
|
|
10
|
-
const utils_validation_1 = require(
|
|
11
|
-
const theme_translations_1 = require(
|
|
10
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
const theme_translations_1 = require("@docusaurus/theme-translations");
|
|
12
12
|
function pluginIdealImage(context, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getThemePath() {
|
|
19
|
-
return '../lib/theme';
|
|
20
|
-
},
|
|
21
|
-
getTypeScriptThemePath() {
|
|
22
|
-
return '../src/theme';
|
|
23
|
-
},
|
|
24
|
-
getDefaultCodeTranslationMessages() {
|
|
25
|
-
return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
|
|
26
|
-
locale: currentLocale,
|
|
27
|
-
name: 'plugin-ideal-image',
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
configureWebpack(_config, isServer) {
|
|
31
|
-
const {disableInDev, ...loaderOptions} = options;
|
|
32
|
-
if (disableInDev && process.env.NODE_ENV !== 'production') {
|
|
33
|
-
return {};
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
mergeStrategy: {
|
|
37
|
-
'module.rules': 'prepend',
|
|
13
|
+
const { i18n: { currentLocale }, } = context;
|
|
14
|
+
return {
|
|
15
|
+
name: 'docusaurus-plugin-ideal-image',
|
|
16
|
+
getThemePath() {
|
|
17
|
+
return '../lib/theme';
|
|
38
18
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
19
|
+
getTypeScriptThemePath() {
|
|
20
|
+
return '../src/theme';
|
|
21
|
+
},
|
|
22
|
+
getDefaultCodeTranslationMessages() {
|
|
23
|
+
return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
|
|
24
|
+
locale: currentLocale,
|
|
25
|
+
name: 'plugin-ideal-image',
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
configureWebpack(_config, isServer) {
|
|
29
|
+
const { disableInDev, ...loaderOptions } = options;
|
|
30
|
+
if (disableInDev && process.env.NODE_ENV !== 'production') {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
mergeStrategy: {
|
|
35
|
+
'module.rules': 'prepend',
|
|
36
|
+
},
|
|
37
|
+
module: {
|
|
38
|
+
rules: [
|
|
39
|
+
{
|
|
40
|
+
test: /\.(?:png|jpe?g)$/i,
|
|
41
|
+
use: [
|
|
42
|
+
require.resolve('@docusaurus/lqip-loader'),
|
|
43
|
+
{
|
|
44
|
+
loader: require.resolve('@docusaurus/responsive-loader'),
|
|
45
|
+
options: {
|
|
46
|
+
// Don't emit for server-side rendering
|
|
47
|
+
emitFile: !isServer,
|
|
48
|
+
// eslint-disable-next-line global-require
|
|
49
|
+
adapter: require('@docusaurus/responsive-loader/sharp'),
|
|
50
|
+
name: 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]',
|
|
51
|
+
...loaderOptions,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
],
|
|
55
57
|
},
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
],
|
|
58
|
+
};
|
|
59
59
|
},
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
};
|
|
60
|
+
};
|
|
63
61
|
}
|
|
64
62
|
exports.default = pluginIdealImage;
|
|
65
|
-
function validateOptions({validate, options}) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
function validateOptions({ validate, options, }) {
|
|
64
|
+
const pluginOptionsSchema = utils_validation_1.Joi.object({
|
|
65
|
+
disableInDev: utils_validation_1.Joi.boolean().default(true),
|
|
66
|
+
}).unknown();
|
|
67
|
+
return validate(pluginOptionsSchema, options);
|
|
70
68
|
}
|
|
71
69
|
exports.validateOptions = validateOptions;
|
|
@@ -89,8 +89,8 @@ export default function IdealImage(props) {
|
|
|
89
89
|
{...props}
|
|
90
90
|
alt={alt}
|
|
91
91
|
className={className}
|
|
92
|
-
height={img.src.height
|
|
93
|
-
width={img.src.width
|
|
92
|
+
height={img.src.height ?? 100}
|
|
93
|
+
width={img.src.width ?? 100}
|
|
94
94
|
placeholder={{lqip: img.preSrc}}
|
|
95
95
|
src={img.src.src}
|
|
96
96
|
srcSet={img.src.images.map((image) => ({
|
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-ideal-image",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "
|
|
9
|
-
"
|
|
10
|
-
"build:
|
|
11
|
-
"
|
|
12
|
-
"build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\""
|
|
8
|
+
"build": "tsc --build && node ../../admin/scripts/copyUntypedFiles.js && prettier --config ../../.prettierrc --write \"lib/theme/**/*.js\"",
|
|
9
|
+
"watch": "run-p -c copy:watch build:watch",
|
|
10
|
+
"build:watch": "tsc --build --watch",
|
|
11
|
+
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
|
13
12
|
},
|
|
14
13
|
"publishConfig": {
|
|
15
14
|
"access": "public"
|
|
@@ -21,20 +20,20 @@
|
|
|
21
20
|
},
|
|
22
21
|
"license": "MIT",
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
25
|
-
"@docusaurus/lqip-loader": "2.0.0-beta.
|
|
23
|
+
"@docusaurus/core": "2.0.0-beta.21",
|
|
24
|
+
"@docusaurus/lqip-loader": "2.0.0-beta.21",
|
|
26
25
|
"@docusaurus/responsive-loader": "^1.7.0",
|
|
27
|
-
"@docusaurus/theme-translations": "2.0.0-beta.
|
|
28
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
26
|
+
"@docusaurus/theme-translations": "2.0.0-beta.21",
|
|
27
|
+
"@docusaurus/utils-validation": "2.0.0-beta.21",
|
|
29
28
|
"@endiliey/react-ideal-image": "^0.0.11",
|
|
30
29
|
"react-waypoint": "^10.1.0",
|
|
31
|
-
"sharp": "^0.30.
|
|
30
|
+
"sharp": "^0.30.5",
|
|
32
31
|
"tslib": "^2.4.0",
|
|
33
|
-
"webpack": "^5.72.
|
|
32
|
+
"webpack": "^5.72.1"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
37
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
35
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.21",
|
|
36
|
+
"@docusaurus/types": "2.0.0-beta.21",
|
|
38
37
|
"fs-extra": "^10.1.0"
|
|
39
38
|
},
|
|
40
39
|
"peerDependencies": {
|
|
@@ -48,7 +47,7 @@
|
|
|
48
47
|
}
|
|
49
48
|
},
|
|
50
49
|
"engines": {
|
|
51
|
-
"node": ">=14"
|
|
50
|
+
"node": ">=16.14"
|
|
52
51
|
},
|
|
53
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "69ac49fc6909517f13615ee40290c4bd00c39df4"
|
|
54
53
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {Joi} from '@docusaurus/utils-validation';
|
|
9
|
+
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
|
|
8
10
|
import type {
|
|
9
11
|
LoadContext,
|
|
10
12
|
Plugin,
|
|
11
13
|
OptionValidationContext,
|
|
12
14
|
} from '@docusaurus/types';
|
|
13
15
|
import type {PluginOptions} from '@docusaurus/plugin-ideal-image';
|
|
14
|
-
import {Joi} from '@docusaurus/utils-validation';
|
|
15
|
-
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
|
|
16
16
|
|
|
17
17
|
export default function pluginIdealImage(
|
|
18
18
|
context: LoadContext,
|
|
@@ -80,7 +80,7 @@ export function validateOptions({
|
|
|
80
80
|
validate,
|
|
81
81
|
options,
|
|
82
82
|
}: OptionValidationContext<PluginOptions, PluginOptions>): PluginOptions {
|
|
83
|
-
const pluginOptionsSchema = Joi.object({
|
|
83
|
+
const pluginOptionsSchema = Joi.object<PluginOptions>({
|
|
84
84
|
disableInDev: Joi.boolean().default(true),
|
|
85
85
|
}).unknown();
|
|
86
86
|
return validate(pluginOptionsSchema, options);
|
|
@@ -22,9 +22,9 @@ function bytesToSize(bytes: number) {
|
|
|
22
22
|
}
|
|
23
23
|
const scale = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
24
24
|
if (scale === 0) {
|
|
25
|
-
return `${bytes} ${sizes[scale]}`;
|
|
25
|
+
return `${bytes} ${sizes[scale]!}`;
|
|
26
26
|
}
|
|
27
|
-
return `${(bytes / 1024 ** scale).toFixed(1)} ${sizes[scale]}`;
|
|
27
|
+
return `${(bytes / 1024 ** scale).toFixed(1)} ${sizes[scale]!}`;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/IdealImage/index.js#L43-L75
|
|
@@ -100,8 +100,8 @@ export default function IdealImage(props: Props): JSX.Element {
|
|
|
100
100
|
{...props}
|
|
101
101
|
alt={alt}
|
|
102
102
|
className={className}
|
|
103
|
-
height={img.src.height
|
|
104
|
-
width={img.src.width
|
|
103
|
+
height={img.src.height ?? 100}
|
|
104
|
+
width={img.src.width ?? 100}
|
|
105
105
|
placeholder={{lqip: img.preSrc}}
|
|
106
106
|
src={img.src.src}
|
|
107
107
|
srcSet={img.src.images.map((image) => ({
|