"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("./standalone-tokens.css.js");
const strings = require("../../../base/common/strings.js");
const fontMeasurements = require("../../browser/config/fontMeasurements.js");
const codeEditorService = require("../../browser/services/codeEditorService.js");
const diffNavigator = require("../../browser/widget/diffNavigator.js");
const editorOptions = require("../../common/config/editorOptions.js");
const fontInfo = require("../../common/config/fontInfo.js");
const editorCommon = require("../../common/editorCommon.js");
const model = require("../../common/model.js");
const languages = require("../../common/languages.js");
const languageConfigurationRegistry = require("../../common/languages/languageConfigurationRegistry.js");
const nullTokenize = require("../../common/languages/nullTokenize.js");
const language = require("../../common/languages/language.js");
const model$1 = require("../../common/services/model.js");
const webWorker = require("../../browser/services/webWorker.js");
const standaloneEnums = require("../../common/standalone/standaloneEnums.js");
const colorizer = require("./colorizer.js");
const standaloneCodeEditor = require("./standaloneCodeEditor.js");
const standaloneServices = require("./standaloneServices.js");
const standaloneTheme = require("../common/standaloneTheme.js");
const commands = require("../../../platform/commands/common/commands.js");
const markers = require("../../../platform/markers/common/markers.js");
function create(domElement, options, override) {
  const instantiationService = standaloneServices.StandaloneServices.initialize(override || {});
  return instantiationService.createInstance(standaloneCodeEditor.StandaloneEditor, domElement, options);
}
function onDidCreateEditor(listener) {
  const codeEditorService$1 = standaloneServices.StandaloneServices.get(codeEditorService.ICodeEditorService);
  return codeEditorService$1.onCodeEditorAdd((editor) => {
    listener(editor);
  });
}
function createDiffEditor(domElement, options, override) {
  const instantiationService = standaloneServices.StandaloneServices.initialize(override || {});
  return instantiationService.createInstance(standaloneCodeEditor.StandaloneDiffEditor, domElement, options);
}
function createDiffNavigator(diffEditor, opts) {
  return new diffNavigator.DiffNavigator(diffEditor, opts);
}
function createModel(value, language$1, uri) {
  const languageService = standaloneServices.StandaloneServices.get(language.ILanguageService);
  const languageId = languageService.getLanguageIdByMimeType(language$1) || language$1;
  return standaloneCodeEditor.createTextModel(standaloneServices.StandaloneServices.get(model$1.IModelService), languageService, value, languageId, uri);
}
function setModelLanguage(model2, languageId) {
  const languageService = standaloneServices.StandaloneServices.get(language.ILanguageService);
  const modelService = standaloneServices.StandaloneServices.get(model$1.IModelService);
  modelService.setMode(model2, languageService.createById(languageId));
}
function setModelMarkers(model2, owner, markers$1) {
  if (model2) {
    const markerService = standaloneServices.StandaloneServices.get(markers.IMarkerService);
    markerService.changeOne(owner, model2.uri, markers$1);
  }
}
function getModelMarkers(filter) {
  const markerService = standaloneServices.StandaloneServices.get(markers.IMarkerService);
  return markerService.read(filter);
}
function onDidChangeMarkers(listener) {
  const markerService = standaloneServices.StandaloneServices.get(markers.IMarkerService);
  return markerService.onMarkerChanged(listener);
}
function getModel(uri) {
  const modelService = standaloneServices.StandaloneServices.get(model$1.IModelService);
  return modelService.getModel(uri);
}
function getModels() {
  const modelService = standaloneServices.StandaloneServices.get(model$1.IModelService);
  return modelService.getModels();
}
function onDidCreateModel(listener) {
  const modelService = standaloneServices.StandaloneServices.get(model$1.IModelService);
  return modelService.onModelAdded(listener);
}
function onWillDisposeModel(listener) {
  const modelService = standaloneServices.StandaloneServices.get(model$1.IModelService);
  return modelService.onModelRemoved(listener);
}
function onDidChangeModelLanguage(listener) {
  const modelService = standaloneServices.StandaloneServices.get(model$1.IModelService);
  return modelService.onModelLanguageChanged((e) => {
    listener({
      model: e.model,
      oldLanguage: e.oldLanguageId
    });
  });
}
function createWebWorker(opts) {
  return webWorker.createWebWorker(standaloneServices.StandaloneServices.get(model$1.IModelService), standaloneServices.StandaloneServices.get(languageConfigurationRegistry.ILanguageConfigurationService), opts);
}
function colorizeElement(domNode, options) {
  const languageService = standaloneServices.StandaloneServices.get(language.ILanguageService);
  const themeService = standaloneServices.StandaloneServices.get(standaloneTheme.IStandaloneThemeService);
  themeService.registerEditorContainer(domNode);
  return colorizer.Colorizer.colorizeElement(themeService, languageService, domNode, options);
}
function colorize(text, languageId, options) {
  const languageService = standaloneServices.StandaloneServices.get(language.ILanguageService);
  const themeService = standaloneServices.StandaloneServices.get(standaloneTheme.IStandaloneThemeService);
  themeService.registerEditorContainer(document.body);
  return colorizer.Colorizer.colorize(languageService, text, languageId, options);
}
function colorizeModelLine(model2, lineNumber, tabSize = 4) {
  const themeService = standaloneServices.StandaloneServices.get(standaloneTheme.IStandaloneThemeService);
  themeService.registerEditorContainer(document.body);
  return colorizer.Colorizer.colorizeModelLine(model2, lineNumber, tabSize);
}
function getSafeTokenizationSupport(language2) {
  const tokenizationSupport = languages.TokenizationRegistry.get(language2);
  if (tokenizationSupport) {
    return tokenizationSupport;
  }
  return {
    getInitialState: () => nullTokenize.NullState,
    tokenize: (line, hasEOL, state) => nullTokenize.nullTokenize(language2, state)
  };
}
function tokenize(text, languageId) {
  languages.TokenizationRegistry.getOrCreate(languageId);
  const tokenizationSupport = getSafeTokenizationSupport(languageId);
  const lines = strings.splitLines(text);
  const result = [];
  let state = tokenizationSupport.getInitialState();
  for (let i = 0, len = lines.length; i < len; i++) {
    const line = lines[i];
    const tokenizationResult = tokenizationSupport.tokenize(line, true, state);
    result[i] = tokenizationResult.tokens;
    state = tokenizationResult.endState;
  }
  return result;
}
function defineTheme(themeName, themeData) {
  const standaloneThemeService = standaloneServices.StandaloneServices.get(standaloneTheme.IStandaloneThemeService);
  standaloneThemeService.defineTheme(themeName, themeData);
}
function setTheme(themeName) {
  const standaloneThemeService = standaloneServices.StandaloneServices.get(standaloneTheme.IStandaloneThemeService);
  standaloneThemeService.setTheme(themeName);
}
function remeasureFonts() {
  fontMeasurements.FontMeasurements.clearAllFontInfos();
}
function registerCommand(id, handler) {
  return commands.CommandsRegistry.registerCommand({ id, handler });
}
function createMonacoEditorAPI() {
  return {
    // methods
    create,
    onDidCreateEditor,
    createDiffEditor,
    createDiffNavigator,
    createModel,
    setModelLanguage,
    setModelMarkers,
    getModelMarkers,
    onDidChangeMarkers,
    getModels,
    getModel,
    onDidCreateModel,
    onWillDisposeModel,
    onDidChangeModelLanguage,
    createWebWorker,
    colorizeElement,
    colorize,
    colorizeModelLine,
    tokenize,
    defineTheme,
    setTheme,
    remeasureFonts,
    registerCommand,
    // enums
    AccessibilitySupport: standaloneEnums.AccessibilitySupport,
    ContentWidgetPositionPreference: standaloneEnums.ContentWidgetPositionPreference,
    CursorChangeReason: standaloneEnums.CursorChangeReason,
    DefaultEndOfLine: standaloneEnums.DefaultEndOfLine,
    EditorAutoIndentStrategy: standaloneEnums.EditorAutoIndentStrategy,
    EditorOption: standaloneEnums.EditorOption,
    EndOfLinePreference: standaloneEnums.EndOfLinePreference,
    EndOfLineSequence: standaloneEnums.EndOfLineSequence,
    MinimapPosition: standaloneEnums.MinimapPosition,
    MouseTargetType: standaloneEnums.MouseTargetType,
    OverlayWidgetPositionPreference: standaloneEnums.OverlayWidgetPositionPreference,
    OverviewRulerLane: standaloneEnums.OverviewRulerLane,
    RenderLineNumbersType: standaloneEnums.RenderLineNumbersType,
    RenderMinimap: standaloneEnums.RenderMinimap,
    ScrollbarVisibility: standaloneEnums.ScrollbarVisibility,
    ScrollType: standaloneEnums.ScrollType,
    TextEditorCursorBlinkingStyle: standaloneEnums.TextEditorCursorBlinkingStyle,
    TextEditorCursorStyle: standaloneEnums.TextEditorCursorStyle,
    TrackedRangeStickiness: standaloneEnums.TrackedRangeStickiness,
    WrappingIndent: standaloneEnums.WrappingIndent,
    InjectedTextCursorStops: standaloneEnums.InjectedTextCursorStops,
    PositionAffinity: standaloneEnums.PositionAffinity,
    // classes
    ConfigurationChangedEvent: editorOptions.ConfigurationChangedEvent,
    BareFontInfo: fontInfo.BareFontInfo,
    FontInfo: fontInfo.FontInfo,
    TextModelResolvedOptions: model.TextModelResolvedOptions,
    FindMatch: model.FindMatch,
    ApplyUpdateResult: editorOptions.ApplyUpdateResult,
    // vars
    EditorType: editorCommon.EditorType,
    EditorOptions: editorOptions.EditorOptions
  };
}
exports.colorize = colorize;
exports.colorizeElement = colorizeElement;
exports.colorizeModelLine = colorizeModelLine;
exports.create = create;
exports.createDiffEditor = createDiffEditor;
exports.createDiffNavigator = createDiffNavigator;
exports.createModel = createModel;
exports.createMonacoEditorAPI = createMonacoEditorAPI;
exports.createWebWorker = createWebWorker;
exports.defineTheme = defineTheme;
exports.getModel = getModel;
exports.getModelMarkers = getModelMarkers;
exports.getModels = getModels;
exports.onDidChangeMarkers = onDidChangeMarkers;
exports.onDidChangeModelLanguage = onDidChangeModelLanguage;
exports.onDidCreateEditor = onDidCreateEditor;
exports.onDidCreateModel = onDidCreateModel;
exports.onWillDisposeModel = onWillDisposeModel;
exports.registerCommand = registerCommand;
exports.remeasureFonts = remeasureFonts;
exports.setModelLanguage = setModelLanguage;
exports.setModelMarkers = setModelMarkers;
exports.setTheme = setTheme;
exports.tokenize = tokenize;
