import { TypeContext , TypePoint , TypeElement , TypeElemDesc , } from '@idraw/types' ; import { calcElementCenter , parseAngleToRadian } from './calculate' ; function rotateElement ( ctx , elem , callback ) { const center = calcElementCenter ( elem ) ; const radian = parseAngleToRadian ( elem . angle || 0 ) ; return rotateContext ( ctx , center , radian || 0 , callback ) ; } function rotateContext ( ctx , center , radian , callback ) { if ( center && ( radian > 0 || radian < 0 ) ) { ctx . translate ( center . x , center . y ) ; ctx . rotate ( radian ) ; ctx . translate ( - center . x , - center . y ) ; } callback ( ctx ) ; if ( center && ( radian > 0 || radian < 0 ) ) { ctx . translate ( center . x , center . y ) ; ctx . rotate ( - radian ) ; ctx . translate ( - center . x , - center . y ) ; } } export { rotateContext , rotateElement , } ;