stream-monaco 0.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.
@@ -0,0 +1,282 @@
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";
5
+
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
+ * When attempting the "minimal edit" algorithm, if prev.length + next.length
74
+ * exceeds this number the library will fall back to full `setValue` to avoid
75
+ * expensive diff computation on very large documents.
76
+ */
77
+ minimalEditMaxChars?: number;
78
+ /**
79
+ * When the relative change ratio (|new-prev|/maxLen) exceeds this value the
80
+ * library will fall back to full `setValue` instead of attempting minimal edit.
81
+ */
82
+ minimalEditMaxChangeRatio?: number;
83
+ onBeforeCreate?: (monaco: typeof monaco_editor0) => monaco$1.IDisposable[];
84
+ /**
85
+ * Optional callback that is invoked after a theme change has been applied.
86
+ * This callback will be awaited when possible so callers can track completion
87
+ * of theme application. It receives the name of the applied theme.
88
+ */
89
+ onThemeChange?: (theme: MonacoTheme) => void | Promise<void>;
90
+ }
91
+ declare enum RevealStrategy {
92
+ Bottom = "bottom",
93
+ CenterIfOutside = "centerIfOutside",
94
+ Center = "center",
95
+ }
96
+ //#endregion
97
+ //#region src/code.detect.d.ts
98
+ /**
99
+ * @module detect
100
+ * (Language detector)
101
+ */
102
+ /**
103
+ * Supported language identifiers
104
+ */
105
+ 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';
106
+ /**
107
+ * Language detection feature with pattern and score
108
+ */
109
+ type LanguageFeature = [RegExp, number];
110
+ /**
111
+ * Language definition with identifier and detection features
112
+ */
113
+ type LanguageDefinition = [CodeLanguage, ...LanguageFeature[]];
114
+ /**
115
+ * Language detection definitions
116
+ */
117
+
118
+ /**
119
+ * Try to find the language the given code belongs to
120
+ *
121
+ * @param {string} code The code to analyze
122
+ * @param {LanguageDefinition[]} [additionalLanguages] Additional language definitions to supplement the built-in ones
123
+ * @returns {CodeLanguage} The detected language of the code
124
+ */
125
+ declare function detectLanguage(code: string, additionalLanguages?: LanguageDefinition[]): CodeLanguage;
126
+ //#endregion
127
+ //#region src/constant.d.ts
128
+ declare const defaultRevealDebounceMs = 75;
129
+ //#endregion
130
+ //#region src/reactivity.d.ts
131
+ interface Ref<T> {
132
+ value: T;
133
+ }
134
+ //#endregion
135
+ //#region src/isDark.d.ts
136
+ declare const isDark: Ref<boolean>;
137
+ declare namespace monaco_shim_d_exports {
138
+ export { monaco as default };
139
+ }
140
+ import * as import_monaco_editor from "monaco-editor";
141
+ __reExport(monaco_shim_d_exports, import_monaco_editor);
142
+ declare const monaco: typeof _monaco;
143
+ //#endregion
144
+ //#region src/preloadMonacoWorkers.d.ts
145
+ declare function preloadMonacoWorkers(): Promise<void>;
146
+ //#endregion
147
+ //#region src/utils/registerMonacoThemes.d.ts
148
+ /**
149
+ * Clear all cached shiki highlighters.
150
+ *
151
+ * Useful for long-running apps that dynamically create many theme combinations,
152
+ * or in tests to ensure a clean state. Call this when you know the highlighters
153
+ * are no longer needed (for example on app shutdown) to free memory.
154
+ */
155
+ declare function clearHighlighterCache(): void;
156
+ /**
157
+ * Return number of entries currently in the highlighter cache.
158
+ * Helpful for tests and debugging.
159
+ */
160
+
161
+ declare function getOrCreateHighlighter(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter>;
162
+ /**
163
+ * Update the theme used by the shiki highlighter for a given themes+languages
164
+ * combination. Useful when Monaco themes are already registered (so switching
165
+ * Monaco only requires `monaco.editor.setTheme`) but you also want shiki's
166
+ * standalone renderer to use the new theme without recreating everything.
167
+ */
168
+ declare function registerMonacoThemes(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter | null>;
169
+ //#endregion
170
+ //#region src/index.d.ts
171
+ /**
172
+ * useMonaco 组合式函数
173
+ *
174
+ * 提供 Monaco 编辑器的创建、销毁、内容/主题/语言更新等能力。
175
+ * 支持主题自动切换、语言高亮、代码更新等功能。
176
+ *
177
+ * @param {MonacoOptions} [monacoOptions] - 编辑器初始化配置,支持 Monaco 原生配置及扩展项
178
+ * @param {number | string} [monacoOptions.MAX_HEIGHT] - 编辑器最大高度,可以是数字(像素)或 CSS 字符串(如 '100%', 'calc(100vh - 100px)')
179
+ * @param {boolean} [monacoOptions.readOnly] - 是否为只读模式
180
+ * @param {MonacoTheme[]} [monacoOptions.themes] - 主题数组,至少包含两个主题:[暗色主题, 亮色主题]
181
+ * @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
182
+ * @param {string} [monacoOptions.theme] - 初始主题名称
183
+ * @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
184
+ * @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
185
+ *
186
+ * @returns {{
187
+ * createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,
188
+ * createDiffEditor: (
189
+ * container: HTMLElement,
190
+ * originalCode: string,
191
+ * modifiedCode: string,
192
+ * language: string,
193
+ * ) => Promise<monaco.editor.IStandaloneDiffEditor>,
194
+ * cleanupEditor: () => void,
195
+ * updateCode: (newCode: string, codeLanguage: string) => void,
196
+ * appendCode: (appendText: string, codeLanguage?: string) => void,
197
+ * updateDiff: (
198
+ * originalCode: string,
199
+ * modifiedCode: string,
200
+ * codeLanguage?: string,
201
+ * ) => void,
202
+ * updateOriginal: (newCode: string, codeLanguage?: string) => void,
203
+ * updateModified: (newCode: string, codeLanguage?: string) => void,
204
+ * appendOriginal: (appendText: string, codeLanguage?: string) => void,
205
+ * appendModified: (appendText: string, codeLanguage?: string) => void,
206
+ * setTheme: (theme: MonacoTheme) => Promise<void>,
207
+ * setLanguage: (language: MonacoLanguage) => void,
208
+ * getCurrentTheme: () => string,
209
+ * getEditor: () => typeof monaco.editor,
210
+ * getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
211
+ * getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
212
+ * getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
213
+ * }} 返回对象包含以下方法和属性:
214
+ *
215
+ * @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
216
+ * @property {Function} cleanupEditor - 销毁编辑器并清理容器
217
+ * @property {Function} updateCode - 更新编辑器内容和语言,必要时滚动到底部
218
+ * @property {Function} appendCode - 在编辑器末尾追加文本,必要时滚动到底部
219
+ * @property {Function} createDiffEditor - 创建并挂载 Diff 编辑器
220
+ * @property {Function} updateDiff - 更新 Diff 编辑器的 original/modified 内容(RAF 合并、增量更新)
221
+ * @property {Function} updateOriginal - 仅更新 Diff 的 original 内容(增量更新)
222
+ * @property {Function} updateModified - 仅更新 Diff 的 modified 内容(增量更新)
223
+ * @property {Function} appendOriginal - 在 Diff 的 original 末尾追加(显式流式场景)
224
+ * @property {Function} appendModified - 在 Diff 的 modified 末尾追加(显式流式场景)
225
+ * @property {Function} setTheme - 切换编辑器主题,返回 Promise,在主题应用完成时 resolve
226
+ * @property {Function} setLanguage - 切换编辑器语言
227
+ * @property {Function} getCurrentTheme - 获取当前主题名称
228
+ * @property {Function} getEditor - 获取 Monaco 的静态 editor 对象(用于静态方法调用)
229
+ * @property {Function} getEditorView - 获取当前编辑器实例
230
+ * @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
231
+ * @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
232
+ *
233
+ * @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * import { useMonaco } from 'stream-monaco'
238
+ *
239
+ * const { createEditor, updateCode, setTheme } = useMonaco({
240
+ * themes: ['vitesse-dark', 'vitesse-light'],
241
+ * languages: ['javascript', 'typescript'],
242
+ * readOnly: false
243
+ * })
244
+ *
245
+ * // 创建编辑器
246
+ * const editor = await createEditor(containerRef.value, 'console.log("hello")', 'javascript')
247
+ *
248
+ * // 更新代码
249
+ * updateCode('console.log("world")', 'javascript')
250
+ *
251
+ * // 切换主题
252
+ * setTheme('vitesse-light')
253
+ * ```
254
+ */
255
+ declare function useMonaco(monacoOptions?: MonacoOptions): {
256
+ createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneCodeEditor>;
257
+ createDiffEditor: (container: HTMLElement, originalCode: string, modifiedCode: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneDiffEditor>;
258
+ cleanupEditor: () => void;
259
+ safeClean(): void;
260
+ updateCode: (newCode: string, codeLanguage: string) => void;
261
+ appendCode: (appendText: string, codeLanguage?: string) => void;
262
+ updateDiff: (originalCode: string, modifiedCode: string, codeLanguage?: string) => void;
263
+ updateOriginal: (newCode: string, codeLanguage?: string) => void;
264
+ updateModified: (newCode: string, codeLanguage?: string) => void;
265
+ appendOriginal: (appendText: string, codeLanguage?: string) => void;
266
+ appendModified: (appendText: string, codeLanguage?: string) => void;
267
+ setTheme: (theme: MonacoTheme, force?: boolean) => Promise<void>;
268
+ setLanguage(language: MonacoLanguage): void;
269
+ getCurrentTheme(): string;
270
+ getEditor(): typeof monaco_shim_d_exports.editor;
271
+ getEditorView(): monaco_shim_d_exports.editor.IStandaloneCodeEditor | null;
272
+ getDiffEditorView(): monaco_shim_d_exports.editor.IStandaloneDiffEditor | null;
273
+ getDiffModels(): {
274
+ original: monaco_shim_d_exports.editor.ITextModel | null;
275
+ modified: monaco_shim_d_exports.editor.ITextModel | null;
276
+ };
277
+ getMonacoInstance(): typeof monaco_shim_d_exports;
278
+ setUpdateThrottleMs: (ms: number) => void;
279
+ getUpdateThrottleMs: () => number;
280
+ };
281
+ //#endregion
282
+ export { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, isDark, preloadMonacoWorkers, registerMonacoThemes, useMonaco };
@@ -0,0 +1,281 @@
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";
6
+
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
+ * When attempting the "minimal edit" algorithm, if prev.length + next.length
73
+ * exceeds this number the library will fall back to full `setValue` to avoid
74
+ * expensive diff computation on very large documents.
75
+ */
76
+ minimalEditMaxChars?: number;
77
+ /**
78
+ * When the relative change ratio (|new-prev|/maxLen) exceeds this value the
79
+ * library will fall back to full `setValue` instead of attempting minimal edit.
80
+ */
81
+ minimalEditMaxChangeRatio?: number;
82
+ onBeforeCreate?: (monaco: typeof monaco_editor0) => monaco$1.IDisposable[];
83
+ /**
84
+ * Optional callback that is invoked after a theme change has been applied.
85
+ * This callback will be awaited when possible so callers can track completion
86
+ * of theme application. It receives the name of the applied theme.
87
+ */
88
+ onThemeChange?: (theme: MonacoTheme) => void | Promise<void>;
89
+ }
90
+ declare enum RevealStrategy {
91
+ Bottom = "bottom",
92
+ CenterIfOutside = "centerIfOutside",
93
+ Center = "center",
94
+ }
95
+ //#endregion
96
+ //#region src/code.detect.d.ts
97
+ /**
98
+ * @module detect
99
+ * (Language detector)
100
+ */
101
+ /**
102
+ * Supported language identifiers
103
+ */
104
+ 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';
105
+ /**
106
+ * Language detection feature with pattern and score
107
+ */
108
+ type LanguageFeature = [RegExp, number];
109
+ /**
110
+ * Language definition with identifier and detection features
111
+ */
112
+ type LanguageDefinition = [CodeLanguage, ...LanguageFeature[]];
113
+ /**
114
+ * Language detection definitions
115
+ */
116
+
117
+ /**
118
+ * Try to find the language the given code belongs to
119
+ *
120
+ * @param {string} code The code to analyze
121
+ * @param {LanguageDefinition[]} [additionalLanguages] Additional language definitions to supplement the built-in ones
122
+ * @returns {CodeLanguage} The detected language of the code
123
+ */
124
+ declare function detectLanguage(code: string, additionalLanguages?: LanguageDefinition[]): CodeLanguage;
125
+ //#endregion
126
+ //#region src/constant.d.ts
127
+ declare const defaultRevealDebounceMs = 75;
128
+ //#endregion
129
+ //#region src/reactivity.d.ts
130
+ interface Ref<T> {
131
+ value: T;
132
+ }
133
+ //#endregion
134
+ //#region src/isDark.d.ts
135
+ declare const isDark: Ref<boolean>;
136
+ declare namespace monaco_shim_d_exports {
137
+ export { monaco as default };
138
+ }
139
+ import * as import_monaco_editor from "monaco-editor";
140
+ __reExport(monaco_shim_d_exports, import_monaco_editor);
141
+ declare const monaco: typeof _monaco;
142
+ //#endregion
143
+ //#region src/preloadMonacoWorkers.d.ts
144
+ declare function preloadMonacoWorkers(): Promise<void>;
145
+ //#endregion
146
+ //#region src/utils/registerMonacoThemes.d.ts
147
+ /**
148
+ * Clear all cached shiki highlighters.
149
+ *
150
+ * Useful for long-running apps that dynamically create many theme combinations,
151
+ * or in tests to ensure a clean state. Call this when you know the highlighters
152
+ * are no longer needed (for example on app shutdown) to free memory.
153
+ */
154
+ declare function clearHighlighterCache(): void;
155
+ /**
156
+ * Return number of entries currently in the highlighter cache.
157
+ * Helpful for tests and debugging.
158
+ */
159
+
160
+ declare function getOrCreateHighlighter(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter>;
161
+ /**
162
+ * Update the theme used by the shiki highlighter for a given themes+languages
163
+ * combination. Useful when Monaco themes are already registered (so switching
164
+ * Monaco only requires `monaco.editor.setTheme`) but you also want shiki's
165
+ * standalone renderer to use the new theme without recreating everything.
166
+ */
167
+ declare function registerMonacoThemes(themes: (ThemeInput | string | SpecialTheme)[], languages: string[]): Promise<ShikiHighlighter | null>;
168
+ //#endregion
169
+ //#region src/index.d.ts
170
+ /**
171
+ * useMonaco 组合式函数
172
+ *
173
+ * 提供 Monaco 编辑器的创建、销毁、内容/主题/语言更新等能力。
174
+ * 支持主题自动切换、语言高亮、代码更新等功能。
175
+ *
176
+ * @param {MonacoOptions} [monacoOptions] - 编辑器初始化配置,支持 Monaco 原生配置及扩展项
177
+ * @param {number | string} [monacoOptions.MAX_HEIGHT] - 编辑器最大高度,可以是数字(像素)或 CSS 字符串(如 '100%', 'calc(100vh - 100px)')
178
+ * @param {boolean} [monacoOptions.readOnly] - 是否为只读模式
179
+ * @param {MonacoTheme[]} [monacoOptions.themes] - 主题数组,至少包含两个主题:[暗色主题, 亮色主题]
180
+ * @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
181
+ * @param {string} [monacoOptions.theme] - 初始主题名称
182
+ * @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
183
+ * @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
184
+ *
185
+ * @returns {{
186
+ * createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,
187
+ * createDiffEditor: (
188
+ * container: HTMLElement,
189
+ * originalCode: string,
190
+ * modifiedCode: string,
191
+ * language: string,
192
+ * ) => Promise<monaco.editor.IStandaloneDiffEditor>,
193
+ * cleanupEditor: () => void,
194
+ * updateCode: (newCode: string, codeLanguage: string) => void,
195
+ * appendCode: (appendText: string, codeLanguage?: string) => void,
196
+ * updateDiff: (
197
+ * originalCode: string,
198
+ * modifiedCode: string,
199
+ * codeLanguage?: string,
200
+ * ) => void,
201
+ * updateOriginal: (newCode: string, codeLanguage?: string) => void,
202
+ * updateModified: (newCode: string, codeLanguage?: string) => void,
203
+ * appendOriginal: (appendText: string, codeLanguage?: string) => void,
204
+ * appendModified: (appendText: string, codeLanguage?: string) => void,
205
+ * setTheme: (theme: MonacoTheme) => Promise<void>,
206
+ * setLanguage: (language: MonacoLanguage) => void,
207
+ * getCurrentTheme: () => string,
208
+ * getEditor: () => typeof monaco.editor,
209
+ * getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
210
+ * getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
211
+ * getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
212
+ * }} 返回对象包含以下方法和属性:
213
+ *
214
+ * @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
215
+ * @property {Function} cleanupEditor - 销毁编辑器并清理容器
216
+ * @property {Function} updateCode - 更新编辑器内容和语言,必要时滚动到底部
217
+ * @property {Function} appendCode - 在编辑器末尾追加文本,必要时滚动到底部
218
+ * @property {Function} createDiffEditor - 创建并挂载 Diff 编辑器
219
+ * @property {Function} updateDiff - 更新 Diff 编辑器的 original/modified 内容(RAF 合并、增量更新)
220
+ * @property {Function} updateOriginal - 仅更新 Diff 的 original 内容(增量更新)
221
+ * @property {Function} updateModified - 仅更新 Diff 的 modified 内容(增量更新)
222
+ * @property {Function} appendOriginal - 在 Diff 的 original 末尾追加(显式流式场景)
223
+ * @property {Function} appendModified - 在 Diff 的 modified 末尾追加(显式流式场景)
224
+ * @property {Function} setTheme - 切换编辑器主题,返回 Promise,在主题应用完成时 resolve
225
+ * @property {Function} setLanguage - 切换编辑器语言
226
+ * @property {Function} getCurrentTheme - 获取当前主题名称
227
+ * @property {Function} getEditor - 获取 Monaco 的静态 editor 对象(用于静态方法调用)
228
+ * @property {Function} getEditorView - 获取当前编辑器实例
229
+ * @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
230
+ * @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
231
+ *
232
+ * @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * import { useMonaco } from 'stream-monaco'
237
+ *
238
+ * const { createEditor, updateCode, setTheme } = useMonaco({
239
+ * themes: ['vitesse-dark', 'vitesse-light'],
240
+ * languages: ['javascript', 'typescript'],
241
+ * readOnly: false
242
+ * })
243
+ *
244
+ * // 创建编辑器
245
+ * const editor = await createEditor(containerRef.value, 'console.log("hello")', 'javascript')
246
+ *
247
+ * // 更新代码
248
+ * updateCode('console.log("world")', 'javascript')
249
+ *
250
+ * // 切换主题
251
+ * setTheme('vitesse-light')
252
+ * ```
253
+ */
254
+ declare function useMonaco(monacoOptions?: MonacoOptions): {
255
+ createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneCodeEditor>;
256
+ createDiffEditor: (container: HTMLElement, originalCode: string, modifiedCode: string, language: string) => Promise<monaco_shim_d_exports.editor.IStandaloneDiffEditor>;
257
+ cleanupEditor: () => void;
258
+ safeClean(): void;
259
+ updateCode: (newCode: string, codeLanguage: string) => void;
260
+ appendCode: (appendText: string, codeLanguage?: string) => void;
261
+ updateDiff: (originalCode: string, modifiedCode: string, codeLanguage?: string) => void;
262
+ updateOriginal: (newCode: string, codeLanguage?: string) => void;
263
+ updateModified: (newCode: string, codeLanguage?: string) => void;
264
+ appendOriginal: (appendText: string, codeLanguage?: string) => void;
265
+ appendModified: (appendText: string, codeLanguage?: string) => void;
266
+ setTheme: (theme: MonacoTheme, force?: boolean) => Promise<void>;
267
+ setLanguage(language: MonacoLanguage): void;
268
+ getCurrentTheme(): string;
269
+ getEditor(): typeof monaco_shim_d_exports.editor;
270
+ getEditorView(): monaco_shim_d_exports.editor.IStandaloneCodeEditor | null;
271
+ getDiffEditorView(): monaco_shim_d_exports.editor.IStandaloneDiffEditor | null;
272
+ getDiffModels(): {
273
+ original: monaco_shim_d_exports.editor.ITextModel | null;
274
+ modified: monaco_shim_d_exports.editor.ITextModel | null;
275
+ };
276
+ getMonacoInstance(): typeof monaco_shim_d_exports;
277
+ setUpdateThrottleMs: (ms: number) => void;
278
+ getUpdateThrottleMs: () => number;
279
+ };
280
+ //#endregion
281
+ export { MonacoDiffEditorInstance, MonacoEditorInstance, MonacoLanguage, MonacoOptions, MonacoTheme, RevealStrategy, ShikiHighlighter, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, getOrCreateHighlighter, isDark, preloadMonacoWorkers, registerMonacoThemes, useMonaco };