import type { Declarations , PluginApply , PluginTokenResult } from './types' ; import { joinTruthy , asTokens } from './util' ; export const apply = ( ... tokens ) : PluginTokenResult => ( parse ) => parse ( asTokens ( tokens ) ) ; const positions = ( resolve ) => ( value , position , prefix ? , suffix ? ) : Declarations | undefined => { if ( value ) { const properties = position && resolve ( position ) ; if ( properties && properties . length > 0 ) { return properties . reduce ( ( declarations , property ) => { declarations [ joinTruthy ( [ prefix , property , suffix ] ) ] = value ; return declarations ; } , { } as Declarations ) ; } } } ; const CORNERS = { t : [ 'top-left' , 'top-right' ] , r : [ 'top-right' , 'bottom-right' ] , b : [ 'bottom-left' , 'bottom-right' ] , l : [ 'bottom-left' , 'top-left' ] , tl : [ 'top-left' ] , tr : [ 'top-right' ] , bl : [ 'bottom-left' ] , br : [ 'bottom-right' ] , } ; export const corners = positions ( ( key ) => CORNERS [ key ] ) ; const X_Y_TO_EDGES = { x : 'lr' , y : 'tb' } ; const EDGES = { t : 'top' , r : 'right' , b : 'bottom' , l : 'left' , } ; export const expandEdges = ( key ) : string [ ] | undefined => { const parts = ( X_Y_TO_EDGES [ key ] || key || '' ) . split ( '' ) . sort ( ) . reduce ( ( result , edge ) => { if ( result && EDGES [ edge ] ) { result . push ( EDGES [ edge ] as string ) ; return result ; } } , [ ] as string [ ] | undefined | void ) as string [ ] | undefined ; if ( parts && parts . length > 0 ) return parts ; } ; export const edges = positions ( expandEdges ) ;