encodedTokenAttributes.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. /**
  6. */
  7. export class TokenMetadata {
  8. static getLanguageId(metadata) {
  9. return (metadata & 255 /* MetadataConsts.LANGUAGEID_MASK */) >>> 0 /* MetadataConsts.LANGUAGEID_OFFSET */;
  10. }
  11. static getTokenType(metadata) {
  12. return (metadata & 768 /* MetadataConsts.TOKEN_TYPE_MASK */) >>> 8 /* MetadataConsts.TOKEN_TYPE_OFFSET */;
  13. }
  14. static containsBalancedBrackets(metadata) {
  15. return (metadata & 1024 /* MetadataConsts.BALANCED_BRACKETS_MASK */) !== 0;
  16. }
  17. static getFontStyle(metadata) {
  18. return (metadata & 30720 /* MetadataConsts.FONT_STYLE_MASK */) >>> 11 /* MetadataConsts.FONT_STYLE_OFFSET */;
  19. }
  20. static getForeground(metadata) {
  21. return (metadata & 16744448 /* MetadataConsts.FOREGROUND_MASK */) >>> 15 /* MetadataConsts.FOREGROUND_OFFSET */;
  22. }
  23. static getBackground(metadata) {
  24. return (metadata & 4278190080 /* MetadataConsts.BACKGROUND_MASK */) >>> 24 /* MetadataConsts.BACKGROUND_OFFSET */;
  25. }
  26. static getClassNameFromMetadata(metadata) {
  27. const foreground = this.getForeground(metadata);
  28. let className = 'mtk' + foreground;
  29. const fontStyle = this.getFontStyle(metadata);
  30. if (fontStyle & 1 /* FontStyle.Italic */) {
  31. className += ' mtki';
  32. }
  33. if (fontStyle & 2 /* FontStyle.Bold */) {
  34. className += ' mtkb';
  35. }
  36. if (fontStyle & 4 /* FontStyle.Underline */) {
  37. className += ' mtku';
  38. }
  39. if (fontStyle & 8 /* FontStyle.Strikethrough */) {
  40. className += ' mtks';
  41. }
  42. return className;
  43. }
  44. static getInlineStyleFromMetadata(metadata, colorMap) {
  45. const foreground = this.getForeground(metadata);
  46. const fontStyle = this.getFontStyle(metadata);
  47. let result = `color: ${colorMap[foreground]};`;
  48. if (fontStyle & 1 /* FontStyle.Italic */) {
  49. result += 'font-style: italic;';
  50. }
  51. if (fontStyle & 2 /* FontStyle.Bold */) {
  52. result += 'font-weight: bold;';
  53. }
  54. let textDecoration = '';
  55. if (fontStyle & 4 /* FontStyle.Underline */) {
  56. textDecoration += ' underline';
  57. }
  58. if (fontStyle & 8 /* FontStyle.Strikethrough */) {
  59. textDecoration += ' line-through';
  60. }
  61. if (textDecoration) {
  62. result += `text-decoration:${textDecoration};`;
  63. }
  64. return result;
  65. }
  66. static getPresentationFromMetadata(metadata) {
  67. const foreground = this.getForeground(metadata);
  68. const fontStyle = this.getFontStyle(metadata);
  69. return {
  70. foreground: foreground,
  71. italic: Boolean(fontStyle & 1 /* FontStyle.Italic */),
  72. bold: Boolean(fontStyle & 2 /* FontStyle.Bold */),
  73. underline: Boolean(fontStyle & 4 /* FontStyle.Underline */),
  74. strikethrough: Boolean(fontStyle & 8 /* FontStyle.Strikethrough */),
  75. };
  76. }
  77. }