import { AvailableFilter } from '../enums/available-filter.enum' ; import { SUPPORTED_FILTERS } from '../globals/supported-filters.global' ; export const applyFilter = ( context , canvasFilters ) => { canvasFilters . match ( /([-a-z]+)(?:\(([\w\d\s\.%-]*)\))?/gmi ) . map ( filter => filter . match ( /([-a-z]+)(?:\((.*)\))?/i ) . slice ( 1 , 3 ) as [ AvailableFilter , string ] ) . reduce ( ( input , [ filter , options ] ) => { if ( SUPPORTED_FILTERS . has ( filter ) ) { return SUPPORTED_FILTERS . get ( filter ) ( input , ... ( options || '' ) . split ( ' ' ) ) ; } return input ; } , context ) ; } ; export const normalizeNumberPercentage = ( percentage ) : number => { let normalized = parseFloat ( percentage ) ; if ( /%\s*?$/i . test ( percentage ) ) { normalized /= 100 ; } return normalized ; } ; export const normalizeAngle = ( angle ) : number => { let normalized = parseFloat ( angle ) ; const unit = angle . slice ( normalized . toString ( ) . length ) ; switch ( unit ) { case 'deg' : normalized /= 360 ; break ; case 'grad' : normalized /= 400 ; break ; case 'rad' : normalized /= 2 * Math . PI ; break ; } return normalized ; } ; export const normalizeLength = ( length ) : number => { return parseFloat ( length ) ; } ;