@coldsmirk/inkstone-monaco 0.36.1 → 0.38.0

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.
package/README.md CHANGED
@@ -12,13 +12,15 @@ Part of [inkstone](https://github.com/coldsmirk/inkstone). For a drop-in React c
12
12
  - **`disabledKeybindings` / `installDisabledKeybindings`** — swallow the find/replace chords and the command palette's F1 for editors that opt in. Monaco's standalone keybinding service is page-global and its rules are permanent, so the install registers each chord once per monaco module's service (duplicate copies of this package share the ledger; independent monaco bundles register their own) and scopes it with a per-capability context key created on the opted-in editor; the chord table is held to the installed `monaco-editor` by an upgrade-tripwire test.
13
13
  - **`installJsxTagClosing`** — VS Code's auto-closing JSX tags: a typed `>` that completes an opening tag inserts the matching closing tag and keeps the caret between the pair. Parser-backed: the bundled TS worker subclasses monaco's stock worker to expose `getJsxClosingTagAtPosition` — a language-service call monaco never proxied (VS Code ships the feature in its TypeScript extension, outside the editor core) — so generics, comparisons, arrow functions, and already-closed elements never trigger. Only a *typed* `>` triggers: the gates require one bare single-character insertion into a **writable** TypeScript/JavaScript model whose path ends in `.tsx` / `.jsx`, and the reply lands only while the caret still sits right after that `>` — so `replaceInEditor` replacements, `StreamingEditorController` appends (the stream holds the editor read-only), and other programmatic writes never earn a closing tag, and the insert arrives as its own undo step (one undo removes just the closing tag). A `getWorker` override that routes the `typescript` label to a worker without the subclass is detected on its first lookup and the install disarms silently. Multi-cursor typing and the diff editor's panes are deliberately out of scope. `<MonacoEditor>` installs it automatically.
14
14
  - **`dropMonacoWorkerFallbacks()`** (from **`@coldsmirk/inkstone-monaco/vite`**) — a Vite plugin that removes monaco's built-in worker fallbacks at build time. Monaco's language workerManagers statically reference their workers as `new Worker(new URL(...))` fallbacks that never run under `ensureMonacoHost` (the environment check prefers `getWorker`), yet bundlers emit a chunk per reference — including a ~7MB TypeScript worker duplicate that is never fetched. The plugin rewrites the fallbacks into located throws so the duplicates are never emitted; if a monaco bump reshapes the pattern it warns and leaves the file untouched (the dead chunk returns, nothing breaks).
15
- - **Embedded-editor fixes** — works around [microsoft/monaco-editor#5177](https://github.com/microsoft/monaco-editor/issues/5177) (find-widget button tooltips landing on top of the buttons they describe) with a `width: max-content` hover-layer style tagged `data-inkstone="monaco-hover-geometry"`; deleted the moment upstream fixes it. And 0.57 draws an editor's context menu under `fixedOverflowWidgets` (inkstone's default) in a shadow root hosted in the node the editor was created in, which no theme color reaches — a transparent menu, its items over the code ([microsoft/monaco-editor#5511](https://github.com/microsoft/monaco-editor/issues/5511)); the host makes that node a `.monaco-component`, the class Monaco writes its theme's colors on, so the menu inherits them, and `<MonacoEditor>` keeps the class in the `className` it renders. Those tooltips and that menu also stand in the node the editor was created in even where the host gave the editor an `overflowWidgetsDomNode` — so a modal or a scroll region around the editor cut them off at its edge; the host answers such an editor with its overflow widgets node instead, where its hover and completion list already stand.
15
+ - **Embedded-editor fixes** — works around [microsoft/monaco-editor#5177](https://github.com/microsoft/monaco-editor/issues/5177) (find-widget button tooltips landing on top of the buttons they describe) with a `width: max-content` hover-layer style tagged `data-inkstone="monaco-hover-geometry"`; deleted the moment upstream fixes it. And 0.57 draws an editor's context menu under `fixedOverflowWidgets` (inkstone's default) in a shadow root hosted in the node the editor was created in, which no theme color reaches — a transparent menu, its items over the code ([microsoft/monaco-editor#5511](https://github.com/microsoft/monaco-editor/issues/5511)); the host makes that node a `.monaco-component`, the class Monaco writes its theme's colors on, so the menu inherits them, and `<MonacoEditor>` keeps the class in the `className` it renders. Those tooltips and that menu also stand in the node the editor was created in even where the host gave the editor an `overflowWidgetsDomNode` — so a modal or a scroll region around the editor cut them off at its edge; the host answers such an editor with its overflow widgets node instead, where its hover and completion list already stand. And Monaco's keybindings are heard only inside an editor's container, so a widget that takes the keyboard from that node — the rename box — took no Enter or Escape; the host listens on each editor's overflow widgets node too and dispatches what is typed there as Monaco does inside the container, against the editor Monaco calls focused.
16
16
  - **`StreamingEditorController`** — stream generated text into an editor without routing every token through app state: `begin()` / `append(chunk)` / `end()` / `discard()`, `attach(editor)` / `detach(editor)` with buffered replay for late-mounting editors (and for a model swapped onto the attached editor mid-stream, including after the final chunk), and `isStreaming()` for the onChange guard. The stream locks every editor it touches read-only and `end()` / `discard()` restore each one's own setting — by handle, so an editor detached mid-stream is restored too; `discard()` puts every displaced document back into the model it came from, and `end()` does the same for every model except the one keeping the streamed text. Full-buffer writes and restorations preserve each model's UTF-8 BOM. Editors and models the app disposed mid-stream are skipped, never touched — teardown can race the stream without wedging it.
17
17
  - **`replaceInEditor(editor, old, new, all)`** — exact find-and-replace on an editor handle via `executeEdits`, preserving undo/cursor/folds; returns whether the edit landed (`false` = no editor / empty search / no match / a read-only editor refused it — e.g. one locked by a stream in progress), so a tool-call handler knows to fall back to a state write.
18
18
  - **`registerShikiHighlighting(monaco, highlighter)`** — wire `@coldsmirk/inkstone-core`'s shared Shiki highlighter onto a monaco module (one from `ensureMonacoHost`), once per distinct module: defines the highlighter's themes as Monaco themes, registers each loaded grammar's canonical name as a Monaco language where Monaco has none and its Shiki tokenization in Monaco's registry — over Monaco's own, JSON's included (its mode's tokenizer is turned off through its configuration, its other features left on) — and patches `setTheme` so the Shiki theme ids route through the highlighter while non-Shiki ids (vs/vs-dark, caller-defined) keep Monaco's original path. Called again on a bridged module, it registers the grammars loaded since. A failed registration is restored and retried on the next call.
19
- - **Tokenization off the page's thread** — VS Code's design, through the same door in Monaco: each model an editor shows is tokenized whole in a worker of its own, built from what the shared highlighter was built from (`highlighterSources`), the tokens and the state each line ends in sent back as they are made and moved past the edits the worker has not yet seen. The page's thread tokenizes only what Monaco still asks of it before the worker reaches it — a model's first lines in view, the lines an edit touches — and of those only a line it can afford: one of 1,000 characters or more, or one the grammar does not finish in 50 ms, is drawn in the default color until the worker's tokens arrive, the line after it read from the state before it (a minified line costs the grammar about 10 ms per 1,000 characters, 370 over 10,000, and one in view would hold the page that long). The worker bounds a line as VS Code does, at 20,000 characters and 500 ms. Where the page passes a line over in the lines it paints first, its own states for the lines after it stand — Monaco keeps a state it computed over one sent later — so an edit there is drawn from them until the worker's tokens arrive. A highlighter inkstone did not build, or a host that routes no worker for `textmate`, leaves every model to Monaco's own pass on the page's thread, under the same bound.
19
+ - A language it registers is edited as its language is — what pairs as it is typed, what a comment is, how Enter indents, what a word is — where `configuredLanguages` names it: a dialect of a language Monaco has (`tsx`, `jsx`, `shellscript`, `docker`, `terraform` …) by Monaco's own configuration of that language, any other (`vue`, `svelte`, `astro`, `jsonc`, `toml`, `zig` …) by the configuration its language's VS Code extension states. A grammar outside it has none, as VS Code reads a language whose extension states none; give it one with `monaco.languages.setLanguageConfiguration`.
20
+ - Each region of another grammar is read in that grammar's language, as VS Code's `embeddedLanguages` reads it: a `.vue` file's `<script lang="ts">` is TypeScript to everything Monaco reads off the token at the caret — its comment (`//`), its Enter rules, its brackets, its words — its template HTML and its `<style>` CSS. What pairs as it is typed is the file's own language's, as in VS Code.
21
+ - **Tokenization off the page's thread** — VS Code's design, through the same door in Monaco: each model an editor shows is tokenized whole in a worker of its own, built from what the shared highlighter was built from (`highlighterSources`), the tokens and the state each line ends in sent back as they are made and moved past the edits the worker has not yet seen. The page's thread tokenizes only what Monaco still asks of it before the worker reaches it — a model's first lines in view, the lines an edit touches — and of those only a line it can afford: one of 1,000 characters or more, or one the grammar does not finish in 50 ms, is drawn in the default color until the worker's tokens arrive, the line after it read from the state before it (a minified line costs the grammar about 10 ms per 1,000 characters, 370 over 10,000, and one in view would hold the page that long). The worker bounds a line as VS Code does, at 20,000 characters and 500 ms. Where the page passes a line over in the lines it paints first, its own states for the lines after it stand — Monaco keeps a state it computed over one sent later — so an edit there is drawn from them until the worker's tokens arrive. The line a typed line break begins on is tokenized on the page as the edit is made, so the caret's new line is one Monaco pairs a bracket or a quote on at once — Monaco pairs only on a line it can tokenize without going back — and never waits on the worker, however busy it is building its grammars. A highlighter inkstone did not build, or a host that routes no worker for `textmate`, leaves every model to Monaco's own pass on the page's thread, under the same bound.
20
22
  - **Which regex engine** — the worker builds the engine kind the shared highlighter was configured with: Oniguruma wherever an engine was configured, the strict JavaScript engine where none was, so the page and the worker tokenize alike. The JavaScript engine translates each grammar's patterns at the first tokenization — in the worker for a model, and on the page for the lines it tokenizes itself (a TypeScript file's first sixty lines: about 170 ms) — so an app that opens files in Monaco should configure `onigurumaEngine` from `@coldsmirk/inkstone-core` (`configureHighlighter({ engine: onigurumaEngine })`, before the first `getHighlighter()`): its WASM is inlined into your bundle and compiles the same lines in about 20 ms.
21
- - **`registerShikiLanguage(monaco, highlighter, language)`** — the lazy path: an app that loads grammars as files are opened calls this after each `highlighter.loadLanguage(...)` and before a model names the language. Registers the language where Monaco lacks it (`toml`, `shellscript`), its tokenization once under the grammar's canonical name (an alias like `ts` collapses), the models of a grammar shiki has built again since (a language it embeds lazily arrived) tokenized again under the new one, and leaves the theme the editor shows alone — the one thing re-running `@shikijs/monaco`'s `shikiToMonaco` cannot promise, which is why the bridge is inkstone's own. Throws for a grammar the highlighter has not loaded.
23
+ - **`registerShikiLanguage(monaco, highlighter, language)`** — the lazy path: an app that loads grammars as files are opened calls this after each `highlighter.loadLanguage(...)` and before a model names the language. Registers the language where Monaco lacks it (`toml`, `shellscript`), its tokenization once under the grammar's canonical name (an alias like `ts` collapses), and so every grammar loaded with it — the grammars it embeds, whose regions are read in their own languages — the models of a grammar shiki has built again since (a language it embeds lazily arrived) tokenized again under the new one, and leaves the theme the editor shows alone — the one thing re-running `@shikijs/monaco`'s `shikiToMonaco` cannot promise, which is why the bridge is inkstone's own. Throws for a grammar the highlighter has not loaded.
22
24
  - **`installDesignTokens()`** — defines the VS Code design tokens monaco-editor's chrome has read since 0.56 and the standalone editor still never does ([microsoft/monaco-editor#5408](https://github.com/microsoft/monaco-editor/issues/5408)): `--vscode-cornerRadius-{small,medium,large,xLarge,circle}` and `--vscode-shadow-{md,lg,xl}`, on `.monaco-editor` (a host's `overflowWidgetsDomNode` carries the class) and on `.monaco-component` — every context view, the class Monaco writes its own theme colors on: an element's tooltip and, since 0.57 under `fixedOverflowWidgets`, the editor's context menu stand in the node the editor was created in, outside `.monaco-editor`. Without them the context menu, completion, hover, and find widgets ship square and shadowless. 0.57 also took the completion list off `--vscode-shadow-lg` for a literal `0 2px 8px` shadow; it is put back on the token, so it wears the host's shadow as the hover and the context menu do. Each resolves through the host's `--inkstone-radius-*` / `--inkstone-shadow-*` token first (see `@coldsmirk/inkstone-core`), then a fallback scale in the spirit of 0.55's look. It also keeps an input box's focus ring single: the standalone editor outlines both the `.monaco-inputbox` container (its `synthetic-focus` ring, which follows the box's radius) and the inner `<input>` (square, 1px inside), and the inner ring's corners poke out as soon as the box has corners — the container's ring is the one ring. `ensureMonacoHost` installs it; idempotent.
23
25
  - **`DEFAULT_MONACO_OPTIONS`** — the inkstone construction-option baseline (no minimap, 14px/1.6 type on the shared `--inkstone-font-family-code` token, embedded-friendly find widget, tuned completion, thin scrollbars). Spread it to extend: `{ ...DEFAULT_MONACO_OPTIONS, wordWrap: "on" }`. Left out on purpose: `fullwidthCharacterWidth: "twoCells"`, which centers each full-width character — CJK text among it — in exactly two cells of a monospace font, so it lines up with the grid the way a terminal draws it. It draws every such character as a span of its own, which costs on text dense with them (a Chinese JSON body, a document of prose), so it is a host's to turn on where the alignment matters more.
24
26
  - **`reconcileModelValue` / `modelValueMatches`** — the controlled-value reconcile: diff an external value against a live model (normalized to the model's EOL) and apply one minimal `applyEdits` replace that never lands on the undo stack or moves a caret outside the changed region. One leading `U+FEFF` is treated as a BOM, as when Monaco loads a document; it is never inserted into the text. Any further `U+FEFF` remains document content. Reconciliation leaves the model's stored BOM unchanged.
@@ -69,6 +69,49 @@ function applyStateDiff(previous, diff) {
69
69
  for (const frame of diff.newFrames) stack = Stack.pushFrame(stack, frame);
70
70
  return stack;
71
71
  }
72
+ const embedding = /* @__PURE__ */ new WeakMap();
73
+ function scopeLanguages(languages) {
74
+ const scopes = Object.keys(languages).toSorted((left, right) => right.length - left.length);
75
+ return (scope) => {
76
+ const found = scopes.find((name) => scope === name || scope.startsWith(name) && scope[name.length] === ".");
77
+ return found === void 0 ? void 0 : languages[found];
78
+ };
79
+ }
80
+ function embedLanguages(grammar, languages) {
81
+ const current = embedding.get(grammar);
82
+ if (current?.languages === languages || !current && Object.keys(languages).length === 0) return grammar;
83
+ const attributed = grammar;
84
+ const own = current?.own ?? attributed.getMetadataForScope.bind(attributed);
85
+ const languageOf = scopeLanguages(languages);
86
+ const answered = /* @__PURE__ */ new Map();
87
+ attributed.getMetadataForScope = (scope) => {
88
+ let attributes = answered.get(scope);
89
+ if (attributes === void 0) {
90
+ const attributesOwn = own(scope);
91
+ const languageId = languageOf(scope);
92
+ attributes = languageId === void 0 ? attributesOwn : {
93
+ languageId,
94
+ tokenType: attributesOwn.tokenType
95
+ };
96
+ answered.set(scope, attributes);
97
+ }
98
+ return attributes;
99
+ };
100
+ embedding.set(grammar, {
101
+ languages,
102
+ own
103
+ });
104
+ return grammar;
105
+ }
106
+ function embeddedLanguagesOf(languages, idOf) {
107
+ const embedded = {};
108
+ for (const language of languages) {
109
+ if ((language.injectTo?.length ?? 0) > 0) continue;
110
+ const id = idOf(language.name);
111
+ if (id !== void 0 && id > 1) embedded[language.scopeName] = id;
112
+ }
113
+ return embedded;
114
+ }
72
115
  //#endregion
73
116
  //#region src/tokenization/metadata.ts
74
117
  const LANGUAGE_MASK = 255;
@@ -97,7 +140,8 @@ function colorIdsFor(highlighterColors, monacoColors) {
97
140
  }
98
141
  function monacoMetadata(metadata, languageId, colorIds) {
99
142
  const foreground = colorIds[(metadata & FOREGROUND_MASK) >>> FOREGROUND_OFFSET] ?? DEFAULT_FOREGROUND;
100
- return (languageId & LANGUAGE_MASK | metadata & KEPT_MASK | foreground << FOREGROUND_OFFSET | DEFAULT_BACKGROUND << BACKGROUND_OFFSET) >>> 0;
143
+ const region = metadata & LANGUAGE_MASK;
144
+ return ((region > 1 ? region : languageId & LANGUAGE_MASK) | metadata & KEPT_MASK | foreground << FOREGROUND_OFFSET | DEFAULT_BACKGROUND << BACKGROUND_OFFSET) >>> 0;
101
145
  }
102
146
  function defaultMetadata(languageId) {
103
147
  return (languageId & LANGUAGE_MASK | 33587200) >>> 0;
@@ -117,4 +161,4 @@ function withEndOffsets(tokens, lineLength) {
117
161
  const SYNC_LINE_BOUND = 1e3;
118
162
  const WORKER_LINE_BOUND = 2e4;
119
163
  //#endregion
120
- export { toMonacoTokens as a, stateDiff as c, lineAfter as d, lineSplice as f, defaultMetadata as i, applyChange as l, WORKER_LINE_BOUND as n, withEndOffsets as o, colorIdsFor as r, applyStateDiff as s, SYNC_LINE_BOUND as t, applySplice as u };
164
+ export { toMonacoTokens as a, embeddedLanguagesOf as c, applyChange as d, applySplice as f, defaultMetadata as i, applyStateDiff as l, lineSplice as m, WORKER_LINE_BOUND as n, withEndOffsets as o, lineAfter as p, colorIdsFor as r, embedLanguages as s, SYNC_LINE_BOUND as t, stateDiff as u };
package/dist/index.d.ts CHANGED
@@ -188,6 +188,15 @@ interface KeybindingTargetEditor {
188
188
  */
189
189
  export declare function installDisabledKeybindings(monaco: MonacoModule, editorInstance: KeybindingTargetEditor, groups: readonly SwallowedKeybindings[]): void;
190
190
  //#endregion
191
+ //#region src/language-configurations.d.ts
192
+ /**
193
+ * The grammars inkstone gives the editing configuration of their language — what pairs as it is
194
+ * typed, what a comment is, how Enter indents, what a word is — where Monaco has no language of
195
+ * theirs, by canonical name. A grammar outside it is a language as VS Code reads one whose
196
+ * extension states none: its host gives it one through `monaco.languages.setLanguageConfiguration`.
197
+ */
198
+ export declare const configuredLanguages: readonly string[];
199
+ //#endregion
191
200
  //#region src/languages.d.ts
192
201
  /**
193
202
  * Monaco's built-in language ids: every id the editor registers out of the box, sourced from the
@@ -280,11 +289,13 @@ export declare function registerShikiHighlighting(monaco: MonacoModule, highligh
280
289
  /**
281
290
  * Register the tokenization of one grammar the highlighter has loaded since the module was
282
291
  * bridged — the lazy path: an app that loads grammars as files are opened registers each here,
283
- * after its `loadLanguage`, and before a model names it. `language` may be an alias (`ts`); it
284
- * collapses to the grammar's canonical name. Bridges the module first where nothing has, and
285
- * is nothing for a grammar already registered — but a grammar shiki has built again since, as
286
- * a language it embeds lazily arrived, has its models tokenized again under the new one. Throws
287
- * when the highlighter has not loaded the grammar: there is nothing to tokenize with.
292
+ * after its `loadLanguage`, and before a model names it — and of every grammar loaded with it:
293
+ * the grammars it embeds, whose regions of its lines are read in their own languages. `language`
294
+ * may be an alias (`ts`); it collapses to the grammar's canonical name. Bridges the module first
295
+ * where nothing has, and is nothing for a grammar already registered — but a grammar shiki has
296
+ * built again since, as a language it embeds lazily arrived, has its models tokenized again
297
+ * under the new one. Throws when the highlighter has not loaded the grammar: there is nothing to
298
+ * tokenize with.
288
299
  */
289
300
  export declare function registerShikiLanguage(monaco: MonacoModule, highlighter: HighlighterCore, language: string): void;
290
301
  //#endregion
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as toMonacoTokens, d as lineAfter, i as defaultMetadata, r as colorIdsFor, s as applyStateDiff } from "./bounds-CZ_iAUoc.js";
1
+ import { a as toMonacoTokens, c as embeddedLanguagesOf, i as defaultMetadata, l as applyStateDiff, m as lineSplice, p as lineAfter, r as colorIdsFor, s as embedLanguages } from "./bounds-CPkzvXiT.js";
2
2
  import { CODE_FONT_FAMILY, INKSTONE_DARK_THEME, INKSTONE_LIGHT_THEME, highlighterSources, inkstoneRadius, inkstoneShadow, subscribeEditorColors } from "@coldsmirk/inkstone-core";
3
3
  import { EncodedTokenMetadata, INITIAL } from "@shikijs/vscode-textmate";
4
4
  //#region src/auto-imports.ts
@@ -296,9 +296,63 @@ function installHoverFocusFix() {
296
296
  document.head.append(style);
297
297
  }
298
298
  //#endregion
299
+ //#region src/overflow-keys-fix.ts
300
+ async function loadOverflowKeysInternals() {
301
+ const [services, keybinding, editors, keyboard] = await Promise.all([
302
+ import("monaco-editor/editor/standalone/browser/standaloneServices.js"),
303
+ import("monaco-editor/platform/keybinding/common/keybinding.js"),
304
+ import("monaco-editor/editor/browser/services/codeEditorService.js"),
305
+ import("monaco-editor/base/browser/keyboardEvent.js")
306
+ ]);
307
+ return {
308
+ get: (service) => services.StandaloneServices.get(service),
309
+ keybindingService: keybinding.IKeybindingService,
310
+ codeEditorService: editors.ICodeEditorService,
311
+ keyEvent: (event) => new keyboard.StandardKeyboardEvent(event)
312
+ };
313
+ }
314
+ const heard = /* @__PURE__ */ new WeakSet();
315
+ function hearKeysInOverflowWidgets(editor, internals) {
316
+ const node = editor.getOverflowWidgetsDomNode();
317
+ if (node === void 0 || heard.has(node)) return;
318
+ heard.add(node);
319
+ const ownerOf = () => {
320
+ const focused = internals.get(internals.codeEditorService).getFocusedCodeEditor();
321
+ if (focused === null || focused.getOverflowWidgetsDomNode() !== node) return;
322
+ const container = focused.getContainerDomNode();
323
+ return container.contains(node) ? void 0 : container;
324
+ };
325
+ const dispatches = () => internals.get(internals.keybindingService);
326
+ node.addEventListener("keydown", (browserEvent) => {
327
+ const owner = ownerOf();
328
+ if (owner === void 0) return;
329
+ const event = internals.keyEvent(browserEvent);
330
+ if (dispatches()._dispatch(event, owner)) {
331
+ event.preventDefault();
332
+ event.stopPropagation();
333
+ }
334
+ });
335
+ node.addEventListener("keyup", (browserEvent) => {
336
+ const owner = ownerOf();
337
+ if (owner === void 0) return;
338
+ const event = internals.keyEvent(browserEvent);
339
+ if (dispatches()._singleModifierDispatch(event, owner)) event.preventDefault();
340
+ });
341
+ }
342
+ function installOverflowKeysFix(monaco, internals) {
343
+ monaco.editor.onDidCreateEditor((editor) => {
344
+ hearKeysInOverflowWidgets(editor, internals);
345
+ });
346
+ }
347
+ //#endregion
299
348
  //#region src/tokenization/internals.ts
300
349
  async function loadMonacoInternals() {
301
- const [languages, tokens] = await Promise.all([import("monaco-editor/editor/common/languages.js"), import("monaco-editor/editor/common/tokens/contiguousMultilineTokensBuilder.js")]);
350
+ const [languages, tokens, services, language] = await Promise.all([
351
+ import("monaco-editor/editor/common/languages.js"),
352
+ import("monaco-editor/editor/common/tokens/contiguousMultilineTokensBuilder.js"),
353
+ import("monaco-editor/editor/standalone/browser/standaloneServices.js"),
354
+ import("monaco-editor/editor/common/languages/language.js")
355
+ ]);
302
356
  return {
303
357
  registry: languages.TokenizationRegistry,
304
358
  encoded: (encoded, endState) => new languages.EncodedTokenizationResult(encoded, [], endState),
@@ -307,6 +361,12 @@ async function loadMonacoInternals() {
307
361
  const builder = new tokens.ContiguousMultilineTokensBuilder();
308
362
  for (const [lineNumber, lineTokens] of lines) builder.add(lineNumber, lineTokens);
309
363
  return builder.finalize();
364
+ },
365
+ encounter: (languageId) => {
366
+ services.StandaloneServices.get(language.ILanguageService).requestBasicLanguageFeatures(languageId);
367
+ },
368
+ tokenizeIfCheap: (model, lineNumber) => {
369
+ model.tokenization.tokenizeIfCheap(lineNumber);
310
370
  }
311
371
  };
312
372
  }
@@ -401,6 +461,7 @@ function ensureMonacoHost(options = {}) {
401
461
  globalThis.MonacoEnvironment = { getWorker: (workerId, label) => getWorker?.(workerId, label) ?? builtinGetWorker(label) };
402
462
  installContextMenuThemeFix(monaco);
403
463
  installContextViewFix(monaco, await loadContextViewInternals());
464
+ installOverflowKeysFix(monaco, await loadOverflowKeysInternals());
404
465
  installFontMetricsRefresh(monaco);
405
466
  if (locale === "zh-cn") monaco.editor.onDidCreateEditor(localizeActionDescriptions);
406
467
  return monaco;
@@ -527,6 +588,532 @@ function installDisabledKeybindings(monaco, editorInstance, groups) {
527
588
  for (const keybinding of keybindings) if (!landed.has(keybinding) && editorInstance.addCommand(keybinding, () => void 0, contextKey) !== null) landed.add(keybinding);
528
589
  }
529
590
  }
591
+ //#endregion
592
+ //#region src/language-configurations.ts
593
+ const COFFEE = () => import("monaco-editor/languages/definitions/coffee/coffee.js");
594
+ const CSS = () => import("monaco-editor/languages/definitions/css/css.js");
595
+ const DOCKERFILE = () => import("monaco-editor/languages/definitions/dockerfile/dockerfile.js");
596
+ const HCL = () => import("monaco-editor/languages/definitions/hcl/hcl.js");
597
+ const HTML = () => import("monaco-editor/languages/definitions/html/html.js");
598
+ const JAVASCRIPT = () => import("monaco-editor/languages/definitions/javascript/javascript.js");
599
+ const MIPS = () => import("monaco-editor/languages/definitions/mips/mips.js");
600
+ const OBJECTIVE_C = () => import("monaco-editor/languages/definitions/objective-c/objective-c.js");
601
+ const RESTRUCTUREDTEXT = () => import("monaco-editor/languages/definitions/restructuredtext/restructuredtext.js");
602
+ const SHELL = () => import("monaco-editor/languages/definitions/shell/shell.js");
603
+ const SOLIDITY = () => import("monaco-editor/languages/definitions/solidity/solidity.js");
604
+ const SQL = () => import("monaco-editor/languages/definitions/sql/sql.js");
605
+ const SYSTEMVERILOG = () => import("monaco-editor/languages/definitions/systemverilog/systemverilog.js");
606
+ const TYPESCRIPT = () => import("monaco-editor/languages/definitions/typescript/typescript.js");
607
+ const XML = () => import("monaco-editor/languages/definitions/xml/xml.js");
608
+ const AS_MONACO_LANGUAGE = {
609
+ "angular-html": HTML,
610
+ "angular-ts": TYPESCRIPT,
611
+ coffee: COFFEE,
612
+ docker: DOCKERFILE,
613
+ "html-derivative": HTML,
614
+ jsx: JAVASCRIPT,
615
+ mipsasm: MIPS,
616
+ "objective-cpp": OBJECTIVE_C,
617
+ plsql: SQL,
618
+ postcss: CSS,
619
+ rst: RESTRUCTUREDTEXT,
620
+ shellscript: SHELL,
621
+ solidity: SOLIDITY,
622
+ "system-verilog": SYSTEMVERILOG,
623
+ terraform: HCL,
624
+ "ts-tags": TYPESCRIPT,
625
+ tsx: TYPESCRIPT,
626
+ "vue-html": HTML,
627
+ xsl: XML
628
+ };
629
+ const BRACKETS = [
630
+ ["{", "}"],
631
+ ["[", "]"],
632
+ ["(", ")"]
633
+ ];
634
+ const BRACKET_PAIRS = BRACKETS.map(([open, close]) => {
635
+ return {
636
+ open,
637
+ close
638
+ };
639
+ });
640
+ const QUOTE_PAIRS = [{
641
+ open: "\"",
642
+ close: "\""
643
+ }, {
644
+ open: "'",
645
+ close: "'"
646
+ }];
647
+ function jsonWithComments() {
648
+ return {
649
+ comments: {
650
+ lineComment: "//",
651
+ blockComment: ["/*", "*/"]
652
+ },
653
+ brackets: [["{", "}"], ["[", "]"]],
654
+ autoClosingPairs: [
655
+ {
656
+ open: "{",
657
+ close: "}",
658
+ notIn: ["string"]
659
+ },
660
+ {
661
+ open: "[",
662
+ close: "]",
663
+ notIn: ["string"]
664
+ },
665
+ {
666
+ open: "(",
667
+ close: ")",
668
+ notIn: ["string"]
669
+ },
670
+ {
671
+ open: "'",
672
+ close: "'",
673
+ notIn: ["string"]
674
+ },
675
+ {
676
+ open: "\"",
677
+ close: "\"",
678
+ notIn: ["string", "comment"]
679
+ },
680
+ {
681
+ open: "`",
682
+ close: "`",
683
+ notIn: ["string", "comment"]
684
+ }
685
+ ],
686
+ indentationRules: {
687
+ increaseIndentPattern: /[[{]$/,
688
+ decreaseIndentPattern: /^\s*[}\]],?\s*$/
689
+ },
690
+ folding: { markers: {
691
+ start: /^\s*\/\/\s*#?region\b/,
692
+ end: /^\s*\/\/\s*#?endregion\b/
693
+ } }
694
+ };
695
+ }
696
+ const OWN = {
697
+ vue: (indent) => {
698
+ return {
699
+ comments: { blockComment: ["<!--", "-->"] },
700
+ brackets: [
701
+ ["<!--", "-->"],
702
+ ["{", "}"],
703
+ ["(", ")"]
704
+ ],
705
+ autoClosingPairs: [
706
+ ...BRACKET_PAIRS,
707
+ ...QUOTE_PAIRS,
708
+ {
709
+ open: "<!--",
710
+ close: "-->",
711
+ notIn: ["comment", "string"]
712
+ },
713
+ {
714
+ open: "`",
715
+ close: "`",
716
+ notIn: ["string", "comment"]
717
+ },
718
+ {
719
+ open: "/**",
720
+ close: " */",
721
+ notIn: ["string"]
722
+ }
723
+ ],
724
+ autoCloseBefore: ";:.,=}])><`'\" \n ",
725
+ surroundingPairs: [
726
+ ...QUOTE_PAIRS,
727
+ ...BRACKET_PAIRS,
728
+ {
729
+ open: "<",
730
+ close: ">"
731
+ },
732
+ {
733
+ open: "`",
734
+ close: "`"
735
+ }
736
+ ],
737
+ colorizedBracketPairs: [],
738
+ folding: { markers: {
739
+ start: /^\s*<!--\s*#region\b.*-->/,
740
+ end: /^\s*<!--\s*#endregion\b.*-->/
741
+ } },
742
+ wordPattern: /-?\d*\.\d\w*|[^`~!@$^&*()=+[{\]}\\|;:'",.<>/\s]+/,
743
+ onEnterRules: [{
744
+ beforeText: /<(?!area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style)[:\w](?:[^'"/>]|"[^"]*"|'[^']*')*>[^<]*$/i,
745
+ afterText: /^<\/[:\w][\w:.-]*\s*>/,
746
+ action: { indentAction: indent.IndentOutdent }
747
+ }, {
748
+ beforeText: /<(?!area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style)[:\w](?:[^'"/>]|"[^"]*"|'[^']*')*>[^<]*$/i,
749
+ action: { indentAction: indent.Indent }
750
+ }],
751
+ indentationRules: {
752
+ increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr|script|style)\b|[^>]*\/>)(?<tag>[-\w.]+)(?=\s|>)\b[^>]*>(?!.*<\/\k<tag>>)|<!--(?!.*-->)|\{[^}"']*$/,
753
+ decreaseIndentPattern: /^\s*(?:<\/(?!html)[-\w.]+\b[^>]*>|-->|\})/
754
+ }
755
+ };
756
+ },
757
+ svelte: () => {
758
+ return {
759
+ comments: { blockComment: ["<!--", "-->"] },
760
+ brackets: [
761
+ ["<!--", "-->"],
762
+ ["<", ">"],
763
+ ...BRACKETS
764
+ ],
765
+ autoClosingPairs: [
766
+ ...BRACKET_PAIRS,
767
+ ...QUOTE_PAIRS,
768
+ {
769
+ open: "`",
770
+ close: "`",
771
+ notIn: ["comment", "string"]
772
+ },
773
+ {
774
+ open: "<!--",
775
+ close: "-->",
776
+ notIn: ["comment", "string"]
777
+ },
778
+ {
779
+ open: "/**",
780
+ close: "*/",
781
+ notIn: ["string"]
782
+ }
783
+ ],
784
+ autoCloseBefore: ";:.,=}])><`/ \n ",
785
+ surroundingPairs: [
786
+ ...QUOTE_PAIRS,
787
+ {
788
+ open: "`",
789
+ close: "`"
790
+ },
791
+ ...BRACKET_PAIRS,
792
+ {
793
+ open: "<",
794
+ close: ">"
795
+ }
796
+ ],
797
+ folding: { markers: {
798
+ start: /^\s*(?:\/\/|\/\*\*?)\s*#?region\b|^<(?:template|style|script)[^>]*>|^\s*<!--\s*#region\b/,
799
+ end: /^\s*(?:\/\/|\/\*\*?)\s*#?endregion\b|^<\/(?:template|style|script)>|^\s*<!--\s*#endregion\b/
800
+ } }
801
+ };
802
+ },
803
+ astro: (indent) => {
804
+ return {
805
+ comments: { blockComment: ["<!--", "-->"] },
806
+ brackets: [
807
+ ["<!--", "-->"],
808
+ ["<", ">"],
809
+ ["{", "}"]
810
+ ],
811
+ autoClosingPairs: [
812
+ ...BRACKET_PAIRS,
813
+ ...QUOTE_PAIRS,
814
+ {
815
+ open: "`",
816
+ close: "`"
817
+ },
818
+ {
819
+ open: "{/*",
820
+ close: " */}",
821
+ notIn: ["comment", "string"]
822
+ },
823
+ {
824
+ open: "<!--",
825
+ close: " -->",
826
+ notIn: ["comment", "string"]
827
+ },
828
+ {
829
+ open: "/**",
830
+ close: " */",
831
+ notIn: ["string"]
832
+ }
833
+ ],
834
+ autoCloseBefore: ";:.,=}])><` \n ",
835
+ surroundingPairs: [
836
+ ...QUOTE_PAIRS,
837
+ {
838
+ open: "`",
839
+ close: "`"
840
+ },
841
+ ...BRACKET_PAIRS,
842
+ {
843
+ open: "<",
844
+ close: ">"
845
+ }
846
+ ],
847
+ folding: { markers: {
848
+ start: /^\s*<!--\s*#region\b.*-->/,
849
+ end: /^\s*<!--\s*#endregion\b.*-->/
850
+ } },
851
+ wordPattern: /[^\-\s]+-[^\-\s]+|-?\d*\.\d\w*|[^`~\-!@$^&*()=+[{\]}\\|;:'",.<>/\s]+/,
852
+ onEnterRules: [{
853
+ beforeText: /<(?!area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[:\w][^/>]*>[^<]*$/i,
854
+ afterText: /^<\/[:\w][\w:.-]*\s*>$/,
855
+ action: { indentAction: indent.IndentOutdent }
856
+ }, {
857
+ beforeText: /<(?!area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[:\w][^/>]*>[^<]*$/i,
858
+ action: { indentAction: indent.Indent }
859
+ }],
860
+ indentationRules: {
861
+ increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|keygen|link|menuitem|meta|param|source|track|wbr)\b|[^>]*\/>)(?<tag>[-\w.]+)(?=\s|>)\b[^>]*>(?!.*<\/\k<tag>>)|<!--(?!.*-->)|\{[^}"']*$/,
862
+ decreaseIndentPattern: /^\s*(?:<\/(?!html)[-\w.]+\b[^>]*>|-->|\})/
863
+ }
864
+ };
865
+ },
866
+ jsonc: jsonWithComments,
867
+ json5: jsonWithComments,
868
+ toml: () => {
869
+ return {
870
+ comments: { lineComment: "#" },
871
+ autoCloseBefore: ";:.,=}])> \n ",
872
+ brackets: [["[", "]"]],
873
+ autoClosingPairs: [
874
+ {
875
+ open: "\"",
876
+ close: "\"",
877
+ notIn: ["string"]
878
+ },
879
+ {
880
+ open: "'",
881
+ close: "'",
882
+ notIn: ["string", "comment"]
883
+ },
884
+ {
885
+ open: "[",
886
+ close: "]"
887
+ },
888
+ {
889
+ open: "{",
890
+ close: "}"
891
+ }
892
+ ],
893
+ surroundingPairs: [...QUOTE_PAIRS, ...BRACKET_PAIRS]
894
+ };
895
+ },
896
+ zig: (indent) => {
897
+ return {
898
+ comments: { lineComment: "//" },
899
+ brackets: BRACKETS,
900
+ autoClosingPairs: [...BRACKET_PAIRS, ...QUOTE_PAIRS],
901
+ surroundingPairs: [...BRACKET_PAIRS, ...QUOTE_PAIRS],
902
+ folding: { markers: {
903
+ start: /\/\/ zig fmt: off\b/,
904
+ end: /\/\/ zig fmt: on\b/
905
+ } },
906
+ onEnterRules: [
907
+ {
908
+ beforeText: /^\s*\/\/!.*$/,
909
+ action: {
910
+ indentAction: indent.None,
911
+ appendText: "//! "
912
+ }
913
+ },
914
+ {
915
+ beforeText: /^\s*\/\/\/.*$/,
916
+ action: {
917
+ indentAction: indent.None,
918
+ appendText: "/// "
919
+ }
920
+ },
921
+ {
922
+ beforeText: /^\s*\\\\.*$/,
923
+ action: {
924
+ indentAction: indent.None,
925
+ appendText: "\\\\"
926
+ }
927
+ }
928
+ ]
929
+ };
930
+ },
931
+ haskell: () => {
932
+ return {
933
+ comments: {
934
+ lineComment: "--",
935
+ blockComment: ["{-", "-}"]
936
+ },
937
+ brackets: BRACKETS,
938
+ autoClosingPairs: [
939
+ ...BRACKET_PAIRS,
940
+ {
941
+ open: "\"",
942
+ close: "\"",
943
+ notIn: ["string"]
944
+ },
945
+ {
946
+ open: "`",
947
+ close: "`",
948
+ notIn: ["string", "comment"]
949
+ }
950
+ ],
951
+ surroundingPairs: [
952
+ ...BRACKET_PAIRS,
953
+ ...QUOTE_PAIRS,
954
+ {
955
+ open: "`",
956
+ close: "`"
957
+ }
958
+ ],
959
+ folding: { offSide: true }
960
+ };
961
+ },
962
+ make: () => {
963
+ return {
964
+ comments: { lineComment: {
965
+ comment: "#",
966
+ noIndent: true
967
+ } },
968
+ brackets: BRACKETS,
969
+ autoClosingPairs: [
970
+ ...BRACKET_PAIRS,
971
+ {
972
+ open: "'",
973
+ close: "'",
974
+ notIn: ["string", "comment"]
975
+ },
976
+ {
977
+ open: "\"",
978
+ close: "\"",
979
+ notIn: ["string", "comment"]
980
+ }
981
+ ]
982
+ };
983
+ },
984
+ nginx: () => {
985
+ return {
986
+ comments: { lineComment: "#" },
987
+ brackets: BRACKETS,
988
+ autoClosingPairs: [...BRACKET_PAIRS, ...QUOTE_PAIRS],
989
+ surroundingPairs: [...BRACKET_PAIRS, ...QUOTE_PAIRS]
990
+ };
991
+ },
992
+ http: () => {
993
+ return {
994
+ comments: { lineComment: "#" },
995
+ brackets: [
996
+ ["{", "}"],
997
+ ["[", "]"],
998
+ ["<", ">"]
999
+ ],
1000
+ autoClosingPairs: [
1001
+ {
1002
+ open: "{",
1003
+ close: "}"
1004
+ },
1005
+ {
1006
+ open: "[",
1007
+ close: "]"
1008
+ },
1009
+ {
1010
+ open: "<",
1011
+ close: ">"
1012
+ },
1013
+ {
1014
+ open: "\"",
1015
+ close: "\""
1016
+ }
1017
+ ],
1018
+ folding: { markers: {
1019
+ start: /^(?:GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|CONNECT|TRACE|LOCK|UNLOCK|PROPFIND|PROPPATCH|COPY|MOVE|MKCOL|MKCALENDAR|ACL|SEARCH|curl)\s+/,
1020
+ end: /^#{3,}$/
1021
+ } }
1022
+ };
1023
+ },
1024
+ mermaid: () => {
1025
+ return { comments: { lineComment: "%%" } };
1026
+ },
1027
+ diff: () => {
1028
+ return {
1029
+ comments: {
1030
+ lineComment: "#",
1031
+ blockComment: ["#", " "]
1032
+ },
1033
+ brackets: BRACKETS
1034
+ };
1035
+ },
1036
+ latex: () => {
1037
+ return {
1038
+ comments: { lineComment: "%" },
1039
+ brackets: [
1040
+ ...BRACKETS,
1041
+ [String.raw`\{`, String.raw`\}`],
1042
+ [String.raw`\left(`, String.raw`\right)`],
1043
+ [String.raw`\left[`, String.raw`\right]`],
1044
+ [String.raw`\left\{`, String.raw`\right\}`],
1045
+ [String.raw`\langle`, String.raw`\rangle`]
1046
+ ],
1047
+ autoClosingPairs: [
1048
+ ...[
1049
+ [String.raw`\left(`, String.raw`\right)`],
1050
+ [String.raw`\left[`, String.raw`\right]`],
1051
+ [String.raw`\left\{`, String.raw`\right\}`],
1052
+ [String.raw`\bigl(`, String.raw`\bigr)`],
1053
+ [String.raw`\bigl[`, String.raw`\bigr]`],
1054
+ [String.raw`\bigl\{`, String.raw`\bigr\}`],
1055
+ [String.raw`\Bigl(`, String.raw`\Bigr)`],
1056
+ [String.raw`\Bigl[`, String.raw`\Bigr]`],
1057
+ [String.raw`\Bigl\{`, String.raw`\Bigr\}`],
1058
+ [String.raw`\biggl(`, String.raw`\biggr)`],
1059
+ [String.raw`\biggl[`, String.raw`\biggr]`],
1060
+ [String.raw`\biggl\{`, String.raw`\biggr\}`],
1061
+ [String.raw`\Biggl(`, String.raw`\Biggr)`],
1062
+ [String.raw`\Biggl[`, String.raw`\Biggr]`],
1063
+ [String.raw`\Biggl\{`, String.raw`\Biggr\}`],
1064
+ [String.raw`\(`, String.raw`\)`],
1065
+ [String.raw`\[`, String.raw`\]`],
1066
+ [String.raw`\{`, String.raw`\}`]
1067
+ ].map(([open = "", close = ""]) => {
1068
+ return {
1069
+ open,
1070
+ close
1071
+ };
1072
+ }),
1073
+ ...BRACKET_PAIRS,
1074
+ {
1075
+ open: "`",
1076
+ close: "'"
1077
+ }
1078
+ ],
1079
+ surroundingPairs: [
1080
+ ...BRACKET_PAIRS,
1081
+ ...QUOTE_PAIRS,
1082
+ {
1083
+ open: "`",
1084
+ close: "'"
1085
+ },
1086
+ {
1087
+ open: "$",
1088
+ close: "$"
1089
+ }
1090
+ ],
1091
+ indentationRules: {
1092
+ increaseIndentPattern: /\\begin\{(?!document)(?<environment>[^}]*)\}(?!.*\\end\{\k<environment>\})/,
1093
+ decreaseIndentPattern: /^\s*\\end\{(?!document)/
1094
+ },
1095
+ folding: { markers: {
1096
+ start: /^\s*(?:%\s*region|(?:%\s*)?\\begingroup)\b/,
1097
+ end: /^\s*(?:%\s*endregion|(?:%\s*)?\\endgroup)\b/
1098
+ } },
1099
+ autoCloseBefore: ";:.,={}])>\\` \n $",
1100
+ wordPattern: /[\p{Alphabetic}\p{Number}\p{Nonspacing_Mark}]+/u
1101
+ };
1102
+ }
1103
+ };
1104
+ const configuredLanguages = [...Object.keys(AS_MONACO_LANGUAGE), ...Object.keys(OWN)].toSorted();
1105
+ function configureLanguage(monaco, language) {
1106
+ const own = OWN[language];
1107
+ if (own) {
1108
+ monaco.languages.setLanguageConfiguration(language, own(monaco.languages.IndentAction));
1109
+ return;
1110
+ }
1111
+ AS_MONACO_LANGUAGE[language]?.().then(({ conf }) => {
1112
+ monaco.languages.setLanguageConfiguration(language, conf);
1113
+ }, (error) => {
1114
+ console.warn(`inkstone: Monaco's editing configuration for ${language} did not load`, error);
1115
+ });
1116
+ }
530
1117
  const monacoLanguages = [
531
1118
  "abap",
532
1119
  "aes",
@@ -769,6 +1356,7 @@ var WorkerTokenizerController = class {
769
1356
  version: event.versionId,
770
1357
  changes
771
1358
  });
1359
+ this.keepCaretLineCheap(id, changes);
772
1360
  });
773
1361
  this.session = {
774
1362
  id,
@@ -776,6 +1364,15 @@ var WorkerTokenizerController = class {
776
1364
  listener
777
1365
  };
778
1366
  }
1367
+ keepCaretLineCheap(session, changes) {
1368
+ let first;
1369
+ for (const change of changes) if (lineSplice(change).inserted > 1) first = Math.min(first ?? change.range.startLineNumber, change.range.startLineNumber);
1370
+ if (first === void 0) return;
1371
+ const line = first;
1372
+ queueMicrotask(() => {
1373
+ if (this.session?.id === session) this.internals.tokenizeIfCheap(this.model, line);
1374
+ });
1375
+ }
779
1376
  disconnect() {
780
1377
  if (!this.session) return;
781
1378
  this.session.listener.dispose();
@@ -840,6 +1437,7 @@ var TokenizationClient = class {
840
1437
  controllers = /* @__PURE__ */ new Map();
841
1438
  worker;
842
1439
  sentLanguages = 0;
1440
+ sentEmbedded;
843
1441
  nextModel = 1;
844
1442
  dead = false;
845
1443
  constructor(options) {
@@ -868,11 +1466,13 @@ var TokenizationClient = class {
868
1466
  });
869
1467
  const { sources } = this.options;
870
1468
  this.sentLanguages = sources.languages.length;
1469
+ this.sentEmbedded = this.options.embedded();
871
1470
  this.post({
872
1471
  kind: "build",
873
1472
  engine: sources.engine,
874
1473
  themes: this.options.themes(),
875
- languages: [...sources.languages]
1474
+ languages: [...sources.languages],
1475
+ embedded: this.sentEmbedded
876
1476
  });
877
1477
  return true;
878
1478
  }
@@ -885,6 +1485,14 @@ var TokenizationClient = class {
885
1485
  });
886
1486
  this.sentLanguages = languages.length;
887
1487
  }
1488
+ const embedded = this.options.embedded();
1489
+ if (embedded !== this.sentEmbedded) {
1490
+ this.post({
1491
+ kind: "embedded",
1492
+ languages: embedded
1493
+ });
1494
+ this.sentEmbedded = embedded;
1495
+ }
888
1496
  }
889
1497
  post(message) {
890
1498
  this.worker?.then((worker) => {
@@ -955,12 +1563,12 @@ var TokenizationClient = class {
955
1563
  //#endregion
956
1564
  //#region src/tokenization/support.ts
957
1565
  function shikiTokenization(options) {
958
- const { internals, highlighter, language, languageId, theme, colorIds, scopeOf, background } = options;
1566
+ const { internals, highlighter, language, languageId, embedded, theme, colorIds, scopeOf, background } = options;
959
1567
  const tokenizeOnPage = (line, state) => {
960
1568
  if (line.length >= 1e3) return;
961
1569
  try {
962
1570
  highlighter.setTheme(theme());
963
- const result = highlighter.getLanguage(language).tokenizeLine2(line, state, 50);
1571
+ const result = embedLanguages(highlighter.getLanguage(language), embedded()).tokenizeLine2(line, state, 50);
964
1572
  return result.stoppedEarly ? void 0 : result;
965
1573
  } catch {
966
1574
  return;
@@ -1096,6 +1704,7 @@ function clientOf(bridge) {
1096
1704
  internals: bridge.internals,
1097
1705
  sources,
1098
1706
  themes: () => bridge.highlighter.getLoadedThemes().map((id) => bridge.highlighter.getTheme(id)),
1707
+ embedded: () => bridge.embedded,
1099
1708
  createWorker: () => getWorker("inkstone-textmate", TEXTMATE_WORKER_LABEL),
1100
1709
  unavailable: (languages) => {
1101
1710
  if (languages === "all") bridge.client = null;
@@ -1115,14 +1724,19 @@ function quietBuiltInTokenizer(monaco, language) {
1115
1724
  }
1116
1725
  function install(monaco, bridge, canonical) {
1117
1726
  if (bridge.registered.has(canonical)) return;
1118
- if (monaco.languages.getLanguages().every((language) => language.id !== canonical)) monaco.languages.register({ id: canonical });
1727
+ if (monaco.languages.getLanguages().every((language) => language.id !== canonical)) {
1728
+ monaco.languages.register({ id: canonical });
1729
+ configureLanguage(monaco, canonical);
1730
+ }
1119
1731
  quietBuiltInTokenizer(monaco, canonical);
1732
+ bridge.internals.encounter(canonical);
1120
1733
  bridge.registered.set(canonical, bridge.highlighter.getLanguage(canonical));
1121
1734
  bridge.internals.registry.register(canonical, shikiTokenization({
1122
1735
  internals: bridge.internals,
1123
1736
  highlighter: bridge.highlighter,
1124
1737
  language: canonical,
1125
1738
  languageId: monaco.languages.getEncodedLanguageId(canonical),
1739
+ embedded: () => bridge.embedded,
1126
1740
  theme: () => bridge.theme,
1127
1741
  colorIds: () => colorIds(bridge),
1128
1742
  scopeOf: (metadata) => scopeOfMetadata(bridge, metadata),
@@ -1136,6 +1750,13 @@ function install(monaco, bridge, canonical) {
1136
1750
  }
1137
1751
  }));
1138
1752
  }
1753
+ function refreshEmbedded(monaco, bridge) {
1754
+ const sources = highlighterSources(bridge.highlighter);
1755
+ if (!sources) return;
1756
+ const embedded = embeddedLanguagesOf(sources.languages, (language) => bridge.registered.has(language) ? monaco.languages.getEncodedLanguageId(language) : void 0);
1757
+ const scopes = Object.keys(embedded);
1758
+ if (scopes.length !== Object.keys(bridge.embedded).length || scopes.some((scope) => embedded[scope] !== bridge.embedded[scope])) bridge.embedded = embedded;
1759
+ }
1139
1760
  function retokenizeRebuilt(bridge) {
1140
1761
  const rebuilt = [];
1141
1762
  for (const [language, grammar] of bridge.registered) {
@@ -1155,6 +1776,7 @@ function registerShikiHighlighting(monaco, highlighter) {
1155
1776
  const bridged = registry.get(monaco);
1156
1777
  if (bridged) {
1157
1778
  for (const canonical of canonicalLanguages(highlighter)) install(monaco, bridged, canonical);
1779
+ refreshEmbedded(monaco, bridged);
1158
1780
  retokenizeRebuilt(bridged);
1159
1781
  return;
1160
1782
  }
@@ -1170,7 +1792,8 @@ function registerShikiHighlighting(monaco, highlighter) {
1170
1792
  scopeOf: /* @__PURE__ */ new Map(),
1171
1793
  registered: /* @__PURE__ */ new Map(),
1172
1794
  client: void 0,
1173
- workerless: /* @__PURE__ */ new Set()
1795
+ workerless: /* @__PURE__ */ new Set(),
1796
+ embedded: {}
1174
1797
  };
1175
1798
  const originalCreate = monaco.editor.create;
1176
1799
  const originalSetTheme = monaco.editor.setTheme;
@@ -1191,6 +1814,7 @@ function registerShikiHighlighting(monaco, highlighter) {
1191
1814
  const [firstTheme] = highlighter.getLoadedThemes();
1192
1815
  if (firstTheme !== void 0) monaco.editor.setTheme(firstTheme);
1193
1816
  for (const canonical of canonicalLanguages(highlighter)) install(monaco, bridge, canonical);
1817
+ refreshEmbedded(monaco, bridge);
1194
1818
  } catch (error) {
1195
1819
  monaco.editor.create = originalCreate;
1196
1820
  monaco.editor.setTheme = originalSetTheme;
@@ -1219,6 +1843,8 @@ function registerShikiLanguage(monaco, highlighter, language) {
1219
1843
  }
1220
1844
  if (!bridge) throw new Error("inkstone: the Shiki bridge is not installed on this monaco module");
1221
1845
  install(monaco, bridge, highlighter.getLanguage(language).name);
1846
+ for (const canonical of canonicalLanguages(highlighter)) install(monaco, bridge, canonical);
1847
+ refreshEmbedded(monaco, bridge);
1222
1848
  retokenizeRebuilt(bridge);
1223
1849
  }
1224
1850
  //#endregion
@@ -1331,4 +1957,4 @@ var StreamingEditorController = class {
1331
1957
  }
1332
1958
  };
1333
1959
  //#endregion
1334
- export { DEFAULT_MONACO_OPTIONS, StreamingEditorController, disabledKeybindings, ensureMonacoHost, installAutoImportCompletions, installDesignTokens, installDisabledKeybindings, installHoverDeadBandFix, installJsxTagClosing, modelValueMatches, monacoLanguages, reconcileModelValue, registerShikiHighlighting, registerShikiLanguage, replaceInEditor };
1960
+ export { DEFAULT_MONACO_OPTIONS, StreamingEditorController, configuredLanguages, disabledKeybindings, ensureMonacoHost, installAutoImportCompletions, installDesignTokens, installDisabledKeybindings, installHoverDeadBandFix, installJsxTagClosing, modelValueMatches, monacoLanguages, reconcileModelValue, registerShikiHighlighting, registerShikiLanguage, replaceInEditor };
@@ -1,4 +1,4 @@
1
- import { a as toMonacoTokens, c as stateDiff, f as lineSplice, i as defaultMetadata, l as applyChange, o as withEndOffsets, u as applySplice } from "../bounds-CZ_iAUoc.js";
1
+ import { a as toMonacoTokens, d as applyChange, f as applySplice, i as defaultMetadata, m as lineSplice, o as withEndOffsets, s as embedLanguages, u as stateDiff } from "../bounds-CPkzvXiT.js";
2
2
  import { INITIAL } from "@shikijs/vscode-textmate";
3
3
  import { createHighlighterCore } from "shiki/core";
4
4
  //#region src/tokenization/invalid-lines.ts
@@ -131,6 +131,7 @@ var TokenizationWorker = class {
131
131
  schedule;
132
132
  now;
133
133
  highlighter;
134
+ embedded = {};
134
135
  models = /* @__PURE__ */ new Map();
135
136
  scheduled = false;
136
137
  failed = false;
@@ -177,7 +178,7 @@ var TokenizationWorker = class {
177
178
  let grammar;
178
179
  try {
179
180
  highlighter.setTheme(model.theme);
180
- grammar = highlighter.getLanguage(model.language);
181
+ grammar = embedLanguages(highlighter.getLanguage(model.language), this.embedded);
181
182
  } catch {
182
183
  this.models.delete(model.id);
183
184
  this.send({
@@ -219,6 +220,7 @@ var TokenizationWorker = class {
219
220
  receive(message) {
220
221
  switch (message.kind) {
221
222
  case "build":
223
+ this.embedded = message.embedded;
222
224
  this.highlighter = (async () => createHighlighterCore({
223
225
  themes: [...message.themes],
224
226
  langs: [...message.languages],
@@ -235,6 +237,9 @@ var TokenizationWorker = class {
235
237
  return highlighter;
236
238
  });
237
239
  break;
240
+ case "embedded":
241
+ this.embedded = message.languages;
242
+ break;
238
243
  case "open":
239
244
  this.models.set(message.model, {
240
245
  id: message.model,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coldsmirk/inkstone-monaco",
3
- "version": "0.36.1",
3
+ "version": "0.38.0",
4
4
  "description": "Framework-agnostic Monaco assembly: lazy offline host (all language workers bundled, no CDN), opt-in Simplified-Chinese UI via monaco's official NLS catalog, a streaming editor controller for AI-typed content, and the shared Shiki highlighting bridge.",
5
5
  "keywords": [
6
6
  "monaco",
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@shikijs/vscode-textmate": "^10.0.2",
43
43
  "shiki": "^4.5.0",
44
- "@coldsmirk/inkstone-core": "^0.36.1"
44
+ "@coldsmirk/inkstone-core": "^0.38.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "monaco-editor": "^0.57.0",