import * as d3 from 'd3' ; import { getYSeries , query , contrastRatio } from '@byted/prism' ; export function createPalette ( seedColors , backgroundColor = '#fff' ) { const primaryContrastRatio = contrastRatio ( d3 . rgb ( backgroundColor ) , d3 . rgb ( seedColors . primaryColor ) ) ; const contrastRatioList = getYSeries ( 'curveByDesign' , 11 , primaryContrastRatio ) ; const primaryIndex = contrastRatioList . indexOf ( primaryContrastRatio ) ; const colorSequences = query ( { space : 'Lab' , backgroundColor , contrastRatioList , seedColors , } , result => { result . primaryColor [ primaryIndex ] = [ seedColors . primaryColor , primaryContrastRatio ] ; return result ; } ) ; console . log ( colorSequences ) ; return colorSequences ; } export function pickPalette ( seedColors = { } , colorSequences , picked = [ 7 , 6 , 5 , 3 , 1 ] ) { return Object . keys ( seedColors ) . map ( color => { const currentColor = seedColors [ color ] ; return { color , pickedColor : [ ] . concat ( currentColor ) . concat ( picked . map ( index => { return colorSequences [ color ] [ index ] [ 0 ] ; } ) ) , } ; } ) . reduce ( ( pre , item ) => { return Object . assign ( { } , pre , { [ item . color ] : item . pickedColor , } ) ; } , { } ) ; }