@@ -31,10 +31,9 @@ export class Graffiti {
3131 this . isDrawing = true
3232 // 缓存起始数据
3333 this . startStroke = {
34- isBegin : true ,
35- lineWidth : this . options . graffiti . defaultLineWidth ,
3634 lineColor : this . options . graffiti . defaultLineColor ,
37- linePoints : [ evt . offsetX , evt . offsetY ]
35+ lineWidth : this . options . graffiti . defaultLineWidth ,
36+ points : [ evt . offsetX , evt . offsetY ]
3837 }
3938 }
4039
@@ -49,8 +48,8 @@ export class Graffiti {
4948 const DISTANCE = 2
5049 if (
5150 this . startStroke &&
52- Math . abs ( this . startStroke . linePoints [ 0 ] - offsetX ) < DISTANCE &&
53- Math . abs ( this . startStroke . linePoints [ 1 ] - offsetY ) < DISTANCE
51+ Math . abs ( this . startStroke . points [ 0 ] - offsetX ) < DISTANCE &&
52+ Math . abs ( this . startStroke . points [ 1 ] - offsetY ) < DISTANCE
5453 ) {
5554 return
5655 }
@@ -70,9 +69,9 @@ export class Graffiti {
7069 this . startStroke = null
7170 }
7271 if ( ! currentValue ?. strokes ?. length ) return
73- currentValue . strokes . push ( {
74- linePoints : [ offsetX , offsetY ]
75- } )
72+ const lastPoints =
73+ currentValue . strokes [ currentValue . strokes . length - 1 ] . points
74+ lastPoints . push ( offsetX , offsetY )
7675 // 重新渲染
7776 this . draw . render ( {
7877 isCompute : false ,
@@ -110,14 +109,12 @@ export class Graffiti {
110109 ctx . save ( )
111110 for ( let s = 0 ; s < strokes . length ; s ++ ) {
112111 const stroke = strokes [ s ]
113- const { isBegin, lineColor, lineWidth, linePoints } = stroke
114- if ( isBegin ) {
115- ctx . strokeStyle = lineColor || defaultLineColor
116- ctx . lineWidth = ( lineWidth || defaultLineWidth ) * scale
117- ctx . beginPath ( )
118- ctx . moveTo ( linePoints [ 0 ] * scale , linePoints [ 1 ] * scale )
119- } else {
120- ctx . lineTo ( linePoints [ 0 ] * scale , linePoints [ 1 ] * scale )
112+ ctx . beginPath ( )
113+ ctx . strokeStyle = stroke . lineColor || defaultLineColor
114+ ctx . lineWidth = ( stroke . lineWidth || defaultLineWidth ) * scale
115+ ctx . moveTo ( stroke . points [ 0 ] * scale , stroke . points [ 1 ] * scale )
116+ for ( let p = 2 ; p < stroke . points . length ; p += 2 ) {
117+ ctx . lineTo ( stroke . points [ p ] * scale , stroke . points [ p + 1 ] * scale )
121118 }
122119 ctx . stroke ( )
123120 }
0 commit comments