@@ -22,6 +22,15 @@ const DEFAULT_STYLES = { color: 'black', size: 'm', dash: 'draw', fill: 'none',
2222
2323export const TOOLS = [ 'select' , 'hand' , 'draw' , 'highlight' , 'eraser' , 'laser' , 'arrow' , 'line' , 'geo' , 'text' , 'note' ]
2424
25+ // local position of the bend handle: the curve's midpoint (chord midpoint
26+ // when straight — sampleLinePts collapses to the two endpoints at bend 0)
27+ const bendMidpoint = ( pr ) => {
28+ if ( ! pr . bend ) return { x : pr . dx / 2 , y : pr . dy / 2 }
29+ const mid = sampleLinePts ( pr , pr . bend )
30+ const mi = Math . floor ( mid . length / 4 ) * 2
31+ return { x : mid [ mi ] , y : mid [ mi + 1 ] }
32+ }
33+
2534export class Editor {
2635 constructor ( { container, store, theme = 'light' , grid = 'none' , readonly = false , camera, styles, geoKind } = { } ) {
2736 this . container = container
@@ -772,7 +781,7 @@ export class Editor {
772781 this . store . put ( {
773782 id, typeName : 'shape' , type, x : p . x , y : p . y , rot : 0 , z : this . store . maxZ ( ) + 1 ,
774783 props : {
775- dx : 0.01 , dy : 0.01 , ... ( type === 'arrow' ? { bend : 0 } : { } ) ,
784+ dx : 0.01 , dy : 0.01 , bend : 0 ,
776785 color : this . styles . color , size : this . styles . size ,
777786 dash : this . styles . dash === 'draw' ? 'solid' : this . styles . dash ,
778787 } ,
@@ -1146,11 +1155,8 @@ export class Editor {
11461155 { which : 'start' , x : one . x , y : one . y } ,
11471156 { which : 'end' , x : one . x + pr . dx , y : one . y + pr . dy } ,
11481157 ]
1149- if ( one . type === 'arrow' ) {
1150- const mid = sampleLinePts ( pr , pr . bend || 0 )
1151- const mi = Math . floor ( mid . length / 4 ) * 2
1152- pts . push ( { which : 'bend' , x : one . x + mid [ mi ] , y : one . y + mid [ mi + 1 ] } )
1153- }
1158+ const bm = bendMidpoint ( pr )
1159+ pts . push ( { which : 'bend' , x : one . x + bm . x , y : one . y + bm . y } )
11541160 for ( const h of pts ) {
11551161 const s = this . pageToScreen ( h . x , h . y )
11561162 if ( Math . hypot ( s . x - sx , s . y - sy ) <= HANDLE + 3 ) return { kind : 'handle' , which : h . which , id : one . id }
@@ -1601,11 +1607,8 @@ export class Editor {
16011607 this . pageToScreen ( one . x , one . y ) ,
16021608 this . pageToScreen ( one . x + pr . dx , one . y + pr . dy ) ,
16031609 ]
1604- if ( one . type === 'arrow' ) {
1605- const mid = sampleLinePts ( pr , pr . bend || 0 )
1606- const mi = Math . floor ( mid . length / 4 ) * 2
1607- hs . push ( this . pageToScreen ( one . x + mid [ mi ] , one . y + mid [ mi + 1 ] ) )
1608- }
1610+ const bm = bendMidpoint ( pr )
1611+ hs . push ( this . pageToScreen ( one . x + bm . x , one . y + bm . y ) )
16091612 for ( const p2 of hs ) {
16101613 ctx . beginPath ( )
16111614 ctx . arc ( p2 . x , p2 . y , 5 , 0 , Math . PI * 2 )
0 commit comments