@docusaurus/plugin-ideal-image 2.0.0-beta.16 → 2.0.0-beta.19

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 CHANGED
@@ -4,7 +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 type { LoadContext, Plugin, OptionValidationContext, ValidationResult } from '@docusaurus/types';
7
+ import type { LoadContext, Plugin, OptionValidationContext } from '@docusaurus/types';
8
8
  import type { PluginOptions } from '@docusaurus/plugin-ideal-image';
9
9
  export default function pluginIdealImage(context: LoadContext, options: PluginOptions): Plugin<void>;
10
- export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;
10
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions, PluginOptions>): PluginOptions;
package/lib/index.js CHANGED
@@ -7,10 +7,8 @@
7
7
  */
8
8
  Object.defineProperty(exports, '__esModule', {value: true});
9
9
  exports.validateOptions = void 0;
10
- const tslib_1 = require('tslib');
11
10
  const utils_validation_1 = require('@docusaurus/utils-validation');
12
11
  const theme_translations_1 = require('@docusaurus/theme-translations');
13
- const path_1 = (0, tslib_1.__importDefault)(require('path'));
14
12
  function pluginIdealImage(context, options) {
15
13
  const {
16
14
  i18n: {currentLocale},
@@ -18,10 +16,10 @@ function pluginIdealImage(context, options) {
18
16
  return {
19
17
  name: 'docusaurus-plugin-ideal-image',
20
18
  getThemePath() {
21
- return path_1.default.resolve(__dirname, '../lib/theme');
19
+ return '../lib/theme';
22
20
  },
23
21
  getTypeScriptThemePath() {
24
- return path_1.default.resolve(__dirname, '../src/theme');
22
+ return '../src/theme';
25
23
  },
26
24
  getDefaultCodeTranslationMessages() {
27
25
  return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
@@ -41,12 +39,13 @@ function pluginIdealImage(context, options) {
41
39
  module: {
42
40
  rules: [
43
41
  {
44
- test: /\.(?:png|jpe?g|gif)$/i,
42
+ test: /\.(?:png|jpe?g)$/i,
45
43
  use: [
46
44
  require.resolve('@docusaurus/lqip-loader'),
47
45
  {
48
46
  loader: require.resolve('@docusaurus/responsive-loader'),
49
47
  options: {
48
+ // Don't emit for server-side rendering
50
49
  emitFile: !isServer,
51
50
  // eslint-disable-next-line global-require
52
51
  adapter: require('@docusaurus/responsive-loader/sharp'),
@@ -8,7 +8,7 @@ import React from 'react';
8
8
  import ReactIdealImage from '@endiliey/react-ideal-image';
9
9
  import {translate} from '@docusaurus/Translate';
10
10
  // Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/helpers.js#L59-L65
11
- const bytesToSize = (bytes) => {
11
+ function bytesToSize(bytes) {
12
12
  const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
13
13
  if (bytes === 0) {
14
14
  return 'n/a';
@@ -18,9 +18,9 @@ const bytesToSize = (bytes) => {
18
18
  return `${bytes} ${sizes[scale]}`;
19
19
  }
20
20
  return `${(bytes / 1024 ** scale).toFixed(1)} ${sizes[scale]}`;
21
- };
21
+ }
22
22
  // Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/IdealImage/index.js#L43-L75
23
- const getMessage = (icon, state) => {
23
+ function getMessage(icon, state) {
24
24
  switch (icon) {
25
25
  case 'noicon':
26
26
  case 'loaded':
@@ -32,7 +32,7 @@ const getMessage = (icon, state) => {
32
32
  description: 'When the full-scale image is loading',
33
33
  });
34
34
  case 'load': {
35
- // we can show `alt` here
35
+ // We can show `alt` here
36
36
  const {pickedSrc} = state;
37
37
  const {size} = pickedSrc;
38
38
  const sizeMessage = size ? ` (${bytesToSize(size)})` : '';
@@ -70,7 +70,7 @@ const getMessage = (icon, state) => {
70
70
  default:
71
71
  throw new Error(`Wrong icon: ${icon}`);
72
72
  }
73
- };
73
+ }
74
74
  export default function IdealImage(props) {
75
75
  const {alt, className, img} = props;
76
76
  // In dev env just use regular img with original file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-ideal-image",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.19",
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.16",
25
- "@docusaurus/lqip-loader": "2.0.0-beta.16",
24
+ "@docusaurus/core": "2.0.0-beta.19",
25
+ "@docusaurus/lqip-loader": "2.0.0-beta.19",
26
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
+ "@docusaurus/theme-translations": "2.0.0-beta.19",
28
+ "@docusaurus/utils-validation": "2.0.0-beta.19",
29
29
  "@endiliey/react-ideal-image": "^0.0.11",
30
30
  "react-waypoint": "^10.1.0",
31
- "sharp": "^0.30.1",
32
- "tslib": "^2.3.1",
33
- "webpack": "^5.69.1"
31
+ "sharp": "^0.30.4",
32
+ "tslib": "^2.4.0",
33
+ "webpack": "^5.72.0"
34
34
  },
35
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"
36
+ "@docusaurus/module-type-aliases": "2.0.0-beta.19",
37
+ "@docusaurus/types": "2.0.0-beta.19",
38
+ "fs-extra": "^10.1.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "jimp": "*",
@@ -50,5 +50,5 @@
50
50
  "engines": {
51
51
  "node": ">=14"
52
52
  },
53
- "gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
53
+ "gitHead": "a71e60a49cce93c1006ef10c41ac03187f057102"
54
54
  }
package/src/deps.d.ts CHANGED
@@ -33,16 +33,17 @@ declare module '@endiliey/react-ideal-image' {
33
33
  | 'noicon'
34
34
  | 'offline';
35
35
 
36
- export interface SrcType {
36
+ export type SrcType = {
37
37
  width: number;
38
38
  src?: string;
39
39
  size?: number;
40
40
  format?: 'webp' | 'jpeg' | 'png' | 'gif';
41
- }
41
+ };
42
42
 
43
43
  type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript';
44
44
 
45
- export interface ImageProps extends ComponentProps<'img'> {
45
+ export interface ImageProps
46
+ extends Omit<ComponentProps<'img'>, 'srcSet' | 'placeholder'> {
46
47
  /**
47
48
  * This function decides what icon to show based on the current state of the
48
49
  * component.
@@ -68,7 +69,7 @@ declare module '@endiliey/react-ideal-image' {
68
69
  * from material design, Implemented as React components with the SVG
69
70
  * element. You can customize icons
70
71
  */
71
- icons?: Partial<Record<IconKey, ComponentType>>;
72
+ icons?: Partial<{[icon in IconKey]: ComponentType}>;
72
73
  /**
73
74
  * This prop takes one of the 2 options, xhr and image.
74
75
  * Read more about it:
@@ -102,7 +103,7 @@ declare module '@endiliey/react-ideal-image' {
102
103
  * inline styles, but it is also possible to use CSS modules and override
103
104
  * all styles.
104
105
  */
105
- theme?: Partial<Record<ThemeKey, string | CSSProperties>>;
106
+ theme?: Partial<{[key in ThemeKey]: string | CSSProperties}>;
106
107
  /**
107
108
  * Tells how much to wait in milliseconds until consider the download to be
108
109
  * slow.
package/src/index.ts CHANGED
@@ -9,14 +9,11 @@ import type {
9
9
  LoadContext,
10
10
  Plugin,
11
11
  OptionValidationContext,
12
- ValidationResult,
13
12
  } from '@docusaurus/types';
14
13
  import type {PluginOptions} from '@docusaurus/plugin-ideal-image';
15
14
  import {Joi} from '@docusaurus/utils-validation';
16
15
  import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
17
16
 
18
- import path from 'path';
19
-
20
17
  export default function pluginIdealImage(
21
18
  context: LoadContext,
22
19
  options: PluginOptions,
@@ -29,11 +26,11 @@ export default function pluginIdealImage(
29
26
  name: 'docusaurus-plugin-ideal-image',
30
27
 
31
28
  getThemePath() {
32
- return path.resolve(__dirname, '../lib/theme');
29
+ return '../lib/theme';
33
30
  },
34
31
 
35
32
  getTypeScriptThemePath() {
36
- return path.resolve(__dirname, '../src/theme');
33
+ return '../src/theme';
37
34
  },
38
35
 
39
36
  getDefaultCodeTranslationMessages() {
@@ -56,13 +53,14 @@ export default function pluginIdealImage(
56
53
  module: {
57
54
  rules: [
58
55
  {
59
- test: /\.(?:png|jpe?g|gif)$/i,
56
+ test: /\.(?:png|jpe?g)$/i,
60
57
  use: [
61
58
  require.resolve('@docusaurus/lqip-loader'),
62
59
  {
63
60
  loader: require.resolve('@docusaurus/responsive-loader'),
64
61
  options: {
65
- emitFile: !isServer, // don't emit for server-side rendering
62
+ // Don't emit for server-side rendering
63
+ emitFile: !isServer,
66
64
  // eslint-disable-next-line global-require
67
65
  adapter: require('@docusaurus/responsive-loader/sharp'),
68
66
  name: 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]',
@@ -81,7 +79,7 @@ export default function pluginIdealImage(
81
79
  export function validateOptions({
82
80
  validate,
83
81
  options,
84
- }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
82
+ }: OptionValidationContext<PluginOptions, PluginOptions>): PluginOptions {
85
83
  const pluginOptionsSchema = Joi.object({
86
84
  disableInDev: Joi.boolean().default(true),
87
85
  }).unknown();
@@ -14,8 +14,7 @@ declare module '@docusaurus/plugin-ideal-image' {
14
14
  /**
15
15
  * Specify all widths you want to use; if a specified size exceeds the
16
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.
17
+ * scaled up).
19
18
  */
20
19
  sizes?: number[];
21
20
  /**
@@ -25,16 +24,17 @@ declare module '@docusaurus/plugin-ideal-image' {
25
24
  */
26
25
  size?: number;
27
26
  /**
28
- * As an alternative to manually specifying sizes, you can specify min, max
29
- * and steps, and the sizes will be generated for you.
27
+ * As an alternative to manually specifying `sizes`, you can specify `min`,
28
+ * `max` and `steps`, and the `sizes` will be generated for you.
30
29
  */
31
30
  min?: number;
32
31
  /**
33
- * See min above
32
+ * @see {@link PluginOptions.min}
34
33
  */
35
34
  max?: number;
36
35
  /**
37
- * Configure the number of images generated between min and max (inclusive)
36
+ * Configure the number of images generated between `min` and `max`
37
+ * (inclusive)
38
38
  */
39
39
  steps?: number;
40
40
  /**
@@ -42,7 +42,8 @@ declare module '@docusaurus/plugin-ideal-image' {
42
42
  */
43
43
  quality?: number;
44
44
  /**
45
- * Just use regular images in dev mode
45
+ * You can test ideal image behavior in dev mode by setting this to `false`.
46
+ * Tip: use network throttling in your browser to simulate slow networks.
46
47
  */
47
48
  disableInDev?: boolean;
48
49
  };
@@ -15,7 +15,7 @@ import {translate} from '@docusaurus/Translate';
15
15
  import type {Props} from '@theme/IdealImage';
16
16
 
17
17
  // Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/helpers.js#L59-L65
18
- const bytesToSize = (bytes: number) => {
18
+ function bytesToSize(bytes: number) {
19
19
  const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
20
20
  if (bytes === 0) {
21
21
  return 'n/a';
@@ -25,10 +25,10 @@ const bytesToSize = (bytes: number) => {
25
25
  return `${bytes} ${sizes[scale]}`;
26
26
  }
27
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
31
- const getMessage = (icon: IconKey, state: State) => {
31
+ function getMessage(icon: IconKey, state: State) {
32
32
  switch (icon) {
33
33
  case 'noicon':
34
34
  case 'loaded':
@@ -40,7 +40,7 @@ const getMessage = (icon: IconKey, state: State) => {
40
40
  description: 'When the full-scale image is loading',
41
41
  });
42
42
  case 'load': {
43
- // we can show `alt` here
43
+ // We can show `alt` here
44
44
  const {pickedSrc} = state;
45
45
  const {size} = pickedSrc;
46
46
  const sizeMessage = size ? ` (${bytesToSize(size)})` : '';
@@ -78,7 +78,7 @@ const getMessage = (icon: IconKey, state: State) => {
78
78
  default:
79
79
  throw new Error(`Wrong icon: ${icon}`);
80
80
  }
81
- };
81
+ }
82
82
 
83
83
  export default function IdealImage(props: Props): JSX.Element {
84
84
  const {alt, className, img} = props;