import { SKLayer , Layer } from '../types' ; /**
 *
 * 坐标格式转换，将相对坐标系转换为绝对坐标系
 *
 */ const formatCoordinate = ( layers , groupX = 0 , groupY = 0 , sizeX = 1 , sizeY = 1 , parentList = [ ] ) : Layer [ ] => { layers = layers . map ( ( layer ) => { let bg = '0-0-0-0' ; if ( layer . backgroundColor && layer . hasBackgroundColor && layer . includeBackgroundColorInExport ) { const { red , green , blue , alpha } = layer . backgroundColor ; bg = `${ red }-${ green }-${ blue }-${ alpha }` ; } let currParentList = [ `${ layer . frame . x },${ layer . frame . y },${ layer . frame . imgWidth },${ layer . frame . imgHeight },${ layer . do_objectID },${ layer . _class },${ bg }` , ... parentList ] ; layer . parentList = currParentList ; layer . frame = { _class : 'rect' , x : layer . frame . x * sizeX + groupX , y : layer . frame . y * sizeY + groupY , imgWidth : layer . frame . width , imgHeight : layer . frame . height , width : layer . frame . width * sizeX , height : layer . frame . height * sizeY , sizeX , sizeY , } ; let currSizeX = sizeX , currSizeY = sizeY ; if ( layer . _class === 'symbolInstance' && Array . isArray ( layer . layers ) && layer . layers . length === 1 && layer . layers [ 0 ] . _class === 'symbolMaster' ) { let symbolInstanceRect = layer . frame ; let symbolMasterRect = layer . layers [ 0 ] . frame ; currSizeX = sizeX * symbolInstanceRect . width / symbolMasterRect . width ; currSizeY = sizeY * symbolInstanceRect . height / symbolMasterRect . height ; } if ( Array . isArray ( layer . layers ) ) { layer . layers = formatCoordinate ( layer . layers , layer . frame . x , layer . frame . y , currSizeX , currSizeY , currParentList ) ; } return layer ; } ) ; return layers ; } ; export default formatCoordinate ;