import { Layer } from '../types' ; export const utils = { isEqualWidth ( data ) { let setList = new Set ( ) ; for ( let item of data ) { setList . add ( item . structure . width ) ; } let ary = [ ... new Set ( setList ) ] ; return ary . length == 1 ? true : false ; } , isAlignMiddle ( data , parent ) { let middlePos = parent . structure . y + parent . structure . height / 2 ; let isAlignMiddle = true ; for ( let i = 0 ; i < data . length ; i ++ ) { let item = data [ i ] ; if ( Math . abs ( item . structure . y + item . structure . height / 2 - middlePos ) > 2 ) { isAlignMiddle = false ; break ; } } return isAlignMiddle ; } , isEqualHeight ( data ) { let setList = new Set ( ) ; for ( let item of data ) { setList . add ( item . structure . height ) ; } let ary = [ ... new Set ( setList ) ] ; return ary . length == 1 ? true : false ; } , hasTextType ( data ) { if ( data . type == "Text" ) return true ; if ( data . children ) { let textList = [ ] ; for ( let item of data . children ) { if ( item . type == "Text" ) { textList . push ( item ) ; } } return textList . length == 1 ; } return false ; } , isSameSpacing ( data ) { let flag = true ; let space = data [ 1 ] . structure . x - data [ 0 ] . structure . x - data [ 0 ] . structure . width ; for ( let i = 1 ; i < data . length ; i ++ ) { if ( data [ i ] . structure . y == data [ i - 1 ] . structure . y && Math . abs ( data [ i ] . structure . x - data [ i - 1 ] . structure . x - data [ i - 1 ] . structure . width - space ) > 4 || ( ! data [ i ] . structure . x && data [ i ] . structure . x !== 0 ) ) { flag = false ; break ; } } return flag ; } , hasBorder ( data ) { let flag = true ; for ( let i = 0 ; i < data . length ; i ++ ) { let item = data [ i ] ; if ( ! ( item . structure ?. border ) ) { flag = false ; break ; } } return flag ; } , hasBackground ( data ) { let flag = true ; for ( let i = 0 ; i < data . length ; i ++ ) { let item = data [ i ] ; if ( item . style ?. background ) { flag = false ; break ; } } return flag ; } , isSameParentHeight ( data , parent ) { let flag = true ; for ( let i = 0 ; i < data . length ; i ++ ) { let item = data [ i ] ; if ( item . structure . height != parent . structure . height ) { flag = false ; break ; } } return flag ; } , isHorizontalCloseParent ( data , parent ) { if ( data . length < 2 ) return false ; return ( data [ 0 ] . structure . x == parent . structure . x && Math . abs ( data [ data . length - 1 ] . structure . x + data [ data . length - 1 ] . structure . width - parent . structure . x - parent . structure . width ) < 2 ) ; } , isVerticalCloseParent ( data , parent ) { if ( data . length < 2 ) return false ; return ( data [ 0 ] . structure . y == parent . structure . y && Math . abs ( data [ data . length - 1 ] . structure . y + data [ data . length - 1 ] . structure . height - parent . structure . y - parent . structure . height ) < 2 ) ; } } ;