import getString from './getString' ; import getStringStyle from './getStringStyle' ; import { SKLayer , Text } from '../../types' ; export default ( text , layer ) : Text => { if ( layer . _class !== 'text' ) { return text ; } text . type = 'Text' ; if ( ! text . style . textStyle ) { text . style . textStyle = { } ; } text . value = getString ( layer ) ; let strStyleList = getStringStyle ( layer ) ; if ( Array . isArray ( strStyleList ) && strStyleList . length > 0 ) { if ( strStyleList [ 0 ] . paragraphSpacing ) { text . style . textStyle . paragraphSpacing = strStyleList [ 0 ] . paragraphSpacing ; } for ( let i = 0 ; i < strStyleList . length ; i ++ ) { delete strStyleList [ i ] . paragraphSpacing ; } } const style = getStringStyle ( layer ) [ 0 ] ; if ( style && style . pos ) { delete style . pos ; } text . style . textStyle = style || { } ; if ( Array . isArray ( strStyleList ) && strStyleList . length > 1 ) { text . children = [ ] ; for ( let i = 0 ; i < strStyleList . length ; i ++ ) { let strStyle = strStyleList [ i ] ; let tempObj = { type : 'Text' , value : '' , style : { textStyle : { lineHeight : + text . structure . height } } , structure : { height : text . structure . height , y : text . structure . y , } } ; if ( i == 0 ) { tempObj . structure . x = text . structure . x ; } for ( let key in strStyle ) { if ( key === 'pos' ) { let [ location , length ] = strStyle [ key ] ; tempObj . value = text . value . substr ( location , length ) ; delete strStyle . pos ; } else { tempObj . style . textStyle [ key ] = strStyle [ key ] ; } } text . children . push ( tempObj ) ; } } return text ; } ;