import { getProp } from "@esri/hub-common" ; import { ISection , ISettings , IEntry , ICard , IRow } from "./types" ; param { Object } layout private export function _getImageCropIdsFromLayout ( layout ) { const imgAssets = [ ] as IEntry [ ] | ISettings [ ] ; const headerLogo = getProp ( layout , "header.component.settings.logo" ) ; if ( headerLogo && headerLogo . cropId ) { imgAssets . push ( headerLogo ) ; } const sections = getProp ( layout , "sections" ) || [ ] ; return sections . reduce ( collectSectionAssets , imgAssets ) . filter ( hasCropId ) . map ( extractCropId ) ; } function collectSectionAssets ( assets , section ) { const sectionAssets = section . rows . reduce ( collectCards , [ ] ) . filter ( isImageOrJumbotronCard ) . map ( extractSettingsProperty ) ; if ( getProp ( section , "style.background.cropSrc" ) ) { sectionAssets . unshift ( section . style . background ) ; } return assets . concat ( sectionAssets ) ; } function collectCards ( acc , row ) { return acc . concat ( row . cards ) ; } function isImageOrJumbotronCard ( card ) { return [ "image-card" , "jumbotron-card" ] . indexOf ( card . component . name ) > - 1 ; } function extractSettingsProperty ( card ) { return card . component . settings ; } function hasCropId ( entry ) { return ! ! entry . cropId ; } function extractCropId ( entry ) { return entry . cropId ; }