@codingame/monaco-vscode-markdown-language-features-default-extension 34.1.3 → 35.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/index.js +78 -11
  2. package/package.json +2 -2
  3. package/resources/KaTeX_AMS-Regular-CYEKBG2K.woff +0 -0
  4. package/resources/KaTeX_AMS-Regular-JKX5W2C4.ttf +0 -0
  5. package/resources/KaTeX_AMS-Regular-U6PRYMIZ.woff2 +0 -0
  6. package/resources/KaTeX_Caligraphic-Bold-5QL5CMTE.woff2 +0 -0
  7. package/resources/KaTeX_Caligraphic-Bold-WZ3QSGD3.woff +0 -0
  8. package/resources/KaTeX_Caligraphic-Bold-ZTS3R3HK.ttf +0 -0
  9. package/resources/KaTeX_Caligraphic-Regular-3LKEU76G.woff +0 -0
  10. package/resources/KaTeX_Caligraphic-Regular-A7XRTZ5Q.ttf +0 -0
  11. package/resources/KaTeX_Caligraphic-Regular-KX5MEWCF.woff2 +0 -0
  12. package/resources/KaTeX_Fraktur-Bold-2QVFK6NQ.woff2 +0 -0
  13. package/resources/KaTeX_Fraktur-Bold-T4SWXBMT.woff +0 -0
  14. package/resources/KaTeX_Fraktur-Bold-WGHVTYOR.ttf +0 -0
  15. package/resources/KaTeX_Fraktur-Regular-2PEIFJSJ.woff2 +0 -0
  16. package/resources/KaTeX_Fraktur-Regular-5U4OPH2X.ttf +0 -0
  17. package/resources/KaTeX_Fraktur-Regular-PQMHCIK6.woff +0 -0
  18. package/resources/KaTeX_Main-Bold-2GA4IZIN.woff +0 -0
  19. package/resources/KaTeX_Main-Bold-W5FBVCZM.ttf +0 -0
  20. package/resources/KaTeX_Main-Bold-YP5VVQRP.woff2 +0 -0
  21. package/resources/KaTeX_Main-BoldItalic-4P4C7HJH.woff +0 -0
  22. package/resources/KaTeX_Main-BoldItalic-N4V3DX7S.woff2 +0 -0
  23. package/resources/KaTeX_Main-BoldItalic-ODMLBJJQ.ttf +0 -0
  24. package/resources/KaTeX_Main-Italic-I43T2HSR.ttf +0 -0
  25. package/resources/KaTeX_Main-Italic-RELBIK7M.woff2 +0 -0
  26. package/resources/KaTeX_Main-Italic-SASNQFN2.woff +0 -0
  27. package/resources/KaTeX_Main-Regular-ARRPAO67.woff2 +0 -0
  28. package/resources/KaTeX_Main-Regular-P5I74A2A.woff +0 -0
  29. package/resources/KaTeX_Main-Regular-W74P5G27.ttf +0 -0
  30. package/resources/KaTeX_Math-BoldItalic-6EBV3DK5.woff +0 -0
  31. package/resources/KaTeX_Math-BoldItalic-K4WTGH3J.woff2 +0 -0
  32. package/resources/KaTeX_Math-BoldItalic-VB447A4D.ttf +0 -0
  33. package/resources/KaTeX_Math-Italic-6KGCHLFN.woff2 +0 -0
  34. package/resources/KaTeX_Math-Italic-KKK3USB2.woff +0 -0
  35. package/resources/KaTeX_Math-Italic-SON4MRCA.ttf +0 -0
  36. package/resources/KaTeX_SansSerif-Bold-RRNVJFFW.woff2 +0 -0
  37. package/resources/KaTeX_SansSerif-Bold-STQ6RXC7.ttf +0 -0
  38. package/resources/KaTeX_SansSerif-Bold-X5M5EMOD.woff +0 -0
  39. package/resources/KaTeX_SansSerif-Italic-HMPFTM52.woff2 +0 -0
  40. package/resources/KaTeX_SansSerif-Italic-PSN4QKYX.woff +0 -0
  41. package/resources/KaTeX_SansSerif-Italic-WTBAZBGY.ttf +0 -0
  42. package/resources/KaTeX_SansSerif-Regular-2TL3USAE.ttf +0 -0
  43. package/resources/KaTeX_SansSerif-Regular-OQCII6EP.woff +0 -0
  44. package/resources/KaTeX_SansSerif-Regular-XIQ62X4E.woff2 +0 -0
  45. package/resources/KaTeX_Script-Regular-72OLXYNA.ttf +0 -0
  46. package/resources/KaTeX_Script-Regular-A5IFOEBS.woff +0 -0
  47. package/resources/KaTeX_Script-Regular-APUWIHLP.woff2 +0 -0
  48. package/resources/KaTeX_Size1-Regular-4HRHTS65.woff +0 -0
  49. package/resources/KaTeX_Size1-Regular-5LRUTBFT.woff2 +0 -0
  50. package/resources/KaTeX_Size1-Regular-7K6AASVL.ttf +0 -0
  51. package/resources/KaTeX_Size2-Regular-222HN3GT.ttf +0 -0
  52. package/resources/KaTeX_Size2-Regular-K5ZHAIS6.woff +0 -0
  53. package/resources/KaTeX_Size2-Regular-LELKET5D.woff2 +0 -0
  54. package/resources/KaTeX_Size3-Regular-TLFPAHDE.woff +0 -0
  55. package/resources/KaTeX_Size3-Regular-UFCO6WCA.ttf +0 -0
  56. package/resources/KaTeX_Size3-Regular-WQRQ47UD.woff2 +0 -0
  57. package/resources/KaTeX_Size4-Regular-7PGNVPQK.ttf +0 -0
  58. package/resources/KaTeX_Size4-Regular-CDMV7U5C.woff2 +0 -0
  59. package/resources/KaTeX_Size4-Regular-PKMWZHNC.woff +0 -0
  60. package/resources/KaTeX_Typewriter-Regular-3F5K6SQ6.ttf +0 -0
  61. package/resources/KaTeX_Typewriter-Regular-MJMFSK64.woff +0 -0
  62. package/resources/KaTeX_Typewriter-Regular-VBYJ4NRC.woff2 +0 -0
  63. package/resources/editor.css.txt +1 -0
  64. package/resources/editor.js +3446 -0
  65. package/resources/editor.ts +128 -0
  66. package/resources/extension.js +192 -179
  67. package/resources/extension.js.map +4 -4
  68. package/resources/index.js +1 -1
  69. package/resources/index2.js +21 -22
  70. package/resources/markdownEditor.css.txt +22 -0
  71. package/resources/package.json +1 -1
  72. package/resources/serverWorkerMain.js +297 -250
  73. package/resources/syntaxHighlighter.ts +216 -0
  74. package/resources/tsconfig.json +1 -0
@@ -0,0 +1,216 @@
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
+ import { LengthEdit, OffsetRange, StringEdit } from '@vscode/markdown-editor';
7
+ import { ISettableObservable, ITransaction, observableValue } from '@vscode/markdown-editor/observables';
8
+
9
+ /**
10
+ * A single coloured run as returned by the `documentSyntaxHighlighting`
11
+ * proposed API. Tokens are dense and offset-free: `sum(length)` equals the
12
+ * highlighted source length.
13
+ */
14
+ interface IHighlightToken {
15
+ readonly length: number;
16
+ readonly foreground: number;
17
+ readonly fontStyle: number;
18
+ }
19
+
20
+ interface IHighlightResult {
21
+ readonly tokens: readonly IHighlightToken[];
22
+ readonly colorMap: readonly string[];
23
+ }
24
+
25
+ /** A `Token` as consumed by `@vscode/markdown-editor`'s code block view. */
26
+ interface IRenderToken {
27
+ readonly length: number;
28
+ readonly className: string | undefined;
29
+ }
30
+
31
+ interface ISnapshot {
32
+ getTokens(queryRange: OffsetRange): { readonly range: OffsetRange; readonly tokens: readonly IRenderToken[] };
33
+ }
34
+
35
+ /**
36
+ * Builds the static CSS rules for the 16 possible font-style bit combinations.
37
+ * The bit values mirror the `SyntaxHighlightingTokenFontStyle` enum from the
38
+ * `documentSyntaxHighlighting` proposed API (Italic = 1, Bold = 2, Underline = 4,
39
+ * Strikethrough = 8), defined in
40
+ * `../../../src/vscode-dts/vscode.proposed.documentSyntaxHighlighting.d.ts`.
41
+ * They cannot be imported here because this module is bundled into the webview.
42
+ */
43
+ function fontStyleRules(): string {
44
+ const rules: string[] = [];
45
+ for (let fontStyle = 1; fontStyle <= 15; fontStyle++) {
46
+ const declarations: string[] = [];
47
+ if (fontStyle & 1) { declarations.push('font-style: italic;'); }
48
+ if (fontStyle & 2) { declarations.push('font-weight: bold;'); }
49
+ const decorations: string[] = [];
50
+ if (fontStyle & 4) { decorations.push('underline'); }
51
+ if (fontStyle & 8) { decorations.push('line-through'); }
52
+ if (decorations.length) { declarations.push(`text-decoration: ${decorations.join(' ')};`); }
53
+ rules.push(`.tok-mdhl-fs-${fontStyle} { ${declarations.join(' ')} }`);
54
+ }
55
+ return rules.join('\n');
56
+ }
57
+
58
+ function colorRules(colorMap: readonly string[]): string {
59
+ return colorMap.map((color, index) => `.tok-mdhl-fg-${index} { color: ${color}; }`).join('\n');
60
+ }
61
+
62
+ function classNameFor(foreground: number, fontStyle: number): string | undefined {
63
+ const parts: string[] = [];
64
+ if (foreground > 0) { parts.push(`mdhl-fg-${foreground}`); }
65
+ if (fontStyle > 0) { parts.push(`mdhl-fs-${fontStyle}`); }
66
+ return parts.length ? parts.join('.') : undefined;
67
+ }
68
+
69
+ function makeSnapshot(tokens: readonly IRenderToken[]): ISnapshot {
70
+ let total = 0;
71
+ for (const token of tokens) { total += token.length; }
72
+ const range = OffsetRange.ofLength(total);
73
+ return { getTokens: () => ({ range, tokens }) };
74
+ }
75
+
76
+ function unstyledTokens(length: number): readonly IRenderToken[] {
77
+ return length > 0 ? [{ length, className: undefined }] : [];
78
+ }
79
+
80
+ /**
81
+ * Keeps the previous tokens but absorbs the length delta into the last token,
82
+ * so the snapshot stays dense (`sum(length) === newLength`) during the brief
83
+ * window before the re-highlight response arrives. Falls back to a single
84
+ * unstyled run when the adjustment is not representable.
85
+ */
86
+ function adjustTokens(tokens: readonly IRenderToken[], previousLength: number, newLength: number): readonly IRenderToken[] {
87
+ const delta = newLength - previousLength;
88
+ if (delta === 0) { return tokens; }
89
+ if (tokens.length === 0) { return unstyledTokens(newLength); }
90
+ const last = tokens[tokens.length - 1];
91
+ const newLastLength = last.length + delta;
92
+ if (newLastLength <= 0) { return unstyledTokens(newLength); }
93
+ return [...tokens.slice(0, -1), { length: newLastLength, className: last.className }];
94
+ }
95
+
96
+ /**
97
+ * A live highlighting session for one fenced code block. Renders an unstyled
98
+ * (or optimistically shifted) snapshot synchronously, then swaps in the themed
99
+ * tokens once the asynchronous `documentSyntaxHighlighting` response lands.
100
+ */
101
+ class HighlighterDocument {
102
+ #text: string;
103
+ #tokens: readonly IRenderToken[];
104
+ readonly snapshot: ISettableObservable<ISnapshot, LengthEdit>;
105
+ readonly #owner: WebviewSyntaxHighlighter;
106
+ readonly #languageId: string;
107
+
108
+ constructor(
109
+ owner: WebviewSyntaxHighlighter,
110
+ languageId: string,
111
+ initialText: string,
112
+ ) {
113
+ this.#owner = owner;
114
+ this.#languageId = languageId;
115
+ this.#text = initialText;
116
+ this.#tokens = unstyledTokens(initialText.length);
117
+ this.snapshot = observableValue('mdSyntaxHighlight', makeSnapshot(this.#tokens));
118
+ this.#request(initialText);
119
+ }
120
+
121
+ update(edit: StringEdit, tx: ITransaction | undefined): void {
122
+ const newText = edit.apply(this.#text);
123
+ const previousLength = this.#text.length;
124
+ this.#tokens = adjustTokens(this.#tokens, previousLength, newText.length);
125
+ this.#text = newText;
126
+ this.snapshot.set(makeSnapshot(this.#tokens), tx, LengthEdit.replace(OffsetRange.ofLength(previousLength), newText.length));
127
+ this.#request(newText);
128
+ }
129
+
130
+ /** Re-highlights the current text, e.g. after a theme change. */
131
+ refresh(): void {
132
+ this.#request(this.#text);
133
+ }
134
+
135
+ dispose(): void {
136
+ this.#owner._remove(this);
137
+ }
138
+
139
+ async #request(text: string): Promise<void> {
140
+ const result = await this.#owner.request(text, this.#languageId);
141
+ if (text !== this.#text) {
142
+ return;
143
+ }
144
+ this.#tokens = result.tokens.map(token => ({ length: token.length, className: classNameFor(token.foreground, token.fontStyle) }));
145
+ this.snapshot.set(makeSnapshot(this.#tokens), undefined, LengthEdit.replace(OffsetRange.ofLength(text.length), text.length));
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Bridges `@vscode/markdown-editor`'s `ISyntaxHighlighter` contract to the
151
+ * extension host's `documentSyntaxHighlighting` proposed API over the webview
152
+ * message channel. The webview cannot call the proposed API directly, so each
153
+ * highlight request is proxied to the host and the themed result posted back.
154
+ */
155
+ export class WebviewSyntaxHighlighter {
156
+ #nextRequestId = 0;
157
+ readonly #pending = new Map<number, (result: IHighlightResult) => void>();
158
+ readonly #documents = new Set<HighlighterDocument>();
159
+ readonly #styleElement: HTMLStyleElement;
160
+ readonly #postMessage: (message: unknown) => void;
161
+
162
+ constructor(postMessage: (message: unknown) => void) {
163
+ this.#postMessage = postMessage;
164
+ this.#styleElement = document.createElement('style');
165
+ this.#styleElement.textContent = fontStyleRules();
166
+ document.head.appendChild(this.#styleElement);
167
+ }
168
+
169
+ create(languageId: string, initialText: string): HighlighterDocument {
170
+ const document = new HighlighterDocument(this, languageId, initialText);
171
+ this.#documents.add(document);
172
+ return document;
173
+ }
174
+
175
+ request(source: string, languageId: string): Promise<IHighlightResult> {
176
+ const requestId = this.#nextRequestId++;
177
+ return new Promise<IHighlightResult>(resolve => {
178
+ this.#pending.set(requestId, resolve);
179
+ this.#postMessage({ type: 'highlight', requestId, source, languageId });
180
+ });
181
+ }
182
+
183
+ /**
184
+ * Handles highlighter-related messages from the extension host. Returns
185
+ * `true` if the message was consumed.
186
+ */
187
+ handleMessage(message: { readonly type: string; readonly requestId?: number; readonly tokens?: readonly IHighlightToken[]; readonly colorMap?: readonly string[] }): boolean {
188
+ switch (message.type) {
189
+ case 'highlightResult': {
190
+ const resolve = this.#pending.get(message.requestId!);
191
+ if (resolve) {
192
+ this.#pending.delete(message.requestId!);
193
+ this.#updateColors(message.colorMap!);
194
+ resolve({ tokens: message.tokens!, colorMap: message.colorMap! });
195
+ }
196
+ return true;
197
+ }
198
+ case 'highlightThemeChanged': {
199
+ for (const document of this.#documents) {
200
+ document.refresh();
201
+ }
202
+ return true;
203
+ }
204
+ default:
205
+ return false;
206
+ }
207
+ }
208
+
209
+ _remove(document: HighlighterDocument): void {
210
+ this.#documents.delete(document);
211
+ }
212
+
213
+ #updateColors(colorMap: readonly string[]): void {
214
+ this.#styleElement.textContent = `${fontStyleRules()}\n${colorRules(colorMap)}`;
215
+ }
216
+ }
@@ -0,0 +1 @@
1
+ {"extends":"../../tsconfig.base.json","compilerOptions":{"rootDir":".","outDir":"./dist/","module":"esnext","moduleResolution":"bundler","lib":["es2024","DOM","DOM.Iterable"],"types":["vscode-webview"],"typeRoots":["../node_modules/@types"],"skipLibCheck":true,"noEmit":true},"include":["./**/*.ts"]}