import { SKLayer , BorderRadius } from '../../types' ; import { precisionControl } from '../../common/utils' ; import * as fs from 'fs' ; param { * } layer const calculateBorderRadius = ( layer ) : BorderRadius => { if ( layer . points && layer . points . length !== 4 ) { return { } ; } if ( layer . points && layer . points . length == 4 && layer . points [ 0 ] . curveMode == 1 && layer . points [ 1 ] . curveMode == 1 && layer . points [ 2 ] . curveMode == 1 && layer . points [ 3 ] . curveMode == 1 && layer . fixedRadius !== undefined ) { const cornerRadiusList = [ ] ; for ( let item of layer . points ) { cornerRadiusList . push ( item . cornerRadius ) ; } const [ topLeft , topRight , bottomRight , bottomLeft ] = cornerRadiusList ; return { topLeft : precisionControl ( topLeft ) , topRight : precisionControl ( topRight ) , bottomRight : precisionControl ( bottomRight ) , bottomLeft : precisionControl ( bottomLeft ) } ; } if ( layer . points ?. length === 4 && layer . points [ 0 ] . curveMode === 2 && layer . points [ 1 ] . curveMode === 2 && layer . points [ 2 ] . curveMode === 2 && layer . points [ 3 ] . curveMode === 2 ) { const cornerRadiusList = [ ] ; for ( let item of layer . points ) { cornerRadiusList . push ( item . cornerRadius ) ; } const [ topLeft , topRight , bottomRight , bottomLeft ] = cornerRadiusList ; if ( topLeft === 0 && topRight === 0 && bottomRight === 0 && bottomLeft === 0 ) { return { topLeft : '50%' , topRight : '50%' , bottomRight : '50%' , bottomLeft : '50%' , } ; } } let radius = 0 ; if ( layer . layers && layer . layers . length && layer . layers [ 0 ] . fixedRadius ) { radius = layer . layers [ 0 ] . fixedRadius > layer . frame . height / 2 ? layer . frame . height / 2 : layer . layers [ 0 ] . fixedRadius ; } else if ( layer . fixedRadius ) { radius = layer . fixedRadius > layer . frame . height / 2 ? layer . frame . height / 2 : layer . fixedRadius ; } return { topLeft : precisionControl ( radius ) , topRight : precisionControl ( radius ) , bottomRight : precisionControl ( radius ) , bottomLeft : precisionControl ( radius ) } ; } ; export default calculateBorderRadius ;