@@ -5,8 +5,7 @@ export class Rotation extends HTMLElement {
55 super ( )
66 this . $shadow = this . attachShadow ( { mode : 'closed' } )
77 this . styles = [ HandlesStyles , RotationStyles ]
8- this . startAngle = 0
9- this . currentAngle = 0
8+ this . totalAngle = 0
109 }
1110
1211 connectedCallback ( ) {
@@ -42,7 +41,6 @@ export class Rotation extends HTMLElement {
4241 e . clientY - this . originalCenter . y ,
4342 e . clientX - this . originalCenter . x
4443 )
45- this . currentAngle = 0
4644
4745 this . handleRadius = Math . sqrt (
4846 Math . pow ( e . clientX - this . originalCenter . x , 2 ) +
@@ -70,25 +68,21 @@ export class Rotation extends HTMLElement {
7068 } else if ( delta < - Math . PI ) {
7169 delta += 2 * Math . PI
7270 }
73- this . currentAngle += delta
71+
72+ this . totalAngle += delta
7473 this . lastAngle = currentAngle
7574
76- const rotationDegrees = this . currentAngle * ( 180 / Math . PI )
75+ const rotationDegrees = this . totalAngle * ( 180 / Math . PI )
7776 this . targetElement . style . transform = `rotate(${ rotationDegrees } deg)`
7877
79- this . handleRadius = Math . sqrt (
80- Math . pow ( e . clientX - this . originalCenter . x , 2 ) +
81- Math . pow ( e . clientY - this . originalCenter . y , 2 )
82- )
78+ const handleX = e . clientX
79+ const handleY = e . clientY
8380
84- const handle = this . $shadow . querySelector ( '.rotation-handle' )
81+ const hostRect = this . getBoundingClientRect ( )
8582 const handleRect = handle . getBoundingClientRect ( )
8683 const handleSize = handleRect . width
8784
88- const handleX = this . originalCenter . x + this . handleRadius * Math . cos ( currentAngle )
89- const handleY = this . originalCenter . y + this . handleRadius * Math . sin ( currentAngle )
90-
91- const hostRect = this . getBoundingClientRect ( )
85+ // position handle centered on cursor
9286 handle . style . left = `${ handleX - hostRect . left - handleSize / 2 } px`
9387 handle . style . top = `${ handleY - hostRect . top - handleSize / 2 } px`
9488
@@ -100,6 +94,7 @@ export class Rotation extends HTMLElement {
10094 }
10195
10296 const onMouseUp = ( ) => {
97+ this . lastAngle = 0
10398 document . removeEventListener ( 'mousemove' , onMouseMove )
10499 document . removeEventListener ( 'mouseup' , onMouseUp )
105100 line . classList . remove ( 'active' )
0 commit comments