"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../_vendor/@codemirror/state/dist-index.cjs");
const standalone = require("../_vendor/prettier/standalone.cjs");
const babel = require("../_vendor/prettier/plugins-babel.cjs");
const estree = require("../_vendor/prettier/plugins-estree.cjs");
const formatCallbackFacet = index.Facet.define({
  combine: (callbacks) => callbacks[0] ?? (() => {
  })
});
function formatDocument(view) {
  const onFormat = view.state.facet(formatCallbackFacet);
  function format(parser) {
    void standalone.formatWithCursor(view.state.doc.toString(), {
      cursorOffset: view.state.selection.main.anchor,
      parser,
      plugins: [babel.default, estree.default]
    }).then(({ formatted, cursorOffset }) => {
      view.dispatch({
        changes: {
          from: 0,
          to: view.state.doc.length,
          insert: formatted
        },
        selection: index.EditorSelection.single(cursorOffset)
      });
      onFormat(formatted);
    });
  }
  format("babel");
  return true;
}
function createFormatExtension(onFormat) {
  return [formatCallbackFacet.of(onFormat)];
}
exports.createFormatExtension = createFormatExtension;
exports.formatCallbackFacet = formatCallbackFacet;
exports.formatDocument = formatDocument;
//# sourceMappingURL=format.cjs.map
