import cb from 'color-blind' ; import { ColorBlindnessMode , ColorBlindnessMeta , Scheme } from './interfaces' ; const noop = ( color ) => color ; param scheme param mode export function colorBlindness ( scheme , mode ? ) { const m = mode || ColorBlindnessMode . None ; const fnName = ColorBlindnessMode [ m ] . toLowerCase ( ) ; const fn = cb [ fnName ] || noop ; return Object . entries ( scheme ) . reduce ( ( acc , cur ) => { const [ key , value ] = cur ; if ( Array . isArray ( value ) ) { acc [ key ] = value . map ( c => fn ( c ) ) ; } else { acc [ key ] = fn ( value ) ; } return acc ; } , { } as Record < string , any > ) as Scheme ; } type CBMetaMap = Record < string , { incidence : number ; description : string ; } > ; const cbMeta = { None : { incidence : 0.92 , description : 'Normal color vision' , } , Deuteranomaly : { incidence : 0.06 , description : 'Red/green due to mutated green pigment' , } , Protanomaly : { incidence : 0.01 , description : 'Red/green due to mutated red pigment' , } , Protanopia : { incidence : 0.01 , description : 'Red/green due to missing red cones' , } , Deuteranopia : { incidence : 0.01 , description : 'Red/green due to missing green cones' , } , Tritanopia : { incidence : 0.01 , description : 'Blue/yellow due to missing blue cones' , } , Tritanomaly : { incidence : 0.001 , description : 'Blue/yellow due to mutated blue pigment' , } , Achromatopsia : { incidence : 0.003 , description : 'No color, often due to retinal transduction pathway, extremely rare' , } , } ; param mode export function colorBlindnessInfo ( mode ) { const key = ColorBlindnessMode [ mode ] ; return cbMeta [ key ] ; }