@@ -4,25 +4,58 @@ import {
44 disableUserSelect ,
55 enableUserSelect ,
66 findSVGAtPoint ,
7+ findSVGContainer ,
78 getMetadata ,
8- convertToSvgPoint
9+ convertToSvgPoint ,
10+ convertToScreenPoint ,
11+ findAnnotationAtPoint
912} from './utils' ;
1013
1114let _enabled = false ;
1215let _penSize ;
1316let _penColor ;
1417let path ;
1518let lines ;
19+ let originY ;
20+ let originX ;
1621
1722/**
1823 * Handle document.mousedown event
1924 */
20- function handleDocumentMousedown ( ) {
21- path = null ;
22- lines = [ ] ;
25+ function handleDocumentMousedown ( e ) {
26+ let target = findAnnotationAtPoint ( e . clientX , e . clientY ) ;
27+ if ( target === null )
28+ return ;
29+
30+ let type = target . getAttribute ( 'data-pdf-annotate-type' ) ;
31+ if ( type !== 'circle' && type !== 'fillcircle' && type !== 'emptycircle' ) {
32+ return ;
33+ }
34+
35+ let svg = findSVGContainer ( target ) ;
36+ let { documentId } = getMetadata ( svg ) ;
37+ let annotationId = target . getAttribute ( 'data-pdf-annotate-id' ) ;
38+
39+ let event = e ;
40+ PDFJSAnnotate . getStoreAdapter ( ) . getAnnotation ( documentId , annotationId ) . then ( ( annotation ) => {
41+ if ( annotation ) {
42+ path = null ;
43+ lines = [ ] ;
2344
24- document . addEventListener ( 'mousemove' , handleDocumentMousemove ) ;
25- document . addEventListener ( 'mouseup' , handleDocumentMouseup ) ;
45+ let point = convertToScreenPoint ( [
46+ annotation . cx ,
47+ annotation . cy
48+ ] , svg ) ;
49+
50+ let rect = svg . getBoundingClientRect ( ) ;
51+
52+ originX = point [ 0 ] + rect . left ;
53+ originY = point [ 1 ] + rect . top ;
54+
55+ document . addEventListener ( 'mousemove' , handleDocumentMousemove ) ;
56+ document . addEventListener ( 'mouseup' , handleDocumentMouseup ) ;
57+ }
58+ } ) ;
2659}
2760
2861/**
@@ -60,7 +93,10 @@ function handleDocumentMouseup(e) {
6093 * @param {Event } e The DOM event to be handled
6194 */
6295function handleDocumentMousemove ( e ) {
63- savePoint ( e . clientX , e . clientY ) ;
96+ let x = lines . length === 0 ? originX : e . clientX ;
97+ let y = lines . length === 0 ? originY : e . clientY ;
98+
99+ savePoint ( x , y ) ;
64100}
65101
66102/**
0 commit comments