@@ -166,11 +166,14 @@ export default class extends PureComponent {
166
166
167
167
// Load the image
168
168
this . image = new Image ( ) ;
169
- this . image . src = this . props . imgSrc ;
169
+
170
+ // Prevent SecurityError "Tainted canvases may not be exported." #70
171
+ this . image . crossOrigin = "anonymous" ;
170
172
171
173
// Draw the image once loaded
172
174
this . image . onload = ( ) =>
173
175
drawImage ( { ctx : this . ctx . grid , img : this . image } ) ;
176
+ this . image . src = this . props . imgSrc ;
174
177
} ;
175
178
176
179
undo = ( ) => {
@@ -275,42 +278,39 @@ export default class extends PureComponent {
275
278
} ) ;
276
279
} ;
277
280
278
- handleTouchStart = e => {
279
- const { x, y } = this . getPointerPos ( e ) ;
280
- this . lazy . update ( { x, y } , { both : true } ) ;
281
- this . handleMouseDown ( e ) ;
281
+ handleDrawStart = e => {
282
+ e . preventDefault ( ) ;
282
283
283
- this . mouseHasMoved = true ;
284
- } ;
284
+ // Start drawing
285
+ this . isPressing = true ;
285
286
286
- handleTouchMove = e => {
287
- e . preventDefault ( ) ;
288
287
const { x, y } = this . getPointerPos ( e ) ;
289
- this . handlePointerMove ( x , y ) ;
290
- } ;
291
288
292
- handleTouchEnd = e => {
293
- this . handleMouseUp ( e ) ;
294
- const brush = this . lazy . getBrushCoordinates ( ) ;
295
- this . lazy . update ( { x : brush . x , y : brush . y } , { both : true } ) ;
296
- this . mouseHasMoved = true ;
289
+ if ( e . touches && e . touches . length > 0 ) {
290
+ // on touch, set catenary position to touch pos
291
+ this . lazy . update ( { x, y } , { both : true } ) ;
292
+ }
293
+
294
+ // Ensure the initial down position gets added to our line
295
+ this . handlePointerMove ( x , y ) ;
297
296
} ;
298
297
299
- handleMouseDown = e => {
298
+ handleDrawMove = e => {
300
299
e . preventDefault ( ) ;
301
- this . isPressing = true ;
302
- } ;
303
300
304
- handleMouseMove = e => {
305
301
const { x, y } = this . getPointerPos ( e ) ;
306
302
this . handlePointerMove ( x , y ) ;
307
303
} ;
308
304
309
- handleMouseUp = e => {
305
+ handleDrawEnd = e => {
310
306
e . preventDefault ( ) ;
307
+
308
+ // Draw to this end pos
309
+ this . handleDrawMove ( e ) ;
310
+
311
+ // Stop drawing & save the drawn line
311
312
this . isDrawing = false ;
312
313
this . isPressing = false ;
313
-
314
314
this . saveLine ( ) ;
315
315
} ;
316
316
@@ -324,6 +324,7 @@ export default class extends PureComponent {
324
324
this . setCanvasSize ( this . canvas . grid , width , height ) ;
325
325
326
326
this . drawGrid ( this . ctx . grid ) ;
327
+ this . drawImage ( ) ;
327
328
this . loop ( { once : true } ) ;
328
329
}
329
330
this . loadSaveData ( saveData , true ) ;
@@ -359,19 +360,19 @@ export default class extends PureComponent {
359
360
handlePointerMove = ( x , y ) => {
360
361
if ( this . props . disabled ) return ;
361
362
362
- const hasChanged = this . lazy . update ( { x, y } ) ;
363
+ this . lazy . update ( { x, y } ) ;
363
364
const isDisabled = ! this . lazy . isEnabled ( ) ;
364
365
365
366
if (
366
- ( this . isPressing && hasChanged && ! this . isDrawing ) ||
367
+ ( this . isPressing && ! this . isDrawing ) ||
367
368
( isDisabled && this . isPressing )
368
369
) {
369
370
// Start drawing and add point
370
371
this . isDrawing = true ;
371
372
this . points . push ( this . lazy . brush . toObject ( ) ) ;
372
373
}
373
374
374
- if ( this . isDrawing && ( this . lazy . brushHasMoved ( ) || isDisabled ) ) {
375
+ if ( this . isDrawing ) {
375
376
// Add new point
376
377
this . points . push ( this . lazy . brush . toObject ( ) ) ;
377
378
@@ -583,14 +584,14 @@ export default class extends PureComponent {
583
584
}
584
585
} }
585
586
style = { { ...canvasStyle , zIndex } }
586
- onMouseDown = { isInterface ? this . handleMouseDown : undefined }
587
- onMouseMove = { isInterface ? this . handleMouseMove : undefined }
588
- onMouseUp = { isInterface ? this . handleMouseUp : undefined }
589
- onMouseOut = { isInterface ? this . handleMouseUp : undefined }
590
- onTouchStart = { isInterface ? this . handleTouchStart : undefined }
591
- onTouchMove = { isInterface ? this . handleTouchMove : undefined }
592
- onTouchEnd = { isInterface ? this . handleTouchEnd : undefined }
593
- onTouchCancel = { isInterface ? this . handleTouchEnd : undefined }
587
+ onMouseDown = { isInterface ? this . handleDrawStart : undefined }
588
+ onMouseMove = { isInterface ? this . handleDrawMove : undefined }
589
+ onMouseUp = { isInterface ? this . handleDrawEnd : undefined }
590
+ onMouseOut = { isInterface ? this . handleDrawEnd : undefined }
591
+ onTouchStart = { isInterface ? this . handleDrawStart : undefined }
592
+ onTouchMove = { isInterface ? this . handleDrawMove : undefined }
593
+ onTouchEnd = { isInterface ? this . handleDrawEnd : undefined }
594
+ onTouchCancel = { isInterface ? this . handleDrawEnd : undefined }
594
595
/>
595
596
) ;
596
597
} ) }
0 commit comments