import { Layer , Page , Group , Selection , Fill , Border , } from 'sketch' ; export const getParents = ( parents , id ) => [ ... parents , id ] ; export const hasBorder = ( layer ) : boolean => ! ! layer . style . borders . filter ( ( border ) => border . enabled ) . length ; export const hasFill = ( layer ) : boolean => ! ! layer . style . fills . filter ( ( fill ) => fill . enabled ) . length ; export const hasTextColor = ( layer ) => ! ! layer . style . textColor ; export const createDataStructure = ( layer , colorType , parents ) => ( { id : layer . id , name : layer . name , type : layer . type , colorType , parents , } ) ; export const getColorArray = ( colorsObject , color , dataStructure ) => ( colorsObject [ color ] ? [ ... colorsObject [ color ] , dataStructure ] : [ dataStructure ] ) ; const mapLayerToPageWithOnlyLayerAcc = ( accLayer , layer ) => { let mappedLayer ; if ( ! accLayer ) { mappedLayer = layer ; } else { mappedLayer = { id : layer . id , type : layer . type , name : layer . name , layers : [ accLayer ] , } as Partial < Page > | Partial < Group > ; } if ( layer . parent . type === 'Document' ) { return mappedLayer ; } return mapLayerToPageWithOnlyLayerAcc ( mappedLayer , layer . parent as Layer ) ; } ; const mapLayerToPageWithOnlyLayer = ( layer ) : Partial < Page > => mapLayerToPageWithOnlyLayerAcc ( null , layer ) ; export const getPagesWithSelectedLayers = ( selectedLayers ) : Page [ ] => { return selectedLayers . layers . map ( ( layer ) => mapLayerToPageWithOnlyLayer ( layer ) ) as Page [ ] ; } ;