import { Range , Position , TextEditorDecorationType } from 'vscode' ; import { IDecoration } from '../util/color-util' ; import Color from './color' ; class ColorDecoration implements IDecoration { type { Color } public memberOf public color : Color ; type { boolean } public memberOf public disposed = false ; public hidden = false ; private decorationFn : ( Color ) => TextEditorDecorationType ; public currentRange : Range ; private _decoration : TextEditorDecorationType ; type { TextEditorDecorationType } memberOf get decoration ( ) : TextEditorDecorationType { this . _generateDecorator ( ) ; return this . _decoration ; } set decoration ( deco ) { this . _decoration = deco ; } get rgb ( ) : [ number , number , number ] { return this . color . rgb ; } public constructor ( color , line , decorationFn ) { this . color = color ; this . decorationFn = decorationFn ; this . generateRange ( line ) ; } public memberOf public dispose ( ) { try { this . _decoration . dispose ( ) ; this . disposed = true ; } catch ( error ) { } } public memberOf public hide ( ) { if ( this . _decoration ) { this . _decoration . dispose ( ) ; } this . hidden = true ; } param { number } line returns { Range } memberOf public generateRange ( line ) { const range = new Range ( new Position ( line , this . color . positionInText ) , new Position ( line , this . color . positionInText + this . color . value . length ) ) ; this . currentRange = range ; return range ; } public shouldGenerateDecoration ( ) { if ( this . disposed === true ) { return false ; } return this . _decoration === null || this . _decoration === undefined || this . hidden ; } private _generateDecorator ( ) { this . _decoration = this . decorationFn ( this . color ) ; } } export default ColorDecoration ;