upsetjs import type { ISetLike } from '@upsetjs/model' ; import type { UpSetAddonHandlerInfos , UpSetAddons } from '../interfaces' ; function noop ( ) { return undefined ; } export function wrap < T > ( f ? ) { if ( ! f ) { return noop ; } return ( set , addons ) => { return function ( this , evt ) { return f . call ( this , set , evt . nativeEvent , addons . map ( ( a ) => ( a . createOnHandlerData ? a . createOnHandlerData ( set ) : null ) ) ) ; } ; } ; } export function addonPositionGenerator ( total , padding ) { let beforeAcc = 0 ; let afterAcc = 0 ; return ( addon ) => { let x = 0 ; if ( addon . position === 'before' ) { beforeAcc += addon . size + padding ; x = - beforeAcc ; } else { x = total + afterAcc + padding ; afterAcc += addon . size + padding ; } return x ; } ; } export function mergeColor ( style ? , color ? , prop = 'fill' ) { if ( ! color ) { return style ; } if ( ! style ) { return ! color ? undefined : { [ prop ] : color } ; } return Object . assign ( { [ prop ] : color } , style ) ; }