html-reporter 8.4.4 → 9.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 (45) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +9 -1
  3. package/lib/config/index.js +17 -6
  4. package/lib/constants/defaults.js +2 -1
  5. package/lib/constants/diff-modes.js +32 -0
  6. package/lib/server-utils.js +1 -1
  7. package/lib/static/components/controls/common-controls.js +17 -15
  8. package/lib/static/components/controls/control-select/index.js +50 -0
  9. package/lib/static/components/controls/control-select/index.styl +44 -0
  10. package/lib/static/components/controls/controls.less +0 -31
  11. package/lib/static/components/icons/arrows-move.js +24 -0
  12. package/lib/static/components/modals/screenshot-accepter/body.js +4 -12
  13. package/lib/static/components/modals/screenshot-accepter/header.js +3 -32
  14. package/lib/static/components/state/index.js +2 -9
  15. package/lib/static/components/state/{diff-circle.js → screenshot/diff-circle.js} +1 -1
  16. package/lib/static/components/state/screenshot/full.js +28 -0
  17. package/lib/static/components/state/{screenshot.js → screenshot/resized.js} +28 -30
  18. package/lib/static/components/state/screenshot/with-encode-uri.js +44 -0
  19. package/lib/static/components/state/screenshot/with-synced-scale.js +116 -0
  20. package/lib/static/components/state/state-error.js +3 -3
  21. package/lib/static/components/state/state-fail/index.js +142 -0
  22. package/lib/static/components/state/state-fail/index.styl +31 -0
  23. package/lib/static/components/state/state-fail/onion-skin-diff/index.js +43 -0
  24. package/lib/static/components/state/state-fail/onion-skin-diff/index.styl +19 -0
  25. package/lib/static/components/state/state-fail/prop-types.js +16 -0
  26. package/lib/static/components/state/state-fail/swipe-diff/index.js +138 -0
  27. package/lib/static/components/state/state-fail/swipe-diff/index.styl +82 -0
  28. package/lib/static/components/state/state-fail/switch-diff/index.js +36 -0
  29. package/lib/static/components/state/state-fail/switch-diff/index.styl +12 -0
  30. package/lib/static/components/state/state-success.js +2 -2
  31. package/lib/static/gui.min.css +192 -27
  32. package/lib/static/gui.min.js +16 -16
  33. package/lib/static/modules/action-names.js +6 -2
  34. package/lib/static/modules/actions.js +27 -3
  35. package/lib/static/modules/default-state.js +2 -2
  36. package/lib/static/modules/middlewares/local-storage.js +1 -2
  37. package/lib/static/modules/middlewares/metrika.js +6 -2
  38. package/lib/static/modules/reducers/view.js +27 -12
  39. package/lib/static/report.min.css +192 -27
  40. package/lib/static/report.min.js +16 -16
  41. package/lib/static/styles.css +3 -11
  42. package/package.json +3 -1
  43. package/webpack.common.js +7 -0
  44. package/lib/static/components/controls/view-select.js +0 -50
  45. package/lib/static/components/state/state-fail.js +0 -56
@@ -2,10 +2,11 @@
2
2
 
3
3
  import React, {Component, Fragment} from 'react';
4
4
  import PropTypes from 'prop-types';
5
+ import classNames from 'classnames';
5
6
  import DiffCircle from './diff-circle';
6
- import {isUrl} from '../../../common-utils';
7
+ import withEncodeUri from './with-encode-uri';
7
8
 
8
- export default class Screenshot extends Component {
9
+ class ResizedScreenshot extends Component {
9
10
  constructor(props) {
10
11
  super(props);
11
12
 
@@ -24,11 +25,9 @@ export default class Screenshot extends Component {
24
25
  height: PropTypes.number
25
26
  })
26
27
  }).isRequired,
27
- diffClusters: PropTypes.array
28
- }
29
-
30
- static defaultProps = {
31
- noCache: false
28
+ diffClusters: PropTypes.array,
29
+ // from withEncodeUri
30
+ imageUrl: PropTypes.string.isRequired
32
31
  }
33
32
 
34
33
  _getScreenshotComponent(elem, diffClusters) {
@@ -54,38 +53,37 @@ export default class Screenshot extends Component {
54
53
  }
55
54
 
56
55
  render() {
57
- const {noCache, image: {path: imgPath, size: imgSize}, diffClusters} = this.props;
58
-
59
- const url = noCache
60
- ? addTimestamp(encodeUri(imgPath))
61
- : encodeUri(imgPath);
56
+ const {imageUrl, image: {size: imgSize}, diffClusters, style} = this.props;
57
+ const cursorStyle = diffClusters ? {cursor: 'pointer'} : {};
62
58
 
63
59
  if (!imgSize) {
64
- const elem = <div className="image-box__screenshot-container image-box__screenshot-container_auto-size"><img src={url} style={{width: '100%', height: '100%'}}/></div>;
60
+ const elem = (
61
+ <div className="image-box__screenshot-container image-box__screenshot-container_auto-size">
62
+ <img src={imageUrl} style={{width: '100%', height: '100%', style, ...cursorStyle}}/>
63
+ </div>
64
+ );
65
65
 
66
66
  return this._getScreenshotComponent(elem, diffClusters);
67
67
  }
68
68
 
69
+ const imgClassNames = classNames(
70
+ 'image-box__screenshot',
71
+ this.props.className
72
+ );
73
+
69
74
  const paddingTop = ((imgSize.height / imgSize.width) * 100).toFixed(2);
70
- const elem = <div onClick={diffClusters && this._handleDiffClick(diffClusters)} className="image-box__screenshot-container image-box__screenshot-container_fixed-size" style={{width: imgSize.width, paddingTop: `${paddingTop}%`}}><img src={url} className="image-box__screenshot"/></div>;
75
+ const elem = (
76
+ <div
77
+ onClick={diffClusters && this._handleDiffClick(diffClusters)}
78
+ className="image-box__screenshot-container image-box__screenshot-container_fixed-size"
79
+ style={{width: imgSize.width, paddingTop: `${paddingTop}%`}}
80
+ >
81
+ <img src={imageUrl} className={imgClassNames} style={{...style, ...cursorStyle}} />
82
+ </div>
83
+ );
71
84
 
72
85
  return this._getScreenshotComponent(elem, diffClusters);
73
86
  }
74
87
  }
75
88
 
76
- function encodeUri(imagePath) {
77
- if (isUrl(imagePath)) {
78
- return imagePath;
79
- }
80
-
81
- return imagePath
82
- // we can't use path.sep here because on Windows browser returns '/' instead of '\\'
83
- .split(/\/|\\/)
84
- .map((item) => encodeURIComponent(item))
85
- .join('/');
86
- }
87
-
88
- // for prevent image caching
89
- function addTimestamp(imagePath) {
90
- return `${imagePath}?t=${Date.now()}`;
91
- }
89
+ export default withEncodeUri(ResizedScreenshot);
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {isUrl} from '../../../../common-utils';
4
+
5
+ // for prevent image caching
6
+ function addTimestamp(imagePath) {
7
+ return `${imagePath}?t=${Date.now()}`;
8
+ }
9
+
10
+ function encodeUri(imagePath) {
11
+ if (isUrl(imagePath)) {
12
+ return imagePath;
13
+ }
14
+
15
+ return imagePath
16
+ // we can't use path.sep here because on Windows browser returns '/' instead of '\\'
17
+ .split(/\/|\\/)
18
+ .map((item) => encodeURIComponent(item))
19
+ .join('/');
20
+ }
21
+
22
+ function withEncodeUri(ScreenshotComponent) {
23
+ return function wrapper(props) {
24
+ const {noCache, image: {path: imgPath}} = props;
25
+
26
+ const imageUrl = noCache
27
+ ? addTimestamp(encodeUri(imgPath))
28
+ : encodeUri(imgPath);
29
+
30
+ return <ScreenshotComponent
31
+ imageUrl={imageUrl}
32
+ {...props}
33
+ />;
34
+ };
35
+ }
36
+
37
+ withEncodeUri.propTypes = {
38
+ noCache: PropTypes.bool,
39
+ image: PropTypes.shape({
40
+ path: PropTypes.string.isRequired
41
+ }).isRequired
42
+ };
43
+
44
+ export default withEncodeUri;
@@ -0,0 +1,116 @@
1
+ import React, {Component} from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ResizeObserver from 'rc-resize-observer';
4
+
5
+ export default (WrappedComponent) => class WithSyncedScale extends Component {
6
+ static propTypes = {
7
+ image1: PropTypes.shape({
8
+ size: PropTypes.shape({
9
+ width: PropTypes.number,
10
+ height: PropTypes.number
11
+ })
12
+ }).isRequired,
13
+ image2: PropTypes.shape({
14
+ size: PropTypes.shape({
15
+ width: PropTypes.number,
16
+ height: PropTypes.number
17
+ })
18
+ }).isRequired
19
+ }
20
+
21
+ constructor(props) {
22
+ super(props);
23
+
24
+ const {image1, image2} = props;
25
+
26
+ this._scaleFactor = 1;
27
+ this._shouldScale = image1.size.width !== image2.size.width;
28
+ this._isFirstImageWider = image1.size.width > image2.size.width;
29
+
30
+ this.state = {
31
+ syncedImage1: {
32
+ containerRef: React.createRef(),
33
+ width: image1.size.width
34
+ },
35
+ syncedImage2: {
36
+ containerRef: React.createRef(),
37
+ width: image2.size.width
38
+ },
39
+ resizesNum: 0
40
+ };
41
+ }
42
+
43
+ componentDidMount() {
44
+ this._handleResize();
45
+ }
46
+
47
+ _calcScaleFactor = () => {
48
+ if (!this._shouldScale) {
49
+ return this._scaleFactor;
50
+ }
51
+
52
+ const {image1, image2} = this.props;
53
+ const {syncedImage1, syncedImage2} = this.state;
54
+
55
+ const imgWidth = this._isFirstImageWider ? image1.size.width : image2.size.width;
56
+ const renderedImgWidth = this._isFirstImageWider
57
+ ? this.getRenderedImgWidth(syncedImage1)
58
+ : this.getRenderedImgWidth(syncedImage2);
59
+
60
+ return renderedImgWidth / imgWidth;
61
+ }
62
+
63
+ _getScaledWidth = (image) => {
64
+ if (!this._shouldScale) {
65
+ return image.size.width;
66
+ }
67
+
68
+ const scaledWidth = Math.ceil(image.size.width * this._scaleFactor);
69
+
70
+ return Math.min(scaledWidth, image.size.width);
71
+ }
72
+
73
+ getRenderedImgWidth(syncedImage) {
74
+ return syncedImage.containerRef.current
75
+ ? syncedImage.containerRef.current.offsetWidth
76
+ : syncedImage.width;
77
+ }
78
+
79
+ _handleResize = () => {
80
+ if (!this._shouldScale) {
81
+ return;
82
+ }
83
+
84
+ const {image1, image2} = this.props;
85
+ this._scaleFactor = this._calcScaleFactor();
86
+
87
+ this.setState(prevState => ({
88
+ syncedImage1: {
89
+ ...prevState.syncedImage1,
90
+ width: this._isFirstImageWider ? image1.size.width : this._getScaledWidth(image1)
91
+ },
92
+ syncedImage2: {
93
+ ...prevState.syncedImage2,
94
+ width: this._isFirstImageWider ? this._getScaledWidth(image2) : image2.size.width
95
+ },
96
+ resizesNum: prevState.resizesNum + 1
97
+ }));
98
+ }
99
+
100
+ render() {
101
+ const {syncedImage1, syncedImage2, resizesNum} = this.state;
102
+
103
+ return (
104
+ <ResizeObserver onResize={this._handleResize}>
105
+ <WrappedComponent
106
+ syncedImage1={syncedImage1}
107
+ syncedImage2={syncedImage2}
108
+ resizesNum={resizesNum}
109
+ getRenderedImgWidth={this.getRenderedImgWidth}
110
+
111
+ {...this.props}
112
+ />
113
+ </ResizeObserver>
114
+ );
115
+ }
116
+ };
@@ -7,7 +7,7 @@ import PropTypes from 'prop-types';
7
7
  import {isEmpty, map, isFunction} from 'lodash';
8
8
  import ReactHtmlParser from 'react-html-parser';
9
9
  import * as actions from '../../modules/actions';
10
- import Screenshot from './screenshot';
10
+ import ResizedScreenshot from './screenshot/resized';
11
11
  import {isNoRefImageError, isAssertViewError} from '../../modules/utils';
12
12
  import ErrorDetails from './error-details';
13
13
  import Details from '../details';
@@ -44,10 +44,10 @@ class StateError extends Component {
44
44
  }
45
45
 
46
46
  return isNoRefImageError(error)
47
- ? <Screenshot image={image.actualImg} />
47
+ ? <ResizedScreenshot image={image.actualImg} />
48
48
  : <Details
49
49
  title="Page screenshot"
50
- content={() => <Screenshot image={image.actualImg} />}
50
+ content={() => <ResizedScreenshot image={image.actualImg} />}
51
51
  extendClassNames="details_type_image"
52
52
  onClick={this.onTogglePageScreenshot}
53
53
  />;
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ import React, {Component, Fragment} from 'react';
4
+ import {connect} from 'react-redux';
5
+ import PropTypes from 'prop-types';
6
+ import classNames from 'classnames';
7
+ import ResizedScreenshot from '../screenshot/resized';
8
+ import SwipeDiff from './swipe-diff';
9
+ import SwitchDiff from './switch-diff';
10
+ import OnionSkinDiff from './onion-skin-diff';
11
+ import diffModes from '../../../../constants/diff-modes';
12
+
13
+ import './index.styl';
14
+
15
+ class StateFail extends Component {
16
+ static propTypes = {
17
+ image: PropTypes.shape({
18
+ expectedImg: PropTypes.object.isRequired,
19
+ actualImg: PropTypes.object.isRequired,
20
+ diffImg: PropTypes.object.isRequired,
21
+ diffClusters: PropTypes.array
22
+ }).isRequired,
23
+ // from store
24
+ diffMode: PropTypes.string
25
+ }
26
+
27
+ constructor(props) {
28
+ super(props);
29
+
30
+ this.state = {diffMode: this.props.diffMode};
31
+ }
32
+
33
+ componentWillReceiveProps(nextProps) {
34
+ if (this.state.diffMode !== nextProps.diffMode) {
35
+ this.setState({diffMode: nextProps.diffMode});
36
+ }
37
+ }
38
+
39
+ _handleDiffModeClick = (diffMode) => {
40
+ if (this.state.diffMode === diffMode) {
41
+ return;
42
+ }
43
+
44
+ this.setState({diffMode});
45
+ }
46
+
47
+ _renderDiffModeItems() {
48
+ const diffModeItems = Object.values(diffModes).map((diffMode) => {
49
+ return this._renderDiffModeItem(diffMode);
50
+ });
51
+
52
+ return (
53
+ <ul className="diff-modes">
54
+ {diffModeItems}
55
+ </ul>
56
+ );
57
+ }
58
+
59
+ _renderDiffModeItem(diffMode) {
60
+ const className = classNames(
61
+ 'diff-modes__item',
62
+ {'diff-modes__active': this.state.diffMode === diffMode.id}
63
+ );
64
+
65
+ return <li key={diffMode.id} title={diffMode.description} className={className} onClick={() => this._handleDiffModeClick(diffMode.id)}>{diffMode.title}</li>;
66
+ }
67
+
68
+ _renderImages() {
69
+ const {image: {expectedImg, actualImg}} = this.props;
70
+
71
+ switch (this.state.diffMode) {
72
+ case diffModes.ONLY_DIFF.id:
73
+ return this._renderOnlyDiff();
74
+
75
+ case diffModes.SWITCH.id:
76
+ return <SwitchDiff image1={expectedImg} image2={actualImg} />;
77
+
78
+ case diffModes.SWIPE.id:
79
+ return <SwipeDiff image1={expectedImg} image2={actualImg} />;
80
+
81
+ case diffModes.ONION_SKIN.id:
82
+ return <OnionSkinDiff image1={expectedImg} image2={actualImg} />;
83
+
84
+ case diffModes.THREE_UP_SCALED.id:
85
+ return <div className="image-box__scaled">
86
+ {this._renderThreeImages()}
87
+ </div>;
88
+
89
+ case diffModes.THREE_UP.id:
90
+ default:
91
+ return this._renderThreeImages();
92
+ }
93
+ }
94
+
95
+ _renderOnlyDiff() {
96
+ const {image: {diffImg, diffClusters}} = this.props;
97
+
98
+ return this._drawImageBox(diffImg, {diffClusters});
99
+ }
100
+
101
+ _renderThreeImages() {
102
+ const {image: {expectedImg, actualImg, diffImg, diffClusters}} = this.props;
103
+
104
+ return <Fragment>
105
+ {this._drawExpectedAndActual(expectedImg, actualImg)}
106
+ {this._drawImageBox(diffImg, {label: 'Diff', diffClusters})}
107
+ </Fragment>;
108
+ }
109
+
110
+ render() {
111
+ return (
112
+ <Fragment>
113
+ {this._renderDiffModeItems()}
114
+ {this._renderImages()}
115
+ </Fragment>
116
+ );
117
+ }
118
+
119
+ _drawExpectedAndActual(expectedImg, actualImg) {
120
+ return (
121
+ <Fragment>
122
+ {this._drawImageBox(expectedImg, {label: 'Expected'})}
123
+ {this._drawImageBox(actualImg, {label: 'Actual'})}
124
+ </Fragment>
125
+ );
126
+ }
127
+
128
+ _drawImageBox(image, {label, diffClusters} = {}) {
129
+ const text = `${label} (${image.size.width}x${image.size.height})`;
130
+
131
+ return (
132
+ <div className="image-box__image" style={{flex: image.size.width}}>
133
+ {label && <div className="image-box__title">{text}</div>}
134
+ <ResizedScreenshot image={image} diffClusters={diffClusters}/>
135
+ </div>
136
+ );
137
+ }
138
+ }
139
+
140
+ export default connect(
141
+ ({view: {diffMode}}) => ({diffMode})
142
+ )(StateFail);
@@ -0,0 +1,31 @@
1
+ .diff-modes
2
+ display: flex
3
+ justify-content: center
4
+ border-bottom: 1px solid #ccc
5
+ padding: 5px 0
6
+ margin: 10px auto
7
+ width: 420px
8
+
9
+ &__item
10
+ display: inline-block
11
+ padding: 0 5px
12
+ cursor: pointer
13
+
14
+ &__item:not(:last-child)
15
+ border-right: 1px solid #ccc
16
+
17
+ &__active
18
+ font-weight: bold
19
+
20
+ .image-box__scaled
21
+ display: flex
22
+ flex-flow: row wrap
23
+
24
+ .image-box__image
25
+ padding: 0 5px
26
+
27
+ &:first-child
28
+ padding-left: 0
29
+
30
+ &:last-child
31
+ padding-right: 0
@@ -0,0 +1,43 @@
1
+ import React, {Component} from 'react';
2
+ import FullScreenshot from '../../screenshot/full';
3
+ import withSyncedScale from '../../screenshot/with-synced-scale';
4
+ import {imageType, syncedImageType} from '../prop-types';
5
+
6
+ import './index.styl';
7
+
8
+ const DEFAULT_IMAGE_TRANSPARENCY = 0.5;
9
+
10
+ class OnionSkinDiff extends Component {
11
+ static propTypes = {
12
+ image1: imageType.isRequired,
13
+ image2: imageType.isRequired,
14
+ // from withSyncedScale
15
+ syncedImage1: syncedImageType.isRequired,
16
+ syncedImage2: syncedImageType.isRequired
17
+ }
18
+
19
+ state = {imgTransparency: DEFAULT_IMAGE_TRANSPARENCY}
20
+
21
+ _handleChangeTransparency = (e) => {
22
+ return this.setState({imgTransparency: parseFloat(e.target.value)});
23
+ }
24
+
25
+ render() {
26
+ const {image1, image2, syncedImage1, syncedImage2} = this.props;
27
+ const {imgTransparency} = this.state;
28
+
29
+ return (
30
+ <div className='onion-skin-diff'>
31
+ <div className='onion-skin-diff__img-container'>
32
+ <FullScreenshot className='onion-skin-diff__img' image={image1} imgRef={syncedImage1.containerRef} style={{width: syncedImage1.width}} />
33
+ <FullScreenshot className='onion-skin-diff__img' image={image2} imgRef={syncedImage2.containerRef} style={{width: syncedImage2.width, opacity: imgTransparency}} />
34
+ </div>
35
+ <div className="onion-skin-diff__footer">
36
+ <input className='onion-skin-diff__slider' type="range" min={0} max={1} step={0.01} value={imgTransparency} onChange={this._handleChangeTransparency} />
37
+ </div>
38
+ </div>
39
+ );
40
+ }
41
+ }
42
+
43
+ export default withSyncedScale(OnionSkinDiff);
@@ -0,0 +1,19 @@
1
+ .onion-skin-diff
2
+ &__img-container
3
+ display: grid
4
+ grid-template-areas: 'one one'
5
+ max-width: max-content
6
+
7
+ &__img
8
+ max-width: 100%
9
+ grid-area: one
10
+ border: 1px solid #ccc
11
+
12
+ &__footer
13
+ display: flex
14
+ justify-content: center
15
+
16
+ &__slider
17
+ width: 250px
18
+ margin-top: 10px
19
+ cursor: pointer
@@ -0,0 +1,16 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ export const imageType = PropTypes.shape({
4
+ path: PropTypes.string.isRequired,
5
+ size: PropTypes.shape({
6
+ width: PropTypes.number,
7
+ height: PropTypes.number
8
+ })
9
+ });
10
+
11
+ export const syncedImageType = PropTypes.shape({
12
+ containerRef: PropTypes.shape({
13
+ current: PropTypes.instanceOf(Element)
14
+ }),
15
+ width: PropTypes.number
16
+ });
@@ -0,0 +1,138 @@
1
+ import React, {Component} from 'react';
2
+ import classNames from 'classnames';
3
+ import PropTypes from 'prop-types';
4
+ import FullScreenshot from '../../screenshot/full';
5
+ import ArrowsMove from '../../../icons/arrows-move';
6
+ import withSyncedScale from '../../screenshot/with-synced-scale';
7
+ import {imageType, syncedImageType} from '../prop-types';
8
+
9
+ import './index.styl';
10
+
11
+ function clamp(n, min = 0, max = 100) {
12
+ return Math.max(Math.min(n, max), min);
13
+ }
14
+
15
+ class SwipeDiff extends Component {
16
+ static propTypes = {
17
+ image1: imageType.isRequired,
18
+ image2: imageType.isRequired,
19
+ // from withSyncedScale
20
+ syncedImage1: syncedImageType.isRequired,
21
+ syncedImage2: syncedImageType.isRequired,
22
+ resizesNum: PropTypes.number.isRequired,
23
+ getRenderedImgWidth: PropTypes.func.isRequired
24
+ }
25
+
26
+ constructor(props) {
27
+ super(props);
28
+
29
+ this._swipeContainer = React.createRef();
30
+ this._swipeContainerLeft = 0;
31
+
32
+ this.state = {
33
+ mousePosX: 0,
34
+ isPressed: false,
35
+ dividerWasMoved: false
36
+ };
37
+ }
38
+
39
+ componentDidMount() {
40
+ this._swipeContainerLeft = this._swipeContainer.current.getBoundingClientRect().left;
41
+
42
+ this.setState({mousePosX: this._getMiddleMousePosX()});
43
+ }
44
+
45
+ componentDidUpdate(prevProps) {
46
+ if (this.state.dividerWasMoved || prevProps.resizesNum === this.props.resizesNum) {
47
+ return;
48
+ }
49
+
50
+ this.setState({mousePosX: this._getMiddleMousePosX()});
51
+ }
52
+
53
+ _getMiddleMousePosX() {
54
+ const {image1, syncedImage1, syncedImage2, getRenderedImgWidth} = this.props;
55
+ const middlePosX = Math.min(getRenderedImgWidth(syncedImage1), getRenderedImgWidth(syncedImage2)) / 2;
56
+
57
+ return clamp(middlePosX, 0, image1.size.width);
58
+ }
59
+
60
+ _getMousePosX(e) {
61
+ const newMousePosX = e.pageX - this._swipeContainerLeft - window.scrollX;
62
+ return clamp(newMousePosX, 0, this.props.syncedImage1.width);
63
+ }
64
+
65
+ _calcImgPosX(width) {
66
+ const imgPosX = this.state.mousePosX / width * 100;
67
+ return clamp(imgPosX, 0, 100);
68
+ }
69
+
70
+ _handleMouseMove = (e) => {
71
+ if (!this.state.isPressed) {
72
+ return;
73
+ }
74
+
75
+ this.setState({mousePosX: this._getMousePosX(e)});
76
+ }
77
+
78
+ _handleMouseDown = (e) => {
79
+ this.setState({mousePosX: this._getMousePosX(e), isPressed: true, dividerWasMoved: true});
80
+
81
+ window.addEventListener('mousemove', this._handleMouseMove);
82
+ window.addEventListener('mouseup', this._handleMouseUp);
83
+
84
+ document.body.classList.add('disable-user-select');
85
+ }
86
+
87
+ _handleMouseUp = () => {
88
+ this.setState({isPressed: false});
89
+ document.body.classList.remove('disable-user-select');
90
+
91
+ window.removeEventListener('mouseup', this._handleMouseUp);
92
+ window.removeEventListener('mousemove', this._handleMouseMove);
93
+ }
94
+
95
+ render() {
96
+ const {image1, image2, syncedImage1, syncedImage2, getRenderedImgWidth} = this.props;
97
+ const {isPressed} = this.state;
98
+
99
+ const maxRenderedWidth = Math.max(getRenderedImgWidth(syncedImage1), getRenderedImgWidth(syncedImage2));
100
+ const img1PosX = 100 - this._calcImgPosX(maxRenderedWidth);
101
+ const img2PosX = this._calcImgPosX(maxRenderedWidth);
102
+
103
+ const className = classNames(
104
+ 'swipe-diff',
105
+ {'swipe-diff_pressed': isPressed}
106
+ );
107
+
108
+ return (
109
+ <div
110
+ className={className}
111
+ style={{'--img1-pos-x': `${img1PosX}%`, '--img2-pos-x': `${img2PosX}%`}}
112
+ ref={this._swipeContainer}
113
+ onMouseDown={this._handleMouseDown}
114
+ >
115
+ <div className='swipe-diff__second'>
116
+ <div className='swipe-diff__frame'>
117
+ <FullScreenshot className='swipe-diff__img' image={image2} imgRef={syncedImage2.containerRef} style={{width: syncedImage2.width}} />
118
+ </div>
119
+ </div>
120
+ <div className="swipe-diff__first">
121
+ <div className="swipe-diff__overlay">
122
+ <div className='swipe-diff__frame'>
123
+ <FullScreenshot className='swipe-diff__img' image={image1} imgRef={syncedImage1.containerRef} style={{width: syncedImage1.width}} />
124
+ </div>
125
+ </div>
126
+ <div className="swipe-diff-divider">
127
+ <div className="swipe-diff-divider__line"></div>
128
+ <div className="swipe-diff-divider__arrows">
129
+ <ArrowsMove />
130
+ </div>
131
+ </div>
132
+ </div>
133
+ </div>
134
+ );
135
+ }
136
+ }
137
+
138
+ export default withSyncedScale(SwipeDiff);