UNPKG

vue-renderer-markdown-monaco

Version:

A Vue 3 component that renders Markdown string content as HTML, supporting custom components and advanced markdown features.

959 lines (955 loc) 32.1 kB
var K = Object.defineProperty, E = Object.defineProperties; var H = Object.getOwnPropertyDescriptors; var P = Object.getOwnPropertySymbols; var V = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable; var L = (e, t, s) => t in e ? K(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, O = (e, t) => { for (var s in t || (t = {})) V.call(t, s) && L(e, s, t[s]); if (P) for (var s of P(t)) W.call(t, s) && L(e, s, t[s]); return e; }, I = (e, t) => E(e, H(t)); var b = (e, t, s) => new Promise((o, n) => { var c = (l) => { try { r(s.next(l)); } catch (g) { n(g); } }, u = (l) => { try { r(s.throw(l)); } catch (g) { n(g); } }, r = (l) => l.done ? o(l.value) : Promise.resolve(l.value).then(c, u); r((s = s.apply(e, t)).next()); }); import { t as j, m as B } from "./exports-BXFrEqsi.js"; /*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1) * Released under the MIT license * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt *-----------------------------------------------------------------------------*/ var U = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, z = Object.getOwnPropertyNames, G = Object.prototype.hasOwnProperty, J = (e, t, s, o) => { if (t && typeof t == "object" || typeof t == "function") for (let n of z(t)) !G.call(e, n) && n !== s && U(e, n, { get: () => t[n], enumerable: !(o = $(t, n)) || o.enumerable }); return e; }, Q = (e, t, s) => (J(e, t, "default"), s), a = {}; Q(a, B); var q = class { constructor(e, t) { this._modeId = e, this._defaults = t, this._worker = null, this._client = null, this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker()), this._updateExtraLibsToken = 0, this._extraLibsChangeListener = this._defaults.onDidExtraLibsChange( () => this._updateExtraLibs() ); } dispose() { this._configChangeListener.dispose(), this._extraLibsChangeListener.dispose(), this._stopWorker(); } _stopWorker() { this._worker && (this._worker.dispose(), this._worker = null), this._client = null; } _updateExtraLibs() { return b(this, null, function* () { if (!this._worker) return; const e = ++this._updateExtraLibsToken, t = yield this._worker.getProxy(); this._updateExtraLibsToken === e && t.updateExtraLibs(this._defaults.getExtraLibs()); }); } _getClient() { return this._client || (this._client = b(this, null, function* () { return this._worker = a.editor.createWebWorker({ // module that exports the create() method and returns a `TypeScriptWorker` instance moduleId: "vs/language/typescript/tsWorker", label: this._modeId, keepIdleModels: !0, // passed in to the create() method createData: { compilerOptions: this._defaults.getCompilerOptions(), extraLibs: this._defaults.getExtraLibs(), customWorkerPath: this._defaults.workerOptions.customWorkerPath, inlayHintsOptions: this._defaults.inlayHintsOptions } }), this._defaults.getEagerModelSync() ? yield this._worker.withSyncedResources( a.editor.getModels().filter((e) => e.getLanguageId() === this._modeId).map((e) => e.uri) ) : yield this._worker.getProxy(); })), this._client; } getLanguageServiceWorker(...e) { return b(this, null, function* () { const t = yield this._getClient(); return this._worker && (yield this._worker.withSyncedResources(e)), t; }); } }, i = {}; i["lib.d.ts"] = !0; i["lib.decorators.d.ts"] = !0; i["lib.decorators.legacy.d.ts"] = !0; i["lib.dom.asynciterable.d.ts"] = !0; i["lib.dom.d.ts"] = !0; i["lib.dom.iterable.d.ts"] = !0; i["lib.es2015.collection.d.ts"] = !0; i["lib.es2015.core.d.ts"] = !0; i["lib.es2015.d.ts"] = !0; i["lib.es2015.generator.d.ts"] = !0; i["lib.es2015.iterable.d.ts"] = !0; i["lib.es2015.promise.d.ts"] = !0; i["lib.es2015.proxy.d.ts"] = !0; i["lib.es2015.reflect.d.ts"] = !0; i["lib.es2015.symbol.d.ts"] = !0; i["lib.es2015.symbol.wellknown.d.ts"] = !0; i["lib.es2016.array.include.d.ts"] = !0; i["lib.es2016.d.ts"] = !0; i["lib.es2016.full.d.ts"] = !0; i["lib.es2016.intl.d.ts"] = !0; i["lib.es2017.d.ts"] = !0; i["lib.es2017.date.d.ts"] = !0; i["lib.es2017.full.d.ts"] = !0; i["lib.es2017.intl.d.ts"] = !0; i["lib.es2017.object.d.ts"] = !0; i["lib.es2017.sharedmemory.d.ts"] = !0; i["lib.es2017.string.d.ts"] = !0; i["lib.es2017.typedarrays.d.ts"] = !0; i["lib.es2018.asyncgenerator.d.ts"] = !0; i["lib.es2018.asynciterable.d.ts"] = !0; i["lib.es2018.d.ts"] = !0; i["lib.es2018.full.d.ts"] = !0; i["lib.es2018.intl.d.ts"] = !0; i["lib.es2018.promise.d.ts"] = !0; i["lib.es2018.regexp.d.ts"] = !0; i["lib.es2019.array.d.ts"] = !0; i["lib.es2019.d.ts"] = !0; i["lib.es2019.full.d.ts"] = !0; i["lib.es2019.intl.d.ts"] = !0; i["lib.es2019.object.d.ts"] = !0; i["lib.es2019.string.d.ts"] = !0; i["lib.es2019.symbol.d.ts"] = !0; i["lib.es2020.bigint.d.ts"] = !0; i["lib.es2020.d.ts"] = !0; i["lib.es2020.date.d.ts"] = !0; i["lib.es2020.full.d.ts"] = !0; i["lib.es2020.intl.d.ts"] = !0; i["lib.es2020.number.d.ts"] = !0; i["lib.es2020.promise.d.ts"] = !0; i["lib.es2020.sharedmemory.d.ts"] = !0; i["lib.es2020.string.d.ts"] = !0; i["lib.es2020.symbol.wellknown.d.ts"] = !0; i["lib.es2021.d.ts"] = !0; i["lib.es2021.full.d.ts"] = !0; i["lib.es2021.intl.d.ts"] = !0; i["lib.es2021.promise.d.ts"] = !0; i["lib.es2021.string.d.ts"] = !0; i["lib.es2021.weakref.d.ts"] = !0; i["lib.es2022.array.d.ts"] = !0; i["lib.es2022.d.ts"] = !0; i["lib.es2022.error.d.ts"] = !0; i["lib.es2022.full.d.ts"] = !0; i["lib.es2022.intl.d.ts"] = !0; i["lib.es2022.object.d.ts"] = !0; i["lib.es2022.regexp.d.ts"] = !0; i["lib.es2022.sharedmemory.d.ts"] = !0; i["lib.es2022.string.d.ts"] = !0; i["lib.es2023.array.d.ts"] = !0; i["lib.es2023.collection.d.ts"] = !0; i["lib.es2023.d.ts"] = !0; i["lib.es2023.full.d.ts"] = !0; i["lib.es5.d.ts"] = !0; i["lib.es6.d.ts"] = !0; i["lib.esnext.collection.d.ts"] = !0; i["lib.esnext.d.ts"] = !0; i["lib.esnext.decorators.d.ts"] = !0; i["lib.esnext.disposable.d.ts"] = !0; i["lib.esnext.full.d.ts"] = !0; i["lib.esnext.intl.d.ts"] = !0; i["lib.esnext.object.d.ts"] = !0; i["lib.esnext.promise.d.ts"] = !0; i["lib.scripthost.d.ts"] = !0; i["lib.webworker.asynciterable.d.ts"] = !0; i["lib.webworker.d.ts"] = !0; i["lib.webworker.importscripts.d.ts"] = !0; i["lib.webworker.iterable.d.ts"] = !0; function A(e, t, s = 0) { if (typeof e == "string") return e; if (e === void 0) return ""; let o = ""; if (s) { o += t; for (let n = 0; n < s; n++) o += " "; } if (o += e.messageText, s++, e.next) for (const n of e.next) o += A(n, t, s); return o; } function y(e) { return e ? e.map((t) => t.text).join("") : ""; } var w = class { constructor(e) { this._worker = e; } // protected _positionToOffset(model: editor.ITextModel, position: monaco.IPosition): number { // return model.getOffsetAt(position); // } // protected _offsetToPosition(model: editor.ITextModel, offset: number): monaco.IPosition { // return model.getPositionAt(offset); // } _textSpanToRange(e, t) { let s = e.getPositionAt(t.start), o = e.getPositionAt(t.start + t.length), { lineNumber: n, column: c } = s, { lineNumber: u, column: r } = o; return { startLineNumber: n, startColumn: c, endLineNumber: u, endColumn: r }; } }, X = class { constructor(e) { this._worker = e, this._libFiles = {}, this._hasFetchedLibFiles = !1, this._fetchLibFilesPromise = null; } isLibFile(e) { return e && e.path.indexOf("/lib.") === 0 ? !!i[e.path.slice(1)] : !1; } getOrCreateModel(e) { const t = a.Uri.parse(e), s = a.editor.getModel(t); if (s) return s; if (this.isLibFile(t) && this._hasFetchedLibFiles) return a.editor.createModel(this._libFiles[t.path.slice(1)], "typescript", t); const o = j.getExtraLibs()[e]; return o ? a.editor.createModel(o.content, "typescript", t) : null; } _containsLibFile(e) { for (let t of e) if (this.isLibFile(t)) return !0; return !1; } fetchLibFilesIfNecessary(e) { return b(this, null, function* () { this._containsLibFile(e) && (yield this._fetchLibFiles()); }); } _fetchLibFiles() { return this._fetchLibFilesPromise || (this._fetchLibFilesPromise = this._worker().then((e) => e.getLibFiles()).then((e) => { this._hasFetchedLibFiles = !0, this._libFiles = e; })), this._fetchLibFilesPromise; } }, Y = class extends w { constructor(e, t, s, o) { super(o), this._libFiles = e, this._defaults = t, this._selector = s, this._disposables = [], this._listener = /* @__PURE__ */ Object.create(null); const n = (r) => { if (r.getLanguageId() !== s) return; const l = () => { const { onlyVisible: h } = this._defaults.getDiagnosticsOptions(); h ? r.isAttachedToEditor() && this._doValidate(r) : this._doValidate(r); }; let g; const d = r.onDidChangeContent(() => { clearTimeout(g), g = window.setTimeout(l, 500); }), m = r.onDidChangeAttached(() => { const { onlyVisible: h } = this._defaults.getDiagnosticsOptions(); h && (r.isAttachedToEditor() ? l() : a.editor.setModelMarkers(r, this._selector, [])); }); this._listener[r.uri.toString()] = { dispose() { d.dispose(), m.dispose(), clearTimeout(g); } }, l(); }, c = (r) => { a.editor.setModelMarkers(r, this._selector, []); const l = r.uri.toString(); this._listener[l] && (this._listener[l].dispose(), delete this._listener[l]); }; this._disposables.push( a.editor.onDidCreateModel((r) => n(r)) ), this._disposables.push(a.editor.onWillDisposeModel(c)), this._disposables.push( a.editor.onDidChangeModelLanguage((r) => { c(r.model), n(r.model); }) ), this._disposables.push({ dispose() { for (const r of a.editor.getModels()) c(r); } }); const u = () => { for (const r of a.editor.getModels()) c(r), n(r); }; this._disposables.push(this._defaults.onDidChange(u)), this._disposables.push(this._defaults.onDidExtraLibsChange(u)), a.editor.getModels().forEach((r) => n(r)); } dispose() { this._disposables.forEach((e) => e && e.dispose()), this._disposables = []; } _doValidate(e) { return b(this, null, function* () { const t = yield this._worker(e.uri); if (e.isDisposed()) return; const s = [], { noSyntaxValidation: o, noSemanticValidation: n, noSuggestionDiagnostics: c } = this._defaults.getDiagnosticsOptions(); o || s.push(t.getSyntacticDiagnostics(e.uri.toString())), n || s.push(t.getSemanticDiagnostics(e.uri.toString())), c || s.push(t.getSuggestionDiagnostics(e.uri.toString())); const u = yield Promise.all(s); if (!u || e.isDisposed()) return; const r = u.reduce((g, d) => d.concat(g), []).filter( (g) => (this._defaults.getDiagnosticsOptions().diagnosticCodesToIgnore || []).indexOf(g.code) === -1 ), l = r.map((g) => g.relatedInformation || []).reduce((g, d) => d.concat(g), []).map( (g) => g.file ? a.Uri.parse(g.file.fileName) : null ); yield this._libFiles.fetchLibFilesIfNecessary(l), !e.isDisposed() && a.editor.setModelMarkers( e, this._selector, r.map((g) => this._convertDiagnostics(e, g)) ); }); } _convertDiagnostics(e, t) { const s = t.start || 0, o = t.length || 1, { lineNumber: n, column: c } = e.getPositionAt(s), { lineNumber: u, column: r } = e.getPositionAt( s + o ), l = []; return t.reportsUnnecessary && l.push(a.MarkerTag.Unnecessary), t.reportsDeprecated && l.push(a.MarkerTag.Deprecated), { severity: this._tsDiagnosticCategoryToMarkerSeverity(t.category), startLineNumber: n, startColumn: c, endLineNumber: u, endColumn: r, message: A(t.messageText, ` `), code: t.code.toString(), tags: l, relatedInformation: this._convertRelatedInformation(e, t.relatedInformation) }; } _convertRelatedInformation(e, t) { if (!t) return []; const s = []; return t.forEach((o) => { let n = e; if (o.file && (n = this._libFiles.getOrCreateModel(o.file.fileName)), !n) return; const c = o.start || 0, u = o.length || 1, { lineNumber: r, column: l } = n.getPositionAt(c), { lineNumber: g, column: d } = n.getPositionAt( c + u ); s.push({ resource: n.uri, startLineNumber: r, startColumn: l, endLineNumber: g, endColumn: d, message: A(o.messageText, ` `) }); }), s; } _tsDiagnosticCategoryToMarkerSeverity(e) { switch (e) { case 1: return a.MarkerSeverity.Error; case 3: return a.MarkerSeverity.Info; case 0: return a.MarkerSeverity.Warning; case 2: return a.MarkerSeverity.Hint; } return a.MarkerSeverity.Info; } }, Z = class D extends w { get triggerCharacters() { return ["."]; } provideCompletionItems(t, s, o, n) { return b(this, null, function* () { const c = t.getWordUntilPosition(s), u = new a.Range( s.lineNumber, c.startColumn, s.lineNumber, c.endColumn ), r = t.uri, l = t.getOffsetAt(s), g = yield this._worker(r); if (t.isDisposed()) return; const d = yield g.getCompletionsAtPosition(r.toString(), l); return !d || t.isDisposed() ? void 0 : { suggestions: d.entries.map((h) => { let k = u; if (h.replacementSpan) { const v = t.getPositionAt(h.replacementSpan.start), C = t.getPositionAt(h.replacementSpan.start + h.replacementSpan.length); k = new a.Range(v.lineNumber, v.column, C.lineNumber, C.column); } const x = []; return h.kindModifiers !== void 0 && h.kindModifiers.indexOf("deprecated") !== -1 && x.push(a.languages.CompletionItemTag.Deprecated), { uri: r, position: s, offset: l, range: k, label: h.name, insertText: h.name, sortText: h.sortText, kind: D.convertKind(h.kind), tags: x }; }) }; }); } resolveCompletionItem(t, s) { return b(this, null, function* () { const o = t, n = o.uri, c = o.position, u = o.offset, l = yield (yield this._worker(n)).getCompletionEntryDetails( n.toString(), u, o.label ); return l ? { uri: n, position: c, label: l.name, kind: D.convertKind(l.kind), detail: y(l.displayParts), documentation: { value: D.createDocumentationString(l) } } : o; }); } static convertKind(t) { switch (t) { case f.primitiveType: case f.keyword: return a.languages.CompletionItemKind.Keyword; case f.variable: case f.localVariable: return a.languages.CompletionItemKind.Variable; case f.memberVariable: case f.memberGetAccessor: case f.memberSetAccessor: return a.languages.CompletionItemKind.Field; case f.function: case f.memberFunction: case f.constructSignature: case f.callSignature: case f.indexSignature: return a.languages.CompletionItemKind.Function; case f.enum: return a.languages.CompletionItemKind.Enum; case f.module: return a.languages.CompletionItemKind.Module; case f.class: return a.languages.CompletionItemKind.Class; case f.interface: return a.languages.CompletionItemKind.Interface; case f.warning: return a.languages.CompletionItemKind.File; } return a.languages.CompletionItemKind.Property; } static createDocumentationString(t) { let s = y(t.documentation); if (t.tags) for (const o of t.tags) s += ` ${N(o)}`; return s; } }; function N(e) { let t = `*@${e.name}*`; if (e.name === "param" && e.text) { const [s, ...o] = e.text; t += `\`${s.text}\``, o.length > 0 && (t += ` — ${o.map((n) => n.text).join(" ")}`); } else Array.isArray(e.text) ? t += ` — ${e.text.map((s) => s.text).join(" ")}` : e.text && (t += ` — ${e.text}`); return t; } var ee = class M extends w { constructor() { super(...arguments), this.signatureHelpTriggerCharacters = ["(", ","]; } static _toSignatureHelpTriggerReason(t) { switch (t.triggerKind) { case a.languages.SignatureHelpTriggerKind.TriggerCharacter: return t.triggerCharacter ? t.isRetrigger ? { kind: "retrigger", triggerCharacter: t.triggerCharacter } : { kind: "characterTyped", triggerCharacter: t.triggerCharacter } : { kind: "invoked" }; case a.languages.SignatureHelpTriggerKind.ContentChange: return t.isRetrigger ? { kind: "retrigger" } : { kind: "invoked" }; case a.languages.SignatureHelpTriggerKind.Invoke: default: return { kind: "invoked" }; } } provideSignatureHelp(t, s, o, n) { return b(this, null, function* () { const c = t.uri, u = t.getOffsetAt(s), r = yield this._worker(c); if (t.isDisposed()) return; const l = yield r.getSignatureHelpItems(c.toString(), u, { triggerReason: M._toSignatureHelpTriggerReason(n) }); if (!l || t.isDisposed()) return; const g = { activeSignature: l.selectedItemIndex, activeParameter: l.argumentIndex, signatures: [] }; return l.items.forEach((d) => { const m = { label: "", parameters: [] }; m.documentation = { value: y(d.documentation) }, m.label += y(d.prefixDisplayParts), d.parameters.forEach((h, k, x) => { const v = y(h.displayParts), C = { label: v, documentation: { value: y(h.documentation) } }; m.label += v, m.parameters.push(C), k < x.length - 1 && (m.label += y(d.separatorDisplayParts)); }), m.label += y(d.suffixDisplayParts), g.signatures.push(m); }), { value: g, dispose() { } }; }); } }, te = class extends w { provideHover(e, t, s) { return b(this, null, function* () { const o = e.uri, n = e.getOffsetAt(t), c = yield this._worker(o); if (e.isDisposed()) return; const u = yield c.getQuickInfoAtPosition(o.toString(), n); if (!u || e.isDisposed()) return; const r = y(u.documentation), l = u.tags ? u.tags.map((d) => N(d)).join(` `) : "", g = y(u.displayParts); return { range: this._textSpanToRange(e, u.textSpan), contents: [ { value: "```typescript\n" + g + "\n```\n" }, { value: r + (l ? ` ` + l : "") } ] }; }); } }, se = class extends w { provideDocumentHighlights(e, t, s) { return b(this, null, function* () { const o = e.uri, n = e.getOffsetAt(t), c = yield this._worker(o); if (e.isDisposed()) return; const u = yield c.getDocumentHighlights(o.toString(), n, [ o.toString() ]); if (!(!u || e.isDisposed())) return u.flatMap((r) => r.highlightSpans.map((l) => ({ range: this._textSpanToRange(e, l.textSpan), kind: l.kind === "writtenReference" ? a.languages.DocumentHighlightKind.Write : a.languages.DocumentHighlightKind.Text }))); }); } }, re = class extends w { constructor(e, t) { super(t), this._libFiles = e; } provideDefinition(e, t, s) { return b(this, null, function* () { const o = e.uri, n = e.getOffsetAt(t), c = yield this._worker(o); if (e.isDisposed()) return; const u = yield c.getDefinitionAtPosition(o.toString(), n); if (!u || e.isDisposed() || (yield this._libFiles.fetchLibFilesIfNecessary( u.map((l) => a.Uri.parse(l.fileName)) ), e.isDisposed())) return; const r = []; for (let l of u) { const g = this._libFiles.getOrCreateModel(l.fileName); g && r.push({ uri: g.uri, range: this._textSpanToRange(g, l.textSpan) }); } return r; }); } }, ie = class extends w { constructor(e, t) { super(t), this._libFiles = e; } provideReferences(e, t, s, o) { return b(this, null, function* () { const n = e.uri, c = e.getOffsetAt(t), u = yield this._worker(n); if (e.isDisposed()) return; const r = yield u.getReferencesAtPosition(n.toString(), c); if (!r || e.isDisposed() || (yield this._libFiles.fetchLibFilesIfNecessary( r.map((g) => a.Uri.parse(g.fileName)) ), e.isDisposed())) return; const l = []; for (let g of r) { const d = this._libFiles.getOrCreateModel(g.fileName); d && l.push({ uri: d.uri, range: this._textSpanToRange(d, g.textSpan) }); } return l; }); } }, ne = class extends w { provideDocumentSymbols(e, t) { return b(this, null, function* () { const s = e.uri, o = yield this._worker(s); if (e.isDisposed()) return; const n = yield o.getNavigationTree(s.toString()); if (!n || e.isDisposed()) return; const c = (r, l) => { var d; return { name: r.text, detail: "", kind: _[r.kind] || a.languages.SymbolKind.Variable, range: this._textSpanToRange(e, r.spans[0]), selectionRange: this._textSpanToRange(e, r.spans[0]), tags: [], children: (d = r.childItems) == null ? void 0 : d.map((m) => c(m, r.text)), containerName: l }; }; return n.childItems ? n.childItems.map((r) => c(r)) : []; }); } }, p, f = (p = class { }, p.unknown = "", p.keyword = "keyword", p.script = "script", p.module = "module", p.class = "class", p.interface = "interface", p.type = "type", p.enum = "enum", p.variable = "var", p.localVariable = "local var", p.function = "function", p.localFunction = "local function", p.memberFunction = "method", p.memberGetAccessor = "getter", p.memberSetAccessor = "setter", p.memberVariable = "property", p.constructorImplementation = "constructor", p.callSignature = "call", p.indexSignature = "index", p.constructSignature = "construct", p.parameter = "parameter", p.typeParameter = "type parameter", p.primitiveType = "primitive type", p.label = "label", p.alias = "alias", p.const = "const", p.let = "let", p.warning = "warning", p), _ = /* @__PURE__ */ Object.create(null); _[f.module] = a.languages.SymbolKind.Module; _[f.class] = a.languages.SymbolKind.Class; _[f.enum] = a.languages.SymbolKind.Enum; _[f.interface] = a.languages.SymbolKind.Interface; _[f.memberFunction] = a.languages.SymbolKind.Method; _[f.memberVariable] = a.languages.SymbolKind.Property; _[f.memberGetAccessor] = a.languages.SymbolKind.Property; _[f.memberSetAccessor] = a.languages.SymbolKind.Property; _[f.variable] = a.languages.SymbolKind.Variable; _[f.const] = a.languages.SymbolKind.Variable; _[f.localVariable] = a.languages.SymbolKind.Variable; _[f.variable] = a.languages.SymbolKind.Variable; _[f.function] = a.languages.SymbolKind.Function; _[f.localFunction] = a.languages.SymbolKind.Function; var S = class extends w { static _convertOptions(e) { return { ConvertTabsToSpaces: e.insertSpaces, TabSize: e.tabSize, IndentSize: e.tabSize, IndentStyle: 2, NewLineCharacter: ` `, InsertSpaceAfterCommaDelimiter: !0, InsertSpaceAfterSemicolonInForStatements: !0, InsertSpaceBeforeAndAfterBinaryOperators: !0, InsertSpaceAfterKeywordsInControlFlowStatements: !0, InsertSpaceAfterFunctionKeywordForAnonymousFunctions: !0, InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: !1, InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: !1, InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: !1, PlaceOpenBraceOnNewLineForControlBlocks: !1, PlaceOpenBraceOnNewLineForFunctions: !1 }; } _convertTextChanges(e, t) { return { text: t.newText, range: this._textSpanToRange(e, t.span) }; } }, ae = class extends S { constructor() { super(...arguments), this.canFormatMultipleRanges = !1; } provideDocumentRangeFormattingEdits(e, t, s, o) { return b(this, null, function* () { const n = e.uri, c = e.getOffsetAt({ lineNumber: t.startLineNumber, column: t.startColumn }), u = e.getOffsetAt({ lineNumber: t.endLineNumber, column: t.endColumn }), r = yield this._worker(n); if (e.isDisposed()) return; const l = yield r.getFormattingEditsForRange( n.toString(), c, u, S._convertOptions(s) ); if (!(!l || e.isDisposed())) return l.map((g) => this._convertTextChanges(e, g)); }); } }, oe = class extends S { get autoFormatTriggerCharacters() { return [";", "}", ` `]; } provideOnTypeFormattingEdits(e, t, s, o, n) { return b(this, null, function* () { const c = e.uri, u = e.getOffsetAt(t), r = yield this._worker(c); if (e.isDisposed()) return; const l = yield r.getFormattingEditsAfterKeystroke( c.toString(), u, s, S._convertOptions(o) ); if (!(!l || e.isDisposed())) return l.map((g) => this._convertTextChanges(e, g)); }); } }, le = class extends S { provideCodeActions(e, t, s, o) { return b(this, null, function* () { const n = e.uri, c = e.getOffsetAt({ lineNumber: t.startLineNumber, column: t.startColumn }), u = e.getOffsetAt({ lineNumber: t.endLineNumber, column: t.endColumn }), r = S._convertOptions(e.getOptions()), l = s.markers.filter((h) => h.code).map((h) => h.code).map(Number), g = yield this._worker(n); if (e.isDisposed()) return; const d = yield g.getCodeFixesAtPosition( n.toString(), c, u, l, r ); return !d || e.isDisposed() ? { actions: [], dispose: () => { } } : { actions: d.filter((h) => h.changes.filter((k) => k.isNewFile).length === 0).map((h) => this._tsCodeFixActionToMonacoCodeAction(e, s, h)), dispose: () => { } }; }); } _tsCodeFixActionToMonacoCodeAction(e, t, s) { const o = []; for (const c of s.changes) for (const u of c.textChanges) o.push({ resource: e.uri, versionId: void 0, textEdit: { range: this._textSpanToRange(e, u.span), text: u.newText } }); return { title: s.description, edit: { edits: o }, diagnostics: t.markers, kind: "quickfix" }; } }, ce = class extends w { constructor(e, t) { super(t), this._libFiles = e; } provideRenameEdits(e, t, s, o) { return b(this, null, function* () { const n = e.uri, c = n.toString(), u = e.getOffsetAt(t), r = yield this._worker(n); if (e.isDisposed()) return; const l = yield r.getRenameInfo(c, u, { allowRenameOfImportPath: !1 }); if (l.canRename === !1) return { edits: [], rejectReason: l.localizedErrorMessage }; if (l.fileToRename !== void 0) throw new Error("Renaming files is not supported."); const g = yield r.findRenameLocations( c, u, /*strings*/ !1, /*comments*/ !1, /*prefixAndSuffix*/ !1 ); if (!g || e.isDisposed()) return; const d = []; for (const m of g) { const h = this._libFiles.getOrCreateModel(m.fileName); if (h) d.push({ resource: h.uri, versionId: void 0, textEdit: { range: this._textSpanToRange(h, m.textSpan), text: s } }); else throw new Error(`Unknown file ${m.fileName}.`); } return { edits: d }; }); } }, ue = class extends w { provideInlayHints(e, t, s) { return b(this, null, function* () { const o = e.uri, n = o.toString(), c = e.getOffsetAt({ lineNumber: t.startLineNumber, column: t.startColumn }), u = e.getOffsetAt({ lineNumber: t.endLineNumber, column: t.endColumn }), r = yield this._worker(o); return e.isDisposed() ? null : { hints: (yield r.provideInlayHints(n, c, u)).map((d) => I(O({}, d), { label: d.text, position: e.getPositionAt(d.position), kind: this._convertHintKind(d.kind) })), dispose: () => { } }; }); } _convertHintKind(e) { switch (e) { case "Parameter": return a.languages.InlayHintKind.Parameter; case "Type": return a.languages.InlayHintKind.Type; default: return a.languages.InlayHintKind.Type; } } }, F, T; function fe(e) { T = R(e, "typescript"); } function he(e) { F = R(e, "javascript"); } function be() { return new Promise((e, t) => { if (!F) return t("JavaScript not registered!"); e(F); }); } function me() { return new Promise((e, t) => { if (!T) return t("TypeScript not registered!"); e(T); }); } function R(e, t) { const s = [], o = new q(t, e), n = (...r) => o.getLanguageServiceWorker(...r), c = new X(n); function u() { const { modeConfiguration: r } = e; ge(s), r.completionItems && s.push( a.languages.registerCompletionItemProvider( t, new Z(n) ) ), r.signatureHelp && s.push( a.languages.registerSignatureHelpProvider( t, new ee(n) ) ), r.hovers && s.push( a.languages.registerHoverProvider(t, new te(n)) ), r.documentHighlights && s.push( a.languages.registerDocumentHighlightProvider( t, new se(n) ) ), r.definitions && s.push( a.languages.registerDefinitionProvider( t, new re(c, n) ) ), r.references && s.push( a.languages.registerReferenceProvider( t, new ie(c, n) ) ), r.documentSymbols && s.push( a.languages.registerDocumentSymbolProvider( t, new ne(n) ) ), r.rename && s.push( a.languages.registerRenameProvider( t, new ce(c, n) ) ), r.documentRangeFormattingEdits && s.push( a.languages.registerDocumentRangeFormattingEditProvider( t, new ae(n) ) ), r.onTypeFormattingEdits && s.push( a.languages.registerOnTypeFormattingEditProvider( t, new oe(n) ) ), r.codeActions && s.push( a.languages.registerCodeActionProvider(t, new le(n)) ), r.inlayHints && s.push( a.languages.registerInlayHintsProvider(t, new ue(n)) ), r.diagnostics && s.push(new Y(c, e, t, n)); } return u(), n; } function ge(e) { for (; e.length; ) e.pop().dispose(); } export { w as Adapter, le as CodeActionAdaptor, re as DefinitionAdapter, Y as DiagnosticsAdapter, se as DocumentHighlightAdapter, ae as FormatAdapter, S as FormatHelper, oe as FormatOnTypeAdapter, ue as InlayHintsAdapter, f as Kind, X as LibFiles, ne as OutlineAdapter, te as QuickInfoAdapter, ie as ReferenceAdapter, ce as RenameAdapter, ee as SignatureHelpAdapter, Z as SuggestAdapter, q as WorkerManager, A as flattenDiagnosticMessageText, be as getJavaScriptWorker, me as getTypeScriptWorker, he as setupJavaScript, fe as setupTypeScript };