import { Layer } from './types' ; import handleOverlap from "./handleOverlap" ; import calculateRow from "./calculateRow" ; import isBlock from "./isBlock" ; import calculateBlock from "./calculateBlock" ; import handleParentIsText from "./handleParentIsText" ; import markIsOnlyText from "./markIsOnlyText" ; import { isRow , layoutRow } from "./row" ; import { isLabelList , layoutLabelList , isSingleText } from "./handleTypeLayout" ; import { isVerticalList , calculateVerticalList , isLeftImgRightInfo , calculateLeftImgRightInfo , handleContinuousListItem , } from './calculateClassName' ; import * as fs from 'fs' ; param { Layer [ ] } data param { Layer } parent returns const handleLayout = ( data , parent ? ) => { let dataIsPositionLayout = [ ] ; let dataIsNotPositionLayout = [ ] ; data . forEach ( ( item ) => { if ( parent && item . isPosition ) { dataIsPositionLayout . push ( item ) ; } else { dataIsNotPositionLayout . push ( item ) ; } } ) ; data = dataIsNotPositionLayout ; if ( isLeftImgRightInfo ( data ) ) { data = calculateLeftImgRightInfo ( data ) ; } if ( isVerticalList ( data ) ) { data = calculateVerticalList ( data ) ; } else { data = handleContinuousListItem ( data ) ; } switch ( true ) { case parent === undefined : data = calculateRow ( data ) ; break ; case parent && parent . textContainer : break ; case parent && parent . _class == "text" : data = handleParentIsText ( data , parent ) ; break ; case isLabelList ( data , parent ) : data = layoutLabelList ( data , parent ) ; break ; case isBlock ( data ) : data = calculateBlock ( data , parent ) ; break ; case isRow ( data ) : data = layoutRow ( data , parent ) ; break ; default : break ; } if ( parent ) { markIsOnlyText ( data , parent ) ; } data = handleOverlap ( dataIsPositionLayout , parent , data ) ; if ( Array . isArray ( data ) ) { for ( let i = 0 ; i < data . length ; i ++ ) { try { if ( isSingleText ( data [ i ] ) ) { delete data [ i ] . style . width ; if ( data . length > 1 && data [ i ] . style . textAlign == 'right' && parent && data [ i ] . structure . width < parent . structure . width * 0.9 ) { delete data [ i ] . style . textAlign ; } } } catch ( error ) { console . log ( '文本宽度剔除异常' + error ) ; } if ( Array . isArray ( data [ i ] . children ) && data [ i ] . children . length > 0 ) { data [ i ] . children = handleLayout ( data [ i ] . children , data [ i ] ) ; } } } return data ; } ; export default handleLayout ;