1+ "use strict" ; 
2+ 3+ if  ( typeof  exports  ===  "undefined" )  { 
4+  var  exports  =  { } ; 
5+ } 
6+ 7+ if  ( typeof  module  ===  "undefined" )  { 
8+  var  module  =  { } ; 
9+ } 
10+ 11+ Object . defineProperty ( exports ,  "__esModule" ,  { 
12+  value : true , 
13+ } ) ; 
14+ 15+ var  _createClass  =  ( function ( )  { 
16+  function  defineProperties ( target ,  props )  { 
17+  for  ( var  i  =  0 ;  i  <  props . length ;  i ++ )  { 
18+  var  descriptor  =  props [ i ] ; 
19+  descriptor . enumerable  =  descriptor . enumerable  ||  false ; 
20+  descriptor . configurable  =  true ; 
21+  if  ( "value"  in  descriptor )  descriptor . writable  =  true ; 
22+  Object . defineProperty ( target ,  descriptor . key ,  descriptor ) ; 
23+  } 
24+  } 
25+  return  function ( Constructor ,  protoProps ,  staticProps )  { 
26+  if  ( protoProps )  defineProperties ( Constructor . prototype ,  protoProps ) ; 
27+  if  ( staticProps )  defineProperties ( Constructor ,  staticProps ) ; 
28+  return  Constructor ; 
29+  } ; 
30+ } ) ( ) ; 
31+ 32+ function  _classCallCheck ( instance ,  Constructor )  { 
33+  if  ( ! ( instance  instanceof  Constructor ) )  { 
34+  throw  new  TypeError ( "Cannot call a class as a function" ) ; 
35+  } 
36+ } 
37+ 38+ var  hasBlobConstructor  = 
39+  typeof  Blob  !==  "undefined"  && 
40+  ( function ( )  { 
41+  try  { 
42+  return  Boolean ( new  Blob ( ) ) ; 
43+  }  catch  ( e )  { 
44+  return  false ; 
45+  } 
46+  } ) ( ) ; 
47+ 48+ var  hasArrayBufferViewSupport  = 
49+  hasBlobConstructor  && 
50+  typeof  Uint8Array  !==  "undefined"  && 
51+  ( function ( )  { 
52+  try  { 
53+  return  new  Blob ( [ new  Uint8Array ( 100 ) ] ) . size  ===  100 ; 
54+  }  catch  ( e )  { 
55+  return  false ; 
56+  } 
57+  } ) ( ) ; 
58+ 59+ var  hasToBlobSupport  = 
60+  typeof  HTMLCanvasElement  !==  "undefined"  ?
61+  HTMLCanvasElement . prototype . toBlob  :
62+  false ; 
63+ 64+ var  hasBlobSupport  = 
65+  hasToBlobSupport  || 
66+  ( typeof  Uint8Array  !==  "undefined"  && 
67+  typeof  ArrayBuffer  !==  "undefined"  && 
68+  typeof  atob  !==  "undefined" ) ; 
69+ 70+ var  hasReaderSupport  = 
71+  typeof  FileReader  !==  "undefined"  ||  typeof  URL  !==  "undefined" ; 
72+ 73+ var  ImageTools  =  ( function ( )  { 
74+  function  ImageTools ( )  { 
75+  _classCallCheck ( this ,  ImageTools ) ; 
76+  } 
77+ 78+  _createClass ( ImageTools ,  null ,  [ { 
79+  key : "resize" , 
80+  value : function  resize ( file ,  maxDimensions ,  callback )  { 
81+  if  ( typeof  maxDimensions  ===  "function" )  { 
82+  callback  =  maxDimensions ; 
83+  maxDimensions  =  { 
84+  width : 640 , 
85+  height : 480 , 
86+  } ; 
87+  } 
88+ 89+  var  maxWidth  =  maxDimensions . width ; 
90+  var  maxHeight  =  maxDimensions . height ; 
91+ 92+  if  ( ! ImageTools . isSupported ( )  ||  ! file . type . match ( / i m a g e .* / ) )  { 
93+  callback ( file ,  false ) ; 
94+  return  false ; 
95+  } 
96+ 97+  if  ( file . type . match ( / i m a g e \/ g i f / ) )  { 
98+  // Not attempting, could be an animated gif 
99+  callback ( file ,  false ) ; 
100+  // TODO: use https://github.com/antimatter15/whammy to convert gif to webm 
101+  return  false ; 
102+  } 
103+ 104+  var  image  =  document . createElement ( "img" ) ; 
105+ 106+  image . onload  =  function ( imgEvt )  { 
107+  var  width  =  image . width ; 
108+  var  height  =  image . height ; 
109+  var  isTooLarge  =  false ; 
110+ 111+  if  ( width  >  height  &&  width  >  maxDimensions . width )  { 
112+  // width is the largest dimension, and it's too big. 
113+  height  *=  maxDimensions . width  /  width ; 
114+  width  =  maxDimensions . width ; 
115+  isTooLarge  =  true ; 
116+  }  else  if  ( height  >  maxDimensions . height )  { 
117+  // either width wasn't over-size or height is the largest dimension 
118+  // and the height is over-size 
119+  width  *=  maxDimensions . height  /  height ; 
120+  height  =  maxDimensions . height ; 
121+  isTooLarge  =  true ; 
122+  } 
123+ 124+  if  ( ! isTooLarge )  { 
125+  // early exit; no need to resize 
126+  callback ( file ,  false ) ; 
127+  return ; 
128+  } 
129+ 130+  var  canvas  =  document . createElement ( "canvas" ) ; 
131+  canvas . width  =  width ; 
132+  canvas . height  =  height ; 
133+ 134+  var  ctx  =  canvas . getContext ( "2d" ) ; 
135+  ctx . imageSmoothingEnabled  =  true ; 
136+  ctx . imageSmoothingQuality  =  'high' ; 
137+  ctx . drawImage ( image ,  0 ,  0 ,  width ,  height ) ; 
138+ 139+  if  ( hasToBlobSupport )  { 
140+  canvas . toBlob ( function ( blob )  { 
141+  callback ( blob ,  true ) ; 
142+  } ,  file . type ) ; 
143+  }  else  { 
144+  var  blob  =  ImageTools . _toBlob ( canvas ,  file . type ) ; 
145+  callback ( blob ,  true ) ; 
146+  } 
147+  } ; 
148+  ImageTools . _loadImage ( image ,  file ) ; 
149+ 150+  return  true ; 
151+  } , 
152+  } , 
153+  { 
154+  key : "_toBlob" , 
155+  value : function  _toBlob ( canvas ,  type )  { 
156+  var  dataURI  =  canvas . toDataURL ( type ) ; 
157+  var  dataURIParts  =  dataURI . split ( "," ) ; 
158+  var  byteString  =  undefined ; 
159+  if  ( dataURIParts [ 0 ] . indexOf ( "base64" )  >=  0 )  { 
160+  // Convert base64 to raw binary data held in a string: 
161+  byteString  =  atob ( dataURIParts [ 1 ] ) ; 
162+  }  else  { 
163+  // Convert base64/URLEncoded data component to raw binary data: 
164+  byteString  =  decodeURIComponent ( dataURIParts [ 1 ] ) ; 
165+  } 
166+  var  arrayBuffer  =  new  ArrayBuffer ( byteString . length ) ; 
167+  var  intArray  =  new  Uint8Array ( arrayBuffer ) ; 
168+ 169+  for  ( var  i  =  0 ;  i  <  byteString . length ;  i  +=  1 )  { 
170+  intArray [ i ]  =  byteString . charCodeAt ( i ) ; 
171+  } 
172+ 173+  var  mimeString  =  dataURIParts [ 0 ] . split ( ":" ) [ 1 ] . split ( ";" ) [ 0 ] ; 
174+  var  blob  =  null ; 
175+ 176+  if  ( hasBlobConstructor )  { 
177+  blob  =  new  Blob ( 
178+  [ hasArrayBufferViewSupport  ? intArray  : arrayBuffer ] ,  { 
179+  type : mimeString 
180+  } 
181+  ) ; 
182+  }  else  { 
183+  var  bb  =  new  BlobBuilder ( ) ; 
184+  bb . append ( arrayBuffer ) ; 
185+  blob  =  bb . getBlob ( mimeString ) ; 
186+  } 
187+ 188+  return  blob ; 
189+  } , 
190+  } , 
191+  { 
192+  key : "_loadImage" , 
193+  value : function  _loadImage ( image ,  file ,  callback )  { 
194+  if  ( typeof  URL  ===  "undefined" )  { 
195+  var  reader  =  new  FileReader ( ) ; 
196+  reader . onload  =  function ( evt )  { 
197+  image . src  =  evt . target . result ; 
198+  if  ( callback )  { 
199+  callback ( ) ; 
200+  } 
201+  } ; 
202+  reader . readAsDataURL ( file ) ; 
203+  }  else  { 
204+  image . src  =  URL . createObjectURL ( file ) ; 
205+  if  ( callback )  { 
206+  callback ( ) ; 
207+  } 
208+  } 
209+  } , 
210+  } , 
211+  { 
212+  key : "isSupported" , 
213+  value : function  isSupported ( )  { 
214+  return  ( 
215+  typeof  HTMLCanvasElement  !==  "undefined"  && 
216+  hasBlobSupport  && 
217+  hasReaderSupport 
218+  ) ; 
219+  } , 
220+  } , 
221+  ] ) ; 
222+ 223+  return  ImageTools ; 
224+ } ) ( ) ; 
225+ 226+ exports [ "default" ]  =  ImageTools ; 
227+ module . exports  =  exports [ "default" ] ; 
0 commit comments