import { Modifier , IRequest , EType , IHTMLInjection , EHTMLInjectionType , IModifierRange , Modifiers , } from 'chipmunk.client.toolkit' ; export class FiltersModifier extends Modifier { private _ranges : IModifierRange [ ] = [ ] ; constructor ( filters , row ) { super ( ) ; this . _map ( row , filters ) ; } public getInjections ( ) { const injections = [ ] ; this . _ranges . forEach ( ( range ) => { injections . push ( ... [ { offset : range . start , injection : `<span class="noreset match">` , type : EHTMLInjectionType . open , } , { offset : range . end , injection : `</span>` , type : EHTMLInjectionType . close , } , ] ) ; } ) ; return injections ; } public type ( ) { return EType . match ; } public obey ( ranges ) { this . _ranges = Modifiers . obey ( ranges , this . _ranges ) ; } public getRanges ( ) { return this . _ranges ; } public getGroupPriority ( ) { return 1 ; } public finalize ( str ) { return str ; } public getName ( ) { return 'FiltersModifier' ; } private _map ( row , filters ) { filters . forEach ( ( request ) => { row . replace ( request . reg , ( match , ... args ) => { const offset = typeof args [ args . length - 2 ] === 'number' ? args [ args . length - 2 ] : args [ args . length - 3 ] ; this . _ranges . push ( { start : offset , end : offset + match . length , } ) ; return '' ; } ) ; } ) ; this . _ranges = Modifiers . removeIncluded ( this . _ranges ) ; this . _ranges = Modifiers . removeCrossing ( this . _ranges ) ; } }