monaco-editor-core
Version:
A browser based code editor
78 lines (77 loc) • 3.31 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
*/
export class TokenMetadata {
static getLanguageId(metadata) {
return (metadata & 255 /* MetadataConsts.LANGUAGEID_MASK */) >>> 0 /* MetadataConsts.LANGUAGEID_OFFSET */;
}
static getTokenType(metadata) {
return (metadata & 768 /* MetadataConsts.TOKEN_TYPE_MASK */) >>> 8 /* MetadataConsts.TOKEN_TYPE_OFFSET */;
}
static containsBalancedBrackets(metadata) {
return (metadata & 1024 /* MetadataConsts.BALANCED_BRACKETS_MASK */) !== 0;
}
static getFontStyle(metadata) {
return (metadata & 30720 /* MetadataConsts.FONT_STYLE_MASK */) >>> 11 /* MetadataConsts.FONT_STYLE_OFFSET */;
}
static getForeground(metadata) {
return (metadata & 16744448 /* MetadataConsts.FOREGROUND_MASK */) >>> 15 /* MetadataConsts.FOREGROUND_OFFSET */;
}
static getBackground(metadata) {
return (metadata & 4278190080 /* MetadataConsts.BACKGROUND_MASK */) >>> 24 /* MetadataConsts.BACKGROUND_OFFSET */;
}
static getClassNameFromMetadata(metadata) {
const foreground = this.getForeground(metadata);
let className = 'mtk' + foreground;
const fontStyle = this.getFontStyle(metadata);
if (fontStyle & 1 /* FontStyle.Italic */) {
className += ' mtki';
}
if (fontStyle & 2 /* FontStyle.Bold */) {
className += ' mtkb';
}
if (fontStyle & 4 /* FontStyle.Underline */) {
className += ' mtku';
}
if (fontStyle & 8 /* FontStyle.Strikethrough */) {
className += ' mtks';
}
return className;
}
static getInlineStyleFromMetadata(metadata, colorMap) {
const foreground = this.getForeground(metadata);
const fontStyle = this.getFontStyle(metadata);
let result = `color: ${colorMap[foreground]};`;
if (fontStyle & 1 /* FontStyle.Italic */) {
result += 'font-style: italic;';
}
if (fontStyle & 2 /* FontStyle.Bold */) {
result += 'font-weight: bold;';
}
let textDecoration = '';
if (fontStyle & 4 /* FontStyle.Underline */) {
textDecoration += ' underline';
}
if (fontStyle & 8 /* FontStyle.Strikethrough */) {
textDecoration += ' line-through';
}
if (textDecoration) {
result += `text-decoration:${textDecoration};`;
}
return result;
}
static getPresentationFromMetadata(metadata) {
const foreground = this.getForeground(metadata);
const fontStyle = this.getFontStyle(metadata);
return {
foreground: foreground,
italic: Boolean(fontStyle & 1 /* FontStyle.Italic */),
bold: Boolean(fontStyle & 2 /* FontStyle.Bold */),
underline: Boolean(fontStyle & 4 /* FontStyle.Underline */),
strikethrough: Boolean(fontStyle & 8 /* FontStyle.Strikethrough */),
};
}
}