@docusaurus/plugin-ideal-image 2.0.0-beta.15d451942 → 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.d.ts +4 -3
- package/lib/index.js +68 -39
- package/lib/{types.js → theme/IdealImage/index.d.ts} +3 -2
- package/lib/theme/IdealImage/index.js +103 -0
- package/package.json +29 -16
- package/src/deps.d.ts +118 -0
- package/src/index.ts +89 -0
- package/src/plugin-ideal-image.d.ts +73 -0
- package/src/theme/IdealImage/index.tsx +114 -0
- package/lib/.tsbuildinfo +0 -3898
- package/lib/theme/IdealImage.js +0 -29
- package/lib/types.d.ts +0 -36
- package/tsconfig.json +0 -9
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
|
-
import { PluginOptions } from '
|
|
9
|
-
export default function (
|
|
7
|
+
import type { LoadContext, Plugin, OptionValidationContext, ValidationResult } from '@docusaurus/types';
|
|
8
|
+
import type { PluginOptions } from '@docusaurus/plugin-ideal-image';
|
|
9
|
+
export default function pluginIdealImage(context: LoadContext, options: PluginOptions): Plugin<void>;
|
|
10
|
+
export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;
|
package/lib/index.js
CHANGED
|
@@ -1,43 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, '__esModule', {value: true});
|
|
9
|
+
exports.validateOptions = void 0;
|
|
10
|
+
const tslib_1 = require('tslib');
|
|
11
|
+
const utils_validation_1 = require('@docusaurus/utils-validation');
|
|
12
|
+
const theme_translations_1 = require('@docusaurus/theme-translations');
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require('path'));
|
|
14
|
+
function pluginIdealImage(context, options) {
|
|
15
|
+
const {
|
|
16
|
+
i18n: {currentLocale},
|
|
17
|
+
} = context;
|
|
18
|
+
return {
|
|
19
|
+
name: 'docusaurus-plugin-ideal-image',
|
|
20
|
+
getThemePath() {
|
|
21
|
+
return path_1.default.resolve(__dirname, '../lib/theme');
|
|
22
|
+
},
|
|
23
|
+
getTypeScriptThemePath() {
|
|
24
|
+
return path_1.default.resolve(__dirname, '../src/theme');
|
|
25
|
+
},
|
|
26
|
+
getDefaultCodeTranslationMessages() {
|
|
27
|
+
return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
|
|
28
|
+
locale: currentLocale,
|
|
29
|
+
name: 'plugin-ideal-image',
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
configureWebpack(_config, isServer) {
|
|
33
|
+
const {disableInDev, ...loaderOptions} = options;
|
|
34
|
+
if (disableInDev && process.env.NODE_ENV !== 'production') {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
mergeStrategy: {
|
|
39
|
+
'module.rules': 'prepend',
|
|
11
40
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
41
|
+
module: {
|
|
42
|
+
rules: [
|
|
43
|
+
{
|
|
44
|
+
test: /\.(?:png|jpe?g|gif)$/i,
|
|
45
|
+
use: [
|
|
46
|
+
require.resolve('@docusaurus/lqip-loader'),
|
|
47
|
+
{
|
|
48
|
+
loader: require.resolve('@docusaurus/responsive-loader'),
|
|
49
|
+
options: {
|
|
50
|
+
emitFile: !isServer,
|
|
51
|
+
// eslint-disable-next-line global-require
|
|
52
|
+
adapter: require('@docusaurus/responsive-loader/sharp'),
|
|
53
|
+
name: 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]',
|
|
54
|
+
...loaderOptions,
|
|
55
|
+
},
|
|
16
56
|
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
test: /\.(png|jpe?g|gif)$/i,
|
|
21
|
-
use: [
|
|
22
|
-
require.resolve('@docusaurus/lqip-loader'),
|
|
23
|
-
{
|
|
24
|
-
loader: require.resolve('@docusaurus/responsive-loader'),
|
|
25
|
-
options: {
|
|
26
|
-
emitFile: !isServer,
|
|
27
|
-
disable: !isProd,
|
|
28
|
-
adapter: require('@docusaurus/responsive-loader/sharp'),
|
|
29
|
-
name: isProd
|
|
30
|
-
? 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]'
|
|
31
|
-
: 'assets/ideal-img/[name].[width].[ext]',
|
|
32
|
-
...options,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
};
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
40
60
|
},
|
|
41
|
-
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
exports.default = pluginIdealImage;
|
|
66
|
+
function validateOptions({validate, options}) {
|
|
67
|
+
const pluginOptionsSchema = utils_validation_1.Joi.object({
|
|
68
|
+
disableInDev: utils_validation_1.Joi.boolean().default(true),
|
|
69
|
+
}).unknown();
|
|
70
|
+
return validate(pluginOptionsSchema, options);
|
|
42
71
|
}
|
|
43
|
-
exports.
|
|
72
|
+
exports.validateOptions = validateOptions;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
3
|
*
|
|
5
4
|
* This source code is licensed under the MIT license found in the
|
|
6
5
|
* LICENSE file in the root directory of this source tree.
|
|
7
6
|
*/
|
|
8
|
-
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
import type { Props } from '@theme/IdealImage';
|
|
9
|
+
export default function IdealImage(props: Props): JSX.Element;
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
import React from 'react';
|
|
8
|
+
import ReactIdealImage from '@endiliey/react-ideal-image';
|
|
9
|
+
import {translate} from '@docusaurus/Translate';
|
|
10
|
+
// Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/helpers.js#L59-L65
|
|
11
|
+
const bytesToSize = (bytes) => {
|
|
12
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
13
|
+
if (bytes === 0) {
|
|
14
|
+
return 'n/a';
|
|
15
|
+
}
|
|
16
|
+
const scale = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
17
|
+
if (scale === 0) {
|
|
18
|
+
return `${bytes} ${sizes[scale]}`;
|
|
19
|
+
}
|
|
20
|
+
return `${(bytes / 1024 ** scale).toFixed(1)} ${sizes[scale]}`;
|
|
21
|
+
};
|
|
22
|
+
// Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/IdealImage/index.js#L43-L75
|
|
23
|
+
const getMessage = (icon, state) => {
|
|
24
|
+
switch (icon) {
|
|
25
|
+
case 'noicon':
|
|
26
|
+
case 'loaded':
|
|
27
|
+
return null;
|
|
28
|
+
case 'loading':
|
|
29
|
+
return translate({
|
|
30
|
+
id: 'theme.IdealImageMessage.loading',
|
|
31
|
+
message: 'Loading...',
|
|
32
|
+
description: 'When the full-scale image is loading',
|
|
33
|
+
});
|
|
34
|
+
case 'load': {
|
|
35
|
+
// we can show `alt` here
|
|
36
|
+
const {pickedSrc} = state;
|
|
37
|
+
const {size} = pickedSrc;
|
|
38
|
+
const sizeMessage = size ? ` (${bytesToSize(size)})` : '';
|
|
39
|
+
return translate(
|
|
40
|
+
{
|
|
41
|
+
id: 'theme.IdealImageMessage.load',
|
|
42
|
+
message: 'Click to load{sizeMessage}',
|
|
43
|
+
description:
|
|
44
|
+
'To prompt users to load the full image. sizeMessage is a parenthesized size figure.',
|
|
45
|
+
},
|
|
46
|
+
{sizeMessage},
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
case 'offline':
|
|
50
|
+
return translate({
|
|
51
|
+
id: 'theme.IdealImageMessage.offline',
|
|
52
|
+
message: 'Your browser is offline. Image not loaded',
|
|
53
|
+
description: 'When the user is viewing an offline document',
|
|
54
|
+
});
|
|
55
|
+
case 'error': {
|
|
56
|
+
const {loadInfo} = state;
|
|
57
|
+
if (loadInfo === 404) {
|
|
58
|
+
return translate({
|
|
59
|
+
id: 'theme.IdealImageMessage.404error',
|
|
60
|
+
message: '404. Image not found',
|
|
61
|
+
description: 'When the image is not found',
|
|
62
|
+
});
|
|
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
|
+
});
|
|
69
|
+
}
|
|
70
|
+
default:
|
|
71
|
+
throw new Error(`Wrong icon: ${icon}`);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
export default function IdealImage(props) {
|
|
75
|
+
const {alt, className, img} = props;
|
|
76
|
+
// In dev env just use regular img with original file
|
|
77
|
+
if (typeof img === 'string' || 'default' in img) {
|
|
78
|
+
return (
|
|
79
|
+
<img
|
|
80
|
+
src={typeof img === 'string' ? img : img.default}
|
|
81
|
+
className={className}
|
|
82
|
+
alt={alt}
|
|
83
|
+
{...props}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return (
|
|
88
|
+
<ReactIdealImage
|
|
89
|
+
{...props}
|
|
90
|
+
alt={alt}
|
|
91
|
+
className={className}
|
|
92
|
+
height={img.src.height || 100}
|
|
93
|
+
width={img.src.width || 100}
|
|
94
|
+
placeholder={{lqip: img.preSrc}}
|
|
95
|
+
src={img.src.src}
|
|
96
|
+
srcSet={img.src.images.map((image) => ({
|
|
97
|
+
...image,
|
|
98
|
+
src: image.path,
|
|
99
|
+
}))}
|
|
100
|
+
getMessage={getMessage}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
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
|
+
"types": "src/plugin-ideal-image.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"build": "
|
|
8
|
-
"
|
|
8
|
+
"build": "yarn build:server && yarn build:browser && yarn build:copy && yarn build:format",
|
|
9
|
+
"build:server": "tsc --project tsconfig.server.json",
|
|
10
|
+
"build:browser": "tsc --project tsconfig.browser.json",
|
|
11
|
+
"build:copy": "node copyUntypedFiles.mjs",
|
|
12
|
+
"build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\""
|
|
9
13
|
},
|
|
10
14
|
"publishConfig": {
|
|
11
15
|
"access": "public"
|
|
@@ -16,26 +20,35 @@
|
|
|
16
20
|
"directory": "packages/docusaurus-plugin-ideal-image"
|
|
17
21
|
},
|
|
18
22
|
"license": "MIT",
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"fs-extra": "^9.1.0"
|
|
21
|
-
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
24
|
-
"@docusaurus/lqip-loader": "2.0.0-beta.
|
|
25
|
-
"@docusaurus/responsive-loader": "1.
|
|
26
|
-
"@docusaurus/
|
|
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",
|
|
27
29
|
"@endiliey/react-ideal-image": "^0.0.11",
|
|
28
|
-
"react-waypoint": "^
|
|
29
|
-
"sharp": "^0.
|
|
30
|
-
"tslib": "^2.1
|
|
31
|
-
"webpack": "^5.
|
|
30
|
+
"react-waypoint": "^10.1.0",
|
|
31
|
+
"sharp": "^0.30.1",
|
|
32
|
+
"tslib": "^2.3.1",
|
|
33
|
+
"webpack": "^5.69.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.16",
|
|
37
|
+
"@docusaurus/types": "2.0.0-beta.16",
|
|
38
|
+
"fs-extra": "^10.0.1"
|
|
32
39
|
},
|
|
33
40
|
"peerDependencies": {
|
|
41
|
+
"jimp": "*",
|
|
34
42
|
"react": "^16.8.4 || ^17.0.0",
|
|
35
43
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
36
44
|
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"jimp": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
37
50
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
51
|
+
"node": ">=14"
|
|
39
52
|
},
|
|
40
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
|
|
41
54
|
}
|
package/src/deps.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
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 '@endiliey/react-ideal-image' {
|
|
16
|
+
import type {ComponentProps, ComponentType, CSSProperties} from 'react';
|
|
17
|
+
|
|
18
|
+
export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error';
|
|
19
|
+
|
|
20
|
+
export type State = {
|
|
21
|
+
pickedSrc: {
|
|
22
|
+
size: number;
|
|
23
|
+
};
|
|
24
|
+
loadInfo: 404 | null;
|
|
25
|
+
loadState: LoadingState;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type IconKey =
|
|
29
|
+
| 'load'
|
|
30
|
+
| 'loading'
|
|
31
|
+
| 'loaded'
|
|
32
|
+
| 'error'
|
|
33
|
+
| 'noicon'
|
|
34
|
+
| 'offline';
|
|
35
|
+
|
|
36
|
+
export interface SrcType {
|
|
37
|
+
width: number;
|
|
38
|
+
src?: string;
|
|
39
|
+
size?: number;
|
|
40
|
+
format?: 'webp' | 'jpeg' | 'png' | 'gif';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript';
|
|
44
|
+
|
|
45
|
+
export interface ImageProps extends ComponentProps<'img'> {
|
|
46
|
+
/**
|
|
47
|
+
* This function decides what icon to show based on the current state of the
|
|
48
|
+
* component.
|
|
49
|
+
*/
|
|
50
|
+
getIcon?: (state: State) => IconKey;
|
|
51
|
+
/**
|
|
52
|
+
* This function decides what message to show based on the icon (returned
|
|
53
|
+
* from `getIcon` prop) and the current state of the component.
|
|
54
|
+
*/
|
|
55
|
+
getMessage?: (icon: IconKey, state: State) => string | null;
|
|
56
|
+
/**
|
|
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.
|
|
60
|
+
*/
|
|
61
|
+
getUrl?: (srcType: SrcType) => string;
|
|
62
|
+
/**
|
|
63
|
+
* The Height of the image in px.
|
|
64
|
+
*/
|
|
65
|
+
height: number;
|
|
66
|
+
/**
|
|
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
|
|
70
|
+
*/
|
|
71
|
+
icons?: Partial<Record<IconKey, ComponentType>>;
|
|
72
|
+
/**
|
|
73
|
+
* This prop takes one of the 2 options, xhr and image.
|
|
74
|
+
* Read more about it:
|
|
75
|
+
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#cancel-download
|
|
76
|
+
*/
|
|
77
|
+
loader?: 'xhr' | 'image';
|
|
78
|
+
/**
|
|
79
|
+
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#lqip
|
|
80
|
+
*/
|
|
81
|
+
placeholder: {color: string} | {lqip: string};
|
|
82
|
+
/**
|
|
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.
|
|
87
|
+
*/
|
|
88
|
+
shouldAutoDownload?: (options: {
|
|
89
|
+
connection?: 'slow-2g' | '2g' | '3g' | '4g';
|
|
90
|
+
size?: number;
|
|
91
|
+
threshold?: number;
|
|
92
|
+
possiblySlowNetwork?: boolean;
|
|
93
|
+
}) => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* This provides an array of sources of different format and size of the
|
|
96
|
+
* image. Read more about it:
|
|
97
|
+
* https://github.com/stereobooster/react-ideal-image/blob/master/introduction.md#srcset
|
|
98
|
+
*/
|
|
99
|
+
srcSet: SrcType[];
|
|
100
|
+
/**
|
|
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.
|
|
104
|
+
*/
|
|
105
|
+
theme?: Partial<Record<ThemeKey, string | CSSProperties>>;
|
|
106
|
+
/**
|
|
107
|
+
* Tells how much to wait in milliseconds until consider the download to be
|
|
108
|
+
* slow.
|
|
109
|
+
*/
|
|
110
|
+
threshold?: number;
|
|
111
|
+
/**
|
|
112
|
+
* Width of the image in px.
|
|
113
|
+
*/
|
|
114
|
+
width: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default function IdealImage(props: ImageProps): JSX.Element;
|
|
118
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
import type {
|
|
9
|
+
LoadContext,
|
|
10
|
+
Plugin,
|
|
11
|
+
OptionValidationContext,
|
|
12
|
+
ValidationResult,
|
|
13
|
+
} from '@docusaurus/types';
|
|
14
|
+
import type {PluginOptions} from '@docusaurus/plugin-ideal-image';
|
|
15
|
+
import {Joi} from '@docusaurus/utils-validation';
|
|
16
|
+
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
|
|
17
|
+
|
|
18
|
+
import path from 'path';
|
|
19
|
+
|
|
20
|
+
export default function pluginIdealImage(
|
|
21
|
+
context: LoadContext,
|
|
22
|
+
options: PluginOptions,
|
|
23
|
+
): Plugin<void> {
|
|
24
|
+
const {
|
|
25
|
+
i18n: {currentLocale},
|
|
26
|
+
} = context;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
name: 'docusaurus-plugin-ideal-image',
|
|
30
|
+
|
|
31
|
+
getThemePath() {
|
|
32
|
+
return path.resolve(__dirname, '../lib/theme');
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
getTypeScriptThemePath() {
|
|
36
|
+
return path.resolve(__dirname, '../src/theme');
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
getDefaultCodeTranslationMessages() {
|
|
40
|
+
return readDefaultCodeTranslationMessages({
|
|
41
|
+
locale: currentLocale,
|
|
42
|
+
name: 'plugin-ideal-image',
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
configureWebpack(_config, isServer) {
|
|
47
|
+
const {disableInDev, ...loaderOptions} = options;
|
|
48
|
+
if (disableInDev && process.env.NODE_ENV !== 'production') {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
mergeStrategy: {
|
|
54
|
+
'module.rules': 'prepend',
|
|
55
|
+
},
|
|
56
|
+
module: {
|
|
57
|
+
rules: [
|
|
58
|
+
{
|
|
59
|
+
test: /\.(?:png|jpe?g|gif)$/i,
|
|
60
|
+
use: [
|
|
61
|
+
require.resolve('@docusaurus/lqip-loader'),
|
|
62
|
+
{
|
|
63
|
+
loader: require.resolve('@docusaurus/responsive-loader'),
|
|
64
|
+
options: {
|
|
65
|
+
emitFile: !isServer, // don't emit for server-side rendering
|
|
66
|
+
// eslint-disable-next-line global-require
|
|
67
|
+
adapter: require('@docusaurus/responsive-loader/sharp'),
|
|
68
|
+
name: 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]',
|
|
69
|
+
...loaderOptions,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function validateOptions({
|
|
82
|
+
validate,
|
|
83
|
+
options,
|
|
84
|
+
}: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
|
|
85
|
+
const pluginOptionsSchema = Joi.object({
|
|
86
|
+
disableInDev: Joi.boolean().default(true),
|
|
87
|
+
}).unknown();
|
|
88
|
+
return validate(pluginOptionsSchema, options);
|
|
89
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
declare module '@docusaurus/plugin-ideal-image' {
|
|
9
|
+
export type PluginOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* Filename template for output files.
|
|
12
|
+
*/
|
|
13
|
+
name?: string;
|
|
14
|
+
/**
|
|
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.
|
|
19
|
+
*/
|
|
20
|
+
sizes?: number[];
|
|
21
|
+
/**
|
|
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)
|
|
25
|
+
*/
|
|
26
|
+
size?: number;
|
|
27
|
+
/**
|
|
28
|
+
* As an alternative to manually specifying sizes, you can specify min, max
|
|
29
|
+
* and steps, and the sizes will be generated for you.
|
|
30
|
+
*/
|
|
31
|
+
min?: number;
|
|
32
|
+
/**
|
|
33
|
+
* See min above
|
|
34
|
+
*/
|
|
35
|
+
max?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Configure the number of images generated between min and max (inclusive)
|
|
38
|
+
*/
|
|
39
|
+
steps?: number;
|
|
40
|
+
/**
|
|
41
|
+
* JPEG compression quality
|
|
42
|
+
*/
|
|
43
|
+
quality?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Just use regular images in dev mode
|
|
46
|
+
*/
|
|
47
|
+
disableInDev?: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare module '@theme/IdealImage' {
|
|
52
|
+
import type {ComponentProps} from 'react';
|
|
53
|
+
|
|
54
|
+
export type SrcType = {
|
|
55
|
+
width: number;
|
|
56
|
+
path?: string;
|
|
57
|
+
size?: number;
|
|
58
|
+
format?: 'webp' | 'jpeg' | 'png' | 'gif';
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type SrcImage = {
|
|
62
|
+
height?: number;
|
|
63
|
+
width?: number;
|
|
64
|
+
preSrc: string;
|
|
65
|
+
src: string;
|
|
66
|
+
images: SrcType[];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export interface Props extends ComponentProps<'img'> {
|
|
70
|
+
readonly img: {default: string} | {src: SrcImage; preSrc: string} | string;
|
|
71
|
+
}
|
|
72
|
+
export default function IdealImage(props: Props): JSX.Element;
|
|
73
|
+
}
|