import { DSL , Component , SKLayer } from '../types' ; import parseText from './parseText' ; import parseStructure from './parseStructure' ; import parseStyle from './parseStyle' ; import parseImage from './parseImage' ; import handleSlicePosition from './handleSlicePosition' ; import filterGroupLayer from './filterGroupLayer' ; const _parseDSL = ( sketchData , type ) : DSL => { const dsl = [ ] ; sketchData . forEach ( ( layer ) => { let dslLayer = { type : 'Container' , id : layer . do_objectID , name : layer . name , symbolName : layer . symbolName || '' } ; if ( type === 'lowcode' ) { dslLayer . type = 'View' ; if ( layer . haikuiComponentInfo ) { dslLayer . haikuiComponentInfo = layer . haikuiComponentInfo ; } } if ( type !== 'lowcode' ) { if ( layer . symbolComponentObject ) { dslLayer . symbolComponentObject = layer . symbolComponentObject ; } dslLayer . panel = layer . panel ; } dslLayer . structure = { ... dslLayer . structure , ... parseStructure ( layer ) } ; dslLayer . style = { ... dslLayer . style , ... parseStyle ( layer ) } ; dslLayer = parseText ( dslLayer , layer ) ; dslLayer = parseImage ( dslLayer , layer , type ) ; if ( dslLayer . type !== 'Text' && Array . isArray ( layer . layers ) ) { dslLayer . children = _parseDSL ( layer . layers , type ) ; } dsl . push ( dslLayer ) ; } ) ; return dsl ; } ; export default ( sketchData , type ) : DSL => { const layers = [ ] ; for ( let i = 0 ; i < sketchData . length ; i ++ ) { const layer = sketchData [ i ] ; layer . layers = filterGroupLayer ( layer . layers , [ ] , type ) ; if ( type === 'measure' ) { layer . layers = handleSlicePosition ( layer . layers ) ; } layers . push ( layer ) ; } return _parseDSL ( layers , type ) ; } ;