1
- import React from 'react'
2
- import imageCompression from 'browser-image-compression'
1
+ import React from 'react' ;
2
+ import imageCompression from 'browser-image-compression' ;
3
3
4
4
export default class App extends React . Component {
5
- constructor ( ...args ) {
6
- super ( ...args )
7
- this . compressImage = this . compressImage . bind ( this )
8
- this . handleChange = this . handleChange . bind ( this )
5
+ constructor ( ...args ) {
6
+ super ( ...args ) ;
7
+ this . compressImage = this . compressImage . bind ( this ) ;
8
+ this . handleChange = this . handleChange . bind ( this ) ;
9
9
this . state = {
10
10
maxSizeMB : 1 ,
11
11
maxWidthOrHeight : 1024 ,
@@ -14,72 +14,74 @@ export default class App extends React.Component {
14
14
inputSize : null ,
15
15
outputSize : null ,
16
16
inputUrl : null ,
17
- outputUrl : null
17
+ outputUrl : null ,
18
18
} ,
19
19
mainThread : {
20
20
progress : null ,
21
21
inputSize : null ,
22
22
outputSize : null ,
23
23
inputUrl : null ,
24
- outputUrl : null
25
- }
26
- }
24
+ outputUrl : null ,
25
+ } ,
26
+ } ;
27
27
}
28
28
29
- handleChange ( target ) {
29
+ handleChange ( target ) {
30
30
return ( e ) => {
31
- this . setState ( { [ target ] : e . currentTarget . value } )
32
- }
31
+ this . setState ( { [ target ] : e . currentTarget . value } ) ;
32
+ } ;
33
33
}
34
34
35
- onProgress ( p , useWebWorker ) {
36
- const targetName = useWebWorker ? 'webWorker' : 'mainThread'
37
- this . setState ( prevState => ( {
35
+ onProgress ( p , useWebWorker ) {
36
+ const targetName = useWebWorker ? 'webWorker' : 'mainThread' ;
37
+ this . setState ( ( prevState ) => ( {
38
38
...prevState ,
39
39
[ targetName ] : {
40
40
...prevState [ targetName ] ,
41
- progress : p
42
- }
43
- } ) )
41
+ progress : p ,
42
+ } ,
43
+ } ) ) ;
44
44
}
45
45
46
- async compressImage ( event , useWebWorker ) {
47
- const file = event . target . files [ 0 ]
48
- console . log ( 'input' , file )
46
+ async compressImage ( event , useWebWorker ) {
47
+ const file = event . target . files [ 0 ] ;
48
+ console . log ( 'input' , file ) ;
49
49
console . log (
50
50
'ExifOrientation' ,
51
- await imageCompression . getExifOrientation ( file )
52
- )
53
- const targetName = useWebWorker ? 'webWorker' : 'mainThread'
54
- this . setState ( prevState => ( {
51
+ await imageCompression . getExifOrientation ( file ) ,
52
+ ) ;
53
+ const targetName = useWebWorker ? 'webWorker' : 'mainThread' ;
54
+ this . setState ( ( prevState ) => ( {
55
55
...prevState ,
56
56
[ targetName ] : {
57
57
...prevState [ targetName ] ,
58
58
inputSize : ( file . size / 1024 / 1024 ) . toFixed ( 2 ) ,
59
- inputUrl : URL . createObjectURL ( file )
60
- }
61
- } ) )
62
- var options = {
59
+ inputUrl : URL . createObjectURL ( file ) ,
60
+ } ,
61
+ } ) ) ;
62
+ const options = {
63
63
maxSizeMB : this . state . maxSizeMB ,
64
64
maxWidthOrHeight : this . state . maxWidthOrHeight ,
65
65
useWebWorker,
66
- onProgress : p => this . onProgress ( p , useWebWorker )
67
- }
68
- const output = await imageCompression ( file , options )
69
- console . log ( 'output' , output )
70
- this . setState ( prevState => ( {
66
+ onProgress : ( p ) => this . onProgress ( p , useWebWorker ) ,
67
+ } ;
68
+ const output = await imageCompression ( file , options ) ;
69
+ console . log ( 'output' , output ) ;
70
+ this . setState ( ( prevState ) => ( {
71
71
...prevState ,
72
72
[ targetName ] : {
73
73
...prevState [ targetName ] ,
74
74
outputSize : ( output . size / 1024 / 1024 ) . toFixed ( 2 ) ,
75
- outputUrl : URL . createObjectURL ( output )
76
- }
77
- } ) )
75
+ outputUrl : URL . createObjectURL ( output ) ,
76
+ } ,
77
+ } ) ) ;
78
78
}
79
79
80
- render ( ) {
81
- const version = imageCompression . version
82
- const { webWorker, mainThread, maxSizeMB, maxWidthOrHeight } = this . state
80
+ render ( ) {
81
+ const { version } = imageCompression ;
82
+ const {
83
+ webWorker, mainThread, maxSizeMB, maxWidthOrHeight,
84
+ } = this . state ;
83
85
return (
84
86
< div className = "App" >
85
87
< div >
@@ -100,7 +102,7 @@ export default class App extends React.Component {
100
102
id = "web-worker"
101
103
type = "file"
102
104
accept = "image/*"
103
- onChange = { e => this . compressImage ( e , true ) }
105
+ onChange = { ( e ) => this . compressImage ( e , true ) }
104
106
/>
105
107
</ label >
106
108
< p >
@@ -120,7 +122,7 @@ export default class App extends React.Component {
120
122
id = "main-thread"
121
123
type = "file"
122
124
accept = "image/*"
123
- onChange = { e => this . compressImage ( e , false ) }
125
+ onChange = { ( e ) => this . compressImage ( e , false ) }
124
126
/>
125
127
</ label >
126
128
< p >
@@ -170,6 +172,6 @@ export default class App extends React.Component {
170
172
}
171
173
` } </ style >
172
174
</ div >
173
- )
175
+ ) ;
174
176
}
175
- } ;
177
+ }
0 commit comments