@azerion/bunosaurus-plugin-ideal-image 0.0.0-stage → 4.0.0

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 (71) hide show
  1. package/README.md +6 -2
  2. package/lib/index.d.ts +10 -0
  3. package/lib/index.js +75 -0
  4. package/lib/theme/IdealImage/index.d.ts +9 -0
  5. package/lib/theme/IdealImage/index.js +96 -0
  6. package/lib/theme/IdealImageLegacy/LICENSE +20 -0
  7. package/lib/theme/IdealImageLegacy/README.md +13 -0
  8. package/lib/theme/IdealImageLegacy/components/Icon/Download.d.ts +2 -0
  9. package/lib/theme/IdealImageLegacy/components/Icon/Download.js +14 -0
  10. package/lib/theme/IdealImageLegacy/components/Icon/Loading.d.ts +2 -0
  11. package/lib/theme/IdealImageLegacy/components/Icon/Loading.js +14 -0
  12. package/lib/theme/IdealImageLegacy/components/Icon/Offline.d.ts +2 -0
  13. package/lib/theme/IdealImageLegacy/components/Icon/Offline.js +14 -0
  14. package/lib/theme/IdealImageLegacy/components/Icon/Warning.d.ts +2 -0
  15. package/lib/theme/IdealImageLegacy/components/Icon/Warning.js +14 -0
  16. package/lib/theme/IdealImageLegacy/components/Icon/index.d.ts +7 -0
  17. package/lib/theme/IdealImageLegacy/components/Icon/index.js +24 -0
  18. package/lib/theme/IdealImageLegacy/components/IdealImage/index.d.ts +46 -0
  19. package/lib/theme/IdealImageLegacy/components/IdealImage/index.js +352 -0
  20. package/lib/theme/IdealImageLegacy/components/IdealImage/waypoint.d.ts +10 -0
  21. package/lib/theme/IdealImageLegacy/components/IdealImage/waypoint.js +188 -0
  22. package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.d.ts +32 -0
  23. package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +11 -0
  24. package/lib/theme/IdealImageLegacy/components/Media/index.d.ts +20 -0
  25. package/lib/theme/IdealImageLegacy/components/Media/index.js +169 -0
  26. package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
  27. package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.d.ts +32 -0
  28. package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +11 -0
  29. package/lib/theme/IdealImageLegacy/components/composeStyle.d.ts +23 -0
  30. package/lib/theme/IdealImageLegacy/components/composeStyle.js +37 -0
  31. package/lib/theme/IdealImageLegacy/components/constants.d.ts +14 -0
  32. package/lib/theme/IdealImageLegacy/components/constants.js +24 -0
  33. package/lib/theme/IdealImageLegacy/components/helpers.d.ts +22 -0
  34. package/lib/theme/IdealImageLegacy/components/helpers.js +141 -0
  35. package/lib/theme/IdealImageLegacy/components/icons.d.ts +14 -0
  36. package/lib/theme/IdealImageLegacy/components/icons.js +16 -0
  37. package/lib/theme/IdealImageLegacy/components/loaders.d.ts +11 -0
  38. package/lib/theme/IdealImageLegacy/components/loaders.js +112 -0
  39. package/lib/theme/IdealImageLegacy/components/theme.d.ts +26 -0
  40. package/lib/theme/IdealImageLegacy/components/theme.js +26 -0
  41. package/lib/theme/IdealImageLegacy/components/theme.module.css +35 -0
  42. package/lib/theme/IdealImageLegacy/components/unfetch.d.ts +8 -0
  43. package/lib/theme/IdealImageLegacy/components/unfetch.js +74 -0
  44. package/lib/theme/IdealImageLegacy/index.d.ts +2 -0
  45. package/lib/theme/IdealImageLegacy/index.js +2 -0
  46. package/package.json +46 -4
  47. package/src/index.ts +94 -0
  48. package/src/plugin-ideal-image.d.ts +199 -0
  49. package/src/theme/IdealImage/index.tsx +108 -0
  50. package/src/theme/IdealImageLegacy/LICENSE +20 -0
  51. package/src/theme/IdealImageLegacy/README.md +13 -0
  52. package/src/theme/IdealImageLegacy/components/Icon/Download.js +14 -0
  53. package/src/theme/IdealImageLegacy/components/Icon/Loading.js +14 -0
  54. package/src/theme/IdealImageLegacy/components/Icon/Offline.js +14 -0
  55. package/src/theme/IdealImageLegacy/components/Icon/Warning.js +14 -0
  56. package/src/theme/IdealImageLegacy/components/Icon/index.js +24 -0
  57. package/src/theme/IdealImageLegacy/components/IdealImage/index.js +352 -0
  58. package/src/theme/IdealImageLegacy/components/IdealImage/waypoint.tsx +254 -0
  59. package/src/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +11 -0
  60. package/src/theme/IdealImageLegacy/components/Media/index.js +169 -0
  61. package/src/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
  62. package/src/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +11 -0
  63. package/src/theme/IdealImageLegacy/components/composeStyle.js +37 -0
  64. package/src/theme/IdealImageLegacy/components/constants.js +24 -0
  65. package/src/theme/IdealImageLegacy/components/helpers.js +141 -0
  66. package/src/theme/IdealImageLegacy/components/icons.js +16 -0
  67. package/src/theme/IdealImageLegacy/components/loaders.js +112 -0
  68. package/src/theme/IdealImageLegacy/components/theme.js +26 -0
  69. package/src/theme/IdealImageLegacy/components/theme.module.css +35 -0
  70. package/src/theme/IdealImageLegacy/components/unfetch.js +74 -0
  71. package/src/theme/IdealImageLegacy/index.tsx +3 -0
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # `@docusaurus/plugin-ideal-image`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder).
4
+
5
+ ## Usage
6
+
7
+ See [plugin-ideal-image documentation](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-ideal-image).
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
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 type { LoadContext, Plugin, OptionValidationContext } 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, PluginOptions>): PluginOptions;
package/lib/index.js ADDED
@@ -0,0 +1,75 @@
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.default = pluginIdealImage;
10
+ exports.validateOptions = validateOptions;
11
+ const utils_validation_1 = require("@docusaurus/utils-validation");
12
+ const theme_translations_1 = require("@docusaurus/theme-translations");
13
+ function pluginIdealImage(context, options) {
14
+ const { i18n: { currentLocale }, } = context;
15
+ return {
16
+ name: 'docusaurus-plugin-ideal-image',
17
+ getThemePath() {
18
+ return '../lib/theme';
19
+ },
20
+ getTypeScriptThemePath() {
21
+ return '../src/theme';
22
+ },
23
+ getDefaultCodeTranslationMessages() {
24
+ return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
25
+ locale: currentLocale,
26
+ name: 'plugin-ideal-image',
27
+ });
28
+ },
29
+ configureWebpack(_config, isServer) {
30
+ const { disableInDev, ...loaderOptions } = options;
31
+ if (disableInDev && process.env.NODE_ENV !== 'production') {
32
+ return {};
33
+ }
34
+ return {
35
+ mergeStrategy: {
36
+ 'module.rules': 'prepend',
37
+ },
38
+ module: {
39
+ rules: [
40
+ {
41
+ test: /\.(?:png|jpe?g)$/i,
42
+ with: { type: { not: 'text' } },
43
+ // We don't want to use the image loader for non-React source code
44
+ // ie we don't want to use ideal image loader for CSS files...
45
+ // See https://github.com/facebook/docusaurus/issues/10862
46
+ issuer: {
47
+ and: [/\.(?:tsx?|jsx?|mdx?)$/i],
48
+ },
49
+ use: [
50
+ require.resolve('@docusaurus/lqip-loader'),
51
+ {
52
+ loader: require.resolve('@docusaurus/responsive-loader'),
53
+ options: {
54
+ // Don't emit for server-side rendering
55
+ emitFile: !isServer,
56
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
57
+ adapter: require('@docusaurus/responsive-loader/sharp'),
58
+ name: 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]',
59
+ ...loaderOptions,
60
+ },
61
+ },
62
+ ],
63
+ },
64
+ ],
65
+ },
66
+ };
67
+ },
68
+ };
69
+ }
70
+ function validateOptions({ validate, options, }) {
71
+ const pluginOptionsSchema = utils_validation_1.Joi.object({
72
+ disableInDev: utils_validation_1.Joi.boolean().default(true),
73
+ }).unknown();
74
+ return validate(pluginOptionsSchema, options);
75
+ }
@@ -0,0 +1,9 @@
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 type { ReactNode } from 'react';
8
+ import type { Props } from '@theme/IdealImage';
9
+ export default function IdealImage(props: Props): ReactNode;
@@ -0,0 +1,96 @@
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 {translate} from '@docusaurus/Translate';
8
+ import ReactIdealImage from '@theme/IdealImageLegacy';
9
+ // Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/helpers.js#L59-L65
10
+ function bytesToSize(bytes) {
11
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
12
+ if (bytes === 0) {
13
+ return 'n/a';
14
+ }
15
+ const scale = Math.floor(Math.log(bytes) / Math.log(1024));
16
+ if (scale === 0) {
17
+ return `${bytes} ${sizes[scale]}`;
18
+ }
19
+ return `${(bytes / 1024 ** scale).toFixed(1)} ${sizes[scale]}`;
20
+ }
21
+ // Adopted from https://github.com/endiliey/react-ideal-image/blob/master/src/components/IdealImage/index.js#L43-L75
22
+ function getMessage(icon, state) {
23
+ switch (icon) {
24
+ case 'noicon':
25
+ case 'loaded':
26
+ return null;
27
+ case 'loading':
28
+ return translate({
29
+ id: 'theme.IdealImageMessage.loading',
30
+ message: 'Loading...',
31
+ description: 'When the full-scale image is loading',
32
+ });
33
+ case 'load': {
34
+ // We can show `alt` here
35
+ const {pickedSrc} = state;
36
+ const {size} = pickedSrc;
37
+ const sizeMessage = size ? ` (${bytesToSize(size)})` : '';
38
+ return translate(
39
+ {
40
+ id: 'theme.IdealImageMessage.load',
41
+ message: 'Click to load{sizeMessage}',
42
+ description:
43
+ 'To prompt users to load the full image. sizeMessage is a parenthesized size figure.',
44
+ },
45
+ {sizeMessage},
46
+ );
47
+ }
48
+ case 'offline':
49
+ return translate({
50
+ id: 'theme.IdealImageMessage.offline',
51
+ message: 'Your browser is offline. Image not loaded',
52
+ description: 'When the user is viewing an offline document',
53
+ });
54
+ case 'error': {
55
+ const {loadInfo} = state;
56
+ if (loadInfo === 404) {
57
+ return translate({
58
+ id: 'theme.IdealImageMessage.404error',
59
+ message: '404. Image not found',
60
+ description: 'When the image is not found',
61
+ });
62
+ }
63
+ return translate({
64
+ id: 'theme.IdealImageMessage.error',
65
+ message: 'Error. Click to reload',
66
+ description: 'When the image fails to load for unknown error',
67
+ });
68
+ }
69
+ default:
70
+ throw new Error(`Wrong icon: ${icon}`);
71
+ }
72
+ }
73
+ export default function IdealImage(props) {
74
+ const {img, ...propsRest} = props;
75
+ // In dev env just use regular img with original file
76
+ if (typeof img === 'string' || 'default' in img) {
77
+ return (
78
+ // eslint-disable-next-line jsx-a11y/alt-text
79
+ <img src={typeof img === 'string' ? img : img.default} {...propsRest} />
80
+ );
81
+ }
82
+ return (
83
+ <ReactIdealImage
84
+ {...propsRest}
85
+ height={img.src.height ?? 100}
86
+ width={img.src.width ?? 100}
87
+ placeholder={{lqip: img.preSrc}}
88
+ src={img.src.src}
89
+ srcSet={img.src.images.map((image) => ({
90
+ ...image,
91
+ src: image.path,
92
+ }))}
93
+ getMessage={getMessage}
94
+ />
95
+ );
96
+ }
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2017 stereobooster
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # Legacy React IdealImage lib
2
+
3
+ This is legacy code from an npm package we forked, then internalized
4
+
5
+ See also:
6
+
7
+ - https://github.com/slorber/docusaurus-react-ideal-image
8
+ - https://github.com/endiliey/react-ideal-image
9
+ - https://github.com/stereobooster/react-ideal-image
10
+
11
+ ---
12
+
13
+ TODO: we need to clean it up, remove what we don't need, and maintain it up to date
@@ -0,0 +1,2 @@
1
+ declare const Download: (props: any) => import("react").JSX.Element;
2
+ export default Download;
@@ -0,0 +1,14 @@
1
+ // This icon is from "material design icons"
2
+ // It is licensed under Apache License 2.0
3
+ // Full text is available here
4
+ // https://github.com/google/material-design-icons/blob/master/LICENSE
5
+ import Icon from './index';
6
+
7
+ const Download = (props) => (
8
+ <Icon
9
+ {...props}
10
+ path="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z"
11
+ />
12
+ );
13
+
14
+ export default Download;
@@ -0,0 +1,2 @@
1
+ declare const Loading: (props: any) => import("react").JSX.Element;
2
+ export default Loading;
@@ -0,0 +1,14 @@
1
+ // This icon is from "material design icons"
2
+ // It is licensed under Apache License 2.0
3
+ // Full text is available here
4
+ // https://github.com/google/material-design-icons/blob/master/LICENSE
5
+ import Icon from './index';
6
+
7
+ const Loading = (props) => (
8
+ <Icon
9
+ {...props}
10
+ path="M6,2V8H6V8L10,12L6,16V16H6V22H18V16H18V16L14,12L18,8V8H18V2H6M16,16.5V20H8V16.5L12,12.5L16,16.5M12,11.5L8,7.5V4H16V7.5L12,11.5Z"
11
+ />
12
+ );
13
+
14
+ export default Loading;
@@ -0,0 +1,2 @@
1
+ declare const Offline: (props: any) => import("react").JSX.Element;
2
+ export default Offline;
@@ -0,0 +1,14 @@
1
+ // This icon is from "material design icons"
2
+ // It is licensed under Apache License 2.0
3
+ // Full text is available here
4
+ // https://github.com/google/material-design-icons/blob/master/LICENSE
5
+ import Icon from './index';
6
+
7
+ const Offline = (props) => (
8
+ <Icon
9
+ {...props}
10
+ path="M19.35 10.04C18.67 6.59 15.64 4 12 4c-1.48 0-2.85.43-4.01 1.17l1.46 1.46C10.21 6.23 11.08 6 12 6c3.04 0 5.5 2.46 5.5 5.5v.5H19c1.66 0 3 1.34 3 3 0 1.13-.64 2.11-1.56 2.62l1.45 1.45C23.16 18.16 24 16.68 24 15c0-2.64-2.05-4.78-4.65-4.96zM3 5.27l2.75 2.74C2.56 8.15 0 10.77 0 14c0 3.31 2.69 6 6 6h11.73l2 2L21 20.73 4.27 4 3 5.27zM7.73 10l8 8H6c-2.21 0-4-1.79-4-4s1.79-4 4-4h1.73z"
11
+ />
12
+ );
13
+
14
+ export default Offline;
@@ -0,0 +1,2 @@
1
+ declare const Warning: (props: any) => import("react").JSX.Element;
2
+ export default Warning;
@@ -0,0 +1,14 @@
1
+ // This icon is from "material design icons"
2
+ // It is licensed under Apache License 2.0
3
+ // Full text is available here
4
+ // https://github.com/google/material-design-icons/blob/master/LICENSE
5
+ import Icon from './index';
6
+
7
+ const Warning = (props) => (
8
+ <Icon
9
+ {...props}
10
+ path="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
11
+ />
12
+ );
13
+
14
+ export default Warning;
@@ -0,0 +1,7 @@
1
+ declare const Icon: ({ size, fill, className, path }: {
2
+ className: any;
3
+ fill?: string | undefined;
4
+ path: any;
5
+ size?: number | undefined;
6
+ }) => import("react").JSX.Element;
7
+ export default Icon;
@@ -0,0 +1,24 @@
1
+ // import PropTypes from 'prop-types'
2
+
3
+ const Icon = ({size = 24, fill = '#000', className, path}) => (
4
+ <svg
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ width={size}
7
+ height={size}
8
+ viewBox="0 0 24 24"
9
+ className={className}>
10
+ <path d="M0 0h24v24H0z" fill="none" />
11
+ <path fill={fill} d={path} />
12
+ </svg>
13
+ );
14
+
15
+ /*
16
+ Icon.propTypes = {
17
+ size: PropTypes.number,
18
+ fill: PropTypes.string,
19
+ className: PropTypes.string,
20
+ path: PropTypes.string.isRequired,
21
+ }
22
+ */
23
+
24
+ export default Icon;
@@ -0,0 +1,46 @@
1
+ import { Component } from 'react';
2
+ declare const defaultShouldAutoDownload: ({ connection, size, threshold, possiblySlowNetwork, }: {
3
+ connection: any;
4
+ possiblySlowNetwork: any;
5
+ size: any;
6
+ threshold: any;
7
+ }) => boolean;
8
+ declare const defaultGetMessage: (icon: any, state: any) => "404. Image not found" | "Click to load" | "Error. Click to reload" | "Loading..." | "Your browser is offline. Image not loaded" | (string | import("react").JSX.Element)[] | null;
9
+ declare const defaultGetIcon: (state: any) => string;
10
+ export default class IdealImage extends Component {
11
+ state: {
12
+ loadState: string;
13
+ connection: {
14
+ downlink: any;
15
+ rtt: any;
16
+ effectiveType: any;
17
+ } | null;
18
+ onLine: boolean;
19
+ overThreshold: boolean;
20
+ inViewport: boolean;
21
+ userTriggered: boolean;
22
+ possiblySlowNetwork: boolean;
23
+ };
24
+ updateConnection: (() => void) | undefined;
25
+ possiblySlowNetworkListener: ((e: any) => void) | undefined;
26
+ updateOnlineStatus: (() => void) | undefined;
27
+ loader: Promise<any> | undefined;
28
+ constructor(props: any);
29
+ static defaultProps: {
30
+ shouldAutoDownload: typeof defaultShouldAutoDownload;
31
+ getMessage: typeof defaultGetMessage;
32
+ getIcon: typeof defaultGetIcon;
33
+ loader: string;
34
+ };
35
+ componentDidMount(): void;
36
+ componentWillUnmount(): void;
37
+ onClick: () => void;
38
+ clear(): void;
39
+ cancel(userTriggered: any): void;
40
+ loadStateChange(loadState: any, userTriggered: any, loadInfo?: null): void;
41
+ load: (userTriggered: any) => void;
42
+ onEnter: () => void;
43
+ onLeave: () => void;
44
+ render(): import("react").JSX.Element;
45
+ }
46
+ export {};