stream-monaco 0.0.15 → 0.0.17

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/dist/index.d.cts CHANGED
@@ -1,292 +1,9 @@
1
- import * as monaco_editor0 from "monaco-editor";
2
- import * as monaco$1 from "monaco-editor";
3
- import * as _monaco from "monaco-editor";
4
- import { Highlighter, SpecialTheme, ThemeInput } from "shiki";
1
+ import { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, registerMonacoThemes, useMonaco } from "./index.base-D0jPJkA_.cjs";
5
2
 
6
- //#region rolldown:runtime
7
- //#endregion
8
- //#region src/type.d.ts
9
- type ShikiHighlighter = Highlighter | any;
10
- type MonacoEditorInstance = monaco$1.editor.IStandaloneCodeEditor;
11
- type MonacoDiffEditorInstance = monaco$1.editor.IStandaloneDiffEditor;
12
- type MonacoTheme = 'andromeeda' | 'aurora-x' | 'ayu-dark' | 'catppuccin-frappe' | 'catppuccin-latte' | 'catppuccin-macchiato' | 'catppuccin-mocha' | 'dark-plus' | 'dracula' | 'dracula-soft' | 'everforest-dark' | 'everforest-light' | 'github-dark' | 'github-dark-default' | 'github-dark-dimmed' | 'github-dark-high-contrast' | 'github-light' | 'github-light-default' | 'github-light-high-contrast' | 'gruvbox-dark-hard' | 'gruvbox-dark-medium' | 'gruvbox-dark-soft' | 'gruvbox-light-hard' | 'gruvbox-light-medium' | 'gruvbox-light-soft' | 'houston' | 'kanagawa-dragon' | 'kanagawa-lotus' | 'kanagawa-wave' | 'laserwave' | 'light-plus' | 'material-theme' | 'material-theme-darker' | 'material-theme-lighter' | 'material-theme-ocean' | 'material-theme-palenight' | 'min-dark' | 'min-light' | 'monokai' | 'night-owl' | 'nord' | 'one-dark-pro' | 'one-light' | 'plastic' | 'poimandres' | 'red' | 'rose-pine' | 'rose-pine-dawn' | 'rose-pine-moon' | 'slack-dark' | 'slack-ochin' | 'snazzy-light' | 'solarized-dark' | 'solarized-light' | 'synthwave-84' | 'tokyo-night' | 'vesper' | 'vitesse-black' | 'vitesse-dark' | 'vitesse-light' | ThemeInput | string | SpecialTheme;
13
- type MonacoLanguage = 'abap' | 'actionscript-3' | 'ada' | 'angular-html' | 'angular-ts' | 'apache' | 'apex' | 'apl' | 'applescript' | 'ara' | 'asciidoc' | 'asm' | 'astro' | 'awk' | 'ballerina' | 'bat' | 'beancount' | 'berry' | 'bibtex' | 'bicep' | 'blade' | 'bsl' | 'c' | 'cadence' | 'cairo' | 'clarity' | 'clojure' | 'cmake' | 'cobol' | 'codeowners' | 'codeql' | 'coffee' | 'common-lisp' | 'coq' | 'cpp' | 'crystal' | 'csharp' | 'css' | 'csv' | 'cue' | 'cypher' | 'd' | 'dart' | 'dax' | 'desktop' | 'diff' | 'docker' | 'dotenv' | 'dream-maker' | 'edge' | 'elixir' | 'elm' | 'emacs-lisp' | 'erb' | 'erlang' | 'fennel' | 'fish' | 'fluent' | 'fortran-fixed-form' | 'fortran-free-form' | 'fsharp' | 'gdresource' | 'gdscript' | 'gdshader' | 'genie' | 'gherkin' | 'git-commit' | 'git-rebase' | 'gleam' | 'glimmer-js' | 'glimmer-ts' | 'glsl' | 'gnuplot' | 'go' | 'graphql' | 'groovy' | 'hack' | 'haml' | 'handlebars' | 'haskell' | 'haxe' | 'hcl' | 'hjson' | 'hlsl' | 'html' | 'html-derivative' | 'http' | 'hxml' | 'hy' | 'imba' | 'ini' | 'java' | 'javascript' | 'jinja' | 'jison' | 'json' | 'json5' | 'jsonc' | 'jsonl' | 'jsonnet' | 'jssm' | 'jsx' | 'julia' | 'kotlin' | 'kusto' | 'latex' | 'lean' | 'less' | 'liquid' | 'llvm' | 'log' | 'logo' | 'lua' | 'luau' | 'make' | 'markdown' | 'marko' | 'matlab' | 'mdc' | 'mdx' | 'mermaid' | 'mipsasm' | 'mojo' | 'move' | 'narrat' | 'nextflow' | 'nginx' | 'nim' | 'nix' | 'nushell' | 'objective-c' | 'objective-cpp' | 'ocaml' | 'pascal' | 'perl' | 'php' | 'plsql' | 'po' | 'polar' | 'postcss' | 'powerquery' | 'powershell' | 'prisma' | 'prolog' | 'proto' | 'pug' | 'puppet' | 'purescript' | 'python' | 'qml' | 'qmldir' | 'qss' | 'r' | 'racket' | 'raku' | 'razor' | 'reg' | 'regexp' | 'rel' | 'riscv' | 'rst' | 'ruby' | 'rust' | 'sas' | 'sass' | 'scala' | 'scheme' | 'scss' | 'sdbl' | 'shaderlab' | 'shellscript' | 'shellsession' | 'smalltalk' | 'solidity' | 'soy' | 'sparql' | 'splunk' | 'sql' | 'ssh-config' | 'stata' | 'stylus' | 'svelte' | 'swift' | 'system-verilog' | 'systemd' | 'talonscript' | 'tasl' | 'tcl' | 'templ' | 'terraform' | 'tex' | 'toml' | 'ts-tags' | 'tsv' | 'tsx' | 'turtle' | 'twig' | 'typescript' | 'typespec' | 'typst' | 'v' | 'vala' | 'vb' | 'verilog' | 'vhdl' | 'viml' | 'vue' | 'vue-html' | 'vyper' | 'wasm' | 'wenyan' | 'wgsl' | 'wikitext' | 'wit' | 'wolfram' | 'xml' | 'xsl' | 'yaml' | 'zenscript' | 'zig' | string;
14
- interface MonacoOptions extends monaco$1.editor.IStandaloneEditorConstructionOptions {
15
- MAX_HEIGHT?: number | string;
16
- readOnly?: boolean;
17
- themes?: MonacoTheme[];
18
- languages?: MonacoLanguage[];
19
- theme?: string;
20
- isCleanOnBeforeCreate?: boolean;
21
- /**
22
- * 控制更新时的自动滚动行为:当为 true 时,如果当前接近底部则在新增内容后自动滚动到底部;
23
- * 当为 false 时,将完全禁用自动滚动。
24
- * 默认 true。
25
- */
26
- autoScrollOnUpdate?: boolean;
27
- /**
28
- * 编辑器创建时是否默认启用自动滚动。用户一旦滚离底部将自动暂停,回到底部附近再恢复。
29
- * 默认 true(保持原有行为)。
30
- */
31
- autoScrollInitial?: boolean;
32
- /**
33
- * 触发“接近底部”的绝对像素阈值。如果设置,将与 autoScrollThresholdLines 共同取最大值。
34
- * 默认 32。
35
- */
36
- autoScrollThresholdPx?: number;
37
- /**
38
- * 触发“接近底部”的相对行数阈值(以当前行高计算)。如果设置,将与 autoScrollThresholdPx 共同取最大值。
39
- * 默认 2 行。
40
- */
41
- autoScrollThresholdLines?: number;
42
- /**
43
- * 是否启用 Diff 编辑器 modified 侧的自动滚动逻辑。
44
- * 当为 false 时,updateDiff/appendModified 等不会触发自动滚动。
45
- * 默认 true(与单编辑器体验保持一致)。
46
- */
47
- diffAutoScroll?: boolean;
48
- /**
49
- * Debounce time (ms) to coalesce multiple reveal requests into a single
50
- * reveal. Useful for streaming/append scenarios. Default: 75
51
- */
52
- revealDebounceMs?: number;
53
- /**
54
- * How to reveal target line when auto-scrolling.
55
- * - 'bottom' : revealLine (closest to bottom)
56
- * - 'centerIfOutside' : revealLineInCenterIfOutsideViewport (default)
57
- * - 'center' : revealLineInCenter
58
- */
59
- revealStrategy?: 'bottom' | 'centerIfOutside' | 'center';
60
- /**
61
- * If set to a positive number (ms), append/streaming scenarios will delay a final
62
- * "scroll to bottom" until this idle time has passed since the last append. Useful
63
- * to batch many small appends and then perform one final jump to bottom. Default: undefined (disabled).
64
- */
65
- revealBatchOnIdleMs?: number;
66
- /**
67
- * Time window (ms) used to throttle `updateCode` calls in addition to RAF batching.
68
- * - 0 means only RAF-based coalescing (no extra time throttling).
69
- * - Default (library): 50
70
- */
71
- updateThrottleMs?: number;
72
- /**
73
- * Time window (ms) used to throttle diff streaming updates in addition to RAF batching.
74
- * This affects `appendOriginal`/`appendModified` and the fast-path append branches of `updateDiff`.
75
- *
76
- * Why: Monaco's diff computation is async and cancels/restarts when models change.
77
- * If you apply edits every frame (or per token), the diff may only finish once
78
- * streaming stops, so the highlights appear "at the end".
79
- *
80
- * - 0 means only RAF-based coalescing (more responsive, but can starve diff computation).
81
- * - Default (library): 50
82
- */
83
- diffUpdateThrottleMs?: number;
84
- /**
85
- * When attempting the "minimal edit" algorithm, if prev.length + next.length
86
- * exceeds this number the library will fall back to full `setValue` to avoid
87
- * expensive diff computation on very large documents.
88
- */
89
- minimalEditMaxChars?: number;
90
- /**
91
- * When the relative change ratio (|new-prev|/maxLen) exceeds this value the
92
- * library will fall back to full `setValue` instead of attempting minimal edit.
93
- */
94
- minimalEditMaxChangeRatio?: number;
95
- onBeforeCreate?: (monaco: typeof monaco_editor0) => monaco$1.IDisposable[];
96
- /**
97
- * Optional callback that is invoked after a theme change has been applied.
98
- * This callback will be awaited when possible so callers can track completion
99
- * of theme application. It receives the name of the applied theme.
100
- */
101
- onThemeChange?: (theme: MonacoTheme) => void | Promise<void>;
102
- }
103
- declare enum RevealStrategy {
104
- Bottom = "bottom",
105
- CenterIfOutside = "centerIfOutside",
106
- Center = "center",
107
- }
108
- //#endregion
109
- //#region src/code.detect.d.ts
110
- /**
111
- * @module detect
112
- * (Language detector)
113
- */
114
- /**
115
- * Supported language identifiers
116
- */
117
- type CodeLanguage = 'bash' | 'html' | 'http' | 'js' | 'ts' | 'py' | 'sql' | 'pl' | 'lua' | 'make' | 'uri' | 'css' | 'diff' | 'md' | 'docker' | 'xml' | 'c' | 'rs' | 'go' | 'java' | 'asm' | 'json' | 'yaml' | 'toml' | 'mermaid' | 'plain';
118
- /**
119
- * Language detection feature with pattern and score
120
- */
121
- type LanguageFeature = [RegExp, number];
122
- /**
123
- * Language definition with identifier and detection features
124
- */
125
- type LanguageDefinition = [CodeLanguage, ...LanguageFeature[]];
126
- /**
127
- * Language detection definitions
128
- */
129
-
130
- /**
131
- * Try to find the language the given code belongs to
132
- *
133
- * @param {string} code The code to analyze
134
- * @param {LanguageDefinition[]} [additionalLanguages] Additional language definitions to supplement the built-in ones
135
- * @returns {CodeLanguage} The detected language of the code
136
- */
137
- declare function detectLanguage(code: string, additionalLanguages?: LanguageDefinition[]): CodeLanguage;
138
- //#endregion
139
- //#region src/constant.d.ts
140
- declare const defaultRevealDebounceMs = 75;
141
- declare namespace monaco_shim_d_exports {
142
- export { monaco as default };
143
- }
144
- import * as import_monaco_editor from "monaco-editor";
145
- __reExport(monaco_shim_d_exports, import_monaco_editor);
146
- declare const monaco: typeof _monaco;
147
- //#endregion
148
3
  //#region src/preloadMonacoWorkers.d.ts
149
4
  declare function preloadMonacoWorkers(): Promise<void>;
150
5
  //#endregion
151
- //#region src/utils/registerMonacoThemes.d.ts
152
- /**
153
- * Clear all cached shiki highlighters.
154
- *
155
- * Useful for long-running apps that dynamically create many theme combinations,
156
- * or in tests to ensure a clean state. Call this when you know the highlighters
157
- * are no longer needed (for example on app shutdown) to free memory.
158
- */
159
- declare function clearHighlighterCache(): void;
160
- /**
161
- * Return number of entries currently in the highlighter cache.
162
- * Helpful for tests and debugging.
163
- */
164
-
165
- declare function getOrCreateHighlighter(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter>;
166
- /**
167
- * Update the theme used by the shiki highlighter for a given themes+languages
168
- * combination. Useful when Monaco themes are already registered (so switching
169
- * Monaco only requires `monaco.editor.setTheme`) but you also want shiki's
170
- * standalone renderer to use the new theme without recreating everything.
171
- */
172
- declare function registerMonacoThemes(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter | null>;
173
- //#endregion
174
- //#region src/index.d.ts
175
- /**
176
- * useMonaco 组合式函数
177
- *
178
- * 提供 Monaco 编辑器的创建、销毁、内容/主题/语言更新等能力。
179
- * 支持主题自动切换、语言高亮、代码更新等功能。
180
- *
181
- * @param {MonacoOptions} [monacoOptions] - 编辑器初始化配置,支持 Monaco 原生配置及扩展项
182
- * @param {number | string} [monacoOptions.MAX_HEIGHT] - 编辑器最大高度,可以是数字(像素)或 CSS 字符串(如 '100%', 'calc(100vh - 100px)')
183
- * @param {boolean} [monacoOptions.readOnly] - 是否为只读模式
184
- * @param {MonacoTheme[]} [monacoOptions.themes] - 主题数组,至少包含两个主题:[暗色主题, 亮色主题]
185
- * @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
186
- * @param {string} [monacoOptions.theme] - 初始主题名称
187
- * @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
188
- * @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
189
- *
190
- * @returns {{
191
- * createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,
192
- * createDiffEditor: (
193
- * container: HTMLElement,
194
- * originalCode: string,
195
- * modifiedCode: string,
196
- * language: string,
197
- * ) => Promise<monaco.editor.IStandaloneDiffEditor>,
198
- * cleanupEditor: () => void,
199
- * updateCode: (newCode: string, codeLanguage: string) => void,
200
- * appendCode: (appendText: string, codeLanguage?: string) => void,
201
- * updateDiff: (
202
- * originalCode: string,
203
- * modifiedCode: string,
204
- * codeLanguage?: string,
205
- * ) => void,
206
- * updateOriginal: (newCode: string, codeLanguage?: string) => void,
207
- * updateModified: (newCode: string, codeLanguage?: string) => void,
208
- * appendOriginal: (appendText: string, codeLanguage?: string) => void,
209
- * appendModified: (appendText: string, codeLanguage?: string) => void,
210
- * setTheme: (theme: MonacoTheme) => Promise<void>,
211
- * setLanguage: (language: MonacoLanguage) => void,
212
- * getCurrentTheme: () => string,
213
- * getEditor: () => typeof monaco.editor,
214
- * getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
215
- * getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
216
- * getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
217
- * getCode: () => string | { original: string, modified: string } | null,
218
- * }} 返回对象包含以下方法和属性:
219
- *
220
- * @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
221
- * @property {Function} cleanupEditor - 销毁编辑器并清理容器
222
- * @property {Function} updateCode - 更新编辑器内容和语言,必要时滚动到底部
223
- * @property {Function} appendCode - 在编辑器末尾追加文本,必要时滚动到底部
224
- * @property {Function} createDiffEditor - 创建并挂载 Diff 编辑器
225
- * @property {Function} updateDiff - 更新 Diff 编辑器的 original/modified 内容(RAF 合并、增量更新)
226
- * @property {Function} updateOriginal - 仅更新 Diff 的 original 内容(增量更新)
227
- * @property {Function} updateModified - 仅更新 Diff 的 modified 内容(增量更新)
228
- * @property {Function} appendOriginal - 在 Diff 的 original 末尾追加(显式流式场景)
229
- * @property {Function} appendModified - 在 Diff 的 modified 末尾追加(显式流式场景)
230
- * @property {Function} setTheme - 切换编辑器主题,返回 Promise,在主题应用完成时 resolve
231
- * @property {Function} setLanguage - 切换编辑器语言
232
- * @property {Function} getCurrentTheme - 获取当前主题名称
233
- * @property {Function} getEditor - 获取 Monaco 的静态 editor 对象(用于静态方法调用)
234
- * @property {Function} getEditorView - 获取当前编辑器实例
235
- * @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
236
- * @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
237
- * @property {Function} getCode - 获取当前编辑器或 Diff 编辑器中的代码内容
238
- *
239
- * @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
240
- *
241
- * @example
242
- * ```typescript
243
- * import { useMonaco } from 'stream-monaco'
244
- *
245
- * const { createEditor, updateCode, setTheme } = useMonaco({
246
- * themes: ['vitesse-dark', 'vitesse-light'],
247
- * languages: ['javascript', 'typescript'],
248
- * readOnly: false
249
- * })
250
- *
251
- * // 创建编辑器
252
- * const editor = await createEditor(containerRef.value, 'console.log("hello")', 'javascript')
253
- *
254
- * // 更新代码
255
- * updateCode('console.log("world")', 'javascript')
256
- *
257
- * // 切换主题
258
- * setTheme('vitesse-light')
259
- * ```
260
- */
261
- declare function useMonaco(monacoOptions?: MonacoOptions): {
262
- createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneCodeEditor>;
263
- createDiffEditor: (container: HTMLElement, originalCode: string, modifiedCode: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneDiffEditor>;
264
- cleanupEditor: () => void;
265
- safeClean(): void;
266
- updateCode: (newCode: string, codeLanguage: string) => void;
267
- appendCode: (appendText: string, codeLanguage?: string) => void;
268
- updateDiff: (originalCode: string, modifiedCode: string, codeLanguage?: string) => void;
269
- updateOriginal: (newCode: string, codeLanguage?: string) => void;
270
- updateModified: (newCode: string, codeLanguage?: string) => void;
271
- appendOriginal: (appendText: string, codeLanguage?: string) => void;
272
- appendModified: (appendText: string, codeLanguage?: string) => void;
273
- setTheme: (theme: MonacoTheme, force?: boolean) => Promise<void>;
274
- setLanguage(language: MonacoLanguage): void;
275
- getCurrentTheme(): string;
276
- getEditor(): typeof monaco_shim_d_exports.editor;
277
- getEditorView(): monaco_shim_d_exports.editor.IStandaloneCodeEditor | null;
278
- getDiffEditorView(): monaco_shim_d_exports.editor.IStandaloneDiffEditor | null;
279
- getDiffModels(): {
280
- original: monaco_shim_d_exports.editor.ITextModel | null;
281
- modified: monaco_shim_d_exports.editor.ITextModel | null;
282
- };
283
- getMonacoInstance(): typeof monaco_shim_d_exports;
284
- setUpdateThrottleMs: (ms: number) => void;
285
- getUpdateThrottleMs: () => number;
286
- getCode(): string | {
287
- original: string;
288
- modified: string;
289
- } | null;
290
- };
6
+ //#region src/ensureMonacoWorkers.d.ts
7
+ declare function ensureMonacoWorkers(): void;
291
8
  //#endregion
292
- export { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, preloadMonacoWorkers, registerMonacoThemes, useMonaco };
9
+ export { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, ensureMonacoWorkers, getOrCreateHighlighter, preloadMonacoWorkers, registerMonacoThemes, useMonaco };
package/dist/index.d.ts CHANGED
@@ -1,291 +1,9 @@
1
- import { __export, __reExport } from "./chunk-CHLpw0oG.js";
2
- import * as monaco_editor0 from "monaco-editor";
3
- import * as monaco$1 from "monaco-editor";
4
- import * as _monaco from "monaco-editor";
5
- import { Highlighter, SpecialTheme, ThemeInput } from "shiki";
1
+ import { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, registerMonacoThemes, useMonaco } from "./index.base-BaAqAXUs.js";
6
2
 
7
- //#region src/type.d.ts
8
- type ShikiHighlighter = Highlighter | any;
9
- type MonacoEditorInstance = monaco$1.editor.IStandaloneCodeEditor;
10
- type MonacoDiffEditorInstance = monaco$1.editor.IStandaloneDiffEditor;
11
- type MonacoTheme = 'andromeeda' | 'aurora-x' | 'ayu-dark' | 'catppuccin-frappe' | 'catppuccin-latte' | 'catppuccin-macchiato' | 'catppuccin-mocha' | 'dark-plus' | 'dracula' | 'dracula-soft' | 'everforest-dark' | 'everforest-light' | 'github-dark' | 'github-dark-default' | 'github-dark-dimmed' | 'github-dark-high-contrast' | 'github-light' | 'github-light-default' | 'github-light-high-contrast' | 'gruvbox-dark-hard' | 'gruvbox-dark-medium' | 'gruvbox-dark-soft' | 'gruvbox-light-hard' | 'gruvbox-light-medium' | 'gruvbox-light-soft' | 'houston' | 'kanagawa-dragon' | 'kanagawa-lotus' | 'kanagawa-wave' | 'laserwave' | 'light-plus' | 'material-theme' | 'material-theme-darker' | 'material-theme-lighter' | 'material-theme-ocean' | 'material-theme-palenight' | 'min-dark' | 'min-light' | 'monokai' | 'night-owl' | 'nord' | 'one-dark-pro' | 'one-light' | 'plastic' | 'poimandres' | 'red' | 'rose-pine' | 'rose-pine-dawn' | 'rose-pine-moon' | 'slack-dark' | 'slack-ochin' | 'snazzy-light' | 'solarized-dark' | 'solarized-light' | 'synthwave-84' | 'tokyo-night' | 'vesper' | 'vitesse-black' | 'vitesse-dark' | 'vitesse-light' | ThemeInput | string | SpecialTheme;
12
- type MonacoLanguage = 'abap' | 'actionscript-3' | 'ada' | 'angular-html' | 'angular-ts' | 'apache' | 'apex' | 'apl' | 'applescript' | 'ara' | 'asciidoc' | 'asm' | 'astro' | 'awk' | 'ballerina' | 'bat' | 'beancount' | 'berry' | 'bibtex' | 'bicep' | 'blade' | 'bsl' | 'c' | 'cadence' | 'cairo' | 'clarity' | 'clojure' | 'cmake' | 'cobol' | 'codeowners' | 'codeql' | 'coffee' | 'common-lisp' | 'coq' | 'cpp' | 'crystal' | 'csharp' | 'css' | 'csv' | 'cue' | 'cypher' | 'd' | 'dart' | 'dax' | 'desktop' | 'diff' | 'docker' | 'dotenv' | 'dream-maker' | 'edge' | 'elixir' | 'elm' | 'emacs-lisp' | 'erb' | 'erlang' | 'fennel' | 'fish' | 'fluent' | 'fortran-fixed-form' | 'fortran-free-form' | 'fsharp' | 'gdresource' | 'gdscript' | 'gdshader' | 'genie' | 'gherkin' | 'git-commit' | 'git-rebase' | 'gleam' | 'glimmer-js' | 'glimmer-ts' | 'glsl' | 'gnuplot' | 'go' | 'graphql' | 'groovy' | 'hack' | 'haml' | 'handlebars' | 'haskell' | 'haxe' | 'hcl' | 'hjson' | 'hlsl' | 'html' | 'html-derivative' | 'http' | 'hxml' | 'hy' | 'imba' | 'ini' | 'java' | 'javascript' | 'jinja' | 'jison' | 'json' | 'json5' | 'jsonc' | 'jsonl' | 'jsonnet' | 'jssm' | 'jsx' | 'julia' | 'kotlin' | 'kusto' | 'latex' | 'lean' | 'less' | 'liquid' | 'llvm' | 'log' | 'logo' | 'lua' | 'luau' | 'make' | 'markdown' | 'marko' | 'matlab' | 'mdc' | 'mdx' | 'mermaid' | 'mipsasm' | 'mojo' | 'move' | 'narrat' | 'nextflow' | 'nginx' | 'nim' | 'nix' | 'nushell' | 'objective-c' | 'objective-cpp' | 'ocaml' | 'pascal' | 'perl' | 'php' | 'plsql' | 'po' | 'polar' | 'postcss' | 'powerquery' | 'powershell' | 'prisma' | 'prolog' | 'proto' | 'pug' | 'puppet' | 'purescript' | 'python' | 'qml' | 'qmldir' | 'qss' | 'r' | 'racket' | 'raku' | 'razor' | 'reg' | 'regexp' | 'rel' | 'riscv' | 'rst' | 'ruby' | 'rust' | 'sas' | 'sass' | 'scala' | 'scheme' | 'scss' | 'sdbl' | 'shaderlab' | 'shellscript' | 'shellsession' | 'smalltalk' | 'solidity' | 'soy' | 'sparql' | 'splunk' | 'sql' | 'ssh-config' | 'stata' | 'stylus' | 'svelte' | 'swift' | 'system-verilog' | 'systemd' | 'talonscript' | 'tasl' | 'tcl' | 'templ' | 'terraform' | 'tex' | 'toml' | 'ts-tags' | 'tsv' | 'tsx' | 'turtle' | 'twig' | 'typescript' | 'typespec' | 'typst' | 'v' | 'vala' | 'vb' | 'verilog' | 'vhdl' | 'viml' | 'vue' | 'vue-html' | 'vyper' | 'wasm' | 'wenyan' | 'wgsl' | 'wikitext' | 'wit' | 'wolfram' | 'xml' | 'xsl' | 'yaml' | 'zenscript' | 'zig' | string;
13
- interface MonacoOptions extends monaco$1.editor.IStandaloneEditorConstructionOptions {
14
- MAX_HEIGHT?: number | string;
15
- readOnly?: boolean;
16
- themes?: MonacoTheme[];
17
- languages?: MonacoLanguage[];
18
- theme?: string;
19
- isCleanOnBeforeCreate?: boolean;
20
- /**
21
- * 控制更新时的自动滚动行为:当为 true 时,如果当前接近底部则在新增内容后自动滚动到底部;
22
- * 当为 false 时,将完全禁用自动滚动。
23
- * 默认 true。
24
- */
25
- autoScrollOnUpdate?: boolean;
26
- /**
27
- * 编辑器创建时是否默认启用自动滚动。用户一旦滚离底部将自动暂停,回到底部附近再恢复。
28
- * 默认 true(保持原有行为)。
29
- */
30
- autoScrollInitial?: boolean;
31
- /**
32
- * 触发“接近底部”的绝对像素阈值。如果设置,将与 autoScrollThresholdLines 共同取最大值。
33
- * 默认 32。
34
- */
35
- autoScrollThresholdPx?: number;
36
- /**
37
- * 触发“接近底部”的相对行数阈值(以当前行高计算)。如果设置,将与 autoScrollThresholdPx 共同取最大值。
38
- * 默认 2 行。
39
- */
40
- autoScrollThresholdLines?: number;
41
- /**
42
- * 是否启用 Diff 编辑器 modified 侧的自动滚动逻辑。
43
- * 当为 false 时,updateDiff/appendModified 等不会触发自动滚动。
44
- * 默认 true(与单编辑器体验保持一致)。
45
- */
46
- diffAutoScroll?: boolean;
47
- /**
48
- * Debounce time (ms) to coalesce multiple reveal requests into a single
49
- * reveal. Useful for streaming/append scenarios. Default: 75
50
- */
51
- revealDebounceMs?: number;
52
- /**
53
- * How to reveal target line when auto-scrolling.
54
- * - 'bottom' : revealLine (closest to bottom)
55
- * - 'centerIfOutside' : revealLineInCenterIfOutsideViewport (default)
56
- * - 'center' : revealLineInCenter
57
- */
58
- revealStrategy?: 'bottom' | 'centerIfOutside' | 'center';
59
- /**
60
- * If set to a positive number (ms), append/streaming scenarios will delay a final
61
- * "scroll to bottom" until this idle time has passed since the last append. Useful
62
- * to batch many small appends and then perform one final jump to bottom. Default: undefined (disabled).
63
- */
64
- revealBatchOnIdleMs?: number;
65
- /**
66
- * Time window (ms) used to throttle `updateCode` calls in addition to RAF batching.
67
- * - 0 means only RAF-based coalescing (no extra time throttling).
68
- * - Default (library): 50
69
- */
70
- updateThrottleMs?: number;
71
- /**
72
- * Time window (ms) used to throttle diff streaming updates in addition to RAF batching.
73
- * This affects `appendOriginal`/`appendModified` and the fast-path append branches of `updateDiff`.
74
- *
75
- * Why: Monaco's diff computation is async and cancels/restarts when models change.
76
- * If you apply edits every frame (or per token), the diff may only finish once
77
- * streaming stops, so the highlights appear "at the end".
78
- *
79
- * - 0 means only RAF-based coalescing (more responsive, but can starve diff computation).
80
- * - Default (library): 50
81
- */
82
- diffUpdateThrottleMs?: number;
83
- /**
84
- * When attempting the "minimal edit" algorithm, if prev.length + next.length
85
- * exceeds this number the library will fall back to full `setValue` to avoid
86
- * expensive diff computation on very large documents.
87
- */
88
- minimalEditMaxChars?: number;
89
- /**
90
- * When the relative change ratio (|new-prev|/maxLen) exceeds this value the
91
- * library will fall back to full `setValue` instead of attempting minimal edit.
92
- */
93
- minimalEditMaxChangeRatio?: number;
94
- onBeforeCreate?: (monaco: typeof monaco_editor0) => monaco$1.IDisposable[];
95
- /**
96
- * Optional callback that is invoked after a theme change has been applied.
97
- * This callback will be awaited when possible so callers can track completion
98
- * of theme application. It receives the name of the applied theme.
99
- */
100
- onThemeChange?: (theme: MonacoTheme) => void | Promise<void>;
101
- }
102
- declare enum RevealStrategy {
103
- Bottom = "bottom",
104
- CenterIfOutside = "centerIfOutside",
105
- Center = "center",
106
- }
107
- //#endregion
108
- //#region src/code.detect.d.ts
109
- /**
110
- * @module detect
111
- * (Language detector)
112
- */
113
- /**
114
- * Supported language identifiers
115
- */
116
- type CodeLanguage = 'bash' | 'html' | 'http' | 'js' | 'ts' | 'py' | 'sql' | 'pl' | 'lua' | 'make' | 'uri' | 'css' | 'diff' | 'md' | 'docker' | 'xml' | 'c' | 'rs' | 'go' | 'java' | 'asm' | 'json' | 'yaml' | 'toml' | 'mermaid' | 'plain';
117
- /**
118
- * Language detection feature with pattern and score
119
- */
120
- type LanguageFeature = [RegExp, number];
121
- /**
122
- * Language definition with identifier and detection features
123
- */
124
- type LanguageDefinition = [CodeLanguage, ...LanguageFeature[]];
125
- /**
126
- * Language detection definitions
127
- */
128
-
129
- /**
130
- * Try to find the language the given code belongs to
131
- *
132
- * @param {string} code The code to analyze
133
- * @param {LanguageDefinition[]} [additionalLanguages] Additional language definitions to supplement the built-in ones
134
- * @returns {CodeLanguage} The detected language of the code
135
- */
136
- declare function detectLanguage(code: string, additionalLanguages?: LanguageDefinition[]): CodeLanguage;
137
- //#endregion
138
- //#region src/constant.d.ts
139
- declare const defaultRevealDebounceMs = 75;
140
- declare namespace monaco_shim_d_exports {
141
- export { monaco as default };
142
- }
143
- import * as import_monaco_editor from "monaco-editor";
144
- __reExport(monaco_shim_d_exports, import_monaco_editor);
145
- declare const monaco: typeof _monaco;
146
- //#endregion
147
3
  //#region src/preloadMonacoWorkers.d.ts
148
4
  declare function preloadMonacoWorkers(): Promise<void>;
149
5
  //#endregion
150
- //#region src/utils/registerMonacoThemes.d.ts
151
- /**
152
- * Clear all cached shiki highlighters.
153
- *
154
- * Useful for long-running apps that dynamically create many theme combinations,
155
- * or in tests to ensure a clean state. Call this when you know the highlighters
156
- * are no longer needed (for example on app shutdown) to free memory.
157
- */
158
- declare function clearHighlighterCache(): void;
159
- /**
160
- * Return number of entries currently in the highlighter cache.
161
- * Helpful for tests and debugging.
162
- */
163
-
164
- declare function getOrCreateHighlighter(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter>;
165
- /**
166
- * Update the theme used by the shiki highlighter for a given themes+languages
167
- * combination. Useful when Monaco themes are already registered (so switching
168
- * Monaco only requires `monaco.editor.setTheme`) but you also want shiki's
169
- * standalone renderer to use the new theme without recreating everything.
170
- */
171
- declare function registerMonacoThemes(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter | null>;
172
- //#endregion
173
- //#region src/index.d.ts
174
- /**
175
- * useMonaco 组合式函数
176
- *
177
- * 提供 Monaco 编辑器的创建、销毁、内容/主题/语言更新等能力。
178
- * 支持主题自动切换、语言高亮、代码更新等功能。
179
- *
180
- * @param {MonacoOptions} [monacoOptions] - 编辑器初始化配置,支持 Monaco 原生配置及扩展项
181
- * @param {number | string} [monacoOptions.MAX_HEIGHT] - 编辑器最大高度,可以是数字(像素)或 CSS 字符串(如 '100%', 'calc(100vh - 100px)')
182
- * @param {boolean} [monacoOptions.readOnly] - 是否为只读模式
183
- * @param {MonacoTheme[]} [monacoOptions.themes] - 主题数组,至少包含两个主题:[暗色主题, 亮色主题]
184
- * @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
185
- * @param {string} [monacoOptions.theme] - 初始主题名称
186
- * @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
187
- * @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
188
- *
189
- * @returns {{
190
- * createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,
191
- * createDiffEditor: (
192
- * container: HTMLElement,
193
- * originalCode: string,
194
- * modifiedCode: string,
195
- * language: string,
196
- * ) => Promise<monaco.editor.IStandaloneDiffEditor>,
197
- * cleanupEditor: () => void,
198
- * updateCode: (newCode: string, codeLanguage: string) => void,
199
- * appendCode: (appendText: string, codeLanguage?: string) => void,
200
- * updateDiff: (
201
- * originalCode: string,
202
- * modifiedCode: string,
203
- * codeLanguage?: string,
204
- * ) => void,
205
- * updateOriginal: (newCode: string, codeLanguage?: string) => void,
206
- * updateModified: (newCode: string, codeLanguage?: string) => void,
207
- * appendOriginal: (appendText: string, codeLanguage?: string) => void,
208
- * appendModified: (appendText: string, codeLanguage?: string) => void,
209
- * setTheme: (theme: MonacoTheme) => Promise<void>,
210
- * setLanguage: (language: MonacoLanguage) => void,
211
- * getCurrentTheme: () => string,
212
- * getEditor: () => typeof monaco.editor,
213
- * getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
214
- * getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
215
- * getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
216
- * getCode: () => string | { original: string, modified: string } | null,
217
- * }} 返回对象包含以下方法和属性:
218
- *
219
- * @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
220
- * @property {Function} cleanupEditor - 销毁编辑器并清理容器
221
- * @property {Function} updateCode - 更新编辑器内容和语言,必要时滚动到底部
222
- * @property {Function} appendCode - 在编辑器末尾追加文本,必要时滚动到底部
223
- * @property {Function} createDiffEditor - 创建并挂载 Diff 编辑器
224
- * @property {Function} updateDiff - 更新 Diff 编辑器的 original/modified 内容(RAF 合并、增量更新)
225
- * @property {Function} updateOriginal - 仅更新 Diff 的 original 内容(增量更新)
226
- * @property {Function} updateModified - 仅更新 Diff 的 modified 内容(增量更新)
227
- * @property {Function} appendOriginal - 在 Diff 的 original 末尾追加(显式流式场景)
228
- * @property {Function} appendModified - 在 Diff 的 modified 末尾追加(显式流式场景)
229
- * @property {Function} setTheme - 切换编辑器主题,返回 Promise,在主题应用完成时 resolve
230
- * @property {Function} setLanguage - 切换编辑器语言
231
- * @property {Function} getCurrentTheme - 获取当前主题名称
232
- * @property {Function} getEditor - 获取 Monaco 的静态 editor 对象(用于静态方法调用)
233
- * @property {Function} getEditorView - 获取当前编辑器实例
234
- * @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
235
- * @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
236
- * @property {Function} getCode - 获取当前编辑器或 Diff 编辑器中的代码内容
237
- *
238
- * @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
239
- *
240
- * @example
241
- * ```typescript
242
- * import { useMonaco } from 'stream-monaco'
243
- *
244
- * const { createEditor, updateCode, setTheme } = useMonaco({
245
- * themes: ['vitesse-dark', 'vitesse-light'],
246
- * languages: ['javascript', 'typescript'],
247
- * readOnly: false
248
- * })
249
- *
250
- * // 创建编辑器
251
- * const editor = await createEditor(containerRef.value, 'console.log("hello")', 'javascript')
252
- *
253
- * // 更新代码
254
- * updateCode('console.log("world")', 'javascript')
255
- *
256
- * // 切换主题
257
- * setTheme('vitesse-light')
258
- * ```
259
- */
260
- declare function useMonaco(monacoOptions?: MonacoOptions): {
261
- createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneCodeEditor>;
262
- createDiffEditor: (container: HTMLElement, originalCode: string, modifiedCode: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneDiffEditor>;
263
- cleanupEditor: () => void;
264
- safeClean(): void;
265
- updateCode: (newCode: string, codeLanguage: string) => void;
266
- appendCode: (appendText: string, codeLanguage?: string) => void;
267
- updateDiff: (originalCode: string, modifiedCode: string, codeLanguage?: string) => void;
268
- updateOriginal: (newCode: string, codeLanguage?: string) => void;
269
- updateModified: (newCode: string, codeLanguage?: string) => void;
270
- appendOriginal: (appendText: string, codeLanguage?: string) => void;
271
- appendModified: (appendText: string, codeLanguage?: string) => void;
272
- setTheme: (theme: MonacoTheme, force?: boolean) => Promise<void>;
273
- setLanguage(language: MonacoLanguage): void;
274
- getCurrentTheme(): string;
275
- getEditor(): typeof monaco_shim_d_exports.editor;
276
- getEditorView(): monaco_shim_d_exports.editor.IStandaloneCodeEditor | null;
277
- getDiffEditorView(): monaco_shim_d_exports.editor.IStandaloneDiffEditor | null;
278
- getDiffModels(): {
279
- original: monaco_shim_d_exports.editor.ITextModel | null;
280
- modified: monaco_shim_d_exports.editor.ITextModel | null;
281
- };
282
- getMonacoInstance(): typeof monaco_shim_d_exports;
283
- setUpdateThrottleMs: (ms: number) => void;
284
- getUpdateThrottleMs: () => number;
285
- getCode(): string | {
286
- original: string;
287
- modified: string;
288
- } | null;
289
- };
6
+ //#region src/ensureMonacoWorkers.d.ts
7
+ declare function ensureMonacoWorkers(): void;
290
8
  //#endregion
291
- export { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, preloadMonacoWorkers, registerMonacoThemes, useMonaco };
9
+ export { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, ensureMonacoWorkers, getOrCreateHighlighter, preloadMonacoWorkers, registerMonacoThemes, useMonaco };