import { getResourceXMLPathAsync } from './Paths' ; import { buildResourceItem , getObjectAsResourceItems , getResourceItemsAsObject , ResourceItemXML , ResourceKind , ResourceXML , } from './Resources' ; export function getProjectColorsXMLPathAsync ( projectRoot , { kind } = { } ) { return getResourceXMLPathAsync ( projectRoot , { kind , name : 'colors' } ) ; } export function setColorItem ( itemToAdd , colorFileContentsJSON ) { if ( colorFileContentsJSON . resources ?. color ) { const colorNameExists = colorFileContentsJSON . resources . color . filter ( ( e ) => e . $ . name === itemToAdd . $ . name ) [ 0 ] ; if ( colorNameExists ) { colorNameExists . _ = itemToAdd . _ ; } else { colorFileContentsJSON . resources . color . push ( itemToAdd ) ; } } else { if ( ! colorFileContentsJSON . resources || typeof colorFileContentsJSON . resources === 'string' ) { colorFileContentsJSON . resources = { } ; } colorFileContentsJSON . resources . color = [ itemToAdd ] ; } return colorFileContentsJSON ; } export function removeColorItem ( named , contents ) { if ( contents . resources ?. color ) { const index = contents . resources . color . findIndex ( ( e ) => e . $ . name === named ) ; if ( index > - 1 ) { contents . resources . color . splice ( index , 1 ) ; } } return contents ; } /**
 * Set or remove value in XML based on nullish factor of the `value` property.
 */ export function assignColorValue ( xml , { value , name , } ) { if ( value ) { return setColorItem ( buildResourceItem ( { name , value } ) , xml ) ; } return removeColorItem ( name , xml ) ; } param xml returns export function getColorsAsObject ( xml ) { if ( ! xml ?. resources ?. color ) { return null ; } return getResourceItemsAsObject ( xml . resources . color ) ; } param xml returns export function getObjectAsColorsXml ( obj ) { return { resources : { color : getObjectAsResourceItems ( obj ) } } ; }