import { FontMetrics } from './view' ; import { DEVMODE } from '../utils/environment' ; import { colorFromARBG } from '../utils/misc' ; export const COLORS = { CURSOR : '#AAAAAA' , BACKGROUND : '#2e2e2e' , FOREGROUND : '#ffffff' , } ; /**
 * The styles for the editor - xi-core reserves numbers below `N_RESERVED_STYLES` for selection
 * and highlights, etc.
 */ export const STYLE_SELECTION = 0 ; export const STYLE_HIGHLIGHT = 1 ; export const N_RESERVED_STYLES = 2 ; /**
 * Simple wrapper class for a style defined by the xi-syntect-plugin.
 */ export class Style { static DefinedStyles : Style [ ] = [ new Style ( STYLE_SELECTION , '' , 'rgba(135, 135, 135, 0.25)' ) , new Style ( STYLE_HIGHLIGHT , '' , 'rgba(255, 215, 0, 0.5)' ) , ] ; constructor ( private id , public fg , public bg , public weight = 'normal' , public italic = false , public underline = false ) { } fontString ( metrics ) { return `${ this . italic ? 'italic' : '' } ${ this . weight } ${ metrics . fontString ( ) }` ; } isSelection ( ) { return this === Style . DefinedStyles [ STYLE_SELECTION ] ; } isHighlight ( ) { return this === Style . DefinedStyles [ STYLE_HIGHLIGHT ] ; } isReservedStyle ( ) { return this . id < N_RESERVED_STYLES ; } } Style . DefinedStyles [ - 1 ] = new Style ( - 1 , 'white' , '' ) ; export const defineStyle = ( params ) => { const { id , fg_color , bg_color , italic , weight , underline } = params ; Style . DefinedStyles [ id ] = new Style ( id , colorFromARBG ( fg_color ) , colorFromARBG ( bg_color ) , weight , italic , underline ) ; } ; /**
 * Simple range class.
 */ export class Range { param { Number } start param { Number } length constructor ( public start = 0 , public length = 0 ) { } } /**
 * A basic type representing a range of text and and a style identifier.
 */ export class StyleSpan { param utf8ToChIndices param utf8Styles param charLength static stylesFromCore ( utf8ToChIndices , utf8Styles , charLength ) { const styles = [ ] ; let pos = 0 , pos8 = 0 ; if ( utf8Styles . length ) { const firstStylePos = utf8ToChIndices [ utf8Styles [ 0 ] ] ; if ( firstStylePos > pos ) { styles . push ( new StyleSpan ( new Range ( 0 , firstStylePos ) ) ) ; } } for ( let i = 0 ; i < utf8Styles . length ; i += 3 ) { const start8 = pos8 + utf8Styles [ i ] ; const end8 = start8 + utf8Styles [ i + 1 ] ; const styleId = utf8Styles [ i + 2 ] ; const start = utf8ToChIndices [ start8 ] ; const end = utf8ToChIndices [ end8 ] ; if ( start == undefined || end == undefined || end < start ) { console . error ( 'bad offsets' ) ; } styles . push ( new StyleSpan ( new Range ( start , end - start ) , Style . DefinedStyles [ styleId ] ) ) ; pos8 = end8 ; pos = end ; } if ( pos < charLength ) { styles . push ( new StyleSpan ( new Range ( pos , charLength - pos ) ) ) ; } return styles ; } param { Range } range param { StyleIdentifier } style constructor ( public range , public style = Style . DefinedStyles [ - 1 ] ) { } } if ( DEVMODE ) { ( < any > window ) . DefinedStyles = Style . DefinedStyles ; }