react-lazy-load-image-component 1.5.6 → 1.6.1
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/.github/workflows/run-tests.yml +38 -0
- package/CONTRIBUTING.md +72 -0
- package/README.md +11 -5
- package/package.json +3 -5
- package/src/components/LazyLoadImage.jsx +9 -4
- package/src/components/LazyLoadImage.spec.js +4 -2
- package/src/components/PlaceholderWithoutTracking.jsx +1 -2
- package/src/hoc/trackWindowScroll.js +2 -3
- package/build/index.js +0 -1
@@ -0,0 +1,38 @@
|
|
1
|
+
name: Run Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- name: Checkout code
|
17
|
+
uses: actions/checkout@v3
|
18
|
+
|
19
|
+
- name: Set up Node.js
|
20
|
+
uses: actions/setup-node@v3
|
21
|
+
with:
|
22
|
+
node-version: '20'
|
23
|
+
|
24
|
+
- name: Install dependencies
|
25
|
+
run: npm ci
|
26
|
+
|
27
|
+
- name: Run tests
|
28
|
+
run: npm run test
|
29
|
+
|
30
|
+
- name: Check test status
|
31
|
+
run: |
|
32
|
+
if [ $? -ne 0 ]; then
|
33
|
+
echo "Tests failed. Failing the workflow."
|
34
|
+
exit 1
|
35
|
+
else
|
36
|
+
echo "Tests passed."
|
37
|
+
fi
|
38
|
+
|
package/CONTRIBUTING.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Contributing to react-lazy-load-image-component
|
2
|
+
|
3
|
+
Thank you for considering contributing to react-lazy-load-image-component! We appreciate your support and welcome any contributions you can make to enhance the package.
|
4
|
+
|
5
|
+
The following guidelines will help you understand how to contribute effectively:
|
6
|
+
|
7
|
+
## Ways to Contribute
|
8
|
+
|
9
|
+
There are several ways you can contribute to the project:
|
10
|
+
|
11
|
+
1. Report Issues
|
12
|
+
2. Suggest Enhancements
|
13
|
+
3. Answer Open Issues
|
14
|
+
4. Submit Pull Requests
|
15
|
+
|
16
|
+
## Reporting Issues
|
17
|
+
|
18
|
+
If you encounter any issues or bugs while using react-lazy-load-image-component, please help us improve by reporting them. To report an issue, follow these steps:
|
19
|
+
|
20
|
+
1. Check if the issue has already been reported by searching the [GitHub Issues](https://github.com/Aljullu/react-lazy-load-image-component/issues) of the repository.
|
21
|
+
2. If the issue hasn't been reported, click on the "New Issue" button.
|
22
|
+
3. Provide a clear and descriptive title for the issue.
|
23
|
+
4. Describe the steps to reproduce the issue, including any relevant code snippets or error messages.
|
24
|
+
5. Explain the expected behavior and the actual behavior you observed.
|
25
|
+
6. Add any additional information, such as screenshots or environment details, that may be helpful.
|
26
|
+
7. Finally, submit the issue and await further instructions or clarifications.
|
27
|
+
|
28
|
+
## Suggesting Enhancements
|
29
|
+
|
30
|
+
We welcome suggestions for enhancing react-lazy-load-image-component. If you have an idea for a new feature, or you believe an existing feature can be improved, please follow these steps:
|
31
|
+
|
32
|
+
1. Check the [GitHub Issues](https://github.com/Aljullu/react-lazy-load-image-component/issues) of the repository to see if a similar suggestion has already been made.
|
33
|
+
2. If your suggestion hasn't been proposed yet, click on the "New Issue" button.
|
34
|
+
3. Provide a clear and descriptive title for the enhancement.
|
35
|
+
4. Describe the current limitations or problems you're experiencing that your suggested enhancement aims to address.
|
36
|
+
5. Clearly explain how your suggested enhancement would improve the package.
|
37
|
+
6. Include any relevant code examples, if applicable.
|
38
|
+
7. Submit the enhancement suggestion and await further discussion or feedback.
|
39
|
+
|
40
|
+
## Answering Open Issues
|
41
|
+
|
42
|
+
You can contribute to react-lazy-load-image-component by helping to answer open issues in the GitHub repository. This includes:
|
43
|
+
|
44
|
+
- Helping users solve their problems or find workarounds.
|
45
|
+
- Replicating reported bugs and providing additional information or insights.
|
46
|
+
- Sharing your knowledge and expertise to assist other users.
|
47
|
+
|
48
|
+
To contribute in this way, follow these steps:
|
49
|
+
|
50
|
+
1. Visit the [GitHub Issues](https://github.com/Aljullu/react-lazy-load-image-component/issues) page of the repository.
|
51
|
+
2. Look for open issues that you can provide assistance with.
|
52
|
+
3. Read through the issue description and any existing comments to understand the problem or question.
|
53
|
+
4. If you can reproduce the issue, follow the steps provided and document your findings in a comment.
|
54
|
+
5. Offer suggestions, workarounds, or explanations to help resolve the issue.
|
55
|
+
6. Engage in respectful and constructive conversations with the issue reporter and other contributors.
|
56
|
+
|
57
|
+
## Submitting Pull Requests
|
58
|
+
|
59
|
+
We encourage you to contribute directly to the codebase of react-lazy-load-image-component by submitting pull requests (PRs). Follow these steps to submit a PR:
|
60
|
+
|
61
|
+
1. Fork the repository to your GitHub account.
|
62
|
+
2. Create a new branch with a descriptive name for your changes.
|
63
|
+
3. Implement your changes or new features. When developing, you can use `npm run start` and `npm run build` to build your changes.
|
64
|
+
4. Include tests that cover your changes and update the documentation, if applicable.
|
65
|
+
5. Make sure the codebase passes all existing tests (run `npm run test`) and lint checks (`npm run lint`).
|
66
|
+
6. Commit your changes with a clear and concise commit message.
|
67
|
+
7. Push your branch to your forked repository.
|
68
|
+
8. Open a PR against the `master` branch of the original repository.
|
69
|
+
9. Provide a detailed description of your changes in the PR, including the problem or feature addressed.
|
70
|
+
10. Engage in any further discussion or feedback requested on the PR.
|
71
|
+
|
72
|
+
Once your PR is reviewed and approved, it will be merged into the main codebase, and your contributions will become part of react-lazy-load-image-component!
|
package/README.md
CHANGED
@@ -7,10 +7,9 @@ React Lazy Load Image Component
|
|
7
7
|
|
8
8
|
React Component to lazy load images and other components/elements. Supports IntersectionObserver and includes a HOC to track window scroll position to improve performance.
|
9
9
|
|
10
|
-
"[_An easy-to-use performant solution to lazy load images in React_](https://
|
10
|
+
"[_An easy-to-use performant solution to lazy load images in React_](https://medium.com/@albertjuhe/an-easy-to-use-performant-solution-to-lazy-load-images-in-react-e6752071020c)"
|
11
11
|
|
12
12
|
[](https://travis-ci.org/Aljullu/react-lazy-load-image-component)
|
13
|
-
[](http://david-dm.org/Aljullu/react-lazy-load-image-component)
|
14
13
|
[](https://www.npmjs.com/package/react-lazy-load-image-component)
|
15
14
|
[](https://www.npmjs.com/package/react-lazy-load-image-component)
|
16
15
|
|
@@ -24,7 +23,7 @@ React Component to lazy load images and other components/elements. Supports Inte
|
|
24
23
|
* A custom placeholder component or image can be specified.
|
25
24
|
* Built-in on-visible effects (blur, black and white and opacity transitions).
|
26
25
|
* threshold is set to 100px by default and can be modified.
|
27
|
-
* `beforeLoad` and `
|
26
|
+
* `beforeLoad` and `onLoad` events.
|
28
27
|
* `debounce` and `throttle` included by default and configurable.
|
29
28
|
* Uses IntersectionObserver for browsers that support it.
|
30
29
|
* Server Side Rendering (SSR) compatible.
|
@@ -66,7 +65,8 @@ export default MyImage;
|
|
66
65
|
|
67
66
|
| Prop | Type | Default | Description |
|
68
67
|
|:---|:---|:---|:---|
|
69
|
-
|
|
68
|
+
| onLoad | `Function` | | Function called when the image has been loaded. This is the same function as the `onLoad` of an `<img>` which contains an event object. |
|
69
|
+
| afterLoad | `Function` | | Deprecated, use `onLoad` instead. This prop is only for backward compatibility. |
|
70
70
|
| beforeLoad | `Function` | | Function called right before the placeholder is replaced with the image element. |
|
71
71
|
| delayMethod | `String` | `throttle` | Method from lodash to use to delay the scroll/resize events. It can be `throttle` or `debounce`. |
|
72
72
|
| delayTime | `Number` | 300 | Time in ms sent to the delayMethod. |
|
@@ -96,6 +96,10 @@ const MyImage = ({ image }) => (
|
|
96
96
|
<LazyLoadImage
|
97
97
|
alt={image.alt}
|
98
98
|
effect="blur"
|
99
|
+
wrapperProps={{
|
100
|
+
// If you need to, you can tweak the effect transition using the wrapper style.
|
101
|
+
style: {transitionDelay: "1s"},
|
102
|
+
}}
|
99
103
|
src={image.src} />
|
100
104
|
);
|
101
105
|
```
|
@@ -114,6 +118,7 @@ The current available effects are:
|
|
114
118
|
|
115
119
|

|
116
120
|
|
121
|
+
All the effects have a transition duration of 0.3 seconds by default, without transition delay and the default transition timing function. All those values can be modified overriding the wrapper style as shown in the code example above.
|
117
122
|
|
118
123
|
## `LazyLoadComponent` usage
|
119
124
|
|
@@ -188,7 +193,8 @@ You must set the prop `scrollPosition` to the lazy load components. This way, th
|
|
188
193
|
| Prop | Type | Default | Description |
|
189
194
|
|:---|:---|:---|:---|
|
190
195
|
| scrollPosition | `Object` | | Object containing `x` and `y` with the curent window scroll position. Required. |
|
191
|
-
|
|
196
|
+
| onLoad | `Function` | | Function called when the image has been loaded. This is the same function as the `onLoad` of an `<img>` which contains an event object. |
|
197
|
+
| afterLoad | `Function` | | Deprecated, use `onLoad` instead. This prop is only for backward compatibility. |
|
192
198
|
| beforeLoad | `Function` | | Function called right before the image is rendered. |
|
193
199
|
| placeholder | `ReactClass` | `<span>` | React element to use as a placeholder. |
|
194
200
|
| threshold | `Number` | 100 | Threshold in pixels. So the image starts loading before it appears in the viewport. |
|
package/package.json
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-lazy-load-image-component",
|
3
|
-
"version": "1.
|
4
|
-
"description": "
|
3
|
+
"version": "1.6.1",
|
4
|
+
"description": "React Component to lazy load images using a HOC to track window scroll position.",
|
5
5
|
"main": "build/index.js",
|
6
6
|
"peerDependencies": {
|
7
|
-
"react": "^15.x.x || ^16.x.x || ^17.x.x || ^18.x.x"
|
8
|
-
"react-dom": "^15.x.x || ^16.x.x || ^17.x.x || ^18.x.x"
|
7
|
+
"react": "^15.x.x || ^16.x.x || ^17.x.x || ^18.x.x"
|
9
8
|
},
|
10
9
|
"dependencies": {
|
11
10
|
"lodash.debounce": "^4.0.8",
|
@@ -31,7 +30,6 @@
|
|
31
30
|
"path": "^0.12.7",
|
32
31
|
"prettier": "^2.3.2",
|
33
32
|
"react": "^16.2.0",
|
34
|
-
"react-dom": "^16.2.0",
|
35
33
|
"style-loader": "^3.2.1",
|
36
34
|
"webpack": "^5.50.0",
|
37
35
|
"webpack-cli": "^4.7.2"
|
@@ -17,7 +17,10 @@ class LazyLoadImage extends React.Component {
|
|
17
17
|
return null;
|
18
18
|
}
|
19
19
|
|
20
|
-
return
|
20
|
+
return e => {
|
21
|
+
// We keep support for afterLoad for backwards compatibility,
|
22
|
+
// but `onLoad` is the preferred prop.
|
23
|
+
this.props.onLoad(e);
|
21
24
|
this.props.afterLoad();
|
22
25
|
|
23
26
|
this.setState({
|
@@ -44,7 +47,7 @@ class LazyLoadImage extends React.Component {
|
|
44
47
|
...imgProps
|
45
48
|
} = this.props;
|
46
49
|
|
47
|
-
return <img onLoad={this.onImageLoad()}
|
50
|
+
return <img {...imgProps} onLoad={this.onImageLoad()} />;
|
48
51
|
}
|
49
52
|
|
50
53
|
getLazyLoadImage() {
|
@@ -146,7 +149,8 @@ class LazyLoadImage extends React.Component {
|
|
146
149
|
}
|
147
150
|
|
148
151
|
LazyLoadImage.propTypes = {
|
149
|
-
|
152
|
+
onLoad: PropTypes.func,
|
153
|
+
afterLoad: PropTypes.func, // Deprecated, use onLoad instead
|
150
154
|
beforeLoad: PropTypes.func,
|
151
155
|
delayMethod: PropTypes.string,
|
152
156
|
delayTime: PropTypes.number,
|
@@ -160,7 +164,8 @@ LazyLoadImage.propTypes = {
|
|
160
164
|
};
|
161
165
|
|
162
166
|
LazyLoadImage.defaultProps = {
|
163
|
-
|
167
|
+
onLoad: () => {},
|
168
|
+
afterLoad: () => ({}), // Deprecated, use onLoad instead
|
164
169
|
beforeLoad: () => ({}),
|
165
170
|
delayMethod: 'throttle',
|
166
171
|
delayTime: 300,
|
@@ -67,9 +67,10 @@ describe('LazyLoadImage', function() {
|
|
67
67
|
expect(img.src).toEqual(props.src);
|
68
68
|
});
|
69
69
|
|
70
|
-
it('updates state and calls afterLoad when img triggers onLoad', function() {
|
70
|
+
it('updates state and calls onLoad and afterLoad when img triggers onLoad', function() {
|
71
71
|
const afterLoad = jest.fn();
|
72
|
-
const
|
72
|
+
const onLoad = jest.fn();
|
73
|
+
const lazyLoadImage = mount(<LazyLoadImage onLoad={onLoad} afterLoad={afterLoad} />);
|
73
74
|
|
74
75
|
const img = findRenderedDOMComponentWithTag(
|
75
76
|
lazyLoadImage.instance(),
|
@@ -80,6 +81,7 @@ describe('LazyLoadImage', function() {
|
|
80
81
|
|
81
82
|
expect(lazyLoadImage.instance().state.loaded);
|
82
83
|
expect(afterLoad).toHaveBeenCalledTimes(1);
|
84
|
+
expect(onLoad).toHaveBeenCalledTimes(1);
|
83
85
|
});
|
84
86
|
|
85
87
|
it('sets loaded class to wrapper when img triggers onLoad', function() {
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import ReactDOM from 'react-dom';
|
3
2
|
import { PropTypes } from 'prop-types';
|
4
3
|
import isIntersectionObserverAvailable from '../utils/intersection-observer';
|
5
4
|
|
@@ -64,7 +63,7 @@ class PlaceholderWithoutTracking extends React.Component {
|
|
64
63
|
|
65
64
|
getPlaceholderBoundingBox(scrollPosition = this.props.scrollPosition) {
|
66
65
|
const boundingRect = this.placeholder.getBoundingClientRect();
|
67
|
-
const style =
|
66
|
+
const style = this.placeholder.style;
|
68
67
|
const margin = {
|
69
68
|
left: parseInt(style.getPropertyValue('margin-left'), 10) || 0,
|
70
69
|
top: parseInt(style.getPropertyValue('margin-top'), 10) || 0,
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import ReactDom from 'react-dom';
|
3
2
|
import { PropTypes } from 'prop-types';
|
4
3
|
import debounce from 'lodash.debounce';
|
5
4
|
import throttle from 'lodash.throttle';
|
@@ -55,7 +54,7 @@ const trackWindowScroll = BaseComponent => {
|
|
55
54
|
}
|
56
55
|
|
57
56
|
const scrollElement = getScrollAncestor(
|
58
|
-
|
57
|
+
this.baseComponentRef.current
|
59
58
|
);
|
60
59
|
|
61
60
|
if (scrollElement !== this.scrollElement) {
|
@@ -70,7 +69,7 @@ const trackWindowScroll = BaseComponent => {
|
|
70
69
|
}
|
71
70
|
|
72
71
|
this.scrollElement = getScrollAncestor(
|
73
|
-
|
72
|
+
this.baseComponentRef.current
|
74
73
|
);
|
75
74
|
|
76
75
|
this.scrollElement.addEventListener('scroll', this.delayedScroll, {
|
package/build/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
(()=>{var e={296:(e,t,r)=>{var o=/^\s+|\s+$/g,n=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,c=/^0o[0-7]+$/i,s=parseInt,u="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g,l="object"==typeof self&&self&&self.Object===Object&&self,a=u||l||Function("return this")(),f=Object.prototype.toString,p=Math.max,y=Math.min,d=function(){return a.Date.now()};function b(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function h(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==f.call(e)}(e))return NaN;if(b(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=b(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(o,"");var r=i.test(e);return r||c.test(e)?s(e.slice(2),r?2:8):n.test(e)?NaN:+e}e.exports=function(e,t,r){var o,n,i,c,s,u,l=0,a=!1,f=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function m(t){var r=o,i=n;return o=n=void 0,l=t,c=e.apply(i,r)}function O(e){return l=e,s=setTimeout(g,t),a?m(e):c}function w(e){var r=e-u;return void 0===u||r>=t||r<0||f&&e-l>=i}function g(){var e=d();if(w(e))return P(e);s=setTimeout(g,function(e){var r=t-(e-u);return f?y(r,i-(e-l)):r}(e))}function P(e){return s=void 0,v&&o?m(e):(o=n=void 0,c)}function j(){var e=d(),r=w(e);if(o=arguments,n=this,u=e,r){if(void 0===s)return O(u);if(f)return s=setTimeout(g,t),m(u)}return void 0===s&&(s=setTimeout(g,t)),c}return t=h(t)||0,b(r)&&(a=!!r.leading,i=(f="maxWait"in r)?p(h(r.maxWait)||0,t):i,v="trailing"in r?!!r.trailing:v),j.cancel=function(){void 0!==s&&clearTimeout(s),l=0,o=u=n=s=void 0},j.flush=function(){return void 0===s?c:P(d())},j}},96:(e,t,r)=>{var o="Expected a function",n=/^\s+|\s+$/g,i=/^[-+]0x[0-9a-f]+$/i,c=/^0b[01]+$/i,s=/^0o[0-7]+$/i,u=parseInt,l="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g,a="object"==typeof self&&self&&self.Object===Object&&self,f=l||a||Function("return this")(),p=Object.prototype.toString,y=Math.max,d=Math.min,b=function(){return f.Date.now()};function h(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function v(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==p.call(e)}(e))return NaN;if(h(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=h(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(n,"");var r=c.test(e);return r||s.test(e)?u(e.slice(2),r?2:8):i.test(e)?NaN:+e}e.exports=function(e,t,r){var n=!0,i=!0;if("function"!=typeof e)throw new TypeError(o);return h(r)&&(n="leading"in r?!!r.leading:n,i="trailing"in r?!!r.trailing:i),function(e,t,r){var n,i,c,s,u,l,a=0,f=!1,p=!1,m=!0;if("function"!=typeof e)throw new TypeError(o);function O(t){var r=n,o=i;return n=i=void 0,a=t,s=e.apply(o,r)}function w(e){return a=e,u=setTimeout(P,t),f?O(e):s}function g(e){var r=e-l;return void 0===l||r>=t||r<0||p&&e-a>=c}function P(){var e=b();if(g(e))return j(e);u=setTimeout(P,function(e){var r=t-(e-l);return p?d(r,c-(e-a)):r}(e))}function j(e){return u=void 0,m&&n?O(e):(n=i=void 0,s)}function T(){var e=b(),r=g(e);if(n=arguments,i=this,l=e,r){if(void 0===u)return w(l);if(p)return u=setTimeout(P,t),O(l)}return void 0===u&&(u=setTimeout(P,t)),s}return t=v(t)||0,h(r)&&(f=!!r.leading,c=(p="maxWait"in r)?y(v(r.maxWait)||0,t):c,m="trailing"in r?!!r.trailing:m),T.cancel=function(){void 0!==u&&clearTimeout(u),a=0,n=l=i=u=void 0},T.flush=function(){return void 0===u?s:j(b())},T}(e,t,{leading:n,maxWait:t,trailing:i})}},703:(e,t,r)=>{"use strict";var o=r(414);function n(){}function i(){}i.resetWarningCache=n,e.exports=function(){function e(e,t,r,n,i,c){if(c!==o){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:n};return r.PropTypes=r,r}},697:(e,t,r)=>{e.exports=r(703)()},414:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";r.r(o),r.d(o,{LazyLoadComponent:()=>J,LazyLoadImage:()=>ue,trackWindowScroll:()=>C});const e=require("react");var t=r.n(e),n=r(697);const i=require("react-dom");var c=r.n(i);function s(){return"undefined"!=typeof window&&"IntersectionObserver"in window&&"isIntersecting"in window.IntersectionObserverEntry.prototype}function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function f(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function p(e,t){return(p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function y(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var b=function(e){e.forEach((function(e){e.isIntersecting&&e.target.onVisible()}))},h={},v=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&p(e,t)}(v,e);var r,o,n,i,u=(n=v,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=d(n);if(i){var r=d(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return y(this,e)});function v(e){var t;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,v),(t=u.call(this,e)).supportsObserver=!e.scrollPosition&&e.useIntersectionObserver&&s(),t.supportsObserver){var r=e.threshold;t.observer=function(e){return h[e]=h[e]||new IntersectionObserver(b,{rootMargin:e+"px"}),h[e]}(r)}return t}return r=v,(o=[{key:"componentDidMount",value:function(){this.placeholder&&this.observer&&(this.placeholder.onVisible=this.props.onVisible,this.observer.observe(this.placeholder)),this.supportsObserver||this.updateVisibility()}},{key:"componentWillUnmount",value:function(){this.observer&&this.placeholder&&this.observer.unobserve(this.placeholder)}},{key:"componentDidUpdate",value:function(){this.supportsObserver||this.updateVisibility()}},{key:"getPlaceholderBoundingBox",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props.scrollPosition,t=this.placeholder.getBoundingClientRect(),r=c().findDOMNode(this.placeholder).style,o={left:parseInt(r.getPropertyValue("margin-left"),10)||0,top:parseInt(r.getPropertyValue("margin-top"),10)||0};return{bottom:e.y+t.bottom+o.top,left:e.x+t.left+o.left,right:e.x+t.right+o.left,top:e.y+t.top+o.top}}},{key:"isPlaceholderInViewport",value:function(){if("undefined"==typeof window||!this.placeholder)return!1;var e=this.props,t=e.scrollPosition,r=e.threshold,o=this.getPlaceholderBoundingBox(t),n=t.y+window.innerHeight,i=t.x,c=t.x+window.innerWidth,s=t.y;return Boolean(s-r<=o.bottom&&n+r>=o.top&&i-r<=o.right&&c+r>=o.left)}},{key:"updateVisibility",value:function(){this.isPlaceholderInViewport()&&this.props.onVisible()}},{key:"render",value:function(){var e=this,r=this.props,o=r.className,n=r.height,i=r.placeholder,c=r.style,s=r.width;if(i&&"function"!=typeof i.type)return t().cloneElement(i,{ref:function(t){return e.placeholder=t}});var u=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({display:"inline-block"},c);return void 0!==s&&(u.width=s),void 0!==n&&(u.height=n),t().createElement("span",{className:o,ref:function(t){return e.placeholder=t},style:u},i)}}])&&f(r.prototype,o),v}(t().Component);v.propTypes={onVisible:n.PropTypes.func.isRequired,className:n.PropTypes.string,height:n.PropTypes.oneOfType([n.PropTypes.number,n.PropTypes.string]),placeholder:n.PropTypes.element,threshold:n.PropTypes.number,useIntersectionObserver:n.PropTypes.bool,scrollPosition:n.PropTypes.shape({x:n.PropTypes.number.isRequired,y:n.PropTypes.number.isRequired}),width:n.PropTypes.oneOfType([n.PropTypes.number,n.PropTypes.string])},v.defaultProps={className:"",placeholder:null,threshold:100,useIntersectionObserver:!0};const m=v;var O=r(296),w=r.n(O),g=r(96),P=r.n(g),j=function(e){var t=getComputedStyle(e,null);return t.getPropertyValue("overflow")+t.getPropertyValue("overflow-y")+t.getPropertyValue("overflow-x")};const T=function(e){if(!(e instanceof HTMLElement))return window;for(var t=e;t&&t instanceof HTMLElement;){if(/(scroll|auto)/.test(j(t)))return t;t=t.parentNode}return window};function S(e){return(S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var E=["delayMethod","delayTime"];function _(){return(_=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}function I(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function L(e,t){return(L=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function x(e,t){if(t&&("object"===S(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return R(e)}function R(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function k(e){return(k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var D=function(){return"undefined"==typeof window?0:window.scrollX||window.pageXOffset},N=function(){return"undefined"==typeof window?0:window.scrollY||window.pageYOffset};const C=function(e){var r=function(r){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&L(e,t)}(a,r);var o,n,i,u,l=(i=a,u=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=k(i);if(u){var r=k(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return x(this,e)});function a(e){var r;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),(r=l.call(this,e)).useIntersectionObserver=e.useIntersectionObserver&&s(),r.useIntersectionObserver)return x(r);var o=r.onChangeScroll.bind(R(r));return"debounce"===e.delayMethod?r.delayedScroll=w()(o,e.delayTime):"throttle"===e.delayMethod&&(r.delayedScroll=P()(o,e.delayTime)),r.state={scrollPosition:{x:D(),y:N()}},r.baseComponentRef=t().createRef(),r}return o=a,(n=[{key:"componentDidMount",value:function(){this.addListeners()}},{key:"componentWillUnmount",value:function(){this.removeListeners()}},{key:"componentDidUpdate",value:function(){"undefined"==typeof window||this.useIntersectionObserver||T(c().findDOMNode(this.baseComponentRef.current))!==this.scrollElement&&(this.removeListeners(),this.addListeners())}},{key:"addListeners",value:function(){"undefined"==typeof window||this.useIntersectionObserver||(this.scrollElement=T(c().findDOMNode(this.baseComponentRef.current)),this.scrollElement.addEventListener("scroll",this.delayedScroll,{passive:!0}),window.addEventListener("resize",this.delayedScroll,{passive:!0}),this.scrollElement!==window&&window.addEventListener("scroll",this.delayedScroll,{passive:!0}))}},{key:"removeListeners",value:function(){"undefined"==typeof window||this.useIntersectionObserver||(this.scrollElement.removeEventListener("scroll",this.delayedScroll),window.removeEventListener("resize",this.delayedScroll),this.scrollElement!==window&&window.removeEventListener("scroll",this.delayedScroll))}},{key:"onChangeScroll",value:function(){this.useIntersectionObserver||this.setState({scrollPosition:{x:D(),y:N()}})}},{key:"render",value:function(){var r=this.props,o=(r.delayMethod,r.delayTime,function(e,t){if(null==e)return{};var r,o,n=function(e,t){if(null==e)return{};var r,o,n={},i=Object.keys(e);for(o=0;o<i.length;o++)r=i[o],t.indexOf(r)>=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}(r,E)),n=this.useIntersectionObserver?null:this.state.scrollPosition;return t().createElement(e,_({forwardRef:this.baseComponentRef,scrollPosition:n},o))}}])&&I(o.prototype,n),a}(t().Component);return r.propTypes={delayMethod:n.PropTypes.oneOf(["debounce","throttle"]),delayTime:n.PropTypes.number,useIntersectionObserver:n.PropTypes.bool},r.defaultProps={delayMethod:"throttle",delayTime:300,useIntersectionObserver:!0},r};function M(e){return(M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function B(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function V(e,t){return(V=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function W(e,t){if(t&&("object"===M(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function z(e){return(z=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var $=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&V(e,t)}(s,e);var r,o,n,i,c=(n=s,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=z(n);if(i){var r=z(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return W(this,e)});function s(e){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),c.call(this,e)}return r=s,(o=[{key:"render",value:function(){return t().createElement(m,this.props)}}])&&B(r.prototype,o),s}(t().Component);const U=C($);function q(e){return(q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function F(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function H(e,t){return(H=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Y(e,t){if(t&&("object"===q(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return X(e)}function X(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function A(e){return(A=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var G=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&H(e,t)}(u,e);var r,o,n,i,c=(n=u,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=A(n);if(i){var r=A(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return Y(this,e)});function u(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),t=c.call(this,e);var r=e.afterLoad,o=e.beforeLoad,n=e.scrollPosition,i=e.visibleByDefault;return t.state={visible:i},i&&(o(),r()),t.onVisible=t.onVisible.bind(X(t)),t.isScrollTracked=Boolean(n&&Number.isFinite(n.x)&&n.x>=0&&Number.isFinite(n.y)&&n.y>=0),t}return r=u,(o=[{key:"componentDidUpdate",value:function(e,t){t.visible!==this.state.visible&&this.props.afterLoad()}},{key:"onVisible",value:function(){this.props.beforeLoad(),this.setState({visible:!0})}},{key:"render",value:function(){if(this.state.visible)return this.props.children;var e=this.props,r=e.className,o=e.delayMethod,n=e.delayTime,i=e.height,c=e.placeholder,u=e.scrollPosition,l=e.style,a=e.threshold,f=e.useIntersectionObserver,p=e.width;return this.isScrollTracked||f&&s()?t().createElement(m,{className:r,height:i,onVisible:this.onVisible,placeholder:c,scrollPosition:u,style:l,threshold:a,useIntersectionObserver:f,width:p}):t().createElement(U,{className:r,delayMethod:o,delayTime:n,height:i,onVisible:this.onVisible,placeholder:c,style:l,threshold:a,width:p})}}])&&F(r.prototype,o),u}(t().Component);G.propTypes={afterLoad:n.PropTypes.func,beforeLoad:n.PropTypes.func,useIntersectionObserver:n.PropTypes.bool,visibleByDefault:n.PropTypes.bool},G.defaultProps={afterLoad:function(){return{}},beforeLoad:function(){return{}},useIntersectionObserver:!0,visibleByDefault:!1};const J=G;function K(e){return(K="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var Q=["afterLoad","beforeLoad","delayMethod","delayTime","effect","placeholder","placeholderSrc","scrollPosition","threshold","useIntersectionObserver","visibleByDefault","wrapperClassName","wrapperProps"];function Z(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function ee(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Z(Object(r),!0).forEach((function(t){te(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Z(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function te(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function re(){return(re=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}function oe(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function ne(e,t){return(ne=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function ie(e,t){if(t&&("object"===K(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function ce(e){return(ce=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var se=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&ne(e,t)}(s,e);var r,o,n,i,c=(n=s,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=ce(n);if(i){var r=ce(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return ie(this,e)});function s(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),(t=c.call(this,e)).state={loaded:!1},t}return r=s,(o=[{key:"onImageLoad",value:function(){var e=this;return this.state.loaded?null:function(){e.props.afterLoad(),e.setState({loaded:!0})}}},{key:"getImg",value:function(){var e=this.props,r=(e.afterLoad,e.beforeLoad,e.delayMethod,e.delayTime,e.effect,e.placeholder,e.placeholderSrc,e.scrollPosition,e.threshold,e.useIntersectionObserver,e.visibleByDefault,e.wrapperClassName,e.wrapperProps,function(e,t){if(null==e)return{};var r,o,n=function(e,t){if(null==e)return{};var r,o,n={},i=Object.keys(e);for(o=0;o<i.length;o++)r=i[o],t.indexOf(r)>=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}(e,Q));return t().createElement("img",re({onLoad:this.onImageLoad()},r))}},{key:"getLazyLoadImage",value:function(){var e=this.props,r=e.beforeLoad,o=e.className,n=e.delayMethod,i=e.delayTime,c=e.height,s=e.placeholder,u=e.scrollPosition,l=e.style,a=e.threshold,f=e.useIntersectionObserver,p=e.visibleByDefault,y=e.width;return t().createElement(J,{beforeLoad:r,className:o,delayMethod:n,delayTime:i,height:c,placeholder:s,scrollPosition:u,style:l,threshold:a,useIntersectionObserver:f,visibleByDefault:p,width:y},this.getImg())}},{key:"getWrappedLazyLoadImage",value:function(e){var r=this.props,o=r.effect,n=r.height,i=r.placeholderSrc,c=r.width,s=r.wrapperClassName,u=r.wrapperProps,l=this.state.loaded,a=l?" lazy-load-image-loaded":"",f=l||!i?{}:{backgroundImage:"url(".concat(i,")"),backgroundSize:"100% 100%"};return t().createElement("span",re({className:s+" lazy-load-image-background "+o+a,style:ee(ee({},f),{},{color:"transparent",display:"inline-block",height:n,width:c})},u),e)}},{key:"render",value:function(){var e=this.props,t=e.effect,r=e.placeholderSrc,o=e.visibleByDefault,n=e.wrapperClassName,i=e.wrapperProps,c=this.getLazyLoadImage();return(t||r)&&!o||n||i?this.getWrappedLazyLoadImage(c):c}}])&&oe(r.prototype,o),s}(t().Component);se.propTypes={afterLoad:n.PropTypes.func,beforeLoad:n.PropTypes.func,delayMethod:n.PropTypes.string,delayTime:n.PropTypes.number,effect:n.PropTypes.string,placeholderSrc:n.PropTypes.string,threshold:n.PropTypes.number,useIntersectionObserver:n.PropTypes.bool,visibleByDefault:n.PropTypes.bool,wrapperClassName:n.PropTypes.string,wrapperProps:n.PropTypes.object},se.defaultProps={afterLoad:function(){return{}},beforeLoad:function(){return{}},delayMethod:"throttle",delayTime:300,effect:"",placeholderSrc:null,threshold:100,useIntersectionObserver:!0,visibleByDefault:!1,wrapperClassName:""};const ue=se})(),module.exports=o})();
|